pdf.combined.js 1.7 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377
  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. /* umdutils ignore */
  17. (function (root, factory) {
  18. 'use strict';
  19. if (typeof define === 'function' && define.amd) {
  20. define('pdfjs-dist/build/pdf.combined', ['exports'], factory);
  21. } else if (typeof exports !== 'undefined') {
  22. factory(exports);
  23. } else {
  24. factory((root.pdfjsDistBuildPdfCombined = {}));
  25. }
  26. }(this, function (exports) {
  27. // Use strict in our context only - users might not want it
  28. 'use strict';
  29. var pdfjsVersion = '1.5.488';
  30. var pdfjsBuild = '6c263c1';
  31. var pdfjsFilePath =
  32. typeof document !== 'undefined' && document.currentScript ?
  33. document.currentScript.src : null;
  34. var pdfjsLibs = {};
  35. (function pdfjsWrapper() {
  36. (function (root, factory) {
  37. {
  38. factory((root.pdfjsCoreArithmeticDecoder = {}));
  39. }
  40. }(this, function (exports) {
  41. /* This class implements the QM Coder decoding as defined in
  42. * JPEG 2000 Part I Final Committee Draft Version 1.0
  43. * Annex C.3 Arithmetic decoding procedure
  44. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  45. *
  46. * The arithmetic decoder is used in conjunction with context models to decode
  47. * JPEG2000 and JBIG2 streams.
  48. */
  49. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  50. // Table C-2
  51. var QeTable = [
  52. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  53. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  54. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  55. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  56. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  57. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  58. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  59. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  60. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  61. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  62. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  63. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  64. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  65. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  66. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  67. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  68. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  69. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  70. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  71. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  72. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  73. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  74. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  75. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  76. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  77. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  78. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  79. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  80. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  81. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  82. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  83. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  84. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  85. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  86. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  87. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  88. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  89. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  90. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  91. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  92. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  93. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  94. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  95. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  96. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  97. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  98. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  99. ];
  100. // C.3.5 Initialisation of the decoder (INITDEC)
  101. function ArithmeticDecoder(data, start, end) {
  102. this.data = data;
  103. this.bp = start;
  104. this.dataEnd = end;
  105. this.chigh = data[start];
  106. this.clow = 0;
  107. this.byteIn();
  108. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  109. this.clow = (this.clow << 7) & 0xFFFF;
  110. this.ct -= 7;
  111. this.a = 0x8000;
  112. }
  113. ArithmeticDecoder.prototype = {
  114. // C.3.4 Compressed data input (BYTEIN)
  115. byteIn: function ArithmeticDecoder_byteIn() {
  116. var data = this.data;
  117. var bp = this.bp;
  118. if (data[bp] === 0xFF) {
  119. var b1 = data[bp + 1];
  120. if (b1 > 0x8F) {
  121. this.clow += 0xFF00;
  122. this.ct = 8;
  123. } else {
  124. bp++;
  125. this.clow += (data[bp] << 9);
  126. this.ct = 7;
  127. this.bp = bp;
  128. }
  129. } else {
  130. bp++;
  131. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  132. this.ct = 8;
  133. this.bp = bp;
  134. }
  135. if (this.clow > 0xFFFF) {
  136. this.chigh += (this.clow >> 16);
  137. this.clow &= 0xFFFF;
  138. }
  139. },
  140. // C.3.2 Decoding a decision (DECODE)
  141. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  142. // contexts are packed into 1 byte:
  143. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  144. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  145. var qeTableIcx = QeTable[cx_index];
  146. var qeIcx = qeTableIcx.qe;
  147. var d;
  148. var a = this.a - qeIcx;
  149. if (this.chigh < qeIcx) {
  150. // exchangeLps
  151. if (a < qeIcx) {
  152. a = qeIcx;
  153. d = cx_mps;
  154. cx_index = qeTableIcx.nmps;
  155. } else {
  156. a = qeIcx;
  157. d = 1 ^ cx_mps;
  158. if (qeTableIcx.switchFlag === 1) {
  159. cx_mps = d;
  160. }
  161. cx_index = qeTableIcx.nlps;
  162. }
  163. } else {
  164. this.chigh -= qeIcx;
  165. if ((a & 0x8000) !== 0) {
  166. this.a = a;
  167. return cx_mps;
  168. }
  169. // exchangeMps
  170. if (a < qeIcx) {
  171. d = 1 ^ cx_mps;
  172. if (qeTableIcx.switchFlag === 1) {
  173. cx_mps = d;
  174. }
  175. cx_index = qeTableIcx.nlps;
  176. } else {
  177. d = cx_mps;
  178. cx_index = qeTableIcx.nmps;
  179. }
  180. }
  181. // C.3.3 renormD;
  182. do {
  183. if (this.ct === 0) {
  184. this.byteIn();
  185. }
  186. a <<= 1;
  187. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  188. this.clow = (this.clow << 1) & 0xFFFF;
  189. this.ct--;
  190. } while ((a & 0x8000) === 0);
  191. this.a = a;
  192. contexts[pos] = cx_index << 1 | cx_mps;
  193. return d;
  194. }
  195. };
  196. return ArithmeticDecoder;
  197. })();
  198. exports.ArithmeticDecoder = ArithmeticDecoder;
  199. }));
  200. (function (root, factory) {
  201. {
  202. factory((root.pdfjsCoreBidi = {}));
  203. }
  204. }(this, function (exports) {
  205. // Character types for symbols from 0000 to 00FF.
  206. var baseTypes = [
  207. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  208. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  209. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  210. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  211. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  212. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  213. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  214. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  215. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  216. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  217. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  218. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  219. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  220. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  221. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  222. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  223. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  224. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  225. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  226. ];
  227. // Character types for symbols from 0600 to 06FF
  228. var arabicTypes = [
  229. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  230. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  231. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  232. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  233. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  234. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  235. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  236. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  237. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  238. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  239. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  240. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  241. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  242. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  243. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  244. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  245. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  246. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  247. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  248. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  249. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  250. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  251. ];
  252. function isOdd(i) {
  253. return (i & 1) !== 0;
  254. }
  255. function isEven(i) {
  256. return (i & 1) === 0;
  257. }
  258. function findUnequal(arr, start, value) {
  259. for (var j = start, jj = arr.length; j < jj; ++j) {
  260. if (arr[j] !== value) {
  261. return j;
  262. }
  263. }
  264. return j;
  265. }
  266. function setValues(arr, start, end, value) {
  267. for (var j = start; j < end; ++j) {
  268. arr[j] = value;
  269. }
  270. }
  271. function reverseValues(arr, start, end) {
  272. for (var i = start, j = end - 1; i < j; ++i, --j) {
  273. var temp = arr[i];
  274. arr[i] = arr[j];
  275. arr[j] = temp;
  276. }
  277. }
  278. function createBidiText(str, isLTR, vertical) {
  279. return {
  280. str: str,
  281. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  282. };
  283. }
  284. // These are used in bidi(), which is called frequently. We re-use them on
  285. // each call to avoid unnecessary allocations.
  286. var chars = [];
  287. var types = [];
  288. function bidi(str, startLevel, vertical) {
  289. var isLTR = true;
  290. var strLength = str.length;
  291. if (strLength === 0 || vertical) {
  292. return createBidiText(str, isLTR, vertical);
  293. }
  294. // Get types and fill arrays
  295. chars.length = strLength;
  296. types.length = strLength;
  297. var numBidi = 0;
  298. var i, ii;
  299. for (i = 0; i < strLength; ++i) {
  300. chars[i] = str.charAt(i);
  301. var charCode = str.charCodeAt(i);
  302. var charType = 'L';
  303. if (charCode <= 0x00ff) {
  304. charType = baseTypes[charCode];
  305. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  306. charType = 'R';
  307. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  308. charType = arabicTypes[charCode & 0xff];
  309. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  310. charType = 'AL';
  311. }
  312. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  313. numBidi++;
  314. }
  315. types[i] = charType;
  316. }
  317. // Detect the bidi method
  318. // - If there are no rtl characters then no bidi needed
  319. // - If less than 30% chars are rtl then string is primarily ltr
  320. // - If more than 30% chars are rtl then string is primarily rtl
  321. if (numBidi === 0) {
  322. isLTR = true;
  323. return createBidiText(str, isLTR);
  324. }
  325. if (startLevel === -1) {
  326. if ((strLength / numBidi) < 0.3) {
  327. isLTR = true;
  328. startLevel = 0;
  329. } else {
  330. isLTR = false;
  331. startLevel = 1;
  332. }
  333. }
  334. var levels = [];
  335. for (i = 0; i < strLength; ++i) {
  336. levels[i] = startLevel;
  337. }
  338. /*
  339. X1-X10: skip most of this, since we are NOT doing the embeddings.
  340. */
  341. var e = (isOdd(startLevel) ? 'R' : 'L');
  342. var sor = e;
  343. var eor = sor;
  344. /*
  345. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  346. type of the NSM to the type of the previous character. If the NSM is at the
  347. start of the level run, it will get the type of sor.
  348. */
  349. var lastType = sor;
  350. for (i = 0; i < strLength; ++i) {
  351. if (types[i] === 'NSM') {
  352. types[i] = lastType;
  353. } else {
  354. lastType = types[i];
  355. }
  356. }
  357. /*
  358. W2. Search backwards from each instance of a European number until the
  359. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  360. the type of the European number to Arabic number.
  361. */
  362. lastType = sor;
  363. var t;
  364. for (i = 0; i < strLength; ++i) {
  365. t = types[i];
  366. if (t === 'EN') {
  367. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  368. } else if (t === 'R' || t === 'L' || t === 'AL') {
  369. lastType = t;
  370. }
  371. }
  372. /*
  373. W3. Change all ALs to R.
  374. */
  375. for (i = 0; i < strLength; ++i) {
  376. t = types[i];
  377. if (t === 'AL') {
  378. types[i] = 'R';
  379. }
  380. }
  381. /*
  382. W4. A single European separator between two European numbers changes to a
  383. European number. A single common separator between two numbers of the same
  384. type changes to that type:
  385. */
  386. for (i = 1; i < strLength - 1; ++i) {
  387. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  388. types[i] = 'EN';
  389. }
  390. if (types[i] === 'CS' &&
  391. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  392. types[i + 1] === types[i - 1]) {
  393. types[i] = types[i - 1];
  394. }
  395. }
  396. /*
  397. W5. A sequence of European terminators adjacent to European numbers changes
  398. to all European numbers:
  399. */
  400. for (i = 0; i < strLength; ++i) {
  401. if (types[i] === 'EN') {
  402. // do before
  403. var j;
  404. for (j = i - 1; j >= 0; --j) {
  405. if (types[j] !== 'ET') {
  406. break;
  407. }
  408. types[j] = 'EN';
  409. }
  410. // do after
  411. for (j = i + 1; j < strLength; ++j) {
  412. if (types[j] !== 'ET') {
  413. break;
  414. }
  415. types[j] = 'EN';
  416. }
  417. }
  418. }
  419. /*
  420. W6. Otherwise, separators and terminators change to Other Neutral:
  421. */
  422. for (i = 0; i < strLength; ++i) {
  423. t = types[i];
  424. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  425. types[i] = 'ON';
  426. }
  427. }
  428. /*
  429. W7. Search backwards from each instance of a European number until the
  430. first strong type (R, L, or sor) is found. If an L is found, then change
  431. the type of the European number to L.
  432. */
  433. lastType = sor;
  434. for (i = 0; i < strLength; ++i) {
  435. t = types[i];
  436. if (t === 'EN') {
  437. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  438. } else if (t === 'R' || t === 'L') {
  439. lastType = t;
  440. }
  441. }
  442. /*
  443. N1. A sequence of neutrals takes the direction of the surrounding strong
  444. text if the text on both sides has the same direction. European and Arabic
  445. numbers are treated as though they were R. Start-of-level-run (sor) and
  446. end-of-level-run (eor) are used at level run boundaries.
  447. */
  448. for (i = 0; i < strLength; ++i) {
  449. if (types[i] === 'ON') {
  450. var end = findUnequal(types, i + 1, 'ON');
  451. var before = sor;
  452. if (i > 0) {
  453. before = types[i - 1];
  454. }
  455. var after = eor;
  456. if (end + 1 < strLength) {
  457. after = types[end + 1];
  458. }
  459. if (before !== 'L') {
  460. before = 'R';
  461. }
  462. if (after !== 'L') {
  463. after = 'R';
  464. }
  465. if (before === after) {
  466. setValues(types, i, end, before);
  467. }
  468. i = end - 1; // reset to end (-1 so next iteration is ok)
  469. }
  470. }
  471. /*
  472. N2. Any remaining neutrals take the embedding direction.
  473. */
  474. for (i = 0; i < strLength; ++i) {
  475. if (types[i] === 'ON') {
  476. types[i] = e;
  477. }
  478. }
  479. /*
  480. I1. For all characters with an even (left-to-right) embedding direction,
  481. those of type R go up one level and those of type AN or EN go up two
  482. levels.
  483. I2. For all characters with an odd (right-to-left) embedding direction,
  484. those of type L, EN or AN go up one level.
  485. */
  486. for (i = 0; i < strLength; ++i) {
  487. t = types[i];
  488. if (isEven(levels[i])) {
  489. if (t === 'R') {
  490. levels[i] += 1;
  491. } else if (t === 'AN' || t === 'EN') {
  492. levels[i] += 2;
  493. }
  494. } else { // isOdd
  495. if (t === 'L' || t === 'AN' || t === 'EN') {
  496. levels[i] += 1;
  497. }
  498. }
  499. }
  500. /*
  501. L1. On each line, reset the embedding level of the following characters to
  502. the paragraph embedding level:
  503. segment separators,
  504. paragraph separators,
  505. any sequence of whitespace characters preceding a segment separator or
  506. paragraph separator, and any sequence of white space characters at the end
  507. of the line.
  508. */
  509. // don't bother as text is only single line
  510. /*
  511. L2. From the highest level found in the text to the lowest odd level on
  512. each line, reverse any contiguous sequence of characters that are at that
  513. level or higher.
  514. */
  515. // find highest level & lowest odd level
  516. var highestLevel = -1;
  517. var lowestOddLevel = 99;
  518. var level;
  519. for (i = 0, ii = levels.length; i < ii; ++i) {
  520. level = levels[i];
  521. if (highestLevel < level) {
  522. highestLevel = level;
  523. }
  524. if (lowestOddLevel > level && isOdd(level)) {
  525. lowestOddLevel = level;
  526. }
  527. }
  528. // now reverse between those limits
  529. for (level = highestLevel; level >= lowestOddLevel; --level) {
  530. // find segments to reverse
  531. var start = -1;
  532. for (i = 0, ii = levels.length; i < ii; ++i) {
  533. if (levels[i] < level) {
  534. if (start >= 0) {
  535. reverseValues(chars, start, i);
  536. start = -1;
  537. }
  538. } else if (start < 0) {
  539. start = i;
  540. }
  541. }
  542. if (start >= 0) {
  543. reverseValues(chars, start, levels.length);
  544. }
  545. }
  546. /*
  547. L3. Combining marks applied to a right-to-left base character will at this
  548. point precede their base character. If the rendering engine expects them to
  549. follow the base characters in the final display process, then the ordering
  550. of the marks and the base character must be reversed.
  551. */
  552. // don't bother for now
  553. /*
  554. L4. A character that possesses the mirrored property as specified by
  555. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  556. directionality of that character is R.
  557. */
  558. // don't mirror as characters are already mirrored in the pdf
  559. // Finally, return string
  560. for (i = 0, ii = chars.length; i < ii; ++i) {
  561. var ch = chars[i];
  562. if (ch === '<' || ch === '>') {
  563. chars[i] = '';
  564. }
  565. }
  566. return createBidiText(chars.join(''), isLTR);
  567. }
  568. exports.bidi = bidi;
  569. }));
  570. (function (root, factory) {
  571. {
  572. factory((root.pdfjsCoreCharsets = {}));
  573. }
  574. }(this, function (exports) {
  575. var ISOAdobeCharset = [
  576. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  577. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  578. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  579. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  580. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  581. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  582. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  583. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  584. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  585. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  586. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  587. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  588. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  589. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  590. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  591. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  592. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  593. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  594. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  595. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  596. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  597. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  598. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  599. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  600. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  601. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  602. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  603. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  604. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  605. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  606. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  607. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  608. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  609. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  610. ];
  611. var ExpertCharset = [
  612. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  613. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  614. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  615. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  616. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  617. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  618. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  619. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  620. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  621. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  622. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  623. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  624. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  625. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  626. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  627. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  628. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  629. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  630. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  631. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  632. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  633. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  634. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  635. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  636. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  637. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  638. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  639. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  640. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  641. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  642. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  643. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  644. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  645. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  646. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  647. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  648. 'Ydieresissmall'
  649. ];
  650. var ExpertSubsetCharset = [
  651. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  652. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  653. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  654. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  655. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  656. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  657. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  658. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  659. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  660. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  661. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  662. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  663. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  664. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  665. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  666. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  667. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  668. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  669. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  670. 'periodinferior', 'commainferior'
  671. ];
  672. exports.ISOAdobeCharset = ISOAdobeCharset;
  673. exports.ExpertCharset = ExpertCharset;
  674. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  675. }));
  676. (function (root, factory) {
  677. {
  678. factory((root.pdfjsCoreEncodings = {}));
  679. }
  680. }(this, function (exports) {
  681. var ExpertEncoding = [
  682. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  683. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  684. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  685. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  686. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  687. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  688. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  689. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  690. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  691. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  692. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  693. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  694. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  695. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  696. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  697. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  698. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  699. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  700. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  701. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  702. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  703. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  704. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  705. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  706. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  707. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  708. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  709. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  710. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  711. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  712. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  713. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  714. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  715. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  716. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  717. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  718. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  719. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  720. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  721. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  722. 'Ydieresissmall'];
  723. var MacExpertEncoding = [
  724. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  725. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  726. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  727. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  728. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  729. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  730. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  731. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  732. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  733. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  734. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  735. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  736. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  737. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  738. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  739. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  740. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  741. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  742. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  743. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  744. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  745. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  746. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  747. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  748. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  749. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  750. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  751. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  752. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  753. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  754. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  755. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  756. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  757. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  758. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  759. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  760. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  761. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  762. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  763. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'];
  764. var MacRomanEncoding = [
  765. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  766. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  767. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  768. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  769. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  770. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  771. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  772. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  773. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  774. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  775. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  776. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  777. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  778. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  779. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  780. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  781. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  782. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  783. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  784. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  785. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  786. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  787. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  788. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  789. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  790. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  791. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  792. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  793. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  794. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  795. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  796. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  797. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  798. 'ogonek', 'caron'];
  799. var StandardEncoding = [
  800. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  801. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  802. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  803. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  804. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  805. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  806. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  807. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  808. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  809. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  810. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  811. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  812. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  813. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  814. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  815. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  816. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  817. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  818. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  819. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  820. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  821. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  822. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  823. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  824. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'];
  825. var WinAnsiEncoding = [
  826. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  827. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  828. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  829. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  830. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  831. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  832. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  833. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  834. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  835. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  836. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  837. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  838. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  839. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  840. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  841. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  842. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  843. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  844. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  845. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  846. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  847. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  848. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  849. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  850. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  851. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  852. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  853. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  854. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  855. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  856. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  857. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  858. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  859. 'ydieresis'];
  860. var SymbolSetEncoding = [
  861. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  862. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  863. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  864. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  865. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  866. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  867. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  868. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  869. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  870. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  871. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  872. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  873. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  874. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  875. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  876. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  877. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  878. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  879. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  880. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  881. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  882. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  883. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  884. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  885. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  886. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  887. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  888. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  889. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  890. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  891. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  892. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  893. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  894. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  895. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  896. 'bracerightbt'];
  897. var ZapfDingbatsEncoding = [
  898. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  899. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  900. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  901. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  902. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  903. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  904. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  905. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  906. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  907. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  908. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  909. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  910. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  911. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  912. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  913. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  914. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  915. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  916. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  917. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  918. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  919. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  920. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  921. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191'];
  922. function getEncoding(encodingName) {
  923. switch (encodingName) {
  924. case 'WinAnsiEncoding':
  925. return WinAnsiEncoding;
  926. case 'StandardEncoding':
  927. return StandardEncoding;
  928. case 'MacRomanEncoding':
  929. return MacRomanEncoding;
  930. case 'SymbolSetEncoding':
  931. return SymbolSetEncoding;
  932. case 'ZapfDingbatsEncoding':
  933. return ZapfDingbatsEncoding;
  934. case 'ExpertEncoding':
  935. return ExpertEncoding;
  936. case 'MacExpertEncoding':
  937. return MacExpertEncoding;
  938. default:
  939. return null;
  940. }
  941. }
  942. exports.WinAnsiEncoding = WinAnsiEncoding;
  943. exports.StandardEncoding = StandardEncoding;
  944. exports.MacRomanEncoding = MacRomanEncoding;
  945. exports.SymbolSetEncoding = SymbolSetEncoding;
  946. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  947. exports.ExpertEncoding = ExpertEncoding;
  948. exports.getEncoding = getEncoding;
  949. }));
  950. (function (root, factory) {
  951. {
  952. factory((root.pdfjsSharedUtil = {}));
  953. }
  954. }(this, function (exports) {
  955. var globalScope = (typeof window !== 'undefined') ? window :
  956. (typeof global !== 'undefined') ? global :
  957. (typeof self !== 'undefined') ? self : this;
  958. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  959. var TextRenderingMode = {
  960. FILL: 0,
  961. STROKE: 1,
  962. FILL_STROKE: 2,
  963. INVISIBLE: 3,
  964. FILL_ADD_TO_PATH: 4,
  965. STROKE_ADD_TO_PATH: 5,
  966. FILL_STROKE_ADD_TO_PATH: 6,
  967. ADD_TO_PATH: 7,
  968. FILL_STROKE_MASK: 3,
  969. ADD_TO_PATH_FLAG: 4
  970. };
  971. var ImageKind = {
  972. GRAYSCALE_1BPP: 1,
  973. RGB_24BPP: 2,
  974. RGBA_32BPP: 3
  975. };
  976. var AnnotationType = {
  977. TEXT: 1,
  978. LINK: 2,
  979. FREETEXT: 3,
  980. LINE: 4,
  981. SQUARE: 5,
  982. CIRCLE: 6,
  983. POLYGON: 7,
  984. POLYLINE: 8,
  985. HIGHLIGHT: 9,
  986. UNDERLINE: 10,
  987. SQUIGGLY: 11,
  988. STRIKEOUT: 12,
  989. STAMP: 13,
  990. CARET: 14,
  991. INK: 15,
  992. POPUP: 16,
  993. FILEATTACHMENT: 17,
  994. SOUND: 18,
  995. MOVIE: 19,
  996. WIDGET: 20,
  997. SCREEN: 21,
  998. PRINTERMARK: 22,
  999. TRAPNET: 23,
  1000. WATERMARK: 24,
  1001. THREED: 25,
  1002. REDACT: 26
  1003. };
  1004. var AnnotationFlag = {
  1005. INVISIBLE: 0x01,
  1006. HIDDEN: 0x02,
  1007. PRINT: 0x04,
  1008. NOZOOM: 0x08,
  1009. NOROTATE: 0x10,
  1010. NOVIEW: 0x20,
  1011. READONLY: 0x40,
  1012. LOCKED: 0x80,
  1013. TOGGLENOVIEW: 0x100,
  1014. LOCKEDCONTENTS: 0x200
  1015. };
  1016. var AnnotationFieldFlag = {
  1017. READONLY: 0x0000001,
  1018. REQUIRED: 0x0000002,
  1019. NOEXPORT: 0x0000004,
  1020. MULTILINE: 0x0001000,
  1021. PASSWORD: 0x0002000,
  1022. NOTOGGLETOOFF: 0x0004000,
  1023. RADIO: 0x0008000,
  1024. PUSHBUTTON: 0x0010000,
  1025. COMBO: 0x0020000,
  1026. EDIT: 0x0040000,
  1027. SORT: 0x0080000,
  1028. FILESELECT: 0x0100000,
  1029. MULTISELECT: 0x0200000,
  1030. DONOTSPELLCHECK: 0x0400000,
  1031. DONOTSCROLL: 0x0800000,
  1032. COMB: 0x1000000,
  1033. RICHTEXT: 0x2000000,
  1034. RADIOSINUNISON: 0x2000000,
  1035. COMMITONSELCHANGE: 0x4000000,
  1036. };
  1037. var AnnotationBorderStyleType = {
  1038. SOLID: 1,
  1039. DASHED: 2,
  1040. BEVELED: 3,
  1041. INSET: 4,
  1042. UNDERLINE: 5
  1043. };
  1044. var StreamType = {
  1045. UNKNOWN: 0,
  1046. FLATE: 1,
  1047. LZW: 2,
  1048. DCT: 3,
  1049. JPX: 4,
  1050. JBIG: 5,
  1051. A85: 6,
  1052. AHX: 7,
  1053. CCF: 8,
  1054. RL: 9
  1055. };
  1056. var FontType = {
  1057. UNKNOWN: 0,
  1058. TYPE1: 1,
  1059. TYPE1C: 2,
  1060. CIDFONTTYPE0: 3,
  1061. CIDFONTTYPE0C: 4,
  1062. TRUETYPE: 5,
  1063. CIDFONTTYPE2: 6,
  1064. TYPE3: 7,
  1065. OPENTYPE: 8,
  1066. TYPE0: 9,
  1067. MMTYPE1: 10
  1068. };
  1069. var VERBOSITY_LEVELS = {
  1070. errors: 0,
  1071. warnings: 1,
  1072. infos: 5
  1073. };
  1074. // All the possible operations for an operator list.
  1075. var OPS = {
  1076. // Intentionally start from 1 so it is easy to spot bad operators that will be
  1077. // 0's.
  1078. dependency: 1,
  1079. setLineWidth: 2,
  1080. setLineCap: 3,
  1081. setLineJoin: 4,
  1082. setMiterLimit: 5,
  1083. setDash: 6,
  1084. setRenderingIntent: 7,
  1085. setFlatness: 8,
  1086. setGState: 9,
  1087. save: 10,
  1088. restore: 11,
  1089. transform: 12,
  1090. moveTo: 13,
  1091. lineTo: 14,
  1092. curveTo: 15,
  1093. curveTo2: 16,
  1094. curveTo3: 17,
  1095. closePath: 18,
  1096. rectangle: 19,
  1097. stroke: 20,
  1098. closeStroke: 21,
  1099. fill: 22,
  1100. eoFill: 23,
  1101. fillStroke: 24,
  1102. eoFillStroke: 25,
  1103. closeFillStroke: 26,
  1104. closeEOFillStroke: 27,
  1105. endPath: 28,
  1106. clip: 29,
  1107. eoClip: 30,
  1108. beginText: 31,
  1109. endText: 32,
  1110. setCharSpacing: 33,
  1111. setWordSpacing: 34,
  1112. setHScale: 35,
  1113. setLeading: 36,
  1114. setFont: 37,
  1115. setTextRenderingMode: 38,
  1116. setTextRise: 39,
  1117. moveText: 40,
  1118. setLeadingMoveText: 41,
  1119. setTextMatrix: 42,
  1120. nextLine: 43,
  1121. showText: 44,
  1122. showSpacedText: 45,
  1123. nextLineShowText: 46,
  1124. nextLineSetSpacingShowText: 47,
  1125. setCharWidth: 48,
  1126. setCharWidthAndBounds: 49,
  1127. setStrokeColorSpace: 50,
  1128. setFillColorSpace: 51,
  1129. setStrokeColor: 52,
  1130. setStrokeColorN: 53,
  1131. setFillColor: 54,
  1132. setFillColorN: 55,
  1133. setStrokeGray: 56,
  1134. setFillGray: 57,
  1135. setStrokeRGBColor: 58,
  1136. setFillRGBColor: 59,
  1137. setStrokeCMYKColor: 60,
  1138. setFillCMYKColor: 61,
  1139. shadingFill: 62,
  1140. beginInlineImage: 63,
  1141. beginImageData: 64,
  1142. endInlineImage: 65,
  1143. paintXObject: 66,
  1144. markPoint: 67,
  1145. markPointProps: 68,
  1146. beginMarkedContent: 69,
  1147. beginMarkedContentProps: 70,
  1148. endMarkedContent: 71,
  1149. beginCompat: 72,
  1150. endCompat: 73,
  1151. paintFormXObjectBegin: 74,
  1152. paintFormXObjectEnd: 75,
  1153. beginGroup: 76,
  1154. endGroup: 77,
  1155. beginAnnotations: 78,
  1156. endAnnotations: 79,
  1157. beginAnnotation: 80,
  1158. endAnnotation: 81,
  1159. paintJpegXObject: 82,
  1160. paintImageMaskXObject: 83,
  1161. paintImageMaskXObjectGroup: 84,
  1162. paintImageXObject: 85,
  1163. paintInlineImageXObject: 86,
  1164. paintInlineImageXObjectGroup: 87,
  1165. paintImageXObjectRepeat: 88,
  1166. paintImageMaskXObjectRepeat: 89,
  1167. paintSolidColorImageMask: 90,
  1168. constructPath: 91
  1169. };
  1170. var verbosity = VERBOSITY_LEVELS.warnings;
  1171. function setVerbosityLevel(level) {
  1172. verbosity = level;
  1173. }
  1174. function getVerbosityLevel() {
  1175. return verbosity;
  1176. }
  1177. // A notice for devs. These are good for things that are helpful to devs, such
  1178. // as warning that Workers were disabled, which is important to devs but not
  1179. // end users.
  1180. function info(msg) {
  1181. if (verbosity >= VERBOSITY_LEVELS.infos) {
  1182. console.log('Info: ' + msg);
  1183. }
  1184. }
  1185. // Non-fatal warnings.
  1186. function warn(msg) {
  1187. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  1188. console.log('Warning: ' + msg);
  1189. }
  1190. }
  1191. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  1192. function deprecated(details) {
  1193. console.log('Deprecated API usage: ' + details);
  1194. }
  1195. // Fatal errors that should trigger the fallback UI and halt execution by
  1196. // throwing an exception.
  1197. function error(msg) {
  1198. if (verbosity >= VERBOSITY_LEVELS.errors) {
  1199. console.log('Error: ' + msg);
  1200. console.log(backtrace());
  1201. }
  1202. throw new Error(msg);
  1203. }
  1204. function backtrace() {
  1205. try {
  1206. throw new Error();
  1207. } catch (e) {
  1208. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  1209. }
  1210. }
  1211. function assert(cond, msg) {
  1212. if (!cond) {
  1213. error(msg);
  1214. }
  1215. }
  1216. var UNSUPPORTED_FEATURES = {
  1217. unknown: 'unknown',
  1218. forms: 'forms',
  1219. javaScript: 'javaScript',
  1220. smask: 'smask',
  1221. shadingPattern: 'shadingPattern',
  1222. font: 'font'
  1223. };
  1224. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  1225. function isSameOrigin(baseUrl, otherUrl) {
  1226. try {
  1227. var base = new URL(baseUrl);
  1228. if (!base.origin || base.origin === 'null') {
  1229. return false; // non-HTTP url
  1230. }
  1231. } catch (e) {
  1232. return false;
  1233. }
  1234. var other = new URL(otherUrl, base);
  1235. return base.origin === other.origin;
  1236. }
  1237. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  1238. function isValidUrl(url, allowRelative) {
  1239. if (!url || typeof url !== 'string') {
  1240. return false;
  1241. }
  1242. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  1243. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  1244. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  1245. if (!protocol) {
  1246. return allowRelative;
  1247. }
  1248. protocol = protocol[0].toLowerCase();
  1249. switch (protocol) {
  1250. case 'http':
  1251. case 'https':
  1252. case 'ftp':
  1253. case 'mailto':
  1254. case 'tel':
  1255. return true;
  1256. default:
  1257. return false;
  1258. }
  1259. }
  1260. function shadow(obj, prop, value) {
  1261. Object.defineProperty(obj, prop, { value: value,
  1262. enumerable: true,
  1263. configurable: true,
  1264. writable: false });
  1265. return value;
  1266. }
  1267. function getLookupTableFactory(initializer) {
  1268. var lookup;
  1269. return function () {
  1270. if (initializer) {
  1271. lookup = Object.create(null);
  1272. initializer(lookup);
  1273. initializer = null;
  1274. }
  1275. return lookup;
  1276. };
  1277. }
  1278. var PasswordResponses = {
  1279. NEED_PASSWORD: 1,
  1280. INCORRECT_PASSWORD: 2
  1281. };
  1282. var PasswordException = (function PasswordExceptionClosure() {
  1283. function PasswordException(msg, code) {
  1284. this.name = 'PasswordException';
  1285. this.message = msg;
  1286. this.code = code;
  1287. }
  1288. PasswordException.prototype = new Error();
  1289. PasswordException.constructor = PasswordException;
  1290. return PasswordException;
  1291. })();
  1292. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  1293. function UnknownErrorException(msg, details) {
  1294. this.name = 'UnknownErrorException';
  1295. this.message = msg;
  1296. this.details = details;
  1297. }
  1298. UnknownErrorException.prototype = new Error();
  1299. UnknownErrorException.constructor = UnknownErrorException;
  1300. return UnknownErrorException;
  1301. })();
  1302. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  1303. function InvalidPDFException(msg) {
  1304. this.name = 'InvalidPDFException';
  1305. this.message = msg;
  1306. }
  1307. InvalidPDFException.prototype = new Error();
  1308. InvalidPDFException.constructor = InvalidPDFException;
  1309. return InvalidPDFException;
  1310. })();
  1311. var MissingPDFException = (function MissingPDFExceptionClosure() {
  1312. function MissingPDFException(msg) {
  1313. this.name = 'MissingPDFException';
  1314. this.message = msg;
  1315. }
  1316. MissingPDFException.prototype = new Error();
  1317. MissingPDFException.constructor = MissingPDFException;
  1318. return MissingPDFException;
  1319. })();
  1320. var UnexpectedResponseException =
  1321. (function UnexpectedResponseExceptionClosure() {
  1322. function UnexpectedResponseException(msg, status) {
  1323. this.name = 'UnexpectedResponseException';
  1324. this.message = msg;
  1325. this.status = status;
  1326. }
  1327. UnexpectedResponseException.prototype = new Error();
  1328. UnexpectedResponseException.constructor = UnexpectedResponseException;
  1329. return UnexpectedResponseException;
  1330. })();
  1331. var NotImplementedException = (function NotImplementedExceptionClosure() {
  1332. function NotImplementedException(msg) {
  1333. this.message = msg;
  1334. }
  1335. NotImplementedException.prototype = new Error();
  1336. NotImplementedException.prototype.name = 'NotImplementedException';
  1337. NotImplementedException.constructor = NotImplementedException;
  1338. return NotImplementedException;
  1339. })();
  1340. var MissingDataException = (function MissingDataExceptionClosure() {
  1341. function MissingDataException(begin, end) {
  1342. this.begin = begin;
  1343. this.end = end;
  1344. this.message = 'Missing data [' + begin + ', ' + end + ')';
  1345. }
  1346. MissingDataException.prototype = new Error();
  1347. MissingDataException.prototype.name = 'MissingDataException';
  1348. MissingDataException.constructor = MissingDataException;
  1349. return MissingDataException;
  1350. })();
  1351. var XRefParseException = (function XRefParseExceptionClosure() {
  1352. function XRefParseException(msg) {
  1353. this.message = msg;
  1354. }
  1355. XRefParseException.prototype = new Error();
  1356. XRefParseException.prototype.name = 'XRefParseException';
  1357. XRefParseException.constructor = XRefParseException;
  1358. return XRefParseException;
  1359. })();
  1360. var NullCharactersRegExp = /\x00/g;
  1361. function removeNullCharacters(str) {
  1362. if (typeof str !== 'string') {
  1363. warn('The argument for removeNullCharacters must be a string.');
  1364. return str;
  1365. }
  1366. return str.replace(NullCharactersRegExp, '');
  1367. }
  1368. function bytesToString(bytes) {
  1369. assert(bytes !== null && typeof bytes === 'object' &&
  1370. bytes.length !== undefined, 'Invalid argument for bytesToString');
  1371. var length = bytes.length;
  1372. var MAX_ARGUMENT_COUNT = 8192;
  1373. if (length < MAX_ARGUMENT_COUNT) {
  1374. return String.fromCharCode.apply(null, bytes);
  1375. }
  1376. var strBuf = [];
  1377. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  1378. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  1379. var chunk = bytes.subarray(i, chunkEnd);
  1380. strBuf.push(String.fromCharCode.apply(null, chunk));
  1381. }
  1382. return strBuf.join('');
  1383. }
  1384. function stringToBytes(str) {
  1385. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  1386. var length = str.length;
  1387. var bytes = new Uint8Array(length);
  1388. for (var i = 0; i < length; ++i) {
  1389. bytes[i] = str.charCodeAt(i) & 0xFF;
  1390. }
  1391. return bytes;
  1392. }
  1393. /**
  1394. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  1395. * @param {Array|Uint8Array|string} arr
  1396. * @returns {number}
  1397. */
  1398. function arrayByteLength(arr) {
  1399. if (arr.length !== undefined) {
  1400. return arr.length;
  1401. }
  1402. assert(arr.byteLength !== undefined);
  1403. return arr.byteLength;
  1404. }
  1405. /**
  1406. * Combines array items (arrays) into single Uint8Array object.
  1407. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  1408. * @returns {Uint8Array}
  1409. */
  1410. function arraysToBytes(arr) {
  1411. // Shortcut: if first and only item is Uint8Array, return it.
  1412. if (arr.length === 1 && (arr[0] instanceof Uint8Array)) {
  1413. return arr[0];
  1414. }
  1415. var resultLength = 0;
  1416. var i, ii = arr.length;
  1417. var item, itemLength ;
  1418. for (i = 0; i < ii; i++) {
  1419. item = arr[i];
  1420. itemLength = arrayByteLength(item);
  1421. resultLength += itemLength;
  1422. }
  1423. var pos = 0;
  1424. var data = new Uint8Array(resultLength);
  1425. for (i = 0; i < ii; i++) {
  1426. item = arr[i];
  1427. if (!(item instanceof Uint8Array)) {
  1428. if (typeof item === 'string') {
  1429. item = stringToBytes(item);
  1430. } else {
  1431. item = new Uint8Array(item);
  1432. }
  1433. }
  1434. itemLength = item.byteLength;
  1435. data.set(item, pos);
  1436. pos += itemLength;
  1437. }
  1438. return data;
  1439. }
  1440. function string32(value) {
  1441. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  1442. (value >> 8) & 0xff, value & 0xff);
  1443. }
  1444. function log2(x) {
  1445. var n = 1, i = 0;
  1446. while (x > n) {
  1447. n <<= 1;
  1448. i++;
  1449. }
  1450. return i;
  1451. }
  1452. function readInt8(data, start) {
  1453. return (data[start] << 24) >> 24;
  1454. }
  1455. function readUint16(data, offset) {
  1456. return (data[offset] << 8) | data[offset + 1];
  1457. }
  1458. function readUint32(data, offset) {
  1459. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  1460. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  1461. }
  1462. // Lazy test the endianness of the platform
  1463. // NOTE: This will be 'true' for simulated TypedArrays
  1464. function isLittleEndian() {
  1465. var buffer8 = new Uint8Array(2);
  1466. buffer8[0] = 1;
  1467. var buffer16 = new Uint16Array(buffer8.buffer);
  1468. return (buffer16[0] === 1);
  1469. }
  1470. // Checks if it's possible to eval JS expressions.
  1471. function isEvalSupported() {
  1472. try {
  1473. /* jshint evil: true */
  1474. new Function('');
  1475. return true;
  1476. } catch (e) {
  1477. return false;
  1478. }
  1479. }
  1480. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  1481. function Uint32ArrayView(buffer, length) {
  1482. this.buffer = buffer;
  1483. this.byteLength = buffer.length;
  1484. this.length = length === undefined ? (this.byteLength >> 2) : length;
  1485. ensureUint32ArrayViewProps(this.length);
  1486. }
  1487. Uint32ArrayView.prototype = Object.create(null);
  1488. var uint32ArrayViewSetters = 0;
  1489. function createUint32ArrayProp(index) {
  1490. return {
  1491. get: function () {
  1492. var buffer = this.buffer, offset = index << 2;
  1493. return (buffer[offset] | (buffer[offset + 1] << 8) |
  1494. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  1495. },
  1496. set: function (value) {
  1497. var buffer = this.buffer, offset = index << 2;
  1498. buffer[offset] = value & 255;
  1499. buffer[offset + 1] = (value >> 8) & 255;
  1500. buffer[offset + 2] = (value >> 16) & 255;
  1501. buffer[offset + 3] = (value >>> 24) & 255;
  1502. }
  1503. };
  1504. }
  1505. function ensureUint32ArrayViewProps(length) {
  1506. while (uint32ArrayViewSetters < length) {
  1507. Object.defineProperty(Uint32ArrayView.prototype,
  1508. uint32ArrayViewSetters,
  1509. createUint32ArrayProp(uint32ArrayViewSetters));
  1510. uint32ArrayViewSetters++;
  1511. }
  1512. }
  1513. return Uint32ArrayView;
  1514. })();
  1515. exports.Uint32ArrayView = Uint32ArrayView;
  1516. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  1517. var Util = (function UtilClosure() {
  1518. function Util() {}
  1519. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  1520. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  1521. // creating many intermediate strings.
  1522. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  1523. rgbBuf[1] = r;
  1524. rgbBuf[3] = g;
  1525. rgbBuf[5] = b;
  1526. return rgbBuf.join('');
  1527. };
  1528. // Concatenates two transformation matrices together and returns the result.
  1529. Util.transform = function Util_transform(m1, m2) {
  1530. return [
  1531. m1[0] * m2[0] + m1[2] * m2[1],
  1532. m1[1] * m2[0] + m1[3] * m2[1],
  1533. m1[0] * m2[2] + m1[2] * m2[3],
  1534. m1[1] * m2[2] + m1[3] * m2[3],
  1535. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  1536. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  1537. ];
  1538. };
  1539. // For 2d affine transforms
  1540. Util.applyTransform = function Util_applyTransform(p, m) {
  1541. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  1542. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  1543. return [xt, yt];
  1544. };
  1545. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  1546. var d = m[0] * m[3] - m[1] * m[2];
  1547. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  1548. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  1549. return [xt, yt];
  1550. };
  1551. // Applies the transform to the rectangle and finds the minimum axially
  1552. // aligned bounding box.
  1553. Util.getAxialAlignedBoundingBox =
  1554. function Util_getAxialAlignedBoundingBox(r, m) {
  1555. var p1 = Util.applyTransform(r, m);
  1556. var p2 = Util.applyTransform(r.slice(2, 4), m);
  1557. var p3 = Util.applyTransform([r[0], r[3]], m);
  1558. var p4 = Util.applyTransform([r[2], r[1]], m);
  1559. return [
  1560. Math.min(p1[0], p2[0], p3[0], p4[0]),
  1561. Math.min(p1[1], p2[1], p3[1], p4[1]),
  1562. Math.max(p1[0], p2[0], p3[0], p4[0]),
  1563. Math.max(p1[1], p2[1], p3[1], p4[1])
  1564. ];
  1565. };
  1566. Util.inverseTransform = function Util_inverseTransform(m) {
  1567. var d = m[0] * m[3] - m[1] * m[2];
  1568. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  1569. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  1570. };
  1571. // Apply a generic 3d matrix M on a 3-vector v:
  1572. // | a b c | | X |
  1573. // | d e f | x | Y |
  1574. // | g h i | | Z |
  1575. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  1576. // with v as [X,Y,Z]
  1577. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  1578. return [
  1579. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  1580. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  1581. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  1582. ];
  1583. };
  1584. // This calculation uses Singular Value Decomposition.
  1585. // The SVD can be represented with formula A = USV. We are interested in the
  1586. // matrix S here because it represents the scale values.
  1587. Util.singularValueDecompose2dScale =
  1588. function Util_singularValueDecompose2dScale(m) {
  1589. var transpose = [m[0], m[2], m[1], m[3]];
  1590. // Multiply matrix m with its transpose.
  1591. var a = m[0] * transpose[0] + m[1] * transpose[2];
  1592. var b = m[0] * transpose[1] + m[1] * transpose[3];
  1593. var c = m[2] * transpose[0] + m[3] * transpose[2];
  1594. var d = m[2] * transpose[1] + m[3] * transpose[3];
  1595. // Solve the second degree polynomial to get roots.
  1596. var first = (a + d) / 2;
  1597. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  1598. var sx = first + second || 1;
  1599. var sy = first - second || 1;
  1600. // Scale values are the square roots of the eigenvalues.
  1601. return [Math.sqrt(sx), Math.sqrt(sy)];
  1602. };
  1603. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  1604. // For coordinate systems whose origin lies in the bottom-left, this
  1605. // means normalization to (BL,TR) ordering. For systems with origin in the
  1606. // top-left, this means (TL,BR) ordering.
  1607. Util.normalizeRect = function Util_normalizeRect(rect) {
  1608. var r = rect.slice(0); // clone rect
  1609. if (rect[0] > rect[2]) {
  1610. r[0] = rect[2];
  1611. r[2] = rect[0];
  1612. }
  1613. if (rect[1] > rect[3]) {
  1614. r[1] = rect[3];
  1615. r[3] = rect[1];
  1616. }
  1617. return r;
  1618. };
  1619. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  1620. // intersection of rect1 and rect2. If no intersection, returns 'false'
  1621. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  1622. Util.intersect = function Util_intersect(rect1, rect2) {
  1623. function compare(a, b) {
  1624. return a - b;
  1625. }
  1626. // Order points along the axes
  1627. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  1628. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  1629. result = [];
  1630. rect1 = Util.normalizeRect(rect1);
  1631. rect2 = Util.normalizeRect(rect2);
  1632. // X: first and second points belong to different rectangles?
  1633. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  1634. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  1635. // Intersection must be between second and third points
  1636. result[0] = orderedX[1];
  1637. result[2] = orderedX[2];
  1638. } else {
  1639. return false;
  1640. }
  1641. // Y: first and second points belong to different rectangles?
  1642. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  1643. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  1644. // Intersection must be between second and third points
  1645. result[1] = orderedY[1];
  1646. result[3] = orderedY[2];
  1647. } else {
  1648. return false;
  1649. }
  1650. return result;
  1651. };
  1652. Util.sign = function Util_sign(num) {
  1653. return num < 0 ? -1 : 1;
  1654. };
  1655. var ROMAN_NUMBER_MAP = [
  1656. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  1657. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  1658. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  1659. ];
  1660. /**
  1661. * Converts positive integers to (upper case) Roman numerals.
  1662. * @param {integer} number - The number that should be converted.
  1663. * @param {boolean} lowerCase - Indicates if the result should be converted
  1664. * to lower case letters. The default is false.
  1665. * @return {string} The resulting Roman number.
  1666. */
  1667. Util.toRoman = function Util_toRoman(number, lowerCase) {
  1668. assert(isInt(number) && number > 0,
  1669. 'The number should be a positive integer.');
  1670. var pos, romanBuf = [];
  1671. // Thousands
  1672. while (number >= 1000) {
  1673. number -= 1000;
  1674. romanBuf.push('M');
  1675. }
  1676. // Hundreds
  1677. pos = (number / 100) | 0;
  1678. number %= 100;
  1679. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  1680. // Tens
  1681. pos = (number / 10) | 0;
  1682. number %= 10;
  1683. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  1684. // Ones
  1685. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  1686. var romanStr = romanBuf.join('');
  1687. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  1688. };
  1689. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  1690. Array.prototype.push.apply(arr1, arr2);
  1691. };
  1692. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  1693. Array.prototype.unshift.apply(arr1, arr2);
  1694. };
  1695. Util.extendObj = function extendObj(obj1, obj2) {
  1696. for (var key in obj2) {
  1697. obj1[key] = obj2[key];
  1698. }
  1699. };
  1700. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  1701. name) {
  1702. while (dict && !dict.has(name)) {
  1703. dict = dict.get('Parent');
  1704. }
  1705. if (!dict) {
  1706. return null;
  1707. }
  1708. return dict.get(name);
  1709. };
  1710. Util.inherit = function Util_inherit(sub, base, prototype) {
  1711. sub.prototype = Object.create(base.prototype);
  1712. sub.prototype.constructor = sub;
  1713. for (var prop in prototype) {
  1714. sub.prototype[prop] = prototype[prop];
  1715. }
  1716. };
  1717. Util.loadScript = function Util_loadScript(src, callback) {
  1718. var script = document.createElement('script');
  1719. var loaded = false;
  1720. script.setAttribute('src', src);
  1721. if (callback) {
  1722. script.onload = function() {
  1723. if (!loaded) {
  1724. callback();
  1725. }
  1726. loaded = true;
  1727. };
  1728. }
  1729. document.getElementsByTagName('head')[0].appendChild(script);
  1730. };
  1731. return Util;
  1732. })();
  1733. /**
  1734. * PDF page viewport created based on scale, rotation and offset.
  1735. * @class
  1736. * @alias PageViewport
  1737. */
  1738. var PageViewport = (function PageViewportClosure() {
  1739. /**
  1740. * @constructor
  1741. * @private
  1742. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  1743. * @param scale {number} scale of the viewport.
  1744. * @param rotation {number} rotations of the viewport in degrees.
  1745. * @param offsetX {number} offset X
  1746. * @param offsetY {number} offset Y
  1747. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  1748. */
  1749. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  1750. this.viewBox = viewBox;
  1751. this.scale = scale;
  1752. this.rotation = rotation;
  1753. this.offsetX = offsetX;
  1754. this.offsetY = offsetY;
  1755. // creating transform to convert pdf coordinate system to the normal
  1756. // canvas like coordinates taking in account scale and rotation
  1757. var centerX = (viewBox[2] + viewBox[0]) / 2;
  1758. var centerY = (viewBox[3] + viewBox[1]) / 2;
  1759. var rotateA, rotateB, rotateC, rotateD;
  1760. rotation = rotation % 360;
  1761. rotation = rotation < 0 ? rotation + 360 : rotation;
  1762. switch (rotation) {
  1763. case 180:
  1764. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  1765. break;
  1766. case 90:
  1767. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  1768. break;
  1769. case 270:
  1770. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  1771. break;
  1772. //case 0:
  1773. default:
  1774. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  1775. break;
  1776. }
  1777. if (dontFlip) {
  1778. rotateC = -rotateC; rotateD = -rotateD;
  1779. }
  1780. var offsetCanvasX, offsetCanvasY;
  1781. var width, height;
  1782. if (rotateA === 0) {
  1783. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  1784. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  1785. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  1786. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  1787. } else {
  1788. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  1789. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  1790. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  1791. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  1792. }
  1793. // creating transform for the following operations:
  1794. // translate(-centerX, -centerY), rotate and flip vertically,
  1795. // scale, and translate(offsetCanvasX, offsetCanvasY)
  1796. this.transform = [
  1797. rotateA * scale,
  1798. rotateB * scale,
  1799. rotateC * scale,
  1800. rotateD * scale,
  1801. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  1802. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  1803. ];
  1804. this.width = width;
  1805. this.height = height;
  1806. this.fontScale = scale;
  1807. }
  1808. PageViewport.prototype = /** @lends PageViewport.prototype */ {
  1809. /**
  1810. * Clones viewport with additional properties.
  1811. * @param args {Object} (optional) If specified, may contain the 'scale' or
  1812. * 'rotation' properties to override the corresponding properties in
  1813. * the cloned viewport.
  1814. * @returns {PageViewport} Cloned viewport.
  1815. */
  1816. clone: function PageViewPort_clone(args) {
  1817. args = args || {};
  1818. var scale = 'scale' in args ? args.scale : this.scale;
  1819. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  1820. return new PageViewport(this.viewBox.slice(), scale, rotation,
  1821. this.offsetX, this.offsetY, args.dontFlip);
  1822. },
  1823. /**
  1824. * Converts PDF point to the viewport coordinates. For examples, useful for
  1825. * converting PDF location into canvas pixel coordinates.
  1826. * @param x {number} X coordinate.
  1827. * @param y {number} Y coordinate.
  1828. * @returns {Object} Object that contains 'x' and 'y' properties of the
  1829. * point in the viewport coordinate space.
  1830. * @see {@link convertToPdfPoint}
  1831. * @see {@link convertToViewportRectangle}
  1832. */
  1833. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  1834. return Util.applyTransform([x, y], this.transform);
  1835. },
  1836. /**
  1837. * Converts PDF rectangle to the viewport coordinates.
  1838. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  1839. * @returns {Array} Contains corresponding coordinates of the rectangle
  1840. * in the viewport coordinate space.
  1841. * @see {@link convertToViewportPoint}
  1842. */
  1843. convertToViewportRectangle:
  1844. function PageViewport_convertToViewportRectangle(rect) {
  1845. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  1846. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  1847. return [tl[0], tl[1], br[0], br[1]];
  1848. },
  1849. /**
  1850. * Converts viewport coordinates to the PDF location. For examples, useful
  1851. * for converting canvas pixel location into PDF one.
  1852. * @param x {number} X coordinate.
  1853. * @param y {number} Y coordinate.
  1854. * @returns {Object} Object that contains 'x' and 'y' properties of the
  1855. * point in the PDF coordinate space.
  1856. * @see {@link convertToViewportPoint}
  1857. */
  1858. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  1859. return Util.applyInverseTransform([x, y], this.transform);
  1860. }
  1861. };
  1862. return PageViewport;
  1863. })();
  1864. var PDFStringTranslateTable = [
  1865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1866. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  1867. 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,
  1868. 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,
  1869. 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,
  1870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  1871. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  1872. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  1873. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  1874. ];
  1875. function stringToPDFString(str) {
  1876. var i, n = str.length, strBuf = [];
  1877. if (str[0] === '\xFE' && str[1] === '\xFF') {
  1878. // UTF16BE BOM
  1879. for (i = 2; i < n; i += 2) {
  1880. strBuf.push(String.fromCharCode(
  1881. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  1882. }
  1883. } else {
  1884. for (i = 0; i < n; ++i) {
  1885. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  1886. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  1887. }
  1888. }
  1889. return strBuf.join('');
  1890. }
  1891. function stringToUTF8String(str) {
  1892. return decodeURIComponent(escape(str));
  1893. }
  1894. function utf8StringToString(str) {
  1895. return unescape(encodeURIComponent(str));
  1896. }
  1897. function isEmptyObj(obj) {
  1898. for (var key in obj) {
  1899. return false;
  1900. }
  1901. return true;
  1902. }
  1903. function isBool(v) {
  1904. return typeof v === 'boolean';
  1905. }
  1906. function isInt(v) {
  1907. return typeof v === 'number' && ((v | 0) === v);
  1908. }
  1909. function isNum(v) {
  1910. return typeof v === 'number';
  1911. }
  1912. function isString(v) {
  1913. return typeof v === 'string';
  1914. }
  1915. function isArray(v) {
  1916. return v instanceof Array;
  1917. }
  1918. function isArrayBuffer(v) {
  1919. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  1920. }
  1921. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  1922. function isSpace(ch) {
  1923. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  1924. }
  1925. /**
  1926. * Promise Capability object.
  1927. *
  1928. * @typedef {Object} PromiseCapability
  1929. * @property {Promise} promise - A promise object.
  1930. * @property {function} resolve - Fulfills the promise.
  1931. * @property {function} reject - Rejects the promise.
  1932. */
  1933. /**
  1934. * Creates a promise capability object.
  1935. * @alias createPromiseCapability
  1936. *
  1937. * @return {PromiseCapability} A capability object contains:
  1938. * - a Promise, resolve and reject methods.
  1939. */
  1940. function createPromiseCapability() {
  1941. var capability = {};
  1942. capability.promise = new Promise(function (resolve, reject) {
  1943. capability.resolve = resolve;
  1944. capability.reject = reject;
  1945. });
  1946. return capability;
  1947. }
  1948. /**
  1949. * Polyfill for Promises:
  1950. * The following promise implementation tries to generally implement the
  1951. * Promise/A+ spec. Some notable differences from other promise libraries are:
  1952. * - There currently isn't a separate deferred and promise object.
  1953. * - Unhandled rejections eventually show an error if they aren't handled.
  1954. *
  1955. * Based off of the work in:
  1956. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  1957. */
  1958. (function PromiseClosure() {
  1959. if (globalScope.Promise) {
  1960. // Promises existing in the DOM/Worker, checking presence of all/resolve
  1961. if (typeof globalScope.Promise.all !== 'function') {
  1962. globalScope.Promise.all = function (iterable) {
  1963. var count = 0, results = [], resolve, reject;
  1964. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1965. resolve = resolve_;
  1966. reject = reject_;
  1967. });
  1968. iterable.forEach(function (p, i) {
  1969. count++;
  1970. p.then(function (result) {
  1971. results[i] = result;
  1972. count--;
  1973. if (count === 0) {
  1974. resolve(results);
  1975. }
  1976. }, reject);
  1977. });
  1978. if (count === 0) {
  1979. resolve(results);
  1980. }
  1981. return promise;
  1982. };
  1983. }
  1984. if (typeof globalScope.Promise.resolve !== 'function') {
  1985. globalScope.Promise.resolve = function (value) {
  1986. return new globalScope.Promise(function (resolve) { resolve(value); });
  1987. };
  1988. }
  1989. if (typeof globalScope.Promise.reject !== 'function') {
  1990. globalScope.Promise.reject = function (reason) {
  1991. return new globalScope.Promise(function (resolve, reject) {
  1992. reject(reason);
  1993. });
  1994. };
  1995. }
  1996. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1997. globalScope.Promise.prototype.catch = function (onReject) {
  1998. return globalScope.Promise.prototype.then(undefined, onReject);
  1999. };
  2000. }
  2001. return;
  2002. }
  2003. var STATUS_PENDING = 0;
  2004. var STATUS_RESOLVED = 1;
  2005. var STATUS_REJECTED = 2;
  2006. // In an attempt to avoid silent exceptions, unhandled rejections are
  2007. // tracked and if they aren't handled in a certain amount of time an
  2008. // error is logged.
  2009. var REJECTION_TIMEOUT = 500;
  2010. var HandlerManager = {
  2011. handlers: [],
  2012. running: false,
  2013. unhandledRejections: [],
  2014. pendingRejectionCheck: false,
  2015. scheduleHandlers: function scheduleHandlers(promise) {
  2016. if (promise._status === STATUS_PENDING) {
  2017. return;
  2018. }
  2019. this.handlers = this.handlers.concat(promise._handlers);
  2020. promise._handlers = [];
  2021. if (this.running) {
  2022. return;
  2023. }
  2024. this.running = true;
  2025. setTimeout(this.runHandlers.bind(this), 0);
  2026. },
  2027. runHandlers: function runHandlers() {
  2028. var RUN_TIMEOUT = 1; // ms
  2029. var timeoutAt = Date.now() + RUN_TIMEOUT;
  2030. while (this.handlers.length > 0) {
  2031. var handler = this.handlers.shift();
  2032. var nextStatus = handler.thisPromise._status;
  2033. var nextValue = handler.thisPromise._value;
  2034. try {
  2035. if (nextStatus === STATUS_RESOLVED) {
  2036. if (typeof handler.onResolve === 'function') {
  2037. nextValue = handler.onResolve(nextValue);
  2038. }
  2039. } else if (typeof handler.onReject === 'function') {
  2040. nextValue = handler.onReject(nextValue);
  2041. nextStatus = STATUS_RESOLVED;
  2042. if (handler.thisPromise._unhandledRejection) {
  2043. this.removeUnhandeledRejection(handler.thisPromise);
  2044. }
  2045. }
  2046. } catch (ex) {
  2047. nextStatus = STATUS_REJECTED;
  2048. nextValue = ex;
  2049. }
  2050. handler.nextPromise._updateStatus(nextStatus, nextValue);
  2051. if (Date.now() >= timeoutAt) {
  2052. break;
  2053. }
  2054. }
  2055. if (this.handlers.length > 0) {
  2056. setTimeout(this.runHandlers.bind(this), 0);
  2057. return;
  2058. }
  2059. this.running = false;
  2060. },
  2061. addUnhandledRejection: function addUnhandledRejection(promise) {
  2062. this.unhandledRejections.push({
  2063. promise: promise,
  2064. time: Date.now()
  2065. });
  2066. this.scheduleRejectionCheck();
  2067. },
  2068. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  2069. promise._unhandledRejection = false;
  2070. for (var i = 0; i < this.unhandledRejections.length; i++) {
  2071. if (this.unhandledRejections[i].promise === promise) {
  2072. this.unhandledRejections.splice(i);
  2073. i--;
  2074. }
  2075. }
  2076. },
  2077. scheduleRejectionCheck: function scheduleRejectionCheck() {
  2078. if (this.pendingRejectionCheck) {
  2079. return;
  2080. }
  2081. this.pendingRejectionCheck = true;
  2082. setTimeout(function rejectionCheck() {
  2083. this.pendingRejectionCheck = false;
  2084. var now = Date.now();
  2085. for (var i = 0; i < this.unhandledRejections.length; i++) {
  2086. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  2087. var unhandled = this.unhandledRejections[i].promise._value;
  2088. var msg = 'Unhandled rejection: ' + unhandled;
  2089. if (unhandled.stack) {
  2090. msg += '\n' + unhandled.stack;
  2091. }
  2092. warn(msg);
  2093. this.unhandledRejections.splice(i);
  2094. i--;
  2095. }
  2096. }
  2097. if (this.unhandledRejections.length) {
  2098. this.scheduleRejectionCheck();
  2099. }
  2100. }.bind(this), REJECTION_TIMEOUT);
  2101. }
  2102. };
  2103. function Promise(resolver) {
  2104. this._status = STATUS_PENDING;
  2105. this._handlers = [];
  2106. try {
  2107. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  2108. } catch (e) {
  2109. this._reject(e);
  2110. }
  2111. }
  2112. /**
  2113. * Builds a promise that is resolved when all the passed in promises are
  2114. * resolved.
  2115. * @param {array} promises array of data and/or promises to wait for.
  2116. * @return {Promise} New dependent promise.
  2117. */
  2118. Promise.all = function Promise_all(promises) {
  2119. var resolveAll, rejectAll;
  2120. var deferred = new Promise(function (resolve, reject) {
  2121. resolveAll = resolve;
  2122. rejectAll = reject;
  2123. });
  2124. var unresolved = promises.length;
  2125. var results = [];
  2126. if (unresolved === 0) {
  2127. resolveAll(results);
  2128. return deferred;
  2129. }
  2130. function reject(reason) {
  2131. if (deferred._status === STATUS_REJECTED) {
  2132. return;
  2133. }
  2134. results = [];
  2135. rejectAll(reason);
  2136. }
  2137. for (var i = 0, ii = promises.length; i < ii; ++i) {
  2138. var promise = promises[i];
  2139. var resolve = (function(i) {
  2140. return function(value) {
  2141. if (deferred._status === STATUS_REJECTED) {
  2142. return;
  2143. }
  2144. results[i] = value;
  2145. unresolved--;
  2146. if (unresolved === 0) {
  2147. resolveAll(results);
  2148. }
  2149. };
  2150. })(i);
  2151. if (Promise.isPromise(promise)) {
  2152. promise.then(resolve, reject);
  2153. } else {
  2154. resolve(promise);
  2155. }
  2156. }
  2157. return deferred;
  2158. };
  2159. /**
  2160. * Checks if the value is likely a promise (has a 'then' function).
  2161. * @return {boolean} true if value is thenable
  2162. */
  2163. Promise.isPromise = function Promise_isPromise(value) {
  2164. return value && typeof value.then === 'function';
  2165. };
  2166. /**
  2167. * Creates resolved promise
  2168. * @param value resolve value
  2169. * @returns {Promise}
  2170. */
  2171. Promise.resolve = function Promise_resolve(value) {
  2172. return new Promise(function (resolve) { resolve(value); });
  2173. };
  2174. /**
  2175. * Creates rejected promise
  2176. * @param reason rejection value
  2177. * @returns {Promise}
  2178. */
  2179. Promise.reject = function Promise_reject(reason) {
  2180. return new Promise(function (resolve, reject) { reject(reason); });
  2181. };
  2182. Promise.prototype = {
  2183. _status: null,
  2184. _value: null,
  2185. _handlers: null,
  2186. _unhandledRejection: null,
  2187. _updateStatus: function Promise__updateStatus(status, value) {
  2188. if (this._status === STATUS_RESOLVED ||
  2189. this._status === STATUS_REJECTED) {
  2190. return;
  2191. }
  2192. if (status === STATUS_RESOLVED &&
  2193. Promise.isPromise(value)) {
  2194. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  2195. this._updateStatus.bind(this, STATUS_REJECTED));
  2196. return;
  2197. }
  2198. this._status = status;
  2199. this._value = value;
  2200. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  2201. this._unhandledRejection = true;
  2202. HandlerManager.addUnhandledRejection(this);
  2203. }
  2204. HandlerManager.scheduleHandlers(this);
  2205. },
  2206. _resolve: function Promise_resolve(value) {
  2207. this._updateStatus(STATUS_RESOLVED, value);
  2208. },
  2209. _reject: function Promise_reject(reason) {
  2210. this._updateStatus(STATUS_REJECTED, reason);
  2211. },
  2212. then: function Promise_then(onResolve, onReject) {
  2213. var nextPromise = new Promise(function (resolve, reject) {
  2214. this.resolve = resolve;
  2215. this.reject = reject;
  2216. });
  2217. this._handlers.push({
  2218. thisPromise: this,
  2219. onResolve: onResolve,
  2220. onReject: onReject,
  2221. nextPromise: nextPromise
  2222. });
  2223. HandlerManager.scheduleHandlers(this);
  2224. return nextPromise;
  2225. },
  2226. catch: function Promise_catch(onReject) {
  2227. return this.then(undefined, onReject);
  2228. }
  2229. };
  2230. globalScope.Promise = Promise;
  2231. })();
  2232. (function WeakMapClosure() {
  2233. if (globalScope.WeakMap) {
  2234. return;
  2235. }
  2236. var id = 0;
  2237. function WeakMap() {
  2238. this.id = '$weakmap' + (id++);
  2239. }
  2240. WeakMap.prototype = {
  2241. has: function(obj) {
  2242. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  2243. },
  2244. get: function(obj, defaultValue) {
  2245. return this.has(obj) ? obj[this.id] : defaultValue;
  2246. },
  2247. set: function(obj, value) {
  2248. Object.defineProperty(obj, this.id, {
  2249. value: value,
  2250. enumerable: false,
  2251. configurable: true
  2252. });
  2253. },
  2254. delete: function(obj) {
  2255. delete obj[this.id];
  2256. }
  2257. };
  2258. globalScope.WeakMap = WeakMap;
  2259. })();
  2260. var StatTimer = (function StatTimerClosure() {
  2261. function rpad(str, pad, length) {
  2262. while (str.length < length) {
  2263. str += pad;
  2264. }
  2265. return str;
  2266. }
  2267. function StatTimer() {
  2268. this.started = Object.create(null);
  2269. this.times = [];
  2270. this.enabled = true;
  2271. }
  2272. StatTimer.prototype = {
  2273. time: function StatTimer_time(name) {
  2274. if (!this.enabled) {
  2275. return;
  2276. }
  2277. if (name in this.started) {
  2278. warn('Timer is already running for ' + name);
  2279. }
  2280. this.started[name] = Date.now();
  2281. },
  2282. timeEnd: function StatTimer_timeEnd(name) {
  2283. if (!this.enabled) {
  2284. return;
  2285. }
  2286. if (!(name in this.started)) {
  2287. warn('Timer has not been started for ' + name);
  2288. }
  2289. this.times.push({
  2290. 'name': name,
  2291. 'start': this.started[name],
  2292. 'end': Date.now()
  2293. });
  2294. // Remove timer from started so it can be called again.
  2295. delete this.started[name];
  2296. },
  2297. toString: function StatTimer_toString() {
  2298. var i, ii;
  2299. var times = this.times;
  2300. var out = '';
  2301. // Find the longest name for padding purposes.
  2302. var longest = 0;
  2303. for (i = 0, ii = times.length; i < ii; ++i) {
  2304. var name = times[i]['name'];
  2305. if (name.length > longest) {
  2306. longest = name.length;
  2307. }
  2308. }
  2309. for (i = 0, ii = times.length; i < ii; ++i) {
  2310. var span = times[i];
  2311. var duration = span.end - span.start;
  2312. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  2313. }
  2314. return out;
  2315. }
  2316. };
  2317. return StatTimer;
  2318. })();
  2319. var createBlob = function createBlob(data, contentType) {
  2320. if (typeof Blob !== 'undefined') {
  2321. return new Blob([data], { type: contentType });
  2322. }
  2323. warn('The "Blob" constructor is not supported.');
  2324. };
  2325. var createObjectURL = (function createObjectURLClosure() {
  2326. // Blob/createObjectURL is not available, falling back to data schema.
  2327. var digits =
  2328. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  2329. return function createObjectURL(data, contentType, forceDataSchema) {
  2330. if (!forceDataSchema &&
  2331. typeof URL !== 'undefined' && URL.createObjectURL) {
  2332. var blob = createBlob(data, contentType);
  2333. return URL.createObjectURL(blob);
  2334. }
  2335. var buffer = 'data:' + contentType + ';base64,';
  2336. for (var i = 0, ii = data.length; i < ii; i += 3) {
  2337. var b1 = data[i] & 0xFF;
  2338. var b2 = data[i + 1] & 0xFF;
  2339. var b3 = data[i + 2] & 0xFF;
  2340. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  2341. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  2342. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  2343. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  2344. }
  2345. return buffer;
  2346. };
  2347. })();
  2348. function MessageHandler(sourceName, targetName, comObj) {
  2349. this.sourceName = sourceName;
  2350. this.targetName = targetName;
  2351. this.comObj = comObj;
  2352. this.callbackIndex = 1;
  2353. this.postMessageTransfers = true;
  2354. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  2355. var ah = this.actionHandler = Object.create(null);
  2356. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  2357. var data = event.data;
  2358. if (data.targetName !== this.sourceName) {
  2359. return;
  2360. }
  2361. if (data.isReply) {
  2362. var callbackId = data.callbackId;
  2363. if (data.callbackId in callbacksCapabilities) {
  2364. var callback = callbacksCapabilities[callbackId];
  2365. delete callbacksCapabilities[callbackId];
  2366. if ('error' in data) {
  2367. callback.reject(data.error);
  2368. } else {
  2369. callback.resolve(data.data);
  2370. }
  2371. } else {
  2372. error('Cannot resolve callback ' + callbackId);
  2373. }
  2374. } else if (data.action in ah) {
  2375. var action = ah[data.action];
  2376. if (data.callbackId) {
  2377. var sourceName = this.sourceName;
  2378. var targetName = data.sourceName;
  2379. Promise.resolve().then(function () {
  2380. return action[0].call(action[1], data.data);
  2381. }).then(function (result) {
  2382. comObj.postMessage({
  2383. sourceName: sourceName,
  2384. targetName: targetName,
  2385. isReply: true,
  2386. callbackId: data.callbackId,
  2387. data: result
  2388. });
  2389. }, function (reason) {
  2390. if (reason instanceof Error) {
  2391. // Serialize error to avoid "DataCloneError"
  2392. reason = reason + '';
  2393. }
  2394. comObj.postMessage({
  2395. sourceName: sourceName,
  2396. targetName: targetName,
  2397. isReply: true,
  2398. callbackId: data.callbackId,
  2399. error: reason
  2400. });
  2401. });
  2402. } else {
  2403. action[0].call(action[1], data.data);
  2404. }
  2405. } else {
  2406. error('Unknown action from worker: ' + data.action);
  2407. }
  2408. }.bind(this);
  2409. comObj.addEventListener('message', this._onComObjOnMessage);
  2410. }
  2411. MessageHandler.prototype = {
  2412. on: function messageHandlerOn(actionName, handler, scope) {
  2413. var ah = this.actionHandler;
  2414. if (ah[actionName]) {
  2415. error('There is already an actionName called "' + actionName + '"');
  2416. }
  2417. ah[actionName] = [handler, scope];
  2418. },
  2419. /**
  2420. * Sends a message to the comObj to invoke the action with the supplied data.
  2421. * @param {String} actionName Action to call.
  2422. * @param {JSON} data JSON data to send.
  2423. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  2424. */
  2425. send: function messageHandlerSend(actionName, data, transfers) {
  2426. var message = {
  2427. sourceName: this.sourceName,
  2428. targetName: this.targetName,
  2429. action: actionName,
  2430. data: data
  2431. };
  2432. this.postMessage(message, transfers);
  2433. },
  2434. /**
  2435. * Sends a message to the comObj to invoke the action with the supplied data.
  2436. * Expects that other side will callback with the response.
  2437. * @param {String} actionName Action to call.
  2438. * @param {JSON} data JSON data to send.
  2439. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  2440. * @returns {Promise} Promise to be resolved with response data.
  2441. */
  2442. sendWithPromise:
  2443. function messageHandlerSendWithPromise(actionName, data, transfers) {
  2444. var callbackId = this.callbackIndex++;
  2445. var message = {
  2446. sourceName: this.sourceName,
  2447. targetName: this.targetName,
  2448. action: actionName,
  2449. data: data,
  2450. callbackId: callbackId
  2451. };
  2452. var capability = createPromiseCapability();
  2453. this.callbacksCapabilities[callbackId] = capability;
  2454. try {
  2455. this.postMessage(message, transfers);
  2456. } catch (e) {
  2457. capability.reject(e);
  2458. }
  2459. return capability.promise;
  2460. },
  2461. /**
  2462. * Sends raw message to the comObj.
  2463. * @private
  2464. * @param message {Object} Raw message.
  2465. * @param transfers List of transfers/ArrayBuffers, or undefined.
  2466. */
  2467. postMessage: function (message, transfers) {
  2468. if (transfers && this.postMessageTransfers) {
  2469. this.comObj.postMessage(message, transfers);
  2470. } else {
  2471. this.comObj.postMessage(message);
  2472. }
  2473. },
  2474. destroy: function () {
  2475. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  2476. }
  2477. };
  2478. function loadJpegStream(id, imageUrl, objs) {
  2479. var img = new Image();
  2480. img.onload = (function loadJpegStream_onloadClosure() {
  2481. objs.resolve(id, img);
  2482. });
  2483. img.onerror = (function loadJpegStream_onerrorClosure() {
  2484. objs.resolve(id, null);
  2485. warn('Error during JPEG image loading');
  2486. });
  2487. img.src = imageUrl;
  2488. }
  2489. // Polyfill from https://github.com/Polymer/URL
  2490. /* Any copyright is dedicated to the Public Domain.
  2491. * http://creativecommons.org/publicdomain/zero/1.0/ */
  2492. (function checkURLConstructor(scope) {
  2493. // feature detect for URL constructor
  2494. var hasWorkingUrl = false;
  2495. try {
  2496. if (typeof URL === 'function' &&
  2497. typeof URL.prototype === 'object' &&
  2498. ('origin' in URL.prototype)) {
  2499. var u = new URL('b', 'http://a');
  2500. u.pathname = 'c%20d';
  2501. hasWorkingUrl = u.href === 'http://a/c%20d';
  2502. }
  2503. } catch(e) { }
  2504. if (hasWorkingUrl) {
  2505. return;
  2506. }
  2507. var relative = Object.create(null);
  2508. relative['ftp'] = 21;
  2509. relative['file'] = 0;
  2510. relative['gopher'] = 70;
  2511. relative['http'] = 80;
  2512. relative['https'] = 443;
  2513. relative['ws'] = 80;
  2514. relative['wss'] = 443;
  2515. var relativePathDotMapping = Object.create(null);
  2516. relativePathDotMapping['%2e'] = '.';
  2517. relativePathDotMapping['.%2e'] = '..';
  2518. relativePathDotMapping['%2e.'] = '..';
  2519. relativePathDotMapping['%2e%2e'] = '..';
  2520. function isRelativeScheme(scheme) {
  2521. return relative[scheme] !== undefined;
  2522. }
  2523. function invalid() {
  2524. clear.call(this);
  2525. this._isInvalid = true;
  2526. }
  2527. function IDNAToASCII(h) {
  2528. if ('' === h) {
  2529. invalid.call(this);
  2530. }
  2531. // XXX
  2532. return h.toLowerCase();
  2533. }
  2534. function percentEscape(c) {
  2535. var unicode = c.charCodeAt(0);
  2536. if (unicode > 0x20 &&
  2537. unicode < 0x7F &&
  2538. // " # < > ? `
  2539. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1
  2540. ) {
  2541. return c;
  2542. }
  2543. return encodeURIComponent(c);
  2544. }
  2545. function percentEscapeQuery(c) {
  2546. // XXX This actually needs to encode c using encoding and then
  2547. // convert the bytes one-by-one.
  2548. var unicode = c.charCodeAt(0);
  2549. if (unicode > 0x20 &&
  2550. unicode < 0x7F &&
  2551. // " # < > ` (do not escape '?')
  2552. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1
  2553. ) {
  2554. return c;
  2555. }
  2556. return encodeURIComponent(c);
  2557. }
  2558. var EOF, ALPHA = /[a-zA-Z]/,
  2559. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  2560. function parse(input, stateOverride, base) {
  2561. function err(message) {
  2562. errors.push(message);
  2563. }
  2564. var state = stateOverride || 'scheme start',
  2565. cursor = 0,
  2566. buffer = '',
  2567. seenAt = false,
  2568. seenBracket = false,
  2569. errors = [];
  2570. loop: while ((input[cursor - 1] !== EOF || cursor === 0) &&
  2571. !this._isInvalid) {
  2572. var c = input[cursor];
  2573. switch (state) {
  2574. case 'scheme start':
  2575. if (c && ALPHA.test(c)) {
  2576. buffer += c.toLowerCase(); // ASCII-safe
  2577. state = 'scheme';
  2578. } else if (!stateOverride) {
  2579. buffer = '';
  2580. state = 'no scheme';
  2581. continue;
  2582. } else {
  2583. err('Invalid scheme.');
  2584. break loop;
  2585. }
  2586. break;
  2587. case 'scheme':
  2588. if (c && ALPHANUMERIC.test(c)) {
  2589. buffer += c.toLowerCase(); // ASCII-safe
  2590. } else if (':' === c) {
  2591. this._scheme = buffer;
  2592. buffer = '';
  2593. if (stateOverride) {
  2594. break loop;
  2595. }
  2596. if (isRelativeScheme(this._scheme)) {
  2597. this._isRelative = true;
  2598. }
  2599. if ('file' === this._scheme) {
  2600. state = 'relative';
  2601. } else if (this._isRelative && base &&
  2602. base._scheme === this._scheme) {
  2603. state = 'relative or authority';
  2604. } else if (this._isRelative) {
  2605. state = 'authority first slash';
  2606. } else {
  2607. state = 'scheme data';
  2608. }
  2609. } else if (!stateOverride) {
  2610. buffer = '';
  2611. cursor = 0;
  2612. state = 'no scheme';
  2613. continue;
  2614. } else if (EOF === c) {
  2615. break loop;
  2616. } else {
  2617. err('Code point not allowed in scheme: ' + c);
  2618. break loop;
  2619. }
  2620. break;
  2621. case 'scheme data':
  2622. if ('?' === c) {
  2623. this._query = '?';
  2624. state = 'query';
  2625. } else if ('#' === c) {
  2626. this._fragment = '#';
  2627. state = 'fragment';
  2628. } else {
  2629. // XXX error handling
  2630. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2631. this._schemeData += percentEscape(c);
  2632. }
  2633. }
  2634. break;
  2635. case 'no scheme':
  2636. if (!base || !(isRelativeScheme(base._scheme))) {
  2637. err('Missing scheme.');
  2638. invalid.call(this);
  2639. } else {
  2640. state = 'relative';
  2641. continue;
  2642. }
  2643. break;
  2644. case 'relative or authority':
  2645. if ('/' === c && '/' === input[cursor+1]) {
  2646. state = 'authority ignore slashes';
  2647. } else {
  2648. err('Expected /, got: ' + c);
  2649. state = 'relative';
  2650. continue;
  2651. }
  2652. break;
  2653. case 'relative':
  2654. this._isRelative = true;
  2655. if ('file' !== this._scheme) {
  2656. this._scheme = base._scheme;
  2657. }
  2658. if (EOF === c) {
  2659. this._host = base._host;
  2660. this._port = base._port;
  2661. this._path = base._path.slice();
  2662. this._query = base._query;
  2663. this._username = base._username;
  2664. this._password = base._password;
  2665. break loop;
  2666. } else if ('/' === c || '\\' === c) {
  2667. if ('\\' === c) {
  2668. err('\\ is an invalid code point.');
  2669. }
  2670. state = 'relative slash';
  2671. } else if ('?' === c) {
  2672. this._host = base._host;
  2673. this._port = base._port;
  2674. this._path = base._path.slice();
  2675. this._query = '?';
  2676. this._username = base._username;
  2677. this._password = base._password;
  2678. state = 'query';
  2679. } else if ('#' === c) {
  2680. this._host = base._host;
  2681. this._port = base._port;
  2682. this._path = base._path.slice();
  2683. this._query = base._query;
  2684. this._fragment = '#';
  2685. this._username = base._username;
  2686. this._password = base._password;
  2687. state = 'fragment';
  2688. } else {
  2689. var nextC = input[cursor+1];
  2690. var nextNextC = input[cursor+2];
  2691. if ('file' !== this._scheme || !ALPHA.test(c) ||
  2692. (nextC !== ':' && nextC !== '|') ||
  2693. (EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC &&
  2694. '?' !== nextNextC && '#' !== nextNextC)) {
  2695. this._host = base._host;
  2696. this._port = base._port;
  2697. this._username = base._username;
  2698. this._password = base._password;
  2699. this._path = base._path.slice();
  2700. this._path.pop();
  2701. }
  2702. state = 'relative path';
  2703. continue;
  2704. }
  2705. break;
  2706. case 'relative slash':
  2707. if ('/' === c || '\\' === c) {
  2708. if ('\\' === c) {
  2709. err('\\ is an invalid code point.');
  2710. }
  2711. if ('file' === this._scheme) {
  2712. state = 'file host';
  2713. } else {
  2714. state = 'authority ignore slashes';
  2715. }
  2716. } else {
  2717. if ('file' !== this._scheme) {
  2718. this._host = base._host;
  2719. this._port = base._port;
  2720. this._username = base._username;
  2721. this._password = base._password;
  2722. }
  2723. state = 'relative path';
  2724. continue;
  2725. }
  2726. break;
  2727. case 'authority first slash':
  2728. if ('/' === c) {
  2729. state = 'authority second slash';
  2730. } else {
  2731. err('Expected \'/\', got: ' + c);
  2732. state = 'authority ignore slashes';
  2733. continue;
  2734. }
  2735. break;
  2736. case 'authority second slash':
  2737. state = 'authority ignore slashes';
  2738. if ('/' !== c) {
  2739. err('Expected \'/\', got: ' + c);
  2740. continue;
  2741. }
  2742. break;
  2743. case 'authority ignore slashes':
  2744. if ('/' !== c && '\\' !== c) {
  2745. state = 'authority';
  2746. continue;
  2747. } else {
  2748. err('Expected authority, got: ' + c);
  2749. }
  2750. break;
  2751. case 'authority':
  2752. if ('@' === c) {
  2753. if (seenAt) {
  2754. err('@ already seen.');
  2755. buffer += '%40';
  2756. }
  2757. seenAt = true;
  2758. for (var i = 0; i < buffer.length; i++) {
  2759. var cp = buffer[i];
  2760. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  2761. err('Invalid whitespace in authority.');
  2762. continue;
  2763. }
  2764. // XXX check URL code points
  2765. if (':' === cp && null === this._password) {
  2766. this._password = '';
  2767. continue;
  2768. }
  2769. var tempC = percentEscape(cp);
  2770. if (null !== this._password) {
  2771. this._password += tempC;
  2772. } else {
  2773. this._username += tempC;
  2774. }
  2775. }
  2776. buffer = '';
  2777. } else if (EOF === c || '/' === c || '\\' === c ||
  2778. '?' === c || '#' === c) {
  2779. cursor -= buffer.length;
  2780. buffer = '';
  2781. state = 'host';
  2782. continue;
  2783. } else {
  2784. buffer += c;
  2785. }
  2786. break;
  2787. case 'file host':
  2788. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  2789. if (buffer.length === 2 && ALPHA.test(buffer[0]) &&
  2790. (buffer[1] === ':' || buffer[1] === '|')) {
  2791. state = 'relative path';
  2792. } else if (buffer.length === 0) {
  2793. state = 'relative path start';
  2794. } else {
  2795. this._host = IDNAToASCII.call(this, buffer);
  2796. buffer = '';
  2797. state = 'relative path start';
  2798. }
  2799. continue;
  2800. } else if ('\t' === c || '\n' === c || '\r' === c) {
  2801. err('Invalid whitespace in file host.');
  2802. } else {
  2803. buffer += c;
  2804. }
  2805. break;
  2806. case 'host':
  2807. case 'hostname':
  2808. if (':' === c && !seenBracket) {
  2809. // XXX host parsing
  2810. this._host = IDNAToASCII.call(this, buffer);
  2811. buffer = '';
  2812. state = 'port';
  2813. if ('hostname' === stateOverride) {
  2814. break loop;
  2815. }
  2816. } else if (EOF === c || '/' === c ||
  2817. '\\' === c || '?' === c || '#' === c) {
  2818. this._host = IDNAToASCII.call(this, buffer);
  2819. buffer = '';
  2820. state = 'relative path start';
  2821. if (stateOverride) {
  2822. break loop;
  2823. }
  2824. continue;
  2825. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  2826. if ('[' === c) {
  2827. seenBracket = true;
  2828. } else if (']' === c) {
  2829. seenBracket = false;
  2830. }
  2831. buffer += c;
  2832. } else {
  2833. err('Invalid code point in host/hostname: ' + c);
  2834. }
  2835. break;
  2836. case 'port':
  2837. if (/[0-9]/.test(c)) {
  2838. buffer += c;
  2839. } else if (EOF === c || '/' === c || '\\' === c ||
  2840. '?' === c || '#' === c || stateOverride) {
  2841. if ('' !== buffer) {
  2842. var temp = parseInt(buffer, 10);
  2843. if (temp !== relative[this._scheme]) {
  2844. this._port = temp + '';
  2845. }
  2846. buffer = '';
  2847. }
  2848. if (stateOverride) {
  2849. break loop;
  2850. }
  2851. state = 'relative path start';
  2852. continue;
  2853. } else if ('\t' === c || '\n' === c || '\r' === c) {
  2854. err('Invalid code point in port: ' + c);
  2855. } else {
  2856. invalid.call(this);
  2857. }
  2858. break;
  2859. case 'relative path start':
  2860. if ('\\' === c) {
  2861. err('\'\\\' not allowed in path.');
  2862. }
  2863. state = 'relative path';
  2864. if ('/' !== c && '\\' !== c) {
  2865. continue;
  2866. }
  2867. break;
  2868. case 'relative path':
  2869. if (EOF === c || '/' === c || '\\' === c ||
  2870. (!stateOverride && ('?' === c || '#' === c))) {
  2871. if ('\\' === c) {
  2872. err('\\ not allowed in relative path.');
  2873. }
  2874. var tmp;
  2875. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  2876. buffer = tmp;
  2877. }
  2878. if ('..' === buffer) {
  2879. this._path.pop();
  2880. if ('/' !== c && '\\' !== c) {
  2881. this._path.push('');
  2882. }
  2883. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  2884. this._path.push('');
  2885. } else if ('.' !== buffer) {
  2886. if ('file' === this._scheme && this._path.length === 0 &&
  2887. buffer.length === 2 && ALPHA.test(buffer[0]) &&
  2888. buffer[1] === '|') {
  2889. buffer = buffer[0] + ':';
  2890. }
  2891. this._path.push(buffer);
  2892. }
  2893. buffer = '';
  2894. if ('?' === c) {
  2895. this._query = '?';
  2896. state = 'query';
  2897. } else if ('#' === c) {
  2898. this._fragment = '#';
  2899. state = 'fragment';
  2900. }
  2901. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  2902. buffer += percentEscape(c);
  2903. }
  2904. break;
  2905. case 'query':
  2906. if (!stateOverride && '#' === c) {
  2907. this._fragment = '#';
  2908. state = 'fragment';
  2909. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2910. this._query += percentEscapeQuery(c);
  2911. }
  2912. break;
  2913. case 'fragment':
  2914. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2915. this._fragment += c;
  2916. }
  2917. break;
  2918. }
  2919. cursor++;
  2920. }
  2921. }
  2922. function clear() {
  2923. this._scheme = '';
  2924. this._schemeData = '';
  2925. this._username = '';
  2926. this._password = null;
  2927. this._host = '';
  2928. this._port = '';
  2929. this._path = [];
  2930. this._query = '';
  2931. this._fragment = '';
  2932. this._isInvalid = false;
  2933. this._isRelative = false;
  2934. }
  2935. // Does not process domain names or IP addresses.
  2936. // Does not handle encoding for the query parameter.
  2937. function JURL(url, base /* , encoding */) {
  2938. if (base !== undefined && !(base instanceof JURL)) {
  2939. base = new JURL(String(base));
  2940. }
  2941. this._url = url;
  2942. clear.call(this);
  2943. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  2944. // encoding = encoding || 'utf-8'
  2945. parse.call(this, input, null, base);
  2946. }
  2947. JURL.prototype = {
  2948. toString: function() {
  2949. return this.href;
  2950. },
  2951. get href() {
  2952. if (this._isInvalid) {
  2953. return this._url;
  2954. }
  2955. var authority = '';
  2956. if ('' !== this._username || null !== this._password) {
  2957. authority = this._username +
  2958. (null !== this._password ? ':' + this._password : '') + '@';
  2959. }
  2960. return this.protocol +
  2961. (this._isRelative ? '//' + authority + this.host : '') +
  2962. this.pathname + this._query + this._fragment;
  2963. },
  2964. set href(href) {
  2965. clear.call(this);
  2966. parse.call(this, href);
  2967. },
  2968. get protocol() {
  2969. return this._scheme + ':';
  2970. },
  2971. set protocol(protocol) {
  2972. if (this._isInvalid) {
  2973. return;
  2974. }
  2975. parse.call(this, protocol + ':', 'scheme start');
  2976. },
  2977. get host() {
  2978. return this._isInvalid ? '' : this._port ?
  2979. this._host + ':' + this._port : this._host;
  2980. },
  2981. set host(host) {
  2982. if (this._isInvalid || !this._isRelative) {
  2983. return;
  2984. }
  2985. parse.call(this, host, 'host');
  2986. },
  2987. get hostname() {
  2988. return this._host;
  2989. },
  2990. set hostname(hostname) {
  2991. if (this._isInvalid || !this._isRelative) {
  2992. return;
  2993. }
  2994. parse.call(this, hostname, 'hostname');
  2995. },
  2996. get port() {
  2997. return this._port;
  2998. },
  2999. set port(port) {
  3000. if (this._isInvalid || !this._isRelative) {
  3001. return;
  3002. }
  3003. parse.call(this, port, 'port');
  3004. },
  3005. get pathname() {
  3006. return this._isInvalid ? '' : this._isRelative ?
  3007. '/' + this._path.join('/') : this._schemeData;
  3008. },
  3009. set pathname(pathname) {
  3010. if (this._isInvalid || !this._isRelative) {
  3011. return;
  3012. }
  3013. this._path = [];
  3014. parse.call(this, pathname, 'relative path start');
  3015. },
  3016. get search() {
  3017. return this._isInvalid || !this._query || '?' === this._query ?
  3018. '' : this._query;
  3019. },
  3020. set search(search) {
  3021. if (this._isInvalid || !this._isRelative) {
  3022. return;
  3023. }
  3024. this._query = '?';
  3025. if ('?' === search[0]) {
  3026. search = search.slice(1);
  3027. }
  3028. parse.call(this, search, 'query');
  3029. },
  3030. get hash() {
  3031. return this._isInvalid || !this._fragment || '#' === this._fragment ?
  3032. '' : this._fragment;
  3033. },
  3034. set hash(hash) {
  3035. if (this._isInvalid) {
  3036. return;
  3037. }
  3038. this._fragment = '#';
  3039. if ('#' === hash[0]) {
  3040. hash = hash.slice(1);
  3041. }
  3042. parse.call(this, hash, 'fragment');
  3043. },
  3044. get origin() {
  3045. var host;
  3046. if (this._isInvalid || !this._scheme) {
  3047. return '';
  3048. }
  3049. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  3050. // Gecko throws error for "data://"
  3051. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  3052. // Gecko returns String("") for file: mailto:
  3053. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  3054. switch (this._scheme) {
  3055. case 'data':
  3056. case 'file':
  3057. case 'javascript':
  3058. case 'mailto':
  3059. return 'null';
  3060. }
  3061. host = this.host;
  3062. if (!host) {
  3063. return '';
  3064. }
  3065. return this._scheme + '://' + host;
  3066. }
  3067. };
  3068. // Copy over the static methods
  3069. var OriginalURL = scope.URL;
  3070. if (OriginalURL) {
  3071. JURL.createObjectURL = function(blob) {
  3072. // IE extension allows a second optional options argument.
  3073. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  3074. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  3075. };
  3076. JURL.revokeObjectURL = function(url) {
  3077. OriginalURL.revokeObjectURL(url);
  3078. };
  3079. }
  3080. scope.URL = JURL;
  3081. })(globalScope);
  3082. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  3083. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  3084. exports.OPS = OPS;
  3085. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  3086. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  3087. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  3088. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  3089. exports.AnnotationFlag = AnnotationFlag;
  3090. exports.AnnotationType = AnnotationType;
  3091. exports.FontType = FontType;
  3092. exports.ImageKind = ImageKind;
  3093. exports.InvalidPDFException = InvalidPDFException;
  3094. exports.MessageHandler = MessageHandler;
  3095. exports.MissingDataException = MissingDataException;
  3096. exports.MissingPDFException = MissingPDFException;
  3097. exports.NotImplementedException = NotImplementedException;
  3098. exports.PageViewport = PageViewport;
  3099. exports.PasswordException = PasswordException;
  3100. exports.PasswordResponses = PasswordResponses;
  3101. exports.StatTimer = StatTimer;
  3102. exports.StreamType = StreamType;
  3103. exports.TextRenderingMode = TextRenderingMode;
  3104. exports.UnexpectedResponseException = UnexpectedResponseException;
  3105. exports.UnknownErrorException = UnknownErrorException;
  3106. exports.Util = Util;
  3107. exports.XRefParseException = XRefParseException;
  3108. exports.arrayByteLength = arrayByteLength;
  3109. exports.arraysToBytes = arraysToBytes;
  3110. exports.assert = assert;
  3111. exports.bytesToString = bytesToString;
  3112. exports.createBlob = createBlob;
  3113. exports.createPromiseCapability = createPromiseCapability;
  3114. exports.createObjectURL = createObjectURL;
  3115. exports.deprecated = deprecated;
  3116. exports.error = error;
  3117. exports.getLookupTableFactory = getLookupTableFactory;
  3118. exports.getVerbosityLevel = getVerbosityLevel;
  3119. exports.globalScope = globalScope;
  3120. exports.info = info;
  3121. exports.isArray = isArray;
  3122. exports.isArrayBuffer = isArrayBuffer;
  3123. exports.isBool = isBool;
  3124. exports.isEmptyObj = isEmptyObj;
  3125. exports.isInt = isInt;
  3126. exports.isNum = isNum;
  3127. exports.isString = isString;
  3128. exports.isSpace = isSpace;
  3129. exports.isSameOrigin = isSameOrigin;
  3130. exports.isValidUrl = isValidUrl;
  3131. exports.isLittleEndian = isLittleEndian;
  3132. exports.isEvalSupported = isEvalSupported;
  3133. exports.loadJpegStream = loadJpegStream;
  3134. exports.log2 = log2;
  3135. exports.readInt8 = readInt8;
  3136. exports.readUint16 = readUint16;
  3137. exports.readUint32 = readUint32;
  3138. exports.removeNullCharacters = removeNullCharacters;
  3139. exports.setVerbosityLevel = setVerbosityLevel;
  3140. exports.shadow = shadow;
  3141. exports.string32 = string32;
  3142. exports.stringToBytes = stringToBytes;
  3143. exports.stringToPDFString = stringToPDFString;
  3144. exports.stringToUTF8String = stringToUTF8String;
  3145. exports.utf8StringToString = utf8StringToString;
  3146. exports.warn = warn;
  3147. }));
  3148. (function (root, factory) {
  3149. {
  3150. factory((root.pdfjsCoreCFFParser = {}), root.pdfjsSharedUtil,
  3151. root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  3152. }
  3153. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  3154. var error = sharedUtil.error;
  3155. var info = sharedUtil.info;
  3156. var bytesToString = sharedUtil.bytesToString;
  3157. var warn = sharedUtil.warn;
  3158. var isArray = sharedUtil.isArray;
  3159. var Util = sharedUtil.Util;
  3160. var stringToBytes = sharedUtil.stringToBytes;
  3161. var assert = sharedUtil.assert;
  3162. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  3163. var ExpertCharset = coreCharsets.ExpertCharset;
  3164. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  3165. var StandardEncoding = coreEncodings.StandardEncoding;
  3166. var ExpertEncoding = coreEncodings.ExpertEncoding;
  3167. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  3168. var MAX_SUBR_NESTING = 10;
  3169. /**
  3170. * The CFF class takes a Type1 file and wrap it into a
  3171. * 'Compact Font Format' which itself embed Type2 charstrings.
  3172. */
  3173. var CFFStandardStrings = [
  3174. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  3175. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  3176. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  3177. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  3178. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  3179. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  3180. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  3181. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  3182. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  3183. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  3184. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  3185. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  3186. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  3187. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  3188. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  3189. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  3190. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  3191. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  3192. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  3193. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  3194. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  3195. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  3196. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  3197. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  3198. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  3199. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  3200. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  3201. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  3202. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  3203. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  3204. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  3205. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  3206. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  3207. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  3208. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  3209. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  3210. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  3211. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  3212. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  3213. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  3214. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  3215. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  3216. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  3217. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  3218. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  3219. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  3220. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  3221. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  3222. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  3223. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  3224. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  3225. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  3226. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  3227. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  3228. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  3229. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  3230. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  3231. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  3232. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  3233. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  3234. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  3235. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  3236. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  3237. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  3238. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  3239. ];
  3240. var CFFParser = (function CFFParserClosure() {
  3241. var CharstringValidationData = [
  3242. null,
  3243. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  3244. null,
  3245. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  3246. { id: 'vmoveto', min: 1, stackClearing: true },
  3247. { id: 'rlineto', min: 2, resetStack: true },
  3248. { id: 'hlineto', min: 1, resetStack: true },
  3249. { id: 'vlineto', min: 1, resetStack: true },
  3250. { id: 'rrcurveto', min: 6, resetStack: true },
  3251. null,
  3252. { id: 'callsubr', min: 1, undefStack: true },
  3253. { id: 'return', min: 0, undefStack: true },
  3254. null, // 12
  3255. null,
  3256. { id: 'endchar', min: 0, stackClearing: true },
  3257. null,
  3258. null,
  3259. null,
  3260. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  3261. { id: 'hintmask', min: 0, stackClearing: true },
  3262. { id: 'cntrmask', min: 0, stackClearing: true },
  3263. { id: 'rmoveto', min: 2, stackClearing: true },
  3264. { id: 'hmoveto', min: 1, stackClearing: true },
  3265. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  3266. { id: 'rcurveline', min: 8, resetStack: true },
  3267. { id: 'rlinecurve', min: 8, resetStack: true },
  3268. { id: 'vvcurveto', min: 4, resetStack: true },
  3269. { id: 'hhcurveto', min: 4, resetStack: true },
  3270. null, // shortint
  3271. { id: 'callgsubr', min: 1, undefStack: true },
  3272. { id: 'vhcurveto', min: 4, resetStack: true },
  3273. { id: 'hvcurveto', min: 4, resetStack: true }
  3274. ];
  3275. var CharstringValidationData12 = [
  3276. null,
  3277. null,
  3278. null,
  3279. { id: 'and', min: 2, stackDelta: -1 },
  3280. { id: 'or', min: 2, stackDelta: -1 },
  3281. { id: 'not', min: 1, stackDelta: 0 },
  3282. null,
  3283. null,
  3284. null,
  3285. { id: 'abs', min: 1, stackDelta: 0 },
  3286. { id: 'add', min: 2, stackDelta: -1,
  3287. stackFn: function stack_div(stack, index) {
  3288. stack[index - 2] = stack[index - 2] + stack[index - 1];
  3289. }
  3290. },
  3291. { id: 'sub', min: 2, stackDelta: -1,
  3292. stackFn: function stack_div(stack, index) {
  3293. stack[index - 2] = stack[index - 2] - stack[index - 1];
  3294. }
  3295. },
  3296. { id: 'div', min: 2, stackDelta: -1,
  3297. stackFn: function stack_div(stack, index) {
  3298. stack[index - 2] = stack[index - 2] / stack[index - 1];
  3299. }
  3300. },
  3301. null,
  3302. { id: 'neg', min: 1, stackDelta: 0,
  3303. stackFn: function stack_div(stack, index) {
  3304. stack[index - 1] = -stack[index - 1];
  3305. }
  3306. },
  3307. { id: 'eq', min: 2, stackDelta: -1 },
  3308. null,
  3309. null,
  3310. { id: 'drop', min: 1, stackDelta: -1 },
  3311. null,
  3312. { id: 'put', min: 2, stackDelta: -2 },
  3313. { id: 'get', min: 1, stackDelta: 0 },
  3314. { id: 'ifelse', min: 4, stackDelta: -3 },
  3315. { id: 'random', min: 0, stackDelta: 1 },
  3316. { id: 'mul', min: 2, stackDelta: -1,
  3317. stackFn: function stack_div(stack, index) {
  3318. stack[index - 2] = stack[index - 2] * stack[index - 1];
  3319. }
  3320. },
  3321. null,
  3322. { id: 'sqrt', min: 1, stackDelta: 0 },
  3323. { id: 'dup', min: 1, stackDelta: 1 },
  3324. { id: 'exch', min: 2, stackDelta: 0 },
  3325. { id: 'index', min: 2, stackDelta: 0 },
  3326. { id: 'roll', min: 3, stackDelta: -2 },
  3327. null,
  3328. null,
  3329. null,
  3330. { id: 'hflex', min: 7, resetStack: true },
  3331. { id: 'flex', min: 13, resetStack: true },
  3332. { id: 'hflex1', min: 9, resetStack: true },
  3333. { id: 'flex1', min: 11, resetStack: true }
  3334. ];
  3335. function CFFParser(file, properties, seacAnalysisEnabled) {
  3336. this.bytes = file.getBytes();
  3337. this.properties = properties;
  3338. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  3339. }
  3340. CFFParser.prototype = {
  3341. parse: function CFFParser_parse() {
  3342. var properties = this.properties;
  3343. var cff = new CFF();
  3344. this.cff = cff;
  3345. // The first five sections must be in order, all the others are reached
  3346. // via offsets contained in one of the below.
  3347. var header = this.parseHeader();
  3348. var nameIndex = this.parseIndex(header.endPos);
  3349. var topDictIndex = this.parseIndex(nameIndex.endPos);
  3350. var stringIndex = this.parseIndex(topDictIndex.endPos);
  3351. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  3352. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  3353. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  3354. cff.header = header.obj;
  3355. cff.names = this.parseNameIndex(nameIndex.obj);
  3356. cff.strings = this.parseStringIndex(stringIndex.obj);
  3357. cff.topDict = topDict;
  3358. cff.globalSubrIndex = globalSubrIndex.obj;
  3359. this.parsePrivateDict(cff.topDict);
  3360. cff.isCIDFont = topDict.hasName('ROS');
  3361. var charStringOffset = topDict.getByName('CharStrings');
  3362. var charStringIndex = this.parseIndex(charStringOffset).obj;
  3363. var fontMatrix = topDict.getByName('FontMatrix');
  3364. if (fontMatrix) {
  3365. properties.fontMatrix = fontMatrix;
  3366. }
  3367. var fontBBox = topDict.getByName('FontBBox');
  3368. if (fontBBox) {
  3369. // adjusting ascent/descent
  3370. properties.ascent = fontBBox[3];
  3371. properties.descent = fontBBox[1];
  3372. properties.ascentScaled = true;
  3373. }
  3374. var charset, encoding;
  3375. if (cff.isCIDFont) {
  3376. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  3377. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  3378. var dictRaw = fdArrayIndex.get(i);
  3379. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  3380. cff.strings);
  3381. this.parsePrivateDict(fontDict);
  3382. cff.fdArray.push(fontDict);
  3383. }
  3384. // cid fonts don't have an encoding
  3385. encoding = null;
  3386. charset = this.parseCharsets(topDict.getByName('charset'),
  3387. charStringIndex.count, cff.strings, true);
  3388. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  3389. charStringIndex.count);
  3390. } else {
  3391. charset = this.parseCharsets(topDict.getByName('charset'),
  3392. charStringIndex.count, cff.strings, false);
  3393. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  3394. properties,
  3395. cff.strings, charset.charset);
  3396. }
  3397. cff.charset = charset;
  3398. cff.encoding = encoding;
  3399. var charStringsAndSeacs = this.parseCharStrings(
  3400. charStringIndex,
  3401. topDict.privateDict.subrsIndex,
  3402. globalSubrIndex.obj,
  3403. cff.fdSelect,
  3404. cff.fdArray);
  3405. cff.charStrings = charStringsAndSeacs.charStrings;
  3406. cff.seacs = charStringsAndSeacs.seacs;
  3407. cff.widths = charStringsAndSeacs.widths;
  3408. return cff;
  3409. },
  3410. parseHeader: function CFFParser_parseHeader() {
  3411. var bytes = this.bytes;
  3412. var bytesLength = bytes.length;
  3413. var offset = 0;
  3414. // Prevent an infinite loop, by checking that the offset is within the
  3415. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  3416. while (offset < bytesLength && bytes[offset] !== 1) {
  3417. ++offset;
  3418. }
  3419. if (offset >= bytesLength) {
  3420. error('Invalid CFF header');
  3421. } else if (offset !== 0) {
  3422. info('cff data is shifted');
  3423. bytes = bytes.subarray(offset);
  3424. this.bytes = bytes;
  3425. }
  3426. var major = bytes[0];
  3427. var minor = bytes[1];
  3428. var hdrSize = bytes[2];
  3429. var offSize = bytes[3];
  3430. var header = new CFFHeader(major, minor, hdrSize, offSize);
  3431. return { obj: header, endPos: hdrSize };
  3432. },
  3433. parseDict: function CFFParser_parseDict(dict) {
  3434. var pos = 0;
  3435. function parseOperand() {
  3436. var value = dict[pos++];
  3437. if (value === 30) {
  3438. return parseFloatOperand();
  3439. } else if (value === 28) {
  3440. value = dict[pos++];
  3441. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  3442. return value;
  3443. } else if (value === 29) {
  3444. value = dict[pos++];
  3445. value = (value << 8) | dict[pos++];
  3446. value = (value << 8) | dict[pos++];
  3447. value = (value << 8) | dict[pos++];
  3448. return value;
  3449. } else if (value >= 32 && value <= 246) {
  3450. return value - 139;
  3451. } else if (value >= 247 && value <= 250) {
  3452. return ((value - 247) * 256) + dict[pos++] + 108;
  3453. } else if (value >= 251 && value <= 254) {
  3454. return -((value - 251) * 256) - dict[pos++] - 108;
  3455. } else {
  3456. error('255 is not a valid DICT command');
  3457. }
  3458. return -1;
  3459. }
  3460. function parseFloatOperand() {
  3461. var str = '';
  3462. var eof = 15;
  3463. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  3464. '9', '.', 'E', 'E-', null, '-'];
  3465. var length = dict.length;
  3466. while (pos < length) {
  3467. var b = dict[pos++];
  3468. var b1 = b >> 4;
  3469. var b2 = b & 15;
  3470. if (b1 === eof) {
  3471. break;
  3472. }
  3473. str += lookup[b1];
  3474. if (b2 === eof) {
  3475. break;
  3476. }
  3477. str += lookup[b2];
  3478. }
  3479. return parseFloat(str);
  3480. }
  3481. var operands = [];
  3482. var entries = [];
  3483. pos = 0;
  3484. var end = dict.length;
  3485. while (pos < end) {
  3486. var b = dict[pos];
  3487. if (b <= 21) {
  3488. if (b === 12) {
  3489. b = (b << 8) | dict[++pos];
  3490. }
  3491. entries.push([b, operands]);
  3492. operands = [];
  3493. ++pos;
  3494. } else {
  3495. operands.push(parseOperand());
  3496. }
  3497. }
  3498. return entries;
  3499. },
  3500. parseIndex: function CFFParser_parseIndex(pos) {
  3501. var cffIndex = new CFFIndex();
  3502. var bytes = this.bytes;
  3503. var count = (bytes[pos++] << 8) | bytes[pos++];
  3504. var offsets = [];
  3505. var end = pos;
  3506. var i, ii;
  3507. if (count !== 0) {
  3508. var offsetSize = bytes[pos++];
  3509. // add 1 for offset to determine size of last object
  3510. var startPos = pos + ((count + 1) * offsetSize) - 1;
  3511. for (i = 0, ii = count + 1; i < ii; ++i) {
  3512. var offset = 0;
  3513. for (var j = 0; j < offsetSize; ++j) {
  3514. offset <<= 8;
  3515. offset += bytes[pos++];
  3516. }
  3517. offsets.push(startPos + offset);
  3518. }
  3519. end = offsets[count];
  3520. }
  3521. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  3522. var offsetStart = offsets[i];
  3523. var offsetEnd = offsets[i + 1];
  3524. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  3525. }
  3526. return {obj: cffIndex, endPos: end};
  3527. },
  3528. parseNameIndex: function CFFParser_parseNameIndex(index) {
  3529. var names = [];
  3530. for (var i = 0, ii = index.count; i < ii; ++i) {
  3531. var name = index.get(i);
  3532. // OTS doesn't allow names to be over 127 characters.
  3533. var length = Math.min(name.length, 127);
  3534. var data = [];
  3535. // OTS also only permits certain characters in the name.
  3536. for (var j = 0; j < length; ++j) {
  3537. var c = name[j];
  3538. if (j === 0 && c === 0) {
  3539. data[j] = c;
  3540. continue;
  3541. }
  3542. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  3543. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  3544. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  3545. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  3546. data[j] = 95;
  3547. continue;
  3548. }
  3549. data[j] = c;
  3550. }
  3551. names.push(bytesToString(data));
  3552. }
  3553. return names;
  3554. },
  3555. parseStringIndex: function CFFParser_parseStringIndex(index) {
  3556. var strings = new CFFStrings();
  3557. for (var i = 0, ii = index.count; i < ii; ++i) {
  3558. var data = index.get(i);
  3559. strings.add(bytesToString(data));
  3560. }
  3561. return strings;
  3562. },
  3563. createDict: function CFFParser_createDict(Type, dict, strings) {
  3564. var cffDict = new Type(strings);
  3565. for (var i = 0, ii = dict.length; i < ii; ++i) {
  3566. var pair = dict[i];
  3567. var key = pair[0];
  3568. var value = pair[1];
  3569. cffDict.setByKey(key, value);
  3570. }
  3571. return cffDict;
  3572. },
  3573. parseCharString: function CFFParser_parseCharString(state, data,
  3574. localSubrIndex,
  3575. globalSubrIndex) {
  3576. if (state.callDepth > MAX_SUBR_NESTING) {
  3577. return false;
  3578. }
  3579. var stackSize = state.stackSize;
  3580. var stack = state.stack;
  3581. var length = data.length;
  3582. for (var j = 0; j < length;) {
  3583. var value = data[j++];
  3584. var validationCommand = null;
  3585. if (value === 12) {
  3586. var q = data[j++];
  3587. if (q === 0) {
  3588. // The CFF specification state that the 'dotsection' command
  3589. // (12, 0) is deprecated and treated as a no-op, but all Type2
  3590. // charstrings processors should support them. Unfortunately
  3591. // the font sanitizer don't. As a workaround the sequence (12, 0)
  3592. // is replaced by a useless (0, hmoveto).
  3593. data[j - 2] = 139;
  3594. data[j - 1] = 22;
  3595. stackSize = 0;
  3596. } else {
  3597. validationCommand = CharstringValidationData12[q];
  3598. }
  3599. } else if (value === 28) { // number (16 bit)
  3600. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  3601. j += 2;
  3602. stackSize++;
  3603. } else if (value === 14) {
  3604. if (stackSize >= 4) {
  3605. stackSize -= 4;
  3606. if (this.seacAnalysisEnabled) {
  3607. state.seac = stack.slice(stackSize, stackSize + 4);
  3608. return false;
  3609. }
  3610. }
  3611. validationCommand = CharstringValidationData[value];
  3612. } else if (value >= 32 && value <= 246) { // number
  3613. stack[stackSize] = value - 139;
  3614. stackSize++;
  3615. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  3616. stack[stackSize] = (value < 251 ?
  3617. ((value - 247) << 8) + data[j] + 108 :
  3618. -((value - 251) << 8) - data[j] - 108);
  3619. j++;
  3620. stackSize++;
  3621. } else if (value === 255) { // number (32 bit)
  3622. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  3623. (data[j + 2] << 8) | data[j + 3]) / 65536;
  3624. j += 4;
  3625. stackSize++;
  3626. } else if (value === 19 || value === 20) {
  3627. state.hints += stackSize >> 1;
  3628. // skipping right amount of hints flag data
  3629. j += (state.hints + 7) >> 3;
  3630. stackSize %= 2;
  3631. validationCommand = CharstringValidationData[value];
  3632. } else if (value === 10 || value === 29) {
  3633. var subrsIndex;
  3634. if (value === 10) {
  3635. subrsIndex = localSubrIndex;
  3636. } else {
  3637. subrsIndex = globalSubrIndex;
  3638. }
  3639. if (!subrsIndex) {
  3640. validationCommand = CharstringValidationData[value];
  3641. warn('Missing subrsIndex for ' + validationCommand.id);
  3642. return false;
  3643. }
  3644. var bias = 32768;
  3645. if (subrsIndex.count < 1240) {
  3646. bias = 107;
  3647. } else if (subrsIndex.count < 33900) {
  3648. bias = 1131;
  3649. }
  3650. var subrNumber = stack[--stackSize] + bias;
  3651. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  3652. validationCommand = CharstringValidationData[value];
  3653. warn('Out of bounds subrIndex for ' + validationCommand.id);
  3654. return false;
  3655. }
  3656. state.stackSize = stackSize;
  3657. state.callDepth++;
  3658. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  3659. localSubrIndex, globalSubrIndex);
  3660. if (!valid) {
  3661. return false;
  3662. }
  3663. state.callDepth--;
  3664. stackSize = state.stackSize;
  3665. continue;
  3666. } else if (value === 11) {
  3667. state.stackSize = stackSize;
  3668. return true;
  3669. } else {
  3670. validationCommand = CharstringValidationData[value];
  3671. }
  3672. if (validationCommand) {
  3673. if (validationCommand.stem) {
  3674. state.hints += stackSize >> 1;
  3675. }
  3676. if ('min' in validationCommand) {
  3677. if (!state.undefStack && stackSize < validationCommand.min) {
  3678. warn('Not enough parameters for ' + validationCommand.id +
  3679. '; actual: ' + stackSize +
  3680. ', expected: ' + validationCommand.min);
  3681. return false;
  3682. }
  3683. }
  3684. if (state.firstStackClearing && validationCommand.stackClearing) {
  3685. state.firstStackClearing = false;
  3686. // the optional character width can be found before the first
  3687. // stack-clearing command arguments
  3688. stackSize -= validationCommand.min;
  3689. if (stackSize >= 2 && validationCommand.stem) {
  3690. // there are even amount of arguments for stem commands
  3691. stackSize %= 2;
  3692. } else if (stackSize > 1) {
  3693. warn('Found too many parameters for stack-clearing command');
  3694. }
  3695. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  3696. state.width = stack[stackSize - 1];
  3697. }
  3698. }
  3699. if ('stackDelta' in validationCommand) {
  3700. if ('stackFn' in validationCommand) {
  3701. validationCommand.stackFn(stack, stackSize);
  3702. }
  3703. stackSize += validationCommand.stackDelta;
  3704. } else if (validationCommand.stackClearing) {
  3705. stackSize = 0;
  3706. } else if (validationCommand.resetStack) {
  3707. stackSize = 0;
  3708. state.undefStack = false;
  3709. } else if (validationCommand.undefStack) {
  3710. stackSize = 0;
  3711. state.undefStack = true;
  3712. state.firstStackClearing = false;
  3713. }
  3714. }
  3715. }
  3716. state.stackSize = stackSize;
  3717. return true;
  3718. },
  3719. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  3720. localSubrIndex,
  3721. globalSubrIndex,
  3722. fdSelect,
  3723. fdArray) {
  3724. var seacs = [];
  3725. var widths = [];
  3726. var count = charStrings.count;
  3727. for (var i = 0; i < count; i++) {
  3728. var charstring = charStrings.get(i);
  3729. var state = {
  3730. callDepth: 0,
  3731. stackSize: 0,
  3732. stack: [],
  3733. undefStack: true,
  3734. hints: 0,
  3735. firstStackClearing: true,
  3736. seac: null,
  3737. width: null
  3738. };
  3739. var valid = true;
  3740. var localSubrToUse = null;
  3741. if (fdSelect && fdArray.length) {
  3742. var fdIndex = fdSelect.getFDIndex(i);
  3743. if (fdIndex === -1) {
  3744. warn('Glyph index is not in fd select.');
  3745. valid = false;
  3746. }
  3747. if (fdIndex >= fdArray.length) {
  3748. warn('Invalid fd index for glyph index.');
  3749. valid = false;
  3750. }
  3751. if (valid) {
  3752. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  3753. }
  3754. } else if (localSubrIndex) {
  3755. localSubrToUse = localSubrIndex;
  3756. }
  3757. if (valid) {
  3758. valid = this.parseCharString(state, charstring, localSubrToUse,
  3759. globalSubrIndex);
  3760. }
  3761. if (state.width !== null) {
  3762. widths[i] = state.width;
  3763. }
  3764. if (state.seac !== null) {
  3765. seacs[i] = state.seac;
  3766. }
  3767. if (!valid) {
  3768. // resetting invalid charstring to single 'endchar'
  3769. charStrings.set(i, new Uint8Array([14]));
  3770. }
  3771. }
  3772. return { charStrings: charStrings, seacs: seacs, widths: widths };
  3773. },
  3774. emptyPrivateDictionary:
  3775. function CFFParser_emptyPrivateDictionary(parentDict) {
  3776. var privateDict = this.createDict(CFFPrivateDict, [],
  3777. parentDict.strings);
  3778. parentDict.setByKey(18, [0, 0]);
  3779. parentDict.privateDict = privateDict;
  3780. },
  3781. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  3782. // no private dict, do nothing
  3783. if (!parentDict.hasName('Private')) {
  3784. this.emptyPrivateDictionary(parentDict);
  3785. return;
  3786. }
  3787. var privateOffset = parentDict.getByName('Private');
  3788. // make sure the params are formatted correctly
  3789. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  3790. parentDict.removeByName('Private');
  3791. return;
  3792. }
  3793. var size = privateOffset[0];
  3794. var offset = privateOffset[1];
  3795. // remove empty dicts or ones that refer to invalid location
  3796. if (size === 0 || offset >= this.bytes.length) {
  3797. this.emptyPrivateDictionary(parentDict);
  3798. return;
  3799. }
  3800. var privateDictEnd = offset + size;
  3801. var dictData = this.bytes.subarray(offset, privateDictEnd);
  3802. var dict = this.parseDict(dictData);
  3803. var privateDict = this.createDict(CFFPrivateDict, dict,
  3804. parentDict.strings);
  3805. parentDict.privateDict = privateDict;
  3806. // Parse the Subrs index also since it's relative to the private dict.
  3807. if (!privateDict.getByName('Subrs')) {
  3808. return;
  3809. }
  3810. var subrsOffset = privateDict.getByName('Subrs');
  3811. var relativeOffset = offset + subrsOffset;
  3812. // Validate the offset.
  3813. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  3814. this.emptyPrivateDictionary(parentDict);
  3815. return;
  3816. }
  3817. var subrsIndex = this.parseIndex(relativeOffset);
  3818. privateDict.subrsIndex = subrsIndex.obj;
  3819. },
  3820. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  3821. if (pos === 0) {
  3822. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  3823. ISOAdobeCharset);
  3824. } else if (pos === 1) {
  3825. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  3826. ExpertCharset);
  3827. } else if (pos === 2) {
  3828. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  3829. ExpertSubsetCharset);
  3830. }
  3831. var bytes = this.bytes;
  3832. var start = pos;
  3833. var format = bytes[pos++];
  3834. var charset = ['.notdef'];
  3835. var id, count, i;
  3836. // subtract 1 for the .notdef glyph
  3837. length -= 1;
  3838. switch (format) {
  3839. case 0:
  3840. for (i = 0; i < length; i++) {
  3841. id = (bytes[pos++] << 8) | bytes[pos++];
  3842. charset.push(cid ? id : strings.get(id));
  3843. }
  3844. break;
  3845. case 1:
  3846. while (charset.length <= length) {
  3847. id = (bytes[pos++] << 8) | bytes[pos++];
  3848. count = bytes[pos++];
  3849. for (i = 0; i <= count; i++) {
  3850. charset.push(cid ? id++ : strings.get(id++));
  3851. }
  3852. }
  3853. break;
  3854. case 2:
  3855. while (charset.length <= length) {
  3856. id = (bytes[pos++] << 8) | bytes[pos++];
  3857. count = (bytes[pos++] << 8) | bytes[pos++];
  3858. for (i = 0; i <= count; i++) {
  3859. charset.push(cid ? id++ : strings.get(id++));
  3860. }
  3861. }
  3862. break;
  3863. default:
  3864. error('Unknown charset format');
  3865. }
  3866. // Raw won't be needed if we actually compile the charset.
  3867. var end = pos;
  3868. var raw = bytes.subarray(start, end);
  3869. return new CFFCharset(false, format, charset, raw);
  3870. },
  3871. parseEncoding: function CFFParser_parseEncoding(pos,
  3872. properties,
  3873. strings,
  3874. charset) {
  3875. var encoding = Object.create(null);
  3876. var bytes = this.bytes;
  3877. var predefined = false;
  3878. var hasSupplement = false;
  3879. var format, i, ii;
  3880. var raw = null;
  3881. function readSupplement() {
  3882. var supplementsCount = bytes[pos++];
  3883. for (i = 0; i < supplementsCount; i++) {
  3884. var code = bytes[pos++];
  3885. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  3886. encoding[code] = charset.indexOf(strings.get(sid));
  3887. }
  3888. }
  3889. if (pos === 0 || pos === 1) {
  3890. predefined = true;
  3891. format = pos;
  3892. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  3893. for (i = 0, ii = charset.length; i < ii; i++) {
  3894. var index = baseEncoding.indexOf(charset[i]);
  3895. if (index !== -1) {
  3896. encoding[index] = i;
  3897. }
  3898. }
  3899. } else {
  3900. var dataStart = pos;
  3901. format = bytes[pos++];
  3902. switch (format & 0x7f) {
  3903. case 0:
  3904. var glyphsCount = bytes[pos++];
  3905. for (i = 1; i <= glyphsCount; i++) {
  3906. encoding[bytes[pos++]] = i;
  3907. }
  3908. break;
  3909. case 1:
  3910. var rangesCount = bytes[pos++];
  3911. var gid = 1;
  3912. for (i = 0; i < rangesCount; i++) {
  3913. var start = bytes[pos++];
  3914. var left = bytes[pos++];
  3915. for (var j = start; j <= start + left; j++) {
  3916. encoding[j] = gid++;
  3917. }
  3918. }
  3919. break;
  3920. default:
  3921. error('Unknown encoding format: ' + format + ' in CFF');
  3922. break;
  3923. }
  3924. var dataEnd = pos;
  3925. if (format & 0x80) {
  3926. // The font sanitizer does not support CFF encoding with a
  3927. // supplement, since the encoding is not really used to map
  3928. // between gid to glyph, let's overwrite what is declared in
  3929. // the top dictionary to let the sanitizer think the font use
  3930. // StandardEncoding, that's a lie but that's ok.
  3931. bytes[dataStart] &= 0x7f;
  3932. readSupplement();
  3933. hasSupplement = true;
  3934. }
  3935. raw = bytes.subarray(dataStart, dataEnd);
  3936. }
  3937. format = format & 0x7f;
  3938. return new CFFEncoding(predefined, format, encoding, raw);
  3939. },
  3940. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  3941. var start = pos;
  3942. var bytes = this.bytes;
  3943. var format = bytes[pos++];
  3944. var fdSelect = [], rawBytes;
  3945. var i, invalidFirstGID = false;
  3946. switch (format) {
  3947. case 0:
  3948. for (i = 0; i < length; ++i) {
  3949. var id = bytes[pos++];
  3950. fdSelect.push(id);
  3951. }
  3952. rawBytes = bytes.subarray(start, pos);
  3953. break;
  3954. case 3:
  3955. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  3956. for (i = 0; i < rangesCount; ++i) {
  3957. var first = (bytes[pos++] << 8) | bytes[pos++];
  3958. if (i === 0 && first !== 0) {
  3959. warn('parseFDSelect: The first range must have a first GID of 0' +
  3960. ' -- trying to recover.');
  3961. invalidFirstGID = true;
  3962. first = 0;
  3963. }
  3964. var fdIndex = bytes[pos++];
  3965. var next = (bytes[pos] << 8) | bytes[pos + 1];
  3966. for (var j = first; j < next; ++j) {
  3967. fdSelect.push(fdIndex);
  3968. }
  3969. }
  3970. // Advance past the sentinel(next).
  3971. pos += 2;
  3972. rawBytes = bytes.subarray(start, pos);
  3973. if (invalidFirstGID) {
  3974. rawBytes[3] = rawBytes[4] = 0; // Adjust the first range, first GID.
  3975. }
  3976. break;
  3977. default:
  3978. error('parseFDSelect: Unknown format "' + format + '".');
  3979. break;
  3980. }
  3981. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  3982. return new CFFFDSelect(fdSelect, rawBytes);
  3983. }
  3984. };
  3985. return CFFParser;
  3986. })();
  3987. // Compact Font Format
  3988. var CFF = (function CFFClosure() {
  3989. function CFF() {
  3990. this.header = null;
  3991. this.names = [];
  3992. this.topDict = null;
  3993. this.strings = new CFFStrings();
  3994. this.globalSubrIndex = null;
  3995. // The following could really be per font, but since we only have one font
  3996. // store them here.
  3997. this.encoding = null;
  3998. this.charset = null;
  3999. this.charStrings = null;
  4000. this.fdArray = [];
  4001. this.fdSelect = null;
  4002. this.isCIDFont = false;
  4003. }
  4004. return CFF;
  4005. })();
  4006. var CFFHeader = (function CFFHeaderClosure() {
  4007. function CFFHeader(major, minor, hdrSize, offSize) {
  4008. this.major = major;
  4009. this.minor = minor;
  4010. this.hdrSize = hdrSize;
  4011. this.offSize = offSize;
  4012. }
  4013. return CFFHeader;
  4014. })();
  4015. var CFFStrings = (function CFFStringsClosure() {
  4016. function CFFStrings() {
  4017. this.strings = [];
  4018. }
  4019. CFFStrings.prototype = {
  4020. get: function CFFStrings_get(index) {
  4021. if (index >= 0 && index <= 390) {
  4022. return CFFStandardStrings[index];
  4023. }
  4024. if (index - 391 <= this.strings.length) {
  4025. return this.strings[index - 391];
  4026. }
  4027. return CFFStandardStrings[0];
  4028. },
  4029. add: function CFFStrings_add(value) {
  4030. this.strings.push(value);
  4031. },
  4032. get count() {
  4033. return this.strings.length;
  4034. }
  4035. };
  4036. return CFFStrings;
  4037. })();
  4038. var CFFIndex = (function CFFIndexClosure() {
  4039. function CFFIndex() {
  4040. this.objects = [];
  4041. this.length = 0;
  4042. }
  4043. CFFIndex.prototype = {
  4044. add: function CFFIndex_add(data) {
  4045. this.length += data.length;
  4046. this.objects.push(data);
  4047. },
  4048. set: function CFFIndex_set(index, data) {
  4049. this.length += data.length - this.objects[index].length;
  4050. this.objects[index] = data;
  4051. },
  4052. get: function CFFIndex_get(index) {
  4053. return this.objects[index];
  4054. },
  4055. get count() {
  4056. return this.objects.length;
  4057. }
  4058. };
  4059. return CFFIndex;
  4060. })();
  4061. var CFFDict = (function CFFDictClosure() {
  4062. function CFFDict(tables, strings) {
  4063. this.keyToNameMap = tables.keyToNameMap;
  4064. this.nameToKeyMap = tables.nameToKeyMap;
  4065. this.defaults = tables.defaults;
  4066. this.types = tables.types;
  4067. this.opcodes = tables.opcodes;
  4068. this.order = tables.order;
  4069. this.strings = strings;
  4070. this.values = Object.create(null);
  4071. }
  4072. CFFDict.prototype = {
  4073. // value should always be an array
  4074. setByKey: function CFFDict_setByKey(key, value) {
  4075. if (!(key in this.keyToNameMap)) {
  4076. return false;
  4077. }
  4078. // ignore empty values
  4079. if (value.length === 0) {
  4080. return true;
  4081. }
  4082. var type = this.types[key];
  4083. // remove the array wrapping these types of values
  4084. if (type === 'num' || type === 'sid' || type === 'offset') {
  4085. value = value[0];
  4086. // Ignore invalid values (fixes bug 1068432).
  4087. if (isNaN(value)) {
  4088. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  4089. return true;
  4090. }
  4091. }
  4092. this.values[key] = value;
  4093. return true;
  4094. },
  4095. setByName: function CFFDict_setByName(name, value) {
  4096. if (!(name in this.nameToKeyMap)) {
  4097. error('Invalid dictionary name "' + name + '"');
  4098. }
  4099. this.values[this.nameToKeyMap[name]] = value;
  4100. },
  4101. hasName: function CFFDict_hasName(name) {
  4102. return this.nameToKeyMap[name] in this.values;
  4103. },
  4104. getByName: function CFFDict_getByName(name) {
  4105. if (!(name in this.nameToKeyMap)) {
  4106. error('Invalid dictionary name "' + name + '"');
  4107. }
  4108. var key = this.nameToKeyMap[name];
  4109. if (!(key in this.values)) {
  4110. return this.defaults[key];
  4111. }
  4112. return this.values[key];
  4113. },
  4114. removeByName: function CFFDict_removeByName(name) {
  4115. delete this.values[this.nameToKeyMap[name]];
  4116. }
  4117. };
  4118. CFFDict.createTables = function CFFDict_createTables(layout) {
  4119. var tables = {
  4120. keyToNameMap: {},
  4121. nameToKeyMap: {},
  4122. defaults: {},
  4123. types: {},
  4124. opcodes: {},
  4125. order: []
  4126. };
  4127. for (var i = 0, ii = layout.length; i < ii; ++i) {
  4128. var entry = layout[i];
  4129. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  4130. tables.keyToNameMap[key] = entry[1];
  4131. tables.nameToKeyMap[entry[1]] = key;
  4132. tables.types[key] = entry[2];
  4133. tables.defaults[key] = entry[3];
  4134. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  4135. tables.order.push(key);
  4136. }
  4137. return tables;
  4138. };
  4139. return CFFDict;
  4140. })();
  4141. var CFFTopDict = (function CFFTopDictClosure() {
  4142. var layout = [
  4143. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  4144. [[12, 20], 'SyntheticBase', 'num', null],
  4145. [0, 'version', 'sid', null],
  4146. [1, 'Notice', 'sid', null],
  4147. [[12, 0], 'Copyright', 'sid', null],
  4148. [2, 'FullName', 'sid', null],
  4149. [3, 'FamilyName', 'sid', null],
  4150. [4, 'Weight', 'sid', null],
  4151. [[12, 1], 'isFixedPitch', 'num', 0],
  4152. [[12, 2], 'ItalicAngle', 'num', 0],
  4153. [[12, 3], 'UnderlinePosition', 'num', -100],
  4154. [[12, 4], 'UnderlineThickness', 'num', 50],
  4155. [[12, 5], 'PaintType', 'num', 0],
  4156. [[12, 6], 'CharstringType', 'num', 2],
  4157. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  4158. [0.001, 0, 0, 0.001, 0, 0]],
  4159. [13, 'UniqueID', 'num', null],
  4160. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  4161. [[12, 8], 'StrokeWidth', 'num', 0],
  4162. [14, 'XUID', 'array', null],
  4163. [15, 'charset', 'offset', 0],
  4164. [16, 'Encoding', 'offset', 0],
  4165. [17, 'CharStrings', 'offset', 0],
  4166. [18, 'Private', ['offset', 'offset'], null],
  4167. [[12, 21], 'PostScript', 'sid', null],
  4168. [[12, 22], 'BaseFontName', 'sid', null],
  4169. [[12, 23], 'BaseFontBlend', 'delta', null],
  4170. [[12, 31], 'CIDFontVersion', 'num', 0],
  4171. [[12, 32], 'CIDFontRevision', 'num', 0],
  4172. [[12, 33], 'CIDFontType', 'num', 0],
  4173. [[12, 34], 'CIDCount', 'num', 8720],
  4174. [[12, 35], 'UIDBase', 'num', null],
  4175. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  4176. // before FDArray.
  4177. [[12, 37], 'FDSelect', 'offset', null],
  4178. [[12, 36], 'FDArray', 'offset', null],
  4179. [[12, 38], 'FontName', 'sid', null]
  4180. ];
  4181. var tables = null;
  4182. function CFFTopDict(strings) {
  4183. if (tables === null) {
  4184. tables = CFFDict.createTables(layout);
  4185. }
  4186. CFFDict.call(this, tables, strings);
  4187. this.privateDict = null;
  4188. }
  4189. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  4190. return CFFTopDict;
  4191. })();
  4192. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  4193. var layout = [
  4194. [6, 'BlueValues', 'delta', null],
  4195. [7, 'OtherBlues', 'delta', null],
  4196. [8, 'FamilyBlues', 'delta', null],
  4197. [9, 'FamilyOtherBlues', 'delta', null],
  4198. [[12, 9], 'BlueScale', 'num', 0.039625],
  4199. [[12, 10], 'BlueShift', 'num', 7],
  4200. [[12, 11], 'BlueFuzz', 'num', 1],
  4201. [10, 'StdHW', 'num', null],
  4202. [11, 'StdVW', 'num', null],
  4203. [[12, 12], 'StemSnapH', 'delta', null],
  4204. [[12, 13], 'StemSnapV', 'delta', null],
  4205. [[12, 14], 'ForceBold', 'num', 0],
  4206. [[12, 17], 'LanguageGroup', 'num', 0],
  4207. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  4208. [[12, 19], 'initialRandomSeed', 'num', 0],
  4209. [20, 'defaultWidthX', 'num', 0],
  4210. [21, 'nominalWidthX', 'num', 0],
  4211. [19, 'Subrs', 'offset', null]
  4212. ];
  4213. var tables = null;
  4214. function CFFPrivateDict(strings) {
  4215. if (tables === null) {
  4216. tables = CFFDict.createTables(layout);
  4217. }
  4218. CFFDict.call(this, tables, strings);
  4219. this.subrsIndex = null;
  4220. }
  4221. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  4222. return CFFPrivateDict;
  4223. })();
  4224. var CFFCharsetPredefinedTypes = {
  4225. ISO_ADOBE: 0,
  4226. EXPERT: 1,
  4227. EXPERT_SUBSET: 2
  4228. };
  4229. var CFFCharset = (function CFFCharsetClosure() {
  4230. function CFFCharset(predefined, format, charset, raw) {
  4231. this.predefined = predefined;
  4232. this.format = format;
  4233. this.charset = charset;
  4234. this.raw = raw;
  4235. }
  4236. return CFFCharset;
  4237. })();
  4238. var CFFEncoding = (function CFFEncodingClosure() {
  4239. function CFFEncoding(predefined, format, encoding, raw) {
  4240. this.predefined = predefined;
  4241. this.format = format;
  4242. this.encoding = encoding;
  4243. this.raw = raw;
  4244. }
  4245. return CFFEncoding;
  4246. })();
  4247. var CFFFDSelect = (function CFFFDSelectClosure() {
  4248. function CFFFDSelect(fdSelect, raw) {
  4249. this.fdSelect = fdSelect;
  4250. this.raw = raw;
  4251. }
  4252. CFFFDSelect.prototype = {
  4253. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  4254. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  4255. return -1;
  4256. }
  4257. return this.fdSelect[glyphIndex];
  4258. }
  4259. };
  4260. return CFFFDSelect;
  4261. })();
  4262. // Helper class to keep track of where an offset is within the data and helps
  4263. // filling in that offset once it's known.
  4264. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  4265. function CFFOffsetTracker() {
  4266. this.offsets = Object.create(null);
  4267. }
  4268. CFFOffsetTracker.prototype = {
  4269. isTracking: function CFFOffsetTracker_isTracking(key) {
  4270. return key in this.offsets;
  4271. },
  4272. track: function CFFOffsetTracker_track(key, location) {
  4273. if (key in this.offsets) {
  4274. error('Already tracking location of ' + key);
  4275. }
  4276. this.offsets[key] = location;
  4277. },
  4278. offset: function CFFOffsetTracker_offset(value) {
  4279. for (var key in this.offsets) {
  4280. this.offsets[key] += value;
  4281. }
  4282. },
  4283. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  4284. values,
  4285. output) {
  4286. if (!(key in this.offsets)) {
  4287. error('Not tracking location of ' + key);
  4288. }
  4289. var data = output.data;
  4290. var dataOffset = this.offsets[key];
  4291. var size = 5;
  4292. for (var i = 0, ii = values.length; i < ii; ++i) {
  4293. var offset0 = i * size + dataOffset;
  4294. var offset1 = offset0 + 1;
  4295. var offset2 = offset0 + 2;
  4296. var offset3 = offset0 + 3;
  4297. var offset4 = offset0 + 4;
  4298. // It's easy to screw up offsets so perform this sanity check.
  4299. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  4300. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  4301. error('writing to an offset that is not empty');
  4302. }
  4303. var value = values[i];
  4304. data[offset0] = 0x1d;
  4305. data[offset1] = (value >> 24) & 0xFF;
  4306. data[offset2] = (value >> 16) & 0xFF;
  4307. data[offset3] = (value >> 8) & 0xFF;
  4308. data[offset4] = value & 0xFF;
  4309. }
  4310. }
  4311. };
  4312. return CFFOffsetTracker;
  4313. })();
  4314. // Takes a CFF and converts it to the binary representation.
  4315. var CFFCompiler = (function CFFCompilerClosure() {
  4316. function CFFCompiler(cff) {
  4317. this.cff = cff;
  4318. }
  4319. CFFCompiler.prototype = {
  4320. compile: function CFFCompiler_compile() {
  4321. var cff = this.cff;
  4322. var output = {
  4323. data: [],
  4324. length: 0,
  4325. add: function CFFCompiler_add(data) {
  4326. this.data = this.data.concat(data);
  4327. this.length = this.data.length;
  4328. }
  4329. };
  4330. // Compile the five entries that must be in order.
  4331. var header = this.compileHeader(cff.header);
  4332. output.add(header);
  4333. var nameIndex = this.compileNameIndex(cff.names);
  4334. output.add(nameIndex);
  4335. if (cff.isCIDFont) {
  4336. // The spec is unclear on how font matrices should relate to each other
  4337. // when there is one in the main top dict and the sub top dicts.
  4338. // Windows handles this differently than linux and osx so we have to
  4339. // normalize to work on all.
  4340. // Rules based off of some mailing list discussions:
  4341. // - If main font has a matrix and subfont doesn't, use the main matrix.
  4342. // - If no main font matrix and there is a subfont matrix, use the
  4343. // subfont matrix.
  4344. // - If both have matrices, concat together.
  4345. // - If neither have matrices, use default.
  4346. // To make this work on all platforms we move the top matrix into each
  4347. // sub top dict and concat if necessary.
  4348. if (cff.topDict.hasName('FontMatrix')) {
  4349. var base = cff.topDict.getByName('FontMatrix');
  4350. cff.topDict.removeByName('FontMatrix');
  4351. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  4352. var subDict = cff.fdArray[i];
  4353. var matrix = base.slice(0);
  4354. if (subDict.hasName('FontMatrix')) {
  4355. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  4356. }
  4357. subDict.setByName('FontMatrix', matrix);
  4358. }
  4359. }
  4360. }
  4361. var compiled = this.compileTopDicts([cff.topDict],
  4362. output.length,
  4363. cff.isCIDFont);
  4364. output.add(compiled.output);
  4365. var topDictTracker = compiled.trackers[0];
  4366. var stringIndex = this.compileStringIndex(cff.strings.strings);
  4367. output.add(stringIndex);
  4368. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  4369. output.add(globalSubrIndex);
  4370. // Now start on the other entries that have no specific order.
  4371. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  4372. if (cff.encoding.predefined) {
  4373. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  4374. output);
  4375. } else {
  4376. var encoding = this.compileEncoding(cff.encoding);
  4377. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  4378. output.add(encoding);
  4379. }
  4380. }
  4381. if (cff.charset && cff.topDict.hasName('charset')) {
  4382. if (cff.charset.predefined) {
  4383. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  4384. output);
  4385. } else {
  4386. var charset = this.compileCharset(cff.charset);
  4387. topDictTracker.setEntryLocation('charset', [output.length], output);
  4388. output.add(charset);
  4389. }
  4390. }
  4391. var charStrings = this.compileCharStrings(cff.charStrings);
  4392. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  4393. output.add(charStrings);
  4394. if (cff.isCIDFont) {
  4395. // For some reason FDSelect must be in front of FDArray on windows. OSX
  4396. // and linux don't seem to care.
  4397. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  4398. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  4399. output.add(fdSelect);
  4400. // It is unclear if the sub font dictionary can have CID related
  4401. // dictionary keys, but the sanitizer doesn't like them so remove them.
  4402. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  4403. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  4404. output.add(compiled.output);
  4405. var fontDictTrackers = compiled.trackers;
  4406. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  4407. }
  4408. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  4409. // If the font data ends with INDEX whose object data is zero-length,
  4410. // the sanitizer will bail out. Add a dummy byte to avoid that.
  4411. output.add([0]);
  4412. return output.data;
  4413. },
  4414. encodeNumber: function CFFCompiler_encodeNumber(value) {
  4415. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  4416. return this.encodeInteger(value);
  4417. } else {
  4418. return this.encodeFloat(value);
  4419. }
  4420. },
  4421. encodeFloat: function CFFCompiler_encodeFloat(num) {
  4422. var value = num.toString();
  4423. // rounding inaccurate doubles
  4424. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  4425. if (m) {
  4426. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  4427. value = (Math.round(num * epsilon) / epsilon).toString();
  4428. }
  4429. var nibbles = '';
  4430. var i, ii;
  4431. for (i = 0, ii = value.length; i < ii; ++i) {
  4432. var a = value[i];
  4433. if (a === 'e') {
  4434. nibbles += value[++i] === '-' ? 'c' : 'b';
  4435. } else if (a === '.') {
  4436. nibbles += 'a';
  4437. } else if (a === '-') {
  4438. nibbles += 'e';
  4439. } else {
  4440. nibbles += a;
  4441. }
  4442. }
  4443. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  4444. var out = [30];
  4445. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  4446. out.push(parseInt(nibbles.substr(i, 2), 16));
  4447. }
  4448. return out;
  4449. },
  4450. encodeInteger: function CFFCompiler_encodeInteger(value) {
  4451. var code;
  4452. if (value >= -107 && value <= 107) {
  4453. code = [value + 139];
  4454. } else if (value >= 108 && value <= 1131) {
  4455. value = value - 108;
  4456. code = [(value >> 8) + 247, value & 0xFF];
  4457. } else if (value >= -1131 && value <= -108) {
  4458. value = -value - 108;
  4459. code = [(value >> 8) + 251, value & 0xFF];
  4460. } else if (value >= -32768 && value <= 32767) {
  4461. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  4462. } else {
  4463. code = [0x1d,
  4464. (value >> 24) & 0xFF,
  4465. (value >> 16) & 0xFF,
  4466. (value >> 8) & 0xFF,
  4467. value & 0xFF];
  4468. }
  4469. return code;
  4470. },
  4471. compileHeader: function CFFCompiler_compileHeader(header) {
  4472. return [
  4473. header.major,
  4474. header.minor,
  4475. header.hdrSize,
  4476. header.offSize
  4477. ];
  4478. },
  4479. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  4480. var nameIndex = new CFFIndex();
  4481. for (var i = 0, ii = names.length; i < ii; ++i) {
  4482. nameIndex.add(stringToBytes(names[i]));
  4483. }
  4484. return this.compileIndex(nameIndex);
  4485. },
  4486. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  4487. length,
  4488. removeCidKeys) {
  4489. var fontDictTrackers = [];
  4490. var fdArrayIndex = new CFFIndex();
  4491. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  4492. var fontDict = dicts[i];
  4493. if (removeCidKeys) {
  4494. fontDict.removeByName('CIDFontVersion');
  4495. fontDict.removeByName('CIDFontRevision');
  4496. fontDict.removeByName('CIDFontType');
  4497. fontDict.removeByName('CIDCount');
  4498. fontDict.removeByName('UIDBase');
  4499. }
  4500. var fontDictTracker = new CFFOffsetTracker();
  4501. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  4502. fontDictTrackers.push(fontDictTracker);
  4503. fdArrayIndex.add(fontDictData);
  4504. fontDictTracker.offset(length);
  4505. }
  4506. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  4507. return {
  4508. trackers: fontDictTrackers,
  4509. output: fdArrayIndex
  4510. };
  4511. },
  4512. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  4513. trackers,
  4514. output) {
  4515. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  4516. var fontDict = dicts[i];
  4517. assert(fontDict.privateDict && fontDict.hasName('Private'),
  4518. 'There must be an private dictionary.');
  4519. var privateDict = fontDict.privateDict;
  4520. var privateDictTracker = new CFFOffsetTracker();
  4521. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  4522. var outputLength = output.length;
  4523. privateDictTracker.offset(outputLength);
  4524. if (!privateDictData.length) {
  4525. // The private dictionary was empty, set the output length to zero to
  4526. // ensure the offset length isn't out of bounds in the eyes of the
  4527. // sanitizer.
  4528. outputLength = 0;
  4529. }
  4530. trackers[i].setEntryLocation('Private',
  4531. [privateDictData.length, outputLength],
  4532. output);
  4533. output.add(privateDictData);
  4534. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  4535. var subrs = this.compileIndex(privateDict.subrsIndex);
  4536. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  4537. output);
  4538. output.add(subrs);
  4539. }
  4540. }
  4541. },
  4542. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  4543. var out = [];
  4544. // The dictionary keys must be in a certain order.
  4545. var order = dict.order;
  4546. for (var i = 0; i < order.length; ++i) {
  4547. var key = order[i];
  4548. if (!(key in dict.values)) {
  4549. continue;
  4550. }
  4551. var values = dict.values[key];
  4552. var types = dict.types[key];
  4553. if (!isArray(types)) {
  4554. types = [types];
  4555. }
  4556. if (!isArray(values)) {
  4557. values = [values];
  4558. }
  4559. // Remove any empty dict values.
  4560. if (values.length === 0) {
  4561. continue;
  4562. }
  4563. for (var j = 0, jj = types.length; j < jj; ++j) {
  4564. var type = types[j];
  4565. var value = values[j];
  4566. switch (type) {
  4567. case 'num':
  4568. case 'sid':
  4569. out = out.concat(this.encodeNumber(value));
  4570. break;
  4571. case 'offset':
  4572. // For offsets we just insert a 32bit integer so we don't have to
  4573. // deal with figuring out the length of the offset when it gets
  4574. // replaced later on by the compiler.
  4575. var name = dict.keyToNameMap[key];
  4576. // Some offsets have the offset and the length, so just record the
  4577. // position of the first one.
  4578. if (!offsetTracker.isTracking(name)) {
  4579. offsetTracker.track(name, out.length);
  4580. }
  4581. out = out.concat([0x1d, 0, 0, 0, 0]);
  4582. break;
  4583. case 'array':
  4584. case 'delta':
  4585. out = out.concat(this.encodeNumber(value));
  4586. for (var k = 1, kk = values.length; k < kk; ++k) {
  4587. out = out.concat(this.encodeNumber(values[k]));
  4588. }
  4589. break;
  4590. default:
  4591. error('Unknown data type of ' + type);
  4592. break;
  4593. }
  4594. }
  4595. out = out.concat(dict.opcodes[key]);
  4596. }
  4597. return out;
  4598. },
  4599. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  4600. var stringIndex = new CFFIndex();
  4601. for (var i = 0, ii = strings.length; i < ii; ++i) {
  4602. stringIndex.add(stringToBytes(strings[i]));
  4603. }
  4604. return this.compileIndex(stringIndex);
  4605. },
  4606. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  4607. var globalSubrIndex = this.cff.globalSubrIndex;
  4608. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  4609. },
  4610. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  4611. return this.compileIndex(charStrings);
  4612. },
  4613. compileCharset: function CFFCompiler_compileCharset(charset) {
  4614. return this.compileTypedArray(charset.raw);
  4615. },
  4616. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  4617. return this.compileTypedArray(encoding.raw);
  4618. },
  4619. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  4620. return this.compileTypedArray(fdSelect);
  4621. },
  4622. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  4623. var out = [];
  4624. for (var i = 0, ii = data.length; i < ii; ++i) {
  4625. out[i] = data[i];
  4626. }
  4627. return out;
  4628. },
  4629. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  4630. trackers = trackers || [];
  4631. var objects = index.objects;
  4632. // First 2 bytes contains the number of objects contained into this index
  4633. var count = objects.length;
  4634. // If there is no object, just create an index. This technically
  4635. // should just be [0, 0] but OTS has an issue with that.
  4636. if (count === 0) {
  4637. return [0, 0, 0];
  4638. }
  4639. var data = [(count >> 8) & 0xFF, count & 0xff];
  4640. var lastOffset = 1, i;
  4641. for (i = 0; i < count; ++i) {
  4642. lastOffset += objects[i].length;
  4643. }
  4644. var offsetSize;
  4645. if (lastOffset < 0x100) {
  4646. offsetSize = 1;
  4647. } else if (lastOffset < 0x10000) {
  4648. offsetSize = 2;
  4649. } else if (lastOffset < 0x1000000) {
  4650. offsetSize = 3;
  4651. } else {
  4652. offsetSize = 4;
  4653. }
  4654. // Next byte contains the offset size use to reference object in the file
  4655. data.push(offsetSize);
  4656. // Add another offset after this one because we need a new offset
  4657. var relativeOffset = 1;
  4658. for (i = 0; i < count + 1; i++) {
  4659. if (offsetSize === 1) {
  4660. data.push(relativeOffset & 0xFF);
  4661. } else if (offsetSize === 2) {
  4662. data.push((relativeOffset >> 8) & 0xFF,
  4663. relativeOffset & 0xFF);
  4664. } else if (offsetSize === 3) {
  4665. data.push((relativeOffset >> 16) & 0xFF,
  4666. (relativeOffset >> 8) & 0xFF,
  4667. relativeOffset & 0xFF);
  4668. } else {
  4669. data.push((relativeOffset >>> 24) & 0xFF,
  4670. (relativeOffset >> 16) & 0xFF,
  4671. (relativeOffset >> 8) & 0xFF,
  4672. relativeOffset & 0xFF);
  4673. }
  4674. if (objects[i]) {
  4675. relativeOffset += objects[i].length;
  4676. }
  4677. }
  4678. for (i = 0; i < count; i++) {
  4679. // Notify the tracker where the object will be offset in the data.
  4680. if (trackers[i]) {
  4681. trackers[i].offset(data.length);
  4682. }
  4683. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  4684. data.push(objects[i][j]);
  4685. }
  4686. }
  4687. return data;
  4688. }
  4689. };
  4690. return CFFCompiler;
  4691. })();
  4692. exports.CFFStandardStrings = CFFStandardStrings;
  4693. exports.CFFParser = CFFParser;
  4694. exports.CFF = CFF;
  4695. exports.CFFHeader = CFFHeader;
  4696. exports.CFFStrings = CFFStrings;
  4697. exports.CFFIndex = CFFIndex;
  4698. exports.CFFCharset = CFFCharset;
  4699. exports.CFFTopDict = CFFTopDict;
  4700. exports.CFFPrivateDict = CFFPrivateDict;
  4701. exports.CFFCompiler = CFFCompiler;
  4702. }));
  4703. (function (root, factory) {
  4704. {
  4705. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  4706. }
  4707. }(this, function (exports, sharedUtil) {
  4708. var MissingDataException = sharedUtil.MissingDataException;
  4709. var arrayByteLength = sharedUtil.arrayByteLength;
  4710. var arraysToBytes = sharedUtil.arraysToBytes;
  4711. var assert = sharedUtil.assert;
  4712. var createPromiseCapability = sharedUtil.createPromiseCapability;
  4713. var isInt = sharedUtil.isInt;
  4714. var isEmptyObj = sharedUtil.isEmptyObj;
  4715. var ChunkedStream = (function ChunkedStreamClosure() {
  4716. function ChunkedStream(length, chunkSize, manager) {
  4717. this.bytes = new Uint8Array(length);
  4718. this.start = 0;
  4719. this.pos = 0;
  4720. this.end = length;
  4721. this.chunkSize = chunkSize;
  4722. this.loadedChunks = [];
  4723. this.numChunksLoaded = 0;
  4724. this.numChunks = Math.ceil(length / chunkSize);
  4725. this.manager = manager;
  4726. this.progressiveDataLength = 0;
  4727. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  4728. }
  4729. // required methods for a stream. if a particular stream does not
  4730. // implement these, an error should be thrown
  4731. ChunkedStream.prototype = {
  4732. getMissingChunks: function ChunkedStream_getMissingChunks() {
  4733. var chunks = [];
  4734. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  4735. if (!this.loadedChunks[chunk]) {
  4736. chunks.push(chunk);
  4737. }
  4738. }
  4739. return chunks;
  4740. },
  4741. getBaseStreams: function ChunkedStream_getBaseStreams() {
  4742. return [this];
  4743. },
  4744. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  4745. return this.numChunksLoaded === this.numChunks;
  4746. },
  4747. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  4748. var end = begin + chunk.byteLength;
  4749. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  4750. // Using this.length is inaccurate here since this.start can be moved
  4751. // See ChunkedStream.moveStart()
  4752. var length = this.bytes.length;
  4753. assert(end % this.chunkSize === 0 || end === length,
  4754. 'Bad end offset: ' + end);
  4755. this.bytes.set(new Uint8Array(chunk), begin);
  4756. var chunkSize = this.chunkSize;
  4757. var beginChunk = Math.floor(begin / chunkSize);
  4758. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4759. var curChunk;
  4760. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4761. if (!this.loadedChunks[curChunk]) {
  4762. this.loadedChunks[curChunk] = true;
  4763. ++this.numChunksLoaded;
  4764. }
  4765. }
  4766. },
  4767. onReceiveProgressiveData:
  4768. function ChunkedStream_onReceiveProgressiveData(data) {
  4769. var position = this.progressiveDataLength;
  4770. var beginChunk = Math.floor(position / this.chunkSize);
  4771. this.bytes.set(new Uint8Array(data), position);
  4772. position += data.byteLength;
  4773. this.progressiveDataLength = position;
  4774. var endChunk = position >= this.end ? this.numChunks :
  4775. Math.floor(position / this.chunkSize);
  4776. var curChunk;
  4777. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4778. if (!this.loadedChunks[curChunk]) {
  4779. this.loadedChunks[curChunk] = true;
  4780. ++this.numChunksLoaded;
  4781. }
  4782. }
  4783. },
  4784. ensureByte: function ChunkedStream_ensureByte(pos) {
  4785. var chunk = Math.floor(pos / this.chunkSize);
  4786. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  4787. return;
  4788. }
  4789. if (!this.loadedChunks[chunk]) {
  4790. throw new MissingDataException(pos, pos + 1);
  4791. }
  4792. this.lastSuccessfulEnsureByteChunk = chunk;
  4793. },
  4794. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  4795. if (begin >= end) {
  4796. return;
  4797. }
  4798. if (end <= this.progressiveDataLength) {
  4799. return;
  4800. }
  4801. var chunkSize = this.chunkSize;
  4802. var beginChunk = Math.floor(begin / chunkSize);
  4803. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4804. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4805. if (!this.loadedChunks[chunk]) {
  4806. throw new MissingDataException(begin, end);
  4807. }
  4808. }
  4809. },
  4810. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  4811. var chunk, numChunks = this.numChunks;
  4812. for (var i = 0; i < numChunks; ++i) {
  4813. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  4814. if (!this.loadedChunks[chunk]) {
  4815. return chunk;
  4816. }
  4817. }
  4818. return null;
  4819. },
  4820. hasChunk: function ChunkedStream_hasChunk(chunk) {
  4821. return !!this.loadedChunks[chunk];
  4822. },
  4823. get length() {
  4824. return this.end - this.start;
  4825. },
  4826. get isEmpty() {
  4827. return this.length === 0;
  4828. },
  4829. getByte: function ChunkedStream_getByte() {
  4830. var pos = this.pos;
  4831. if (pos >= this.end) {
  4832. return -1;
  4833. }
  4834. this.ensureByte(pos);
  4835. return this.bytes[this.pos++];
  4836. },
  4837. getUint16: function ChunkedStream_getUint16() {
  4838. var b0 = this.getByte();
  4839. var b1 = this.getByte();
  4840. if (b0 === -1 || b1 === -1) {
  4841. return -1;
  4842. }
  4843. return (b0 << 8) + b1;
  4844. },
  4845. getInt32: function ChunkedStream_getInt32() {
  4846. var b0 = this.getByte();
  4847. var b1 = this.getByte();
  4848. var b2 = this.getByte();
  4849. var b3 = this.getByte();
  4850. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4851. },
  4852. // returns subarray of original buffer
  4853. // should only be read
  4854. getBytes: function ChunkedStream_getBytes(length) {
  4855. var bytes = this.bytes;
  4856. var pos = this.pos;
  4857. var strEnd = this.end;
  4858. if (!length) {
  4859. this.ensureRange(pos, strEnd);
  4860. return bytes.subarray(pos, strEnd);
  4861. }
  4862. var end = pos + length;
  4863. if (end > strEnd) {
  4864. end = strEnd;
  4865. }
  4866. this.ensureRange(pos, end);
  4867. this.pos = end;
  4868. return bytes.subarray(pos, end);
  4869. },
  4870. peekByte: function ChunkedStream_peekByte() {
  4871. var peekedByte = this.getByte();
  4872. this.pos--;
  4873. return peekedByte;
  4874. },
  4875. peekBytes: function ChunkedStream_peekBytes(length) {
  4876. var bytes = this.getBytes(length);
  4877. this.pos -= bytes.length;
  4878. return bytes;
  4879. },
  4880. getByteRange: function ChunkedStream_getBytes(begin, end) {
  4881. this.ensureRange(begin, end);
  4882. return this.bytes.subarray(begin, end);
  4883. },
  4884. skip: function ChunkedStream_skip(n) {
  4885. if (!n) {
  4886. n = 1;
  4887. }
  4888. this.pos += n;
  4889. },
  4890. reset: function ChunkedStream_reset() {
  4891. this.pos = this.start;
  4892. },
  4893. moveStart: function ChunkedStream_moveStart() {
  4894. this.start = this.pos;
  4895. },
  4896. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  4897. this.ensureRange(start, start + length);
  4898. function ChunkedStreamSubstream() {}
  4899. ChunkedStreamSubstream.prototype = Object.create(this);
  4900. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  4901. var chunkSize = this.chunkSize;
  4902. var beginChunk = Math.floor(this.start / chunkSize);
  4903. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  4904. var missingChunks = [];
  4905. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4906. if (!this.loadedChunks[chunk]) {
  4907. missingChunks.push(chunk);
  4908. }
  4909. }
  4910. return missingChunks;
  4911. };
  4912. var subStream = new ChunkedStreamSubstream();
  4913. subStream.pos = subStream.start = start;
  4914. subStream.end = start + length || this.end;
  4915. subStream.dict = dict;
  4916. return subStream;
  4917. },
  4918. isStream: true
  4919. };
  4920. return ChunkedStream;
  4921. })();
  4922. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  4923. function ChunkedStreamManager(pdfNetworkStream, args) {
  4924. var chunkSize = args.rangeChunkSize;
  4925. var length = args.length;
  4926. this.stream = new ChunkedStream(length, chunkSize, this);
  4927. this.length = length;
  4928. this.chunkSize = chunkSize;
  4929. this.pdfNetworkStream = pdfNetworkStream;
  4930. this.url = args.url;
  4931. this.disableAutoFetch = args.disableAutoFetch;
  4932. this.msgHandler = args.msgHandler;
  4933. this.currRequestId = 0;
  4934. this.chunksNeededByRequest = Object.create(null);
  4935. this.requestsByChunk = Object.create(null);
  4936. this.promisesByRequest = Object.create(null);
  4937. this.progressiveDataLength = 0;
  4938. this.aborted = false;
  4939. this._loadedStreamCapability = createPromiseCapability();
  4940. }
  4941. ChunkedStreamManager.prototype = {
  4942. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  4943. return this._loadedStreamCapability.promise;
  4944. },
  4945. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  4946. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  4947. if (!rangeReader.isStreamingSupported) {
  4948. rangeReader.onProgress = this.onProgress.bind(this);
  4949. }
  4950. var chunks = [], loaded = 0;
  4951. var manager = this;
  4952. var promise = new Promise(function (resolve, reject) {
  4953. var readChunk = function (chunk) {
  4954. try {
  4955. if (!chunk.done) {
  4956. var data = chunk.value;
  4957. chunks.push(data);
  4958. loaded += arrayByteLength(data);
  4959. if (rangeReader.isStreamingSupported) {
  4960. manager.onProgress({loaded: loaded});
  4961. }
  4962. rangeReader.read().then(readChunk, reject);
  4963. return;
  4964. }
  4965. var chunkData = arraysToBytes(chunks);
  4966. chunks = null;
  4967. resolve(chunkData);
  4968. } catch (e) {
  4969. reject(e);
  4970. }
  4971. };
  4972. rangeReader.read().then(readChunk, reject);
  4973. });
  4974. promise.then(function (data) {
  4975. if (this.aborted) {
  4976. return; // ignoring any data after abort
  4977. }
  4978. this.onReceiveData({chunk: data, begin: begin});
  4979. }.bind(this));
  4980. // TODO check errors
  4981. },
  4982. // Get all the chunks that are not yet loaded and groups them into
  4983. // contiguous ranges to load in as few requests as possible
  4984. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  4985. var missingChunks = this.stream.getMissingChunks();
  4986. this._requestChunks(missingChunks);
  4987. return this._loadedStreamCapability.promise;
  4988. },
  4989. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  4990. var requestId = this.currRequestId++;
  4991. var i, ii;
  4992. var chunksNeeded = Object.create(null);
  4993. this.chunksNeededByRequest[requestId] = chunksNeeded;
  4994. for (i = 0, ii = chunks.length; i < ii; i++) {
  4995. if (!this.stream.hasChunk(chunks[i])) {
  4996. chunksNeeded[chunks[i]] = true;
  4997. }
  4998. }
  4999. if (isEmptyObj(chunksNeeded)) {
  5000. return Promise.resolve();
  5001. }
  5002. var capability = createPromiseCapability();
  5003. this.promisesByRequest[requestId] = capability;
  5004. var chunksToRequest = [];
  5005. for (var chunk in chunksNeeded) {
  5006. chunk = chunk | 0;
  5007. if (!(chunk in this.requestsByChunk)) {
  5008. this.requestsByChunk[chunk] = [];
  5009. chunksToRequest.push(chunk);
  5010. }
  5011. this.requestsByChunk[chunk].push(requestId);
  5012. }
  5013. if (!chunksToRequest.length) {
  5014. return capability.promise;
  5015. }
  5016. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  5017. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  5018. var groupedChunk = groupedChunksToRequest[i];
  5019. var begin = groupedChunk.beginChunk * this.chunkSize;
  5020. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  5021. this.sendRequest(begin, end);
  5022. }
  5023. return capability.promise;
  5024. },
  5025. getStream: function ChunkedStreamManager_getStream() {
  5026. return this.stream;
  5027. },
  5028. // Loads any chunks in the requested range that are not yet loaded
  5029. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  5030. end = Math.min(end, this.length);
  5031. var beginChunk = this.getBeginChunk(begin);
  5032. var endChunk = this.getEndChunk(end);
  5033. var chunks = [];
  5034. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5035. chunks.push(chunk);
  5036. }
  5037. return this._requestChunks(chunks);
  5038. },
  5039. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  5040. ranges = ranges || [];
  5041. var chunksToRequest = [];
  5042. for (var i = 0; i < ranges.length; i++) {
  5043. var beginChunk = this.getBeginChunk(ranges[i].begin);
  5044. var endChunk = this.getEndChunk(ranges[i].end);
  5045. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5046. if (chunksToRequest.indexOf(chunk) < 0) {
  5047. chunksToRequest.push(chunk);
  5048. }
  5049. }
  5050. }
  5051. chunksToRequest.sort(function(a, b) { return a - b; });
  5052. return this._requestChunks(chunksToRequest);
  5053. },
  5054. // Groups a sorted array of chunks into as few contiguous larger
  5055. // chunks as possible
  5056. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  5057. var groupedChunks = [];
  5058. var beginChunk = -1;
  5059. var prevChunk = -1;
  5060. for (var i = 0; i < chunks.length; ++i) {
  5061. var chunk = chunks[i];
  5062. if (beginChunk < 0) {
  5063. beginChunk = chunk;
  5064. }
  5065. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  5066. groupedChunks.push({ beginChunk: beginChunk,
  5067. endChunk: prevChunk + 1 });
  5068. beginChunk = chunk;
  5069. }
  5070. if (i + 1 === chunks.length) {
  5071. groupedChunks.push({ beginChunk: beginChunk,
  5072. endChunk: chunk + 1 });
  5073. }
  5074. prevChunk = chunk;
  5075. }
  5076. return groupedChunks;
  5077. },
  5078. onProgress: function ChunkedStreamManager_onProgress(args) {
  5079. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  5080. args.loaded);
  5081. this.msgHandler.send('DocProgress', {
  5082. loaded: bytesLoaded,
  5083. total: this.length
  5084. });
  5085. },
  5086. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  5087. var chunk = args.chunk;
  5088. var isProgressive = args.begin === undefined;
  5089. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  5090. var end = begin + chunk.byteLength;
  5091. var beginChunk = Math.floor(begin / this.chunkSize);
  5092. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  5093. Math.ceil(end / this.chunkSize);
  5094. if (isProgressive) {
  5095. this.stream.onReceiveProgressiveData(chunk);
  5096. this.progressiveDataLength = end;
  5097. } else {
  5098. this.stream.onReceiveData(begin, chunk);
  5099. }
  5100. if (this.stream.allChunksLoaded()) {
  5101. this._loadedStreamCapability.resolve(this.stream);
  5102. }
  5103. var loadedRequests = [];
  5104. var i, requestId;
  5105. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  5106. // The server might return more chunks than requested
  5107. var requestIds = this.requestsByChunk[chunk] || [];
  5108. delete this.requestsByChunk[chunk];
  5109. for (i = 0; i < requestIds.length; ++i) {
  5110. requestId = requestIds[i];
  5111. var chunksNeeded = this.chunksNeededByRequest[requestId];
  5112. if (chunk in chunksNeeded) {
  5113. delete chunksNeeded[chunk];
  5114. }
  5115. if (!isEmptyObj(chunksNeeded)) {
  5116. continue;
  5117. }
  5118. loadedRequests.push(requestId);
  5119. }
  5120. }
  5121. // If there are no pending requests, automatically fetch the next
  5122. // unfetched chunk of the PDF
  5123. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  5124. var nextEmptyChunk;
  5125. if (this.stream.numChunksLoaded === 1) {
  5126. // This is a special optimization so that after fetching the first
  5127. // chunk, rather than fetching the second chunk, we fetch the last
  5128. // chunk.
  5129. var lastChunk = this.stream.numChunks - 1;
  5130. if (!this.stream.hasChunk(lastChunk)) {
  5131. nextEmptyChunk = lastChunk;
  5132. }
  5133. } else {
  5134. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  5135. }
  5136. if (isInt(nextEmptyChunk)) {
  5137. this._requestChunks([nextEmptyChunk]);
  5138. }
  5139. }
  5140. for (i = 0; i < loadedRequests.length; ++i) {
  5141. requestId = loadedRequests[i];
  5142. var capability = this.promisesByRequest[requestId];
  5143. delete this.promisesByRequest[requestId];
  5144. capability.resolve();
  5145. }
  5146. this.msgHandler.send('DocProgress', {
  5147. loaded: this.stream.numChunksLoaded * this.chunkSize,
  5148. total: this.length
  5149. });
  5150. },
  5151. onError: function ChunkedStreamManager_onError(err) {
  5152. this._loadedStreamCapability.reject(err);
  5153. },
  5154. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  5155. var chunk = Math.floor(begin / this.chunkSize);
  5156. return chunk;
  5157. },
  5158. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  5159. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  5160. return chunk;
  5161. },
  5162. abort: function ChunkedStreamManager_abort() {
  5163. this.aborted = true;
  5164. if (this.pdfNetworkStream) {
  5165. this.pdfNetworkStream.cancelAllRequests('abort');
  5166. }
  5167. for(var requestId in this.promisesByRequest) {
  5168. var capability = this.promisesByRequest[requestId];
  5169. capability.reject(new Error('Request was aborted'));
  5170. }
  5171. }
  5172. };
  5173. return ChunkedStreamManager;
  5174. })();
  5175. exports.ChunkedStream = ChunkedStream;
  5176. exports.ChunkedStreamManager = ChunkedStreamManager;
  5177. }));
  5178. (function (root, factory) {
  5179. {
  5180. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  5181. }
  5182. }(this, function (exports, sharedUtil) {
  5183. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  5184. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  5185. t['A'] = 0x0041;
  5186. t['AE'] = 0x00C6;
  5187. t['AEacute'] = 0x01FC;
  5188. t['AEmacron'] = 0x01E2;
  5189. t['AEsmall'] = 0xF7E6;
  5190. t['Aacute'] = 0x00C1;
  5191. t['Aacutesmall'] = 0xF7E1;
  5192. t['Abreve'] = 0x0102;
  5193. t['Abreveacute'] = 0x1EAE;
  5194. t['Abrevecyrillic'] = 0x04D0;
  5195. t['Abrevedotbelow'] = 0x1EB6;
  5196. t['Abrevegrave'] = 0x1EB0;
  5197. t['Abrevehookabove'] = 0x1EB2;
  5198. t['Abrevetilde'] = 0x1EB4;
  5199. t['Acaron'] = 0x01CD;
  5200. t['Acircle'] = 0x24B6;
  5201. t['Acircumflex'] = 0x00C2;
  5202. t['Acircumflexacute'] = 0x1EA4;
  5203. t['Acircumflexdotbelow'] = 0x1EAC;
  5204. t['Acircumflexgrave'] = 0x1EA6;
  5205. t['Acircumflexhookabove'] = 0x1EA8;
  5206. t['Acircumflexsmall'] = 0xF7E2;
  5207. t['Acircumflextilde'] = 0x1EAA;
  5208. t['Acute'] = 0xF6C9;
  5209. t['Acutesmall'] = 0xF7B4;
  5210. t['Acyrillic'] = 0x0410;
  5211. t['Adblgrave'] = 0x0200;
  5212. t['Adieresis'] = 0x00C4;
  5213. t['Adieresiscyrillic'] = 0x04D2;
  5214. t['Adieresismacron'] = 0x01DE;
  5215. t['Adieresissmall'] = 0xF7E4;
  5216. t['Adotbelow'] = 0x1EA0;
  5217. t['Adotmacron'] = 0x01E0;
  5218. t['Agrave'] = 0x00C0;
  5219. t['Agravesmall'] = 0xF7E0;
  5220. t['Ahookabove'] = 0x1EA2;
  5221. t['Aiecyrillic'] = 0x04D4;
  5222. t['Ainvertedbreve'] = 0x0202;
  5223. t['Alpha'] = 0x0391;
  5224. t['Alphatonos'] = 0x0386;
  5225. t['Amacron'] = 0x0100;
  5226. t['Amonospace'] = 0xFF21;
  5227. t['Aogonek'] = 0x0104;
  5228. t['Aring'] = 0x00C5;
  5229. t['Aringacute'] = 0x01FA;
  5230. t['Aringbelow'] = 0x1E00;
  5231. t['Aringsmall'] = 0xF7E5;
  5232. t['Asmall'] = 0xF761;
  5233. t['Atilde'] = 0x00C3;
  5234. t['Atildesmall'] = 0xF7E3;
  5235. t['Aybarmenian'] = 0x0531;
  5236. t['B'] = 0x0042;
  5237. t['Bcircle'] = 0x24B7;
  5238. t['Bdotaccent'] = 0x1E02;
  5239. t['Bdotbelow'] = 0x1E04;
  5240. t['Becyrillic'] = 0x0411;
  5241. t['Benarmenian'] = 0x0532;
  5242. t['Beta'] = 0x0392;
  5243. t['Bhook'] = 0x0181;
  5244. t['Blinebelow'] = 0x1E06;
  5245. t['Bmonospace'] = 0xFF22;
  5246. t['Brevesmall'] = 0xF6F4;
  5247. t['Bsmall'] = 0xF762;
  5248. t['Btopbar'] = 0x0182;
  5249. t['C'] = 0x0043;
  5250. t['Caarmenian'] = 0x053E;
  5251. t['Cacute'] = 0x0106;
  5252. t['Caron'] = 0xF6CA;
  5253. t['Caronsmall'] = 0xF6F5;
  5254. t['Ccaron'] = 0x010C;
  5255. t['Ccedilla'] = 0x00C7;
  5256. t['Ccedillaacute'] = 0x1E08;
  5257. t['Ccedillasmall'] = 0xF7E7;
  5258. t['Ccircle'] = 0x24B8;
  5259. t['Ccircumflex'] = 0x0108;
  5260. t['Cdot'] = 0x010A;
  5261. t['Cdotaccent'] = 0x010A;
  5262. t['Cedillasmall'] = 0xF7B8;
  5263. t['Chaarmenian'] = 0x0549;
  5264. t['Cheabkhasiancyrillic'] = 0x04BC;
  5265. t['Checyrillic'] = 0x0427;
  5266. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  5267. t['Chedescendercyrillic'] = 0x04B6;
  5268. t['Chedieresiscyrillic'] = 0x04F4;
  5269. t['Cheharmenian'] = 0x0543;
  5270. t['Chekhakassiancyrillic'] = 0x04CB;
  5271. t['Cheverticalstrokecyrillic'] = 0x04B8;
  5272. t['Chi'] = 0x03A7;
  5273. t['Chook'] = 0x0187;
  5274. t['Circumflexsmall'] = 0xF6F6;
  5275. t['Cmonospace'] = 0xFF23;
  5276. t['Coarmenian'] = 0x0551;
  5277. t['Csmall'] = 0xF763;
  5278. t['D'] = 0x0044;
  5279. t['DZ'] = 0x01F1;
  5280. t['DZcaron'] = 0x01C4;
  5281. t['Daarmenian'] = 0x0534;
  5282. t['Dafrican'] = 0x0189;
  5283. t['Dcaron'] = 0x010E;
  5284. t['Dcedilla'] = 0x1E10;
  5285. t['Dcircle'] = 0x24B9;
  5286. t['Dcircumflexbelow'] = 0x1E12;
  5287. t['Dcroat'] = 0x0110;
  5288. t['Ddotaccent'] = 0x1E0A;
  5289. t['Ddotbelow'] = 0x1E0C;
  5290. t['Decyrillic'] = 0x0414;
  5291. t['Deicoptic'] = 0x03EE;
  5292. t['Delta'] = 0x2206;
  5293. t['Deltagreek'] = 0x0394;
  5294. t['Dhook'] = 0x018A;
  5295. t['Dieresis'] = 0xF6CB;
  5296. t['DieresisAcute'] = 0xF6CC;
  5297. t['DieresisGrave'] = 0xF6CD;
  5298. t['Dieresissmall'] = 0xF7A8;
  5299. t['Digammagreek'] = 0x03DC;
  5300. t['Djecyrillic'] = 0x0402;
  5301. t['Dlinebelow'] = 0x1E0E;
  5302. t['Dmonospace'] = 0xFF24;
  5303. t['Dotaccentsmall'] = 0xF6F7;
  5304. t['Dslash'] = 0x0110;
  5305. t['Dsmall'] = 0xF764;
  5306. t['Dtopbar'] = 0x018B;
  5307. t['Dz'] = 0x01F2;
  5308. t['Dzcaron'] = 0x01C5;
  5309. t['Dzeabkhasiancyrillic'] = 0x04E0;
  5310. t['Dzecyrillic'] = 0x0405;
  5311. t['Dzhecyrillic'] = 0x040F;
  5312. t['E'] = 0x0045;
  5313. t['Eacute'] = 0x00C9;
  5314. t['Eacutesmall'] = 0xF7E9;
  5315. t['Ebreve'] = 0x0114;
  5316. t['Ecaron'] = 0x011A;
  5317. t['Ecedillabreve'] = 0x1E1C;
  5318. t['Echarmenian'] = 0x0535;
  5319. t['Ecircle'] = 0x24BA;
  5320. t['Ecircumflex'] = 0x00CA;
  5321. t['Ecircumflexacute'] = 0x1EBE;
  5322. t['Ecircumflexbelow'] = 0x1E18;
  5323. t['Ecircumflexdotbelow'] = 0x1EC6;
  5324. t['Ecircumflexgrave'] = 0x1EC0;
  5325. t['Ecircumflexhookabove'] = 0x1EC2;
  5326. t['Ecircumflexsmall'] = 0xF7EA;
  5327. t['Ecircumflextilde'] = 0x1EC4;
  5328. t['Ecyrillic'] = 0x0404;
  5329. t['Edblgrave'] = 0x0204;
  5330. t['Edieresis'] = 0x00CB;
  5331. t['Edieresissmall'] = 0xF7EB;
  5332. t['Edot'] = 0x0116;
  5333. t['Edotaccent'] = 0x0116;
  5334. t['Edotbelow'] = 0x1EB8;
  5335. t['Efcyrillic'] = 0x0424;
  5336. t['Egrave'] = 0x00C8;
  5337. t['Egravesmall'] = 0xF7E8;
  5338. t['Eharmenian'] = 0x0537;
  5339. t['Ehookabove'] = 0x1EBA;
  5340. t['Eightroman'] = 0x2167;
  5341. t['Einvertedbreve'] = 0x0206;
  5342. t['Eiotifiedcyrillic'] = 0x0464;
  5343. t['Elcyrillic'] = 0x041B;
  5344. t['Elevenroman'] = 0x216A;
  5345. t['Emacron'] = 0x0112;
  5346. t['Emacronacute'] = 0x1E16;
  5347. t['Emacrongrave'] = 0x1E14;
  5348. t['Emcyrillic'] = 0x041C;
  5349. t['Emonospace'] = 0xFF25;
  5350. t['Encyrillic'] = 0x041D;
  5351. t['Endescendercyrillic'] = 0x04A2;
  5352. t['Eng'] = 0x014A;
  5353. t['Enghecyrillic'] = 0x04A4;
  5354. t['Enhookcyrillic'] = 0x04C7;
  5355. t['Eogonek'] = 0x0118;
  5356. t['Eopen'] = 0x0190;
  5357. t['Epsilon'] = 0x0395;
  5358. t['Epsilontonos'] = 0x0388;
  5359. t['Ercyrillic'] = 0x0420;
  5360. t['Ereversed'] = 0x018E;
  5361. t['Ereversedcyrillic'] = 0x042D;
  5362. t['Escyrillic'] = 0x0421;
  5363. t['Esdescendercyrillic'] = 0x04AA;
  5364. t['Esh'] = 0x01A9;
  5365. t['Esmall'] = 0xF765;
  5366. t['Eta'] = 0x0397;
  5367. t['Etarmenian'] = 0x0538;
  5368. t['Etatonos'] = 0x0389;
  5369. t['Eth'] = 0x00D0;
  5370. t['Ethsmall'] = 0xF7F0;
  5371. t['Etilde'] = 0x1EBC;
  5372. t['Etildebelow'] = 0x1E1A;
  5373. t['Euro'] = 0x20AC;
  5374. t['Ezh'] = 0x01B7;
  5375. t['Ezhcaron'] = 0x01EE;
  5376. t['Ezhreversed'] = 0x01B8;
  5377. t['F'] = 0x0046;
  5378. t['Fcircle'] = 0x24BB;
  5379. t['Fdotaccent'] = 0x1E1E;
  5380. t['Feharmenian'] = 0x0556;
  5381. t['Feicoptic'] = 0x03E4;
  5382. t['Fhook'] = 0x0191;
  5383. t['Fitacyrillic'] = 0x0472;
  5384. t['Fiveroman'] = 0x2164;
  5385. t['Fmonospace'] = 0xFF26;
  5386. t['Fourroman'] = 0x2163;
  5387. t['Fsmall'] = 0xF766;
  5388. t['G'] = 0x0047;
  5389. t['GBsquare'] = 0x3387;
  5390. t['Gacute'] = 0x01F4;
  5391. t['Gamma'] = 0x0393;
  5392. t['Gammaafrican'] = 0x0194;
  5393. t['Gangiacoptic'] = 0x03EA;
  5394. t['Gbreve'] = 0x011E;
  5395. t['Gcaron'] = 0x01E6;
  5396. t['Gcedilla'] = 0x0122;
  5397. t['Gcircle'] = 0x24BC;
  5398. t['Gcircumflex'] = 0x011C;
  5399. t['Gcommaaccent'] = 0x0122;
  5400. t['Gdot'] = 0x0120;
  5401. t['Gdotaccent'] = 0x0120;
  5402. t['Gecyrillic'] = 0x0413;
  5403. t['Ghadarmenian'] = 0x0542;
  5404. t['Ghemiddlehookcyrillic'] = 0x0494;
  5405. t['Ghestrokecyrillic'] = 0x0492;
  5406. t['Gheupturncyrillic'] = 0x0490;
  5407. t['Ghook'] = 0x0193;
  5408. t['Gimarmenian'] = 0x0533;
  5409. t['Gjecyrillic'] = 0x0403;
  5410. t['Gmacron'] = 0x1E20;
  5411. t['Gmonospace'] = 0xFF27;
  5412. t['Grave'] = 0xF6CE;
  5413. t['Gravesmall'] = 0xF760;
  5414. t['Gsmall'] = 0xF767;
  5415. t['Gsmallhook'] = 0x029B;
  5416. t['Gstroke'] = 0x01E4;
  5417. t['H'] = 0x0048;
  5418. t['H18533'] = 0x25CF;
  5419. t['H18543'] = 0x25AA;
  5420. t['H18551'] = 0x25AB;
  5421. t['H22073'] = 0x25A1;
  5422. t['HPsquare'] = 0x33CB;
  5423. t['Haabkhasiancyrillic'] = 0x04A8;
  5424. t['Hadescendercyrillic'] = 0x04B2;
  5425. t['Hardsigncyrillic'] = 0x042A;
  5426. t['Hbar'] = 0x0126;
  5427. t['Hbrevebelow'] = 0x1E2A;
  5428. t['Hcedilla'] = 0x1E28;
  5429. t['Hcircle'] = 0x24BD;
  5430. t['Hcircumflex'] = 0x0124;
  5431. t['Hdieresis'] = 0x1E26;
  5432. t['Hdotaccent'] = 0x1E22;
  5433. t['Hdotbelow'] = 0x1E24;
  5434. t['Hmonospace'] = 0xFF28;
  5435. t['Hoarmenian'] = 0x0540;
  5436. t['Horicoptic'] = 0x03E8;
  5437. t['Hsmall'] = 0xF768;
  5438. t['Hungarumlaut'] = 0xF6CF;
  5439. t['Hungarumlautsmall'] = 0xF6F8;
  5440. t['Hzsquare'] = 0x3390;
  5441. t['I'] = 0x0049;
  5442. t['IAcyrillic'] = 0x042F;
  5443. t['IJ'] = 0x0132;
  5444. t['IUcyrillic'] = 0x042E;
  5445. t['Iacute'] = 0x00CD;
  5446. t['Iacutesmall'] = 0xF7ED;
  5447. t['Ibreve'] = 0x012C;
  5448. t['Icaron'] = 0x01CF;
  5449. t['Icircle'] = 0x24BE;
  5450. t['Icircumflex'] = 0x00CE;
  5451. t['Icircumflexsmall'] = 0xF7EE;
  5452. t['Icyrillic'] = 0x0406;
  5453. t['Idblgrave'] = 0x0208;
  5454. t['Idieresis'] = 0x00CF;
  5455. t['Idieresisacute'] = 0x1E2E;
  5456. t['Idieresiscyrillic'] = 0x04E4;
  5457. t['Idieresissmall'] = 0xF7EF;
  5458. t['Idot'] = 0x0130;
  5459. t['Idotaccent'] = 0x0130;
  5460. t['Idotbelow'] = 0x1ECA;
  5461. t['Iebrevecyrillic'] = 0x04D6;
  5462. t['Iecyrillic'] = 0x0415;
  5463. t['Ifraktur'] = 0x2111;
  5464. t['Igrave'] = 0x00CC;
  5465. t['Igravesmall'] = 0xF7EC;
  5466. t['Ihookabove'] = 0x1EC8;
  5467. t['Iicyrillic'] = 0x0418;
  5468. t['Iinvertedbreve'] = 0x020A;
  5469. t['Iishortcyrillic'] = 0x0419;
  5470. t['Imacron'] = 0x012A;
  5471. t['Imacroncyrillic'] = 0x04E2;
  5472. t['Imonospace'] = 0xFF29;
  5473. t['Iniarmenian'] = 0x053B;
  5474. t['Iocyrillic'] = 0x0401;
  5475. t['Iogonek'] = 0x012E;
  5476. t['Iota'] = 0x0399;
  5477. t['Iotaafrican'] = 0x0196;
  5478. t['Iotadieresis'] = 0x03AA;
  5479. t['Iotatonos'] = 0x038A;
  5480. t['Ismall'] = 0xF769;
  5481. t['Istroke'] = 0x0197;
  5482. t['Itilde'] = 0x0128;
  5483. t['Itildebelow'] = 0x1E2C;
  5484. t['Izhitsacyrillic'] = 0x0474;
  5485. t['Izhitsadblgravecyrillic'] = 0x0476;
  5486. t['J'] = 0x004A;
  5487. t['Jaarmenian'] = 0x0541;
  5488. t['Jcircle'] = 0x24BF;
  5489. t['Jcircumflex'] = 0x0134;
  5490. t['Jecyrillic'] = 0x0408;
  5491. t['Jheharmenian'] = 0x054B;
  5492. t['Jmonospace'] = 0xFF2A;
  5493. t['Jsmall'] = 0xF76A;
  5494. t['K'] = 0x004B;
  5495. t['KBsquare'] = 0x3385;
  5496. t['KKsquare'] = 0x33CD;
  5497. t['Kabashkircyrillic'] = 0x04A0;
  5498. t['Kacute'] = 0x1E30;
  5499. t['Kacyrillic'] = 0x041A;
  5500. t['Kadescendercyrillic'] = 0x049A;
  5501. t['Kahookcyrillic'] = 0x04C3;
  5502. t['Kappa'] = 0x039A;
  5503. t['Kastrokecyrillic'] = 0x049E;
  5504. t['Kaverticalstrokecyrillic'] = 0x049C;
  5505. t['Kcaron'] = 0x01E8;
  5506. t['Kcedilla'] = 0x0136;
  5507. t['Kcircle'] = 0x24C0;
  5508. t['Kcommaaccent'] = 0x0136;
  5509. t['Kdotbelow'] = 0x1E32;
  5510. t['Keharmenian'] = 0x0554;
  5511. t['Kenarmenian'] = 0x053F;
  5512. t['Khacyrillic'] = 0x0425;
  5513. t['Kheicoptic'] = 0x03E6;
  5514. t['Khook'] = 0x0198;
  5515. t['Kjecyrillic'] = 0x040C;
  5516. t['Klinebelow'] = 0x1E34;
  5517. t['Kmonospace'] = 0xFF2B;
  5518. t['Koppacyrillic'] = 0x0480;
  5519. t['Koppagreek'] = 0x03DE;
  5520. t['Ksicyrillic'] = 0x046E;
  5521. t['Ksmall'] = 0xF76B;
  5522. t['L'] = 0x004C;
  5523. t['LJ'] = 0x01C7;
  5524. t['LL'] = 0xF6BF;
  5525. t['Lacute'] = 0x0139;
  5526. t['Lambda'] = 0x039B;
  5527. t['Lcaron'] = 0x013D;
  5528. t['Lcedilla'] = 0x013B;
  5529. t['Lcircle'] = 0x24C1;
  5530. t['Lcircumflexbelow'] = 0x1E3C;
  5531. t['Lcommaaccent'] = 0x013B;
  5532. t['Ldot'] = 0x013F;
  5533. t['Ldotaccent'] = 0x013F;
  5534. t['Ldotbelow'] = 0x1E36;
  5535. t['Ldotbelowmacron'] = 0x1E38;
  5536. t['Liwnarmenian'] = 0x053C;
  5537. t['Lj'] = 0x01C8;
  5538. t['Ljecyrillic'] = 0x0409;
  5539. t['Llinebelow'] = 0x1E3A;
  5540. t['Lmonospace'] = 0xFF2C;
  5541. t['Lslash'] = 0x0141;
  5542. t['Lslashsmall'] = 0xF6F9;
  5543. t['Lsmall'] = 0xF76C;
  5544. t['M'] = 0x004D;
  5545. t['MBsquare'] = 0x3386;
  5546. t['Macron'] = 0xF6D0;
  5547. t['Macronsmall'] = 0xF7AF;
  5548. t['Macute'] = 0x1E3E;
  5549. t['Mcircle'] = 0x24C2;
  5550. t['Mdotaccent'] = 0x1E40;
  5551. t['Mdotbelow'] = 0x1E42;
  5552. t['Menarmenian'] = 0x0544;
  5553. t['Mmonospace'] = 0xFF2D;
  5554. t['Msmall'] = 0xF76D;
  5555. t['Mturned'] = 0x019C;
  5556. t['Mu'] = 0x039C;
  5557. t['N'] = 0x004E;
  5558. t['NJ'] = 0x01CA;
  5559. t['Nacute'] = 0x0143;
  5560. t['Ncaron'] = 0x0147;
  5561. t['Ncedilla'] = 0x0145;
  5562. t['Ncircle'] = 0x24C3;
  5563. t['Ncircumflexbelow'] = 0x1E4A;
  5564. t['Ncommaaccent'] = 0x0145;
  5565. t['Ndotaccent'] = 0x1E44;
  5566. t['Ndotbelow'] = 0x1E46;
  5567. t['Nhookleft'] = 0x019D;
  5568. t['Nineroman'] = 0x2168;
  5569. t['Nj'] = 0x01CB;
  5570. t['Njecyrillic'] = 0x040A;
  5571. t['Nlinebelow'] = 0x1E48;
  5572. t['Nmonospace'] = 0xFF2E;
  5573. t['Nowarmenian'] = 0x0546;
  5574. t['Nsmall'] = 0xF76E;
  5575. t['Ntilde'] = 0x00D1;
  5576. t['Ntildesmall'] = 0xF7F1;
  5577. t['Nu'] = 0x039D;
  5578. t['O'] = 0x004F;
  5579. t['OE'] = 0x0152;
  5580. t['OEsmall'] = 0xF6FA;
  5581. t['Oacute'] = 0x00D3;
  5582. t['Oacutesmall'] = 0xF7F3;
  5583. t['Obarredcyrillic'] = 0x04E8;
  5584. t['Obarreddieresiscyrillic'] = 0x04EA;
  5585. t['Obreve'] = 0x014E;
  5586. t['Ocaron'] = 0x01D1;
  5587. t['Ocenteredtilde'] = 0x019F;
  5588. t['Ocircle'] = 0x24C4;
  5589. t['Ocircumflex'] = 0x00D4;
  5590. t['Ocircumflexacute'] = 0x1ED0;
  5591. t['Ocircumflexdotbelow'] = 0x1ED8;
  5592. t['Ocircumflexgrave'] = 0x1ED2;
  5593. t['Ocircumflexhookabove'] = 0x1ED4;
  5594. t['Ocircumflexsmall'] = 0xF7F4;
  5595. t['Ocircumflextilde'] = 0x1ED6;
  5596. t['Ocyrillic'] = 0x041E;
  5597. t['Odblacute'] = 0x0150;
  5598. t['Odblgrave'] = 0x020C;
  5599. t['Odieresis'] = 0x00D6;
  5600. t['Odieresiscyrillic'] = 0x04E6;
  5601. t['Odieresissmall'] = 0xF7F6;
  5602. t['Odotbelow'] = 0x1ECC;
  5603. t['Ogoneksmall'] = 0xF6FB;
  5604. t['Ograve'] = 0x00D2;
  5605. t['Ogravesmall'] = 0xF7F2;
  5606. t['Oharmenian'] = 0x0555;
  5607. t['Ohm'] = 0x2126;
  5608. t['Ohookabove'] = 0x1ECE;
  5609. t['Ohorn'] = 0x01A0;
  5610. t['Ohornacute'] = 0x1EDA;
  5611. t['Ohorndotbelow'] = 0x1EE2;
  5612. t['Ohorngrave'] = 0x1EDC;
  5613. t['Ohornhookabove'] = 0x1EDE;
  5614. t['Ohorntilde'] = 0x1EE0;
  5615. t['Ohungarumlaut'] = 0x0150;
  5616. t['Oi'] = 0x01A2;
  5617. t['Oinvertedbreve'] = 0x020E;
  5618. t['Omacron'] = 0x014C;
  5619. t['Omacronacute'] = 0x1E52;
  5620. t['Omacrongrave'] = 0x1E50;
  5621. t['Omega'] = 0x2126;
  5622. t['Omegacyrillic'] = 0x0460;
  5623. t['Omegagreek'] = 0x03A9;
  5624. t['Omegaroundcyrillic'] = 0x047A;
  5625. t['Omegatitlocyrillic'] = 0x047C;
  5626. t['Omegatonos'] = 0x038F;
  5627. t['Omicron'] = 0x039F;
  5628. t['Omicrontonos'] = 0x038C;
  5629. t['Omonospace'] = 0xFF2F;
  5630. t['Oneroman'] = 0x2160;
  5631. t['Oogonek'] = 0x01EA;
  5632. t['Oogonekmacron'] = 0x01EC;
  5633. t['Oopen'] = 0x0186;
  5634. t['Oslash'] = 0x00D8;
  5635. t['Oslashacute'] = 0x01FE;
  5636. t['Oslashsmall'] = 0xF7F8;
  5637. t['Osmall'] = 0xF76F;
  5638. t['Ostrokeacute'] = 0x01FE;
  5639. t['Otcyrillic'] = 0x047E;
  5640. t['Otilde'] = 0x00D5;
  5641. t['Otildeacute'] = 0x1E4C;
  5642. t['Otildedieresis'] = 0x1E4E;
  5643. t['Otildesmall'] = 0xF7F5;
  5644. t['P'] = 0x0050;
  5645. t['Pacute'] = 0x1E54;
  5646. t['Pcircle'] = 0x24C5;
  5647. t['Pdotaccent'] = 0x1E56;
  5648. t['Pecyrillic'] = 0x041F;
  5649. t['Peharmenian'] = 0x054A;
  5650. t['Pemiddlehookcyrillic'] = 0x04A6;
  5651. t['Phi'] = 0x03A6;
  5652. t['Phook'] = 0x01A4;
  5653. t['Pi'] = 0x03A0;
  5654. t['Piwrarmenian'] = 0x0553;
  5655. t['Pmonospace'] = 0xFF30;
  5656. t['Psi'] = 0x03A8;
  5657. t['Psicyrillic'] = 0x0470;
  5658. t['Psmall'] = 0xF770;
  5659. t['Q'] = 0x0051;
  5660. t['Qcircle'] = 0x24C6;
  5661. t['Qmonospace'] = 0xFF31;
  5662. t['Qsmall'] = 0xF771;
  5663. t['R'] = 0x0052;
  5664. t['Raarmenian'] = 0x054C;
  5665. t['Racute'] = 0x0154;
  5666. t['Rcaron'] = 0x0158;
  5667. t['Rcedilla'] = 0x0156;
  5668. t['Rcircle'] = 0x24C7;
  5669. t['Rcommaaccent'] = 0x0156;
  5670. t['Rdblgrave'] = 0x0210;
  5671. t['Rdotaccent'] = 0x1E58;
  5672. t['Rdotbelow'] = 0x1E5A;
  5673. t['Rdotbelowmacron'] = 0x1E5C;
  5674. t['Reharmenian'] = 0x0550;
  5675. t['Rfraktur'] = 0x211C;
  5676. t['Rho'] = 0x03A1;
  5677. t['Ringsmall'] = 0xF6FC;
  5678. t['Rinvertedbreve'] = 0x0212;
  5679. t['Rlinebelow'] = 0x1E5E;
  5680. t['Rmonospace'] = 0xFF32;
  5681. t['Rsmall'] = 0xF772;
  5682. t['Rsmallinverted'] = 0x0281;
  5683. t['Rsmallinvertedsuperior'] = 0x02B6;
  5684. t['S'] = 0x0053;
  5685. t['SF010000'] = 0x250C;
  5686. t['SF020000'] = 0x2514;
  5687. t['SF030000'] = 0x2510;
  5688. t['SF040000'] = 0x2518;
  5689. t['SF050000'] = 0x253C;
  5690. t['SF060000'] = 0x252C;
  5691. t['SF070000'] = 0x2534;
  5692. t['SF080000'] = 0x251C;
  5693. t['SF090000'] = 0x2524;
  5694. t['SF100000'] = 0x2500;
  5695. t['SF110000'] = 0x2502;
  5696. t['SF190000'] = 0x2561;
  5697. t['SF200000'] = 0x2562;
  5698. t['SF210000'] = 0x2556;
  5699. t['SF220000'] = 0x2555;
  5700. t['SF230000'] = 0x2563;
  5701. t['SF240000'] = 0x2551;
  5702. t['SF250000'] = 0x2557;
  5703. t['SF260000'] = 0x255D;
  5704. t['SF270000'] = 0x255C;
  5705. t['SF280000'] = 0x255B;
  5706. t['SF360000'] = 0x255E;
  5707. t['SF370000'] = 0x255F;
  5708. t['SF380000'] = 0x255A;
  5709. t['SF390000'] = 0x2554;
  5710. t['SF400000'] = 0x2569;
  5711. t['SF410000'] = 0x2566;
  5712. t['SF420000'] = 0x2560;
  5713. t['SF430000'] = 0x2550;
  5714. t['SF440000'] = 0x256C;
  5715. t['SF450000'] = 0x2567;
  5716. t['SF460000'] = 0x2568;
  5717. t['SF470000'] = 0x2564;
  5718. t['SF480000'] = 0x2565;
  5719. t['SF490000'] = 0x2559;
  5720. t['SF500000'] = 0x2558;
  5721. t['SF510000'] = 0x2552;
  5722. t['SF520000'] = 0x2553;
  5723. t['SF530000'] = 0x256B;
  5724. t['SF540000'] = 0x256A;
  5725. t['Sacute'] = 0x015A;
  5726. t['Sacutedotaccent'] = 0x1E64;
  5727. t['Sampigreek'] = 0x03E0;
  5728. t['Scaron'] = 0x0160;
  5729. t['Scarondotaccent'] = 0x1E66;
  5730. t['Scaronsmall'] = 0xF6FD;
  5731. t['Scedilla'] = 0x015E;
  5732. t['Schwa'] = 0x018F;
  5733. t['Schwacyrillic'] = 0x04D8;
  5734. t['Schwadieresiscyrillic'] = 0x04DA;
  5735. t['Scircle'] = 0x24C8;
  5736. t['Scircumflex'] = 0x015C;
  5737. t['Scommaaccent'] = 0x0218;
  5738. t['Sdotaccent'] = 0x1E60;
  5739. t['Sdotbelow'] = 0x1E62;
  5740. t['Sdotbelowdotaccent'] = 0x1E68;
  5741. t['Seharmenian'] = 0x054D;
  5742. t['Sevenroman'] = 0x2166;
  5743. t['Shaarmenian'] = 0x0547;
  5744. t['Shacyrillic'] = 0x0428;
  5745. t['Shchacyrillic'] = 0x0429;
  5746. t['Sheicoptic'] = 0x03E2;
  5747. t['Shhacyrillic'] = 0x04BA;
  5748. t['Shimacoptic'] = 0x03EC;
  5749. t['Sigma'] = 0x03A3;
  5750. t['Sixroman'] = 0x2165;
  5751. t['Smonospace'] = 0xFF33;
  5752. t['Softsigncyrillic'] = 0x042C;
  5753. t['Ssmall'] = 0xF773;
  5754. t['Stigmagreek'] = 0x03DA;
  5755. t['T'] = 0x0054;
  5756. t['Tau'] = 0x03A4;
  5757. t['Tbar'] = 0x0166;
  5758. t['Tcaron'] = 0x0164;
  5759. t['Tcedilla'] = 0x0162;
  5760. t['Tcircle'] = 0x24C9;
  5761. t['Tcircumflexbelow'] = 0x1E70;
  5762. t['Tcommaaccent'] = 0x0162;
  5763. t['Tdotaccent'] = 0x1E6A;
  5764. t['Tdotbelow'] = 0x1E6C;
  5765. t['Tecyrillic'] = 0x0422;
  5766. t['Tedescendercyrillic'] = 0x04AC;
  5767. t['Tenroman'] = 0x2169;
  5768. t['Tetsecyrillic'] = 0x04B4;
  5769. t['Theta'] = 0x0398;
  5770. t['Thook'] = 0x01AC;
  5771. t['Thorn'] = 0x00DE;
  5772. t['Thornsmall'] = 0xF7FE;
  5773. t['Threeroman'] = 0x2162;
  5774. t['Tildesmall'] = 0xF6FE;
  5775. t['Tiwnarmenian'] = 0x054F;
  5776. t['Tlinebelow'] = 0x1E6E;
  5777. t['Tmonospace'] = 0xFF34;
  5778. t['Toarmenian'] = 0x0539;
  5779. t['Tonefive'] = 0x01BC;
  5780. t['Tonesix'] = 0x0184;
  5781. t['Tonetwo'] = 0x01A7;
  5782. t['Tretroflexhook'] = 0x01AE;
  5783. t['Tsecyrillic'] = 0x0426;
  5784. t['Tshecyrillic'] = 0x040B;
  5785. t['Tsmall'] = 0xF774;
  5786. t['Twelveroman'] = 0x216B;
  5787. t['Tworoman'] = 0x2161;
  5788. t['U'] = 0x0055;
  5789. t['Uacute'] = 0x00DA;
  5790. t['Uacutesmall'] = 0xF7FA;
  5791. t['Ubreve'] = 0x016C;
  5792. t['Ucaron'] = 0x01D3;
  5793. t['Ucircle'] = 0x24CA;
  5794. t['Ucircumflex'] = 0x00DB;
  5795. t['Ucircumflexbelow'] = 0x1E76;
  5796. t['Ucircumflexsmall'] = 0xF7FB;
  5797. t['Ucyrillic'] = 0x0423;
  5798. t['Udblacute'] = 0x0170;
  5799. t['Udblgrave'] = 0x0214;
  5800. t['Udieresis'] = 0x00DC;
  5801. t['Udieresisacute'] = 0x01D7;
  5802. t['Udieresisbelow'] = 0x1E72;
  5803. t['Udieresiscaron'] = 0x01D9;
  5804. t['Udieresiscyrillic'] = 0x04F0;
  5805. t['Udieresisgrave'] = 0x01DB;
  5806. t['Udieresismacron'] = 0x01D5;
  5807. t['Udieresissmall'] = 0xF7FC;
  5808. t['Udotbelow'] = 0x1EE4;
  5809. t['Ugrave'] = 0x00D9;
  5810. t['Ugravesmall'] = 0xF7F9;
  5811. t['Uhookabove'] = 0x1EE6;
  5812. t['Uhorn'] = 0x01AF;
  5813. t['Uhornacute'] = 0x1EE8;
  5814. t['Uhorndotbelow'] = 0x1EF0;
  5815. t['Uhorngrave'] = 0x1EEA;
  5816. t['Uhornhookabove'] = 0x1EEC;
  5817. t['Uhorntilde'] = 0x1EEE;
  5818. t['Uhungarumlaut'] = 0x0170;
  5819. t['Uhungarumlautcyrillic'] = 0x04F2;
  5820. t['Uinvertedbreve'] = 0x0216;
  5821. t['Ukcyrillic'] = 0x0478;
  5822. t['Umacron'] = 0x016A;
  5823. t['Umacroncyrillic'] = 0x04EE;
  5824. t['Umacrondieresis'] = 0x1E7A;
  5825. t['Umonospace'] = 0xFF35;
  5826. t['Uogonek'] = 0x0172;
  5827. t['Upsilon'] = 0x03A5;
  5828. t['Upsilon1'] = 0x03D2;
  5829. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  5830. t['Upsilonafrican'] = 0x01B1;
  5831. t['Upsilondieresis'] = 0x03AB;
  5832. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  5833. t['Upsilonhooksymbol'] = 0x03D2;
  5834. t['Upsilontonos'] = 0x038E;
  5835. t['Uring'] = 0x016E;
  5836. t['Ushortcyrillic'] = 0x040E;
  5837. t['Usmall'] = 0xF775;
  5838. t['Ustraightcyrillic'] = 0x04AE;
  5839. t['Ustraightstrokecyrillic'] = 0x04B0;
  5840. t['Utilde'] = 0x0168;
  5841. t['Utildeacute'] = 0x1E78;
  5842. t['Utildebelow'] = 0x1E74;
  5843. t['V'] = 0x0056;
  5844. t['Vcircle'] = 0x24CB;
  5845. t['Vdotbelow'] = 0x1E7E;
  5846. t['Vecyrillic'] = 0x0412;
  5847. t['Vewarmenian'] = 0x054E;
  5848. t['Vhook'] = 0x01B2;
  5849. t['Vmonospace'] = 0xFF36;
  5850. t['Voarmenian'] = 0x0548;
  5851. t['Vsmall'] = 0xF776;
  5852. t['Vtilde'] = 0x1E7C;
  5853. t['W'] = 0x0057;
  5854. t['Wacute'] = 0x1E82;
  5855. t['Wcircle'] = 0x24CC;
  5856. t['Wcircumflex'] = 0x0174;
  5857. t['Wdieresis'] = 0x1E84;
  5858. t['Wdotaccent'] = 0x1E86;
  5859. t['Wdotbelow'] = 0x1E88;
  5860. t['Wgrave'] = 0x1E80;
  5861. t['Wmonospace'] = 0xFF37;
  5862. t['Wsmall'] = 0xF777;
  5863. t['X'] = 0x0058;
  5864. t['Xcircle'] = 0x24CD;
  5865. t['Xdieresis'] = 0x1E8C;
  5866. t['Xdotaccent'] = 0x1E8A;
  5867. t['Xeharmenian'] = 0x053D;
  5868. t['Xi'] = 0x039E;
  5869. t['Xmonospace'] = 0xFF38;
  5870. t['Xsmall'] = 0xF778;
  5871. t['Y'] = 0x0059;
  5872. t['Yacute'] = 0x00DD;
  5873. t['Yacutesmall'] = 0xF7FD;
  5874. t['Yatcyrillic'] = 0x0462;
  5875. t['Ycircle'] = 0x24CE;
  5876. t['Ycircumflex'] = 0x0176;
  5877. t['Ydieresis'] = 0x0178;
  5878. t['Ydieresissmall'] = 0xF7FF;
  5879. t['Ydotaccent'] = 0x1E8E;
  5880. t['Ydotbelow'] = 0x1EF4;
  5881. t['Yericyrillic'] = 0x042B;
  5882. t['Yerudieresiscyrillic'] = 0x04F8;
  5883. t['Ygrave'] = 0x1EF2;
  5884. t['Yhook'] = 0x01B3;
  5885. t['Yhookabove'] = 0x1EF6;
  5886. t['Yiarmenian'] = 0x0545;
  5887. t['Yicyrillic'] = 0x0407;
  5888. t['Yiwnarmenian'] = 0x0552;
  5889. t['Ymonospace'] = 0xFF39;
  5890. t['Ysmall'] = 0xF779;
  5891. t['Ytilde'] = 0x1EF8;
  5892. t['Yusbigcyrillic'] = 0x046A;
  5893. t['Yusbigiotifiedcyrillic'] = 0x046C;
  5894. t['Yuslittlecyrillic'] = 0x0466;
  5895. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  5896. t['Z'] = 0x005A;
  5897. t['Zaarmenian'] = 0x0536;
  5898. t['Zacute'] = 0x0179;
  5899. t['Zcaron'] = 0x017D;
  5900. t['Zcaronsmall'] = 0xF6FF;
  5901. t['Zcircle'] = 0x24CF;
  5902. t['Zcircumflex'] = 0x1E90;
  5903. t['Zdot'] = 0x017B;
  5904. t['Zdotaccent'] = 0x017B;
  5905. t['Zdotbelow'] = 0x1E92;
  5906. t['Zecyrillic'] = 0x0417;
  5907. t['Zedescendercyrillic'] = 0x0498;
  5908. t['Zedieresiscyrillic'] = 0x04DE;
  5909. t['Zeta'] = 0x0396;
  5910. t['Zhearmenian'] = 0x053A;
  5911. t['Zhebrevecyrillic'] = 0x04C1;
  5912. t['Zhecyrillic'] = 0x0416;
  5913. t['Zhedescendercyrillic'] = 0x0496;
  5914. t['Zhedieresiscyrillic'] = 0x04DC;
  5915. t['Zlinebelow'] = 0x1E94;
  5916. t['Zmonospace'] = 0xFF3A;
  5917. t['Zsmall'] = 0xF77A;
  5918. t['Zstroke'] = 0x01B5;
  5919. t['a'] = 0x0061;
  5920. t['aabengali'] = 0x0986;
  5921. t['aacute'] = 0x00E1;
  5922. t['aadeva'] = 0x0906;
  5923. t['aagujarati'] = 0x0A86;
  5924. t['aagurmukhi'] = 0x0A06;
  5925. t['aamatragurmukhi'] = 0x0A3E;
  5926. t['aarusquare'] = 0x3303;
  5927. t['aavowelsignbengali'] = 0x09BE;
  5928. t['aavowelsigndeva'] = 0x093E;
  5929. t['aavowelsigngujarati'] = 0x0ABE;
  5930. t['abbreviationmarkarmenian'] = 0x055F;
  5931. t['abbreviationsigndeva'] = 0x0970;
  5932. t['abengali'] = 0x0985;
  5933. t['abopomofo'] = 0x311A;
  5934. t['abreve'] = 0x0103;
  5935. t['abreveacute'] = 0x1EAF;
  5936. t['abrevecyrillic'] = 0x04D1;
  5937. t['abrevedotbelow'] = 0x1EB7;
  5938. t['abrevegrave'] = 0x1EB1;
  5939. t['abrevehookabove'] = 0x1EB3;
  5940. t['abrevetilde'] = 0x1EB5;
  5941. t['acaron'] = 0x01CE;
  5942. t['acircle'] = 0x24D0;
  5943. t['acircumflex'] = 0x00E2;
  5944. t['acircumflexacute'] = 0x1EA5;
  5945. t['acircumflexdotbelow'] = 0x1EAD;
  5946. t['acircumflexgrave'] = 0x1EA7;
  5947. t['acircumflexhookabove'] = 0x1EA9;
  5948. t['acircumflextilde'] = 0x1EAB;
  5949. t['acute'] = 0x00B4;
  5950. t['acutebelowcmb'] = 0x0317;
  5951. t['acutecmb'] = 0x0301;
  5952. t['acutecomb'] = 0x0301;
  5953. t['acutedeva'] = 0x0954;
  5954. t['acutelowmod'] = 0x02CF;
  5955. t['acutetonecmb'] = 0x0341;
  5956. t['acyrillic'] = 0x0430;
  5957. t['adblgrave'] = 0x0201;
  5958. t['addakgurmukhi'] = 0x0A71;
  5959. t['adeva'] = 0x0905;
  5960. t['adieresis'] = 0x00E4;
  5961. t['adieresiscyrillic'] = 0x04D3;
  5962. t['adieresismacron'] = 0x01DF;
  5963. t['adotbelow'] = 0x1EA1;
  5964. t['adotmacron'] = 0x01E1;
  5965. t['ae'] = 0x00E6;
  5966. t['aeacute'] = 0x01FD;
  5967. t['aekorean'] = 0x3150;
  5968. t['aemacron'] = 0x01E3;
  5969. t['afii00208'] = 0x2015;
  5970. t['afii08941'] = 0x20A4;
  5971. t['afii10017'] = 0x0410;
  5972. t['afii10018'] = 0x0411;
  5973. t['afii10019'] = 0x0412;
  5974. t['afii10020'] = 0x0413;
  5975. t['afii10021'] = 0x0414;
  5976. t['afii10022'] = 0x0415;
  5977. t['afii10023'] = 0x0401;
  5978. t['afii10024'] = 0x0416;
  5979. t['afii10025'] = 0x0417;
  5980. t['afii10026'] = 0x0418;
  5981. t['afii10027'] = 0x0419;
  5982. t['afii10028'] = 0x041A;
  5983. t['afii10029'] = 0x041B;
  5984. t['afii10030'] = 0x041C;
  5985. t['afii10031'] = 0x041D;
  5986. t['afii10032'] = 0x041E;
  5987. t['afii10033'] = 0x041F;
  5988. t['afii10034'] = 0x0420;
  5989. t['afii10035'] = 0x0421;
  5990. t['afii10036'] = 0x0422;
  5991. t['afii10037'] = 0x0423;
  5992. t['afii10038'] = 0x0424;
  5993. t['afii10039'] = 0x0425;
  5994. t['afii10040'] = 0x0426;
  5995. t['afii10041'] = 0x0427;
  5996. t['afii10042'] = 0x0428;
  5997. t['afii10043'] = 0x0429;
  5998. t['afii10044'] = 0x042A;
  5999. t['afii10045'] = 0x042B;
  6000. t['afii10046'] = 0x042C;
  6001. t['afii10047'] = 0x042D;
  6002. t['afii10048'] = 0x042E;
  6003. t['afii10049'] = 0x042F;
  6004. t['afii10050'] = 0x0490;
  6005. t['afii10051'] = 0x0402;
  6006. t['afii10052'] = 0x0403;
  6007. t['afii10053'] = 0x0404;
  6008. t['afii10054'] = 0x0405;
  6009. t['afii10055'] = 0x0406;
  6010. t['afii10056'] = 0x0407;
  6011. t['afii10057'] = 0x0408;
  6012. t['afii10058'] = 0x0409;
  6013. t['afii10059'] = 0x040A;
  6014. t['afii10060'] = 0x040B;
  6015. t['afii10061'] = 0x040C;
  6016. t['afii10062'] = 0x040E;
  6017. t['afii10063'] = 0xF6C4;
  6018. t['afii10064'] = 0xF6C5;
  6019. t['afii10065'] = 0x0430;
  6020. t['afii10066'] = 0x0431;
  6021. t['afii10067'] = 0x0432;
  6022. t['afii10068'] = 0x0433;
  6023. t['afii10069'] = 0x0434;
  6024. t['afii10070'] = 0x0435;
  6025. t['afii10071'] = 0x0451;
  6026. t['afii10072'] = 0x0436;
  6027. t['afii10073'] = 0x0437;
  6028. t['afii10074'] = 0x0438;
  6029. t['afii10075'] = 0x0439;
  6030. t['afii10076'] = 0x043A;
  6031. t['afii10077'] = 0x043B;
  6032. t['afii10078'] = 0x043C;
  6033. t['afii10079'] = 0x043D;
  6034. t['afii10080'] = 0x043E;
  6035. t['afii10081'] = 0x043F;
  6036. t['afii10082'] = 0x0440;
  6037. t['afii10083'] = 0x0441;
  6038. t['afii10084'] = 0x0442;
  6039. t['afii10085'] = 0x0443;
  6040. t['afii10086'] = 0x0444;
  6041. t['afii10087'] = 0x0445;
  6042. t['afii10088'] = 0x0446;
  6043. t['afii10089'] = 0x0447;
  6044. t['afii10090'] = 0x0448;
  6045. t['afii10091'] = 0x0449;
  6046. t['afii10092'] = 0x044A;
  6047. t['afii10093'] = 0x044B;
  6048. t['afii10094'] = 0x044C;
  6049. t['afii10095'] = 0x044D;
  6050. t['afii10096'] = 0x044E;
  6051. t['afii10097'] = 0x044F;
  6052. t['afii10098'] = 0x0491;
  6053. t['afii10099'] = 0x0452;
  6054. t['afii10100'] = 0x0453;
  6055. t['afii10101'] = 0x0454;
  6056. t['afii10102'] = 0x0455;
  6057. t['afii10103'] = 0x0456;
  6058. t['afii10104'] = 0x0457;
  6059. t['afii10105'] = 0x0458;
  6060. t['afii10106'] = 0x0459;
  6061. t['afii10107'] = 0x045A;
  6062. t['afii10108'] = 0x045B;
  6063. t['afii10109'] = 0x045C;
  6064. t['afii10110'] = 0x045E;
  6065. t['afii10145'] = 0x040F;
  6066. t['afii10146'] = 0x0462;
  6067. t['afii10147'] = 0x0472;
  6068. t['afii10148'] = 0x0474;
  6069. t['afii10192'] = 0xF6C6;
  6070. t['afii10193'] = 0x045F;
  6071. t['afii10194'] = 0x0463;
  6072. t['afii10195'] = 0x0473;
  6073. t['afii10196'] = 0x0475;
  6074. t['afii10831'] = 0xF6C7;
  6075. t['afii10832'] = 0xF6C8;
  6076. t['afii10846'] = 0x04D9;
  6077. t['afii299'] = 0x200E;
  6078. t['afii300'] = 0x200F;
  6079. t['afii301'] = 0x200D;
  6080. t['afii57381'] = 0x066A;
  6081. t['afii57388'] = 0x060C;
  6082. t['afii57392'] = 0x0660;
  6083. t['afii57393'] = 0x0661;
  6084. t['afii57394'] = 0x0662;
  6085. t['afii57395'] = 0x0663;
  6086. t['afii57396'] = 0x0664;
  6087. t['afii57397'] = 0x0665;
  6088. t['afii57398'] = 0x0666;
  6089. t['afii57399'] = 0x0667;
  6090. t['afii57400'] = 0x0668;
  6091. t['afii57401'] = 0x0669;
  6092. t['afii57403'] = 0x061B;
  6093. t['afii57407'] = 0x061F;
  6094. t['afii57409'] = 0x0621;
  6095. t['afii57410'] = 0x0622;
  6096. t['afii57411'] = 0x0623;
  6097. t['afii57412'] = 0x0624;
  6098. t['afii57413'] = 0x0625;
  6099. t['afii57414'] = 0x0626;
  6100. t['afii57415'] = 0x0627;
  6101. t['afii57416'] = 0x0628;
  6102. t['afii57417'] = 0x0629;
  6103. t['afii57418'] = 0x062A;
  6104. t['afii57419'] = 0x062B;
  6105. t['afii57420'] = 0x062C;
  6106. t['afii57421'] = 0x062D;
  6107. t['afii57422'] = 0x062E;
  6108. t['afii57423'] = 0x062F;
  6109. t['afii57424'] = 0x0630;
  6110. t['afii57425'] = 0x0631;
  6111. t['afii57426'] = 0x0632;
  6112. t['afii57427'] = 0x0633;
  6113. t['afii57428'] = 0x0634;
  6114. t['afii57429'] = 0x0635;
  6115. t['afii57430'] = 0x0636;
  6116. t['afii57431'] = 0x0637;
  6117. t['afii57432'] = 0x0638;
  6118. t['afii57433'] = 0x0639;
  6119. t['afii57434'] = 0x063A;
  6120. t['afii57440'] = 0x0640;
  6121. t['afii57441'] = 0x0641;
  6122. t['afii57442'] = 0x0642;
  6123. t['afii57443'] = 0x0643;
  6124. t['afii57444'] = 0x0644;
  6125. t['afii57445'] = 0x0645;
  6126. t['afii57446'] = 0x0646;
  6127. t['afii57448'] = 0x0648;
  6128. t['afii57449'] = 0x0649;
  6129. t['afii57450'] = 0x064A;
  6130. t['afii57451'] = 0x064B;
  6131. t['afii57452'] = 0x064C;
  6132. t['afii57453'] = 0x064D;
  6133. t['afii57454'] = 0x064E;
  6134. t['afii57455'] = 0x064F;
  6135. t['afii57456'] = 0x0650;
  6136. t['afii57457'] = 0x0651;
  6137. t['afii57458'] = 0x0652;
  6138. t['afii57470'] = 0x0647;
  6139. t['afii57505'] = 0x06A4;
  6140. t['afii57506'] = 0x067E;
  6141. t['afii57507'] = 0x0686;
  6142. t['afii57508'] = 0x0698;
  6143. t['afii57509'] = 0x06AF;
  6144. t['afii57511'] = 0x0679;
  6145. t['afii57512'] = 0x0688;
  6146. t['afii57513'] = 0x0691;
  6147. t['afii57514'] = 0x06BA;
  6148. t['afii57519'] = 0x06D2;
  6149. t['afii57534'] = 0x06D5;
  6150. t['afii57636'] = 0x20AA;
  6151. t['afii57645'] = 0x05BE;
  6152. t['afii57658'] = 0x05C3;
  6153. t['afii57664'] = 0x05D0;
  6154. t['afii57665'] = 0x05D1;
  6155. t['afii57666'] = 0x05D2;
  6156. t['afii57667'] = 0x05D3;
  6157. t['afii57668'] = 0x05D4;
  6158. t['afii57669'] = 0x05D5;
  6159. t['afii57670'] = 0x05D6;
  6160. t['afii57671'] = 0x05D7;
  6161. t['afii57672'] = 0x05D8;
  6162. t['afii57673'] = 0x05D9;
  6163. t['afii57674'] = 0x05DA;
  6164. t['afii57675'] = 0x05DB;
  6165. t['afii57676'] = 0x05DC;
  6166. t['afii57677'] = 0x05DD;
  6167. t['afii57678'] = 0x05DE;
  6168. t['afii57679'] = 0x05DF;
  6169. t['afii57680'] = 0x05E0;
  6170. t['afii57681'] = 0x05E1;
  6171. t['afii57682'] = 0x05E2;
  6172. t['afii57683'] = 0x05E3;
  6173. t['afii57684'] = 0x05E4;
  6174. t['afii57685'] = 0x05E5;
  6175. t['afii57686'] = 0x05E6;
  6176. t['afii57687'] = 0x05E7;
  6177. t['afii57688'] = 0x05E8;
  6178. t['afii57689'] = 0x05E9;
  6179. t['afii57690'] = 0x05EA;
  6180. t['afii57694'] = 0xFB2A;
  6181. t['afii57695'] = 0xFB2B;
  6182. t['afii57700'] = 0xFB4B;
  6183. t['afii57705'] = 0xFB1F;
  6184. t['afii57716'] = 0x05F0;
  6185. t['afii57717'] = 0x05F1;
  6186. t['afii57718'] = 0x05F2;
  6187. t['afii57723'] = 0xFB35;
  6188. t['afii57793'] = 0x05B4;
  6189. t['afii57794'] = 0x05B5;
  6190. t['afii57795'] = 0x05B6;
  6191. t['afii57796'] = 0x05BB;
  6192. t['afii57797'] = 0x05B8;
  6193. t['afii57798'] = 0x05B7;
  6194. t['afii57799'] = 0x05B0;
  6195. t['afii57800'] = 0x05B2;
  6196. t['afii57801'] = 0x05B1;
  6197. t['afii57802'] = 0x05B3;
  6198. t['afii57803'] = 0x05C2;
  6199. t['afii57804'] = 0x05C1;
  6200. t['afii57806'] = 0x05B9;
  6201. t['afii57807'] = 0x05BC;
  6202. t['afii57839'] = 0x05BD;
  6203. t['afii57841'] = 0x05BF;
  6204. t['afii57842'] = 0x05C0;
  6205. t['afii57929'] = 0x02BC;
  6206. t['afii61248'] = 0x2105;
  6207. t['afii61289'] = 0x2113;
  6208. t['afii61352'] = 0x2116;
  6209. t['afii61573'] = 0x202C;
  6210. t['afii61574'] = 0x202D;
  6211. t['afii61575'] = 0x202E;
  6212. t['afii61664'] = 0x200C;
  6213. t['afii63167'] = 0x066D;
  6214. t['afii64937'] = 0x02BD;
  6215. t['agrave'] = 0x00E0;
  6216. t['agujarati'] = 0x0A85;
  6217. t['agurmukhi'] = 0x0A05;
  6218. t['ahiragana'] = 0x3042;
  6219. t['ahookabove'] = 0x1EA3;
  6220. t['aibengali'] = 0x0990;
  6221. t['aibopomofo'] = 0x311E;
  6222. t['aideva'] = 0x0910;
  6223. t['aiecyrillic'] = 0x04D5;
  6224. t['aigujarati'] = 0x0A90;
  6225. t['aigurmukhi'] = 0x0A10;
  6226. t['aimatragurmukhi'] = 0x0A48;
  6227. t['ainarabic'] = 0x0639;
  6228. t['ainfinalarabic'] = 0xFECA;
  6229. t['aininitialarabic'] = 0xFECB;
  6230. t['ainmedialarabic'] = 0xFECC;
  6231. t['ainvertedbreve'] = 0x0203;
  6232. t['aivowelsignbengali'] = 0x09C8;
  6233. t['aivowelsigndeva'] = 0x0948;
  6234. t['aivowelsigngujarati'] = 0x0AC8;
  6235. t['akatakana'] = 0x30A2;
  6236. t['akatakanahalfwidth'] = 0xFF71;
  6237. t['akorean'] = 0x314F;
  6238. t['alef'] = 0x05D0;
  6239. t['alefarabic'] = 0x0627;
  6240. t['alefdageshhebrew'] = 0xFB30;
  6241. t['aleffinalarabic'] = 0xFE8E;
  6242. t['alefhamzaabovearabic'] = 0x0623;
  6243. t['alefhamzaabovefinalarabic'] = 0xFE84;
  6244. t['alefhamzabelowarabic'] = 0x0625;
  6245. t['alefhamzabelowfinalarabic'] = 0xFE88;
  6246. t['alefhebrew'] = 0x05D0;
  6247. t['aleflamedhebrew'] = 0xFB4F;
  6248. t['alefmaddaabovearabic'] = 0x0622;
  6249. t['alefmaddaabovefinalarabic'] = 0xFE82;
  6250. t['alefmaksuraarabic'] = 0x0649;
  6251. t['alefmaksurafinalarabic'] = 0xFEF0;
  6252. t['alefmaksurainitialarabic'] = 0xFEF3;
  6253. t['alefmaksuramedialarabic'] = 0xFEF4;
  6254. t['alefpatahhebrew'] = 0xFB2E;
  6255. t['alefqamatshebrew'] = 0xFB2F;
  6256. t['aleph'] = 0x2135;
  6257. t['allequal'] = 0x224C;
  6258. t['alpha'] = 0x03B1;
  6259. t['alphatonos'] = 0x03AC;
  6260. t['amacron'] = 0x0101;
  6261. t['amonospace'] = 0xFF41;
  6262. t['ampersand'] = 0x0026;
  6263. t['ampersandmonospace'] = 0xFF06;
  6264. t['ampersandsmall'] = 0xF726;
  6265. t['amsquare'] = 0x33C2;
  6266. t['anbopomofo'] = 0x3122;
  6267. t['angbopomofo'] = 0x3124;
  6268. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  6269. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  6270. t['angkhankhuthai'] = 0x0E5A;
  6271. t['angle'] = 0x2220;
  6272. t['anglebracketleft'] = 0x3008;
  6273. t['anglebracketleftvertical'] = 0xFE3F;
  6274. t['anglebracketright'] = 0x3009;
  6275. t['anglebracketrightvertical'] = 0xFE40;
  6276. t['angleleft'] = 0x2329;
  6277. t['angleright'] = 0x232A;
  6278. t['angstrom'] = 0x212B;
  6279. t['anoteleia'] = 0x0387;
  6280. t['anudattadeva'] = 0x0952;
  6281. t['anusvarabengali'] = 0x0982;
  6282. t['anusvaradeva'] = 0x0902;
  6283. t['anusvaragujarati'] = 0x0A82;
  6284. t['aogonek'] = 0x0105;
  6285. t['apaatosquare'] = 0x3300;
  6286. t['aparen'] = 0x249C;
  6287. t['apostrophearmenian'] = 0x055A;
  6288. t['apostrophemod'] = 0x02BC;
  6289. t['apple'] = 0xF8FF;
  6290. t['approaches'] = 0x2250;
  6291. t['approxequal'] = 0x2248;
  6292. t['approxequalorimage'] = 0x2252;
  6293. t['approximatelyequal'] = 0x2245;
  6294. t['araeaekorean'] = 0x318E;
  6295. t['araeakorean'] = 0x318D;
  6296. t['arc'] = 0x2312;
  6297. t['arighthalfring'] = 0x1E9A;
  6298. t['aring'] = 0x00E5;
  6299. t['aringacute'] = 0x01FB;
  6300. t['aringbelow'] = 0x1E01;
  6301. t['arrowboth'] = 0x2194;
  6302. t['arrowdashdown'] = 0x21E3;
  6303. t['arrowdashleft'] = 0x21E0;
  6304. t['arrowdashright'] = 0x21E2;
  6305. t['arrowdashup'] = 0x21E1;
  6306. t['arrowdblboth'] = 0x21D4;
  6307. t['arrowdbldown'] = 0x21D3;
  6308. t['arrowdblleft'] = 0x21D0;
  6309. t['arrowdblright'] = 0x21D2;
  6310. t['arrowdblup'] = 0x21D1;
  6311. t['arrowdown'] = 0x2193;
  6312. t['arrowdownleft'] = 0x2199;
  6313. t['arrowdownright'] = 0x2198;
  6314. t['arrowdownwhite'] = 0x21E9;
  6315. t['arrowheaddownmod'] = 0x02C5;
  6316. t['arrowheadleftmod'] = 0x02C2;
  6317. t['arrowheadrightmod'] = 0x02C3;
  6318. t['arrowheadupmod'] = 0x02C4;
  6319. t['arrowhorizex'] = 0xF8E7;
  6320. t['arrowleft'] = 0x2190;
  6321. t['arrowleftdbl'] = 0x21D0;
  6322. t['arrowleftdblstroke'] = 0x21CD;
  6323. t['arrowleftoverright'] = 0x21C6;
  6324. t['arrowleftwhite'] = 0x21E6;
  6325. t['arrowright'] = 0x2192;
  6326. t['arrowrightdblstroke'] = 0x21CF;
  6327. t['arrowrightheavy'] = 0x279E;
  6328. t['arrowrightoverleft'] = 0x21C4;
  6329. t['arrowrightwhite'] = 0x21E8;
  6330. t['arrowtableft'] = 0x21E4;
  6331. t['arrowtabright'] = 0x21E5;
  6332. t['arrowup'] = 0x2191;
  6333. t['arrowupdn'] = 0x2195;
  6334. t['arrowupdnbse'] = 0x21A8;
  6335. t['arrowupdownbase'] = 0x21A8;
  6336. t['arrowupleft'] = 0x2196;
  6337. t['arrowupleftofdown'] = 0x21C5;
  6338. t['arrowupright'] = 0x2197;
  6339. t['arrowupwhite'] = 0x21E7;
  6340. t['arrowvertex'] = 0xF8E6;
  6341. t['asciicircum'] = 0x005E;
  6342. t['asciicircummonospace'] = 0xFF3E;
  6343. t['asciitilde'] = 0x007E;
  6344. t['asciitildemonospace'] = 0xFF5E;
  6345. t['ascript'] = 0x0251;
  6346. t['ascriptturned'] = 0x0252;
  6347. t['asmallhiragana'] = 0x3041;
  6348. t['asmallkatakana'] = 0x30A1;
  6349. t['asmallkatakanahalfwidth'] = 0xFF67;
  6350. t['asterisk'] = 0x002A;
  6351. t['asteriskaltonearabic'] = 0x066D;
  6352. t['asteriskarabic'] = 0x066D;
  6353. t['asteriskmath'] = 0x2217;
  6354. t['asteriskmonospace'] = 0xFF0A;
  6355. t['asterisksmall'] = 0xFE61;
  6356. t['asterism'] = 0x2042;
  6357. t['asuperior'] = 0xF6E9;
  6358. t['asymptoticallyequal'] = 0x2243;
  6359. t['at'] = 0x0040;
  6360. t['atilde'] = 0x00E3;
  6361. t['atmonospace'] = 0xFF20;
  6362. t['atsmall'] = 0xFE6B;
  6363. t['aturned'] = 0x0250;
  6364. t['aubengali'] = 0x0994;
  6365. t['aubopomofo'] = 0x3120;
  6366. t['audeva'] = 0x0914;
  6367. t['augujarati'] = 0x0A94;
  6368. t['augurmukhi'] = 0x0A14;
  6369. t['aulengthmarkbengali'] = 0x09D7;
  6370. t['aumatragurmukhi'] = 0x0A4C;
  6371. t['auvowelsignbengali'] = 0x09CC;
  6372. t['auvowelsigndeva'] = 0x094C;
  6373. t['auvowelsigngujarati'] = 0x0ACC;
  6374. t['avagrahadeva'] = 0x093D;
  6375. t['aybarmenian'] = 0x0561;
  6376. t['ayin'] = 0x05E2;
  6377. t['ayinaltonehebrew'] = 0xFB20;
  6378. t['ayinhebrew'] = 0x05E2;
  6379. t['b'] = 0x0062;
  6380. t['babengali'] = 0x09AC;
  6381. t['backslash'] = 0x005C;
  6382. t['backslashmonospace'] = 0xFF3C;
  6383. t['badeva'] = 0x092C;
  6384. t['bagujarati'] = 0x0AAC;
  6385. t['bagurmukhi'] = 0x0A2C;
  6386. t['bahiragana'] = 0x3070;
  6387. t['bahtthai'] = 0x0E3F;
  6388. t['bakatakana'] = 0x30D0;
  6389. t['bar'] = 0x007C;
  6390. t['barmonospace'] = 0xFF5C;
  6391. t['bbopomofo'] = 0x3105;
  6392. t['bcircle'] = 0x24D1;
  6393. t['bdotaccent'] = 0x1E03;
  6394. t['bdotbelow'] = 0x1E05;
  6395. t['beamedsixteenthnotes'] = 0x266C;
  6396. t['because'] = 0x2235;
  6397. t['becyrillic'] = 0x0431;
  6398. t['beharabic'] = 0x0628;
  6399. t['behfinalarabic'] = 0xFE90;
  6400. t['behinitialarabic'] = 0xFE91;
  6401. t['behiragana'] = 0x3079;
  6402. t['behmedialarabic'] = 0xFE92;
  6403. t['behmeeminitialarabic'] = 0xFC9F;
  6404. t['behmeemisolatedarabic'] = 0xFC08;
  6405. t['behnoonfinalarabic'] = 0xFC6D;
  6406. t['bekatakana'] = 0x30D9;
  6407. t['benarmenian'] = 0x0562;
  6408. t['bet'] = 0x05D1;
  6409. t['beta'] = 0x03B2;
  6410. t['betasymbolgreek'] = 0x03D0;
  6411. t['betdagesh'] = 0xFB31;
  6412. t['betdageshhebrew'] = 0xFB31;
  6413. t['bethebrew'] = 0x05D1;
  6414. t['betrafehebrew'] = 0xFB4C;
  6415. t['bhabengali'] = 0x09AD;
  6416. t['bhadeva'] = 0x092D;
  6417. t['bhagujarati'] = 0x0AAD;
  6418. t['bhagurmukhi'] = 0x0A2D;
  6419. t['bhook'] = 0x0253;
  6420. t['bihiragana'] = 0x3073;
  6421. t['bikatakana'] = 0x30D3;
  6422. t['bilabialclick'] = 0x0298;
  6423. t['bindigurmukhi'] = 0x0A02;
  6424. t['birusquare'] = 0x3331;
  6425. t['blackcircle'] = 0x25CF;
  6426. t['blackdiamond'] = 0x25C6;
  6427. t['blackdownpointingtriangle'] = 0x25BC;
  6428. t['blackleftpointingpointer'] = 0x25C4;
  6429. t['blackleftpointingtriangle'] = 0x25C0;
  6430. t['blacklenticularbracketleft'] = 0x3010;
  6431. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  6432. t['blacklenticularbracketright'] = 0x3011;
  6433. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  6434. t['blacklowerlefttriangle'] = 0x25E3;
  6435. t['blacklowerrighttriangle'] = 0x25E2;
  6436. t['blackrectangle'] = 0x25AC;
  6437. t['blackrightpointingpointer'] = 0x25BA;
  6438. t['blackrightpointingtriangle'] = 0x25B6;
  6439. t['blacksmallsquare'] = 0x25AA;
  6440. t['blacksmilingface'] = 0x263B;
  6441. t['blacksquare'] = 0x25A0;
  6442. t['blackstar'] = 0x2605;
  6443. t['blackupperlefttriangle'] = 0x25E4;
  6444. t['blackupperrighttriangle'] = 0x25E5;
  6445. t['blackuppointingsmalltriangle'] = 0x25B4;
  6446. t['blackuppointingtriangle'] = 0x25B2;
  6447. t['blank'] = 0x2423;
  6448. t['blinebelow'] = 0x1E07;
  6449. t['block'] = 0x2588;
  6450. t['bmonospace'] = 0xFF42;
  6451. t['bobaimaithai'] = 0x0E1A;
  6452. t['bohiragana'] = 0x307C;
  6453. t['bokatakana'] = 0x30DC;
  6454. t['bparen'] = 0x249D;
  6455. t['bqsquare'] = 0x33C3;
  6456. t['braceex'] = 0xF8F4;
  6457. t['braceleft'] = 0x007B;
  6458. t['braceleftbt'] = 0xF8F3;
  6459. t['braceleftmid'] = 0xF8F2;
  6460. t['braceleftmonospace'] = 0xFF5B;
  6461. t['braceleftsmall'] = 0xFE5B;
  6462. t['bracelefttp'] = 0xF8F1;
  6463. t['braceleftvertical'] = 0xFE37;
  6464. t['braceright'] = 0x007D;
  6465. t['bracerightbt'] = 0xF8FE;
  6466. t['bracerightmid'] = 0xF8FD;
  6467. t['bracerightmonospace'] = 0xFF5D;
  6468. t['bracerightsmall'] = 0xFE5C;
  6469. t['bracerighttp'] = 0xF8FC;
  6470. t['bracerightvertical'] = 0xFE38;
  6471. t['bracketleft'] = 0x005B;
  6472. t['bracketleftbt'] = 0xF8F0;
  6473. t['bracketleftex'] = 0xF8EF;
  6474. t['bracketleftmonospace'] = 0xFF3B;
  6475. t['bracketlefttp'] = 0xF8EE;
  6476. t['bracketright'] = 0x005D;
  6477. t['bracketrightbt'] = 0xF8FB;
  6478. t['bracketrightex'] = 0xF8FA;
  6479. t['bracketrightmonospace'] = 0xFF3D;
  6480. t['bracketrighttp'] = 0xF8F9;
  6481. t['breve'] = 0x02D8;
  6482. t['brevebelowcmb'] = 0x032E;
  6483. t['brevecmb'] = 0x0306;
  6484. t['breveinvertedbelowcmb'] = 0x032F;
  6485. t['breveinvertedcmb'] = 0x0311;
  6486. t['breveinverteddoublecmb'] = 0x0361;
  6487. t['bridgebelowcmb'] = 0x032A;
  6488. t['bridgeinvertedbelowcmb'] = 0x033A;
  6489. t['brokenbar'] = 0x00A6;
  6490. t['bstroke'] = 0x0180;
  6491. t['bsuperior'] = 0xF6EA;
  6492. t['btopbar'] = 0x0183;
  6493. t['buhiragana'] = 0x3076;
  6494. t['bukatakana'] = 0x30D6;
  6495. t['bullet'] = 0x2022;
  6496. t['bulletinverse'] = 0x25D8;
  6497. t['bulletoperator'] = 0x2219;
  6498. t['bullseye'] = 0x25CE;
  6499. t['c'] = 0x0063;
  6500. t['caarmenian'] = 0x056E;
  6501. t['cabengali'] = 0x099A;
  6502. t['cacute'] = 0x0107;
  6503. t['cadeva'] = 0x091A;
  6504. t['cagujarati'] = 0x0A9A;
  6505. t['cagurmukhi'] = 0x0A1A;
  6506. t['calsquare'] = 0x3388;
  6507. t['candrabindubengali'] = 0x0981;
  6508. t['candrabinducmb'] = 0x0310;
  6509. t['candrabindudeva'] = 0x0901;
  6510. t['candrabindugujarati'] = 0x0A81;
  6511. t['capslock'] = 0x21EA;
  6512. t['careof'] = 0x2105;
  6513. t['caron'] = 0x02C7;
  6514. t['caronbelowcmb'] = 0x032C;
  6515. t['caroncmb'] = 0x030C;
  6516. t['carriagereturn'] = 0x21B5;
  6517. t['cbopomofo'] = 0x3118;
  6518. t['ccaron'] = 0x010D;
  6519. t['ccedilla'] = 0x00E7;
  6520. t['ccedillaacute'] = 0x1E09;
  6521. t['ccircle'] = 0x24D2;
  6522. t['ccircumflex'] = 0x0109;
  6523. t['ccurl'] = 0x0255;
  6524. t['cdot'] = 0x010B;
  6525. t['cdotaccent'] = 0x010B;
  6526. t['cdsquare'] = 0x33C5;
  6527. t['cedilla'] = 0x00B8;
  6528. t['cedillacmb'] = 0x0327;
  6529. t['cent'] = 0x00A2;
  6530. t['centigrade'] = 0x2103;
  6531. t['centinferior'] = 0xF6DF;
  6532. t['centmonospace'] = 0xFFE0;
  6533. t['centoldstyle'] = 0xF7A2;
  6534. t['centsuperior'] = 0xF6E0;
  6535. t['chaarmenian'] = 0x0579;
  6536. t['chabengali'] = 0x099B;
  6537. t['chadeva'] = 0x091B;
  6538. t['chagujarati'] = 0x0A9B;
  6539. t['chagurmukhi'] = 0x0A1B;
  6540. t['chbopomofo'] = 0x3114;
  6541. t['cheabkhasiancyrillic'] = 0x04BD;
  6542. t['checkmark'] = 0x2713;
  6543. t['checyrillic'] = 0x0447;
  6544. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  6545. t['chedescendercyrillic'] = 0x04B7;
  6546. t['chedieresiscyrillic'] = 0x04F5;
  6547. t['cheharmenian'] = 0x0573;
  6548. t['chekhakassiancyrillic'] = 0x04CC;
  6549. t['cheverticalstrokecyrillic'] = 0x04B9;
  6550. t['chi'] = 0x03C7;
  6551. t['chieuchacirclekorean'] = 0x3277;
  6552. t['chieuchaparenkorean'] = 0x3217;
  6553. t['chieuchcirclekorean'] = 0x3269;
  6554. t['chieuchkorean'] = 0x314A;
  6555. t['chieuchparenkorean'] = 0x3209;
  6556. t['chochangthai'] = 0x0E0A;
  6557. t['chochanthai'] = 0x0E08;
  6558. t['chochingthai'] = 0x0E09;
  6559. t['chochoethai'] = 0x0E0C;
  6560. t['chook'] = 0x0188;
  6561. t['cieucacirclekorean'] = 0x3276;
  6562. t['cieucaparenkorean'] = 0x3216;
  6563. t['cieuccirclekorean'] = 0x3268;
  6564. t['cieuckorean'] = 0x3148;
  6565. t['cieucparenkorean'] = 0x3208;
  6566. t['cieucuparenkorean'] = 0x321C;
  6567. t['circle'] = 0x25CB;
  6568. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  6569. t['circlemultiply'] = 0x2297;
  6570. t['circleot'] = 0x2299;
  6571. t['circleplus'] = 0x2295;
  6572. t['circlepostalmark'] = 0x3036;
  6573. t['circlewithlefthalfblack'] = 0x25D0;
  6574. t['circlewithrighthalfblack'] = 0x25D1;
  6575. t['circumflex'] = 0x02C6;
  6576. t['circumflexbelowcmb'] = 0x032D;
  6577. t['circumflexcmb'] = 0x0302;
  6578. t['clear'] = 0x2327;
  6579. t['clickalveolar'] = 0x01C2;
  6580. t['clickdental'] = 0x01C0;
  6581. t['clicklateral'] = 0x01C1;
  6582. t['clickretroflex'] = 0x01C3;
  6583. t['club'] = 0x2663;
  6584. t['clubsuitblack'] = 0x2663;
  6585. t['clubsuitwhite'] = 0x2667;
  6586. t['cmcubedsquare'] = 0x33A4;
  6587. t['cmonospace'] = 0xFF43;
  6588. t['cmsquaredsquare'] = 0x33A0;
  6589. t['coarmenian'] = 0x0581;
  6590. t['colon'] = 0x003A;
  6591. t['colonmonetary'] = 0x20A1;
  6592. t['colonmonospace'] = 0xFF1A;
  6593. t['colonsign'] = 0x20A1;
  6594. t['colonsmall'] = 0xFE55;
  6595. t['colontriangularhalfmod'] = 0x02D1;
  6596. t['colontriangularmod'] = 0x02D0;
  6597. t['comma'] = 0x002C;
  6598. t['commaabovecmb'] = 0x0313;
  6599. t['commaaboverightcmb'] = 0x0315;
  6600. t['commaaccent'] = 0xF6C3;
  6601. t['commaarabic'] = 0x060C;
  6602. t['commaarmenian'] = 0x055D;
  6603. t['commainferior'] = 0xF6E1;
  6604. t['commamonospace'] = 0xFF0C;
  6605. t['commareversedabovecmb'] = 0x0314;
  6606. t['commareversedmod'] = 0x02BD;
  6607. t['commasmall'] = 0xFE50;
  6608. t['commasuperior'] = 0xF6E2;
  6609. t['commaturnedabovecmb'] = 0x0312;
  6610. t['commaturnedmod'] = 0x02BB;
  6611. t['compass'] = 0x263C;
  6612. t['congruent'] = 0x2245;
  6613. t['contourintegral'] = 0x222E;
  6614. t['control'] = 0x2303;
  6615. t['controlACK'] = 0x0006;
  6616. t['controlBEL'] = 0x0007;
  6617. t['controlBS'] = 0x0008;
  6618. t['controlCAN'] = 0x0018;
  6619. t['controlCR'] = 0x000D;
  6620. t['controlDC1'] = 0x0011;
  6621. t['controlDC2'] = 0x0012;
  6622. t['controlDC3'] = 0x0013;
  6623. t['controlDC4'] = 0x0014;
  6624. t['controlDEL'] = 0x007F;
  6625. t['controlDLE'] = 0x0010;
  6626. t['controlEM'] = 0x0019;
  6627. t['controlENQ'] = 0x0005;
  6628. t['controlEOT'] = 0x0004;
  6629. t['controlESC'] = 0x001B;
  6630. t['controlETB'] = 0x0017;
  6631. t['controlETX'] = 0x0003;
  6632. t['controlFF'] = 0x000C;
  6633. t['controlFS'] = 0x001C;
  6634. t['controlGS'] = 0x001D;
  6635. t['controlHT'] = 0x0009;
  6636. t['controlLF'] = 0x000A;
  6637. t['controlNAK'] = 0x0015;
  6638. t['controlRS'] = 0x001E;
  6639. t['controlSI'] = 0x000F;
  6640. t['controlSO'] = 0x000E;
  6641. t['controlSOT'] = 0x0002;
  6642. t['controlSTX'] = 0x0001;
  6643. t['controlSUB'] = 0x001A;
  6644. t['controlSYN'] = 0x0016;
  6645. t['controlUS'] = 0x001F;
  6646. t['controlVT'] = 0x000B;
  6647. t['copyright'] = 0x00A9;
  6648. t['copyrightsans'] = 0xF8E9;
  6649. t['copyrightserif'] = 0xF6D9;
  6650. t['cornerbracketleft'] = 0x300C;
  6651. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6652. t['cornerbracketleftvertical'] = 0xFE41;
  6653. t['cornerbracketright'] = 0x300D;
  6654. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6655. t['cornerbracketrightvertical'] = 0xFE42;
  6656. t['corporationsquare'] = 0x337F;
  6657. t['cosquare'] = 0x33C7;
  6658. t['coverkgsquare'] = 0x33C6;
  6659. t['cparen'] = 0x249E;
  6660. t['cruzeiro'] = 0x20A2;
  6661. t['cstretched'] = 0x0297;
  6662. t['curlyand'] = 0x22CF;
  6663. t['curlyor'] = 0x22CE;
  6664. t['currency'] = 0x00A4;
  6665. t['cyrBreve'] = 0xF6D1;
  6666. t['cyrFlex'] = 0xF6D2;
  6667. t['cyrbreve'] = 0xF6D4;
  6668. t['cyrflex'] = 0xF6D5;
  6669. t['d'] = 0x0064;
  6670. t['daarmenian'] = 0x0564;
  6671. t['dabengali'] = 0x09A6;
  6672. t['dadarabic'] = 0x0636;
  6673. t['dadeva'] = 0x0926;
  6674. t['dadfinalarabic'] = 0xFEBE;
  6675. t['dadinitialarabic'] = 0xFEBF;
  6676. t['dadmedialarabic'] = 0xFEC0;
  6677. t['dagesh'] = 0x05BC;
  6678. t['dageshhebrew'] = 0x05BC;
  6679. t['dagger'] = 0x2020;
  6680. t['daggerdbl'] = 0x2021;
  6681. t['dagujarati'] = 0x0AA6;
  6682. t['dagurmukhi'] = 0x0A26;
  6683. t['dahiragana'] = 0x3060;
  6684. t['dakatakana'] = 0x30C0;
  6685. t['dalarabic'] = 0x062F;
  6686. t['dalet'] = 0x05D3;
  6687. t['daletdagesh'] = 0xFB33;
  6688. t['daletdageshhebrew'] = 0xFB33;
  6689. t['dalethebrew'] = 0x05D3;
  6690. t['dalfinalarabic'] = 0xFEAA;
  6691. t['dammaarabic'] = 0x064F;
  6692. t['dammalowarabic'] = 0x064F;
  6693. t['dammatanaltonearabic'] = 0x064C;
  6694. t['dammatanarabic'] = 0x064C;
  6695. t['danda'] = 0x0964;
  6696. t['dargahebrew'] = 0x05A7;
  6697. t['dargalefthebrew'] = 0x05A7;
  6698. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6699. t['dblGrave'] = 0xF6D3;
  6700. t['dblanglebracketleft'] = 0x300A;
  6701. t['dblanglebracketleftvertical'] = 0xFE3D;
  6702. t['dblanglebracketright'] = 0x300B;
  6703. t['dblanglebracketrightvertical'] = 0xFE3E;
  6704. t['dblarchinvertedbelowcmb'] = 0x032B;
  6705. t['dblarrowleft'] = 0x21D4;
  6706. t['dblarrowright'] = 0x21D2;
  6707. t['dbldanda'] = 0x0965;
  6708. t['dblgrave'] = 0xF6D6;
  6709. t['dblgravecmb'] = 0x030F;
  6710. t['dblintegral'] = 0x222C;
  6711. t['dbllowline'] = 0x2017;
  6712. t['dbllowlinecmb'] = 0x0333;
  6713. t['dbloverlinecmb'] = 0x033F;
  6714. t['dblprimemod'] = 0x02BA;
  6715. t['dblverticalbar'] = 0x2016;
  6716. t['dblverticallineabovecmb'] = 0x030E;
  6717. t['dbopomofo'] = 0x3109;
  6718. t['dbsquare'] = 0x33C8;
  6719. t['dcaron'] = 0x010F;
  6720. t['dcedilla'] = 0x1E11;
  6721. t['dcircle'] = 0x24D3;
  6722. t['dcircumflexbelow'] = 0x1E13;
  6723. t['dcroat'] = 0x0111;
  6724. t['ddabengali'] = 0x09A1;
  6725. t['ddadeva'] = 0x0921;
  6726. t['ddagujarati'] = 0x0AA1;
  6727. t['ddagurmukhi'] = 0x0A21;
  6728. t['ddalarabic'] = 0x0688;
  6729. t['ddalfinalarabic'] = 0xFB89;
  6730. t['dddhadeva'] = 0x095C;
  6731. t['ddhabengali'] = 0x09A2;
  6732. t['ddhadeva'] = 0x0922;
  6733. t['ddhagujarati'] = 0x0AA2;
  6734. t['ddhagurmukhi'] = 0x0A22;
  6735. t['ddotaccent'] = 0x1E0B;
  6736. t['ddotbelow'] = 0x1E0D;
  6737. t['decimalseparatorarabic'] = 0x066B;
  6738. t['decimalseparatorpersian'] = 0x066B;
  6739. t['decyrillic'] = 0x0434;
  6740. t['degree'] = 0x00B0;
  6741. t['dehihebrew'] = 0x05AD;
  6742. t['dehiragana'] = 0x3067;
  6743. t['deicoptic'] = 0x03EF;
  6744. t['dekatakana'] = 0x30C7;
  6745. t['deleteleft'] = 0x232B;
  6746. t['deleteright'] = 0x2326;
  6747. t['delta'] = 0x03B4;
  6748. t['deltaturned'] = 0x018D;
  6749. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6750. t['dezh'] = 0x02A4;
  6751. t['dhabengali'] = 0x09A7;
  6752. t['dhadeva'] = 0x0927;
  6753. t['dhagujarati'] = 0x0AA7;
  6754. t['dhagurmukhi'] = 0x0A27;
  6755. t['dhook'] = 0x0257;
  6756. t['dialytikatonos'] = 0x0385;
  6757. t['dialytikatonoscmb'] = 0x0344;
  6758. t['diamond'] = 0x2666;
  6759. t['diamondsuitwhite'] = 0x2662;
  6760. t['dieresis'] = 0x00A8;
  6761. t['dieresisacute'] = 0xF6D7;
  6762. t['dieresisbelowcmb'] = 0x0324;
  6763. t['dieresiscmb'] = 0x0308;
  6764. t['dieresisgrave'] = 0xF6D8;
  6765. t['dieresistonos'] = 0x0385;
  6766. t['dihiragana'] = 0x3062;
  6767. t['dikatakana'] = 0x30C2;
  6768. t['dittomark'] = 0x3003;
  6769. t['divide'] = 0x00F7;
  6770. t['divides'] = 0x2223;
  6771. t['divisionslash'] = 0x2215;
  6772. t['djecyrillic'] = 0x0452;
  6773. t['dkshade'] = 0x2593;
  6774. t['dlinebelow'] = 0x1E0F;
  6775. t['dlsquare'] = 0x3397;
  6776. t['dmacron'] = 0x0111;
  6777. t['dmonospace'] = 0xFF44;
  6778. t['dnblock'] = 0x2584;
  6779. t['dochadathai'] = 0x0E0E;
  6780. t['dodekthai'] = 0x0E14;
  6781. t['dohiragana'] = 0x3069;
  6782. t['dokatakana'] = 0x30C9;
  6783. t['dollar'] = 0x0024;
  6784. t['dollarinferior'] = 0xF6E3;
  6785. t['dollarmonospace'] = 0xFF04;
  6786. t['dollaroldstyle'] = 0xF724;
  6787. t['dollarsmall'] = 0xFE69;
  6788. t['dollarsuperior'] = 0xF6E4;
  6789. t['dong'] = 0x20AB;
  6790. t['dorusquare'] = 0x3326;
  6791. t['dotaccent'] = 0x02D9;
  6792. t['dotaccentcmb'] = 0x0307;
  6793. t['dotbelowcmb'] = 0x0323;
  6794. t['dotbelowcomb'] = 0x0323;
  6795. t['dotkatakana'] = 0x30FB;
  6796. t['dotlessi'] = 0x0131;
  6797. t['dotlessj'] = 0xF6BE;
  6798. t['dotlessjstrokehook'] = 0x0284;
  6799. t['dotmath'] = 0x22C5;
  6800. t['dottedcircle'] = 0x25CC;
  6801. t['doubleyodpatah'] = 0xFB1F;
  6802. t['doubleyodpatahhebrew'] = 0xFB1F;
  6803. t['downtackbelowcmb'] = 0x031E;
  6804. t['downtackmod'] = 0x02D5;
  6805. t['dparen'] = 0x249F;
  6806. t['dsuperior'] = 0xF6EB;
  6807. t['dtail'] = 0x0256;
  6808. t['dtopbar'] = 0x018C;
  6809. t['duhiragana'] = 0x3065;
  6810. t['dukatakana'] = 0x30C5;
  6811. t['dz'] = 0x01F3;
  6812. t['dzaltone'] = 0x02A3;
  6813. t['dzcaron'] = 0x01C6;
  6814. t['dzcurl'] = 0x02A5;
  6815. t['dzeabkhasiancyrillic'] = 0x04E1;
  6816. t['dzecyrillic'] = 0x0455;
  6817. t['dzhecyrillic'] = 0x045F;
  6818. t['e'] = 0x0065;
  6819. t['eacute'] = 0x00E9;
  6820. t['earth'] = 0x2641;
  6821. t['ebengali'] = 0x098F;
  6822. t['ebopomofo'] = 0x311C;
  6823. t['ebreve'] = 0x0115;
  6824. t['ecandradeva'] = 0x090D;
  6825. t['ecandragujarati'] = 0x0A8D;
  6826. t['ecandravowelsigndeva'] = 0x0945;
  6827. t['ecandravowelsigngujarati'] = 0x0AC5;
  6828. t['ecaron'] = 0x011B;
  6829. t['ecedillabreve'] = 0x1E1D;
  6830. t['echarmenian'] = 0x0565;
  6831. t['echyiwnarmenian'] = 0x0587;
  6832. t['ecircle'] = 0x24D4;
  6833. t['ecircumflex'] = 0x00EA;
  6834. t['ecircumflexacute'] = 0x1EBF;
  6835. t['ecircumflexbelow'] = 0x1E19;
  6836. t['ecircumflexdotbelow'] = 0x1EC7;
  6837. t['ecircumflexgrave'] = 0x1EC1;
  6838. t['ecircumflexhookabove'] = 0x1EC3;
  6839. t['ecircumflextilde'] = 0x1EC5;
  6840. t['ecyrillic'] = 0x0454;
  6841. t['edblgrave'] = 0x0205;
  6842. t['edeva'] = 0x090F;
  6843. t['edieresis'] = 0x00EB;
  6844. t['edot'] = 0x0117;
  6845. t['edotaccent'] = 0x0117;
  6846. t['edotbelow'] = 0x1EB9;
  6847. t['eegurmukhi'] = 0x0A0F;
  6848. t['eematragurmukhi'] = 0x0A47;
  6849. t['efcyrillic'] = 0x0444;
  6850. t['egrave'] = 0x00E8;
  6851. t['egujarati'] = 0x0A8F;
  6852. t['eharmenian'] = 0x0567;
  6853. t['ehbopomofo'] = 0x311D;
  6854. t['ehiragana'] = 0x3048;
  6855. t['ehookabove'] = 0x1EBB;
  6856. t['eibopomofo'] = 0x311F;
  6857. t['eight'] = 0x0038;
  6858. t['eightarabic'] = 0x0668;
  6859. t['eightbengali'] = 0x09EE;
  6860. t['eightcircle'] = 0x2467;
  6861. t['eightcircleinversesansserif'] = 0x2791;
  6862. t['eightdeva'] = 0x096E;
  6863. t['eighteencircle'] = 0x2471;
  6864. t['eighteenparen'] = 0x2485;
  6865. t['eighteenperiod'] = 0x2499;
  6866. t['eightgujarati'] = 0x0AEE;
  6867. t['eightgurmukhi'] = 0x0A6E;
  6868. t['eighthackarabic'] = 0x0668;
  6869. t['eighthangzhou'] = 0x3028;
  6870. t['eighthnotebeamed'] = 0x266B;
  6871. t['eightideographicparen'] = 0x3227;
  6872. t['eightinferior'] = 0x2088;
  6873. t['eightmonospace'] = 0xFF18;
  6874. t['eightoldstyle'] = 0xF738;
  6875. t['eightparen'] = 0x247B;
  6876. t['eightperiod'] = 0x248F;
  6877. t['eightpersian'] = 0x06F8;
  6878. t['eightroman'] = 0x2177;
  6879. t['eightsuperior'] = 0x2078;
  6880. t['eightthai'] = 0x0E58;
  6881. t['einvertedbreve'] = 0x0207;
  6882. t['eiotifiedcyrillic'] = 0x0465;
  6883. t['ekatakana'] = 0x30A8;
  6884. t['ekatakanahalfwidth'] = 0xFF74;
  6885. t['ekonkargurmukhi'] = 0x0A74;
  6886. t['ekorean'] = 0x3154;
  6887. t['elcyrillic'] = 0x043B;
  6888. t['element'] = 0x2208;
  6889. t['elevencircle'] = 0x246A;
  6890. t['elevenparen'] = 0x247E;
  6891. t['elevenperiod'] = 0x2492;
  6892. t['elevenroman'] = 0x217A;
  6893. t['ellipsis'] = 0x2026;
  6894. t['ellipsisvertical'] = 0x22EE;
  6895. t['emacron'] = 0x0113;
  6896. t['emacronacute'] = 0x1E17;
  6897. t['emacrongrave'] = 0x1E15;
  6898. t['emcyrillic'] = 0x043C;
  6899. t['emdash'] = 0x2014;
  6900. t['emdashvertical'] = 0xFE31;
  6901. t['emonospace'] = 0xFF45;
  6902. t['emphasismarkarmenian'] = 0x055B;
  6903. t['emptyset'] = 0x2205;
  6904. t['enbopomofo'] = 0x3123;
  6905. t['encyrillic'] = 0x043D;
  6906. t['endash'] = 0x2013;
  6907. t['endashvertical'] = 0xFE32;
  6908. t['endescendercyrillic'] = 0x04A3;
  6909. t['eng'] = 0x014B;
  6910. t['engbopomofo'] = 0x3125;
  6911. t['enghecyrillic'] = 0x04A5;
  6912. t['enhookcyrillic'] = 0x04C8;
  6913. t['enspace'] = 0x2002;
  6914. t['eogonek'] = 0x0119;
  6915. t['eokorean'] = 0x3153;
  6916. t['eopen'] = 0x025B;
  6917. t['eopenclosed'] = 0x029A;
  6918. t['eopenreversed'] = 0x025C;
  6919. t['eopenreversedclosed'] = 0x025E;
  6920. t['eopenreversedhook'] = 0x025D;
  6921. t['eparen'] = 0x24A0;
  6922. t['epsilon'] = 0x03B5;
  6923. t['epsilontonos'] = 0x03AD;
  6924. t['equal'] = 0x003D;
  6925. t['equalmonospace'] = 0xFF1D;
  6926. t['equalsmall'] = 0xFE66;
  6927. t['equalsuperior'] = 0x207C;
  6928. t['equivalence'] = 0x2261;
  6929. t['erbopomofo'] = 0x3126;
  6930. t['ercyrillic'] = 0x0440;
  6931. t['ereversed'] = 0x0258;
  6932. t['ereversedcyrillic'] = 0x044D;
  6933. t['escyrillic'] = 0x0441;
  6934. t['esdescendercyrillic'] = 0x04AB;
  6935. t['esh'] = 0x0283;
  6936. t['eshcurl'] = 0x0286;
  6937. t['eshortdeva'] = 0x090E;
  6938. t['eshortvowelsigndeva'] = 0x0946;
  6939. t['eshreversedloop'] = 0x01AA;
  6940. t['eshsquatreversed'] = 0x0285;
  6941. t['esmallhiragana'] = 0x3047;
  6942. t['esmallkatakana'] = 0x30A7;
  6943. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6944. t['estimated'] = 0x212E;
  6945. t['esuperior'] = 0xF6EC;
  6946. t['eta'] = 0x03B7;
  6947. t['etarmenian'] = 0x0568;
  6948. t['etatonos'] = 0x03AE;
  6949. t['eth'] = 0x00F0;
  6950. t['etilde'] = 0x1EBD;
  6951. t['etildebelow'] = 0x1E1B;
  6952. t['etnahtafoukhhebrew'] = 0x0591;
  6953. t['etnahtafoukhlefthebrew'] = 0x0591;
  6954. t['etnahtahebrew'] = 0x0591;
  6955. t['etnahtalefthebrew'] = 0x0591;
  6956. t['eturned'] = 0x01DD;
  6957. t['eukorean'] = 0x3161;
  6958. t['euro'] = 0x20AC;
  6959. t['evowelsignbengali'] = 0x09C7;
  6960. t['evowelsigndeva'] = 0x0947;
  6961. t['evowelsigngujarati'] = 0x0AC7;
  6962. t['exclam'] = 0x0021;
  6963. t['exclamarmenian'] = 0x055C;
  6964. t['exclamdbl'] = 0x203C;
  6965. t['exclamdown'] = 0x00A1;
  6966. t['exclamdownsmall'] = 0xF7A1;
  6967. t['exclammonospace'] = 0xFF01;
  6968. t['exclamsmall'] = 0xF721;
  6969. t['existential'] = 0x2203;
  6970. t['ezh'] = 0x0292;
  6971. t['ezhcaron'] = 0x01EF;
  6972. t['ezhcurl'] = 0x0293;
  6973. t['ezhreversed'] = 0x01B9;
  6974. t['ezhtail'] = 0x01BA;
  6975. t['f'] = 0x0066;
  6976. t['fadeva'] = 0x095E;
  6977. t['fagurmukhi'] = 0x0A5E;
  6978. t['fahrenheit'] = 0x2109;
  6979. t['fathaarabic'] = 0x064E;
  6980. t['fathalowarabic'] = 0x064E;
  6981. t['fathatanarabic'] = 0x064B;
  6982. t['fbopomofo'] = 0x3108;
  6983. t['fcircle'] = 0x24D5;
  6984. t['fdotaccent'] = 0x1E1F;
  6985. t['feharabic'] = 0x0641;
  6986. t['feharmenian'] = 0x0586;
  6987. t['fehfinalarabic'] = 0xFED2;
  6988. t['fehinitialarabic'] = 0xFED3;
  6989. t['fehmedialarabic'] = 0xFED4;
  6990. t['feicoptic'] = 0x03E5;
  6991. t['female'] = 0x2640;
  6992. t['ff'] = 0xFB00;
  6993. t['ffi'] = 0xFB03;
  6994. t['ffl'] = 0xFB04;
  6995. t['fi'] = 0xFB01;
  6996. t['fifteencircle'] = 0x246E;
  6997. t['fifteenparen'] = 0x2482;
  6998. t['fifteenperiod'] = 0x2496;
  6999. t['figuredash'] = 0x2012;
  7000. t['filledbox'] = 0x25A0;
  7001. t['filledrect'] = 0x25AC;
  7002. t['finalkaf'] = 0x05DA;
  7003. t['finalkafdagesh'] = 0xFB3A;
  7004. t['finalkafdageshhebrew'] = 0xFB3A;
  7005. t['finalkafhebrew'] = 0x05DA;
  7006. t['finalmem'] = 0x05DD;
  7007. t['finalmemhebrew'] = 0x05DD;
  7008. t['finalnun'] = 0x05DF;
  7009. t['finalnunhebrew'] = 0x05DF;
  7010. t['finalpe'] = 0x05E3;
  7011. t['finalpehebrew'] = 0x05E3;
  7012. t['finaltsadi'] = 0x05E5;
  7013. t['finaltsadihebrew'] = 0x05E5;
  7014. t['firsttonechinese'] = 0x02C9;
  7015. t['fisheye'] = 0x25C9;
  7016. t['fitacyrillic'] = 0x0473;
  7017. t['five'] = 0x0035;
  7018. t['fivearabic'] = 0x0665;
  7019. t['fivebengali'] = 0x09EB;
  7020. t['fivecircle'] = 0x2464;
  7021. t['fivecircleinversesansserif'] = 0x278E;
  7022. t['fivedeva'] = 0x096B;
  7023. t['fiveeighths'] = 0x215D;
  7024. t['fivegujarati'] = 0x0AEB;
  7025. t['fivegurmukhi'] = 0x0A6B;
  7026. t['fivehackarabic'] = 0x0665;
  7027. t['fivehangzhou'] = 0x3025;
  7028. t['fiveideographicparen'] = 0x3224;
  7029. t['fiveinferior'] = 0x2085;
  7030. t['fivemonospace'] = 0xFF15;
  7031. t['fiveoldstyle'] = 0xF735;
  7032. t['fiveparen'] = 0x2478;
  7033. t['fiveperiod'] = 0x248C;
  7034. t['fivepersian'] = 0x06F5;
  7035. t['fiveroman'] = 0x2174;
  7036. t['fivesuperior'] = 0x2075;
  7037. t['fivethai'] = 0x0E55;
  7038. t['fl'] = 0xFB02;
  7039. t['florin'] = 0x0192;
  7040. t['fmonospace'] = 0xFF46;
  7041. t['fmsquare'] = 0x3399;
  7042. t['fofanthai'] = 0x0E1F;
  7043. t['fofathai'] = 0x0E1D;
  7044. t['fongmanthai'] = 0x0E4F;
  7045. t['forall'] = 0x2200;
  7046. t['four'] = 0x0034;
  7047. t['fourarabic'] = 0x0664;
  7048. t['fourbengali'] = 0x09EA;
  7049. t['fourcircle'] = 0x2463;
  7050. t['fourcircleinversesansserif'] = 0x278D;
  7051. t['fourdeva'] = 0x096A;
  7052. t['fourgujarati'] = 0x0AEA;
  7053. t['fourgurmukhi'] = 0x0A6A;
  7054. t['fourhackarabic'] = 0x0664;
  7055. t['fourhangzhou'] = 0x3024;
  7056. t['fourideographicparen'] = 0x3223;
  7057. t['fourinferior'] = 0x2084;
  7058. t['fourmonospace'] = 0xFF14;
  7059. t['fournumeratorbengali'] = 0x09F7;
  7060. t['fouroldstyle'] = 0xF734;
  7061. t['fourparen'] = 0x2477;
  7062. t['fourperiod'] = 0x248B;
  7063. t['fourpersian'] = 0x06F4;
  7064. t['fourroman'] = 0x2173;
  7065. t['foursuperior'] = 0x2074;
  7066. t['fourteencircle'] = 0x246D;
  7067. t['fourteenparen'] = 0x2481;
  7068. t['fourteenperiod'] = 0x2495;
  7069. t['fourthai'] = 0x0E54;
  7070. t['fourthtonechinese'] = 0x02CB;
  7071. t['fparen'] = 0x24A1;
  7072. t['fraction'] = 0x2044;
  7073. t['franc'] = 0x20A3;
  7074. t['g'] = 0x0067;
  7075. t['gabengali'] = 0x0997;
  7076. t['gacute'] = 0x01F5;
  7077. t['gadeva'] = 0x0917;
  7078. t['gafarabic'] = 0x06AF;
  7079. t['gaffinalarabic'] = 0xFB93;
  7080. t['gafinitialarabic'] = 0xFB94;
  7081. t['gafmedialarabic'] = 0xFB95;
  7082. t['gagujarati'] = 0x0A97;
  7083. t['gagurmukhi'] = 0x0A17;
  7084. t['gahiragana'] = 0x304C;
  7085. t['gakatakana'] = 0x30AC;
  7086. t['gamma'] = 0x03B3;
  7087. t['gammalatinsmall'] = 0x0263;
  7088. t['gammasuperior'] = 0x02E0;
  7089. t['gangiacoptic'] = 0x03EB;
  7090. t['gbopomofo'] = 0x310D;
  7091. t['gbreve'] = 0x011F;
  7092. t['gcaron'] = 0x01E7;
  7093. t['gcedilla'] = 0x0123;
  7094. t['gcircle'] = 0x24D6;
  7095. t['gcircumflex'] = 0x011D;
  7096. t['gcommaaccent'] = 0x0123;
  7097. t['gdot'] = 0x0121;
  7098. t['gdotaccent'] = 0x0121;
  7099. t['gecyrillic'] = 0x0433;
  7100. t['gehiragana'] = 0x3052;
  7101. t['gekatakana'] = 0x30B2;
  7102. t['geometricallyequal'] = 0x2251;
  7103. t['gereshaccenthebrew'] = 0x059C;
  7104. t['gereshhebrew'] = 0x05F3;
  7105. t['gereshmuqdamhebrew'] = 0x059D;
  7106. t['germandbls'] = 0x00DF;
  7107. t['gershayimaccenthebrew'] = 0x059E;
  7108. t['gershayimhebrew'] = 0x05F4;
  7109. t['getamark'] = 0x3013;
  7110. t['ghabengali'] = 0x0998;
  7111. t['ghadarmenian'] = 0x0572;
  7112. t['ghadeva'] = 0x0918;
  7113. t['ghagujarati'] = 0x0A98;
  7114. t['ghagurmukhi'] = 0x0A18;
  7115. t['ghainarabic'] = 0x063A;
  7116. t['ghainfinalarabic'] = 0xFECE;
  7117. t['ghaininitialarabic'] = 0xFECF;
  7118. t['ghainmedialarabic'] = 0xFED0;
  7119. t['ghemiddlehookcyrillic'] = 0x0495;
  7120. t['ghestrokecyrillic'] = 0x0493;
  7121. t['gheupturncyrillic'] = 0x0491;
  7122. t['ghhadeva'] = 0x095A;
  7123. t['ghhagurmukhi'] = 0x0A5A;
  7124. t['ghook'] = 0x0260;
  7125. t['ghzsquare'] = 0x3393;
  7126. t['gihiragana'] = 0x304E;
  7127. t['gikatakana'] = 0x30AE;
  7128. t['gimarmenian'] = 0x0563;
  7129. t['gimel'] = 0x05D2;
  7130. t['gimeldagesh'] = 0xFB32;
  7131. t['gimeldageshhebrew'] = 0xFB32;
  7132. t['gimelhebrew'] = 0x05D2;
  7133. t['gjecyrillic'] = 0x0453;
  7134. t['glottalinvertedstroke'] = 0x01BE;
  7135. t['glottalstop'] = 0x0294;
  7136. t['glottalstopinverted'] = 0x0296;
  7137. t['glottalstopmod'] = 0x02C0;
  7138. t['glottalstopreversed'] = 0x0295;
  7139. t['glottalstopreversedmod'] = 0x02C1;
  7140. t['glottalstopreversedsuperior'] = 0x02E4;
  7141. t['glottalstopstroke'] = 0x02A1;
  7142. t['glottalstopstrokereversed'] = 0x02A2;
  7143. t['gmacron'] = 0x1E21;
  7144. t['gmonospace'] = 0xFF47;
  7145. t['gohiragana'] = 0x3054;
  7146. t['gokatakana'] = 0x30B4;
  7147. t['gparen'] = 0x24A2;
  7148. t['gpasquare'] = 0x33AC;
  7149. t['gradient'] = 0x2207;
  7150. t['grave'] = 0x0060;
  7151. t['gravebelowcmb'] = 0x0316;
  7152. t['gravecmb'] = 0x0300;
  7153. t['gravecomb'] = 0x0300;
  7154. t['gravedeva'] = 0x0953;
  7155. t['gravelowmod'] = 0x02CE;
  7156. t['gravemonospace'] = 0xFF40;
  7157. t['gravetonecmb'] = 0x0340;
  7158. t['greater'] = 0x003E;
  7159. t['greaterequal'] = 0x2265;
  7160. t['greaterequalorless'] = 0x22DB;
  7161. t['greatermonospace'] = 0xFF1E;
  7162. t['greaterorequivalent'] = 0x2273;
  7163. t['greaterorless'] = 0x2277;
  7164. t['greateroverequal'] = 0x2267;
  7165. t['greatersmall'] = 0xFE65;
  7166. t['gscript'] = 0x0261;
  7167. t['gstroke'] = 0x01E5;
  7168. t['guhiragana'] = 0x3050;
  7169. t['guillemotleft'] = 0x00AB;
  7170. t['guillemotright'] = 0x00BB;
  7171. t['guilsinglleft'] = 0x2039;
  7172. t['guilsinglright'] = 0x203A;
  7173. t['gukatakana'] = 0x30B0;
  7174. t['guramusquare'] = 0x3318;
  7175. t['gysquare'] = 0x33C9;
  7176. t['h'] = 0x0068;
  7177. t['haabkhasiancyrillic'] = 0x04A9;
  7178. t['haaltonearabic'] = 0x06C1;
  7179. t['habengali'] = 0x09B9;
  7180. t['hadescendercyrillic'] = 0x04B3;
  7181. t['hadeva'] = 0x0939;
  7182. t['hagujarati'] = 0x0AB9;
  7183. t['hagurmukhi'] = 0x0A39;
  7184. t['haharabic'] = 0x062D;
  7185. t['hahfinalarabic'] = 0xFEA2;
  7186. t['hahinitialarabic'] = 0xFEA3;
  7187. t['hahiragana'] = 0x306F;
  7188. t['hahmedialarabic'] = 0xFEA4;
  7189. t['haitusquare'] = 0x332A;
  7190. t['hakatakana'] = 0x30CF;
  7191. t['hakatakanahalfwidth'] = 0xFF8A;
  7192. t['halantgurmukhi'] = 0x0A4D;
  7193. t['hamzaarabic'] = 0x0621;
  7194. t['hamzalowarabic'] = 0x0621;
  7195. t['hangulfiller'] = 0x3164;
  7196. t['hardsigncyrillic'] = 0x044A;
  7197. t['harpoonleftbarbup'] = 0x21BC;
  7198. t['harpoonrightbarbup'] = 0x21C0;
  7199. t['hasquare'] = 0x33CA;
  7200. t['hatafpatah'] = 0x05B2;
  7201. t['hatafpatah16'] = 0x05B2;
  7202. t['hatafpatah23'] = 0x05B2;
  7203. t['hatafpatah2f'] = 0x05B2;
  7204. t['hatafpatahhebrew'] = 0x05B2;
  7205. t['hatafpatahnarrowhebrew'] = 0x05B2;
  7206. t['hatafpatahquarterhebrew'] = 0x05B2;
  7207. t['hatafpatahwidehebrew'] = 0x05B2;
  7208. t['hatafqamats'] = 0x05B3;
  7209. t['hatafqamats1b'] = 0x05B3;
  7210. t['hatafqamats28'] = 0x05B3;
  7211. t['hatafqamats34'] = 0x05B3;
  7212. t['hatafqamatshebrew'] = 0x05B3;
  7213. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  7214. t['hatafqamatsquarterhebrew'] = 0x05B3;
  7215. t['hatafqamatswidehebrew'] = 0x05B3;
  7216. t['hatafsegol'] = 0x05B1;
  7217. t['hatafsegol17'] = 0x05B1;
  7218. t['hatafsegol24'] = 0x05B1;
  7219. t['hatafsegol30'] = 0x05B1;
  7220. t['hatafsegolhebrew'] = 0x05B1;
  7221. t['hatafsegolnarrowhebrew'] = 0x05B1;
  7222. t['hatafsegolquarterhebrew'] = 0x05B1;
  7223. t['hatafsegolwidehebrew'] = 0x05B1;
  7224. t['hbar'] = 0x0127;
  7225. t['hbopomofo'] = 0x310F;
  7226. t['hbrevebelow'] = 0x1E2B;
  7227. t['hcedilla'] = 0x1E29;
  7228. t['hcircle'] = 0x24D7;
  7229. t['hcircumflex'] = 0x0125;
  7230. t['hdieresis'] = 0x1E27;
  7231. t['hdotaccent'] = 0x1E23;
  7232. t['hdotbelow'] = 0x1E25;
  7233. t['he'] = 0x05D4;
  7234. t['heart'] = 0x2665;
  7235. t['heartsuitblack'] = 0x2665;
  7236. t['heartsuitwhite'] = 0x2661;
  7237. t['hedagesh'] = 0xFB34;
  7238. t['hedageshhebrew'] = 0xFB34;
  7239. t['hehaltonearabic'] = 0x06C1;
  7240. t['heharabic'] = 0x0647;
  7241. t['hehebrew'] = 0x05D4;
  7242. t['hehfinalaltonearabic'] = 0xFBA7;
  7243. t['hehfinalalttwoarabic'] = 0xFEEA;
  7244. t['hehfinalarabic'] = 0xFEEA;
  7245. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  7246. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  7247. t['hehinitialaltonearabic'] = 0xFBA8;
  7248. t['hehinitialarabic'] = 0xFEEB;
  7249. t['hehiragana'] = 0x3078;
  7250. t['hehmedialaltonearabic'] = 0xFBA9;
  7251. t['hehmedialarabic'] = 0xFEEC;
  7252. t['heiseierasquare'] = 0x337B;
  7253. t['hekatakana'] = 0x30D8;
  7254. t['hekatakanahalfwidth'] = 0xFF8D;
  7255. t['hekutaarusquare'] = 0x3336;
  7256. t['henghook'] = 0x0267;
  7257. t['herutusquare'] = 0x3339;
  7258. t['het'] = 0x05D7;
  7259. t['hethebrew'] = 0x05D7;
  7260. t['hhook'] = 0x0266;
  7261. t['hhooksuperior'] = 0x02B1;
  7262. t['hieuhacirclekorean'] = 0x327B;
  7263. t['hieuhaparenkorean'] = 0x321B;
  7264. t['hieuhcirclekorean'] = 0x326D;
  7265. t['hieuhkorean'] = 0x314E;
  7266. t['hieuhparenkorean'] = 0x320D;
  7267. t['hihiragana'] = 0x3072;
  7268. t['hikatakana'] = 0x30D2;
  7269. t['hikatakanahalfwidth'] = 0xFF8B;
  7270. t['hiriq'] = 0x05B4;
  7271. t['hiriq14'] = 0x05B4;
  7272. t['hiriq21'] = 0x05B4;
  7273. t['hiriq2d'] = 0x05B4;
  7274. t['hiriqhebrew'] = 0x05B4;
  7275. t['hiriqnarrowhebrew'] = 0x05B4;
  7276. t['hiriqquarterhebrew'] = 0x05B4;
  7277. t['hiriqwidehebrew'] = 0x05B4;
  7278. t['hlinebelow'] = 0x1E96;
  7279. t['hmonospace'] = 0xFF48;
  7280. t['hoarmenian'] = 0x0570;
  7281. t['hohipthai'] = 0x0E2B;
  7282. t['hohiragana'] = 0x307B;
  7283. t['hokatakana'] = 0x30DB;
  7284. t['hokatakanahalfwidth'] = 0xFF8E;
  7285. t['holam'] = 0x05B9;
  7286. t['holam19'] = 0x05B9;
  7287. t['holam26'] = 0x05B9;
  7288. t['holam32'] = 0x05B9;
  7289. t['holamhebrew'] = 0x05B9;
  7290. t['holamnarrowhebrew'] = 0x05B9;
  7291. t['holamquarterhebrew'] = 0x05B9;
  7292. t['holamwidehebrew'] = 0x05B9;
  7293. t['honokhukthai'] = 0x0E2E;
  7294. t['hookabovecomb'] = 0x0309;
  7295. t['hookcmb'] = 0x0309;
  7296. t['hookpalatalizedbelowcmb'] = 0x0321;
  7297. t['hookretroflexbelowcmb'] = 0x0322;
  7298. t['hoonsquare'] = 0x3342;
  7299. t['horicoptic'] = 0x03E9;
  7300. t['horizontalbar'] = 0x2015;
  7301. t['horncmb'] = 0x031B;
  7302. t['hotsprings'] = 0x2668;
  7303. t['house'] = 0x2302;
  7304. t['hparen'] = 0x24A3;
  7305. t['hsuperior'] = 0x02B0;
  7306. t['hturned'] = 0x0265;
  7307. t['huhiragana'] = 0x3075;
  7308. t['huiitosquare'] = 0x3333;
  7309. t['hukatakana'] = 0x30D5;
  7310. t['hukatakanahalfwidth'] = 0xFF8C;
  7311. t['hungarumlaut'] = 0x02DD;
  7312. t['hungarumlautcmb'] = 0x030B;
  7313. t['hv'] = 0x0195;
  7314. t['hyphen'] = 0x002D;
  7315. t['hypheninferior'] = 0xF6E5;
  7316. t['hyphenmonospace'] = 0xFF0D;
  7317. t['hyphensmall'] = 0xFE63;
  7318. t['hyphensuperior'] = 0xF6E6;
  7319. t['hyphentwo'] = 0x2010;
  7320. t['i'] = 0x0069;
  7321. t['iacute'] = 0x00ED;
  7322. t['iacyrillic'] = 0x044F;
  7323. t['ibengali'] = 0x0987;
  7324. t['ibopomofo'] = 0x3127;
  7325. t['ibreve'] = 0x012D;
  7326. t['icaron'] = 0x01D0;
  7327. t['icircle'] = 0x24D8;
  7328. t['icircumflex'] = 0x00EE;
  7329. t['icyrillic'] = 0x0456;
  7330. t['idblgrave'] = 0x0209;
  7331. t['ideographearthcircle'] = 0x328F;
  7332. t['ideographfirecircle'] = 0x328B;
  7333. t['ideographicallianceparen'] = 0x323F;
  7334. t['ideographiccallparen'] = 0x323A;
  7335. t['ideographiccentrecircle'] = 0x32A5;
  7336. t['ideographicclose'] = 0x3006;
  7337. t['ideographiccomma'] = 0x3001;
  7338. t['ideographiccommaleft'] = 0xFF64;
  7339. t['ideographiccongratulationparen'] = 0x3237;
  7340. t['ideographiccorrectcircle'] = 0x32A3;
  7341. t['ideographicearthparen'] = 0x322F;
  7342. t['ideographicenterpriseparen'] = 0x323D;
  7343. t['ideographicexcellentcircle'] = 0x329D;
  7344. t['ideographicfestivalparen'] = 0x3240;
  7345. t['ideographicfinancialcircle'] = 0x3296;
  7346. t['ideographicfinancialparen'] = 0x3236;
  7347. t['ideographicfireparen'] = 0x322B;
  7348. t['ideographichaveparen'] = 0x3232;
  7349. t['ideographichighcircle'] = 0x32A4;
  7350. t['ideographiciterationmark'] = 0x3005;
  7351. t['ideographiclaborcircle'] = 0x3298;
  7352. t['ideographiclaborparen'] = 0x3238;
  7353. t['ideographicleftcircle'] = 0x32A7;
  7354. t['ideographiclowcircle'] = 0x32A6;
  7355. t['ideographicmedicinecircle'] = 0x32A9;
  7356. t['ideographicmetalparen'] = 0x322E;
  7357. t['ideographicmoonparen'] = 0x322A;
  7358. t['ideographicnameparen'] = 0x3234;
  7359. t['ideographicperiod'] = 0x3002;
  7360. t['ideographicprintcircle'] = 0x329E;
  7361. t['ideographicreachparen'] = 0x3243;
  7362. t['ideographicrepresentparen'] = 0x3239;
  7363. t['ideographicresourceparen'] = 0x323E;
  7364. t['ideographicrightcircle'] = 0x32A8;
  7365. t['ideographicsecretcircle'] = 0x3299;
  7366. t['ideographicselfparen'] = 0x3242;
  7367. t['ideographicsocietyparen'] = 0x3233;
  7368. t['ideographicspace'] = 0x3000;
  7369. t['ideographicspecialparen'] = 0x3235;
  7370. t['ideographicstockparen'] = 0x3231;
  7371. t['ideographicstudyparen'] = 0x323B;
  7372. t['ideographicsunparen'] = 0x3230;
  7373. t['ideographicsuperviseparen'] = 0x323C;
  7374. t['ideographicwaterparen'] = 0x322C;
  7375. t['ideographicwoodparen'] = 0x322D;
  7376. t['ideographiczero'] = 0x3007;
  7377. t['ideographmetalcircle'] = 0x328E;
  7378. t['ideographmooncircle'] = 0x328A;
  7379. t['ideographnamecircle'] = 0x3294;
  7380. t['ideographsuncircle'] = 0x3290;
  7381. t['ideographwatercircle'] = 0x328C;
  7382. t['ideographwoodcircle'] = 0x328D;
  7383. t['ideva'] = 0x0907;
  7384. t['idieresis'] = 0x00EF;
  7385. t['idieresisacute'] = 0x1E2F;
  7386. t['idieresiscyrillic'] = 0x04E5;
  7387. t['idotbelow'] = 0x1ECB;
  7388. t['iebrevecyrillic'] = 0x04D7;
  7389. t['iecyrillic'] = 0x0435;
  7390. t['ieungacirclekorean'] = 0x3275;
  7391. t['ieungaparenkorean'] = 0x3215;
  7392. t['ieungcirclekorean'] = 0x3267;
  7393. t['ieungkorean'] = 0x3147;
  7394. t['ieungparenkorean'] = 0x3207;
  7395. t['igrave'] = 0x00EC;
  7396. t['igujarati'] = 0x0A87;
  7397. t['igurmukhi'] = 0x0A07;
  7398. t['ihiragana'] = 0x3044;
  7399. t['ihookabove'] = 0x1EC9;
  7400. t['iibengali'] = 0x0988;
  7401. t['iicyrillic'] = 0x0438;
  7402. t['iideva'] = 0x0908;
  7403. t['iigujarati'] = 0x0A88;
  7404. t['iigurmukhi'] = 0x0A08;
  7405. t['iimatragurmukhi'] = 0x0A40;
  7406. t['iinvertedbreve'] = 0x020B;
  7407. t['iishortcyrillic'] = 0x0439;
  7408. t['iivowelsignbengali'] = 0x09C0;
  7409. t['iivowelsigndeva'] = 0x0940;
  7410. t['iivowelsigngujarati'] = 0x0AC0;
  7411. t['ij'] = 0x0133;
  7412. t['ikatakana'] = 0x30A4;
  7413. t['ikatakanahalfwidth'] = 0xFF72;
  7414. t['ikorean'] = 0x3163;
  7415. t['ilde'] = 0x02DC;
  7416. t['iluyhebrew'] = 0x05AC;
  7417. t['imacron'] = 0x012B;
  7418. t['imacroncyrillic'] = 0x04E3;
  7419. t['imageorapproximatelyequal'] = 0x2253;
  7420. t['imatragurmukhi'] = 0x0A3F;
  7421. t['imonospace'] = 0xFF49;
  7422. t['increment'] = 0x2206;
  7423. t['infinity'] = 0x221E;
  7424. t['iniarmenian'] = 0x056B;
  7425. t['integral'] = 0x222B;
  7426. t['integralbottom'] = 0x2321;
  7427. t['integralbt'] = 0x2321;
  7428. t['integralex'] = 0xF8F5;
  7429. t['integraltop'] = 0x2320;
  7430. t['integraltp'] = 0x2320;
  7431. t['intersection'] = 0x2229;
  7432. t['intisquare'] = 0x3305;
  7433. t['invbullet'] = 0x25D8;
  7434. t['invcircle'] = 0x25D9;
  7435. t['invsmileface'] = 0x263B;
  7436. t['iocyrillic'] = 0x0451;
  7437. t['iogonek'] = 0x012F;
  7438. t['iota'] = 0x03B9;
  7439. t['iotadieresis'] = 0x03CA;
  7440. t['iotadieresistonos'] = 0x0390;
  7441. t['iotalatin'] = 0x0269;
  7442. t['iotatonos'] = 0x03AF;
  7443. t['iparen'] = 0x24A4;
  7444. t['irigurmukhi'] = 0x0A72;
  7445. t['ismallhiragana'] = 0x3043;
  7446. t['ismallkatakana'] = 0x30A3;
  7447. t['ismallkatakanahalfwidth'] = 0xFF68;
  7448. t['issharbengali'] = 0x09FA;
  7449. t['istroke'] = 0x0268;
  7450. t['isuperior'] = 0xF6ED;
  7451. t['iterationhiragana'] = 0x309D;
  7452. t['iterationkatakana'] = 0x30FD;
  7453. t['itilde'] = 0x0129;
  7454. t['itildebelow'] = 0x1E2D;
  7455. t['iubopomofo'] = 0x3129;
  7456. t['iucyrillic'] = 0x044E;
  7457. t['ivowelsignbengali'] = 0x09BF;
  7458. t['ivowelsigndeva'] = 0x093F;
  7459. t['ivowelsigngujarati'] = 0x0ABF;
  7460. t['izhitsacyrillic'] = 0x0475;
  7461. t['izhitsadblgravecyrillic'] = 0x0477;
  7462. t['j'] = 0x006A;
  7463. t['jaarmenian'] = 0x0571;
  7464. t['jabengali'] = 0x099C;
  7465. t['jadeva'] = 0x091C;
  7466. t['jagujarati'] = 0x0A9C;
  7467. t['jagurmukhi'] = 0x0A1C;
  7468. t['jbopomofo'] = 0x3110;
  7469. t['jcaron'] = 0x01F0;
  7470. t['jcircle'] = 0x24D9;
  7471. t['jcircumflex'] = 0x0135;
  7472. t['jcrossedtail'] = 0x029D;
  7473. t['jdotlessstroke'] = 0x025F;
  7474. t['jecyrillic'] = 0x0458;
  7475. t['jeemarabic'] = 0x062C;
  7476. t['jeemfinalarabic'] = 0xFE9E;
  7477. t['jeeminitialarabic'] = 0xFE9F;
  7478. t['jeemmedialarabic'] = 0xFEA0;
  7479. t['jeharabic'] = 0x0698;
  7480. t['jehfinalarabic'] = 0xFB8B;
  7481. t['jhabengali'] = 0x099D;
  7482. t['jhadeva'] = 0x091D;
  7483. t['jhagujarati'] = 0x0A9D;
  7484. t['jhagurmukhi'] = 0x0A1D;
  7485. t['jheharmenian'] = 0x057B;
  7486. t['jis'] = 0x3004;
  7487. t['jmonospace'] = 0xFF4A;
  7488. t['jparen'] = 0x24A5;
  7489. t['jsuperior'] = 0x02B2;
  7490. t['k'] = 0x006B;
  7491. t['kabashkircyrillic'] = 0x04A1;
  7492. t['kabengali'] = 0x0995;
  7493. t['kacute'] = 0x1E31;
  7494. t['kacyrillic'] = 0x043A;
  7495. t['kadescendercyrillic'] = 0x049B;
  7496. t['kadeva'] = 0x0915;
  7497. t['kaf'] = 0x05DB;
  7498. t['kafarabic'] = 0x0643;
  7499. t['kafdagesh'] = 0xFB3B;
  7500. t['kafdageshhebrew'] = 0xFB3B;
  7501. t['kaffinalarabic'] = 0xFEDA;
  7502. t['kafhebrew'] = 0x05DB;
  7503. t['kafinitialarabic'] = 0xFEDB;
  7504. t['kafmedialarabic'] = 0xFEDC;
  7505. t['kafrafehebrew'] = 0xFB4D;
  7506. t['kagujarati'] = 0x0A95;
  7507. t['kagurmukhi'] = 0x0A15;
  7508. t['kahiragana'] = 0x304B;
  7509. t['kahookcyrillic'] = 0x04C4;
  7510. t['kakatakana'] = 0x30AB;
  7511. t['kakatakanahalfwidth'] = 0xFF76;
  7512. t['kappa'] = 0x03BA;
  7513. t['kappasymbolgreek'] = 0x03F0;
  7514. t['kapyeounmieumkorean'] = 0x3171;
  7515. t['kapyeounphieuphkorean'] = 0x3184;
  7516. t['kapyeounpieupkorean'] = 0x3178;
  7517. t['kapyeounssangpieupkorean'] = 0x3179;
  7518. t['karoriisquare'] = 0x330D;
  7519. t['kashidaautoarabic'] = 0x0640;
  7520. t['kashidaautonosidebearingarabic'] = 0x0640;
  7521. t['kasmallkatakana'] = 0x30F5;
  7522. t['kasquare'] = 0x3384;
  7523. t['kasraarabic'] = 0x0650;
  7524. t['kasratanarabic'] = 0x064D;
  7525. t['kastrokecyrillic'] = 0x049F;
  7526. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7527. t['kaverticalstrokecyrillic'] = 0x049D;
  7528. t['kbopomofo'] = 0x310E;
  7529. t['kcalsquare'] = 0x3389;
  7530. t['kcaron'] = 0x01E9;
  7531. t['kcedilla'] = 0x0137;
  7532. t['kcircle'] = 0x24DA;
  7533. t['kcommaaccent'] = 0x0137;
  7534. t['kdotbelow'] = 0x1E33;
  7535. t['keharmenian'] = 0x0584;
  7536. t['kehiragana'] = 0x3051;
  7537. t['kekatakana'] = 0x30B1;
  7538. t['kekatakanahalfwidth'] = 0xFF79;
  7539. t['kenarmenian'] = 0x056F;
  7540. t['kesmallkatakana'] = 0x30F6;
  7541. t['kgreenlandic'] = 0x0138;
  7542. t['khabengali'] = 0x0996;
  7543. t['khacyrillic'] = 0x0445;
  7544. t['khadeva'] = 0x0916;
  7545. t['khagujarati'] = 0x0A96;
  7546. t['khagurmukhi'] = 0x0A16;
  7547. t['khaharabic'] = 0x062E;
  7548. t['khahfinalarabic'] = 0xFEA6;
  7549. t['khahinitialarabic'] = 0xFEA7;
  7550. t['khahmedialarabic'] = 0xFEA8;
  7551. t['kheicoptic'] = 0x03E7;
  7552. t['khhadeva'] = 0x0959;
  7553. t['khhagurmukhi'] = 0x0A59;
  7554. t['khieukhacirclekorean'] = 0x3278;
  7555. t['khieukhaparenkorean'] = 0x3218;
  7556. t['khieukhcirclekorean'] = 0x326A;
  7557. t['khieukhkorean'] = 0x314B;
  7558. t['khieukhparenkorean'] = 0x320A;
  7559. t['khokhaithai'] = 0x0E02;
  7560. t['khokhonthai'] = 0x0E05;
  7561. t['khokhuatthai'] = 0x0E03;
  7562. t['khokhwaithai'] = 0x0E04;
  7563. t['khomutthai'] = 0x0E5B;
  7564. t['khook'] = 0x0199;
  7565. t['khorakhangthai'] = 0x0E06;
  7566. t['khzsquare'] = 0x3391;
  7567. t['kihiragana'] = 0x304D;
  7568. t['kikatakana'] = 0x30AD;
  7569. t['kikatakanahalfwidth'] = 0xFF77;
  7570. t['kiroguramusquare'] = 0x3315;
  7571. t['kiromeetorusquare'] = 0x3316;
  7572. t['kirosquare'] = 0x3314;
  7573. t['kiyeokacirclekorean'] = 0x326E;
  7574. t['kiyeokaparenkorean'] = 0x320E;
  7575. t['kiyeokcirclekorean'] = 0x3260;
  7576. t['kiyeokkorean'] = 0x3131;
  7577. t['kiyeokparenkorean'] = 0x3200;
  7578. t['kiyeoksioskorean'] = 0x3133;
  7579. t['kjecyrillic'] = 0x045C;
  7580. t['klinebelow'] = 0x1E35;
  7581. t['klsquare'] = 0x3398;
  7582. t['kmcubedsquare'] = 0x33A6;
  7583. t['kmonospace'] = 0xFF4B;
  7584. t['kmsquaredsquare'] = 0x33A2;
  7585. t['kohiragana'] = 0x3053;
  7586. t['kohmsquare'] = 0x33C0;
  7587. t['kokaithai'] = 0x0E01;
  7588. t['kokatakana'] = 0x30B3;
  7589. t['kokatakanahalfwidth'] = 0xFF7A;
  7590. t['kooposquare'] = 0x331E;
  7591. t['koppacyrillic'] = 0x0481;
  7592. t['koreanstandardsymbol'] = 0x327F;
  7593. t['koroniscmb'] = 0x0343;
  7594. t['kparen'] = 0x24A6;
  7595. t['kpasquare'] = 0x33AA;
  7596. t['ksicyrillic'] = 0x046F;
  7597. t['ktsquare'] = 0x33CF;
  7598. t['kturned'] = 0x029E;
  7599. t['kuhiragana'] = 0x304F;
  7600. t['kukatakana'] = 0x30AF;
  7601. t['kukatakanahalfwidth'] = 0xFF78;
  7602. t['kvsquare'] = 0x33B8;
  7603. t['kwsquare'] = 0x33BE;
  7604. t['l'] = 0x006C;
  7605. t['labengali'] = 0x09B2;
  7606. t['lacute'] = 0x013A;
  7607. t['ladeva'] = 0x0932;
  7608. t['lagujarati'] = 0x0AB2;
  7609. t['lagurmukhi'] = 0x0A32;
  7610. t['lakkhangyaothai'] = 0x0E45;
  7611. t['lamaleffinalarabic'] = 0xFEFC;
  7612. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7613. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7614. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7615. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7616. t['lamalefisolatedarabic'] = 0xFEFB;
  7617. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7618. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7619. t['lamarabic'] = 0x0644;
  7620. t['lambda'] = 0x03BB;
  7621. t['lambdastroke'] = 0x019B;
  7622. t['lamed'] = 0x05DC;
  7623. t['lameddagesh'] = 0xFB3C;
  7624. t['lameddageshhebrew'] = 0xFB3C;
  7625. t['lamedhebrew'] = 0x05DC;
  7626. t['lamfinalarabic'] = 0xFEDE;
  7627. t['lamhahinitialarabic'] = 0xFCCA;
  7628. t['laminitialarabic'] = 0xFEDF;
  7629. t['lamjeeminitialarabic'] = 0xFCC9;
  7630. t['lamkhahinitialarabic'] = 0xFCCB;
  7631. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7632. t['lammedialarabic'] = 0xFEE0;
  7633. t['lammeemhahinitialarabic'] = 0xFD88;
  7634. t['lammeeminitialarabic'] = 0xFCCC;
  7635. t['largecircle'] = 0x25EF;
  7636. t['lbar'] = 0x019A;
  7637. t['lbelt'] = 0x026C;
  7638. t['lbopomofo'] = 0x310C;
  7639. t['lcaron'] = 0x013E;
  7640. t['lcedilla'] = 0x013C;
  7641. t['lcircle'] = 0x24DB;
  7642. t['lcircumflexbelow'] = 0x1E3D;
  7643. t['lcommaaccent'] = 0x013C;
  7644. t['ldot'] = 0x0140;
  7645. t['ldotaccent'] = 0x0140;
  7646. t['ldotbelow'] = 0x1E37;
  7647. t['ldotbelowmacron'] = 0x1E39;
  7648. t['leftangleabovecmb'] = 0x031A;
  7649. t['lefttackbelowcmb'] = 0x0318;
  7650. t['less'] = 0x003C;
  7651. t['lessequal'] = 0x2264;
  7652. t['lessequalorgreater'] = 0x22DA;
  7653. t['lessmonospace'] = 0xFF1C;
  7654. t['lessorequivalent'] = 0x2272;
  7655. t['lessorgreater'] = 0x2276;
  7656. t['lessoverequal'] = 0x2266;
  7657. t['lesssmall'] = 0xFE64;
  7658. t['lezh'] = 0x026E;
  7659. t['lfblock'] = 0x258C;
  7660. t['lhookretroflex'] = 0x026D;
  7661. t['lira'] = 0x20A4;
  7662. t['liwnarmenian'] = 0x056C;
  7663. t['lj'] = 0x01C9;
  7664. t['ljecyrillic'] = 0x0459;
  7665. t['ll'] = 0xF6C0;
  7666. t['lladeva'] = 0x0933;
  7667. t['llagujarati'] = 0x0AB3;
  7668. t['llinebelow'] = 0x1E3B;
  7669. t['llladeva'] = 0x0934;
  7670. t['llvocalicbengali'] = 0x09E1;
  7671. t['llvocalicdeva'] = 0x0961;
  7672. t['llvocalicvowelsignbengali'] = 0x09E3;
  7673. t['llvocalicvowelsigndeva'] = 0x0963;
  7674. t['lmiddletilde'] = 0x026B;
  7675. t['lmonospace'] = 0xFF4C;
  7676. t['lmsquare'] = 0x33D0;
  7677. t['lochulathai'] = 0x0E2C;
  7678. t['logicaland'] = 0x2227;
  7679. t['logicalnot'] = 0x00AC;
  7680. t['logicalnotreversed'] = 0x2310;
  7681. t['logicalor'] = 0x2228;
  7682. t['lolingthai'] = 0x0E25;
  7683. t['longs'] = 0x017F;
  7684. t['lowlinecenterline'] = 0xFE4E;
  7685. t['lowlinecmb'] = 0x0332;
  7686. t['lowlinedashed'] = 0xFE4D;
  7687. t['lozenge'] = 0x25CA;
  7688. t['lparen'] = 0x24A7;
  7689. t['lslash'] = 0x0142;
  7690. t['lsquare'] = 0x2113;
  7691. t['lsuperior'] = 0xF6EE;
  7692. t['ltshade'] = 0x2591;
  7693. t['luthai'] = 0x0E26;
  7694. t['lvocalicbengali'] = 0x098C;
  7695. t['lvocalicdeva'] = 0x090C;
  7696. t['lvocalicvowelsignbengali'] = 0x09E2;
  7697. t['lvocalicvowelsigndeva'] = 0x0962;
  7698. t['lxsquare'] = 0x33D3;
  7699. t['m'] = 0x006D;
  7700. t['mabengali'] = 0x09AE;
  7701. t['macron'] = 0x00AF;
  7702. t['macronbelowcmb'] = 0x0331;
  7703. t['macroncmb'] = 0x0304;
  7704. t['macronlowmod'] = 0x02CD;
  7705. t['macronmonospace'] = 0xFFE3;
  7706. t['macute'] = 0x1E3F;
  7707. t['madeva'] = 0x092E;
  7708. t['magujarati'] = 0x0AAE;
  7709. t['magurmukhi'] = 0x0A2E;
  7710. t['mahapakhhebrew'] = 0x05A4;
  7711. t['mahapakhlefthebrew'] = 0x05A4;
  7712. t['mahiragana'] = 0x307E;
  7713. t['maichattawalowleftthai'] = 0xF895;
  7714. t['maichattawalowrightthai'] = 0xF894;
  7715. t['maichattawathai'] = 0x0E4B;
  7716. t['maichattawaupperleftthai'] = 0xF893;
  7717. t['maieklowleftthai'] = 0xF88C;
  7718. t['maieklowrightthai'] = 0xF88B;
  7719. t['maiekthai'] = 0x0E48;
  7720. t['maiekupperleftthai'] = 0xF88A;
  7721. t['maihanakatleftthai'] = 0xF884;
  7722. t['maihanakatthai'] = 0x0E31;
  7723. t['maitaikhuleftthai'] = 0xF889;
  7724. t['maitaikhuthai'] = 0x0E47;
  7725. t['maitholowleftthai'] = 0xF88F;
  7726. t['maitholowrightthai'] = 0xF88E;
  7727. t['maithothai'] = 0x0E49;
  7728. t['maithoupperleftthai'] = 0xF88D;
  7729. t['maitrilowleftthai'] = 0xF892;
  7730. t['maitrilowrightthai'] = 0xF891;
  7731. t['maitrithai'] = 0x0E4A;
  7732. t['maitriupperleftthai'] = 0xF890;
  7733. t['maiyamokthai'] = 0x0E46;
  7734. t['makatakana'] = 0x30DE;
  7735. t['makatakanahalfwidth'] = 0xFF8F;
  7736. t['male'] = 0x2642;
  7737. t['mansyonsquare'] = 0x3347;
  7738. t['maqafhebrew'] = 0x05BE;
  7739. t['mars'] = 0x2642;
  7740. t['masoracirclehebrew'] = 0x05AF;
  7741. t['masquare'] = 0x3383;
  7742. t['mbopomofo'] = 0x3107;
  7743. t['mbsquare'] = 0x33D4;
  7744. t['mcircle'] = 0x24DC;
  7745. t['mcubedsquare'] = 0x33A5;
  7746. t['mdotaccent'] = 0x1E41;
  7747. t['mdotbelow'] = 0x1E43;
  7748. t['meemarabic'] = 0x0645;
  7749. t['meemfinalarabic'] = 0xFEE2;
  7750. t['meeminitialarabic'] = 0xFEE3;
  7751. t['meemmedialarabic'] = 0xFEE4;
  7752. t['meemmeeminitialarabic'] = 0xFCD1;
  7753. t['meemmeemisolatedarabic'] = 0xFC48;
  7754. t['meetorusquare'] = 0x334D;
  7755. t['mehiragana'] = 0x3081;
  7756. t['meizierasquare'] = 0x337E;
  7757. t['mekatakana'] = 0x30E1;
  7758. t['mekatakanahalfwidth'] = 0xFF92;
  7759. t['mem'] = 0x05DE;
  7760. t['memdagesh'] = 0xFB3E;
  7761. t['memdageshhebrew'] = 0xFB3E;
  7762. t['memhebrew'] = 0x05DE;
  7763. t['menarmenian'] = 0x0574;
  7764. t['merkhahebrew'] = 0x05A5;
  7765. t['merkhakefulahebrew'] = 0x05A6;
  7766. t['merkhakefulalefthebrew'] = 0x05A6;
  7767. t['merkhalefthebrew'] = 0x05A5;
  7768. t['mhook'] = 0x0271;
  7769. t['mhzsquare'] = 0x3392;
  7770. t['middledotkatakanahalfwidth'] = 0xFF65;
  7771. t['middot'] = 0x00B7;
  7772. t['mieumacirclekorean'] = 0x3272;
  7773. t['mieumaparenkorean'] = 0x3212;
  7774. t['mieumcirclekorean'] = 0x3264;
  7775. t['mieumkorean'] = 0x3141;
  7776. t['mieumpansioskorean'] = 0x3170;
  7777. t['mieumparenkorean'] = 0x3204;
  7778. t['mieumpieupkorean'] = 0x316E;
  7779. t['mieumsioskorean'] = 0x316F;
  7780. t['mihiragana'] = 0x307F;
  7781. t['mikatakana'] = 0x30DF;
  7782. t['mikatakanahalfwidth'] = 0xFF90;
  7783. t['minus'] = 0x2212;
  7784. t['minusbelowcmb'] = 0x0320;
  7785. t['minuscircle'] = 0x2296;
  7786. t['minusmod'] = 0x02D7;
  7787. t['minusplus'] = 0x2213;
  7788. t['minute'] = 0x2032;
  7789. t['miribaarusquare'] = 0x334A;
  7790. t['mirisquare'] = 0x3349;
  7791. t['mlonglegturned'] = 0x0270;
  7792. t['mlsquare'] = 0x3396;
  7793. t['mmcubedsquare'] = 0x33A3;
  7794. t['mmonospace'] = 0xFF4D;
  7795. t['mmsquaredsquare'] = 0x339F;
  7796. t['mohiragana'] = 0x3082;
  7797. t['mohmsquare'] = 0x33C1;
  7798. t['mokatakana'] = 0x30E2;
  7799. t['mokatakanahalfwidth'] = 0xFF93;
  7800. t['molsquare'] = 0x33D6;
  7801. t['momathai'] = 0x0E21;
  7802. t['moverssquare'] = 0x33A7;
  7803. t['moverssquaredsquare'] = 0x33A8;
  7804. t['mparen'] = 0x24A8;
  7805. t['mpasquare'] = 0x33AB;
  7806. t['mssquare'] = 0x33B3;
  7807. t['msuperior'] = 0xF6EF;
  7808. t['mturned'] = 0x026F;
  7809. t['mu'] = 0x00B5;
  7810. t['mu1'] = 0x00B5;
  7811. t['muasquare'] = 0x3382;
  7812. t['muchgreater'] = 0x226B;
  7813. t['muchless'] = 0x226A;
  7814. t['mufsquare'] = 0x338C;
  7815. t['mugreek'] = 0x03BC;
  7816. t['mugsquare'] = 0x338D;
  7817. t['muhiragana'] = 0x3080;
  7818. t['mukatakana'] = 0x30E0;
  7819. t['mukatakanahalfwidth'] = 0xFF91;
  7820. t['mulsquare'] = 0x3395;
  7821. t['multiply'] = 0x00D7;
  7822. t['mumsquare'] = 0x339B;
  7823. t['munahhebrew'] = 0x05A3;
  7824. t['munahlefthebrew'] = 0x05A3;
  7825. t['musicalnote'] = 0x266A;
  7826. t['musicalnotedbl'] = 0x266B;
  7827. t['musicflatsign'] = 0x266D;
  7828. t['musicsharpsign'] = 0x266F;
  7829. t['mussquare'] = 0x33B2;
  7830. t['muvsquare'] = 0x33B6;
  7831. t['muwsquare'] = 0x33BC;
  7832. t['mvmegasquare'] = 0x33B9;
  7833. t['mvsquare'] = 0x33B7;
  7834. t['mwmegasquare'] = 0x33BF;
  7835. t['mwsquare'] = 0x33BD;
  7836. t['n'] = 0x006E;
  7837. t['nabengali'] = 0x09A8;
  7838. t['nabla'] = 0x2207;
  7839. t['nacute'] = 0x0144;
  7840. t['nadeva'] = 0x0928;
  7841. t['nagujarati'] = 0x0AA8;
  7842. t['nagurmukhi'] = 0x0A28;
  7843. t['nahiragana'] = 0x306A;
  7844. t['nakatakana'] = 0x30CA;
  7845. t['nakatakanahalfwidth'] = 0xFF85;
  7846. t['napostrophe'] = 0x0149;
  7847. t['nasquare'] = 0x3381;
  7848. t['nbopomofo'] = 0x310B;
  7849. t['nbspace'] = 0x00A0;
  7850. t['ncaron'] = 0x0148;
  7851. t['ncedilla'] = 0x0146;
  7852. t['ncircle'] = 0x24DD;
  7853. t['ncircumflexbelow'] = 0x1E4B;
  7854. t['ncommaaccent'] = 0x0146;
  7855. t['ndotaccent'] = 0x1E45;
  7856. t['ndotbelow'] = 0x1E47;
  7857. t['nehiragana'] = 0x306D;
  7858. t['nekatakana'] = 0x30CD;
  7859. t['nekatakanahalfwidth'] = 0xFF88;
  7860. t['newsheqelsign'] = 0x20AA;
  7861. t['nfsquare'] = 0x338B;
  7862. t['ngabengali'] = 0x0999;
  7863. t['ngadeva'] = 0x0919;
  7864. t['ngagujarati'] = 0x0A99;
  7865. t['ngagurmukhi'] = 0x0A19;
  7866. t['ngonguthai'] = 0x0E07;
  7867. t['nhiragana'] = 0x3093;
  7868. t['nhookleft'] = 0x0272;
  7869. t['nhookretroflex'] = 0x0273;
  7870. t['nieunacirclekorean'] = 0x326F;
  7871. t['nieunaparenkorean'] = 0x320F;
  7872. t['nieuncieuckorean'] = 0x3135;
  7873. t['nieuncirclekorean'] = 0x3261;
  7874. t['nieunhieuhkorean'] = 0x3136;
  7875. t['nieunkorean'] = 0x3134;
  7876. t['nieunpansioskorean'] = 0x3168;
  7877. t['nieunparenkorean'] = 0x3201;
  7878. t['nieunsioskorean'] = 0x3167;
  7879. t['nieuntikeutkorean'] = 0x3166;
  7880. t['nihiragana'] = 0x306B;
  7881. t['nikatakana'] = 0x30CB;
  7882. t['nikatakanahalfwidth'] = 0xFF86;
  7883. t['nikhahitleftthai'] = 0xF899;
  7884. t['nikhahitthai'] = 0x0E4D;
  7885. t['nine'] = 0x0039;
  7886. t['ninearabic'] = 0x0669;
  7887. t['ninebengali'] = 0x09EF;
  7888. t['ninecircle'] = 0x2468;
  7889. t['ninecircleinversesansserif'] = 0x2792;
  7890. t['ninedeva'] = 0x096F;
  7891. t['ninegujarati'] = 0x0AEF;
  7892. t['ninegurmukhi'] = 0x0A6F;
  7893. t['ninehackarabic'] = 0x0669;
  7894. t['ninehangzhou'] = 0x3029;
  7895. t['nineideographicparen'] = 0x3228;
  7896. t['nineinferior'] = 0x2089;
  7897. t['ninemonospace'] = 0xFF19;
  7898. t['nineoldstyle'] = 0xF739;
  7899. t['nineparen'] = 0x247C;
  7900. t['nineperiod'] = 0x2490;
  7901. t['ninepersian'] = 0x06F9;
  7902. t['nineroman'] = 0x2178;
  7903. t['ninesuperior'] = 0x2079;
  7904. t['nineteencircle'] = 0x2472;
  7905. t['nineteenparen'] = 0x2486;
  7906. t['nineteenperiod'] = 0x249A;
  7907. t['ninethai'] = 0x0E59;
  7908. t['nj'] = 0x01CC;
  7909. t['njecyrillic'] = 0x045A;
  7910. t['nkatakana'] = 0x30F3;
  7911. t['nkatakanahalfwidth'] = 0xFF9D;
  7912. t['nlegrightlong'] = 0x019E;
  7913. t['nlinebelow'] = 0x1E49;
  7914. t['nmonospace'] = 0xFF4E;
  7915. t['nmsquare'] = 0x339A;
  7916. t['nnabengali'] = 0x09A3;
  7917. t['nnadeva'] = 0x0923;
  7918. t['nnagujarati'] = 0x0AA3;
  7919. t['nnagurmukhi'] = 0x0A23;
  7920. t['nnnadeva'] = 0x0929;
  7921. t['nohiragana'] = 0x306E;
  7922. t['nokatakana'] = 0x30CE;
  7923. t['nokatakanahalfwidth'] = 0xFF89;
  7924. t['nonbreakingspace'] = 0x00A0;
  7925. t['nonenthai'] = 0x0E13;
  7926. t['nonuthai'] = 0x0E19;
  7927. t['noonarabic'] = 0x0646;
  7928. t['noonfinalarabic'] = 0xFEE6;
  7929. t['noonghunnaarabic'] = 0x06BA;
  7930. t['noonghunnafinalarabic'] = 0xFB9F;
  7931. t['nooninitialarabic'] = 0xFEE7;
  7932. t['noonjeeminitialarabic'] = 0xFCD2;
  7933. t['noonjeemisolatedarabic'] = 0xFC4B;
  7934. t['noonmedialarabic'] = 0xFEE8;
  7935. t['noonmeeminitialarabic'] = 0xFCD5;
  7936. t['noonmeemisolatedarabic'] = 0xFC4E;
  7937. t['noonnoonfinalarabic'] = 0xFC8D;
  7938. t['notcontains'] = 0x220C;
  7939. t['notelement'] = 0x2209;
  7940. t['notelementof'] = 0x2209;
  7941. t['notequal'] = 0x2260;
  7942. t['notgreater'] = 0x226F;
  7943. t['notgreaternorequal'] = 0x2271;
  7944. t['notgreaternorless'] = 0x2279;
  7945. t['notidentical'] = 0x2262;
  7946. t['notless'] = 0x226E;
  7947. t['notlessnorequal'] = 0x2270;
  7948. t['notparallel'] = 0x2226;
  7949. t['notprecedes'] = 0x2280;
  7950. t['notsubset'] = 0x2284;
  7951. t['notsucceeds'] = 0x2281;
  7952. t['notsuperset'] = 0x2285;
  7953. t['nowarmenian'] = 0x0576;
  7954. t['nparen'] = 0x24A9;
  7955. t['nssquare'] = 0x33B1;
  7956. t['nsuperior'] = 0x207F;
  7957. t['ntilde'] = 0x00F1;
  7958. t['nu'] = 0x03BD;
  7959. t['nuhiragana'] = 0x306C;
  7960. t['nukatakana'] = 0x30CC;
  7961. t['nukatakanahalfwidth'] = 0xFF87;
  7962. t['nuktabengali'] = 0x09BC;
  7963. t['nuktadeva'] = 0x093C;
  7964. t['nuktagujarati'] = 0x0ABC;
  7965. t['nuktagurmukhi'] = 0x0A3C;
  7966. t['numbersign'] = 0x0023;
  7967. t['numbersignmonospace'] = 0xFF03;
  7968. t['numbersignsmall'] = 0xFE5F;
  7969. t['numeralsigngreek'] = 0x0374;
  7970. t['numeralsignlowergreek'] = 0x0375;
  7971. t['numero'] = 0x2116;
  7972. t['nun'] = 0x05E0;
  7973. t['nundagesh'] = 0xFB40;
  7974. t['nundageshhebrew'] = 0xFB40;
  7975. t['nunhebrew'] = 0x05E0;
  7976. t['nvsquare'] = 0x33B5;
  7977. t['nwsquare'] = 0x33BB;
  7978. t['nyabengali'] = 0x099E;
  7979. t['nyadeva'] = 0x091E;
  7980. t['nyagujarati'] = 0x0A9E;
  7981. t['nyagurmukhi'] = 0x0A1E;
  7982. t['o'] = 0x006F;
  7983. t['oacute'] = 0x00F3;
  7984. t['oangthai'] = 0x0E2D;
  7985. t['obarred'] = 0x0275;
  7986. t['obarredcyrillic'] = 0x04E9;
  7987. t['obarreddieresiscyrillic'] = 0x04EB;
  7988. t['obengali'] = 0x0993;
  7989. t['obopomofo'] = 0x311B;
  7990. t['obreve'] = 0x014F;
  7991. t['ocandradeva'] = 0x0911;
  7992. t['ocandragujarati'] = 0x0A91;
  7993. t['ocandravowelsigndeva'] = 0x0949;
  7994. t['ocandravowelsigngujarati'] = 0x0AC9;
  7995. t['ocaron'] = 0x01D2;
  7996. t['ocircle'] = 0x24DE;
  7997. t['ocircumflex'] = 0x00F4;
  7998. t['ocircumflexacute'] = 0x1ED1;
  7999. t['ocircumflexdotbelow'] = 0x1ED9;
  8000. t['ocircumflexgrave'] = 0x1ED3;
  8001. t['ocircumflexhookabove'] = 0x1ED5;
  8002. t['ocircumflextilde'] = 0x1ED7;
  8003. t['ocyrillic'] = 0x043E;
  8004. t['odblacute'] = 0x0151;
  8005. t['odblgrave'] = 0x020D;
  8006. t['odeva'] = 0x0913;
  8007. t['odieresis'] = 0x00F6;
  8008. t['odieresiscyrillic'] = 0x04E7;
  8009. t['odotbelow'] = 0x1ECD;
  8010. t['oe'] = 0x0153;
  8011. t['oekorean'] = 0x315A;
  8012. t['ogonek'] = 0x02DB;
  8013. t['ogonekcmb'] = 0x0328;
  8014. t['ograve'] = 0x00F2;
  8015. t['ogujarati'] = 0x0A93;
  8016. t['oharmenian'] = 0x0585;
  8017. t['ohiragana'] = 0x304A;
  8018. t['ohookabove'] = 0x1ECF;
  8019. t['ohorn'] = 0x01A1;
  8020. t['ohornacute'] = 0x1EDB;
  8021. t['ohorndotbelow'] = 0x1EE3;
  8022. t['ohorngrave'] = 0x1EDD;
  8023. t['ohornhookabove'] = 0x1EDF;
  8024. t['ohorntilde'] = 0x1EE1;
  8025. t['ohungarumlaut'] = 0x0151;
  8026. t['oi'] = 0x01A3;
  8027. t['oinvertedbreve'] = 0x020F;
  8028. t['okatakana'] = 0x30AA;
  8029. t['okatakanahalfwidth'] = 0xFF75;
  8030. t['okorean'] = 0x3157;
  8031. t['olehebrew'] = 0x05AB;
  8032. t['omacron'] = 0x014D;
  8033. t['omacronacute'] = 0x1E53;
  8034. t['omacrongrave'] = 0x1E51;
  8035. t['omdeva'] = 0x0950;
  8036. t['omega'] = 0x03C9;
  8037. t['omega1'] = 0x03D6;
  8038. t['omegacyrillic'] = 0x0461;
  8039. t['omegalatinclosed'] = 0x0277;
  8040. t['omegaroundcyrillic'] = 0x047B;
  8041. t['omegatitlocyrillic'] = 0x047D;
  8042. t['omegatonos'] = 0x03CE;
  8043. t['omgujarati'] = 0x0AD0;
  8044. t['omicron'] = 0x03BF;
  8045. t['omicrontonos'] = 0x03CC;
  8046. t['omonospace'] = 0xFF4F;
  8047. t['one'] = 0x0031;
  8048. t['onearabic'] = 0x0661;
  8049. t['onebengali'] = 0x09E7;
  8050. t['onecircle'] = 0x2460;
  8051. t['onecircleinversesansserif'] = 0x278A;
  8052. t['onedeva'] = 0x0967;
  8053. t['onedotenleader'] = 0x2024;
  8054. t['oneeighth'] = 0x215B;
  8055. t['onefitted'] = 0xF6DC;
  8056. t['onegujarati'] = 0x0AE7;
  8057. t['onegurmukhi'] = 0x0A67;
  8058. t['onehackarabic'] = 0x0661;
  8059. t['onehalf'] = 0x00BD;
  8060. t['onehangzhou'] = 0x3021;
  8061. t['oneideographicparen'] = 0x3220;
  8062. t['oneinferior'] = 0x2081;
  8063. t['onemonospace'] = 0xFF11;
  8064. t['onenumeratorbengali'] = 0x09F4;
  8065. t['oneoldstyle'] = 0xF731;
  8066. t['oneparen'] = 0x2474;
  8067. t['oneperiod'] = 0x2488;
  8068. t['onepersian'] = 0x06F1;
  8069. t['onequarter'] = 0x00BC;
  8070. t['oneroman'] = 0x2170;
  8071. t['onesuperior'] = 0x00B9;
  8072. t['onethai'] = 0x0E51;
  8073. t['onethird'] = 0x2153;
  8074. t['oogonek'] = 0x01EB;
  8075. t['oogonekmacron'] = 0x01ED;
  8076. t['oogurmukhi'] = 0x0A13;
  8077. t['oomatragurmukhi'] = 0x0A4B;
  8078. t['oopen'] = 0x0254;
  8079. t['oparen'] = 0x24AA;
  8080. t['openbullet'] = 0x25E6;
  8081. t['option'] = 0x2325;
  8082. t['ordfeminine'] = 0x00AA;
  8083. t['ordmasculine'] = 0x00BA;
  8084. t['orthogonal'] = 0x221F;
  8085. t['oshortdeva'] = 0x0912;
  8086. t['oshortvowelsigndeva'] = 0x094A;
  8087. t['oslash'] = 0x00F8;
  8088. t['oslashacute'] = 0x01FF;
  8089. t['osmallhiragana'] = 0x3049;
  8090. t['osmallkatakana'] = 0x30A9;
  8091. t['osmallkatakanahalfwidth'] = 0xFF6B;
  8092. t['ostrokeacute'] = 0x01FF;
  8093. t['osuperior'] = 0xF6F0;
  8094. t['otcyrillic'] = 0x047F;
  8095. t['otilde'] = 0x00F5;
  8096. t['otildeacute'] = 0x1E4D;
  8097. t['otildedieresis'] = 0x1E4F;
  8098. t['oubopomofo'] = 0x3121;
  8099. t['overline'] = 0x203E;
  8100. t['overlinecenterline'] = 0xFE4A;
  8101. t['overlinecmb'] = 0x0305;
  8102. t['overlinedashed'] = 0xFE49;
  8103. t['overlinedblwavy'] = 0xFE4C;
  8104. t['overlinewavy'] = 0xFE4B;
  8105. t['overscore'] = 0x00AF;
  8106. t['ovowelsignbengali'] = 0x09CB;
  8107. t['ovowelsigndeva'] = 0x094B;
  8108. t['ovowelsigngujarati'] = 0x0ACB;
  8109. t['p'] = 0x0070;
  8110. t['paampssquare'] = 0x3380;
  8111. t['paasentosquare'] = 0x332B;
  8112. t['pabengali'] = 0x09AA;
  8113. t['pacute'] = 0x1E55;
  8114. t['padeva'] = 0x092A;
  8115. t['pagedown'] = 0x21DF;
  8116. t['pageup'] = 0x21DE;
  8117. t['pagujarati'] = 0x0AAA;
  8118. t['pagurmukhi'] = 0x0A2A;
  8119. t['pahiragana'] = 0x3071;
  8120. t['paiyannoithai'] = 0x0E2F;
  8121. t['pakatakana'] = 0x30D1;
  8122. t['palatalizationcyrilliccmb'] = 0x0484;
  8123. t['palochkacyrillic'] = 0x04C0;
  8124. t['pansioskorean'] = 0x317F;
  8125. t['paragraph'] = 0x00B6;
  8126. t['parallel'] = 0x2225;
  8127. t['parenleft'] = 0x0028;
  8128. t['parenleftaltonearabic'] = 0xFD3E;
  8129. t['parenleftbt'] = 0xF8ED;
  8130. t['parenleftex'] = 0xF8EC;
  8131. t['parenleftinferior'] = 0x208D;
  8132. t['parenleftmonospace'] = 0xFF08;
  8133. t['parenleftsmall'] = 0xFE59;
  8134. t['parenleftsuperior'] = 0x207D;
  8135. t['parenlefttp'] = 0xF8EB;
  8136. t['parenleftvertical'] = 0xFE35;
  8137. t['parenright'] = 0x0029;
  8138. t['parenrightaltonearabic'] = 0xFD3F;
  8139. t['parenrightbt'] = 0xF8F8;
  8140. t['parenrightex'] = 0xF8F7;
  8141. t['parenrightinferior'] = 0x208E;
  8142. t['parenrightmonospace'] = 0xFF09;
  8143. t['parenrightsmall'] = 0xFE5A;
  8144. t['parenrightsuperior'] = 0x207E;
  8145. t['parenrighttp'] = 0xF8F6;
  8146. t['parenrightvertical'] = 0xFE36;
  8147. t['partialdiff'] = 0x2202;
  8148. t['paseqhebrew'] = 0x05C0;
  8149. t['pashtahebrew'] = 0x0599;
  8150. t['pasquare'] = 0x33A9;
  8151. t['patah'] = 0x05B7;
  8152. t['patah11'] = 0x05B7;
  8153. t['patah1d'] = 0x05B7;
  8154. t['patah2a'] = 0x05B7;
  8155. t['patahhebrew'] = 0x05B7;
  8156. t['patahnarrowhebrew'] = 0x05B7;
  8157. t['patahquarterhebrew'] = 0x05B7;
  8158. t['patahwidehebrew'] = 0x05B7;
  8159. t['pazerhebrew'] = 0x05A1;
  8160. t['pbopomofo'] = 0x3106;
  8161. t['pcircle'] = 0x24DF;
  8162. t['pdotaccent'] = 0x1E57;
  8163. t['pe'] = 0x05E4;
  8164. t['pecyrillic'] = 0x043F;
  8165. t['pedagesh'] = 0xFB44;
  8166. t['pedageshhebrew'] = 0xFB44;
  8167. t['peezisquare'] = 0x333B;
  8168. t['pefinaldageshhebrew'] = 0xFB43;
  8169. t['peharabic'] = 0x067E;
  8170. t['peharmenian'] = 0x057A;
  8171. t['pehebrew'] = 0x05E4;
  8172. t['pehfinalarabic'] = 0xFB57;
  8173. t['pehinitialarabic'] = 0xFB58;
  8174. t['pehiragana'] = 0x307A;
  8175. t['pehmedialarabic'] = 0xFB59;
  8176. t['pekatakana'] = 0x30DA;
  8177. t['pemiddlehookcyrillic'] = 0x04A7;
  8178. t['perafehebrew'] = 0xFB4E;
  8179. t['percent'] = 0x0025;
  8180. t['percentarabic'] = 0x066A;
  8181. t['percentmonospace'] = 0xFF05;
  8182. t['percentsmall'] = 0xFE6A;
  8183. t['period'] = 0x002E;
  8184. t['periodarmenian'] = 0x0589;
  8185. t['periodcentered'] = 0x00B7;
  8186. t['periodhalfwidth'] = 0xFF61;
  8187. t['periodinferior'] = 0xF6E7;
  8188. t['periodmonospace'] = 0xFF0E;
  8189. t['periodsmall'] = 0xFE52;
  8190. t['periodsuperior'] = 0xF6E8;
  8191. t['perispomenigreekcmb'] = 0x0342;
  8192. t['perpendicular'] = 0x22A5;
  8193. t['perthousand'] = 0x2030;
  8194. t['peseta'] = 0x20A7;
  8195. t['pfsquare'] = 0x338A;
  8196. t['phabengali'] = 0x09AB;
  8197. t['phadeva'] = 0x092B;
  8198. t['phagujarati'] = 0x0AAB;
  8199. t['phagurmukhi'] = 0x0A2B;
  8200. t['phi'] = 0x03C6;
  8201. t['phi1'] = 0x03D5;
  8202. t['phieuphacirclekorean'] = 0x327A;
  8203. t['phieuphaparenkorean'] = 0x321A;
  8204. t['phieuphcirclekorean'] = 0x326C;
  8205. t['phieuphkorean'] = 0x314D;
  8206. t['phieuphparenkorean'] = 0x320C;
  8207. t['philatin'] = 0x0278;
  8208. t['phinthuthai'] = 0x0E3A;
  8209. t['phisymbolgreek'] = 0x03D5;
  8210. t['phook'] = 0x01A5;
  8211. t['phophanthai'] = 0x0E1E;
  8212. t['phophungthai'] = 0x0E1C;
  8213. t['phosamphaothai'] = 0x0E20;
  8214. t['pi'] = 0x03C0;
  8215. t['pieupacirclekorean'] = 0x3273;
  8216. t['pieupaparenkorean'] = 0x3213;
  8217. t['pieupcieuckorean'] = 0x3176;
  8218. t['pieupcirclekorean'] = 0x3265;
  8219. t['pieupkiyeokkorean'] = 0x3172;
  8220. t['pieupkorean'] = 0x3142;
  8221. t['pieupparenkorean'] = 0x3205;
  8222. t['pieupsioskiyeokkorean'] = 0x3174;
  8223. t['pieupsioskorean'] = 0x3144;
  8224. t['pieupsiostikeutkorean'] = 0x3175;
  8225. t['pieupthieuthkorean'] = 0x3177;
  8226. t['pieuptikeutkorean'] = 0x3173;
  8227. t['pihiragana'] = 0x3074;
  8228. t['pikatakana'] = 0x30D4;
  8229. t['pisymbolgreek'] = 0x03D6;
  8230. t['piwrarmenian'] = 0x0583;
  8231. t['plus'] = 0x002B;
  8232. t['plusbelowcmb'] = 0x031F;
  8233. t['pluscircle'] = 0x2295;
  8234. t['plusminus'] = 0x00B1;
  8235. t['plusmod'] = 0x02D6;
  8236. t['plusmonospace'] = 0xFF0B;
  8237. t['plussmall'] = 0xFE62;
  8238. t['plussuperior'] = 0x207A;
  8239. t['pmonospace'] = 0xFF50;
  8240. t['pmsquare'] = 0x33D8;
  8241. t['pohiragana'] = 0x307D;
  8242. t['pointingindexdownwhite'] = 0x261F;
  8243. t['pointingindexleftwhite'] = 0x261C;
  8244. t['pointingindexrightwhite'] = 0x261E;
  8245. t['pointingindexupwhite'] = 0x261D;
  8246. t['pokatakana'] = 0x30DD;
  8247. t['poplathai'] = 0x0E1B;
  8248. t['postalmark'] = 0x3012;
  8249. t['postalmarkface'] = 0x3020;
  8250. t['pparen'] = 0x24AB;
  8251. t['precedes'] = 0x227A;
  8252. t['prescription'] = 0x211E;
  8253. t['primemod'] = 0x02B9;
  8254. t['primereversed'] = 0x2035;
  8255. t['product'] = 0x220F;
  8256. t['projective'] = 0x2305;
  8257. t['prolongedkana'] = 0x30FC;
  8258. t['propellor'] = 0x2318;
  8259. t['propersubset'] = 0x2282;
  8260. t['propersuperset'] = 0x2283;
  8261. t['proportion'] = 0x2237;
  8262. t['proportional'] = 0x221D;
  8263. t['psi'] = 0x03C8;
  8264. t['psicyrillic'] = 0x0471;
  8265. t['psilipneumatacyrilliccmb'] = 0x0486;
  8266. t['pssquare'] = 0x33B0;
  8267. t['puhiragana'] = 0x3077;
  8268. t['pukatakana'] = 0x30D7;
  8269. t['pvsquare'] = 0x33B4;
  8270. t['pwsquare'] = 0x33BA;
  8271. t['q'] = 0x0071;
  8272. t['qadeva'] = 0x0958;
  8273. t['qadmahebrew'] = 0x05A8;
  8274. t['qafarabic'] = 0x0642;
  8275. t['qaffinalarabic'] = 0xFED6;
  8276. t['qafinitialarabic'] = 0xFED7;
  8277. t['qafmedialarabic'] = 0xFED8;
  8278. t['qamats'] = 0x05B8;
  8279. t['qamats10'] = 0x05B8;
  8280. t['qamats1a'] = 0x05B8;
  8281. t['qamats1c'] = 0x05B8;
  8282. t['qamats27'] = 0x05B8;
  8283. t['qamats29'] = 0x05B8;
  8284. t['qamats33'] = 0x05B8;
  8285. t['qamatsde'] = 0x05B8;
  8286. t['qamatshebrew'] = 0x05B8;
  8287. t['qamatsnarrowhebrew'] = 0x05B8;
  8288. t['qamatsqatanhebrew'] = 0x05B8;
  8289. t['qamatsqatannarrowhebrew'] = 0x05B8;
  8290. t['qamatsqatanquarterhebrew'] = 0x05B8;
  8291. t['qamatsqatanwidehebrew'] = 0x05B8;
  8292. t['qamatsquarterhebrew'] = 0x05B8;
  8293. t['qamatswidehebrew'] = 0x05B8;
  8294. t['qarneyparahebrew'] = 0x059F;
  8295. t['qbopomofo'] = 0x3111;
  8296. t['qcircle'] = 0x24E0;
  8297. t['qhook'] = 0x02A0;
  8298. t['qmonospace'] = 0xFF51;
  8299. t['qof'] = 0x05E7;
  8300. t['qofdagesh'] = 0xFB47;
  8301. t['qofdageshhebrew'] = 0xFB47;
  8302. t['qofhebrew'] = 0x05E7;
  8303. t['qparen'] = 0x24AC;
  8304. t['quarternote'] = 0x2669;
  8305. t['qubuts'] = 0x05BB;
  8306. t['qubuts18'] = 0x05BB;
  8307. t['qubuts25'] = 0x05BB;
  8308. t['qubuts31'] = 0x05BB;
  8309. t['qubutshebrew'] = 0x05BB;
  8310. t['qubutsnarrowhebrew'] = 0x05BB;
  8311. t['qubutsquarterhebrew'] = 0x05BB;
  8312. t['qubutswidehebrew'] = 0x05BB;
  8313. t['question'] = 0x003F;
  8314. t['questionarabic'] = 0x061F;
  8315. t['questionarmenian'] = 0x055E;
  8316. t['questiondown'] = 0x00BF;
  8317. t['questiondownsmall'] = 0xF7BF;
  8318. t['questiongreek'] = 0x037E;
  8319. t['questionmonospace'] = 0xFF1F;
  8320. t['questionsmall'] = 0xF73F;
  8321. t['quotedbl'] = 0x0022;
  8322. t['quotedblbase'] = 0x201E;
  8323. t['quotedblleft'] = 0x201C;
  8324. t['quotedblmonospace'] = 0xFF02;
  8325. t['quotedblprime'] = 0x301E;
  8326. t['quotedblprimereversed'] = 0x301D;
  8327. t['quotedblright'] = 0x201D;
  8328. t['quoteleft'] = 0x2018;
  8329. t['quoteleftreversed'] = 0x201B;
  8330. t['quotereversed'] = 0x201B;
  8331. t['quoteright'] = 0x2019;
  8332. t['quoterightn'] = 0x0149;
  8333. t['quotesinglbase'] = 0x201A;
  8334. t['quotesingle'] = 0x0027;
  8335. t['quotesinglemonospace'] = 0xFF07;
  8336. t['r'] = 0x0072;
  8337. t['raarmenian'] = 0x057C;
  8338. t['rabengali'] = 0x09B0;
  8339. t['racute'] = 0x0155;
  8340. t['radeva'] = 0x0930;
  8341. t['radical'] = 0x221A;
  8342. t['radicalex'] = 0xF8E5;
  8343. t['radoverssquare'] = 0x33AE;
  8344. t['radoverssquaredsquare'] = 0x33AF;
  8345. t['radsquare'] = 0x33AD;
  8346. t['rafe'] = 0x05BF;
  8347. t['rafehebrew'] = 0x05BF;
  8348. t['ragujarati'] = 0x0AB0;
  8349. t['ragurmukhi'] = 0x0A30;
  8350. t['rahiragana'] = 0x3089;
  8351. t['rakatakana'] = 0x30E9;
  8352. t['rakatakanahalfwidth'] = 0xFF97;
  8353. t['ralowerdiagonalbengali'] = 0x09F1;
  8354. t['ramiddlediagonalbengali'] = 0x09F0;
  8355. t['ramshorn'] = 0x0264;
  8356. t['ratio'] = 0x2236;
  8357. t['rbopomofo'] = 0x3116;
  8358. t['rcaron'] = 0x0159;
  8359. t['rcedilla'] = 0x0157;
  8360. t['rcircle'] = 0x24E1;
  8361. t['rcommaaccent'] = 0x0157;
  8362. t['rdblgrave'] = 0x0211;
  8363. t['rdotaccent'] = 0x1E59;
  8364. t['rdotbelow'] = 0x1E5B;
  8365. t['rdotbelowmacron'] = 0x1E5D;
  8366. t['referencemark'] = 0x203B;
  8367. t['reflexsubset'] = 0x2286;
  8368. t['reflexsuperset'] = 0x2287;
  8369. t['registered'] = 0x00AE;
  8370. t['registersans'] = 0xF8E8;
  8371. t['registerserif'] = 0xF6DA;
  8372. t['reharabic'] = 0x0631;
  8373. t['reharmenian'] = 0x0580;
  8374. t['rehfinalarabic'] = 0xFEAE;
  8375. t['rehiragana'] = 0x308C;
  8376. t['rekatakana'] = 0x30EC;
  8377. t['rekatakanahalfwidth'] = 0xFF9A;
  8378. t['resh'] = 0x05E8;
  8379. t['reshdageshhebrew'] = 0xFB48;
  8380. t['reshhebrew'] = 0x05E8;
  8381. t['reversedtilde'] = 0x223D;
  8382. t['reviahebrew'] = 0x0597;
  8383. t['reviamugrashhebrew'] = 0x0597;
  8384. t['revlogicalnot'] = 0x2310;
  8385. t['rfishhook'] = 0x027E;
  8386. t['rfishhookreversed'] = 0x027F;
  8387. t['rhabengali'] = 0x09DD;
  8388. t['rhadeva'] = 0x095D;
  8389. t['rho'] = 0x03C1;
  8390. t['rhook'] = 0x027D;
  8391. t['rhookturned'] = 0x027B;
  8392. t['rhookturnedsuperior'] = 0x02B5;
  8393. t['rhosymbolgreek'] = 0x03F1;
  8394. t['rhotichookmod'] = 0x02DE;
  8395. t['rieulacirclekorean'] = 0x3271;
  8396. t['rieulaparenkorean'] = 0x3211;
  8397. t['rieulcirclekorean'] = 0x3263;
  8398. t['rieulhieuhkorean'] = 0x3140;
  8399. t['rieulkiyeokkorean'] = 0x313A;
  8400. t['rieulkiyeoksioskorean'] = 0x3169;
  8401. t['rieulkorean'] = 0x3139;
  8402. t['rieulmieumkorean'] = 0x313B;
  8403. t['rieulpansioskorean'] = 0x316C;
  8404. t['rieulparenkorean'] = 0x3203;
  8405. t['rieulphieuphkorean'] = 0x313F;
  8406. t['rieulpieupkorean'] = 0x313C;
  8407. t['rieulpieupsioskorean'] = 0x316B;
  8408. t['rieulsioskorean'] = 0x313D;
  8409. t['rieulthieuthkorean'] = 0x313E;
  8410. t['rieultikeutkorean'] = 0x316A;
  8411. t['rieulyeorinhieuhkorean'] = 0x316D;
  8412. t['rightangle'] = 0x221F;
  8413. t['righttackbelowcmb'] = 0x0319;
  8414. t['righttriangle'] = 0x22BF;
  8415. t['rihiragana'] = 0x308A;
  8416. t['rikatakana'] = 0x30EA;
  8417. t['rikatakanahalfwidth'] = 0xFF98;
  8418. t['ring'] = 0x02DA;
  8419. t['ringbelowcmb'] = 0x0325;
  8420. t['ringcmb'] = 0x030A;
  8421. t['ringhalfleft'] = 0x02BF;
  8422. t['ringhalfleftarmenian'] = 0x0559;
  8423. t['ringhalfleftbelowcmb'] = 0x031C;
  8424. t['ringhalfleftcentered'] = 0x02D3;
  8425. t['ringhalfright'] = 0x02BE;
  8426. t['ringhalfrightbelowcmb'] = 0x0339;
  8427. t['ringhalfrightcentered'] = 0x02D2;
  8428. t['rinvertedbreve'] = 0x0213;
  8429. t['rittorusquare'] = 0x3351;
  8430. t['rlinebelow'] = 0x1E5F;
  8431. t['rlongleg'] = 0x027C;
  8432. t['rlonglegturned'] = 0x027A;
  8433. t['rmonospace'] = 0xFF52;
  8434. t['rohiragana'] = 0x308D;
  8435. t['rokatakana'] = 0x30ED;
  8436. t['rokatakanahalfwidth'] = 0xFF9B;
  8437. t['roruathai'] = 0x0E23;
  8438. t['rparen'] = 0x24AD;
  8439. t['rrabengali'] = 0x09DC;
  8440. t['rradeva'] = 0x0931;
  8441. t['rragurmukhi'] = 0x0A5C;
  8442. t['rreharabic'] = 0x0691;
  8443. t['rrehfinalarabic'] = 0xFB8D;
  8444. t['rrvocalicbengali'] = 0x09E0;
  8445. t['rrvocalicdeva'] = 0x0960;
  8446. t['rrvocalicgujarati'] = 0x0AE0;
  8447. t['rrvocalicvowelsignbengali'] = 0x09C4;
  8448. t['rrvocalicvowelsigndeva'] = 0x0944;
  8449. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  8450. t['rsuperior'] = 0xF6F1;
  8451. t['rtblock'] = 0x2590;
  8452. t['rturned'] = 0x0279;
  8453. t['rturnedsuperior'] = 0x02B4;
  8454. t['ruhiragana'] = 0x308B;
  8455. t['rukatakana'] = 0x30EB;
  8456. t['rukatakanahalfwidth'] = 0xFF99;
  8457. t['rupeemarkbengali'] = 0x09F2;
  8458. t['rupeesignbengali'] = 0x09F3;
  8459. t['rupiah'] = 0xF6DD;
  8460. t['ruthai'] = 0x0E24;
  8461. t['rvocalicbengali'] = 0x098B;
  8462. t['rvocalicdeva'] = 0x090B;
  8463. t['rvocalicgujarati'] = 0x0A8B;
  8464. t['rvocalicvowelsignbengali'] = 0x09C3;
  8465. t['rvocalicvowelsigndeva'] = 0x0943;
  8466. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  8467. t['s'] = 0x0073;
  8468. t['sabengali'] = 0x09B8;
  8469. t['sacute'] = 0x015B;
  8470. t['sacutedotaccent'] = 0x1E65;
  8471. t['sadarabic'] = 0x0635;
  8472. t['sadeva'] = 0x0938;
  8473. t['sadfinalarabic'] = 0xFEBA;
  8474. t['sadinitialarabic'] = 0xFEBB;
  8475. t['sadmedialarabic'] = 0xFEBC;
  8476. t['sagujarati'] = 0x0AB8;
  8477. t['sagurmukhi'] = 0x0A38;
  8478. t['sahiragana'] = 0x3055;
  8479. t['sakatakana'] = 0x30B5;
  8480. t['sakatakanahalfwidth'] = 0xFF7B;
  8481. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  8482. t['samekh'] = 0x05E1;
  8483. t['samekhdagesh'] = 0xFB41;
  8484. t['samekhdageshhebrew'] = 0xFB41;
  8485. t['samekhhebrew'] = 0x05E1;
  8486. t['saraaathai'] = 0x0E32;
  8487. t['saraaethai'] = 0x0E41;
  8488. t['saraaimaimalaithai'] = 0x0E44;
  8489. t['saraaimaimuanthai'] = 0x0E43;
  8490. t['saraamthai'] = 0x0E33;
  8491. t['saraathai'] = 0x0E30;
  8492. t['saraethai'] = 0x0E40;
  8493. t['saraiileftthai'] = 0xF886;
  8494. t['saraiithai'] = 0x0E35;
  8495. t['saraileftthai'] = 0xF885;
  8496. t['saraithai'] = 0x0E34;
  8497. t['saraothai'] = 0x0E42;
  8498. t['saraueeleftthai'] = 0xF888;
  8499. t['saraueethai'] = 0x0E37;
  8500. t['saraueleftthai'] = 0xF887;
  8501. t['sarauethai'] = 0x0E36;
  8502. t['sarauthai'] = 0x0E38;
  8503. t['sarauuthai'] = 0x0E39;
  8504. t['sbopomofo'] = 0x3119;
  8505. t['scaron'] = 0x0161;
  8506. t['scarondotaccent'] = 0x1E67;
  8507. t['scedilla'] = 0x015F;
  8508. t['schwa'] = 0x0259;
  8509. t['schwacyrillic'] = 0x04D9;
  8510. t['schwadieresiscyrillic'] = 0x04DB;
  8511. t['schwahook'] = 0x025A;
  8512. t['scircle'] = 0x24E2;
  8513. t['scircumflex'] = 0x015D;
  8514. t['scommaaccent'] = 0x0219;
  8515. t['sdotaccent'] = 0x1E61;
  8516. t['sdotbelow'] = 0x1E63;
  8517. t['sdotbelowdotaccent'] = 0x1E69;
  8518. t['seagullbelowcmb'] = 0x033C;
  8519. t['second'] = 0x2033;
  8520. t['secondtonechinese'] = 0x02CA;
  8521. t['section'] = 0x00A7;
  8522. t['seenarabic'] = 0x0633;
  8523. t['seenfinalarabic'] = 0xFEB2;
  8524. t['seeninitialarabic'] = 0xFEB3;
  8525. t['seenmedialarabic'] = 0xFEB4;
  8526. t['segol'] = 0x05B6;
  8527. t['segol13'] = 0x05B6;
  8528. t['segol1f'] = 0x05B6;
  8529. t['segol2c'] = 0x05B6;
  8530. t['segolhebrew'] = 0x05B6;
  8531. t['segolnarrowhebrew'] = 0x05B6;
  8532. t['segolquarterhebrew'] = 0x05B6;
  8533. t['segoltahebrew'] = 0x0592;
  8534. t['segolwidehebrew'] = 0x05B6;
  8535. t['seharmenian'] = 0x057D;
  8536. t['sehiragana'] = 0x305B;
  8537. t['sekatakana'] = 0x30BB;
  8538. t['sekatakanahalfwidth'] = 0xFF7E;
  8539. t['semicolon'] = 0x003B;
  8540. t['semicolonarabic'] = 0x061B;
  8541. t['semicolonmonospace'] = 0xFF1B;
  8542. t['semicolonsmall'] = 0xFE54;
  8543. t['semivoicedmarkkana'] = 0x309C;
  8544. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8545. t['sentisquare'] = 0x3322;
  8546. t['sentosquare'] = 0x3323;
  8547. t['seven'] = 0x0037;
  8548. t['sevenarabic'] = 0x0667;
  8549. t['sevenbengali'] = 0x09ED;
  8550. t['sevencircle'] = 0x2466;
  8551. t['sevencircleinversesansserif'] = 0x2790;
  8552. t['sevendeva'] = 0x096D;
  8553. t['seveneighths'] = 0x215E;
  8554. t['sevengujarati'] = 0x0AED;
  8555. t['sevengurmukhi'] = 0x0A6D;
  8556. t['sevenhackarabic'] = 0x0667;
  8557. t['sevenhangzhou'] = 0x3027;
  8558. t['sevenideographicparen'] = 0x3226;
  8559. t['seveninferior'] = 0x2087;
  8560. t['sevenmonospace'] = 0xFF17;
  8561. t['sevenoldstyle'] = 0xF737;
  8562. t['sevenparen'] = 0x247A;
  8563. t['sevenperiod'] = 0x248E;
  8564. t['sevenpersian'] = 0x06F7;
  8565. t['sevenroman'] = 0x2176;
  8566. t['sevensuperior'] = 0x2077;
  8567. t['seventeencircle'] = 0x2470;
  8568. t['seventeenparen'] = 0x2484;
  8569. t['seventeenperiod'] = 0x2498;
  8570. t['seventhai'] = 0x0E57;
  8571. t['sfthyphen'] = 0x00AD;
  8572. t['shaarmenian'] = 0x0577;
  8573. t['shabengali'] = 0x09B6;
  8574. t['shacyrillic'] = 0x0448;
  8575. t['shaddaarabic'] = 0x0651;
  8576. t['shaddadammaarabic'] = 0xFC61;
  8577. t['shaddadammatanarabic'] = 0xFC5E;
  8578. t['shaddafathaarabic'] = 0xFC60;
  8579. t['shaddakasraarabic'] = 0xFC62;
  8580. t['shaddakasratanarabic'] = 0xFC5F;
  8581. t['shade'] = 0x2592;
  8582. t['shadedark'] = 0x2593;
  8583. t['shadelight'] = 0x2591;
  8584. t['shademedium'] = 0x2592;
  8585. t['shadeva'] = 0x0936;
  8586. t['shagujarati'] = 0x0AB6;
  8587. t['shagurmukhi'] = 0x0A36;
  8588. t['shalshelethebrew'] = 0x0593;
  8589. t['shbopomofo'] = 0x3115;
  8590. t['shchacyrillic'] = 0x0449;
  8591. t['sheenarabic'] = 0x0634;
  8592. t['sheenfinalarabic'] = 0xFEB6;
  8593. t['sheeninitialarabic'] = 0xFEB7;
  8594. t['sheenmedialarabic'] = 0xFEB8;
  8595. t['sheicoptic'] = 0x03E3;
  8596. t['sheqel'] = 0x20AA;
  8597. t['sheqelhebrew'] = 0x20AA;
  8598. t['sheva'] = 0x05B0;
  8599. t['sheva115'] = 0x05B0;
  8600. t['sheva15'] = 0x05B0;
  8601. t['sheva22'] = 0x05B0;
  8602. t['sheva2e'] = 0x05B0;
  8603. t['shevahebrew'] = 0x05B0;
  8604. t['shevanarrowhebrew'] = 0x05B0;
  8605. t['shevaquarterhebrew'] = 0x05B0;
  8606. t['shevawidehebrew'] = 0x05B0;
  8607. t['shhacyrillic'] = 0x04BB;
  8608. t['shimacoptic'] = 0x03ED;
  8609. t['shin'] = 0x05E9;
  8610. t['shindagesh'] = 0xFB49;
  8611. t['shindageshhebrew'] = 0xFB49;
  8612. t['shindageshshindot'] = 0xFB2C;
  8613. t['shindageshshindothebrew'] = 0xFB2C;
  8614. t['shindageshsindot'] = 0xFB2D;
  8615. t['shindageshsindothebrew'] = 0xFB2D;
  8616. t['shindothebrew'] = 0x05C1;
  8617. t['shinhebrew'] = 0x05E9;
  8618. t['shinshindot'] = 0xFB2A;
  8619. t['shinshindothebrew'] = 0xFB2A;
  8620. t['shinsindot'] = 0xFB2B;
  8621. t['shinsindothebrew'] = 0xFB2B;
  8622. t['shook'] = 0x0282;
  8623. t['sigma'] = 0x03C3;
  8624. t['sigma1'] = 0x03C2;
  8625. t['sigmafinal'] = 0x03C2;
  8626. t['sigmalunatesymbolgreek'] = 0x03F2;
  8627. t['sihiragana'] = 0x3057;
  8628. t['sikatakana'] = 0x30B7;
  8629. t['sikatakanahalfwidth'] = 0xFF7C;
  8630. t['siluqhebrew'] = 0x05BD;
  8631. t['siluqlefthebrew'] = 0x05BD;
  8632. t['similar'] = 0x223C;
  8633. t['sindothebrew'] = 0x05C2;
  8634. t['siosacirclekorean'] = 0x3274;
  8635. t['siosaparenkorean'] = 0x3214;
  8636. t['sioscieuckorean'] = 0x317E;
  8637. t['sioscirclekorean'] = 0x3266;
  8638. t['sioskiyeokkorean'] = 0x317A;
  8639. t['sioskorean'] = 0x3145;
  8640. t['siosnieunkorean'] = 0x317B;
  8641. t['siosparenkorean'] = 0x3206;
  8642. t['siospieupkorean'] = 0x317D;
  8643. t['siostikeutkorean'] = 0x317C;
  8644. t['six'] = 0x0036;
  8645. t['sixarabic'] = 0x0666;
  8646. t['sixbengali'] = 0x09EC;
  8647. t['sixcircle'] = 0x2465;
  8648. t['sixcircleinversesansserif'] = 0x278F;
  8649. t['sixdeva'] = 0x096C;
  8650. t['sixgujarati'] = 0x0AEC;
  8651. t['sixgurmukhi'] = 0x0A6C;
  8652. t['sixhackarabic'] = 0x0666;
  8653. t['sixhangzhou'] = 0x3026;
  8654. t['sixideographicparen'] = 0x3225;
  8655. t['sixinferior'] = 0x2086;
  8656. t['sixmonospace'] = 0xFF16;
  8657. t['sixoldstyle'] = 0xF736;
  8658. t['sixparen'] = 0x2479;
  8659. t['sixperiod'] = 0x248D;
  8660. t['sixpersian'] = 0x06F6;
  8661. t['sixroman'] = 0x2175;
  8662. t['sixsuperior'] = 0x2076;
  8663. t['sixteencircle'] = 0x246F;
  8664. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8665. t['sixteenparen'] = 0x2483;
  8666. t['sixteenperiod'] = 0x2497;
  8667. t['sixthai'] = 0x0E56;
  8668. t['slash'] = 0x002F;
  8669. t['slashmonospace'] = 0xFF0F;
  8670. t['slong'] = 0x017F;
  8671. t['slongdotaccent'] = 0x1E9B;
  8672. t['smileface'] = 0x263A;
  8673. t['smonospace'] = 0xFF53;
  8674. t['sofpasuqhebrew'] = 0x05C3;
  8675. t['softhyphen'] = 0x00AD;
  8676. t['softsigncyrillic'] = 0x044C;
  8677. t['sohiragana'] = 0x305D;
  8678. t['sokatakana'] = 0x30BD;
  8679. t['sokatakanahalfwidth'] = 0xFF7F;
  8680. t['soliduslongoverlaycmb'] = 0x0338;
  8681. t['solidusshortoverlaycmb'] = 0x0337;
  8682. t['sorusithai'] = 0x0E29;
  8683. t['sosalathai'] = 0x0E28;
  8684. t['sosothai'] = 0x0E0B;
  8685. t['sosuathai'] = 0x0E2A;
  8686. t['space'] = 0x0020;
  8687. t['spacehackarabic'] = 0x0020;
  8688. t['spade'] = 0x2660;
  8689. t['spadesuitblack'] = 0x2660;
  8690. t['spadesuitwhite'] = 0x2664;
  8691. t['sparen'] = 0x24AE;
  8692. t['squarebelowcmb'] = 0x033B;
  8693. t['squarecc'] = 0x33C4;
  8694. t['squarecm'] = 0x339D;
  8695. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8696. t['squarehorizontalfill'] = 0x25A4;
  8697. t['squarekg'] = 0x338F;
  8698. t['squarekm'] = 0x339E;
  8699. t['squarekmcapital'] = 0x33CE;
  8700. t['squareln'] = 0x33D1;
  8701. t['squarelog'] = 0x33D2;
  8702. t['squaremg'] = 0x338E;
  8703. t['squaremil'] = 0x33D5;
  8704. t['squaremm'] = 0x339C;
  8705. t['squaremsquared'] = 0x33A1;
  8706. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8707. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8708. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8709. t['squareverticalfill'] = 0x25A5;
  8710. t['squarewhitewithsmallblack'] = 0x25A3;
  8711. t['srsquare'] = 0x33DB;
  8712. t['ssabengali'] = 0x09B7;
  8713. t['ssadeva'] = 0x0937;
  8714. t['ssagujarati'] = 0x0AB7;
  8715. t['ssangcieuckorean'] = 0x3149;
  8716. t['ssanghieuhkorean'] = 0x3185;
  8717. t['ssangieungkorean'] = 0x3180;
  8718. t['ssangkiyeokkorean'] = 0x3132;
  8719. t['ssangnieunkorean'] = 0x3165;
  8720. t['ssangpieupkorean'] = 0x3143;
  8721. t['ssangsioskorean'] = 0x3146;
  8722. t['ssangtikeutkorean'] = 0x3138;
  8723. t['ssuperior'] = 0xF6F2;
  8724. t['sterling'] = 0x00A3;
  8725. t['sterlingmonospace'] = 0xFFE1;
  8726. t['strokelongoverlaycmb'] = 0x0336;
  8727. t['strokeshortoverlaycmb'] = 0x0335;
  8728. t['subset'] = 0x2282;
  8729. t['subsetnotequal'] = 0x228A;
  8730. t['subsetorequal'] = 0x2286;
  8731. t['succeeds'] = 0x227B;
  8732. t['suchthat'] = 0x220B;
  8733. t['suhiragana'] = 0x3059;
  8734. t['sukatakana'] = 0x30B9;
  8735. t['sukatakanahalfwidth'] = 0xFF7D;
  8736. t['sukunarabic'] = 0x0652;
  8737. t['summation'] = 0x2211;
  8738. t['sun'] = 0x263C;
  8739. t['superset'] = 0x2283;
  8740. t['supersetnotequal'] = 0x228B;
  8741. t['supersetorequal'] = 0x2287;
  8742. t['svsquare'] = 0x33DC;
  8743. t['syouwaerasquare'] = 0x337C;
  8744. t['t'] = 0x0074;
  8745. t['tabengali'] = 0x09A4;
  8746. t['tackdown'] = 0x22A4;
  8747. t['tackleft'] = 0x22A3;
  8748. t['tadeva'] = 0x0924;
  8749. t['tagujarati'] = 0x0AA4;
  8750. t['tagurmukhi'] = 0x0A24;
  8751. t['taharabic'] = 0x0637;
  8752. t['tahfinalarabic'] = 0xFEC2;
  8753. t['tahinitialarabic'] = 0xFEC3;
  8754. t['tahiragana'] = 0x305F;
  8755. t['tahmedialarabic'] = 0xFEC4;
  8756. t['taisyouerasquare'] = 0x337D;
  8757. t['takatakana'] = 0x30BF;
  8758. t['takatakanahalfwidth'] = 0xFF80;
  8759. t['tatweelarabic'] = 0x0640;
  8760. t['tau'] = 0x03C4;
  8761. t['tav'] = 0x05EA;
  8762. t['tavdages'] = 0xFB4A;
  8763. t['tavdagesh'] = 0xFB4A;
  8764. t['tavdageshhebrew'] = 0xFB4A;
  8765. t['tavhebrew'] = 0x05EA;
  8766. t['tbar'] = 0x0167;
  8767. t['tbopomofo'] = 0x310A;
  8768. t['tcaron'] = 0x0165;
  8769. t['tccurl'] = 0x02A8;
  8770. t['tcedilla'] = 0x0163;
  8771. t['tcheharabic'] = 0x0686;
  8772. t['tchehfinalarabic'] = 0xFB7B;
  8773. t['tchehinitialarabic'] = 0xFB7C;
  8774. t['tchehmedialarabic'] = 0xFB7D;
  8775. t['tcircle'] = 0x24E3;
  8776. t['tcircumflexbelow'] = 0x1E71;
  8777. t['tcommaaccent'] = 0x0163;
  8778. t['tdieresis'] = 0x1E97;
  8779. t['tdotaccent'] = 0x1E6B;
  8780. t['tdotbelow'] = 0x1E6D;
  8781. t['tecyrillic'] = 0x0442;
  8782. t['tedescendercyrillic'] = 0x04AD;
  8783. t['teharabic'] = 0x062A;
  8784. t['tehfinalarabic'] = 0xFE96;
  8785. t['tehhahinitialarabic'] = 0xFCA2;
  8786. t['tehhahisolatedarabic'] = 0xFC0C;
  8787. t['tehinitialarabic'] = 0xFE97;
  8788. t['tehiragana'] = 0x3066;
  8789. t['tehjeeminitialarabic'] = 0xFCA1;
  8790. t['tehjeemisolatedarabic'] = 0xFC0B;
  8791. t['tehmarbutaarabic'] = 0x0629;
  8792. t['tehmarbutafinalarabic'] = 0xFE94;
  8793. t['tehmedialarabic'] = 0xFE98;
  8794. t['tehmeeminitialarabic'] = 0xFCA4;
  8795. t['tehmeemisolatedarabic'] = 0xFC0E;
  8796. t['tehnoonfinalarabic'] = 0xFC73;
  8797. t['tekatakana'] = 0x30C6;
  8798. t['tekatakanahalfwidth'] = 0xFF83;
  8799. t['telephone'] = 0x2121;
  8800. t['telephoneblack'] = 0x260E;
  8801. t['telishagedolahebrew'] = 0x05A0;
  8802. t['telishaqetanahebrew'] = 0x05A9;
  8803. t['tencircle'] = 0x2469;
  8804. t['tenideographicparen'] = 0x3229;
  8805. t['tenparen'] = 0x247D;
  8806. t['tenperiod'] = 0x2491;
  8807. t['tenroman'] = 0x2179;
  8808. t['tesh'] = 0x02A7;
  8809. t['tet'] = 0x05D8;
  8810. t['tetdagesh'] = 0xFB38;
  8811. t['tetdageshhebrew'] = 0xFB38;
  8812. t['tethebrew'] = 0x05D8;
  8813. t['tetsecyrillic'] = 0x04B5;
  8814. t['tevirhebrew'] = 0x059B;
  8815. t['tevirlefthebrew'] = 0x059B;
  8816. t['thabengali'] = 0x09A5;
  8817. t['thadeva'] = 0x0925;
  8818. t['thagujarati'] = 0x0AA5;
  8819. t['thagurmukhi'] = 0x0A25;
  8820. t['thalarabic'] = 0x0630;
  8821. t['thalfinalarabic'] = 0xFEAC;
  8822. t['thanthakhatlowleftthai'] = 0xF898;
  8823. t['thanthakhatlowrightthai'] = 0xF897;
  8824. t['thanthakhatthai'] = 0x0E4C;
  8825. t['thanthakhatupperleftthai'] = 0xF896;
  8826. t['theharabic'] = 0x062B;
  8827. t['thehfinalarabic'] = 0xFE9A;
  8828. t['thehinitialarabic'] = 0xFE9B;
  8829. t['thehmedialarabic'] = 0xFE9C;
  8830. t['thereexists'] = 0x2203;
  8831. t['therefore'] = 0x2234;
  8832. t['theta'] = 0x03B8;
  8833. t['theta1'] = 0x03D1;
  8834. t['thetasymbolgreek'] = 0x03D1;
  8835. t['thieuthacirclekorean'] = 0x3279;
  8836. t['thieuthaparenkorean'] = 0x3219;
  8837. t['thieuthcirclekorean'] = 0x326B;
  8838. t['thieuthkorean'] = 0x314C;
  8839. t['thieuthparenkorean'] = 0x320B;
  8840. t['thirteencircle'] = 0x246C;
  8841. t['thirteenparen'] = 0x2480;
  8842. t['thirteenperiod'] = 0x2494;
  8843. t['thonangmonthothai'] = 0x0E11;
  8844. t['thook'] = 0x01AD;
  8845. t['thophuthaothai'] = 0x0E12;
  8846. t['thorn'] = 0x00FE;
  8847. t['thothahanthai'] = 0x0E17;
  8848. t['thothanthai'] = 0x0E10;
  8849. t['thothongthai'] = 0x0E18;
  8850. t['thothungthai'] = 0x0E16;
  8851. t['thousandcyrillic'] = 0x0482;
  8852. t['thousandsseparatorarabic'] = 0x066C;
  8853. t['thousandsseparatorpersian'] = 0x066C;
  8854. t['three'] = 0x0033;
  8855. t['threearabic'] = 0x0663;
  8856. t['threebengali'] = 0x09E9;
  8857. t['threecircle'] = 0x2462;
  8858. t['threecircleinversesansserif'] = 0x278C;
  8859. t['threedeva'] = 0x0969;
  8860. t['threeeighths'] = 0x215C;
  8861. t['threegujarati'] = 0x0AE9;
  8862. t['threegurmukhi'] = 0x0A69;
  8863. t['threehackarabic'] = 0x0663;
  8864. t['threehangzhou'] = 0x3023;
  8865. t['threeideographicparen'] = 0x3222;
  8866. t['threeinferior'] = 0x2083;
  8867. t['threemonospace'] = 0xFF13;
  8868. t['threenumeratorbengali'] = 0x09F6;
  8869. t['threeoldstyle'] = 0xF733;
  8870. t['threeparen'] = 0x2476;
  8871. t['threeperiod'] = 0x248A;
  8872. t['threepersian'] = 0x06F3;
  8873. t['threequarters'] = 0x00BE;
  8874. t['threequartersemdash'] = 0xF6DE;
  8875. t['threeroman'] = 0x2172;
  8876. t['threesuperior'] = 0x00B3;
  8877. t['threethai'] = 0x0E53;
  8878. t['thzsquare'] = 0x3394;
  8879. t['tihiragana'] = 0x3061;
  8880. t['tikatakana'] = 0x30C1;
  8881. t['tikatakanahalfwidth'] = 0xFF81;
  8882. t['tikeutacirclekorean'] = 0x3270;
  8883. t['tikeutaparenkorean'] = 0x3210;
  8884. t['tikeutcirclekorean'] = 0x3262;
  8885. t['tikeutkorean'] = 0x3137;
  8886. t['tikeutparenkorean'] = 0x3202;
  8887. t['tilde'] = 0x02DC;
  8888. t['tildebelowcmb'] = 0x0330;
  8889. t['tildecmb'] = 0x0303;
  8890. t['tildecomb'] = 0x0303;
  8891. t['tildedoublecmb'] = 0x0360;
  8892. t['tildeoperator'] = 0x223C;
  8893. t['tildeoverlaycmb'] = 0x0334;
  8894. t['tildeverticalcmb'] = 0x033E;
  8895. t['timescircle'] = 0x2297;
  8896. t['tipehahebrew'] = 0x0596;
  8897. t['tipehalefthebrew'] = 0x0596;
  8898. t['tippigurmukhi'] = 0x0A70;
  8899. t['titlocyrilliccmb'] = 0x0483;
  8900. t['tiwnarmenian'] = 0x057F;
  8901. t['tlinebelow'] = 0x1E6F;
  8902. t['tmonospace'] = 0xFF54;
  8903. t['toarmenian'] = 0x0569;
  8904. t['tohiragana'] = 0x3068;
  8905. t['tokatakana'] = 0x30C8;
  8906. t['tokatakanahalfwidth'] = 0xFF84;
  8907. t['tonebarextrahighmod'] = 0x02E5;
  8908. t['tonebarextralowmod'] = 0x02E9;
  8909. t['tonebarhighmod'] = 0x02E6;
  8910. t['tonebarlowmod'] = 0x02E8;
  8911. t['tonebarmidmod'] = 0x02E7;
  8912. t['tonefive'] = 0x01BD;
  8913. t['tonesix'] = 0x0185;
  8914. t['tonetwo'] = 0x01A8;
  8915. t['tonos'] = 0x0384;
  8916. t['tonsquare'] = 0x3327;
  8917. t['topatakthai'] = 0x0E0F;
  8918. t['tortoiseshellbracketleft'] = 0x3014;
  8919. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8920. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8921. t['tortoiseshellbracketright'] = 0x3015;
  8922. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8923. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8924. t['totaothai'] = 0x0E15;
  8925. t['tpalatalhook'] = 0x01AB;
  8926. t['tparen'] = 0x24AF;
  8927. t['trademark'] = 0x2122;
  8928. t['trademarksans'] = 0xF8EA;
  8929. t['trademarkserif'] = 0xF6DB;
  8930. t['tretroflexhook'] = 0x0288;
  8931. t['triagdn'] = 0x25BC;
  8932. t['triaglf'] = 0x25C4;
  8933. t['triagrt'] = 0x25BA;
  8934. t['triagup'] = 0x25B2;
  8935. t['ts'] = 0x02A6;
  8936. t['tsadi'] = 0x05E6;
  8937. t['tsadidagesh'] = 0xFB46;
  8938. t['tsadidageshhebrew'] = 0xFB46;
  8939. t['tsadihebrew'] = 0x05E6;
  8940. t['tsecyrillic'] = 0x0446;
  8941. t['tsere'] = 0x05B5;
  8942. t['tsere12'] = 0x05B5;
  8943. t['tsere1e'] = 0x05B5;
  8944. t['tsere2b'] = 0x05B5;
  8945. t['tserehebrew'] = 0x05B5;
  8946. t['tserenarrowhebrew'] = 0x05B5;
  8947. t['tserequarterhebrew'] = 0x05B5;
  8948. t['tserewidehebrew'] = 0x05B5;
  8949. t['tshecyrillic'] = 0x045B;
  8950. t['tsuperior'] = 0xF6F3;
  8951. t['ttabengali'] = 0x099F;
  8952. t['ttadeva'] = 0x091F;
  8953. t['ttagujarati'] = 0x0A9F;
  8954. t['ttagurmukhi'] = 0x0A1F;
  8955. t['tteharabic'] = 0x0679;
  8956. t['ttehfinalarabic'] = 0xFB67;
  8957. t['ttehinitialarabic'] = 0xFB68;
  8958. t['ttehmedialarabic'] = 0xFB69;
  8959. t['tthabengali'] = 0x09A0;
  8960. t['tthadeva'] = 0x0920;
  8961. t['tthagujarati'] = 0x0AA0;
  8962. t['tthagurmukhi'] = 0x0A20;
  8963. t['tturned'] = 0x0287;
  8964. t['tuhiragana'] = 0x3064;
  8965. t['tukatakana'] = 0x30C4;
  8966. t['tukatakanahalfwidth'] = 0xFF82;
  8967. t['tusmallhiragana'] = 0x3063;
  8968. t['tusmallkatakana'] = 0x30C3;
  8969. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8970. t['twelvecircle'] = 0x246B;
  8971. t['twelveparen'] = 0x247F;
  8972. t['twelveperiod'] = 0x2493;
  8973. t['twelveroman'] = 0x217B;
  8974. t['twentycircle'] = 0x2473;
  8975. t['twentyhangzhou'] = 0x5344;
  8976. t['twentyparen'] = 0x2487;
  8977. t['twentyperiod'] = 0x249B;
  8978. t['two'] = 0x0032;
  8979. t['twoarabic'] = 0x0662;
  8980. t['twobengali'] = 0x09E8;
  8981. t['twocircle'] = 0x2461;
  8982. t['twocircleinversesansserif'] = 0x278B;
  8983. t['twodeva'] = 0x0968;
  8984. t['twodotenleader'] = 0x2025;
  8985. t['twodotleader'] = 0x2025;
  8986. t['twodotleadervertical'] = 0xFE30;
  8987. t['twogujarati'] = 0x0AE8;
  8988. t['twogurmukhi'] = 0x0A68;
  8989. t['twohackarabic'] = 0x0662;
  8990. t['twohangzhou'] = 0x3022;
  8991. t['twoideographicparen'] = 0x3221;
  8992. t['twoinferior'] = 0x2082;
  8993. t['twomonospace'] = 0xFF12;
  8994. t['twonumeratorbengali'] = 0x09F5;
  8995. t['twooldstyle'] = 0xF732;
  8996. t['twoparen'] = 0x2475;
  8997. t['twoperiod'] = 0x2489;
  8998. t['twopersian'] = 0x06F2;
  8999. t['tworoman'] = 0x2171;
  9000. t['twostroke'] = 0x01BB;
  9001. t['twosuperior'] = 0x00B2;
  9002. t['twothai'] = 0x0E52;
  9003. t['twothirds'] = 0x2154;
  9004. t['u'] = 0x0075;
  9005. t['uacute'] = 0x00FA;
  9006. t['ubar'] = 0x0289;
  9007. t['ubengali'] = 0x0989;
  9008. t['ubopomofo'] = 0x3128;
  9009. t['ubreve'] = 0x016D;
  9010. t['ucaron'] = 0x01D4;
  9011. t['ucircle'] = 0x24E4;
  9012. t['ucircumflex'] = 0x00FB;
  9013. t['ucircumflexbelow'] = 0x1E77;
  9014. t['ucyrillic'] = 0x0443;
  9015. t['udattadeva'] = 0x0951;
  9016. t['udblacute'] = 0x0171;
  9017. t['udblgrave'] = 0x0215;
  9018. t['udeva'] = 0x0909;
  9019. t['udieresis'] = 0x00FC;
  9020. t['udieresisacute'] = 0x01D8;
  9021. t['udieresisbelow'] = 0x1E73;
  9022. t['udieresiscaron'] = 0x01DA;
  9023. t['udieresiscyrillic'] = 0x04F1;
  9024. t['udieresisgrave'] = 0x01DC;
  9025. t['udieresismacron'] = 0x01D6;
  9026. t['udotbelow'] = 0x1EE5;
  9027. t['ugrave'] = 0x00F9;
  9028. t['ugujarati'] = 0x0A89;
  9029. t['ugurmukhi'] = 0x0A09;
  9030. t['uhiragana'] = 0x3046;
  9031. t['uhookabove'] = 0x1EE7;
  9032. t['uhorn'] = 0x01B0;
  9033. t['uhornacute'] = 0x1EE9;
  9034. t['uhorndotbelow'] = 0x1EF1;
  9035. t['uhorngrave'] = 0x1EEB;
  9036. t['uhornhookabove'] = 0x1EED;
  9037. t['uhorntilde'] = 0x1EEF;
  9038. t['uhungarumlaut'] = 0x0171;
  9039. t['uhungarumlautcyrillic'] = 0x04F3;
  9040. t['uinvertedbreve'] = 0x0217;
  9041. t['ukatakana'] = 0x30A6;
  9042. t['ukatakanahalfwidth'] = 0xFF73;
  9043. t['ukcyrillic'] = 0x0479;
  9044. t['ukorean'] = 0x315C;
  9045. t['umacron'] = 0x016B;
  9046. t['umacroncyrillic'] = 0x04EF;
  9047. t['umacrondieresis'] = 0x1E7B;
  9048. t['umatragurmukhi'] = 0x0A41;
  9049. t['umonospace'] = 0xFF55;
  9050. t['underscore'] = 0x005F;
  9051. t['underscoredbl'] = 0x2017;
  9052. t['underscoremonospace'] = 0xFF3F;
  9053. t['underscorevertical'] = 0xFE33;
  9054. t['underscorewavy'] = 0xFE4F;
  9055. t['union'] = 0x222A;
  9056. t['universal'] = 0x2200;
  9057. t['uogonek'] = 0x0173;
  9058. t['uparen'] = 0x24B0;
  9059. t['upblock'] = 0x2580;
  9060. t['upperdothebrew'] = 0x05C4;
  9061. t['upsilon'] = 0x03C5;
  9062. t['upsilondieresis'] = 0x03CB;
  9063. t['upsilondieresistonos'] = 0x03B0;
  9064. t['upsilonlatin'] = 0x028A;
  9065. t['upsilontonos'] = 0x03CD;
  9066. t['uptackbelowcmb'] = 0x031D;
  9067. t['uptackmod'] = 0x02D4;
  9068. t['uragurmukhi'] = 0x0A73;
  9069. t['uring'] = 0x016F;
  9070. t['ushortcyrillic'] = 0x045E;
  9071. t['usmallhiragana'] = 0x3045;
  9072. t['usmallkatakana'] = 0x30A5;
  9073. t['usmallkatakanahalfwidth'] = 0xFF69;
  9074. t['ustraightcyrillic'] = 0x04AF;
  9075. t['ustraightstrokecyrillic'] = 0x04B1;
  9076. t['utilde'] = 0x0169;
  9077. t['utildeacute'] = 0x1E79;
  9078. t['utildebelow'] = 0x1E75;
  9079. t['uubengali'] = 0x098A;
  9080. t['uudeva'] = 0x090A;
  9081. t['uugujarati'] = 0x0A8A;
  9082. t['uugurmukhi'] = 0x0A0A;
  9083. t['uumatragurmukhi'] = 0x0A42;
  9084. t['uuvowelsignbengali'] = 0x09C2;
  9085. t['uuvowelsigndeva'] = 0x0942;
  9086. t['uuvowelsigngujarati'] = 0x0AC2;
  9087. t['uvowelsignbengali'] = 0x09C1;
  9088. t['uvowelsigndeva'] = 0x0941;
  9089. t['uvowelsigngujarati'] = 0x0AC1;
  9090. t['v'] = 0x0076;
  9091. t['vadeva'] = 0x0935;
  9092. t['vagujarati'] = 0x0AB5;
  9093. t['vagurmukhi'] = 0x0A35;
  9094. t['vakatakana'] = 0x30F7;
  9095. t['vav'] = 0x05D5;
  9096. t['vavdagesh'] = 0xFB35;
  9097. t['vavdagesh65'] = 0xFB35;
  9098. t['vavdageshhebrew'] = 0xFB35;
  9099. t['vavhebrew'] = 0x05D5;
  9100. t['vavholam'] = 0xFB4B;
  9101. t['vavholamhebrew'] = 0xFB4B;
  9102. t['vavvavhebrew'] = 0x05F0;
  9103. t['vavyodhebrew'] = 0x05F1;
  9104. t['vcircle'] = 0x24E5;
  9105. t['vdotbelow'] = 0x1E7F;
  9106. t['vecyrillic'] = 0x0432;
  9107. t['veharabic'] = 0x06A4;
  9108. t['vehfinalarabic'] = 0xFB6B;
  9109. t['vehinitialarabic'] = 0xFB6C;
  9110. t['vehmedialarabic'] = 0xFB6D;
  9111. t['vekatakana'] = 0x30F9;
  9112. t['venus'] = 0x2640;
  9113. t['verticalbar'] = 0x007C;
  9114. t['verticallineabovecmb'] = 0x030D;
  9115. t['verticallinebelowcmb'] = 0x0329;
  9116. t['verticallinelowmod'] = 0x02CC;
  9117. t['verticallinemod'] = 0x02C8;
  9118. t['vewarmenian'] = 0x057E;
  9119. t['vhook'] = 0x028B;
  9120. t['vikatakana'] = 0x30F8;
  9121. t['viramabengali'] = 0x09CD;
  9122. t['viramadeva'] = 0x094D;
  9123. t['viramagujarati'] = 0x0ACD;
  9124. t['visargabengali'] = 0x0983;
  9125. t['visargadeva'] = 0x0903;
  9126. t['visargagujarati'] = 0x0A83;
  9127. t['vmonospace'] = 0xFF56;
  9128. t['voarmenian'] = 0x0578;
  9129. t['voicediterationhiragana'] = 0x309E;
  9130. t['voicediterationkatakana'] = 0x30FE;
  9131. t['voicedmarkkana'] = 0x309B;
  9132. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  9133. t['vokatakana'] = 0x30FA;
  9134. t['vparen'] = 0x24B1;
  9135. t['vtilde'] = 0x1E7D;
  9136. t['vturned'] = 0x028C;
  9137. t['vuhiragana'] = 0x3094;
  9138. t['vukatakana'] = 0x30F4;
  9139. t['w'] = 0x0077;
  9140. t['wacute'] = 0x1E83;
  9141. t['waekorean'] = 0x3159;
  9142. t['wahiragana'] = 0x308F;
  9143. t['wakatakana'] = 0x30EF;
  9144. t['wakatakanahalfwidth'] = 0xFF9C;
  9145. t['wakorean'] = 0x3158;
  9146. t['wasmallhiragana'] = 0x308E;
  9147. t['wasmallkatakana'] = 0x30EE;
  9148. t['wattosquare'] = 0x3357;
  9149. t['wavedash'] = 0x301C;
  9150. t['wavyunderscorevertical'] = 0xFE34;
  9151. t['wawarabic'] = 0x0648;
  9152. t['wawfinalarabic'] = 0xFEEE;
  9153. t['wawhamzaabovearabic'] = 0x0624;
  9154. t['wawhamzaabovefinalarabic'] = 0xFE86;
  9155. t['wbsquare'] = 0x33DD;
  9156. t['wcircle'] = 0x24E6;
  9157. t['wcircumflex'] = 0x0175;
  9158. t['wdieresis'] = 0x1E85;
  9159. t['wdotaccent'] = 0x1E87;
  9160. t['wdotbelow'] = 0x1E89;
  9161. t['wehiragana'] = 0x3091;
  9162. t['weierstrass'] = 0x2118;
  9163. t['wekatakana'] = 0x30F1;
  9164. t['wekorean'] = 0x315E;
  9165. t['weokorean'] = 0x315D;
  9166. t['wgrave'] = 0x1E81;
  9167. t['whitebullet'] = 0x25E6;
  9168. t['whitecircle'] = 0x25CB;
  9169. t['whitecircleinverse'] = 0x25D9;
  9170. t['whitecornerbracketleft'] = 0x300E;
  9171. t['whitecornerbracketleftvertical'] = 0xFE43;
  9172. t['whitecornerbracketright'] = 0x300F;
  9173. t['whitecornerbracketrightvertical'] = 0xFE44;
  9174. t['whitediamond'] = 0x25C7;
  9175. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  9176. t['whitedownpointingsmalltriangle'] = 0x25BF;
  9177. t['whitedownpointingtriangle'] = 0x25BD;
  9178. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  9179. t['whiteleftpointingtriangle'] = 0x25C1;
  9180. t['whitelenticularbracketleft'] = 0x3016;
  9181. t['whitelenticularbracketright'] = 0x3017;
  9182. t['whiterightpointingsmalltriangle'] = 0x25B9;
  9183. t['whiterightpointingtriangle'] = 0x25B7;
  9184. t['whitesmallsquare'] = 0x25AB;
  9185. t['whitesmilingface'] = 0x263A;
  9186. t['whitesquare'] = 0x25A1;
  9187. t['whitestar'] = 0x2606;
  9188. t['whitetelephone'] = 0x260F;
  9189. t['whitetortoiseshellbracketleft'] = 0x3018;
  9190. t['whitetortoiseshellbracketright'] = 0x3019;
  9191. t['whiteuppointingsmalltriangle'] = 0x25B5;
  9192. t['whiteuppointingtriangle'] = 0x25B3;
  9193. t['wihiragana'] = 0x3090;
  9194. t['wikatakana'] = 0x30F0;
  9195. t['wikorean'] = 0x315F;
  9196. t['wmonospace'] = 0xFF57;
  9197. t['wohiragana'] = 0x3092;
  9198. t['wokatakana'] = 0x30F2;
  9199. t['wokatakanahalfwidth'] = 0xFF66;
  9200. t['won'] = 0x20A9;
  9201. t['wonmonospace'] = 0xFFE6;
  9202. t['wowaenthai'] = 0x0E27;
  9203. t['wparen'] = 0x24B2;
  9204. t['wring'] = 0x1E98;
  9205. t['wsuperior'] = 0x02B7;
  9206. t['wturned'] = 0x028D;
  9207. t['wynn'] = 0x01BF;
  9208. t['x'] = 0x0078;
  9209. t['xabovecmb'] = 0x033D;
  9210. t['xbopomofo'] = 0x3112;
  9211. t['xcircle'] = 0x24E7;
  9212. t['xdieresis'] = 0x1E8D;
  9213. t['xdotaccent'] = 0x1E8B;
  9214. t['xeharmenian'] = 0x056D;
  9215. t['xi'] = 0x03BE;
  9216. t['xmonospace'] = 0xFF58;
  9217. t['xparen'] = 0x24B3;
  9218. t['xsuperior'] = 0x02E3;
  9219. t['y'] = 0x0079;
  9220. t['yaadosquare'] = 0x334E;
  9221. t['yabengali'] = 0x09AF;
  9222. t['yacute'] = 0x00FD;
  9223. t['yadeva'] = 0x092F;
  9224. t['yaekorean'] = 0x3152;
  9225. t['yagujarati'] = 0x0AAF;
  9226. t['yagurmukhi'] = 0x0A2F;
  9227. t['yahiragana'] = 0x3084;
  9228. t['yakatakana'] = 0x30E4;
  9229. t['yakatakanahalfwidth'] = 0xFF94;
  9230. t['yakorean'] = 0x3151;
  9231. t['yamakkanthai'] = 0x0E4E;
  9232. t['yasmallhiragana'] = 0x3083;
  9233. t['yasmallkatakana'] = 0x30E3;
  9234. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  9235. t['yatcyrillic'] = 0x0463;
  9236. t['ycircle'] = 0x24E8;
  9237. t['ycircumflex'] = 0x0177;
  9238. t['ydieresis'] = 0x00FF;
  9239. t['ydotaccent'] = 0x1E8F;
  9240. t['ydotbelow'] = 0x1EF5;
  9241. t['yeharabic'] = 0x064A;
  9242. t['yehbarreearabic'] = 0x06D2;
  9243. t['yehbarreefinalarabic'] = 0xFBAF;
  9244. t['yehfinalarabic'] = 0xFEF2;
  9245. t['yehhamzaabovearabic'] = 0x0626;
  9246. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  9247. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  9248. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  9249. t['yehinitialarabic'] = 0xFEF3;
  9250. t['yehmedialarabic'] = 0xFEF4;
  9251. t['yehmeeminitialarabic'] = 0xFCDD;
  9252. t['yehmeemisolatedarabic'] = 0xFC58;
  9253. t['yehnoonfinalarabic'] = 0xFC94;
  9254. t['yehthreedotsbelowarabic'] = 0x06D1;
  9255. t['yekorean'] = 0x3156;
  9256. t['yen'] = 0x00A5;
  9257. t['yenmonospace'] = 0xFFE5;
  9258. t['yeokorean'] = 0x3155;
  9259. t['yeorinhieuhkorean'] = 0x3186;
  9260. t['yerahbenyomohebrew'] = 0x05AA;
  9261. t['yerahbenyomolefthebrew'] = 0x05AA;
  9262. t['yericyrillic'] = 0x044B;
  9263. t['yerudieresiscyrillic'] = 0x04F9;
  9264. t['yesieungkorean'] = 0x3181;
  9265. t['yesieungpansioskorean'] = 0x3183;
  9266. t['yesieungsioskorean'] = 0x3182;
  9267. t['yetivhebrew'] = 0x059A;
  9268. t['ygrave'] = 0x1EF3;
  9269. t['yhook'] = 0x01B4;
  9270. t['yhookabove'] = 0x1EF7;
  9271. t['yiarmenian'] = 0x0575;
  9272. t['yicyrillic'] = 0x0457;
  9273. t['yikorean'] = 0x3162;
  9274. t['yinyang'] = 0x262F;
  9275. t['yiwnarmenian'] = 0x0582;
  9276. t['ymonospace'] = 0xFF59;
  9277. t['yod'] = 0x05D9;
  9278. t['yoddagesh'] = 0xFB39;
  9279. t['yoddageshhebrew'] = 0xFB39;
  9280. t['yodhebrew'] = 0x05D9;
  9281. t['yodyodhebrew'] = 0x05F2;
  9282. t['yodyodpatahhebrew'] = 0xFB1F;
  9283. t['yohiragana'] = 0x3088;
  9284. t['yoikorean'] = 0x3189;
  9285. t['yokatakana'] = 0x30E8;
  9286. t['yokatakanahalfwidth'] = 0xFF96;
  9287. t['yokorean'] = 0x315B;
  9288. t['yosmallhiragana'] = 0x3087;
  9289. t['yosmallkatakana'] = 0x30E7;
  9290. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  9291. t['yotgreek'] = 0x03F3;
  9292. t['yoyaekorean'] = 0x3188;
  9293. t['yoyakorean'] = 0x3187;
  9294. t['yoyakthai'] = 0x0E22;
  9295. t['yoyingthai'] = 0x0E0D;
  9296. t['yparen'] = 0x24B4;
  9297. t['ypogegrammeni'] = 0x037A;
  9298. t['ypogegrammenigreekcmb'] = 0x0345;
  9299. t['yr'] = 0x01A6;
  9300. t['yring'] = 0x1E99;
  9301. t['ysuperior'] = 0x02B8;
  9302. t['ytilde'] = 0x1EF9;
  9303. t['yturned'] = 0x028E;
  9304. t['yuhiragana'] = 0x3086;
  9305. t['yuikorean'] = 0x318C;
  9306. t['yukatakana'] = 0x30E6;
  9307. t['yukatakanahalfwidth'] = 0xFF95;
  9308. t['yukorean'] = 0x3160;
  9309. t['yusbigcyrillic'] = 0x046B;
  9310. t['yusbigiotifiedcyrillic'] = 0x046D;
  9311. t['yuslittlecyrillic'] = 0x0467;
  9312. t['yuslittleiotifiedcyrillic'] = 0x0469;
  9313. t['yusmallhiragana'] = 0x3085;
  9314. t['yusmallkatakana'] = 0x30E5;
  9315. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  9316. t['yuyekorean'] = 0x318B;
  9317. t['yuyeokorean'] = 0x318A;
  9318. t['yyabengali'] = 0x09DF;
  9319. t['yyadeva'] = 0x095F;
  9320. t['z'] = 0x007A;
  9321. t['zaarmenian'] = 0x0566;
  9322. t['zacute'] = 0x017A;
  9323. t['zadeva'] = 0x095B;
  9324. t['zagurmukhi'] = 0x0A5B;
  9325. t['zaharabic'] = 0x0638;
  9326. t['zahfinalarabic'] = 0xFEC6;
  9327. t['zahinitialarabic'] = 0xFEC7;
  9328. t['zahiragana'] = 0x3056;
  9329. t['zahmedialarabic'] = 0xFEC8;
  9330. t['zainarabic'] = 0x0632;
  9331. t['zainfinalarabic'] = 0xFEB0;
  9332. t['zakatakana'] = 0x30B6;
  9333. t['zaqefgadolhebrew'] = 0x0595;
  9334. t['zaqefqatanhebrew'] = 0x0594;
  9335. t['zarqahebrew'] = 0x0598;
  9336. t['zayin'] = 0x05D6;
  9337. t['zayindagesh'] = 0xFB36;
  9338. t['zayindageshhebrew'] = 0xFB36;
  9339. t['zayinhebrew'] = 0x05D6;
  9340. t['zbopomofo'] = 0x3117;
  9341. t['zcaron'] = 0x017E;
  9342. t['zcircle'] = 0x24E9;
  9343. t['zcircumflex'] = 0x1E91;
  9344. t['zcurl'] = 0x0291;
  9345. t['zdot'] = 0x017C;
  9346. t['zdotaccent'] = 0x017C;
  9347. t['zdotbelow'] = 0x1E93;
  9348. t['zecyrillic'] = 0x0437;
  9349. t['zedescendercyrillic'] = 0x0499;
  9350. t['zedieresiscyrillic'] = 0x04DF;
  9351. t['zehiragana'] = 0x305C;
  9352. t['zekatakana'] = 0x30BC;
  9353. t['zero'] = 0x0030;
  9354. t['zeroarabic'] = 0x0660;
  9355. t['zerobengali'] = 0x09E6;
  9356. t['zerodeva'] = 0x0966;
  9357. t['zerogujarati'] = 0x0AE6;
  9358. t['zerogurmukhi'] = 0x0A66;
  9359. t['zerohackarabic'] = 0x0660;
  9360. t['zeroinferior'] = 0x2080;
  9361. t['zeromonospace'] = 0xFF10;
  9362. t['zerooldstyle'] = 0xF730;
  9363. t['zeropersian'] = 0x06F0;
  9364. t['zerosuperior'] = 0x2070;
  9365. t['zerothai'] = 0x0E50;
  9366. t['zerowidthjoiner'] = 0xFEFF;
  9367. t['zerowidthnonjoiner'] = 0x200C;
  9368. t['zerowidthspace'] = 0x200B;
  9369. t['zeta'] = 0x03B6;
  9370. t['zhbopomofo'] = 0x3113;
  9371. t['zhearmenian'] = 0x056A;
  9372. t['zhebrevecyrillic'] = 0x04C2;
  9373. t['zhecyrillic'] = 0x0436;
  9374. t['zhedescendercyrillic'] = 0x0497;
  9375. t['zhedieresiscyrillic'] = 0x04DD;
  9376. t['zihiragana'] = 0x3058;
  9377. t['zikatakana'] = 0x30B8;
  9378. t['zinorhebrew'] = 0x05AE;
  9379. t['zlinebelow'] = 0x1E95;
  9380. t['zmonospace'] = 0xFF5A;
  9381. t['zohiragana'] = 0x305E;
  9382. t['zokatakana'] = 0x30BE;
  9383. t['zparen'] = 0x24B5;
  9384. t['zretroflexhook'] = 0x0290;
  9385. t['zstroke'] = 0x01B6;
  9386. t['zuhiragana'] = 0x305A;
  9387. t['zukatakana'] = 0x30BA;
  9388. t['.notdef'] = 0x0000;
  9389. });
  9390. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  9391. t['space'] = 0x0020;
  9392. t['a1'] = 0x2701;
  9393. t['a2'] = 0x2702;
  9394. t['a202'] = 0x2703;
  9395. t['a3'] = 0x2704;
  9396. t['a4'] = 0x260E;
  9397. t['a5'] = 0x2706;
  9398. t['a119'] = 0x2707;
  9399. t['a118'] = 0x2708;
  9400. t['a117'] = 0x2709;
  9401. t['a11'] = 0x261B;
  9402. t['a12'] = 0x261E;
  9403. t['a13'] = 0x270C;
  9404. t['a14'] = 0x270D;
  9405. t['a15'] = 0x270E;
  9406. t['a16'] = 0x270F;
  9407. t['a105'] = 0x2710;
  9408. t['a17'] = 0x2711;
  9409. t['a18'] = 0x2712;
  9410. t['a19'] = 0x2713;
  9411. t['a20'] = 0x2714;
  9412. t['a21'] = 0x2715;
  9413. t['a22'] = 0x2716;
  9414. t['a23'] = 0x2717;
  9415. t['a24'] = 0x2718;
  9416. t['a25'] = 0x2719;
  9417. t['a26'] = 0x271A;
  9418. t['a27'] = 0x271B;
  9419. t['a28'] = 0x271C;
  9420. t['a6'] = 0x271D;
  9421. t['a7'] = 0x271E;
  9422. t['a8'] = 0x271F;
  9423. t['a9'] = 0x2720;
  9424. t['a10'] = 0x2721;
  9425. t['a29'] = 0x2722;
  9426. t['a30'] = 0x2723;
  9427. t['a31'] = 0x2724;
  9428. t['a32'] = 0x2725;
  9429. t['a33'] = 0x2726;
  9430. t['a34'] = 0x2727;
  9431. t['a35'] = 0x2605;
  9432. t['a36'] = 0x2729;
  9433. t['a37'] = 0x272A;
  9434. t['a38'] = 0x272B;
  9435. t['a39'] = 0x272C;
  9436. t['a40'] = 0x272D;
  9437. t['a41'] = 0x272E;
  9438. t['a42'] = 0x272F;
  9439. t['a43'] = 0x2730;
  9440. t['a44'] = 0x2731;
  9441. t['a45'] = 0x2732;
  9442. t['a46'] = 0x2733;
  9443. t['a47'] = 0x2734;
  9444. t['a48'] = 0x2735;
  9445. t['a49'] = 0x2736;
  9446. t['a50'] = 0x2737;
  9447. t['a51'] = 0x2738;
  9448. t['a52'] = 0x2739;
  9449. t['a53'] = 0x273A;
  9450. t['a54'] = 0x273B;
  9451. t['a55'] = 0x273C;
  9452. t['a56'] = 0x273D;
  9453. t['a57'] = 0x273E;
  9454. t['a58'] = 0x273F;
  9455. t['a59'] = 0x2740;
  9456. t['a60'] = 0x2741;
  9457. t['a61'] = 0x2742;
  9458. t['a62'] = 0x2743;
  9459. t['a63'] = 0x2744;
  9460. t['a64'] = 0x2745;
  9461. t['a65'] = 0x2746;
  9462. t['a66'] = 0x2747;
  9463. t['a67'] = 0x2748;
  9464. t['a68'] = 0x2749;
  9465. t['a69'] = 0x274A;
  9466. t['a70'] = 0x274B;
  9467. t['a71'] = 0x25CF;
  9468. t['a72'] = 0x274D;
  9469. t['a73'] = 0x25A0;
  9470. t['a74'] = 0x274F;
  9471. t['a203'] = 0x2750;
  9472. t['a75'] = 0x2751;
  9473. t['a204'] = 0x2752;
  9474. t['a76'] = 0x25B2;
  9475. t['a77'] = 0x25BC;
  9476. t['a78'] = 0x25C6;
  9477. t['a79'] = 0x2756;
  9478. t['a81'] = 0x25D7;
  9479. t['a82'] = 0x2758;
  9480. t['a83'] = 0x2759;
  9481. t['a84'] = 0x275A;
  9482. t['a97'] = 0x275B;
  9483. t['a98'] = 0x275C;
  9484. t['a99'] = 0x275D;
  9485. t['a100'] = 0x275E;
  9486. t['a101'] = 0x2761;
  9487. t['a102'] = 0x2762;
  9488. t['a103'] = 0x2763;
  9489. t['a104'] = 0x2764;
  9490. t['a106'] = 0x2765;
  9491. t['a107'] = 0x2766;
  9492. t['a108'] = 0x2767;
  9493. t['a112'] = 0x2663;
  9494. t['a111'] = 0x2666;
  9495. t['a110'] = 0x2665;
  9496. t['a109'] = 0x2660;
  9497. t['a120'] = 0x2460;
  9498. t['a121'] = 0x2461;
  9499. t['a122'] = 0x2462;
  9500. t['a123'] = 0x2463;
  9501. t['a124'] = 0x2464;
  9502. t['a125'] = 0x2465;
  9503. t['a126'] = 0x2466;
  9504. t['a127'] = 0x2467;
  9505. t['a128'] = 0x2468;
  9506. t['a129'] = 0x2469;
  9507. t['a130'] = 0x2776;
  9508. t['a131'] = 0x2777;
  9509. t['a132'] = 0x2778;
  9510. t['a133'] = 0x2779;
  9511. t['a134'] = 0x277A;
  9512. t['a135'] = 0x277B;
  9513. t['a136'] = 0x277C;
  9514. t['a137'] = 0x277D;
  9515. t['a138'] = 0x277E;
  9516. t['a139'] = 0x277F;
  9517. t['a140'] = 0x2780;
  9518. t['a141'] = 0x2781;
  9519. t['a142'] = 0x2782;
  9520. t['a143'] = 0x2783;
  9521. t['a144'] = 0x2784;
  9522. t['a145'] = 0x2785;
  9523. t['a146'] = 0x2786;
  9524. t['a147'] = 0x2787;
  9525. t['a148'] = 0x2788;
  9526. t['a149'] = 0x2789;
  9527. t['a150'] = 0x278A;
  9528. t['a151'] = 0x278B;
  9529. t['a152'] = 0x278C;
  9530. t['a153'] = 0x278D;
  9531. t['a154'] = 0x278E;
  9532. t['a155'] = 0x278F;
  9533. t['a156'] = 0x2790;
  9534. t['a157'] = 0x2791;
  9535. t['a158'] = 0x2792;
  9536. t['a159'] = 0x2793;
  9537. t['a160'] = 0x2794;
  9538. t['a161'] = 0x2192;
  9539. t['a163'] = 0x2194;
  9540. t['a164'] = 0x2195;
  9541. t['a196'] = 0x2798;
  9542. t['a165'] = 0x2799;
  9543. t['a192'] = 0x279A;
  9544. t['a166'] = 0x279B;
  9545. t['a167'] = 0x279C;
  9546. t['a168'] = 0x279D;
  9547. t['a169'] = 0x279E;
  9548. t['a170'] = 0x279F;
  9549. t['a171'] = 0x27A0;
  9550. t['a172'] = 0x27A1;
  9551. t['a173'] = 0x27A2;
  9552. t['a162'] = 0x27A3;
  9553. t['a174'] = 0x27A4;
  9554. t['a175'] = 0x27A5;
  9555. t['a176'] = 0x27A6;
  9556. t['a177'] = 0x27A7;
  9557. t['a178'] = 0x27A8;
  9558. t['a179'] = 0x27A9;
  9559. t['a193'] = 0x27AA;
  9560. t['a180'] = 0x27AB;
  9561. t['a199'] = 0x27AC;
  9562. t['a181'] = 0x27AD;
  9563. t['a200'] = 0x27AE;
  9564. t['a182'] = 0x27AF;
  9565. t['a201'] = 0x27B1;
  9566. t['a183'] = 0x27B2;
  9567. t['a184'] = 0x27B3;
  9568. t['a197'] = 0x27B4;
  9569. t['a185'] = 0x27B5;
  9570. t['a194'] = 0x27B6;
  9571. t['a198'] = 0x27B7;
  9572. t['a186'] = 0x27B8;
  9573. t['a195'] = 0x27B9;
  9574. t['a187'] = 0x27BA;
  9575. t['a188'] = 0x27BB;
  9576. t['a189'] = 0x27BC;
  9577. t['a190'] = 0x27BD;
  9578. t['a191'] = 0x27BE;
  9579. t['a89'] = 0x2768; // 0xF8D7
  9580. t['a90'] = 0x2769; // 0xF8D8
  9581. t['a93'] = 0x276A; // 0xF8D9
  9582. t['a94'] = 0x276B; // 0xF8DA
  9583. t['a91'] = 0x276C; // 0xF8DB
  9584. t['a92'] = 0x276D; // 0xF8DC
  9585. t['a205'] = 0x276E; // 0xF8DD
  9586. t['a85'] = 0x276F; // 0xF8DE
  9587. t['a206'] = 0x2770; // 0xF8DF
  9588. t['a86'] = 0x2771; // 0xF8E0
  9589. t['a87'] = 0x2772; // 0xF8E1
  9590. t['a88'] = 0x2773; // 0xF8E2
  9591. t['a95'] = 0x2774; // 0xF8E3
  9592. t['a96'] = 0x2775; // 0xF8E4
  9593. t['.notdef'] = 0x0000;
  9594. });
  9595. exports.getGlyphsUnicode = getGlyphsUnicode;
  9596. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9597. }));
  9598. (function (root, factory) {
  9599. {
  9600. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9601. root.pdfjsCoreArithmeticDecoder);
  9602. }
  9603. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9604. var error = sharedUtil.error;
  9605. var log2 = sharedUtil.log2;
  9606. var readInt8 = sharedUtil.readInt8;
  9607. var readUint16 = sharedUtil.readUint16;
  9608. var readUint32 = sharedUtil.readUint32;
  9609. var shadow = sharedUtil.shadow;
  9610. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9611. var Jbig2Image = (function Jbig2ImageClosure() {
  9612. // Utility data structures
  9613. function ContextCache() {}
  9614. ContextCache.prototype = {
  9615. getContexts: function(id) {
  9616. if (id in this) {
  9617. return this[id];
  9618. }
  9619. return (this[id] = new Int8Array(1 << 16));
  9620. }
  9621. };
  9622. function DecodingContext(data, start, end) {
  9623. this.data = data;
  9624. this.start = start;
  9625. this.end = end;
  9626. }
  9627. DecodingContext.prototype = {
  9628. get decoder() {
  9629. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9630. return shadow(this, 'decoder', decoder);
  9631. },
  9632. get contextCache() {
  9633. var cache = new ContextCache();
  9634. return shadow(this, 'contextCache', cache);
  9635. }
  9636. };
  9637. // Annex A. Arithmetic Integer Decoding Procedure
  9638. // A.2 Procedure for decoding values
  9639. function decodeInteger(contextCache, procedure, decoder) {
  9640. var contexts = contextCache.getContexts(procedure);
  9641. var prev = 1;
  9642. function readBits(length) {
  9643. var v = 0;
  9644. for (var i = 0; i < length; i++) {
  9645. var bit = decoder.readBit(contexts, prev);
  9646. prev = (prev < 256 ? (prev << 1) | bit :
  9647. (((prev << 1) | bit) & 511) | 256);
  9648. v = (v << 1) | bit;
  9649. }
  9650. return v >>> 0;
  9651. }
  9652. var sign = readBits(1);
  9653. var value = readBits(1) ?
  9654. (readBits(1) ?
  9655. (readBits(1) ?
  9656. (readBits(1) ?
  9657. (readBits(1) ?
  9658. (readBits(32) + 4436) :
  9659. readBits(12) + 340) :
  9660. readBits(8) + 84) :
  9661. readBits(6) + 20) :
  9662. readBits(4) + 4) :
  9663. readBits(2);
  9664. return (sign === 0 ? value : (value > 0 ? -value : null));
  9665. }
  9666. // A.3 The IAID decoding procedure
  9667. function decodeIAID(contextCache, decoder, codeLength) {
  9668. var contexts = contextCache.getContexts('IAID');
  9669. var prev = 1;
  9670. for (var i = 0; i < codeLength; i++) {
  9671. var bit = decoder.readBit(contexts, prev);
  9672. prev = (prev << 1) | bit;
  9673. }
  9674. if (codeLength < 31) {
  9675. return prev & ((1 << codeLength) - 1);
  9676. }
  9677. return prev & 0x7FFFFFFF;
  9678. }
  9679. // 7.3 Segment types
  9680. var SegmentTypes = [
  9681. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9682. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9683. null, null, null, null, null, 'patternDictionary', null, null, null,
  9684. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9685. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9686. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9687. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9688. 'IntermediateGenericRefinementRegion', null,
  9689. 'ImmediateGenericRefinementRegion',
  9690. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9691. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9692. 'Tables', null, null, null, null, null, null, null, null,
  9693. 'Extension'
  9694. ];
  9695. var CodingTemplates = [
  9696. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9697. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9698. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9699. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9700. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9701. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9702. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9703. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9704. {x: -1, y: 0}],
  9705. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9706. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9707. ];
  9708. var RefinementTemplates = [
  9709. {
  9710. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9711. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9712. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9713. },
  9714. {
  9715. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9716. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9717. {x: 0, y: 1}, {x: 1, y: 1}]
  9718. }
  9719. ];
  9720. // See 6.2.5.7 Decoding the bitmap.
  9721. var ReusedContexts = [
  9722. 0x9B25, // 10011 0110010 0101
  9723. 0x0795, // 0011 110010 101
  9724. 0x00E5, // 001 11001 01
  9725. 0x0195 // 011001 0101
  9726. ];
  9727. var RefinementReusedContexts = [
  9728. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9729. 0x0008 // '0000' + '001000'
  9730. ];
  9731. function decodeBitmapTemplate0(width, height, decodingContext) {
  9732. var decoder = decodingContext.decoder;
  9733. var contexts = decodingContext.contextCache.getContexts('GB');
  9734. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9735. // ...ooooo....
  9736. // ..ooooooo... Context template for current pixel (X)
  9737. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9738. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9739. for (i = 0; i < height; i++) {
  9740. row = bitmap[i] = new Uint8Array(width);
  9741. row1 = (i < 1) ? row : bitmap[i - 1];
  9742. row2 = (i < 2) ? row : bitmap[i - 2];
  9743. // At the beginning of each row:
  9744. // Fill contextLabel with pixels that are above/right of (X)
  9745. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9746. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9747. (row1[3] << 4);
  9748. for (j = 0; j < width; j++) {
  9749. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9750. // At each pixel: Clear contextLabel pixels that are shifted
  9751. // out of the context, then add new ones.
  9752. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9753. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9754. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9755. }
  9756. }
  9757. return bitmap;
  9758. }
  9759. // 6.2 Generic Region Decoding Procedure
  9760. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9761. decodingContext) {
  9762. if (mmr) {
  9763. error('JBIG2 error: MMR encoding is not supported');
  9764. }
  9765. // Use optimized version for the most common case
  9766. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9767. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9768. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9769. return decodeBitmapTemplate0(width, height, decodingContext);
  9770. }
  9771. var useskip = !!skip;
  9772. var template = CodingTemplates[templateIndex].concat(at);
  9773. // Sorting is non-standard, and it is not required. But sorting increases
  9774. // the number of template bits that can be reused from the previous
  9775. // contextLabel in the main loop.
  9776. template.sort(function (a, b) {
  9777. return (a.y - b.y) || (a.x - b.x);
  9778. });
  9779. var templateLength = template.length;
  9780. var templateX = new Int8Array(templateLength);
  9781. var templateY = new Int8Array(templateLength);
  9782. var changingTemplateEntries = [];
  9783. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9784. var c, k;
  9785. for (k = 0; k < templateLength; k++) {
  9786. templateX[k] = template[k].x;
  9787. templateY[k] = template[k].y;
  9788. minX = Math.min(minX, template[k].x);
  9789. maxX = Math.max(maxX, template[k].x);
  9790. minY = Math.min(minY, template[k].y);
  9791. // Check if the template pixel appears in two consecutive context labels,
  9792. // so it can be reused. Otherwise, we add it to the list of changing
  9793. // template entries.
  9794. if (k < templateLength - 1 &&
  9795. template[k].y === template[k + 1].y &&
  9796. template[k].x === template[k + 1].x - 1) {
  9797. reuseMask |= 1 << (templateLength - 1 - k);
  9798. } else {
  9799. changingTemplateEntries.push(k);
  9800. }
  9801. }
  9802. var changingEntriesLength = changingTemplateEntries.length;
  9803. var changingTemplateX = new Int8Array(changingEntriesLength);
  9804. var changingTemplateY = new Int8Array(changingEntriesLength);
  9805. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9806. for (c = 0; c < changingEntriesLength; c++) {
  9807. k = changingTemplateEntries[c];
  9808. changingTemplateX[c] = template[k].x;
  9809. changingTemplateY[c] = template[k].y;
  9810. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9811. }
  9812. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9813. var sbb_left = -minX;
  9814. var sbb_top = -minY;
  9815. var sbb_right = width - maxX;
  9816. var pseudoPixelContext = ReusedContexts[templateIndex];
  9817. var row = new Uint8Array(width);
  9818. var bitmap = [];
  9819. var decoder = decodingContext.decoder;
  9820. var contexts = decodingContext.contextCache.getContexts('GB');
  9821. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9822. for (var i = 0; i < height; i++) {
  9823. if (prediction) {
  9824. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9825. ltp ^= sltp;
  9826. if (ltp) {
  9827. bitmap.push(row); // duplicate previous row
  9828. continue;
  9829. }
  9830. }
  9831. row = new Uint8Array(row);
  9832. bitmap.push(row);
  9833. for (j = 0; j < width; j++) {
  9834. if (useskip && skip[i][j]) {
  9835. row[j] = 0;
  9836. continue;
  9837. }
  9838. // Are we in the middle of a scanline, so we can reuse contextLabel
  9839. // bits?
  9840. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9841. // If yes, we can just shift the bits that are reusable and only
  9842. // fetch the remaining ones.
  9843. contextLabel = (contextLabel << 1) & reuseMask;
  9844. for (k = 0; k < changingEntriesLength; k++) {
  9845. i0 = i + changingTemplateY[k];
  9846. j0 = j + changingTemplateX[k];
  9847. bit = bitmap[i0][j0];
  9848. if (bit) {
  9849. bit = changingTemplateBit[k];
  9850. contextLabel |= bit;
  9851. }
  9852. }
  9853. } else {
  9854. // compute the contextLabel from scratch
  9855. contextLabel = 0;
  9856. shift = templateLength - 1;
  9857. for (k = 0; k < templateLength; k++, shift--) {
  9858. j0 = j + templateX[k];
  9859. if (j0 >= 0 && j0 < width) {
  9860. i0 = i + templateY[k];
  9861. if (i0 >= 0) {
  9862. bit = bitmap[i0][j0];
  9863. if (bit) {
  9864. contextLabel |= bit << shift;
  9865. }
  9866. }
  9867. }
  9868. }
  9869. }
  9870. var pixel = decoder.readBit(contexts, contextLabel);
  9871. row[j] = pixel;
  9872. }
  9873. }
  9874. return bitmap;
  9875. }
  9876. // 6.3.2 Generic Refinement Region Decoding Procedure
  9877. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9878. offsetX, offsetY, prediction, at,
  9879. decodingContext) {
  9880. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9881. if (templateIndex === 0) {
  9882. codingTemplate = codingTemplate.concat([at[0]]);
  9883. }
  9884. var codingTemplateLength = codingTemplate.length;
  9885. var codingTemplateX = new Int32Array(codingTemplateLength);
  9886. var codingTemplateY = new Int32Array(codingTemplateLength);
  9887. var k;
  9888. for (k = 0; k < codingTemplateLength; k++) {
  9889. codingTemplateX[k] = codingTemplate[k].x;
  9890. codingTemplateY[k] = codingTemplate[k].y;
  9891. }
  9892. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9893. if (templateIndex === 0) {
  9894. referenceTemplate = referenceTemplate.concat([at[1]]);
  9895. }
  9896. var referenceTemplateLength = referenceTemplate.length;
  9897. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9898. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9899. for (k = 0; k < referenceTemplateLength; k++) {
  9900. referenceTemplateX[k] = referenceTemplate[k].x;
  9901. referenceTemplateY[k] = referenceTemplate[k].y;
  9902. }
  9903. var referenceWidth = referenceBitmap[0].length;
  9904. var referenceHeight = referenceBitmap.length;
  9905. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9906. var bitmap = [];
  9907. var decoder = decodingContext.decoder;
  9908. var contexts = decodingContext.contextCache.getContexts('GR');
  9909. var ltp = 0;
  9910. for (var i = 0; i < height; i++) {
  9911. if (prediction) {
  9912. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9913. ltp ^= sltp;
  9914. if (ltp) {
  9915. error('JBIG2 error: prediction is not supported');
  9916. }
  9917. }
  9918. var row = new Uint8Array(width);
  9919. bitmap.push(row);
  9920. for (var j = 0; j < width; j++) {
  9921. var i0, j0;
  9922. var contextLabel = 0;
  9923. for (k = 0; k < codingTemplateLength; k++) {
  9924. i0 = i + codingTemplateY[k];
  9925. j0 = j + codingTemplateX[k];
  9926. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9927. contextLabel <<= 1; // out of bound pixel
  9928. } else {
  9929. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9930. }
  9931. }
  9932. for (k = 0; k < referenceTemplateLength; k++) {
  9933. i0 = i + referenceTemplateY[k] + offsetY;
  9934. j0 = j + referenceTemplateX[k] + offsetX;
  9935. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9936. j0 >= referenceWidth) {
  9937. contextLabel <<= 1; // out of bound pixel
  9938. } else {
  9939. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9940. }
  9941. }
  9942. var pixel = decoder.readBit(contexts, contextLabel);
  9943. row[j] = pixel;
  9944. }
  9945. }
  9946. return bitmap;
  9947. }
  9948. // 6.5.5 Decoding the symbol dictionary
  9949. function decodeSymbolDictionary(huffman, refinement, symbols,
  9950. numberOfNewSymbols, numberOfExportedSymbols,
  9951. huffmanTables, templateIndex, at,
  9952. refinementTemplateIndex, refinementAt,
  9953. decodingContext) {
  9954. if (huffman) {
  9955. error('JBIG2 error: huffman is not supported');
  9956. }
  9957. var newSymbols = [];
  9958. var currentHeight = 0;
  9959. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9960. var decoder = decodingContext.decoder;
  9961. var contextCache = decodingContext.contextCache;
  9962. while (newSymbols.length < numberOfNewSymbols) {
  9963. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9964. currentHeight += deltaHeight;
  9965. var currentWidth = 0;
  9966. var totalWidth = 0;
  9967. while (true) {
  9968. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9969. if (deltaWidth === null) {
  9970. break; // OOB
  9971. }
  9972. currentWidth += deltaWidth;
  9973. totalWidth += currentWidth;
  9974. var bitmap;
  9975. if (refinement) {
  9976. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9977. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9978. if (numberOfInstances > 1) {
  9979. bitmap = decodeTextRegion(huffman, refinement,
  9980. currentWidth, currentHeight, 0,
  9981. numberOfInstances, 1, //strip size
  9982. symbols.concat(newSymbols),
  9983. symbolCodeLength,
  9984. 0, //transposed
  9985. 0, //ds offset
  9986. 1, //top left 7.4.3.1.1
  9987. 0, //OR operator
  9988. huffmanTables,
  9989. refinementTemplateIndex, refinementAt,
  9990. decodingContext);
  9991. } else {
  9992. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9993. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9994. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9995. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9996. newSymbols[symbolId - symbols.length]);
  9997. bitmap = decodeRefinement(currentWidth, currentHeight,
  9998. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9999. decodingContext);
  10000. }
  10001. } else {
  10002. // 6.5.8.1 Direct-coded symbol bitmap
  10003. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  10004. templateIndex, false, null, at, decodingContext);
  10005. }
  10006. newSymbols.push(bitmap);
  10007. }
  10008. }
  10009. // 6.5.10 Exported symbols
  10010. var exportedSymbols = [];
  10011. var flags = [], currentFlag = false;
  10012. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  10013. while (flags.length < totalSymbolsLength) {
  10014. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  10015. while (runLength--) {
  10016. flags.push(currentFlag);
  10017. }
  10018. currentFlag = !currentFlag;
  10019. }
  10020. for (var i = 0, ii = symbols.length; i < ii; i++) {
  10021. if (flags[i]) {
  10022. exportedSymbols.push(symbols[i]);
  10023. }
  10024. }
  10025. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  10026. if (flags[i]) {
  10027. exportedSymbols.push(newSymbols[j]);
  10028. }
  10029. }
  10030. return exportedSymbols;
  10031. }
  10032. function decodeTextRegion(huffman, refinement, width, height,
  10033. defaultPixelValue, numberOfSymbolInstances,
  10034. stripSize, inputSymbols, symbolCodeLength,
  10035. transposed, dsOffset, referenceCorner,
  10036. combinationOperator, huffmanTables,
  10037. refinementTemplateIndex, refinementAt,
  10038. decodingContext) {
  10039. if (huffman) {
  10040. error('JBIG2 error: huffman is not supported');
  10041. }
  10042. // Prepare bitmap
  10043. var bitmap = [];
  10044. var i, row;
  10045. for (i = 0; i < height; i++) {
  10046. row = new Uint8Array(width);
  10047. if (defaultPixelValue) {
  10048. for (var j = 0; j < width; j++) {
  10049. row[j] = defaultPixelValue;
  10050. }
  10051. }
  10052. bitmap.push(row);
  10053. }
  10054. var decoder = decodingContext.decoder;
  10055. var contextCache = decodingContext.contextCache;
  10056. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10057. var firstS = 0;
  10058. i = 0;
  10059. while (i < numberOfSymbolInstances) {
  10060. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10061. stripT += deltaT;
  10062. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  10063. firstS += deltaFirstS;
  10064. var currentS = firstS;
  10065. do {
  10066. var currentT = (stripSize === 1 ? 0 :
  10067. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  10068. var t = stripSize * stripT + currentT;
  10069. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10070. var applyRefinement = (refinement &&
  10071. decodeInteger(contextCache, 'IARI', decoder));
  10072. var symbolBitmap = inputSymbols[symbolId];
  10073. var symbolWidth = symbolBitmap[0].length;
  10074. var symbolHeight = symbolBitmap.length;
  10075. if (applyRefinement) {
  10076. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  10077. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  10078. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10079. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10080. symbolWidth += rdw;
  10081. symbolHeight += rdh;
  10082. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  10083. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  10084. (rdh >> 1) + rdy, false, refinementAt,
  10085. decodingContext);
  10086. }
  10087. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  10088. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  10089. var s2, t2, symbolRow;
  10090. if (transposed) {
  10091. // Place Symbol Bitmap from T1,S1
  10092. for (s2 = 0; s2 < symbolHeight; s2++) {
  10093. row = bitmap[offsetS + s2];
  10094. if (!row) {
  10095. continue;
  10096. }
  10097. symbolRow = symbolBitmap[s2];
  10098. // To ignore Parts of Symbol bitmap which goes
  10099. // outside bitmap region
  10100. var maxWidth = Math.min(width - offsetT, symbolWidth);
  10101. switch (combinationOperator) {
  10102. case 0: // OR
  10103. for (t2 = 0; t2 < maxWidth; t2++) {
  10104. row[offsetT + t2] |= symbolRow[t2];
  10105. }
  10106. break;
  10107. case 2: // XOR
  10108. for (t2 = 0; t2 < maxWidth; t2++) {
  10109. row[offsetT + t2] ^= symbolRow[t2];
  10110. }
  10111. break;
  10112. default:
  10113. error('JBIG2 error: operator ' + combinationOperator +
  10114. ' is not supported');
  10115. }
  10116. }
  10117. currentS += symbolHeight - 1;
  10118. } else {
  10119. for (t2 = 0; t2 < symbolHeight; t2++) {
  10120. row = bitmap[offsetT + t2];
  10121. if (!row) {
  10122. continue;
  10123. }
  10124. symbolRow = symbolBitmap[t2];
  10125. switch (combinationOperator) {
  10126. case 0: // OR
  10127. for (s2 = 0; s2 < symbolWidth; s2++) {
  10128. row[offsetS + s2] |= symbolRow[s2];
  10129. }
  10130. break;
  10131. case 2: // XOR
  10132. for (s2 = 0; s2 < symbolWidth; s2++) {
  10133. row[offsetS + s2] ^= symbolRow[s2];
  10134. }
  10135. break;
  10136. default:
  10137. error('JBIG2 error: operator ' + combinationOperator +
  10138. ' is not supported');
  10139. }
  10140. }
  10141. currentS += symbolWidth - 1;
  10142. }
  10143. i++;
  10144. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  10145. if (deltaS === null) {
  10146. break; // OOB
  10147. }
  10148. currentS += deltaS + dsOffset;
  10149. } while (true);
  10150. }
  10151. return bitmap;
  10152. }
  10153. function readSegmentHeader(data, start) {
  10154. var segmentHeader = {};
  10155. segmentHeader.number = readUint32(data, start);
  10156. var flags = data[start + 4];
  10157. var segmentType = flags & 0x3F;
  10158. if (!SegmentTypes[segmentType]) {
  10159. error('JBIG2 error: invalid segment type: ' + segmentType);
  10160. }
  10161. segmentHeader.type = segmentType;
  10162. segmentHeader.typeName = SegmentTypes[segmentType];
  10163. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  10164. var pageAssociationFieldSize = !!(flags & 0x40);
  10165. var referredFlags = data[start + 5];
  10166. var referredToCount = (referredFlags >> 5) & 7;
  10167. var retainBits = [referredFlags & 31];
  10168. var position = start + 6;
  10169. if (referredFlags === 7) {
  10170. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  10171. position += 3;
  10172. var bytes = (referredToCount + 7) >> 3;
  10173. retainBits[0] = data[position++];
  10174. while (--bytes > 0) {
  10175. retainBits.push(data[position++]);
  10176. }
  10177. } else if (referredFlags === 5 || referredFlags === 6) {
  10178. error('JBIG2 error: invalid referred-to flags');
  10179. }
  10180. segmentHeader.retainBits = retainBits;
  10181. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  10182. (segmentHeader.number <= 65536 ? 2 : 4));
  10183. var referredTo = [];
  10184. var i, ii;
  10185. for (i = 0; i < referredToCount; i++) {
  10186. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  10187. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  10188. readUint32(data, position)));
  10189. referredTo.push(number);
  10190. position += referredToSegmentNumberSize;
  10191. }
  10192. segmentHeader.referredTo = referredTo;
  10193. if (!pageAssociationFieldSize) {
  10194. segmentHeader.pageAssociation = data[position++];
  10195. } else {
  10196. segmentHeader.pageAssociation = readUint32(data, position);
  10197. position += 4;
  10198. }
  10199. segmentHeader.length = readUint32(data, position);
  10200. position += 4;
  10201. if (segmentHeader.length === 0xFFFFFFFF) {
  10202. // 7.2.7 Segment data length, unknown segment length
  10203. if (segmentType === 38) { // ImmediateGenericRegion
  10204. var genericRegionInfo = readRegionSegmentInformation(data, position);
  10205. var genericRegionSegmentFlags = data[position +
  10206. RegionSegmentInformationFieldLength];
  10207. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  10208. // searching for the segment end
  10209. var searchPatternLength = 6;
  10210. var searchPattern = new Uint8Array(searchPatternLength);
  10211. if (!genericRegionMmr) {
  10212. searchPattern[0] = 0xFF;
  10213. searchPattern[1] = 0xAC;
  10214. }
  10215. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  10216. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  10217. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  10218. searchPattern[5] = genericRegionInfo.height & 0xFF;
  10219. for (i = position, ii = data.length; i < ii; i++) {
  10220. var j = 0;
  10221. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  10222. j++;
  10223. }
  10224. if (j === searchPatternLength) {
  10225. segmentHeader.length = i + searchPatternLength;
  10226. break;
  10227. }
  10228. }
  10229. if (segmentHeader.length === 0xFFFFFFFF) {
  10230. error('JBIG2 error: segment end was not found');
  10231. }
  10232. } else {
  10233. error('JBIG2 error: invalid unknown segment length');
  10234. }
  10235. }
  10236. segmentHeader.headerEnd = position;
  10237. return segmentHeader;
  10238. }
  10239. function readSegments(header, data, start, end) {
  10240. var segments = [];
  10241. var position = start;
  10242. while (position < end) {
  10243. var segmentHeader = readSegmentHeader(data, position);
  10244. position = segmentHeader.headerEnd;
  10245. var segment = {
  10246. header: segmentHeader,
  10247. data: data
  10248. };
  10249. if (!header.randomAccess) {
  10250. segment.start = position;
  10251. position += segmentHeader.length;
  10252. segment.end = position;
  10253. }
  10254. segments.push(segment);
  10255. if (segmentHeader.type === 51) {
  10256. break; // end of file is found
  10257. }
  10258. }
  10259. if (header.randomAccess) {
  10260. for (var i = 0, ii = segments.length; i < ii; i++) {
  10261. segments[i].start = position;
  10262. position += segments[i].header.length;
  10263. segments[i].end = position;
  10264. }
  10265. }
  10266. return segments;
  10267. }
  10268. // 7.4.1 Region segment information field
  10269. function readRegionSegmentInformation(data, start) {
  10270. return {
  10271. width: readUint32(data, start),
  10272. height: readUint32(data, start + 4),
  10273. x: readUint32(data, start + 8),
  10274. y: readUint32(data, start + 12),
  10275. combinationOperator: data[start + 16] & 7
  10276. };
  10277. }
  10278. var RegionSegmentInformationFieldLength = 17;
  10279. function processSegment(segment, visitor) {
  10280. var header = segment.header;
  10281. var data = segment.data, position = segment.start, end = segment.end;
  10282. var args, at, i, atLength;
  10283. switch (header.type) {
  10284. case 0: // SymbolDictionary
  10285. // 7.4.2 Symbol dictionary segment syntax
  10286. var dictionary = {};
  10287. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  10288. dictionary.huffman = !!(dictionaryFlags & 1);
  10289. dictionary.refinement = !!(dictionaryFlags & 2);
  10290. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  10291. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  10292. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  10293. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  10294. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  10295. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  10296. dictionary.template = (dictionaryFlags >> 10) & 3;
  10297. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  10298. position += 2;
  10299. if (!dictionary.huffman) {
  10300. atLength = dictionary.template === 0 ? 4 : 1;
  10301. at = [];
  10302. for (i = 0; i < atLength; i++) {
  10303. at.push({
  10304. x: readInt8(data, position),
  10305. y: readInt8(data, position + 1)
  10306. });
  10307. position += 2;
  10308. }
  10309. dictionary.at = at;
  10310. }
  10311. if (dictionary.refinement && !dictionary.refinementTemplate) {
  10312. at = [];
  10313. for (i = 0; i < 2; i++) {
  10314. at.push({
  10315. x: readInt8(data, position),
  10316. y: readInt8(data, position + 1)
  10317. });
  10318. position += 2;
  10319. }
  10320. dictionary.refinementAt = at;
  10321. }
  10322. dictionary.numberOfExportedSymbols = readUint32(data, position);
  10323. position += 4;
  10324. dictionary.numberOfNewSymbols = readUint32(data, position);
  10325. position += 4;
  10326. args = [dictionary, header.number, header.referredTo,
  10327. data, position, end];
  10328. break;
  10329. case 6: // ImmediateTextRegion
  10330. case 7: // ImmediateLosslessTextRegion
  10331. var textRegion = {};
  10332. textRegion.info = readRegionSegmentInformation(data, position);
  10333. position += RegionSegmentInformationFieldLength;
  10334. var textRegionSegmentFlags = readUint16(data, position);
  10335. position += 2;
  10336. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  10337. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  10338. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  10339. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  10340. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  10341. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  10342. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  10343. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  10344. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  10345. if (textRegion.huffman) {
  10346. var textRegionHuffmanFlags = readUint16(data, position);
  10347. position += 2;
  10348. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  10349. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  10350. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  10351. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  10352. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  10353. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  10354. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  10355. textRegion.huffmanRefinementSizeSelector =
  10356. !!(textRegionHuffmanFlags & 14);
  10357. }
  10358. if (textRegion.refinement && !textRegion.refinementTemplate) {
  10359. at = [];
  10360. for (i = 0; i < 2; i++) {
  10361. at.push({
  10362. x: readInt8(data, position),
  10363. y: readInt8(data, position + 1)
  10364. });
  10365. position += 2;
  10366. }
  10367. textRegion.refinementAt = at;
  10368. }
  10369. textRegion.numberOfSymbolInstances = readUint32(data, position);
  10370. position += 4;
  10371. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  10372. if (textRegion.huffman) {
  10373. error('JBIG2 error: huffman is not supported');
  10374. }
  10375. args = [textRegion, header.referredTo, data, position, end];
  10376. break;
  10377. case 38: // ImmediateGenericRegion
  10378. case 39: // ImmediateLosslessGenericRegion
  10379. var genericRegion = {};
  10380. genericRegion.info = readRegionSegmentInformation(data, position);
  10381. position += RegionSegmentInformationFieldLength;
  10382. var genericRegionSegmentFlags = data[position++];
  10383. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  10384. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  10385. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  10386. if (!genericRegion.mmr) {
  10387. atLength = genericRegion.template === 0 ? 4 : 1;
  10388. at = [];
  10389. for (i = 0; i < atLength; i++) {
  10390. at.push({
  10391. x: readInt8(data, position),
  10392. y: readInt8(data, position + 1)
  10393. });
  10394. position += 2;
  10395. }
  10396. genericRegion.at = at;
  10397. }
  10398. args = [genericRegion, data, position, end];
  10399. break;
  10400. case 48: // PageInformation
  10401. var pageInfo = {
  10402. width: readUint32(data, position),
  10403. height: readUint32(data, position + 4),
  10404. resolutionX: readUint32(data, position + 8),
  10405. resolutionY: readUint32(data, position + 12)
  10406. };
  10407. if (pageInfo.height === 0xFFFFFFFF) {
  10408. delete pageInfo.height;
  10409. }
  10410. var pageSegmentFlags = data[position + 16];
  10411. var pageStripingInformation = readUint16(data, position + 17);
  10412. pageInfo.lossless = !!(pageSegmentFlags & 1);
  10413. pageInfo.refinement = !!(pageSegmentFlags & 2);
  10414. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  10415. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  10416. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  10417. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  10418. args = [pageInfo];
  10419. break;
  10420. case 49: // EndOfPage
  10421. break;
  10422. case 50: // EndOfStripe
  10423. break;
  10424. case 51: // EndOfFile
  10425. break;
  10426. case 62: // 7.4.15 defines 2 extension types which
  10427. // are comments and can be ignored.
  10428. break;
  10429. default:
  10430. error('JBIG2 error: segment type ' + header.typeName + '(' +
  10431. header.type + ') is not implemented');
  10432. }
  10433. var callbackName = 'on' + header.typeName;
  10434. if (callbackName in visitor) {
  10435. visitor[callbackName].apply(visitor, args);
  10436. }
  10437. }
  10438. function processSegments(segments, visitor) {
  10439. for (var i = 0, ii = segments.length; i < ii; i++) {
  10440. processSegment(segments[i], visitor);
  10441. }
  10442. }
  10443. function parseJbig2(data, start, end) {
  10444. var position = start;
  10445. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  10446. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  10447. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  10448. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  10449. error('JBIG2 error: invalid header');
  10450. }
  10451. var header = {};
  10452. position += 8;
  10453. var flags = data[position++];
  10454. header.randomAccess = !(flags & 1);
  10455. if (!(flags & 2)) {
  10456. header.numberOfPages = readUint32(data, position);
  10457. position += 4;
  10458. }
  10459. var segments = readSegments(header, data, position, end);
  10460. error('Not implemented');
  10461. // processSegments(segments, new SimpleSegmentVisitor());
  10462. }
  10463. function parseJbig2Chunks(chunks) {
  10464. var visitor = new SimpleSegmentVisitor();
  10465. for (var i = 0, ii = chunks.length; i < ii; i++) {
  10466. var chunk = chunks[i];
  10467. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  10468. processSegments(segments, visitor);
  10469. }
  10470. return visitor.buffer;
  10471. }
  10472. function SimpleSegmentVisitor() {}
  10473. SimpleSegmentVisitor.prototype = {
  10474. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  10475. this.currentPageInfo = info;
  10476. var rowSize = (info.width + 7) >> 3;
  10477. var buffer = new Uint8Array(rowSize * info.height);
  10478. // The contents of ArrayBuffers are initialized to 0.
  10479. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  10480. if (info.defaultPixelValue) {
  10481. for (var i = 0, ii = buffer.length; i < ii; i++) {
  10482. buffer[i] = 0xFF;
  10483. }
  10484. }
  10485. this.buffer = buffer;
  10486. },
  10487. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  10488. var pageInfo = this.currentPageInfo;
  10489. var width = regionInfo.width, height = regionInfo.height;
  10490. var rowSize = (pageInfo.width + 7) >> 3;
  10491. var combinationOperator = pageInfo.combinationOperatorOverride ?
  10492. regionInfo.combinationOperator : pageInfo.combinationOperator;
  10493. var buffer = this.buffer;
  10494. var mask0 = 128 >> (regionInfo.x & 7);
  10495. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  10496. var i, j, mask, offset;
  10497. switch (combinationOperator) {
  10498. case 0: // OR
  10499. for (i = 0; i < height; i++) {
  10500. mask = mask0;
  10501. offset = offset0;
  10502. for (j = 0; j < width; j++) {
  10503. if (bitmap[i][j]) {
  10504. buffer[offset] |= mask;
  10505. }
  10506. mask >>= 1;
  10507. if (!mask) {
  10508. mask = 128;
  10509. offset++;
  10510. }
  10511. }
  10512. offset0 += rowSize;
  10513. }
  10514. break;
  10515. case 2: // XOR
  10516. for (i = 0; i < height; i++) {
  10517. mask = mask0;
  10518. offset = offset0;
  10519. for (j = 0; j < width; j++) {
  10520. if (bitmap[i][j]) {
  10521. buffer[offset] ^= mask;
  10522. }
  10523. mask >>= 1;
  10524. if (!mask) {
  10525. mask = 128;
  10526. offset++;
  10527. }
  10528. }
  10529. offset0 += rowSize;
  10530. }
  10531. break;
  10532. default:
  10533. error('JBIG2 error: operator ' + combinationOperator +
  10534. ' is not supported');
  10535. }
  10536. },
  10537. onImmediateGenericRegion:
  10538. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10539. start, end) {
  10540. var regionInfo = region.info;
  10541. var decodingContext = new DecodingContext(data, start, end);
  10542. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10543. region.template, region.prediction, null,
  10544. region.at, decodingContext);
  10545. this.drawBitmap(regionInfo, bitmap);
  10546. },
  10547. onImmediateLosslessGenericRegion:
  10548. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10549. this.onImmediateGenericRegion.apply(this, arguments);
  10550. },
  10551. onSymbolDictionary:
  10552. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10553. currentSegment,
  10554. referredSegments,
  10555. data, start, end) {
  10556. var huffmanTables;
  10557. if (dictionary.huffman) {
  10558. error('JBIG2 error: huffman is not supported');
  10559. }
  10560. // Combines exported symbols from all referred segments
  10561. var symbols = this.symbols;
  10562. if (!symbols) {
  10563. this.symbols = symbols = {};
  10564. }
  10565. var inputSymbols = [];
  10566. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10567. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10568. }
  10569. var decodingContext = new DecodingContext(data, start, end);
  10570. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10571. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10572. dictionary.numberOfExportedSymbols, huffmanTables,
  10573. dictionary.template, dictionary.at,
  10574. dictionary.refinementTemplate, dictionary.refinementAt,
  10575. decodingContext);
  10576. },
  10577. onImmediateTextRegion:
  10578. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10579. referredSegments,
  10580. data, start, end) {
  10581. var regionInfo = region.info;
  10582. var huffmanTables;
  10583. // Combines exported symbols from all referred segments
  10584. var symbols = this.symbols;
  10585. var inputSymbols = [];
  10586. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10587. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10588. }
  10589. var symbolCodeLength = log2(inputSymbols.length);
  10590. var decodingContext = new DecodingContext(data, start, end);
  10591. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10592. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10593. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10594. symbolCodeLength, region.transposed, region.dsOffset,
  10595. region.referenceCorner, region.combinationOperator, huffmanTables,
  10596. region.refinementTemplate, region.refinementAt, decodingContext);
  10597. this.drawBitmap(regionInfo, bitmap);
  10598. },
  10599. onImmediateLosslessTextRegion:
  10600. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10601. this.onImmediateTextRegion.apply(this, arguments);
  10602. }
  10603. };
  10604. function Jbig2Image() {}
  10605. Jbig2Image.prototype = {
  10606. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10607. return parseJbig2Chunks(chunks);
  10608. }
  10609. };
  10610. return Jbig2Image;
  10611. })();
  10612. exports.Jbig2Image = Jbig2Image;
  10613. }));
  10614. (function (root, factory) {
  10615. {
  10616. factory((root.pdfjsCoreJpg = {}), root.pdfjsSharedUtil);
  10617. }
  10618. }(this, function (exports, sharedUtil) {
  10619. var error = sharedUtil.error;
  10620. /**
  10621. * This code was forked from https://github.com/notmasteryet/jpgjs.
  10622. * The original version was created by GitHub user notmasteryet.
  10623. *
  10624. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  10625. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  10626. * - The JFIF specification can be found in the JPEG File Interchange Format
  10627. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  10628. * - The Adobe Application-Specific JPEG markers in the
  10629. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  10630. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  10631. */
  10632. var JpegImage = (function jpegImage() {
  10633. var dctZigZag = new Uint8Array([
  10634. 0,
  10635. 1, 8,
  10636. 16, 9, 2,
  10637. 3, 10, 17, 24,
  10638. 32, 25, 18, 11, 4,
  10639. 5, 12, 19, 26, 33, 40,
  10640. 48, 41, 34, 27, 20, 13, 6,
  10641. 7, 14, 21, 28, 35, 42, 49, 56,
  10642. 57, 50, 43, 36, 29, 22, 15,
  10643. 23, 30, 37, 44, 51, 58,
  10644. 59, 52, 45, 38, 31,
  10645. 39, 46, 53, 60,
  10646. 61, 54, 47,
  10647. 55, 62,
  10648. 63
  10649. ]);
  10650. var dctCos1 = 4017; // cos(pi/16)
  10651. var dctSin1 = 799; // sin(pi/16)
  10652. var dctCos3 = 3406; // cos(3*pi/16)
  10653. var dctSin3 = 2276; // sin(3*pi/16)
  10654. var dctCos6 = 1567; // cos(6*pi/16)
  10655. var dctSin6 = 3784; // sin(6*pi/16)
  10656. var dctSqrt2 = 5793; // sqrt(2)
  10657. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  10658. function constructor() {
  10659. }
  10660. function buildHuffmanTable(codeLengths, values) {
  10661. var k = 0, code = [], i, j, length = 16;
  10662. while (length > 0 && !codeLengths[length - 1]) {
  10663. length--;
  10664. }
  10665. code.push({children: [], index: 0});
  10666. var p = code[0], q;
  10667. for (i = 0; i < length; i++) {
  10668. for (j = 0; j < codeLengths[i]; j++) {
  10669. p = code.pop();
  10670. p.children[p.index] = values[k];
  10671. while (p.index > 0) {
  10672. p = code.pop();
  10673. }
  10674. p.index++;
  10675. code.push(p);
  10676. while (code.length <= i) {
  10677. code.push(q = {children: [], index: 0});
  10678. p.children[p.index] = q.children;
  10679. p = q;
  10680. }
  10681. k++;
  10682. }
  10683. if (i + 1 < length) {
  10684. // p here points to last code
  10685. code.push(q = {children: [], index: 0});
  10686. p.children[p.index] = q.children;
  10687. p = q;
  10688. }
  10689. }
  10690. return code[0].children;
  10691. }
  10692. function getBlockBufferOffset(component, row, col) {
  10693. return 64 * ((component.blocksPerLine + 1) * row + col);
  10694. }
  10695. function decodeScan(data, offset, frame, components, resetInterval,
  10696. spectralStart, spectralEnd, successivePrev, successive) {
  10697. var mcusPerLine = frame.mcusPerLine;
  10698. var progressive = frame.progressive;
  10699. var startOffset = offset, bitsData = 0, bitsCount = 0;
  10700. function readBit() {
  10701. if (bitsCount > 0) {
  10702. bitsCount--;
  10703. return (bitsData >> bitsCount) & 1;
  10704. }
  10705. bitsData = data[offset++];
  10706. if (bitsData === 0xFF) {
  10707. var nextByte = data[offset++];
  10708. if (nextByte) {
  10709. error('JPEG error: unexpected marker ' +
  10710. ((bitsData << 8) | nextByte).toString(16));
  10711. }
  10712. // unstuff 0
  10713. }
  10714. bitsCount = 7;
  10715. return bitsData >>> 7;
  10716. }
  10717. function decodeHuffman(tree) {
  10718. var node = tree;
  10719. while (true) {
  10720. node = node[readBit()];
  10721. if (typeof node === 'number') {
  10722. return node;
  10723. }
  10724. if (typeof node !== 'object') {
  10725. error('JPEG error: invalid huffman sequence');
  10726. }
  10727. }
  10728. }
  10729. function receive(length) {
  10730. var n = 0;
  10731. while (length > 0) {
  10732. n = (n << 1) | readBit();
  10733. length--;
  10734. }
  10735. return n;
  10736. }
  10737. function receiveAndExtend(length) {
  10738. if (length === 1) {
  10739. return readBit() === 1 ? 1 : -1;
  10740. }
  10741. var n = receive(length);
  10742. if (n >= 1 << (length - 1)) {
  10743. return n;
  10744. }
  10745. return n + (-1 << length) + 1;
  10746. }
  10747. function decodeBaseline(component, offset) {
  10748. var t = decodeHuffman(component.huffmanTableDC);
  10749. var diff = t === 0 ? 0 : receiveAndExtend(t);
  10750. component.blockData[offset] = (component.pred += diff);
  10751. var k = 1;
  10752. while (k < 64) {
  10753. var rs = decodeHuffman(component.huffmanTableAC);
  10754. var s = rs & 15, r = rs >> 4;
  10755. if (s === 0) {
  10756. if (r < 15) {
  10757. break;
  10758. }
  10759. k += 16;
  10760. continue;
  10761. }
  10762. k += r;
  10763. var z = dctZigZag[k];
  10764. component.blockData[offset + z] = receiveAndExtend(s);
  10765. k++;
  10766. }
  10767. }
  10768. function decodeDCFirst(component, offset) {
  10769. var t = decodeHuffman(component.huffmanTableDC);
  10770. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  10771. component.blockData[offset] = (component.pred += diff);
  10772. }
  10773. function decodeDCSuccessive(component, offset) {
  10774. component.blockData[offset] |= readBit() << successive;
  10775. }
  10776. var eobrun = 0;
  10777. function decodeACFirst(component, offset) {
  10778. if (eobrun > 0) {
  10779. eobrun--;
  10780. return;
  10781. }
  10782. var k = spectralStart, e = spectralEnd;
  10783. while (k <= e) {
  10784. var rs = decodeHuffman(component.huffmanTableAC);
  10785. var s = rs & 15, r = rs >> 4;
  10786. if (s === 0) {
  10787. if (r < 15) {
  10788. eobrun = receive(r) + (1 << r) - 1;
  10789. break;
  10790. }
  10791. k += 16;
  10792. continue;
  10793. }
  10794. k += r;
  10795. var z = dctZigZag[k];
  10796. component.blockData[offset + z] =
  10797. receiveAndExtend(s) * (1 << successive);
  10798. k++;
  10799. }
  10800. }
  10801. var successiveACState = 0, successiveACNextValue;
  10802. function decodeACSuccessive(component, offset) {
  10803. var k = spectralStart;
  10804. var e = spectralEnd;
  10805. var r = 0;
  10806. var s;
  10807. var rs;
  10808. while (k <= e) {
  10809. var z = dctZigZag[k];
  10810. switch (successiveACState) {
  10811. case 0: // initial state
  10812. rs = decodeHuffman(component.huffmanTableAC);
  10813. s = rs & 15;
  10814. r = rs >> 4;
  10815. if (s === 0) {
  10816. if (r < 15) {
  10817. eobrun = receive(r) + (1 << r);
  10818. successiveACState = 4;
  10819. } else {
  10820. r = 16;
  10821. successiveACState = 1;
  10822. }
  10823. } else {
  10824. if (s !== 1) {
  10825. error('JPEG error: invalid ACn encoding');
  10826. }
  10827. successiveACNextValue = receiveAndExtend(s);
  10828. successiveACState = r ? 2 : 3;
  10829. }
  10830. continue;
  10831. case 1: // skipping r zero items
  10832. case 2:
  10833. if (component.blockData[offset + z]) {
  10834. component.blockData[offset + z] += (readBit() << successive);
  10835. } else {
  10836. r--;
  10837. if (r === 0) {
  10838. successiveACState = successiveACState === 2 ? 3 : 0;
  10839. }
  10840. }
  10841. break;
  10842. case 3: // set value for a zero item
  10843. if (component.blockData[offset + z]) {
  10844. component.blockData[offset + z] += (readBit() << successive);
  10845. } else {
  10846. component.blockData[offset + z] =
  10847. successiveACNextValue << successive;
  10848. successiveACState = 0;
  10849. }
  10850. break;
  10851. case 4: // eob
  10852. if (component.blockData[offset + z]) {
  10853. component.blockData[offset + z] += (readBit() << successive);
  10854. }
  10855. break;
  10856. }
  10857. k++;
  10858. }
  10859. if (successiveACState === 4) {
  10860. eobrun--;
  10861. if (eobrun === 0) {
  10862. successiveACState = 0;
  10863. }
  10864. }
  10865. }
  10866. function decodeMcu(component, decode, mcu, row, col) {
  10867. var mcuRow = (mcu / mcusPerLine) | 0;
  10868. var mcuCol = mcu % mcusPerLine;
  10869. var blockRow = mcuRow * component.v + row;
  10870. var blockCol = mcuCol * component.h + col;
  10871. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10872. decode(component, offset);
  10873. }
  10874. function decodeBlock(component, decode, mcu) {
  10875. var blockRow = (mcu / component.blocksPerLine) | 0;
  10876. var blockCol = mcu % component.blocksPerLine;
  10877. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10878. decode(component, offset);
  10879. }
  10880. var componentsLength = components.length;
  10881. var component, i, j, k, n;
  10882. var decodeFn;
  10883. if (progressive) {
  10884. if (spectralStart === 0) {
  10885. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  10886. } else {
  10887. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  10888. }
  10889. } else {
  10890. decodeFn = decodeBaseline;
  10891. }
  10892. var mcu = 0, marker;
  10893. var mcuExpected;
  10894. if (componentsLength === 1) {
  10895. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  10896. } else {
  10897. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  10898. }
  10899. if (!resetInterval) {
  10900. resetInterval = mcuExpected;
  10901. }
  10902. var h, v;
  10903. while (mcu < mcuExpected) {
  10904. // reset interval stuff
  10905. for (i = 0; i < componentsLength; i++) {
  10906. components[i].pred = 0;
  10907. }
  10908. eobrun = 0;
  10909. if (componentsLength === 1) {
  10910. component = components[0];
  10911. for (n = 0; n < resetInterval; n++) {
  10912. decodeBlock(component, decodeFn, mcu);
  10913. mcu++;
  10914. }
  10915. } else {
  10916. for (n = 0; n < resetInterval; n++) {
  10917. for (i = 0; i < componentsLength; i++) {
  10918. component = components[i];
  10919. h = component.h;
  10920. v = component.v;
  10921. for (j = 0; j < v; j++) {
  10922. for (k = 0; k < h; k++) {
  10923. decodeMcu(component, decodeFn, mcu, j, k);
  10924. }
  10925. }
  10926. }
  10927. mcu++;
  10928. }
  10929. }
  10930. // find marker
  10931. bitsCount = 0;
  10932. marker = (data[offset] << 8) | data[offset + 1];
  10933. if (marker <= 0xFF00) {
  10934. error('JPEG error: marker was not found');
  10935. }
  10936. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  10937. offset += 2;
  10938. } else {
  10939. break;
  10940. }
  10941. }
  10942. return offset - startOffset;
  10943. }
  10944. // A port of poppler's IDCT method which in turn is taken from:
  10945. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  10946. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  10947. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  10948. // 988-991.
  10949. function quantizeAndInverse(component, blockBufferOffset, p) {
  10950. var qt = component.quantizationTable, blockData = component.blockData;
  10951. var v0, v1, v2, v3, v4, v5, v6, v7;
  10952. var p0, p1, p2, p3, p4, p5, p6, p7;
  10953. var t;
  10954. if (!qt) {
  10955. error('JPEG error: missing required Quantization Table.');
  10956. }
  10957. // inverse DCT on rows
  10958. for (var row = 0; row < 64; row += 8) {
  10959. // gather block data
  10960. p0 = blockData[blockBufferOffset + row];
  10961. p1 = blockData[blockBufferOffset + row + 1];
  10962. p2 = blockData[blockBufferOffset + row + 2];
  10963. p3 = blockData[blockBufferOffset + row + 3];
  10964. p4 = blockData[blockBufferOffset + row + 4];
  10965. p5 = blockData[blockBufferOffset + row + 5];
  10966. p6 = blockData[blockBufferOffset + row + 6];
  10967. p7 = blockData[blockBufferOffset + row + 7];
  10968. // dequant p0
  10969. p0 *= qt[row];
  10970. // check for all-zero AC coefficients
  10971. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  10972. t = (dctSqrt2 * p0 + 512) >> 10;
  10973. p[row] = t;
  10974. p[row + 1] = t;
  10975. p[row + 2] = t;
  10976. p[row + 3] = t;
  10977. p[row + 4] = t;
  10978. p[row + 5] = t;
  10979. p[row + 6] = t;
  10980. p[row + 7] = t;
  10981. continue;
  10982. }
  10983. // dequant p1 ... p7
  10984. p1 *= qt[row + 1];
  10985. p2 *= qt[row + 2];
  10986. p3 *= qt[row + 3];
  10987. p4 *= qt[row + 4];
  10988. p5 *= qt[row + 5];
  10989. p6 *= qt[row + 6];
  10990. p7 *= qt[row + 7];
  10991. // stage 4
  10992. v0 = (dctSqrt2 * p0 + 128) >> 8;
  10993. v1 = (dctSqrt2 * p4 + 128) >> 8;
  10994. v2 = p2;
  10995. v3 = p6;
  10996. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  10997. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  10998. v5 = p3 << 4;
  10999. v6 = p5 << 4;
  11000. // stage 3
  11001. v0 = (v0 + v1 + 1) >> 1;
  11002. v1 = v0 - v1;
  11003. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  11004. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  11005. v3 = t;
  11006. v4 = (v4 + v6 + 1) >> 1;
  11007. v6 = v4 - v6;
  11008. v7 = (v7 + v5 + 1) >> 1;
  11009. v5 = v7 - v5;
  11010. // stage 2
  11011. v0 = (v0 + v3 + 1) >> 1;
  11012. v3 = v0 - v3;
  11013. v1 = (v1 + v2 + 1) >> 1;
  11014. v2 = v1 - v2;
  11015. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11016. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11017. v7 = t;
  11018. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11019. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11020. v6 = t;
  11021. // stage 1
  11022. p[row] = v0 + v7;
  11023. p[row + 7] = v0 - v7;
  11024. p[row + 1] = v1 + v6;
  11025. p[row + 6] = v1 - v6;
  11026. p[row + 2] = v2 + v5;
  11027. p[row + 5] = v2 - v5;
  11028. p[row + 3] = v3 + v4;
  11029. p[row + 4] = v3 - v4;
  11030. }
  11031. // inverse DCT on columns
  11032. for (var col = 0; col < 8; ++col) {
  11033. p0 = p[col];
  11034. p1 = p[col + 8];
  11035. p2 = p[col + 16];
  11036. p3 = p[col + 24];
  11037. p4 = p[col + 32];
  11038. p5 = p[col + 40];
  11039. p6 = p[col + 48];
  11040. p7 = p[col + 56];
  11041. // check for all-zero AC coefficients
  11042. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  11043. t = (dctSqrt2 * p0 + 8192) >> 14;
  11044. // convert to 8 bit
  11045. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  11046. blockData[blockBufferOffset + col] = t;
  11047. blockData[blockBufferOffset + col + 8] = t;
  11048. blockData[blockBufferOffset + col + 16] = t;
  11049. blockData[blockBufferOffset + col + 24] = t;
  11050. blockData[blockBufferOffset + col + 32] = t;
  11051. blockData[blockBufferOffset + col + 40] = t;
  11052. blockData[blockBufferOffset + col + 48] = t;
  11053. blockData[blockBufferOffset + col + 56] = t;
  11054. continue;
  11055. }
  11056. // stage 4
  11057. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  11058. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  11059. v2 = p2;
  11060. v3 = p6;
  11061. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  11062. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  11063. v5 = p3;
  11064. v6 = p5;
  11065. // stage 3
  11066. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  11067. // converting to UInt8 range later.
  11068. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  11069. v1 = v0 - v1;
  11070. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  11071. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  11072. v3 = t;
  11073. v4 = (v4 + v6 + 1) >> 1;
  11074. v6 = v4 - v6;
  11075. v7 = (v7 + v5 + 1) >> 1;
  11076. v5 = v7 - v5;
  11077. // stage 2
  11078. v0 = (v0 + v3 + 1) >> 1;
  11079. v3 = v0 - v3;
  11080. v1 = (v1 + v2 + 1) >> 1;
  11081. v2 = v1 - v2;
  11082. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11083. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11084. v7 = t;
  11085. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11086. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11087. v6 = t;
  11088. // stage 1
  11089. p0 = v0 + v7;
  11090. p7 = v0 - v7;
  11091. p1 = v1 + v6;
  11092. p6 = v1 - v6;
  11093. p2 = v2 + v5;
  11094. p5 = v2 - v5;
  11095. p3 = v3 + v4;
  11096. p4 = v3 - v4;
  11097. // convert to 8-bit integers
  11098. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  11099. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  11100. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  11101. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  11102. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  11103. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  11104. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  11105. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  11106. // store block data
  11107. blockData[blockBufferOffset + col] = p0;
  11108. blockData[blockBufferOffset + col + 8] = p1;
  11109. blockData[blockBufferOffset + col + 16] = p2;
  11110. blockData[blockBufferOffset + col + 24] = p3;
  11111. blockData[blockBufferOffset + col + 32] = p4;
  11112. blockData[blockBufferOffset + col + 40] = p5;
  11113. blockData[blockBufferOffset + col + 48] = p6;
  11114. blockData[blockBufferOffset + col + 56] = p7;
  11115. }
  11116. }
  11117. function buildComponentData(frame, component) {
  11118. var blocksPerLine = component.blocksPerLine;
  11119. var blocksPerColumn = component.blocksPerColumn;
  11120. var computationBuffer = new Int16Array(64);
  11121. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  11122. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  11123. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  11124. quantizeAndInverse(component, offset, computationBuffer);
  11125. }
  11126. }
  11127. return component.blockData;
  11128. }
  11129. function clamp0to255(a) {
  11130. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  11131. }
  11132. constructor.prototype = {
  11133. parse: function parse(data) {
  11134. function readUint16() {
  11135. var value = (data[offset] << 8) | data[offset + 1];
  11136. offset += 2;
  11137. return value;
  11138. }
  11139. function readDataBlock() {
  11140. var length = readUint16();
  11141. var array = data.subarray(offset, offset + length - 2);
  11142. offset += array.length;
  11143. return array;
  11144. }
  11145. function prepareComponents(frame) {
  11146. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  11147. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  11148. for (var i = 0; i < frame.components.length; i++) {
  11149. component = frame.components[i];
  11150. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  11151. component.h / frame.maxH);
  11152. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  11153. component.v / frame.maxV);
  11154. var blocksPerLineForMcu = mcusPerLine * component.h;
  11155. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  11156. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  11157. (blocksPerLineForMcu + 1);
  11158. component.blockData = new Int16Array(blocksBufferSize);
  11159. component.blocksPerLine = blocksPerLine;
  11160. component.blocksPerColumn = blocksPerColumn;
  11161. }
  11162. frame.mcusPerLine = mcusPerLine;
  11163. frame.mcusPerColumn = mcusPerColumn;
  11164. }
  11165. var offset = 0;
  11166. var jfif = null;
  11167. var adobe = null;
  11168. var frame, resetInterval;
  11169. var quantizationTables = [];
  11170. var huffmanTablesAC = [], huffmanTablesDC = [];
  11171. var fileMarker = readUint16();
  11172. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  11173. error('JPEG error: SOI not found');
  11174. }
  11175. fileMarker = readUint16();
  11176. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  11177. var i, j, l;
  11178. switch(fileMarker) {
  11179. case 0xFFE0: // APP0 (Application Specific)
  11180. case 0xFFE1: // APP1
  11181. case 0xFFE2: // APP2
  11182. case 0xFFE3: // APP3
  11183. case 0xFFE4: // APP4
  11184. case 0xFFE5: // APP5
  11185. case 0xFFE6: // APP6
  11186. case 0xFFE7: // APP7
  11187. case 0xFFE8: // APP8
  11188. case 0xFFE9: // APP9
  11189. case 0xFFEA: // APP10
  11190. case 0xFFEB: // APP11
  11191. case 0xFFEC: // APP12
  11192. case 0xFFED: // APP13
  11193. case 0xFFEE: // APP14
  11194. case 0xFFEF: // APP15
  11195. case 0xFFFE: // COM (Comment)
  11196. var appData = readDataBlock();
  11197. if (fileMarker === 0xFFE0) {
  11198. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  11199. appData[2] === 0x49 && appData[3] === 0x46 &&
  11200. appData[4] === 0) { // 'JFIF\x00'
  11201. jfif = {
  11202. version: { major: appData[5], minor: appData[6] },
  11203. densityUnits: appData[7],
  11204. xDensity: (appData[8] << 8) | appData[9],
  11205. yDensity: (appData[10] << 8) | appData[11],
  11206. thumbWidth: appData[12],
  11207. thumbHeight: appData[13],
  11208. thumbData: appData.subarray(14, 14 +
  11209. 3 * appData[12] * appData[13])
  11210. };
  11211. }
  11212. }
  11213. // TODO APP1 - Exif
  11214. if (fileMarker === 0xFFEE) {
  11215. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  11216. appData[2] === 0x6F && appData[3] === 0x62 &&
  11217. appData[4] === 0x65) { // 'Adobe'
  11218. adobe = {
  11219. version: (appData[5] << 8) | appData[6],
  11220. flags0: (appData[7] << 8) | appData[8],
  11221. flags1: (appData[9] << 8) | appData[10],
  11222. transformCode: appData[11]
  11223. };
  11224. }
  11225. }
  11226. break;
  11227. case 0xFFDB: // DQT (Define Quantization Tables)
  11228. var quantizationTablesLength = readUint16();
  11229. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  11230. var z;
  11231. while (offset < quantizationTablesEnd) {
  11232. var quantizationTableSpec = data[offset++];
  11233. var tableData = new Uint16Array(64);
  11234. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  11235. for (j = 0; j < 64; j++) {
  11236. z = dctZigZag[j];
  11237. tableData[z] = data[offset++];
  11238. }
  11239. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  11240. for (j = 0; j < 64; j++) {
  11241. z = dctZigZag[j];
  11242. tableData[z] = readUint16();
  11243. }
  11244. } else {
  11245. error('JPEG error: DQT - invalid table spec');
  11246. }
  11247. quantizationTables[quantizationTableSpec & 15] = tableData;
  11248. }
  11249. break;
  11250. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  11251. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  11252. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  11253. if (frame) {
  11254. error('JPEG error: Only single frame JPEGs supported');
  11255. }
  11256. readUint16(); // skip data length
  11257. frame = {};
  11258. frame.extended = (fileMarker === 0xFFC1);
  11259. frame.progressive = (fileMarker === 0xFFC2);
  11260. frame.precision = data[offset++];
  11261. frame.scanLines = readUint16();
  11262. frame.samplesPerLine = readUint16();
  11263. frame.components = [];
  11264. frame.componentIds = {};
  11265. var componentsCount = data[offset++], componentId;
  11266. var maxH = 0, maxV = 0;
  11267. for (i = 0; i < componentsCount; i++) {
  11268. componentId = data[offset];
  11269. var h = data[offset + 1] >> 4;
  11270. var v = data[offset + 1] & 15;
  11271. if (maxH < h) {
  11272. maxH = h;
  11273. }
  11274. if (maxV < v) {
  11275. maxV = v;
  11276. }
  11277. var qId = data[offset + 2];
  11278. l = frame.components.push({
  11279. h: h,
  11280. v: v,
  11281. quantizationId: qId,
  11282. quantizationTable: null, // See comment below.
  11283. });
  11284. frame.componentIds[componentId] = l - 1;
  11285. offset += 3;
  11286. }
  11287. frame.maxH = maxH;
  11288. frame.maxV = maxV;
  11289. prepareComponents(frame);
  11290. break;
  11291. case 0xFFC4: // DHT (Define Huffman Tables)
  11292. var huffmanLength = readUint16();
  11293. for (i = 2; i < huffmanLength;) {
  11294. var huffmanTableSpec = data[offset++];
  11295. var codeLengths = new Uint8Array(16);
  11296. var codeLengthSum = 0;
  11297. for (j = 0; j < 16; j++, offset++) {
  11298. codeLengthSum += (codeLengths[j] = data[offset]);
  11299. }
  11300. var huffmanValues = new Uint8Array(codeLengthSum);
  11301. for (j = 0; j < codeLengthSum; j++, offset++) {
  11302. huffmanValues[j] = data[offset];
  11303. }
  11304. i += 17 + codeLengthSum;
  11305. ((huffmanTableSpec >> 4) === 0 ?
  11306. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  11307. buildHuffmanTable(codeLengths, huffmanValues);
  11308. }
  11309. break;
  11310. case 0xFFDD: // DRI (Define Restart Interval)
  11311. readUint16(); // skip data length
  11312. resetInterval = readUint16();
  11313. break;
  11314. case 0xFFDA: // SOS (Start of Scan)
  11315. var scanLength = readUint16();
  11316. var selectorsCount = data[offset++];
  11317. var components = [], component;
  11318. for (i = 0; i < selectorsCount; i++) {
  11319. var componentIndex = frame.componentIds[data[offset++]];
  11320. component = frame.components[componentIndex];
  11321. var tableSpec = data[offset++];
  11322. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  11323. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  11324. components.push(component);
  11325. }
  11326. var spectralStart = data[offset++];
  11327. var spectralEnd = data[offset++];
  11328. var successiveApproximation = data[offset++];
  11329. var processed = decodeScan(data, offset,
  11330. frame, components, resetInterval,
  11331. spectralStart, spectralEnd,
  11332. successiveApproximation >> 4, successiveApproximation & 15);
  11333. offset += processed;
  11334. break;
  11335. case 0xFFFF: // Fill bytes
  11336. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  11337. offset--;
  11338. }
  11339. break;
  11340. default:
  11341. if (data[offset - 3] === 0xFF &&
  11342. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  11343. // could be incorrect encoding -- last 0xFF byte of the previous
  11344. // block was eaten by the encoder
  11345. offset -= 3;
  11346. break;
  11347. }
  11348. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  11349. }
  11350. fileMarker = readUint16();
  11351. }
  11352. this.width = frame.samplesPerLine;
  11353. this.height = frame.scanLines;
  11354. this.jfif = jfif;
  11355. this.adobe = adobe;
  11356. this.components = [];
  11357. for (i = 0; i < frame.components.length; i++) {
  11358. component = frame.components[i];
  11359. // Prevent errors when DQT markers are placed after SOF{n} markers,
  11360. // by assigning the `quantizationTable` entry after the entire image
  11361. // has been parsed (fixes issue7406.pdf).
  11362. var quantizationTable = quantizationTables[component.quantizationId];
  11363. if (quantizationTable) {
  11364. component.quantizationTable = quantizationTable;
  11365. }
  11366. this.components.push({
  11367. output: buildComponentData(frame, component),
  11368. scaleX: component.h / frame.maxH,
  11369. scaleY: component.v / frame.maxV,
  11370. blocksPerLine: component.blocksPerLine,
  11371. blocksPerColumn: component.blocksPerColumn
  11372. });
  11373. }
  11374. this.numComponents = this.components.length;
  11375. },
  11376. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  11377. var scaleX = this.width / width, scaleY = this.height / height;
  11378. var component, componentScaleX, componentScaleY, blocksPerScanline;
  11379. var x, y, i, j, k;
  11380. var index;
  11381. var offset = 0;
  11382. var output;
  11383. var numComponents = this.components.length;
  11384. var dataLength = width * height * numComponents;
  11385. var data = new Uint8Array(dataLength);
  11386. var xScaleBlockOffset = new Uint32Array(width);
  11387. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  11388. for (i = 0; i < numComponents; i++) {
  11389. component = this.components[i];
  11390. componentScaleX = component.scaleX * scaleX;
  11391. componentScaleY = component.scaleY * scaleY;
  11392. offset = i;
  11393. output = component.output;
  11394. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  11395. // precalculate the xScaleBlockOffset
  11396. for (x = 0; x < width; x++) {
  11397. j = 0 | (x * componentScaleX);
  11398. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  11399. }
  11400. // linearize the blocks of the component
  11401. for (y = 0; y < height; y++) {
  11402. j = 0 | (y * componentScaleY);
  11403. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  11404. for (x = 0; x < width; x++) {
  11405. data[offset] = output[index + xScaleBlockOffset[x]];
  11406. offset += numComponents;
  11407. }
  11408. }
  11409. }
  11410. // decodeTransform contains pairs of multiplier (-256..256) and additive
  11411. var transform = this.decodeTransform;
  11412. if (transform) {
  11413. for (i = 0; i < dataLength;) {
  11414. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  11415. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  11416. }
  11417. }
  11418. }
  11419. return data;
  11420. },
  11421. _isColorConversionNeeded: function isColorConversionNeeded() {
  11422. if (this.adobe && this.adobe.transformCode) {
  11423. // The adobe transform marker overrides any previous setting
  11424. return true;
  11425. } else if (this.numComponents === 3) {
  11426. return true;
  11427. } else {
  11428. return false;
  11429. }
  11430. },
  11431. _convertYccToRgb: function convertYccToRgb(data) {
  11432. var Y, Cb, Cr;
  11433. for (var i = 0, length = data.length; i < length; i += 3) {
  11434. Y = data[i ];
  11435. Cb = data[i + 1];
  11436. Cr = data[i + 2];
  11437. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  11438. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  11439. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  11440. }
  11441. return data;
  11442. },
  11443. _convertYcckToRgb: function convertYcckToRgb(data) {
  11444. var Y, Cb, Cr, k;
  11445. var offset = 0;
  11446. for (var i = 0, length = data.length; i < length; i += 4) {
  11447. Y = data[i];
  11448. Cb = data[i + 1];
  11449. Cr = data[i + 2];
  11450. k = data[i + 3];
  11451. var r = -122.67195406894 +
  11452. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  11453. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  11454. 0.154362151871126) +
  11455. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  11456. 0.00477271405408747 * k + 1.53380253221734) +
  11457. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  11458. 0.48357088451265) +
  11459. k * (-0.000336197177618394 * k + 0.484791561490776);
  11460. var g = 107.268039397724 +
  11461. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  11462. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  11463. 0.176491792462875) +
  11464. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  11465. 0.000770482631801132 * k - 0.151051492775562) +
  11466. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  11467. 0.25802910206845) +
  11468. k * (-0.000318913117588328 * k - 0.213742400323665);
  11469. var b = -20.810012546947 +
  11470. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  11471. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  11472. 0.814272968359295) +
  11473. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  11474. 0.000560833691242812 * k - 0.195152027534049) +
  11475. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  11476. 0.116935020465145) +
  11477. k * (-0.000343531996510555 * k + 0.24165260232407);
  11478. data[offset++] = clamp0to255(r);
  11479. data[offset++] = clamp0to255(g);
  11480. data[offset++] = clamp0to255(b);
  11481. }
  11482. return data;
  11483. },
  11484. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  11485. var Y, Cb, Cr;
  11486. for (var i = 0, length = data.length; i < length; i += 4) {
  11487. Y = data[i];
  11488. Cb = data[i + 1];
  11489. Cr = data[i + 2];
  11490. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  11491. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  11492. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  11493. // K in data[i + 3] is unchanged
  11494. }
  11495. return data;
  11496. },
  11497. _convertCmykToRgb: function convertCmykToRgb(data) {
  11498. var c, m, y, k;
  11499. var offset = 0;
  11500. var min = -255 * 255 * 255;
  11501. var scale = 1 / 255 / 255;
  11502. for (var i = 0, length = data.length; i < length; i += 4) {
  11503. c = data[i];
  11504. m = data[i + 1];
  11505. y = data[i + 2];
  11506. k = data[i + 3];
  11507. var r =
  11508. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11509. 18.82290502165302 * y + 212.25662451639585 * k -
  11510. 72734.4411664936) +
  11511. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  11512. 17.873870861415444 * k - 1401.7366389350734) +
  11513. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11514. 4465.541406466231) -
  11515. k * (21.86122147463605 * k + 48317.86113160301);
  11516. var g =
  11517. c * (8.841041422036149 * c + 60.118027045597366 * m +
  11518. 6.871425592049007 * y + 31.159100130055922 * k -
  11519. 20220.756542821975) +
  11520. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11521. 131.35250912493976 * k - 48691.05921601825) +
  11522. y * (4.444339102852739 * y + 9.8632861493405 * k -
  11523. 6341.191035517494) -
  11524. k * (20.737325471181034 * k + 47890.15695978492);
  11525. var b =
  11526. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11527. 30.89978309703729 * y - 0.23883238689178934 * k -
  11528. 3616.812083916688) +
  11529. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11530. 50.606957656360734 * k - 28620.90484698408) +
  11531. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  11532. 49363.43385999684) -
  11533. k * (22.33816807309886 * k + 45932.16563550634);
  11534. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  11535. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  11536. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  11537. }
  11538. return data;
  11539. },
  11540. getData: function getData(width, height, forceRGBoutput) {
  11541. if (this.numComponents > 4) {
  11542. error('JPEG error: Unsupported color mode');
  11543. }
  11544. // type of data: Uint8Array(width * height * numComponents)
  11545. var data = this._getLinearizedBlockData(width, height);
  11546. if (this.numComponents === 1 && forceRGBoutput) {
  11547. var dataLength = data.length;
  11548. var rgbData = new Uint8Array(dataLength * 3);
  11549. var offset = 0;
  11550. for (var i = 0; i < dataLength; i++) {
  11551. var grayColor = data[i];
  11552. rgbData[offset++] = grayColor;
  11553. rgbData[offset++] = grayColor;
  11554. rgbData[offset++] = grayColor;
  11555. }
  11556. return rgbData;
  11557. } else if (this.numComponents === 3) {
  11558. return this._convertYccToRgb(data);
  11559. } else if (this.numComponents === 4) {
  11560. if (this._isColorConversionNeeded()) {
  11561. if (forceRGBoutput) {
  11562. return this._convertYcckToRgb(data);
  11563. } else {
  11564. return this._convertYcckToCmyk(data);
  11565. }
  11566. } else if (forceRGBoutput) {
  11567. return this._convertCmykToRgb(data);
  11568. }
  11569. }
  11570. return data;
  11571. }
  11572. };
  11573. return constructor;
  11574. })();
  11575. exports.JpegImage = JpegImage;
  11576. }));
  11577. (function (root, factory) {
  11578. {
  11579. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11580. root.pdfjsCoreArithmeticDecoder);
  11581. }
  11582. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11583. var info = sharedUtil.info;
  11584. var warn = sharedUtil.warn;
  11585. var error = sharedUtil.error;
  11586. var log2 = sharedUtil.log2;
  11587. var readUint16 = sharedUtil.readUint16;
  11588. var readUint32 = sharedUtil.readUint32;
  11589. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11590. var JpxImage = (function JpxImageClosure() {
  11591. // Table E.1
  11592. var SubbandsGainLog2 = {
  11593. 'LL': 0,
  11594. 'LH': 1,
  11595. 'HL': 1,
  11596. 'HH': 2
  11597. };
  11598. function JpxImage() {
  11599. this.failOnCorruptedImage = false;
  11600. }
  11601. JpxImage.prototype = {
  11602. parse: function JpxImage_parse(data) {
  11603. var head = readUint16(data, 0);
  11604. // No box header, immediate start of codestream (SOC)
  11605. if (head === 0xFF4F) {
  11606. this.parseCodestream(data, 0, data.length);
  11607. return;
  11608. }
  11609. var position = 0, length = data.length;
  11610. while (position < length) {
  11611. var headerSize = 8;
  11612. var lbox = readUint32(data, position);
  11613. var tbox = readUint32(data, position + 4);
  11614. position += headerSize;
  11615. if (lbox === 1) {
  11616. // XLBox: read UInt64 according to spec.
  11617. // JavaScript's int precision of 53 bit should be sufficient here.
  11618. lbox = readUint32(data, position) * 4294967296 +
  11619. readUint32(data, position + 4);
  11620. position += 8;
  11621. headerSize += 8;
  11622. }
  11623. if (lbox === 0) {
  11624. lbox = length - position + headerSize;
  11625. }
  11626. if (lbox < headerSize) {
  11627. error('JPX Error: Invalid box field size');
  11628. }
  11629. var dataLength = lbox - headerSize;
  11630. var jumpDataLength = true;
  11631. switch (tbox) {
  11632. case 0x6A703268: // 'jp2h'
  11633. jumpDataLength = false; // parsing child boxes
  11634. break;
  11635. case 0x636F6C72: // 'colr'
  11636. // Colorspaces are not used, the CS from the PDF is used.
  11637. var method = data[position];
  11638. if (method === 1) {
  11639. // enumerated colorspace
  11640. var colorspace = readUint32(data, position + 3);
  11641. switch (colorspace) {
  11642. case 16: // this indicates a sRGB colorspace
  11643. case 17: // this indicates a grayscale colorspace
  11644. case 18: // this indicates a YUV colorspace
  11645. break;
  11646. default:
  11647. warn('Unknown colorspace ' + colorspace);
  11648. break;
  11649. }
  11650. } else if (method === 2) {
  11651. info('ICC profile not supported');
  11652. }
  11653. break;
  11654. case 0x6A703263: // 'jp2c'
  11655. this.parseCodestream(data, position, position + dataLength);
  11656. break;
  11657. case 0x6A502020: // 'jP\024\024'
  11658. if (0x0d0a870a !== readUint32(data, position)) {
  11659. warn('Invalid JP2 signature');
  11660. }
  11661. break;
  11662. // The following header types are valid but currently not used:
  11663. case 0x6A501A1A: // 'jP\032\032'
  11664. case 0x66747970: // 'ftyp'
  11665. case 0x72726571: // 'rreq'
  11666. case 0x72657320: // 'res '
  11667. case 0x69686472: // 'ihdr'
  11668. break;
  11669. default:
  11670. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11671. (tbox >> 16) & 0xFF,
  11672. (tbox >> 8) & 0xFF,
  11673. tbox & 0xFF);
  11674. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11675. break;
  11676. }
  11677. if (jumpDataLength) {
  11678. position += dataLength;
  11679. }
  11680. }
  11681. },
  11682. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11683. var newByte = stream.getByte();
  11684. while (newByte >= 0) {
  11685. var oldByte = newByte;
  11686. newByte = stream.getByte();
  11687. var code = (oldByte << 8) | newByte;
  11688. // Image and tile size (SIZ)
  11689. if (code === 0xFF51) {
  11690. stream.skip(4);
  11691. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11692. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11693. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11694. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11695. stream.skip(16);
  11696. var Csiz = stream.getUint16(); // Byte 36
  11697. this.width = Xsiz - XOsiz;
  11698. this.height = Ysiz - YOsiz;
  11699. this.componentsCount = Csiz;
  11700. // Results are always returned as Uint8Arrays
  11701. this.bitsPerComponent = 8;
  11702. return;
  11703. }
  11704. }
  11705. error('JPX Error: No size marker found in JPX stream');
  11706. },
  11707. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11708. var context = {};
  11709. var doNotRecover = false;
  11710. try {
  11711. var position = start;
  11712. while (position + 1 < end) {
  11713. var code = readUint16(data, position);
  11714. position += 2;
  11715. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11716. switch (code) {
  11717. case 0xFF4F: // Start of codestream (SOC)
  11718. context.mainHeader = true;
  11719. break;
  11720. case 0xFFD9: // End of codestream (EOC)
  11721. break;
  11722. case 0xFF51: // Image and tile size (SIZ)
  11723. length = readUint16(data, position);
  11724. var siz = {};
  11725. siz.Xsiz = readUint32(data, position + 4);
  11726. siz.Ysiz = readUint32(data, position + 8);
  11727. siz.XOsiz = readUint32(data, position + 12);
  11728. siz.YOsiz = readUint32(data, position + 16);
  11729. siz.XTsiz = readUint32(data, position + 20);
  11730. siz.YTsiz = readUint32(data, position + 24);
  11731. siz.XTOsiz = readUint32(data, position + 28);
  11732. siz.YTOsiz = readUint32(data, position + 32);
  11733. var componentsCount = readUint16(data, position + 36);
  11734. siz.Csiz = componentsCount;
  11735. var components = [];
  11736. j = position + 38;
  11737. for (var i = 0; i < componentsCount; i++) {
  11738. var component = {
  11739. precision: (data[j] & 0x7F) + 1,
  11740. isSigned: !!(data[j] & 0x80),
  11741. XRsiz: data[j + 1],
  11742. YRsiz: data[j + 1]
  11743. };
  11744. calculateComponentDimensions(component, siz);
  11745. components.push(component);
  11746. }
  11747. context.SIZ = siz;
  11748. context.components = components;
  11749. calculateTileGrids(context, components);
  11750. context.QCC = [];
  11751. context.COC = [];
  11752. break;
  11753. case 0xFF5C: // Quantization default (QCD)
  11754. length = readUint16(data, position);
  11755. var qcd = {};
  11756. j = position + 2;
  11757. sqcd = data[j++];
  11758. switch (sqcd & 0x1F) {
  11759. case 0:
  11760. spqcdSize = 8;
  11761. scalarExpounded = true;
  11762. break;
  11763. case 1:
  11764. spqcdSize = 16;
  11765. scalarExpounded = false;
  11766. break;
  11767. case 2:
  11768. spqcdSize = 16;
  11769. scalarExpounded = true;
  11770. break;
  11771. default:
  11772. throw new Error('Invalid SQcd value ' + sqcd);
  11773. }
  11774. qcd.noQuantization = (spqcdSize === 8);
  11775. qcd.scalarExpounded = scalarExpounded;
  11776. qcd.guardBits = sqcd >> 5;
  11777. spqcds = [];
  11778. while (j < length + position) {
  11779. var spqcd = {};
  11780. if (spqcdSize === 8) {
  11781. spqcd.epsilon = data[j++] >> 3;
  11782. spqcd.mu = 0;
  11783. } else {
  11784. spqcd.epsilon = data[j] >> 3;
  11785. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11786. j += 2;
  11787. }
  11788. spqcds.push(spqcd);
  11789. }
  11790. qcd.SPqcds = spqcds;
  11791. if (context.mainHeader) {
  11792. context.QCD = qcd;
  11793. } else {
  11794. context.currentTile.QCD = qcd;
  11795. context.currentTile.QCC = [];
  11796. }
  11797. break;
  11798. case 0xFF5D: // Quantization component (QCC)
  11799. length = readUint16(data, position);
  11800. var qcc = {};
  11801. j = position + 2;
  11802. var cqcc;
  11803. if (context.SIZ.Csiz < 257) {
  11804. cqcc = data[j++];
  11805. } else {
  11806. cqcc = readUint16(data, j);
  11807. j += 2;
  11808. }
  11809. sqcd = data[j++];
  11810. switch (sqcd & 0x1F) {
  11811. case 0:
  11812. spqcdSize = 8;
  11813. scalarExpounded = true;
  11814. break;
  11815. case 1:
  11816. spqcdSize = 16;
  11817. scalarExpounded = false;
  11818. break;
  11819. case 2:
  11820. spqcdSize = 16;
  11821. scalarExpounded = true;
  11822. break;
  11823. default:
  11824. throw new Error('Invalid SQcd value ' + sqcd);
  11825. }
  11826. qcc.noQuantization = (spqcdSize === 8);
  11827. qcc.scalarExpounded = scalarExpounded;
  11828. qcc.guardBits = sqcd >> 5;
  11829. spqcds = [];
  11830. while (j < (length + position)) {
  11831. spqcd = {};
  11832. if (spqcdSize === 8) {
  11833. spqcd.epsilon = data[j++] >> 3;
  11834. spqcd.mu = 0;
  11835. } else {
  11836. spqcd.epsilon = data[j] >> 3;
  11837. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11838. j += 2;
  11839. }
  11840. spqcds.push(spqcd);
  11841. }
  11842. qcc.SPqcds = spqcds;
  11843. if (context.mainHeader) {
  11844. context.QCC[cqcc] = qcc;
  11845. } else {
  11846. context.currentTile.QCC[cqcc] = qcc;
  11847. }
  11848. break;
  11849. case 0xFF52: // Coding style default (COD)
  11850. length = readUint16(data, position);
  11851. var cod = {};
  11852. j = position + 2;
  11853. var scod = data[j++];
  11854. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11855. cod.sopMarkerUsed = !!(scod & 2);
  11856. cod.ephMarkerUsed = !!(scod & 4);
  11857. cod.progressionOrder = data[j++];
  11858. cod.layersCount = readUint16(data, j);
  11859. j += 2;
  11860. cod.multipleComponentTransform = data[j++];
  11861. cod.decompositionLevelsCount = data[j++];
  11862. cod.xcb = (data[j++] & 0xF) + 2;
  11863. cod.ycb = (data[j++] & 0xF) + 2;
  11864. var blockStyle = data[j++];
  11865. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  11866. cod.resetContextProbabilities = !!(blockStyle & 2);
  11867. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  11868. cod.verticalyStripe = !!(blockStyle & 8);
  11869. cod.predictableTermination = !!(blockStyle & 16);
  11870. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  11871. cod.reversibleTransformation = data[j++];
  11872. if (cod.entropyCoderWithCustomPrecincts) {
  11873. var precinctsSizes = [];
  11874. while (j < length + position) {
  11875. var precinctsSize = data[j++];
  11876. precinctsSizes.push({
  11877. PPx: precinctsSize & 0xF,
  11878. PPy: precinctsSize >> 4
  11879. });
  11880. }
  11881. cod.precinctsSizes = precinctsSizes;
  11882. }
  11883. var unsupported = [];
  11884. if (cod.selectiveArithmeticCodingBypass) {
  11885. unsupported.push('selectiveArithmeticCodingBypass');
  11886. }
  11887. if (cod.resetContextProbabilities) {
  11888. unsupported.push('resetContextProbabilities');
  11889. }
  11890. if (cod.terminationOnEachCodingPass) {
  11891. unsupported.push('terminationOnEachCodingPass');
  11892. }
  11893. if (cod.verticalyStripe) {
  11894. unsupported.push('verticalyStripe');
  11895. }
  11896. if (cod.predictableTermination) {
  11897. unsupported.push('predictableTermination');
  11898. }
  11899. if (unsupported.length > 0) {
  11900. doNotRecover = true;
  11901. throw new Error('Unsupported COD options (' +
  11902. unsupported.join(', ') + ')');
  11903. }
  11904. if (context.mainHeader) {
  11905. context.COD = cod;
  11906. } else {
  11907. context.currentTile.COD = cod;
  11908. context.currentTile.COC = [];
  11909. }
  11910. break;
  11911. case 0xFF90: // Start of tile-part (SOT)
  11912. length = readUint16(data, position);
  11913. tile = {};
  11914. tile.index = readUint16(data, position + 2);
  11915. tile.length = readUint32(data, position + 4);
  11916. tile.dataEnd = tile.length + position - 2;
  11917. tile.partIndex = data[position + 8];
  11918. tile.partsCount = data[position + 9];
  11919. context.mainHeader = false;
  11920. if (tile.partIndex === 0) {
  11921. // reset component specific settings
  11922. tile.COD = context.COD;
  11923. tile.COC = context.COC.slice(0); // clone of the global COC
  11924. tile.QCD = context.QCD;
  11925. tile.QCC = context.QCC.slice(0); // clone of the global COC
  11926. }
  11927. context.currentTile = tile;
  11928. break;
  11929. case 0xFF93: // Start of data (SOD)
  11930. tile = context.currentTile;
  11931. if (tile.partIndex === 0) {
  11932. initializeTile(context, tile.index);
  11933. buildPackets(context);
  11934. }
  11935. // moving to the end of the data
  11936. length = tile.dataEnd - position;
  11937. parseTilePackets(context, data, position, length);
  11938. break;
  11939. case 0xFF55: // Tile-part lengths, main header (TLM)
  11940. case 0xFF57: // Packet length, main header (PLM)
  11941. case 0xFF58: // Packet length, tile-part header (PLT)
  11942. case 0xFF64: // Comment (COM)
  11943. length = readUint16(data, position);
  11944. // skipping content
  11945. break;
  11946. case 0xFF53: // Coding style component (COC)
  11947. throw new Error('Codestream code 0xFF53 (COC) is ' +
  11948. 'not implemented');
  11949. default:
  11950. throw new Error('Unknown codestream code: ' + code.toString(16));
  11951. }
  11952. position += length;
  11953. }
  11954. } catch (e) {
  11955. if (doNotRecover || this.failOnCorruptedImage) {
  11956. error('JPX Error: ' + e.message);
  11957. } else {
  11958. warn('JPX: Trying to recover from: ' + e.message);
  11959. }
  11960. }
  11961. this.tiles = transformComponents(context);
  11962. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  11963. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  11964. this.componentsCount = context.SIZ.Csiz;
  11965. }
  11966. };
  11967. function calculateComponentDimensions(component, siz) {
  11968. // Section B.2 Component mapping
  11969. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  11970. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  11971. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  11972. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  11973. component.width = component.x1 - component.x0;
  11974. component.height = component.y1 - component.y0;
  11975. }
  11976. function calculateTileGrids(context, components) {
  11977. var siz = context.SIZ;
  11978. // Section B.3 Division into tile and tile-components
  11979. var tile, tiles = [];
  11980. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  11981. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  11982. for (var q = 0; q < numYtiles; q++) {
  11983. for (var p = 0; p < numXtiles; p++) {
  11984. tile = {};
  11985. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  11986. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  11987. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  11988. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  11989. tile.width = tile.tx1 - tile.tx0;
  11990. tile.height = tile.ty1 - tile.ty0;
  11991. tile.components = [];
  11992. tiles.push(tile);
  11993. }
  11994. }
  11995. context.tiles = tiles;
  11996. var componentsCount = siz.Csiz;
  11997. for (var i = 0, ii = componentsCount; i < ii; i++) {
  11998. var component = components[i];
  11999. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12000. var tileComponent = {};
  12001. tile = tiles[j];
  12002. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12003. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12004. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12005. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12006. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12007. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12008. tile.components[i] = tileComponent;
  12009. }
  12010. }
  12011. }
  12012. function getBlocksDimensions(context, component, r) {
  12013. var codOrCoc = component.codingStyleParameters;
  12014. var result = {};
  12015. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12016. result.PPx = 15;
  12017. result.PPy = 15;
  12018. } else {
  12019. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12020. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12021. }
  12022. // calculate codeblock size as described in section B.7
  12023. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12024. Math.min(codOrCoc.xcb, result.PPx));
  12025. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12026. Math.min(codOrCoc.ycb, result.PPy));
  12027. return result;
  12028. }
  12029. function buildPrecincts(context, resolution, dimensions) {
  12030. // Section B.6 Division resolution to precincts
  12031. var precinctWidth = 1 << dimensions.PPx;
  12032. var precinctHeight = 1 << dimensions.PPy;
  12033. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12034. // to precincts. Precinct partition divides a resolution according to width
  12035. // and height parameters. The subband that belongs to the resolution level
  12036. // has a different size than the level, unless it is the zero resolution.
  12037. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12038. // The precinct partitioning for a particular subband is derived from a
  12039. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12040. // resolution level)... The LL band associated with each resolution level is
  12041. // divided into precincts... Each of the resulting precinct regions is then
  12042. // mapped into its child subbands (if any) at the next lower resolution
  12043. // level. This is accomplished by using the coordinate transformation
  12044. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12045. // coordinates of a point in the LL band and child subband, respectively.
  12046. var isZeroRes = resolution.resLevel === 0;
  12047. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12048. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12049. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12050. Math.ceil(resolution.trx1 / precinctWidth) -
  12051. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12052. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12053. Math.ceil(resolution.try1 / precinctHeight) -
  12054. Math.floor(resolution.try0 / precinctHeight) : 0);
  12055. var numprecincts = numprecinctswide * numprecinctshigh;
  12056. resolution.precinctParameters = {
  12057. precinctWidth: precinctWidth,
  12058. precinctHeight: precinctHeight,
  12059. numprecinctswide: numprecinctswide,
  12060. numprecinctshigh: numprecinctshigh,
  12061. numprecincts: numprecincts,
  12062. precinctWidthInSubband: precinctWidthInSubband,
  12063. precinctHeightInSubband: precinctHeightInSubband
  12064. };
  12065. }
  12066. function buildCodeblocks(context, subband, dimensions) {
  12067. // Section B.7 Division sub-band into code-blocks
  12068. var xcb_ = dimensions.xcb_;
  12069. var ycb_ = dimensions.ycb_;
  12070. var codeblockWidth = 1 << xcb_;
  12071. var codeblockHeight = 1 << ycb_;
  12072. var cbx0 = subband.tbx0 >> xcb_;
  12073. var cby0 = subband.tby0 >> ycb_;
  12074. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12075. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12076. var precinctParameters = subband.resolution.precinctParameters;
  12077. var codeblocks = [];
  12078. var precincts = [];
  12079. var i, j, codeblock, precinctNumber;
  12080. for (j = cby0; j < cby1; j++) {
  12081. for (i = cbx0; i < cbx1; i++) {
  12082. codeblock = {
  12083. cbx: i,
  12084. cby: j,
  12085. tbx0: codeblockWidth * i,
  12086. tby0: codeblockHeight * j,
  12087. tbx1: codeblockWidth * (i + 1),
  12088. tby1: codeblockHeight * (j + 1)
  12089. };
  12090. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12091. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12092. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12093. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12094. // Calculate precinct number for this codeblock, codeblock position
  12095. // should be relative to its subband, use actual dimension and position
  12096. // See comment about codeblock group width and height
  12097. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12098. precinctParameters.precinctWidthInSubband);
  12099. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12100. precinctParameters.precinctHeightInSubband);
  12101. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12102. codeblock.precinctNumber = precinctNumber;
  12103. codeblock.subbandType = subband.type;
  12104. codeblock.Lblock = 3;
  12105. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12106. codeblock.tby1_ <= codeblock.tby0_) {
  12107. continue;
  12108. }
  12109. codeblocks.push(codeblock);
  12110. // building precinct for the sub-band
  12111. var precinct = precincts[precinctNumber];
  12112. if (precinct !== undefined) {
  12113. if (i < precinct.cbxMin) {
  12114. precinct.cbxMin = i;
  12115. } else if (i > precinct.cbxMax) {
  12116. precinct.cbxMax = i;
  12117. }
  12118. if (j < precinct.cbyMin) {
  12119. precinct.cbxMin = j;
  12120. } else if (j > precinct.cbyMax) {
  12121. precinct.cbyMax = j;
  12122. }
  12123. } else {
  12124. precincts[precinctNumber] = precinct = {
  12125. cbxMin: i,
  12126. cbyMin: j,
  12127. cbxMax: i,
  12128. cbyMax: j
  12129. };
  12130. }
  12131. codeblock.precinct = precinct;
  12132. }
  12133. }
  12134. subband.codeblockParameters = {
  12135. codeblockWidth: xcb_,
  12136. codeblockHeight: ycb_,
  12137. numcodeblockwide: cbx1 - cbx0 + 1,
  12138. numcodeblockhigh: cby1 - cby0 + 1
  12139. };
  12140. subband.codeblocks = codeblocks;
  12141. subband.precincts = precincts;
  12142. }
  12143. function createPacket(resolution, precinctNumber, layerNumber) {
  12144. var precinctCodeblocks = [];
  12145. // Section B.10.8 Order of info in packet
  12146. var subbands = resolution.subbands;
  12147. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12148. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12149. var subband = subbands[i];
  12150. var codeblocks = subband.codeblocks;
  12151. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12152. var codeblock = codeblocks[j];
  12153. if (codeblock.precinctNumber !== precinctNumber) {
  12154. continue;
  12155. }
  12156. precinctCodeblocks.push(codeblock);
  12157. }
  12158. }
  12159. return {
  12160. layerNumber: layerNumber,
  12161. codeblocks: precinctCodeblocks
  12162. };
  12163. }
  12164. function LayerResolutionComponentPositionIterator(context) {
  12165. var siz = context.SIZ;
  12166. var tileIndex = context.currentTile.index;
  12167. var tile = context.tiles[tileIndex];
  12168. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12169. var componentsCount = siz.Csiz;
  12170. var maxDecompositionLevelsCount = 0;
  12171. for (var q = 0; q < componentsCount; q++) {
  12172. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12173. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12174. }
  12175. var l = 0, r = 0, i = 0, k = 0;
  12176. this.nextPacket = function JpxImage_nextPacket() {
  12177. // Section B.12.1.1 Layer-resolution-component-position
  12178. for (; l < layersCount; l++) {
  12179. for (; r <= maxDecompositionLevelsCount; r++) {
  12180. for (; i < componentsCount; i++) {
  12181. var component = tile.components[i];
  12182. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12183. continue;
  12184. }
  12185. var resolution = component.resolutions[r];
  12186. var numprecincts = resolution.precinctParameters.numprecincts;
  12187. for (; k < numprecincts;) {
  12188. var packet = createPacket(resolution, k, l);
  12189. k++;
  12190. return packet;
  12191. }
  12192. k = 0;
  12193. }
  12194. i = 0;
  12195. }
  12196. r = 0;
  12197. }
  12198. error('JPX Error: Out of packets');
  12199. };
  12200. }
  12201. function ResolutionLayerComponentPositionIterator(context) {
  12202. var siz = context.SIZ;
  12203. var tileIndex = context.currentTile.index;
  12204. var tile = context.tiles[tileIndex];
  12205. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12206. var componentsCount = siz.Csiz;
  12207. var maxDecompositionLevelsCount = 0;
  12208. for (var q = 0; q < componentsCount; q++) {
  12209. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12210. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12211. }
  12212. var r = 0, l = 0, i = 0, k = 0;
  12213. this.nextPacket = function JpxImage_nextPacket() {
  12214. // Section B.12.1.2 Resolution-layer-component-position
  12215. for (; r <= maxDecompositionLevelsCount; r++) {
  12216. for (; l < layersCount; l++) {
  12217. for (; i < componentsCount; i++) {
  12218. var component = tile.components[i];
  12219. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12220. continue;
  12221. }
  12222. var resolution = component.resolutions[r];
  12223. var numprecincts = resolution.precinctParameters.numprecincts;
  12224. for (; k < numprecincts;) {
  12225. var packet = createPacket(resolution, k, l);
  12226. k++;
  12227. return packet;
  12228. }
  12229. k = 0;
  12230. }
  12231. i = 0;
  12232. }
  12233. l = 0;
  12234. }
  12235. error('JPX Error: Out of packets');
  12236. };
  12237. }
  12238. function ResolutionPositionComponentLayerIterator(context) {
  12239. var siz = context.SIZ;
  12240. var tileIndex = context.currentTile.index;
  12241. var tile = context.tiles[tileIndex];
  12242. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12243. var componentsCount = siz.Csiz;
  12244. var l, r, c, p;
  12245. var maxDecompositionLevelsCount = 0;
  12246. for (c = 0; c < componentsCount; c++) {
  12247. var component = tile.components[c];
  12248. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12249. component.codingStyleParameters.decompositionLevelsCount);
  12250. }
  12251. var maxNumPrecinctsInLevel = new Int32Array(
  12252. maxDecompositionLevelsCount + 1);
  12253. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12254. var maxNumPrecincts = 0;
  12255. for (c = 0; c < componentsCount; ++c) {
  12256. var resolutions = tile.components[c].resolutions;
  12257. if (r < resolutions.length) {
  12258. maxNumPrecincts = Math.max(maxNumPrecincts,
  12259. resolutions[r].precinctParameters.numprecincts);
  12260. }
  12261. }
  12262. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12263. }
  12264. l = 0;
  12265. r = 0;
  12266. c = 0;
  12267. p = 0;
  12268. this.nextPacket = function JpxImage_nextPacket() {
  12269. // Section B.12.1.3 Resolution-position-component-layer
  12270. for (; r <= maxDecompositionLevelsCount; r++) {
  12271. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12272. for (; c < componentsCount; c++) {
  12273. var component = tile.components[c];
  12274. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12275. continue;
  12276. }
  12277. var resolution = component.resolutions[r];
  12278. var numprecincts = resolution.precinctParameters.numprecincts;
  12279. if (p >= numprecincts) {
  12280. continue;
  12281. }
  12282. for (; l < layersCount;) {
  12283. var packet = createPacket(resolution, p, l);
  12284. l++;
  12285. return packet;
  12286. }
  12287. l = 0;
  12288. }
  12289. c = 0;
  12290. }
  12291. p = 0;
  12292. }
  12293. error('JPX Error: Out of packets');
  12294. };
  12295. }
  12296. function PositionComponentResolutionLayerIterator(context) {
  12297. var siz = context.SIZ;
  12298. var tileIndex = context.currentTile.index;
  12299. var tile = context.tiles[tileIndex];
  12300. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12301. var componentsCount = siz.Csiz;
  12302. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12303. var precinctsIterationSizes = precinctsSizes;
  12304. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12305. this.nextPacket = function JpxImage_nextPacket() {
  12306. // Section B.12.1.4 Position-component-resolution-layer
  12307. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12308. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12309. for (; c < componentsCount; c++) {
  12310. var component = tile.components[c];
  12311. var decompositionLevelsCount =
  12312. component.codingStyleParameters.decompositionLevelsCount;
  12313. for (; r <= decompositionLevelsCount; r++) {
  12314. var resolution = component.resolutions[r];
  12315. var sizeInImageScale =
  12316. precinctsSizes.components[c].resolutions[r];
  12317. var k = getPrecinctIndexIfExist(
  12318. px,
  12319. py,
  12320. sizeInImageScale,
  12321. precinctsIterationSizes,
  12322. resolution);
  12323. if (k === null) {
  12324. continue;
  12325. }
  12326. for (; l < layersCount;) {
  12327. var packet = createPacket(resolution, k, l);
  12328. l++;
  12329. return packet;
  12330. }
  12331. l = 0;
  12332. }
  12333. r = 0;
  12334. }
  12335. c = 0;
  12336. }
  12337. px = 0;
  12338. }
  12339. error('JPX Error: Out of packets');
  12340. };
  12341. }
  12342. function ComponentPositionResolutionLayerIterator(context) {
  12343. var siz = context.SIZ;
  12344. var tileIndex = context.currentTile.index;
  12345. var tile = context.tiles[tileIndex];
  12346. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12347. var componentsCount = siz.Csiz;
  12348. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12349. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12350. this.nextPacket = function JpxImage_nextPacket() {
  12351. // Section B.12.1.5 Component-position-resolution-layer
  12352. for (; c < componentsCount; ++c) {
  12353. var component = tile.components[c];
  12354. var precinctsIterationSizes = precinctsSizes.components[c];
  12355. var decompositionLevelsCount =
  12356. component.codingStyleParameters.decompositionLevelsCount;
  12357. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12358. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12359. for (; r <= decompositionLevelsCount; r++) {
  12360. var resolution = component.resolutions[r];
  12361. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12362. var k = getPrecinctIndexIfExist(
  12363. px,
  12364. py,
  12365. sizeInImageScale,
  12366. precinctsIterationSizes,
  12367. resolution);
  12368. if (k === null) {
  12369. continue;
  12370. }
  12371. for (; l < layersCount;) {
  12372. var packet = createPacket(resolution, k, l);
  12373. l++;
  12374. return packet;
  12375. }
  12376. l = 0;
  12377. }
  12378. r = 0;
  12379. }
  12380. px = 0;
  12381. }
  12382. py = 0;
  12383. }
  12384. error('JPX Error: Out of packets');
  12385. };
  12386. }
  12387. function getPrecinctIndexIfExist(
  12388. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12389. var posX = pxIndex * precinctIterationSizes.minWidth;
  12390. var posY = pyIndex * precinctIterationSizes.minHeight;
  12391. if (posX % sizeInImageScale.width !== 0 ||
  12392. posY % sizeInImageScale.height !== 0) {
  12393. return null;
  12394. }
  12395. var startPrecinctRowIndex =
  12396. (posY / sizeInImageScale.width) *
  12397. resolution.precinctParameters.numprecinctswide;
  12398. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12399. }
  12400. function getPrecinctSizesInImageScale(tile) {
  12401. var componentsCount = tile.components.length;
  12402. var minWidth = Number.MAX_VALUE;
  12403. var minHeight = Number.MAX_VALUE;
  12404. var maxNumWide = 0;
  12405. var maxNumHigh = 0;
  12406. var sizePerComponent = new Array(componentsCount);
  12407. for (var c = 0; c < componentsCount; c++) {
  12408. var component = tile.components[c];
  12409. var decompositionLevelsCount =
  12410. component.codingStyleParameters.decompositionLevelsCount;
  12411. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12412. var minWidthCurrentComponent = Number.MAX_VALUE;
  12413. var minHeightCurrentComponent = Number.MAX_VALUE;
  12414. var maxNumWideCurrentComponent = 0;
  12415. var maxNumHighCurrentComponent = 0;
  12416. var scale = 1;
  12417. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12418. var resolution = component.resolutions[r];
  12419. var widthCurrentResolution =
  12420. scale * resolution.precinctParameters.precinctWidth;
  12421. var heightCurrentResolution =
  12422. scale * resolution.precinctParameters.precinctHeight;
  12423. minWidthCurrentComponent = Math.min(
  12424. minWidthCurrentComponent,
  12425. widthCurrentResolution);
  12426. minHeightCurrentComponent = Math.min(
  12427. minHeightCurrentComponent,
  12428. heightCurrentResolution);
  12429. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12430. resolution.precinctParameters.numprecinctswide);
  12431. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12432. resolution.precinctParameters.numprecinctshigh);
  12433. sizePerResolution[r] = {
  12434. width: widthCurrentResolution,
  12435. height: heightCurrentResolution
  12436. };
  12437. scale <<= 1;
  12438. }
  12439. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12440. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12441. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12442. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12443. sizePerComponent[c] = {
  12444. resolutions: sizePerResolution,
  12445. minWidth: minWidthCurrentComponent,
  12446. minHeight: minHeightCurrentComponent,
  12447. maxNumWide: maxNumWideCurrentComponent,
  12448. maxNumHigh: maxNumHighCurrentComponent
  12449. };
  12450. }
  12451. return {
  12452. components: sizePerComponent,
  12453. minWidth: minWidth,
  12454. minHeight: minHeight,
  12455. maxNumWide: maxNumWide,
  12456. maxNumHigh: maxNumHigh
  12457. };
  12458. }
  12459. function buildPackets(context) {
  12460. var siz = context.SIZ;
  12461. var tileIndex = context.currentTile.index;
  12462. var tile = context.tiles[tileIndex];
  12463. var componentsCount = siz.Csiz;
  12464. // Creating resolutions and sub-bands for each component
  12465. for (var c = 0; c < componentsCount; c++) {
  12466. var component = tile.components[c];
  12467. var decompositionLevelsCount =
  12468. component.codingStyleParameters.decompositionLevelsCount;
  12469. // Section B.5 Resolution levels and sub-bands
  12470. var resolutions = [];
  12471. var subbands = [];
  12472. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12473. var blocksDimensions = getBlocksDimensions(context, component, r);
  12474. var resolution = {};
  12475. var scale = 1 << (decompositionLevelsCount - r);
  12476. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12477. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12478. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12479. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12480. resolution.resLevel = r;
  12481. buildPrecincts(context, resolution, blocksDimensions);
  12482. resolutions.push(resolution);
  12483. var subband;
  12484. if (r === 0) {
  12485. // one sub-band (LL) with last decomposition
  12486. subband = {};
  12487. subband.type = 'LL';
  12488. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12489. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12490. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12491. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12492. subband.resolution = resolution;
  12493. buildCodeblocks(context, subband, blocksDimensions);
  12494. subbands.push(subband);
  12495. resolution.subbands = [subband];
  12496. } else {
  12497. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12498. var resolutionSubbands = [];
  12499. // three sub-bands (HL, LH and HH) with rest of decompositions
  12500. subband = {};
  12501. subband.type = 'HL';
  12502. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12503. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12504. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12505. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12506. subband.resolution = resolution;
  12507. buildCodeblocks(context, subband, blocksDimensions);
  12508. subbands.push(subband);
  12509. resolutionSubbands.push(subband);
  12510. subband = {};
  12511. subband.type = 'LH';
  12512. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12513. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12514. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12515. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12516. subband.resolution = resolution;
  12517. buildCodeblocks(context, subband, blocksDimensions);
  12518. subbands.push(subband);
  12519. resolutionSubbands.push(subband);
  12520. subband = {};
  12521. subband.type = 'HH';
  12522. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12523. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12524. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12525. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12526. subband.resolution = resolution;
  12527. buildCodeblocks(context, subband, blocksDimensions);
  12528. subbands.push(subband);
  12529. resolutionSubbands.push(subband);
  12530. resolution.subbands = resolutionSubbands;
  12531. }
  12532. }
  12533. component.resolutions = resolutions;
  12534. component.subbands = subbands;
  12535. }
  12536. // Generate the packets sequence
  12537. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12538. switch (progressionOrder) {
  12539. case 0:
  12540. tile.packetsIterator =
  12541. new LayerResolutionComponentPositionIterator(context);
  12542. break;
  12543. case 1:
  12544. tile.packetsIterator =
  12545. new ResolutionLayerComponentPositionIterator(context);
  12546. break;
  12547. case 2:
  12548. tile.packetsIterator =
  12549. new ResolutionPositionComponentLayerIterator(context);
  12550. break;
  12551. case 3:
  12552. tile.packetsIterator =
  12553. new PositionComponentResolutionLayerIterator(context);
  12554. break;
  12555. case 4:
  12556. tile.packetsIterator =
  12557. new ComponentPositionResolutionLayerIterator(context);
  12558. break;
  12559. default:
  12560. error('JPX Error: Unsupported progression order ' + progressionOrder);
  12561. }
  12562. }
  12563. function parseTilePackets(context, data, offset, dataLength) {
  12564. var position = 0;
  12565. var buffer, bufferSize = 0, skipNextBit = false;
  12566. function readBits(count) {
  12567. while (bufferSize < count) {
  12568. var b = data[offset + position];
  12569. position++;
  12570. if (skipNextBit) {
  12571. buffer = (buffer << 7) | b;
  12572. bufferSize += 7;
  12573. skipNextBit = false;
  12574. } else {
  12575. buffer = (buffer << 8) | b;
  12576. bufferSize += 8;
  12577. }
  12578. if (b === 0xFF) {
  12579. skipNextBit = true;
  12580. }
  12581. }
  12582. bufferSize -= count;
  12583. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12584. }
  12585. function skipMarkerIfEqual(value) {
  12586. if (data[offset + position - 1] === 0xFF &&
  12587. data[offset + position] === value) {
  12588. skipBytes(1);
  12589. return true;
  12590. } else if (data[offset + position] === 0xFF &&
  12591. data[offset + position + 1] === value) {
  12592. skipBytes(2);
  12593. return true;
  12594. }
  12595. return false;
  12596. }
  12597. function skipBytes(count) {
  12598. position += count;
  12599. }
  12600. function alignToByte() {
  12601. bufferSize = 0;
  12602. if (skipNextBit) {
  12603. position++;
  12604. skipNextBit = false;
  12605. }
  12606. }
  12607. function readCodingpasses() {
  12608. if (readBits(1) === 0) {
  12609. return 1;
  12610. }
  12611. if (readBits(1) === 0) {
  12612. return 2;
  12613. }
  12614. var value = readBits(2);
  12615. if (value < 3) {
  12616. return value + 3;
  12617. }
  12618. value = readBits(5);
  12619. if (value < 31) {
  12620. return value + 6;
  12621. }
  12622. value = readBits(7);
  12623. return value + 37;
  12624. }
  12625. var tileIndex = context.currentTile.index;
  12626. var tile = context.tiles[tileIndex];
  12627. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12628. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12629. var packetsIterator = tile.packetsIterator;
  12630. while (position < dataLength) {
  12631. alignToByte();
  12632. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12633. // Skip also marker segment length and packet sequence ID
  12634. skipBytes(4);
  12635. }
  12636. var packet = packetsIterator.nextPacket();
  12637. if (!readBits(1)) {
  12638. continue;
  12639. }
  12640. var layerNumber = packet.layerNumber;
  12641. var queue = [], codeblock;
  12642. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12643. codeblock = packet.codeblocks[i];
  12644. var precinct = codeblock.precinct;
  12645. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12646. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12647. var codeblockIncluded = false;
  12648. var firstTimeInclusion = false;
  12649. var valueReady;
  12650. if (codeblock['included'] !== undefined) {
  12651. codeblockIncluded = !!readBits(1);
  12652. } else {
  12653. // reading inclusion tree
  12654. precinct = codeblock.precinct;
  12655. var inclusionTree, zeroBitPlanesTree;
  12656. if (precinct['inclusionTree'] !== undefined) {
  12657. inclusionTree = precinct.inclusionTree;
  12658. } else {
  12659. // building inclusion and zero bit-planes trees
  12660. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12661. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12662. inclusionTree = new InclusionTree(width, height, layerNumber);
  12663. zeroBitPlanesTree = new TagTree(width, height);
  12664. precinct.inclusionTree = inclusionTree;
  12665. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12666. }
  12667. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12668. while (true) {
  12669. if (readBits(1)) {
  12670. valueReady = !inclusionTree.nextLevel();
  12671. if (valueReady) {
  12672. codeblock.included = true;
  12673. codeblockIncluded = firstTimeInclusion = true;
  12674. break;
  12675. }
  12676. } else {
  12677. inclusionTree.incrementValue(layerNumber);
  12678. break;
  12679. }
  12680. }
  12681. }
  12682. }
  12683. if (!codeblockIncluded) {
  12684. continue;
  12685. }
  12686. if (firstTimeInclusion) {
  12687. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12688. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12689. while (true) {
  12690. if (readBits(1)) {
  12691. valueReady = !zeroBitPlanesTree.nextLevel();
  12692. if (valueReady) {
  12693. break;
  12694. }
  12695. } else {
  12696. zeroBitPlanesTree.incrementValue();
  12697. }
  12698. }
  12699. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12700. }
  12701. var codingpasses = readCodingpasses();
  12702. while (readBits(1)) {
  12703. codeblock.Lblock++;
  12704. }
  12705. var codingpassesLog2 = log2(codingpasses);
  12706. // rounding down log2
  12707. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12708. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12709. var codedDataLength = readBits(bits);
  12710. queue.push({
  12711. codeblock: codeblock,
  12712. codingpasses: codingpasses,
  12713. dataLength: codedDataLength
  12714. });
  12715. }
  12716. alignToByte();
  12717. if (ephMarkerUsed) {
  12718. skipMarkerIfEqual(0x92);
  12719. }
  12720. while (queue.length > 0) {
  12721. var packetItem = queue.shift();
  12722. codeblock = packetItem.codeblock;
  12723. if (codeblock['data'] === undefined) {
  12724. codeblock.data = [];
  12725. }
  12726. codeblock.data.push({
  12727. data: data,
  12728. start: offset + position,
  12729. end: offset + position + packetItem.dataLength,
  12730. codingpasses: packetItem.codingpasses
  12731. });
  12732. position += packetItem.dataLength;
  12733. }
  12734. }
  12735. return position;
  12736. }
  12737. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12738. delta, mb, reversible, segmentationSymbolUsed) {
  12739. var x0 = subband.tbx0;
  12740. var y0 = subband.tby0;
  12741. var width = subband.tbx1 - subband.tbx0;
  12742. var codeblocks = subband.codeblocks;
  12743. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12744. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12745. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12746. var codeblock = codeblocks[i];
  12747. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12748. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12749. if (blockWidth === 0 || blockHeight === 0) {
  12750. continue;
  12751. }
  12752. if (codeblock['data'] === undefined) {
  12753. continue;
  12754. }
  12755. var bitModel, currentCodingpassType;
  12756. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12757. codeblock.zeroBitPlanes, mb);
  12758. currentCodingpassType = 2; // first bit plane starts from cleanup
  12759. // collect data
  12760. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12761. var j, jj, dataItem;
  12762. for (j = 0, jj = data.length; j < jj; j++) {
  12763. dataItem = data[j];
  12764. totalLength += dataItem.end - dataItem.start;
  12765. codingpasses += dataItem.codingpasses;
  12766. }
  12767. var encodedData = new Uint8Array(totalLength);
  12768. var position = 0;
  12769. for (j = 0, jj = data.length; j < jj; j++) {
  12770. dataItem = data[j];
  12771. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12772. encodedData.set(chunk, position);
  12773. position += chunk.length;
  12774. }
  12775. // decoding the item
  12776. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12777. bitModel.setDecoder(decoder);
  12778. for (j = 0; j < codingpasses; j++) {
  12779. switch (currentCodingpassType) {
  12780. case 0:
  12781. bitModel.runSignificancePropagationPass();
  12782. break;
  12783. case 1:
  12784. bitModel.runMagnitudeRefinementPass();
  12785. break;
  12786. case 2:
  12787. bitModel.runCleanupPass();
  12788. if (segmentationSymbolUsed) {
  12789. bitModel.checkSegmentationSymbol();
  12790. }
  12791. break;
  12792. }
  12793. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12794. }
  12795. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12796. var sign = bitModel.coefficentsSign;
  12797. var magnitude = bitModel.coefficentsMagnitude;
  12798. var bitsDecoded = bitModel.bitsDecoded;
  12799. var magnitudeCorrection = reversible ? 0 : 0.5;
  12800. var k, n, nb;
  12801. position = 0;
  12802. // Do the interleaving of Section F.3.3 here, so we do not need
  12803. // to copy later. LL level is not interleaved, just copied.
  12804. var interleave = (subband.type !== 'LL');
  12805. for (j = 0; j < blockHeight; j++) {
  12806. var row = (offset / width) | 0; // row in the non-interleaved subband
  12807. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12808. for (k = 0; k < blockWidth; k++) {
  12809. n = magnitude[position];
  12810. if (n !== 0) {
  12811. n = (n + magnitudeCorrection) * delta;
  12812. if (sign[position] !== 0) {
  12813. n = -n;
  12814. }
  12815. nb = bitsDecoded[position];
  12816. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12817. if (reversible && (nb >= mb)) {
  12818. coefficients[pos] = n;
  12819. } else {
  12820. coefficients[pos] = n * (1 << (mb - nb));
  12821. }
  12822. }
  12823. offset++;
  12824. position++;
  12825. }
  12826. offset += width - blockWidth;
  12827. }
  12828. }
  12829. }
  12830. function transformTile(context, tile, c) {
  12831. var component = tile.components[c];
  12832. var codingStyleParameters = component.codingStyleParameters;
  12833. var quantizationParameters = component.quantizationParameters;
  12834. var decompositionLevelsCount =
  12835. codingStyleParameters.decompositionLevelsCount;
  12836. var spqcds = quantizationParameters.SPqcds;
  12837. var scalarExpounded = quantizationParameters.scalarExpounded;
  12838. var guardBits = quantizationParameters.guardBits;
  12839. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12840. var precision = context.components[c].precision;
  12841. var reversible = codingStyleParameters.reversibleTransformation;
  12842. var transform = (reversible ? new ReversibleTransform() :
  12843. new IrreversibleTransform());
  12844. var subbandCoefficients = [];
  12845. var b = 0;
  12846. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12847. var resolution = component.resolutions[i];
  12848. var width = resolution.trx1 - resolution.trx0;
  12849. var height = resolution.try1 - resolution.try0;
  12850. // Allocate space for the whole sublevel.
  12851. var coefficients = new Float32Array(width * height);
  12852. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12853. var mu, epsilon;
  12854. if (!scalarExpounded) {
  12855. // formula E-5
  12856. mu = spqcds[0].mu;
  12857. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12858. } else {
  12859. mu = spqcds[b].mu;
  12860. epsilon = spqcds[b].epsilon;
  12861. b++;
  12862. }
  12863. var subband = resolution.subbands[j];
  12864. var gainLog2 = SubbandsGainLog2[subband.type];
  12865. // calculate quantization coefficient (Section E.1.1.1)
  12866. var delta = (reversible ? 1 :
  12867. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  12868. var mb = (guardBits + epsilon - 1);
  12869. // In the first resolution level, copyCoefficients will fill the
  12870. // whole array with coefficients. In the succeeding passes,
  12871. // copyCoefficients will consecutively fill in the values that belong
  12872. // to the interleaved positions of the HL, LH, and HH coefficients.
  12873. // The LL coefficients will then be interleaved in Transform.iterate().
  12874. copyCoefficients(coefficients, width, height, subband, delta, mb,
  12875. reversible, segmentationSymbolUsed);
  12876. }
  12877. subbandCoefficients.push({
  12878. width: width,
  12879. height: height,
  12880. items: coefficients
  12881. });
  12882. }
  12883. var result = transform.calculate(subbandCoefficients,
  12884. component.tcx0, component.tcy0);
  12885. return {
  12886. left: component.tcx0,
  12887. top: component.tcy0,
  12888. width: result.width,
  12889. height: result.height,
  12890. items: result.items
  12891. };
  12892. }
  12893. function transformComponents(context) {
  12894. var siz = context.SIZ;
  12895. var components = context.components;
  12896. var componentsCount = siz.Csiz;
  12897. var resultImages = [];
  12898. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  12899. var tile = context.tiles[i];
  12900. var transformedTiles = [];
  12901. var c;
  12902. for (c = 0; c < componentsCount; c++) {
  12903. transformedTiles[c] = transformTile(context, tile, c);
  12904. }
  12905. var tile0 = transformedTiles[0];
  12906. var out = new Uint8Array(tile0.items.length * componentsCount);
  12907. var result = {
  12908. left: tile0.left,
  12909. top: tile0.top,
  12910. width: tile0.width,
  12911. height: tile0.height,
  12912. items: out
  12913. };
  12914. // Section G.2.2 Inverse multi component transform
  12915. var shift, offset, max, min, maxK;
  12916. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  12917. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  12918. var fourComponents = componentsCount === 4;
  12919. var y0items = transformedTiles[0].items;
  12920. var y1items = transformedTiles[1].items;
  12921. var y2items = transformedTiles[2].items;
  12922. var y3items = fourComponents ? transformedTiles[3].items : null;
  12923. // HACK: The multiple component transform formulas below assume that
  12924. // all components have the same precision. With this in mind, we
  12925. // compute shift and offset only once.
  12926. shift = components[0].precision - 8;
  12927. offset = (128 << shift) + 0.5;
  12928. max = 255 * (1 << shift);
  12929. maxK = max * 0.5;
  12930. min = -maxK;
  12931. var component0 = tile.components[0];
  12932. var alpha01 = componentsCount - 3;
  12933. jj = y0items.length;
  12934. if (!component0.codingStyleParameters.reversibleTransformation) {
  12935. // inverse irreversible multiple component transform
  12936. for (j = 0; j < jj; j++, pos += alpha01) {
  12937. y0 = y0items[j] + offset;
  12938. y1 = y1items[j];
  12939. y2 = y2items[j];
  12940. r = y0 + 1.402 * y2;
  12941. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  12942. b = y0 + 1.772 * y1;
  12943. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12944. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12945. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12946. }
  12947. } else {
  12948. // inverse reversible multiple component transform
  12949. for (j = 0; j < jj; j++, pos += alpha01) {
  12950. y0 = y0items[j] + offset;
  12951. y1 = y1items[j];
  12952. y2 = y2items[j];
  12953. g = y0 - ((y2 + y1) >> 2);
  12954. r = g + y2;
  12955. b = g + y1;
  12956. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12957. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12958. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12959. }
  12960. }
  12961. if (fourComponents) {
  12962. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  12963. k = y3items[j];
  12964. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  12965. }
  12966. }
  12967. } else { // no multi-component transform
  12968. for (c = 0; c < componentsCount; c++) {
  12969. var items = transformedTiles[c].items;
  12970. shift = components[c].precision - 8;
  12971. offset = (128 << shift) + 0.5;
  12972. max = (127.5 * (1 << shift));
  12973. min = -max;
  12974. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  12975. val = items[j];
  12976. out[pos] = val <= min ? 0 :
  12977. val >= max ? 255 : (val + offset) >> shift;
  12978. pos += componentsCount;
  12979. }
  12980. }
  12981. }
  12982. resultImages.push(result);
  12983. }
  12984. return resultImages;
  12985. }
  12986. function initializeTile(context, tileIndex) {
  12987. var siz = context.SIZ;
  12988. var componentsCount = siz.Csiz;
  12989. var tile = context.tiles[tileIndex];
  12990. for (var c = 0; c < componentsCount; c++) {
  12991. var component = tile.components[c];
  12992. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  12993. context.currentTile.QCC[c] : context.currentTile.QCD);
  12994. component.quantizationParameters = qcdOrQcc;
  12995. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  12996. context.currentTile.COC[c] : context.currentTile.COD);
  12997. component.codingStyleParameters = codOrCoc;
  12998. }
  12999. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13000. }
  13001. // Section B.10.2 Tag trees
  13002. var TagTree = (function TagTreeClosure() {
  13003. function TagTree(width, height) {
  13004. var levelsLength = log2(Math.max(width, height)) + 1;
  13005. this.levels = [];
  13006. for (var i = 0; i < levelsLength; i++) {
  13007. var level = {
  13008. width: width,
  13009. height: height,
  13010. items: []
  13011. };
  13012. this.levels.push(level);
  13013. width = Math.ceil(width / 2);
  13014. height = Math.ceil(height / 2);
  13015. }
  13016. }
  13017. TagTree.prototype = {
  13018. reset: function TagTree_reset(i, j) {
  13019. var currentLevel = 0, value = 0, level;
  13020. while (currentLevel < this.levels.length) {
  13021. level = this.levels[currentLevel];
  13022. var index = i + j * level.width;
  13023. if (level.items[index] !== undefined) {
  13024. value = level.items[index];
  13025. break;
  13026. }
  13027. level.index = index;
  13028. i >>= 1;
  13029. j >>= 1;
  13030. currentLevel++;
  13031. }
  13032. currentLevel--;
  13033. level = this.levels[currentLevel];
  13034. level.items[level.index] = value;
  13035. this.currentLevel = currentLevel;
  13036. delete this.value;
  13037. },
  13038. incrementValue: function TagTree_incrementValue() {
  13039. var level = this.levels[this.currentLevel];
  13040. level.items[level.index]++;
  13041. },
  13042. nextLevel: function TagTree_nextLevel() {
  13043. var currentLevel = this.currentLevel;
  13044. var level = this.levels[currentLevel];
  13045. var value = level.items[level.index];
  13046. currentLevel--;
  13047. if (currentLevel < 0) {
  13048. this.value = value;
  13049. return false;
  13050. }
  13051. this.currentLevel = currentLevel;
  13052. level = this.levels[currentLevel];
  13053. level.items[level.index] = value;
  13054. return true;
  13055. }
  13056. };
  13057. return TagTree;
  13058. })();
  13059. var InclusionTree = (function InclusionTreeClosure() {
  13060. function InclusionTree(width, height, defaultValue) {
  13061. var levelsLength = log2(Math.max(width, height)) + 1;
  13062. this.levels = [];
  13063. for (var i = 0; i < levelsLength; i++) {
  13064. var items = new Uint8Array(width * height);
  13065. for (var j = 0, jj = items.length; j < jj; j++) {
  13066. items[j] = defaultValue;
  13067. }
  13068. var level = {
  13069. width: width,
  13070. height: height,
  13071. items: items
  13072. };
  13073. this.levels.push(level);
  13074. width = Math.ceil(width / 2);
  13075. height = Math.ceil(height / 2);
  13076. }
  13077. }
  13078. InclusionTree.prototype = {
  13079. reset: function InclusionTree_reset(i, j, stopValue) {
  13080. var currentLevel = 0;
  13081. while (currentLevel < this.levels.length) {
  13082. var level = this.levels[currentLevel];
  13083. var index = i + j * level.width;
  13084. level.index = index;
  13085. var value = level.items[index];
  13086. if (value === 0xFF) {
  13087. break;
  13088. }
  13089. if (value > stopValue) {
  13090. this.currentLevel = currentLevel;
  13091. // already know about this one, propagating the value to top levels
  13092. this.propagateValues();
  13093. return false;
  13094. }
  13095. i >>= 1;
  13096. j >>= 1;
  13097. currentLevel++;
  13098. }
  13099. this.currentLevel = currentLevel - 1;
  13100. return true;
  13101. },
  13102. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13103. var level = this.levels[this.currentLevel];
  13104. level.items[level.index] = stopValue + 1;
  13105. this.propagateValues();
  13106. },
  13107. propagateValues: function InclusionTree_propagateValues() {
  13108. var levelIndex = this.currentLevel;
  13109. var level = this.levels[levelIndex];
  13110. var currentValue = level.items[level.index];
  13111. while (--levelIndex >= 0) {
  13112. level = this.levels[levelIndex];
  13113. level.items[level.index] = currentValue;
  13114. }
  13115. },
  13116. nextLevel: function InclusionTree_nextLevel() {
  13117. var currentLevel = this.currentLevel;
  13118. var level = this.levels[currentLevel];
  13119. var value = level.items[level.index];
  13120. level.items[level.index] = 0xFF;
  13121. currentLevel--;
  13122. if (currentLevel < 0) {
  13123. return false;
  13124. }
  13125. this.currentLevel = currentLevel;
  13126. level = this.levels[currentLevel];
  13127. level.items[level.index] = value;
  13128. return true;
  13129. }
  13130. };
  13131. return InclusionTree;
  13132. })();
  13133. // Section D. Coefficient bit modeling
  13134. var BitModel = (function BitModelClosure() {
  13135. var UNIFORM_CONTEXT = 17;
  13136. var RUNLENGTH_CONTEXT = 18;
  13137. // Table D-1
  13138. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13139. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13140. var LLAndLHContextsLabel = new Uint8Array([
  13141. 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,
  13142. 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,
  13143. 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
  13144. ]);
  13145. var HLContextLabel = new Uint8Array([
  13146. 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,
  13147. 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,
  13148. 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
  13149. ]);
  13150. var HHContextLabel = new Uint8Array([
  13151. 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,
  13152. 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,
  13153. 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
  13154. ]);
  13155. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13156. this.width = width;
  13157. this.height = height;
  13158. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13159. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13160. var coefficientCount = width * height;
  13161. // coefficients outside the encoding region treated as insignificant
  13162. // add border state cells for significanceState
  13163. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13164. this.coefficentsSign = new Uint8Array(coefficientCount);
  13165. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13166. mb > 6 ? new Uint16Array(coefficientCount) :
  13167. new Uint8Array(coefficientCount);
  13168. this.processingFlags = new Uint8Array(coefficientCount);
  13169. var bitsDecoded = new Uint8Array(coefficientCount);
  13170. if (zeroBitPlanes !== 0) {
  13171. for (var i = 0; i < coefficientCount; i++) {
  13172. bitsDecoded[i] = zeroBitPlanes;
  13173. }
  13174. }
  13175. this.bitsDecoded = bitsDecoded;
  13176. this.reset();
  13177. }
  13178. BitModel.prototype = {
  13179. setDecoder: function BitModel_setDecoder(decoder) {
  13180. this.decoder = decoder;
  13181. },
  13182. reset: function BitModel_reset() {
  13183. // We have 17 contexts that are accessed via context labels,
  13184. // plus the uniform and runlength context.
  13185. this.contexts = new Int8Array(19);
  13186. // Contexts are packed into 1 byte:
  13187. // highest 7 bits carry the index, lowest bit carries mps
  13188. this.contexts[0] = (4 << 1) | 0;
  13189. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13190. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13191. },
  13192. setNeighborsSignificance:
  13193. function BitModel_setNeighborsSignificance(row, column, index) {
  13194. var neighborsSignificance = this.neighborsSignificance;
  13195. var width = this.width, height = this.height;
  13196. var left = (column > 0);
  13197. var right = (column + 1 < width);
  13198. var i;
  13199. if (row > 0) {
  13200. i = index - width;
  13201. if (left) {
  13202. neighborsSignificance[i - 1] += 0x10;
  13203. }
  13204. if (right) {
  13205. neighborsSignificance[i + 1] += 0x10;
  13206. }
  13207. neighborsSignificance[i] += 0x04;
  13208. }
  13209. if (row + 1 < height) {
  13210. i = index + width;
  13211. if (left) {
  13212. neighborsSignificance[i - 1] += 0x10;
  13213. }
  13214. if (right) {
  13215. neighborsSignificance[i + 1] += 0x10;
  13216. }
  13217. neighborsSignificance[i] += 0x04;
  13218. }
  13219. if (left) {
  13220. neighborsSignificance[index - 1] += 0x01;
  13221. }
  13222. if (right) {
  13223. neighborsSignificance[index + 1] += 0x01;
  13224. }
  13225. neighborsSignificance[index] |= 0x80;
  13226. },
  13227. runSignificancePropagationPass:
  13228. function BitModel_runSignificancePropagationPass() {
  13229. var decoder = this.decoder;
  13230. var width = this.width, height = this.height;
  13231. var coefficentsMagnitude = this.coefficentsMagnitude;
  13232. var coefficentsSign = this.coefficentsSign;
  13233. var neighborsSignificance = this.neighborsSignificance;
  13234. var processingFlags = this.processingFlags;
  13235. var contexts = this.contexts;
  13236. var labels = this.contextLabelTable;
  13237. var bitsDecoded = this.bitsDecoded;
  13238. var processedInverseMask = ~1;
  13239. var processedMask = 1;
  13240. var firstMagnitudeBitMask = 2;
  13241. for (var i0 = 0; i0 < height; i0 += 4) {
  13242. for (var j = 0; j < width; j++) {
  13243. var index = i0 * width + j;
  13244. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13245. var i = i0 + i1;
  13246. if (i >= height) {
  13247. break;
  13248. }
  13249. // clear processed flag first
  13250. processingFlags[index] &= processedInverseMask;
  13251. if (coefficentsMagnitude[index] ||
  13252. !neighborsSignificance[index]) {
  13253. continue;
  13254. }
  13255. var contextLabel = labels[neighborsSignificance[index]];
  13256. var decision = decoder.readBit(contexts, contextLabel);
  13257. if (decision) {
  13258. var sign = this.decodeSignBit(i, j, index);
  13259. coefficentsSign[index] = sign;
  13260. coefficentsMagnitude[index] = 1;
  13261. this.setNeighborsSignificance(i, j, index);
  13262. processingFlags[index] |= firstMagnitudeBitMask;
  13263. }
  13264. bitsDecoded[index]++;
  13265. processingFlags[index] |= processedMask;
  13266. }
  13267. }
  13268. }
  13269. },
  13270. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13271. var width = this.width, height = this.height;
  13272. var coefficentsMagnitude = this.coefficentsMagnitude;
  13273. var coefficentsSign = this.coefficentsSign;
  13274. var contribution, sign0, sign1, significance1;
  13275. var contextLabel, decoded;
  13276. // calculate horizontal contribution
  13277. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13278. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13279. sign1 = coefficentsSign[index + 1];
  13280. if (significance1) {
  13281. sign0 = coefficentsSign[index - 1];
  13282. contribution = 1 - sign1 - sign0;
  13283. } else {
  13284. contribution = 1 - sign1 - sign1;
  13285. }
  13286. } else if (significance1) {
  13287. sign0 = coefficentsSign[index - 1];
  13288. contribution = 1 - sign0 - sign0;
  13289. } else {
  13290. contribution = 0;
  13291. }
  13292. var horizontalContribution = 3 * contribution;
  13293. // calculate vertical contribution and combine with the horizontal
  13294. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13295. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13296. sign1 = coefficentsSign[index + width];
  13297. if (significance1) {
  13298. sign0 = coefficentsSign[index - width];
  13299. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13300. } else {
  13301. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13302. }
  13303. } else if (significance1) {
  13304. sign0 = coefficentsSign[index - width];
  13305. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13306. } else {
  13307. contribution = horizontalContribution;
  13308. }
  13309. if (contribution >= 0) {
  13310. contextLabel = 9 + contribution;
  13311. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13312. } else {
  13313. contextLabel = 9 - contribution;
  13314. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13315. }
  13316. return decoded;
  13317. },
  13318. runMagnitudeRefinementPass:
  13319. function BitModel_runMagnitudeRefinementPass() {
  13320. var decoder = this.decoder;
  13321. var width = this.width, height = this.height;
  13322. var coefficentsMagnitude = this.coefficentsMagnitude;
  13323. var neighborsSignificance = this.neighborsSignificance;
  13324. var contexts = this.contexts;
  13325. var bitsDecoded = this.bitsDecoded;
  13326. var processingFlags = this.processingFlags;
  13327. var processedMask = 1;
  13328. var firstMagnitudeBitMask = 2;
  13329. var length = width * height;
  13330. var width4 = width * 4;
  13331. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13332. indexNext = Math.min(length, index0 + width4);
  13333. for (var j = 0; j < width; j++) {
  13334. for (var index = index0 + j; index < indexNext; index += width) {
  13335. // significant but not those that have just become
  13336. if (!coefficentsMagnitude[index] ||
  13337. (processingFlags[index] & processedMask) !== 0) {
  13338. continue;
  13339. }
  13340. var contextLabel = 16;
  13341. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13342. processingFlags[index] ^= firstMagnitudeBitMask;
  13343. // first refinement
  13344. var significance = neighborsSignificance[index] & 127;
  13345. contextLabel = significance === 0 ? 15 : 14;
  13346. }
  13347. var bit = decoder.readBit(contexts, contextLabel);
  13348. coefficentsMagnitude[index] =
  13349. (coefficentsMagnitude[index] << 1) | bit;
  13350. bitsDecoded[index]++;
  13351. processingFlags[index] |= processedMask;
  13352. }
  13353. }
  13354. }
  13355. },
  13356. runCleanupPass: function BitModel_runCleanupPass() {
  13357. var decoder = this.decoder;
  13358. var width = this.width, height = this.height;
  13359. var neighborsSignificance = this.neighborsSignificance;
  13360. var coefficentsMagnitude = this.coefficentsMagnitude;
  13361. var coefficentsSign = this.coefficentsSign;
  13362. var contexts = this.contexts;
  13363. var labels = this.contextLabelTable;
  13364. var bitsDecoded = this.bitsDecoded;
  13365. var processingFlags = this.processingFlags;
  13366. var processedMask = 1;
  13367. var firstMagnitudeBitMask = 2;
  13368. var oneRowDown = width;
  13369. var twoRowsDown = width * 2;
  13370. var threeRowsDown = width * 3;
  13371. var iNext;
  13372. for (var i0 = 0; i0 < height; i0 = iNext) {
  13373. iNext = Math.min(i0 + 4, height);
  13374. var indexBase = i0 * width;
  13375. var checkAllEmpty = i0 + 3 < height;
  13376. for (var j = 0; j < width; j++) {
  13377. var index0 = indexBase + j;
  13378. // using the property: labels[neighborsSignificance[index]] === 0
  13379. // when neighborsSignificance[index] === 0
  13380. var allEmpty = (checkAllEmpty &&
  13381. processingFlags[index0] === 0 &&
  13382. processingFlags[index0 + oneRowDown] === 0 &&
  13383. processingFlags[index0 + twoRowsDown] === 0 &&
  13384. processingFlags[index0 + threeRowsDown] === 0 &&
  13385. neighborsSignificance[index0] === 0 &&
  13386. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13387. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13388. neighborsSignificance[index0 + threeRowsDown] === 0);
  13389. var i1 = 0, index = index0;
  13390. var i = i0, sign;
  13391. if (allEmpty) {
  13392. var hasSignificantCoefficent =
  13393. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13394. if (!hasSignificantCoefficent) {
  13395. bitsDecoded[index0]++;
  13396. bitsDecoded[index0 + oneRowDown]++;
  13397. bitsDecoded[index0 + twoRowsDown]++;
  13398. bitsDecoded[index0 + threeRowsDown]++;
  13399. continue; // next column
  13400. }
  13401. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13402. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13403. if (i1 !== 0) {
  13404. i = i0 + i1;
  13405. index += i1 * width;
  13406. }
  13407. sign = this.decodeSignBit(i, j, index);
  13408. coefficentsSign[index] = sign;
  13409. coefficentsMagnitude[index] = 1;
  13410. this.setNeighborsSignificance(i, j, index);
  13411. processingFlags[index] |= firstMagnitudeBitMask;
  13412. index = index0;
  13413. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13414. bitsDecoded[index]++;
  13415. }
  13416. i1++;
  13417. }
  13418. for (i = i0 + i1; i < iNext; i++, index += width) {
  13419. if (coefficentsMagnitude[index] ||
  13420. (processingFlags[index] & processedMask) !== 0) {
  13421. continue;
  13422. }
  13423. var contextLabel = labels[neighborsSignificance[index]];
  13424. var decision = decoder.readBit(contexts, contextLabel);
  13425. if (decision === 1) {
  13426. sign = this.decodeSignBit(i, j, index);
  13427. coefficentsSign[index] = sign;
  13428. coefficentsMagnitude[index] = 1;
  13429. this.setNeighborsSignificance(i, j, index);
  13430. processingFlags[index] |= firstMagnitudeBitMask;
  13431. }
  13432. bitsDecoded[index]++;
  13433. }
  13434. }
  13435. }
  13436. },
  13437. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13438. var decoder = this.decoder;
  13439. var contexts = this.contexts;
  13440. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13441. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13442. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13443. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13444. if (symbol !== 0xA) {
  13445. error('JPX Error: Invalid segmentation symbol');
  13446. }
  13447. }
  13448. };
  13449. return BitModel;
  13450. })();
  13451. // Section F, Discrete wavelet transformation
  13452. var Transform = (function TransformClosure() {
  13453. function Transform() {}
  13454. Transform.prototype.calculate =
  13455. function transformCalculate(subbands, u0, v0) {
  13456. var ll = subbands[0];
  13457. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13458. ll = this.iterate(ll, subbands[i], u0, v0);
  13459. }
  13460. return ll;
  13461. };
  13462. Transform.prototype.extend = function extend(buffer, offset, size) {
  13463. // Section F.3.7 extending... using max extension of 4
  13464. var i1 = offset - 1, j1 = offset + 1;
  13465. var i2 = offset + size - 2, j2 = offset + size;
  13466. buffer[i1--] = buffer[j1++];
  13467. buffer[j2++] = buffer[i2--];
  13468. buffer[i1--] = buffer[j1++];
  13469. buffer[j2++] = buffer[i2--];
  13470. buffer[i1--] = buffer[j1++];
  13471. buffer[j2++] = buffer[i2--];
  13472. buffer[i1] = buffer[j1];
  13473. buffer[j2] = buffer[i2];
  13474. };
  13475. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13476. u0, v0) {
  13477. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13478. var width = hl_lh_hh.width;
  13479. var height = hl_lh_hh.height;
  13480. var items = hl_lh_hh.items;
  13481. var i, j, k, l, u, v;
  13482. // Interleave LL according to Section F.3.3
  13483. for (k = 0, i = 0; i < llHeight; i++) {
  13484. l = i * 2 * width;
  13485. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13486. items[l] = llItems[k];
  13487. }
  13488. }
  13489. // The LL band is not needed anymore.
  13490. llItems = ll.items = null;
  13491. var bufferPadding = 4;
  13492. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13493. // Section F.3.4 HOR_SR
  13494. if (width === 1) {
  13495. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13496. if ((u0 & 1) !== 0) {
  13497. for (v = 0, k = 0; v < height; v++, k += width) {
  13498. items[k] *= 0.5;
  13499. }
  13500. }
  13501. } else {
  13502. for (v = 0, k = 0; v < height; v++, k += width) {
  13503. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13504. this.extend(rowBuffer, bufferPadding, width);
  13505. this.filter(rowBuffer, bufferPadding, width);
  13506. items.set(
  13507. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13508. k);
  13509. }
  13510. }
  13511. // Accesses to the items array can take long, because it may not fit into
  13512. // CPU cache and has to be fetched from main memory. Since subsequent
  13513. // accesses to the items array are not local when reading columns, we
  13514. // have a cache miss every time. To reduce cache misses, get up to
  13515. // 'numBuffers' items at a time and store them into the individual
  13516. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13517. var numBuffers = 16;
  13518. var colBuffers = [];
  13519. for (i = 0; i < numBuffers; i++) {
  13520. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13521. }
  13522. var b, currentBuffer = 0;
  13523. ll = bufferPadding + height;
  13524. // Section F.3.5 VER_SR
  13525. if (height === 1) {
  13526. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13527. if ((v0 & 1) !== 0) {
  13528. for (u = 0; u < width; u++) {
  13529. items[u] *= 0.5;
  13530. }
  13531. }
  13532. } else {
  13533. for (u = 0; u < width; u++) {
  13534. // if we ran out of buffers, copy several image columns at once
  13535. if (currentBuffer === 0) {
  13536. numBuffers = Math.min(width - u, numBuffers);
  13537. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13538. for (b = 0; b < numBuffers; b++) {
  13539. colBuffers[b][l] = items[k + b];
  13540. }
  13541. }
  13542. currentBuffer = numBuffers;
  13543. }
  13544. currentBuffer--;
  13545. var buffer = colBuffers[currentBuffer];
  13546. this.extend(buffer, bufferPadding, height);
  13547. this.filter(buffer, bufferPadding, height);
  13548. // If this is last buffer in this group of buffers, flush all buffers.
  13549. if (currentBuffer === 0) {
  13550. k = u - numBuffers + 1;
  13551. for (l = bufferPadding; l < ll; k += width, l++) {
  13552. for (b = 0; b < numBuffers; b++) {
  13553. items[k + b] = colBuffers[b][l];
  13554. }
  13555. }
  13556. }
  13557. }
  13558. }
  13559. return {
  13560. width: width,
  13561. height: height,
  13562. items: items
  13563. };
  13564. };
  13565. return Transform;
  13566. })();
  13567. // Section 3.8.2 Irreversible 9-7 filter
  13568. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13569. function IrreversibleTransform() {
  13570. Transform.call(this);
  13571. }
  13572. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13573. IrreversibleTransform.prototype.filter =
  13574. function irreversibleTransformFilter(x, offset, length) {
  13575. var len = length >> 1;
  13576. offset = offset | 0;
  13577. var j, n, current, next;
  13578. var alpha = -1.586134342059924;
  13579. var beta = -0.052980118572961;
  13580. var gamma = 0.882911075530934;
  13581. var delta = 0.443506852043971;
  13582. var K = 1.230174104914001;
  13583. var K_ = 1 / K;
  13584. // step 1 is combined with step 3
  13585. // step 2
  13586. j = offset - 3;
  13587. for (n = len + 4; n--; j += 2) {
  13588. x[j] *= K_;
  13589. }
  13590. // step 1 & 3
  13591. j = offset - 2;
  13592. current = delta * x[j -1];
  13593. for (n = len + 3; n--; j += 2) {
  13594. next = delta * x[j + 1];
  13595. x[j] = K * x[j] - current - next;
  13596. if (n--) {
  13597. j += 2;
  13598. current = delta * x[j + 1];
  13599. x[j] = K * x[j] - current - next;
  13600. } else {
  13601. break;
  13602. }
  13603. }
  13604. // step 4
  13605. j = offset - 1;
  13606. current = gamma * x[j - 1];
  13607. for (n = len + 2; n--; j += 2) {
  13608. next = gamma * x[j + 1];
  13609. x[j] -= current + next;
  13610. if (n--) {
  13611. j += 2;
  13612. current = gamma * x[j + 1];
  13613. x[j] -= current + next;
  13614. } else {
  13615. break;
  13616. }
  13617. }
  13618. // step 5
  13619. j = offset;
  13620. current = beta * x[j - 1];
  13621. for (n = len + 1; n--; j += 2) {
  13622. next = beta * x[j + 1];
  13623. x[j] -= current + next;
  13624. if (n--) {
  13625. j += 2;
  13626. current = beta * x[j + 1];
  13627. x[j] -= current + next;
  13628. } else {
  13629. break;
  13630. }
  13631. }
  13632. // step 6
  13633. if (len !== 0) {
  13634. j = offset + 1;
  13635. current = alpha * x[j - 1];
  13636. for (n = len; n--; j += 2) {
  13637. next = alpha * x[j + 1];
  13638. x[j] -= current + next;
  13639. if (n--) {
  13640. j += 2;
  13641. current = alpha * x[j + 1];
  13642. x[j] -= current + next;
  13643. } else {
  13644. break;
  13645. }
  13646. }
  13647. }
  13648. };
  13649. return IrreversibleTransform;
  13650. })();
  13651. // Section 3.8.1 Reversible 5-3 filter
  13652. var ReversibleTransform = (function ReversibleTransformClosure() {
  13653. function ReversibleTransform() {
  13654. Transform.call(this);
  13655. }
  13656. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13657. ReversibleTransform.prototype.filter =
  13658. function reversibleTransformFilter(x, offset, length) {
  13659. var len = length >> 1;
  13660. offset = offset | 0;
  13661. var j, n;
  13662. for (j = offset, n = len + 1; n--; j += 2) {
  13663. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13664. }
  13665. for (j = offset + 1, n = len; n--; j += 2) {
  13666. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13667. }
  13668. };
  13669. return ReversibleTransform;
  13670. })();
  13671. return JpxImage;
  13672. })();
  13673. exports.JpxImage = JpxImage;
  13674. }));
  13675. (function (root, factory) {
  13676. {
  13677. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13678. }
  13679. }(this, function (exports, sharedUtil) {
  13680. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13681. // The Metrics object contains glyph widths (in glyph space units).
  13682. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13683. // space unit corresponds to 1/1000th of text space unit.
  13684. var getMetrics = getLookupTableFactory(function (t) {
  13685. t['Courier'] = 600;
  13686. t['Courier-Bold'] = 600;
  13687. t['Courier-BoldOblique'] = 600;
  13688. t['Courier-Oblique'] = 600;
  13689. t['Helvetica'] = getLookupTableFactory(function (t) {
  13690. t['space'] = 278;
  13691. t['exclam'] = 278;
  13692. t['quotedbl'] = 355;
  13693. t['numbersign'] = 556;
  13694. t['dollar'] = 556;
  13695. t['percent'] = 889;
  13696. t['ampersand'] = 667;
  13697. t['quoteright'] = 222;
  13698. t['parenleft'] = 333;
  13699. t['parenright'] = 333;
  13700. t['asterisk'] = 389;
  13701. t['plus'] = 584;
  13702. t['comma'] = 278;
  13703. t['hyphen'] = 333;
  13704. t['period'] = 278;
  13705. t['slash'] = 278;
  13706. t['zero'] = 556;
  13707. t['one'] = 556;
  13708. t['two'] = 556;
  13709. t['three'] = 556;
  13710. t['four'] = 556;
  13711. t['five'] = 556;
  13712. t['six'] = 556;
  13713. t['seven'] = 556;
  13714. t['eight'] = 556;
  13715. t['nine'] = 556;
  13716. t['colon'] = 278;
  13717. t['semicolon'] = 278;
  13718. t['less'] = 584;
  13719. t['equal'] = 584;
  13720. t['greater'] = 584;
  13721. t['question'] = 556;
  13722. t['at'] = 1015;
  13723. t['A'] = 667;
  13724. t['B'] = 667;
  13725. t['C'] = 722;
  13726. t['D'] = 722;
  13727. t['E'] = 667;
  13728. t['F'] = 611;
  13729. t['G'] = 778;
  13730. t['H'] = 722;
  13731. t['I'] = 278;
  13732. t['J'] = 500;
  13733. t['K'] = 667;
  13734. t['L'] = 556;
  13735. t['M'] = 833;
  13736. t['N'] = 722;
  13737. t['O'] = 778;
  13738. t['P'] = 667;
  13739. t['Q'] = 778;
  13740. t['R'] = 722;
  13741. t['S'] = 667;
  13742. t['T'] = 611;
  13743. t['U'] = 722;
  13744. t['V'] = 667;
  13745. t['W'] = 944;
  13746. t['X'] = 667;
  13747. t['Y'] = 667;
  13748. t['Z'] = 611;
  13749. t['bracketleft'] = 278;
  13750. t['backslash'] = 278;
  13751. t['bracketright'] = 278;
  13752. t['asciicircum'] = 469;
  13753. t['underscore'] = 556;
  13754. t['quoteleft'] = 222;
  13755. t['a'] = 556;
  13756. t['b'] = 556;
  13757. t['c'] = 500;
  13758. t['d'] = 556;
  13759. t['e'] = 556;
  13760. t['f'] = 278;
  13761. t['g'] = 556;
  13762. t['h'] = 556;
  13763. t['i'] = 222;
  13764. t['j'] = 222;
  13765. t['k'] = 500;
  13766. t['l'] = 222;
  13767. t['m'] = 833;
  13768. t['n'] = 556;
  13769. t['o'] = 556;
  13770. t['p'] = 556;
  13771. t['q'] = 556;
  13772. t['r'] = 333;
  13773. t['s'] = 500;
  13774. t['t'] = 278;
  13775. t['u'] = 556;
  13776. t['v'] = 500;
  13777. t['w'] = 722;
  13778. t['x'] = 500;
  13779. t['y'] = 500;
  13780. t['z'] = 500;
  13781. t['braceleft'] = 334;
  13782. t['bar'] = 260;
  13783. t['braceright'] = 334;
  13784. t['asciitilde'] = 584;
  13785. t['exclamdown'] = 333;
  13786. t['cent'] = 556;
  13787. t['sterling'] = 556;
  13788. t['fraction'] = 167;
  13789. t['yen'] = 556;
  13790. t['florin'] = 556;
  13791. t['section'] = 556;
  13792. t['currency'] = 556;
  13793. t['quotesingle'] = 191;
  13794. t['quotedblleft'] = 333;
  13795. t['guillemotleft'] = 556;
  13796. t['guilsinglleft'] = 333;
  13797. t['guilsinglright'] = 333;
  13798. t['fi'] = 500;
  13799. t['fl'] = 500;
  13800. t['endash'] = 556;
  13801. t['dagger'] = 556;
  13802. t['daggerdbl'] = 556;
  13803. t['periodcentered'] = 278;
  13804. t['paragraph'] = 537;
  13805. t['bullet'] = 350;
  13806. t['quotesinglbase'] = 222;
  13807. t['quotedblbase'] = 333;
  13808. t['quotedblright'] = 333;
  13809. t['guillemotright'] = 556;
  13810. t['ellipsis'] = 1000;
  13811. t['perthousand'] = 1000;
  13812. t['questiondown'] = 611;
  13813. t['grave'] = 333;
  13814. t['acute'] = 333;
  13815. t['circumflex'] = 333;
  13816. t['tilde'] = 333;
  13817. t['macron'] = 333;
  13818. t['breve'] = 333;
  13819. t['dotaccent'] = 333;
  13820. t['dieresis'] = 333;
  13821. t['ring'] = 333;
  13822. t['cedilla'] = 333;
  13823. t['hungarumlaut'] = 333;
  13824. t['ogonek'] = 333;
  13825. t['caron'] = 333;
  13826. t['emdash'] = 1000;
  13827. t['AE'] = 1000;
  13828. t['ordfeminine'] = 370;
  13829. t['Lslash'] = 556;
  13830. t['Oslash'] = 778;
  13831. t['OE'] = 1000;
  13832. t['ordmasculine'] = 365;
  13833. t['ae'] = 889;
  13834. t['dotlessi'] = 278;
  13835. t['lslash'] = 222;
  13836. t['oslash'] = 611;
  13837. t['oe'] = 944;
  13838. t['germandbls'] = 611;
  13839. t['Idieresis'] = 278;
  13840. t['eacute'] = 556;
  13841. t['abreve'] = 556;
  13842. t['uhungarumlaut'] = 556;
  13843. t['ecaron'] = 556;
  13844. t['Ydieresis'] = 667;
  13845. t['divide'] = 584;
  13846. t['Yacute'] = 667;
  13847. t['Acircumflex'] = 667;
  13848. t['aacute'] = 556;
  13849. t['Ucircumflex'] = 722;
  13850. t['yacute'] = 500;
  13851. t['scommaaccent'] = 500;
  13852. t['ecircumflex'] = 556;
  13853. t['Uring'] = 722;
  13854. t['Udieresis'] = 722;
  13855. t['aogonek'] = 556;
  13856. t['Uacute'] = 722;
  13857. t['uogonek'] = 556;
  13858. t['Edieresis'] = 667;
  13859. t['Dcroat'] = 722;
  13860. t['commaaccent'] = 250;
  13861. t['copyright'] = 737;
  13862. t['Emacron'] = 667;
  13863. t['ccaron'] = 500;
  13864. t['aring'] = 556;
  13865. t['Ncommaaccent'] = 722;
  13866. t['lacute'] = 222;
  13867. t['agrave'] = 556;
  13868. t['Tcommaaccent'] = 611;
  13869. t['Cacute'] = 722;
  13870. t['atilde'] = 556;
  13871. t['Edotaccent'] = 667;
  13872. t['scaron'] = 500;
  13873. t['scedilla'] = 500;
  13874. t['iacute'] = 278;
  13875. t['lozenge'] = 471;
  13876. t['Rcaron'] = 722;
  13877. t['Gcommaaccent'] = 778;
  13878. t['ucircumflex'] = 556;
  13879. t['acircumflex'] = 556;
  13880. t['Amacron'] = 667;
  13881. t['rcaron'] = 333;
  13882. t['ccedilla'] = 500;
  13883. t['Zdotaccent'] = 611;
  13884. t['Thorn'] = 667;
  13885. t['Omacron'] = 778;
  13886. t['Racute'] = 722;
  13887. t['Sacute'] = 667;
  13888. t['dcaron'] = 643;
  13889. t['Umacron'] = 722;
  13890. t['uring'] = 556;
  13891. t['threesuperior'] = 333;
  13892. t['Ograve'] = 778;
  13893. t['Agrave'] = 667;
  13894. t['Abreve'] = 667;
  13895. t['multiply'] = 584;
  13896. t['uacute'] = 556;
  13897. t['Tcaron'] = 611;
  13898. t['partialdiff'] = 476;
  13899. t['ydieresis'] = 500;
  13900. t['Nacute'] = 722;
  13901. t['icircumflex'] = 278;
  13902. t['Ecircumflex'] = 667;
  13903. t['adieresis'] = 556;
  13904. t['edieresis'] = 556;
  13905. t['cacute'] = 500;
  13906. t['nacute'] = 556;
  13907. t['umacron'] = 556;
  13908. t['Ncaron'] = 722;
  13909. t['Iacute'] = 278;
  13910. t['plusminus'] = 584;
  13911. t['brokenbar'] = 260;
  13912. t['registered'] = 737;
  13913. t['Gbreve'] = 778;
  13914. t['Idotaccent'] = 278;
  13915. t['summation'] = 600;
  13916. t['Egrave'] = 667;
  13917. t['racute'] = 333;
  13918. t['omacron'] = 556;
  13919. t['Zacute'] = 611;
  13920. t['Zcaron'] = 611;
  13921. t['greaterequal'] = 549;
  13922. t['Eth'] = 722;
  13923. t['Ccedilla'] = 722;
  13924. t['lcommaaccent'] = 222;
  13925. t['tcaron'] = 317;
  13926. t['eogonek'] = 556;
  13927. t['Uogonek'] = 722;
  13928. t['Aacute'] = 667;
  13929. t['Adieresis'] = 667;
  13930. t['egrave'] = 556;
  13931. t['zacute'] = 500;
  13932. t['iogonek'] = 222;
  13933. t['Oacute'] = 778;
  13934. t['oacute'] = 556;
  13935. t['amacron'] = 556;
  13936. t['sacute'] = 500;
  13937. t['idieresis'] = 278;
  13938. t['Ocircumflex'] = 778;
  13939. t['Ugrave'] = 722;
  13940. t['Delta'] = 612;
  13941. t['thorn'] = 556;
  13942. t['twosuperior'] = 333;
  13943. t['Odieresis'] = 778;
  13944. t['mu'] = 556;
  13945. t['igrave'] = 278;
  13946. t['ohungarumlaut'] = 556;
  13947. t['Eogonek'] = 667;
  13948. t['dcroat'] = 556;
  13949. t['threequarters'] = 834;
  13950. t['Scedilla'] = 667;
  13951. t['lcaron'] = 299;
  13952. t['Kcommaaccent'] = 667;
  13953. t['Lacute'] = 556;
  13954. t['trademark'] = 1000;
  13955. t['edotaccent'] = 556;
  13956. t['Igrave'] = 278;
  13957. t['Imacron'] = 278;
  13958. t['Lcaron'] = 556;
  13959. t['onehalf'] = 834;
  13960. t['lessequal'] = 549;
  13961. t['ocircumflex'] = 556;
  13962. t['ntilde'] = 556;
  13963. t['Uhungarumlaut'] = 722;
  13964. t['Eacute'] = 667;
  13965. t['emacron'] = 556;
  13966. t['gbreve'] = 556;
  13967. t['onequarter'] = 834;
  13968. t['Scaron'] = 667;
  13969. t['Scommaaccent'] = 667;
  13970. t['Ohungarumlaut'] = 778;
  13971. t['degree'] = 400;
  13972. t['ograve'] = 556;
  13973. t['Ccaron'] = 722;
  13974. t['ugrave'] = 556;
  13975. t['radical'] = 453;
  13976. t['Dcaron'] = 722;
  13977. t['rcommaaccent'] = 333;
  13978. t['Ntilde'] = 722;
  13979. t['otilde'] = 556;
  13980. t['Rcommaaccent'] = 722;
  13981. t['Lcommaaccent'] = 556;
  13982. t['Atilde'] = 667;
  13983. t['Aogonek'] = 667;
  13984. t['Aring'] = 667;
  13985. t['Otilde'] = 778;
  13986. t['zdotaccent'] = 500;
  13987. t['Ecaron'] = 667;
  13988. t['Iogonek'] = 278;
  13989. t['kcommaaccent'] = 500;
  13990. t['minus'] = 584;
  13991. t['Icircumflex'] = 278;
  13992. t['ncaron'] = 556;
  13993. t['tcommaaccent'] = 278;
  13994. t['logicalnot'] = 584;
  13995. t['odieresis'] = 556;
  13996. t['udieresis'] = 556;
  13997. t['notequal'] = 549;
  13998. t['gcommaaccent'] = 556;
  13999. t['eth'] = 556;
  14000. t['zcaron'] = 500;
  14001. t['ncommaaccent'] = 556;
  14002. t['onesuperior'] = 333;
  14003. t['imacron'] = 278;
  14004. t['Euro'] = 556;
  14005. });
  14006. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  14007. t['space'] = 278;
  14008. t['exclam'] = 333;
  14009. t['quotedbl'] = 474;
  14010. t['numbersign'] = 556;
  14011. t['dollar'] = 556;
  14012. t['percent'] = 889;
  14013. t['ampersand'] = 722;
  14014. t['quoteright'] = 278;
  14015. t['parenleft'] = 333;
  14016. t['parenright'] = 333;
  14017. t['asterisk'] = 389;
  14018. t['plus'] = 584;
  14019. t['comma'] = 278;
  14020. t['hyphen'] = 333;
  14021. t['period'] = 278;
  14022. t['slash'] = 278;
  14023. t['zero'] = 556;
  14024. t['one'] = 556;
  14025. t['two'] = 556;
  14026. t['three'] = 556;
  14027. t['four'] = 556;
  14028. t['five'] = 556;
  14029. t['six'] = 556;
  14030. t['seven'] = 556;
  14031. t['eight'] = 556;
  14032. t['nine'] = 556;
  14033. t['colon'] = 333;
  14034. t['semicolon'] = 333;
  14035. t['less'] = 584;
  14036. t['equal'] = 584;
  14037. t['greater'] = 584;
  14038. t['question'] = 611;
  14039. t['at'] = 975;
  14040. t['A'] = 722;
  14041. t['B'] = 722;
  14042. t['C'] = 722;
  14043. t['D'] = 722;
  14044. t['E'] = 667;
  14045. t['F'] = 611;
  14046. t['G'] = 778;
  14047. t['H'] = 722;
  14048. t['I'] = 278;
  14049. t['J'] = 556;
  14050. t['K'] = 722;
  14051. t['L'] = 611;
  14052. t['M'] = 833;
  14053. t['N'] = 722;
  14054. t['O'] = 778;
  14055. t['P'] = 667;
  14056. t['Q'] = 778;
  14057. t['R'] = 722;
  14058. t['S'] = 667;
  14059. t['T'] = 611;
  14060. t['U'] = 722;
  14061. t['V'] = 667;
  14062. t['W'] = 944;
  14063. t['X'] = 667;
  14064. t['Y'] = 667;
  14065. t['Z'] = 611;
  14066. t['bracketleft'] = 333;
  14067. t['backslash'] = 278;
  14068. t['bracketright'] = 333;
  14069. t['asciicircum'] = 584;
  14070. t['underscore'] = 556;
  14071. t['quoteleft'] = 278;
  14072. t['a'] = 556;
  14073. t['b'] = 611;
  14074. t['c'] = 556;
  14075. t['d'] = 611;
  14076. t['e'] = 556;
  14077. t['f'] = 333;
  14078. t['g'] = 611;
  14079. t['h'] = 611;
  14080. t['i'] = 278;
  14081. t['j'] = 278;
  14082. t['k'] = 556;
  14083. t['l'] = 278;
  14084. t['m'] = 889;
  14085. t['n'] = 611;
  14086. t['o'] = 611;
  14087. t['p'] = 611;
  14088. t['q'] = 611;
  14089. t['r'] = 389;
  14090. t['s'] = 556;
  14091. t['t'] = 333;
  14092. t['u'] = 611;
  14093. t['v'] = 556;
  14094. t['w'] = 778;
  14095. t['x'] = 556;
  14096. t['y'] = 556;
  14097. t['z'] = 500;
  14098. t['braceleft'] = 389;
  14099. t['bar'] = 280;
  14100. t['braceright'] = 389;
  14101. t['asciitilde'] = 584;
  14102. t['exclamdown'] = 333;
  14103. t['cent'] = 556;
  14104. t['sterling'] = 556;
  14105. t['fraction'] = 167;
  14106. t['yen'] = 556;
  14107. t['florin'] = 556;
  14108. t['section'] = 556;
  14109. t['currency'] = 556;
  14110. t['quotesingle'] = 238;
  14111. t['quotedblleft'] = 500;
  14112. t['guillemotleft'] = 556;
  14113. t['guilsinglleft'] = 333;
  14114. t['guilsinglright'] = 333;
  14115. t['fi'] = 611;
  14116. t['fl'] = 611;
  14117. t['endash'] = 556;
  14118. t['dagger'] = 556;
  14119. t['daggerdbl'] = 556;
  14120. t['periodcentered'] = 278;
  14121. t['paragraph'] = 556;
  14122. t['bullet'] = 350;
  14123. t['quotesinglbase'] = 278;
  14124. t['quotedblbase'] = 500;
  14125. t['quotedblright'] = 500;
  14126. t['guillemotright'] = 556;
  14127. t['ellipsis'] = 1000;
  14128. t['perthousand'] = 1000;
  14129. t['questiondown'] = 611;
  14130. t['grave'] = 333;
  14131. t['acute'] = 333;
  14132. t['circumflex'] = 333;
  14133. t['tilde'] = 333;
  14134. t['macron'] = 333;
  14135. t['breve'] = 333;
  14136. t['dotaccent'] = 333;
  14137. t['dieresis'] = 333;
  14138. t['ring'] = 333;
  14139. t['cedilla'] = 333;
  14140. t['hungarumlaut'] = 333;
  14141. t['ogonek'] = 333;
  14142. t['caron'] = 333;
  14143. t['emdash'] = 1000;
  14144. t['AE'] = 1000;
  14145. t['ordfeminine'] = 370;
  14146. t['Lslash'] = 611;
  14147. t['Oslash'] = 778;
  14148. t['OE'] = 1000;
  14149. t['ordmasculine'] = 365;
  14150. t['ae'] = 889;
  14151. t['dotlessi'] = 278;
  14152. t['lslash'] = 278;
  14153. t['oslash'] = 611;
  14154. t['oe'] = 944;
  14155. t['germandbls'] = 611;
  14156. t['Idieresis'] = 278;
  14157. t['eacute'] = 556;
  14158. t['abreve'] = 556;
  14159. t['uhungarumlaut'] = 611;
  14160. t['ecaron'] = 556;
  14161. t['Ydieresis'] = 667;
  14162. t['divide'] = 584;
  14163. t['Yacute'] = 667;
  14164. t['Acircumflex'] = 722;
  14165. t['aacute'] = 556;
  14166. t['Ucircumflex'] = 722;
  14167. t['yacute'] = 556;
  14168. t['scommaaccent'] = 556;
  14169. t['ecircumflex'] = 556;
  14170. t['Uring'] = 722;
  14171. t['Udieresis'] = 722;
  14172. t['aogonek'] = 556;
  14173. t['Uacute'] = 722;
  14174. t['uogonek'] = 611;
  14175. t['Edieresis'] = 667;
  14176. t['Dcroat'] = 722;
  14177. t['commaaccent'] = 250;
  14178. t['copyright'] = 737;
  14179. t['Emacron'] = 667;
  14180. t['ccaron'] = 556;
  14181. t['aring'] = 556;
  14182. t['Ncommaaccent'] = 722;
  14183. t['lacute'] = 278;
  14184. t['agrave'] = 556;
  14185. t['Tcommaaccent'] = 611;
  14186. t['Cacute'] = 722;
  14187. t['atilde'] = 556;
  14188. t['Edotaccent'] = 667;
  14189. t['scaron'] = 556;
  14190. t['scedilla'] = 556;
  14191. t['iacute'] = 278;
  14192. t['lozenge'] = 494;
  14193. t['Rcaron'] = 722;
  14194. t['Gcommaaccent'] = 778;
  14195. t['ucircumflex'] = 611;
  14196. t['acircumflex'] = 556;
  14197. t['Amacron'] = 722;
  14198. t['rcaron'] = 389;
  14199. t['ccedilla'] = 556;
  14200. t['Zdotaccent'] = 611;
  14201. t['Thorn'] = 667;
  14202. t['Omacron'] = 778;
  14203. t['Racute'] = 722;
  14204. t['Sacute'] = 667;
  14205. t['dcaron'] = 743;
  14206. t['Umacron'] = 722;
  14207. t['uring'] = 611;
  14208. t['threesuperior'] = 333;
  14209. t['Ograve'] = 778;
  14210. t['Agrave'] = 722;
  14211. t['Abreve'] = 722;
  14212. t['multiply'] = 584;
  14213. t['uacute'] = 611;
  14214. t['Tcaron'] = 611;
  14215. t['partialdiff'] = 494;
  14216. t['ydieresis'] = 556;
  14217. t['Nacute'] = 722;
  14218. t['icircumflex'] = 278;
  14219. t['Ecircumflex'] = 667;
  14220. t['adieresis'] = 556;
  14221. t['edieresis'] = 556;
  14222. t['cacute'] = 556;
  14223. t['nacute'] = 611;
  14224. t['umacron'] = 611;
  14225. t['Ncaron'] = 722;
  14226. t['Iacute'] = 278;
  14227. t['plusminus'] = 584;
  14228. t['brokenbar'] = 280;
  14229. t['registered'] = 737;
  14230. t['Gbreve'] = 778;
  14231. t['Idotaccent'] = 278;
  14232. t['summation'] = 600;
  14233. t['Egrave'] = 667;
  14234. t['racute'] = 389;
  14235. t['omacron'] = 611;
  14236. t['Zacute'] = 611;
  14237. t['Zcaron'] = 611;
  14238. t['greaterequal'] = 549;
  14239. t['Eth'] = 722;
  14240. t['Ccedilla'] = 722;
  14241. t['lcommaaccent'] = 278;
  14242. t['tcaron'] = 389;
  14243. t['eogonek'] = 556;
  14244. t['Uogonek'] = 722;
  14245. t['Aacute'] = 722;
  14246. t['Adieresis'] = 722;
  14247. t['egrave'] = 556;
  14248. t['zacute'] = 500;
  14249. t['iogonek'] = 278;
  14250. t['Oacute'] = 778;
  14251. t['oacute'] = 611;
  14252. t['amacron'] = 556;
  14253. t['sacute'] = 556;
  14254. t['idieresis'] = 278;
  14255. t['Ocircumflex'] = 778;
  14256. t['Ugrave'] = 722;
  14257. t['Delta'] = 612;
  14258. t['thorn'] = 611;
  14259. t['twosuperior'] = 333;
  14260. t['Odieresis'] = 778;
  14261. t['mu'] = 611;
  14262. t['igrave'] = 278;
  14263. t['ohungarumlaut'] = 611;
  14264. t['Eogonek'] = 667;
  14265. t['dcroat'] = 611;
  14266. t['threequarters'] = 834;
  14267. t['Scedilla'] = 667;
  14268. t['lcaron'] = 400;
  14269. t['Kcommaaccent'] = 722;
  14270. t['Lacute'] = 611;
  14271. t['trademark'] = 1000;
  14272. t['edotaccent'] = 556;
  14273. t['Igrave'] = 278;
  14274. t['Imacron'] = 278;
  14275. t['Lcaron'] = 611;
  14276. t['onehalf'] = 834;
  14277. t['lessequal'] = 549;
  14278. t['ocircumflex'] = 611;
  14279. t['ntilde'] = 611;
  14280. t['Uhungarumlaut'] = 722;
  14281. t['Eacute'] = 667;
  14282. t['emacron'] = 556;
  14283. t['gbreve'] = 611;
  14284. t['onequarter'] = 834;
  14285. t['Scaron'] = 667;
  14286. t['Scommaaccent'] = 667;
  14287. t['Ohungarumlaut'] = 778;
  14288. t['degree'] = 400;
  14289. t['ograve'] = 611;
  14290. t['Ccaron'] = 722;
  14291. t['ugrave'] = 611;
  14292. t['radical'] = 549;
  14293. t['Dcaron'] = 722;
  14294. t['rcommaaccent'] = 389;
  14295. t['Ntilde'] = 722;
  14296. t['otilde'] = 611;
  14297. t['Rcommaaccent'] = 722;
  14298. t['Lcommaaccent'] = 611;
  14299. t['Atilde'] = 722;
  14300. t['Aogonek'] = 722;
  14301. t['Aring'] = 722;
  14302. t['Otilde'] = 778;
  14303. t['zdotaccent'] = 500;
  14304. t['Ecaron'] = 667;
  14305. t['Iogonek'] = 278;
  14306. t['kcommaaccent'] = 556;
  14307. t['minus'] = 584;
  14308. t['Icircumflex'] = 278;
  14309. t['ncaron'] = 611;
  14310. t['tcommaaccent'] = 333;
  14311. t['logicalnot'] = 584;
  14312. t['odieresis'] = 611;
  14313. t['udieresis'] = 611;
  14314. t['notequal'] = 549;
  14315. t['gcommaaccent'] = 611;
  14316. t['eth'] = 611;
  14317. t['zcaron'] = 500;
  14318. t['ncommaaccent'] = 611;
  14319. t['onesuperior'] = 333;
  14320. t['imacron'] = 278;
  14321. t['Euro'] = 556;
  14322. });
  14323. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14324. t['space'] = 278;
  14325. t['exclam'] = 333;
  14326. t['quotedbl'] = 474;
  14327. t['numbersign'] = 556;
  14328. t['dollar'] = 556;
  14329. t['percent'] = 889;
  14330. t['ampersand'] = 722;
  14331. t['quoteright'] = 278;
  14332. t['parenleft'] = 333;
  14333. t['parenright'] = 333;
  14334. t['asterisk'] = 389;
  14335. t['plus'] = 584;
  14336. t['comma'] = 278;
  14337. t['hyphen'] = 333;
  14338. t['period'] = 278;
  14339. t['slash'] = 278;
  14340. t['zero'] = 556;
  14341. t['one'] = 556;
  14342. t['two'] = 556;
  14343. t['three'] = 556;
  14344. t['four'] = 556;
  14345. t['five'] = 556;
  14346. t['six'] = 556;
  14347. t['seven'] = 556;
  14348. t['eight'] = 556;
  14349. t['nine'] = 556;
  14350. t['colon'] = 333;
  14351. t['semicolon'] = 333;
  14352. t['less'] = 584;
  14353. t['equal'] = 584;
  14354. t['greater'] = 584;
  14355. t['question'] = 611;
  14356. t['at'] = 975;
  14357. t['A'] = 722;
  14358. t['B'] = 722;
  14359. t['C'] = 722;
  14360. t['D'] = 722;
  14361. t['E'] = 667;
  14362. t['F'] = 611;
  14363. t['G'] = 778;
  14364. t['H'] = 722;
  14365. t['I'] = 278;
  14366. t['J'] = 556;
  14367. t['K'] = 722;
  14368. t['L'] = 611;
  14369. t['M'] = 833;
  14370. t['N'] = 722;
  14371. t['O'] = 778;
  14372. t['P'] = 667;
  14373. t['Q'] = 778;
  14374. t['R'] = 722;
  14375. t['S'] = 667;
  14376. t['T'] = 611;
  14377. t['U'] = 722;
  14378. t['V'] = 667;
  14379. t['W'] = 944;
  14380. t['X'] = 667;
  14381. t['Y'] = 667;
  14382. t['Z'] = 611;
  14383. t['bracketleft'] = 333;
  14384. t['backslash'] = 278;
  14385. t['bracketright'] = 333;
  14386. t['asciicircum'] = 584;
  14387. t['underscore'] = 556;
  14388. t['quoteleft'] = 278;
  14389. t['a'] = 556;
  14390. t['b'] = 611;
  14391. t['c'] = 556;
  14392. t['d'] = 611;
  14393. t['e'] = 556;
  14394. t['f'] = 333;
  14395. t['g'] = 611;
  14396. t['h'] = 611;
  14397. t['i'] = 278;
  14398. t['j'] = 278;
  14399. t['k'] = 556;
  14400. t['l'] = 278;
  14401. t['m'] = 889;
  14402. t['n'] = 611;
  14403. t['o'] = 611;
  14404. t['p'] = 611;
  14405. t['q'] = 611;
  14406. t['r'] = 389;
  14407. t['s'] = 556;
  14408. t['t'] = 333;
  14409. t['u'] = 611;
  14410. t['v'] = 556;
  14411. t['w'] = 778;
  14412. t['x'] = 556;
  14413. t['y'] = 556;
  14414. t['z'] = 500;
  14415. t['braceleft'] = 389;
  14416. t['bar'] = 280;
  14417. t['braceright'] = 389;
  14418. t['asciitilde'] = 584;
  14419. t['exclamdown'] = 333;
  14420. t['cent'] = 556;
  14421. t['sterling'] = 556;
  14422. t['fraction'] = 167;
  14423. t['yen'] = 556;
  14424. t['florin'] = 556;
  14425. t['section'] = 556;
  14426. t['currency'] = 556;
  14427. t['quotesingle'] = 238;
  14428. t['quotedblleft'] = 500;
  14429. t['guillemotleft'] = 556;
  14430. t['guilsinglleft'] = 333;
  14431. t['guilsinglright'] = 333;
  14432. t['fi'] = 611;
  14433. t['fl'] = 611;
  14434. t['endash'] = 556;
  14435. t['dagger'] = 556;
  14436. t['daggerdbl'] = 556;
  14437. t['periodcentered'] = 278;
  14438. t['paragraph'] = 556;
  14439. t['bullet'] = 350;
  14440. t['quotesinglbase'] = 278;
  14441. t['quotedblbase'] = 500;
  14442. t['quotedblright'] = 500;
  14443. t['guillemotright'] = 556;
  14444. t['ellipsis'] = 1000;
  14445. t['perthousand'] = 1000;
  14446. t['questiondown'] = 611;
  14447. t['grave'] = 333;
  14448. t['acute'] = 333;
  14449. t['circumflex'] = 333;
  14450. t['tilde'] = 333;
  14451. t['macron'] = 333;
  14452. t['breve'] = 333;
  14453. t['dotaccent'] = 333;
  14454. t['dieresis'] = 333;
  14455. t['ring'] = 333;
  14456. t['cedilla'] = 333;
  14457. t['hungarumlaut'] = 333;
  14458. t['ogonek'] = 333;
  14459. t['caron'] = 333;
  14460. t['emdash'] = 1000;
  14461. t['AE'] = 1000;
  14462. t['ordfeminine'] = 370;
  14463. t['Lslash'] = 611;
  14464. t['Oslash'] = 778;
  14465. t['OE'] = 1000;
  14466. t['ordmasculine'] = 365;
  14467. t['ae'] = 889;
  14468. t['dotlessi'] = 278;
  14469. t['lslash'] = 278;
  14470. t['oslash'] = 611;
  14471. t['oe'] = 944;
  14472. t['germandbls'] = 611;
  14473. t['Idieresis'] = 278;
  14474. t['eacute'] = 556;
  14475. t['abreve'] = 556;
  14476. t['uhungarumlaut'] = 611;
  14477. t['ecaron'] = 556;
  14478. t['Ydieresis'] = 667;
  14479. t['divide'] = 584;
  14480. t['Yacute'] = 667;
  14481. t['Acircumflex'] = 722;
  14482. t['aacute'] = 556;
  14483. t['Ucircumflex'] = 722;
  14484. t['yacute'] = 556;
  14485. t['scommaaccent'] = 556;
  14486. t['ecircumflex'] = 556;
  14487. t['Uring'] = 722;
  14488. t['Udieresis'] = 722;
  14489. t['aogonek'] = 556;
  14490. t['Uacute'] = 722;
  14491. t['uogonek'] = 611;
  14492. t['Edieresis'] = 667;
  14493. t['Dcroat'] = 722;
  14494. t['commaaccent'] = 250;
  14495. t['copyright'] = 737;
  14496. t['Emacron'] = 667;
  14497. t['ccaron'] = 556;
  14498. t['aring'] = 556;
  14499. t['Ncommaaccent'] = 722;
  14500. t['lacute'] = 278;
  14501. t['agrave'] = 556;
  14502. t['Tcommaaccent'] = 611;
  14503. t['Cacute'] = 722;
  14504. t['atilde'] = 556;
  14505. t['Edotaccent'] = 667;
  14506. t['scaron'] = 556;
  14507. t['scedilla'] = 556;
  14508. t['iacute'] = 278;
  14509. t['lozenge'] = 494;
  14510. t['Rcaron'] = 722;
  14511. t['Gcommaaccent'] = 778;
  14512. t['ucircumflex'] = 611;
  14513. t['acircumflex'] = 556;
  14514. t['Amacron'] = 722;
  14515. t['rcaron'] = 389;
  14516. t['ccedilla'] = 556;
  14517. t['Zdotaccent'] = 611;
  14518. t['Thorn'] = 667;
  14519. t['Omacron'] = 778;
  14520. t['Racute'] = 722;
  14521. t['Sacute'] = 667;
  14522. t['dcaron'] = 743;
  14523. t['Umacron'] = 722;
  14524. t['uring'] = 611;
  14525. t['threesuperior'] = 333;
  14526. t['Ograve'] = 778;
  14527. t['Agrave'] = 722;
  14528. t['Abreve'] = 722;
  14529. t['multiply'] = 584;
  14530. t['uacute'] = 611;
  14531. t['Tcaron'] = 611;
  14532. t['partialdiff'] = 494;
  14533. t['ydieresis'] = 556;
  14534. t['Nacute'] = 722;
  14535. t['icircumflex'] = 278;
  14536. t['Ecircumflex'] = 667;
  14537. t['adieresis'] = 556;
  14538. t['edieresis'] = 556;
  14539. t['cacute'] = 556;
  14540. t['nacute'] = 611;
  14541. t['umacron'] = 611;
  14542. t['Ncaron'] = 722;
  14543. t['Iacute'] = 278;
  14544. t['plusminus'] = 584;
  14545. t['brokenbar'] = 280;
  14546. t['registered'] = 737;
  14547. t['Gbreve'] = 778;
  14548. t['Idotaccent'] = 278;
  14549. t['summation'] = 600;
  14550. t['Egrave'] = 667;
  14551. t['racute'] = 389;
  14552. t['omacron'] = 611;
  14553. t['Zacute'] = 611;
  14554. t['Zcaron'] = 611;
  14555. t['greaterequal'] = 549;
  14556. t['Eth'] = 722;
  14557. t['Ccedilla'] = 722;
  14558. t['lcommaaccent'] = 278;
  14559. t['tcaron'] = 389;
  14560. t['eogonek'] = 556;
  14561. t['Uogonek'] = 722;
  14562. t['Aacute'] = 722;
  14563. t['Adieresis'] = 722;
  14564. t['egrave'] = 556;
  14565. t['zacute'] = 500;
  14566. t['iogonek'] = 278;
  14567. t['Oacute'] = 778;
  14568. t['oacute'] = 611;
  14569. t['amacron'] = 556;
  14570. t['sacute'] = 556;
  14571. t['idieresis'] = 278;
  14572. t['Ocircumflex'] = 778;
  14573. t['Ugrave'] = 722;
  14574. t['Delta'] = 612;
  14575. t['thorn'] = 611;
  14576. t['twosuperior'] = 333;
  14577. t['Odieresis'] = 778;
  14578. t['mu'] = 611;
  14579. t['igrave'] = 278;
  14580. t['ohungarumlaut'] = 611;
  14581. t['Eogonek'] = 667;
  14582. t['dcroat'] = 611;
  14583. t['threequarters'] = 834;
  14584. t['Scedilla'] = 667;
  14585. t['lcaron'] = 400;
  14586. t['Kcommaaccent'] = 722;
  14587. t['Lacute'] = 611;
  14588. t['trademark'] = 1000;
  14589. t['edotaccent'] = 556;
  14590. t['Igrave'] = 278;
  14591. t['Imacron'] = 278;
  14592. t['Lcaron'] = 611;
  14593. t['onehalf'] = 834;
  14594. t['lessequal'] = 549;
  14595. t['ocircumflex'] = 611;
  14596. t['ntilde'] = 611;
  14597. t['Uhungarumlaut'] = 722;
  14598. t['Eacute'] = 667;
  14599. t['emacron'] = 556;
  14600. t['gbreve'] = 611;
  14601. t['onequarter'] = 834;
  14602. t['Scaron'] = 667;
  14603. t['Scommaaccent'] = 667;
  14604. t['Ohungarumlaut'] = 778;
  14605. t['degree'] = 400;
  14606. t['ograve'] = 611;
  14607. t['Ccaron'] = 722;
  14608. t['ugrave'] = 611;
  14609. t['radical'] = 549;
  14610. t['Dcaron'] = 722;
  14611. t['rcommaaccent'] = 389;
  14612. t['Ntilde'] = 722;
  14613. t['otilde'] = 611;
  14614. t['Rcommaaccent'] = 722;
  14615. t['Lcommaaccent'] = 611;
  14616. t['Atilde'] = 722;
  14617. t['Aogonek'] = 722;
  14618. t['Aring'] = 722;
  14619. t['Otilde'] = 778;
  14620. t['zdotaccent'] = 500;
  14621. t['Ecaron'] = 667;
  14622. t['Iogonek'] = 278;
  14623. t['kcommaaccent'] = 556;
  14624. t['minus'] = 584;
  14625. t['Icircumflex'] = 278;
  14626. t['ncaron'] = 611;
  14627. t['tcommaaccent'] = 333;
  14628. t['logicalnot'] = 584;
  14629. t['odieresis'] = 611;
  14630. t['udieresis'] = 611;
  14631. t['notequal'] = 549;
  14632. t['gcommaaccent'] = 611;
  14633. t['eth'] = 611;
  14634. t['zcaron'] = 500;
  14635. t['ncommaaccent'] = 611;
  14636. t['onesuperior'] = 333;
  14637. t['imacron'] = 278;
  14638. t['Euro'] = 556;
  14639. });
  14640. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14641. t['space'] = 278;
  14642. t['exclam'] = 278;
  14643. t['quotedbl'] = 355;
  14644. t['numbersign'] = 556;
  14645. t['dollar'] = 556;
  14646. t['percent'] = 889;
  14647. t['ampersand'] = 667;
  14648. t['quoteright'] = 222;
  14649. t['parenleft'] = 333;
  14650. t['parenright'] = 333;
  14651. t['asterisk'] = 389;
  14652. t['plus'] = 584;
  14653. t['comma'] = 278;
  14654. t['hyphen'] = 333;
  14655. t['period'] = 278;
  14656. t['slash'] = 278;
  14657. t['zero'] = 556;
  14658. t['one'] = 556;
  14659. t['two'] = 556;
  14660. t['three'] = 556;
  14661. t['four'] = 556;
  14662. t['five'] = 556;
  14663. t['six'] = 556;
  14664. t['seven'] = 556;
  14665. t['eight'] = 556;
  14666. t['nine'] = 556;
  14667. t['colon'] = 278;
  14668. t['semicolon'] = 278;
  14669. t['less'] = 584;
  14670. t['equal'] = 584;
  14671. t['greater'] = 584;
  14672. t['question'] = 556;
  14673. t['at'] = 1015;
  14674. t['A'] = 667;
  14675. t['B'] = 667;
  14676. t['C'] = 722;
  14677. t['D'] = 722;
  14678. t['E'] = 667;
  14679. t['F'] = 611;
  14680. t['G'] = 778;
  14681. t['H'] = 722;
  14682. t['I'] = 278;
  14683. t['J'] = 500;
  14684. t['K'] = 667;
  14685. t['L'] = 556;
  14686. t['M'] = 833;
  14687. t['N'] = 722;
  14688. t['O'] = 778;
  14689. t['P'] = 667;
  14690. t['Q'] = 778;
  14691. t['R'] = 722;
  14692. t['S'] = 667;
  14693. t['T'] = 611;
  14694. t['U'] = 722;
  14695. t['V'] = 667;
  14696. t['W'] = 944;
  14697. t['X'] = 667;
  14698. t['Y'] = 667;
  14699. t['Z'] = 611;
  14700. t['bracketleft'] = 278;
  14701. t['backslash'] = 278;
  14702. t['bracketright'] = 278;
  14703. t['asciicircum'] = 469;
  14704. t['underscore'] = 556;
  14705. t['quoteleft'] = 222;
  14706. t['a'] = 556;
  14707. t['b'] = 556;
  14708. t['c'] = 500;
  14709. t['d'] = 556;
  14710. t['e'] = 556;
  14711. t['f'] = 278;
  14712. t['g'] = 556;
  14713. t['h'] = 556;
  14714. t['i'] = 222;
  14715. t['j'] = 222;
  14716. t['k'] = 500;
  14717. t['l'] = 222;
  14718. t['m'] = 833;
  14719. t['n'] = 556;
  14720. t['o'] = 556;
  14721. t['p'] = 556;
  14722. t['q'] = 556;
  14723. t['r'] = 333;
  14724. t['s'] = 500;
  14725. t['t'] = 278;
  14726. t['u'] = 556;
  14727. t['v'] = 500;
  14728. t['w'] = 722;
  14729. t['x'] = 500;
  14730. t['y'] = 500;
  14731. t['z'] = 500;
  14732. t['braceleft'] = 334;
  14733. t['bar'] = 260;
  14734. t['braceright'] = 334;
  14735. t['asciitilde'] = 584;
  14736. t['exclamdown'] = 333;
  14737. t['cent'] = 556;
  14738. t['sterling'] = 556;
  14739. t['fraction'] = 167;
  14740. t['yen'] = 556;
  14741. t['florin'] = 556;
  14742. t['section'] = 556;
  14743. t['currency'] = 556;
  14744. t['quotesingle'] = 191;
  14745. t['quotedblleft'] = 333;
  14746. t['guillemotleft'] = 556;
  14747. t['guilsinglleft'] = 333;
  14748. t['guilsinglright'] = 333;
  14749. t['fi'] = 500;
  14750. t['fl'] = 500;
  14751. t['endash'] = 556;
  14752. t['dagger'] = 556;
  14753. t['daggerdbl'] = 556;
  14754. t['periodcentered'] = 278;
  14755. t['paragraph'] = 537;
  14756. t['bullet'] = 350;
  14757. t['quotesinglbase'] = 222;
  14758. t['quotedblbase'] = 333;
  14759. t['quotedblright'] = 333;
  14760. t['guillemotright'] = 556;
  14761. t['ellipsis'] = 1000;
  14762. t['perthousand'] = 1000;
  14763. t['questiondown'] = 611;
  14764. t['grave'] = 333;
  14765. t['acute'] = 333;
  14766. t['circumflex'] = 333;
  14767. t['tilde'] = 333;
  14768. t['macron'] = 333;
  14769. t['breve'] = 333;
  14770. t['dotaccent'] = 333;
  14771. t['dieresis'] = 333;
  14772. t['ring'] = 333;
  14773. t['cedilla'] = 333;
  14774. t['hungarumlaut'] = 333;
  14775. t['ogonek'] = 333;
  14776. t['caron'] = 333;
  14777. t['emdash'] = 1000;
  14778. t['AE'] = 1000;
  14779. t['ordfeminine'] = 370;
  14780. t['Lslash'] = 556;
  14781. t['Oslash'] = 778;
  14782. t['OE'] = 1000;
  14783. t['ordmasculine'] = 365;
  14784. t['ae'] = 889;
  14785. t['dotlessi'] = 278;
  14786. t['lslash'] = 222;
  14787. t['oslash'] = 611;
  14788. t['oe'] = 944;
  14789. t['germandbls'] = 611;
  14790. t['Idieresis'] = 278;
  14791. t['eacute'] = 556;
  14792. t['abreve'] = 556;
  14793. t['uhungarumlaut'] = 556;
  14794. t['ecaron'] = 556;
  14795. t['Ydieresis'] = 667;
  14796. t['divide'] = 584;
  14797. t['Yacute'] = 667;
  14798. t['Acircumflex'] = 667;
  14799. t['aacute'] = 556;
  14800. t['Ucircumflex'] = 722;
  14801. t['yacute'] = 500;
  14802. t['scommaaccent'] = 500;
  14803. t['ecircumflex'] = 556;
  14804. t['Uring'] = 722;
  14805. t['Udieresis'] = 722;
  14806. t['aogonek'] = 556;
  14807. t['Uacute'] = 722;
  14808. t['uogonek'] = 556;
  14809. t['Edieresis'] = 667;
  14810. t['Dcroat'] = 722;
  14811. t['commaaccent'] = 250;
  14812. t['copyright'] = 737;
  14813. t['Emacron'] = 667;
  14814. t['ccaron'] = 500;
  14815. t['aring'] = 556;
  14816. t['Ncommaaccent'] = 722;
  14817. t['lacute'] = 222;
  14818. t['agrave'] = 556;
  14819. t['Tcommaaccent'] = 611;
  14820. t['Cacute'] = 722;
  14821. t['atilde'] = 556;
  14822. t['Edotaccent'] = 667;
  14823. t['scaron'] = 500;
  14824. t['scedilla'] = 500;
  14825. t['iacute'] = 278;
  14826. t['lozenge'] = 471;
  14827. t['Rcaron'] = 722;
  14828. t['Gcommaaccent'] = 778;
  14829. t['ucircumflex'] = 556;
  14830. t['acircumflex'] = 556;
  14831. t['Amacron'] = 667;
  14832. t['rcaron'] = 333;
  14833. t['ccedilla'] = 500;
  14834. t['Zdotaccent'] = 611;
  14835. t['Thorn'] = 667;
  14836. t['Omacron'] = 778;
  14837. t['Racute'] = 722;
  14838. t['Sacute'] = 667;
  14839. t['dcaron'] = 643;
  14840. t['Umacron'] = 722;
  14841. t['uring'] = 556;
  14842. t['threesuperior'] = 333;
  14843. t['Ograve'] = 778;
  14844. t['Agrave'] = 667;
  14845. t['Abreve'] = 667;
  14846. t['multiply'] = 584;
  14847. t['uacute'] = 556;
  14848. t['Tcaron'] = 611;
  14849. t['partialdiff'] = 476;
  14850. t['ydieresis'] = 500;
  14851. t['Nacute'] = 722;
  14852. t['icircumflex'] = 278;
  14853. t['Ecircumflex'] = 667;
  14854. t['adieresis'] = 556;
  14855. t['edieresis'] = 556;
  14856. t['cacute'] = 500;
  14857. t['nacute'] = 556;
  14858. t['umacron'] = 556;
  14859. t['Ncaron'] = 722;
  14860. t['Iacute'] = 278;
  14861. t['plusminus'] = 584;
  14862. t['brokenbar'] = 260;
  14863. t['registered'] = 737;
  14864. t['Gbreve'] = 778;
  14865. t['Idotaccent'] = 278;
  14866. t['summation'] = 600;
  14867. t['Egrave'] = 667;
  14868. t['racute'] = 333;
  14869. t['omacron'] = 556;
  14870. t['Zacute'] = 611;
  14871. t['Zcaron'] = 611;
  14872. t['greaterequal'] = 549;
  14873. t['Eth'] = 722;
  14874. t['Ccedilla'] = 722;
  14875. t['lcommaaccent'] = 222;
  14876. t['tcaron'] = 317;
  14877. t['eogonek'] = 556;
  14878. t['Uogonek'] = 722;
  14879. t['Aacute'] = 667;
  14880. t['Adieresis'] = 667;
  14881. t['egrave'] = 556;
  14882. t['zacute'] = 500;
  14883. t['iogonek'] = 222;
  14884. t['Oacute'] = 778;
  14885. t['oacute'] = 556;
  14886. t['amacron'] = 556;
  14887. t['sacute'] = 500;
  14888. t['idieresis'] = 278;
  14889. t['Ocircumflex'] = 778;
  14890. t['Ugrave'] = 722;
  14891. t['Delta'] = 612;
  14892. t['thorn'] = 556;
  14893. t['twosuperior'] = 333;
  14894. t['Odieresis'] = 778;
  14895. t['mu'] = 556;
  14896. t['igrave'] = 278;
  14897. t['ohungarumlaut'] = 556;
  14898. t['Eogonek'] = 667;
  14899. t['dcroat'] = 556;
  14900. t['threequarters'] = 834;
  14901. t['Scedilla'] = 667;
  14902. t['lcaron'] = 299;
  14903. t['Kcommaaccent'] = 667;
  14904. t['Lacute'] = 556;
  14905. t['trademark'] = 1000;
  14906. t['edotaccent'] = 556;
  14907. t['Igrave'] = 278;
  14908. t['Imacron'] = 278;
  14909. t['Lcaron'] = 556;
  14910. t['onehalf'] = 834;
  14911. t['lessequal'] = 549;
  14912. t['ocircumflex'] = 556;
  14913. t['ntilde'] = 556;
  14914. t['Uhungarumlaut'] = 722;
  14915. t['Eacute'] = 667;
  14916. t['emacron'] = 556;
  14917. t['gbreve'] = 556;
  14918. t['onequarter'] = 834;
  14919. t['Scaron'] = 667;
  14920. t['Scommaaccent'] = 667;
  14921. t['Ohungarumlaut'] = 778;
  14922. t['degree'] = 400;
  14923. t['ograve'] = 556;
  14924. t['Ccaron'] = 722;
  14925. t['ugrave'] = 556;
  14926. t['radical'] = 453;
  14927. t['Dcaron'] = 722;
  14928. t['rcommaaccent'] = 333;
  14929. t['Ntilde'] = 722;
  14930. t['otilde'] = 556;
  14931. t['Rcommaaccent'] = 722;
  14932. t['Lcommaaccent'] = 556;
  14933. t['Atilde'] = 667;
  14934. t['Aogonek'] = 667;
  14935. t['Aring'] = 667;
  14936. t['Otilde'] = 778;
  14937. t['zdotaccent'] = 500;
  14938. t['Ecaron'] = 667;
  14939. t['Iogonek'] = 278;
  14940. t['kcommaaccent'] = 500;
  14941. t['minus'] = 584;
  14942. t['Icircumflex'] = 278;
  14943. t['ncaron'] = 556;
  14944. t['tcommaaccent'] = 278;
  14945. t['logicalnot'] = 584;
  14946. t['odieresis'] = 556;
  14947. t['udieresis'] = 556;
  14948. t['notequal'] = 549;
  14949. t['gcommaaccent'] = 556;
  14950. t['eth'] = 556;
  14951. t['zcaron'] = 500;
  14952. t['ncommaaccent'] = 556;
  14953. t['onesuperior'] = 333;
  14954. t['imacron'] = 278;
  14955. t['Euro'] = 556;
  14956. });
  14957. t['Symbol'] = getLookupTableFactory(function (t) {
  14958. t['space'] = 250;
  14959. t['exclam'] = 333;
  14960. t['universal'] = 713;
  14961. t['numbersign'] = 500;
  14962. t['existential'] = 549;
  14963. t['percent'] = 833;
  14964. t['ampersand'] = 778;
  14965. t['suchthat'] = 439;
  14966. t['parenleft'] = 333;
  14967. t['parenright'] = 333;
  14968. t['asteriskmath'] = 500;
  14969. t['plus'] = 549;
  14970. t['comma'] = 250;
  14971. t['minus'] = 549;
  14972. t['period'] = 250;
  14973. t['slash'] = 278;
  14974. t['zero'] = 500;
  14975. t['one'] = 500;
  14976. t['two'] = 500;
  14977. t['three'] = 500;
  14978. t['four'] = 500;
  14979. t['five'] = 500;
  14980. t['six'] = 500;
  14981. t['seven'] = 500;
  14982. t['eight'] = 500;
  14983. t['nine'] = 500;
  14984. t['colon'] = 278;
  14985. t['semicolon'] = 278;
  14986. t['less'] = 549;
  14987. t['equal'] = 549;
  14988. t['greater'] = 549;
  14989. t['question'] = 444;
  14990. t['congruent'] = 549;
  14991. t['Alpha'] = 722;
  14992. t['Beta'] = 667;
  14993. t['Chi'] = 722;
  14994. t['Delta'] = 612;
  14995. t['Epsilon'] = 611;
  14996. t['Phi'] = 763;
  14997. t['Gamma'] = 603;
  14998. t['Eta'] = 722;
  14999. t['Iota'] = 333;
  15000. t['theta1'] = 631;
  15001. t['Kappa'] = 722;
  15002. t['Lambda'] = 686;
  15003. t['Mu'] = 889;
  15004. t['Nu'] = 722;
  15005. t['Omicron'] = 722;
  15006. t['Pi'] = 768;
  15007. t['Theta'] = 741;
  15008. t['Rho'] = 556;
  15009. t['Sigma'] = 592;
  15010. t['Tau'] = 611;
  15011. t['Upsilon'] = 690;
  15012. t['sigma1'] = 439;
  15013. t['Omega'] = 768;
  15014. t['Xi'] = 645;
  15015. t['Psi'] = 795;
  15016. t['Zeta'] = 611;
  15017. t['bracketleft'] = 333;
  15018. t['therefore'] = 863;
  15019. t['bracketright'] = 333;
  15020. t['perpendicular'] = 658;
  15021. t['underscore'] = 500;
  15022. t['radicalex'] = 500;
  15023. t['alpha'] = 631;
  15024. t['beta'] = 549;
  15025. t['chi'] = 549;
  15026. t['delta'] = 494;
  15027. t['epsilon'] = 439;
  15028. t['phi'] = 521;
  15029. t['gamma'] = 411;
  15030. t['eta'] = 603;
  15031. t['iota'] = 329;
  15032. t['phi1'] = 603;
  15033. t['kappa'] = 549;
  15034. t['lambda'] = 549;
  15035. t['mu'] = 576;
  15036. t['nu'] = 521;
  15037. t['omicron'] = 549;
  15038. t['pi'] = 549;
  15039. t['theta'] = 521;
  15040. t['rho'] = 549;
  15041. t['sigma'] = 603;
  15042. t['tau'] = 439;
  15043. t['upsilon'] = 576;
  15044. t['omega1'] = 713;
  15045. t['omega'] = 686;
  15046. t['xi'] = 493;
  15047. t['psi'] = 686;
  15048. t['zeta'] = 494;
  15049. t['braceleft'] = 480;
  15050. t['bar'] = 200;
  15051. t['braceright'] = 480;
  15052. t['similar'] = 549;
  15053. t['Euro'] = 750;
  15054. t['Upsilon1'] = 620;
  15055. t['minute'] = 247;
  15056. t['lessequal'] = 549;
  15057. t['fraction'] = 167;
  15058. t['infinity'] = 713;
  15059. t['florin'] = 500;
  15060. t['club'] = 753;
  15061. t['diamond'] = 753;
  15062. t['heart'] = 753;
  15063. t['spade'] = 753;
  15064. t['arrowboth'] = 1042;
  15065. t['arrowleft'] = 987;
  15066. t['arrowup'] = 603;
  15067. t['arrowright'] = 987;
  15068. t['arrowdown'] = 603;
  15069. t['degree'] = 400;
  15070. t['plusminus'] = 549;
  15071. t['second'] = 411;
  15072. t['greaterequal'] = 549;
  15073. t['multiply'] = 549;
  15074. t['proportional'] = 713;
  15075. t['partialdiff'] = 494;
  15076. t['bullet'] = 460;
  15077. t['divide'] = 549;
  15078. t['notequal'] = 549;
  15079. t['equivalence'] = 549;
  15080. t['approxequal'] = 549;
  15081. t['ellipsis'] = 1000;
  15082. t['arrowvertex'] = 603;
  15083. t['arrowhorizex'] = 1000;
  15084. t['carriagereturn'] = 658;
  15085. t['aleph'] = 823;
  15086. t['Ifraktur'] = 686;
  15087. t['Rfraktur'] = 795;
  15088. t['weierstrass'] = 987;
  15089. t['circlemultiply'] = 768;
  15090. t['circleplus'] = 768;
  15091. t['emptyset'] = 823;
  15092. t['intersection'] = 768;
  15093. t['union'] = 768;
  15094. t['propersuperset'] = 713;
  15095. t['reflexsuperset'] = 713;
  15096. t['notsubset'] = 713;
  15097. t['propersubset'] = 713;
  15098. t['reflexsubset'] = 713;
  15099. t['element'] = 713;
  15100. t['notelement'] = 713;
  15101. t['angle'] = 768;
  15102. t['gradient'] = 713;
  15103. t['registerserif'] = 790;
  15104. t['copyrightserif'] = 790;
  15105. t['trademarkserif'] = 890;
  15106. t['product'] = 823;
  15107. t['radical'] = 549;
  15108. t['dotmath'] = 250;
  15109. t['logicalnot'] = 713;
  15110. t['logicaland'] = 603;
  15111. t['logicalor'] = 603;
  15112. t['arrowdblboth'] = 1042;
  15113. t['arrowdblleft'] = 987;
  15114. t['arrowdblup'] = 603;
  15115. t['arrowdblright'] = 987;
  15116. t['arrowdbldown'] = 603;
  15117. t['lozenge'] = 494;
  15118. t['angleleft'] = 329;
  15119. t['registersans'] = 790;
  15120. t['copyrightsans'] = 790;
  15121. t['trademarksans'] = 786;
  15122. t['summation'] = 713;
  15123. t['parenlefttp'] = 384;
  15124. t['parenleftex'] = 384;
  15125. t['parenleftbt'] = 384;
  15126. t['bracketlefttp'] = 384;
  15127. t['bracketleftex'] = 384;
  15128. t['bracketleftbt'] = 384;
  15129. t['bracelefttp'] = 494;
  15130. t['braceleftmid'] = 494;
  15131. t['braceleftbt'] = 494;
  15132. t['braceex'] = 494;
  15133. t['angleright'] = 329;
  15134. t['integral'] = 274;
  15135. t['integraltp'] = 686;
  15136. t['integralex'] = 686;
  15137. t['integralbt'] = 686;
  15138. t['parenrighttp'] = 384;
  15139. t['parenrightex'] = 384;
  15140. t['parenrightbt'] = 384;
  15141. t['bracketrighttp'] = 384;
  15142. t['bracketrightex'] = 384;
  15143. t['bracketrightbt'] = 384;
  15144. t['bracerighttp'] = 494;
  15145. t['bracerightmid'] = 494;
  15146. t['bracerightbt'] = 494;
  15147. t['apple'] = 790;
  15148. });
  15149. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15150. t['space'] = 250;
  15151. t['exclam'] = 333;
  15152. t['quotedbl'] = 408;
  15153. t['numbersign'] = 500;
  15154. t['dollar'] = 500;
  15155. t['percent'] = 833;
  15156. t['ampersand'] = 778;
  15157. t['quoteright'] = 333;
  15158. t['parenleft'] = 333;
  15159. t['parenright'] = 333;
  15160. t['asterisk'] = 500;
  15161. t['plus'] = 564;
  15162. t['comma'] = 250;
  15163. t['hyphen'] = 333;
  15164. t['period'] = 250;
  15165. t['slash'] = 278;
  15166. t['zero'] = 500;
  15167. t['one'] = 500;
  15168. t['two'] = 500;
  15169. t['three'] = 500;
  15170. t['four'] = 500;
  15171. t['five'] = 500;
  15172. t['six'] = 500;
  15173. t['seven'] = 500;
  15174. t['eight'] = 500;
  15175. t['nine'] = 500;
  15176. t['colon'] = 278;
  15177. t['semicolon'] = 278;
  15178. t['less'] = 564;
  15179. t['equal'] = 564;
  15180. t['greater'] = 564;
  15181. t['question'] = 444;
  15182. t['at'] = 921;
  15183. t['A'] = 722;
  15184. t['B'] = 667;
  15185. t['C'] = 667;
  15186. t['D'] = 722;
  15187. t['E'] = 611;
  15188. t['F'] = 556;
  15189. t['G'] = 722;
  15190. t['H'] = 722;
  15191. t['I'] = 333;
  15192. t['J'] = 389;
  15193. t['K'] = 722;
  15194. t['L'] = 611;
  15195. t['M'] = 889;
  15196. t['N'] = 722;
  15197. t['O'] = 722;
  15198. t['P'] = 556;
  15199. t['Q'] = 722;
  15200. t['R'] = 667;
  15201. t['S'] = 556;
  15202. t['T'] = 611;
  15203. t['U'] = 722;
  15204. t['V'] = 722;
  15205. t['W'] = 944;
  15206. t['X'] = 722;
  15207. t['Y'] = 722;
  15208. t['Z'] = 611;
  15209. t['bracketleft'] = 333;
  15210. t['backslash'] = 278;
  15211. t['bracketright'] = 333;
  15212. t['asciicircum'] = 469;
  15213. t['underscore'] = 500;
  15214. t['quoteleft'] = 333;
  15215. t['a'] = 444;
  15216. t['b'] = 500;
  15217. t['c'] = 444;
  15218. t['d'] = 500;
  15219. t['e'] = 444;
  15220. t['f'] = 333;
  15221. t['g'] = 500;
  15222. t['h'] = 500;
  15223. t['i'] = 278;
  15224. t['j'] = 278;
  15225. t['k'] = 500;
  15226. t['l'] = 278;
  15227. t['m'] = 778;
  15228. t['n'] = 500;
  15229. t['o'] = 500;
  15230. t['p'] = 500;
  15231. t['q'] = 500;
  15232. t['r'] = 333;
  15233. t['s'] = 389;
  15234. t['t'] = 278;
  15235. t['u'] = 500;
  15236. t['v'] = 500;
  15237. t['w'] = 722;
  15238. t['x'] = 500;
  15239. t['y'] = 500;
  15240. t['z'] = 444;
  15241. t['braceleft'] = 480;
  15242. t['bar'] = 200;
  15243. t['braceright'] = 480;
  15244. t['asciitilde'] = 541;
  15245. t['exclamdown'] = 333;
  15246. t['cent'] = 500;
  15247. t['sterling'] = 500;
  15248. t['fraction'] = 167;
  15249. t['yen'] = 500;
  15250. t['florin'] = 500;
  15251. t['section'] = 500;
  15252. t['currency'] = 500;
  15253. t['quotesingle'] = 180;
  15254. t['quotedblleft'] = 444;
  15255. t['guillemotleft'] = 500;
  15256. t['guilsinglleft'] = 333;
  15257. t['guilsinglright'] = 333;
  15258. t['fi'] = 556;
  15259. t['fl'] = 556;
  15260. t['endash'] = 500;
  15261. t['dagger'] = 500;
  15262. t['daggerdbl'] = 500;
  15263. t['periodcentered'] = 250;
  15264. t['paragraph'] = 453;
  15265. t['bullet'] = 350;
  15266. t['quotesinglbase'] = 333;
  15267. t['quotedblbase'] = 444;
  15268. t['quotedblright'] = 444;
  15269. t['guillemotright'] = 500;
  15270. t['ellipsis'] = 1000;
  15271. t['perthousand'] = 1000;
  15272. t['questiondown'] = 444;
  15273. t['grave'] = 333;
  15274. t['acute'] = 333;
  15275. t['circumflex'] = 333;
  15276. t['tilde'] = 333;
  15277. t['macron'] = 333;
  15278. t['breve'] = 333;
  15279. t['dotaccent'] = 333;
  15280. t['dieresis'] = 333;
  15281. t['ring'] = 333;
  15282. t['cedilla'] = 333;
  15283. t['hungarumlaut'] = 333;
  15284. t['ogonek'] = 333;
  15285. t['caron'] = 333;
  15286. t['emdash'] = 1000;
  15287. t['AE'] = 889;
  15288. t['ordfeminine'] = 276;
  15289. t['Lslash'] = 611;
  15290. t['Oslash'] = 722;
  15291. t['OE'] = 889;
  15292. t['ordmasculine'] = 310;
  15293. t['ae'] = 667;
  15294. t['dotlessi'] = 278;
  15295. t['lslash'] = 278;
  15296. t['oslash'] = 500;
  15297. t['oe'] = 722;
  15298. t['germandbls'] = 500;
  15299. t['Idieresis'] = 333;
  15300. t['eacute'] = 444;
  15301. t['abreve'] = 444;
  15302. t['uhungarumlaut'] = 500;
  15303. t['ecaron'] = 444;
  15304. t['Ydieresis'] = 722;
  15305. t['divide'] = 564;
  15306. t['Yacute'] = 722;
  15307. t['Acircumflex'] = 722;
  15308. t['aacute'] = 444;
  15309. t['Ucircumflex'] = 722;
  15310. t['yacute'] = 500;
  15311. t['scommaaccent'] = 389;
  15312. t['ecircumflex'] = 444;
  15313. t['Uring'] = 722;
  15314. t['Udieresis'] = 722;
  15315. t['aogonek'] = 444;
  15316. t['Uacute'] = 722;
  15317. t['uogonek'] = 500;
  15318. t['Edieresis'] = 611;
  15319. t['Dcroat'] = 722;
  15320. t['commaaccent'] = 250;
  15321. t['copyright'] = 760;
  15322. t['Emacron'] = 611;
  15323. t['ccaron'] = 444;
  15324. t['aring'] = 444;
  15325. t['Ncommaaccent'] = 722;
  15326. t['lacute'] = 278;
  15327. t['agrave'] = 444;
  15328. t['Tcommaaccent'] = 611;
  15329. t['Cacute'] = 667;
  15330. t['atilde'] = 444;
  15331. t['Edotaccent'] = 611;
  15332. t['scaron'] = 389;
  15333. t['scedilla'] = 389;
  15334. t['iacute'] = 278;
  15335. t['lozenge'] = 471;
  15336. t['Rcaron'] = 667;
  15337. t['Gcommaaccent'] = 722;
  15338. t['ucircumflex'] = 500;
  15339. t['acircumflex'] = 444;
  15340. t['Amacron'] = 722;
  15341. t['rcaron'] = 333;
  15342. t['ccedilla'] = 444;
  15343. t['Zdotaccent'] = 611;
  15344. t['Thorn'] = 556;
  15345. t['Omacron'] = 722;
  15346. t['Racute'] = 667;
  15347. t['Sacute'] = 556;
  15348. t['dcaron'] = 588;
  15349. t['Umacron'] = 722;
  15350. t['uring'] = 500;
  15351. t['threesuperior'] = 300;
  15352. t['Ograve'] = 722;
  15353. t['Agrave'] = 722;
  15354. t['Abreve'] = 722;
  15355. t['multiply'] = 564;
  15356. t['uacute'] = 500;
  15357. t['Tcaron'] = 611;
  15358. t['partialdiff'] = 476;
  15359. t['ydieresis'] = 500;
  15360. t['Nacute'] = 722;
  15361. t['icircumflex'] = 278;
  15362. t['Ecircumflex'] = 611;
  15363. t['adieresis'] = 444;
  15364. t['edieresis'] = 444;
  15365. t['cacute'] = 444;
  15366. t['nacute'] = 500;
  15367. t['umacron'] = 500;
  15368. t['Ncaron'] = 722;
  15369. t['Iacute'] = 333;
  15370. t['plusminus'] = 564;
  15371. t['brokenbar'] = 200;
  15372. t['registered'] = 760;
  15373. t['Gbreve'] = 722;
  15374. t['Idotaccent'] = 333;
  15375. t['summation'] = 600;
  15376. t['Egrave'] = 611;
  15377. t['racute'] = 333;
  15378. t['omacron'] = 500;
  15379. t['Zacute'] = 611;
  15380. t['Zcaron'] = 611;
  15381. t['greaterequal'] = 549;
  15382. t['Eth'] = 722;
  15383. t['Ccedilla'] = 667;
  15384. t['lcommaaccent'] = 278;
  15385. t['tcaron'] = 326;
  15386. t['eogonek'] = 444;
  15387. t['Uogonek'] = 722;
  15388. t['Aacute'] = 722;
  15389. t['Adieresis'] = 722;
  15390. t['egrave'] = 444;
  15391. t['zacute'] = 444;
  15392. t['iogonek'] = 278;
  15393. t['Oacute'] = 722;
  15394. t['oacute'] = 500;
  15395. t['amacron'] = 444;
  15396. t['sacute'] = 389;
  15397. t['idieresis'] = 278;
  15398. t['Ocircumflex'] = 722;
  15399. t['Ugrave'] = 722;
  15400. t['Delta'] = 612;
  15401. t['thorn'] = 500;
  15402. t['twosuperior'] = 300;
  15403. t['Odieresis'] = 722;
  15404. t['mu'] = 500;
  15405. t['igrave'] = 278;
  15406. t['ohungarumlaut'] = 500;
  15407. t['Eogonek'] = 611;
  15408. t['dcroat'] = 500;
  15409. t['threequarters'] = 750;
  15410. t['Scedilla'] = 556;
  15411. t['lcaron'] = 344;
  15412. t['Kcommaaccent'] = 722;
  15413. t['Lacute'] = 611;
  15414. t['trademark'] = 980;
  15415. t['edotaccent'] = 444;
  15416. t['Igrave'] = 333;
  15417. t['Imacron'] = 333;
  15418. t['Lcaron'] = 611;
  15419. t['onehalf'] = 750;
  15420. t['lessequal'] = 549;
  15421. t['ocircumflex'] = 500;
  15422. t['ntilde'] = 500;
  15423. t['Uhungarumlaut'] = 722;
  15424. t['Eacute'] = 611;
  15425. t['emacron'] = 444;
  15426. t['gbreve'] = 500;
  15427. t['onequarter'] = 750;
  15428. t['Scaron'] = 556;
  15429. t['Scommaaccent'] = 556;
  15430. t['Ohungarumlaut'] = 722;
  15431. t['degree'] = 400;
  15432. t['ograve'] = 500;
  15433. t['Ccaron'] = 667;
  15434. t['ugrave'] = 500;
  15435. t['radical'] = 453;
  15436. t['Dcaron'] = 722;
  15437. t['rcommaaccent'] = 333;
  15438. t['Ntilde'] = 722;
  15439. t['otilde'] = 500;
  15440. t['Rcommaaccent'] = 667;
  15441. t['Lcommaaccent'] = 611;
  15442. t['Atilde'] = 722;
  15443. t['Aogonek'] = 722;
  15444. t['Aring'] = 722;
  15445. t['Otilde'] = 722;
  15446. t['zdotaccent'] = 444;
  15447. t['Ecaron'] = 611;
  15448. t['Iogonek'] = 333;
  15449. t['kcommaaccent'] = 500;
  15450. t['minus'] = 564;
  15451. t['Icircumflex'] = 333;
  15452. t['ncaron'] = 500;
  15453. t['tcommaaccent'] = 278;
  15454. t['logicalnot'] = 564;
  15455. t['odieresis'] = 500;
  15456. t['udieresis'] = 500;
  15457. t['notequal'] = 549;
  15458. t['gcommaaccent'] = 500;
  15459. t['eth'] = 500;
  15460. t['zcaron'] = 444;
  15461. t['ncommaaccent'] = 500;
  15462. t['onesuperior'] = 300;
  15463. t['imacron'] = 278;
  15464. t['Euro'] = 500;
  15465. });
  15466. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15467. t['space'] = 250;
  15468. t['exclam'] = 333;
  15469. t['quotedbl'] = 555;
  15470. t['numbersign'] = 500;
  15471. t['dollar'] = 500;
  15472. t['percent'] = 1000;
  15473. t['ampersand'] = 833;
  15474. t['quoteright'] = 333;
  15475. t['parenleft'] = 333;
  15476. t['parenright'] = 333;
  15477. t['asterisk'] = 500;
  15478. t['plus'] = 570;
  15479. t['comma'] = 250;
  15480. t['hyphen'] = 333;
  15481. t['period'] = 250;
  15482. t['slash'] = 278;
  15483. t['zero'] = 500;
  15484. t['one'] = 500;
  15485. t['two'] = 500;
  15486. t['three'] = 500;
  15487. t['four'] = 500;
  15488. t['five'] = 500;
  15489. t['six'] = 500;
  15490. t['seven'] = 500;
  15491. t['eight'] = 500;
  15492. t['nine'] = 500;
  15493. t['colon'] = 333;
  15494. t['semicolon'] = 333;
  15495. t['less'] = 570;
  15496. t['equal'] = 570;
  15497. t['greater'] = 570;
  15498. t['question'] = 500;
  15499. t['at'] = 930;
  15500. t['A'] = 722;
  15501. t['B'] = 667;
  15502. t['C'] = 722;
  15503. t['D'] = 722;
  15504. t['E'] = 667;
  15505. t['F'] = 611;
  15506. t['G'] = 778;
  15507. t['H'] = 778;
  15508. t['I'] = 389;
  15509. t['J'] = 500;
  15510. t['K'] = 778;
  15511. t['L'] = 667;
  15512. t['M'] = 944;
  15513. t['N'] = 722;
  15514. t['O'] = 778;
  15515. t['P'] = 611;
  15516. t['Q'] = 778;
  15517. t['R'] = 722;
  15518. t['S'] = 556;
  15519. t['T'] = 667;
  15520. t['U'] = 722;
  15521. t['V'] = 722;
  15522. t['W'] = 1000;
  15523. t['X'] = 722;
  15524. t['Y'] = 722;
  15525. t['Z'] = 667;
  15526. t['bracketleft'] = 333;
  15527. t['backslash'] = 278;
  15528. t['bracketright'] = 333;
  15529. t['asciicircum'] = 581;
  15530. t['underscore'] = 500;
  15531. t['quoteleft'] = 333;
  15532. t['a'] = 500;
  15533. t['b'] = 556;
  15534. t['c'] = 444;
  15535. t['d'] = 556;
  15536. t['e'] = 444;
  15537. t['f'] = 333;
  15538. t['g'] = 500;
  15539. t['h'] = 556;
  15540. t['i'] = 278;
  15541. t['j'] = 333;
  15542. t['k'] = 556;
  15543. t['l'] = 278;
  15544. t['m'] = 833;
  15545. t['n'] = 556;
  15546. t['o'] = 500;
  15547. t['p'] = 556;
  15548. t['q'] = 556;
  15549. t['r'] = 444;
  15550. t['s'] = 389;
  15551. t['t'] = 333;
  15552. t['u'] = 556;
  15553. t['v'] = 500;
  15554. t['w'] = 722;
  15555. t['x'] = 500;
  15556. t['y'] = 500;
  15557. t['z'] = 444;
  15558. t['braceleft'] = 394;
  15559. t['bar'] = 220;
  15560. t['braceright'] = 394;
  15561. t['asciitilde'] = 520;
  15562. t['exclamdown'] = 333;
  15563. t['cent'] = 500;
  15564. t['sterling'] = 500;
  15565. t['fraction'] = 167;
  15566. t['yen'] = 500;
  15567. t['florin'] = 500;
  15568. t['section'] = 500;
  15569. t['currency'] = 500;
  15570. t['quotesingle'] = 278;
  15571. t['quotedblleft'] = 500;
  15572. t['guillemotleft'] = 500;
  15573. t['guilsinglleft'] = 333;
  15574. t['guilsinglright'] = 333;
  15575. t['fi'] = 556;
  15576. t['fl'] = 556;
  15577. t['endash'] = 500;
  15578. t['dagger'] = 500;
  15579. t['daggerdbl'] = 500;
  15580. t['periodcentered'] = 250;
  15581. t['paragraph'] = 540;
  15582. t['bullet'] = 350;
  15583. t['quotesinglbase'] = 333;
  15584. t['quotedblbase'] = 500;
  15585. t['quotedblright'] = 500;
  15586. t['guillemotright'] = 500;
  15587. t['ellipsis'] = 1000;
  15588. t['perthousand'] = 1000;
  15589. t['questiondown'] = 500;
  15590. t['grave'] = 333;
  15591. t['acute'] = 333;
  15592. t['circumflex'] = 333;
  15593. t['tilde'] = 333;
  15594. t['macron'] = 333;
  15595. t['breve'] = 333;
  15596. t['dotaccent'] = 333;
  15597. t['dieresis'] = 333;
  15598. t['ring'] = 333;
  15599. t['cedilla'] = 333;
  15600. t['hungarumlaut'] = 333;
  15601. t['ogonek'] = 333;
  15602. t['caron'] = 333;
  15603. t['emdash'] = 1000;
  15604. t['AE'] = 1000;
  15605. t['ordfeminine'] = 300;
  15606. t['Lslash'] = 667;
  15607. t['Oslash'] = 778;
  15608. t['OE'] = 1000;
  15609. t['ordmasculine'] = 330;
  15610. t['ae'] = 722;
  15611. t['dotlessi'] = 278;
  15612. t['lslash'] = 278;
  15613. t['oslash'] = 500;
  15614. t['oe'] = 722;
  15615. t['germandbls'] = 556;
  15616. t['Idieresis'] = 389;
  15617. t['eacute'] = 444;
  15618. t['abreve'] = 500;
  15619. t['uhungarumlaut'] = 556;
  15620. t['ecaron'] = 444;
  15621. t['Ydieresis'] = 722;
  15622. t['divide'] = 570;
  15623. t['Yacute'] = 722;
  15624. t['Acircumflex'] = 722;
  15625. t['aacute'] = 500;
  15626. t['Ucircumflex'] = 722;
  15627. t['yacute'] = 500;
  15628. t['scommaaccent'] = 389;
  15629. t['ecircumflex'] = 444;
  15630. t['Uring'] = 722;
  15631. t['Udieresis'] = 722;
  15632. t['aogonek'] = 500;
  15633. t['Uacute'] = 722;
  15634. t['uogonek'] = 556;
  15635. t['Edieresis'] = 667;
  15636. t['Dcroat'] = 722;
  15637. t['commaaccent'] = 250;
  15638. t['copyright'] = 747;
  15639. t['Emacron'] = 667;
  15640. t['ccaron'] = 444;
  15641. t['aring'] = 500;
  15642. t['Ncommaaccent'] = 722;
  15643. t['lacute'] = 278;
  15644. t['agrave'] = 500;
  15645. t['Tcommaaccent'] = 667;
  15646. t['Cacute'] = 722;
  15647. t['atilde'] = 500;
  15648. t['Edotaccent'] = 667;
  15649. t['scaron'] = 389;
  15650. t['scedilla'] = 389;
  15651. t['iacute'] = 278;
  15652. t['lozenge'] = 494;
  15653. t['Rcaron'] = 722;
  15654. t['Gcommaaccent'] = 778;
  15655. t['ucircumflex'] = 556;
  15656. t['acircumflex'] = 500;
  15657. t['Amacron'] = 722;
  15658. t['rcaron'] = 444;
  15659. t['ccedilla'] = 444;
  15660. t['Zdotaccent'] = 667;
  15661. t['Thorn'] = 611;
  15662. t['Omacron'] = 778;
  15663. t['Racute'] = 722;
  15664. t['Sacute'] = 556;
  15665. t['dcaron'] = 672;
  15666. t['Umacron'] = 722;
  15667. t['uring'] = 556;
  15668. t['threesuperior'] = 300;
  15669. t['Ograve'] = 778;
  15670. t['Agrave'] = 722;
  15671. t['Abreve'] = 722;
  15672. t['multiply'] = 570;
  15673. t['uacute'] = 556;
  15674. t['Tcaron'] = 667;
  15675. t['partialdiff'] = 494;
  15676. t['ydieresis'] = 500;
  15677. t['Nacute'] = 722;
  15678. t['icircumflex'] = 278;
  15679. t['Ecircumflex'] = 667;
  15680. t['adieresis'] = 500;
  15681. t['edieresis'] = 444;
  15682. t['cacute'] = 444;
  15683. t['nacute'] = 556;
  15684. t['umacron'] = 556;
  15685. t['Ncaron'] = 722;
  15686. t['Iacute'] = 389;
  15687. t['plusminus'] = 570;
  15688. t['brokenbar'] = 220;
  15689. t['registered'] = 747;
  15690. t['Gbreve'] = 778;
  15691. t['Idotaccent'] = 389;
  15692. t['summation'] = 600;
  15693. t['Egrave'] = 667;
  15694. t['racute'] = 444;
  15695. t['omacron'] = 500;
  15696. t['Zacute'] = 667;
  15697. t['Zcaron'] = 667;
  15698. t['greaterequal'] = 549;
  15699. t['Eth'] = 722;
  15700. t['Ccedilla'] = 722;
  15701. t['lcommaaccent'] = 278;
  15702. t['tcaron'] = 416;
  15703. t['eogonek'] = 444;
  15704. t['Uogonek'] = 722;
  15705. t['Aacute'] = 722;
  15706. t['Adieresis'] = 722;
  15707. t['egrave'] = 444;
  15708. t['zacute'] = 444;
  15709. t['iogonek'] = 278;
  15710. t['Oacute'] = 778;
  15711. t['oacute'] = 500;
  15712. t['amacron'] = 500;
  15713. t['sacute'] = 389;
  15714. t['idieresis'] = 278;
  15715. t['Ocircumflex'] = 778;
  15716. t['Ugrave'] = 722;
  15717. t['Delta'] = 612;
  15718. t['thorn'] = 556;
  15719. t['twosuperior'] = 300;
  15720. t['Odieresis'] = 778;
  15721. t['mu'] = 556;
  15722. t['igrave'] = 278;
  15723. t['ohungarumlaut'] = 500;
  15724. t['Eogonek'] = 667;
  15725. t['dcroat'] = 556;
  15726. t['threequarters'] = 750;
  15727. t['Scedilla'] = 556;
  15728. t['lcaron'] = 394;
  15729. t['Kcommaaccent'] = 778;
  15730. t['Lacute'] = 667;
  15731. t['trademark'] = 1000;
  15732. t['edotaccent'] = 444;
  15733. t['Igrave'] = 389;
  15734. t['Imacron'] = 389;
  15735. t['Lcaron'] = 667;
  15736. t['onehalf'] = 750;
  15737. t['lessequal'] = 549;
  15738. t['ocircumflex'] = 500;
  15739. t['ntilde'] = 556;
  15740. t['Uhungarumlaut'] = 722;
  15741. t['Eacute'] = 667;
  15742. t['emacron'] = 444;
  15743. t['gbreve'] = 500;
  15744. t['onequarter'] = 750;
  15745. t['Scaron'] = 556;
  15746. t['Scommaaccent'] = 556;
  15747. t['Ohungarumlaut'] = 778;
  15748. t['degree'] = 400;
  15749. t['ograve'] = 500;
  15750. t['Ccaron'] = 722;
  15751. t['ugrave'] = 556;
  15752. t['radical'] = 549;
  15753. t['Dcaron'] = 722;
  15754. t['rcommaaccent'] = 444;
  15755. t['Ntilde'] = 722;
  15756. t['otilde'] = 500;
  15757. t['Rcommaaccent'] = 722;
  15758. t['Lcommaaccent'] = 667;
  15759. t['Atilde'] = 722;
  15760. t['Aogonek'] = 722;
  15761. t['Aring'] = 722;
  15762. t['Otilde'] = 778;
  15763. t['zdotaccent'] = 444;
  15764. t['Ecaron'] = 667;
  15765. t['Iogonek'] = 389;
  15766. t['kcommaaccent'] = 556;
  15767. t['minus'] = 570;
  15768. t['Icircumflex'] = 389;
  15769. t['ncaron'] = 556;
  15770. t['tcommaaccent'] = 333;
  15771. t['logicalnot'] = 570;
  15772. t['odieresis'] = 500;
  15773. t['udieresis'] = 556;
  15774. t['notequal'] = 549;
  15775. t['gcommaaccent'] = 500;
  15776. t['eth'] = 500;
  15777. t['zcaron'] = 444;
  15778. t['ncommaaccent'] = 556;
  15779. t['onesuperior'] = 300;
  15780. t['imacron'] = 278;
  15781. t['Euro'] = 500;
  15782. });
  15783. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15784. t['space'] = 250;
  15785. t['exclam'] = 389;
  15786. t['quotedbl'] = 555;
  15787. t['numbersign'] = 500;
  15788. t['dollar'] = 500;
  15789. t['percent'] = 833;
  15790. t['ampersand'] = 778;
  15791. t['quoteright'] = 333;
  15792. t['parenleft'] = 333;
  15793. t['parenright'] = 333;
  15794. t['asterisk'] = 500;
  15795. t['plus'] = 570;
  15796. t['comma'] = 250;
  15797. t['hyphen'] = 333;
  15798. t['period'] = 250;
  15799. t['slash'] = 278;
  15800. t['zero'] = 500;
  15801. t['one'] = 500;
  15802. t['two'] = 500;
  15803. t['three'] = 500;
  15804. t['four'] = 500;
  15805. t['five'] = 500;
  15806. t['six'] = 500;
  15807. t['seven'] = 500;
  15808. t['eight'] = 500;
  15809. t['nine'] = 500;
  15810. t['colon'] = 333;
  15811. t['semicolon'] = 333;
  15812. t['less'] = 570;
  15813. t['equal'] = 570;
  15814. t['greater'] = 570;
  15815. t['question'] = 500;
  15816. t['at'] = 832;
  15817. t['A'] = 667;
  15818. t['B'] = 667;
  15819. t['C'] = 667;
  15820. t['D'] = 722;
  15821. t['E'] = 667;
  15822. t['F'] = 667;
  15823. t['G'] = 722;
  15824. t['H'] = 778;
  15825. t['I'] = 389;
  15826. t['J'] = 500;
  15827. t['K'] = 667;
  15828. t['L'] = 611;
  15829. t['M'] = 889;
  15830. t['N'] = 722;
  15831. t['O'] = 722;
  15832. t['P'] = 611;
  15833. t['Q'] = 722;
  15834. t['R'] = 667;
  15835. t['S'] = 556;
  15836. t['T'] = 611;
  15837. t['U'] = 722;
  15838. t['V'] = 667;
  15839. t['W'] = 889;
  15840. t['X'] = 667;
  15841. t['Y'] = 611;
  15842. t['Z'] = 611;
  15843. t['bracketleft'] = 333;
  15844. t['backslash'] = 278;
  15845. t['bracketright'] = 333;
  15846. t['asciicircum'] = 570;
  15847. t['underscore'] = 500;
  15848. t['quoteleft'] = 333;
  15849. t['a'] = 500;
  15850. t['b'] = 500;
  15851. t['c'] = 444;
  15852. t['d'] = 500;
  15853. t['e'] = 444;
  15854. t['f'] = 333;
  15855. t['g'] = 500;
  15856. t['h'] = 556;
  15857. t['i'] = 278;
  15858. t['j'] = 278;
  15859. t['k'] = 500;
  15860. t['l'] = 278;
  15861. t['m'] = 778;
  15862. t['n'] = 556;
  15863. t['o'] = 500;
  15864. t['p'] = 500;
  15865. t['q'] = 500;
  15866. t['r'] = 389;
  15867. t['s'] = 389;
  15868. t['t'] = 278;
  15869. t['u'] = 556;
  15870. t['v'] = 444;
  15871. t['w'] = 667;
  15872. t['x'] = 500;
  15873. t['y'] = 444;
  15874. t['z'] = 389;
  15875. t['braceleft'] = 348;
  15876. t['bar'] = 220;
  15877. t['braceright'] = 348;
  15878. t['asciitilde'] = 570;
  15879. t['exclamdown'] = 389;
  15880. t['cent'] = 500;
  15881. t['sterling'] = 500;
  15882. t['fraction'] = 167;
  15883. t['yen'] = 500;
  15884. t['florin'] = 500;
  15885. t['section'] = 500;
  15886. t['currency'] = 500;
  15887. t['quotesingle'] = 278;
  15888. t['quotedblleft'] = 500;
  15889. t['guillemotleft'] = 500;
  15890. t['guilsinglleft'] = 333;
  15891. t['guilsinglright'] = 333;
  15892. t['fi'] = 556;
  15893. t['fl'] = 556;
  15894. t['endash'] = 500;
  15895. t['dagger'] = 500;
  15896. t['daggerdbl'] = 500;
  15897. t['periodcentered'] = 250;
  15898. t['paragraph'] = 500;
  15899. t['bullet'] = 350;
  15900. t['quotesinglbase'] = 333;
  15901. t['quotedblbase'] = 500;
  15902. t['quotedblright'] = 500;
  15903. t['guillemotright'] = 500;
  15904. t['ellipsis'] = 1000;
  15905. t['perthousand'] = 1000;
  15906. t['questiondown'] = 500;
  15907. t['grave'] = 333;
  15908. t['acute'] = 333;
  15909. t['circumflex'] = 333;
  15910. t['tilde'] = 333;
  15911. t['macron'] = 333;
  15912. t['breve'] = 333;
  15913. t['dotaccent'] = 333;
  15914. t['dieresis'] = 333;
  15915. t['ring'] = 333;
  15916. t['cedilla'] = 333;
  15917. t['hungarumlaut'] = 333;
  15918. t['ogonek'] = 333;
  15919. t['caron'] = 333;
  15920. t['emdash'] = 1000;
  15921. t['AE'] = 944;
  15922. t['ordfeminine'] = 266;
  15923. t['Lslash'] = 611;
  15924. t['Oslash'] = 722;
  15925. t['OE'] = 944;
  15926. t['ordmasculine'] = 300;
  15927. t['ae'] = 722;
  15928. t['dotlessi'] = 278;
  15929. t['lslash'] = 278;
  15930. t['oslash'] = 500;
  15931. t['oe'] = 722;
  15932. t['germandbls'] = 500;
  15933. t['Idieresis'] = 389;
  15934. t['eacute'] = 444;
  15935. t['abreve'] = 500;
  15936. t['uhungarumlaut'] = 556;
  15937. t['ecaron'] = 444;
  15938. t['Ydieresis'] = 611;
  15939. t['divide'] = 570;
  15940. t['Yacute'] = 611;
  15941. t['Acircumflex'] = 667;
  15942. t['aacute'] = 500;
  15943. t['Ucircumflex'] = 722;
  15944. t['yacute'] = 444;
  15945. t['scommaaccent'] = 389;
  15946. t['ecircumflex'] = 444;
  15947. t['Uring'] = 722;
  15948. t['Udieresis'] = 722;
  15949. t['aogonek'] = 500;
  15950. t['Uacute'] = 722;
  15951. t['uogonek'] = 556;
  15952. t['Edieresis'] = 667;
  15953. t['Dcroat'] = 722;
  15954. t['commaaccent'] = 250;
  15955. t['copyright'] = 747;
  15956. t['Emacron'] = 667;
  15957. t['ccaron'] = 444;
  15958. t['aring'] = 500;
  15959. t['Ncommaaccent'] = 722;
  15960. t['lacute'] = 278;
  15961. t['agrave'] = 500;
  15962. t['Tcommaaccent'] = 611;
  15963. t['Cacute'] = 667;
  15964. t['atilde'] = 500;
  15965. t['Edotaccent'] = 667;
  15966. t['scaron'] = 389;
  15967. t['scedilla'] = 389;
  15968. t['iacute'] = 278;
  15969. t['lozenge'] = 494;
  15970. t['Rcaron'] = 667;
  15971. t['Gcommaaccent'] = 722;
  15972. t['ucircumflex'] = 556;
  15973. t['acircumflex'] = 500;
  15974. t['Amacron'] = 667;
  15975. t['rcaron'] = 389;
  15976. t['ccedilla'] = 444;
  15977. t['Zdotaccent'] = 611;
  15978. t['Thorn'] = 611;
  15979. t['Omacron'] = 722;
  15980. t['Racute'] = 667;
  15981. t['Sacute'] = 556;
  15982. t['dcaron'] = 608;
  15983. t['Umacron'] = 722;
  15984. t['uring'] = 556;
  15985. t['threesuperior'] = 300;
  15986. t['Ograve'] = 722;
  15987. t['Agrave'] = 667;
  15988. t['Abreve'] = 667;
  15989. t['multiply'] = 570;
  15990. t['uacute'] = 556;
  15991. t['Tcaron'] = 611;
  15992. t['partialdiff'] = 494;
  15993. t['ydieresis'] = 444;
  15994. t['Nacute'] = 722;
  15995. t['icircumflex'] = 278;
  15996. t['Ecircumflex'] = 667;
  15997. t['adieresis'] = 500;
  15998. t['edieresis'] = 444;
  15999. t['cacute'] = 444;
  16000. t['nacute'] = 556;
  16001. t['umacron'] = 556;
  16002. t['Ncaron'] = 722;
  16003. t['Iacute'] = 389;
  16004. t['plusminus'] = 570;
  16005. t['brokenbar'] = 220;
  16006. t['registered'] = 747;
  16007. t['Gbreve'] = 722;
  16008. t['Idotaccent'] = 389;
  16009. t['summation'] = 600;
  16010. t['Egrave'] = 667;
  16011. t['racute'] = 389;
  16012. t['omacron'] = 500;
  16013. t['Zacute'] = 611;
  16014. t['Zcaron'] = 611;
  16015. t['greaterequal'] = 549;
  16016. t['Eth'] = 722;
  16017. t['Ccedilla'] = 667;
  16018. t['lcommaaccent'] = 278;
  16019. t['tcaron'] = 366;
  16020. t['eogonek'] = 444;
  16021. t['Uogonek'] = 722;
  16022. t['Aacute'] = 667;
  16023. t['Adieresis'] = 667;
  16024. t['egrave'] = 444;
  16025. t['zacute'] = 389;
  16026. t['iogonek'] = 278;
  16027. t['Oacute'] = 722;
  16028. t['oacute'] = 500;
  16029. t['amacron'] = 500;
  16030. t['sacute'] = 389;
  16031. t['idieresis'] = 278;
  16032. t['Ocircumflex'] = 722;
  16033. t['Ugrave'] = 722;
  16034. t['Delta'] = 612;
  16035. t['thorn'] = 500;
  16036. t['twosuperior'] = 300;
  16037. t['Odieresis'] = 722;
  16038. t['mu'] = 576;
  16039. t['igrave'] = 278;
  16040. t['ohungarumlaut'] = 500;
  16041. t['Eogonek'] = 667;
  16042. t['dcroat'] = 500;
  16043. t['threequarters'] = 750;
  16044. t['Scedilla'] = 556;
  16045. t['lcaron'] = 382;
  16046. t['Kcommaaccent'] = 667;
  16047. t['Lacute'] = 611;
  16048. t['trademark'] = 1000;
  16049. t['edotaccent'] = 444;
  16050. t['Igrave'] = 389;
  16051. t['Imacron'] = 389;
  16052. t['Lcaron'] = 611;
  16053. t['onehalf'] = 750;
  16054. t['lessequal'] = 549;
  16055. t['ocircumflex'] = 500;
  16056. t['ntilde'] = 556;
  16057. t['Uhungarumlaut'] = 722;
  16058. t['Eacute'] = 667;
  16059. t['emacron'] = 444;
  16060. t['gbreve'] = 500;
  16061. t['onequarter'] = 750;
  16062. t['Scaron'] = 556;
  16063. t['Scommaaccent'] = 556;
  16064. t['Ohungarumlaut'] = 722;
  16065. t['degree'] = 400;
  16066. t['ograve'] = 500;
  16067. t['Ccaron'] = 667;
  16068. t['ugrave'] = 556;
  16069. t['radical'] = 549;
  16070. t['Dcaron'] = 722;
  16071. t['rcommaaccent'] = 389;
  16072. t['Ntilde'] = 722;
  16073. t['otilde'] = 500;
  16074. t['Rcommaaccent'] = 667;
  16075. t['Lcommaaccent'] = 611;
  16076. t['Atilde'] = 667;
  16077. t['Aogonek'] = 667;
  16078. t['Aring'] = 667;
  16079. t['Otilde'] = 722;
  16080. t['zdotaccent'] = 389;
  16081. t['Ecaron'] = 667;
  16082. t['Iogonek'] = 389;
  16083. t['kcommaaccent'] = 500;
  16084. t['minus'] = 606;
  16085. t['Icircumflex'] = 389;
  16086. t['ncaron'] = 556;
  16087. t['tcommaaccent'] = 278;
  16088. t['logicalnot'] = 606;
  16089. t['odieresis'] = 500;
  16090. t['udieresis'] = 556;
  16091. t['notequal'] = 549;
  16092. t['gcommaaccent'] = 500;
  16093. t['eth'] = 500;
  16094. t['zcaron'] = 389;
  16095. t['ncommaaccent'] = 556;
  16096. t['onesuperior'] = 300;
  16097. t['imacron'] = 278;
  16098. t['Euro'] = 500;
  16099. });
  16100. t['Times-Italic'] = getLookupTableFactory(function (t) {
  16101. t['space'] = 250;
  16102. t['exclam'] = 333;
  16103. t['quotedbl'] = 420;
  16104. t['numbersign'] = 500;
  16105. t['dollar'] = 500;
  16106. t['percent'] = 833;
  16107. t['ampersand'] = 778;
  16108. t['quoteright'] = 333;
  16109. t['parenleft'] = 333;
  16110. t['parenright'] = 333;
  16111. t['asterisk'] = 500;
  16112. t['plus'] = 675;
  16113. t['comma'] = 250;
  16114. t['hyphen'] = 333;
  16115. t['period'] = 250;
  16116. t['slash'] = 278;
  16117. t['zero'] = 500;
  16118. t['one'] = 500;
  16119. t['two'] = 500;
  16120. t['three'] = 500;
  16121. t['four'] = 500;
  16122. t['five'] = 500;
  16123. t['six'] = 500;
  16124. t['seven'] = 500;
  16125. t['eight'] = 500;
  16126. t['nine'] = 500;
  16127. t['colon'] = 333;
  16128. t['semicolon'] = 333;
  16129. t['less'] = 675;
  16130. t['equal'] = 675;
  16131. t['greater'] = 675;
  16132. t['question'] = 500;
  16133. t['at'] = 920;
  16134. t['A'] = 611;
  16135. t['B'] = 611;
  16136. t['C'] = 667;
  16137. t['D'] = 722;
  16138. t['E'] = 611;
  16139. t['F'] = 611;
  16140. t['G'] = 722;
  16141. t['H'] = 722;
  16142. t['I'] = 333;
  16143. t['J'] = 444;
  16144. t['K'] = 667;
  16145. t['L'] = 556;
  16146. t['M'] = 833;
  16147. t['N'] = 667;
  16148. t['O'] = 722;
  16149. t['P'] = 611;
  16150. t['Q'] = 722;
  16151. t['R'] = 611;
  16152. t['S'] = 500;
  16153. t['T'] = 556;
  16154. t['U'] = 722;
  16155. t['V'] = 611;
  16156. t['W'] = 833;
  16157. t['X'] = 611;
  16158. t['Y'] = 556;
  16159. t['Z'] = 556;
  16160. t['bracketleft'] = 389;
  16161. t['backslash'] = 278;
  16162. t['bracketright'] = 389;
  16163. t['asciicircum'] = 422;
  16164. t['underscore'] = 500;
  16165. t['quoteleft'] = 333;
  16166. t['a'] = 500;
  16167. t['b'] = 500;
  16168. t['c'] = 444;
  16169. t['d'] = 500;
  16170. t['e'] = 444;
  16171. t['f'] = 278;
  16172. t['g'] = 500;
  16173. t['h'] = 500;
  16174. t['i'] = 278;
  16175. t['j'] = 278;
  16176. t['k'] = 444;
  16177. t['l'] = 278;
  16178. t['m'] = 722;
  16179. t['n'] = 500;
  16180. t['o'] = 500;
  16181. t['p'] = 500;
  16182. t['q'] = 500;
  16183. t['r'] = 389;
  16184. t['s'] = 389;
  16185. t['t'] = 278;
  16186. t['u'] = 500;
  16187. t['v'] = 444;
  16188. t['w'] = 667;
  16189. t['x'] = 444;
  16190. t['y'] = 444;
  16191. t['z'] = 389;
  16192. t['braceleft'] = 400;
  16193. t['bar'] = 275;
  16194. t['braceright'] = 400;
  16195. t['asciitilde'] = 541;
  16196. t['exclamdown'] = 389;
  16197. t['cent'] = 500;
  16198. t['sterling'] = 500;
  16199. t['fraction'] = 167;
  16200. t['yen'] = 500;
  16201. t['florin'] = 500;
  16202. t['section'] = 500;
  16203. t['currency'] = 500;
  16204. t['quotesingle'] = 214;
  16205. t['quotedblleft'] = 556;
  16206. t['guillemotleft'] = 500;
  16207. t['guilsinglleft'] = 333;
  16208. t['guilsinglright'] = 333;
  16209. t['fi'] = 500;
  16210. t['fl'] = 500;
  16211. t['endash'] = 500;
  16212. t['dagger'] = 500;
  16213. t['daggerdbl'] = 500;
  16214. t['periodcentered'] = 250;
  16215. t['paragraph'] = 523;
  16216. t['bullet'] = 350;
  16217. t['quotesinglbase'] = 333;
  16218. t['quotedblbase'] = 556;
  16219. t['quotedblright'] = 556;
  16220. t['guillemotright'] = 500;
  16221. t['ellipsis'] = 889;
  16222. t['perthousand'] = 1000;
  16223. t['questiondown'] = 500;
  16224. t['grave'] = 333;
  16225. t['acute'] = 333;
  16226. t['circumflex'] = 333;
  16227. t['tilde'] = 333;
  16228. t['macron'] = 333;
  16229. t['breve'] = 333;
  16230. t['dotaccent'] = 333;
  16231. t['dieresis'] = 333;
  16232. t['ring'] = 333;
  16233. t['cedilla'] = 333;
  16234. t['hungarumlaut'] = 333;
  16235. t['ogonek'] = 333;
  16236. t['caron'] = 333;
  16237. t['emdash'] = 889;
  16238. t['AE'] = 889;
  16239. t['ordfeminine'] = 276;
  16240. t['Lslash'] = 556;
  16241. t['Oslash'] = 722;
  16242. t['OE'] = 944;
  16243. t['ordmasculine'] = 310;
  16244. t['ae'] = 667;
  16245. t['dotlessi'] = 278;
  16246. t['lslash'] = 278;
  16247. t['oslash'] = 500;
  16248. t['oe'] = 667;
  16249. t['germandbls'] = 500;
  16250. t['Idieresis'] = 333;
  16251. t['eacute'] = 444;
  16252. t['abreve'] = 500;
  16253. t['uhungarumlaut'] = 500;
  16254. t['ecaron'] = 444;
  16255. t['Ydieresis'] = 556;
  16256. t['divide'] = 675;
  16257. t['Yacute'] = 556;
  16258. t['Acircumflex'] = 611;
  16259. t['aacute'] = 500;
  16260. t['Ucircumflex'] = 722;
  16261. t['yacute'] = 444;
  16262. t['scommaaccent'] = 389;
  16263. t['ecircumflex'] = 444;
  16264. t['Uring'] = 722;
  16265. t['Udieresis'] = 722;
  16266. t['aogonek'] = 500;
  16267. t['Uacute'] = 722;
  16268. t['uogonek'] = 500;
  16269. t['Edieresis'] = 611;
  16270. t['Dcroat'] = 722;
  16271. t['commaaccent'] = 250;
  16272. t['copyright'] = 760;
  16273. t['Emacron'] = 611;
  16274. t['ccaron'] = 444;
  16275. t['aring'] = 500;
  16276. t['Ncommaaccent'] = 667;
  16277. t['lacute'] = 278;
  16278. t['agrave'] = 500;
  16279. t['Tcommaaccent'] = 556;
  16280. t['Cacute'] = 667;
  16281. t['atilde'] = 500;
  16282. t['Edotaccent'] = 611;
  16283. t['scaron'] = 389;
  16284. t['scedilla'] = 389;
  16285. t['iacute'] = 278;
  16286. t['lozenge'] = 471;
  16287. t['Rcaron'] = 611;
  16288. t['Gcommaaccent'] = 722;
  16289. t['ucircumflex'] = 500;
  16290. t['acircumflex'] = 500;
  16291. t['Amacron'] = 611;
  16292. t['rcaron'] = 389;
  16293. t['ccedilla'] = 444;
  16294. t['Zdotaccent'] = 556;
  16295. t['Thorn'] = 611;
  16296. t['Omacron'] = 722;
  16297. t['Racute'] = 611;
  16298. t['Sacute'] = 500;
  16299. t['dcaron'] = 544;
  16300. t['Umacron'] = 722;
  16301. t['uring'] = 500;
  16302. t['threesuperior'] = 300;
  16303. t['Ograve'] = 722;
  16304. t['Agrave'] = 611;
  16305. t['Abreve'] = 611;
  16306. t['multiply'] = 675;
  16307. t['uacute'] = 500;
  16308. t['Tcaron'] = 556;
  16309. t['partialdiff'] = 476;
  16310. t['ydieresis'] = 444;
  16311. t['Nacute'] = 667;
  16312. t['icircumflex'] = 278;
  16313. t['Ecircumflex'] = 611;
  16314. t['adieresis'] = 500;
  16315. t['edieresis'] = 444;
  16316. t['cacute'] = 444;
  16317. t['nacute'] = 500;
  16318. t['umacron'] = 500;
  16319. t['Ncaron'] = 667;
  16320. t['Iacute'] = 333;
  16321. t['plusminus'] = 675;
  16322. t['brokenbar'] = 275;
  16323. t['registered'] = 760;
  16324. t['Gbreve'] = 722;
  16325. t['Idotaccent'] = 333;
  16326. t['summation'] = 600;
  16327. t['Egrave'] = 611;
  16328. t['racute'] = 389;
  16329. t['omacron'] = 500;
  16330. t['Zacute'] = 556;
  16331. t['Zcaron'] = 556;
  16332. t['greaterequal'] = 549;
  16333. t['Eth'] = 722;
  16334. t['Ccedilla'] = 667;
  16335. t['lcommaaccent'] = 278;
  16336. t['tcaron'] = 300;
  16337. t['eogonek'] = 444;
  16338. t['Uogonek'] = 722;
  16339. t['Aacute'] = 611;
  16340. t['Adieresis'] = 611;
  16341. t['egrave'] = 444;
  16342. t['zacute'] = 389;
  16343. t['iogonek'] = 278;
  16344. t['Oacute'] = 722;
  16345. t['oacute'] = 500;
  16346. t['amacron'] = 500;
  16347. t['sacute'] = 389;
  16348. t['idieresis'] = 278;
  16349. t['Ocircumflex'] = 722;
  16350. t['Ugrave'] = 722;
  16351. t['Delta'] = 612;
  16352. t['thorn'] = 500;
  16353. t['twosuperior'] = 300;
  16354. t['Odieresis'] = 722;
  16355. t['mu'] = 500;
  16356. t['igrave'] = 278;
  16357. t['ohungarumlaut'] = 500;
  16358. t['Eogonek'] = 611;
  16359. t['dcroat'] = 500;
  16360. t['threequarters'] = 750;
  16361. t['Scedilla'] = 500;
  16362. t['lcaron'] = 300;
  16363. t['Kcommaaccent'] = 667;
  16364. t['Lacute'] = 556;
  16365. t['trademark'] = 980;
  16366. t['edotaccent'] = 444;
  16367. t['Igrave'] = 333;
  16368. t['Imacron'] = 333;
  16369. t['Lcaron'] = 611;
  16370. t['onehalf'] = 750;
  16371. t['lessequal'] = 549;
  16372. t['ocircumflex'] = 500;
  16373. t['ntilde'] = 500;
  16374. t['Uhungarumlaut'] = 722;
  16375. t['Eacute'] = 611;
  16376. t['emacron'] = 444;
  16377. t['gbreve'] = 500;
  16378. t['onequarter'] = 750;
  16379. t['Scaron'] = 500;
  16380. t['Scommaaccent'] = 500;
  16381. t['Ohungarumlaut'] = 722;
  16382. t['degree'] = 400;
  16383. t['ograve'] = 500;
  16384. t['Ccaron'] = 667;
  16385. t['ugrave'] = 500;
  16386. t['radical'] = 453;
  16387. t['Dcaron'] = 722;
  16388. t['rcommaaccent'] = 389;
  16389. t['Ntilde'] = 667;
  16390. t['otilde'] = 500;
  16391. t['Rcommaaccent'] = 611;
  16392. t['Lcommaaccent'] = 556;
  16393. t['Atilde'] = 611;
  16394. t['Aogonek'] = 611;
  16395. t['Aring'] = 611;
  16396. t['Otilde'] = 722;
  16397. t['zdotaccent'] = 389;
  16398. t['Ecaron'] = 611;
  16399. t['Iogonek'] = 333;
  16400. t['kcommaaccent'] = 444;
  16401. t['minus'] = 675;
  16402. t['Icircumflex'] = 333;
  16403. t['ncaron'] = 500;
  16404. t['tcommaaccent'] = 278;
  16405. t['logicalnot'] = 675;
  16406. t['odieresis'] = 500;
  16407. t['udieresis'] = 500;
  16408. t['notequal'] = 549;
  16409. t['gcommaaccent'] = 500;
  16410. t['eth'] = 500;
  16411. t['zcaron'] = 389;
  16412. t['ncommaaccent'] = 500;
  16413. t['onesuperior'] = 300;
  16414. t['imacron'] = 278;
  16415. t['Euro'] = 500;
  16416. });
  16417. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16418. t['space'] = 278;
  16419. t['a1'] = 974;
  16420. t['a2'] = 961;
  16421. t['a202'] = 974;
  16422. t['a3'] = 980;
  16423. t['a4'] = 719;
  16424. t['a5'] = 789;
  16425. t['a119'] = 790;
  16426. t['a118'] = 791;
  16427. t['a117'] = 690;
  16428. t['a11'] = 960;
  16429. t['a12'] = 939;
  16430. t['a13'] = 549;
  16431. t['a14'] = 855;
  16432. t['a15'] = 911;
  16433. t['a16'] = 933;
  16434. t['a105'] = 911;
  16435. t['a17'] = 945;
  16436. t['a18'] = 974;
  16437. t['a19'] = 755;
  16438. t['a20'] = 846;
  16439. t['a21'] = 762;
  16440. t['a22'] = 761;
  16441. t['a23'] = 571;
  16442. t['a24'] = 677;
  16443. t['a25'] = 763;
  16444. t['a26'] = 760;
  16445. t['a27'] = 759;
  16446. t['a28'] = 754;
  16447. t['a6'] = 494;
  16448. t['a7'] = 552;
  16449. t['a8'] = 537;
  16450. t['a9'] = 577;
  16451. t['a10'] = 692;
  16452. t['a29'] = 786;
  16453. t['a30'] = 788;
  16454. t['a31'] = 788;
  16455. t['a32'] = 790;
  16456. t['a33'] = 793;
  16457. t['a34'] = 794;
  16458. t['a35'] = 816;
  16459. t['a36'] = 823;
  16460. t['a37'] = 789;
  16461. t['a38'] = 841;
  16462. t['a39'] = 823;
  16463. t['a40'] = 833;
  16464. t['a41'] = 816;
  16465. t['a42'] = 831;
  16466. t['a43'] = 923;
  16467. t['a44'] = 744;
  16468. t['a45'] = 723;
  16469. t['a46'] = 749;
  16470. t['a47'] = 790;
  16471. t['a48'] = 792;
  16472. t['a49'] = 695;
  16473. t['a50'] = 776;
  16474. t['a51'] = 768;
  16475. t['a52'] = 792;
  16476. t['a53'] = 759;
  16477. t['a54'] = 707;
  16478. t['a55'] = 708;
  16479. t['a56'] = 682;
  16480. t['a57'] = 701;
  16481. t['a58'] = 826;
  16482. t['a59'] = 815;
  16483. t['a60'] = 789;
  16484. t['a61'] = 789;
  16485. t['a62'] = 707;
  16486. t['a63'] = 687;
  16487. t['a64'] = 696;
  16488. t['a65'] = 689;
  16489. t['a66'] = 786;
  16490. t['a67'] = 787;
  16491. t['a68'] = 713;
  16492. t['a69'] = 791;
  16493. t['a70'] = 785;
  16494. t['a71'] = 791;
  16495. t['a72'] = 873;
  16496. t['a73'] = 761;
  16497. t['a74'] = 762;
  16498. t['a203'] = 762;
  16499. t['a75'] = 759;
  16500. t['a204'] = 759;
  16501. t['a76'] = 892;
  16502. t['a77'] = 892;
  16503. t['a78'] = 788;
  16504. t['a79'] = 784;
  16505. t['a81'] = 438;
  16506. t['a82'] = 138;
  16507. t['a83'] = 277;
  16508. t['a84'] = 415;
  16509. t['a97'] = 392;
  16510. t['a98'] = 392;
  16511. t['a99'] = 668;
  16512. t['a100'] = 668;
  16513. t['a89'] = 390;
  16514. t['a90'] = 390;
  16515. t['a93'] = 317;
  16516. t['a94'] = 317;
  16517. t['a91'] = 276;
  16518. t['a92'] = 276;
  16519. t['a205'] = 509;
  16520. t['a85'] = 509;
  16521. t['a206'] = 410;
  16522. t['a86'] = 410;
  16523. t['a87'] = 234;
  16524. t['a88'] = 234;
  16525. t['a95'] = 334;
  16526. t['a96'] = 334;
  16527. t['a101'] = 732;
  16528. t['a102'] = 544;
  16529. t['a103'] = 544;
  16530. t['a104'] = 910;
  16531. t['a106'] = 667;
  16532. t['a107'] = 760;
  16533. t['a108'] = 760;
  16534. t['a112'] = 776;
  16535. t['a111'] = 595;
  16536. t['a110'] = 694;
  16537. t['a109'] = 626;
  16538. t['a120'] = 788;
  16539. t['a121'] = 788;
  16540. t['a122'] = 788;
  16541. t['a123'] = 788;
  16542. t['a124'] = 788;
  16543. t['a125'] = 788;
  16544. t['a126'] = 788;
  16545. t['a127'] = 788;
  16546. t['a128'] = 788;
  16547. t['a129'] = 788;
  16548. t['a130'] = 788;
  16549. t['a131'] = 788;
  16550. t['a132'] = 788;
  16551. t['a133'] = 788;
  16552. t['a134'] = 788;
  16553. t['a135'] = 788;
  16554. t['a136'] = 788;
  16555. t['a137'] = 788;
  16556. t['a138'] = 788;
  16557. t['a139'] = 788;
  16558. t['a140'] = 788;
  16559. t['a141'] = 788;
  16560. t['a142'] = 788;
  16561. t['a143'] = 788;
  16562. t['a144'] = 788;
  16563. t['a145'] = 788;
  16564. t['a146'] = 788;
  16565. t['a147'] = 788;
  16566. t['a148'] = 788;
  16567. t['a149'] = 788;
  16568. t['a150'] = 788;
  16569. t['a151'] = 788;
  16570. t['a152'] = 788;
  16571. t['a153'] = 788;
  16572. t['a154'] = 788;
  16573. t['a155'] = 788;
  16574. t['a156'] = 788;
  16575. t['a157'] = 788;
  16576. t['a158'] = 788;
  16577. t['a159'] = 788;
  16578. t['a160'] = 894;
  16579. t['a161'] = 838;
  16580. t['a163'] = 1016;
  16581. t['a164'] = 458;
  16582. t['a196'] = 748;
  16583. t['a165'] = 924;
  16584. t['a192'] = 748;
  16585. t['a166'] = 918;
  16586. t['a167'] = 927;
  16587. t['a168'] = 928;
  16588. t['a169'] = 928;
  16589. t['a170'] = 834;
  16590. t['a171'] = 873;
  16591. t['a172'] = 828;
  16592. t['a173'] = 924;
  16593. t['a162'] = 924;
  16594. t['a174'] = 917;
  16595. t['a175'] = 930;
  16596. t['a176'] = 931;
  16597. t['a177'] = 463;
  16598. t['a178'] = 883;
  16599. t['a179'] = 836;
  16600. t['a193'] = 836;
  16601. t['a180'] = 867;
  16602. t['a199'] = 867;
  16603. t['a181'] = 696;
  16604. t['a200'] = 696;
  16605. t['a182'] = 874;
  16606. t['a201'] = 874;
  16607. t['a183'] = 760;
  16608. t['a184'] = 946;
  16609. t['a197'] = 771;
  16610. t['a185'] = 865;
  16611. t['a194'] = 771;
  16612. t['a198'] = 888;
  16613. t['a186'] = 967;
  16614. t['a195'] = 888;
  16615. t['a187'] = 831;
  16616. t['a188'] = 873;
  16617. t['a189'] = 927;
  16618. t['a190'] = 970;
  16619. t['a191'] = 918;
  16620. });
  16621. });
  16622. exports.getMetrics = getMetrics;
  16623. }));
  16624. (function (root, factory) {
  16625. {
  16626. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16627. }
  16628. }(this, function (exports, sharedUtil) {
  16629. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16630. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16631. // Workaround for missing math precision in JS.
  16632. var MASK_HIGH = 0xffff0000;
  16633. var MASK_LOW = 0xffff;
  16634. function MurmurHash3_64 (seed) {
  16635. var SEED = 0xc3d2e1f0;
  16636. this.h1 = seed ? seed & 0xffffffff : SEED;
  16637. this.h2 = seed ? seed & 0xffffffff : SEED;
  16638. }
  16639. var alwaysUseUint32ArrayView = false;
  16640. // old webkits have issues with non-aligned arrays
  16641. try {
  16642. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16643. } catch (e) {
  16644. alwaysUseUint32ArrayView = true;
  16645. }
  16646. MurmurHash3_64.prototype = {
  16647. update: function MurmurHash3_64_update(input) {
  16648. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16649. var i;
  16650. if (typeof input === 'string') {
  16651. var data = new Uint8Array(input.length * 2);
  16652. var length = 0;
  16653. for (i = 0; i < input.length; i++) {
  16654. var code = input.charCodeAt(i);
  16655. if (code <= 0xff) {
  16656. data[length++] = code;
  16657. }
  16658. else {
  16659. data[length++] = code >>> 8;
  16660. data[length++] = code & 0xff;
  16661. }
  16662. }
  16663. } else if (input instanceof Uint8Array) {
  16664. data = input;
  16665. length = data.length;
  16666. } else if (typeof input === 'object' && ('length' in input)) {
  16667. // processing regular arrays as well, e.g. for IE9
  16668. data = input;
  16669. length = data.length;
  16670. useUint32ArrayView = true;
  16671. } else {
  16672. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16673. 'Input must be a string or array.');
  16674. }
  16675. var blockCounts = length >> 2;
  16676. var tailLength = length - blockCounts * 4;
  16677. // we don't care about endianness here
  16678. var dataUint32 = useUint32ArrayView ?
  16679. new Uint32ArrayView(data, blockCounts) :
  16680. new Uint32Array(data.buffer, 0, blockCounts);
  16681. var k1 = 0;
  16682. var k2 = 0;
  16683. var h1 = this.h1;
  16684. var h2 = this.h2;
  16685. var C1 = 0xcc9e2d51;
  16686. var C2 = 0x1b873593;
  16687. var C1_LOW = C1 & MASK_LOW;
  16688. var C2_LOW = C2 & MASK_LOW;
  16689. for (i = 0; i < blockCounts; i++) {
  16690. if (i & 1) {
  16691. k1 = dataUint32[i];
  16692. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16693. k1 = k1 << 15 | k1 >>> 17;
  16694. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16695. h1 ^= k1;
  16696. h1 = h1 << 13 | h1 >>> 19;
  16697. h1 = h1 * 5 + 0xe6546b64;
  16698. } else {
  16699. k2 = dataUint32[i];
  16700. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16701. k2 = k2 << 15 | k2 >>> 17;
  16702. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16703. h2 ^= k2;
  16704. h2 = h2 << 13 | h2 >>> 19;
  16705. h2 = h2 * 5 + 0xe6546b64;
  16706. }
  16707. }
  16708. k1 = 0;
  16709. switch (tailLength) {
  16710. case 3:
  16711. k1 ^= data[blockCounts * 4 + 2] << 16;
  16712. /* falls through */
  16713. case 2:
  16714. k1 ^= data[blockCounts * 4 + 1] << 8;
  16715. /* falls through */
  16716. case 1:
  16717. k1 ^= data[blockCounts * 4];
  16718. /* falls through */
  16719. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16720. k1 = k1 << 15 | k1 >>> 17;
  16721. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16722. if (blockCounts & 1) {
  16723. h1 ^= k1;
  16724. } else {
  16725. h2 ^= k1;
  16726. }
  16727. }
  16728. this.h1 = h1;
  16729. this.h2 = h2;
  16730. return this;
  16731. },
  16732. hexdigest: function MurmurHash3_64_hexdigest () {
  16733. var h1 = this.h1;
  16734. var h2 = this.h2;
  16735. h1 ^= h2 >>> 1;
  16736. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16737. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16738. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16739. h1 ^= h2 >>> 1;
  16740. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16741. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16742. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16743. h1 ^= h2 >>> 1;
  16744. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16745. var hex = (arr[i] >>> 0).toString(16);
  16746. while (hex.length < 8) {
  16747. hex = '0' + hex;
  16748. }
  16749. str += hex;
  16750. }
  16751. return str;
  16752. }
  16753. };
  16754. return MurmurHash3_64;
  16755. })();
  16756. exports.MurmurHash3_64 = MurmurHash3_64;
  16757. }));
  16758. (function (root, factory) {
  16759. {
  16760. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16761. }
  16762. }(this, function (exports, sharedUtil) {
  16763. var isArray = sharedUtil.isArray;
  16764. var Name = (function NameClosure() {
  16765. function Name(name) {
  16766. this.name = name;
  16767. }
  16768. Name.prototype = {};
  16769. var nameCache = Object.create(null);
  16770. Name.get = function Name_get(name) {
  16771. var nameValue = nameCache[name];
  16772. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16773. };
  16774. return Name;
  16775. })();
  16776. var Cmd = (function CmdClosure() {
  16777. function Cmd(cmd) {
  16778. this.cmd = cmd;
  16779. }
  16780. Cmd.prototype = {};
  16781. var cmdCache = Object.create(null);
  16782. Cmd.get = function Cmd_get(cmd) {
  16783. var cmdValue = cmdCache[cmd];
  16784. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16785. };
  16786. return Cmd;
  16787. })();
  16788. var Dict = (function DictClosure() {
  16789. var nonSerializable = function nonSerializableClosure() {
  16790. return nonSerializable; // creating closure on some variable
  16791. };
  16792. // xref is optional
  16793. function Dict(xref) {
  16794. // Map should only be used internally, use functions below to access.
  16795. this.map = Object.create(null);
  16796. this.xref = xref;
  16797. this.objId = null;
  16798. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16799. }
  16800. Dict.prototype = {
  16801. assignXref: function Dict_assignXref(newXref) {
  16802. this.xref = newXref;
  16803. },
  16804. // automatically dereferences Ref objects
  16805. get: function Dict_get(key1, key2, key3) {
  16806. var value;
  16807. var xref = this.xref;
  16808. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16809. typeof key2 === 'undefined') {
  16810. return xref ? xref.fetchIfRef(value) : value;
  16811. }
  16812. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16813. typeof key3 === 'undefined') {
  16814. return xref ? xref.fetchIfRef(value) : value;
  16815. }
  16816. value = this.map[key3] || null;
  16817. return xref ? xref.fetchIfRef(value) : value;
  16818. },
  16819. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16820. getAsync: function Dict_getAsync(key1, key2, key3) {
  16821. var value;
  16822. var xref = this.xref;
  16823. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16824. typeof key2 === 'undefined') {
  16825. if (xref) {
  16826. return xref.fetchIfRefAsync(value);
  16827. }
  16828. return Promise.resolve(value);
  16829. }
  16830. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16831. typeof key3 === 'undefined') {
  16832. if (xref) {
  16833. return xref.fetchIfRefAsync(value);
  16834. }
  16835. return Promise.resolve(value);
  16836. }
  16837. value = this.map[key3] || null;
  16838. if (xref) {
  16839. return xref.fetchIfRefAsync(value);
  16840. }
  16841. return Promise.resolve(value);
  16842. },
  16843. // Same as get(), but dereferences all elements if the result is an Array.
  16844. getArray: function Dict_getArray(key1, key2, key3) {
  16845. var value = this.get(key1, key2, key3);
  16846. var xref = this.xref;
  16847. if (!isArray(value) || !xref) {
  16848. return value;
  16849. }
  16850. value = value.slice(); // Ensure that we don't modify the Dict data.
  16851. for (var i = 0, ii = value.length; i < ii; i++) {
  16852. if (!isRef(value[i])) {
  16853. continue;
  16854. }
  16855. value[i] = xref.fetch(value[i]);
  16856. }
  16857. return value;
  16858. },
  16859. // no dereferencing
  16860. getRaw: function Dict_getRaw(key) {
  16861. return this.map[key];
  16862. },
  16863. getKeys: function Dict_getKeys() {
  16864. return Object.keys(this.map);
  16865. },
  16866. set: function Dict_set(key, value) {
  16867. this.map[key] = value;
  16868. },
  16869. has: function Dict_has(key) {
  16870. return key in this.map;
  16871. },
  16872. forEach: function Dict_forEach(callback) {
  16873. for (var key in this.map) {
  16874. callback(key, this.get(key));
  16875. }
  16876. }
  16877. };
  16878. Dict.empty = new Dict(null);
  16879. Dict.merge = function Dict_merge(xref, dictArray) {
  16880. var mergedDict = new Dict(xref);
  16881. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  16882. var dict = dictArray[i];
  16883. if (!isDict(dict)) {
  16884. continue;
  16885. }
  16886. for (var keyName in dict.map) {
  16887. if (mergedDict.map[keyName]) {
  16888. continue;
  16889. }
  16890. mergedDict.map[keyName] = dict.map[keyName];
  16891. }
  16892. }
  16893. return mergedDict;
  16894. };
  16895. return Dict;
  16896. })();
  16897. var Ref = (function RefClosure() {
  16898. function Ref(num, gen) {
  16899. this.num = num;
  16900. this.gen = gen;
  16901. }
  16902. Ref.prototype = {
  16903. toString: function Ref_toString() {
  16904. // This function is hot, so we make the string as compact as possible.
  16905. // |this.gen| is almost always zero, so we treat that case specially.
  16906. var str = this.num + 'R';
  16907. if (this.gen !== 0) {
  16908. str += this.gen;
  16909. }
  16910. return str;
  16911. }
  16912. };
  16913. return Ref;
  16914. })();
  16915. // The reference is identified by number and generation.
  16916. // This structure stores only one instance of the reference.
  16917. var RefSet = (function RefSetClosure() {
  16918. function RefSet() {
  16919. this.dict = Object.create(null);
  16920. }
  16921. RefSet.prototype = {
  16922. has: function RefSet_has(ref) {
  16923. return ref.toString() in this.dict;
  16924. },
  16925. put: function RefSet_put(ref) {
  16926. this.dict[ref.toString()] = true;
  16927. },
  16928. remove: function RefSet_remove(ref) {
  16929. delete this.dict[ref.toString()];
  16930. }
  16931. };
  16932. return RefSet;
  16933. })();
  16934. var RefSetCache = (function RefSetCacheClosure() {
  16935. function RefSetCache() {
  16936. this.dict = Object.create(null);
  16937. }
  16938. RefSetCache.prototype = {
  16939. get: function RefSetCache_get(ref) {
  16940. return this.dict[ref.toString()];
  16941. },
  16942. has: function RefSetCache_has(ref) {
  16943. return ref.toString() in this.dict;
  16944. },
  16945. put: function RefSetCache_put(ref, obj) {
  16946. this.dict[ref.toString()] = obj;
  16947. },
  16948. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  16949. this.dict[ref.toString()] = this.get(aliasRef);
  16950. },
  16951. forEach: function RefSetCache_forEach(fn, thisArg) {
  16952. for (var i in this.dict) {
  16953. fn.call(thisArg, this.dict[i]);
  16954. }
  16955. },
  16956. clear: function RefSetCache_clear() {
  16957. this.dict = Object.create(null);
  16958. }
  16959. };
  16960. return RefSetCache;
  16961. })();
  16962. function isName(v, name) {
  16963. return v instanceof Name && (name === undefined || v.name === name);
  16964. }
  16965. function isCmd(v, cmd) {
  16966. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  16967. }
  16968. function isDict(v, type) {
  16969. return v instanceof Dict &&
  16970. (type === undefined || isName(v.get('Type'), type));
  16971. }
  16972. function isRef(v) {
  16973. return v instanceof Ref;
  16974. }
  16975. function isRefsEqual(v1, v2) {
  16976. return v1.num === v2.num && v1.gen === v2.gen;
  16977. }
  16978. function isStream(v) {
  16979. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  16980. }
  16981. exports.Cmd = Cmd;
  16982. exports.Dict = Dict;
  16983. exports.Name = Name;
  16984. exports.Ref = Ref;
  16985. exports.RefSet = RefSet;
  16986. exports.RefSetCache = RefSetCache;
  16987. exports.isCmd = isCmd;
  16988. exports.isDict = isDict;
  16989. exports.isName = isName;
  16990. exports.isRef = isRef;
  16991. exports.isRefsEqual = isRefsEqual;
  16992. exports.isStream = isStream;
  16993. }));
  16994. (function (root, factory) {
  16995. {
  16996. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  16997. }
  16998. }(this, function (exports, sharedUtil) {
  16999. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17000. /**
  17001. * Hold a map of decoded fonts and of the standard fourteen Type1
  17002. * fonts and their acronyms.
  17003. */
  17004. var getStdFontMap = getLookupTableFactory(function (t) {
  17005. t['ArialNarrow'] = 'Helvetica';
  17006. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  17007. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  17008. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  17009. t['ArialBlack'] = 'Helvetica';
  17010. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  17011. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  17012. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  17013. t['Arial'] = 'Helvetica';
  17014. t['Arial-Bold'] = 'Helvetica-Bold';
  17015. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  17016. t['Arial-Italic'] = 'Helvetica-Oblique';
  17017. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  17018. t['Arial-BoldMT'] = 'Helvetica-Bold';
  17019. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  17020. t['ArialMT'] = 'Helvetica';
  17021. t['Courier-Bold'] = 'Courier-Bold';
  17022. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  17023. t['Courier-Italic'] = 'Courier-Oblique';
  17024. t['CourierNew'] = 'Courier';
  17025. t['CourierNew-Bold'] = 'Courier-Bold';
  17026. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  17027. t['CourierNew-Italic'] = 'Courier-Oblique';
  17028. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  17029. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  17030. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  17031. t['CourierNewPSMT'] = 'Courier';
  17032. t['Helvetica'] = 'Helvetica';
  17033. t['Helvetica-Bold'] = 'Helvetica-Bold';
  17034. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  17035. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  17036. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  17037. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  17038. t['Symbol-Bold'] = 'Symbol';
  17039. t['Symbol-BoldItalic'] = 'Symbol';
  17040. t['Symbol-Italic'] = 'Symbol';
  17041. t['TimesNewRoman'] = 'Times-Roman';
  17042. t['TimesNewRoman-Bold'] = 'Times-Bold';
  17043. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  17044. t['TimesNewRoman-Italic'] = 'Times-Italic';
  17045. t['TimesNewRomanPS'] = 'Times-Roman';
  17046. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  17047. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  17048. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  17049. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  17050. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  17051. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  17052. t['TimesNewRomanPSMT'] = 'Times-Roman';
  17053. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  17054. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  17055. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  17056. });
  17057. /**
  17058. * Holds the map of the non-standard fonts that might be included as
  17059. * a standard fonts without glyph data.
  17060. */
  17061. var getNonStdFontMap = getLookupTableFactory(function (t) {
  17062. t['CenturyGothic'] = 'Helvetica';
  17063. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  17064. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  17065. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  17066. t['ComicSansMS'] = 'Comic Sans MS';
  17067. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  17068. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  17069. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  17070. t['LucidaConsole'] = 'Courier';
  17071. t['LucidaConsole-Bold'] = 'Courier-Bold';
  17072. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  17073. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  17074. t['MS-Gothic'] = 'MS Gothic';
  17075. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  17076. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  17077. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  17078. t['MS-Mincho'] = 'MS Mincho';
  17079. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  17080. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  17081. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  17082. t['MS-PGothic'] = 'MS PGothic';
  17083. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  17084. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  17085. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  17086. t['MS-PMincho'] = 'MS PMincho';
  17087. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  17088. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  17089. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  17090. t['Wingdings'] = 'ZapfDingbats';
  17091. });
  17092. var getSerifFonts = getLookupTableFactory(function (t) {
  17093. t['Adobe Jenson'] = true;
  17094. t['Adobe Text'] = true;
  17095. t['Albertus'] = true;
  17096. t['Aldus'] = true;
  17097. t['Alexandria'] = true;
  17098. t['Algerian'] = true;
  17099. t['American Typewriter'] = true;
  17100. t['Antiqua'] = true;
  17101. t['Apex'] = true;
  17102. t['Arno'] = true;
  17103. t['Aster'] = true;
  17104. t['Aurora'] = true;
  17105. t['Baskerville'] = true;
  17106. t['Bell'] = true;
  17107. t['Bembo'] = true;
  17108. t['Bembo Schoolbook'] = true;
  17109. t['Benguiat'] = true;
  17110. t['Berkeley Old Style'] = true;
  17111. t['Bernhard Modern'] = true;
  17112. t['Berthold City'] = true;
  17113. t['Bodoni'] = true;
  17114. t['Bauer Bodoni'] = true;
  17115. t['Book Antiqua'] = true;
  17116. t['Bookman'] = true;
  17117. t['Bordeaux Roman'] = true;
  17118. t['Californian FB'] = true;
  17119. t['Calisto'] = true;
  17120. t['Calvert'] = true;
  17121. t['Capitals'] = true;
  17122. t['Cambria'] = true;
  17123. t['Cartier'] = true;
  17124. t['Caslon'] = true;
  17125. t['Catull'] = true;
  17126. t['Centaur'] = true;
  17127. t['Century Old Style'] = true;
  17128. t['Century Schoolbook'] = true;
  17129. t['Chaparral'] = true;
  17130. t['Charis SIL'] = true;
  17131. t['Cheltenham'] = true;
  17132. t['Cholla Slab'] = true;
  17133. t['Clarendon'] = true;
  17134. t['Clearface'] = true;
  17135. t['Cochin'] = true;
  17136. t['Colonna'] = true;
  17137. t['Computer Modern'] = true;
  17138. t['Concrete Roman'] = true;
  17139. t['Constantia'] = true;
  17140. t['Cooper Black'] = true;
  17141. t['Corona'] = true;
  17142. t['Ecotype'] = true;
  17143. t['Egyptienne'] = true;
  17144. t['Elephant'] = true;
  17145. t['Excelsior'] = true;
  17146. t['Fairfield'] = true;
  17147. t['FF Scala'] = true;
  17148. t['Folkard'] = true;
  17149. t['Footlight'] = true;
  17150. t['FreeSerif'] = true;
  17151. t['Friz Quadrata'] = true;
  17152. t['Garamond'] = true;
  17153. t['Gentium'] = true;
  17154. t['Georgia'] = true;
  17155. t['Gloucester'] = true;
  17156. t['Goudy Old Style'] = true;
  17157. t['Goudy Schoolbook'] = true;
  17158. t['Goudy Pro Font'] = true;
  17159. t['Granjon'] = true;
  17160. t['Guardian Egyptian'] = true;
  17161. t['Heather'] = true;
  17162. t['Hercules'] = true;
  17163. t['High Tower Text'] = true;
  17164. t['Hiroshige'] = true;
  17165. t['Hoefler Text'] = true;
  17166. t['Humana Serif'] = true;
  17167. t['Imprint'] = true;
  17168. t['Ionic No. 5'] = true;
  17169. t['Janson'] = true;
  17170. t['Joanna'] = true;
  17171. t['Korinna'] = true;
  17172. t['Lexicon'] = true;
  17173. t['Liberation Serif'] = true;
  17174. t['Linux Libertine'] = true;
  17175. t['Literaturnaya'] = true;
  17176. t['Lucida'] = true;
  17177. t['Lucida Bright'] = true;
  17178. t['Melior'] = true;
  17179. t['Memphis'] = true;
  17180. t['Miller'] = true;
  17181. t['Minion'] = true;
  17182. t['Modern'] = true;
  17183. t['Mona Lisa'] = true;
  17184. t['Mrs Eaves'] = true;
  17185. t['MS Serif'] = true;
  17186. t['Museo Slab'] = true;
  17187. t['New York'] = true;
  17188. t['Nimbus Roman'] = true;
  17189. t['NPS Rawlinson Roadway'] = true;
  17190. t['Palatino'] = true;
  17191. t['Perpetua'] = true;
  17192. t['Plantin'] = true;
  17193. t['Plantin Schoolbook'] = true;
  17194. t['Playbill'] = true;
  17195. t['Poor Richard'] = true;
  17196. t['Rawlinson Roadway'] = true;
  17197. t['Renault'] = true;
  17198. t['Requiem'] = true;
  17199. t['Rockwell'] = true;
  17200. t['Roman'] = true;
  17201. t['Rotis Serif'] = true;
  17202. t['Sabon'] = true;
  17203. t['Scala'] = true;
  17204. t['Seagull'] = true;
  17205. t['Sistina'] = true;
  17206. t['Souvenir'] = true;
  17207. t['STIX'] = true;
  17208. t['Stone Informal'] = true;
  17209. t['Stone Serif'] = true;
  17210. t['Sylfaen'] = true;
  17211. t['Times'] = true;
  17212. t['Trajan'] = true;
  17213. t['Trinité'] = true;
  17214. t['Trump Mediaeval'] = true;
  17215. t['Utopia'] = true;
  17216. t['Vale Type'] = true;
  17217. t['Bitstream Vera'] = true;
  17218. t['Vera Serif'] = true;
  17219. t['Versailles'] = true;
  17220. t['Wanted'] = true;
  17221. t['Weiss'] = true;
  17222. t['Wide Latin'] = true;
  17223. t['Windsor'] = true;
  17224. t['XITS'] = true;
  17225. });
  17226. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17227. t['Dingbats'] = true;
  17228. t['Symbol'] = true;
  17229. t['ZapfDingbats'] = true;
  17230. });
  17231. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17232. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17233. // for all glyphs, but common for some set of the standard fonts.
  17234. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17235. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17236. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17237. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17238. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17239. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17240. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17241. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17242. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17243. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17244. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17245. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17246. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17247. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17248. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17249. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17250. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17251. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17252. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17253. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17254. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17255. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17256. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17257. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17258. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17259. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17260. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17261. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17262. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17263. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17264. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17265. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17266. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17267. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17268. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17269. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17270. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17271. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17272. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17273. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17274. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17275. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17276. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17277. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17278. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17279. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17280. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17281. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17282. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17283. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17284. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17285. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17286. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17287. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17288. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17289. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17290. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17291. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17292. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17293. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17294. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17295. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17296. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17297. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17298. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17299. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17300. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17301. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17302. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17303. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17304. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17305. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17306. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17307. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17308. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17309. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17310. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17311. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17312. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17313. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17314. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17315. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17316. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17317. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17318. t[3416] = 8377;
  17319. });
  17320. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17321. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17322. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17323. var getSupplementalGlyphMapForArialBlack =
  17324. getLookupTableFactory(function (t) {
  17325. t[227] = 322; t[264] = 261; t[291] = 346;
  17326. });
  17327. exports.getStdFontMap = getStdFontMap;
  17328. exports.getNonStdFontMap = getNonStdFontMap;
  17329. exports.getSerifFonts = getSerifFonts;
  17330. exports.getSymbolsFonts = getSymbolsFonts;
  17331. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17332. exports.getSupplementalGlyphMapForArialBlack =
  17333. getSupplementalGlyphMapForArialBlack;
  17334. }));
  17335. (function (root, factory) {
  17336. {
  17337. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17338. }
  17339. }(this, function (exports, sharedUtil) {
  17340. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17341. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17342. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17343. // chars to the similar equivalents in the normal characters range.
  17344. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17345. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17346. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17347. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17348. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17349. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17350. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17351. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17352. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17353. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17354. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17355. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17356. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17357. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17358. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17359. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17360. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17361. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17362. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17363. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17364. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17365. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17366. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17367. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17368. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17369. });
  17370. function mapSpecialUnicodeValues(code) {
  17371. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17372. return 0;
  17373. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17374. return (getSpecialPUASymbols()[code] || code);
  17375. }
  17376. return code;
  17377. }
  17378. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17379. var unicode = glyphsUnicodeMap[name];
  17380. if (unicode !== undefined) {
  17381. return unicode;
  17382. }
  17383. if (!name) {
  17384. return -1;
  17385. }
  17386. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17387. if (name[0] === 'u') {
  17388. var nameLen = name.length, hexStr;
  17389. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17390. hexStr = name.substr(3);
  17391. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17392. hexStr = name.substr(1);
  17393. } else {
  17394. return -1;
  17395. }
  17396. // Check for upper-case hexadecimal characters, to avoid false positives.
  17397. if (hexStr === hexStr.toUpperCase()) {
  17398. unicode = parseInt(hexStr, 16);
  17399. if (unicode >= 0) {
  17400. return unicode;
  17401. }
  17402. }
  17403. }
  17404. return -1;
  17405. }
  17406. var UnicodeRanges = [
  17407. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17408. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17409. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17410. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17411. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17412. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17413. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17414. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17415. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17416. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17417. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17418. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17419. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17420. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17421. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17422. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17423. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17424. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17425. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17426. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17427. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17428. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17429. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17430. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17431. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17432. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17433. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17434. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17435. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17436. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17437. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17438. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17439. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17440. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17441. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17442. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17443. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17444. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17445. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17446. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17447. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17448. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17449. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17450. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17451. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17452. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17453. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17454. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17455. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17456. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17457. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17458. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17459. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17460. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17461. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17462. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17463. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17464. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17465. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17466. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17467. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17468. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17469. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17470. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17471. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17472. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17473. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17474. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17475. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17476. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17477. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17478. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17479. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17480. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17481. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17482. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17483. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17484. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17485. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17486. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17487. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17488. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17489. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17490. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17491. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17492. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17493. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17494. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17495. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17496. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17497. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17498. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17499. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17500. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17501. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17502. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17503. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17504. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17505. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17506. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17507. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17508. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17509. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17510. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17511. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17512. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17513. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17514. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17515. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17516. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17517. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17518. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17519. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17520. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17521. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17522. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17523. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17524. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17525. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17526. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17527. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17528. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17529. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17530. ];
  17531. function getUnicodeRangeFor(value) {
  17532. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17533. var range = UnicodeRanges[i];
  17534. if (value >= range.begin && value < range.end) {
  17535. return i;
  17536. }
  17537. }
  17538. return -1;
  17539. }
  17540. function isRTLRangeFor(value) {
  17541. var range = UnicodeRanges[13];
  17542. if (value >= range.begin && value < range.end) {
  17543. return true;
  17544. }
  17545. range = UnicodeRanges[11];
  17546. if (value >= range.begin && value < range.end) {
  17547. return true;
  17548. }
  17549. return false;
  17550. }
  17551. // The normalization table is obtained by filtering the Unicode characters
  17552. // database with <compat> entries.
  17553. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17554. t['\u00A8'] = '\u0020\u0308';
  17555. t['\u00AF'] = '\u0020\u0304';
  17556. t['\u00B4'] = '\u0020\u0301';
  17557. t['\u00B5'] = '\u03BC';
  17558. t['\u00B8'] = '\u0020\u0327';
  17559. t['\u0132'] = '\u0049\u004A';
  17560. t['\u0133'] = '\u0069\u006A';
  17561. t['\u013F'] = '\u004C\u00B7';
  17562. t['\u0140'] = '\u006C\u00B7';
  17563. t['\u0149'] = '\u02BC\u006E';
  17564. t['\u017F'] = '\u0073';
  17565. t['\u01C4'] = '\u0044\u017D';
  17566. t['\u01C5'] = '\u0044\u017E';
  17567. t['\u01C6'] = '\u0064\u017E';
  17568. t['\u01C7'] = '\u004C\u004A';
  17569. t['\u01C8'] = '\u004C\u006A';
  17570. t['\u01C9'] = '\u006C\u006A';
  17571. t['\u01CA'] = '\u004E\u004A';
  17572. t['\u01CB'] = '\u004E\u006A';
  17573. t['\u01CC'] = '\u006E\u006A';
  17574. t['\u01F1'] = '\u0044\u005A';
  17575. t['\u01F2'] = '\u0044\u007A';
  17576. t['\u01F3'] = '\u0064\u007A';
  17577. t['\u02D8'] = '\u0020\u0306';
  17578. t['\u02D9'] = '\u0020\u0307';
  17579. t['\u02DA'] = '\u0020\u030A';
  17580. t['\u02DB'] = '\u0020\u0328';
  17581. t['\u02DC'] = '\u0020\u0303';
  17582. t['\u02DD'] = '\u0020\u030B';
  17583. t['\u037A'] = '\u0020\u0345';
  17584. t['\u0384'] = '\u0020\u0301';
  17585. t['\u03D0'] = '\u03B2';
  17586. t['\u03D1'] = '\u03B8';
  17587. t['\u03D2'] = '\u03A5';
  17588. t['\u03D5'] = '\u03C6';
  17589. t['\u03D6'] = '\u03C0';
  17590. t['\u03F0'] = '\u03BA';
  17591. t['\u03F1'] = '\u03C1';
  17592. t['\u03F2'] = '\u03C2';
  17593. t['\u03F4'] = '\u0398';
  17594. t['\u03F5'] = '\u03B5';
  17595. t['\u03F9'] = '\u03A3';
  17596. t['\u0587'] = '\u0565\u0582';
  17597. t['\u0675'] = '\u0627\u0674';
  17598. t['\u0676'] = '\u0648\u0674';
  17599. t['\u0677'] = '\u06C7\u0674';
  17600. t['\u0678'] = '\u064A\u0674';
  17601. t['\u0E33'] = '\u0E4D\u0E32';
  17602. t['\u0EB3'] = '\u0ECD\u0EB2';
  17603. t['\u0EDC'] = '\u0EAB\u0E99';
  17604. t['\u0EDD'] = '\u0EAB\u0EA1';
  17605. t['\u0F77'] = '\u0FB2\u0F81';
  17606. t['\u0F79'] = '\u0FB3\u0F81';
  17607. t['\u1E9A'] = '\u0061\u02BE';
  17608. t['\u1FBD'] = '\u0020\u0313';
  17609. t['\u1FBF'] = '\u0020\u0313';
  17610. t['\u1FC0'] = '\u0020\u0342';
  17611. t['\u1FFE'] = '\u0020\u0314';
  17612. t['\u2002'] = '\u0020';
  17613. t['\u2003'] = '\u0020';
  17614. t['\u2004'] = '\u0020';
  17615. t['\u2005'] = '\u0020';
  17616. t['\u2006'] = '\u0020';
  17617. t['\u2008'] = '\u0020';
  17618. t['\u2009'] = '\u0020';
  17619. t['\u200A'] = '\u0020';
  17620. t['\u2017'] = '\u0020\u0333';
  17621. t['\u2024'] = '\u002E';
  17622. t['\u2025'] = '\u002E\u002E';
  17623. t['\u2026'] = '\u002E\u002E\u002E';
  17624. t['\u2033'] = '\u2032\u2032';
  17625. t['\u2034'] = '\u2032\u2032\u2032';
  17626. t['\u2036'] = '\u2035\u2035';
  17627. t['\u2037'] = '\u2035\u2035\u2035';
  17628. t['\u203C'] = '\u0021\u0021';
  17629. t['\u203E'] = '\u0020\u0305';
  17630. t['\u2047'] = '\u003F\u003F';
  17631. t['\u2048'] = '\u003F\u0021';
  17632. t['\u2049'] = '\u0021\u003F';
  17633. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17634. t['\u205F'] = '\u0020';
  17635. t['\u20A8'] = '\u0052\u0073';
  17636. t['\u2100'] = '\u0061\u002F\u0063';
  17637. t['\u2101'] = '\u0061\u002F\u0073';
  17638. t['\u2103'] = '\u00B0\u0043';
  17639. t['\u2105'] = '\u0063\u002F\u006F';
  17640. t['\u2106'] = '\u0063\u002F\u0075';
  17641. t['\u2107'] = '\u0190';
  17642. t['\u2109'] = '\u00B0\u0046';
  17643. t['\u2116'] = '\u004E\u006F';
  17644. t['\u2121'] = '\u0054\u0045\u004C';
  17645. t['\u2135'] = '\u05D0';
  17646. t['\u2136'] = '\u05D1';
  17647. t['\u2137'] = '\u05D2';
  17648. t['\u2138'] = '\u05D3';
  17649. t['\u213B'] = '\u0046\u0041\u0058';
  17650. t['\u2160'] = '\u0049';
  17651. t['\u2161'] = '\u0049\u0049';
  17652. t['\u2162'] = '\u0049\u0049\u0049';
  17653. t['\u2163'] = '\u0049\u0056';
  17654. t['\u2164'] = '\u0056';
  17655. t['\u2165'] = '\u0056\u0049';
  17656. t['\u2166'] = '\u0056\u0049\u0049';
  17657. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17658. t['\u2168'] = '\u0049\u0058';
  17659. t['\u2169'] = '\u0058';
  17660. t['\u216A'] = '\u0058\u0049';
  17661. t['\u216B'] = '\u0058\u0049\u0049';
  17662. t['\u216C'] = '\u004C';
  17663. t['\u216D'] = '\u0043';
  17664. t['\u216E'] = '\u0044';
  17665. t['\u216F'] = '\u004D';
  17666. t['\u2170'] = '\u0069';
  17667. t['\u2171'] = '\u0069\u0069';
  17668. t['\u2172'] = '\u0069\u0069\u0069';
  17669. t['\u2173'] = '\u0069\u0076';
  17670. t['\u2174'] = '\u0076';
  17671. t['\u2175'] = '\u0076\u0069';
  17672. t['\u2176'] = '\u0076\u0069\u0069';
  17673. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17674. t['\u2178'] = '\u0069\u0078';
  17675. t['\u2179'] = '\u0078';
  17676. t['\u217A'] = '\u0078\u0069';
  17677. t['\u217B'] = '\u0078\u0069\u0069';
  17678. t['\u217C'] = '\u006C';
  17679. t['\u217D'] = '\u0063';
  17680. t['\u217E'] = '\u0064';
  17681. t['\u217F'] = '\u006D';
  17682. t['\u222C'] = '\u222B\u222B';
  17683. t['\u222D'] = '\u222B\u222B\u222B';
  17684. t['\u222F'] = '\u222E\u222E';
  17685. t['\u2230'] = '\u222E\u222E\u222E';
  17686. t['\u2474'] = '\u0028\u0031\u0029';
  17687. t['\u2475'] = '\u0028\u0032\u0029';
  17688. t['\u2476'] = '\u0028\u0033\u0029';
  17689. t['\u2477'] = '\u0028\u0034\u0029';
  17690. t['\u2478'] = '\u0028\u0035\u0029';
  17691. t['\u2479'] = '\u0028\u0036\u0029';
  17692. t['\u247A'] = '\u0028\u0037\u0029';
  17693. t['\u247B'] = '\u0028\u0038\u0029';
  17694. t['\u247C'] = '\u0028\u0039\u0029';
  17695. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17696. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17697. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17698. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17699. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17700. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17701. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17702. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17703. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17704. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17705. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17706. t['\u2488'] = '\u0031\u002E';
  17707. t['\u2489'] = '\u0032\u002E';
  17708. t['\u248A'] = '\u0033\u002E';
  17709. t['\u248B'] = '\u0034\u002E';
  17710. t['\u248C'] = '\u0035\u002E';
  17711. t['\u248D'] = '\u0036\u002E';
  17712. t['\u248E'] = '\u0037\u002E';
  17713. t['\u248F'] = '\u0038\u002E';
  17714. t['\u2490'] = '\u0039\u002E';
  17715. t['\u2491'] = '\u0031\u0030\u002E';
  17716. t['\u2492'] = '\u0031\u0031\u002E';
  17717. t['\u2493'] = '\u0031\u0032\u002E';
  17718. t['\u2494'] = '\u0031\u0033\u002E';
  17719. t['\u2495'] = '\u0031\u0034\u002E';
  17720. t['\u2496'] = '\u0031\u0035\u002E';
  17721. t['\u2497'] = '\u0031\u0036\u002E';
  17722. t['\u2498'] = '\u0031\u0037\u002E';
  17723. t['\u2499'] = '\u0031\u0038\u002E';
  17724. t['\u249A'] = '\u0031\u0039\u002E';
  17725. t['\u249B'] = '\u0032\u0030\u002E';
  17726. t['\u249C'] = '\u0028\u0061\u0029';
  17727. t['\u249D'] = '\u0028\u0062\u0029';
  17728. t['\u249E'] = '\u0028\u0063\u0029';
  17729. t['\u249F'] = '\u0028\u0064\u0029';
  17730. t['\u24A0'] = '\u0028\u0065\u0029';
  17731. t['\u24A1'] = '\u0028\u0066\u0029';
  17732. t['\u24A2'] = '\u0028\u0067\u0029';
  17733. t['\u24A3'] = '\u0028\u0068\u0029';
  17734. t['\u24A4'] = '\u0028\u0069\u0029';
  17735. t['\u24A5'] = '\u0028\u006A\u0029';
  17736. t['\u24A6'] = '\u0028\u006B\u0029';
  17737. t['\u24A7'] = '\u0028\u006C\u0029';
  17738. t['\u24A8'] = '\u0028\u006D\u0029';
  17739. t['\u24A9'] = '\u0028\u006E\u0029';
  17740. t['\u24AA'] = '\u0028\u006F\u0029';
  17741. t['\u24AB'] = '\u0028\u0070\u0029';
  17742. t['\u24AC'] = '\u0028\u0071\u0029';
  17743. t['\u24AD'] = '\u0028\u0072\u0029';
  17744. t['\u24AE'] = '\u0028\u0073\u0029';
  17745. t['\u24AF'] = '\u0028\u0074\u0029';
  17746. t['\u24B0'] = '\u0028\u0075\u0029';
  17747. t['\u24B1'] = '\u0028\u0076\u0029';
  17748. t['\u24B2'] = '\u0028\u0077\u0029';
  17749. t['\u24B3'] = '\u0028\u0078\u0029';
  17750. t['\u24B4'] = '\u0028\u0079\u0029';
  17751. t['\u24B5'] = '\u0028\u007A\u0029';
  17752. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17753. t['\u2A74'] = '\u003A\u003A\u003D';
  17754. t['\u2A75'] = '\u003D\u003D';
  17755. t['\u2A76'] = '\u003D\u003D\u003D';
  17756. t['\u2E9F'] = '\u6BCD';
  17757. t['\u2EF3'] = '\u9F9F';
  17758. t['\u2F00'] = '\u4E00';
  17759. t['\u2F01'] = '\u4E28';
  17760. t['\u2F02'] = '\u4E36';
  17761. t['\u2F03'] = '\u4E3F';
  17762. t['\u2F04'] = '\u4E59';
  17763. t['\u2F05'] = '\u4E85';
  17764. t['\u2F06'] = '\u4E8C';
  17765. t['\u2F07'] = '\u4EA0';
  17766. t['\u2F08'] = '\u4EBA';
  17767. t['\u2F09'] = '\u513F';
  17768. t['\u2F0A'] = '\u5165';
  17769. t['\u2F0B'] = '\u516B';
  17770. t['\u2F0C'] = '\u5182';
  17771. t['\u2F0D'] = '\u5196';
  17772. t['\u2F0E'] = '\u51AB';
  17773. t['\u2F0F'] = '\u51E0';
  17774. t['\u2F10'] = '\u51F5';
  17775. t['\u2F11'] = '\u5200';
  17776. t['\u2F12'] = '\u529B';
  17777. t['\u2F13'] = '\u52F9';
  17778. t['\u2F14'] = '\u5315';
  17779. t['\u2F15'] = '\u531A';
  17780. t['\u2F16'] = '\u5338';
  17781. t['\u2F17'] = '\u5341';
  17782. t['\u2F18'] = '\u535C';
  17783. t['\u2F19'] = '\u5369';
  17784. t['\u2F1A'] = '\u5382';
  17785. t['\u2F1B'] = '\u53B6';
  17786. t['\u2F1C'] = '\u53C8';
  17787. t['\u2F1D'] = '\u53E3';
  17788. t['\u2F1E'] = '\u56D7';
  17789. t['\u2F1F'] = '\u571F';
  17790. t['\u2F20'] = '\u58EB';
  17791. t['\u2F21'] = '\u5902';
  17792. t['\u2F22'] = '\u590A';
  17793. t['\u2F23'] = '\u5915';
  17794. t['\u2F24'] = '\u5927';
  17795. t['\u2F25'] = '\u5973';
  17796. t['\u2F26'] = '\u5B50';
  17797. t['\u2F27'] = '\u5B80';
  17798. t['\u2F28'] = '\u5BF8';
  17799. t['\u2F29'] = '\u5C0F';
  17800. t['\u2F2A'] = '\u5C22';
  17801. t['\u2F2B'] = '\u5C38';
  17802. t['\u2F2C'] = '\u5C6E';
  17803. t['\u2F2D'] = '\u5C71';
  17804. t['\u2F2E'] = '\u5DDB';
  17805. t['\u2F2F'] = '\u5DE5';
  17806. t['\u2F30'] = '\u5DF1';
  17807. t['\u2F31'] = '\u5DFE';
  17808. t['\u2F32'] = '\u5E72';
  17809. t['\u2F33'] = '\u5E7A';
  17810. t['\u2F34'] = '\u5E7F';
  17811. t['\u2F35'] = '\u5EF4';
  17812. t['\u2F36'] = '\u5EFE';
  17813. t['\u2F37'] = '\u5F0B';
  17814. t['\u2F38'] = '\u5F13';
  17815. t['\u2F39'] = '\u5F50';
  17816. t['\u2F3A'] = '\u5F61';
  17817. t['\u2F3B'] = '\u5F73';
  17818. t['\u2F3C'] = '\u5FC3';
  17819. t['\u2F3D'] = '\u6208';
  17820. t['\u2F3E'] = '\u6236';
  17821. t['\u2F3F'] = '\u624B';
  17822. t['\u2F40'] = '\u652F';
  17823. t['\u2F41'] = '\u6534';
  17824. t['\u2F42'] = '\u6587';
  17825. t['\u2F43'] = '\u6597';
  17826. t['\u2F44'] = '\u65A4';
  17827. t['\u2F45'] = '\u65B9';
  17828. t['\u2F46'] = '\u65E0';
  17829. t['\u2F47'] = '\u65E5';
  17830. t['\u2F48'] = '\u66F0';
  17831. t['\u2F49'] = '\u6708';
  17832. t['\u2F4A'] = '\u6728';
  17833. t['\u2F4B'] = '\u6B20';
  17834. t['\u2F4C'] = '\u6B62';
  17835. t['\u2F4D'] = '\u6B79';
  17836. t['\u2F4E'] = '\u6BB3';
  17837. t['\u2F4F'] = '\u6BCB';
  17838. t['\u2F50'] = '\u6BD4';
  17839. t['\u2F51'] = '\u6BDB';
  17840. t['\u2F52'] = '\u6C0F';
  17841. t['\u2F53'] = '\u6C14';
  17842. t['\u2F54'] = '\u6C34';
  17843. t['\u2F55'] = '\u706B';
  17844. t['\u2F56'] = '\u722A';
  17845. t['\u2F57'] = '\u7236';
  17846. t['\u2F58'] = '\u723B';
  17847. t['\u2F59'] = '\u723F';
  17848. t['\u2F5A'] = '\u7247';
  17849. t['\u2F5B'] = '\u7259';
  17850. t['\u2F5C'] = '\u725B';
  17851. t['\u2F5D'] = '\u72AC';
  17852. t['\u2F5E'] = '\u7384';
  17853. t['\u2F5F'] = '\u7389';
  17854. t['\u2F60'] = '\u74DC';
  17855. t['\u2F61'] = '\u74E6';
  17856. t['\u2F62'] = '\u7518';
  17857. t['\u2F63'] = '\u751F';
  17858. t['\u2F64'] = '\u7528';
  17859. t['\u2F65'] = '\u7530';
  17860. t['\u2F66'] = '\u758B';
  17861. t['\u2F67'] = '\u7592';
  17862. t['\u2F68'] = '\u7676';
  17863. t['\u2F69'] = '\u767D';
  17864. t['\u2F6A'] = '\u76AE';
  17865. t['\u2F6B'] = '\u76BF';
  17866. t['\u2F6C'] = '\u76EE';
  17867. t['\u2F6D'] = '\u77DB';
  17868. t['\u2F6E'] = '\u77E2';
  17869. t['\u2F6F'] = '\u77F3';
  17870. t['\u2F70'] = '\u793A';
  17871. t['\u2F71'] = '\u79B8';
  17872. t['\u2F72'] = '\u79BE';
  17873. t['\u2F73'] = '\u7A74';
  17874. t['\u2F74'] = '\u7ACB';
  17875. t['\u2F75'] = '\u7AF9';
  17876. t['\u2F76'] = '\u7C73';
  17877. t['\u2F77'] = '\u7CF8';
  17878. t['\u2F78'] = '\u7F36';
  17879. t['\u2F79'] = '\u7F51';
  17880. t['\u2F7A'] = '\u7F8A';
  17881. t['\u2F7B'] = '\u7FBD';
  17882. t['\u2F7C'] = '\u8001';
  17883. t['\u2F7D'] = '\u800C';
  17884. t['\u2F7E'] = '\u8012';
  17885. t['\u2F7F'] = '\u8033';
  17886. t['\u2F80'] = '\u807F';
  17887. t['\u2F81'] = '\u8089';
  17888. t['\u2F82'] = '\u81E3';
  17889. t['\u2F83'] = '\u81EA';
  17890. t['\u2F84'] = '\u81F3';
  17891. t['\u2F85'] = '\u81FC';
  17892. t['\u2F86'] = '\u820C';
  17893. t['\u2F87'] = '\u821B';
  17894. t['\u2F88'] = '\u821F';
  17895. t['\u2F89'] = '\u826E';
  17896. t['\u2F8A'] = '\u8272';
  17897. t['\u2F8B'] = '\u8278';
  17898. t['\u2F8C'] = '\u864D';
  17899. t['\u2F8D'] = '\u866B';
  17900. t['\u2F8E'] = '\u8840';
  17901. t['\u2F8F'] = '\u884C';
  17902. t['\u2F90'] = '\u8863';
  17903. t['\u2F91'] = '\u897E';
  17904. t['\u2F92'] = '\u898B';
  17905. t['\u2F93'] = '\u89D2';
  17906. t['\u2F94'] = '\u8A00';
  17907. t['\u2F95'] = '\u8C37';
  17908. t['\u2F96'] = '\u8C46';
  17909. t['\u2F97'] = '\u8C55';
  17910. t['\u2F98'] = '\u8C78';
  17911. t['\u2F99'] = '\u8C9D';
  17912. t['\u2F9A'] = '\u8D64';
  17913. t['\u2F9B'] = '\u8D70';
  17914. t['\u2F9C'] = '\u8DB3';
  17915. t['\u2F9D'] = '\u8EAB';
  17916. t['\u2F9E'] = '\u8ECA';
  17917. t['\u2F9F'] = '\u8F9B';
  17918. t['\u2FA0'] = '\u8FB0';
  17919. t['\u2FA1'] = '\u8FB5';
  17920. t['\u2FA2'] = '\u9091';
  17921. t['\u2FA3'] = '\u9149';
  17922. t['\u2FA4'] = '\u91C6';
  17923. t['\u2FA5'] = '\u91CC';
  17924. t['\u2FA6'] = '\u91D1';
  17925. t['\u2FA7'] = '\u9577';
  17926. t['\u2FA8'] = '\u9580';
  17927. t['\u2FA9'] = '\u961C';
  17928. t['\u2FAA'] = '\u96B6';
  17929. t['\u2FAB'] = '\u96B9';
  17930. t['\u2FAC'] = '\u96E8';
  17931. t['\u2FAD'] = '\u9751';
  17932. t['\u2FAE'] = '\u975E';
  17933. t['\u2FAF'] = '\u9762';
  17934. t['\u2FB0'] = '\u9769';
  17935. t['\u2FB1'] = '\u97CB';
  17936. t['\u2FB2'] = '\u97ED';
  17937. t['\u2FB3'] = '\u97F3';
  17938. t['\u2FB4'] = '\u9801';
  17939. t['\u2FB5'] = '\u98A8';
  17940. t['\u2FB6'] = '\u98DB';
  17941. t['\u2FB7'] = '\u98DF';
  17942. t['\u2FB8'] = '\u9996';
  17943. t['\u2FB9'] = '\u9999';
  17944. t['\u2FBA'] = '\u99AC';
  17945. t['\u2FBB'] = '\u9AA8';
  17946. t['\u2FBC'] = '\u9AD8';
  17947. t['\u2FBD'] = '\u9ADF';
  17948. t['\u2FBE'] = '\u9B25';
  17949. t['\u2FBF'] = '\u9B2F';
  17950. t['\u2FC0'] = '\u9B32';
  17951. t['\u2FC1'] = '\u9B3C';
  17952. t['\u2FC2'] = '\u9B5A';
  17953. t['\u2FC3'] = '\u9CE5';
  17954. t['\u2FC4'] = '\u9E75';
  17955. t['\u2FC5'] = '\u9E7F';
  17956. t['\u2FC6'] = '\u9EA5';
  17957. t['\u2FC7'] = '\u9EBB';
  17958. t['\u2FC8'] = '\u9EC3';
  17959. t['\u2FC9'] = '\u9ECD';
  17960. t['\u2FCA'] = '\u9ED1';
  17961. t['\u2FCB'] = '\u9EF9';
  17962. t['\u2FCC'] = '\u9EFD';
  17963. t['\u2FCD'] = '\u9F0E';
  17964. t['\u2FCE'] = '\u9F13';
  17965. t['\u2FCF'] = '\u9F20';
  17966. t['\u2FD0'] = '\u9F3B';
  17967. t['\u2FD1'] = '\u9F4A';
  17968. t['\u2FD2'] = '\u9F52';
  17969. t['\u2FD3'] = '\u9F8D';
  17970. t['\u2FD4'] = '\u9F9C';
  17971. t['\u2FD5'] = '\u9FA0';
  17972. t['\u3036'] = '\u3012';
  17973. t['\u3038'] = '\u5341';
  17974. t['\u3039'] = '\u5344';
  17975. t['\u303A'] = '\u5345';
  17976. t['\u309B'] = '\u0020\u3099';
  17977. t['\u309C'] = '\u0020\u309A';
  17978. t['\u3131'] = '\u1100';
  17979. t['\u3132'] = '\u1101';
  17980. t['\u3133'] = '\u11AA';
  17981. t['\u3134'] = '\u1102';
  17982. t['\u3135'] = '\u11AC';
  17983. t['\u3136'] = '\u11AD';
  17984. t['\u3137'] = '\u1103';
  17985. t['\u3138'] = '\u1104';
  17986. t['\u3139'] = '\u1105';
  17987. t['\u313A'] = '\u11B0';
  17988. t['\u313B'] = '\u11B1';
  17989. t['\u313C'] = '\u11B2';
  17990. t['\u313D'] = '\u11B3';
  17991. t['\u313E'] = '\u11B4';
  17992. t['\u313F'] = '\u11B5';
  17993. t['\u3140'] = '\u111A';
  17994. t['\u3141'] = '\u1106';
  17995. t['\u3142'] = '\u1107';
  17996. t['\u3143'] = '\u1108';
  17997. t['\u3144'] = '\u1121';
  17998. t['\u3145'] = '\u1109';
  17999. t['\u3146'] = '\u110A';
  18000. t['\u3147'] = '\u110B';
  18001. t['\u3148'] = '\u110C';
  18002. t['\u3149'] = '\u110D';
  18003. t['\u314A'] = '\u110E';
  18004. t['\u314B'] = '\u110F';
  18005. t['\u314C'] = '\u1110';
  18006. t['\u314D'] = '\u1111';
  18007. t['\u314E'] = '\u1112';
  18008. t['\u314F'] = '\u1161';
  18009. t['\u3150'] = '\u1162';
  18010. t['\u3151'] = '\u1163';
  18011. t['\u3152'] = '\u1164';
  18012. t['\u3153'] = '\u1165';
  18013. t['\u3154'] = '\u1166';
  18014. t['\u3155'] = '\u1167';
  18015. t['\u3156'] = '\u1168';
  18016. t['\u3157'] = '\u1169';
  18017. t['\u3158'] = '\u116A';
  18018. t['\u3159'] = '\u116B';
  18019. t['\u315A'] = '\u116C';
  18020. t['\u315B'] = '\u116D';
  18021. t['\u315C'] = '\u116E';
  18022. t['\u315D'] = '\u116F';
  18023. t['\u315E'] = '\u1170';
  18024. t['\u315F'] = '\u1171';
  18025. t['\u3160'] = '\u1172';
  18026. t['\u3161'] = '\u1173';
  18027. t['\u3162'] = '\u1174';
  18028. t['\u3163'] = '\u1175';
  18029. t['\u3164'] = '\u1160';
  18030. t['\u3165'] = '\u1114';
  18031. t['\u3166'] = '\u1115';
  18032. t['\u3167'] = '\u11C7';
  18033. t['\u3168'] = '\u11C8';
  18034. t['\u3169'] = '\u11CC';
  18035. t['\u316A'] = '\u11CE';
  18036. t['\u316B'] = '\u11D3';
  18037. t['\u316C'] = '\u11D7';
  18038. t['\u316D'] = '\u11D9';
  18039. t['\u316E'] = '\u111C';
  18040. t['\u316F'] = '\u11DD';
  18041. t['\u3170'] = '\u11DF';
  18042. t['\u3171'] = '\u111D';
  18043. t['\u3172'] = '\u111E';
  18044. t['\u3173'] = '\u1120';
  18045. t['\u3174'] = '\u1122';
  18046. t['\u3175'] = '\u1123';
  18047. t['\u3176'] = '\u1127';
  18048. t['\u3177'] = '\u1129';
  18049. t['\u3178'] = '\u112B';
  18050. t['\u3179'] = '\u112C';
  18051. t['\u317A'] = '\u112D';
  18052. t['\u317B'] = '\u112E';
  18053. t['\u317C'] = '\u112F';
  18054. t['\u317D'] = '\u1132';
  18055. t['\u317E'] = '\u1136';
  18056. t['\u317F'] = '\u1140';
  18057. t['\u3180'] = '\u1147';
  18058. t['\u3181'] = '\u114C';
  18059. t['\u3182'] = '\u11F1';
  18060. t['\u3183'] = '\u11F2';
  18061. t['\u3184'] = '\u1157';
  18062. t['\u3185'] = '\u1158';
  18063. t['\u3186'] = '\u1159';
  18064. t['\u3187'] = '\u1184';
  18065. t['\u3188'] = '\u1185';
  18066. t['\u3189'] = '\u1188';
  18067. t['\u318A'] = '\u1191';
  18068. t['\u318B'] = '\u1192';
  18069. t['\u318C'] = '\u1194';
  18070. t['\u318D'] = '\u119E';
  18071. t['\u318E'] = '\u11A1';
  18072. t['\u3200'] = '\u0028\u1100\u0029';
  18073. t['\u3201'] = '\u0028\u1102\u0029';
  18074. t['\u3202'] = '\u0028\u1103\u0029';
  18075. t['\u3203'] = '\u0028\u1105\u0029';
  18076. t['\u3204'] = '\u0028\u1106\u0029';
  18077. t['\u3205'] = '\u0028\u1107\u0029';
  18078. t['\u3206'] = '\u0028\u1109\u0029';
  18079. t['\u3207'] = '\u0028\u110B\u0029';
  18080. t['\u3208'] = '\u0028\u110C\u0029';
  18081. t['\u3209'] = '\u0028\u110E\u0029';
  18082. t['\u320A'] = '\u0028\u110F\u0029';
  18083. t['\u320B'] = '\u0028\u1110\u0029';
  18084. t['\u320C'] = '\u0028\u1111\u0029';
  18085. t['\u320D'] = '\u0028\u1112\u0029';
  18086. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  18087. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  18088. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  18089. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  18090. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  18091. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  18092. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  18093. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  18094. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  18095. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  18096. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  18097. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  18098. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  18099. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  18100. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  18101. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  18102. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  18103. t['\u3220'] = '\u0028\u4E00\u0029';
  18104. t['\u3221'] = '\u0028\u4E8C\u0029';
  18105. t['\u3222'] = '\u0028\u4E09\u0029';
  18106. t['\u3223'] = '\u0028\u56DB\u0029';
  18107. t['\u3224'] = '\u0028\u4E94\u0029';
  18108. t['\u3225'] = '\u0028\u516D\u0029';
  18109. t['\u3226'] = '\u0028\u4E03\u0029';
  18110. t['\u3227'] = '\u0028\u516B\u0029';
  18111. t['\u3228'] = '\u0028\u4E5D\u0029';
  18112. t['\u3229'] = '\u0028\u5341\u0029';
  18113. t['\u322A'] = '\u0028\u6708\u0029';
  18114. t['\u322B'] = '\u0028\u706B\u0029';
  18115. t['\u322C'] = '\u0028\u6C34\u0029';
  18116. t['\u322D'] = '\u0028\u6728\u0029';
  18117. t['\u322E'] = '\u0028\u91D1\u0029';
  18118. t['\u322F'] = '\u0028\u571F\u0029';
  18119. t['\u3230'] = '\u0028\u65E5\u0029';
  18120. t['\u3231'] = '\u0028\u682A\u0029';
  18121. t['\u3232'] = '\u0028\u6709\u0029';
  18122. t['\u3233'] = '\u0028\u793E\u0029';
  18123. t['\u3234'] = '\u0028\u540D\u0029';
  18124. t['\u3235'] = '\u0028\u7279\u0029';
  18125. t['\u3236'] = '\u0028\u8CA1\u0029';
  18126. t['\u3237'] = '\u0028\u795D\u0029';
  18127. t['\u3238'] = '\u0028\u52B4\u0029';
  18128. t['\u3239'] = '\u0028\u4EE3\u0029';
  18129. t['\u323A'] = '\u0028\u547C\u0029';
  18130. t['\u323B'] = '\u0028\u5B66\u0029';
  18131. t['\u323C'] = '\u0028\u76E3\u0029';
  18132. t['\u323D'] = '\u0028\u4F01\u0029';
  18133. t['\u323E'] = '\u0028\u8CC7\u0029';
  18134. t['\u323F'] = '\u0028\u5354\u0029';
  18135. t['\u3240'] = '\u0028\u796D\u0029';
  18136. t['\u3241'] = '\u0028\u4F11\u0029';
  18137. t['\u3242'] = '\u0028\u81EA\u0029';
  18138. t['\u3243'] = '\u0028\u81F3\u0029';
  18139. t['\u32C0'] = '\u0031\u6708';
  18140. t['\u32C1'] = '\u0032\u6708';
  18141. t['\u32C2'] = '\u0033\u6708';
  18142. t['\u32C3'] = '\u0034\u6708';
  18143. t['\u32C4'] = '\u0035\u6708';
  18144. t['\u32C5'] = '\u0036\u6708';
  18145. t['\u32C6'] = '\u0037\u6708';
  18146. t['\u32C7'] = '\u0038\u6708';
  18147. t['\u32C8'] = '\u0039\u6708';
  18148. t['\u32C9'] = '\u0031\u0030\u6708';
  18149. t['\u32CA'] = '\u0031\u0031\u6708';
  18150. t['\u32CB'] = '\u0031\u0032\u6708';
  18151. t['\u3358'] = '\u0030\u70B9';
  18152. t['\u3359'] = '\u0031\u70B9';
  18153. t['\u335A'] = '\u0032\u70B9';
  18154. t['\u335B'] = '\u0033\u70B9';
  18155. t['\u335C'] = '\u0034\u70B9';
  18156. t['\u335D'] = '\u0035\u70B9';
  18157. t['\u335E'] = '\u0036\u70B9';
  18158. t['\u335F'] = '\u0037\u70B9';
  18159. t['\u3360'] = '\u0038\u70B9';
  18160. t['\u3361'] = '\u0039\u70B9';
  18161. t['\u3362'] = '\u0031\u0030\u70B9';
  18162. t['\u3363'] = '\u0031\u0031\u70B9';
  18163. t['\u3364'] = '\u0031\u0032\u70B9';
  18164. t['\u3365'] = '\u0031\u0033\u70B9';
  18165. t['\u3366'] = '\u0031\u0034\u70B9';
  18166. t['\u3367'] = '\u0031\u0035\u70B9';
  18167. t['\u3368'] = '\u0031\u0036\u70B9';
  18168. t['\u3369'] = '\u0031\u0037\u70B9';
  18169. t['\u336A'] = '\u0031\u0038\u70B9';
  18170. t['\u336B'] = '\u0031\u0039\u70B9';
  18171. t['\u336C'] = '\u0032\u0030\u70B9';
  18172. t['\u336D'] = '\u0032\u0031\u70B9';
  18173. t['\u336E'] = '\u0032\u0032\u70B9';
  18174. t['\u336F'] = '\u0032\u0033\u70B9';
  18175. t['\u3370'] = '\u0032\u0034\u70B9';
  18176. t['\u33E0'] = '\u0031\u65E5';
  18177. t['\u33E1'] = '\u0032\u65E5';
  18178. t['\u33E2'] = '\u0033\u65E5';
  18179. t['\u33E3'] = '\u0034\u65E5';
  18180. t['\u33E4'] = '\u0035\u65E5';
  18181. t['\u33E5'] = '\u0036\u65E5';
  18182. t['\u33E6'] = '\u0037\u65E5';
  18183. t['\u33E7'] = '\u0038\u65E5';
  18184. t['\u33E8'] = '\u0039\u65E5';
  18185. t['\u33E9'] = '\u0031\u0030\u65E5';
  18186. t['\u33EA'] = '\u0031\u0031\u65E5';
  18187. t['\u33EB'] = '\u0031\u0032\u65E5';
  18188. t['\u33EC'] = '\u0031\u0033\u65E5';
  18189. t['\u33ED'] = '\u0031\u0034\u65E5';
  18190. t['\u33EE'] = '\u0031\u0035\u65E5';
  18191. t['\u33EF'] = '\u0031\u0036\u65E5';
  18192. t['\u33F0'] = '\u0031\u0037\u65E5';
  18193. t['\u33F1'] = '\u0031\u0038\u65E5';
  18194. t['\u33F2'] = '\u0031\u0039\u65E5';
  18195. t['\u33F3'] = '\u0032\u0030\u65E5';
  18196. t['\u33F4'] = '\u0032\u0031\u65E5';
  18197. t['\u33F5'] = '\u0032\u0032\u65E5';
  18198. t['\u33F6'] = '\u0032\u0033\u65E5';
  18199. t['\u33F7'] = '\u0032\u0034\u65E5';
  18200. t['\u33F8'] = '\u0032\u0035\u65E5';
  18201. t['\u33F9'] = '\u0032\u0036\u65E5';
  18202. t['\u33FA'] = '\u0032\u0037\u65E5';
  18203. t['\u33FB'] = '\u0032\u0038\u65E5';
  18204. t['\u33FC'] = '\u0032\u0039\u65E5';
  18205. t['\u33FD'] = '\u0033\u0030\u65E5';
  18206. t['\u33FE'] = '\u0033\u0031\u65E5';
  18207. t['\uFB00'] = '\u0066\u0066';
  18208. t['\uFB01'] = '\u0066\u0069';
  18209. t['\uFB02'] = '\u0066\u006C';
  18210. t['\uFB03'] = '\u0066\u0066\u0069';
  18211. t['\uFB04'] = '\u0066\u0066\u006C';
  18212. t['\uFB05'] = '\u017F\u0074';
  18213. t['\uFB06'] = '\u0073\u0074';
  18214. t['\uFB13'] = '\u0574\u0576';
  18215. t['\uFB14'] = '\u0574\u0565';
  18216. t['\uFB15'] = '\u0574\u056B';
  18217. t['\uFB16'] = '\u057E\u0576';
  18218. t['\uFB17'] = '\u0574\u056D';
  18219. t['\uFB4F'] = '\u05D0\u05DC';
  18220. t['\uFB50'] = '\u0671';
  18221. t['\uFB51'] = '\u0671';
  18222. t['\uFB52'] = '\u067B';
  18223. t['\uFB53'] = '\u067B';
  18224. t['\uFB54'] = '\u067B';
  18225. t['\uFB55'] = '\u067B';
  18226. t['\uFB56'] = '\u067E';
  18227. t['\uFB57'] = '\u067E';
  18228. t['\uFB58'] = '\u067E';
  18229. t['\uFB59'] = '\u067E';
  18230. t['\uFB5A'] = '\u0680';
  18231. t['\uFB5B'] = '\u0680';
  18232. t['\uFB5C'] = '\u0680';
  18233. t['\uFB5D'] = '\u0680';
  18234. t['\uFB5E'] = '\u067A';
  18235. t['\uFB5F'] = '\u067A';
  18236. t['\uFB60'] = '\u067A';
  18237. t['\uFB61'] = '\u067A';
  18238. t['\uFB62'] = '\u067F';
  18239. t['\uFB63'] = '\u067F';
  18240. t['\uFB64'] = '\u067F';
  18241. t['\uFB65'] = '\u067F';
  18242. t['\uFB66'] = '\u0679';
  18243. t['\uFB67'] = '\u0679';
  18244. t['\uFB68'] = '\u0679';
  18245. t['\uFB69'] = '\u0679';
  18246. t['\uFB6A'] = '\u06A4';
  18247. t['\uFB6B'] = '\u06A4';
  18248. t['\uFB6C'] = '\u06A4';
  18249. t['\uFB6D'] = '\u06A4';
  18250. t['\uFB6E'] = '\u06A6';
  18251. t['\uFB6F'] = '\u06A6';
  18252. t['\uFB70'] = '\u06A6';
  18253. t['\uFB71'] = '\u06A6';
  18254. t['\uFB72'] = '\u0684';
  18255. t['\uFB73'] = '\u0684';
  18256. t['\uFB74'] = '\u0684';
  18257. t['\uFB75'] = '\u0684';
  18258. t['\uFB76'] = '\u0683';
  18259. t['\uFB77'] = '\u0683';
  18260. t['\uFB78'] = '\u0683';
  18261. t['\uFB79'] = '\u0683';
  18262. t['\uFB7A'] = '\u0686';
  18263. t['\uFB7B'] = '\u0686';
  18264. t['\uFB7C'] = '\u0686';
  18265. t['\uFB7D'] = '\u0686';
  18266. t['\uFB7E'] = '\u0687';
  18267. t['\uFB7F'] = '\u0687';
  18268. t['\uFB80'] = '\u0687';
  18269. t['\uFB81'] = '\u0687';
  18270. t['\uFB82'] = '\u068D';
  18271. t['\uFB83'] = '\u068D';
  18272. t['\uFB84'] = '\u068C';
  18273. t['\uFB85'] = '\u068C';
  18274. t['\uFB86'] = '\u068E';
  18275. t['\uFB87'] = '\u068E';
  18276. t['\uFB88'] = '\u0688';
  18277. t['\uFB89'] = '\u0688';
  18278. t['\uFB8A'] = '\u0698';
  18279. t['\uFB8B'] = '\u0698';
  18280. t['\uFB8C'] = '\u0691';
  18281. t['\uFB8D'] = '\u0691';
  18282. t['\uFB8E'] = '\u06A9';
  18283. t['\uFB8F'] = '\u06A9';
  18284. t['\uFB90'] = '\u06A9';
  18285. t['\uFB91'] = '\u06A9';
  18286. t['\uFB92'] = '\u06AF';
  18287. t['\uFB93'] = '\u06AF';
  18288. t['\uFB94'] = '\u06AF';
  18289. t['\uFB95'] = '\u06AF';
  18290. t['\uFB96'] = '\u06B3';
  18291. t['\uFB97'] = '\u06B3';
  18292. t['\uFB98'] = '\u06B3';
  18293. t['\uFB99'] = '\u06B3';
  18294. t['\uFB9A'] = '\u06B1';
  18295. t['\uFB9B'] = '\u06B1';
  18296. t['\uFB9C'] = '\u06B1';
  18297. t['\uFB9D'] = '\u06B1';
  18298. t['\uFB9E'] = '\u06BA';
  18299. t['\uFB9F'] = '\u06BA';
  18300. t['\uFBA0'] = '\u06BB';
  18301. t['\uFBA1'] = '\u06BB';
  18302. t['\uFBA2'] = '\u06BB';
  18303. t['\uFBA3'] = '\u06BB';
  18304. t['\uFBA4'] = '\u06C0';
  18305. t['\uFBA5'] = '\u06C0';
  18306. t['\uFBA6'] = '\u06C1';
  18307. t['\uFBA7'] = '\u06C1';
  18308. t['\uFBA8'] = '\u06C1';
  18309. t['\uFBA9'] = '\u06C1';
  18310. t['\uFBAA'] = '\u06BE';
  18311. t['\uFBAB'] = '\u06BE';
  18312. t['\uFBAC'] = '\u06BE';
  18313. t['\uFBAD'] = '\u06BE';
  18314. t['\uFBAE'] = '\u06D2';
  18315. t['\uFBAF'] = '\u06D2';
  18316. t['\uFBB0'] = '\u06D3';
  18317. t['\uFBB1'] = '\u06D3';
  18318. t['\uFBD3'] = '\u06AD';
  18319. t['\uFBD4'] = '\u06AD';
  18320. t['\uFBD5'] = '\u06AD';
  18321. t['\uFBD6'] = '\u06AD';
  18322. t['\uFBD7'] = '\u06C7';
  18323. t['\uFBD8'] = '\u06C7';
  18324. t['\uFBD9'] = '\u06C6';
  18325. t['\uFBDA'] = '\u06C6';
  18326. t['\uFBDB'] = '\u06C8';
  18327. t['\uFBDC'] = '\u06C8';
  18328. t['\uFBDD'] = '\u0677';
  18329. t['\uFBDE'] = '\u06CB';
  18330. t['\uFBDF'] = '\u06CB';
  18331. t['\uFBE0'] = '\u06C5';
  18332. t['\uFBE1'] = '\u06C5';
  18333. t['\uFBE2'] = '\u06C9';
  18334. t['\uFBE3'] = '\u06C9';
  18335. t['\uFBE4'] = '\u06D0';
  18336. t['\uFBE5'] = '\u06D0';
  18337. t['\uFBE6'] = '\u06D0';
  18338. t['\uFBE7'] = '\u06D0';
  18339. t['\uFBE8'] = '\u0649';
  18340. t['\uFBE9'] = '\u0649';
  18341. t['\uFBEA'] = '\u0626\u0627';
  18342. t['\uFBEB'] = '\u0626\u0627';
  18343. t['\uFBEC'] = '\u0626\u06D5';
  18344. t['\uFBED'] = '\u0626\u06D5';
  18345. t['\uFBEE'] = '\u0626\u0648';
  18346. t['\uFBEF'] = '\u0626\u0648';
  18347. t['\uFBF0'] = '\u0626\u06C7';
  18348. t['\uFBF1'] = '\u0626\u06C7';
  18349. t['\uFBF2'] = '\u0626\u06C6';
  18350. t['\uFBF3'] = '\u0626\u06C6';
  18351. t['\uFBF4'] = '\u0626\u06C8';
  18352. t['\uFBF5'] = '\u0626\u06C8';
  18353. t['\uFBF6'] = '\u0626\u06D0';
  18354. t['\uFBF7'] = '\u0626\u06D0';
  18355. t['\uFBF8'] = '\u0626\u06D0';
  18356. t['\uFBF9'] = '\u0626\u0649';
  18357. t['\uFBFA'] = '\u0626\u0649';
  18358. t['\uFBFB'] = '\u0626\u0649';
  18359. t['\uFBFC'] = '\u06CC';
  18360. t['\uFBFD'] = '\u06CC';
  18361. t['\uFBFE'] = '\u06CC';
  18362. t['\uFBFF'] = '\u06CC';
  18363. t['\uFC00'] = '\u0626\u062C';
  18364. t['\uFC01'] = '\u0626\u062D';
  18365. t['\uFC02'] = '\u0626\u0645';
  18366. t['\uFC03'] = '\u0626\u0649';
  18367. t['\uFC04'] = '\u0626\u064A';
  18368. t['\uFC05'] = '\u0628\u062C';
  18369. t['\uFC06'] = '\u0628\u062D';
  18370. t['\uFC07'] = '\u0628\u062E';
  18371. t['\uFC08'] = '\u0628\u0645';
  18372. t['\uFC09'] = '\u0628\u0649';
  18373. t['\uFC0A'] = '\u0628\u064A';
  18374. t['\uFC0B'] = '\u062A\u062C';
  18375. t['\uFC0C'] = '\u062A\u062D';
  18376. t['\uFC0D'] = '\u062A\u062E';
  18377. t['\uFC0E'] = '\u062A\u0645';
  18378. t['\uFC0F'] = '\u062A\u0649';
  18379. t['\uFC10'] = '\u062A\u064A';
  18380. t['\uFC11'] = '\u062B\u062C';
  18381. t['\uFC12'] = '\u062B\u0645';
  18382. t['\uFC13'] = '\u062B\u0649';
  18383. t['\uFC14'] = '\u062B\u064A';
  18384. t['\uFC15'] = '\u062C\u062D';
  18385. t['\uFC16'] = '\u062C\u0645';
  18386. t['\uFC17'] = '\u062D\u062C';
  18387. t['\uFC18'] = '\u062D\u0645';
  18388. t['\uFC19'] = '\u062E\u062C';
  18389. t['\uFC1A'] = '\u062E\u062D';
  18390. t['\uFC1B'] = '\u062E\u0645';
  18391. t['\uFC1C'] = '\u0633\u062C';
  18392. t['\uFC1D'] = '\u0633\u062D';
  18393. t['\uFC1E'] = '\u0633\u062E';
  18394. t['\uFC1F'] = '\u0633\u0645';
  18395. t['\uFC20'] = '\u0635\u062D';
  18396. t['\uFC21'] = '\u0635\u0645';
  18397. t['\uFC22'] = '\u0636\u062C';
  18398. t['\uFC23'] = '\u0636\u062D';
  18399. t['\uFC24'] = '\u0636\u062E';
  18400. t['\uFC25'] = '\u0636\u0645';
  18401. t['\uFC26'] = '\u0637\u062D';
  18402. t['\uFC27'] = '\u0637\u0645';
  18403. t['\uFC28'] = '\u0638\u0645';
  18404. t['\uFC29'] = '\u0639\u062C';
  18405. t['\uFC2A'] = '\u0639\u0645';
  18406. t['\uFC2B'] = '\u063A\u062C';
  18407. t['\uFC2C'] = '\u063A\u0645';
  18408. t['\uFC2D'] = '\u0641\u062C';
  18409. t['\uFC2E'] = '\u0641\u062D';
  18410. t['\uFC2F'] = '\u0641\u062E';
  18411. t['\uFC30'] = '\u0641\u0645';
  18412. t['\uFC31'] = '\u0641\u0649';
  18413. t['\uFC32'] = '\u0641\u064A';
  18414. t['\uFC33'] = '\u0642\u062D';
  18415. t['\uFC34'] = '\u0642\u0645';
  18416. t['\uFC35'] = '\u0642\u0649';
  18417. t['\uFC36'] = '\u0642\u064A';
  18418. t['\uFC37'] = '\u0643\u0627';
  18419. t['\uFC38'] = '\u0643\u062C';
  18420. t['\uFC39'] = '\u0643\u062D';
  18421. t['\uFC3A'] = '\u0643\u062E';
  18422. t['\uFC3B'] = '\u0643\u0644';
  18423. t['\uFC3C'] = '\u0643\u0645';
  18424. t['\uFC3D'] = '\u0643\u0649';
  18425. t['\uFC3E'] = '\u0643\u064A';
  18426. t['\uFC3F'] = '\u0644\u062C';
  18427. t['\uFC40'] = '\u0644\u062D';
  18428. t['\uFC41'] = '\u0644\u062E';
  18429. t['\uFC42'] = '\u0644\u0645';
  18430. t['\uFC43'] = '\u0644\u0649';
  18431. t['\uFC44'] = '\u0644\u064A';
  18432. t['\uFC45'] = '\u0645\u062C';
  18433. t['\uFC46'] = '\u0645\u062D';
  18434. t['\uFC47'] = '\u0645\u062E';
  18435. t['\uFC48'] = '\u0645\u0645';
  18436. t['\uFC49'] = '\u0645\u0649';
  18437. t['\uFC4A'] = '\u0645\u064A';
  18438. t['\uFC4B'] = '\u0646\u062C';
  18439. t['\uFC4C'] = '\u0646\u062D';
  18440. t['\uFC4D'] = '\u0646\u062E';
  18441. t['\uFC4E'] = '\u0646\u0645';
  18442. t['\uFC4F'] = '\u0646\u0649';
  18443. t['\uFC50'] = '\u0646\u064A';
  18444. t['\uFC51'] = '\u0647\u062C';
  18445. t['\uFC52'] = '\u0647\u0645';
  18446. t['\uFC53'] = '\u0647\u0649';
  18447. t['\uFC54'] = '\u0647\u064A';
  18448. t['\uFC55'] = '\u064A\u062C';
  18449. t['\uFC56'] = '\u064A\u062D';
  18450. t['\uFC57'] = '\u064A\u062E';
  18451. t['\uFC58'] = '\u064A\u0645';
  18452. t['\uFC59'] = '\u064A\u0649';
  18453. t['\uFC5A'] = '\u064A\u064A';
  18454. t['\uFC5B'] = '\u0630\u0670';
  18455. t['\uFC5C'] = '\u0631\u0670';
  18456. t['\uFC5D'] = '\u0649\u0670';
  18457. t['\uFC5E'] = '\u0020\u064C\u0651';
  18458. t['\uFC5F'] = '\u0020\u064D\u0651';
  18459. t['\uFC60'] = '\u0020\u064E\u0651';
  18460. t['\uFC61'] = '\u0020\u064F\u0651';
  18461. t['\uFC62'] = '\u0020\u0650\u0651';
  18462. t['\uFC63'] = '\u0020\u0651\u0670';
  18463. t['\uFC64'] = '\u0626\u0631';
  18464. t['\uFC65'] = '\u0626\u0632';
  18465. t['\uFC66'] = '\u0626\u0645';
  18466. t['\uFC67'] = '\u0626\u0646';
  18467. t['\uFC68'] = '\u0626\u0649';
  18468. t['\uFC69'] = '\u0626\u064A';
  18469. t['\uFC6A'] = '\u0628\u0631';
  18470. t['\uFC6B'] = '\u0628\u0632';
  18471. t['\uFC6C'] = '\u0628\u0645';
  18472. t['\uFC6D'] = '\u0628\u0646';
  18473. t['\uFC6E'] = '\u0628\u0649';
  18474. t['\uFC6F'] = '\u0628\u064A';
  18475. t['\uFC70'] = '\u062A\u0631';
  18476. t['\uFC71'] = '\u062A\u0632';
  18477. t['\uFC72'] = '\u062A\u0645';
  18478. t['\uFC73'] = '\u062A\u0646';
  18479. t['\uFC74'] = '\u062A\u0649';
  18480. t['\uFC75'] = '\u062A\u064A';
  18481. t['\uFC76'] = '\u062B\u0631';
  18482. t['\uFC77'] = '\u062B\u0632';
  18483. t['\uFC78'] = '\u062B\u0645';
  18484. t['\uFC79'] = '\u062B\u0646';
  18485. t['\uFC7A'] = '\u062B\u0649';
  18486. t['\uFC7B'] = '\u062B\u064A';
  18487. t['\uFC7C'] = '\u0641\u0649';
  18488. t['\uFC7D'] = '\u0641\u064A';
  18489. t['\uFC7E'] = '\u0642\u0649';
  18490. t['\uFC7F'] = '\u0642\u064A';
  18491. t['\uFC80'] = '\u0643\u0627';
  18492. t['\uFC81'] = '\u0643\u0644';
  18493. t['\uFC82'] = '\u0643\u0645';
  18494. t['\uFC83'] = '\u0643\u0649';
  18495. t['\uFC84'] = '\u0643\u064A';
  18496. t['\uFC85'] = '\u0644\u0645';
  18497. t['\uFC86'] = '\u0644\u0649';
  18498. t['\uFC87'] = '\u0644\u064A';
  18499. t['\uFC88'] = '\u0645\u0627';
  18500. t['\uFC89'] = '\u0645\u0645';
  18501. t['\uFC8A'] = '\u0646\u0631';
  18502. t['\uFC8B'] = '\u0646\u0632';
  18503. t['\uFC8C'] = '\u0646\u0645';
  18504. t['\uFC8D'] = '\u0646\u0646';
  18505. t['\uFC8E'] = '\u0646\u0649';
  18506. t['\uFC8F'] = '\u0646\u064A';
  18507. t['\uFC90'] = '\u0649\u0670';
  18508. t['\uFC91'] = '\u064A\u0631';
  18509. t['\uFC92'] = '\u064A\u0632';
  18510. t['\uFC93'] = '\u064A\u0645';
  18511. t['\uFC94'] = '\u064A\u0646';
  18512. t['\uFC95'] = '\u064A\u0649';
  18513. t['\uFC96'] = '\u064A\u064A';
  18514. t['\uFC97'] = '\u0626\u062C';
  18515. t['\uFC98'] = '\u0626\u062D';
  18516. t['\uFC99'] = '\u0626\u062E';
  18517. t['\uFC9A'] = '\u0626\u0645';
  18518. t['\uFC9B'] = '\u0626\u0647';
  18519. t['\uFC9C'] = '\u0628\u062C';
  18520. t['\uFC9D'] = '\u0628\u062D';
  18521. t['\uFC9E'] = '\u0628\u062E';
  18522. t['\uFC9F'] = '\u0628\u0645';
  18523. t['\uFCA0'] = '\u0628\u0647';
  18524. t['\uFCA1'] = '\u062A\u062C';
  18525. t['\uFCA2'] = '\u062A\u062D';
  18526. t['\uFCA3'] = '\u062A\u062E';
  18527. t['\uFCA4'] = '\u062A\u0645';
  18528. t['\uFCA5'] = '\u062A\u0647';
  18529. t['\uFCA6'] = '\u062B\u0645';
  18530. t['\uFCA7'] = '\u062C\u062D';
  18531. t['\uFCA8'] = '\u062C\u0645';
  18532. t['\uFCA9'] = '\u062D\u062C';
  18533. t['\uFCAA'] = '\u062D\u0645';
  18534. t['\uFCAB'] = '\u062E\u062C';
  18535. t['\uFCAC'] = '\u062E\u0645';
  18536. t['\uFCAD'] = '\u0633\u062C';
  18537. t['\uFCAE'] = '\u0633\u062D';
  18538. t['\uFCAF'] = '\u0633\u062E';
  18539. t['\uFCB0'] = '\u0633\u0645';
  18540. t['\uFCB1'] = '\u0635\u062D';
  18541. t['\uFCB2'] = '\u0635\u062E';
  18542. t['\uFCB3'] = '\u0635\u0645';
  18543. t['\uFCB4'] = '\u0636\u062C';
  18544. t['\uFCB5'] = '\u0636\u062D';
  18545. t['\uFCB6'] = '\u0636\u062E';
  18546. t['\uFCB7'] = '\u0636\u0645';
  18547. t['\uFCB8'] = '\u0637\u062D';
  18548. t['\uFCB9'] = '\u0638\u0645';
  18549. t['\uFCBA'] = '\u0639\u062C';
  18550. t['\uFCBB'] = '\u0639\u0645';
  18551. t['\uFCBC'] = '\u063A\u062C';
  18552. t['\uFCBD'] = '\u063A\u0645';
  18553. t['\uFCBE'] = '\u0641\u062C';
  18554. t['\uFCBF'] = '\u0641\u062D';
  18555. t['\uFCC0'] = '\u0641\u062E';
  18556. t['\uFCC1'] = '\u0641\u0645';
  18557. t['\uFCC2'] = '\u0642\u062D';
  18558. t['\uFCC3'] = '\u0642\u0645';
  18559. t['\uFCC4'] = '\u0643\u062C';
  18560. t['\uFCC5'] = '\u0643\u062D';
  18561. t['\uFCC6'] = '\u0643\u062E';
  18562. t['\uFCC7'] = '\u0643\u0644';
  18563. t['\uFCC8'] = '\u0643\u0645';
  18564. t['\uFCC9'] = '\u0644\u062C';
  18565. t['\uFCCA'] = '\u0644\u062D';
  18566. t['\uFCCB'] = '\u0644\u062E';
  18567. t['\uFCCC'] = '\u0644\u0645';
  18568. t['\uFCCD'] = '\u0644\u0647';
  18569. t['\uFCCE'] = '\u0645\u062C';
  18570. t['\uFCCF'] = '\u0645\u062D';
  18571. t['\uFCD0'] = '\u0645\u062E';
  18572. t['\uFCD1'] = '\u0645\u0645';
  18573. t['\uFCD2'] = '\u0646\u062C';
  18574. t['\uFCD3'] = '\u0646\u062D';
  18575. t['\uFCD4'] = '\u0646\u062E';
  18576. t['\uFCD5'] = '\u0646\u0645';
  18577. t['\uFCD6'] = '\u0646\u0647';
  18578. t['\uFCD7'] = '\u0647\u062C';
  18579. t['\uFCD8'] = '\u0647\u0645';
  18580. t['\uFCD9'] = '\u0647\u0670';
  18581. t['\uFCDA'] = '\u064A\u062C';
  18582. t['\uFCDB'] = '\u064A\u062D';
  18583. t['\uFCDC'] = '\u064A\u062E';
  18584. t['\uFCDD'] = '\u064A\u0645';
  18585. t['\uFCDE'] = '\u064A\u0647';
  18586. t['\uFCDF'] = '\u0626\u0645';
  18587. t['\uFCE0'] = '\u0626\u0647';
  18588. t['\uFCE1'] = '\u0628\u0645';
  18589. t['\uFCE2'] = '\u0628\u0647';
  18590. t['\uFCE3'] = '\u062A\u0645';
  18591. t['\uFCE4'] = '\u062A\u0647';
  18592. t['\uFCE5'] = '\u062B\u0645';
  18593. t['\uFCE6'] = '\u062B\u0647';
  18594. t['\uFCE7'] = '\u0633\u0645';
  18595. t['\uFCE8'] = '\u0633\u0647';
  18596. t['\uFCE9'] = '\u0634\u0645';
  18597. t['\uFCEA'] = '\u0634\u0647';
  18598. t['\uFCEB'] = '\u0643\u0644';
  18599. t['\uFCEC'] = '\u0643\u0645';
  18600. t['\uFCED'] = '\u0644\u0645';
  18601. t['\uFCEE'] = '\u0646\u0645';
  18602. t['\uFCEF'] = '\u0646\u0647';
  18603. t['\uFCF0'] = '\u064A\u0645';
  18604. t['\uFCF1'] = '\u064A\u0647';
  18605. t['\uFCF2'] = '\u0640\u064E\u0651';
  18606. t['\uFCF3'] = '\u0640\u064F\u0651';
  18607. t['\uFCF4'] = '\u0640\u0650\u0651';
  18608. t['\uFCF5'] = '\u0637\u0649';
  18609. t['\uFCF6'] = '\u0637\u064A';
  18610. t['\uFCF7'] = '\u0639\u0649';
  18611. t['\uFCF8'] = '\u0639\u064A';
  18612. t['\uFCF9'] = '\u063A\u0649';
  18613. t['\uFCFA'] = '\u063A\u064A';
  18614. t['\uFCFB'] = '\u0633\u0649';
  18615. t['\uFCFC'] = '\u0633\u064A';
  18616. t['\uFCFD'] = '\u0634\u0649';
  18617. t['\uFCFE'] = '\u0634\u064A';
  18618. t['\uFCFF'] = '\u062D\u0649';
  18619. t['\uFD00'] = '\u062D\u064A';
  18620. t['\uFD01'] = '\u062C\u0649';
  18621. t['\uFD02'] = '\u062C\u064A';
  18622. t['\uFD03'] = '\u062E\u0649';
  18623. t['\uFD04'] = '\u062E\u064A';
  18624. t['\uFD05'] = '\u0635\u0649';
  18625. t['\uFD06'] = '\u0635\u064A';
  18626. t['\uFD07'] = '\u0636\u0649';
  18627. t['\uFD08'] = '\u0636\u064A';
  18628. t['\uFD09'] = '\u0634\u062C';
  18629. t['\uFD0A'] = '\u0634\u062D';
  18630. t['\uFD0B'] = '\u0634\u062E';
  18631. t['\uFD0C'] = '\u0634\u0645';
  18632. t['\uFD0D'] = '\u0634\u0631';
  18633. t['\uFD0E'] = '\u0633\u0631';
  18634. t['\uFD0F'] = '\u0635\u0631';
  18635. t['\uFD10'] = '\u0636\u0631';
  18636. t['\uFD11'] = '\u0637\u0649';
  18637. t['\uFD12'] = '\u0637\u064A';
  18638. t['\uFD13'] = '\u0639\u0649';
  18639. t['\uFD14'] = '\u0639\u064A';
  18640. t['\uFD15'] = '\u063A\u0649';
  18641. t['\uFD16'] = '\u063A\u064A';
  18642. t['\uFD17'] = '\u0633\u0649';
  18643. t['\uFD18'] = '\u0633\u064A';
  18644. t['\uFD19'] = '\u0634\u0649';
  18645. t['\uFD1A'] = '\u0634\u064A';
  18646. t['\uFD1B'] = '\u062D\u0649';
  18647. t['\uFD1C'] = '\u062D\u064A';
  18648. t['\uFD1D'] = '\u062C\u0649';
  18649. t['\uFD1E'] = '\u062C\u064A';
  18650. t['\uFD1F'] = '\u062E\u0649';
  18651. t['\uFD20'] = '\u062E\u064A';
  18652. t['\uFD21'] = '\u0635\u0649';
  18653. t['\uFD22'] = '\u0635\u064A';
  18654. t['\uFD23'] = '\u0636\u0649';
  18655. t['\uFD24'] = '\u0636\u064A';
  18656. t['\uFD25'] = '\u0634\u062C';
  18657. t['\uFD26'] = '\u0634\u062D';
  18658. t['\uFD27'] = '\u0634\u062E';
  18659. t['\uFD28'] = '\u0634\u0645';
  18660. t['\uFD29'] = '\u0634\u0631';
  18661. t['\uFD2A'] = '\u0633\u0631';
  18662. t['\uFD2B'] = '\u0635\u0631';
  18663. t['\uFD2C'] = '\u0636\u0631';
  18664. t['\uFD2D'] = '\u0634\u062C';
  18665. t['\uFD2E'] = '\u0634\u062D';
  18666. t['\uFD2F'] = '\u0634\u062E';
  18667. t['\uFD30'] = '\u0634\u0645';
  18668. t['\uFD31'] = '\u0633\u0647';
  18669. t['\uFD32'] = '\u0634\u0647';
  18670. t['\uFD33'] = '\u0637\u0645';
  18671. t['\uFD34'] = '\u0633\u062C';
  18672. t['\uFD35'] = '\u0633\u062D';
  18673. t['\uFD36'] = '\u0633\u062E';
  18674. t['\uFD37'] = '\u0634\u062C';
  18675. t['\uFD38'] = '\u0634\u062D';
  18676. t['\uFD39'] = '\u0634\u062E';
  18677. t['\uFD3A'] = '\u0637\u0645';
  18678. t['\uFD3B'] = '\u0638\u0645';
  18679. t['\uFD3C'] = '\u0627\u064B';
  18680. t['\uFD3D'] = '\u0627\u064B';
  18681. t['\uFD50'] = '\u062A\u062C\u0645';
  18682. t['\uFD51'] = '\u062A\u062D\u062C';
  18683. t['\uFD52'] = '\u062A\u062D\u062C';
  18684. t['\uFD53'] = '\u062A\u062D\u0645';
  18685. t['\uFD54'] = '\u062A\u062E\u0645';
  18686. t['\uFD55'] = '\u062A\u0645\u062C';
  18687. t['\uFD56'] = '\u062A\u0645\u062D';
  18688. t['\uFD57'] = '\u062A\u0645\u062E';
  18689. t['\uFD58'] = '\u062C\u0645\u062D';
  18690. t['\uFD59'] = '\u062C\u0645\u062D';
  18691. t['\uFD5A'] = '\u062D\u0645\u064A';
  18692. t['\uFD5B'] = '\u062D\u0645\u0649';
  18693. t['\uFD5C'] = '\u0633\u062D\u062C';
  18694. t['\uFD5D'] = '\u0633\u062C\u062D';
  18695. t['\uFD5E'] = '\u0633\u062C\u0649';
  18696. t['\uFD5F'] = '\u0633\u0645\u062D';
  18697. t['\uFD60'] = '\u0633\u0645\u062D';
  18698. t['\uFD61'] = '\u0633\u0645\u062C';
  18699. t['\uFD62'] = '\u0633\u0645\u0645';
  18700. t['\uFD63'] = '\u0633\u0645\u0645';
  18701. t['\uFD64'] = '\u0635\u062D\u062D';
  18702. t['\uFD65'] = '\u0635\u062D\u062D';
  18703. t['\uFD66'] = '\u0635\u0645\u0645';
  18704. t['\uFD67'] = '\u0634\u062D\u0645';
  18705. t['\uFD68'] = '\u0634\u062D\u0645';
  18706. t['\uFD69'] = '\u0634\u062C\u064A';
  18707. t['\uFD6A'] = '\u0634\u0645\u062E';
  18708. t['\uFD6B'] = '\u0634\u0645\u062E';
  18709. t['\uFD6C'] = '\u0634\u0645\u0645';
  18710. t['\uFD6D'] = '\u0634\u0645\u0645';
  18711. t['\uFD6E'] = '\u0636\u062D\u0649';
  18712. t['\uFD6F'] = '\u0636\u062E\u0645';
  18713. t['\uFD70'] = '\u0636\u062E\u0645';
  18714. t['\uFD71'] = '\u0637\u0645\u062D';
  18715. t['\uFD72'] = '\u0637\u0645\u062D';
  18716. t['\uFD73'] = '\u0637\u0645\u0645';
  18717. t['\uFD74'] = '\u0637\u0645\u064A';
  18718. t['\uFD75'] = '\u0639\u062C\u0645';
  18719. t['\uFD76'] = '\u0639\u0645\u0645';
  18720. t['\uFD77'] = '\u0639\u0645\u0645';
  18721. t['\uFD78'] = '\u0639\u0645\u0649';
  18722. t['\uFD79'] = '\u063A\u0645\u0645';
  18723. t['\uFD7A'] = '\u063A\u0645\u064A';
  18724. t['\uFD7B'] = '\u063A\u0645\u0649';
  18725. t['\uFD7C'] = '\u0641\u062E\u0645';
  18726. t['\uFD7D'] = '\u0641\u062E\u0645';
  18727. t['\uFD7E'] = '\u0642\u0645\u062D';
  18728. t['\uFD7F'] = '\u0642\u0645\u0645';
  18729. t['\uFD80'] = '\u0644\u062D\u0645';
  18730. t['\uFD81'] = '\u0644\u062D\u064A';
  18731. t['\uFD82'] = '\u0644\u062D\u0649';
  18732. t['\uFD83'] = '\u0644\u062C\u062C';
  18733. t['\uFD84'] = '\u0644\u062C\u062C';
  18734. t['\uFD85'] = '\u0644\u062E\u0645';
  18735. t['\uFD86'] = '\u0644\u062E\u0645';
  18736. t['\uFD87'] = '\u0644\u0645\u062D';
  18737. t['\uFD88'] = '\u0644\u0645\u062D';
  18738. t['\uFD89'] = '\u0645\u062D\u062C';
  18739. t['\uFD8A'] = '\u0645\u062D\u0645';
  18740. t['\uFD8B'] = '\u0645\u062D\u064A';
  18741. t['\uFD8C'] = '\u0645\u062C\u062D';
  18742. t['\uFD8D'] = '\u0645\u062C\u0645';
  18743. t['\uFD8E'] = '\u0645\u062E\u062C';
  18744. t['\uFD8F'] = '\u0645\u062E\u0645';
  18745. t['\uFD92'] = '\u0645\u062C\u062E';
  18746. t['\uFD93'] = '\u0647\u0645\u062C';
  18747. t['\uFD94'] = '\u0647\u0645\u0645';
  18748. t['\uFD95'] = '\u0646\u062D\u0645';
  18749. t['\uFD96'] = '\u0646\u062D\u0649';
  18750. t['\uFD97'] = '\u0646\u062C\u0645';
  18751. t['\uFD98'] = '\u0646\u062C\u0645';
  18752. t['\uFD99'] = '\u0646\u062C\u0649';
  18753. t['\uFD9A'] = '\u0646\u0645\u064A';
  18754. t['\uFD9B'] = '\u0646\u0645\u0649';
  18755. t['\uFD9C'] = '\u064A\u0645\u0645';
  18756. t['\uFD9D'] = '\u064A\u0645\u0645';
  18757. t['\uFD9E'] = '\u0628\u062E\u064A';
  18758. t['\uFD9F'] = '\u062A\u062C\u064A';
  18759. t['\uFDA0'] = '\u062A\u062C\u0649';
  18760. t['\uFDA1'] = '\u062A\u062E\u064A';
  18761. t['\uFDA2'] = '\u062A\u062E\u0649';
  18762. t['\uFDA3'] = '\u062A\u0645\u064A';
  18763. t['\uFDA4'] = '\u062A\u0645\u0649';
  18764. t['\uFDA5'] = '\u062C\u0645\u064A';
  18765. t['\uFDA6'] = '\u062C\u062D\u0649';
  18766. t['\uFDA7'] = '\u062C\u0645\u0649';
  18767. t['\uFDA8'] = '\u0633\u062E\u0649';
  18768. t['\uFDA9'] = '\u0635\u062D\u064A';
  18769. t['\uFDAA'] = '\u0634\u062D\u064A';
  18770. t['\uFDAB'] = '\u0636\u062D\u064A';
  18771. t['\uFDAC'] = '\u0644\u062C\u064A';
  18772. t['\uFDAD'] = '\u0644\u0645\u064A';
  18773. t['\uFDAE'] = '\u064A\u062D\u064A';
  18774. t['\uFDAF'] = '\u064A\u062C\u064A';
  18775. t['\uFDB0'] = '\u064A\u0645\u064A';
  18776. t['\uFDB1'] = '\u0645\u0645\u064A';
  18777. t['\uFDB2'] = '\u0642\u0645\u064A';
  18778. t['\uFDB3'] = '\u0646\u062D\u064A';
  18779. t['\uFDB4'] = '\u0642\u0645\u062D';
  18780. t['\uFDB5'] = '\u0644\u062D\u0645';
  18781. t['\uFDB6'] = '\u0639\u0645\u064A';
  18782. t['\uFDB7'] = '\u0643\u0645\u064A';
  18783. t['\uFDB8'] = '\u0646\u062C\u062D';
  18784. t['\uFDB9'] = '\u0645\u062E\u064A';
  18785. t['\uFDBA'] = '\u0644\u062C\u0645';
  18786. t['\uFDBB'] = '\u0643\u0645\u0645';
  18787. t['\uFDBC'] = '\u0644\u062C\u0645';
  18788. t['\uFDBD'] = '\u0646\u062C\u062D';
  18789. t['\uFDBE'] = '\u062C\u062D\u064A';
  18790. t['\uFDBF'] = '\u062D\u062C\u064A';
  18791. t['\uFDC0'] = '\u0645\u062C\u064A';
  18792. t['\uFDC1'] = '\u0641\u0645\u064A';
  18793. t['\uFDC2'] = '\u0628\u062D\u064A';
  18794. t['\uFDC3'] = '\u0643\u0645\u0645';
  18795. t['\uFDC4'] = '\u0639\u062C\u0645';
  18796. t['\uFDC5'] = '\u0635\u0645\u0645';
  18797. t['\uFDC6'] = '\u0633\u062E\u064A';
  18798. t['\uFDC7'] = '\u0646\u062C\u064A';
  18799. t['\uFE49'] = '\u203E';
  18800. t['\uFE4A'] = '\u203E';
  18801. t['\uFE4B'] = '\u203E';
  18802. t['\uFE4C'] = '\u203E';
  18803. t['\uFE4D'] = '\u005F';
  18804. t['\uFE4E'] = '\u005F';
  18805. t['\uFE4F'] = '\u005F';
  18806. t['\uFE80'] = '\u0621';
  18807. t['\uFE81'] = '\u0622';
  18808. t['\uFE82'] = '\u0622';
  18809. t['\uFE83'] = '\u0623';
  18810. t['\uFE84'] = '\u0623';
  18811. t['\uFE85'] = '\u0624';
  18812. t['\uFE86'] = '\u0624';
  18813. t['\uFE87'] = '\u0625';
  18814. t['\uFE88'] = '\u0625';
  18815. t['\uFE89'] = '\u0626';
  18816. t['\uFE8A'] = '\u0626';
  18817. t['\uFE8B'] = '\u0626';
  18818. t['\uFE8C'] = '\u0626';
  18819. t['\uFE8D'] = '\u0627';
  18820. t['\uFE8E'] = '\u0627';
  18821. t['\uFE8F'] = '\u0628';
  18822. t['\uFE90'] = '\u0628';
  18823. t['\uFE91'] = '\u0628';
  18824. t['\uFE92'] = '\u0628';
  18825. t['\uFE93'] = '\u0629';
  18826. t['\uFE94'] = '\u0629';
  18827. t['\uFE95'] = '\u062A';
  18828. t['\uFE96'] = '\u062A';
  18829. t['\uFE97'] = '\u062A';
  18830. t['\uFE98'] = '\u062A';
  18831. t['\uFE99'] = '\u062B';
  18832. t['\uFE9A'] = '\u062B';
  18833. t['\uFE9B'] = '\u062B';
  18834. t['\uFE9C'] = '\u062B';
  18835. t['\uFE9D'] = '\u062C';
  18836. t['\uFE9E'] = '\u062C';
  18837. t['\uFE9F'] = '\u062C';
  18838. t['\uFEA0'] = '\u062C';
  18839. t['\uFEA1'] = '\u062D';
  18840. t['\uFEA2'] = '\u062D';
  18841. t['\uFEA3'] = '\u062D';
  18842. t['\uFEA4'] = '\u062D';
  18843. t['\uFEA5'] = '\u062E';
  18844. t['\uFEA6'] = '\u062E';
  18845. t['\uFEA7'] = '\u062E';
  18846. t['\uFEA8'] = '\u062E';
  18847. t['\uFEA9'] = '\u062F';
  18848. t['\uFEAA'] = '\u062F';
  18849. t['\uFEAB'] = '\u0630';
  18850. t['\uFEAC'] = '\u0630';
  18851. t['\uFEAD'] = '\u0631';
  18852. t['\uFEAE'] = '\u0631';
  18853. t['\uFEAF'] = '\u0632';
  18854. t['\uFEB0'] = '\u0632';
  18855. t['\uFEB1'] = '\u0633';
  18856. t['\uFEB2'] = '\u0633';
  18857. t['\uFEB3'] = '\u0633';
  18858. t['\uFEB4'] = '\u0633';
  18859. t['\uFEB5'] = '\u0634';
  18860. t['\uFEB6'] = '\u0634';
  18861. t['\uFEB7'] = '\u0634';
  18862. t['\uFEB8'] = '\u0634';
  18863. t['\uFEB9'] = '\u0635';
  18864. t['\uFEBA'] = '\u0635';
  18865. t['\uFEBB'] = '\u0635';
  18866. t['\uFEBC'] = '\u0635';
  18867. t['\uFEBD'] = '\u0636';
  18868. t['\uFEBE'] = '\u0636';
  18869. t['\uFEBF'] = '\u0636';
  18870. t['\uFEC0'] = '\u0636';
  18871. t['\uFEC1'] = '\u0637';
  18872. t['\uFEC2'] = '\u0637';
  18873. t['\uFEC3'] = '\u0637';
  18874. t['\uFEC4'] = '\u0637';
  18875. t['\uFEC5'] = '\u0638';
  18876. t['\uFEC6'] = '\u0638';
  18877. t['\uFEC7'] = '\u0638';
  18878. t['\uFEC8'] = '\u0638';
  18879. t['\uFEC9'] = '\u0639';
  18880. t['\uFECA'] = '\u0639';
  18881. t['\uFECB'] = '\u0639';
  18882. t['\uFECC'] = '\u0639';
  18883. t['\uFECD'] = '\u063A';
  18884. t['\uFECE'] = '\u063A';
  18885. t['\uFECF'] = '\u063A';
  18886. t['\uFED0'] = '\u063A';
  18887. t['\uFED1'] = '\u0641';
  18888. t['\uFED2'] = '\u0641';
  18889. t['\uFED3'] = '\u0641';
  18890. t['\uFED4'] = '\u0641';
  18891. t['\uFED5'] = '\u0642';
  18892. t['\uFED6'] = '\u0642';
  18893. t['\uFED7'] = '\u0642';
  18894. t['\uFED8'] = '\u0642';
  18895. t['\uFED9'] = '\u0643';
  18896. t['\uFEDA'] = '\u0643';
  18897. t['\uFEDB'] = '\u0643';
  18898. t['\uFEDC'] = '\u0643';
  18899. t['\uFEDD'] = '\u0644';
  18900. t['\uFEDE'] = '\u0644';
  18901. t['\uFEDF'] = '\u0644';
  18902. t['\uFEE0'] = '\u0644';
  18903. t['\uFEE1'] = '\u0645';
  18904. t['\uFEE2'] = '\u0645';
  18905. t['\uFEE3'] = '\u0645';
  18906. t['\uFEE4'] = '\u0645';
  18907. t['\uFEE5'] = '\u0646';
  18908. t['\uFEE6'] = '\u0646';
  18909. t['\uFEE7'] = '\u0646';
  18910. t['\uFEE8'] = '\u0646';
  18911. t['\uFEE9'] = '\u0647';
  18912. t['\uFEEA'] = '\u0647';
  18913. t['\uFEEB'] = '\u0647';
  18914. t['\uFEEC'] = '\u0647';
  18915. t['\uFEED'] = '\u0648';
  18916. t['\uFEEE'] = '\u0648';
  18917. t['\uFEEF'] = '\u0649';
  18918. t['\uFEF0'] = '\u0649';
  18919. t['\uFEF1'] = '\u064A';
  18920. t['\uFEF2'] = '\u064A';
  18921. t['\uFEF3'] = '\u064A';
  18922. t['\uFEF4'] = '\u064A';
  18923. t['\uFEF5'] = '\u0644\u0622';
  18924. t['\uFEF6'] = '\u0644\u0622';
  18925. t['\uFEF7'] = '\u0644\u0623';
  18926. t['\uFEF8'] = '\u0644\u0623';
  18927. t['\uFEF9'] = '\u0644\u0625';
  18928. t['\uFEFA'] = '\u0644\u0625';
  18929. t['\uFEFB'] = '\u0644\u0627';
  18930. t['\uFEFC'] = '\u0644\u0627';
  18931. });
  18932. function reverseIfRtl(chars) {
  18933. var charsLength = chars.length;
  18934. //reverse an arabic ligature
  18935. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18936. return chars;
  18937. }
  18938. var s = '';
  18939. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18940. s += chars[ii];
  18941. }
  18942. return s;
  18943. }
  18944. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  18945. exports.reverseIfRtl = reverseIfRtl;
  18946. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  18947. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  18948. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  18949. }));
  18950. (function (root, factory) {
  18951. {
  18952. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedUtil);
  18953. }
  18954. }(this, function (exports, sharedUtil) {
  18955. var removeNullCharacters = sharedUtil.removeNullCharacters;
  18956. var warn = sharedUtil.warn;
  18957. /**
  18958. * Optimised CSS custom property getter/setter.
  18959. * @class
  18960. */
  18961. var CustomStyle = (function CustomStyleClosure() {
  18962. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  18963. // animate-css-transforms-firefox-webkit.html
  18964. // in some versions of IE9 it is critical that ms appear in this list
  18965. // before Moz
  18966. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  18967. var _cache = Object.create(null);
  18968. function CustomStyle() {}
  18969. CustomStyle.getProp = function get(propName, element) {
  18970. // check cache only when no element is given
  18971. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  18972. return _cache[propName];
  18973. }
  18974. element = element || document.documentElement;
  18975. var style = element.style, prefixed, uPropName;
  18976. // test standard property first
  18977. if (typeof style[propName] === 'string') {
  18978. return (_cache[propName] = propName);
  18979. }
  18980. // capitalize
  18981. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  18982. // test vendor specific properties
  18983. for (var i = 0, l = prefixes.length; i < l; i++) {
  18984. prefixed = prefixes[i] + uPropName;
  18985. if (typeof style[prefixed] === 'string') {
  18986. return (_cache[propName] = prefixed);
  18987. }
  18988. }
  18989. //if all fails then set to undefined
  18990. return (_cache[propName] = 'undefined');
  18991. };
  18992. CustomStyle.setProp = function set(propName, element, str) {
  18993. var prop = this.getProp(propName);
  18994. if (prop !== 'undefined') {
  18995. element.style[prop] = str;
  18996. }
  18997. };
  18998. return CustomStyle;
  18999. })();
  19000. function hasCanvasTypedArrays() {
  19001. var canvas = document.createElement('canvas');
  19002. canvas.width = canvas.height = 1;
  19003. var ctx = canvas.getContext('2d');
  19004. var imageData = ctx.createImageData(1, 1);
  19005. return (typeof imageData.data.buffer !== 'undefined');
  19006. }
  19007. var LinkTarget = {
  19008. NONE: 0, // Default value.
  19009. SELF: 1,
  19010. BLANK: 2,
  19011. PARENT: 3,
  19012. TOP: 4,
  19013. };
  19014. var LinkTargetStringMap = [
  19015. '',
  19016. '_self',
  19017. '_blank',
  19018. '_parent',
  19019. '_top'
  19020. ];
  19021. /**
  19022. * @typedef ExternalLinkParameters
  19023. * @typedef {Object} ExternalLinkParameters
  19024. * @property {string} url - An absolute URL.
  19025. * @property {LinkTarget} target - The link target.
  19026. * @property {string} rel - The link relationship.
  19027. */
  19028. /**
  19029. * Adds various attributes (href, title, target, rel) to hyperlinks.
  19030. * @param {HTMLLinkElement} link - The link element.
  19031. * @param {ExternalLinkParameters} params
  19032. */
  19033. function addLinkAttributes(link, params) {
  19034. var url = params && params.url;
  19035. link.href = link.title = (url ? removeNullCharacters(url) : '');
  19036. if (url) {
  19037. var target = params.target;
  19038. if (typeof target === 'undefined') {
  19039. target = getDefaultSetting('externalLinkTarget');
  19040. }
  19041. link.target = LinkTargetStringMap[target];
  19042. var rel = params.rel;
  19043. if (typeof rel === 'undefined') {
  19044. rel = getDefaultSetting('externalLinkRel');
  19045. }
  19046. link.rel = rel;
  19047. }
  19048. }
  19049. // Gets the file name from a given URL.
  19050. function getFilenameFromUrl(url) {
  19051. var anchor = url.indexOf('#');
  19052. var query = url.indexOf('?');
  19053. var end = Math.min(
  19054. anchor > 0 ? anchor : url.length,
  19055. query > 0 ? query : url.length);
  19056. return url.substring(url.lastIndexOf('/', end) + 1, end);
  19057. }
  19058. function getDefaultSetting(id) {
  19059. // The list of the settings and their default is maintained for backward
  19060. // compatibility and shall not be extended or modified. See also global.js.
  19061. var globalSettings = sharedUtil.globalScope.PDFJS;
  19062. switch (id) {
  19063. case 'pdfBug':
  19064. return globalSettings ? globalSettings.pdfBug : false;
  19065. case 'disableAutoFetch':
  19066. return globalSettings ? globalSettings.disableAutoFetch : false;
  19067. case 'disableStream':
  19068. return globalSettings ? globalSettings.disableStream : false;
  19069. case 'disableRange':
  19070. return globalSettings ? globalSettings.disableRange : false;
  19071. case 'disableFontFace':
  19072. return globalSettings ? globalSettings.disableFontFace : false;
  19073. case 'disableCreateObjectURL':
  19074. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  19075. case 'disableWebGL':
  19076. return globalSettings ? globalSettings.disableWebGL : true;
  19077. case 'cMapUrl':
  19078. return globalSettings ? globalSettings.cMapUrl : null;
  19079. case 'cMapPacked':
  19080. return globalSettings ? globalSettings.cMapPacked : false;
  19081. case 'postMessageTransfers':
  19082. return globalSettings ? globalSettings.postMessageTransfers : true;
  19083. case 'workerSrc':
  19084. return globalSettings ? globalSettings.workerSrc : null;
  19085. case 'disableWorker':
  19086. return globalSettings ? globalSettings.disableWorker : false;
  19087. case 'maxImageSize':
  19088. return globalSettings ? globalSettings.maxImageSize : -1;
  19089. case 'imageResourcesPath':
  19090. return globalSettings ? globalSettings.imageResourcesPath : '';
  19091. case 'isEvalSupported':
  19092. return globalSettings ? globalSettings.isEvalSupported : true;
  19093. case 'externalLinkTarget':
  19094. if (!globalSettings) {
  19095. return LinkTarget.NONE;
  19096. }
  19097. switch (globalSettings.externalLinkTarget) {
  19098. case LinkTarget.NONE:
  19099. case LinkTarget.SELF:
  19100. case LinkTarget.BLANK:
  19101. case LinkTarget.PARENT:
  19102. case LinkTarget.TOP:
  19103. return globalSettings.externalLinkTarget;
  19104. }
  19105. warn('PDFJS.externalLinkTarget is invalid: ' +
  19106. globalSettings.externalLinkTarget);
  19107. // Reset the external link target, to suppress further warnings.
  19108. globalSettings.externalLinkTarget = LinkTarget.NONE;
  19109. return LinkTarget.NONE;
  19110. case 'externalLinkRel':
  19111. return globalSettings ? globalSettings.externalLinkRel : 'noreferrer';
  19112. case 'enableStats':
  19113. return !!(globalSettings && globalSettings.enableStats);
  19114. default:
  19115. throw new Error('Unknown default setting: ' + id);
  19116. }
  19117. }
  19118. function isExternalLinkTargetSet() {
  19119. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  19120. switch (externalLinkTarget) {
  19121. case LinkTarget.NONE:
  19122. return false;
  19123. case LinkTarget.SELF:
  19124. case LinkTarget.BLANK:
  19125. case LinkTarget.PARENT:
  19126. case LinkTarget.TOP:
  19127. return true;
  19128. }
  19129. }
  19130. exports.CustomStyle = CustomStyle;
  19131. exports.addLinkAttributes = addLinkAttributes;
  19132. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  19133. exports.getFilenameFromUrl = getFilenameFromUrl;
  19134. exports.LinkTarget = LinkTarget;
  19135. exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
  19136. exports.getDefaultSetting = getDefaultSetting;
  19137. }));
  19138. (function (root, factory) {
  19139. {
  19140. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil);
  19141. }
  19142. }(this, function (exports, sharedUtil) {
  19143. var assert = sharedUtil.assert;
  19144. var bytesToString = sharedUtil.bytesToString;
  19145. var string32 = sharedUtil.string32;
  19146. var shadow = sharedUtil.shadow;
  19147. var warn = sharedUtil.warn;
  19148. function FontLoader(docId) {
  19149. this.docId = docId;
  19150. this.styleElement = null;
  19151. this.nativeFontFaces = [];
  19152. this.loadTestFontId = 0;
  19153. this.loadingContext = {
  19154. requests: [],
  19155. nextRequestId: 0
  19156. };
  19157. }
  19158. FontLoader.prototype = {
  19159. insertRule: function fontLoaderInsertRule(rule) {
  19160. var styleElement = this.styleElement;
  19161. if (!styleElement) {
  19162. styleElement = this.styleElement = document.createElement('style');
  19163. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  19164. document.documentElement.getElementsByTagName('head')[0].appendChild(
  19165. styleElement);
  19166. }
  19167. var styleSheet = styleElement.sheet;
  19168. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  19169. },
  19170. clear: function fontLoaderClear() {
  19171. var styleElement = this.styleElement;
  19172. if (styleElement) {
  19173. styleElement.parentNode.removeChild(styleElement);
  19174. styleElement = this.styleElement = null;
  19175. }
  19176. this.nativeFontFaces.forEach(function(nativeFontFace) {
  19177. document.fonts.delete(nativeFontFace);
  19178. });
  19179. this.nativeFontFaces.length = 0;
  19180. },
  19181. get loadTestFont() {
  19182. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  19183. // height.
  19184. return shadow(this, 'loadTestFont', atob(
  19185. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  19186. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  19187. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  19188. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  19189. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  19190. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  19191. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  19192. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  19193. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  19194. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  19195. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  19196. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  19197. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  19198. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19199. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19200. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19201. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  19202. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  19203. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  19204. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  19205. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  19206. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  19207. ));
  19208. },
  19209. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  19210. this.nativeFontFaces.push(nativeFontFace);
  19211. document.fonts.add(nativeFontFace);
  19212. },
  19213. bind: function fontLoaderBind(fonts, callback) {
  19214. var rules = [];
  19215. var fontsToLoad = [];
  19216. var fontLoadPromises = [];
  19217. var getNativeFontPromise = function(nativeFontFace) {
  19218. // Return a promise that is always fulfilled, even when the font fails to
  19219. // load.
  19220. return nativeFontFace.loaded.catch(function(e) {
  19221. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  19222. });
  19223. };
  19224. for (var i = 0, ii = fonts.length; i < ii; i++) {
  19225. var font = fonts[i];
  19226. // Add the font to the DOM only once or skip if the font
  19227. // is already loaded.
  19228. if (font.attached || font.loading === false) {
  19229. continue;
  19230. }
  19231. font.attached = true;
  19232. if (FontLoader.isFontLoadingAPISupported) {
  19233. var nativeFontFace = font.createNativeFontFace();
  19234. if (nativeFontFace) {
  19235. this.addNativeFontFace(nativeFontFace);
  19236. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  19237. }
  19238. } else {
  19239. var rule = font.createFontFaceRule();
  19240. if (rule) {
  19241. this.insertRule(rule);
  19242. rules.push(rule);
  19243. fontsToLoad.push(font);
  19244. }
  19245. }
  19246. }
  19247. var request = this.queueLoadingCallback(callback);
  19248. if (FontLoader.isFontLoadingAPISupported) {
  19249. Promise.all(fontLoadPromises).then(function() {
  19250. request.complete();
  19251. });
  19252. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  19253. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  19254. } else {
  19255. request.complete();
  19256. }
  19257. },
  19258. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  19259. function LoadLoader_completeRequest() {
  19260. assert(!request.end, 'completeRequest() cannot be called twice');
  19261. request.end = Date.now();
  19262. // sending all completed requests in order how they were queued
  19263. while (context.requests.length > 0 && context.requests[0].end) {
  19264. var otherRequest = context.requests.shift();
  19265. setTimeout(otherRequest.callback, 0);
  19266. }
  19267. }
  19268. var context = this.loadingContext;
  19269. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  19270. var request = {
  19271. id: requestId,
  19272. complete: LoadLoader_completeRequest,
  19273. callback: callback,
  19274. started: Date.now()
  19275. };
  19276. context.requests.push(request);
  19277. return request;
  19278. },
  19279. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  19280. fonts,
  19281. request) {
  19282. /** Hack begin */
  19283. // There's currently no event when a font has finished downloading so the
  19284. // following code is a dirty hack to 'guess' when a font is
  19285. // ready. It's assumed fonts are loaded in order, so add a known test
  19286. // font after the desired fonts and then test for the loading of that
  19287. // test font.
  19288. function int32(data, offset) {
  19289. return (data.charCodeAt(offset) << 24) |
  19290. (data.charCodeAt(offset + 1) << 16) |
  19291. (data.charCodeAt(offset + 2) << 8) |
  19292. (data.charCodeAt(offset + 3) & 0xff);
  19293. }
  19294. function spliceString(s, offset, remove, insert) {
  19295. var chunk1 = s.substr(0, offset);
  19296. var chunk2 = s.substr(offset + remove);
  19297. return chunk1 + insert + chunk2;
  19298. }
  19299. var i, ii;
  19300. var canvas = document.createElement('canvas');
  19301. canvas.width = 1;
  19302. canvas.height = 1;
  19303. var ctx = canvas.getContext('2d');
  19304. var called = 0;
  19305. function isFontReady(name, callback) {
  19306. called++;
  19307. // With setTimeout clamping this gives the font ~100ms to load.
  19308. if(called > 30) {
  19309. warn('Load test font never loaded.');
  19310. callback();
  19311. return;
  19312. }
  19313. ctx.font = '30px ' + name;
  19314. ctx.fillText('.', 0, 20);
  19315. var imageData = ctx.getImageData(0, 0, 1, 1);
  19316. if (imageData.data[3] > 0) {
  19317. callback();
  19318. return;
  19319. }
  19320. setTimeout(isFontReady.bind(null, name, callback));
  19321. }
  19322. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  19323. // Chromium seems to cache fonts based on a hash of the actual font data,
  19324. // so the font must be modified for each load test else it will appear to
  19325. // be loaded already.
  19326. // TODO: This could maybe be made faster by avoiding the btoa of the full
  19327. // font by splitting it in chunks before hand and padding the font id.
  19328. var data = this.loadTestFont;
  19329. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  19330. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  19331. loadTestFontId);
  19332. // CFF checksum is important for IE, adjusting it
  19333. var CFF_CHECKSUM_OFFSET = 16;
  19334. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  19335. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  19336. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  19337. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  19338. }
  19339. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  19340. checksum = (checksum - XXXX_VALUE +
  19341. int32(loadTestFontId + 'XXX', i)) | 0;
  19342. }
  19343. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  19344. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  19345. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  19346. url + '}';
  19347. this.insertRule(rule);
  19348. var names = [];
  19349. for (i = 0, ii = fonts.length; i < ii; i++) {
  19350. names.push(fonts[i].loadedName);
  19351. }
  19352. names.push(loadTestFontId);
  19353. var div = document.createElement('div');
  19354. div.setAttribute('style',
  19355. 'visibility: hidden;' +
  19356. 'width: 10px; height: 10px;' +
  19357. 'position: absolute; top: 0px; left: 0px;');
  19358. for (i = 0, ii = names.length; i < ii; ++i) {
  19359. var span = document.createElement('span');
  19360. span.textContent = 'Hi';
  19361. span.style.fontFamily = names[i];
  19362. div.appendChild(span);
  19363. }
  19364. document.body.appendChild(div);
  19365. isFontReady(loadTestFontId, function() {
  19366. document.body.removeChild(div);
  19367. request.complete();
  19368. });
  19369. /** Hack end */
  19370. }
  19371. };
  19372. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
  19373. !!document.fonts;
  19374. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  19375. get: function () {
  19376. if (typeof navigator === 'undefined') {
  19377. // node.js - we can pretend sync font loading is supported.
  19378. return shadow(FontLoader, 'isSyncFontLoadingSupported', true);
  19379. }
  19380. var supported = false;
  19381. // User agent string sniffing is bad, but there is no reliable way to tell
  19382. // if font is fully loaded and ready to be used with canvas.
  19383. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  19384. if (m && m[1] >= 14) {
  19385. supported = true;
  19386. }
  19387. // TODO other browsers
  19388. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  19389. },
  19390. enumerable: true,
  19391. configurable: true
  19392. });
  19393. var IsEvalSupportedCached = {
  19394. get value() {
  19395. return shadow(this, 'value', sharedUtil.isEvalSupported());
  19396. }
  19397. };
  19398. var FontFaceObject = (function FontFaceObjectClosure() {
  19399. function FontFaceObject(translatedData, options) {
  19400. this.compiledGlyphs = Object.create(null);
  19401. // importing translated data
  19402. for (var i in translatedData) {
  19403. this[i] = translatedData[i];
  19404. }
  19405. this.options = options;
  19406. }
  19407. FontFaceObject.prototype = {
  19408. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  19409. if (!this.data) {
  19410. return null;
  19411. }
  19412. if (this.options.disableFontFace) {
  19413. this.disableFontFace = true;
  19414. return null;
  19415. }
  19416. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  19417. if (this.options.fontRegistry) {
  19418. this.options.fontRegistry.registerFont(this);
  19419. }
  19420. return nativeFontFace;
  19421. },
  19422. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  19423. if (!this.data) {
  19424. return null;
  19425. }
  19426. if (this.options.disableFontFace) {
  19427. this.disableFontFace = true;
  19428. return null;
  19429. }
  19430. var data = bytesToString(new Uint8Array(this.data));
  19431. var fontName = this.loadedName;
  19432. // Add the font-face rule to the document
  19433. var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
  19434. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  19435. if (this.options.fontRegistry) {
  19436. this.options.fontRegistry.registerFont(this, url);
  19437. }
  19438. return rule;
  19439. },
  19440. getPathGenerator:
  19441. function FontFaceObject_getPathGenerator(objs, character) {
  19442. if (!(character in this.compiledGlyphs)) {
  19443. var cmds = objs.get(this.loadedName + '_path_' + character);
  19444. var current, i, len;
  19445. // If we can, compile cmds into JS for MAXIMUM SPEED
  19446. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  19447. var args, js = '';
  19448. for (i = 0, len = cmds.length; i < len; i++) {
  19449. current = cmds[i];
  19450. if (current.args !== undefined) {
  19451. args = current.args.join(',');
  19452. } else {
  19453. args = '';
  19454. }
  19455. js += 'c.' + current.cmd + '(' + args + ');\n';
  19456. }
  19457. /* jshint -W054 */
  19458. this.compiledGlyphs[character] = new Function('c', 'size', js);
  19459. } else {
  19460. // But fall back on using Function.prototype.apply() if we're
  19461. // blocked from using eval() for whatever reason (like CSP policies)
  19462. this.compiledGlyphs[character] = function(c, size) {
  19463. for (i = 0, len = cmds.length; i < len; i++) {
  19464. current = cmds[i];
  19465. if (current.cmd === 'scale') {
  19466. current.args = [size, -size];
  19467. }
  19468. c[current.cmd].apply(c, current.args);
  19469. }
  19470. };
  19471. }
  19472. }
  19473. return this.compiledGlyphs[character];
  19474. }
  19475. };
  19476. return FontFaceObject;
  19477. })();
  19478. exports.FontFaceObject = FontFaceObject;
  19479. exports.FontLoader = FontLoader;
  19480. }));
  19481. (function (root, factory) {
  19482. {
  19483. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  19484. }
  19485. }(this, function (exports, sharedUtil) {
  19486. var error = sharedUtil.error;
  19487. function fixMetadata(meta) {
  19488. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  19489. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  19490. function(code, d1, d2, d3) {
  19491. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  19492. });
  19493. var chars = '';
  19494. for (var i = 0; i < bytes.length; i += 2) {
  19495. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  19496. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  19497. code !== 38 && false ? String.fromCharCode(code) :
  19498. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  19499. }
  19500. return '>' + chars;
  19501. });
  19502. }
  19503. function Metadata(meta) {
  19504. if (typeof meta === 'string') {
  19505. // Ghostscript produces invalid metadata
  19506. meta = fixMetadata(meta);
  19507. var parser = new DOMParser();
  19508. meta = parser.parseFromString(meta, 'application/xml');
  19509. } else if (!(meta instanceof Document)) {
  19510. error('Metadata: Invalid metadata object');
  19511. }
  19512. this.metaDocument = meta;
  19513. this.metadata = Object.create(null);
  19514. this.parse();
  19515. }
  19516. Metadata.prototype = {
  19517. parse: function Metadata_parse() {
  19518. var doc = this.metaDocument;
  19519. var rdf = doc.documentElement;
  19520. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  19521. rdf = rdf.firstChild;
  19522. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  19523. rdf = rdf.nextSibling;
  19524. }
  19525. }
  19526. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  19527. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  19528. return;
  19529. }
  19530. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  19531. for (i = 0, length = children.length; i < length; i++) {
  19532. desc = children[i];
  19533. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  19534. continue;
  19535. }
  19536. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  19537. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  19538. entry = desc.childNodes[ii];
  19539. name = entry.nodeName.toLowerCase();
  19540. this.metadata[name] = entry.textContent.trim();
  19541. }
  19542. }
  19543. }
  19544. },
  19545. get: function Metadata_get(name) {
  19546. return this.metadata[name] || null;
  19547. },
  19548. has: function Metadata_has(name) {
  19549. return typeof this.metadata[name] !== 'undefined';
  19550. }
  19551. };
  19552. exports.Metadata = Metadata;
  19553. }));
  19554. (function (root, factory) {
  19555. {
  19556. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  19557. }
  19558. }(this, function (exports, sharedUtil) {
  19559. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  19560. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  19561. var ImageKind = sharedUtil.ImageKind;
  19562. var OPS = sharedUtil.OPS;
  19563. var Util = sharedUtil.Util;
  19564. var isNum = sharedUtil.isNum;
  19565. var isArray = sharedUtil.isArray;
  19566. var warn = sharedUtil.warn;
  19567. var createObjectURL = sharedUtil.createObjectURL;
  19568. var SVG_DEFAULTS = {
  19569. fontStyle: 'normal',
  19570. fontWeight: 'normal',
  19571. fillColor: '#000000'
  19572. };
  19573. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  19574. var PNG_HEADER =
  19575. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  19576. var CHUNK_WRAPPER_SIZE = 12;
  19577. var crcTable = new Int32Array(256);
  19578. for (var i = 0; i < 256; i++) {
  19579. var c = i;
  19580. for (var h = 0; h < 8; h++) {
  19581. if (c & 1) {
  19582. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  19583. } else {
  19584. c = (c >> 1) & 0x7fffffff;
  19585. }
  19586. }
  19587. crcTable[i] = c;
  19588. }
  19589. function crc32(data, start, end) {
  19590. var crc = -1;
  19591. for (var i = start; i < end; i++) {
  19592. var a = (crc ^ data[i]) & 0xff;
  19593. var b = crcTable[a];
  19594. crc = (crc >>> 8) ^ b;
  19595. }
  19596. return crc ^ -1;
  19597. }
  19598. function writePngChunk(type, body, data, offset) {
  19599. var p = offset;
  19600. var len = body.length;
  19601. data[p] = len >> 24 & 0xff;
  19602. data[p + 1] = len >> 16 & 0xff;
  19603. data[p + 2] = len >> 8 & 0xff;
  19604. data[p + 3] = len & 0xff;
  19605. p += 4;
  19606. data[p] = type.charCodeAt(0) & 0xff;
  19607. data[p + 1] = type.charCodeAt(1) & 0xff;
  19608. data[p + 2] = type.charCodeAt(2) & 0xff;
  19609. data[p + 3] = type.charCodeAt(3) & 0xff;
  19610. p += 4;
  19611. data.set(body, p);
  19612. p += body.length;
  19613. var crc = crc32(data, offset + 4, p);
  19614. data[p] = crc >> 24 & 0xff;
  19615. data[p + 1] = crc >> 16 & 0xff;
  19616. data[p + 2] = crc >> 8 & 0xff;
  19617. data[p + 3] = crc & 0xff;
  19618. }
  19619. function adler32(data, start, end) {
  19620. var a = 1;
  19621. var b = 0;
  19622. for (var i = start; i < end; ++i) {
  19623. a = (a + (data[i] & 0xff)) % 65521;
  19624. b = (b + a) % 65521;
  19625. }
  19626. return (b << 16) | a;
  19627. }
  19628. function encode(imgData, kind, forceDataSchema) {
  19629. var width = imgData.width;
  19630. var height = imgData.height;
  19631. var bitDepth, colorType, lineSize;
  19632. var bytes = imgData.data;
  19633. switch (kind) {
  19634. case ImageKind.GRAYSCALE_1BPP:
  19635. colorType = 0;
  19636. bitDepth = 1;
  19637. lineSize = (width + 7) >> 3;
  19638. break;
  19639. case ImageKind.RGB_24BPP:
  19640. colorType = 2;
  19641. bitDepth = 8;
  19642. lineSize = width * 3;
  19643. break;
  19644. case ImageKind.RGBA_32BPP:
  19645. colorType = 6;
  19646. bitDepth = 8;
  19647. lineSize = width * 4;
  19648. break;
  19649. default:
  19650. throw new Error('invalid format');
  19651. }
  19652. // prefix every row with predictor 0
  19653. var literals = new Uint8Array((1 + lineSize) * height);
  19654. var offsetLiterals = 0, offsetBytes = 0;
  19655. var y, i;
  19656. for (y = 0; y < height; ++y) {
  19657. literals[offsetLiterals++] = 0; // no prediction
  19658. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  19659. offsetLiterals);
  19660. offsetBytes += lineSize;
  19661. offsetLiterals += lineSize;
  19662. }
  19663. if (kind === ImageKind.GRAYSCALE_1BPP) {
  19664. // inverting for B/W
  19665. offsetLiterals = 0;
  19666. for (y = 0; y < height; y++) {
  19667. offsetLiterals++; // skipping predictor
  19668. for (i = 0; i < lineSize; i++) {
  19669. literals[offsetLiterals++] ^= 0xFF;
  19670. }
  19671. }
  19672. }
  19673. var ihdr = new Uint8Array([
  19674. width >> 24 & 0xff,
  19675. width >> 16 & 0xff,
  19676. width >> 8 & 0xff,
  19677. width & 0xff,
  19678. height >> 24 & 0xff,
  19679. height >> 16 & 0xff,
  19680. height >> 8 & 0xff,
  19681. height & 0xff,
  19682. bitDepth, // bit depth
  19683. colorType, // color type
  19684. 0x00, // compression method
  19685. 0x00, // filter method
  19686. 0x00 // interlace method
  19687. ]);
  19688. var len = literals.length;
  19689. var maxBlockLength = 0xFFFF;
  19690. var deflateBlocks = Math.ceil(len / maxBlockLength);
  19691. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  19692. var pi = 0;
  19693. idat[pi++] = 0x78; // compression method and flags
  19694. idat[pi++] = 0x9c; // flags
  19695. var pos = 0;
  19696. while (len > maxBlockLength) {
  19697. // writing non-final DEFLATE blocks type 0 and length of 65535
  19698. idat[pi++] = 0x00;
  19699. idat[pi++] = 0xff;
  19700. idat[pi++] = 0xff;
  19701. idat[pi++] = 0x00;
  19702. idat[pi++] = 0x00;
  19703. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  19704. pi += maxBlockLength;
  19705. pos += maxBlockLength;
  19706. len -= maxBlockLength;
  19707. }
  19708. // writing non-final DEFLATE blocks type 0
  19709. idat[pi++] = 0x01;
  19710. idat[pi++] = len & 0xff;
  19711. idat[pi++] = len >> 8 & 0xff;
  19712. idat[pi++] = (~len & 0xffff) & 0xff;
  19713. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  19714. idat.set(literals.subarray(pos), pi);
  19715. pi += literals.length - pos;
  19716. var adler = adler32(literals, 0, literals.length); // checksum
  19717. idat[pi++] = adler >> 24 & 0xff;
  19718. idat[pi++] = adler >> 16 & 0xff;
  19719. idat[pi++] = adler >> 8 & 0xff;
  19720. idat[pi++] = adler & 0xff;
  19721. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  19722. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  19723. ihdr.length + idat.length;
  19724. var data = new Uint8Array(pngLength);
  19725. var offset = 0;
  19726. data.set(PNG_HEADER, offset);
  19727. offset += PNG_HEADER.length;
  19728. writePngChunk('IHDR', ihdr, data, offset);
  19729. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  19730. writePngChunk('IDATA', idat, data, offset);
  19731. offset += CHUNK_WRAPPER_SIZE + idat.length;
  19732. writePngChunk('IEND', new Uint8Array(0), data, offset);
  19733. return createObjectURL(data, 'image/png', forceDataSchema);
  19734. }
  19735. return function convertImgDataToPng(imgData, forceDataSchema) {
  19736. var kind = (imgData.kind === undefined ?
  19737. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  19738. return encode(imgData, kind, forceDataSchema);
  19739. };
  19740. })();
  19741. var SVGExtraState = (function SVGExtraStateClosure() {
  19742. function SVGExtraState() {
  19743. this.fontSizeScale = 1;
  19744. this.fontWeight = SVG_DEFAULTS.fontWeight;
  19745. this.fontSize = 0;
  19746. this.textMatrix = IDENTITY_MATRIX;
  19747. this.fontMatrix = FONT_IDENTITY_MATRIX;
  19748. this.leading = 0;
  19749. // Current point (in user coordinates)
  19750. this.x = 0;
  19751. this.y = 0;
  19752. // Start of text line (in text coordinates)
  19753. this.lineX = 0;
  19754. this.lineY = 0;
  19755. // Character and word spacing
  19756. this.charSpacing = 0;
  19757. this.wordSpacing = 0;
  19758. this.textHScale = 1;
  19759. this.textRise = 0;
  19760. // Default foreground and background colors
  19761. this.fillColor = SVG_DEFAULTS.fillColor;
  19762. this.strokeColor = '#000000';
  19763. this.fillAlpha = 1;
  19764. this.strokeAlpha = 1;
  19765. this.lineWidth = 1;
  19766. this.lineJoin = '';
  19767. this.lineCap = '';
  19768. this.miterLimit = 0;
  19769. this.dashArray = [];
  19770. this.dashPhase = 0;
  19771. this.dependencies = [];
  19772. // Clipping
  19773. this.clipId = '';
  19774. this.pendingClip = false;
  19775. this.maskId = '';
  19776. }
  19777. SVGExtraState.prototype = {
  19778. clone: function SVGExtraState_clone() {
  19779. return Object.create(this);
  19780. },
  19781. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  19782. this.x = x;
  19783. this.y = y;
  19784. }
  19785. };
  19786. return SVGExtraState;
  19787. })();
  19788. var SVGGraphics = (function SVGGraphicsClosure() {
  19789. function createScratchSVG(width, height) {
  19790. var NS = 'http://www.w3.org/2000/svg';
  19791. var svg = document.createElementNS(NS, 'svg:svg');
  19792. svg.setAttributeNS(null, 'version', '1.1');
  19793. svg.setAttributeNS(null, 'width', width + 'px');
  19794. svg.setAttributeNS(null, 'height', height + 'px');
  19795. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  19796. return svg;
  19797. }
  19798. function opListToTree(opList) {
  19799. var opTree = [];
  19800. var tmp = [];
  19801. var opListLen = opList.length;
  19802. for (var x = 0; x < opListLen; x++) {
  19803. if (opList[x].fn === 'save') {
  19804. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  19805. tmp.push(opTree);
  19806. opTree = opTree[opTree.length - 1].items;
  19807. continue;
  19808. }
  19809. if(opList[x].fn === 'restore') {
  19810. opTree = tmp.pop();
  19811. } else {
  19812. opTree.push(opList[x]);
  19813. }
  19814. }
  19815. return opTree;
  19816. }
  19817. /**
  19818. * Formats float number.
  19819. * @param value {number} number to format.
  19820. * @returns {string}
  19821. */
  19822. function pf(value) {
  19823. if (value === (value | 0)) { // integer number
  19824. return value.toString();
  19825. }
  19826. var s = value.toFixed(10);
  19827. var i = s.length - 1;
  19828. if (s[i] !== '0') {
  19829. return s;
  19830. }
  19831. // removing trailing zeros
  19832. do {
  19833. i--;
  19834. } while (s[i] === '0');
  19835. return s.substr(0, s[i] === '.' ? i : i + 1);
  19836. }
  19837. /**
  19838. * Formats transform matrix. The standard rotation, scale and translate
  19839. * matrices are replaced by their shorter forms, and for identity matrix
  19840. * returns empty string to save the memory.
  19841. * @param m {Array} matrix to format.
  19842. * @returns {string}
  19843. */
  19844. function pm(m) {
  19845. if (m[4] === 0 && m[5] === 0) {
  19846. if (m[1] === 0 && m[2] === 0) {
  19847. if (m[0] === 1 && m[3] === 1) {
  19848. return '';
  19849. }
  19850. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  19851. }
  19852. if (m[0] === m[3] && m[1] === -m[2]) {
  19853. var a = Math.acos(m[0]) * 180 / Math.PI;
  19854. return 'rotate(' + pf(a) + ')';
  19855. }
  19856. } else {
  19857. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  19858. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19859. }
  19860. }
  19861. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  19862. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19863. }
  19864. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  19865. this.current = new SVGExtraState();
  19866. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  19867. this.transformStack = [];
  19868. this.extraStack = [];
  19869. this.commonObjs = commonObjs;
  19870. this.objs = objs;
  19871. this.pendingEOFill = false;
  19872. this.embedFonts = false;
  19873. this.embeddedFonts = Object.create(null);
  19874. this.cssStyle = null;
  19875. this.forceDataSchema = !!forceDataSchema;
  19876. }
  19877. var NS = 'http://www.w3.org/2000/svg';
  19878. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  19879. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  19880. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  19881. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  19882. var clipCount = 0;
  19883. var maskCount = 0;
  19884. SVGGraphics.prototype = {
  19885. save: function SVGGraphics_save() {
  19886. this.transformStack.push(this.transformMatrix);
  19887. var old = this.current;
  19888. this.extraStack.push(old);
  19889. this.current = old.clone();
  19890. },
  19891. restore: function SVGGraphics_restore() {
  19892. this.transformMatrix = this.transformStack.pop();
  19893. this.current = this.extraStack.pop();
  19894. this.tgrp = document.createElementNS(NS, 'svg:g');
  19895. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19896. this.pgrp.appendChild(this.tgrp);
  19897. },
  19898. group: function SVGGraphics_group(items) {
  19899. this.save();
  19900. this.executeOpTree(items);
  19901. this.restore();
  19902. },
  19903. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  19904. var fnArray = operatorList.fnArray;
  19905. var fnArrayLen = fnArray.length;
  19906. var argsArray = operatorList.argsArray;
  19907. var self = this;
  19908. for (var i = 0; i < fnArrayLen; i++) {
  19909. if (OPS.dependency === fnArray[i]) {
  19910. var deps = argsArray[i];
  19911. for (var n = 0, nn = deps.length; n < nn; n++) {
  19912. var obj = deps[n];
  19913. var common = obj.substring(0, 2) === 'g_';
  19914. var promise;
  19915. if (common) {
  19916. promise = new Promise(function(resolve) {
  19917. self.commonObjs.get(obj, resolve);
  19918. });
  19919. } else {
  19920. promise = new Promise(function(resolve) {
  19921. self.objs.get(obj, resolve);
  19922. });
  19923. }
  19924. this.current.dependencies.push(promise);
  19925. }
  19926. }
  19927. }
  19928. return Promise.all(this.current.dependencies);
  19929. },
  19930. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  19931. var transformMatrix = [a, b, c, d, e, f];
  19932. this.transformMatrix = Util.transform(this.transformMatrix,
  19933. transformMatrix);
  19934. this.tgrp = document.createElementNS(NS, 'svg:g');
  19935. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19936. },
  19937. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  19938. this.svg = createScratchSVG(viewport.width, viewport.height);
  19939. this.viewport = viewport;
  19940. return this.loadDependencies(operatorList).then(function () {
  19941. this.transformMatrix = IDENTITY_MATRIX;
  19942. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  19943. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  19944. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  19945. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19946. this.defs = document.createElementNS(NS, 'svg:defs');
  19947. this.pgrp.appendChild(this.defs);
  19948. this.pgrp.appendChild(this.tgrp);
  19949. this.svg.appendChild(this.pgrp);
  19950. var opTree = this.convertOpList(operatorList);
  19951. this.executeOpTree(opTree);
  19952. return this.svg;
  19953. }.bind(this));
  19954. },
  19955. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  19956. var argsArray = operatorList.argsArray;
  19957. var fnArray = operatorList.fnArray;
  19958. var fnArrayLen = fnArray.length;
  19959. var REVOPS = [];
  19960. var opList = [];
  19961. for (var op in OPS) {
  19962. REVOPS[OPS[op]] = op;
  19963. }
  19964. for (var x = 0; x < fnArrayLen; x++) {
  19965. var fnId = fnArray[x];
  19966. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  19967. }
  19968. return opListToTree(opList);
  19969. },
  19970. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  19971. var opTreeLen = opTree.length;
  19972. for(var x = 0; x < opTreeLen; x++) {
  19973. var fn = opTree[x].fn;
  19974. var fnId = opTree[x].fnId;
  19975. var args = opTree[x].args;
  19976. switch (fnId | 0) {
  19977. case OPS.beginText:
  19978. this.beginText();
  19979. break;
  19980. case OPS.setLeading:
  19981. this.setLeading(args);
  19982. break;
  19983. case OPS.setLeadingMoveText:
  19984. this.setLeadingMoveText(args[0], args[1]);
  19985. break;
  19986. case OPS.setFont:
  19987. this.setFont(args);
  19988. break;
  19989. case OPS.showText:
  19990. this.showText(args[0]);
  19991. break;
  19992. case OPS.showSpacedText:
  19993. this.showText(args[0]);
  19994. break;
  19995. case OPS.endText:
  19996. this.endText();
  19997. break;
  19998. case OPS.moveText:
  19999. this.moveText(args[0], args[1]);
  20000. break;
  20001. case OPS.setCharSpacing:
  20002. this.setCharSpacing(args[0]);
  20003. break;
  20004. case OPS.setWordSpacing:
  20005. this.setWordSpacing(args[0]);
  20006. break;
  20007. case OPS.setHScale:
  20008. this.setHScale(args[0]);
  20009. break;
  20010. case OPS.setTextMatrix:
  20011. this.setTextMatrix(args[0], args[1], args[2],
  20012. args[3], args[4], args[5]);
  20013. break;
  20014. case OPS.setLineWidth:
  20015. this.setLineWidth(args[0]);
  20016. break;
  20017. case OPS.setLineJoin:
  20018. this.setLineJoin(args[0]);
  20019. break;
  20020. case OPS.setLineCap:
  20021. this.setLineCap(args[0]);
  20022. break;
  20023. case OPS.setMiterLimit:
  20024. this.setMiterLimit(args[0]);
  20025. break;
  20026. case OPS.setFillRGBColor:
  20027. this.setFillRGBColor(args[0], args[1], args[2]);
  20028. break;
  20029. case OPS.setStrokeRGBColor:
  20030. this.setStrokeRGBColor(args[0], args[1], args[2]);
  20031. break;
  20032. case OPS.setDash:
  20033. this.setDash(args[0], args[1]);
  20034. break;
  20035. case OPS.setGState:
  20036. this.setGState(args[0]);
  20037. break;
  20038. case OPS.fill:
  20039. this.fill();
  20040. break;
  20041. case OPS.eoFill:
  20042. this.eoFill();
  20043. break;
  20044. case OPS.stroke:
  20045. this.stroke();
  20046. break;
  20047. case OPS.fillStroke:
  20048. this.fillStroke();
  20049. break;
  20050. case OPS.eoFillStroke:
  20051. this.eoFillStroke();
  20052. break;
  20053. case OPS.clip:
  20054. this.clip('nonzero');
  20055. break;
  20056. case OPS.eoClip:
  20057. this.clip('evenodd');
  20058. break;
  20059. case OPS.paintSolidColorImageMask:
  20060. this.paintSolidColorImageMask();
  20061. break;
  20062. case OPS.paintJpegXObject:
  20063. this.paintJpegXObject(args[0], args[1], args[2]);
  20064. break;
  20065. case OPS.paintImageXObject:
  20066. this.paintImageXObject(args[0]);
  20067. break;
  20068. case OPS.paintInlineImageXObject:
  20069. this.paintInlineImageXObject(args[0]);
  20070. break;
  20071. case OPS.paintImageMaskXObject:
  20072. this.paintImageMaskXObject(args[0]);
  20073. break;
  20074. case OPS.paintFormXObjectBegin:
  20075. this.paintFormXObjectBegin(args[0], args[1]);
  20076. break;
  20077. case OPS.paintFormXObjectEnd:
  20078. this.paintFormXObjectEnd();
  20079. break;
  20080. case OPS.closePath:
  20081. this.closePath();
  20082. break;
  20083. case OPS.closeStroke:
  20084. this.closeStroke();
  20085. break;
  20086. case OPS.closeFillStroke:
  20087. this.closeFillStroke();
  20088. break;
  20089. case OPS.nextLine:
  20090. this.nextLine();
  20091. break;
  20092. case OPS.transform:
  20093. this.transform(args[0], args[1], args[2], args[3],
  20094. args[4], args[5]);
  20095. break;
  20096. case OPS.constructPath:
  20097. this.constructPath(args[0], args[1]);
  20098. break;
  20099. case OPS.endPath:
  20100. this.endPath();
  20101. break;
  20102. case 92:
  20103. this.group(opTree[x].items);
  20104. break;
  20105. default:
  20106. warn('Unimplemented method '+ fn);
  20107. break;
  20108. }
  20109. }
  20110. },
  20111. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  20112. this.current.wordSpacing = wordSpacing;
  20113. },
  20114. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  20115. this.current.charSpacing = charSpacing;
  20116. },
  20117. nextLine: function SVGGraphics_nextLine() {
  20118. this.moveText(0, this.current.leading);
  20119. },
  20120. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  20121. var current = this.current;
  20122. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  20123. this.current.x = this.current.lineX = 0;
  20124. this.current.y = this.current.lineY = 0;
  20125. current.xcoords = [];
  20126. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20127. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20128. current.tspan.setAttributeNS(null, 'font-size',
  20129. pf(current.fontSize) + 'px');
  20130. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20131. current.txtElement = document.createElementNS(NS, 'svg:text');
  20132. current.txtElement.appendChild(current.tspan);
  20133. },
  20134. beginText: function SVGGraphics_beginText() {
  20135. this.current.x = this.current.lineX = 0;
  20136. this.current.y = this.current.lineY = 0;
  20137. this.current.textMatrix = IDENTITY_MATRIX;
  20138. this.current.lineMatrix = IDENTITY_MATRIX;
  20139. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  20140. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  20141. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  20142. this.current.xcoords = [];
  20143. },
  20144. moveText: function SVGGraphics_moveText(x, y) {
  20145. var current = this.current;
  20146. this.current.x = this.current.lineX += x;
  20147. this.current.y = this.current.lineY += y;
  20148. current.xcoords = [];
  20149. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20150. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20151. current.tspan.setAttributeNS(null, 'font-size',
  20152. pf(current.fontSize) + 'px');
  20153. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20154. },
  20155. showText: function SVGGraphics_showText(glyphs) {
  20156. var current = this.current;
  20157. var font = current.font;
  20158. var fontSize = current.fontSize;
  20159. if (fontSize === 0) {
  20160. return;
  20161. }
  20162. var charSpacing = current.charSpacing;
  20163. var wordSpacing = current.wordSpacing;
  20164. var fontDirection = current.fontDirection;
  20165. var textHScale = current.textHScale * fontDirection;
  20166. var glyphsLength = glyphs.length;
  20167. var vertical = font.vertical;
  20168. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  20169. var x = 0, i;
  20170. for (i = 0; i < glyphsLength; ++i) {
  20171. var glyph = glyphs[i];
  20172. if (glyph === null) {
  20173. // word break
  20174. x += fontDirection * wordSpacing;
  20175. continue;
  20176. } else if (isNum(glyph)) {
  20177. x += -glyph * fontSize * 0.001;
  20178. continue;
  20179. }
  20180. current.xcoords.push(current.x + x * textHScale);
  20181. var width = glyph.width;
  20182. var character = glyph.fontChar;
  20183. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  20184. x += charWidth;
  20185. current.tspan.textContent += character;
  20186. }
  20187. if (vertical) {
  20188. current.y -= x * textHScale;
  20189. } else {
  20190. current.x += x * textHScale;
  20191. }
  20192. current.tspan.setAttributeNS(null, 'x',
  20193. current.xcoords.map(pf).join(' '));
  20194. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20195. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20196. current.tspan.setAttributeNS(null, 'font-size',
  20197. pf(current.fontSize) + 'px');
  20198. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  20199. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  20200. }
  20201. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  20202. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  20203. }
  20204. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  20205. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  20206. }
  20207. current.txtElement.setAttributeNS(null, 'transform',
  20208. pm(current.textMatrix) +
  20209. ' scale(1, -1)' );
  20210. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  20211. current.txtElement.appendChild(current.tspan);
  20212. current.txtgrp.appendChild(current.txtElement);
  20213. this.tgrp.appendChild(current.txtElement);
  20214. },
  20215. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  20216. this.setLeading(-y);
  20217. this.moveText(x, y);
  20218. },
  20219. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  20220. if (!this.cssStyle) {
  20221. this.cssStyle = document.createElementNS(NS, 'svg:style');
  20222. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  20223. this.defs.appendChild(this.cssStyle);
  20224. }
  20225. var url = createObjectURL(fontObj.data, fontObj.mimetype,
  20226. this.forceDataSchema);
  20227. this.cssStyle.textContent +=
  20228. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  20229. ' src: url(' + url + '); }\n';
  20230. },
  20231. setFont: function SVGGraphics_setFont(details) {
  20232. var current = this.current;
  20233. var fontObj = this.commonObjs.get(details[0]);
  20234. var size = details[1];
  20235. this.current.font = fontObj;
  20236. if (this.embedFonts && fontObj.data &&
  20237. !this.embeddedFonts[fontObj.loadedName]) {
  20238. this.addFontStyle(fontObj);
  20239. this.embeddedFonts[fontObj.loadedName] = fontObj;
  20240. }
  20241. current.fontMatrix = (fontObj.fontMatrix ?
  20242. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  20243. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  20244. (fontObj.bold ? 'bold' : 'normal');
  20245. var italic = fontObj.italic ? 'italic' : 'normal';
  20246. if (size < 0) {
  20247. size = -size;
  20248. current.fontDirection = -1;
  20249. } else {
  20250. current.fontDirection = 1;
  20251. }
  20252. current.fontSize = size;
  20253. current.fontFamily = fontObj.loadedName;
  20254. current.fontWeight = bold;
  20255. current.fontStyle = italic;
  20256. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20257. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20258. current.xcoords = [];
  20259. },
  20260. endText: function SVGGraphics_endText() {
  20261. if (this.current.pendingClip) {
  20262. this.cgrp.appendChild(this.tgrp);
  20263. this.pgrp.appendChild(this.cgrp);
  20264. } else {
  20265. this.pgrp.appendChild(this.tgrp);
  20266. }
  20267. this.tgrp = document.createElementNS(NS, 'svg:g');
  20268. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20269. },
  20270. // Path properties
  20271. setLineWidth: function SVGGraphics_setLineWidth(width) {
  20272. this.current.lineWidth = width;
  20273. },
  20274. setLineCap: function SVGGraphics_setLineCap(style) {
  20275. this.current.lineCap = LINE_CAP_STYLES[style];
  20276. },
  20277. setLineJoin: function SVGGraphics_setLineJoin(style) {
  20278. this.current.lineJoin = LINE_JOIN_STYLES[style];
  20279. },
  20280. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  20281. this.current.miterLimit = limit;
  20282. },
  20283. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  20284. var color = Util.makeCssRgb(r, g, b);
  20285. this.current.strokeColor = color;
  20286. },
  20287. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  20288. var color = Util.makeCssRgb(r, g, b);
  20289. this.current.fillColor = color;
  20290. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  20291. this.current.xcoords = [];
  20292. },
  20293. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  20294. this.current.dashArray = dashArray;
  20295. this.current.dashPhase = dashPhase;
  20296. },
  20297. constructPath: function SVGGraphics_constructPath(ops, args) {
  20298. var current = this.current;
  20299. var x = current.x, y = current.y;
  20300. current.path = document.createElementNS(NS, 'svg:path');
  20301. var d = [];
  20302. var opLength = ops.length;
  20303. for (var i = 0, j = 0; i < opLength; i++) {
  20304. switch (ops[i] | 0) {
  20305. case OPS.rectangle:
  20306. x = args[j++];
  20307. y = args[j++];
  20308. var width = args[j++];
  20309. var height = args[j++];
  20310. var xw = x + width;
  20311. var yh = y + height;
  20312. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  20313. 'L', pf(x), pf(yh), 'Z');
  20314. break;
  20315. case OPS.moveTo:
  20316. x = args[j++];
  20317. y = args[j++];
  20318. d.push('M', pf(x), pf(y));
  20319. break;
  20320. case OPS.lineTo:
  20321. x = args[j++];
  20322. y = args[j++];
  20323. d.push('L', pf(x) , pf(y));
  20324. break;
  20325. case OPS.curveTo:
  20326. x = args[j + 4];
  20327. y = args[j + 5];
  20328. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  20329. pf(args[j + 3]), pf(x), pf(y));
  20330. j += 6;
  20331. break;
  20332. case OPS.curveTo2:
  20333. x = args[j + 2];
  20334. y = args[j + 3];
  20335. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  20336. pf(args[j + 2]), pf(args[j + 3]));
  20337. j += 4;
  20338. break;
  20339. case OPS.curveTo3:
  20340. x = args[j + 2];
  20341. y = args[j + 3];
  20342. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  20343. pf(x), pf(y));
  20344. j += 4;
  20345. break;
  20346. case OPS.closePath:
  20347. d.push('Z');
  20348. break;
  20349. }
  20350. }
  20351. current.path.setAttributeNS(null, 'd', d.join(' '));
  20352. current.path.setAttributeNS(null, 'stroke-miterlimit',
  20353. pf(current.miterLimit));
  20354. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  20355. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  20356. current.path.setAttributeNS(null, 'stroke-width',
  20357. pf(current.lineWidth) + 'px');
  20358. current.path.setAttributeNS(null, 'stroke-dasharray',
  20359. current.dashArray.map(pf).join(' '));
  20360. current.path.setAttributeNS(null, 'stroke-dashoffset',
  20361. pf(current.dashPhase) + 'px');
  20362. current.path.setAttributeNS(null, 'fill', 'none');
  20363. this.tgrp.appendChild(current.path);
  20364. if (current.pendingClip) {
  20365. this.cgrp.appendChild(this.tgrp);
  20366. this.pgrp.appendChild(this.cgrp);
  20367. } else {
  20368. this.pgrp.appendChild(this.tgrp);
  20369. }
  20370. // Saving a reference in current.element so that it can be addressed
  20371. // in 'fill' and 'stroke'
  20372. current.element = current.path;
  20373. current.setCurrentPoint(x, y);
  20374. },
  20375. endPath: function SVGGraphics_endPath() {
  20376. var current = this.current;
  20377. if (current.pendingClip) {
  20378. this.cgrp.appendChild(this.tgrp);
  20379. this.pgrp.appendChild(this.cgrp);
  20380. } else {
  20381. this.pgrp.appendChild(this.tgrp);
  20382. }
  20383. this.tgrp = document.createElementNS(NS, 'svg:g');
  20384. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20385. },
  20386. clip: function SVGGraphics_clip(type) {
  20387. var current = this.current;
  20388. // Add current path to clipping path
  20389. current.clipId = 'clippath' + clipCount;
  20390. clipCount++;
  20391. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  20392. this.clippath.setAttributeNS(null, 'id', current.clipId);
  20393. var clipElement = current.element.cloneNode();
  20394. if (type === 'evenodd') {
  20395. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  20396. } else {
  20397. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  20398. }
  20399. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20400. this.clippath.appendChild(clipElement);
  20401. this.defs.appendChild(this.clippath);
  20402. // Create a new group with that attribute
  20403. current.pendingClip = true;
  20404. this.cgrp = document.createElementNS(NS, 'svg:g');
  20405. this.cgrp.setAttributeNS(null, 'clip-path',
  20406. 'url(#' + current.clipId + ')');
  20407. this.pgrp.appendChild(this.cgrp);
  20408. },
  20409. closePath: function SVGGraphics_closePath() {
  20410. var current = this.current;
  20411. var d = current.path.getAttributeNS(null, 'd');
  20412. d += 'Z';
  20413. current.path.setAttributeNS(null, 'd', d);
  20414. },
  20415. setLeading: function SVGGraphics_setLeading(leading) {
  20416. this.current.leading = -leading;
  20417. },
  20418. setTextRise: function SVGGraphics_setTextRise(textRise) {
  20419. this.current.textRise = textRise;
  20420. },
  20421. setHScale: function SVGGraphics_setHScale(scale) {
  20422. this.current.textHScale = scale / 100;
  20423. },
  20424. setGState: function SVGGraphics_setGState(states) {
  20425. for (var i = 0, ii = states.length; i < ii; i++) {
  20426. var state = states[i];
  20427. var key = state[0];
  20428. var value = state[1];
  20429. switch (key) {
  20430. case 'LW':
  20431. this.setLineWidth(value);
  20432. break;
  20433. case 'LC':
  20434. this.setLineCap(value);
  20435. break;
  20436. case 'LJ':
  20437. this.setLineJoin(value);
  20438. break;
  20439. case 'ML':
  20440. this.setMiterLimit(value);
  20441. break;
  20442. case 'D':
  20443. this.setDash(value[0], value[1]);
  20444. break;
  20445. case 'RI':
  20446. break;
  20447. case 'FL':
  20448. break;
  20449. case 'Font':
  20450. this.setFont(value);
  20451. break;
  20452. case 'CA':
  20453. break;
  20454. case 'ca':
  20455. break;
  20456. case 'BM':
  20457. break;
  20458. case 'SMask':
  20459. break;
  20460. }
  20461. }
  20462. },
  20463. fill: function SVGGraphics_fill() {
  20464. var current = this.current;
  20465. current.element.setAttributeNS(null, 'fill', current.fillColor);
  20466. },
  20467. stroke: function SVGGraphics_stroke() {
  20468. var current = this.current;
  20469. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  20470. current.element.setAttributeNS(null, 'fill', 'none');
  20471. },
  20472. eoFill: function SVGGraphics_eoFill() {
  20473. var current = this.current;
  20474. current.element.setAttributeNS(null, 'fill', current.fillColor);
  20475. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  20476. },
  20477. fillStroke: function SVGGraphics_fillStroke() {
  20478. // Order is important since stroke wants fill to be none.
  20479. // First stroke, then if fill needed, it will be overwritten.
  20480. this.stroke();
  20481. this.fill();
  20482. },
  20483. eoFillStroke: function SVGGraphics_eoFillStroke() {
  20484. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  20485. this.fillStroke();
  20486. },
  20487. closeStroke: function SVGGraphics_closeStroke() {
  20488. this.closePath();
  20489. this.stroke();
  20490. },
  20491. closeFillStroke: function SVGGraphics_closeFillStroke() {
  20492. this.closePath();
  20493. this.fillStroke();
  20494. },
  20495. paintSolidColorImageMask:
  20496. function SVGGraphics_paintSolidColorImageMask() {
  20497. var current = this.current;
  20498. var rect = document.createElementNS(NS, 'svg:rect');
  20499. rect.setAttributeNS(null, 'x', '0');
  20500. rect.setAttributeNS(null, 'y', '0');
  20501. rect.setAttributeNS(null, 'width', '1px');
  20502. rect.setAttributeNS(null, 'height', '1px');
  20503. rect.setAttributeNS(null, 'fill', current.fillColor);
  20504. this.tgrp.appendChild(rect);
  20505. },
  20506. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  20507. var current = this.current;
  20508. var imgObj = this.objs.get(objId);
  20509. var imgEl = document.createElementNS(NS, 'svg:image');
  20510. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  20511. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  20512. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  20513. imgEl.setAttributeNS(null, 'x', '0');
  20514. imgEl.setAttributeNS(null, 'y', pf(-h));
  20515. imgEl.setAttributeNS(null, 'transform',
  20516. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  20517. this.tgrp.appendChild(imgEl);
  20518. if (current.pendingClip) {
  20519. this.cgrp.appendChild(this.tgrp);
  20520. this.pgrp.appendChild(this.cgrp);
  20521. } else {
  20522. this.pgrp.appendChild(this.tgrp);
  20523. }
  20524. },
  20525. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  20526. var imgData = this.objs.get(objId);
  20527. if (!imgData) {
  20528. warn('Dependent image isn\'t ready yet');
  20529. return;
  20530. }
  20531. this.paintInlineImageXObject(imgData);
  20532. },
  20533. paintInlineImageXObject:
  20534. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  20535. var current = this.current;
  20536. var width = imgData.width;
  20537. var height = imgData.height;
  20538. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  20539. var cliprect = document.createElementNS(NS, 'svg:rect');
  20540. cliprect.setAttributeNS(null, 'x', '0');
  20541. cliprect.setAttributeNS(null, 'y', '0');
  20542. cliprect.setAttributeNS(null, 'width', pf(width));
  20543. cliprect.setAttributeNS(null, 'height', pf(height));
  20544. current.element = cliprect;
  20545. this.clip('nonzero');
  20546. var imgEl = document.createElementNS(NS, 'svg:image');
  20547. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  20548. imgEl.setAttributeNS(null, 'x', '0');
  20549. imgEl.setAttributeNS(null, 'y', pf(-height));
  20550. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  20551. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  20552. imgEl.setAttributeNS(null, 'transform',
  20553. 'scale(' + pf(1 / width) + ' ' +
  20554. pf(-1 / height) + ')');
  20555. if (mask) {
  20556. mask.appendChild(imgEl);
  20557. } else {
  20558. this.tgrp.appendChild(imgEl);
  20559. }
  20560. if (current.pendingClip) {
  20561. this.cgrp.appendChild(this.tgrp);
  20562. this.pgrp.appendChild(this.cgrp);
  20563. } else {
  20564. this.pgrp.appendChild(this.tgrp);
  20565. }
  20566. },
  20567. paintImageMaskXObject:
  20568. function SVGGraphics_paintImageMaskXObject(imgData) {
  20569. var current = this.current;
  20570. var width = imgData.width;
  20571. var height = imgData.height;
  20572. var fillColor = current.fillColor;
  20573. current.maskId = 'mask' + maskCount++;
  20574. var mask = document.createElementNS(NS, 'svg:mask');
  20575. mask.setAttributeNS(null, 'id', current.maskId);
  20576. var rect = document.createElementNS(NS, 'svg:rect');
  20577. rect.setAttributeNS(null, 'x', '0');
  20578. rect.setAttributeNS(null, 'y', '0');
  20579. rect.setAttributeNS(null, 'width', pf(width));
  20580. rect.setAttributeNS(null, 'height', pf(height));
  20581. rect.setAttributeNS(null, 'fill', fillColor);
  20582. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  20583. this.defs.appendChild(mask);
  20584. this.tgrp.appendChild(rect);
  20585. this.paintInlineImageXObject(imgData, mask);
  20586. },
  20587. paintFormXObjectBegin:
  20588. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  20589. this.save();
  20590. if (isArray(matrix) && matrix.length === 6) {
  20591. this.transform(matrix[0], matrix[1], matrix[2],
  20592. matrix[3], matrix[4], matrix[5]);
  20593. }
  20594. if (isArray(bbox) && bbox.length === 4) {
  20595. var width = bbox[2] - bbox[0];
  20596. var height = bbox[3] - bbox[1];
  20597. var cliprect = document.createElementNS(NS, 'svg:rect');
  20598. cliprect.setAttributeNS(null, 'x', bbox[0]);
  20599. cliprect.setAttributeNS(null, 'y', bbox[1]);
  20600. cliprect.setAttributeNS(null, 'width', pf(width));
  20601. cliprect.setAttributeNS(null, 'height', pf(height));
  20602. this.current.element = cliprect;
  20603. this.clip('nonzero');
  20604. this.endPath();
  20605. }
  20606. },
  20607. paintFormXObjectEnd:
  20608. function SVGGraphics_paintFormXObjectEnd() {
  20609. this.restore();
  20610. }
  20611. };
  20612. return SVGGraphics;
  20613. })();
  20614. exports.SVGGraphics = SVGGraphics;
  20615. }));
  20616. (function (root, factory) {
  20617. {
  20618. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  20619. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  20620. root.pdfjsCoreJpx);
  20621. }
  20622. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  20623. coreJpx) {
  20624. var Util = sharedUtil.Util;
  20625. var error = sharedUtil.error;
  20626. var info = sharedUtil.info;
  20627. var isArray = sharedUtil.isArray;
  20628. var createObjectURL = sharedUtil.createObjectURL;
  20629. var shadow = sharedUtil.shadow;
  20630. var warn = sharedUtil.warn;
  20631. var isSpace = sharedUtil.isSpace;
  20632. var Dict = corePrimitives.Dict;
  20633. var isDict = corePrimitives.isDict;
  20634. var Jbig2Image = coreJbig2.Jbig2Image;
  20635. var JpegImage = coreJpg.JpegImage;
  20636. var JpxImage = coreJpx.JpxImage;
  20637. var Stream = (function StreamClosure() {
  20638. function Stream(arrayBuffer, start, length, dict) {
  20639. this.bytes = (arrayBuffer instanceof Uint8Array ?
  20640. arrayBuffer : new Uint8Array(arrayBuffer));
  20641. this.start = start || 0;
  20642. this.pos = this.start;
  20643. this.end = (start + length) || this.bytes.length;
  20644. this.dict = dict;
  20645. }
  20646. // required methods for a stream. if a particular stream does not
  20647. // implement these, an error should be thrown
  20648. Stream.prototype = {
  20649. get length() {
  20650. return this.end - this.start;
  20651. },
  20652. get isEmpty() {
  20653. return this.length === 0;
  20654. },
  20655. getByte: function Stream_getByte() {
  20656. if (this.pos >= this.end) {
  20657. return -1;
  20658. }
  20659. return this.bytes[this.pos++];
  20660. },
  20661. getUint16: function Stream_getUint16() {
  20662. var b0 = this.getByte();
  20663. var b1 = this.getByte();
  20664. if (b0 === -1 || b1 === -1) {
  20665. return -1;
  20666. }
  20667. return (b0 << 8) + b1;
  20668. },
  20669. getInt32: function Stream_getInt32() {
  20670. var b0 = this.getByte();
  20671. var b1 = this.getByte();
  20672. var b2 = this.getByte();
  20673. var b3 = this.getByte();
  20674. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20675. },
  20676. // returns subarray of original buffer
  20677. // should only be read
  20678. getBytes: function Stream_getBytes(length) {
  20679. var bytes = this.bytes;
  20680. var pos = this.pos;
  20681. var strEnd = this.end;
  20682. if (!length) {
  20683. return bytes.subarray(pos, strEnd);
  20684. }
  20685. var end = pos + length;
  20686. if (end > strEnd) {
  20687. end = strEnd;
  20688. }
  20689. this.pos = end;
  20690. return bytes.subarray(pos, end);
  20691. },
  20692. peekByte: function Stream_peekByte() {
  20693. var peekedByte = this.getByte();
  20694. this.pos--;
  20695. return peekedByte;
  20696. },
  20697. peekBytes: function Stream_peekBytes(length) {
  20698. var bytes = this.getBytes(length);
  20699. this.pos -= bytes.length;
  20700. return bytes;
  20701. },
  20702. skip: function Stream_skip(n) {
  20703. if (!n) {
  20704. n = 1;
  20705. }
  20706. this.pos += n;
  20707. },
  20708. reset: function Stream_reset() {
  20709. this.pos = this.start;
  20710. },
  20711. moveStart: function Stream_moveStart() {
  20712. this.start = this.pos;
  20713. },
  20714. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  20715. return new Stream(this.bytes.buffer, start, length, dict);
  20716. },
  20717. isStream: true
  20718. };
  20719. return Stream;
  20720. })();
  20721. var StringStream = (function StringStreamClosure() {
  20722. function StringStream(str) {
  20723. var length = str.length;
  20724. var bytes = new Uint8Array(length);
  20725. for (var n = 0; n < length; ++n) {
  20726. bytes[n] = str.charCodeAt(n);
  20727. }
  20728. Stream.call(this, bytes);
  20729. }
  20730. StringStream.prototype = Stream.prototype;
  20731. return StringStream;
  20732. })();
  20733. // super class for the decoding streams
  20734. var DecodeStream = (function DecodeStreamClosure() {
  20735. // Lots of DecodeStreams are created whose buffers are never used. For these
  20736. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  20737. // having special cases that would be required if we used |null| for an empty
  20738. // buffer.
  20739. var emptyBuffer = new Uint8Array(0);
  20740. function DecodeStream(maybeMinBufferLength) {
  20741. this.pos = 0;
  20742. this.bufferLength = 0;
  20743. this.eof = false;
  20744. this.buffer = emptyBuffer;
  20745. this.minBufferLength = 512;
  20746. if (maybeMinBufferLength) {
  20747. // Compute the first power of two that is as big as maybeMinBufferLength.
  20748. while (this.minBufferLength < maybeMinBufferLength) {
  20749. this.minBufferLength *= 2;
  20750. }
  20751. }
  20752. }
  20753. DecodeStream.prototype = {
  20754. get isEmpty() {
  20755. while (!this.eof && this.bufferLength === 0) {
  20756. this.readBlock();
  20757. }
  20758. return this.bufferLength === 0;
  20759. },
  20760. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  20761. var buffer = this.buffer;
  20762. if (requested <= buffer.byteLength) {
  20763. return buffer;
  20764. }
  20765. var size = this.minBufferLength;
  20766. while (size < requested) {
  20767. size *= 2;
  20768. }
  20769. var buffer2 = new Uint8Array(size);
  20770. buffer2.set(buffer);
  20771. return (this.buffer = buffer2);
  20772. },
  20773. getByte: function DecodeStream_getByte() {
  20774. var pos = this.pos;
  20775. while (this.bufferLength <= pos) {
  20776. if (this.eof) {
  20777. return -1;
  20778. }
  20779. this.readBlock();
  20780. }
  20781. return this.buffer[this.pos++];
  20782. },
  20783. getUint16: function DecodeStream_getUint16() {
  20784. var b0 = this.getByte();
  20785. var b1 = this.getByte();
  20786. if (b0 === -1 || b1 === -1) {
  20787. return -1;
  20788. }
  20789. return (b0 << 8) + b1;
  20790. },
  20791. getInt32: function DecodeStream_getInt32() {
  20792. var b0 = this.getByte();
  20793. var b1 = this.getByte();
  20794. var b2 = this.getByte();
  20795. var b3 = this.getByte();
  20796. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20797. },
  20798. getBytes: function DecodeStream_getBytes(length) {
  20799. var end, pos = this.pos;
  20800. if (length) {
  20801. this.ensureBuffer(pos + length);
  20802. end = pos + length;
  20803. while (!this.eof && this.bufferLength < end) {
  20804. this.readBlock();
  20805. }
  20806. var bufEnd = this.bufferLength;
  20807. if (end > bufEnd) {
  20808. end = bufEnd;
  20809. }
  20810. } else {
  20811. while (!this.eof) {
  20812. this.readBlock();
  20813. }
  20814. end = this.bufferLength;
  20815. }
  20816. this.pos = end;
  20817. return this.buffer.subarray(pos, end);
  20818. },
  20819. peekByte: function DecodeStream_peekByte() {
  20820. var peekedByte = this.getByte();
  20821. this.pos--;
  20822. return peekedByte;
  20823. },
  20824. peekBytes: function DecodeStream_peekBytes(length) {
  20825. var bytes = this.getBytes(length);
  20826. this.pos -= bytes.length;
  20827. return bytes;
  20828. },
  20829. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  20830. var end = start + length;
  20831. while (this.bufferLength <= end && !this.eof) {
  20832. this.readBlock();
  20833. }
  20834. return new Stream(this.buffer, start, length, dict);
  20835. },
  20836. skip: function DecodeStream_skip(n) {
  20837. if (!n) {
  20838. n = 1;
  20839. }
  20840. this.pos += n;
  20841. },
  20842. reset: function DecodeStream_reset() {
  20843. this.pos = 0;
  20844. },
  20845. getBaseStreams: function DecodeStream_getBaseStreams() {
  20846. if (this.str && this.str.getBaseStreams) {
  20847. return this.str.getBaseStreams();
  20848. }
  20849. return [];
  20850. }
  20851. };
  20852. return DecodeStream;
  20853. })();
  20854. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  20855. function StreamsSequenceStream(streams) {
  20856. this.streams = streams;
  20857. DecodeStream.call(this, /* maybeLength = */ null);
  20858. }
  20859. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  20860. StreamsSequenceStream.prototype.readBlock =
  20861. function streamSequenceStreamReadBlock() {
  20862. var streams = this.streams;
  20863. if (streams.length === 0) {
  20864. this.eof = true;
  20865. return;
  20866. }
  20867. var stream = streams.shift();
  20868. var chunk = stream.getBytes();
  20869. var bufferLength = this.bufferLength;
  20870. var newLength = bufferLength + chunk.length;
  20871. var buffer = this.ensureBuffer(newLength);
  20872. buffer.set(chunk, bufferLength);
  20873. this.bufferLength = newLength;
  20874. };
  20875. StreamsSequenceStream.prototype.getBaseStreams =
  20876. function StreamsSequenceStream_getBaseStreams() {
  20877. var baseStreams = [];
  20878. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  20879. var stream = this.streams[i];
  20880. if (stream.getBaseStreams) {
  20881. Util.appendToArray(baseStreams, stream.getBaseStreams());
  20882. }
  20883. }
  20884. return baseStreams;
  20885. };
  20886. return StreamsSequenceStream;
  20887. })();
  20888. var FlateStream = (function FlateStreamClosure() {
  20889. var codeLenCodeMap = new Int32Array([
  20890. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  20891. ]);
  20892. var lengthDecode = new Int32Array([
  20893. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  20894. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  20895. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  20896. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  20897. ]);
  20898. var distDecode = new Int32Array([
  20899. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  20900. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  20901. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  20902. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  20903. ]);
  20904. var fixedLitCodeTab = [new Int32Array([
  20905. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  20906. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  20907. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  20908. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  20909. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  20910. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  20911. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  20912. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  20913. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  20914. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  20915. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  20916. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  20917. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  20918. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  20919. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  20920. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  20921. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  20922. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  20923. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  20924. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  20925. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  20926. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  20927. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  20928. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  20929. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  20930. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  20931. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  20932. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  20933. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  20934. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  20935. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  20936. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  20937. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  20938. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  20939. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  20940. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  20941. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  20942. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  20943. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  20944. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  20945. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  20946. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  20947. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  20948. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  20949. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  20950. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  20951. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  20952. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  20953. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  20954. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  20955. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  20956. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  20957. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  20958. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  20959. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  20960. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  20961. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  20962. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  20963. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  20964. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  20965. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  20966. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  20967. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  20968. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  20969. ]), 9];
  20970. var fixedDistCodeTab = [new Int32Array([
  20971. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  20972. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  20973. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  20974. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  20975. ]), 5];
  20976. function FlateStream(str, maybeLength) {
  20977. this.str = str;
  20978. this.dict = str.dict;
  20979. var cmf = str.getByte();
  20980. var flg = str.getByte();
  20981. if (cmf === -1 || flg === -1) {
  20982. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  20983. }
  20984. if ((cmf & 0x0f) !== 0x08) {
  20985. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  20986. }
  20987. if ((((cmf << 8) + flg) % 31) !== 0) {
  20988. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  20989. }
  20990. if (flg & 0x20) {
  20991. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  20992. }
  20993. this.codeSize = 0;
  20994. this.codeBuf = 0;
  20995. DecodeStream.call(this, maybeLength);
  20996. }
  20997. FlateStream.prototype = Object.create(DecodeStream.prototype);
  20998. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  20999. var str = this.str;
  21000. var codeSize = this.codeSize;
  21001. var codeBuf = this.codeBuf;
  21002. var b;
  21003. while (codeSize < bits) {
  21004. if ((b = str.getByte()) === -1) {
  21005. error('Bad encoding in flate stream');
  21006. }
  21007. codeBuf |= b << codeSize;
  21008. codeSize += 8;
  21009. }
  21010. b = codeBuf & ((1 << bits) - 1);
  21011. this.codeBuf = codeBuf >> bits;
  21012. this.codeSize = codeSize -= bits;
  21013. return b;
  21014. };
  21015. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  21016. var str = this.str;
  21017. var codes = table[0];
  21018. var maxLen = table[1];
  21019. var codeSize = this.codeSize;
  21020. var codeBuf = this.codeBuf;
  21021. var b;
  21022. while (codeSize < maxLen) {
  21023. if ((b = str.getByte()) === -1) {
  21024. // premature end of stream. code might however still be valid.
  21025. // codeSize < codeLen check below guards against incomplete codeVal.
  21026. break;
  21027. }
  21028. codeBuf |= (b << codeSize);
  21029. codeSize += 8;
  21030. }
  21031. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  21032. var codeLen = code >> 16;
  21033. var codeVal = code & 0xffff;
  21034. if (codeLen < 1 || codeSize < codeLen) {
  21035. error('Bad encoding in flate stream');
  21036. }
  21037. this.codeBuf = (codeBuf >> codeLen);
  21038. this.codeSize = (codeSize - codeLen);
  21039. return codeVal;
  21040. };
  21041. FlateStream.prototype.generateHuffmanTable =
  21042. function flateStreamGenerateHuffmanTable(lengths) {
  21043. var n = lengths.length;
  21044. // find max code length
  21045. var maxLen = 0;
  21046. var i;
  21047. for (i = 0; i < n; ++i) {
  21048. if (lengths[i] > maxLen) {
  21049. maxLen = lengths[i];
  21050. }
  21051. }
  21052. // build the table
  21053. var size = 1 << maxLen;
  21054. var codes = new Int32Array(size);
  21055. for (var len = 1, code = 0, skip = 2;
  21056. len <= maxLen;
  21057. ++len, code <<= 1, skip <<= 1) {
  21058. for (var val = 0; val < n; ++val) {
  21059. if (lengths[val] === len) {
  21060. // bit-reverse the code
  21061. var code2 = 0;
  21062. var t = code;
  21063. for (i = 0; i < len; ++i) {
  21064. code2 = (code2 << 1) | (t & 1);
  21065. t >>= 1;
  21066. }
  21067. // fill the table entries
  21068. for (i = code2; i < size; i += skip) {
  21069. codes[i] = (len << 16) | val;
  21070. }
  21071. ++code;
  21072. }
  21073. }
  21074. }
  21075. return [codes, maxLen];
  21076. };
  21077. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  21078. var buffer, len;
  21079. var str = this.str;
  21080. // read block header
  21081. var hdr = this.getBits(3);
  21082. if (hdr & 1) {
  21083. this.eof = true;
  21084. }
  21085. hdr >>= 1;
  21086. if (hdr === 0) { // uncompressed block
  21087. var b;
  21088. if ((b = str.getByte()) === -1) {
  21089. error('Bad block header in flate stream');
  21090. }
  21091. var blockLen = b;
  21092. if ((b = str.getByte()) === -1) {
  21093. error('Bad block header in flate stream');
  21094. }
  21095. blockLen |= (b << 8);
  21096. if ((b = str.getByte()) === -1) {
  21097. error('Bad block header in flate stream');
  21098. }
  21099. var check = b;
  21100. if ((b = str.getByte()) === -1) {
  21101. error('Bad block header in flate stream');
  21102. }
  21103. check |= (b << 8);
  21104. if (check !== (~blockLen & 0xffff) &&
  21105. (blockLen !== 0 || check !== 0)) {
  21106. // Ignoring error for bad "empty" block (see issue 1277)
  21107. error('Bad uncompressed block length in flate stream');
  21108. }
  21109. this.codeBuf = 0;
  21110. this.codeSize = 0;
  21111. var bufferLength = this.bufferLength;
  21112. buffer = this.ensureBuffer(bufferLength + blockLen);
  21113. var end = bufferLength + blockLen;
  21114. this.bufferLength = end;
  21115. if (blockLen === 0) {
  21116. if (str.peekByte() === -1) {
  21117. this.eof = true;
  21118. }
  21119. } else {
  21120. for (var n = bufferLength; n < end; ++n) {
  21121. if ((b = str.getByte()) === -1) {
  21122. this.eof = true;
  21123. break;
  21124. }
  21125. buffer[n] = b;
  21126. }
  21127. }
  21128. return;
  21129. }
  21130. var litCodeTable;
  21131. var distCodeTable;
  21132. if (hdr === 1) { // compressed block, fixed codes
  21133. litCodeTable = fixedLitCodeTab;
  21134. distCodeTable = fixedDistCodeTab;
  21135. } else if (hdr === 2) { // compressed block, dynamic codes
  21136. var numLitCodes = this.getBits(5) + 257;
  21137. var numDistCodes = this.getBits(5) + 1;
  21138. var numCodeLenCodes = this.getBits(4) + 4;
  21139. // build the code lengths code table
  21140. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  21141. var i;
  21142. for (i = 0; i < numCodeLenCodes; ++i) {
  21143. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  21144. }
  21145. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  21146. // build the literal and distance code tables
  21147. len = 0;
  21148. i = 0;
  21149. var codes = numLitCodes + numDistCodes;
  21150. var codeLengths = new Uint8Array(codes);
  21151. var bitsLength, bitsOffset, what;
  21152. while (i < codes) {
  21153. var code = this.getCode(codeLenCodeTab);
  21154. if (code === 16) {
  21155. bitsLength = 2; bitsOffset = 3; what = len;
  21156. } else if (code === 17) {
  21157. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  21158. } else if (code === 18) {
  21159. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  21160. } else {
  21161. codeLengths[i++] = len = code;
  21162. continue;
  21163. }
  21164. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  21165. while (repeatLength-- > 0) {
  21166. codeLengths[i++] = what;
  21167. }
  21168. }
  21169. litCodeTable =
  21170. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  21171. distCodeTable =
  21172. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  21173. } else {
  21174. error('Unknown block type in flate stream');
  21175. }
  21176. buffer = this.buffer;
  21177. var limit = buffer ? buffer.length : 0;
  21178. var pos = this.bufferLength;
  21179. while (true) {
  21180. var code1 = this.getCode(litCodeTable);
  21181. if (code1 < 256) {
  21182. if (pos + 1 >= limit) {
  21183. buffer = this.ensureBuffer(pos + 1);
  21184. limit = buffer.length;
  21185. }
  21186. buffer[pos++] = code1;
  21187. continue;
  21188. }
  21189. if (code1 === 256) {
  21190. this.bufferLength = pos;
  21191. return;
  21192. }
  21193. code1 -= 257;
  21194. code1 = lengthDecode[code1];
  21195. var code2 = code1 >> 16;
  21196. if (code2 > 0) {
  21197. code2 = this.getBits(code2);
  21198. }
  21199. len = (code1 & 0xffff) + code2;
  21200. code1 = this.getCode(distCodeTable);
  21201. code1 = distDecode[code1];
  21202. code2 = code1 >> 16;
  21203. if (code2 > 0) {
  21204. code2 = this.getBits(code2);
  21205. }
  21206. var dist = (code1 & 0xffff) + code2;
  21207. if (pos + len >= limit) {
  21208. buffer = this.ensureBuffer(pos + len);
  21209. limit = buffer.length;
  21210. }
  21211. for (var k = 0; k < len; ++k, ++pos) {
  21212. buffer[pos] = buffer[pos - dist];
  21213. }
  21214. }
  21215. };
  21216. return FlateStream;
  21217. })();
  21218. var PredictorStream = (function PredictorStreamClosure() {
  21219. function PredictorStream(str, maybeLength, params) {
  21220. if (!isDict(params)) {
  21221. return str; // no prediction
  21222. }
  21223. var predictor = this.predictor = params.get('Predictor') || 1;
  21224. if (predictor <= 1) {
  21225. return str; // no prediction
  21226. }
  21227. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  21228. error('Unsupported predictor: ' + predictor);
  21229. }
  21230. if (predictor === 2) {
  21231. this.readBlock = this.readBlockTiff;
  21232. } else {
  21233. this.readBlock = this.readBlockPng;
  21234. }
  21235. this.str = str;
  21236. this.dict = str.dict;
  21237. var colors = this.colors = params.get('Colors') || 1;
  21238. var bits = this.bits = params.get('BitsPerComponent') || 8;
  21239. var columns = this.columns = params.get('Columns') || 1;
  21240. this.pixBytes = (colors * bits + 7) >> 3;
  21241. this.rowBytes = (columns * colors * bits + 7) >> 3;
  21242. DecodeStream.call(this, maybeLength);
  21243. return this;
  21244. }
  21245. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  21246. PredictorStream.prototype.readBlockTiff =
  21247. function predictorStreamReadBlockTiff() {
  21248. var rowBytes = this.rowBytes;
  21249. var bufferLength = this.bufferLength;
  21250. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21251. var bits = this.bits;
  21252. var colors = this.colors;
  21253. var rawBytes = this.str.getBytes(rowBytes);
  21254. this.eof = !rawBytes.length;
  21255. if (this.eof) {
  21256. return;
  21257. }
  21258. var inbuf = 0, outbuf = 0;
  21259. var inbits = 0, outbits = 0;
  21260. var pos = bufferLength;
  21261. var i;
  21262. if (bits === 1) {
  21263. for (i = 0; i < rowBytes; ++i) {
  21264. var c = rawBytes[i];
  21265. inbuf = (inbuf << 8) | c;
  21266. // bitwise addition is exclusive or
  21267. // first shift inbuf and then add
  21268. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  21269. // truncate inbuf (assumes colors < 16)
  21270. inbuf &= 0xFFFF;
  21271. }
  21272. } else if (bits === 8) {
  21273. for (i = 0; i < colors; ++i) {
  21274. buffer[pos++] = rawBytes[i];
  21275. }
  21276. for (; i < rowBytes; ++i) {
  21277. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  21278. pos++;
  21279. }
  21280. } else {
  21281. var compArray = new Uint8Array(colors + 1);
  21282. var bitMask = (1 << bits) - 1;
  21283. var j = 0, k = bufferLength;
  21284. var columns = this.columns;
  21285. for (i = 0; i < columns; ++i) {
  21286. for (var kk = 0; kk < colors; ++kk) {
  21287. if (inbits < bits) {
  21288. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  21289. inbits += 8;
  21290. }
  21291. compArray[kk] = (compArray[kk] +
  21292. (inbuf >> (inbits - bits))) & bitMask;
  21293. inbits -= bits;
  21294. outbuf = (outbuf << bits) | compArray[kk];
  21295. outbits += bits;
  21296. if (outbits >= 8) {
  21297. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  21298. outbits -= 8;
  21299. }
  21300. }
  21301. }
  21302. if (outbits > 0) {
  21303. buffer[k++] = (outbuf << (8 - outbits)) +
  21304. (inbuf & ((1 << (8 - outbits)) - 1));
  21305. }
  21306. }
  21307. this.bufferLength += rowBytes;
  21308. };
  21309. PredictorStream.prototype.readBlockPng =
  21310. function predictorStreamReadBlockPng() {
  21311. var rowBytes = this.rowBytes;
  21312. var pixBytes = this.pixBytes;
  21313. var predictor = this.str.getByte();
  21314. var rawBytes = this.str.getBytes(rowBytes);
  21315. this.eof = !rawBytes.length;
  21316. if (this.eof) {
  21317. return;
  21318. }
  21319. var bufferLength = this.bufferLength;
  21320. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21321. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  21322. if (prevRow.length === 0) {
  21323. prevRow = new Uint8Array(rowBytes);
  21324. }
  21325. var i, j = bufferLength, up, c;
  21326. switch (predictor) {
  21327. case 0:
  21328. for (i = 0; i < rowBytes; ++i) {
  21329. buffer[j++] = rawBytes[i];
  21330. }
  21331. break;
  21332. case 1:
  21333. for (i = 0; i < pixBytes; ++i) {
  21334. buffer[j++] = rawBytes[i];
  21335. }
  21336. for (; i < rowBytes; ++i) {
  21337. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  21338. j++;
  21339. }
  21340. break;
  21341. case 2:
  21342. for (i = 0; i < rowBytes; ++i) {
  21343. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  21344. }
  21345. break;
  21346. case 3:
  21347. for (i = 0; i < pixBytes; ++i) {
  21348. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  21349. }
  21350. for (; i < rowBytes; ++i) {
  21351. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  21352. rawBytes[i]) & 0xFF;
  21353. j++;
  21354. }
  21355. break;
  21356. case 4:
  21357. // we need to save the up left pixels values. the simplest way
  21358. // is to create a new buffer
  21359. for (i = 0; i < pixBytes; ++i) {
  21360. up = prevRow[i];
  21361. c = rawBytes[i];
  21362. buffer[j++] = up + c;
  21363. }
  21364. for (; i < rowBytes; ++i) {
  21365. up = prevRow[i];
  21366. var upLeft = prevRow[i - pixBytes];
  21367. var left = buffer[j - pixBytes];
  21368. var p = left + up - upLeft;
  21369. var pa = p - left;
  21370. if (pa < 0) {
  21371. pa = -pa;
  21372. }
  21373. var pb = p - up;
  21374. if (pb < 0) {
  21375. pb = -pb;
  21376. }
  21377. var pc = p - upLeft;
  21378. if (pc < 0) {
  21379. pc = -pc;
  21380. }
  21381. c = rawBytes[i];
  21382. if (pa <= pb && pa <= pc) {
  21383. buffer[j++] = left + c;
  21384. } else if (pb <= pc) {
  21385. buffer[j++] = up + c;
  21386. } else {
  21387. buffer[j++] = upLeft + c;
  21388. }
  21389. }
  21390. break;
  21391. default:
  21392. error('Unsupported predictor: ' + predictor);
  21393. }
  21394. this.bufferLength += rowBytes;
  21395. };
  21396. return PredictorStream;
  21397. })();
  21398. /**
  21399. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  21400. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  21401. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  21402. * a library to decode these images and the stream behaves like all the other
  21403. * DecodeStreams.
  21404. */
  21405. var JpegStream = (function JpegStreamClosure() {
  21406. function JpegStream(stream, maybeLength, dict, xref) {
  21407. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  21408. // Note: this seems to mainly affect inline images.
  21409. var ch;
  21410. while ((ch = stream.getByte()) !== -1) {
  21411. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  21412. stream.skip(-1); // Reset the stream position to the SOI.
  21413. break;
  21414. }
  21415. }
  21416. this.stream = stream;
  21417. this.maybeLength = maybeLength;
  21418. this.dict = dict;
  21419. DecodeStream.call(this, maybeLength);
  21420. }
  21421. JpegStream.prototype = Object.create(DecodeStream.prototype);
  21422. Object.defineProperty(JpegStream.prototype, 'bytes', {
  21423. get: function JpegStream_bytes() {
  21424. // If this.maybeLength is null, we'll get the entire stream.
  21425. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21426. },
  21427. configurable: true
  21428. });
  21429. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  21430. if (this.bufferLength) {
  21431. return;
  21432. }
  21433. var jpegImage = new JpegImage();
  21434. // Checking if values need to be transformed before conversion.
  21435. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  21436. var decodeArr = this.dict.getArray('Decode');
  21437. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  21438. var decodeArrLength = decodeArr.length;
  21439. var transform = new Int32Array(decodeArrLength);
  21440. var transformNeeded = false;
  21441. var maxValue = (1 << bitsPerComponent) - 1;
  21442. for (var i = 0; i < decodeArrLength; i += 2) {
  21443. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  21444. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  21445. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  21446. transformNeeded = true;
  21447. }
  21448. }
  21449. if (transformNeeded) {
  21450. jpegImage.decodeTransform = transform;
  21451. }
  21452. }
  21453. jpegImage.parse(this.bytes);
  21454. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  21455. this.forceRGB);
  21456. this.buffer = data;
  21457. this.bufferLength = data.length;
  21458. this.eof = true;
  21459. };
  21460. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  21461. this.ensureBuffer();
  21462. return this.buffer;
  21463. };
  21464. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  21465. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  21466. };
  21467. return JpegStream;
  21468. })();
  21469. /**
  21470. * For JPEG 2000's we use a library to decode these images and
  21471. * the stream behaves like all the other DecodeStreams.
  21472. */
  21473. var JpxStream = (function JpxStreamClosure() {
  21474. function JpxStream(stream, maybeLength, dict) {
  21475. this.stream = stream;
  21476. this.maybeLength = maybeLength;
  21477. this.dict = dict;
  21478. DecodeStream.call(this, maybeLength);
  21479. }
  21480. JpxStream.prototype = Object.create(DecodeStream.prototype);
  21481. Object.defineProperty(JpxStream.prototype, 'bytes', {
  21482. get: function JpxStream_bytes() {
  21483. // If this.maybeLength is null, we'll get the entire stream.
  21484. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21485. },
  21486. configurable: true
  21487. });
  21488. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  21489. if (this.bufferLength) {
  21490. return;
  21491. }
  21492. var jpxImage = new JpxImage();
  21493. jpxImage.parse(this.bytes);
  21494. var width = jpxImage.width;
  21495. var height = jpxImage.height;
  21496. var componentsCount = jpxImage.componentsCount;
  21497. var tileCount = jpxImage.tiles.length;
  21498. if (tileCount === 1) {
  21499. this.buffer = jpxImage.tiles[0].items;
  21500. } else {
  21501. var data = new Uint8Array(width * height * componentsCount);
  21502. for (var k = 0; k < tileCount; k++) {
  21503. var tileComponents = jpxImage.tiles[k];
  21504. var tileWidth = tileComponents.width;
  21505. var tileHeight = tileComponents.height;
  21506. var tileLeft = tileComponents.left;
  21507. var tileTop = tileComponents.top;
  21508. var src = tileComponents.items;
  21509. var srcPosition = 0;
  21510. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  21511. var imgRowSize = width * componentsCount;
  21512. var tileRowSize = tileWidth * componentsCount;
  21513. for (var j = 0; j < tileHeight; j++) {
  21514. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  21515. data.set(rowBytes, dataPosition);
  21516. srcPosition += tileRowSize;
  21517. dataPosition += imgRowSize;
  21518. }
  21519. }
  21520. this.buffer = data;
  21521. }
  21522. this.bufferLength = this.buffer.length;
  21523. this.eof = true;
  21524. };
  21525. return JpxStream;
  21526. })();
  21527. /**
  21528. * For JBIG2's we use a library to decode these images and
  21529. * the stream behaves like all the other DecodeStreams.
  21530. */
  21531. var Jbig2Stream = (function Jbig2StreamClosure() {
  21532. function Jbig2Stream(stream, maybeLength, dict) {
  21533. this.stream = stream;
  21534. this.maybeLength = maybeLength;
  21535. this.dict = dict;
  21536. DecodeStream.call(this, maybeLength);
  21537. }
  21538. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  21539. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  21540. get: function Jbig2Stream_bytes() {
  21541. // If this.maybeLength is null, we'll get the entire stream.
  21542. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21543. },
  21544. configurable: true
  21545. });
  21546. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  21547. if (this.bufferLength) {
  21548. return;
  21549. }
  21550. var jbig2Image = new Jbig2Image();
  21551. var chunks = [];
  21552. var decodeParams = this.dict.getArray('DecodeParms');
  21553. // According to the PDF specification, DecodeParms can be either
  21554. // a dictionary, or an array whose elements are dictionaries.
  21555. if (isArray(decodeParams)) {
  21556. if (decodeParams.length > 1) {
  21557. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  21558. 'not supported.');
  21559. }
  21560. decodeParams = decodeParams[0];
  21561. }
  21562. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  21563. var globalsStream = decodeParams.get('JBIG2Globals');
  21564. var globals = globalsStream.getBytes();
  21565. chunks.push({data: globals, start: 0, end: globals.length});
  21566. }
  21567. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  21568. var data = jbig2Image.parseChunks(chunks);
  21569. var dataLength = data.length;
  21570. // JBIG2 had black as 1 and white as 0, inverting the colors
  21571. for (var i = 0; i < dataLength; i++) {
  21572. data[i] ^= 0xFF;
  21573. }
  21574. this.buffer = data;
  21575. this.bufferLength = dataLength;
  21576. this.eof = true;
  21577. };
  21578. return Jbig2Stream;
  21579. })();
  21580. var DecryptStream = (function DecryptStreamClosure() {
  21581. function DecryptStream(str, maybeLength, decrypt) {
  21582. this.str = str;
  21583. this.dict = str.dict;
  21584. this.decrypt = decrypt;
  21585. this.nextChunk = null;
  21586. this.initialized = false;
  21587. DecodeStream.call(this, maybeLength);
  21588. }
  21589. var chunkSize = 512;
  21590. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  21591. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  21592. var chunk;
  21593. if (this.initialized) {
  21594. chunk = this.nextChunk;
  21595. } else {
  21596. chunk = this.str.getBytes(chunkSize);
  21597. this.initialized = true;
  21598. }
  21599. if (!chunk || chunk.length === 0) {
  21600. this.eof = true;
  21601. return;
  21602. }
  21603. this.nextChunk = this.str.getBytes(chunkSize);
  21604. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  21605. var decrypt = this.decrypt;
  21606. chunk = decrypt(chunk, !hasMoreData);
  21607. var bufferLength = this.bufferLength;
  21608. var i, n = chunk.length;
  21609. var buffer = this.ensureBuffer(bufferLength + n);
  21610. for (i = 0; i < n; i++) {
  21611. buffer[bufferLength++] = chunk[i];
  21612. }
  21613. this.bufferLength = bufferLength;
  21614. };
  21615. return DecryptStream;
  21616. })();
  21617. var Ascii85Stream = (function Ascii85StreamClosure() {
  21618. function Ascii85Stream(str, maybeLength) {
  21619. this.str = str;
  21620. this.dict = str.dict;
  21621. this.input = new Uint8Array(5);
  21622. // Most streams increase in size when decoded, but Ascii85 streams
  21623. // typically shrink by ~20%.
  21624. if (maybeLength) {
  21625. maybeLength = 0.8 * maybeLength;
  21626. }
  21627. DecodeStream.call(this, maybeLength);
  21628. }
  21629. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  21630. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  21631. var TILDA_CHAR = 0x7E; // '~'
  21632. var Z_LOWER_CHAR = 0x7A; // 'z'
  21633. var EOF = -1;
  21634. var str = this.str;
  21635. var c = str.getByte();
  21636. while (isSpace(c)) {
  21637. c = str.getByte();
  21638. }
  21639. if (c === EOF || c === TILDA_CHAR) {
  21640. this.eof = true;
  21641. return;
  21642. }
  21643. var bufferLength = this.bufferLength, buffer;
  21644. var i;
  21645. // special code for z
  21646. if (c === Z_LOWER_CHAR) {
  21647. buffer = this.ensureBuffer(bufferLength + 4);
  21648. for (i = 0; i < 4; ++i) {
  21649. buffer[bufferLength + i] = 0;
  21650. }
  21651. this.bufferLength += 4;
  21652. } else {
  21653. var input = this.input;
  21654. input[0] = c;
  21655. for (i = 1; i < 5; ++i) {
  21656. c = str.getByte();
  21657. while (isSpace(c)) {
  21658. c = str.getByte();
  21659. }
  21660. input[i] = c;
  21661. if (c === EOF || c === TILDA_CHAR) {
  21662. break;
  21663. }
  21664. }
  21665. buffer = this.ensureBuffer(bufferLength + i - 1);
  21666. this.bufferLength += i - 1;
  21667. // partial ending;
  21668. if (i < 5) {
  21669. for (; i < 5; ++i) {
  21670. input[i] = 0x21 + 84;
  21671. }
  21672. this.eof = true;
  21673. }
  21674. var t = 0;
  21675. for (i = 0; i < 5; ++i) {
  21676. t = t * 85 + (input[i] - 0x21);
  21677. }
  21678. for (i = 3; i >= 0; --i) {
  21679. buffer[bufferLength + i] = t & 0xFF;
  21680. t >>= 8;
  21681. }
  21682. }
  21683. };
  21684. return Ascii85Stream;
  21685. })();
  21686. var AsciiHexStream = (function AsciiHexStreamClosure() {
  21687. function AsciiHexStream(str, maybeLength) {
  21688. this.str = str;
  21689. this.dict = str.dict;
  21690. this.firstDigit = -1;
  21691. // Most streams increase in size when decoded, but AsciiHex streams shrink
  21692. // by 50%.
  21693. if (maybeLength) {
  21694. maybeLength = 0.5 * maybeLength;
  21695. }
  21696. DecodeStream.call(this, maybeLength);
  21697. }
  21698. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  21699. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  21700. var UPSTREAM_BLOCK_SIZE = 8000;
  21701. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  21702. if (!bytes.length) {
  21703. this.eof = true;
  21704. return;
  21705. }
  21706. var maxDecodeLength = (bytes.length + 1) >> 1;
  21707. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  21708. var bufferLength = this.bufferLength;
  21709. var firstDigit = this.firstDigit;
  21710. for (var i = 0, ii = bytes.length; i < ii; i++) {
  21711. var ch = bytes[i], digit;
  21712. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  21713. digit = ch & 0x0F;
  21714. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  21715. // 'A'-'Z', 'a'-'z'
  21716. digit = (ch & 0x0F) + 9;
  21717. } else if (ch === 0x3E) { // '>'
  21718. this.eof = true;
  21719. break;
  21720. } else { // probably whitespace
  21721. continue; // ignoring
  21722. }
  21723. if (firstDigit < 0) {
  21724. firstDigit = digit;
  21725. } else {
  21726. buffer[bufferLength++] = (firstDigit << 4) | digit;
  21727. firstDigit = -1;
  21728. }
  21729. }
  21730. if (firstDigit >= 0 && this.eof) {
  21731. // incomplete byte
  21732. buffer[bufferLength++] = (firstDigit << 4);
  21733. firstDigit = -1;
  21734. }
  21735. this.firstDigit = firstDigit;
  21736. this.bufferLength = bufferLength;
  21737. };
  21738. return AsciiHexStream;
  21739. })();
  21740. var RunLengthStream = (function RunLengthStreamClosure() {
  21741. function RunLengthStream(str, maybeLength) {
  21742. this.str = str;
  21743. this.dict = str.dict;
  21744. DecodeStream.call(this, maybeLength);
  21745. }
  21746. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  21747. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  21748. // The repeatHeader has following format. The first byte defines type of run
  21749. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  21750. // (in addition to the second byte from the header), n = 129 through 255 -
  21751. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  21752. var repeatHeader = this.str.getBytes(2);
  21753. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  21754. this.eof = true;
  21755. return;
  21756. }
  21757. var buffer;
  21758. var bufferLength = this.bufferLength;
  21759. var n = repeatHeader[0];
  21760. if (n < 128) {
  21761. // copy n bytes
  21762. buffer = this.ensureBuffer(bufferLength + n + 1);
  21763. buffer[bufferLength++] = repeatHeader[1];
  21764. if (n > 0) {
  21765. var source = this.str.getBytes(n);
  21766. buffer.set(source, bufferLength);
  21767. bufferLength += n;
  21768. }
  21769. } else {
  21770. n = 257 - n;
  21771. var b = repeatHeader[1];
  21772. buffer = this.ensureBuffer(bufferLength + n + 1);
  21773. for (var i = 0; i < n; i++) {
  21774. buffer[bufferLength++] = b;
  21775. }
  21776. }
  21777. this.bufferLength = bufferLength;
  21778. };
  21779. return RunLengthStream;
  21780. })();
  21781. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  21782. var ccittEOL = -2;
  21783. var ccittEOF = -1;
  21784. var twoDimPass = 0;
  21785. var twoDimHoriz = 1;
  21786. var twoDimVert0 = 2;
  21787. var twoDimVertR1 = 3;
  21788. var twoDimVertL1 = 4;
  21789. var twoDimVertR2 = 5;
  21790. var twoDimVertL2 = 6;
  21791. var twoDimVertR3 = 7;
  21792. var twoDimVertL3 = 8;
  21793. var twoDimTable = [
  21794. [-1, -1], [-1, -1], // 000000x
  21795. [7, twoDimVertL3], // 0000010
  21796. [7, twoDimVertR3], // 0000011
  21797. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  21798. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  21799. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  21800. [4, twoDimPass], [4, twoDimPass],
  21801. [4, twoDimPass], [4, twoDimPass],
  21802. [4, twoDimPass], [4, twoDimPass],
  21803. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  21804. [3, twoDimHoriz], [3, twoDimHoriz],
  21805. [3, twoDimHoriz], [3, twoDimHoriz],
  21806. [3, twoDimHoriz], [3, twoDimHoriz],
  21807. [3, twoDimHoriz], [3, twoDimHoriz],
  21808. [3, twoDimHoriz], [3, twoDimHoriz],
  21809. [3, twoDimHoriz], [3, twoDimHoriz],
  21810. [3, twoDimHoriz], [3, twoDimHoriz],
  21811. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  21812. [3, twoDimVertL1], [3, twoDimVertL1],
  21813. [3, twoDimVertL1], [3, twoDimVertL1],
  21814. [3, twoDimVertL1], [3, twoDimVertL1],
  21815. [3, twoDimVertL1], [3, twoDimVertL1],
  21816. [3, twoDimVertL1], [3, twoDimVertL1],
  21817. [3, twoDimVertL1], [3, twoDimVertL1],
  21818. [3, twoDimVertL1], [3, twoDimVertL1],
  21819. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  21820. [3, twoDimVertR1], [3, twoDimVertR1],
  21821. [3, twoDimVertR1], [3, twoDimVertR1],
  21822. [3, twoDimVertR1], [3, twoDimVertR1],
  21823. [3, twoDimVertR1], [3, twoDimVertR1],
  21824. [3, twoDimVertR1], [3, twoDimVertR1],
  21825. [3, twoDimVertR1], [3, twoDimVertR1],
  21826. [3, twoDimVertR1], [3, twoDimVertR1],
  21827. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  21828. [1, twoDimVert0], [1, twoDimVert0],
  21829. [1, twoDimVert0], [1, twoDimVert0],
  21830. [1, twoDimVert0], [1, twoDimVert0],
  21831. [1, twoDimVert0], [1, twoDimVert0],
  21832. [1, twoDimVert0], [1, twoDimVert0],
  21833. [1, twoDimVert0], [1, twoDimVert0],
  21834. [1, twoDimVert0], [1, twoDimVert0],
  21835. [1, twoDimVert0], [1, twoDimVert0],
  21836. [1, twoDimVert0], [1, twoDimVert0],
  21837. [1, twoDimVert0], [1, twoDimVert0],
  21838. [1, twoDimVert0], [1, twoDimVert0],
  21839. [1, twoDimVert0], [1, twoDimVert0],
  21840. [1, twoDimVert0], [1, twoDimVert0],
  21841. [1, twoDimVert0], [1, twoDimVert0],
  21842. [1, twoDimVert0], [1, twoDimVert0],
  21843. [1, twoDimVert0], [1, twoDimVert0],
  21844. [1, twoDimVert0], [1, twoDimVert0],
  21845. [1, twoDimVert0], [1, twoDimVert0],
  21846. [1, twoDimVert0], [1, twoDimVert0],
  21847. [1, twoDimVert0], [1, twoDimVert0],
  21848. [1, twoDimVert0], [1, twoDimVert0],
  21849. [1, twoDimVert0], [1, twoDimVert0],
  21850. [1, twoDimVert0], [1, twoDimVert0],
  21851. [1, twoDimVert0], [1, twoDimVert0],
  21852. [1, twoDimVert0], [1, twoDimVert0],
  21853. [1, twoDimVert0], [1, twoDimVert0],
  21854. [1, twoDimVert0], [1, twoDimVert0],
  21855. [1, twoDimVert0], [1, twoDimVert0],
  21856. [1, twoDimVert0], [1, twoDimVert0],
  21857. [1, twoDimVert0], [1, twoDimVert0],
  21858. [1, twoDimVert0], [1, twoDimVert0]
  21859. ];
  21860. var whiteTable1 = [
  21861. [-1, -1], // 00000
  21862. [12, ccittEOL], // 00001
  21863. [-1, -1], [-1, -1], // 0001x
  21864. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  21865. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  21866. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  21867. [11, 1792], [11, 1792], // 1000x
  21868. [12, 1984], // 10010
  21869. [12, 2048], // 10011
  21870. [12, 2112], // 10100
  21871. [12, 2176], // 10101
  21872. [12, 2240], // 10110
  21873. [12, 2304], // 10111
  21874. [11, 1856], [11, 1856], // 1100x
  21875. [11, 1920], [11, 1920], // 1101x
  21876. [12, 2368], // 11100
  21877. [12, 2432], // 11101
  21878. [12, 2496], // 11110
  21879. [12, 2560] // 11111
  21880. ];
  21881. var whiteTable2 = [
  21882. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  21883. [8, 29], [8, 29], // 00000010x
  21884. [8, 30], [8, 30], // 00000011x
  21885. [8, 45], [8, 45], // 00000100x
  21886. [8, 46], [8, 46], // 00000101x
  21887. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  21888. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  21889. [8, 47], [8, 47], // 00001010x
  21890. [8, 48], [8, 48], // 00001011x
  21891. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  21892. [6, 13], [6, 13], [6, 13], [6, 13],
  21893. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  21894. [8, 33], [8, 33], // 00010010x
  21895. [8, 34], [8, 34], // 00010011x
  21896. [8, 35], [8, 35], // 00010100x
  21897. [8, 36], [8, 36], // 00010101x
  21898. [8, 37], [8, 37], // 00010110x
  21899. [8, 38], [8, 38], // 00010111x
  21900. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  21901. [8, 31], [8, 31], // 00011010x
  21902. [8, 32], [8, 32], // 00011011x
  21903. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  21904. [6, 1], [6, 1], [6, 1], [6, 1],
  21905. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  21906. [6, 12], [6, 12], [6, 12], [6, 12],
  21907. [8, 53], [8, 53], // 00100100x
  21908. [8, 54], [8, 54], // 00100101x
  21909. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  21910. [8, 39], [8, 39], // 00101000x
  21911. [8, 40], [8, 40], // 00101001x
  21912. [8, 41], [8, 41], // 00101010x
  21913. [8, 42], [8, 42], // 00101011x
  21914. [8, 43], [8, 43], // 00101100x
  21915. [8, 44], [8, 44], // 00101101x
  21916. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  21917. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  21918. [8, 61], [8, 61], // 00110010x
  21919. [8, 62], [8, 62], // 00110011x
  21920. [8, 63], [8, 63], // 00110100x
  21921. [8, 0], [8, 0], // 00110101x
  21922. [8, 320], [8, 320], // 00110110x
  21923. [8, 384], [8, 384], // 00110111x
  21924. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  21925. [5, 10], [5, 10], [5, 10], [5, 10],
  21926. [5, 10], [5, 10], [5, 10], [5, 10],
  21927. [5, 10], [5, 10], [5, 10], [5, 10],
  21928. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  21929. [5, 11], [5, 11], [5, 11], [5, 11],
  21930. [5, 11], [5, 11], [5, 11], [5, 11],
  21931. [5, 11], [5, 11], [5, 11], [5, 11],
  21932. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  21933. [8, 59], [8, 59], // 01001010x
  21934. [8, 60], [8, 60], // 01001011x
  21935. [9, 1472], // 010011000
  21936. [9, 1536], // 010011001
  21937. [9, 1600], // 010011010
  21938. [9, 1728], // 010011011
  21939. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  21940. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  21941. [8, 49], [8, 49], // 01010010x
  21942. [8, 50], [8, 50], // 01010011x
  21943. [8, 51], [8, 51], // 01010100x
  21944. [8, 52], [8, 52], // 01010101x
  21945. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  21946. [8, 55], [8, 55], // 01011000x
  21947. [8, 56], [8, 56], // 01011001x
  21948. [8, 57], [8, 57], // 01011010x
  21949. [8, 58], [8, 58], // 01011011x
  21950. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  21951. [6, 192], [6, 192], [6, 192], [6, 192],
  21952. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  21953. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  21954. [8, 448], [8, 448], // 01100100x
  21955. [8, 512], [8, 512], // 01100101x
  21956. [9, 704], // 011001100
  21957. [9, 768], // 011001101
  21958. [8, 640], [8, 640], // 01100111x
  21959. [8, 576], [8, 576], // 01101000x
  21960. [9, 832], // 011010010
  21961. [9, 896], // 011010011
  21962. [9, 960], // 011010100
  21963. [9, 1024], // 011010101
  21964. [9, 1088], // 011010110
  21965. [9, 1152], // 011010111
  21966. [9, 1216], // 011011000
  21967. [9, 1280], // 011011001
  21968. [9, 1344], // 011011010
  21969. [9, 1408], // 011011011
  21970. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  21971. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  21972. [4, 2], [4, 2], [4, 2], [4, 2],
  21973. [4, 2], [4, 2], [4, 2], [4, 2],
  21974. [4, 2], [4, 2], [4, 2], [4, 2],
  21975. [4, 2], [4, 2], [4, 2], [4, 2],
  21976. [4, 2], [4, 2], [4, 2], [4, 2],
  21977. [4, 2], [4, 2], [4, 2], [4, 2],
  21978. [4, 2], [4, 2], [4, 2], [4, 2],
  21979. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  21980. [4, 3], [4, 3], [4, 3], [4, 3],
  21981. [4, 3], [4, 3], [4, 3], [4, 3],
  21982. [4, 3], [4, 3], [4, 3], [4, 3],
  21983. [4, 3], [4, 3], [4, 3], [4, 3],
  21984. [4, 3], [4, 3], [4, 3], [4, 3],
  21985. [4, 3], [4, 3], [4, 3], [4, 3],
  21986. [4, 3], [4, 3], [4, 3], [4, 3],
  21987. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  21988. [5, 128], [5, 128], [5, 128], [5, 128],
  21989. [5, 128], [5, 128], [5, 128], [5, 128],
  21990. [5, 128], [5, 128], [5, 128], [5, 128],
  21991. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  21992. [5, 8], [5, 8], [5, 8], [5, 8],
  21993. [5, 8], [5, 8], [5, 8], [5, 8],
  21994. [5, 8], [5, 8], [5, 8], [5, 8],
  21995. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  21996. [5, 9], [5, 9], [5, 9], [5, 9],
  21997. [5, 9], [5, 9], [5, 9], [5, 9],
  21998. [5, 9], [5, 9], [5, 9], [5, 9],
  21999. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  22000. [6, 16], [6, 16], [6, 16], [6, 16],
  22001. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  22002. [6, 17], [6, 17], [6, 17], [6, 17],
  22003. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  22004. [4, 4], [4, 4], [4, 4], [4, 4],
  22005. [4, 4], [4, 4], [4, 4], [4, 4],
  22006. [4, 4], [4, 4], [4, 4], [4, 4],
  22007. [4, 4], [4, 4], [4, 4], [4, 4],
  22008. [4, 4], [4, 4], [4, 4], [4, 4],
  22009. [4, 4], [4, 4], [4, 4], [4, 4],
  22010. [4, 4], [4, 4], [4, 4], [4, 4],
  22011. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  22012. [4, 5], [4, 5], [4, 5], [4, 5],
  22013. [4, 5], [4, 5], [4, 5], [4, 5],
  22014. [4, 5], [4, 5], [4, 5], [4, 5],
  22015. [4, 5], [4, 5], [4, 5], [4, 5],
  22016. [4, 5], [4, 5], [4, 5], [4, 5],
  22017. [4, 5], [4, 5], [4, 5], [4, 5],
  22018. [4, 5], [4, 5], [4, 5], [4, 5],
  22019. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  22020. [6, 14], [6, 14], [6, 14], [6, 14],
  22021. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  22022. [6, 15], [6, 15], [6, 15], [6, 15],
  22023. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  22024. [5, 64], [5, 64], [5, 64], [5, 64],
  22025. [5, 64], [5, 64], [5, 64], [5, 64],
  22026. [5, 64], [5, 64], [5, 64], [5, 64],
  22027. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  22028. [4, 6], [4, 6], [4, 6], [4, 6],
  22029. [4, 6], [4, 6], [4, 6], [4, 6],
  22030. [4, 6], [4, 6], [4, 6], [4, 6],
  22031. [4, 6], [4, 6], [4, 6], [4, 6],
  22032. [4, 6], [4, 6], [4, 6], [4, 6],
  22033. [4, 6], [4, 6], [4, 6], [4, 6],
  22034. [4, 6], [4, 6], [4, 6], [4, 6],
  22035. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  22036. [4, 7], [4, 7], [4, 7], [4, 7],
  22037. [4, 7], [4, 7], [4, 7], [4, 7],
  22038. [4, 7], [4, 7], [4, 7], [4, 7],
  22039. [4, 7], [4, 7], [4, 7], [4, 7],
  22040. [4, 7], [4, 7], [4, 7], [4, 7],
  22041. [4, 7], [4, 7], [4, 7], [4, 7],
  22042. [4, 7], [4, 7], [4, 7], [4, 7]
  22043. ];
  22044. var blackTable1 = [
  22045. [-1, -1], [-1, -1], // 000000000000x
  22046. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  22047. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  22048. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  22049. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  22050. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  22051. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  22052. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  22053. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  22054. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  22055. [12, 1984], [12, 1984], // 000000010010x
  22056. [12, 2048], [12, 2048], // 000000010011x
  22057. [12, 2112], [12, 2112], // 000000010100x
  22058. [12, 2176], [12, 2176], // 000000010101x
  22059. [12, 2240], [12, 2240], // 000000010110x
  22060. [12, 2304], [12, 2304], // 000000010111x
  22061. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  22062. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  22063. [12, 2368], [12, 2368], // 000000011100x
  22064. [12, 2432], [12, 2432], // 000000011101x
  22065. [12, 2496], [12, 2496], // 000000011110x
  22066. [12, 2560], [12, 2560], // 000000011111x
  22067. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  22068. [10, 18], [10, 18], [10, 18], [10, 18],
  22069. [12, 52], [12, 52], // 000000100100x
  22070. [13, 640], // 0000001001010
  22071. [13, 704], // 0000001001011
  22072. [13, 768], // 0000001001100
  22073. [13, 832], // 0000001001101
  22074. [12, 55], [12, 55], // 000000100111x
  22075. [12, 56], [12, 56], // 000000101000x
  22076. [13, 1280], // 0000001010010
  22077. [13, 1344], // 0000001010011
  22078. [13, 1408], // 0000001010100
  22079. [13, 1472], // 0000001010101
  22080. [12, 59], [12, 59], // 000000101011x
  22081. [12, 60], [12, 60], // 000000101100x
  22082. [13, 1536], // 0000001011010
  22083. [13, 1600], // 0000001011011
  22084. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  22085. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  22086. [13, 1664], // 0000001100100
  22087. [13, 1728], // 0000001100101
  22088. [12, 320], [12, 320], // 000000110011x
  22089. [12, 384], [12, 384], // 000000110100x
  22090. [12, 448], [12, 448], // 000000110101x
  22091. [13, 512], // 0000001101100
  22092. [13, 576], // 0000001101101
  22093. [12, 53], [12, 53], // 000000110111x
  22094. [12, 54], [12, 54], // 000000111000x
  22095. [13, 896], // 0000001110010
  22096. [13, 960], // 0000001110011
  22097. [13, 1024], // 0000001110100
  22098. [13, 1088], // 0000001110101
  22099. [13, 1152], // 0000001110110
  22100. [13, 1216], // 0000001110111
  22101. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  22102. [10, 64], [10, 64], [10, 64], [10, 64]
  22103. ];
  22104. var blackTable2 = [
  22105. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  22106. [8, 13], [8, 13], [8, 13], [8, 13],
  22107. [8, 13], [8, 13], [8, 13], [8, 13],
  22108. [8, 13], [8, 13], [8, 13], [8, 13],
  22109. [11, 23], [11, 23], // 00000101000x
  22110. [12, 50], // 000001010010
  22111. [12, 51], // 000001010011
  22112. [12, 44], // 000001010100
  22113. [12, 45], // 000001010101
  22114. [12, 46], // 000001010110
  22115. [12, 47], // 000001010111
  22116. [12, 57], // 000001011000
  22117. [12, 58], // 000001011001
  22118. [12, 61], // 000001011010
  22119. [12, 256], // 000001011011
  22120. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  22121. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  22122. [12, 48], // 000001100100
  22123. [12, 49], // 000001100101
  22124. [12, 62], // 000001100110
  22125. [12, 63], // 000001100111
  22126. [12, 30], // 000001101000
  22127. [12, 31], // 000001101001
  22128. [12, 32], // 000001101010
  22129. [12, 33], // 000001101011
  22130. [12, 40], // 000001101100
  22131. [12, 41], // 000001101101
  22132. [11, 22], [11, 22], // 00000110111x
  22133. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  22134. [8, 14], [8, 14], [8, 14], [8, 14],
  22135. [8, 14], [8, 14], [8, 14], [8, 14],
  22136. [8, 14], [8, 14], [8, 14], [8, 14],
  22137. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  22138. [7, 10], [7, 10], [7, 10], [7, 10],
  22139. [7, 10], [7, 10], [7, 10], [7, 10],
  22140. [7, 10], [7, 10], [7, 10], [7, 10],
  22141. [7, 10], [7, 10], [7, 10], [7, 10],
  22142. [7, 10], [7, 10], [7, 10], [7, 10],
  22143. [7, 10], [7, 10], [7, 10], [7, 10],
  22144. [7, 10], [7, 10], [7, 10], [7, 10],
  22145. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  22146. [7, 11], [7, 11], [7, 11], [7, 11],
  22147. [7, 11], [7, 11], [7, 11], [7, 11],
  22148. [7, 11], [7, 11], [7, 11], [7, 11],
  22149. [7, 11], [7, 11], [7, 11], [7, 11],
  22150. [7, 11], [7, 11], [7, 11], [7, 11],
  22151. [7, 11], [7, 11], [7, 11], [7, 11],
  22152. [7, 11], [7, 11], [7, 11], [7, 11],
  22153. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  22154. [9, 15], [9, 15], [9, 15], [9, 15],
  22155. [12, 128], // 000011001000
  22156. [12, 192], // 000011001001
  22157. [12, 26], // 000011001010
  22158. [12, 27], // 000011001011
  22159. [12, 28], // 000011001100
  22160. [12, 29], // 000011001101
  22161. [11, 19], [11, 19], // 00001100111x
  22162. [11, 20], [11, 20], // 00001101000x
  22163. [12, 34], // 000011010010
  22164. [12, 35], // 000011010011
  22165. [12, 36], // 000011010100
  22166. [12, 37], // 000011010101
  22167. [12, 38], // 000011010110
  22168. [12, 39], // 000011010111
  22169. [11, 21], [11, 21], // 00001101100x
  22170. [12, 42], // 000011011010
  22171. [12, 43], // 000011011011
  22172. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  22173. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  22174. [7, 12], [7, 12], [7, 12], [7, 12],
  22175. [7, 12], [7, 12], [7, 12], [7, 12],
  22176. [7, 12], [7, 12], [7, 12], [7, 12],
  22177. [7, 12], [7, 12], [7, 12], [7, 12],
  22178. [7, 12], [7, 12], [7, 12], [7, 12],
  22179. [7, 12], [7, 12], [7, 12], [7, 12],
  22180. [7, 12], [7, 12], [7, 12], [7, 12]
  22181. ];
  22182. var blackTable3 = [
  22183. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  22184. [6, 9], // 000100
  22185. [6, 8], // 000101
  22186. [5, 7], [5, 7], // 00011x
  22187. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  22188. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  22189. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  22190. [3, 1], [3, 1], [3, 1], [3, 1],
  22191. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  22192. [3, 4], [3, 4], [3, 4], [3, 4],
  22193. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  22194. [2, 3], [2, 3], [2, 3], [2, 3],
  22195. [2, 3], [2, 3], [2, 3], [2, 3],
  22196. [2, 3], [2, 3], [2, 3], [2, 3],
  22197. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  22198. [2, 2], [2, 2], [2, 2], [2, 2],
  22199. [2, 2], [2, 2], [2, 2], [2, 2],
  22200. [2, 2], [2, 2], [2, 2], [2, 2]
  22201. ];
  22202. function CCITTFaxStream(str, maybeLength, params) {
  22203. this.str = str;
  22204. this.dict = str.dict;
  22205. params = params || Dict.empty;
  22206. this.encoding = params.get('K') || 0;
  22207. this.eoline = params.get('EndOfLine') || false;
  22208. this.byteAlign = params.get('EncodedByteAlign') || false;
  22209. this.columns = params.get('Columns') || 1728;
  22210. this.rows = params.get('Rows') || 0;
  22211. var eoblock = params.get('EndOfBlock');
  22212. if (eoblock === null || eoblock === undefined) {
  22213. eoblock = true;
  22214. }
  22215. this.eoblock = eoblock;
  22216. this.black = params.get('BlackIs1') || false;
  22217. this.codingLine = new Uint32Array(this.columns + 1);
  22218. this.refLine = new Uint32Array(this.columns + 2);
  22219. this.codingLine[0] = this.columns;
  22220. this.codingPos = 0;
  22221. this.row = 0;
  22222. this.nextLine2D = this.encoding < 0;
  22223. this.inputBits = 0;
  22224. this.inputBuf = 0;
  22225. this.outputBits = 0;
  22226. var code1;
  22227. while ((code1 = this.lookBits(12)) === 0) {
  22228. this.eatBits(1);
  22229. }
  22230. if (code1 === 1) {
  22231. this.eatBits(12);
  22232. }
  22233. if (this.encoding > 0) {
  22234. this.nextLine2D = !this.lookBits(1);
  22235. this.eatBits(1);
  22236. }
  22237. DecodeStream.call(this, maybeLength);
  22238. }
  22239. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  22240. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  22241. while (!this.eof) {
  22242. var c = this.lookChar();
  22243. this.ensureBuffer(this.bufferLength + 1);
  22244. this.buffer[this.bufferLength++] = c;
  22245. }
  22246. };
  22247. CCITTFaxStream.prototype.addPixels =
  22248. function ccittFaxStreamAddPixels(a1, blackPixels) {
  22249. var codingLine = this.codingLine;
  22250. var codingPos = this.codingPos;
  22251. if (a1 > codingLine[codingPos]) {
  22252. if (a1 > this.columns) {
  22253. info('row is wrong length');
  22254. this.err = true;
  22255. a1 = this.columns;
  22256. }
  22257. if ((codingPos & 1) ^ blackPixels) {
  22258. ++codingPos;
  22259. }
  22260. codingLine[codingPos] = a1;
  22261. }
  22262. this.codingPos = codingPos;
  22263. };
  22264. CCITTFaxStream.prototype.addPixelsNeg =
  22265. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  22266. var codingLine = this.codingLine;
  22267. var codingPos = this.codingPos;
  22268. if (a1 > codingLine[codingPos]) {
  22269. if (a1 > this.columns) {
  22270. info('row is wrong length');
  22271. this.err = true;
  22272. a1 = this.columns;
  22273. }
  22274. if ((codingPos & 1) ^ blackPixels) {
  22275. ++codingPos;
  22276. }
  22277. codingLine[codingPos] = a1;
  22278. } else if (a1 < codingLine[codingPos]) {
  22279. if (a1 < 0) {
  22280. info('invalid code');
  22281. this.err = true;
  22282. a1 = 0;
  22283. }
  22284. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  22285. --codingPos;
  22286. }
  22287. codingLine[codingPos] = a1;
  22288. }
  22289. this.codingPos = codingPos;
  22290. };
  22291. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  22292. var refLine = this.refLine;
  22293. var codingLine = this.codingLine;
  22294. var columns = this.columns;
  22295. var refPos, blackPixels, bits, i;
  22296. if (this.outputBits === 0) {
  22297. if (this.eof) {
  22298. return null;
  22299. }
  22300. this.err = false;
  22301. var code1, code2, code3;
  22302. if (this.nextLine2D) {
  22303. for (i = 0; codingLine[i] < columns; ++i) {
  22304. refLine[i] = codingLine[i];
  22305. }
  22306. refLine[i++] = columns;
  22307. refLine[i] = columns;
  22308. codingLine[0] = 0;
  22309. this.codingPos = 0;
  22310. refPos = 0;
  22311. blackPixels = 0;
  22312. while (codingLine[this.codingPos] < columns) {
  22313. code1 = this.getTwoDimCode();
  22314. switch (code1) {
  22315. case twoDimPass:
  22316. this.addPixels(refLine[refPos + 1], blackPixels);
  22317. if (refLine[refPos + 1] < columns) {
  22318. refPos += 2;
  22319. }
  22320. break;
  22321. case twoDimHoriz:
  22322. code1 = code2 = 0;
  22323. if (blackPixels) {
  22324. do {
  22325. code1 += (code3 = this.getBlackCode());
  22326. } while (code3 >= 64);
  22327. do {
  22328. code2 += (code3 = this.getWhiteCode());
  22329. } while (code3 >= 64);
  22330. } else {
  22331. do {
  22332. code1 += (code3 = this.getWhiteCode());
  22333. } while (code3 >= 64);
  22334. do {
  22335. code2 += (code3 = this.getBlackCode());
  22336. } while (code3 >= 64);
  22337. }
  22338. this.addPixels(codingLine[this.codingPos] +
  22339. code1, blackPixels);
  22340. if (codingLine[this.codingPos] < columns) {
  22341. this.addPixels(codingLine[this.codingPos] + code2,
  22342. blackPixels ^ 1);
  22343. }
  22344. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22345. refLine[refPos] < columns) {
  22346. refPos += 2;
  22347. }
  22348. break;
  22349. case twoDimVertR3:
  22350. this.addPixels(refLine[refPos] + 3, blackPixels);
  22351. blackPixels ^= 1;
  22352. if (codingLine[this.codingPos] < columns) {
  22353. ++refPos;
  22354. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22355. refLine[refPos] < columns) {
  22356. refPos += 2;
  22357. }
  22358. }
  22359. break;
  22360. case twoDimVertR2:
  22361. this.addPixels(refLine[refPos] + 2, blackPixels);
  22362. blackPixels ^= 1;
  22363. if (codingLine[this.codingPos] < columns) {
  22364. ++refPos;
  22365. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22366. refLine[refPos] < columns) {
  22367. refPos += 2;
  22368. }
  22369. }
  22370. break;
  22371. case twoDimVertR1:
  22372. this.addPixels(refLine[refPos] + 1, blackPixels);
  22373. blackPixels ^= 1;
  22374. if (codingLine[this.codingPos] < columns) {
  22375. ++refPos;
  22376. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22377. refLine[refPos] < columns) {
  22378. refPos += 2;
  22379. }
  22380. }
  22381. break;
  22382. case twoDimVert0:
  22383. this.addPixels(refLine[refPos], blackPixels);
  22384. blackPixels ^= 1;
  22385. if (codingLine[this.codingPos] < columns) {
  22386. ++refPos;
  22387. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22388. refLine[refPos] < columns) {
  22389. refPos += 2;
  22390. }
  22391. }
  22392. break;
  22393. case twoDimVertL3:
  22394. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  22395. blackPixels ^= 1;
  22396. if (codingLine[this.codingPos] < columns) {
  22397. if (refPos > 0) {
  22398. --refPos;
  22399. } else {
  22400. ++refPos;
  22401. }
  22402. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22403. refLine[refPos] < columns) {
  22404. refPos += 2;
  22405. }
  22406. }
  22407. break;
  22408. case twoDimVertL2:
  22409. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  22410. blackPixels ^= 1;
  22411. if (codingLine[this.codingPos] < columns) {
  22412. if (refPos > 0) {
  22413. --refPos;
  22414. } else {
  22415. ++refPos;
  22416. }
  22417. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22418. refLine[refPos] < columns) {
  22419. refPos += 2;
  22420. }
  22421. }
  22422. break;
  22423. case twoDimVertL1:
  22424. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  22425. blackPixels ^= 1;
  22426. if (codingLine[this.codingPos] < columns) {
  22427. if (refPos > 0) {
  22428. --refPos;
  22429. } else {
  22430. ++refPos;
  22431. }
  22432. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22433. refLine[refPos] < columns) {
  22434. refPos += 2;
  22435. }
  22436. }
  22437. break;
  22438. case ccittEOF:
  22439. this.addPixels(columns, 0);
  22440. this.eof = true;
  22441. break;
  22442. default:
  22443. info('bad 2d code');
  22444. this.addPixels(columns, 0);
  22445. this.err = true;
  22446. }
  22447. }
  22448. } else {
  22449. codingLine[0] = 0;
  22450. this.codingPos = 0;
  22451. blackPixels = 0;
  22452. while (codingLine[this.codingPos] < columns) {
  22453. code1 = 0;
  22454. if (blackPixels) {
  22455. do {
  22456. code1 += (code3 = this.getBlackCode());
  22457. } while (code3 >= 64);
  22458. } else {
  22459. do {
  22460. code1 += (code3 = this.getWhiteCode());
  22461. } while (code3 >= 64);
  22462. }
  22463. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  22464. blackPixels ^= 1;
  22465. }
  22466. }
  22467. var gotEOL = false;
  22468. if (this.byteAlign) {
  22469. this.inputBits &= ~7;
  22470. }
  22471. if (!this.eoblock && this.row === this.rows - 1) {
  22472. this.eof = true;
  22473. } else {
  22474. code1 = this.lookBits(12);
  22475. if (this.eoline) {
  22476. while (code1 !== ccittEOF && code1 !== 1) {
  22477. this.eatBits(1);
  22478. code1 = this.lookBits(12);
  22479. }
  22480. } else {
  22481. while (code1 === 0) {
  22482. this.eatBits(1);
  22483. code1 = this.lookBits(12);
  22484. }
  22485. }
  22486. if (code1 === 1) {
  22487. this.eatBits(12);
  22488. gotEOL = true;
  22489. } else if (code1 === ccittEOF) {
  22490. this.eof = true;
  22491. }
  22492. }
  22493. if (!this.eof && this.encoding > 0) {
  22494. this.nextLine2D = !this.lookBits(1);
  22495. this.eatBits(1);
  22496. }
  22497. if (this.eoblock && gotEOL && this.byteAlign) {
  22498. code1 = this.lookBits(12);
  22499. if (code1 === 1) {
  22500. this.eatBits(12);
  22501. if (this.encoding > 0) {
  22502. this.lookBits(1);
  22503. this.eatBits(1);
  22504. }
  22505. if (this.encoding >= 0) {
  22506. for (i = 0; i < 4; ++i) {
  22507. code1 = this.lookBits(12);
  22508. if (code1 !== 1) {
  22509. info('bad rtc code: ' + code1);
  22510. }
  22511. this.eatBits(12);
  22512. if (this.encoding > 0) {
  22513. this.lookBits(1);
  22514. this.eatBits(1);
  22515. }
  22516. }
  22517. }
  22518. this.eof = true;
  22519. }
  22520. } else if (this.err && this.eoline) {
  22521. while (true) {
  22522. code1 = this.lookBits(13);
  22523. if (code1 === ccittEOF) {
  22524. this.eof = true;
  22525. return null;
  22526. }
  22527. if ((code1 >> 1) === 1) {
  22528. break;
  22529. }
  22530. this.eatBits(1);
  22531. }
  22532. this.eatBits(12);
  22533. if (this.encoding > 0) {
  22534. this.eatBits(1);
  22535. this.nextLine2D = !(code1 & 1);
  22536. }
  22537. }
  22538. if (codingLine[0] > 0) {
  22539. this.outputBits = codingLine[this.codingPos = 0];
  22540. } else {
  22541. this.outputBits = codingLine[this.codingPos = 1];
  22542. }
  22543. this.row++;
  22544. }
  22545. var c;
  22546. if (this.outputBits >= 8) {
  22547. c = (this.codingPos & 1) ? 0 : 0xFF;
  22548. this.outputBits -= 8;
  22549. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  22550. this.codingPos++;
  22551. this.outputBits = (codingLine[this.codingPos] -
  22552. codingLine[this.codingPos - 1]);
  22553. }
  22554. } else {
  22555. bits = 8;
  22556. c = 0;
  22557. do {
  22558. if (this.outputBits > bits) {
  22559. c <<= bits;
  22560. if (!(this.codingPos & 1)) {
  22561. c |= 0xFF >> (8 - bits);
  22562. }
  22563. this.outputBits -= bits;
  22564. bits = 0;
  22565. } else {
  22566. c <<= this.outputBits;
  22567. if (!(this.codingPos & 1)) {
  22568. c |= 0xFF >> (8 - this.outputBits);
  22569. }
  22570. bits -= this.outputBits;
  22571. this.outputBits = 0;
  22572. if (codingLine[this.codingPos] < columns) {
  22573. this.codingPos++;
  22574. this.outputBits = (codingLine[this.codingPos] -
  22575. codingLine[this.codingPos - 1]);
  22576. } else if (bits > 0) {
  22577. c <<= bits;
  22578. bits = 0;
  22579. }
  22580. }
  22581. } while (bits);
  22582. }
  22583. if (this.black) {
  22584. c ^= 0xFF;
  22585. }
  22586. return c;
  22587. };
  22588. // This functions returns the code found from the table.
  22589. // The start and end parameters set the boundaries for searching the table.
  22590. // The limit parameter is optional. Function returns an array with three
  22591. // values. The first array element indicates whether a valid code is being
  22592. // returned. The second array element is the actual code. The third array
  22593. // element indicates whether EOF was reached.
  22594. CCITTFaxStream.prototype.findTableCode =
  22595. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  22596. var limitValue = limit || 0;
  22597. for (var i = start; i <= end; ++i) {
  22598. var code = this.lookBits(i);
  22599. if (code === ccittEOF) {
  22600. return [true, 1, false];
  22601. }
  22602. if (i < end) {
  22603. code <<= end - i;
  22604. }
  22605. if (!limitValue || code >= limitValue) {
  22606. var p = table[code - limitValue];
  22607. if (p[0] === i) {
  22608. this.eatBits(i);
  22609. return [true, p[1], true];
  22610. }
  22611. }
  22612. }
  22613. return [false, 0, false];
  22614. };
  22615. CCITTFaxStream.prototype.getTwoDimCode =
  22616. function ccittFaxStreamGetTwoDimCode() {
  22617. var code = 0;
  22618. var p;
  22619. if (this.eoblock) {
  22620. code = this.lookBits(7);
  22621. p = twoDimTable[code];
  22622. if (p && p[0] > 0) {
  22623. this.eatBits(p[0]);
  22624. return p[1];
  22625. }
  22626. } else {
  22627. var result = this.findTableCode(1, 7, twoDimTable);
  22628. if (result[0] && result[2]) {
  22629. return result[1];
  22630. }
  22631. }
  22632. info('Bad two dim code');
  22633. return ccittEOF;
  22634. };
  22635. CCITTFaxStream.prototype.getWhiteCode =
  22636. function ccittFaxStreamGetWhiteCode() {
  22637. var code = 0;
  22638. var p;
  22639. if (this.eoblock) {
  22640. code = this.lookBits(12);
  22641. if (code === ccittEOF) {
  22642. return 1;
  22643. }
  22644. if ((code >> 5) === 0) {
  22645. p = whiteTable1[code];
  22646. } else {
  22647. p = whiteTable2[code >> 3];
  22648. }
  22649. if (p[0] > 0) {
  22650. this.eatBits(p[0]);
  22651. return p[1];
  22652. }
  22653. } else {
  22654. var result = this.findTableCode(1, 9, whiteTable2);
  22655. if (result[0]) {
  22656. return result[1];
  22657. }
  22658. result = this.findTableCode(11, 12, whiteTable1);
  22659. if (result[0]) {
  22660. return result[1];
  22661. }
  22662. }
  22663. info('bad white code');
  22664. this.eatBits(1);
  22665. return 1;
  22666. };
  22667. CCITTFaxStream.prototype.getBlackCode =
  22668. function ccittFaxStreamGetBlackCode() {
  22669. var code, p;
  22670. if (this.eoblock) {
  22671. code = this.lookBits(13);
  22672. if (code === ccittEOF) {
  22673. return 1;
  22674. }
  22675. if ((code >> 7) === 0) {
  22676. p = blackTable1[code];
  22677. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  22678. p = blackTable2[(code >> 1) - 64];
  22679. } else {
  22680. p = blackTable3[code >> 7];
  22681. }
  22682. if (p[0] > 0) {
  22683. this.eatBits(p[0]);
  22684. return p[1];
  22685. }
  22686. } else {
  22687. var result = this.findTableCode(2, 6, blackTable3);
  22688. if (result[0]) {
  22689. return result[1];
  22690. }
  22691. result = this.findTableCode(7, 12, blackTable2, 64);
  22692. if (result[0]) {
  22693. return result[1];
  22694. }
  22695. result = this.findTableCode(10, 13, blackTable1);
  22696. if (result[0]) {
  22697. return result[1];
  22698. }
  22699. }
  22700. info('bad black code');
  22701. this.eatBits(1);
  22702. return 1;
  22703. };
  22704. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  22705. var c;
  22706. while (this.inputBits < n) {
  22707. if ((c = this.str.getByte()) === -1) {
  22708. if (this.inputBits === 0) {
  22709. return ccittEOF;
  22710. }
  22711. return ((this.inputBuf << (n - this.inputBits)) &
  22712. (0xFFFF >> (16 - n)));
  22713. }
  22714. this.inputBuf = (this.inputBuf << 8) | c;
  22715. this.inputBits += 8;
  22716. }
  22717. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  22718. };
  22719. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  22720. if ((this.inputBits -= n) < 0) {
  22721. this.inputBits = 0;
  22722. }
  22723. };
  22724. return CCITTFaxStream;
  22725. })();
  22726. var LZWStream = (function LZWStreamClosure() {
  22727. function LZWStream(str, maybeLength, earlyChange) {
  22728. this.str = str;
  22729. this.dict = str.dict;
  22730. this.cachedData = 0;
  22731. this.bitsCached = 0;
  22732. var maxLzwDictionarySize = 4096;
  22733. var lzwState = {
  22734. earlyChange: earlyChange,
  22735. codeLength: 9,
  22736. nextCode: 258,
  22737. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  22738. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  22739. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  22740. currentSequence: new Uint8Array(maxLzwDictionarySize),
  22741. currentSequenceLength: 0
  22742. };
  22743. for (var i = 0; i < 256; ++i) {
  22744. lzwState.dictionaryValues[i] = i;
  22745. lzwState.dictionaryLengths[i] = 1;
  22746. }
  22747. this.lzwState = lzwState;
  22748. DecodeStream.call(this, maybeLength);
  22749. }
  22750. LZWStream.prototype = Object.create(DecodeStream.prototype);
  22751. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  22752. var bitsCached = this.bitsCached;
  22753. var cachedData = this.cachedData;
  22754. while (bitsCached < n) {
  22755. var c = this.str.getByte();
  22756. if (c === -1) {
  22757. this.eof = true;
  22758. return null;
  22759. }
  22760. cachedData = (cachedData << 8) | c;
  22761. bitsCached += 8;
  22762. }
  22763. this.bitsCached = (bitsCached -= n);
  22764. this.cachedData = cachedData;
  22765. this.lastCode = null;
  22766. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  22767. };
  22768. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  22769. var blockSize = 512;
  22770. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  22771. var i, j, q;
  22772. var lzwState = this.lzwState;
  22773. if (!lzwState) {
  22774. return; // eof was found
  22775. }
  22776. var earlyChange = lzwState.earlyChange;
  22777. var nextCode = lzwState.nextCode;
  22778. var dictionaryValues = lzwState.dictionaryValues;
  22779. var dictionaryLengths = lzwState.dictionaryLengths;
  22780. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  22781. var codeLength = lzwState.codeLength;
  22782. var prevCode = lzwState.prevCode;
  22783. var currentSequence = lzwState.currentSequence;
  22784. var currentSequenceLength = lzwState.currentSequenceLength;
  22785. var decodedLength = 0;
  22786. var currentBufferLength = this.bufferLength;
  22787. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22788. for (i = 0; i < blockSize; i++) {
  22789. var code = this.readBits(codeLength);
  22790. var hasPrev = currentSequenceLength > 0;
  22791. if (code < 256) {
  22792. currentSequence[0] = code;
  22793. currentSequenceLength = 1;
  22794. } else if (code >= 258) {
  22795. if (code < nextCode) {
  22796. currentSequenceLength = dictionaryLengths[code];
  22797. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  22798. currentSequence[j] = dictionaryValues[q];
  22799. q = dictionaryPrevCodes[q];
  22800. }
  22801. } else {
  22802. currentSequence[currentSequenceLength++] = currentSequence[0];
  22803. }
  22804. } else if (code === 256) {
  22805. codeLength = 9;
  22806. nextCode = 258;
  22807. currentSequenceLength = 0;
  22808. continue;
  22809. } else {
  22810. this.eof = true;
  22811. delete this.lzwState;
  22812. break;
  22813. }
  22814. if (hasPrev) {
  22815. dictionaryPrevCodes[nextCode] = prevCode;
  22816. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  22817. dictionaryValues[nextCode] = currentSequence[0];
  22818. nextCode++;
  22819. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  22820. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  22821. 0.6931471805599453 + 1, 12) | 0;
  22822. }
  22823. prevCode = code;
  22824. decodedLength += currentSequenceLength;
  22825. if (estimatedDecodedSize < decodedLength) {
  22826. do {
  22827. estimatedDecodedSize += decodedSizeDelta;
  22828. } while (estimatedDecodedSize < decodedLength);
  22829. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22830. }
  22831. for (j = 0; j < currentSequenceLength; j++) {
  22832. buffer[currentBufferLength++] = currentSequence[j];
  22833. }
  22834. }
  22835. lzwState.nextCode = nextCode;
  22836. lzwState.codeLength = codeLength;
  22837. lzwState.prevCode = prevCode;
  22838. lzwState.currentSequenceLength = currentSequenceLength;
  22839. this.bufferLength = currentBufferLength;
  22840. };
  22841. return LZWStream;
  22842. })();
  22843. var NullStream = (function NullStreamClosure() {
  22844. function NullStream() {
  22845. Stream.call(this, new Uint8Array(0));
  22846. }
  22847. NullStream.prototype = Stream.prototype;
  22848. return NullStream;
  22849. })();
  22850. exports.Ascii85Stream = Ascii85Stream;
  22851. exports.AsciiHexStream = AsciiHexStream;
  22852. exports.CCITTFaxStream = CCITTFaxStream;
  22853. exports.DecryptStream = DecryptStream;
  22854. exports.DecodeStream = DecodeStream;
  22855. exports.FlateStream = FlateStream;
  22856. exports.Jbig2Stream = Jbig2Stream;
  22857. exports.JpegStream = JpegStream;
  22858. exports.JpxStream = JpxStream;
  22859. exports.NullStream = NullStream;
  22860. exports.PredictorStream = PredictorStream;
  22861. exports.RunLengthStream = RunLengthStream;
  22862. exports.Stream = Stream;
  22863. exports.StreamsSequenceStream = StreamsSequenceStream;
  22864. exports.StringStream = StringStream;
  22865. exports.LZWStream = LZWStream;
  22866. }));
  22867. (function (root, factory) {
  22868. {
  22869. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  22870. root.pdfjsDisplayDOMUtils);
  22871. }
  22872. }(this, function (exports, sharedUtil, displayDOMUtils) {
  22873. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  22874. var AnnotationType = sharedUtil.AnnotationType;
  22875. var Util = sharedUtil.Util;
  22876. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  22877. var LinkTarget = displayDOMUtils.LinkTarget;
  22878. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  22879. var warn = sharedUtil.warn;
  22880. var CustomStyle = displayDOMUtils.CustomStyle;
  22881. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  22882. /**
  22883. * @typedef {Object} AnnotationElementParameters
  22884. * @property {Object} data
  22885. * @property {HTMLDivElement} layer
  22886. * @property {PDFPage} page
  22887. * @property {PageViewport} viewport
  22888. * @property {IPDFLinkService} linkService
  22889. * @property {DownloadManager} downloadManager
  22890. * @property {string} imageResourcesPath
  22891. * @property {boolean} renderInteractiveForms
  22892. */
  22893. /**
  22894. * @class
  22895. * @alias AnnotationElementFactory
  22896. */
  22897. function AnnotationElementFactory() {}
  22898. AnnotationElementFactory.prototype =
  22899. /** @lends AnnotationElementFactory.prototype */ {
  22900. /**
  22901. * @param {AnnotationElementParameters} parameters
  22902. * @returns {AnnotationElement}
  22903. */
  22904. create: function AnnotationElementFactory_create(parameters) {
  22905. var subtype = parameters.data.annotationType;
  22906. switch (subtype) {
  22907. case AnnotationType.LINK:
  22908. return new LinkAnnotationElement(parameters);
  22909. case AnnotationType.TEXT:
  22910. return new TextAnnotationElement(parameters);
  22911. case AnnotationType.WIDGET:
  22912. var fieldType = parameters.data.fieldType;
  22913. switch (fieldType) {
  22914. case 'Tx':
  22915. return new TextWidgetAnnotationElement(parameters);
  22916. }
  22917. return new WidgetAnnotationElement(parameters);
  22918. case AnnotationType.POPUP:
  22919. return new PopupAnnotationElement(parameters);
  22920. case AnnotationType.HIGHLIGHT:
  22921. return new HighlightAnnotationElement(parameters);
  22922. case AnnotationType.UNDERLINE:
  22923. return new UnderlineAnnotationElement(parameters);
  22924. case AnnotationType.SQUIGGLY:
  22925. return new SquigglyAnnotationElement(parameters);
  22926. case AnnotationType.STRIKEOUT:
  22927. return new StrikeOutAnnotationElement(parameters);
  22928. case AnnotationType.FILEATTACHMENT:
  22929. return new FileAttachmentAnnotationElement(parameters);
  22930. default:
  22931. return new AnnotationElement(parameters);
  22932. }
  22933. }
  22934. };
  22935. /**
  22936. * @class
  22937. * @alias AnnotationElement
  22938. */
  22939. var AnnotationElement = (function AnnotationElementClosure() {
  22940. function AnnotationElement(parameters, isRenderable) {
  22941. this.isRenderable = isRenderable || false;
  22942. this.data = parameters.data;
  22943. this.layer = parameters.layer;
  22944. this.page = parameters.page;
  22945. this.viewport = parameters.viewport;
  22946. this.linkService = parameters.linkService;
  22947. this.downloadManager = parameters.downloadManager;
  22948. this.imageResourcesPath = parameters.imageResourcesPath;
  22949. this.renderInteractiveForms = parameters.renderInteractiveForms;
  22950. if (isRenderable) {
  22951. this.container = this._createContainer();
  22952. }
  22953. }
  22954. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  22955. /**
  22956. * Create an empty container for the annotation's HTML element.
  22957. *
  22958. * @private
  22959. * @memberof AnnotationElement
  22960. * @returns {HTMLSectionElement}
  22961. */
  22962. _createContainer: function AnnotationElement_createContainer() {
  22963. var data = this.data, page = this.page, viewport = this.viewport;
  22964. var container = document.createElement('section');
  22965. var width = data.rect[2] - data.rect[0];
  22966. var height = data.rect[3] - data.rect[1];
  22967. container.setAttribute('data-annotation-id', data.id);
  22968. // Do *not* modify `data.rect`, since that will corrupt the annotation
  22969. // position on subsequent calls to `_createContainer` (see issue 6804).
  22970. var rect = Util.normalizeRect([
  22971. data.rect[0],
  22972. page.view[3] - data.rect[1] + page.view[1],
  22973. data.rect[2],
  22974. page.view[3] - data.rect[3] + page.view[1]
  22975. ]);
  22976. CustomStyle.setProp('transform', container,
  22977. 'matrix(' + viewport.transform.join(',') + ')');
  22978. CustomStyle.setProp('transformOrigin', container,
  22979. -rect[0] + 'px ' + -rect[1] + 'px');
  22980. if (data.borderStyle.width > 0) {
  22981. container.style.borderWidth = data.borderStyle.width + 'px';
  22982. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  22983. // Underline styles only have a bottom border, so we do not need
  22984. // to adjust for all borders. This yields a similar result as
  22985. // Adobe Acrobat/Reader.
  22986. width = width - 2 * data.borderStyle.width;
  22987. height = height - 2 * data.borderStyle.width;
  22988. }
  22989. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  22990. var verticalRadius = data.borderStyle.verticalCornerRadius;
  22991. if (horizontalRadius > 0 || verticalRadius > 0) {
  22992. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  22993. CustomStyle.setProp('borderRadius', container, radius);
  22994. }
  22995. switch (data.borderStyle.style) {
  22996. case AnnotationBorderStyleType.SOLID:
  22997. container.style.borderStyle = 'solid';
  22998. break;
  22999. case AnnotationBorderStyleType.DASHED:
  23000. container.style.borderStyle = 'dashed';
  23001. break;
  23002. case AnnotationBorderStyleType.BEVELED:
  23003. warn('Unimplemented border style: beveled');
  23004. break;
  23005. case AnnotationBorderStyleType.INSET:
  23006. warn('Unimplemented border style: inset');
  23007. break;
  23008. case AnnotationBorderStyleType.UNDERLINE:
  23009. container.style.borderBottomStyle = 'solid';
  23010. break;
  23011. default:
  23012. break;
  23013. }
  23014. if (data.color) {
  23015. container.style.borderColor =
  23016. Util.makeCssRgb(data.color[0] | 0,
  23017. data.color[1] | 0,
  23018. data.color[2] | 0);
  23019. } else {
  23020. // Transparent (invisible) border, so do not draw it at all.
  23021. container.style.borderWidth = 0;
  23022. }
  23023. }
  23024. container.style.left = rect[0] + 'px';
  23025. container.style.top = rect[1] + 'px';
  23026. container.style.width = width + 'px';
  23027. container.style.height = height + 'px';
  23028. return container;
  23029. },
  23030. /**
  23031. * Create a popup for the annotation's HTML element. This is used for
  23032. * annotations that do not have a Popup entry in the dictionary, but
  23033. * are of a type that works with popups (such as Highlight annotations).
  23034. *
  23035. * @private
  23036. * @param {HTMLSectionElement} container
  23037. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  23038. * @param {Object} data
  23039. * @memberof AnnotationElement
  23040. */
  23041. _createPopup:
  23042. function AnnotationElement_createPopup(container, trigger, data) {
  23043. // If no trigger element is specified, create it.
  23044. if (!trigger) {
  23045. trigger = document.createElement('div');
  23046. trigger.style.height = container.style.height;
  23047. trigger.style.width = container.style.width;
  23048. container.appendChild(trigger);
  23049. }
  23050. var popupElement = new PopupElement({
  23051. container: container,
  23052. trigger: trigger,
  23053. color: data.color,
  23054. title: data.title,
  23055. contents: data.contents,
  23056. hideWrapper: true
  23057. });
  23058. var popup = popupElement.render();
  23059. // Position the popup next to the annotation's container.
  23060. popup.style.left = container.style.width;
  23061. container.appendChild(popup);
  23062. },
  23063. /**
  23064. * Render the annotation's HTML element in the empty container.
  23065. *
  23066. * @public
  23067. * @memberof AnnotationElement
  23068. */
  23069. render: function AnnotationElement_render() {
  23070. throw new Error('Abstract method AnnotationElement.render called');
  23071. }
  23072. };
  23073. return AnnotationElement;
  23074. })();
  23075. /**
  23076. * @class
  23077. * @alias LinkAnnotationElement
  23078. */
  23079. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  23080. function LinkAnnotationElement(parameters) {
  23081. AnnotationElement.call(this, parameters, true);
  23082. }
  23083. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  23084. /**
  23085. * Render the link annotation's HTML element in the empty container.
  23086. *
  23087. * @public
  23088. * @memberof LinkAnnotationElement
  23089. * @returns {HTMLSectionElement}
  23090. */
  23091. render: function LinkAnnotationElement_render() {
  23092. this.container.className = 'linkAnnotation';
  23093. var link = document.createElement('a');
  23094. addLinkAttributes(link, {
  23095. url: this.data.url,
  23096. target: (this.data.newWindow ? LinkTarget.BLANK : undefined),
  23097. });
  23098. if (!this.data.url) {
  23099. if (this.data.action) {
  23100. this._bindNamedAction(link, this.data.action);
  23101. } else {
  23102. this._bindLink(link, (this.data.dest || null));
  23103. }
  23104. }
  23105. this.container.appendChild(link);
  23106. return this.container;
  23107. },
  23108. /**
  23109. * Bind internal links to the link element.
  23110. *
  23111. * @private
  23112. * @param {Object} link
  23113. * @param {Object} destination
  23114. * @memberof LinkAnnotationElement
  23115. */
  23116. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  23117. var self = this;
  23118. link.href = this.linkService.getDestinationHash(destination);
  23119. link.onclick = function() {
  23120. if (destination) {
  23121. self.linkService.navigateTo(destination);
  23122. }
  23123. return false;
  23124. };
  23125. if (destination) {
  23126. link.className = 'internalLink';
  23127. }
  23128. },
  23129. /**
  23130. * Bind named actions to the link element.
  23131. *
  23132. * @private
  23133. * @param {Object} link
  23134. * @param {Object} action
  23135. * @memberof LinkAnnotationElement
  23136. */
  23137. _bindNamedAction:
  23138. function LinkAnnotationElement_bindNamedAction(link, action) {
  23139. var self = this;
  23140. link.href = this.linkService.getAnchorUrl('');
  23141. link.onclick = function() {
  23142. self.linkService.executeNamedAction(action);
  23143. return false;
  23144. };
  23145. link.className = 'internalLink';
  23146. }
  23147. });
  23148. return LinkAnnotationElement;
  23149. })();
  23150. /**
  23151. * @class
  23152. * @alias TextAnnotationElement
  23153. */
  23154. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  23155. function TextAnnotationElement(parameters) {
  23156. var isRenderable = !!(parameters.data.hasPopup ||
  23157. parameters.data.title || parameters.data.contents);
  23158. AnnotationElement.call(this, parameters, isRenderable);
  23159. }
  23160. Util.inherit(TextAnnotationElement, AnnotationElement, {
  23161. /**
  23162. * Render the text annotation's HTML element in the empty container.
  23163. *
  23164. * @public
  23165. * @memberof TextAnnotationElement
  23166. * @returns {HTMLSectionElement}
  23167. */
  23168. render: function TextAnnotationElement_render() {
  23169. this.container.className = 'textAnnotation';
  23170. var image = document.createElement('img');
  23171. image.style.height = this.container.style.height;
  23172. image.style.width = this.container.style.width;
  23173. image.src = this.imageResourcesPath + 'annotation-' +
  23174. this.data.name.toLowerCase() + '.svg';
  23175. image.alt = '[{{type}} Annotation]';
  23176. image.dataset.l10nId = 'text_annotation_type';
  23177. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  23178. if (!this.data.hasPopup) {
  23179. this._createPopup(this.container, image, this.data);
  23180. }
  23181. this.container.appendChild(image);
  23182. return this.container;
  23183. }
  23184. });
  23185. return TextAnnotationElement;
  23186. })();
  23187. /**
  23188. * @class
  23189. * @alias WidgetAnnotationElement
  23190. */
  23191. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  23192. function WidgetAnnotationElement(parameters) {
  23193. var isRenderable = parameters.renderInteractiveForms ||
  23194. (!parameters.data.hasAppearance && !!parameters.data.fieldValue);
  23195. AnnotationElement.call(this, parameters, isRenderable);
  23196. }
  23197. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  23198. /**
  23199. * Render the widget annotation's HTML element in the empty container.
  23200. *
  23201. * @public
  23202. * @memberof WidgetAnnotationElement
  23203. * @returns {HTMLSectionElement}
  23204. */
  23205. render: function WidgetAnnotationElement_render() {
  23206. // Show only the container for unsupported field types.
  23207. return this.container;
  23208. }
  23209. });
  23210. return WidgetAnnotationElement;
  23211. })();
  23212. /**
  23213. * @class
  23214. * @alias TextWidgetAnnotationElement
  23215. */
  23216. var TextWidgetAnnotationElement = (
  23217. function TextWidgetAnnotationElementClosure() {
  23218. var TEXT_ALIGNMENT = ['left', 'center', 'right'];
  23219. function TextWidgetAnnotationElement(parameters) {
  23220. WidgetAnnotationElement.call(this, parameters);
  23221. }
  23222. Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  23223. /**
  23224. * Render the text widget annotation's HTML element in the empty container.
  23225. *
  23226. * @public
  23227. * @memberof TextWidgetAnnotationElement
  23228. * @returns {HTMLSectionElement}
  23229. */
  23230. render: function TextWidgetAnnotationElement_render() {
  23231. this.container.className = 'textWidgetAnnotation';
  23232. var element = null;
  23233. if (this.renderInteractiveForms) {
  23234. // NOTE: We cannot set the values using `element.value` below, since it
  23235. // prevents the AnnotationLayer rasterizer in `test/driver.js`
  23236. // from parsing the elements correctly for the reference tests.
  23237. if (this.data.multiLine) {
  23238. element = document.createElement('textarea');
  23239. element.textContent = this.data.fieldValue;
  23240. } else {
  23241. element = document.createElement('input');
  23242. element.type = 'text';
  23243. element.setAttribute('value', this.data.fieldValue);
  23244. }
  23245. element.disabled = this.data.readOnly;
  23246. if (this.data.maxLen !== null) {
  23247. element.maxLength = this.data.maxLen;
  23248. }
  23249. if (this.data.comb) {
  23250. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  23251. var combWidth = fieldWidth / this.data.maxLen;
  23252. element.classList.add('comb');
  23253. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  23254. }
  23255. } else {
  23256. element = document.createElement('div');
  23257. element.textContent = this.data.fieldValue;
  23258. element.style.verticalAlign = 'middle';
  23259. element.style.display = 'table-cell';
  23260. var font = null;
  23261. if (this.data.fontRefName) {
  23262. font = this.page.commonObjs.getData(this.data.fontRefName);
  23263. }
  23264. this._setTextStyle(element, font);
  23265. }
  23266. if (this.data.textAlignment !== null) {
  23267. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  23268. }
  23269. this.container.appendChild(element);
  23270. return this.container;
  23271. },
  23272. /**
  23273. * Apply text styles to the text in the element.
  23274. *
  23275. * @private
  23276. * @param {HTMLDivElement} element
  23277. * @param {Object} font
  23278. * @memberof TextWidgetAnnotationElement
  23279. */
  23280. _setTextStyle:
  23281. function TextWidgetAnnotationElement_setTextStyle(element, font) {
  23282. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  23283. var style = element.style;
  23284. style.fontSize = this.data.fontSize + 'px';
  23285. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  23286. if (!font) {
  23287. return;
  23288. }
  23289. style.fontWeight = (font.black ?
  23290. (font.bold ? '900' : 'bold') :
  23291. (font.bold ? 'bold' : 'normal'));
  23292. style.fontStyle = (font.italic ? 'italic' : 'normal');
  23293. // Use a reasonable default font if the font doesn't specify a fallback.
  23294. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  23295. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  23296. style.fontFamily = fontFamily + fallbackName;
  23297. }
  23298. });
  23299. return TextWidgetAnnotationElement;
  23300. })();
  23301. /**
  23302. * @class
  23303. * @alias PopupAnnotationElement
  23304. */
  23305. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  23306. function PopupAnnotationElement(parameters) {
  23307. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  23308. AnnotationElement.call(this, parameters, isRenderable);
  23309. }
  23310. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  23311. /**
  23312. * Render the popup annotation's HTML element in the empty container.
  23313. *
  23314. * @public
  23315. * @memberof PopupAnnotationElement
  23316. * @returns {HTMLSectionElement}
  23317. */
  23318. render: function PopupAnnotationElement_render() {
  23319. this.container.className = 'popupAnnotation';
  23320. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  23321. var parentElement = this.layer.querySelector(selector);
  23322. if (!parentElement) {
  23323. return this.container;
  23324. }
  23325. var popup = new PopupElement({
  23326. container: this.container,
  23327. trigger: parentElement,
  23328. color: this.data.color,
  23329. title: this.data.title,
  23330. contents: this.data.contents
  23331. });
  23332. // Position the popup next to the parent annotation's container.
  23333. // PDF viewers ignore a popup annotation's rectangle.
  23334. var parentLeft = parseFloat(parentElement.style.left);
  23335. var parentWidth = parseFloat(parentElement.style.width);
  23336. CustomStyle.setProp('transformOrigin', this.container,
  23337. -(parentLeft + parentWidth) + 'px -' +
  23338. parentElement.style.top);
  23339. this.container.style.left = (parentLeft + parentWidth) + 'px';
  23340. this.container.appendChild(popup.render());
  23341. return this.container;
  23342. }
  23343. });
  23344. return PopupAnnotationElement;
  23345. })();
  23346. /**
  23347. * @class
  23348. * @alias PopupElement
  23349. */
  23350. var PopupElement = (function PopupElementClosure() {
  23351. var BACKGROUND_ENLIGHT = 0.7;
  23352. function PopupElement(parameters) {
  23353. this.container = parameters.container;
  23354. this.trigger = parameters.trigger;
  23355. this.color = parameters.color;
  23356. this.title = parameters.title;
  23357. this.contents = parameters.contents;
  23358. this.hideWrapper = parameters.hideWrapper || false;
  23359. this.pinned = false;
  23360. }
  23361. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  23362. /**
  23363. * Render the popup's HTML element.
  23364. *
  23365. * @public
  23366. * @memberof PopupElement
  23367. * @returns {HTMLSectionElement}
  23368. */
  23369. render: function PopupElement_render() {
  23370. var wrapper = document.createElement('div');
  23371. wrapper.className = 'popupWrapper';
  23372. // For Popup annotations we hide the entire section because it contains
  23373. // only the popup. However, for Text annotations without a separate Popup
  23374. // annotation, we cannot hide the entire container as the image would
  23375. // disappear too. In that special case, hiding the wrapper suffices.
  23376. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  23377. this.hideElement.setAttribute('hidden', true);
  23378. var popup = document.createElement('div');
  23379. popup.className = 'popup';
  23380. var color = this.color;
  23381. if (color) {
  23382. // Enlighten the color.
  23383. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  23384. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  23385. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  23386. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  23387. }
  23388. var contents = this._formatContents(this.contents);
  23389. var title = document.createElement('h1');
  23390. title.textContent = this.title;
  23391. // Attach the event listeners to the trigger element.
  23392. this.trigger.addEventListener('click', this._toggle.bind(this));
  23393. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  23394. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  23395. popup.addEventListener('click', this._hide.bind(this, true));
  23396. popup.appendChild(title);
  23397. popup.appendChild(contents);
  23398. wrapper.appendChild(popup);
  23399. return wrapper;
  23400. },
  23401. /**
  23402. * Format the contents of the popup by adding newlines where necessary.
  23403. *
  23404. * @private
  23405. * @param {string} contents
  23406. * @memberof PopupElement
  23407. * @returns {HTMLParagraphElement}
  23408. */
  23409. _formatContents: function PopupElement_formatContents(contents) {
  23410. var p = document.createElement('p');
  23411. var lines = contents.split(/(?:\r\n?|\n)/);
  23412. for (var i = 0, ii = lines.length; i < ii; ++i) {
  23413. var line = lines[i];
  23414. p.appendChild(document.createTextNode(line));
  23415. if (i < (ii - 1)) {
  23416. p.appendChild(document.createElement('br'));
  23417. }
  23418. }
  23419. return p;
  23420. },
  23421. /**
  23422. * Toggle the visibility of the popup.
  23423. *
  23424. * @private
  23425. * @memberof PopupElement
  23426. */
  23427. _toggle: function PopupElement_toggle() {
  23428. if (this.pinned) {
  23429. this._hide(true);
  23430. } else {
  23431. this._show(true);
  23432. }
  23433. },
  23434. /**
  23435. * Show the popup.
  23436. *
  23437. * @private
  23438. * @param {boolean} pin
  23439. * @memberof PopupElement
  23440. */
  23441. _show: function PopupElement_show(pin) {
  23442. if (pin) {
  23443. this.pinned = true;
  23444. }
  23445. if (this.hideElement.hasAttribute('hidden')) {
  23446. this.hideElement.removeAttribute('hidden');
  23447. this.container.style.zIndex += 1;
  23448. }
  23449. },
  23450. /**
  23451. * Hide the popup.
  23452. *
  23453. * @private
  23454. * @param {boolean} unpin
  23455. * @memberof PopupElement
  23456. */
  23457. _hide: function PopupElement_hide(unpin) {
  23458. if (unpin) {
  23459. this.pinned = false;
  23460. }
  23461. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  23462. this.hideElement.setAttribute('hidden', true);
  23463. this.container.style.zIndex -= 1;
  23464. }
  23465. }
  23466. };
  23467. return PopupElement;
  23468. })();
  23469. /**
  23470. * @class
  23471. * @alias HighlightAnnotationElement
  23472. */
  23473. var HighlightAnnotationElement = (
  23474. function HighlightAnnotationElementClosure() {
  23475. function HighlightAnnotationElement(parameters) {
  23476. var isRenderable = !!(parameters.data.hasPopup ||
  23477. parameters.data.title || parameters.data.contents);
  23478. AnnotationElement.call(this, parameters, isRenderable);
  23479. }
  23480. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  23481. /**
  23482. * Render the highlight annotation's HTML element in the empty container.
  23483. *
  23484. * @public
  23485. * @memberof HighlightAnnotationElement
  23486. * @returns {HTMLSectionElement}
  23487. */
  23488. render: function HighlightAnnotationElement_render() {
  23489. this.container.className = 'highlightAnnotation';
  23490. if (!this.data.hasPopup) {
  23491. this._createPopup(this.container, null, this.data);
  23492. }
  23493. return this.container;
  23494. }
  23495. });
  23496. return HighlightAnnotationElement;
  23497. })();
  23498. /**
  23499. * @class
  23500. * @alias UnderlineAnnotationElement
  23501. */
  23502. var UnderlineAnnotationElement = (
  23503. function UnderlineAnnotationElementClosure() {
  23504. function UnderlineAnnotationElement(parameters) {
  23505. var isRenderable = !!(parameters.data.hasPopup ||
  23506. parameters.data.title || parameters.data.contents);
  23507. AnnotationElement.call(this, parameters, isRenderable);
  23508. }
  23509. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  23510. /**
  23511. * Render the underline annotation's HTML element in the empty container.
  23512. *
  23513. * @public
  23514. * @memberof UnderlineAnnotationElement
  23515. * @returns {HTMLSectionElement}
  23516. */
  23517. render: function UnderlineAnnotationElement_render() {
  23518. this.container.className = 'underlineAnnotation';
  23519. if (!this.data.hasPopup) {
  23520. this._createPopup(this.container, null, this.data);
  23521. }
  23522. return this.container;
  23523. }
  23524. });
  23525. return UnderlineAnnotationElement;
  23526. })();
  23527. /**
  23528. * @class
  23529. * @alias SquigglyAnnotationElement
  23530. */
  23531. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  23532. function SquigglyAnnotationElement(parameters) {
  23533. var isRenderable = !!(parameters.data.hasPopup ||
  23534. parameters.data.title || parameters.data.contents);
  23535. AnnotationElement.call(this, parameters, isRenderable);
  23536. }
  23537. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  23538. /**
  23539. * Render the squiggly annotation's HTML element in the empty container.
  23540. *
  23541. * @public
  23542. * @memberof SquigglyAnnotationElement
  23543. * @returns {HTMLSectionElement}
  23544. */
  23545. render: function SquigglyAnnotationElement_render() {
  23546. this.container.className = 'squigglyAnnotation';
  23547. if (!this.data.hasPopup) {
  23548. this._createPopup(this.container, null, this.data);
  23549. }
  23550. return this.container;
  23551. }
  23552. });
  23553. return SquigglyAnnotationElement;
  23554. })();
  23555. /**
  23556. * @class
  23557. * @alias StrikeOutAnnotationElement
  23558. */
  23559. var StrikeOutAnnotationElement = (
  23560. function StrikeOutAnnotationElementClosure() {
  23561. function StrikeOutAnnotationElement(parameters) {
  23562. var isRenderable = !!(parameters.data.hasPopup ||
  23563. parameters.data.title || parameters.data.contents);
  23564. AnnotationElement.call(this, parameters, isRenderable);
  23565. }
  23566. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  23567. /**
  23568. * Render the strikeout annotation's HTML element in the empty container.
  23569. *
  23570. * @public
  23571. * @memberof StrikeOutAnnotationElement
  23572. * @returns {HTMLSectionElement}
  23573. */
  23574. render: function StrikeOutAnnotationElement_render() {
  23575. this.container.className = 'strikeoutAnnotation';
  23576. if (!this.data.hasPopup) {
  23577. this._createPopup(this.container, null, this.data);
  23578. }
  23579. return this.container;
  23580. }
  23581. });
  23582. return StrikeOutAnnotationElement;
  23583. })();
  23584. /**
  23585. * @class
  23586. * @alias FileAttachmentAnnotationElement
  23587. */
  23588. var FileAttachmentAnnotationElement = (
  23589. function FileAttachmentAnnotationElementClosure() {
  23590. function FileAttachmentAnnotationElement(parameters) {
  23591. AnnotationElement.call(this, parameters, true);
  23592. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  23593. this.content = parameters.data.file.content;
  23594. }
  23595. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  23596. /**
  23597. * Render the file attachment annotation's HTML element in the empty
  23598. * container.
  23599. *
  23600. * @public
  23601. * @memberof FileAttachmentAnnotationElement
  23602. * @returns {HTMLSectionElement}
  23603. */
  23604. render: function FileAttachmentAnnotationElement_render() {
  23605. this.container.className = 'fileAttachmentAnnotation';
  23606. var trigger = document.createElement('div');
  23607. trigger.style.height = this.container.style.height;
  23608. trigger.style.width = this.container.style.width;
  23609. trigger.addEventListener('dblclick', this._download.bind(this));
  23610. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  23611. this._createPopup(this.container, trigger, this.data);
  23612. }
  23613. this.container.appendChild(trigger);
  23614. return this.container;
  23615. },
  23616. /**
  23617. * Download the file attachment associated with this annotation.
  23618. *
  23619. * @private
  23620. * @memberof FileAttachmentAnnotationElement
  23621. */
  23622. _download: function FileAttachmentAnnotationElement_download() {
  23623. if (!this.downloadManager) {
  23624. warn('Download cannot be started due to unavailable download manager');
  23625. return;
  23626. }
  23627. this.downloadManager.downloadData(this.content, this.filename, '');
  23628. }
  23629. });
  23630. return FileAttachmentAnnotationElement;
  23631. })();
  23632. /**
  23633. * @typedef {Object} AnnotationLayerParameters
  23634. * @property {PageViewport} viewport
  23635. * @property {HTMLDivElement} div
  23636. * @property {Array} annotations
  23637. * @property {PDFPage} page
  23638. * @property {IPDFLinkService} linkService
  23639. * @property {string} imageResourcesPath
  23640. * @property {boolean} renderInteractiveForms
  23641. */
  23642. /**
  23643. * @class
  23644. * @alias AnnotationLayer
  23645. */
  23646. var AnnotationLayer = (function AnnotationLayerClosure() {
  23647. return {
  23648. /**
  23649. * Render a new annotation layer with all annotation elements.
  23650. *
  23651. * @public
  23652. * @param {AnnotationLayerParameters} parameters
  23653. * @memberof AnnotationLayer
  23654. */
  23655. render: function AnnotationLayer_render(parameters) {
  23656. var annotationElementFactory = new AnnotationElementFactory();
  23657. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  23658. var data = parameters.annotations[i];
  23659. if (!data) {
  23660. continue;
  23661. }
  23662. var properties = {
  23663. data: data,
  23664. layer: parameters.div,
  23665. page: parameters.page,
  23666. viewport: parameters.viewport,
  23667. linkService: parameters.linkService,
  23668. downloadManager: parameters.downloadManager,
  23669. imageResourcesPath: parameters.imageResourcesPath ||
  23670. getDefaultSetting('imageResourcesPath'),
  23671. renderInteractiveForms: parameters.renderInteractiveForms || false,
  23672. };
  23673. var element = annotationElementFactory.create(properties);
  23674. if (element.isRenderable) {
  23675. parameters.div.appendChild(element.render());
  23676. }
  23677. }
  23678. },
  23679. /**
  23680. * Update the annotation elements on existing annotation layer.
  23681. *
  23682. * @public
  23683. * @param {AnnotationLayerParameters} parameters
  23684. * @memberof AnnotationLayer
  23685. */
  23686. update: function AnnotationLayer_update(parameters) {
  23687. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  23688. var data = parameters.annotations[i];
  23689. var element = parameters.div.querySelector(
  23690. '[data-annotation-id="' + data.id + '"]');
  23691. if (element) {
  23692. CustomStyle.setProp('transform', element,
  23693. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  23694. }
  23695. }
  23696. parameters.div.removeAttribute('hidden');
  23697. }
  23698. };
  23699. })();
  23700. exports.AnnotationLayer = AnnotationLayer;
  23701. }));
  23702. (function (root, factory) {
  23703. {
  23704. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  23705. root.pdfjsDisplayDOMUtils);
  23706. }
  23707. }(this, function (exports, sharedUtil, displayDOMUtils) {
  23708. var Util = sharedUtil.Util;
  23709. var createPromiseCapability = sharedUtil.createPromiseCapability;
  23710. var CustomStyle = displayDOMUtils.CustomStyle;
  23711. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  23712. /**
  23713. * Text layer render parameters.
  23714. *
  23715. * @typedef {Object} TextLayerRenderParameters
  23716. * @property {TextContent} textContent - Text content to render (the object is
  23717. * returned by the page's getTextContent() method).
  23718. * @property {HTMLElement} container - HTML element that will contain text runs.
  23719. * @property {PageViewport} viewport - The target viewport to properly
  23720. * layout the text runs.
  23721. * @property {Array} textDivs - (optional) HTML elements that are correspond
  23722. * the text items of the textContent input. This is output and shall be
  23723. * initially be set to empty array.
  23724. * @property {number} timeout - (optional) Delay in milliseconds before
  23725. * rendering of the text runs occurs.
  23726. * @property {boolean} enhanceTextSelection - (optional) Whether to turn on the
  23727. * text selection enhancement.
  23728. */
  23729. var renderTextLayer = (function renderTextLayerClosure() {
  23730. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  23731. var NonWhitespaceRegexp = /\S/;
  23732. function isAllWhitespace(str) {
  23733. return !NonWhitespaceRegexp.test(str);
  23734. }
  23735. // Text layers may contain many thousand div's, and using `styleBuf` avoids
  23736. // creating many intermediate strings when building their 'style' properties.
  23737. var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0,
  23738. 'px; font-family: ', '', ';'];
  23739. function appendText(task, geom, styles) {
  23740. // Initialize all used properties to keep the caches monomorphic.
  23741. var textDiv = document.createElement('div');
  23742. var textDivProperties = {
  23743. style: null,
  23744. angle: 0,
  23745. canvasWidth: 0,
  23746. isWhitespace: false,
  23747. originalTransform: null,
  23748. paddingBottom: 0,
  23749. paddingLeft: 0,
  23750. paddingRight: 0,
  23751. paddingTop: 0,
  23752. scale: 1,
  23753. };
  23754. task._textDivs.push(textDiv);
  23755. if (isAllWhitespace(geom.str)) {
  23756. textDivProperties.isWhitespace = true;
  23757. task._textDivProperties.set(textDiv, textDivProperties);
  23758. return;
  23759. }
  23760. var tx = Util.transform(task._viewport.transform, geom.transform);
  23761. var angle = Math.atan2(tx[1], tx[0]);
  23762. var style = styles[geom.fontName];
  23763. if (style.vertical) {
  23764. angle += Math.PI / 2;
  23765. }
  23766. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  23767. var fontAscent = fontHeight;
  23768. if (style.ascent) {
  23769. fontAscent = style.ascent * fontAscent;
  23770. } else if (style.descent) {
  23771. fontAscent = (1 + style.descent) * fontAscent;
  23772. }
  23773. var left;
  23774. var top;
  23775. if (angle === 0) {
  23776. left = tx[4];
  23777. top = tx[5] - fontAscent;
  23778. } else {
  23779. left = tx[4] + (fontAscent * Math.sin(angle));
  23780. top = tx[5] - (fontAscent * Math.cos(angle));
  23781. }
  23782. styleBuf[1] = left;
  23783. styleBuf[3] = top;
  23784. styleBuf[5] = fontHeight;
  23785. styleBuf[7] = style.fontFamily;
  23786. textDivProperties.style = styleBuf.join('');
  23787. textDiv.setAttribute('style', textDivProperties.style);
  23788. textDiv.textContent = geom.str;
  23789. // |fontName| is only used by the Font Inspector. This test will succeed
  23790. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  23791. // not worth the effort to do a more accurate test. We only use `dataset`
  23792. // here to make the font name available for the debugger.
  23793. if (getDefaultSetting('pdfBug')) {
  23794. textDiv.dataset.fontName = geom.fontName;
  23795. }
  23796. if (angle !== 0) {
  23797. textDivProperties.angle = angle * (180 / Math.PI);
  23798. }
  23799. // We don't bother scaling single-char text divs, because it has very
  23800. // little effect on text highlighting. This makes scrolling on docs with
  23801. // lots of such divs a lot faster.
  23802. if (geom.str.length > 1) {
  23803. if (style.vertical) {
  23804. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  23805. } else {
  23806. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  23807. }
  23808. }
  23809. task._textDivProperties.set(textDiv, textDivProperties);
  23810. if (task._enhanceTextSelection) {
  23811. var angleCos = 1, angleSin = 0;
  23812. if (angle !== 0) {
  23813. angleCos = Math.cos(angle);
  23814. angleSin = Math.sin(angle);
  23815. }
  23816. var divWidth = (style.vertical ? geom.height : geom.width) *
  23817. task._viewport.scale;
  23818. var divHeight = fontHeight;
  23819. var m, b;
  23820. if (angle !== 0) {
  23821. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  23822. b = Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  23823. } else {
  23824. b = [left, top, left + divWidth, top + divHeight];
  23825. }
  23826. task._bounds.push({
  23827. left: b[0],
  23828. top: b[1],
  23829. right: b[2],
  23830. bottom: b[3],
  23831. div: textDiv,
  23832. size: [divWidth, divHeight],
  23833. m: m
  23834. });
  23835. }
  23836. }
  23837. function render(task) {
  23838. if (task._canceled) {
  23839. return;
  23840. }
  23841. var textLayerFrag = task._container;
  23842. var textDivs = task._textDivs;
  23843. var capability = task._capability;
  23844. var textDivsLength = textDivs.length;
  23845. // No point in rendering many divs as it would make the browser
  23846. // unusable even after the divs are rendered.
  23847. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  23848. task._renderingDone = true;
  23849. capability.resolve();
  23850. return;
  23851. }
  23852. var canvas = document.createElement('canvas');
  23853. var ctx = canvas.getContext('2d', {alpha: false});
  23854. var lastFontSize;
  23855. var lastFontFamily;
  23856. for (var i = 0; i < textDivsLength; i++) {
  23857. var textDiv = textDivs[i];
  23858. var textDivProperties = task._textDivProperties.get(textDiv);
  23859. if (textDivProperties.isWhitespace) {
  23860. continue;
  23861. }
  23862. var fontSize = textDiv.style.fontSize;
  23863. var fontFamily = textDiv.style.fontFamily;
  23864. // Only build font string and set to context if different from last.
  23865. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  23866. ctx.font = fontSize + ' ' + fontFamily;
  23867. lastFontSize = fontSize;
  23868. lastFontFamily = fontFamily;
  23869. }
  23870. var width = ctx.measureText(textDiv.textContent).width;
  23871. textLayerFrag.appendChild(textDiv);
  23872. var transform = '';
  23873. if (textDivProperties.canvasWidth !== 0 && width > 0) {
  23874. textDivProperties.scale = textDivProperties.canvasWidth / width;
  23875. transform = 'scaleX(' + textDivProperties.scale + ')';
  23876. }
  23877. if (textDivProperties.angle !== 0) {
  23878. transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
  23879. }
  23880. if (transform !== '') {
  23881. textDivProperties.originalTransform = transform;
  23882. CustomStyle.setProp('transform', textDiv, transform);
  23883. }
  23884. task._textDivProperties.set(textDiv, textDivProperties);
  23885. }
  23886. task._renderingDone = true;
  23887. capability.resolve();
  23888. }
  23889. function expand(task) {
  23890. var bounds = task._bounds;
  23891. var viewport = task._viewport;
  23892. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  23893. for (var i = 0; i < expanded.length; i++) {
  23894. var div = bounds[i].div;
  23895. var divProperties = task._textDivProperties.get(div);
  23896. if (divProperties.angle === 0) {
  23897. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  23898. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  23899. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  23900. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  23901. task._textDivProperties.set(div, divProperties);
  23902. continue;
  23903. }
  23904. // Box is rotated -- trying to find padding so rotated div will not
  23905. // exceed its expanded bounds.
  23906. var e = expanded[i], b = bounds[i];
  23907. var m = b.m, c = m[0], s = m[1];
  23908. // Finding intersections with expanded box.
  23909. var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  23910. var ts = new Float64Array(64);
  23911. points.forEach(function (p, i) {
  23912. var t = Util.applyTransform(p, m);
  23913. ts[i + 0] = c && (e.left - t[0]) / c;
  23914. ts[i + 4] = s && (e.top - t[1]) / s;
  23915. ts[i + 8] = c && (e.right - t[0]) / c;
  23916. ts[i + 12] = s && (e.bottom - t[1]) / s;
  23917. ts[i + 16] = s && (e.left - t[0]) / -s;
  23918. ts[i + 20] = c && (e.top - t[1]) / c;
  23919. ts[i + 24] = s && (e.right - t[0]) / -s;
  23920. ts[i + 28] = c && (e.bottom - t[1]) / c;
  23921. ts[i + 32] = c && (e.left - t[0]) / -c;
  23922. ts[i + 36] = s && (e.top - t[1]) / -s;
  23923. ts[i + 40] = c && (e.right - t[0]) / -c;
  23924. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  23925. ts[i + 48] = s && (e.left - t[0]) / s;
  23926. ts[i + 52] = c && (e.top - t[1]) / -c;
  23927. ts[i + 56] = s && (e.right - t[0]) / s;
  23928. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  23929. });
  23930. var findPositiveMin = function (ts, offset, count) {
  23931. var result = 0;
  23932. for (var i = 0; i < count; i++) {
  23933. var t = ts[offset++];
  23934. if (t > 0) {
  23935. result = result ? Math.min(t, result) : t;
  23936. }
  23937. }
  23938. return result;
  23939. };
  23940. // Not based on math, but to simplify calculations, using cos and sin
  23941. // absolute values to not exceed the box (it can but insignificantly).
  23942. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  23943. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  23944. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  23945. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  23946. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  23947. task._textDivProperties.set(div, divProperties);
  23948. }
  23949. }
  23950. function expandBounds(width, height, boxes) {
  23951. var bounds = boxes.map(function (box, i) {
  23952. return {
  23953. x1: box.left,
  23954. y1: box.top,
  23955. x2: box.right,
  23956. y2: box.bottom,
  23957. index: i,
  23958. x1New: undefined,
  23959. x2New: undefined
  23960. };
  23961. });
  23962. expandBoundsLTR(width, bounds);
  23963. var expanded = new Array(boxes.length);
  23964. bounds.forEach(function (b) {
  23965. var i = b.index;
  23966. expanded[i] = {
  23967. left: b.x1New,
  23968. top: 0,
  23969. right: b.x2New,
  23970. bottom: 0
  23971. };
  23972. });
  23973. // Rotating on 90 degrees and extending extended boxes. Reusing the bounds
  23974. // array and objects.
  23975. boxes.map(function (box, i) {
  23976. var e = expanded[i], b = bounds[i];
  23977. b.x1 = box.top;
  23978. b.y1 = width - e.right;
  23979. b.x2 = box.bottom;
  23980. b.y2 = width - e.left;
  23981. b.index = i;
  23982. b.x1New = undefined;
  23983. b.x2New = undefined;
  23984. });
  23985. expandBoundsLTR(height, bounds);
  23986. bounds.forEach(function (b) {
  23987. var i = b.index;
  23988. expanded[i].top = b.x1New;
  23989. expanded[i].bottom = b.x2New;
  23990. });
  23991. return expanded;
  23992. }
  23993. function expandBoundsLTR(width, bounds) {
  23994. // Sorting by x1 coordinate and walk by the bounds in the same order.
  23995. bounds.sort(function (a, b) { return a.x1 - b.x1 || a.index - b.index; });
  23996. // First we see on the horizon is a fake boundary.
  23997. var fakeBoundary = {
  23998. x1: -Infinity,
  23999. y1: -Infinity,
  24000. x2: 0,
  24001. y2: Infinity,
  24002. index: -1,
  24003. x1New: 0,
  24004. x2New: 0
  24005. };
  24006. var horizon = [{
  24007. start: -Infinity,
  24008. end: Infinity,
  24009. boundary: fakeBoundary
  24010. }];
  24011. bounds.forEach(function (boundary) {
  24012. // Searching for the affected part of horizon.
  24013. // TODO red-black tree or simple binary search
  24014. var i = 0;
  24015. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  24016. i++;
  24017. }
  24018. var j = horizon.length - 1;
  24019. while(j >= 0 && horizon[j].start >= boundary.y2) {
  24020. j--;
  24021. }
  24022. var horizonPart, affectedBoundary;
  24023. var q, k, maxXNew = -Infinity;
  24024. for (q = i; q <= j; q++) {
  24025. horizonPart = horizon[q];
  24026. affectedBoundary = horizonPart.boundary;
  24027. var xNew;
  24028. if (affectedBoundary.x2 > boundary.x1) {
  24029. // In the middle of the previous element, new x shall be at the
  24030. // boundary start. Extending if further if the affected bondary
  24031. // placed on top of the current one.
  24032. xNew = affectedBoundary.index > boundary.index ?
  24033. affectedBoundary.x1New : boundary.x1;
  24034. } else if (affectedBoundary.x2New === undefined) {
  24035. // We have some space in between, new x in middle will be a fair
  24036. // choice.
  24037. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  24038. } else {
  24039. // Affected boundary has x2new set, using it as new x.
  24040. xNew = affectedBoundary.x2New;
  24041. }
  24042. if (xNew > maxXNew) {
  24043. maxXNew = xNew;
  24044. }
  24045. }
  24046. // Set new x1 for current boundary.
  24047. boundary.x1New = maxXNew;
  24048. // Adjusts new x2 for the affected boundaries.
  24049. for (q = i; q <= j; q++) {
  24050. horizonPart = horizon[q];
  24051. affectedBoundary = horizonPart.boundary;
  24052. if (affectedBoundary.x2New === undefined) {
  24053. // Was not set yet, choosing new x if possible.
  24054. if (affectedBoundary.x2 > boundary.x1) {
  24055. // Current and affected boundaries intersect. If affected boundary
  24056. // is placed on top of the current, shrinking the affected.
  24057. if (affectedBoundary.index > boundary.index) {
  24058. affectedBoundary.x2New = affectedBoundary.x2;
  24059. }
  24060. } else {
  24061. affectedBoundary.x2New = maxXNew;
  24062. }
  24063. } else if (affectedBoundary.x2New > maxXNew) {
  24064. // Affected boundary is touching new x, pushing it back.
  24065. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  24066. }
  24067. }
  24068. // Fixing the horizon.
  24069. var changedHorizon = [], lastBoundary = null;
  24070. for (q = i; q <= j; q++) {
  24071. horizonPart = horizon[q];
  24072. affectedBoundary = horizonPart.boundary;
  24073. // Checking which boundary will be visible.
  24074. var useBoundary = affectedBoundary.x2 > boundary.x2 ?
  24075. affectedBoundary : boundary;
  24076. if (lastBoundary === useBoundary) {
  24077. // Merging with previous.
  24078. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  24079. } else {
  24080. changedHorizon.push({
  24081. start: horizonPart.start,
  24082. end: horizonPart.end,
  24083. boundary: useBoundary
  24084. });
  24085. lastBoundary = useBoundary;
  24086. }
  24087. }
  24088. if (horizon[i].start < boundary.y1) {
  24089. changedHorizon[0].start = boundary.y1;
  24090. changedHorizon.unshift({
  24091. start: horizon[i].start,
  24092. end: boundary.y1,
  24093. boundary: horizon[i].boundary
  24094. });
  24095. }
  24096. if (boundary.y2 < horizon[j].end) {
  24097. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  24098. changedHorizon.push({
  24099. start: boundary.y2,
  24100. end: horizon[j].end,
  24101. boundary: horizon[j].boundary
  24102. });
  24103. }
  24104. // Set x2 new of boundary that is no longer visible (see overlapping case
  24105. // above).
  24106. // TODO more efficient, e.g. via reference counting.
  24107. for (q = i; q <= j; q++) {
  24108. horizonPart = horizon[q];
  24109. affectedBoundary = horizonPart.boundary;
  24110. if (affectedBoundary.x2New !== undefined) {
  24111. continue;
  24112. }
  24113. var used = false;
  24114. for (k = i - 1; !used && k >= 0 &&
  24115. horizon[k].start >= affectedBoundary.y1; k--) {
  24116. used = horizon[k].boundary === affectedBoundary;
  24117. }
  24118. for (k = j + 1; !used && k < horizon.length &&
  24119. horizon[k].end <= affectedBoundary.y2; k++) {
  24120. used = horizon[k].boundary === affectedBoundary;
  24121. }
  24122. for (k = 0; !used && k < changedHorizon.length; k++) {
  24123. used = changedHorizon[k].boundary === affectedBoundary;
  24124. }
  24125. if (!used) {
  24126. affectedBoundary.x2New = maxXNew;
  24127. }
  24128. }
  24129. Array.prototype.splice.apply(horizon,
  24130. [i, j - i + 1].concat(changedHorizon));
  24131. });
  24132. // Set new x2 for all unset boundaries.
  24133. horizon.forEach(function (horizonPart) {
  24134. var affectedBoundary = horizonPart.boundary;
  24135. if (affectedBoundary.x2New === undefined) {
  24136. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  24137. }
  24138. });
  24139. }
  24140. /**
  24141. * Text layer rendering task.
  24142. *
  24143. * @param {TextContent} textContent
  24144. * @param {HTMLElement} container
  24145. * @param {PageViewport} viewport
  24146. * @param {Array} textDivs
  24147. * @param {boolean} enhanceTextSelection
  24148. * @private
  24149. */
  24150. function TextLayerRenderTask(textContent, container, viewport, textDivs,
  24151. enhanceTextSelection) {
  24152. this._textContent = textContent;
  24153. this._container = container;
  24154. this._viewport = viewport;
  24155. this._textDivs = textDivs || [];
  24156. this._textDivProperties = new WeakMap();
  24157. this._renderingDone = false;
  24158. this._canceled = false;
  24159. this._capability = createPromiseCapability();
  24160. this._renderTimer = null;
  24161. this._bounds = [];
  24162. this._enhanceTextSelection = !!enhanceTextSelection;
  24163. }
  24164. TextLayerRenderTask.prototype = {
  24165. get promise() {
  24166. return this._capability.promise;
  24167. },
  24168. cancel: function TextLayer_cancel() {
  24169. this._canceled = true;
  24170. if (this._renderTimer !== null) {
  24171. clearTimeout(this._renderTimer);
  24172. this._renderTimer = null;
  24173. }
  24174. this._capability.reject('canceled');
  24175. },
  24176. _render: function TextLayer_render(timeout) {
  24177. var textItems = this._textContent.items;
  24178. var textStyles = this._textContent.styles;
  24179. for (var i = 0, len = textItems.length; i < len; i++) {
  24180. appendText(this, textItems[i], textStyles);
  24181. }
  24182. if (!timeout) { // Render right away
  24183. render(this);
  24184. } else { // Schedule
  24185. var self = this;
  24186. this._renderTimer = setTimeout(function() {
  24187. render(self);
  24188. self._renderTimer = null;
  24189. }, timeout);
  24190. }
  24191. },
  24192. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  24193. if (!this._enhanceTextSelection || !this._renderingDone) {
  24194. return;
  24195. }
  24196. if (this._bounds !== null) {
  24197. expand(this);
  24198. this._bounds = null;
  24199. }
  24200. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  24201. var div = this._textDivs[i];
  24202. var divProperties = this._textDivProperties.get(div);
  24203. if (divProperties.isWhitespace) {
  24204. continue;
  24205. }
  24206. if (expandDivs) {
  24207. var transform = '', padding = '';
  24208. if (divProperties.scale !== 1) {
  24209. transform = 'scaleX(' + divProperties.scale + ')';
  24210. }
  24211. if (divProperties.angle !== 0) {
  24212. transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
  24213. }
  24214. if (divProperties.paddingLeft !== 0) {
  24215. padding += ' padding-left: ' +
  24216. (divProperties.paddingLeft / divProperties.scale) + 'px;';
  24217. transform += ' translateX(' +
  24218. (-divProperties.paddingLeft / divProperties.scale) + 'px)';
  24219. }
  24220. if (divProperties.paddingTop !== 0) {
  24221. padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
  24222. transform += ' translateY(' + (-divProperties.paddingTop) + 'px)';
  24223. }
  24224. if (divProperties.paddingRight !== 0) {
  24225. padding += ' padding-right: ' +
  24226. (divProperties.paddingRight / divProperties.scale) + 'px;';
  24227. }
  24228. if (divProperties.paddingBottom !== 0) {
  24229. padding += ' padding-bottom: ' +
  24230. divProperties.paddingBottom + 'px;';
  24231. }
  24232. if (padding !== '') {
  24233. div.setAttribute('style', divProperties.style + padding);
  24234. }
  24235. if (transform !== '') {
  24236. CustomStyle.setProp('transform', div, transform);
  24237. }
  24238. } else {
  24239. div.style.padding = 0;
  24240. CustomStyle.setProp('transform', div,
  24241. divProperties.originalTransform || '');
  24242. }
  24243. }
  24244. },
  24245. };
  24246. /**
  24247. * Starts rendering of the text layer.
  24248. *
  24249. * @param {TextLayerRenderParameters} renderParameters
  24250. * @returns {TextLayerRenderTask}
  24251. */
  24252. function renderTextLayer(renderParameters) {
  24253. var task = new TextLayerRenderTask(renderParameters.textContent,
  24254. renderParameters.container,
  24255. renderParameters.viewport,
  24256. renderParameters.textDivs,
  24257. renderParameters.enhanceTextSelection);
  24258. task._render(renderParameters.timeout);
  24259. return task;
  24260. }
  24261. return renderTextLayer;
  24262. })();
  24263. exports.renderTextLayer = renderTextLayer;
  24264. }));
  24265. (function (root, factory) {
  24266. {
  24267. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil,
  24268. root.pdfjsDisplayDOMUtils);
  24269. }
  24270. }(this, function (exports, sharedUtil, displayDOMUtils) {
  24271. var shadow = sharedUtil.shadow;
  24272. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  24273. var WebGLUtils = (function WebGLUtilsClosure() {
  24274. function loadShader(gl, code, shaderType) {
  24275. var shader = gl.createShader(shaderType);
  24276. gl.shaderSource(shader, code);
  24277. gl.compileShader(shader);
  24278. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  24279. if (!compiled) {
  24280. var errorMsg = gl.getShaderInfoLog(shader);
  24281. throw new Error('Error during shader compilation: ' + errorMsg);
  24282. }
  24283. return shader;
  24284. }
  24285. function createVertexShader(gl, code) {
  24286. return loadShader(gl, code, gl.VERTEX_SHADER);
  24287. }
  24288. function createFragmentShader(gl, code) {
  24289. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  24290. }
  24291. function createProgram(gl, shaders) {
  24292. var program = gl.createProgram();
  24293. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  24294. gl.attachShader(program, shaders[i]);
  24295. }
  24296. gl.linkProgram(program);
  24297. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  24298. if (!linked) {
  24299. var errorMsg = gl.getProgramInfoLog(program);
  24300. throw new Error('Error during program linking: ' + errorMsg);
  24301. }
  24302. return program;
  24303. }
  24304. function createTexture(gl, image, textureId) {
  24305. gl.activeTexture(textureId);
  24306. var texture = gl.createTexture();
  24307. gl.bindTexture(gl.TEXTURE_2D, texture);
  24308. // Set the parameters so we can render any size image.
  24309. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  24310. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  24311. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  24312. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  24313. // Upload the image into the texture.
  24314. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  24315. return texture;
  24316. }
  24317. var currentGL, currentCanvas;
  24318. function generateGL() {
  24319. if (currentGL) {
  24320. return;
  24321. }
  24322. currentCanvas = document.createElement('canvas');
  24323. currentGL = currentCanvas.getContext('webgl',
  24324. { premultipliedalpha: false });
  24325. }
  24326. var smaskVertexShaderCode = '\
  24327. attribute vec2 a_position; \
  24328. attribute vec2 a_texCoord; \
  24329. \
  24330. uniform vec2 u_resolution; \
  24331. \
  24332. varying vec2 v_texCoord; \
  24333. \
  24334. void main() { \
  24335. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  24336. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  24337. \
  24338. v_texCoord = a_texCoord; \
  24339. } ';
  24340. var smaskFragmentShaderCode = '\
  24341. precision mediump float; \
  24342. \
  24343. uniform vec4 u_backdrop; \
  24344. uniform int u_subtype; \
  24345. uniform sampler2D u_image; \
  24346. uniform sampler2D u_mask; \
  24347. \
  24348. varying vec2 v_texCoord; \
  24349. \
  24350. void main() { \
  24351. vec4 imageColor = texture2D(u_image, v_texCoord); \
  24352. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  24353. if (u_backdrop.a > 0.0) { \
  24354. maskColor.rgb = maskColor.rgb * maskColor.a + \
  24355. u_backdrop.rgb * (1.0 - maskColor.a); \
  24356. } \
  24357. float lum; \
  24358. if (u_subtype == 0) { \
  24359. lum = maskColor.a; \
  24360. } else { \
  24361. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  24362. maskColor.b * 0.11; \
  24363. } \
  24364. imageColor.a *= lum; \
  24365. imageColor.rgb *= imageColor.a; \
  24366. gl_FragColor = imageColor; \
  24367. } ';
  24368. var smaskCache = null;
  24369. function initSmaskGL() {
  24370. var canvas, gl;
  24371. generateGL();
  24372. canvas = currentCanvas;
  24373. currentCanvas = null;
  24374. gl = currentGL;
  24375. currentGL = null;
  24376. // setup a GLSL program
  24377. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  24378. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  24379. var program = createProgram(gl, [vertexShader, fragmentShader]);
  24380. gl.useProgram(program);
  24381. var cache = {};
  24382. cache.gl = gl;
  24383. cache.canvas = canvas;
  24384. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  24385. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  24386. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  24387. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  24388. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  24389. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  24390. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  24391. // provide texture coordinates for the rectangle.
  24392. var texCoordBuffer = gl.createBuffer();
  24393. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  24394. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  24395. 0.0, 0.0,
  24396. 1.0, 0.0,
  24397. 0.0, 1.0,
  24398. 0.0, 1.0,
  24399. 1.0, 0.0,
  24400. 1.0, 1.0]), gl.STATIC_DRAW);
  24401. gl.enableVertexAttribArray(texCoordLocation);
  24402. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  24403. gl.uniform1i(texLayerLocation, 0);
  24404. gl.uniform1i(texMaskLocation, 1);
  24405. smaskCache = cache;
  24406. }
  24407. function composeSMask(layer, mask, properties) {
  24408. var width = layer.width, height = layer.height;
  24409. if (!smaskCache) {
  24410. initSmaskGL();
  24411. }
  24412. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  24413. canvas.width = width;
  24414. canvas.height = height;
  24415. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  24416. gl.uniform2f(cache.resolutionLocation, width, height);
  24417. if (properties.backdrop) {
  24418. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  24419. properties.backdrop[1], properties.backdrop[2], 1);
  24420. } else {
  24421. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  24422. }
  24423. gl.uniform1i(cache.subtypeLocation,
  24424. properties.subtype === 'Luminosity' ? 1 : 0);
  24425. // Create a textures
  24426. var texture = createTexture(gl, layer, gl.TEXTURE0);
  24427. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  24428. // Create a buffer and put a single clipspace rectangle in
  24429. // it (2 triangles)
  24430. var buffer = gl.createBuffer();
  24431. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  24432. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  24433. 0, 0,
  24434. width, 0,
  24435. 0, height,
  24436. 0, height,
  24437. width, 0,
  24438. width, height]), gl.STATIC_DRAW);
  24439. gl.enableVertexAttribArray(cache.positionLocation);
  24440. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  24441. // draw
  24442. gl.clearColor(0, 0, 0, 0);
  24443. gl.enable(gl.BLEND);
  24444. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  24445. gl.clear(gl.COLOR_BUFFER_BIT);
  24446. gl.drawArrays(gl.TRIANGLES, 0, 6);
  24447. gl.flush();
  24448. gl.deleteTexture(texture);
  24449. gl.deleteTexture(maskTexture);
  24450. gl.deleteBuffer(buffer);
  24451. return canvas;
  24452. }
  24453. var figuresVertexShaderCode = '\
  24454. attribute vec2 a_position; \
  24455. attribute vec3 a_color; \
  24456. \
  24457. uniform vec2 u_resolution; \
  24458. uniform vec2 u_scale; \
  24459. uniform vec2 u_offset; \
  24460. \
  24461. varying vec4 v_color; \
  24462. \
  24463. void main() { \
  24464. vec2 position = (a_position + u_offset) * u_scale; \
  24465. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  24466. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  24467. \
  24468. v_color = vec4(a_color / 255.0, 1.0); \
  24469. } ';
  24470. var figuresFragmentShaderCode = '\
  24471. precision mediump float; \
  24472. \
  24473. varying vec4 v_color; \
  24474. \
  24475. void main() { \
  24476. gl_FragColor = v_color; \
  24477. } ';
  24478. var figuresCache = null;
  24479. function initFiguresGL() {
  24480. var canvas, gl;
  24481. generateGL();
  24482. canvas = currentCanvas;
  24483. currentCanvas = null;
  24484. gl = currentGL;
  24485. currentGL = null;
  24486. // setup a GLSL program
  24487. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  24488. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  24489. var program = createProgram(gl, [vertexShader, fragmentShader]);
  24490. gl.useProgram(program);
  24491. var cache = {};
  24492. cache.gl = gl;
  24493. cache.canvas = canvas;
  24494. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  24495. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  24496. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  24497. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  24498. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  24499. figuresCache = cache;
  24500. }
  24501. function drawFigures(width, height, backgroundColor, figures, context) {
  24502. if (!figuresCache) {
  24503. initFiguresGL();
  24504. }
  24505. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  24506. canvas.width = width;
  24507. canvas.height = height;
  24508. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  24509. gl.uniform2f(cache.resolutionLocation, width, height);
  24510. // count triangle points
  24511. var count = 0;
  24512. var i, ii, rows;
  24513. for (i = 0, ii = figures.length; i < ii; i++) {
  24514. switch (figures[i].type) {
  24515. case 'lattice':
  24516. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  24517. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  24518. break;
  24519. case 'triangles':
  24520. count += figures[i].coords.length;
  24521. break;
  24522. }
  24523. }
  24524. // transfer data
  24525. var coords = new Float32Array(count * 2);
  24526. var colors = new Uint8Array(count * 3);
  24527. var coordsMap = context.coords, colorsMap = context.colors;
  24528. var pIndex = 0, cIndex = 0;
  24529. for (i = 0, ii = figures.length; i < ii; i++) {
  24530. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  24531. switch (figure.type) {
  24532. case 'lattice':
  24533. var cols = figure.verticesPerRow;
  24534. rows = (ps.length / cols) | 0;
  24535. for (var row = 1; row < rows; row++) {
  24536. var offset = row * cols + 1;
  24537. for (var col = 1; col < cols; col++, offset++) {
  24538. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  24539. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  24540. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  24541. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  24542. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  24543. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  24544. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  24545. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  24546. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  24547. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  24548. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  24549. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  24550. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  24551. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  24552. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  24553. coords[pIndex + 6] = coords[pIndex + 2];
  24554. coords[pIndex + 7] = coords[pIndex + 3];
  24555. coords[pIndex + 8] = coords[pIndex + 4];
  24556. coords[pIndex + 9] = coords[pIndex + 5];
  24557. coords[pIndex + 10] = coordsMap[ps[offset]];
  24558. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  24559. colors[cIndex + 9] = colors[cIndex + 3];
  24560. colors[cIndex + 10] = colors[cIndex + 4];
  24561. colors[cIndex + 11] = colors[cIndex + 5];
  24562. colors[cIndex + 12] = colors[cIndex + 6];
  24563. colors[cIndex + 13] = colors[cIndex + 7];
  24564. colors[cIndex + 14] = colors[cIndex + 8];
  24565. colors[cIndex + 15] = colorsMap[cs[offset]];
  24566. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  24567. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  24568. pIndex += 12;
  24569. cIndex += 18;
  24570. }
  24571. }
  24572. break;
  24573. case 'triangles':
  24574. for (var j = 0, jj = ps.length; j < jj; j++) {
  24575. coords[pIndex] = coordsMap[ps[j]];
  24576. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  24577. colors[cIndex] = colorsMap[cs[j]];
  24578. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  24579. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  24580. pIndex += 2;
  24581. cIndex += 3;
  24582. }
  24583. break;
  24584. }
  24585. }
  24586. // draw
  24587. if (backgroundColor) {
  24588. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  24589. backgroundColor[2] / 255, 1.0);
  24590. } else {
  24591. gl.clearColor(0, 0, 0, 0);
  24592. }
  24593. gl.clear(gl.COLOR_BUFFER_BIT);
  24594. var coordsBuffer = gl.createBuffer();
  24595. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  24596. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  24597. gl.enableVertexAttribArray(cache.positionLocation);
  24598. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  24599. var colorsBuffer = gl.createBuffer();
  24600. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  24601. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  24602. gl.enableVertexAttribArray(cache.colorLocation);
  24603. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  24604. 0, 0);
  24605. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  24606. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  24607. gl.drawArrays(gl.TRIANGLES, 0, count);
  24608. gl.flush();
  24609. gl.deleteBuffer(coordsBuffer);
  24610. gl.deleteBuffer(colorsBuffer);
  24611. return canvas;
  24612. }
  24613. function cleanup() {
  24614. if (smaskCache && smaskCache.canvas) {
  24615. smaskCache.canvas.width = 0;
  24616. smaskCache.canvas.height = 0;
  24617. }
  24618. if (figuresCache && figuresCache.canvas) {
  24619. figuresCache.canvas.width = 0;
  24620. figuresCache.canvas.height = 0;
  24621. }
  24622. smaskCache = null;
  24623. figuresCache = null;
  24624. }
  24625. return {
  24626. get isEnabled() {
  24627. if (getDefaultSetting('disableWebGL')) {
  24628. return false;
  24629. }
  24630. var enabled = false;
  24631. try {
  24632. generateGL();
  24633. enabled = !!currentGL;
  24634. } catch (e) { }
  24635. return shadow(this, 'isEnabled', enabled);
  24636. },
  24637. composeSMask: composeSMask,
  24638. drawFigures: drawFigures,
  24639. clear: cleanup
  24640. };
  24641. })();
  24642. exports.WebGLUtils = WebGLUtils;
  24643. }));
  24644. (function (root, factory) {
  24645. {
  24646. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  24647. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  24648. }
  24649. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  24650. var PasswordException = sharedUtil.PasswordException;
  24651. var PasswordResponses = sharedUtil.PasswordResponses;
  24652. var bytesToString = sharedUtil.bytesToString;
  24653. var error = sharedUtil.error;
  24654. var isInt = sharedUtil.isInt;
  24655. var stringToBytes = sharedUtil.stringToBytes;
  24656. var utf8StringToString = sharedUtil.utf8StringToString;
  24657. var warn = sharedUtil.warn;
  24658. var Name = corePrimitives.Name;
  24659. var isName = corePrimitives.isName;
  24660. var isDict = corePrimitives.isDict;
  24661. var DecryptStream = coreStream.DecryptStream;
  24662. var ARCFourCipher = (function ARCFourCipherClosure() {
  24663. function ARCFourCipher(key) {
  24664. this.a = 0;
  24665. this.b = 0;
  24666. var s = new Uint8Array(256);
  24667. var i, j = 0, tmp, keyLength = key.length;
  24668. for (i = 0; i < 256; ++i) {
  24669. s[i] = i;
  24670. }
  24671. for (i = 0; i < 256; ++i) {
  24672. tmp = s[i];
  24673. j = (j + tmp + key[i % keyLength]) & 0xFF;
  24674. s[i] = s[j];
  24675. s[j] = tmp;
  24676. }
  24677. this.s = s;
  24678. }
  24679. ARCFourCipher.prototype = {
  24680. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  24681. var i, n = data.length, tmp, tmp2;
  24682. var a = this.a, b = this.b, s = this.s;
  24683. var output = new Uint8Array(n);
  24684. for (i = 0; i < n; ++i) {
  24685. a = (a + 1) & 0xFF;
  24686. tmp = s[a];
  24687. b = (b + tmp) & 0xFF;
  24688. tmp2 = s[b];
  24689. s[a] = tmp2;
  24690. s[b] = tmp;
  24691. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  24692. }
  24693. this.a = a;
  24694. this.b = b;
  24695. return output;
  24696. }
  24697. };
  24698. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  24699. return ARCFourCipher;
  24700. })();
  24701. var calculateMD5 = (function calculateMD5Closure() {
  24702. var r = new Uint8Array([
  24703. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  24704. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  24705. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  24706. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  24707. var k = new Int32Array([
  24708. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  24709. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  24710. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  24711. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  24712. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  24713. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  24714. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  24715. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  24716. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  24717. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  24718. -145523070, -1120210379, 718787259, -343485551]);
  24719. function hash(data, offset, length) {
  24720. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  24721. // pre-processing
  24722. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  24723. var padded = new Uint8Array(paddedLength);
  24724. var i, j, n;
  24725. for (i = 0; i < length; ++i) {
  24726. padded[i] = data[offset++];
  24727. }
  24728. padded[i++] = 0x80;
  24729. n = paddedLength - 8;
  24730. while (i < n) {
  24731. padded[i++] = 0;
  24732. }
  24733. padded[i++] = (length << 3) & 0xFF;
  24734. padded[i++] = (length >> 5) & 0xFF;
  24735. padded[i++] = (length >> 13) & 0xFF;
  24736. padded[i++] = (length >> 21) & 0xFF;
  24737. padded[i++] = (length >>> 29) & 0xFF;
  24738. padded[i++] = 0;
  24739. padded[i++] = 0;
  24740. padded[i++] = 0;
  24741. var w = new Int32Array(16);
  24742. for (i = 0; i < paddedLength;) {
  24743. for (j = 0; j < 16; ++j, i += 4) {
  24744. w[j] = (padded[i] | (padded[i + 1] << 8) |
  24745. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  24746. }
  24747. var a = h0, b = h1, c = h2, d = h3, f, g;
  24748. for (j = 0; j < 64; ++j) {
  24749. if (j < 16) {
  24750. f = (b & c) | ((~b) & d);
  24751. g = j;
  24752. } else if (j < 32) {
  24753. f = (d & b) | ((~d) & c);
  24754. g = (5 * j + 1) & 15;
  24755. } else if (j < 48) {
  24756. f = b ^ c ^ d;
  24757. g = (3 * j + 5) & 15;
  24758. } else {
  24759. f = c ^ (b | (~d));
  24760. g = (7 * j) & 15;
  24761. }
  24762. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  24763. d = c;
  24764. c = b;
  24765. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  24766. a = tmp;
  24767. }
  24768. h0 = (h0 + a) | 0;
  24769. h1 = (h1 + b) | 0;
  24770. h2 = (h2 + c) | 0;
  24771. h3 = (h3 + d) | 0;
  24772. }
  24773. return new Uint8Array([
  24774. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  24775. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  24776. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  24777. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  24778. ]);
  24779. }
  24780. return hash;
  24781. })();
  24782. var Word64 = (function Word64Closure() {
  24783. function Word64(highInteger, lowInteger) {
  24784. this.high = highInteger | 0;
  24785. this.low = lowInteger | 0;
  24786. }
  24787. Word64.prototype = {
  24788. and: function Word64_and(word) {
  24789. this.high &= word.high;
  24790. this.low &= word.low;
  24791. },
  24792. xor: function Word64_xor(word) {
  24793. this.high ^= word.high;
  24794. this.low ^= word.low;
  24795. },
  24796. or: function Word64_or(word) {
  24797. this.high |= word.high;
  24798. this.low |= word.low;
  24799. },
  24800. shiftRight: function Word64_shiftRight(places) {
  24801. if (places >= 32) {
  24802. this.low = (this.high >>> (places - 32)) | 0;
  24803. this.high = 0;
  24804. } else {
  24805. this.low = (this.low >>> places) | (this.high << (32 - places));
  24806. this.high = (this.high >>> places) | 0;
  24807. }
  24808. },
  24809. shiftLeft: function Word64_shiftLeft(places) {
  24810. if (places >= 32) {
  24811. this.high = this.low << (places - 32);
  24812. this.low = 0;
  24813. } else {
  24814. this.high = (this.high << places) | (this.low >>> (32 - places));
  24815. this.low = this.low << places;
  24816. }
  24817. },
  24818. rotateRight: function Word64_rotateRight(places) {
  24819. var low, high;
  24820. if (places & 32) {
  24821. high = this.low;
  24822. low = this.high;
  24823. } else {
  24824. low = this.low;
  24825. high = this.high;
  24826. }
  24827. places &= 31;
  24828. this.low = (low >>> places) | (high << (32 - places));
  24829. this.high = (high >>> places) | (low << (32 - places));
  24830. },
  24831. not: function Word64_not() {
  24832. this.high = ~this.high;
  24833. this.low = ~this.low;
  24834. },
  24835. add: function Word64_add(word) {
  24836. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  24837. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  24838. if (lowAdd > 0xFFFFFFFF) {
  24839. highAdd += 1;
  24840. }
  24841. this.low = lowAdd | 0;
  24842. this.high = highAdd | 0;
  24843. },
  24844. copyTo: function Word64_copyTo(bytes, offset) {
  24845. bytes[offset] = (this.high >>> 24) & 0xFF;
  24846. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  24847. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  24848. bytes[offset + 3] = this.high & 0xFF;
  24849. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  24850. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  24851. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  24852. bytes[offset + 7] = this.low & 0xFF;
  24853. },
  24854. assign: function Word64_assign(word) {
  24855. this.high = word.high;
  24856. this.low = word.low;
  24857. }
  24858. };
  24859. return Word64;
  24860. })();
  24861. var calculateSHA256 = (function calculateSHA256Closure() {
  24862. function rotr(x, n) {
  24863. return (x >>> n) | (x << 32 - n);
  24864. }
  24865. function ch(x, y, z) {
  24866. return (x & y) ^ (~x & z);
  24867. }
  24868. function maj(x, y, z) {
  24869. return (x & y) ^ (x & z) ^ (y & z);
  24870. }
  24871. function sigma(x) {
  24872. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  24873. }
  24874. function sigmaPrime(x) {
  24875. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  24876. }
  24877. function littleSigma(x) {
  24878. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  24879. }
  24880. function littleSigmaPrime(x) {
  24881. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  24882. }
  24883. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  24884. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  24885. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  24886. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  24887. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  24888. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  24889. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  24890. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  24891. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  24892. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  24893. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  24894. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  24895. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  24896. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  24897. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  24898. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  24899. function hash(data, offset, length) {
  24900. // initial hash values
  24901. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  24902. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  24903. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  24904. // pre-processing
  24905. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  24906. var padded = new Uint8Array(paddedLength);
  24907. var i, j, n;
  24908. for (i = 0; i < length; ++i) {
  24909. padded[i] = data[offset++];
  24910. }
  24911. padded[i++] = 0x80;
  24912. n = paddedLength - 8;
  24913. while (i < n) {
  24914. padded[i++] = 0;
  24915. }
  24916. padded[i++] = 0;
  24917. padded[i++] = 0;
  24918. padded[i++] = 0;
  24919. padded[i++] = (length >>> 29) & 0xFF;
  24920. padded[i++] = (length >> 21) & 0xFF;
  24921. padded[i++] = (length >> 13) & 0xFF;
  24922. padded[i++] = (length >> 5) & 0xFF;
  24923. padded[i++] = (length << 3) & 0xFF;
  24924. var w = new Uint32Array(64);
  24925. // for each 512 bit block
  24926. for (i = 0; i < paddedLength;) {
  24927. for (j = 0; j < 16; ++j) {
  24928. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  24929. (padded[i + 2] << 8) | (padded[i + 3]));
  24930. i += 4;
  24931. }
  24932. for (j = 16; j < 64; ++j) {
  24933. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  24934. littleSigma(w[j - 15]) + w[j - 16] | 0;
  24935. }
  24936. var a = h0, b = h1, c = h2, d = h3, e = h4,
  24937. f = h5, g = h6, h = h7, t1, t2;
  24938. for (j = 0; j < 64; ++j) {
  24939. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  24940. t2 = sigma(a) + maj(a, b, c);
  24941. h = g;
  24942. g = f;
  24943. f = e;
  24944. e = (d + t1) | 0;
  24945. d = c;
  24946. c = b;
  24947. b = a;
  24948. a = (t1 + t2) | 0;
  24949. }
  24950. h0 = (h0 + a) | 0;
  24951. h1 = (h1 + b) | 0;
  24952. h2 = (h2 + c) | 0;
  24953. h3 = (h3 + d) | 0;
  24954. h4 = (h4 + e) | 0;
  24955. h5 = (h5 + f) | 0;
  24956. h6 = (h6 + g) | 0;
  24957. h7 = (h7 + h) | 0;
  24958. }
  24959. return new Uint8Array([
  24960. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  24961. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  24962. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  24963. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  24964. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  24965. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  24966. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  24967. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  24968. ]);
  24969. }
  24970. return hash;
  24971. })();
  24972. var calculateSHA512 = (function calculateSHA512Closure() {
  24973. function ch(result, x, y, z, tmp) {
  24974. result.assign(x);
  24975. result.and(y);
  24976. tmp.assign(x);
  24977. tmp.not();
  24978. tmp.and(z);
  24979. result.xor(tmp);
  24980. }
  24981. function maj(result, x, y, z, tmp) {
  24982. result.assign(x);
  24983. result.and(y);
  24984. tmp.assign(x);
  24985. tmp.and(z);
  24986. result.xor(tmp);
  24987. tmp.assign(y);
  24988. tmp.and(z);
  24989. result.xor(tmp);
  24990. }
  24991. function sigma(result, x, tmp) {
  24992. result.assign(x);
  24993. result.rotateRight(28);
  24994. tmp.assign(x);
  24995. tmp.rotateRight(34);
  24996. result.xor(tmp);
  24997. tmp.assign(x);
  24998. tmp.rotateRight(39);
  24999. result.xor(tmp);
  25000. }
  25001. function sigmaPrime(result, x, tmp) {
  25002. result.assign(x);
  25003. result.rotateRight(14);
  25004. tmp.assign(x);
  25005. tmp.rotateRight(18);
  25006. result.xor(tmp);
  25007. tmp.assign(x);
  25008. tmp.rotateRight(41);
  25009. result.xor(tmp);
  25010. }
  25011. function littleSigma(result, x, tmp) {
  25012. result.assign(x);
  25013. result.rotateRight(1);
  25014. tmp.assign(x);
  25015. tmp.rotateRight(8);
  25016. result.xor(tmp);
  25017. tmp.assign(x);
  25018. tmp.shiftRight(7);
  25019. result.xor(tmp);
  25020. }
  25021. function littleSigmaPrime(result, x, tmp) {
  25022. result.assign(x);
  25023. result.rotateRight(19);
  25024. tmp.assign(x);
  25025. tmp.rotateRight(61);
  25026. result.xor(tmp);
  25027. tmp.assign(x);
  25028. tmp.shiftRight(6);
  25029. result.xor(tmp);
  25030. }
  25031. var k = [
  25032. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  25033. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  25034. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  25035. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  25036. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  25037. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  25038. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  25039. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  25040. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  25041. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  25042. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  25043. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  25044. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  25045. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  25046. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  25047. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  25048. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  25049. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  25050. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  25051. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  25052. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  25053. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  25054. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  25055. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  25056. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  25057. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  25058. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  25059. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  25060. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  25061. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  25062. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  25063. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  25064. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  25065. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  25066. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  25067. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  25068. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  25069. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  25070. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  25071. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  25072. function hash(data, offset, length, mode384) {
  25073. mode384 = !!mode384;
  25074. // initial hash values
  25075. var h0, h1, h2, h3, h4, h5, h6, h7;
  25076. if (!mode384) {
  25077. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  25078. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  25079. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  25080. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  25081. h4 = new Word64(0x510e527f, 0xade682d1);
  25082. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  25083. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  25084. h7 = new Word64(0x5be0cd19, 0x137e2179);
  25085. }
  25086. else {
  25087. // SHA384 is exactly the same
  25088. // except with different starting values and a trimmed result
  25089. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  25090. h1 = new Word64(0x629a292a, 0x367cd507);
  25091. h2 = new Word64(0x9159015a, 0x3070dd17);
  25092. h3 = new Word64(0x152fecd8, 0xf70e5939);
  25093. h4 = new Word64(0x67332667, 0xffc00b31);
  25094. h5 = new Word64(0x8eb44a87, 0x68581511);
  25095. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  25096. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  25097. }
  25098. // pre-processing
  25099. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  25100. var padded = new Uint8Array(paddedLength);
  25101. var i, j, n;
  25102. for (i = 0; i < length; ++i) {
  25103. padded[i] = data[offset++];
  25104. }
  25105. padded[i++] = 0x80;
  25106. n = paddedLength - 16;
  25107. while (i < n) {
  25108. padded[i++] = 0;
  25109. }
  25110. padded[i++] = 0;
  25111. padded[i++] = 0;
  25112. padded[i++] = 0;
  25113. padded[i++] = 0;
  25114. padded[i++] = 0;
  25115. padded[i++] = 0;
  25116. padded[i++] = 0;
  25117. padded[i++] = 0;
  25118. padded[i++] = 0;
  25119. padded[i++] = 0;
  25120. padded[i++] = 0;
  25121. padded[i++] = (length >>> 29) & 0xFF;
  25122. padded[i++] = (length >> 21) & 0xFF;
  25123. padded[i++] = (length >> 13) & 0xFF;
  25124. padded[i++] = (length >> 5) & 0xFF;
  25125. padded[i++] = (length << 3) & 0xFF;
  25126. var w = new Array(80);
  25127. for (i = 0; i < 80; i++) {
  25128. w[i] = new Word64(0, 0);
  25129. }
  25130. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  25131. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  25132. var g = new Word64(0, 0), h = new Word64(0, 0);
  25133. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  25134. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  25135. // for each 1024 bit block
  25136. for (i = 0; i < paddedLength;) {
  25137. for (j = 0; j < 16; ++j) {
  25138. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  25139. (padded[i + 2] << 8) | (padded[i + 3]);
  25140. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  25141. (padded[i + 6]) << 8 | (padded[i + 7]);
  25142. i += 8;
  25143. }
  25144. for (j = 16; j < 80; ++j) {
  25145. tmp3 = w[j];
  25146. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  25147. tmp3.add(w[j - 7]);
  25148. littleSigma(tmp1, w[j - 15], tmp2);
  25149. tmp3.add(tmp1);
  25150. tmp3.add(w[j - 16]);
  25151. }
  25152. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  25153. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  25154. for (j = 0; j < 80; ++j) {
  25155. t1.assign(h);
  25156. sigmaPrime(tmp1, e, tmp2);
  25157. t1.add(tmp1);
  25158. ch(tmp1, e, f, g, tmp2);
  25159. t1.add(tmp1);
  25160. t1.add(k[j]);
  25161. t1.add(w[j]);
  25162. sigma(t2, a, tmp2);
  25163. maj(tmp1, a, b, c, tmp2);
  25164. t2.add(tmp1);
  25165. tmp3 = h;
  25166. h = g;
  25167. g = f;
  25168. f = e;
  25169. d.add(t1);
  25170. e = d;
  25171. d = c;
  25172. c = b;
  25173. b = a;
  25174. tmp3.assign(t1);
  25175. tmp3.add(t2);
  25176. a = tmp3;
  25177. }
  25178. h0.add(a);
  25179. h1.add(b);
  25180. h2.add(c);
  25181. h3.add(d);
  25182. h4.add(e);
  25183. h5.add(f);
  25184. h6.add(g);
  25185. h7.add(h);
  25186. }
  25187. var result;
  25188. if (!mode384) {
  25189. result = new Uint8Array(64);
  25190. h0.copyTo(result,0);
  25191. h1.copyTo(result,8);
  25192. h2.copyTo(result,16);
  25193. h3.copyTo(result,24);
  25194. h4.copyTo(result,32);
  25195. h5.copyTo(result,40);
  25196. h6.copyTo(result,48);
  25197. h7.copyTo(result,56);
  25198. }
  25199. else {
  25200. result = new Uint8Array(48);
  25201. h0.copyTo(result,0);
  25202. h1.copyTo(result,8);
  25203. h2.copyTo(result,16);
  25204. h3.copyTo(result,24);
  25205. h4.copyTo(result,32);
  25206. h5.copyTo(result,40);
  25207. }
  25208. return result;
  25209. }
  25210. return hash;
  25211. })();
  25212. var calculateSHA384 = (function calculateSHA384Closure() {
  25213. function hash(data, offset, length) {
  25214. return calculateSHA512(data, offset, length, true);
  25215. }
  25216. return hash;
  25217. })();
  25218. var NullCipher = (function NullCipherClosure() {
  25219. function NullCipher() {
  25220. }
  25221. NullCipher.prototype = {
  25222. decryptBlock: function NullCipher_decryptBlock(data) {
  25223. return data;
  25224. }
  25225. };
  25226. return NullCipher;
  25227. })();
  25228. var AES128Cipher = (function AES128CipherClosure() {
  25229. var rcon = new Uint8Array([
  25230. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25231. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25232. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25233. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25234. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  25235. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  25236. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  25237. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  25238. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  25239. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  25240. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  25241. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  25242. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  25243. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  25244. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  25245. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  25246. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  25247. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25248. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25249. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25250. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25251. 0x74, 0xe8, 0xcb, 0x8d]);
  25252. var s = new Uint8Array([
  25253. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  25254. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  25255. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  25256. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  25257. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  25258. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  25259. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  25260. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  25261. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  25262. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  25263. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  25264. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  25265. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  25266. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  25267. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  25268. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  25269. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  25270. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  25271. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  25272. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  25273. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  25274. 0xb0, 0x54, 0xbb, 0x16]);
  25275. var inv_s = new Uint8Array([
  25276. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  25277. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  25278. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  25279. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  25280. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  25281. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  25282. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  25283. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  25284. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  25285. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  25286. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  25287. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  25288. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  25289. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  25290. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  25291. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  25292. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  25293. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  25294. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  25295. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  25296. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  25297. 0x55, 0x21, 0x0c, 0x7d]);
  25298. var mixCol = new Uint8Array(256);
  25299. for (var i = 0; i < 256; i++) {
  25300. if (i < 128) {
  25301. mixCol[i] = i << 1;
  25302. } else {
  25303. mixCol[i] = (i << 1) ^ 0x1b;
  25304. }
  25305. }
  25306. var mix = new Uint32Array([
  25307. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  25308. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  25309. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  25310. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  25311. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  25312. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  25313. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  25314. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  25315. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  25316. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  25317. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  25318. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  25319. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  25320. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  25321. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  25322. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  25323. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  25324. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  25325. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  25326. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  25327. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  25328. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  25329. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  25330. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  25331. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  25332. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  25333. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  25334. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  25335. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  25336. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  25337. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  25338. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  25339. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  25340. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  25341. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  25342. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  25343. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  25344. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  25345. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  25346. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  25347. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  25348. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  25349. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  25350. function expandKey128(cipherKey) {
  25351. var b = 176, result = new Uint8Array(b);
  25352. result.set(cipherKey);
  25353. for (var j = 16, i = 1; j < b; ++i) {
  25354. // RotWord
  25355. var t1 = result[j - 3], t2 = result[j - 2],
  25356. t3 = result[j - 1], t4 = result[j - 4];
  25357. // SubWord
  25358. t1 = s[t1];
  25359. t2 = s[t2];
  25360. t3 = s[t3];
  25361. t4 = s[t4];
  25362. // Rcon
  25363. t1 = t1 ^ rcon[i];
  25364. for (var n = 0; n < 4; ++n) {
  25365. result[j] = (t1 ^= result[j - 16]);
  25366. j++;
  25367. result[j] = (t2 ^= result[j - 16]);
  25368. j++;
  25369. result[j] = (t3 ^= result[j - 16]);
  25370. j++;
  25371. result[j] = (t4 ^= result[j - 16]);
  25372. j++;
  25373. }
  25374. }
  25375. return result;
  25376. }
  25377. function decrypt128(input, key) {
  25378. var state = new Uint8Array(16);
  25379. state.set(input);
  25380. var i, j, k;
  25381. var t, u, v;
  25382. // AddRoundKey
  25383. for (j = 0, k = 160; j < 16; ++j, ++k) {
  25384. state[j] ^= key[k];
  25385. }
  25386. for (i = 9; i >= 1; --i) {
  25387. // InvShiftRows
  25388. t = state[13];
  25389. state[13] = state[9];
  25390. state[9] = state[5];
  25391. state[5] = state[1];
  25392. state[1] = t;
  25393. t = state[14];
  25394. u = state[10];
  25395. state[14] = state[6];
  25396. state[10] = state[2];
  25397. state[6] = t;
  25398. state[2] = u;
  25399. t = state[15];
  25400. u = state[11];
  25401. v = state[7];
  25402. state[15] = state[3];
  25403. state[11] = t;
  25404. state[7] = u;
  25405. state[3] = v;
  25406. // InvSubBytes
  25407. for (j = 0; j < 16; ++j) {
  25408. state[j] = inv_s[state[j]];
  25409. }
  25410. // AddRoundKey
  25411. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25412. state[j] ^= key[k];
  25413. }
  25414. // InvMixColumns
  25415. for (j = 0; j < 16; j += 4) {
  25416. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25417. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25418. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25419. (s3 >>> 24) ^ (s3 << 8));
  25420. state[j] = (t >>> 24) & 0xFF;
  25421. state[j + 1] = (t >> 16) & 0xFF;
  25422. state[j + 2] = (t >> 8) & 0xFF;
  25423. state[j + 3] = t & 0xFF;
  25424. }
  25425. }
  25426. // InvShiftRows
  25427. t = state[13];
  25428. state[13] = state[9];
  25429. state[9] = state[5];
  25430. state[5] = state[1];
  25431. state[1] = t;
  25432. t = state[14];
  25433. u = state[10];
  25434. state[14] = state[6];
  25435. state[10] = state[2];
  25436. state[6] = t;
  25437. state[2] = u;
  25438. t = state[15];
  25439. u = state[11];
  25440. v = state[7];
  25441. state[15] = state[3];
  25442. state[11] = t;
  25443. state[7] = u;
  25444. state[3] = v;
  25445. for (j = 0; j < 16; ++j) {
  25446. // InvSubBytes
  25447. state[j] = inv_s[state[j]];
  25448. // AddRoundKey
  25449. state[j] ^= key[j];
  25450. }
  25451. return state;
  25452. }
  25453. function encrypt128(input, key) {
  25454. var t, u, v, k;
  25455. var state = new Uint8Array(16);
  25456. state.set(input);
  25457. for (j = 0; j < 16; ++j) {
  25458. // AddRoundKey
  25459. state[j] ^= key[j];
  25460. }
  25461. for (i = 1; i < 10; i++) {
  25462. //SubBytes
  25463. for (j = 0; j < 16; ++j) {
  25464. state[j] = s[state[j]];
  25465. }
  25466. //ShiftRows
  25467. v = state[1];
  25468. state[1] = state[5];
  25469. state[5] = state[9];
  25470. state[9] = state[13];
  25471. state[13] = v;
  25472. v = state[2];
  25473. u = state[6];
  25474. state[2] = state[10];
  25475. state[6] = state[14];
  25476. state[10] = v;
  25477. state[14] = u;
  25478. v = state[3];
  25479. u = state[7];
  25480. t = state[11];
  25481. state[3] = state[15];
  25482. state[7] = v;
  25483. state[11] = u;
  25484. state[15] = t;
  25485. //MixColumns
  25486. for (var j = 0; j < 16; j += 4) {
  25487. var s0 = state[j + 0], s1 = state[j + 1];
  25488. var s2 = state[j + 2], s3 = state[j + 3];
  25489. t = s0 ^ s1 ^ s2 ^ s3;
  25490. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25491. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25492. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25493. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25494. }
  25495. //AddRoundKey
  25496. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25497. state[j] ^= key[k];
  25498. }
  25499. }
  25500. //SubBytes
  25501. for (j = 0; j < 16; ++j) {
  25502. state[j] = s[state[j]];
  25503. }
  25504. //ShiftRows
  25505. v = state[1];
  25506. state[1] = state[5];
  25507. state[5] = state[9];
  25508. state[9] = state[13];
  25509. state[13] = v;
  25510. v = state[2];
  25511. u = state[6];
  25512. state[2] = state[10];
  25513. state[6] = state[14];
  25514. state[10] = v;
  25515. state[14] = u;
  25516. v = state[3];
  25517. u = state[7];
  25518. t = state[11];
  25519. state[3] = state[15];
  25520. state[7] = v;
  25521. state[11] = u;
  25522. state[15] = t;
  25523. //AddRoundKey
  25524. for (j = 0, k = 160; j < 16; ++j, ++k) {
  25525. state[j] ^= key[k];
  25526. }
  25527. return state;
  25528. }
  25529. function AES128Cipher(key) {
  25530. this.key = expandKey128(key);
  25531. this.buffer = new Uint8Array(16);
  25532. this.bufferPosition = 0;
  25533. }
  25534. function decryptBlock2(data, finalize) {
  25535. var i, j, ii, sourceLength = data.length,
  25536. buffer = this.buffer, bufferLength = this.bufferPosition,
  25537. result = [], iv = this.iv;
  25538. for (i = 0; i < sourceLength; ++i) {
  25539. buffer[bufferLength] = data[i];
  25540. ++bufferLength;
  25541. if (bufferLength < 16) {
  25542. continue;
  25543. }
  25544. // buffer is full, decrypting
  25545. var plain = decrypt128(buffer, this.key);
  25546. // xor-ing the IV vector to get plain text
  25547. for (j = 0; j < 16; ++j) {
  25548. plain[j] ^= iv[j];
  25549. }
  25550. iv = buffer;
  25551. result.push(plain);
  25552. buffer = new Uint8Array(16);
  25553. bufferLength = 0;
  25554. }
  25555. // saving incomplete buffer
  25556. this.buffer = buffer;
  25557. this.bufferLength = bufferLength;
  25558. this.iv = iv;
  25559. if (result.length === 0) {
  25560. return new Uint8Array([]);
  25561. }
  25562. // combining plain text blocks into one
  25563. var outputLength = 16 * result.length;
  25564. if (finalize) {
  25565. // undo a padding that is described in RFC 2898
  25566. var lastBlock = result[result.length - 1];
  25567. var psLen = lastBlock[15];
  25568. if (psLen <= 16) {
  25569. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  25570. if (lastBlock[i] !== psLen) {
  25571. // Invalid padding, assume that the block has no padding.
  25572. psLen = 0;
  25573. break;
  25574. }
  25575. }
  25576. outputLength -= psLen;
  25577. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  25578. }
  25579. }
  25580. var output = new Uint8Array(outputLength);
  25581. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25582. output.set(result[i], j);
  25583. }
  25584. return output;
  25585. }
  25586. AES128Cipher.prototype = {
  25587. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  25588. var i, sourceLength = data.length;
  25589. var buffer = this.buffer, bufferLength = this.bufferPosition;
  25590. // waiting for IV values -- they are at the start of the stream
  25591. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  25592. buffer[bufferLength] = data[i];
  25593. }
  25594. if (bufferLength < 16) {
  25595. // need more data
  25596. this.bufferLength = bufferLength;
  25597. return new Uint8Array([]);
  25598. }
  25599. this.iv = buffer;
  25600. this.buffer = new Uint8Array(16);
  25601. this.bufferLength = 0;
  25602. // starting decryption
  25603. this.decryptBlock = decryptBlock2;
  25604. return this.decryptBlock(data.subarray(16), finalize);
  25605. },
  25606. encrypt: function AES128Cipher_encrypt(data, iv) {
  25607. var i, j, ii, sourceLength = data.length,
  25608. buffer = this.buffer, bufferLength = this.bufferPosition,
  25609. result = [];
  25610. if (!iv) {
  25611. iv = new Uint8Array(16);
  25612. }
  25613. for (i = 0; i < sourceLength; ++i) {
  25614. buffer[bufferLength] = data[i];
  25615. ++bufferLength;
  25616. if (bufferLength < 16) {
  25617. continue;
  25618. }
  25619. for (j = 0; j < 16; ++j) {
  25620. buffer[j] ^= iv[j];
  25621. }
  25622. // buffer is full, encrypting
  25623. var cipher = encrypt128(buffer, this.key);
  25624. iv = cipher;
  25625. result.push(cipher);
  25626. buffer = new Uint8Array(16);
  25627. bufferLength = 0;
  25628. }
  25629. // saving incomplete buffer
  25630. this.buffer = buffer;
  25631. this.bufferLength = bufferLength;
  25632. this.iv = iv;
  25633. if (result.length === 0) {
  25634. return new Uint8Array([]);
  25635. }
  25636. // combining plain text blocks into one
  25637. var outputLength = 16 * result.length;
  25638. var output = new Uint8Array(outputLength);
  25639. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25640. output.set(result[i], j);
  25641. }
  25642. return output;
  25643. }
  25644. };
  25645. return AES128Cipher;
  25646. })();
  25647. var AES256Cipher = (function AES256CipherClosure() {
  25648. var rcon = new Uint8Array([
  25649. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25650. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25651. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25652. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25653. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  25654. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  25655. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  25656. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  25657. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  25658. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  25659. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  25660. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  25661. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  25662. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  25663. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  25664. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  25665. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  25666. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25667. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25668. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25669. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25670. 0x74, 0xe8, 0xcb, 0x8d]);
  25671. var s = new Uint8Array([
  25672. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  25673. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  25674. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  25675. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  25676. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  25677. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  25678. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  25679. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  25680. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  25681. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  25682. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  25683. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  25684. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  25685. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  25686. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  25687. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  25688. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  25689. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  25690. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  25691. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  25692. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  25693. 0xb0, 0x54, 0xbb, 0x16]);
  25694. var inv_s = new Uint8Array([
  25695. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  25696. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  25697. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  25698. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  25699. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  25700. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  25701. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  25702. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  25703. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  25704. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  25705. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  25706. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  25707. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  25708. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  25709. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  25710. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  25711. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  25712. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  25713. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  25714. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  25715. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  25716. 0x55, 0x21, 0x0c, 0x7d]);
  25717. var mixCol = new Uint8Array(256);
  25718. for (var i = 0; i < 256; i++) {
  25719. if (i < 128) {
  25720. mixCol[i] = i << 1;
  25721. } else {
  25722. mixCol[i] = (i << 1) ^ 0x1b;
  25723. }
  25724. }
  25725. var mix = new Uint32Array([
  25726. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  25727. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  25728. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  25729. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  25730. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  25731. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  25732. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  25733. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  25734. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  25735. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  25736. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  25737. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  25738. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  25739. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  25740. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  25741. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  25742. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  25743. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  25744. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  25745. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  25746. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  25747. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  25748. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  25749. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  25750. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  25751. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  25752. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  25753. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  25754. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  25755. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  25756. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  25757. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  25758. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  25759. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  25760. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  25761. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  25762. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  25763. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  25764. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  25765. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  25766. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  25767. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  25768. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  25769. function expandKey256(cipherKey) {
  25770. var b = 240, result = new Uint8Array(b);
  25771. var r = 1;
  25772. result.set(cipherKey);
  25773. for (var j = 32, i = 1; j < b; ++i) {
  25774. if (j % 32 === 16) {
  25775. t1 = s[t1];
  25776. t2 = s[t2];
  25777. t3 = s[t3];
  25778. t4 = s[t4];
  25779. } else if (j % 32 === 0) {
  25780. // RotWord
  25781. var t1 = result[j - 3], t2 = result[j - 2],
  25782. t3 = result[j - 1], t4 = result[j - 4];
  25783. // SubWord
  25784. t1 = s[t1];
  25785. t2 = s[t2];
  25786. t3 = s[t3];
  25787. t4 = s[t4];
  25788. // Rcon
  25789. t1 = t1 ^ r;
  25790. if ((r <<= 1) >= 256) {
  25791. r = (r ^ 0x1b) & 0xFF;
  25792. }
  25793. }
  25794. for (var n = 0; n < 4; ++n) {
  25795. result[j] = (t1 ^= result[j - 32]);
  25796. j++;
  25797. result[j] = (t2 ^= result[j - 32]);
  25798. j++;
  25799. result[j] = (t3 ^= result[j - 32]);
  25800. j++;
  25801. result[j] = (t4 ^= result[j - 32]);
  25802. j++;
  25803. }
  25804. }
  25805. return result;
  25806. }
  25807. function decrypt256(input, key) {
  25808. var state = new Uint8Array(16);
  25809. state.set(input);
  25810. var i, j, k;
  25811. var t, u, v;
  25812. // AddRoundKey
  25813. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25814. state[j] ^= key[k];
  25815. }
  25816. for (i = 13; i >= 1; --i) {
  25817. // InvShiftRows
  25818. t = state[13];
  25819. state[13] = state[9];
  25820. state[9] = state[5];
  25821. state[5] = state[1];
  25822. state[1] = t;
  25823. t = state[14];
  25824. u = state[10];
  25825. state[14] = state[6];
  25826. state[10] = state[2];
  25827. state[6] = t;
  25828. state[2] = u;
  25829. t = state[15];
  25830. u = state[11];
  25831. v = state[7];
  25832. state[15] = state[3];
  25833. state[11] = t;
  25834. state[7] = u;
  25835. state[3] = v;
  25836. // InvSubBytes
  25837. for (j = 0; j < 16; ++j) {
  25838. state[j] = inv_s[state[j]];
  25839. }
  25840. // AddRoundKey
  25841. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25842. state[j] ^= key[k];
  25843. }
  25844. // InvMixColumns
  25845. for (j = 0; j < 16; j += 4) {
  25846. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25847. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25848. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25849. (s3 >>> 24) ^ (s3 << 8));
  25850. state[j] = (t >>> 24) & 0xFF;
  25851. state[j + 1] = (t >> 16) & 0xFF;
  25852. state[j + 2] = (t >> 8) & 0xFF;
  25853. state[j + 3] = t & 0xFF;
  25854. }
  25855. }
  25856. // InvShiftRows
  25857. t = state[13];
  25858. state[13] = state[9];
  25859. state[9] = state[5];
  25860. state[5] = state[1];
  25861. state[1] = t;
  25862. t = state[14];
  25863. u = state[10];
  25864. state[14] = state[6];
  25865. state[10] = state[2];
  25866. state[6] = t;
  25867. state[2] = u;
  25868. t = state[15];
  25869. u = state[11];
  25870. v = state[7];
  25871. state[15] = state[3];
  25872. state[11] = t;
  25873. state[7] = u;
  25874. state[3] = v;
  25875. for (j = 0; j < 16; ++j) {
  25876. // InvSubBytes
  25877. state[j] = inv_s[state[j]];
  25878. // AddRoundKey
  25879. state[j] ^= key[j];
  25880. }
  25881. return state;
  25882. }
  25883. function encrypt256(input, key) {
  25884. var t, u, v, k;
  25885. var state = new Uint8Array(16);
  25886. state.set(input);
  25887. for (j = 0; j < 16; ++j) {
  25888. // AddRoundKey
  25889. state[j] ^= key[j];
  25890. }
  25891. for (i = 1; i < 14; i++) {
  25892. //SubBytes
  25893. for (j = 0; j < 16; ++j) {
  25894. state[j] = s[state[j]];
  25895. }
  25896. //ShiftRows
  25897. v = state[1];
  25898. state[1] = state[5];
  25899. state[5] = state[9];
  25900. state[9] = state[13];
  25901. state[13] = v;
  25902. v = state[2];
  25903. u = state[6];
  25904. state[2] = state[10];
  25905. state[6] = state[14];
  25906. state[10] = v;
  25907. state[14] = u;
  25908. v = state[3];
  25909. u = state[7];
  25910. t = state[11];
  25911. state[3] = state[15];
  25912. state[7] = v;
  25913. state[11] = u;
  25914. state[15] = t;
  25915. //MixColumns
  25916. for (var j = 0; j < 16; j += 4) {
  25917. var s0 = state[j + 0], s1 = state[j + 1];
  25918. var s2 = state[j + 2], s3 = state[j + 3];
  25919. t = s0 ^ s1 ^ s2 ^ s3;
  25920. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25921. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25922. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25923. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25924. }
  25925. //AddRoundKey
  25926. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25927. state[j] ^= key[k];
  25928. }
  25929. }
  25930. //SubBytes
  25931. for (j = 0; j < 16; ++j) {
  25932. state[j] = s[state[j]];
  25933. }
  25934. //ShiftRows
  25935. v = state[1];
  25936. state[1] = state[5];
  25937. state[5] = state[9];
  25938. state[9] = state[13];
  25939. state[13] = v;
  25940. v = state[2];
  25941. u = state[6];
  25942. state[2] = state[10];
  25943. state[6] = state[14];
  25944. state[10] = v;
  25945. state[14] = u;
  25946. v = state[3];
  25947. u = state[7];
  25948. t = state[11];
  25949. state[3] = state[15];
  25950. state[7] = v;
  25951. state[11] = u;
  25952. state[15] = t;
  25953. //AddRoundKey
  25954. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25955. state[j] ^= key[k];
  25956. }
  25957. return state;
  25958. }
  25959. function AES256Cipher(key) {
  25960. this.key = expandKey256(key);
  25961. this.buffer = new Uint8Array(16);
  25962. this.bufferPosition = 0;
  25963. }
  25964. function decryptBlock2(data, finalize) {
  25965. var i, j, ii, sourceLength = data.length,
  25966. buffer = this.buffer, bufferLength = this.bufferPosition,
  25967. result = [], iv = this.iv;
  25968. for (i = 0; i < sourceLength; ++i) {
  25969. buffer[bufferLength] = data[i];
  25970. ++bufferLength;
  25971. if (bufferLength < 16) {
  25972. continue;
  25973. }
  25974. // buffer is full, decrypting
  25975. var plain = decrypt256(buffer, this.key);
  25976. // xor-ing the IV vector to get plain text
  25977. for (j = 0; j < 16; ++j) {
  25978. plain[j] ^= iv[j];
  25979. }
  25980. iv = buffer;
  25981. result.push(plain);
  25982. buffer = new Uint8Array(16);
  25983. bufferLength = 0;
  25984. }
  25985. // saving incomplete buffer
  25986. this.buffer = buffer;
  25987. this.bufferLength = bufferLength;
  25988. this.iv = iv;
  25989. if (result.length === 0) {
  25990. return new Uint8Array([]);
  25991. }
  25992. // combining plain text blocks into one
  25993. var outputLength = 16 * result.length;
  25994. if (finalize) {
  25995. // undo a padding that is described in RFC 2898
  25996. var lastBlock = result[result.length - 1];
  25997. var psLen = lastBlock[15];
  25998. if (psLen <= 16) {
  25999. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  26000. if (lastBlock[i] !== psLen) {
  26001. // Invalid padding, assume that the block has no padding.
  26002. psLen = 0;
  26003. break;
  26004. }
  26005. }
  26006. outputLength -= psLen;
  26007. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  26008. }
  26009. }
  26010. var output = new Uint8Array(outputLength);
  26011. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  26012. output.set(result[i], j);
  26013. }
  26014. return output;
  26015. }
  26016. AES256Cipher.prototype = {
  26017. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  26018. var i, sourceLength = data.length;
  26019. var buffer = this.buffer, bufferLength = this.bufferPosition;
  26020. // if not supplied an IV wait for IV values
  26021. // they are at the start of the stream
  26022. if (iv) {
  26023. this.iv = iv;
  26024. } else {
  26025. for (i = 0; bufferLength < 16 &&
  26026. i < sourceLength; ++i, ++bufferLength) {
  26027. buffer[bufferLength] = data[i];
  26028. }
  26029. if (bufferLength < 16) {
  26030. //need more data
  26031. this.bufferLength = bufferLength;
  26032. return new Uint8Array([]);
  26033. }
  26034. this.iv = buffer;
  26035. data = data.subarray(16);
  26036. }
  26037. this.buffer = new Uint8Array(16);
  26038. this.bufferLength = 0;
  26039. // starting decryption
  26040. this.decryptBlock = decryptBlock2;
  26041. return this.decryptBlock(data, finalize);
  26042. },
  26043. encrypt: function AES256Cipher_encrypt(data, iv) {
  26044. var i, j, ii, sourceLength = data.length,
  26045. buffer = this.buffer, bufferLength = this.bufferPosition,
  26046. result = [];
  26047. if (!iv) {
  26048. iv = new Uint8Array(16);
  26049. }
  26050. for (i = 0; i < sourceLength; ++i) {
  26051. buffer[bufferLength] = data[i];
  26052. ++bufferLength;
  26053. if (bufferLength < 16) {
  26054. continue;
  26055. }
  26056. for (j = 0; j < 16; ++j) {
  26057. buffer[j] ^= iv[j];
  26058. }
  26059. // buffer is full, encrypting
  26060. var cipher = encrypt256(buffer, this.key);
  26061. this.iv = cipher;
  26062. result.push(cipher);
  26063. buffer = new Uint8Array(16);
  26064. bufferLength = 0;
  26065. }
  26066. // saving incomplete buffer
  26067. this.buffer = buffer;
  26068. this.bufferLength = bufferLength;
  26069. this.iv = iv;
  26070. if (result.length === 0) {
  26071. return new Uint8Array([]);
  26072. }
  26073. // combining plain text blocks into one
  26074. var outputLength = 16 * result.length;
  26075. var output = new Uint8Array(outputLength);
  26076. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  26077. output.set(result[i], j);
  26078. }
  26079. return output;
  26080. }
  26081. };
  26082. return AES256Cipher;
  26083. })();
  26084. var PDF17 = (function PDF17Closure() {
  26085. function compareByteArrays(array1, array2) {
  26086. if (array1.length !== array2.length) {
  26087. return false;
  26088. }
  26089. for (var i = 0; i < array1.length; i++) {
  26090. if (array1[i] !== array2[i]) {
  26091. return false;
  26092. }
  26093. }
  26094. return true;
  26095. }
  26096. function PDF17() {
  26097. }
  26098. PDF17.prototype = {
  26099. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  26100. ownerValidationSalt,
  26101. userBytes,
  26102. ownerPassword) {
  26103. var hashData = new Uint8Array(password.length + 56);
  26104. hashData.set(password, 0);
  26105. hashData.set(ownerValidationSalt, password.length);
  26106. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  26107. var result = calculateSHA256(hashData, 0, hashData.length);
  26108. return compareByteArrays(result, ownerPassword);
  26109. },
  26110. checkUserPassword: function PDF17_checkUserPassword(password,
  26111. userValidationSalt,
  26112. userPassword) {
  26113. var hashData = new Uint8Array(password.length + 8);
  26114. hashData.set(password, 0);
  26115. hashData.set(userValidationSalt, password.length);
  26116. var result = calculateSHA256(hashData, 0, hashData.length);
  26117. return compareByteArrays(result, userPassword);
  26118. },
  26119. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  26120. ownerEncryption) {
  26121. var hashData = new Uint8Array(password.length + 56);
  26122. hashData.set(password, 0);
  26123. hashData.set(ownerKeySalt, password.length);
  26124. hashData.set(userBytes, password.length + ownerKeySalt.length);
  26125. var key = calculateSHA256(hashData, 0, hashData.length);
  26126. var cipher = new AES256Cipher(key);
  26127. return cipher.decryptBlock(ownerEncryption,
  26128. false,
  26129. new Uint8Array(16));
  26130. },
  26131. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  26132. userEncryption) {
  26133. var hashData = new Uint8Array(password.length + 8);
  26134. hashData.set(password, 0);
  26135. hashData.set(userKeySalt, password.length);
  26136. //key is the decryption key for the UE string
  26137. var key = calculateSHA256(hashData, 0, hashData.length);
  26138. var cipher = new AES256Cipher(key);
  26139. return cipher.decryptBlock(userEncryption,
  26140. false,
  26141. new Uint8Array(16));
  26142. }
  26143. };
  26144. return PDF17;
  26145. })();
  26146. var PDF20 = (function PDF20Closure() {
  26147. function concatArrays(array1, array2) {
  26148. var t = new Uint8Array(array1.length + array2.length);
  26149. t.set(array1, 0);
  26150. t.set(array2, array1.length);
  26151. return t;
  26152. }
  26153. function calculatePDF20Hash(password, input, userBytes) {
  26154. //This refers to Algorithm 2.B as defined in ISO 32000-2
  26155. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  26156. var e = [0];
  26157. var i = 0;
  26158. while (i < 64 || e[e.length - 1] > i - 32) {
  26159. var arrayLength = password.length + k.length + userBytes.length;
  26160. var k1 = new Uint8Array(arrayLength * 64);
  26161. var array = concatArrays(password, k);
  26162. array = concatArrays(array, userBytes);
  26163. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  26164. k1.set(array, pos);
  26165. }
  26166. //AES128 CBC NO PADDING with
  26167. //first 16 bytes of k as the key and the second 16 as the iv.
  26168. var cipher = new AES128Cipher(k.subarray(0, 16));
  26169. e = cipher.encrypt(k1, k.subarray(16, 32));
  26170. //Now we have to take the first 16 bytes of an unsigned
  26171. //big endian integer... and compute the remainder
  26172. //modulo 3.... That is a fairly large number and
  26173. //JavaScript isn't going to handle that well...
  26174. //So we're using a trick that allows us to perform
  26175. //modulo math byte by byte
  26176. var remainder = 0;
  26177. for (var z = 0; z < 16; z++) {
  26178. remainder *= (256 % 3);
  26179. remainder %= 3;
  26180. remainder += ((e[z] >>> 0) % 3);
  26181. remainder %= 3;
  26182. }
  26183. if (remainder === 0) {
  26184. k = calculateSHA256(e, 0, e.length);
  26185. }
  26186. else if (remainder === 1) {
  26187. k = calculateSHA384(e, 0, e.length);
  26188. }
  26189. else if (remainder === 2) {
  26190. k = calculateSHA512(e, 0, e.length);
  26191. }
  26192. i++;
  26193. }
  26194. return k.subarray(0, 32);
  26195. }
  26196. function PDF20() {
  26197. }
  26198. function compareByteArrays(array1, array2) {
  26199. if (array1.length !== array2.length) {
  26200. return false;
  26201. }
  26202. for (var i = 0; i < array1.length; i++) {
  26203. if (array1[i] !== array2[i]) {
  26204. return false;
  26205. }
  26206. }
  26207. return true;
  26208. }
  26209. PDF20.prototype = {
  26210. hash: function PDF20_hash(password, concatBytes, userBytes) {
  26211. return calculatePDF20Hash(password, concatBytes, userBytes);
  26212. },
  26213. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  26214. ownerValidationSalt,
  26215. userBytes,
  26216. ownerPassword) {
  26217. var hashData = new Uint8Array(password.length + 56);
  26218. hashData.set(password, 0);
  26219. hashData.set(ownerValidationSalt, password.length);
  26220. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  26221. var result = calculatePDF20Hash(password, hashData, userBytes);
  26222. return compareByteArrays(result, ownerPassword);
  26223. },
  26224. checkUserPassword: function PDF20_checkUserPassword(password,
  26225. userValidationSalt,
  26226. userPassword) {
  26227. var hashData = new Uint8Array(password.length + 8);
  26228. hashData.set(password, 0);
  26229. hashData.set(userValidationSalt, password.length);
  26230. var result = calculatePDF20Hash(password, hashData, []);
  26231. return compareByteArrays(result, userPassword);
  26232. },
  26233. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  26234. ownerEncryption) {
  26235. var hashData = new Uint8Array(password.length + 56);
  26236. hashData.set(password, 0);
  26237. hashData.set(ownerKeySalt, password.length);
  26238. hashData.set(userBytes, password.length + ownerKeySalt.length);
  26239. var key = calculatePDF20Hash(password, hashData, userBytes);
  26240. var cipher = new AES256Cipher(key);
  26241. return cipher.decryptBlock(ownerEncryption,
  26242. false,
  26243. new Uint8Array(16));
  26244. },
  26245. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  26246. userEncryption) {
  26247. var hashData = new Uint8Array(password.length + 8);
  26248. hashData.set(password, 0);
  26249. hashData.set(userKeySalt, password.length);
  26250. //key is the decryption key for the UE string
  26251. var key = calculatePDF20Hash(password, hashData, []);
  26252. var cipher = new AES256Cipher(key);
  26253. return cipher.decryptBlock(userEncryption,
  26254. false,
  26255. new Uint8Array(16));
  26256. }
  26257. };
  26258. return PDF20;
  26259. })();
  26260. var CipherTransform = (function CipherTransformClosure() {
  26261. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  26262. this.stringCipherConstructor = stringCipherConstructor;
  26263. this.streamCipherConstructor = streamCipherConstructor;
  26264. }
  26265. CipherTransform.prototype = {
  26266. createStream: function CipherTransform_createStream(stream, length) {
  26267. var cipher = new this.streamCipherConstructor();
  26268. return new DecryptStream(stream, length,
  26269. function cipherTransformDecryptStream(data, finalize) {
  26270. return cipher.decryptBlock(data, finalize);
  26271. }
  26272. );
  26273. },
  26274. decryptString: function CipherTransform_decryptString(s) {
  26275. var cipher = new this.stringCipherConstructor();
  26276. var data = stringToBytes(s);
  26277. data = cipher.decryptBlock(data, true);
  26278. return bytesToString(data);
  26279. }
  26280. };
  26281. return CipherTransform;
  26282. })();
  26283. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  26284. var defaultPasswordBytes = new Uint8Array([
  26285. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  26286. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  26287. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  26288. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  26289. function createEncryptionKey20(revision, password, ownerPassword,
  26290. ownerValidationSalt, ownerKeySalt, uBytes,
  26291. userPassword, userValidationSalt, userKeySalt,
  26292. ownerEncryption, userEncryption, perms) {
  26293. if (password) {
  26294. var passwordLength = Math.min(127, password.length);
  26295. password = password.subarray(0, passwordLength);
  26296. } else {
  26297. password = [];
  26298. }
  26299. var pdfAlgorithm;
  26300. if (revision === 6) {
  26301. pdfAlgorithm = new PDF20();
  26302. } else {
  26303. pdfAlgorithm = new PDF17();
  26304. }
  26305. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  26306. userPassword)) {
  26307. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  26308. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  26309. ownerValidationSalt,
  26310. uBytes,
  26311. ownerPassword)) {
  26312. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  26313. ownerEncryption);
  26314. }
  26315. return null;
  26316. }
  26317. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  26318. flags, revision, keyLength, encryptMetadata) {
  26319. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  26320. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  26321. if (password) {
  26322. n = Math.min(32, password.length);
  26323. for (; i < n; ++i) {
  26324. hashData[i] = password[i];
  26325. }
  26326. }
  26327. j = 0;
  26328. while (i < 32) {
  26329. hashData[i++] = defaultPasswordBytes[j++];
  26330. }
  26331. // as now the padded password in the hashData[0..i]
  26332. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  26333. hashData[i++] = ownerPassword[j];
  26334. }
  26335. hashData[i++] = flags & 0xFF;
  26336. hashData[i++] = (flags >> 8) & 0xFF;
  26337. hashData[i++] = (flags >> 16) & 0xFF;
  26338. hashData[i++] = (flags >>> 24) & 0xFF;
  26339. for (j = 0, n = fileId.length; j < n; ++j) {
  26340. hashData[i++] = fileId[j];
  26341. }
  26342. if (revision >= 4 && !encryptMetadata) {
  26343. hashData[i++] = 0xFF;
  26344. hashData[i++] = 0xFF;
  26345. hashData[i++] = 0xFF;
  26346. hashData[i++] = 0xFF;
  26347. }
  26348. var hash = calculateMD5(hashData, 0, i);
  26349. var keyLengthInBytes = keyLength >> 3;
  26350. if (revision >= 3) {
  26351. for (j = 0; j < 50; ++j) {
  26352. hash = calculateMD5(hash, 0, keyLengthInBytes);
  26353. }
  26354. }
  26355. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  26356. var cipher, checkData;
  26357. if (revision >= 3) {
  26358. for (i = 0; i < 32; ++i) {
  26359. hashData[i] = defaultPasswordBytes[i];
  26360. }
  26361. for (j = 0, n = fileId.length; j < n; ++j) {
  26362. hashData[i++] = fileId[j];
  26363. }
  26364. cipher = new ARCFourCipher(encryptionKey);
  26365. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  26366. n = encryptionKey.length;
  26367. var derivedKey = new Uint8Array(n), k;
  26368. for (j = 1; j <= 19; ++j) {
  26369. for (k = 0; k < n; ++k) {
  26370. derivedKey[k] = encryptionKey[k] ^ j;
  26371. }
  26372. cipher = new ARCFourCipher(derivedKey);
  26373. checkData = cipher.encryptBlock(checkData);
  26374. }
  26375. for (j = 0, n = checkData.length; j < n; ++j) {
  26376. if (userPassword[j] !== checkData[j]) {
  26377. return null;
  26378. }
  26379. }
  26380. } else {
  26381. cipher = new ARCFourCipher(encryptionKey);
  26382. checkData = cipher.encryptBlock(defaultPasswordBytes);
  26383. for (j = 0, n = checkData.length; j < n; ++j) {
  26384. if (userPassword[j] !== checkData[j]) {
  26385. return null;
  26386. }
  26387. }
  26388. }
  26389. return encryptionKey;
  26390. }
  26391. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  26392. var hashData = new Uint8Array(32), i = 0, j, n;
  26393. n = Math.min(32, password.length);
  26394. for (; i < n; ++i) {
  26395. hashData[i] = password[i];
  26396. }
  26397. j = 0;
  26398. while (i < 32) {
  26399. hashData[i++] = defaultPasswordBytes[j++];
  26400. }
  26401. var hash = calculateMD5(hashData, 0, i);
  26402. var keyLengthInBytes = keyLength >> 3;
  26403. if (revision >= 3) {
  26404. for (j = 0; j < 50; ++j) {
  26405. hash = calculateMD5(hash, 0, hash.length);
  26406. }
  26407. }
  26408. var cipher, userPassword;
  26409. if (revision >= 3) {
  26410. userPassword = ownerPassword;
  26411. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  26412. for (j = 19; j >= 0; j--) {
  26413. for (k = 0; k < keyLengthInBytes; ++k) {
  26414. derivedKey[k] = hash[k] ^ j;
  26415. }
  26416. cipher = new ARCFourCipher(derivedKey);
  26417. userPassword = cipher.encryptBlock(userPassword);
  26418. }
  26419. } else {
  26420. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  26421. userPassword = cipher.encryptBlock(ownerPassword);
  26422. }
  26423. return userPassword;
  26424. }
  26425. var identityName = Name.get('Identity');
  26426. function CipherTransformFactory(dict, fileId, password) {
  26427. var filter = dict.get('Filter');
  26428. if (!isName(filter, 'Standard')) {
  26429. error('unknown encryption method');
  26430. }
  26431. this.dict = dict;
  26432. var algorithm = dict.get('V');
  26433. if (!isInt(algorithm) ||
  26434. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  26435. algorithm !== 5)) {
  26436. error('unsupported encryption algorithm');
  26437. }
  26438. this.algorithm = algorithm;
  26439. var keyLength = dict.get('Length');
  26440. if (!keyLength) {
  26441. // Spec asks to rely on encryption dictionary's Length entry, however
  26442. // some PDFs don't have it. Trying to recover.
  26443. if (algorithm <= 3) {
  26444. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  26445. keyLength = 40;
  26446. } else {
  26447. // Trying to find default handler -- it usually has Length.
  26448. var cfDict = dict.get('CF');
  26449. var streamCryptoName = dict.get('StmF');
  26450. if (isDict(cfDict) && isName(streamCryptoName)) {
  26451. var handlerDict = cfDict.get(streamCryptoName.name);
  26452. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  26453. if (keyLength < 40) {
  26454. // Sometimes it's incorrect value of bits, generators specify bytes.
  26455. keyLength <<= 3;
  26456. }
  26457. }
  26458. }
  26459. }
  26460. if (!isInt(keyLength) ||
  26461. keyLength < 40 || (keyLength % 8) !== 0) {
  26462. error('invalid key length');
  26463. }
  26464. // prepare keys
  26465. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  26466. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  26467. var flags = dict.get('P');
  26468. var revision = dict.get('R');
  26469. // meaningful when V is 4 or 5
  26470. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  26471. dict.get('EncryptMetadata') !== false);
  26472. this.encryptMetadata = encryptMetadata;
  26473. var fileIdBytes = stringToBytes(fileId);
  26474. var passwordBytes;
  26475. if (password) {
  26476. if (revision === 6) {
  26477. try {
  26478. password = utf8StringToString(password);
  26479. } catch (ex) {
  26480. warn('CipherTransformFactory: ' +
  26481. 'Unable to convert UTF8 encoded password.');
  26482. }
  26483. }
  26484. passwordBytes = stringToBytes(password);
  26485. }
  26486. var encryptionKey;
  26487. if (algorithm !== 5) {
  26488. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  26489. ownerPassword, userPassword, flags,
  26490. revision, keyLength, encryptMetadata);
  26491. }
  26492. else {
  26493. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  26494. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  26495. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  26496. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  26497. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  26498. var ownerEncryption = stringToBytes(dict.get('OE'));
  26499. var userEncryption = stringToBytes(dict.get('UE'));
  26500. var perms = stringToBytes(dict.get('Perms'));
  26501. encryptionKey =
  26502. createEncryptionKey20(revision, passwordBytes,
  26503. ownerPassword, ownerValidationSalt,
  26504. ownerKeySalt, uBytes,
  26505. userPassword, userValidationSalt,
  26506. userKeySalt, ownerEncryption,
  26507. userEncryption, perms);
  26508. }
  26509. if (!encryptionKey && !password) {
  26510. throw new PasswordException('No password given',
  26511. PasswordResponses.NEED_PASSWORD);
  26512. } else if (!encryptionKey && password) {
  26513. // Attempting use the password as an owner password
  26514. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  26515. revision, keyLength);
  26516. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  26517. ownerPassword, userPassword, flags,
  26518. revision, keyLength, encryptMetadata);
  26519. }
  26520. if (!encryptionKey) {
  26521. throw new PasswordException('Incorrect Password',
  26522. PasswordResponses.INCORRECT_PASSWORD);
  26523. }
  26524. this.encryptionKey = encryptionKey;
  26525. if (algorithm >= 4) {
  26526. this.cf = dict.get('CF');
  26527. this.stmf = dict.get('StmF') || identityName;
  26528. this.strf = dict.get('StrF') || identityName;
  26529. this.eff = dict.get('EFF') || this.stmf;
  26530. }
  26531. }
  26532. function buildObjectKey(num, gen, encryptionKey, isAes) {
  26533. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  26534. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  26535. key[i] = encryptionKey[i];
  26536. }
  26537. key[i++] = num & 0xFF;
  26538. key[i++] = (num >> 8) & 0xFF;
  26539. key[i++] = (num >> 16) & 0xFF;
  26540. key[i++] = gen & 0xFF;
  26541. key[i++] = (gen >> 8) & 0xFF;
  26542. if (isAes) {
  26543. key[i++] = 0x73;
  26544. key[i++] = 0x41;
  26545. key[i++] = 0x6C;
  26546. key[i++] = 0x54;
  26547. }
  26548. var hash = calculateMD5(key, 0, i);
  26549. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  26550. }
  26551. function buildCipherConstructor(cf, name, num, gen, key) {
  26552. var cryptFilter = cf.get(name.name);
  26553. var cfm;
  26554. if (cryptFilter !== null && cryptFilter !== undefined) {
  26555. cfm = cryptFilter.get('CFM');
  26556. }
  26557. if (!cfm || cfm.name === 'None') {
  26558. return function cipherTransformFactoryBuildCipherConstructorNone() {
  26559. return new NullCipher();
  26560. };
  26561. }
  26562. if ('V2' === cfm.name) {
  26563. return function cipherTransformFactoryBuildCipherConstructorV2() {
  26564. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  26565. };
  26566. }
  26567. if ('AESV2' === cfm.name) {
  26568. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  26569. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  26570. };
  26571. }
  26572. if ('AESV3' === cfm.name) {
  26573. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  26574. return new AES256Cipher(key);
  26575. };
  26576. }
  26577. error('Unknown crypto method');
  26578. }
  26579. CipherTransformFactory.prototype = {
  26580. createCipherTransform:
  26581. function CipherTransformFactory_createCipherTransform(num, gen) {
  26582. if (this.algorithm === 4 || this.algorithm === 5) {
  26583. return new CipherTransform(
  26584. buildCipherConstructor(this.cf, this.stmf,
  26585. num, gen, this.encryptionKey),
  26586. buildCipherConstructor(this.cf, this.strf,
  26587. num, gen, this.encryptionKey));
  26588. }
  26589. // algorithms 1 and 2
  26590. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  26591. var cipherConstructor = function buildCipherCipherConstructor() {
  26592. return new ARCFourCipher(key);
  26593. };
  26594. return new CipherTransform(cipherConstructor, cipherConstructor);
  26595. }
  26596. };
  26597. return CipherTransformFactory;
  26598. })();
  26599. exports.AES128Cipher = AES128Cipher;
  26600. exports.AES256Cipher = AES256Cipher;
  26601. exports.ARCFourCipher = ARCFourCipher;
  26602. exports.CipherTransformFactory = CipherTransformFactory;
  26603. exports.PDF17 = PDF17;
  26604. exports.PDF20 = PDF20;
  26605. exports.calculateMD5 = calculateMD5;
  26606. exports.calculateSHA256 = calculateSHA256;
  26607. exports.calculateSHA384 = calculateSHA384;
  26608. exports.calculateSHA512 = calculateSHA512;
  26609. }));
  26610. (function (root, factory) {
  26611. {
  26612. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  26613. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  26614. root.pdfjsCoreCFFParser);
  26615. }
  26616. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  26617. coreEncodings, coreCFFParser) {
  26618. var Util = sharedUtil.Util;
  26619. var bytesToString = sharedUtil.bytesToString;
  26620. var error = sharedUtil.error;
  26621. var Stream = coreStream.Stream;
  26622. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  26623. var StandardEncoding = coreEncodings.StandardEncoding;
  26624. var CFFParser = coreCFFParser.CFFParser;
  26625. var FontRendererFactory = (function FontRendererFactoryClosure() {
  26626. function getLong(data, offset) {
  26627. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26628. (data[offset + 2] << 8) | data[offset + 3];
  26629. }
  26630. function getUshort(data, offset) {
  26631. return (data[offset] << 8) | data[offset + 1];
  26632. }
  26633. function parseCmap(data, start, end) {
  26634. var offset = (getUshort(data, start + 2) === 1 ?
  26635. getLong(data, start + 8) : getLong(data, start + 16));
  26636. var format = getUshort(data, start + offset);
  26637. var length, ranges, p, i;
  26638. if (format === 4) {
  26639. length = getUshort(data, start + offset + 2);
  26640. var segCount = getUshort(data, start + offset + 6) >> 1;
  26641. p = start + offset + 14;
  26642. ranges = [];
  26643. for (i = 0; i < segCount; i++, p += 2) {
  26644. ranges[i] = {end: getUshort(data, p)};
  26645. }
  26646. p += 2;
  26647. for (i = 0; i < segCount; i++, p += 2) {
  26648. ranges[i].start = getUshort(data, p);
  26649. }
  26650. for (i = 0; i < segCount; i++, p += 2) {
  26651. ranges[i].idDelta = getUshort(data, p);
  26652. }
  26653. for (i = 0; i < segCount; i++, p += 2) {
  26654. var idOffset = getUshort(data, p);
  26655. if (idOffset === 0) {
  26656. continue;
  26657. }
  26658. ranges[i].ids = [];
  26659. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  26660. ranges[i].ids[j] = getUshort(data, p + idOffset);
  26661. idOffset += 2;
  26662. }
  26663. }
  26664. return ranges;
  26665. } else if (format === 12) {
  26666. length = getLong(data, start + offset + 4);
  26667. var groups = getLong(data, start + offset + 12);
  26668. p = start + offset + 16;
  26669. ranges = [];
  26670. for (i = 0; i < groups; i++) {
  26671. ranges.push({
  26672. start: getLong(data, p),
  26673. end: getLong(data, p + 4),
  26674. idDelta: getLong(data, p + 8) - getLong(data, p)
  26675. });
  26676. p += 12;
  26677. }
  26678. return ranges;
  26679. }
  26680. error('not supported cmap: ' + format);
  26681. }
  26682. function parseCff(data, start, end, seacAnalysisEnabled) {
  26683. var properties = {};
  26684. var parser = new CFFParser(new Stream(data, start, end - start),
  26685. properties, seacAnalysisEnabled);
  26686. var cff = parser.parse();
  26687. return {
  26688. glyphs: cff.charStrings.objects,
  26689. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  26690. cff.topDict.privateDict.subrsIndex.objects),
  26691. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  26692. };
  26693. }
  26694. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  26695. var itemSize, itemDecode;
  26696. if (isGlyphLocationsLong) {
  26697. itemSize = 4;
  26698. itemDecode = function fontItemDecodeLong(data, offset) {
  26699. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26700. (data[offset + 2] << 8) | data[offset + 3];
  26701. };
  26702. } else {
  26703. itemSize = 2;
  26704. itemDecode = function fontItemDecode(data, offset) {
  26705. return (data[offset] << 9) | (data[offset + 1] << 1);
  26706. };
  26707. }
  26708. var glyphs = [];
  26709. var startOffset = itemDecode(loca, 0);
  26710. for (var j = itemSize; j < loca.length; j += itemSize) {
  26711. var endOffset = itemDecode(loca, j);
  26712. glyphs.push(glyf.subarray(startOffset, endOffset));
  26713. startOffset = endOffset;
  26714. }
  26715. return glyphs;
  26716. }
  26717. function lookupCmap(ranges, unicode) {
  26718. var code = unicode.charCodeAt(0), gid = 0;
  26719. var l = 0, r = ranges.length - 1;
  26720. while (l < r) {
  26721. var c = (l + r + 1) >> 1;
  26722. if (code < ranges[c].start) {
  26723. r = c - 1;
  26724. } else {
  26725. l = c;
  26726. }
  26727. }
  26728. if (ranges[l].start <= code && code <= ranges[l].end) {
  26729. gid = (ranges[l].idDelta + (ranges[l].ids ?
  26730. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  26731. }
  26732. return {
  26733. charCode: code,
  26734. glyphId: gid,
  26735. };
  26736. }
  26737. function compileGlyf(code, cmds, font) {
  26738. function moveTo(x, y) {
  26739. cmds.push({cmd: 'moveTo', args: [x, y]});
  26740. }
  26741. function lineTo(x, y) {
  26742. cmds.push({cmd: 'lineTo', args: [x, y]});
  26743. }
  26744. function quadraticCurveTo(xa, ya, x, y) {
  26745. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  26746. }
  26747. var i = 0;
  26748. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26749. var flags;
  26750. var x = 0, y = 0;
  26751. i += 10;
  26752. if (numberOfContours < 0) {
  26753. // composite glyph
  26754. do {
  26755. flags = (code[i] << 8) | code[i + 1];
  26756. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  26757. i += 4;
  26758. var arg1, arg2;
  26759. if ((flags & 0x01)) {
  26760. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26761. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  26762. i += 4;
  26763. } else {
  26764. arg1 = code[i++]; arg2 = code[i++];
  26765. }
  26766. if ((flags & 0x02)) {
  26767. x = arg1;
  26768. y = arg2;
  26769. } else {
  26770. x = 0; y = 0; // TODO "they are points" ?
  26771. }
  26772. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  26773. if ((flags & 0x08)) {
  26774. scaleX =
  26775. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26776. i += 2;
  26777. } else if ((flags & 0x40)) {
  26778. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26779. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26780. i += 4;
  26781. } else if ((flags & 0x80)) {
  26782. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26783. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26784. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  26785. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  26786. i += 8;
  26787. }
  26788. var subglyph = font.glyphs[glyphIndex];
  26789. if (subglyph) {
  26790. cmds.push({cmd: 'save'});
  26791. cmds.push({cmd: 'transform',
  26792. args: [scaleX, scale01, scale10, scaleY, x, y]});
  26793. compileGlyf(subglyph, cmds, font);
  26794. cmds.push({cmd: 'restore'});
  26795. }
  26796. } while ((flags & 0x20));
  26797. } else {
  26798. // simple glyph
  26799. var endPtsOfContours = [];
  26800. var j, jj;
  26801. for (j = 0; j < numberOfContours; j++) {
  26802. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  26803. i += 2;
  26804. }
  26805. var instructionLength = (code[i] << 8) | code[i + 1];
  26806. i += 2 + instructionLength; // skipping the instructions
  26807. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  26808. var points = [];
  26809. while (points.length < numberOfPoints) {
  26810. flags = code[i++];
  26811. var repeat = 1;
  26812. if ((flags & 0x08)) {
  26813. repeat += code[i++];
  26814. }
  26815. while (repeat-- > 0) {
  26816. points.push({flags: flags});
  26817. }
  26818. }
  26819. for (j = 0; j < numberOfPoints; j++) {
  26820. switch (points[j].flags & 0x12) {
  26821. case 0x00:
  26822. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26823. i += 2;
  26824. break;
  26825. case 0x02:
  26826. x -= code[i++];
  26827. break;
  26828. case 0x12:
  26829. x += code[i++];
  26830. break;
  26831. }
  26832. points[j].x = x;
  26833. }
  26834. for (j = 0; j < numberOfPoints; j++) {
  26835. switch (points[j].flags & 0x24) {
  26836. case 0x00:
  26837. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26838. i += 2;
  26839. break;
  26840. case 0x04:
  26841. y -= code[i++];
  26842. break;
  26843. case 0x24:
  26844. y += code[i++];
  26845. break;
  26846. }
  26847. points[j].y = y;
  26848. }
  26849. var startPoint = 0;
  26850. for (i = 0; i < numberOfContours; i++) {
  26851. var endPoint = endPtsOfContours[i];
  26852. // contours might have implicit points, which is located in the middle
  26853. // between two neighboring off-curve points
  26854. var contour = points.slice(startPoint, endPoint + 1);
  26855. if ((contour[0].flags & 1)) {
  26856. contour.push(contour[0]); // using start point at the contour end
  26857. } else if ((contour[contour.length - 1].flags & 1)) {
  26858. // first is off-curve point, trying to use one from the end
  26859. contour.unshift(contour[contour.length - 1]);
  26860. } else {
  26861. // start and end are off-curve points, creating implicit one
  26862. var p = {
  26863. flags: 1,
  26864. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  26865. y: (contour[0].y + contour[contour.length - 1].y) / 2
  26866. };
  26867. contour.unshift(p);
  26868. contour.push(p);
  26869. }
  26870. moveTo(contour[0].x, contour[0].y);
  26871. for (j = 1, jj = contour.length; j < jj; j++) {
  26872. if ((contour[j].flags & 1)) {
  26873. lineTo(contour[j].x, contour[j].y);
  26874. } else if ((contour[j + 1].flags & 1)){
  26875. quadraticCurveTo(contour[j].x, contour[j].y,
  26876. contour[j + 1].x, contour[j + 1].y);
  26877. j++;
  26878. } else {
  26879. quadraticCurveTo(contour[j].x, contour[j].y,
  26880. (contour[j].x + contour[j + 1].x) / 2,
  26881. (contour[j].y + contour[j + 1].y) / 2);
  26882. }
  26883. }
  26884. startPoint = endPoint + 1;
  26885. }
  26886. }
  26887. }
  26888. function compileCharString(code, cmds, font) {
  26889. var stack = [];
  26890. var x = 0, y = 0;
  26891. var stems = 0;
  26892. function moveTo(x, y) {
  26893. cmds.push({cmd: 'moveTo', args: [x, y]});
  26894. }
  26895. function lineTo(x, y) {
  26896. cmds.push({cmd: 'lineTo', args: [x, y]});
  26897. }
  26898. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  26899. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  26900. }
  26901. function parse(code) {
  26902. var i = 0;
  26903. while (i < code.length) {
  26904. var stackClean = false;
  26905. var v = code[i++];
  26906. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  26907. switch (v) {
  26908. case 1: // hstem
  26909. stems += stack.length >> 1;
  26910. stackClean = true;
  26911. break;
  26912. case 3: // vstem
  26913. stems += stack.length >> 1;
  26914. stackClean = true;
  26915. break;
  26916. case 4: // vmoveto
  26917. y += stack.pop();
  26918. moveTo(x, y);
  26919. stackClean = true;
  26920. break;
  26921. case 5: // rlineto
  26922. while (stack.length > 0) {
  26923. x += stack.shift();
  26924. y += stack.shift();
  26925. lineTo(x, y);
  26926. }
  26927. break;
  26928. case 6: // hlineto
  26929. while (stack.length > 0) {
  26930. x += stack.shift();
  26931. lineTo(x, y);
  26932. if (stack.length === 0) {
  26933. break;
  26934. }
  26935. y += stack.shift();
  26936. lineTo(x, y);
  26937. }
  26938. break;
  26939. case 7: // vlineto
  26940. while (stack.length > 0) {
  26941. y += stack.shift();
  26942. lineTo(x, y);
  26943. if (stack.length === 0) {
  26944. break;
  26945. }
  26946. x += stack.shift();
  26947. lineTo(x, y);
  26948. }
  26949. break;
  26950. case 8: // rrcurveto
  26951. while (stack.length > 0) {
  26952. xa = x + stack.shift(); ya = y + stack.shift();
  26953. xb = xa + stack.shift(); yb = ya + stack.shift();
  26954. x = xb + stack.shift(); y = yb + stack.shift();
  26955. bezierCurveTo(xa, ya, xb, yb, x, y);
  26956. }
  26957. break;
  26958. case 10: // callsubr
  26959. n = stack.pop() + font.subrsBias;
  26960. subrCode = font.subrs[n];
  26961. if (subrCode) {
  26962. parse(subrCode);
  26963. }
  26964. break;
  26965. case 11: // return
  26966. return;
  26967. case 12:
  26968. v = code[i++];
  26969. switch (v) {
  26970. case 34: // flex
  26971. xa = x + stack.shift();
  26972. xb = xa + stack.shift(); y1 = y + stack.shift();
  26973. x = xb + stack.shift();
  26974. bezierCurveTo(xa, y, xb, y1, x, y1);
  26975. xa = x + stack.shift();
  26976. xb = xa + stack.shift();
  26977. x = xb + stack.shift();
  26978. bezierCurveTo(xa, y1, xb, y, x, y);
  26979. break;
  26980. case 35: // flex
  26981. xa = x + stack.shift(); ya = y + stack.shift();
  26982. xb = xa + stack.shift(); yb = ya + stack.shift();
  26983. x = xb + stack.shift(); y = yb + stack.shift();
  26984. bezierCurveTo(xa, ya, xb, yb, x, y);
  26985. xa = x + stack.shift(); ya = y + stack.shift();
  26986. xb = xa + stack.shift(); yb = ya + stack.shift();
  26987. x = xb + stack.shift(); y = yb + stack.shift();
  26988. bezierCurveTo(xa, ya, xb, yb, x, y);
  26989. stack.pop(); // fd
  26990. break;
  26991. case 36: // hflex1
  26992. xa = x + stack.shift(); y1 = y + stack.shift();
  26993. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  26994. x = xb + stack.shift();
  26995. bezierCurveTo(xa, y1, xb, y2, x, y2);
  26996. xa = x + stack.shift();
  26997. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  26998. x = xb + stack.shift();
  26999. bezierCurveTo(xa, y2, xb, y3, x, y);
  27000. break;
  27001. case 37: // flex1
  27002. var x0 = x, y0 = y;
  27003. xa = x + stack.shift(); ya = y + stack.shift();
  27004. xb = xa + stack.shift(); yb = ya + stack.shift();
  27005. x = xb + stack.shift(); y = yb + stack.shift();
  27006. bezierCurveTo(xa, ya, xb, yb, x, y);
  27007. xa = x + stack.shift(); ya = y + stack.shift();
  27008. xb = xa + stack.shift(); yb = ya + stack.shift();
  27009. x = xb; y = yb;
  27010. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  27011. x += stack.shift();
  27012. } else {
  27013. y += stack.shift();
  27014. }
  27015. bezierCurveTo(xa, ya, xb, yb, x, y);
  27016. break;
  27017. default:
  27018. error('unknown operator: 12 ' + v);
  27019. }
  27020. break;
  27021. case 14: // endchar
  27022. if (stack.length >= 4) {
  27023. var achar = stack.pop();
  27024. var bchar = stack.pop();
  27025. y = stack.pop();
  27026. x = stack.pop();
  27027. cmds.push({cmd: 'save'});
  27028. cmds.push({cmd: 'translate', args: [x, y]});
  27029. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  27030. font.glyphNameMap[StandardEncoding[achar]]));
  27031. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  27032. cmds.push({cmd: 'restore'});
  27033. cmap = lookupCmap(font.cmap, String.fromCharCode(
  27034. font.glyphNameMap[StandardEncoding[bchar]]));
  27035. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  27036. }
  27037. return;
  27038. case 18: // hstemhm
  27039. stems += stack.length >> 1;
  27040. stackClean = true;
  27041. break;
  27042. case 19: // hintmask
  27043. stems += stack.length >> 1;
  27044. i += (stems + 7) >> 3;
  27045. stackClean = true;
  27046. break;
  27047. case 20: // cntrmask
  27048. stems += stack.length >> 1;
  27049. i += (stems + 7) >> 3;
  27050. stackClean = true;
  27051. break;
  27052. case 21: // rmoveto
  27053. y += stack.pop();
  27054. x += stack.pop();
  27055. moveTo(x, y);
  27056. stackClean = true;
  27057. break;
  27058. case 22: // hmoveto
  27059. x += stack.pop();
  27060. moveTo(x, y);
  27061. stackClean = true;
  27062. break;
  27063. case 23: // vstemhm
  27064. stems += stack.length >> 1;
  27065. stackClean = true;
  27066. break;
  27067. case 24: // rcurveline
  27068. while (stack.length > 2) {
  27069. xa = x + stack.shift(); ya = y + stack.shift();
  27070. xb = xa + stack.shift(); yb = ya + stack.shift();
  27071. x = xb + stack.shift(); y = yb + stack.shift();
  27072. bezierCurveTo(xa, ya, xb, yb, x, y);
  27073. }
  27074. x += stack.shift();
  27075. y += stack.shift();
  27076. lineTo(x, y);
  27077. break;
  27078. case 25: // rlinecurve
  27079. while (stack.length > 6) {
  27080. x += stack.shift();
  27081. y += stack.shift();
  27082. lineTo(x, y);
  27083. }
  27084. xa = x + stack.shift(); ya = y + stack.shift();
  27085. xb = xa + stack.shift(); yb = ya + stack.shift();
  27086. x = xb + stack.shift(); y = yb + stack.shift();
  27087. bezierCurveTo(xa, ya, xb, yb, x, y);
  27088. break;
  27089. case 26: // vvcurveto
  27090. if (stack.length % 2) {
  27091. x += stack.shift();
  27092. }
  27093. while (stack.length > 0) {
  27094. xa = x; ya = y + stack.shift();
  27095. xb = xa + stack.shift(); yb = ya + stack.shift();
  27096. x = xb; y = yb + stack.shift();
  27097. bezierCurveTo(xa, ya, xb, yb, x, y);
  27098. }
  27099. break;
  27100. case 27: // hhcurveto
  27101. if (stack.length % 2) {
  27102. y += stack.shift();
  27103. }
  27104. while (stack.length > 0) {
  27105. xa = x + stack.shift(); ya = y;
  27106. xb = xa + stack.shift(); yb = ya + stack.shift();
  27107. x = xb + stack.shift(); y = yb;
  27108. bezierCurveTo(xa, ya, xb, yb, x, y);
  27109. }
  27110. break;
  27111. case 28:
  27112. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  27113. i += 2;
  27114. break;
  27115. case 29: // callgsubr
  27116. n = stack.pop() + font.gsubrsBias;
  27117. subrCode = font.gsubrs[n];
  27118. if (subrCode) {
  27119. parse(subrCode);
  27120. }
  27121. break;
  27122. case 30: // vhcurveto
  27123. while (stack.length > 0) {
  27124. xa = x; ya = y + stack.shift();
  27125. xb = xa + stack.shift(); yb = ya + stack.shift();
  27126. x = xb + stack.shift();
  27127. y = yb + (stack.length === 1 ? stack.shift() : 0);
  27128. bezierCurveTo(xa, ya, xb, yb, x, y);
  27129. if (stack.length === 0) {
  27130. break;
  27131. }
  27132. xa = x + stack.shift(); ya = y;
  27133. xb = xa + stack.shift(); yb = ya + stack.shift();
  27134. y = yb + stack.shift();
  27135. x = xb + (stack.length === 1 ? stack.shift() : 0);
  27136. bezierCurveTo(xa, ya, xb, yb, x, y);
  27137. }
  27138. break;
  27139. case 31: // hvcurveto
  27140. while (stack.length > 0) {
  27141. xa = x + stack.shift(); ya = y;
  27142. xb = xa + stack.shift(); yb = ya + stack.shift();
  27143. y = yb + stack.shift();
  27144. x = xb + (stack.length === 1 ? stack.shift() : 0);
  27145. bezierCurveTo(xa, ya, xb, yb, x, y);
  27146. if (stack.length === 0) {
  27147. break;
  27148. }
  27149. xa = x; ya = y + stack.shift();
  27150. xb = xa + stack.shift(); yb = ya + stack.shift();
  27151. x = xb + stack.shift();
  27152. y = yb + (stack.length === 1 ? stack.shift() : 0);
  27153. bezierCurveTo(xa, ya, xb, yb, x, y);
  27154. }
  27155. break;
  27156. default:
  27157. if (v < 32) {
  27158. error('unknown operator: ' + v);
  27159. }
  27160. if (v < 247) {
  27161. stack.push(v - 139);
  27162. } else if (v < 251) {
  27163. stack.push((v - 247) * 256 + code[i++] + 108);
  27164. } else if (v < 255) {
  27165. stack.push(-(v - 251) * 256 - code[i++] - 108);
  27166. } else {
  27167. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  27168. (code[i + 2] << 8) | code[i + 3]) / 65536);
  27169. i += 4;
  27170. }
  27171. break;
  27172. }
  27173. if (stackClean) {
  27174. stack.length = 0;
  27175. }
  27176. }
  27177. }
  27178. parse(code);
  27179. }
  27180. var noop = '';
  27181. function CompiledFont(fontMatrix) {
  27182. this.compiledGlyphs = Object.create(null);
  27183. this.compiledCharCodeToGlyphId = Object.create(null);
  27184. this.fontMatrix = fontMatrix;
  27185. }
  27186. CompiledFont.prototype = {
  27187. getPathJs: function (unicode) {
  27188. var cmap = lookupCmap(this.cmap, unicode);
  27189. var fn = this.compiledGlyphs[cmap.glyphId];
  27190. if (!fn) {
  27191. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  27192. this.compiledGlyphs[cmap.glyphId] = fn;
  27193. }
  27194. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  27195. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  27196. }
  27197. return fn;
  27198. },
  27199. compileGlyph: function (code) {
  27200. if (!code || code.length === 0 || code[0] === 14) {
  27201. return noop;
  27202. }
  27203. var cmds = [];
  27204. cmds.push({cmd: 'save'});
  27205. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  27206. cmds.push({cmd: 'scale', args: ['size', '-size']});
  27207. this.compileGlyphImpl(code, cmds);
  27208. cmds.push({cmd: 'restore'});
  27209. return cmds;
  27210. },
  27211. compileGlyphImpl: function () {
  27212. error('Children classes should implement this.');
  27213. },
  27214. hasBuiltPath: function (unicode) {
  27215. var cmap = lookupCmap(this.cmap, unicode);
  27216. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  27217. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  27218. }
  27219. };
  27220. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  27221. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  27222. CompiledFont.call(this, fontMatrix);
  27223. this.glyphs = glyphs;
  27224. this.cmap = cmap;
  27225. }
  27226. Util.inherit(TrueTypeCompiled, CompiledFont, {
  27227. compileGlyphImpl: function (code, cmds) {
  27228. compileGlyf(code, cmds, this);
  27229. }
  27230. });
  27231. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  27232. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  27233. CompiledFont.call(this, fontMatrix);
  27234. this.glyphs = cffInfo.glyphs;
  27235. this.gsubrs = cffInfo.gsubrs || [];
  27236. this.subrs = cffInfo.subrs || [];
  27237. this.cmap = cmap;
  27238. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  27239. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  27240. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  27241. this.subrsBias = (this.subrs.length < 1240 ?
  27242. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  27243. }
  27244. Util.inherit(Type2Compiled, CompiledFont, {
  27245. compileGlyphImpl: function (code, cmds) {
  27246. compileCharString(code, cmds, this);
  27247. }
  27248. });
  27249. return {
  27250. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  27251. var data = new Uint8Array(font.data);
  27252. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  27253. var numTables = getUshort(data, 4);
  27254. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  27255. var tag = bytesToString(data.subarray(p, p + 4));
  27256. var offset = getLong(data, p + 8);
  27257. var length = getLong(data, p + 12);
  27258. switch (tag) {
  27259. case 'cmap':
  27260. cmap = parseCmap(data, offset, offset + length);
  27261. break;
  27262. case 'glyf':
  27263. glyf = data.subarray(offset, offset + length);
  27264. break;
  27265. case 'loca':
  27266. loca = data.subarray(offset, offset + length);
  27267. break;
  27268. case 'head':
  27269. unitsPerEm = getUshort(data, offset + 18);
  27270. indexToLocFormat = getUshort(data, offset + 50);
  27271. break;
  27272. case 'CFF ':
  27273. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  27274. break;
  27275. }
  27276. }
  27277. if (glyf) {
  27278. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  27279. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  27280. return new TrueTypeCompiled(
  27281. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  27282. } else {
  27283. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  27284. }
  27285. }
  27286. };
  27287. })();
  27288. exports.FontRendererFactory = FontRendererFactory;
  27289. }));
  27290. (function (root, factory) {
  27291. {
  27292. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  27293. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  27294. }
  27295. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  27296. var MissingDataException = sharedUtil.MissingDataException;
  27297. var StreamType = sharedUtil.StreamType;
  27298. var assert = sharedUtil.assert;
  27299. var error = sharedUtil.error;
  27300. var info = sharedUtil.info;
  27301. var isArray = sharedUtil.isArray;
  27302. var isInt = sharedUtil.isInt;
  27303. var isNum = sharedUtil.isNum;
  27304. var isString = sharedUtil.isString;
  27305. var warn = sharedUtil.warn;
  27306. var Cmd = corePrimitives.Cmd;
  27307. var Dict = corePrimitives.Dict;
  27308. var Name = corePrimitives.Name;
  27309. var Ref = corePrimitives.Ref;
  27310. var isCmd = corePrimitives.isCmd;
  27311. var isDict = corePrimitives.isDict;
  27312. var isName = corePrimitives.isName;
  27313. var Ascii85Stream = coreStream.Ascii85Stream;
  27314. var AsciiHexStream = coreStream.AsciiHexStream;
  27315. var CCITTFaxStream = coreStream.CCITTFaxStream;
  27316. var FlateStream = coreStream.FlateStream;
  27317. var Jbig2Stream = coreStream.Jbig2Stream;
  27318. var JpegStream = coreStream.JpegStream;
  27319. var JpxStream = coreStream.JpxStream;
  27320. var LZWStream = coreStream.LZWStream;
  27321. var NullStream = coreStream.NullStream;
  27322. var PredictorStream = coreStream.PredictorStream;
  27323. var RunLengthStream = coreStream.RunLengthStream;
  27324. var EOF = {};
  27325. function isEOF(v) {
  27326. return (v === EOF);
  27327. }
  27328. var MAX_LENGTH_TO_CACHE = 1000;
  27329. var Parser = (function ParserClosure() {
  27330. function Parser(lexer, allowStreams, xref, recoveryMode) {
  27331. this.lexer = lexer;
  27332. this.allowStreams = allowStreams;
  27333. this.xref = xref;
  27334. this.recoveryMode = recoveryMode || false;
  27335. this.imageCache = Object.create(null);
  27336. this.refill();
  27337. }
  27338. Parser.prototype = {
  27339. refill: function Parser_refill() {
  27340. this.buf1 = this.lexer.getObj();
  27341. this.buf2 = this.lexer.getObj();
  27342. },
  27343. shift: function Parser_shift() {
  27344. if (isCmd(this.buf2, 'ID')) {
  27345. this.buf1 = this.buf2;
  27346. this.buf2 = null;
  27347. } else {
  27348. this.buf1 = this.buf2;
  27349. this.buf2 = this.lexer.getObj();
  27350. }
  27351. },
  27352. tryShift: function Parser_tryShift() {
  27353. try {
  27354. this.shift();
  27355. return true;
  27356. } catch (e) {
  27357. if (e instanceof MissingDataException) {
  27358. throw e;
  27359. }
  27360. // Upon failure, the caller should reset this.lexer.pos to a known good
  27361. // state and call this.shift() twice to reset the buffers.
  27362. return false;
  27363. }
  27364. },
  27365. getObj: function Parser_getObj(cipherTransform) {
  27366. var buf1 = this.buf1;
  27367. this.shift();
  27368. if (buf1 instanceof Cmd) {
  27369. switch (buf1.cmd) {
  27370. case 'BI': // inline image
  27371. return this.makeInlineImage(cipherTransform);
  27372. case '[': // array
  27373. var array = [];
  27374. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  27375. array.push(this.getObj(cipherTransform));
  27376. }
  27377. if (isEOF(this.buf1)) {
  27378. if (!this.recoveryMode) {
  27379. error('End of file inside array');
  27380. }
  27381. return array;
  27382. }
  27383. this.shift();
  27384. return array;
  27385. case '<<': // dictionary or stream
  27386. var dict = new Dict(this.xref);
  27387. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  27388. if (!isName(this.buf1)) {
  27389. info('Malformed dictionary: key must be a name object');
  27390. this.shift();
  27391. continue;
  27392. }
  27393. var key = this.buf1.name;
  27394. this.shift();
  27395. if (isEOF(this.buf1)) {
  27396. break;
  27397. }
  27398. dict.set(key, this.getObj(cipherTransform));
  27399. }
  27400. if (isEOF(this.buf1)) {
  27401. if (!this.recoveryMode) {
  27402. error('End of file inside dictionary');
  27403. }
  27404. return dict;
  27405. }
  27406. // Stream objects are not allowed inside content streams or
  27407. // object streams.
  27408. if (isCmd(this.buf2, 'stream')) {
  27409. return (this.allowStreams ?
  27410. this.makeStream(dict, cipherTransform) : dict);
  27411. }
  27412. this.shift();
  27413. return dict;
  27414. default: // simple object
  27415. return buf1;
  27416. }
  27417. }
  27418. if (isInt(buf1)) { // indirect reference or integer
  27419. var num = buf1;
  27420. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  27421. var ref = new Ref(num, this.buf1);
  27422. this.shift();
  27423. this.shift();
  27424. return ref;
  27425. }
  27426. return num;
  27427. }
  27428. if (isString(buf1)) { // string
  27429. var str = buf1;
  27430. if (cipherTransform) {
  27431. str = cipherTransform.decryptString(str);
  27432. }
  27433. return str;
  27434. }
  27435. // simple object
  27436. return buf1;
  27437. },
  27438. /**
  27439. * Find the end of the stream by searching for the /EI\s/.
  27440. * @returns {number} The inline stream length.
  27441. */
  27442. findDefaultInlineStreamEnd:
  27443. function Parser_findDefaultInlineStreamEnd(stream) {
  27444. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  27445. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  27446. while ((ch = stream.getByte()) !== -1) {
  27447. if (state === 0) {
  27448. state = (ch === E) ? 1 : 0;
  27449. } else if (state === 1) {
  27450. state = (ch === I) ? 2 : 0;
  27451. } else {
  27452. assert(state === 2);
  27453. if (ch === SPACE || ch === LF || ch === CR) {
  27454. // Let's check the next five bytes are ASCII... just be sure.
  27455. n = 5;
  27456. followingBytes = stream.peekBytes(n);
  27457. for (i = 0; i < n; i++) {
  27458. ch = followingBytes[i];
  27459. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  27460. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  27461. // it's binary stuff. Resetting the state.
  27462. state = 0;
  27463. break;
  27464. }
  27465. }
  27466. if (state === 2) {
  27467. break; // Finished!
  27468. }
  27469. } else {
  27470. state = 0;
  27471. }
  27472. }
  27473. }
  27474. return ((stream.pos - 4) - startPos);
  27475. },
  27476. /**
  27477. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  27478. * @returns {number} The inline stream length.
  27479. */
  27480. findDCTDecodeInlineStreamEnd:
  27481. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  27482. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  27483. while ((b = stream.getByte()) !== -1) {
  27484. if (b !== 0xFF) { // Not a valid marker.
  27485. continue;
  27486. }
  27487. switch (stream.getByte()) {
  27488. case 0x00: // Byte stuffing.
  27489. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  27490. break;
  27491. case 0xFF: // Fill byte.
  27492. // Avoid skipping a valid marker, resetting the stream position.
  27493. stream.skip(-1);
  27494. break;
  27495. case 0xD9: // EOI
  27496. foundEOI = true;
  27497. break;
  27498. case 0xC0: // SOF0
  27499. case 0xC1: // SOF1
  27500. case 0xC2: // SOF2
  27501. case 0xC3: // SOF3
  27502. case 0xC5: // SOF5
  27503. case 0xC6: // SOF6
  27504. case 0xC7: // SOF7
  27505. case 0xC9: // SOF9
  27506. case 0xCA: // SOF10
  27507. case 0xCB: // SOF11
  27508. case 0xCD: // SOF13
  27509. case 0xCE: // SOF14
  27510. case 0xCF: // SOF15
  27511. case 0xC4: // DHT
  27512. case 0xCC: // DAC
  27513. case 0xDA: // SOS
  27514. case 0xDB: // DQT
  27515. case 0xDC: // DNL
  27516. case 0xDD: // DRI
  27517. case 0xDE: // DHP
  27518. case 0xDF: // EXP
  27519. case 0xE0: // APP0
  27520. case 0xE1: // APP1
  27521. case 0xE2: // APP2
  27522. case 0xE3: // APP3
  27523. case 0xE4: // APP4
  27524. case 0xE5: // APP5
  27525. case 0xE6: // APP6
  27526. case 0xE7: // APP7
  27527. case 0xE8: // APP8
  27528. case 0xE9: // APP9
  27529. case 0xEA: // APP10
  27530. case 0xEB: // APP11
  27531. case 0xEC: // APP12
  27532. case 0xED: // APP13
  27533. case 0xEE: // APP14
  27534. case 0xEF: // APP15
  27535. case 0xFE: // COM
  27536. // The marker should be followed by the length of the segment.
  27537. markerLength = stream.getUint16();
  27538. if (markerLength > 2) {
  27539. // |markerLength| contains the byte length of the marker segment,
  27540. // including its own length (2 bytes) and excluding the marker.
  27541. stream.skip(markerLength - 2); // Jump to the next marker.
  27542. } else {
  27543. // The marker length is invalid, resetting the stream position.
  27544. stream.skip(-2);
  27545. }
  27546. break;
  27547. }
  27548. if (foundEOI) {
  27549. break;
  27550. }
  27551. }
  27552. length = stream.pos - startPos;
  27553. if (b === -1) {
  27554. warn('Inline DCTDecode image stream: ' +
  27555. 'EOI marker not found, searching for /EI/ instead.');
  27556. stream.skip(-length); // Reset the stream position.
  27557. return this.findDefaultInlineStreamEnd(stream);
  27558. }
  27559. this.inlineStreamSkipEI(stream);
  27560. return length;
  27561. },
  27562. /**
  27563. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  27564. * @returns {number} The inline stream length.
  27565. */
  27566. findASCII85DecodeInlineStreamEnd:
  27567. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  27568. var TILDE = 0x7E, GT = 0x3E;
  27569. var startPos = stream.pos, ch, length;
  27570. while ((ch = stream.getByte()) !== -1) {
  27571. if (ch === TILDE && stream.peekByte() === GT) {
  27572. stream.skip();
  27573. break;
  27574. }
  27575. }
  27576. length = stream.pos - startPos;
  27577. if (ch === -1) {
  27578. warn('Inline ASCII85Decode image stream: ' +
  27579. 'EOD marker not found, searching for /EI/ instead.');
  27580. stream.skip(-length); // Reset the stream position.
  27581. return this.findDefaultInlineStreamEnd(stream);
  27582. }
  27583. this.inlineStreamSkipEI(stream);
  27584. return length;
  27585. },
  27586. /**
  27587. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  27588. * @returns {number} The inline stream length.
  27589. */
  27590. findASCIIHexDecodeInlineStreamEnd:
  27591. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  27592. var GT = 0x3E;
  27593. var startPos = stream.pos, ch, length;
  27594. while ((ch = stream.getByte()) !== -1) {
  27595. if (ch === GT) {
  27596. break;
  27597. }
  27598. }
  27599. length = stream.pos - startPos;
  27600. if (ch === -1) {
  27601. warn('Inline ASCIIHexDecode image stream: ' +
  27602. 'EOD marker not found, searching for /EI/ instead.');
  27603. stream.skip(-length); // Reset the stream position.
  27604. return this.findDefaultInlineStreamEnd(stream);
  27605. }
  27606. this.inlineStreamSkipEI(stream);
  27607. return length;
  27608. },
  27609. /**
  27610. * Skip over the /EI/ for streams where we search for an EOD marker.
  27611. */
  27612. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  27613. var E = 0x45, I = 0x49;
  27614. var state = 0, ch;
  27615. while ((ch = stream.getByte()) !== -1) {
  27616. if (state === 0) {
  27617. state = (ch === E) ? 1 : 0;
  27618. } else if (state === 1) {
  27619. state = (ch === I) ? 2 : 0;
  27620. } else if (state === 2) {
  27621. break;
  27622. }
  27623. }
  27624. },
  27625. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  27626. var lexer = this.lexer;
  27627. var stream = lexer.stream;
  27628. // Parse dictionary.
  27629. var dict = new Dict(this.xref);
  27630. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  27631. if (!isName(this.buf1)) {
  27632. error('Dictionary key must be a name object');
  27633. }
  27634. var key = this.buf1.name;
  27635. this.shift();
  27636. if (isEOF(this.buf1)) {
  27637. break;
  27638. }
  27639. dict.set(key, this.getObj(cipherTransform));
  27640. }
  27641. // Extract the name of the first (i.e. the current) image filter.
  27642. var filter = dict.get('Filter', 'F'), filterName;
  27643. if (isName(filter)) {
  27644. filterName = filter.name;
  27645. } else if (isArray(filter) && isName(filter[0])) {
  27646. filterName = filter[0].name;
  27647. }
  27648. // Parse image stream.
  27649. var startPos = stream.pos, length, i, ii;
  27650. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  27651. length = this.findDCTDecodeInlineStreamEnd(stream);
  27652. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  27653. length = this.findASCII85DecodeInlineStreamEnd(stream);
  27654. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  27655. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  27656. } else {
  27657. length = this.findDefaultInlineStreamEnd(stream);
  27658. }
  27659. var imageStream = stream.makeSubStream(startPos, length, dict);
  27660. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  27661. // adler32 checksum.
  27662. var adler32;
  27663. if (length < MAX_LENGTH_TO_CACHE) {
  27664. var imageBytes = imageStream.getBytes();
  27665. imageStream.reset();
  27666. var a = 1;
  27667. var b = 0;
  27668. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  27669. // No modulo required in the loop if imageBytes.length < 5552.
  27670. a += imageBytes[i] & 0xff;
  27671. b += a;
  27672. }
  27673. adler32 = ((b % 65521) << 16) | (a % 65521);
  27674. if (this.imageCache.adler32 === adler32) {
  27675. this.buf2 = Cmd.get('EI');
  27676. this.shift();
  27677. this.imageCache[adler32].reset();
  27678. return this.imageCache[adler32];
  27679. }
  27680. }
  27681. if (cipherTransform) {
  27682. imageStream = cipherTransform.createStream(imageStream, length);
  27683. }
  27684. imageStream = this.filter(imageStream, dict, length);
  27685. imageStream.dict = dict;
  27686. if (adler32 !== undefined) {
  27687. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  27688. this.imageCache[adler32] = imageStream;
  27689. }
  27690. this.buf2 = Cmd.get('EI');
  27691. this.shift();
  27692. return imageStream;
  27693. },
  27694. makeStream: function Parser_makeStream(dict, cipherTransform) {
  27695. var lexer = this.lexer;
  27696. var stream = lexer.stream;
  27697. // get stream start position
  27698. lexer.skipToNextLine();
  27699. var pos = stream.pos - 1;
  27700. // get length
  27701. var length = dict.get('Length');
  27702. if (!isInt(length)) {
  27703. info('Bad ' + length + ' attribute in stream');
  27704. length = 0;
  27705. }
  27706. // skip over the stream data
  27707. stream.pos = pos + length;
  27708. lexer.nextChar();
  27709. // Shift '>>' and check whether the new object marks the end of the stream
  27710. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  27711. this.shift(); // 'stream'
  27712. } else {
  27713. // bad stream length, scanning for endstream
  27714. stream.pos = pos;
  27715. var SCAN_BLOCK_SIZE = 2048;
  27716. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  27717. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  27718. 0x61, 0x6D];
  27719. var skipped = 0, found = false, i, j;
  27720. while (stream.pos < stream.end) {
  27721. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  27722. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  27723. if (scanLength <= 0) {
  27724. break;
  27725. }
  27726. found = false;
  27727. i = 0;
  27728. while (i < scanLength) {
  27729. j = 0;
  27730. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  27731. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  27732. j++;
  27733. }
  27734. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  27735. found = true;
  27736. break;
  27737. }
  27738. i++;
  27739. }
  27740. if (found) {
  27741. skipped += i;
  27742. stream.pos += i;
  27743. break;
  27744. }
  27745. skipped += scanLength;
  27746. stream.pos += scanLength;
  27747. }
  27748. if (!found) {
  27749. error('Missing endstream');
  27750. }
  27751. length = skipped;
  27752. lexer.nextChar();
  27753. this.shift();
  27754. this.shift();
  27755. }
  27756. this.shift(); // 'endstream'
  27757. stream = stream.makeSubStream(pos, length, dict);
  27758. if (cipherTransform) {
  27759. stream = cipherTransform.createStream(stream, length);
  27760. }
  27761. stream = this.filter(stream, dict, length);
  27762. stream.dict = dict;
  27763. return stream;
  27764. },
  27765. filter: function Parser_filter(stream, dict, length) {
  27766. var filter = dict.get('Filter', 'F');
  27767. var params = dict.get('DecodeParms', 'DP');
  27768. if (isName(filter)) {
  27769. return this.makeFilter(stream, filter.name, length, params);
  27770. }
  27771. var maybeLength = length;
  27772. if (isArray(filter)) {
  27773. var filterArray = filter;
  27774. var paramsArray = params;
  27775. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  27776. filter = filterArray[i];
  27777. if (!isName(filter)) {
  27778. error('Bad filter name: ' + filter);
  27779. }
  27780. params = null;
  27781. if (isArray(paramsArray) && (i in paramsArray)) {
  27782. params = paramsArray[i];
  27783. }
  27784. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  27785. // after the first stream the length variable is invalid
  27786. maybeLength = null;
  27787. }
  27788. }
  27789. return stream;
  27790. },
  27791. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  27792. if (stream.dict.get('Length') === 0 && !maybeLength) {
  27793. warn('Empty "' + name + '" stream.');
  27794. return new NullStream(stream);
  27795. }
  27796. try {
  27797. if (params && this.xref) {
  27798. params = this.xref.fetchIfRef(params);
  27799. }
  27800. var xrefStreamStats = this.xref.stats.streamTypes;
  27801. if (name === 'FlateDecode' || name === 'Fl') {
  27802. xrefStreamStats[StreamType.FLATE] = true;
  27803. if (params) {
  27804. return new PredictorStream(new FlateStream(stream, maybeLength),
  27805. maybeLength, params);
  27806. }
  27807. return new FlateStream(stream, maybeLength);
  27808. }
  27809. if (name === 'LZWDecode' || name === 'LZW') {
  27810. xrefStreamStats[StreamType.LZW] = true;
  27811. var earlyChange = 1;
  27812. if (params) {
  27813. if (params.has('EarlyChange')) {
  27814. earlyChange = params.get('EarlyChange');
  27815. }
  27816. return new PredictorStream(
  27817. new LZWStream(stream, maybeLength, earlyChange),
  27818. maybeLength, params);
  27819. }
  27820. return new LZWStream(stream, maybeLength, earlyChange);
  27821. }
  27822. if (name === 'DCTDecode' || name === 'DCT') {
  27823. xrefStreamStats[StreamType.DCT] = true;
  27824. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  27825. }
  27826. if (name === 'JPXDecode' || name === 'JPX') {
  27827. xrefStreamStats[StreamType.JPX] = true;
  27828. return new JpxStream(stream, maybeLength, stream.dict);
  27829. }
  27830. if (name === 'ASCII85Decode' || name === 'A85') {
  27831. xrefStreamStats[StreamType.A85] = true;
  27832. return new Ascii85Stream(stream, maybeLength);
  27833. }
  27834. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  27835. xrefStreamStats[StreamType.AHX] = true;
  27836. return new AsciiHexStream(stream, maybeLength);
  27837. }
  27838. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  27839. xrefStreamStats[StreamType.CCF] = true;
  27840. return new CCITTFaxStream(stream, maybeLength, params);
  27841. }
  27842. if (name === 'RunLengthDecode' || name === 'RL') {
  27843. xrefStreamStats[StreamType.RL] = true;
  27844. return new RunLengthStream(stream, maybeLength);
  27845. }
  27846. if (name === 'JBIG2Decode') {
  27847. xrefStreamStats[StreamType.JBIG] = true;
  27848. return new Jbig2Stream(stream, maybeLength, stream.dict);
  27849. }
  27850. warn('filter "' + name + '" not supported yet');
  27851. return stream;
  27852. } catch (ex) {
  27853. if (ex instanceof MissingDataException) {
  27854. throw ex;
  27855. }
  27856. warn('Invalid stream: \"' + ex + '\"');
  27857. return new NullStream(stream);
  27858. }
  27859. }
  27860. };
  27861. return Parser;
  27862. })();
  27863. var Lexer = (function LexerClosure() {
  27864. function Lexer(stream, knownCommands) {
  27865. this.stream = stream;
  27866. this.nextChar();
  27867. // While lexing, we build up many strings one char at a time. Using += for
  27868. // this can result in lots of garbage strings. It's better to build an
  27869. // array of single-char strings and then join() them together at the end.
  27870. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  27871. // purpose uses less memory than using a new array for each string.
  27872. this.strBuf = [];
  27873. // The PDFs might have "glued" commands with other commands, operands or
  27874. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  27875. // commands and their prefixes. The prefixes are built the following way:
  27876. // if there a command that is a prefix of the other valid command or
  27877. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  27878. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  27879. // other commands or literals as a prefix. The knowCommands is optional.
  27880. this.knownCommands = knownCommands;
  27881. }
  27882. // A '1' in this array means the character is white space. A '1' or
  27883. // '2' means the character ends a name or command.
  27884. var specialChars = [
  27885. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  27886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  27887. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  27888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  27889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  27890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  27891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  27892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  27893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  27894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  27895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  27896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  27897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  27898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  27899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  27900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  27901. ];
  27902. function toHexDigit(ch) {
  27903. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  27904. return ch & 0x0F;
  27905. }
  27906. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  27907. // 'A'-'F', 'a'-'f'
  27908. return (ch & 0x0F) + 9;
  27909. }
  27910. return -1;
  27911. }
  27912. Lexer.prototype = {
  27913. nextChar: function Lexer_nextChar() {
  27914. return (this.currentChar = this.stream.getByte());
  27915. },
  27916. peekChar: function Lexer_peekChar() {
  27917. return this.stream.peekByte();
  27918. },
  27919. getNumber: function Lexer_getNumber() {
  27920. var ch = this.currentChar;
  27921. var eNotation = false;
  27922. var divideBy = 0; // different from 0 if it's a floating point value
  27923. var sign = 1;
  27924. if (ch === 0x2D) { // '-'
  27925. sign = -1;
  27926. ch = this.nextChar();
  27927. if (ch === 0x2D) { // '-'
  27928. // Ignore double negative (this is consistent with Adobe Reader).
  27929. ch = this.nextChar();
  27930. }
  27931. } else if (ch === 0x2B) { // '+'
  27932. ch = this.nextChar();
  27933. }
  27934. if (ch === 0x2E) { // '.'
  27935. divideBy = 10;
  27936. ch = this.nextChar();
  27937. }
  27938. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27939. error('Invalid number: ' + String.fromCharCode(ch));
  27940. return 0;
  27941. }
  27942. var baseValue = ch - 0x30; // '0'
  27943. var powerValue = 0;
  27944. var powerValueSign = 1;
  27945. while ((ch = this.nextChar()) >= 0) {
  27946. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  27947. var currentDigit = ch - 0x30; // '0'
  27948. if (eNotation) { // We are after an 'e' or 'E'
  27949. powerValue = powerValue * 10 + currentDigit;
  27950. } else {
  27951. if (divideBy !== 0) { // We are after a point
  27952. divideBy *= 10;
  27953. }
  27954. baseValue = baseValue * 10 + currentDigit;
  27955. }
  27956. } else if (ch === 0x2E) { // '.'
  27957. if (divideBy === 0) {
  27958. divideBy = 1;
  27959. } else {
  27960. // A number can have only one '.'
  27961. break;
  27962. }
  27963. } else if (ch === 0x2D) { // '-'
  27964. // ignore minus signs in the middle of numbers to match
  27965. // Adobe's behavior
  27966. warn('Badly formatted number');
  27967. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  27968. // 'E' can be either a scientific notation or the beginning of a new
  27969. // operator
  27970. ch = this.peekChar();
  27971. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  27972. powerValueSign = (ch === 0x2D) ? -1 : 1;
  27973. this.nextChar(); // Consume the sign character
  27974. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27975. // The 'E' must be the beginning of a new operator
  27976. break;
  27977. }
  27978. eNotation = true;
  27979. } else {
  27980. // the last character doesn't belong to us
  27981. break;
  27982. }
  27983. }
  27984. if (divideBy !== 0) {
  27985. baseValue /= divideBy;
  27986. }
  27987. if (eNotation) {
  27988. baseValue *= Math.pow(10, powerValueSign * powerValue);
  27989. }
  27990. return sign * baseValue;
  27991. },
  27992. getString: function Lexer_getString() {
  27993. var numParen = 1;
  27994. var done = false;
  27995. var strBuf = this.strBuf;
  27996. strBuf.length = 0;
  27997. var ch = this.nextChar();
  27998. while (true) {
  27999. var charBuffered = false;
  28000. switch (ch | 0) {
  28001. case -1:
  28002. warn('Unterminated string');
  28003. done = true;
  28004. break;
  28005. case 0x28: // '('
  28006. ++numParen;
  28007. strBuf.push('(');
  28008. break;
  28009. case 0x29: // ')'
  28010. if (--numParen === 0) {
  28011. this.nextChar(); // consume strings ')'
  28012. done = true;
  28013. } else {
  28014. strBuf.push(')');
  28015. }
  28016. break;
  28017. case 0x5C: // '\\'
  28018. ch = this.nextChar();
  28019. switch (ch) {
  28020. case -1:
  28021. warn('Unterminated string');
  28022. done = true;
  28023. break;
  28024. case 0x6E: // 'n'
  28025. strBuf.push('\n');
  28026. break;
  28027. case 0x72: // 'r'
  28028. strBuf.push('\r');
  28029. break;
  28030. case 0x74: // 't'
  28031. strBuf.push('\t');
  28032. break;
  28033. case 0x62: // 'b'
  28034. strBuf.push('\b');
  28035. break;
  28036. case 0x66: // 'f'
  28037. strBuf.push('\f');
  28038. break;
  28039. case 0x5C: // '\'
  28040. case 0x28: // '('
  28041. case 0x29: // ')'
  28042. strBuf.push(String.fromCharCode(ch));
  28043. break;
  28044. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28045. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28046. var x = ch & 0x0F;
  28047. ch = this.nextChar();
  28048. charBuffered = true;
  28049. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28050. x = (x << 3) + (ch & 0x0F);
  28051. ch = this.nextChar();
  28052. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28053. charBuffered = false;
  28054. x = (x << 3) + (ch & 0x0F);
  28055. }
  28056. }
  28057. strBuf.push(String.fromCharCode(x));
  28058. break;
  28059. case 0x0D: // CR
  28060. if (this.peekChar() === 0x0A) { // LF
  28061. this.nextChar();
  28062. }
  28063. break;
  28064. case 0x0A: // LF
  28065. break;
  28066. default:
  28067. strBuf.push(String.fromCharCode(ch));
  28068. break;
  28069. }
  28070. break;
  28071. default:
  28072. strBuf.push(String.fromCharCode(ch));
  28073. break;
  28074. }
  28075. if (done) {
  28076. break;
  28077. }
  28078. if (!charBuffered) {
  28079. ch = this.nextChar();
  28080. }
  28081. }
  28082. return strBuf.join('');
  28083. },
  28084. getName: function Lexer_getName() {
  28085. var ch, previousCh;
  28086. var strBuf = this.strBuf;
  28087. strBuf.length = 0;
  28088. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28089. if (ch === 0x23) { // '#'
  28090. ch = this.nextChar();
  28091. if (specialChars[ch]) {
  28092. warn('Lexer_getName: ' +
  28093. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  28094. strBuf.push('#');
  28095. break;
  28096. }
  28097. var x = toHexDigit(ch);
  28098. if (x !== -1) {
  28099. previousCh = ch;
  28100. ch = this.nextChar();
  28101. var x2 = toHexDigit(ch);
  28102. if (x2 === -1) {
  28103. warn('Lexer_getName: Illegal digit (' +
  28104. String.fromCharCode(ch) +') in hexadecimal number.');
  28105. strBuf.push('#', String.fromCharCode(previousCh));
  28106. if (specialChars[ch]) {
  28107. break;
  28108. }
  28109. strBuf.push(String.fromCharCode(ch));
  28110. continue;
  28111. }
  28112. strBuf.push(String.fromCharCode((x << 4) | x2));
  28113. } else {
  28114. strBuf.push('#', String.fromCharCode(ch));
  28115. }
  28116. } else {
  28117. strBuf.push(String.fromCharCode(ch));
  28118. }
  28119. }
  28120. if (strBuf.length > 127) {
  28121. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  28122. }
  28123. return Name.get(strBuf.join(''));
  28124. },
  28125. getHexString: function Lexer_getHexString() {
  28126. var strBuf = this.strBuf;
  28127. strBuf.length = 0;
  28128. var ch = this.currentChar;
  28129. var isFirstHex = true;
  28130. var firstDigit;
  28131. var secondDigit;
  28132. while (true) {
  28133. if (ch < 0) {
  28134. warn('Unterminated hex string');
  28135. break;
  28136. } else if (ch === 0x3E) { // '>'
  28137. this.nextChar();
  28138. break;
  28139. } else if (specialChars[ch] === 1) {
  28140. ch = this.nextChar();
  28141. continue;
  28142. } else {
  28143. if (isFirstHex) {
  28144. firstDigit = toHexDigit(ch);
  28145. if (firstDigit === -1) {
  28146. warn('Ignoring invalid character "' + ch + '" in hex string');
  28147. ch = this.nextChar();
  28148. continue;
  28149. }
  28150. } else {
  28151. secondDigit = toHexDigit(ch);
  28152. if (secondDigit === -1) {
  28153. warn('Ignoring invalid character "' + ch + '" in hex string');
  28154. ch = this.nextChar();
  28155. continue;
  28156. }
  28157. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28158. }
  28159. isFirstHex = !isFirstHex;
  28160. ch = this.nextChar();
  28161. }
  28162. }
  28163. return strBuf.join('');
  28164. },
  28165. getObj: function Lexer_getObj() {
  28166. // skip whitespace and comments
  28167. var comment = false;
  28168. var ch = this.currentChar;
  28169. while (true) {
  28170. if (ch < 0) {
  28171. return EOF;
  28172. }
  28173. if (comment) {
  28174. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28175. comment = false;
  28176. }
  28177. } else if (ch === 0x25) { // '%'
  28178. comment = true;
  28179. } else if (specialChars[ch] !== 1) {
  28180. break;
  28181. }
  28182. ch = this.nextChar();
  28183. }
  28184. // start reading token
  28185. switch (ch | 0) {
  28186. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28187. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28188. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28189. return this.getNumber();
  28190. case 0x28: // '('
  28191. return this.getString();
  28192. case 0x2F: // '/'
  28193. return this.getName();
  28194. // array punctuation
  28195. case 0x5B: // '['
  28196. this.nextChar();
  28197. return Cmd.get('[');
  28198. case 0x5D: // ']'
  28199. this.nextChar();
  28200. return Cmd.get(']');
  28201. // hex string or dict punctuation
  28202. case 0x3C: // '<'
  28203. ch = this.nextChar();
  28204. if (ch === 0x3C) {
  28205. // dict punctuation
  28206. this.nextChar();
  28207. return Cmd.get('<<');
  28208. }
  28209. return this.getHexString();
  28210. // dict punctuation
  28211. case 0x3E: // '>'
  28212. ch = this.nextChar();
  28213. if (ch === 0x3E) {
  28214. this.nextChar();
  28215. return Cmd.get('>>');
  28216. }
  28217. return Cmd.get('>');
  28218. case 0x7B: // '{'
  28219. this.nextChar();
  28220. return Cmd.get('{');
  28221. case 0x7D: // '}'
  28222. this.nextChar();
  28223. return Cmd.get('}');
  28224. case 0x29: // ')'
  28225. error('Illegal character: ' + ch);
  28226. break;
  28227. }
  28228. // command
  28229. var str = String.fromCharCode(ch);
  28230. var knownCommands = this.knownCommands;
  28231. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28232. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28233. // stop if known command is found and next character does not make
  28234. // the str a command
  28235. var possibleCommand = str + String.fromCharCode(ch);
  28236. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  28237. break;
  28238. }
  28239. if (str.length === 128) {
  28240. error('Command token too long: ' + str.length);
  28241. }
  28242. str = possibleCommand;
  28243. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28244. }
  28245. if (str === 'true') {
  28246. return true;
  28247. }
  28248. if (str === 'false') {
  28249. return false;
  28250. }
  28251. if (str === 'null') {
  28252. return null;
  28253. }
  28254. return Cmd.get(str);
  28255. },
  28256. skipToNextLine: function Lexer_skipToNextLine() {
  28257. var ch = this.currentChar;
  28258. while (ch >= 0) {
  28259. if (ch === 0x0D) { // CR
  28260. ch = this.nextChar();
  28261. if (ch === 0x0A) { // LF
  28262. this.nextChar();
  28263. }
  28264. break;
  28265. } else if (ch === 0x0A) { // LF
  28266. this.nextChar();
  28267. break;
  28268. }
  28269. ch = this.nextChar();
  28270. }
  28271. }
  28272. };
  28273. return Lexer;
  28274. })();
  28275. var Linearization = {
  28276. create: function LinearizationCreate(stream) {
  28277. function getInt(name, allowZeroValue) {
  28278. var obj = linDict.get(name);
  28279. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  28280. return obj;
  28281. }
  28282. throw new Error('The "' + name + '" parameter in the linearization ' +
  28283. 'dictionary is invalid.');
  28284. }
  28285. function getHints() {
  28286. var hints = linDict.get('H'), hintsLength, item;
  28287. if (isArray(hints) &&
  28288. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  28289. for (var index = 0; index < hintsLength; index++) {
  28290. if (!(isInt(item = hints[index]) && item > 0)) {
  28291. throw new Error('Hint (' + index +
  28292. ') in the linearization dictionary is invalid.');
  28293. }
  28294. }
  28295. return hints;
  28296. }
  28297. throw new Error('Hint array in the linearization dictionary is invalid.');
  28298. }
  28299. var parser = new Parser(new Lexer(stream), false, null);
  28300. var obj1 = parser.getObj();
  28301. var obj2 = parser.getObj();
  28302. var obj3 = parser.getObj();
  28303. var linDict = parser.getObj();
  28304. var obj, length;
  28305. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  28306. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  28307. return null; // No valid linearization dictionary found.
  28308. } else if ((length = getInt('L')) !== stream.length) {
  28309. throw new Error('The "L" parameter in the linearization dictionary ' +
  28310. 'does not equal the stream length.');
  28311. }
  28312. return {
  28313. length: length,
  28314. hints: getHints(),
  28315. objectNumberFirst: getInt('O'),
  28316. endFirst: getInt('E'),
  28317. numPages: getInt('N'),
  28318. mainXRefEntriesOffset: getInt('T'),
  28319. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  28320. };
  28321. }
  28322. };
  28323. exports.EOF = EOF;
  28324. exports.Lexer = Lexer;
  28325. exports.Linearization = Linearization;
  28326. exports.Parser = Parser;
  28327. exports.isEOF = isEOF;
  28328. }));
  28329. (function (root, factory) {
  28330. {
  28331. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  28332. root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  28333. }
  28334. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  28335. var warn = sharedUtil.warn;
  28336. var isSpace = sharedUtil.isSpace;
  28337. var Stream = coreStream.Stream;
  28338. var getEncoding = coreEncodings.getEncoding;
  28339. // Hinting is currently disabled due to unknown problems on windows
  28340. // in tracemonkey and various other pdfs with type1 fonts.
  28341. var HINTING_ENABLED = false;
  28342. /*
  28343. * CharStrings are encoded following the the CharString Encoding sequence
  28344. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  28345. * The value in a byte indicates a command, a number, or subsequent bytes
  28346. * that are to be interpreted in a special way.
  28347. *
  28348. * CharString Number Encoding:
  28349. * A CharString byte containing the values from 32 through 255 inclusive
  28350. * indicate an integer. These values are decoded in four ranges.
  28351. *
  28352. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  28353. * indicate the integer v - 139. Thus, the integer values from -107 through
  28354. * 107 inclusive may be encoded in single byte.
  28355. *
  28356. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  28357. * indicates an integer involving the next byte, w, according to the formula:
  28358. * [(v - 247) x 256] + w + 108
  28359. *
  28360. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  28361. * indicates an integer involving the next byte, w, according to the formula:
  28362. * -[(v - 251) * 256] - w - 108
  28363. *
  28364. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  28365. * are a two complement signed integer. The first of these bytes contains the
  28366. * highest order bits, the second byte contains the next higher order bits
  28367. * and the fourth byte contain the lowest order bits.
  28368. *
  28369. *
  28370. * CharString Command Encoding:
  28371. * CharStrings commands are encoded in 1 or 2 bytes.
  28372. *
  28373. * Single byte commands are encoded in 1 byte that contains a value between
  28374. * 0 and 31 inclusive.
  28375. * If a command byte contains the value 12, then the value in the next byte
  28376. * indicates a command. This "escape" mechanism allows many extra commands
  28377. * to be encoded and this encoding technique helps to minimize the length of
  28378. * the charStrings.
  28379. */
  28380. var Type1CharString = (function Type1CharStringClosure() {
  28381. var COMMAND_MAP = {
  28382. 'hstem': [1],
  28383. 'vstem': [3],
  28384. 'vmoveto': [4],
  28385. 'rlineto': [5],
  28386. 'hlineto': [6],
  28387. 'vlineto': [7],
  28388. 'rrcurveto': [8],
  28389. 'callsubr': [10],
  28390. 'flex': [12, 35],
  28391. 'drop' : [12, 18],
  28392. 'endchar': [14],
  28393. 'rmoveto': [21],
  28394. 'hmoveto': [22],
  28395. 'vhcurveto': [30],
  28396. 'hvcurveto': [31]
  28397. };
  28398. function Type1CharString() {
  28399. this.width = 0;
  28400. this.lsb = 0;
  28401. this.flexing = false;
  28402. this.output = [];
  28403. this.stack = [];
  28404. }
  28405. Type1CharString.prototype = {
  28406. convert: function Type1CharString_convert(encoded, subrs,
  28407. seacAnalysisEnabled) {
  28408. var count = encoded.length;
  28409. var error = false;
  28410. var wx, sbx, subrNumber;
  28411. for (var i = 0; i < count; i++) {
  28412. var value = encoded[i];
  28413. if (value < 32) {
  28414. if (value === 12) {
  28415. value = (value << 8) + encoded[++i];
  28416. }
  28417. switch (value) {
  28418. case 1: // hstem
  28419. if (!HINTING_ENABLED) {
  28420. this.stack = [];
  28421. break;
  28422. }
  28423. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28424. break;
  28425. case 3: // vstem
  28426. if (!HINTING_ENABLED) {
  28427. this.stack = [];
  28428. break;
  28429. }
  28430. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28431. break;
  28432. case 4: // vmoveto
  28433. if (this.flexing) {
  28434. if (this.stack.length < 1) {
  28435. error = true;
  28436. break;
  28437. }
  28438. // Add the dx for flex and but also swap the values so they are
  28439. // the right order.
  28440. var dy = this.stack.pop();
  28441. this.stack.push(0, dy);
  28442. break;
  28443. }
  28444. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  28445. break;
  28446. case 5: // rlineto
  28447. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  28448. break;
  28449. case 6: // hlineto
  28450. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  28451. break;
  28452. case 7: // vlineto
  28453. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  28454. break;
  28455. case 8: // rrcurveto
  28456. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  28457. break;
  28458. case 9: // closepath
  28459. // closepath is a Type1 command that does not take argument and is
  28460. // useless in Type2 and it can simply be ignored.
  28461. this.stack = [];
  28462. break;
  28463. case 10: // callsubr
  28464. if (this.stack.length < 1) {
  28465. error = true;
  28466. break;
  28467. }
  28468. subrNumber = this.stack.pop();
  28469. error = this.convert(subrs[subrNumber], subrs,
  28470. seacAnalysisEnabled);
  28471. break;
  28472. case 11: // return
  28473. return error;
  28474. case 13: // hsbw
  28475. if (this.stack.length < 2) {
  28476. error = true;
  28477. break;
  28478. }
  28479. // To convert to type2 we have to move the width value to the
  28480. // first part of the charstring and then use hmoveto with lsb.
  28481. wx = this.stack.pop();
  28482. sbx = this.stack.pop();
  28483. this.lsb = sbx;
  28484. this.width = wx;
  28485. this.stack.push(wx, sbx);
  28486. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  28487. break;
  28488. case 14: // endchar
  28489. this.output.push(COMMAND_MAP.endchar[0]);
  28490. break;
  28491. case 21: // rmoveto
  28492. if (this.flexing) {
  28493. break;
  28494. }
  28495. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  28496. break;
  28497. case 22: // hmoveto
  28498. if (this.flexing) {
  28499. // Add the dy for flex.
  28500. this.stack.push(0);
  28501. break;
  28502. }
  28503. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  28504. break;
  28505. case 30: // vhcurveto
  28506. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  28507. break;
  28508. case 31: // hvcurveto
  28509. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  28510. break;
  28511. case (12 << 8) + 0: // dotsection
  28512. // dotsection is a Type1 command to specify some hinting feature
  28513. // for dots that do not take a parameter and it can safely be
  28514. // ignored for Type2.
  28515. this.stack = [];
  28516. break;
  28517. case (12 << 8) + 1: // vstem3
  28518. if (!HINTING_ENABLED) {
  28519. this.stack = [];
  28520. break;
  28521. }
  28522. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28523. // multiple parameters, so instead of returning [vh]stem3 take a
  28524. // shortcut and return [vhstem] instead.
  28525. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28526. break;
  28527. case (12 << 8) + 2: // hstem3
  28528. if (!HINTING_ENABLED) {
  28529. this.stack = [];
  28530. break;
  28531. }
  28532. // See vstem3.
  28533. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28534. break;
  28535. case (12 << 8) + 6: // seac
  28536. // seac is like type 2's special endchar but it doesn't use the
  28537. // first argument asb, so remove it.
  28538. if (seacAnalysisEnabled) {
  28539. this.seac = this.stack.splice(-4, 4);
  28540. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28541. } else {
  28542. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28543. }
  28544. break;
  28545. case (12 << 8) + 7: // sbw
  28546. if (this.stack.length < 4) {
  28547. error = true;
  28548. break;
  28549. }
  28550. // To convert to type2 we have to move the width value to the
  28551. // first part of the charstring and then use rmoveto with
  28552. // (dx, dy). The height argument will not be used for vmtx and
  28553. // vhea tables reconstruction -- ignoring it.
  28554. var wy = this.stack.pop();
  28555. wx = this.stack.pop();
  28556. var sby = this.stack.pop();
  28557. sbx = this.stack.pop();
  28558. this.lsb = sbx;
  28559. this.width = wx;
  28560. this.stack.push(wx, sbx, sby);
  28561. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28562. break;
  28563. case (12 << 8) + 12: // div
  28564. if (this.stack.length < 2) {
  28565. error = true;
  28566. break;
  28567. }
  28568. var num2 = this.stack.pop();
  28569. var num1 = this.stack.pop();
  28570. this.stack.push(num1 / num2);
  28571. break;
  28572. case (12 << 8) + 16: // callothersubr
  28573. if (this.stack.length < 2) {
  28574. error = true;
  28575. break;
  28576. }
  28577. subrNumber = this.stack.pop();
  28578. var numArgs = this.stack.pop();
  28579. if (subrNumber === 0 && numArgs === 3) {
  28580. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28581. this.stack.push(
  28582. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28583. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28584. flexArgs[4], // bcp2x
  28585. flexArgs[5], // bcp2y
  28586. flexArgs[6], // p2x
  28587. flexArgs[7], // p2y
  28588. flexArgs[8], // bcp3x
  28589. flexArgs[9], // bcp3y
  28590. flexArgs[10], // bcp4x
  28591. flexArgs[11], // bcp4y
  28592. flexArgs[12], // p3x
  28593. flexArgs[13], // p3y
  28594. flexArgs[14] // flexDepth
  28595. // 15 = finalx unused by flex
  28596. // 16 = finaly unused by flex
  28597. );
  28598. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28599. this.flexing = false;
  28600. this.stack.push(flexArgs[15], flexArgs[16]);
  28601. } else if (subrNumber === 1 && numArgs === 0) {
  28602. this.flexing = true;
  28603. }
  28604. break;
  28605. case (12 << 8) + 17: // pop
  28606. // Ignore this since it is only used with othersubr.
  28607. break;
  28608. case (12 << 8) + 33: // setcurrentpoint
  28609. // Ignore for now.
  28610. this.stack = [];
  28611. break;
  28612. default:
  28613. warn('Unknown type 1 charstring command of "' + value + '"');
  28614. break;
  28615. }
  28616. if (error) {
  28617. break;
  28618. }
  28619. continue;
  28620. } else if (value <= 246) {
  28621. value = value - 139;
  28622. } else if (value <= 250) {
  28623. value = ((value - 247) * 256) + encoded[++i] + 108;
  28624. } else if (value <= 254) {
  28625. value = -((value - 251) * 256) - encoded[++i] - 108;
  28626. } else {
  28627. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28628. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28629. }
  28630. this.stack.push(value);
  28631. }
  28632. return error;
  28633. },
  28634. executeCommand: function(howManyArgs, command, keepStack) {
  28635. var stackLength = this.stack.length;
  28636. if (howManyArgs > stackLength) {
  28637. return true;
  28638. }
  28639. var start = stackLength - howManyArgs;
  28640. for (var i = start; i < stackLength; i++) {
  28641. var value = this.stack[i];
  28642. if (value === (value | 0)) { // int
  28643. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28644. } else { // fixed point
  28645. value = (65536 * value) | 0;
  28646. this.output.push(255,
  28647. (value >> 24) & 0xFF,
  28648. (value >> 16) & 0xFF,
  28649. (value >> 8) & 0xFF,
  28650. value & 0xFF);
  28651. }
  28652. }
  28653. this.output.push.apply(this.output, command);
  28654. if (keepStack) {
  28655. this.stack.splice(start, howManyArgs);
  28656. } else {
  28657. this.stack.length = 0;
  28658. }
  28659. return false;
  28660. }
  28661. };
  28662. return Type1CharString;
  28663. })();
  28664. /*
  28665. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28666. * program. Some of its logic depends on the Type2 charstrings
  28667. * structure.
  28668. * Note: this doesn't really parse the font since that would require evaluation
  28669. * of PostScript, but it is possible in most cases to extract what we need
  28670. * without a full parse.
  28671. */
  28672. var Type1Parser = (function Type1ParserClosure() {
  28673. /*
  28674. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28675. * of Plaintext Bytes. The function took a key as a parameter which can be
  28676. * for decrypting the eexec block of for decoding charStrings.
  28677. */
  28678. var EEXEC_ENCRYPT_KEY = 55665;
  28679. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28680. function isHexDigit(code) {
  28681. return code >= 48 && code <= 57 || // '0'-'9'
  28682. code >= 65 && code <= 70 || // 'A'-'F'
  28683. code >= 97 && code <= 102; // 'a'-'f'
  28684. }
  28685. function decrypt(data, key, discardNumber) {
  28686. if (discardNumber >= data.length) {
  28687. return new Uint8Array(0);
  28688. }
  28689. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  28690. for (i = 0; i < discardNumber; i++) {
  28691. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  28692. }
  28693. var count = data.length - discardNumber;
  28694. var decrypted = new Uint8Array(count);
  28695. for (i = discardNumber, j = 0; j < count; i++, j++) {
  28696. var value = data[i];
  28697. decrypted[j] = value ^ (r >> 8);
  28698. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28699. }
  28700. return decrypted;
  28701. }
  28702. function decryptAscii(data, key, discardNumber) {
  28703. var r = key | 0, c1 = 52845, c2 = 22719;
  28704. var count = data.length, maybeLength = count >>> 1;
  28705. var decrypted = new Uint8Array(maybeLength);
  28706. var i, j;
  28707. for (i = 0, j = 0; i < count; i++) {
  28708. var digit1 = data[i];
  28709. if (!isHexDigit(digit1)) {
  28710. continue;
  28711. }
  28712. i++;
  28713. var digit2;
  28714. while (i < count && !isHexDigit(digit2 = data[i])) {
  28715. i++;
  28716. }
  28717. if (i < count) {
  28718. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28719. decrypted[j++] = value ^ (r >> 8);
  28720. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28721. }
  28722. }
  28723. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28724. }
  28725. function isSpecial(c) {
  28726. return c === 0x2F || // '/'
  28727. c === 0x5B || c === 0x5D || // '[', ']'
  28728. c === 0x7B || c === 0x7D || // '{', '}'
  28729. c === 0x28 || c === 0x29; // '(', ')'
  28730. }
  28731. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  28732. if (encrypted) {
  28733. var data = stream.getBytes();
  28734. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28735. isHexDigit(data[2]) && isHexDigit(data[3]));
  28736. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28737. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28738. }
  28739. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  28740. this.stream = stream;
  28741. this.nextChar();
  28742. }
  28743. Type1Parser.prototype = {
  28744. readNumberArray: function Type1Parser_readNumberArray() {
  28745. this.getToken(); // read '[' or '{' (arrays can start with either)
  28746. var array = [];
  28747. while (true) {
  28748. var token = this.getToken();
  28749. if (token === null || token === ']' || token === '}') {
  28750. break;
  28751. }
  28752. array.push(parseFloat(token || 0));
  28753. }
  28754. return array;
  28755. },
  28756. readNumber: function Type1Parser_readNumber() {
  28757. var token = this.getToken();
  28758. return parseFloat(token || 0);
  28759. },
  28760. readInt: function Type1Parser_readInt() {
  28761. // Use '| 0' to prevent setting a double into length such as the double
  28762. // does not flow into the loop variable.
  28763. var token = this.getToken();
  28764. return parseInt(token || 0, 10) | 0;
  28765. },
  28766. readBoolean: function Type1Parser_readBoolean() {
  28767. var token = this.getToken();
  28768. // Use 1 and 0 since that's what type2 charstrings use.
  28769. return token === 'true' ? 1 : 0;
  28770. },
  28771. nextChar : function Type1_nextChar() {
  28772. return (this.currentChar = this.stream.getByte());
  28773. },
  28774. getToken: function Type1Parser_getToken() {
  28775. // Eat whitespace and comments.
  28776. var comment = false;
  28777. var ch = this.currentChar;
  28778. while (true) {
  28779. if (ch === -1) {
  28780. return null;
  28781. }
  28782. if (comment) {
  28783. if (ch === 0x0A || ch === 0x0D) {
  28784. comment = false;
  28785. }
  28786. } else if (ch === 0x25) { // '%'
  28787. comment = true;
  28788. } else if (!isSpace(ch)) {
  28789. break;
  28790. }
  28791. ch = this.nextChar();
  28792. }
  28793. if (isSpecial(ch)) {
  28794. this.nextChar();
  28795. return String.fromCharCode(ch);
  28796. }
  28797. var token = '';
  28798. do {
  28799. token += String.fromCharCode(ch);
  28800. ch = this.nextChar();
  28801. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  28802. return token;
  28803. },
  28804. /*
  28805. * Returns an object containing a Subrs array and a CharStrings
  28806. * array extracted from and eexec encrypted block of data
  28807. */
  28808. extractFontProgram: function Type1Parser_extractFontProgram() {
  28809. var stream = this.stream;
  28810. var subrs = [], charstrings = [];
  28811. var privateData = Object.create(null);
  28812. privateData['lenIV'] = 4;
  28813. var program = {
  28814. subrs: [],
  28815. charstrings: [],
  28816. properties: {
  28817. 'privateData': privateData
  28818. }
  28819. };
  28820. var token, length, data, lenIV, encoded;
  28821. while ((token = this.getToken()) !== null) {
  28822. if (token !== '/') {
  28823. continue;
  28824. }
  28825. token = this.getToken();
  28826. switch (token) {
  28827. case 'CharStrings':
  28828. // The number immediately following CharStrings must be greater or
  28829. // equal to the number of CharStrings.
  28830. this.getToken();
  28831. this.getToken(); // read in 'dict'
  28832. this.getToken(); // read in 'dup'
  28833. this.getToken(); // read in 'begin'
  28834. while(true) {
  28835. token = this.getToken();
  28836. if (token === null || token === 'end') {
  28837. break;
  28838. }
  28839. if (token !== '/') {
  28840. continue;
  28841. }
  28842. var glyph = this.getToken();
  28843. length = this.readInt();
  28844. this.getToken(); // read in 'RD' or '-|'
  28845. data = stream.makeSubStream(stream.pos, length);
  28846. lenIV = program.properties.privateData['lenIV'];
  28847. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28848. // Skip past the required space and binary data.
  28849. stream.skip(length);
  28850. this.nextChar();
  28851. token = this.getToken(); // read in 'ND' or '|-'
  28852. if (token === 'noaccess') {
  28853. this.getToken(); // read in 'def'
  28854. }
  28855. charstrings.push({
  28856. glyph: glyph,
  28857. encoded: encoded
  28858. });
  28859. }
  28860. break;
  28861. case 'Subrs':
  28862. var num = this.readInt();
  28863. this.getToken(); // read in 'array'
  28864. while ((token = this.getToken()) === 'dup') {
  28865. var index = this.readInt();
  28866. length = this.readInt();
  28867. this.getToken(); // read in 'RD' or '-|'
  28868. data = stream.makeSubStream(stream.pos, length);
  28869. lenIV = program.properties.privateData['lenIV'];
  28870. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28871. // Skip past the required space and binary data.
  28872. stream.skip(length);
  28873. this.nextChar();
  28874. token = this.getToken(); // read in 'NP' or '|'
  28875. if (token === 'noaccess') {
  28876. this.getToken(); // read in 'put'
  28877. }
  28878. subrs[index] = encoded;
  28879. }
  28880. break;
  28881. case 'BlueValues':
  28882. case 'OtherBlues':
  28883. case 'FamilyBlues':
  28884. case 'FamilyOtherBlues':
  28885. var blueArray = this.readNumberArray();
  28886. // *Blue* values may contain invalid data: disables reading of
  28887. // those values when hinting is disabled.
  28888. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  28889. HINTING_ENABLED) {
  28890. program.properties.privateData[token] = blueArray;
  28891. }
  28892. break;
  28893. case 'StemSnapH':
  28894. case 'StemSnapV':
  28895. program.properties.privateData[token] = this.readNumberArray();
  28896. break;
  28897. case 'StdHW':
  28898. case 'StdVW':
  28899. program.properties.privateData[token] =
  28900. this.readNumberArray()[0];
  28901. break;
  28902. case 'BlueShift':
  28903. case 'lenIV':
  28904. case 'BlueFuzz':
  28905. case 'BlueScale':
  28906. case 'LanguageGroup':
  28907. case 'ExpansionFactor':
  28908. program.properties.privateData[token] = this.readNumber();
  28909. break;
  28910. case 'ForceBold':
  28911. program.properties.privateData[token] = this.readBoolean();
  28912. break;
  28913. }
  28914. }
  28915. for (var i = 0; i < charstrings.length; i++) {
  28916. glyph = charstrings[i].glyph;
  28917. encoded = charstrings[i].encoded;
  28918. var charString = new Type1CharString();
  28919. var error = charString.convert(encoded, subrs,
  28920. this.seacAnalysisEnabled);
  28921. var output = charString.output;
  28922. if (error) {
  28923. // It seems when FreeType encounters an error while evaluating a glyph
  28924. // that it completely ignores the glyph so we'll mimic that behaviour
  28925. // here and put an endchar to make the validator happy.
  28926. output = [14];
  28927. }
  28928. program.charstrings.push({
  28929. glyphName: glyph,
  28930. charstring: output,
  28931. width: charString.width,
  28932. lsb: charString.lsb,
  28933. seac: charString.seac
  28934. });
  28935. }
  28936. return program;
  28937. },
  28938. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  28939. var token;
  28940. while ((token = this.getToken()) !== null) {
  28941. if (token !== '/') {
  28942. continue;
  28943. }
  28944. token = this.getToken();
  28945. switch (token) {
  28946. case 'FontMatrix':
  28947. var matrix = this.readNumberArray();
  28948. properties.fontMatrix = matrix;
  28949. break;
  28950. case 'Encoding':
  28951. var encodingArg = this.getToken();
  28952. var encoding;
  28953. if (!/^\d+$/.test(encodingArg)) {
  28954. // encoding name is specified
  28955. encoding = getEncoding(encodingArg);
  28956. } else {
  28957. encoding = [];
  28958. var size = parseInt(encodingArg, 10) | 0;
  28959. this.getToken(); // read in 'array'
  28960. for (var j = 0; j < size; j++) {
  28961. token = this.getToken();
  28962. // skipping till first dup or def (e.g. ignoring for statement)
  28963. while (token !== 'dup' && token !== 'def') {
  28964. token = this.getToken();
  28965. if (token === null) {
  28966. return; // invalid header
  28967. }
  28968. }
  28969. if (token === 'def') {
  28970. break; // read all array data
  28971. }
  28972. var index = this.readInt();
  28973. this.getToken(); // read in '/'
  28974. var glyph = this.getToken();
  28975. encoding[index] = glyph;
  28976. this.getToken(); // read the in 'put'
  28977. }
  28978. }
  28979. properties.builtInEncoding = encoding;
  28980. break;
  28981. case 'FontBBox':
  28982. var fontBBox = this.readNumberArray();
  28983. // adjusting ascent/descent
  28984. properties.ascent = fontBBox[3];
  28985. properties.descent = fontBBox[1];
  28986. properties.ascentScaled = true;
  28987. break;
  28988. }
  28989. }
  28990. }
  28991. };
  28992. return Type1Parser;
  28993. })();
  28994. exports.Type1Parser = Type1Parser;
  28995. }));
  28996. (function (root, factory) {
  28997. {
  28998. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  28999. root.pdfjsDisplayWebGL);
  29000. }
  29001. }(this, function (exports, sharedUtil, displayWebGL) {
  29002. var Util = sharedUtil.Util;
  29003. var info = sharedUtil.info;
  29004. var isArray = sharedUtil.isArray;
  29005. var error = sharedUtil.error;
  29006. var WebGLUtils = displayWebGL.WebGLUtils;
  29007. var ShadingIRs = {};
  29008. ShadingIRs.RadialAxial = {
  29009. fromIR: function RadialAxial_fromIR(raw) {
  29010. var type = raw[1];
  29011. var colorStops = raw[2];
  29012. var p0 = raw[3];
  29013. var p1 = raw[4];
  29014. var r0 = raw[5];
  29015. var r1 = raw[6];
  29016. return {
  29017. type: 'Pattern',
  29018. getPattern: function RadialAxial_getPattern(ctx) {
  29019. var grad;
  29020. if (type === 'axial') {
  29021. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  29022. } else if (type === 'radial') {
  29023. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  29024. }
  29025. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  29026. var c = colorStops[i];
  29027. grad.addColorStop(c[0], c[1]);
  29028. }
  29029. return grad;
  29030. }
  29031. };
  29032. }
  29033. };
  29034. var createMeshCanvas = (function createMeshCanvasClosure() {
  29035. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  29036. // Very basic Gouraud-shaded triangle rasterization algorithm.
  29037. var coords = context.coords, colors = context.colors;
  29038. var bytes = data.data, rowSize = data.width * 4;
  29039. var tmp;
  29040. if (coords[p1 + 1] > coords[p2 + 1]) {
  29041. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  29042. }
  29043. if (coords[p2 + 1] > coords[p3 + 1]) {
  29044. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  29045. }
  29046. if (coords[p1 + 1] > coords[p2 + 1]) {
  29047. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  29048. }
  29049. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  29050. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  29051. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  29052. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  29053. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  29054. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  29055. if (y1 >= y3) {
  29056. return;
  29057. }
  29058. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  29059. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  29060. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  29061. var minY = Math.round(y1), maxY = Math.round(y3);
  29062. var xa, car, cag, cab;
  29063. var xb, cbr, cbg, cbb;
  29064. var k;
  29065. for (var y = minY; y <= maxY; y++) {
  29066. if (y < y2) {
  29067. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  29068. xa = x1 - (x1 - x2) * k;
  29069. car = c1r - (c1r - c2r) * k;
  29070. cag = c1g - (c1g - c2g) * k;
  29071. cab = c1b - (c1b - c2b) * k;
  29072. } else {
  29073. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  29074. xa = x2 - (x2 - x3) * k;
  29075. car = c2r - (c2r - c3r) * k;
  29076. cag = c2g - (c2g - c3g) * k;
  29077. cab = c2b - (c2b - c3b) * k;
  29078. }
  29079. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  29080. xb = x1 - (x1 - x3) * k;
  29081. cbr = c1r - (c1r - c3r) * k;
  29082. cbg = c1g - (c1g - c3g) * k;
  29083. cbb = c1b - (c1b - c3b) * k;
  29084. var x1_ = Math.round(Math.min(xa, xb));
  29085. var x2_ = Math.round(Math.max(xa, xb));
  29086. var j = rowSize * y + x1_ * 4;
  29087. for (var x = x1_; x <= x2_; x++) {
  29088. k = (xa - x) / (xa - xb);
  29089. k = k < 0 ? 0 : k > 1 ? 1 : k;
  29090. bytes[j++] = (car - (car - cbr) * k) | 0;
  29091. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  29092. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  29093. bytes[j++] = 255;
  29094. }
  29095. }
  29096. }
  29097. function drawFigure(data, figure, context) {
  29098. var ps = figure.coords;
  29099. var cs = figure.colors;
  29100. var i, ii;
  29101. switch (figure.type) {
  29102. case 'lattice':
  29103. var verticesPerRow = figure.verticesPerRow;
  29104. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  29105. var cols = verticesPerRow - 1;
  29106. for (i = 0; i < rows; i++) {
  29107. var q = i * verticesPerRow;
  29108. for (var j = 0; j < cols; j++, q++) {
  29109. drawTriangle(data, context,
  29110. ps[q], ps[q + 1], ps[q + verticesPerRow],
  29111. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  29112. drawTriangle(data, context,
  29113. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  29114. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  29115. }
  29116. }
  29117. break;
  29118. case 'triangles':
  29119. for (i = 0, ii = ps.length; i < ii; i += 3) {
  29120. drawTriangle(data, context,
  29121. ps[i], ps[i + 1], ps[i + 2],
  29122. cs[i], cs[i + 1], cs[i + 2]);
  29123. }
  29124. break;
  29125. default:
  29126. error('illigal figure');
  29127. break;
  29128. }
  29129. }
  29130. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  29131. backgroundColor, cachedCanvases) {
  29132. // we will increase scale on some weird factor to let antialiasing take
  29133. // care of "rough" edges
  29134. var EXPECTED_SCALE = 1.1;
  29135. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  29136. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  29137. // We need to keep transparent border around our pattern for fill():
  29138. // createPattern with 'no-repeat' will bleed edges across entire area.
  29139. var BORDER_SIZE = 2;
  29140. var offsetX = Math.floor(bounds[0]);
  29141. var offsetY = Math.floor(bounds[1]);
  29142. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  29143. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  29144. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  29145. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  29146. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  29147. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  29148. var scaleX = boundsWidth / width;
  29149. var scaleY = boundsHeight / height;
  29150. var context = {
  29151. coords: coords,
  29152. colors: colors,
  29153. offsetX: -offsetX,
  29154. offsetY: -offsetY,
  29155. scaleX: 1 / scaleX,
  29156. scaleY: 1 / scaleY
  29157. };
  29158. var paddedWidth = width + BORDER_SIZE * 2;
  29159. var paddedHeight = height + BORDER_SIZE * 2;
  29160. var canvas, tmpCanvas, i, ii;
  29161. if (WebGLUtils.isEnabled) {
  29162. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  29163. figures, context);
  29164. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  29165. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
  29166. false);
  29167. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  29168. canvas = tmpCanvas.canvas;
  29169. } else {
  29170. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
  29171. false);
  29172. var tmpCtx = tmpCanvas.context;
  29173. var data = tmpCtx.createImageData(width, height);
  29174. if (backgroundColor) {
  29175. var bytes = data.data;
  29176. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  29177. bytes[i] = backgroundColor[0];
  29178. bytes[i + 1] = backgroundColor[1];
  29179. bytes[i + 2] = backgroundColor[2];
  29180. bytes[i + 3] = 255;
  29181. }
  29182. }
  29183. for (i = 0; i < figures.length; i++) {
  29184. drawFigure(data, figures[i], context);
  29185. }
  29186. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  29187. canvas = tmpCanvas.canvas;
  29188. }
  29189. return {canvas: canvas,
  29190. offsetX: offsetX - BORDER_SIZE * scaleX,
  29191. offsetY: offsetY - BORDER_SIZE * scaleY,
  29192. scaleX: scaleX, scaleY: scaleY};
  29193. }
  29194. return createMeshCanvas;
  29195. })();
  29196. ShadingIRs.Mesh = {
  29197. fromIR: function Mesh_fromIR(raw) {
  29198. //var type = raw[1];
  29199. var coords = raw[2];
  29200. var colors = raw[3];
  29201. var figures = raw[4];
  29202. var bounds = raw[5];
  29203. var matrix = raw[6];
  29204. //var bbox = raw[7];
  29205. var background = raw[8];
  29206. return {
  29207. type: 'Pattern',
  29208. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  29209. var scale;
  29210. if (shadingFill) {
  29211. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  29212. } else {
  29213. // Obtain scale from matrix and current transformation matrix.
  29214. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  29215. if (matrix) {
  29216. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  29217. scale = [scale[0] * matrixScale[0],
  29218. scale[1] * matrixScale[1]];
  29219. }
  29220. }
  29221. // Rasterizing on the main thread since sending/queue large canvases
  29222. // might cause OOM.
  29223. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  29224. colors, figures, shadingFill ? null : background,
  29225. owner.cachedCanvases);
  29226. if (!shadingFill) {
  29227. ctx.setTransform.apply(ctx, owner.baseTransform);
  29228. if (matrix) {
  29229. ctx.transform.apply(ctx, matrix);
  29230. }
  29231. }
  29232. ctx.translate(temporaryPatternCanvas.offsetX,
  29233. temporaryPatternCanvas.offsetY);
  29234. ctx.scale(temporaryPatternCanvas.scaleX,
  29235. temporaryPatternCanvas.scaleY);
  29236. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  29237. }
  29238. };
  29239. }
  29240. };
  29241. ShadingIRs.Dummy = {
  29242. fromIR: function Dummy_fromIR() {
  29243. return {
  29244. type: 'Pattern',
  29245. getPattern: function Dummy_fromIR_getPattern() {
  29246. return 'hotpink';
  29247. }
  29248. };
  29249. }
  29250. };
  29251. function getShadingPatternFromIR(raw) {
  29252. var shadingIR = ShadingIRs[raw[0]];
  29253. if (!shadingIR) {
  29254. error('Unknown IR type: ' + raw[0]);
  29255. }
  29256. return shadingIR.fromIR(raw);
  29257. }
  29258. var TilingPattern = (function TilingPatternClosure() {
  29259. var PaintType = {
  29260. COLORED: 1,
  29261. UNCOLORED: 2
  29262. };
  29263. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  29264. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  29265. this.operatorList = IR[2];
  29266. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  29267. this.bbox = IR[4];
  29268. this.xstep = IR[5];
  29269. this.ystep = IR[6];
  29270. this.paintType = IR[7];
  29271. this.tilingType = IR[8];
  29272. this.color = color;
  29273. this.canvasGraphicsFactory = canvasGraphicsFactory;
  29274. this.baseTransform = baseTransform;
  29275. this.type = 'Pattern';
  29276. this.ctx = ctx;
  29277. }
  29278. TilingPattern.prototype = {
  29279. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  29280. var operatorList = this.operatorList;
  29281. var bbox = this.bbox;
  29282. var xstep = this.xstep;
  29283. var ystep = this.ystep;
  29284. var paintType = this.paintType;
  29285. var tilingType = this.tilingType;
  29286. var color = this.color;
  29287. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  29288. info('TilingType: ' + tilingType);
  29289. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  29290. var topLeft = [x0, y0];
  29291. // we want the canvas to be as large as the step size
  29292. var botRight = [x0 + xstep, y0 + ystep];
  29293. var width = botRight[0] - topLeft[0];
  29294. var height = botRight[1] - topLeft[1];
  29295. // Obtain scale from matrix and current transformation matrix.
  29296. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  29297. var curMatrixScale = Util.singularValueDecompose2dScale(
  29298. this.baseTransform);
  29299. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  29300. matrixScale[1] * curMatrixScale[1]];
  29301. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  29302. // Use width and height values that are as close as possible to the end
  29303. // result when the pattern is used. Too low value makes the pattern look
  29304. // blurry. Too large value makes it look too crispy.
  29305. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  29306. MAX_PATTERN_SIZE);
  29307. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  29308. MAX_PATTERN_SIZE);
  29309. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  29310. width, height, true);
  29311. var tmpCtx = tmpCanvas.context;
  29312. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  29313. graphics.groupLevel = owner.groupLevel;
  29314. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  29315. this.setScale(width, height, xstep, ystep);
  29316. this.transformToScale(graphics);
  29317. // transform coordinates to pattern space
  29318. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  29319. graphics.transform.apply(graphics, tmpTranslate);
  29320. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  29321. graphics.executeOperatorList(operatorList);
  29322. return tmpCanvas.canvas;
  29323. },
  29324. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  29325. this.scale = [width / xstep, height / ystep];
  29326. },
  29327. transformToScale: function TilingPattern_transformToScale(graphics) {
  29328. var scale = this.scale;
  29329. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  29330. graphics.transform.apply(graphics, tmpScale);
  29331. },
  29332. scaleToContext: function TilingPattern_scaleToContext() {
  29333. var scale = this.scale;
  29334. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  29335. },
  29336. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  29337. if (bbox && isArray(bbox) && bbox.length === 4) {
  29338. var bboxWidth = x1 - x0;
  29339. var bboxHeight = y1 - y0;
  29340. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  29341. graphics.clip();
  29342. graphics.endPath();
  29343. }
  29344. },
  29345. setFillAndStrokeStyleToContext:
  29346. function setFillAndStrokeStyleToContext(context, paintType, color) {
  29347. switch (paintType) {
  29348. case PaintType.COLORED:
  29349. var ctx = this.ctx;
  29350. context.fillStyle = ctx.fillStyle;
  29351. context.strokeStyle = ctx.strokeStyle;
  29352. break;
  29353. case PaintType.UNCOLORED:
  29354. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  29355. context.fillStyle = cssColor;
  29356. context.strokeStyle = cssColor;
  29357. break;
  29358. default:
  29359. error('Unsupported paint type: ' + paintType);
  29360. }
  29361. },
  29362. getPattern: function TilingPattern_getPattern(ctx, owner) {
  29363. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  29364. ctx = this.ctx;
  29365. ctx.setTransform.apply(ctx, this.baseTransform);
  29366. ctx.transform.apply(ctx, this.matrix);
  29367. this.scaleToContext();
  29368. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  29369. }
  29370. };
  29371. return TilingPattern;
  29372. })();
  29373. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  29374. exports.TilingPattern = TilingPattern;
  29375. }));
  29376. (function (root, factory) {
  29377. {
  29378. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  29379. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  29380. }
  29381. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  29382. var Util = sharedUtil.Util;
  29383. var assert = sharedUtil.assert;
  29384. var warn = sharedUtil.warn;
  29385. var error = sharedUtil.error;
  29386. var isInt = sharedUtil.isInt;
  29387. var isString = sharedUtil.isString;
  29388. var MissingDataException = sharedUtil.MissingDataException;
  29389. var isName = corePrimitives.isName;
  29390. var isCmd = corePrimitives.isCmd;
  29391. var isStream = corePrimitives.isStream;
  29392. var StringStream = coreStream.StringStream;
  29393. var Lexer = coreParser.Lexer;
  29394. var isEOF = coreParser.isEOF;
  29395. var BUILT_IN_CMAPS = [
  29396. // << Start unicode maps.
  29397. 'Adobe-GB1-UCS2',
  29398. 'Adobe-CNS1-UCS2',
  29399. 'Adobe-Japan1-UCS2',
  29400. 'Adobe-Korea1-UCS2',
  29401. // >> End unicode maps.
  29402. '78-EUC-H',
  29403. '78-EUC-V',
  29404. '78-H',
  29405. '78-RKSJ-H',
  29406. '78-RKSJ-V',
  29407. '78-V',
  29408. '78ms-RKSJ-H',
  29409. '78ms-RKSJ-V',
  29410. '83pv-RKSJ-H',
  29411. '90ms-RKSJ-H',
  29412. '90ms-RKSJ-V',
  29413. '90msp-RKSJ-H',
  29414. '90msp-RKSJ-V',
  29415. '90pv-RKSJ-H',
  29416. '90pv-RKSJ-V',
  29417. 'Add-H',
  29418. 'Add-RKSJ-H',
  29419. 'Add-RKSJ-V',
  29420. 'Add-V',
  29421. 'Adobe-CNS1-0',
  29422. 'Adobe-CNS1-1',
  29423. 'Adobe-CNS1-2',
  29424. 'Adobe-CNS1-3',
  29425. 'Adobe-CNS1-4',
  29426. 'Adobe-CNS1-5',
  29427. 'Adobe-CNS1-6',
  29428. 'Adobe-GB1-0',
  29429. 'Adobe-GB1-1',
  29430. 'Adobe-GB1-2',
  29431. 'Adobe-GB1-3',
  29432. 'Adobe-GB1-4',
  29433. 'Adobe-GB1-5',
  29434. 'Adobe-Japan1-0',
  29435. 'Adobe-Japan1-1',
  29436. 'Adobe-Japan1-2',
  29437. 'Adobe-Japan1-3',
  29438. 'Adobe-Japan1-4',
  29439. 'Adobe-Japan1-5',
  29440. 'Adobe-Japan1-6',
  29441. 'Adobe-Korea1-0',
  29442. 'Adobe-Korea1-1',
  29443. 'Adobe-Korea1-2',
  29444. 'B5-H',
  29445. 'B5-V',
  29446. 'B5pc-H',
  29447. 'B5pc-V',
  29448. 'CNS-EUC-H',
  29449. 'CNS-EUC-V',
  29450. 'CNS1-H',
  29451. 'CNS1-V',
  29452. 'CNS2-H',
  29453. 'CNS2-V',
  29454. 'ETHK-B5-H',
  29455. 'ETHK-B5-V',
  29456. 'ETen-B5-H',
  29457. 'ETen-B5-V',
  29458. 'ETenms-B5-H',
  29459. 'ETenms-B5-V',
  29460. 'EUC-H',
  29461. 'EUC-V',
  29462. 'Ext-H',
  29463. 'Ext-RKSJ-H',
  29464. 'Ext-RKSJ-V',
  29465. 'Ext-V',
  29466. 'GB-EUC-H',
  29467. 'GB-EUC-V',
  29468. 'GB-H',
  29469. 'GB-V',
  29470. 'GBK-EUC-H',
  29471. 'GBK-EUC-V',
  29472. 'GBK2K-H',
  29473. 'GBK2K-V',
  29474. 'GBKp-EUC-H',
  29475. 'GBKp-EUC-V',
  29476. 'GBT-EUC-H',
  29477. 'GBT-EUC-V',
  29478. 'GBT-H',
  29479. 'GBT-V',
  29480. 'GBTpc-EUC-H',
  29481. 'GBTpc-EUC-V',
  29482. 'GBpc-EUC-H',
  29483. 'GBpc-EUC-V',
  29484. 'H',
  29485. 'HKdla-B5-H',
  29486. 'HKdla-B5-V',
  29487. 'HKdlb-B5-H',
  29488. 'HKdlb-B5-V',
  29489. 'HKgccs-B5-H',
  29490. 'HKgccs-B5-V',
  29491. 'HKm314-B5-H',
  29492. 'HKm314-B5-V',
  29493. 'HKm471-B5-H',
  29494. 'HKm471-B5-V',
  29495. 'HKscs-B5-H',
  29496. 'HKscs-B5-V',
  29497. 'Hankaku',
  29498. 'Hiragana',
  29499. 'KSC-EUC-H',
  29500. 'KSC-EUC-V',
  29501. 'KSC-H',
  29502. 'KSC-Johab-H',
  29503. 'KSC-Johab-V',
  29504. 'KSC-V',
  29505. 'KSCms-UHC-H',
  29506. 'KSCms-UHC-HW-H',
  29507. 'KSCms-UHC-HW-V',
  29508. 'KSCms-UHC-V',
  29509. 'KSCpc-EUC-H',
  29510. 'KSCpc-EUC-V',
  29511. 'Katakana',
  29512. 'NWP-H',
  29513. 'NWP-V',
  29514. 'RKSJ-H',
  29515. 'RKSJ-V',
  29516. 'Roman',
  29517. 'UniCNS-UCS2-H',
  29518. 'UniCNS-UCS2-V',
  29519. 'UniCNS-UTF16-H',
  29520. 'UniCNS-UTF16-V',
  29521. 'UniCNS-UTF32-H',
  29522. 'UniCNS-UTF32-V',
  29523. 'UniCNS-UTF8-H',
  29524. 'UniCNS-UTF8-V',
  29525. 'UniGB-UCS2-H',
  29526. 'UniGB-UCS2-V',
  29527. 'UniGB-UTF16-H',
  29528. 'UniGB-UTF16-V',
  29529. 'UniGB-UTF32-H',
  29530. 'UniGB-UTF32-V',
  29531. 'UniGB-UTF8-H',
  29532. 'UniGB-UTF8-V',
  29533. 'UniJIS-UCS2-H',
  29534. 'UniJIS-UCS2-HW-H',
  29535. 'UniJIS-UCS2-HW-V',
  29536. 'UniJIS-UCS2-V',
  29537. 'UniJIS-UTF16-H',
  29538. 'UniJIS-UTF16-V',
  29539. 'UniJIS-UTF32-H',
  29540. 'UniJIS-UTF32-V',
  29541. 'UniJIS-UTF8-H',
  29542. 'UniJIS-UTF8-V',
  29543. 'UniJIS2004-UTF16-H',
  29544. 'UniJIS2004-UTF16-V',
  29545. 'UniJIS2004-UTF32-H',
  29546. 'UniJIS2004-UTF32-V',
  29547. 'UniJIS2004-UTF8-H',
  29548. 'UniJIS2004-UTF8-V',
  29549. 'UniJISPro-UCS2-HW-V',
  29550. 'UniJISPro-UCS2-V',
  29551. 'UniJISPro-UTF8-V',
  29552. 'UniJISX0213-UTF32-H',
  29553. 'UniJISX0213-UTF32-V',
  29554. 'UniJISX02132004-UTF32-H',
  29555. 'UniJISX02132004-UTF32-V',
  29556. 'UniKS-UCS2-H',
  29557. 'UniKS-UCS2-V',
  29558. 'UniKS-UTF16-H',
  29559. 'UniKS-UTF16-V',
  29560. 'UniKS-UTF32-H',
  29561. 'UniKS-UTF32-V',
  29562. 'UniKS-UTF8-H',
  29563. 'UniKS-UTF8-V',
  29564. 'V',
  29565. 'WP-Symbol'];
  29566. // CMap, not to be confused with TrueType's cmap.
  29567. var CMap = (function CMapClosure() {
  29568. function CMap(builtInCMap) {
  29569. // Codespace ranges are stored as follows:
  29570. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  29571. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  29572. this.codespaceRanges = [[], [], [], []];
  29573. this.numCodespaceRanges = 0;
  29574. // Map entries have one of two forms.
  29575. // - cid chars are 16-bit unsigned integers, stored as integers.
  29576. // - bf chars are variable-length byte sequences, stored as strings, with
  29577. // one byte per character.
  29578. this._map = [];
  29579. this.name = '';
  29580. this.vertical = false;
  29581. this.useCMap = null;
  29582. this.builtInCMap = builtInCMap;
  29583. }
  29584. CMap.prototype = {
  29585. addCodespaceRange: function(n, low, high) {
  29586. this.codespaceRanges[n - 1].push(low, high);
  29587. this.numCodespaceRanges++;
  29588. },
  29589. mapCidRange: function(low, high, dstLow) {
  29590. while (low <= high) {
  29591. this._map[low++] = dstLow++;
  29592. }
  29593. },
  29594. mapBfRange: function(low, high, dstLow) {
  29595. var lastByte = dstLow.length - 1;
  29596. while (low <= high) {
  29597. this._map[low++] = dstLow;
  29598. // Only the last byte has to be incremented.
  29599. dstLow = dstLow.substr(0, lastByte) +
  29600. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  29601. }
  29602. },
  29603. mapBfRangeToArray: function(low, high, array) {
  29604. var i = 0, ii = array.length;
  29605. while (low <= high && i < ii) {
  29606. this._map[low] = array[i++];
  29607. ++low;
  29608. }
  29609. },
  29610. // This is used for both bf and cid chars.
  29611. mapOne: function(src, dst) {
  29612. this._map[src] = dst;
  29613. },
  29614. lookup: function(code) {
  29615. return this._map[code];
  29616. },
  29617. contains: function(code) {
  29618. return this._map[code] !== undefined;
  29619. },
  29620. forEach: function(callback) {
  29621. // Most maps have fewer than 65536 entries, and for those we use normal
  29622. // array iteration. But really sparse tables are possible -- e.g. with
  29623. // indices in the *billions*. For such tables we use for..in, which isn't
  29624. // ideal because it stringifies the indices for all present elements, but
  29625. // it does avoid iterating over every undefined entry.
  29626. var map = this._map;
  29627. var length = map.length;
  29628. var i;
  29629. if (length <= 0x10000) {
  29630. for (i = 0; i < length; i++) {
  29631. if (map[i] !== undefined) {
  29632. callback(i, map[i]);
  29633. }
  29634. }
  29635. } else {
  29636. for (i in this._map) {
  29637. callback(i, map[i]);
  29638. }
  29639. }
  29640. },
  29641. charCodeOf: function(value) {
  29642. return this._map.indexOf(value);
  29643. },
  29644. getMap: function() {
  29645. return this._map;
  29646. },
  29647. readCharCode: function(str, offset, out) {
  29648. var c = 0;
  29649. var codespaceRanges = this.codespaceRanges;
  29650. var codespaceRangesLen = this.codespaceRanges.length;
  29651. // 9.7.6.2 CMap Mapping
  29652. // The code length is at most 4.
  29653. for (var n = 0; n < codespaceRangesLen; n++) {
  29654. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  29655. // Check each codespace range to see if it falls within.
  29656. var codespaceRange = codespaceRanges[n];
  29657. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  29658. var low = codespaceRange[k++];
  29659. var high = codespaceRange[k++];
  29660. if (c >= low && c <= high) {
  29661. out.charcode = c;
  29662. out.length = n + 1;
  29663. return;
  29664. }
  29665. }
  29666. }
  29667. out.charcode = 0;
  29668. out.length = 1;
  29669. },
  29670. get length() {
  29671. return this._map.length;
  29672. },
  29673. get isIdentityCMap() {
  29674. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  29675. return false;
  29676. }
  29677. if (this._map.length !== 0x10000) {
  29678. return false;
  29679. }
  29680. for (var i = 0; i < 0x10000; i++) {
  29681. if (this._map[i] !== i) {
  29682. return false;
  29683. }
  29684. }
  29685. return true;
  29686. }
  29687. };
  29688. return CMap;
  29689. })();
  29690. // A special case of CMap, where the _map array implicitly has a length of
  29691. // 65536 and each element is equal to its index.
  29692. var IdentityCMap = (function IdentityCMapClosure() {
  29693. function IdentityCMap(vertical, n) {
  29694. CMap.call(this);
  29695. this.vertical = vertical;
  29696. this.addCodespaceRange(n, 0, 0xffff);
  29697. }
  29698. Util.inherit(IdentityCMap, CMap, {});
  29699. IdentityCMap.prototype = {
  29700. addCodespaceRange: CMap.prototype.addCodespaceRange,
  29701. mapCidRange: function(low, high, dstLow) {
  29702. error('should not call mapCidRange');
  29703. },
  29704. mapBfRange: function(low, high, dstLow) {
  29705. error('should not call mapBfRange');
  29706. },
  29707. mapBfRangeToArray: function(low, high, array) {
  29708. error('should not call mapBfRangeToArray');
  29709. },
  29710. mapOne: function(src, dst) {
  29711. error('should not call mapCidOne');
  29712. },
  29713. lookup: function(code) {
  29714. return (isInt(code) && code <= 0xffff) ? code : undefined;
  29715. },
  29716. contains: function(code) {
  29717. return isInt(code) && code <= 0xffff;
  29718. },
  29719. forEach: function(callback) {
  29720. for (var i = 0; i <= 0xffff; i++) {
  29721. callback(i, i);
  29722. }
  29723. },
  29724. charCodeOf: function(value) {
  29725. return (isInt(value) && value <= 0xffff) ? value : -1;
  29726. },
  29727. getMap: function() {
  29728. // Sometimes identity maps must be instantiated, but it's rare.
  29729. var map = new Array(0x10000);
  29730. for (var i = 0; i <= 0xffff; i++) {
  29731. map[i] = i;
  29732. }
  29733. return map;
  29734. },
  29735. readCharCode: CMap.prototype.readCharCode,
  29736. get length() {
  29737. return 0x10000;
  29738. },
  29739. get isIdentityCMap() {
  29740. error('should not access .isIdentityCMap');
  29741. }
  29742. };
  29743. return IdentityCMap;
  29744. })();
  29745. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  29746. function fetchBinaryData(url) {
  29747. return new Promise(function (resolve, reject) {
  29748. var request = new XMLHttpRequest();
  29749. request.open('GET', url, true);
  29750. request.responseType = 'arraybuffer';
  29751. request.onreadystatechange = function () {
  29752. if (request.readyState === XMLHttpRequest.DONE) {
  29753. if (!request.response || request.status !== 200 &&
  29754. request.status !== 0) {
  29755. reject(new Error('Unable to get binary cMap at: ' + url));
  29756. } else {
  29757. resolve(new Uint8Array(request.response));
  29758. }
  29759. }
  29760. };
  29761. request.send(null);
  29762. });
  29763. }
  29764. function hexToInt(a, size) {
  29765. var n = 0;
  29766. for (var i = 0; i <= size; i++) {
  29767. n = (n << 8) | a[i];
  29768. }
  29769. return n >>> 0;
  29770. }
  29771. function hexToStr(a, size) {
  29772. // This code is hot. Special-case some common values to avoid creating an
  29773. // object with subarray().
  29774. if (size === 1) {
  29775. return String.fromCharCode(a[0], a[1]);
  29776. }
  29777. if (size === 3) {
  29778. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  29779. }
  29780. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  29781. }
  29782. function addHex(a, b, size) {
  29783. var c = 0;
  29784. for (var i = size; i >= 0; i--) {
  29785. c += a[i] + b[i];
  29786. a[i] = c & 255;
  29787. c >>= 8;
  29788. }
  29789. }
  29790. function incHex(a, size) {
  29791. var c = 1;
  29792. for (var i = size; i >= 0 && c > 0; i--) {
  29793. c += a[i];
  29794. a[i] = c & 255;
  29795. c >>= 8;
  29796. }
  29797. }
  29798. var MAX_NUM_SIZE = 16;
  29799. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  29800. function BinaryCMapStream(data) {
  29801. this.buffer = data;
  29802. this.pos = 0;
  29803. this.end = data.length;
  29804. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  29805. }
  29806. BinaryCMapStream.prototype = {
  29807. readByte: function () {
  29808. if (this.pos >= this.end) {
  29809. return -1;
  29810. }
  29811. return this.buffer[this.pos++];
  29812. },
  29813. readNumber: function () {
  29814. var n = 0;
  29815. var last;
  29816. do {
  29817. var b = this.readByte();
  29818. if (b < 0) {
  29819. error('unexpected EOF in bcmap');
  29820. }
  29821. last = !(b & 0x80);
  29822. n = (n << 7) | (b & 0x7F);
  29823. } while (!last);
  29824. return n;
  29825. },
  29826. readSigned: function () {
  29827. var n = this.readNumber();
  29828. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  29829. },
  29830. readHex: function (num, size) {
  29831. num.set(this.buffer.subarray(this.pos,
  29832. this.pos + size + 1));
  29833. this.pos += size + 1;
  29834. },
  29835. readHexNumber: function (num, size) {
  29836. var last;
  29837. var stack = this.tmpBuf, sp = 0;
  29838. do {
  29839. var b = this.readByte();
  29840. if (b < 0) {
  29841. error('unexpected EOF in bcmap');
  29842. }
  29843. last = !(b & 0x80);
  29844. stack[sp++] = b & 0x7F;
  29845. } while (!last);
  29846. var i = size, buffer = 0, bufferSize = 0;
  29847. while (i >= 0) {
  29848. while (bufferSize < 8 && stack.length > 0) {
  29849. buffer = (stack[--sp] << bufferSize) | buffer;
  29850. bufferSize += 7;
  29851. }
  29852. num[i] = buffer & 255;
  29853. i--;
  29854. buffer >>= 8;
  29855. bufferSize -= 8;
  29856. }
  29857. },
  29858. readHexSigned: function (num, size) {
  29859. this.readHexNumber(num, size);
  29860. var sign = num[size] & 1 ? 255 : 0;
  29861. var c = 0;
  29862. for (var i = 0; i <= size; i++) {
  29863. c = ((c & 1) << 8) | num[i];
  29864. num[i] = (c >> 1) ^ sign;
  29865. }
  29866. },
  29867. readString: function () {
  29868. var len = this.readNumber();
  29869. var s = '';
  29870. for (var i = 0; i < len; i++) {
  29871. s += String.fromCharCode(this.readNumber());
  29872. }
  29873. return s;
  29874. }
  29875. };
  29876. function processBinaryCMap(url, cMap, extend) {
  29877. return fetchBinaryData(url).then(function (data) {
  29878. var stream = new BinaryCMapStream(data);
  29879. var header = stream.readByte();
  29880. cMap.vertical = !!(header & 1);
  29881. var useCMap = null;
  29882. var start = new Uint8Array(MAX_NUM_SIZE);
  29883. var end = new Uint8Array(MAX_NUM_SIZE);
  29884. var char = new Uint8Array(MAX_NUM_SIZE);
  29885. var charCode = new Uint8Array(MAX_NUM_SIZE);
  29886. var tmp = new Uint8Array(MAX_NUM_SIZE);
  29887. var code;
  29888. var b;
  29889. while ((b = stream.readByte()) >= 0) {
  29890. var type = b >> 5;
  29891. if (type === 7) { // metadata, e.g. comment or usecmap
  29892. switch (b & 0x1F) {
  29893. case 0:
  29894. stream.readString(); // skipping comment
  29895. break;
  29896. case 1:
  29897. useCMap = stream.readString();
  29898. break;
  29899. }
  29900. continue;
  29901. }
  29902. var sequence = !!(b & 0x10);
  29903. var dataSize = b & 15;
  29904. assert(dataSize + 1 <= MAX_NUM_SIZE);
  29905. var ucs2DataSize = 1;
  29906. var subitemsCount = stream.readNumber();
  29907. var i;
  29908. switch (type) {
  29909. case 0: // codespacerange
  29910. stream.readHex(start, dataSize);
  29911. stream.readHexNumber(end, dataSize);
  29912. addHex(end, start, dataSize);
  29913. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29914. hexToInt(end, dataSize));
  29915. for (i = 1; i < subitemsCount; i++) {
  29916. incHex(end, dataSize);
  29917. stream.readHexNumber(start, dataSize);
  29918. addHex(start, end, dataSize);
  29919. stream.readHexNumber(end, dataSize);
  29920. addHex(end, start, dataSize);
  29921. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29922. hexToInt(end, dataSize));
  29923. }
  29924. break;
  29925. case 1: // notdefrange
  29926. stream.readHex(start, dataSize);
  29927. stream.readHexNumber(end, dataSize);
  29928. addHex(end, start, dataSize);
  29929. code = stream.readNumber();
  29930. // undefined range, skipping
  29931. for (i = 1; i < subitemsCount; i++) {
  29932. incHex(end, dataSize);
  29933. stream.readHexNumber(start, dataSize);
  29934. addHex(start, end, dataSize);
  29935. stream.readHexNumber(end, dataSize);
  29936. addHex(end, start, dataSize);
  29937. code = stream.readNumber();
  29938. // nop
  29939. }
  29940. break;
  29941. case 2: // cidchar
  29942. stream.readHex(char, dataSize);
  29943. code = stream.readNumber();
  29944. cMap.mapOne(hexToInt(char, dataSize), code);
  29945. for (i = 1; i < subitemsCount; i++) {
  29946. incHex(char, dataSize);
  29947. if (!sequence) {
  29948. stream.readHexNumber(tmp, dataSize);
  29949. addHex(char, tmp, dataSize);
  29950. }
  29951. code = stream.readSigned() + (code + 1);
  29952. cMap.mapOne(hexToInt(char, dataSize), code);
  29953. }
  29954. break;
  29955. case 3: // cidrange
  29956. stream.readHex(start, dataSize);
  29957. stream.readHexNumber(end, dataSize);
  29958. addHex(end, start, dataSize);
  29959. code = stream.readNumber();
  29960. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29961. code);
  29962. for (i = 1; i < subitemsCount; i++) {
  29963. incHex(end, dataSize);
  29964. if (!sequence) {
  29965. stream.readHexNumber(start, dataSize);
  29966. addHex(start, end, dataSize);
  29967. } else {
  29968. start.set(end);
  29969. }
  29970. stream.readHexNumber(end, dataSize);
  29971. addHex(end, start, dataSize);
  29972. code = stream.readNumber();
  29973. cMap.mapCidRange(hexToInt(start, dataSize),
  29974. hexToInt(end, dataSize), code);
  29975. }
  29976. break;
  29977. case 4: // bfchar
  29978. stream.readHex(char, ucs2DataSize);
  29979. stream.readHex(charCode, dataSize);
  29980. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29981. hexToStr(charCode, dataSize));
  29982. for (i = 1; i < subitemsCount; i++) {
  29983. incHex(char, ucs2DataSize);
  29984. if (!sequence) {
  29985. stream.readHexNumber(tmp, ucs2DataSize);
  29986. addHex(char, tmp, ucs2DataSize);
  29987. }
  29988. incHex(charCode, dataSize);
  29989. stream.readHexSigned(tmp, dataSize);
  29990. addHex(charCode, tmp, dataSize);
  29991. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29992. hexToStr(charCode, dataSize));
  29993. }
  29994. break;
  29995. case 5: // bfrange
  29996. stream.readHex(start, ucs2DataSize);
  29997. stream.readHexNumber(end, ucs2DataSize);
  29998. addHex(end, start, ucs2DataSize);
  29999. stream.readHex(charCode, dataSize);
  30000. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  30001. hexToInt(end, ucs2DataSize),
  30002. hexToStr(charCode, dataSize));
  30003. for (i = 1; i < subitemsCount; i++) {
  30004. incHex(end, ucs2DataSize);
  30005. if (!sequence) {
  30006. stream.readHexNumber(start, ucs2DataSize);
  30007. addHex(start, end, ucs2DataSize);
  30008. } else {
  30009. start.set(end);
  30010. }
  30011. stream.readHexNumber(end, ucs2DataSize);
  30012. addHex(end, start, ucs2DataSize);
  30013. stream.readHex(charCode, dataSize);
  30014. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  30015. hexToInt(end, ucs2DataSize),
  30016. hexToStr(charCode, dataSize));
  30017. }
  30018. break;
  30019. default:
  30020. error('Unknown type: ' + type);
  30021. break;
  30022. }
  30023. }
  30024. if (useCMap) {
  30025. return extend(useCMap);
  30026. }
  30027. return cMap;
  30028. });
  30029. }
  30030. function BinaryCMapReader() {}
  30031. BinaryCMapReader.prototype = {
  30032. read: processBinaryCMap
  30033. };
  30034. return BinaryCMapReader;
  30035. })();
  30036. var CMapFactory = (function CMapFactoryClosure() {
  30037. function strToInt(str) {
  30038. var a = 0;
  30039. for (var i = 0; i < str.length; i++) {
  30040. a = (a << 8) | str.charCodeAt(i);
  30041. }
  30042. return a >>> 0;
  30043. }
  30044. function expectString(obj) {
  30045. if (!isString(obj)) {
  30046. error('Malformed CMap: expected string.');
  30047. }
  30048. }
  30049. function expectInt(obj) {
  30050. if (!isInt(obj)) {
  30051. error('Malformed CMap: expected int.');
  30052. }
  30053. }
  30054. function parseBfChar(cMap, lexer) {
  30055. while (true) {
  30056. var obj = lexer.getObj();
  30057. if (isEOF(obj)) {
  30058. break;
  30059. }
  30060. if (isCmd(obj, 'endbfchar')) {
  30061. return;
  30062. }
  30063. expectString(obj);
  30064. var src = strToInt(obj);
  30065. obj = lexer.getObj();
  30066. // TODO are /dstName used?
  30067. expectString(obj);
  30068. var dst = obj;
  30069. cMap.mapOne(src, dst);
  30070. }
  30071. }
  30072. function parseBfRange(cMap, lexer) {
  30073. while (true) {
  30074. var obj = lexer.getObj();
  30075. if (isEOF(obj)) {
  30076. break;
  30077. }
  30078. if (isCmd(obj, 'endbfrange')) {
  30079. return;
  30080. }
  30081. expectString(obj);
  30082. var low = strToInt(obj);
  30083. obj = lexer.getObj();
  30084. expectString(obj);
  30085. var high = strToInt(obj);
  30086. obj = lexer.getObj();
  30087. if (isInt(obj) || isString(obj)) {
  30088. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  30089. cMap.mapBfRange(low, high, dstLow);
  30090. } else if (isCmd(obj, '[')) {
  30091. obj = lexer.getObj();
  30092. var array = [];
  30093. while (!isCmd(obj, ']') && !isEOF(obj)) {
  30094. array.push(obj);
  30095. obj = lexer.getObj();
  30096. }
  30097. cMap.mapBfRangeToArray(low, high, array);
  30098. } else {
  30099. break;
  30100. }
  30101. }
  30102. error('Invalid bf range.');
  30103. }
  30104. function parseCidChar(cMap, lexer) {
  30105. while (true) {
  30106. var obj = lexer.getObj();
  30107. if (isEOF(obj)) {
  30108. break;
  30109. }
  30110. if (isCmd(obj, 'endcidchar')) {
  30111. return;
  30112. }
  30113. expectString(obj);
  30114. var src = strToInt(obj);
  30115. obj = lexer.getObj();
  30116. expectInt(obj);
  30117. var dst = obj;
  30118. cMap.mapOne(src, dst);
  30119. }
  30120. }
  30121. function parseCidRange(cMap, lexer) {
  30122. while (true) {
  30123. var obj = lexer.getObj();
  30124. if (isEOF(obj)) {
  30125. break;
  30126. }
  30127. if (isCmd(obj, 'endcidrange')) {
  30128. return;
  30129. }
  30130. expectString(obj);
  30131. var low = strToInt(obj);
  30132. obj = lexer.getObj();
  30133. expectString(obj);
  30134. var high = strToInt(obj);
  30135. obj = lexer.getObj();
  30136. expectInt(obj);
  30137. var dstLow = obj;
  30138. cMap.mapCidRange(low, high, dstLow);
  30139. }
  30140. }
  30141. function parseCodespaceRange(cMap, lexer) {
  30142. while (true) {
  30143. var obj = lexer.getObj();
  30144. if (isEOF(obj)) {
  30145. break;
  30146. }
  30147. if (isCmd(obj, 'endcodespacerange')) {
  30148. return;
  30149. }
  30150. if (!isString(obj)) {
  30151. break;
  30152. }
  30153. var low = strToInt(obj);
  30154. obj = lexer.getObj();
  30155. if (!isString(obj)) {
  30156. break;
  30157. }
  30158. var high = strToInt(obj);
  30159. cMap.addCodespaceRange(obj.length, low, high);
  30160. }
  30161. error('Invalid codespace range.');
  30162. }
  30163. function parseWMode(cMap, lexer) {
  30164. var obj = lexer.getObj();
  30165. if (isInt(obj)) {
  30166. cMap.vertical = !!obj;
  30167. }
  30168. }
  30169. function parseCMapName(cMap, lexer) {
  30170. var obj = lexer.getObj();
  30171. if (isName(obj) && isString(obj.name)) {
  30172. cMap.name = obj.name;
  30173. }
  30174. }
  30175. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  30176. var previous;
  30177. var embededUseCMap;
  30178. objLoop: while (true) {
  30179. try {
  30180. var obj = lexer.getObj();
  30181. if (isEOF(obj)) {
  30182. break;
  30183. } else if (isName(obj)) {
  30184. if (obj.name === 'WMode') {
  30185. parseWMode(cMap, lexer);
  30186. } else if (obj.name === 'CMapName') {
  30187. parseCMapName(cMap, lexer);
  30188. }
  30189. previous = obj;
  30190. } else if (isCmd(obj)) {
  30191. switch (obj.cmd) {
  30192. case 'endcmap':
  30193. break objLoop;
  30194. case 'usecmap':
  30195. if (isName(previous)) {
  30196. embededUseCMap = previous.name;
  30197. }
  30198. break;
  30199. case 'begincodespacerange':
  30200. parseCodespaceRange(cMap, lexer);
  30201. break;
  30202. case 'beginbfchar':
  30203. parseBfChar(cMap, lexer);
  30204. break;
  30205. case 'begincidchar':
  30206. parseCidChar(cMap, lexer);
  30207. break;
  30208. case 'beginbfrange':
  30209. parseBfRange(cMap, lexer);
  30210. break;
  30211. case 'begincidrange':
  30212. parseCidRange(cMap, lexer);
  30213. break;
  30214. }
  30215. }
  30216. } catch (ex) {
  30217. if (ex instanceof MissingDataException) {
  30218. throw ex;
  30219. }
  30220. warn('Invalid cMap data: ' + ex);
  30221. continue;
  30222. }
  30223. }
  30224. if (!useCMap && embededUseCMap) {
  30225. // Load the usecmap definition from the file only if there wasn't one
  30226. // specified.
  30227. useCMap = embededUseCMap;
  30228. }
  30229. if (useCMap) {
  30230. return extendCMap(cMap, builtInCMapParams, useCMap);
  30231. }
  30232. return Promise.resolve(cMap);
  30233. }
  30234. function extendCMap(cMap, builtInCMapParams, useCMap) {
  30235. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  30236. function(newCMap) {
  30237. cMap.useCMap = newCMap;
  30238. // If there aren't any code space ranges defined clone all the parent ones
  30239. // into this cMap.
  30240. if (cMap.numCodespaceRanges === 0) {
  30241. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  30242. for (var i = 0; i < useCodespaceRanges.length; i++) {
  30243. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  30244. }
  30245. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  30246. }
  30247. // Merge the map into the current one, making sure not to override
  30248. // any previously defined entries.
  30249. cMap.useCMap.forEach(function(key, value) {
  30250. if (!cMap.contains(key)) {
  30251. cMap.mapOne(key, cMap.useCMap.lookup(key));
  30252. }
  30253. });
  30254. return cMap;
  30255. });
  30256. }
  30257. function parseBinaryCMap(name, builtInCMapParams) {
  30258. var url = builtInCMapParams.url + name + '.bcmap';
  30259. var cMap = new CMap(true);
  30260. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  30261. return extendCMap(cMap, builtInCMapParams, useCMap);
  30262. });
  30263. }
  30264. function createBuiltInCMap(name, builtInCMapParams) {
  30265. if (name === 'Identity-H') {
  30266. return Promise.resolve(new IdentityCMap(false, 2));
  30267. } else if (name === 'Identity-V') {
  30268. return Promise.resolve(new IdentityCMap(true, 2));
  30269. }
  30270. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  30271. return Promise.reject(new Error('Unknown cMap name: ' + name));
  30272. }
  30273. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  30274. if (builtInCMapParams.packed) {
  30275. return parseBinaryCMap(name, builtInCMapParams);
  30276. }
  30277. return new Promise(function (resolve, reject) {
  30278. var url = builtInCMapParams.url + name;
  30279. var request = new XMLHttpRequest();
  30280. request.onreadystatechange = function () {
  30281. if (request.readyState === XMLHttpRequest.DONE) {
  30282. if (request.status === 200 || request.status === 0) {
  30283. var cMap = new CMap(true);
  30284. var lexer = new Lexer(new StringStream(request.responseText));
  30285. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  30286. function (parsedCMap) {
  30287. resolve(parsedCMap);
  30288. });
  30289. } else {
  30290. reject(new Error('Unable to get cMap at: ' + url));
  30291. }
  30292. }
  30293. };
  30294. request.open('GET', url, true);
  30295. request.send(null);
  30296. });
  30297. }
  30298. return {
  30299. create: function (encoding, builtInCMapParams, useCMap) {
  30300. if (isName(encoding)) {
  30301. return createBuiltInCMap(encoding.name, builtInCMapParams);
  30302. } else if (isStream(encoding)) {
  30303. var cMap = new CMap();
  30304. var lexer = new Lexer(encoding);
  30305. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  30306. function (parsedCMap) {
  30307. if (parsedCMap.isIdentityCMap) {
  30308. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  30309. }
  30310. return parsedCMap;
  30311. });
  30312. }
  30313. return Promise.reject(new Error('Encoding required.'));
  30314. }
  30315. };
  30316. })();
  30317. exports.CMap = CMap;
  30318. exports.CMapFactory = CMapFactory;
  30319. exports.IdentityCMap = IdentityCMap;
  30320. }));
  30321. (function (root, factory) {
  30322. {
  30323. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  30324. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList,
  30325. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  30326. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  30327. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  30328. }
  30329. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  30330. coreGlyphList, coreFontRenderer, coreEncodings,
  30331. coreStandardFonts, coreUnicode, coreType1Parser,
  30332. coreCFFParser) {
  30333. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  30334. var FontType = sharedUtil.FontType;
  30335. var assert = sharedUtil.assert;
  30336. var bytesToString = sharedUtil.bytesToString;
  30337. var error = sharedUtil.error;
  30338. var info = sharedUtil.info;
  30339. var isArray = sharedUtil.isArray;
  30340. var isInt = sharedUtil.isInt;
  30341. var isNum = sharedUtil.isNum;
  30342. var readUint32 = sharedUtil.readUint32;
  30343. var shadow = sharedUtil.shadow;
  30344. var string32 = sharedUtil.string32;
  30345. var warn = sharedUtil.warn;
  30346. var MissingDataException = sharedUtil.MissingDataException;
  30347. var isSpace = sharedUtil.isSpace;
  30348. var Stream = coreStream.Stream;
  30349. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  30350. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  30351. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  30352. var StandardEncoding = coreEncodings.StandardEncoding;
  30353. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  30354. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  30355. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  30356. var getEncoding = coreEncodings.getEncoding;
  30357. var getStdFontMap = coreStandardFonts.getStdFontMap;
  30358. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  30359. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  30360. var getSupplementalGlyphMapForArialBlack =
  30361. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  30362. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  30363. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  30364. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  30365. var Type1Parser = coreType1Parser.Type1Parser;
  30366. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  30367. var CFFParser = coreCFFParser.CFFParser;
  30368. var CFFCompiler = coreCFFParser.CFFCompiler;
  30369. var CFF = coreCFFParser.CFF;
  30370. var CFFHeader = coreCFFParser.CFFHeader;
  30371. var CFFTopDict = coreCFFParser.CFFTopDict;
  30372. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  30373. var CFFStrings = coreCFFParser.CFFStrings;
  30374. var CFFIndex = coreCFFParser.CFFIndex;
  30375. var CFFCharset = coreCFFParser.CFFCharset;
  30376. // Unicode Private Use Area
  30377. var PRIVATE_USE_OFFSET_START = 0xE000;
  30378. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  30379. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  30380. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  30381. // except for Type 3 fonts
  30382. var PDF_GLYPH_SPACE_UNITS = 1000;
  30383. // Accented charactars are not displayed properly on Windows, using this flag
  30384. // to control analysis of seac charstrings.
  30385. var SEAC_ANALYSIS_ENABLED = false;
  30386. var FontFlags = {
  30387. FixedPitch: 1,
  30388. Serif: 2,
  30389. Symbolic: 4,
  30390. Script: 8,
  30391. Nonsymbolic: 32,
  30392. Italic: 64,
  30393. AllCap: 65536,
  30394. SmallCap: 131072,
  30395. ForceBold: 262144
  30396. };
  30397. var MacStandardGlyphOrdering = [
  30398. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  30399. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  30400. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  30401. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  30402. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  30403. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  30404. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  30405. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  30406. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  30407. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  30408. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  30409. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  30410. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30411. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  30412. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  30413. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  30414. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  30415. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  30416. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  30417. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  30418. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  30419. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  30420. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  30421. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  30422. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  30423. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  30424. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  30425. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  30426. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  30427. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  30428. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  30429. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  30430. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  30431. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  30432. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  30433. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  30434. function adjustWidths(properties) {
  30435. if (!properties.fontMatrix) {
  30436. return;
  30437. }
  30438. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  30439. return;
  30440. }
  30441. // adjusting width to fontMatrix scale
  30442. var scale = 0.001 / properties.fontMatrix[0];
  30443. var glyphsWidths = properties.widths;
  30444. for (var glyph in glyphsWidths) {
  30445. glyphsWidths[glyph] *= scale;
  30446. }
  30447. properties.defaultWidth *= scale;
  30448. }
  30449. function adjustToUnicode(properties, builtInEncoding) {
  30450. if (properties.hasIncludedToUnicodeMap) {
  30451. return; // The font dictionary has a `ToUnicode` entry.
  30452. }
  30453. if (properties.hasEncoding) {
  30454. return; // The font dictionary has an `Encoding` entry.
  30455. }
  30456. if (builtInEncoding === properties.defaultEncoding) {
  30457. return; // No point in trying to adjust `toUnicode` if the encodings match.
  30458. }
  30459. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  30460. return;
  30461. }
  30462. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  30463. for (var charCode in builtInEncoding) {
  30464. var glyphName = builtInEncoding[charCode];
  30465. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  30466. if (unicode !== -1) {
  30467. toUnicode[charCode] = String.fromCharCode(unicode);
  30468. }
  30469. }
  30470. properties.toUnicode.amend(toUnicode);
  30471. }
  30472. function getFontType(type, subtype) {
  30473. switch (type) {
  30474. case 'Type1':
  30475. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  30476. case 'CIDFontType0':
  30477. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  30478. FontType.CIDFONTTYPE0;
  30479. case 'OpenType':
  30480. return FontType.OPENTYPE;
  30481. case 'TrueType':
  30482. return FontType.TRUETYPE;
  30483. case 'CIDFontType2':
  30484. return FontType.CIDFONTTYPE2;
  30485. case 'MMType1':
  30486. return FontType.MMTYPE1;
  30487. case 'Type0':
  30488. return FontType.TYPE0;
  30489. default:
  30490. return FontType.UNKNOWN;
  30491. }
  30492. }
  30493. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  30494. // in a 'uniXXXX' format -- attempting to recover proper ones.
  30495. function recoverGlyphName(name, glyphsUnicodeMap) {
  30496. if (glyphsUnicodeMap[name] !== undefined) {
  30497. return name;
  30498. }
  30499. // The glyph name is non-standard, trying to recover.
  30500. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  30501. if (unicode !== -1) {
  30502. for (var key in glyphsUnicodeMap) {
  30503. if (glyphsUnicodeMap[key] === unicode) {
  30504. return key;
  30505. }
  30506. }
  30507. }
  30508. info('Unable to recover a standard glyph name for: ' + name);
  30509. return name;
  30510. }
  30511. var Glyph = (function GlyphClosure() {
  30512. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  30513. isSpace, isInFont) {
  30514. this.fontChar = fontChar;
  30515. this.unicode = unicode;
  30516. this.accent = accent;
  30517. this.width = width;
  30518. this.vmetric = vmetric;
  30519. this.operatorListId = operatorListId;
  30520. this.isSpace = isSpace;
  30521. this.isInFont = isInFont;
  30522. }
  30523. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  30524. vmetric, operatorListId, isSpace,
  30525. isInFont) {
  30526. return this.fontChar === fontChar &&
  30527. this.unicode === unicode &&
  30528. this.accent === accent &&
  30529. this.width === width &&
  30530. this.vmetric === vmetric &&
  30531. this.operatorListId === operatorListId &&
  30532. this.isSpace === isSpace &&
  30533. this.isInFont === isInFont;
  30534. };
  30535. return Glyph;
  30536. })();
  30537. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  30538. function ToUnicodeMap(cmap) {
  30539. // The elements of this._map can be integers or strings, depending on how
  30540. // |cmap| was created.
  30541. this._map = cmap;
  30542. }
  30543. ToUnicodeMap.prototype = {
  30544. get length() {
  30545. return this._map.length;
  30546. },
  30547. forEach: function(callback) {
  30548. for (var charCode in this._map) {
  30549. callback(charCode, this._map[charCode].charCodeAt(0));
  30550. }
  30551. },
  30552. has: function(i) {
  30553. return this._map[i] !== undefined;
  30554. },
  30555. get: function(i) {
  30556. return this._map[i];
  30557. },
  30558. charCodeOf: function(v) {
  30559. return this._map.indexOf(v);
  30560. },
  30561. amend: function (map) {
  30562. for (var charCode in map) {
  30563. this._map[charCode] = map[charCode];
  30564. }
  30565. },
  30566. };
  30567. return ToUnicodeMap;
  30568. })();
  30569. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  30570. function IdentityToUnicodeMap(firstChar, lastChar) {
  30571. this.firstChar = firstChar;
  30572. this.lastChar = lastChar;
  30573. }
  30574. IdentityToUnicodeMap.prototype = {
  30575. get length() {
  30576. return (this.lastChar + 1) - this.firstChar;
  30577. },
  30578. forEach: function (callback) {
  30579. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  30580. callback(i, i);
  30581. }
  30582. },
  30583. has: function (i) {
  30584. return this.firstChar <= i && i <= this.lastChar;
  30585. },
  30586. get: function (i) {
  30587. if (this.firstChar <= i && i <= this.lastChar) {
  30588. return String.fromCharCode(i);
  30589. }
  30590. return undefined;
  30591. },
  30592. charCodeOf: function (v) {
  30593. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  30594. },
  30595. amend: function (map) {
  30596. error('Should not call amend()');
  30597. },
  30598. };
  30599. return IdentityToUnicodeMap;
  30600. })();
  30601. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  30602. function writeInt16(dest, offset, num) {
  30603. dest[offset] = (num >> 8) & 0xFF;
  30604. dest[offset + 1] = num & 0xFF;
  30605. }
  30606. function writeInt32(dest, offset, num) {
  30607. dest[offset] = (num >> 24) & 0xFF;
  30608. dest[offset + 1] = (num >> 16) & 0xFF;
  30609. dest[offset + 2] = (num >> 8) & 0xFF;
  30610. dest[offset + 3] = num & 0xFF;
  30611. }
  30612. function writeData(dest, offset, data) {
  30613. var i, ii;
  30614. if (data instanceof Uint8Array) {
  30615. dest.set(data, offset);
  30616. } else if (typeof data === 'string') {
  30617. for (i = 0, ii = data.length; i < ii; i++) {
  30618. dest[offset++] = data.charCodeAt(i) & 0xFF;
  30619. }
  30620. } else {
  30621. // treating everything else as array
  30622. for (i = 0, ii = data.length; i < ii; i++) {
  30623. dest[offset++] = data[i] & 0xFF;
  30624. }
  30625. }
  30626. }
  30627. function OpenTypeFileBuilder(sfnt) {
  30628. this.sfnt = sfnt;
  30629. this.tables = Object.create(null);
  30630. }
  30631. OpenTypeFileBuilder.getSearchParams =
  30632. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  30633. var maxPower2 = 1, log2 = 0;
  30634. while ((maxPower2 ^ entriesCount) > maxPower2) {
  30635. maxPower2 <<= 1;
  30636. log2++;
  30637. }
  30638. var searchRange = maxPower2 * entrySize;
  30639. return {
  30640. range: searchRange,
  30641. entry: log2,
  30642. rangeShift: entrySize * entriesCount - searchRange
  30643. };
  30644. };
  30645. var OTF_HEADER_SIZE = 12;
  30646. var OTF_TABLE_ENTRY_SIZE = 16;
  30647. OpenTypeFileBuilder.prototype = {
  30648. toArray: function OpenTypeFileBuilder_toArray() {
  30649. var sfnt = this.sfnt;
  30650. // Tables needs to be written by ascendant alphabetic order
  30651. var tables = this.tables;
  30652. var tablesNames = Object.keys(tables);
  30653. tablesNames.sort();
  30654. var numTables = tablesNames.length;
  30655. var i, j, jj, table, tableName;
  30656. // layout the tables data
  30657. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  30658. var tableOffsets = [offset];
  30659. for (i = 0; i < numTables; i++) {
  30660. table = tables[tablesNames[i]];
  30661. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  30662. offset += paddedLength;
  30663. tableOffsets.push(offset);
  30664. }
  30665. var file = new Uint8Array(offset);
  30666. // write the table data first (mostly for checksum)
  30667. for (i = 0; i < numTables; i++) {
  30668. table = tables[tablesNames[i]];
  30669. writeData(file, tableOffsets[i], table);
  30670. }
  30671. // sfnt version (4 bytes)
  30672. if (sfnt === 'true') {
  30673. // Windows hates the Mac TrueType sfnt version number
  30674. sfnt = string32(0x00010000);
  30675. }
  30676. file[0] = sfnt.charCodeAt(0) & 0xFF;
  30677. file[1] = sfnt.charCodeAt(1) & 0xFF;
  30678. file[2] = sfnt.charCodeAt(2) & 0xFF;
  30679. file[3] = sfnt.charCodeAt(3) & 0xFF;
  30680. // numTables (2 bytes)
  30681. writeInt16(file, 4, numTables);
  30682. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  30683. // searchRange (2 bytes)
  30684. writeInt16(file, 6, searchParams.range);
  30685. // entrySelector (2 bytes)
  30686. writeInt16(file, 8, searchParams.entry);
  30687. // rangeShift (2 bytes)
  30688. writeInt16(file, 10, searchParams.rangeShift);
  30689. offset = OTF_HEADER_SIZE;
  30690. // writing table entries
  30691. for (i = 0; i < numTables; i++) {
  30692. tableName = tablesNames[i];
  30693. file[offset] = tableName.charCodeAt(0) & 0xFF;
  30694. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  30695. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  30696. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  30697. // checksum
  30698. var checksum = 0;
  30699. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  30700. var quad = readUint32(file, j);
  30701. checksum = (checksum + quad) >>> 0;
  30702. }
  30703. writeInt32(file, offset + 4, checksum);
  30704. // offset
  30705. writeInt32(file, offset + 8, tableOffsets[i]);
  30706. // length
  30707. writeInt32(file, offset + 12, tables[tableName].length);
  30708. offset += OTF_TABLE_ENTRY_SIZE;
  30709. }
  30710. return file;
  30711. },
  30712. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  30713. if (tag in this.tables) {
  30714. throw new Error('Table ' + tag + ' already exists');
  30715. }
  30716. this.tables[tag] = data;
  30717. }
  30718. };
  30719. return OpenTypeFileBuilder;
  30720. })();
  30721. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  30722. // issues when they are painted on the canvas, e.g. complex-script shaping or
  30723. // control/whitespace characters. The ranges are listed in pairs: the first item
  30724. // is a code of the first problematic code, the second one is the next
  30725. // non-problematic code. The ranges must be in sorted order.
  30726. var ProblematicCharRanges = new Int32Array([
  30727. // Control characters.
  30728. 0x0000, 0x0020,
  30729. 0x007F, 0x00A1,
  30730. 0x00AD, 0x00AE,
  30731. // Chars that is used in complex-script shaping.
  30732. 0x0600, 0x0780,
  30733. 0x08A0, 0x10A0,
  30734. 0x1780, 0x1800,
  30735. 0x1C00, 0x1C50,
  30736. // General punctuation chars.
  30737. 0x2000, 0x2010,
  30738. 0x2011, 0x2012,
  30739. 0x2028, 0x2030,
  30740. 0x205F, 0x2070,
  30741. 0x25CC, 0x25CD,
  30742. 0x3000, 0x3001,
  30743. // Chars that is used in complex-script shaping.
  30744. 0xAA60, 0xAA80,
  30745. // Specials Unicode block.
  30746. 0xFFF0, 0x10000
  30747. ]);
  30748. /**
  30749. * 'Font' is the class the outside world should use, it encapsulate all the font
  30750. * decoding logics whatever type it is (assuming the font type is supported).
  30751. *
  30752. * For example to read a Type1 font and to attach it to the document:
  30753. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  30754. * type1Font.bind();
  30755. */
  30756. var Font = (function FontClosure() {
  30757. function Font(name, file, properties) {
  30758. var charCode, glyphName, unicode;
  30759. this.name = name;
  30760. this.loadedName = properties.loadedName;
  30761. this.isType3Font = properties.isType3Font;
  30762. this.sizes = [];
  30763. this.missingFile = false;
  30764. this.glyphCache = Object.create(null);
  30765. var names = name.split('+');
  30766. names = names.length > 1 ? names[1] : names[0];
  30767. names = names.split(/[-,_]/g)[0];
  30768. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  30769. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  30770. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  30771. var type = properties.type;
  30772. var subtype = properties.subtype;
  30773. this.type = type;
  30774. this.fallbackName = (this.isMonospace ? 'monospace' :
  30775. (this.isSerifFont ? 'serif' : 'sans-serif'));
  30776. this.differences = properties.differences;
  30777. this.widths = properties.widths;
  30778. this.defaultWidth = properties.defaultWidth;
  30779. this.composite = properties.composite;
  30780. this.wideChars = properties.wideChars;
  30781. this.cMap = properties.cMap;
  30782. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  30783. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  30784. this.fontMatrix = properties.fontMatrix;
  30785. this.bbox = properties.bbox;
  30786. this.toUnicode = properties.toUnicode;
  30787. this.toFontChar = [];
  30788. if (properties.type === 'Type3') {
  30789. for (charCode = 0; charCode < 256; charCode++) {
  30790. this.toFontChar[charCode] = (this.differences[charCode] ||
  30791. properties.defaultEncoding[charCode]);
  30792. }
  30793. this.fontType = FontType.TYPE3;
  30794. return;
  30795. }
  30796. this.cidEncoding = properties.cidEncoding;
  30797. this.vertical = properties.vertical;
  30798. if (this.vertical) {
  30799. this.vmetrics = properties.vmetrics;
  30800. this.defaultVMetrics = properties.defaultVMetrics;
  30801. }
  30802. var glyphsUnicodeMap;
  30803. if (!file || file.isEmpty) {
  30804. if (file) {
  30805. // Some bad PDF generators will include empty font files,
  30806. // attempting to recover by assuming that no file exists.
  30807. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  30808. }
  30809. this.missingFile = true;
  30810. // The file data is not specified. Trying to fix the font name
  30811. // to be used with the canvas.font.
  30812. var fontName = name.replace(/[,_]/g, '-');
  30813. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  30814. var isStandardFont = !!stdFontMap[fontName] ||
  30815. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  30816. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  30817. this.bold = (fontName.search(/bold/gi) !== -1);
  30818. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  30819. (fontName.search(/italic/gi) !== -1));
  30820. // Use 'name' instead of 'fontName' here because the original
  30821. // name ArialBlack for example will be replaced by Helvetica.
  30822. this.black = (name.search(/Black/g) !== -1);
  30823. // if at least one width is present, remeasure all chars when exists
  30824. this.remeasure = Object.keys(this.widths).length > 0;
  30825. if (isStandardFont && type === 'CIDFontType2' &&
  30826. properties.cidEncoding.indexOf('Identity-') === 0) {
  30827. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  30828. // Standard fonts might be embedded as CID font without glyph mapping.
  30829. // Building one based on GlyphMapForStandardFonts.
  30830. var map = [];
  30831. for (charCode in GlyphMapForStandardFonts) {
  30832. map[+charCode] = GlyphMapForStandardFonts[charCode];
  30833. }
  30834. if (/ArialBlack/i.test(name)) {
  30835. var SupplementalGlyphMapForArialBlack =
  30836. getSupplementalGlyphMapForArialBlack();
  30837. for (charCode in SupplementalGlyphMapForArialBlack) {
  30838. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  30839. }
  30840. }
  30841. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  30842. if (!isIdentityUnicode) {
  30843. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  30844. map[+charCode] = unicodeCharCode;
  30845. });
  30846. }
  30847. this.toFontChar = map;
  30848. this.toUnicode = new ToUnicodeMap(map);
  30849. } else if (/Symbol/i.test(fontName)) {
  30850. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  30851. properties.differences);
  30852. } else if (/Dingbats/i.test(fontName)) {
  30853. if (/Wingdings/i.test(name)) {
  30854. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  30855. }
  30856. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  30857. getDingbatsGlyphsUnicode(),
  30858. properties.differences);
  30859. } else if (isStandardFont) {
  30860. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  30861. getGlyphsUnicode(),
  30862. properties.differences);
  30863. } else {
  30864. glyphsUnicodeMap = getGlyphsUnicode();
  30865. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  30866. if (!this.composite) {
  30867. glyphName = (properties.differences[charCode] ||
  30868. properties.defaultEncoding[charCode]);
  30869. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  30870. if (unicode !== -1) {
  30871. unicodeCharCode = unicode;
  30872. }
  30873. }
  30874. this.toFontChar[charCode] = unicodeCharCode;
  30875. }.bind(this));
  30876. }
  30877. this.loadedName = fontName.split('-')[0];
  30878. this.loading = false;
  30879. this.fontType = getFontType(type, subtype);
  30880. return;
  30881. }
  30882. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  30883. if (subtype === 'Type1C') {
  30884. if (type !== 'Type1' && type !== 'MMType1') {
  30885. // Some TrueType fonts by mistake claim Type1C
  30886. if (isTrueTypeFile(file)) {
  30887. subtype = 'TrueType';
  30888. } else {
  30889. type = 'Type1';
  30890. }
  30891. } else if (isOpenTypeFile(file)) {
  30892. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  30893. type = subtype = 'OpenType';
  30894. }
  30895. }
  30896. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  30897. type = 'CIDFontType0';
  30898. }
  30899. if (subtype === 'OpenType') {
  30900. type = 'OpenType';
  30901. }
  30902. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  30903. if (type === 'CIDFontType0') {
  30904. if (isType1File(file)) {
  30905. subtype = 'CIDFontType0';
  30906. } else if (isOpenTypeFile(file)) {
  30907. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  30908. type = subtype = 'OpenType';
  30909. } else {
  30910. subtype = 'CIDFontType0C';
  30911. }
  30912. }
  30913. var data;
  30914. switch (type) {
  30915. case 'MMType1':
  30916. info('MMType1 font (' + name + '), falling back to Type1.');
  30917. /* falls through */
  30918. case 'Type1':
  30919. case 'CIDFontType0':
  30920. this.mimetype = 'font/opentype';
  30921. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  30922. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  30923. adjustWidths(properties);
  30924. // Wrap the CFF data inside an OTF font file
  30925. data = this.convert(name, cff, properties);
  30926. break;
  30927. case 'OpenType':
  30928. case 'TrueType':
  30929. case 'CIDFontType2':
  30930. this.mimetype = 'font/opentype';
  30931. // Repair the TrueType file. It is can be damaged in the point of
  30932. // view of the sanitizer
  30933. data = this.checkAndRepair(name, file, properties);
  30934. if (this.isOpenType) {
  30935. adjustWidths(properties);
  30936. type = 'OpenType';
  30937. }
  30938. break;
  30939. default:
  30940. error('Font ' + type + ' is not supported');
  30941. break;
  30942. }
  30943. this.data = data;
  30944. this.fontType = getFontType(type, subtype);
  30945. // Transfer some properties again that could change during font conversion
  30946. this.fontMatrix = properties.fontMatrix;
  30947. this.widths = properties.widths;
  30948. this.defaultWidth = properties.defaultWidth;
  30949. this.toUnicode = properties.toUnicode;
  30950. this.encoding = properties.baseEncoding;
  30951. this.seacMap = properties.seacMap;
  30952. this.loading = true;
  30953. }
  30954. Font.getFontID = (function () {
  30955. var ID = 1;
  30956. return function Font_getFontID() {
  30957. return String(ID++);
  30958. };
  30959. })();
  30960. function int16(b0, b1) {
  30961. return (b0 << 8) + b1;
  30962. }
  30963. function signedInt16(b0, b1) {
  30964. var value = (b0 << 8) + b1;
  30965. return value & (1 << 15) ? value - 0x10000 : value;
  30966. }
  30967. function int32(b0, b1, b2, b3) {
  30968. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  30969. }
  30970. function string16(value) {
  30971. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  30972. }
  30973. function safeString16(value) {
  30974. // clamp value to the 16-bit int range
  30975. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  30976. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  30977. }
  30978. function isTrueTypeFile(file) {
  30979. var header = file.peekBytes(4);
  30980. return readUint32(header, 0) === 0x00010000;
  30981. }
  30982. function isOpenTypeFile(file) {
  30983. var header = file.peekBytes(4);
  30984. return bytesToString(header) === 'OTTO';
  30985. }
  30986. function isType1File(file) {
  30987. var header = file.peekBytes(2);
  30988. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  30989. if (header[0] === 0x25 && header[1] === 0x21) {
  30990. return true;
  30991. }
  30992. // ... obviously some fonts violate that part of the specification,
  30993. // please refer to the comment in |Type1Font| below.
  30994. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  30995. return true;
  30996. }
  30997. return false;
  30998. }
  30999. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  31000. var toFontChar = [], unicode;
  31001. for (var i = 0, ii = encoding.length; i < ii; i++) {
  31002. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  31003. if (unicode !== -1) {
  31004. toFontChar[i] = unicode;
  31005. }
  31006. }
  31007. for (var charCode in differences) {
  31008. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  31009. if (unicode !== -1) {
  31010. toFontChar[+charCode] = unicode;
  31011. }
  31012. }
  31013. return toFontChar;
  31014. }
  31015. /**
  31016. * Helper function for |adjustMapping|.
  31017. * @return {boolean}
  31018. */
  31019. function isProblematicUnicodeLocation(code) {
  31020. // Using binary search to find a range start.
  31021. var i = 0, j = ProblematicCharRanges.length - 1;
  31022. while (i < j) {
  31023. var c = (i + j + 1) >> 1;
  31024. if (code < ProblematicCharRanges[c]) {
  31025. j = c - 1;
  31026. } else {
  31027. i = c;
  31028. }
  31029. }
  31030. // Even index means code in problematic range.
  31031. return !(i & 1);
  31032. }
  31033. /**
  31034. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  31035. * with their unicode value. It also moves char codes that are in known
  31036. * problematic locations.
  31037. * @return {Object} Two properties:
  31038. * 'toFontChar' - maps original char codes(the value that will be read
  31039. * from commands such as show text) to the char codes that will be used in the
  31040. * font that we build
  31041. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  31042. */
  31043. function adjustMapping(charCodeToGlyphId, properties) {
  31044. var toUnicode = properties.toUnicode;
  31045. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  31046. var isIdentityUnicode =
  31047. properties.toUnicode instanceof IdentityToUnicodeMap;
  31048. var newMap = Object.create(null);
  31049. var toFontChar = [];
  31050. var usedFontCharCodes = [];
  31051. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  31052. for (var originalCharCode in charCodeToGlyphId) {
  31053. originalCharCode |= 0;
  31054. var glyphId = charCodeToGlyphId[originalCharCode];
  31055. var fontCharCode = originalCharCode;
  31056. // First try to map the value to a unicode position if a non identity map
  31057. // was created.
  31058. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  31059. var unicode = toUnicode.get(fontCharCode);
  31060. // TODO: Try to map ligatures to the correct spot.
  31061. if (unicode.length === 1) {
  31062. fontCharCode = unicode.charCodeAt(0);
  31063. }
  31064. }
  31065. // Try to move control characters, special characters and already mapped
  31066. // characters to the private use area since they will not be drawn by
  31067. // canvas if left in their current position. Also, move characters if the
  31068. // font was symbolic and there is only an identity unicode map since the
  31069. // characters probably aren't in the correct position (fixes an issue
  31070. // with firefox and thuluthfont).
  31071. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  31072. isProblematicUnicodeLocation(fontCharCode) ||
  31073. (isSymbolic && isIdentityUnicode)) &&
  31074. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  31075. // Loop to try and find a free spot in the private use area.
  31076. do {
  31077. fontCharCode = nextAvailableFontCharCode++;
  31078. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  31079. fontCharCode = 0xF020;
  31080. nextAvailableFontCharCode = fontCharCode + 1;
  31081. }
  31082. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  31083. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  31084. }
  31085. newMap[fontCharCode] = glyphId;
  31086. toFontChar[originalCharCode] = fontCharCode;
  31087. usedFontCharCodes[fontCharCode] = true;
  31088. }
  31089. return {
  31090. toFontChar: toFontChar,
  31091. charCodeToGlyphId: newMap,
  31092. nextAvailableFontCharCode: nextAvailableFontCharCode
  31093. };
  31094. }
  31095. function getRanges(glyphs, numGlyphs) {
  31096. // Array.sort() sorts by characters, not numerically, so convert to an
  31097. // array of characters.
  31098. var codes = [];
  31099. for (var charCode in glyphs) {
  31100. // Remove an invalid glyph ID mappings to make OTS happy.
  31101. if (glyphs[charCode] >= numGlyphs) {
  31102. continue;
  31103. }
  31104. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  31105. }
  31106. codes.sort(function fontGetRangesSort(a, b) {
  31107. return a.fontCharCode - b.fontCharCode;
  31108. });
  31109. // Split the sorted codes into ranges.
  31110. var ranges = [];
  31111. var length = codes.length;
  31112. for (var n = 0; n < length; ) {
  31113. var start = codes[n].fontCharCode;
  31114. var codeIndices = [codes[n].glyphId];
  31115. ++n;
  31116. var end = start;
  31117. while (n < length && end + 1 === codes[n].fontCharCode) {
  31118. codeIndices.push(codes[n].glyphId);
  31119. ++end;
  31120. ++n;
  31121. if (end === 0xFFFF) {
  31122. break;
  31123. }
  31124. }
  31125. ranges.push([start, end, codeIndices]);
  31126. }
  31127. return ranges;
  31128. }
  31129. function createCmapTable(glyphs, numGlyphs) {
  31130. var ranges = getRanges(glyphs, numGlyphs);
  31131. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  31132. var cmap = '\x00\x00' + // version
  31133. string16(numTables) + // numTables
  31134. '\x00\x03' + // platformID
  31135. '\x00\x01' + // encodingID
  31136. string32(4 + numTables * 8); // start of the table record
  31137. var i, ii, j, jj;
  31138. for (i = ranges.length - 1; i >= 0; --i) {
  31139. if (ranges[i][0] <= 0xFFFF) { break; }
  31140. }
  31141. var bmpLength = i + 1;
  31142. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  31143. ranges[i][1] = 0xFFFE;
  31144. }
  31145. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  31146. var segCount = bmpLength + trailingRangesCount;
  31147. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  31148. // Fill up the 4 parallel arrays describing the segments.
  31149. var startCount = '';
  31150. var endCount = '';
  31151. var idDeltas = '';
  31152. var idRangeOffsets = '';
  31153. var glyphsIds = '';
  31154. var bias = 0;
  31155. var range, start, end, codes;
  31156. for (i = 0, ii = bmpLength; i < ii; i++) {
  31157. range = ranges[i];
  31158. start = range[0];
  31159. end = range[1];
  31160. startCount += string16(start);
  31161. endCount += string16(end);
  31162. codes = range[2];
  31163. var contiguous = true;
  31164. for (j = 1, jj = codes.length; j < jj; ++j) {
  31165. if (codes[j] !== codes[j - 1] + 1) {
  31166. contiguous = false;
  31167. break;
  31168. }
  31169. }
  31170. if (!contiguous) {
  31171. var offset = (segCount - i) * 2 + bias * 2;
  31172. bias += (end - start + 1);
  31173. idDeltas += string16(0);
  31174. idRangeOffsets += string16(offset);
  31175. for (j = 0, jj = codes.length; j < jj; ++j) {
  31176. glyphsIds += string16(codes[j]);
  31177. }
  31178. } else {
  31179. var startCode = codes[0];
  31180. idDeltas += string16((startCode - start) & 0xFFFF);
  31181. idRangeOffsets += string16(0);
  31182. }
  31183. }
  31184. if (trailingRangesCount > 0) {
  31185. endCount += '\xFF\xFF';
  31186. startCount += '\xFF\xFF';
  31187. idDeltas += '\x00\x01';
  31188. idRangeOffsets += '\x00\x00';
  31189. }
  31190. var format314 = '\x00\x00' + // language
  31191. string16(2 * segCount) +
  31192. string16(searchParams.range) +
  31193. string16(searchParams.entry) +
  31194. string16(searchParams.rangeShift) +
  31195. endCount + '\x00\x00' + startCount +
  31196. idDeltas + idRangeOffsets + glyphsIds;
  31197. var format31012 = '';
  31198. var header31012 = '';
  31199. if (numTables > 1) {
  31200. cmap += '\x00\x03' + // platformID
  31201. '\x00\x0A' + // encodingID
  31202. string32(4 + numTables * 8 +
  31203. 4 + format314.length); // start of the table record
  31204. format31012 = '';
  31205. for (i = 0, ii = ranges.length; i < ii; i++) {
  31206. range = ranges[i];
  31207. start = range[0];
  31208. codes = range[2];
  31209. var code = codes[0];
  31210. for (j = 1, jj = codes.length; j < jj; ++j) {
  31211. if (codes[j] !== codes[j - 1] + 1) {
  31212. end = range[0] + j - 1;
  31213. format31012 += string32(start) + // startCharCode
  31214. string32(end) + // endCharCode
  31215. string32(code); // startGlyphID
  31216. start = end + 1;
  31217. code = codes[j];
  31218. }
  31219. }
  31220. format31012 += string32(start) + // startCharCode
  31221. string32(range[1]) + // endCharCode
  31222. string32(code); // startGlyphID
  31223. }
  31224. header31012 = '\x00\x0C' + // format
  31225. '\x00\x00' + // reserved
  31226. string32(format31012.length + 16) + // length
  31227. '\x00\x00\x00\x00' + // language
  31228. string32(format31012.length / 12); // nGroups
  31229. }
  31230. return cmap + '\x00\x04' + // format
  31231. string16(format314.length + 4) + // length
  31232. format314 + header31012 + format31012;
  31233. }
  31234. function validateOS2Table(os2) {
  31235. var stream = new Stream(os2.data);
  31236. var version = stream.getUint16();
  31237. // TODO verify all OS/2 tables fields, but currently we validate only those
  31238. // that give us issues
  31239. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  31240. var selection = stream.getUint16();
  31241. if (version < 4 && (selection & 0x0300)) {
  31242. return false;
  31243. }
  31244. var firstChar = stream.getUint16();
  31245. var lastChar = stream.getUint16();
  31246. if (firstChar > lastChar) {
  31247. return false;
  31248. }
  31249. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  31250. var usWinAscent = stream.getUint16();
  31251. if (usWinAscent === 0) { // makes font unreadable by windows
  31252. return false;
  31253. }
  31254. // OS/2 appears to be valid, resetting some fields
  31255. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  31256. return true;
  31257. }
  31258. function createOS2Table(properties, charstrings, override) {
  31259. override = override || {
  31260. unitsPerEm: 0,
  31261. yMax: 0,
  31262. yMin: 0,
  31263. ascent: 0,
  31264. descent: 0
  31265. };
  31266. var ulUnicodeRange1 = 0;
  31267. var ulUnicodeRange2 = 0;
  31268. var ulUnicodeRange3 = 0;
  31269. var ulUnicodeRange4 = 0;
  31270. var firstCharIndex = null;
  31271. var lastCharIndex = 0;
  31272. if (charstrings) {
  31273. for (var code in charstrings) {
  31274. code |= 0;
  31275. if (firstCharIndex > code || !firstCharIndex) {
  31276. firstCharIndex = code;
  31277. }
  31278. if (lastCharIndex < code) {
  31279. lastCharIndex = code;
  31280. }
  31281. var position = getUnicodeRangeFor(code);
  31282. if (position < 32) {
  31283. ulUnicodeRange1 |= 1 << position;
  31284. } else if (position < 64) {
  31285. ulUnicodeRange2 |= 1 << position - 32;
  31286. } else if (position < 96) {
  31287. ulUnicodeRange3 |= 1 << position - 64;
  31288. } else if (position < 123) {
  31289. ulUnicodeRange4 |= 1 << position - 96;
  31290. } else {
  31291. error('Unicode ranges Bits > 123 are reserved for internal usage');
  31292. }
  31293. }
  31294. } else {
  31295. // TODO
  31296. firstCharIndex = 0;
  31297. lastCharIndex = 255;
  31298. }
  31299. var bbox = properties.bbox || [0, 0, 0, 0];
  31300. var unitsPerEm = (override.unitsPerEm ||
  31301. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  31302. // if the font units differ to the PDF glyph space units
  31303. // then scale up the values
  31304. var scale = (properties.ascentScaled ? 1.0 :
  31305. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  31306. var typoAscent = (override.ascent ||
  31307. Math.round(scale * (properties.ascent || bbox[3])));
  31308. var typoDescent = (override.descent ||
  31309. Math.round(scale * (properties.descent || bbox[1])));
  31310. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  31311. typoDescent = -typoDescent; // fixing incorrect descent
  31312. }
  31313. var winAscent = override.yMax || typoAscent;
  31314. var winDescent = -override.yMin || -typoDescent;
  31315. return '\x00\x03' + // version
  31316. '\x02\x24' + // xAvgCharWidth
  31317. '\x01\xF4' + // usWeightClass
  31318. '\x00\x05' + // usWidthClass
  31319. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  31320. '\x02\x8A' + // ySubscriptXSize
  31321. '\x02\xBB' + // ySubscriptYSize
  31322. '\x00\x00' + // ySubscriptXOffset
  31323. '\x00\x8C' + // ySubscriptYOffset
  31324. '\x02\x8A' + // ySuperScriptXSize
  31325. '\x02\xBB' + // ySuperScriptYSize
  31326. '\x00\x00' + // ySuperScriptXOffset
  31327. '\x01\xDF' + // ySuperScriptYOffset
  31328. '\x00\x31' + // yStrikeOutSize
  31329. '\x01\x02' + // yStrikeOutPosition
  31330. '\x00\x00' + // sFamilyClass
  31331. '\x00\x00\x06' +
  31332. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  31333. '\x00\x00\x00\x00\x00\x00' + // Panose
  31334. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  31335. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  31336. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  31337. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  31338. '\x2A\x32\x31\x2A' + // achVendID
  31339. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  31340. string16(firstCharIndex ||
  31341. properties.firstChar) + // usFirstCharIndex
  31342. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  31343. string16(typoAscent) + // sTypoAscender
  31344. string16(typoDescent) + // sTypoDescender
  31345. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  31346. string16(winAscent) + // usWinAscent
  31347. string16(winDescent) + // usWinDescent
  31348. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  31349. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  31350. string16(properties.xHeight) + // sxHeight
  31351. string16(properties.capHeight) + // sCapHeight
  31352. string16(0) + // usDefaultChar
  31353. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  31354. '\x00\x03'; // usMaxContext
  31355. }
  31356. function createPostTable(properties) {
  31357. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  31358. return ('\x00\x03\x00\x00' + // Version number
  31359. string32(angle) + // italicAngle
  31360. '\x00\x00' + // underlinePosition
  31361. '\x00\x00' + // underlineThickness
  31362. string32(properties.fixedPitch) + // isFixedPitch
  31363. '\x00\x00\x00\x00' + // minMemType42
  31364. '\x00\x00\x00\x00' + // maxMemType42
  31365. '\x00\x00\x00\x00' + // minMemType1
  31366. '\x00\x00\x00\x00'); // maxMemType1
  31367. }
  31368. function createNameTable(name, proto) {
  31369. if (!proto) {
  31370. proto = [[], []]; // no strings and unicode strings
  31371. }
  31372. var strings = [
  31373. proto[0][0] || 'Original licence', // 0.Copyright
  31374. proto[0][1] || name, // 1.Font family
  31375. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  31376. proto[0][3] || 'uniqueID', // 3.Unique ID
  31377. proto[0][4] || name, // 4.Full font name
  31378. proto[0][5] || 'Version 0.11', // 5.Version
  31379. proto[0][6] || '', // 6.Postscript name
  31380. proto[0][7] || 'Unknown', // 7.Trademark
  31381. proto[0][8] || 'Unknown', // 8.Manufacturer
  31382. proto[0][9] || 'Unknown' // 9.Designer
  31383. ];
  31384. // Mac want 1-byte per character strings while Windows want
  31385. // 2-bytes per character, so duplicate the names table
  31386. var stringsUnicode = [];
  31387. var i, ii, j, jj, str;
  31388. for (i = 0, ii = strings.length; i < ii; i++) {
  31389. str = proto[1][i] || strings[i];
  31390. var strBufUnicode = [];
  31391. for (j = 0, jj = str.length; j < jj; j++) {
  31392. strBufUnicode.push(string16(str.charCodeAt(j)));
  31393. }
  31394. stringsUnicode.push(strBufUnicode.join(''));
  31395. }
  31396. var names = [strings, stringsUnicode];
  31397. var platforms = ['\x00\x01', '\x00\x03'];
  31398. var encodings = ['\x00\x00', '\x00\x01'];
  31399. var languages = ['\x00\x00', '\x04\x09'];
  31400. var namesRecordCount = strings.length * platforms.length;
  31401. var nameTable =
  31402. '\x00\x00' + // format
  31403. string16(namesRecordCount) + // Number of names Record
  31404. string16(namesRecordCount * 12 + 6); // Storage
  31405. // Build the name records field
  31406. var strOffset = 0;
  31407. for (i = 0, ii = platforms.length; i < ii; i++) {
  31408. var strs = names[i];
  31409. for (j = 0, jj = strs.length; j < jj; j++) {
  31410. str = strs[j];
  31411. var nameRecord =
  31412. platforms[i] + // platform ID
  31413. encodings[i] + // encoding ID
  31414. languages[i] + // language ID
  31415. string16(j) + // name ID
  31416. string16(str.length) +
  31417. string16(strOffset);
  31418. nameTable += nameRecord;
  31419. strOffset += str.length;
  31420. }
  31421. }
  31422. nameTable += strings.join('') + stringsUnicode.join('');
  31423. return nameTable;
  31424. }
  31425. Font.prototype = {
  31426. name: null,
  31427. font: null,
  31428. mimetype: null,
  31429. encoding: null,
  31430. get renderer() {
  31431. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  31432. return shadow(this, 'renderer', renderer);
  31433. },
  31434. exportData: function Font_exportData() {
  31435. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  31436. var data = {};
  31437. for (var i in this) {
  31438. if (this.hasOwnProperty(i)) {
  31439. data[i] = this[i];
  31440. }
  31441. }
  31442. return data;
  31443. },
  31444. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  31445. function readTableEntry(file) {
  31446. var tag = bytesToString(file.getBytes(4));
  31447. var checksum = file.getInt32() >>> 0;
  31448. var offset = file.getInt32() >>> 0;
  31449. var length = file.getInt32() >>> 0;
  31450. // Read the table associated data
  31451. var previousPosition = file.pos;
  31452. file.pos = file.start ? file.start : 0;
  31453. file.skip(offset);
  31454. var data = file.getBytes(length);
  31455. file.pos = previousPosition;
  31456. if (tag === 'head') {
  31457. // clearing checksum adjustment
  31458. data[8] = data[9] = data[10] = data[11] = 0;
  31459. data[17] |= 0x20; //Set font optimized for cleartype flag
  31460. }
  31461. return {
  31462. tag: tag,
  31463. checksum: checksum,
  31464. length: length,
  31465. offset: offset,
  31466. data: data
  31467. };
  31468. }
  31469. function readOpenTypeHeader(ttf) {
  31470. return {
  31471. version: bytesToString(ttf.getBytes(4)),
  31472. numTables: ttf.getUint16(),
  31473. searchRange: ttf.getUint16(),
  31474. entrySelector: ttf.getUint16(),
  31475. rangeShift: ttf.getUint16()
  31476. };
  31477. }
  31478. /**
  31479. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  31480. * PDF spec
  31481. */
  31482. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  31483. if (!cmap) {
  31484. warn('No cmap table available.');
  31485. return {
  31486. platformId: -1,
  31487. encodingId: -1,
  31488. mappings: [],
  31489. hasShortCmap: false
  31490. };
  31491. }
  31492. var segment;
  31493. var start = (font.start ? font.start : 0) + cmap.offset;
  31494. font.pos = start;
  31495. var version = font.getUint16();
  31496. var numTables = font.getUint16();
  31497. var potentialTable;
  31498. var canBreak = false;
  31499. // There's an order of preference in terms of which cmap subtable to
  31500. // use:
  31501. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  31502. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  31503. // The following takes advantage of the fact that the tables are sorted
  31504. // to work.
  31505. for (var i = 0; i < numTables; i++) {
  31506. var platformId = font.getUint16();
  31507. var encodingId = font.getUint16();
  31508. var offset = font.getInt32() >>> 0;
  31509. var useTable = false;
  31510. if (platformId === 0 && encodingId === 0) {
  31511. useTable = true;
  31512. // Continue the loop since there still may be a higher priority
  31513. // table.
  31514. } else if (platformId === 1 && encodingId === 0) {
  31515. useTable = true;
  31516. // Continue the loop since there still may be a higher priority
  31517. // table.
  31518. } else if (platformId === 3 && encodingId === 1 &&
  31519. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  31520. useTable = true;
  31521. if (!isSymbolicFont) {
  31522. canBreak = true;
  31523. }
  31524. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  31525. useTable = true;
  31526. canBreak = true;
  31527. }
  31528. if (useTable) {
  31529. potentialTable = {
  31530. platformId: platformId,
  31531. encodingId: encodingId,
  31532. offset: offset
  31533. };
  31534. }
  31535. if (canBreak) {
  31536. break;
  31537. }
  31538. }
  31539. if (potentialTable) {
  31540. font.pos = start + potentialTable.offset;
  31541. }
  31542. if (!potentialTable || font.peekByte() === -1) {
  31543. warn('Could not find a preferred cmap table.');
  31544. return {
  31545. platformId: -1,
  31546. encodingId: -1,
  31547. mappings: [],
  31548. hasShortCmap: false
  31549. };
  31550. }
  31551. var format = font.getUint16();
  31552. var length = font.getUint16();
  31553. var language = font.getUint16();
  31554. var hasShortCmap = false;
  31555. var mappings = [];
  31556. var j, glyphId;
  31557. // TODO(mack): refactor this cmap subtable reading logic out
  31558. if (format === 0) {
  31559. for (j = 0; j < 256; j++) {
  31560. var index = font.getByte();
  31561. if (!index) {
  31562. continue;
  31563. }
  31564. mappings.push({
  31565. charCode: j,
  31566. glyphId: index
  31567. });
  31568. }
  31569. hasShortCmap = true;
  31570. } else if (format === 4) {
  31571. // re-creating the table in format 4 since the encoding
  31572. // might be changed
  31573. var segCount = (font.getUint16() >> 1);
  31574. font.getBytes(6); // skipping range fields
  31575. var segIndex, segments = [];
  31576. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31577. segments.push({ end: font.getUint16() });
  31578. }
  31579. font.getUint16();
  31580. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31581. segments[segIndex].start = font.getUint16();
  31582. }
  31583. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31584. segments[segIndex].delta = font.getUint16();
  31585. }
  31586. var offsetsCount = 0;
  31587. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31588. segment = segments[segIndex];
  31589. var rangeOffset = font.getUint16();
  31590. if (!rangeOffset) {
  31591. segment.offsetIndex = -1;
  31592. continue;
  31593. }
  31594. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  31595. segment.offsetIndex = offsetIndex;
  31596. offsetsCount = Math.max(offsetsCount, offsetIndex +
  31597. segment.end - segment.start + 1);
  31598. }
  31599. var offsets = [];
  31600. for (j = 0; j < offsetsCount; j++) {
  31601. offsets.push(font.getUint16());
  31602. }
  31603. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31604. segment = segments[segIndex];
  31605. start = segment.start;
  31606. var end = segment.end;
  31607. var delta = segment.delta;
  31608. offsetIndex = segment.offsetIndex;
  31609. for (j = start; j <= end; j++) {
  31610. if (j === 0xFFFF) {
  31611. continue;
  31612. }
  31613. glyphId = (offsetIndex < 0 ?
  31614. j : offsets[offsetIndex + j - start]);
  31615. glyphId = (glyphId + delta) & 0xFFFF;
  31616. if (glyphId === 0) {
  31617. continue;
  31618. }
  31619. mappings.push({
  31620. charCode: j,
  31621. glyphId: glyphId
  31622. });
  31623. }
  31624. }
  31625. } else if (format === 6) {
  31626. // Format 6 is a 2-bytes dense mapping, which means the font data
  31627. // lives glue together even if they are pretty far in the unicode
  31628. // table. (This looks weird, so I can have missed something), this
  31629. // works on Linux but seems to fails on Mac so let's rewrite the
  31630. // cmap table to a 3-1-4 style
  31631. var firstCode = font.getUint16();
  31632. var entryCount = font.getUint16();
  31633. for (j = 0; j < entryCount; j++) {
  31634. glyphId = font.getUint16();
  31635. var charCode = firstCode + j;
  31636. mappings.push({
  31637. charCode: charCode,
  31638. glyphId: glyphId
  31639. });
  31640. }
  31641. } else {
  31642. warn('cmap table has unsupported format: ' + format);
  31643. return {
  31644. platformId: -1,
  31645. encodingId: -1,
  31646. mappings: [],
  31647. hasShortCmap: false
  31648. };
  31649. }
  31650. // removing duplicate entries
  31651. mappings.sort(function (a, b) {
  31652. return a.charCode - b.charCode;
  31653. });
  31654. for (i = 1; i < mappings.length; i++) {
  31655. if (mappings[i - 1].charCode === mappings[i].charCode) {
  31656. mappings.splice(i, 1);
  31657. i--;
  31658. }
  31659. }
  31660. return {
  31661. platformId: potentialTable.platformId,
  31662. encodingId: potentialTable.encodingId,
  31663. mappings: mappings,
  31664. hasShortCmap: hasShortCmap
  31665. };
  31666. }
  31667. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  31668. if (!header) {
  31669. if (metrics) {
  31670. metrics.data = null;
  31671. }
  31672. return;
  31673. }
  31674. font.pos = (font.start ? font.start : 0) + header.offset;
  31675. font.pos += header.length - 2;
  31676. var numOfMetrics = font.getUint16();
  31677. if (numOfMetrics > numGlyphs) {
  31678. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  31679. 'greater than the numGlyphs (' + numGlyphs + ')');
  31680. // Reduce numOfMetrics if it is greater than numGlyphs
  31681. numOfMetrics = numGlyphs;
  31682. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  31683. header.data[35] = numOfMetrics & 0x00ff;
  31684. }
  31685. var numOfSidebearings = numGlyphs - numOfMetrics;
  31686. var numMissing = numOfSidebearings -
  31687. ((metrics.length - numOfMetrics * 4) >> 1);
  31688. if (numMissing > 0) {
  31689. // For each missing glyph, we set both the width and lsb to 0 (zero).
  31690. // Since we need to add two properties for each glyph, this explains
  31691. // the use of |numMissing * 2| when initializing the typed array.
  31692. var entries = new Uint8Array(metrics.length + numMissing * 2);
  31693. entries.set(metrics.data);
  31694. metrics.data = entries;
  31695. }
  31696. }
  31697. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  31698. hintsValid) {
  31699. if (sourceEnd - sourceStart <= 12) {
  31700. // glyph with data less than 12 is invalid one
  31701. return 0;
  31702. }
  31703. var glyf = source.subarray(sourceStart, sourceEnd);
  31704. var contoursCount = (glyf[0] << 8) | glyf[1];
  31705. if (contoursCount & 0x8000) {
  31706. // complex glyph, writing as is
  31707. dest.set(glyf, destStart);
  31708. return glyf.length;
  31709. }
  31710. var i, j = 10, flagsCount = 0;
  31711. for (i = 0; i < contoursCount; i++) {
  31712. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  31713. flagsCount = endPoint + 1;
  31714. j += 2;
  31715. }
  31716. // skipping instructions
  31717. var instructionsStart = j;
  31718. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  31719. j += 2 + instructionsLength;
  31720. var instructionsEnd = j;
  31721. // validating flags
  31722. var coordinatesLength = 0;
  31723. for (i = 0; i < flagsCount; i++) {
  31724. var flag = glyf[j++];
  31725. if (flag & 0xC0) {
  31726. // reserved flags must be zero, cleaning up
  31727. glyf[j - 1] = flag & 0x3F;
  31728. }
  31729. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  31730. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  31731. coordinatesLength += xyLength;
  31732. if (flag & 8) {
  31733. var repeat = glyf[j++];
  31734. i += repeat;
  31735. coordinatesLength += repeat * xyLength;
  31736. }
  31737. }
  31738. // glyph without coordinates will be rejected
  31739. if (coordinatesLength === 0) {
  31740. return 0;
  31741. }
  31742. var glyphDataLength = j + coordinatesLength;
  31743. if (glyphDataLength > glyf.length) {
  31744. // not enough data for coordinates
  31745. return 0;
  31746. }
  31747. if (!hintsValid && instructionsLength > 0) {
  31748. dest.set(glyf.subarray(0, instructionsStart), destStart);
  31749. dest.set([0, 0], destStart + instructionsStart);
  31750. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  31751. destStart + instructionsStart + 2);
  31752. glyphDataLength -= instructionsLength;
  31753. if (glyf.length - glyphDataLength > 3) {
  31754. glyphDataLength = (glyphDataLength + 3) & ~3;
  31755. }
  31756. return glyphDataLength;
  31757. }
  31758. if (glyf.length - glyphDataLength > 3) {
  31759. // truncating and aligning to 4 bytes the long glyph data
  31760. glyphDataLength = (glyphDataLength + 3) & ~3;
  31761. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  31762. return glyphDataLength;
  31763. }
  31764. // glyph data is fine
  31765. dest.set(glyf, destStart);
  31766. return glyf.length;
  31767. }
  31768. function sanitizeHead(head, numGlyphs, locaLength) {
  31769. var data = head.data;
  31770. // Validate version:
  31771. // Should always be 0x00010000
  31772. var version = int32(data[0], data[1], data[2], data[3]);
  31773. if (version >> 16 !== 1) {
  31774. info('Attempting to fix invalid version in head table: ' + version);
  31775. data[0] = 0;
  31776. data[1] = 1;
  31777. data[2] = 0;
  31778. data[3] = 0;
  31779. }
  31780. var indexToLocFormat = int16(data[50], data[51]);
  31781. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  31782. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  31783. indexToLocFormat);
  31784. // The value of indexToLocFormat should be 0 if the loca table
  31785. // consists of short offsets, and should be 1 if the loca table
  31786. // consists of long offsets.
  31787. //
  31788. // The number of entries in the loca table should be numGlyphs + 1.
  31789. //
  31790. // Using this information, we can work backwards to deduce if the
  31791. // size of each offset in the loca table, and thus figure out the
  31792. // appropriate value for indexToLocFormat.
  31793. var numGlyphsPlusOne = numGlyphs + 1;
  31794. if (locaLength === numGlyphsPlusOne << 1) {
  31795. // 0x0000 indicates the loca table consists of short offsets
  31796. data[50] = 0;
  31797. data[51] = 0;
  31798. } else if (locaLength === numGlyphsPlusOne << 2) {
  31799. // 0x0001 indicates the loca table consists of long offsets
  31800. data[50] = 0;
  31801. data[51] = 1;
  31802. } else {
  31803. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  31804. }
  31805. }
  31806. }
  31807. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  31808. isGlyphLocationsLong, hintsValid,
  31809. dupFirstEntry) {
  31810. var itemSize, itemDecode, itemEncode;
  31811. if (isGlyphLocationsLong) {
  31812. itemSize = 4;
  31813. itemDecode = function fontItemDecodeLong(data, offset) {
  31814. return (data[offset] << 24) | (data[offset + 1] << 16) |
  31815. (data[offset + 2] << 8) | data[offset + 3];
  31816. };
  31817. itemEncode = function fontItemEncodeLong(data, offset, value) {
  31818. data[offset] = (value >>> 24) & 0xFF;
  31819. data[offset + 1] = (value >> 16) & 0xFF;
  31820. data[offset + 2] = (value >> 8) & 0xFF;
  31821. data[offset + 3] = value & 0xFF;
  31822. };
  31823. } else {
  31824. itemSize = 2;
  31825. itemDecode = function fontItemDecode(data, offset) {
  31826. return (data[offset] << 9) | (data[offset + 1] << 1);
  31827. };
  31828. itemEncode = function fontItemEncode(data, offset, value) {
  31829. data[offset] = (value >> 9) & 0xFF;
  31830. data[offset + 1] = (value >> 1) & 0xFF;
  31831. };
  31832. }
  31833. var locaData = loca.data;
  31834. var locaDataSize = itemSize * (1 + numGlyphs);
  31835. // is loca.data too short or long?
  31836. if (locaData.length !== locaDataSize) {
  31837. locaData = new Uint8Array(locaDataSize);
  31838. locaData.set(loca.data.subarray(0, locaDataSize));
  31839. loca.data = locaData;
  31840. }
  31841. // removing the invalid glyphs
  31842. var oldGlyfData = glyf.data;
  31843. var oldGlyfDataLength = oldGlyfData.length;
  31844. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  31845. var startOffset = itemDecode(locaData, 0);
  31846. var writeOffset = 0;
  31847. var missingGlyphData = Object.create(null);
  31848. itemEncode(locaData, 0, writeOffset);
  31849. var i, j;
  31850. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  31851. var endOffset = itemDecode(locaData, j);
  31852. if (endOffset > oldGlyfDataLength &&
  31853. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  31854. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  31855. // the glyf table size, which makes last glyph out of range.
  31856. endOffset = oldGlyfDataLength;
  31857. }
  31858. if (endOffset > oldGlyfDataLength) {
  31859. // glyph end offset points outside glyf data, rejecting the glyph
  31860. itemEncode(locaData, j, writeOffset);
  31861. startOffset = endOffset;
  31862. continue;
  31863. }
  31864. if (startOffset === endOffset) {
  31865. missingGlyphData[i] = true;
  31866. }
  31867. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  31868. newGlyfData, writeOffset, hintsValid);
  31869. writeOffset += newLength;
  31870. itemEncode(locaData, j, writeOffset);
  31871. startOffset = endOffset;
  31872. }
  31873. if (writeOffset === 0) {
  31874. // glyf table cannot be empty -- redoing the glyf and loca tables
  31875. // to have single glyph with one point
  31876. var simpleGlyph = new Uint8Array(
  31877. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  31878. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  31879. itemEncode(locaData, j, simpleGlyph.length);
  31880. }
  31881. glyf.data = simpleGlyph;
  31882. return missingGlyphData;
  31883. }
  31884. if (dupFirstEntry) {
  31885. var firstEntryLength = itemDecode(locaData, itemSize);
  31886. if (newGlyfData.length > firstEntryLength + writeOffset) {
  31887. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  31888. } else {
  31889. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  31890. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  31891. }
  31892. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  31893. itemEncode(loca.data, locaData.length - itemSize,
  31894. writeOffset + firstEntryLength);
  31895. } else {
  31896. glyf.data = newGlyfData.subarray(0, writeOffset);
  31897. }
  31898. return missingGlyphData;
  31899. }
  31900. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  31901. var start = (font.start ? font.start : 0) + post.offset;
  31902. font.pos = start;
  31903. var length = post.length, end = start + length;
  31904. var version = font.getInt32();
  31905. // skip rest to the tables
  31906. font.getBytes(28);
  31907. var glyphNames;
  31908. var valid = true;
  31909. var i;
  31910. switch (version) {
  31911. case 0x00010000:
  31912. glyphNames = MacStandardGlyphOrdering;
  31913. break;
  31914. case 0x00020000:
  31915. var numGlyphs = font.getUint16();
  31916. if (numGlyphs !== maxpNumGlyphs) {
  31917. valid = false;
  31918. break;
  31919. }
  31920. var glyphNameIndexes = [];
  31921. for (i = 0; i < numGlyphs; ++i) {
  31922. var index = font.getUint16();
  31923. if (index >= 32768) {
  31924. valid = false;
  31925. break;
  31926. }
  31927. glyphNameIndexes.push(index);
  31928. }
  31929. if (!valid) {
  31930. break;
  31931. }
  31932. var customNames = [];
  31933. var strBuf = [];
  31934. while (font.pos < end) {
  31935. var stringLength = font.getByte();
  31936. strBuf.length = stringLength;
  31937. for (i = 0; i < stringLength; ++i) {
  31938. strBuf[i] = String.fromCharCode(font.getByte());
  31939. }
  31940. customNames.push(strBuf.join(''));
  31941. }
  31942. glyphNames = [];
  31943. for (i = 0; i < numGlyphs; ++i) {
  31944. var j = glyphNameIndexes[i];
  31945. if (j < 258) {
  31946. glyphNames.push(MacStandardGlyphOrdering[j]);
  31947. continue;
  31948. }
  31949. glyphNames.push(customNames[j - 258]);
  31950. }
  31951. break;
  31952. case 0x00030000:
  31953. break;
  31954. default:
  31955. warn('Unknown/unsupported post table version ' + version);
  31956. valid = false;
  31957. if (properties.defaultEncoding) {
  31958. glyphNames = properties.defaultEncoding;
  31959. }
  31960. break;
  31961. }
  31962. properties.glyphNames = glyphNames;
  31963. return valid;
  31964. }
  31965. function readNameTable(nameTable) {
  31966. var start = (font.start ? font.start : 0) + nameTable.offset;
  31967. font.pos = start;
  31968. var names = [[], []];
  31969. var length = nameTable.length, end = start + length;
  31970. var format = font.getUint16();
  31971. var FORMAT_0_HEADER_LENGTH = 6;
  31972. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  31973. // unsupported name table format or table "too" small
  31974. return names;
  31975. }
  31976. var numRecords = font.getUint16();
  31977. var stringsStart = font.getUint16();
  31978. var records = [];
  31979. var NAME_RECORD_LENGTH = 12;
  31980. var i, ii;
  31981. for (i = 0; i < numRecords &&
  31982. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  31983. var r = {
  31984. platform: font.getUint16(),
  31985. encoding: font.getUint16(),
  31986. language: font.getUint16(),
  31987. name: font.getUint16(),
  31988. length: font.getUint16(),
  31989. offset: font.getUint16()
  31990. };
  31991. // using only Macintosh and Windows platform/encoding names
  31992. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  31993. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  31994. records.push(r);
  31995. }
  31996. }
  31997. for (i = 0, ii = records.length; i < ii; i++) {
  31998. var record = records[i];
  31999. if (record.length <= 0) {
  32000. continue; // Nothing to process, ignoring.
  32001. }
  32002. var pos = start + stringsStart + record.offset;
  32003. if (pos + record.length > end) {
  32004. continue; // outside of name table, ignoring
  32005. }
  32006. font.pos = pos;
  32007. var nameIndex = record.name;
  32008. if (record.encoding) {
  32009. // unicode
  32010. var str = '';
  32011. for (var j = 0, jj = record.length; j < jj; j += 2) {
  32012. str += String.fromCharCode(font.getUint16());
  32013. }
  32014. names[1][nameIndex] = str;
  32015. } else {
  32016. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  32017. }
  32018. }
  32019. return names;
  32020. }
  32021. var TTOpsStackDeltas = [
  32022. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  32023. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  32024. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  32025. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  32026. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  32027. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  32028. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  32029. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  32030. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  32031. // 0xC0-DF == -1 and 0xE0-FF == -2
  32032. function sanitizeTTProgram(table, ttContext) {
  32033. var data = table.data;
  32034. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  32035. var stack = [];
  32036. var callstack = [];
  32037. var functionsCalled = [];
  32038. var tooComplexToFollowFunctions =
  32039. ttContext.tooComplexToFollowFunctions;
  32040. var inFDEF = false, ifLevel = 0, inELSE = 0;
  32041. for (var ii = data.length; i < ii;) {
  32042. var op = data[i++];
  32043. // The TrueType instruction set docs can be found at
  32044. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  32045. if (op === 0x40) { // NPUSHB - pushes n bytes
  32046. n = data[i++];
  32047. if (inFDEF || inELSE) {
  32048. i += n;
  32049. } else {
  32050. for (j = 0; j < n; j++) {
  32051. stack.push(data[i++]);
  32052. }
  32053. }
  32054. } else if (op === 0x41) { // NPUSHW - pushes n words
  32055. n = data[i++];
  32056. if (inFDEF || inELSE) {
  32057. i += n * 2;
  32058. } else {
  32059. for (j = 0; j < n; j++) {
  32060. b = data[i++];
  32061. stack.push((b << 8) | data[i++]);
  32062. }
  32063. }
  32064. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  32065. n = op - 0xB0 + 1;
  32066. if (inFDEF || inELSE) {
  32067. i += n;
  32068. } else {
  32069. for (j = 0; j < n; j++) {
  32070. stack.push(data[i++]);
  32071. }
  32072. }
  32073. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  32074. n = op - 0xB8 + 1;
  32075. if (inFDEF || inELSE) {
  32076. i += n * 2;
  32077. } else {
  32078. for (j = 0; j < n; j++) {
  32079. b = data[i++];
  32080. stack.push((b << 8) | data[i++]);
  32081. }
  32082. }
  32083. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  32084. if (!inFDEF && !inELSE) {
  32085. // collecting inforamtion about which functions are used
  32086. funcId = stack[stack.length - 1];
  32087. ttContext.functionsUsed[funcId] = true;
  32088. if (funcId in ttContext.functionsStackDeltas) {
  32089. stack.length += ttContext.functionsStackDeltas[funcId];
  32090. } else if (funcId in ttContext.functionsDefined &&
  32091. functionsCalled.indexOf(funcId) < 0) {
  32092. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  32093. functionsCalled.push(funcId);
  32094. pc = ttContext.functionsDefined[funcId];
  32095. if (!pc) {
  32096. warn('TT: CALL non-existent function');
  32097. ttContext.hintsValid = false;
  32098. return;
  32099. }
  32100. data = pc.data;
  32101. i = pc.i;
  32102. }
  32103. }
  32104. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  32105. if (inFDEF || inELSE) {
  32106. warn('TT: nested FDEFs not allowed');
  32107. tooComplexToFollowFunctions = true;
  32108. }
  32109. inFDEF = true;
  32110. // collecting inforamtion about which functions are defined
  32111. lastDeff = i;
  32112. funcId = stack.pop();
  32113. ttContext.functionsDefined[funcId] = {data: data, i: i};
  32114. } else if (op === 0x2D) { // ENDF - end of function
  32115. if (inFDEF) {
  32116. inFDEF = false;
  32117. lastEndf = i;
  32118. } else {
  32119. pc = callstack.pop();
  32120. if (!pc) {
  32121. warn('TT: ENDF bad stack');
  32122. ttContext.hintsValid = false;
  32123. return;
  32124. }
  32125. funcId = functionsCalled.pop();
  32126. data = pc.data;
  32127. i = pc.i;
  32128. ttContext.functionsStackDeltas[funcId] =
  32129. stack.length - pc.stackTop;
  32130. }
  32131. } else if (op === 0x89) { // IDEF - instruction definition
  32132. if (inFDEF || inELSE) {
  32133. warn('TT: nested IDEFs not allowed');
  32134. tooComplexToFollowFunctions = true;
  32135. }
  32136. inFDEF = true;
  32137. // recording it as a function to track ENDF
  32138. lastDeff = i;
  32139. } else if (op === 0x58) { // IF
  32140. ++ifLevel;
  32141. } else if (op === 0x1B) { // ELSE
  32142. inELSE = ifLevel;
  32143. } else if (op === 0x59) { // EIF
  32144. if (inELSE === ifLevel) {
  32145. inELSE = 0;
  32146. }
  32147. --ifLevel;
  32148. } else if (op === 0x1C) { // JMPR
  32149. if (!inFDEF && !inELSE) {
  32150. var offset = stack[stack.length - 1];
  32151. // only jumping forward to prevent infinite loop
  32152. if (offset > 0) {
  32153. i += offset - 1;
  32154. }
  32155. }
  32156. }
  32157. // Adjusting stack not extactly, but just enough to get function id
  32158. if (!inFDEF && !inELSE) {
  32159. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  32160. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  32161. if (op >= 0x71 && op <= 0x75) {
  32162. n = stack.pop();
  32163. if (n === n) {
  32164. stackDelta = -n * 2;
  32165. }
  32166. }
  32167. while (stackDelta < 0 && stack.length > 0) {
  32168. stack.pop();
  32169. stackDelta++;
  32170. }
  32171. while (stackDelta > 0) {
  32172. stack.push(NaN); // pushing any number into stack
  32173. stackDelta--;
  32174. }
  32175. }
  32176. }
  32177. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  32178. var content = [data];
  32179. if (i > data.length) {
  32180. content.push(new Uint8Array(i - data.length));
  32181. }
  32182. if (lastDeff > lastEndf) {
  32183. warn('TT: complementing a missing function tail');
  32184. // new function definition started, but not finished
  32185. // complete function by [CLEAR, ENDF]
  32186. content.push(new Uint8Array([0x22, 0x2D]));
  32187. }
  32188. foldTTTable(table, content);
  32189. }
  32190. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  32191. if (ttContext.tooComplexToFollowFunctions) {
  32192. return;
  32193. }
  32194. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  32195. warn('TT: more functions defined than expected');
  32196. ttContext.hintsValid = false;
  32197. return;
  32198. }
  32199. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  32200. if (j > maxFunctionDefs) {
  32201. warn('TT: invalid function id: ' + j);
  32202. ttContext.hintsValid = false;
  32203. return;
  32204. }
  32205. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  32206. warn('TT: undefined function: ' + j);
  32207. ttContext.hintsValid = false;
  32208. return;
  32209. }
  32210. }
  32211. }
  32212. function foldTTTable(table, content) {
  32213. if (content.length > 1) {
  32214. // concatenating the content items
  32215. var newLength = 0;
  32216. var j, jj;
  32217. for (j = 0, jj = content.length; j < jj; j++) {
  32218. newLength += content[j].length;
  32219. }
  32220. newLength = (newLength + 3) & ~3;
  32221. var result = new Uint8Array(newLength);
  32222. var pos = 0;
  32223. for (j = 0, jj = content.length; j < jj; j++) {
  32224. result.set(content[j], pos);
  32225. pos += content[j].length;
  32226. }
  32227. table.data = result;
  32228. table.length = newLength;
  32229. }
  32230. }
  32231. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  32232. var ttContext = {
  32233. functionsDefined: [],
  32234. functionsUsed: [],
  32235. functionsStackDeltas: [],
  32236. tooComplexToFollowFunctions: false,
  32237. hintsValid: true
  32238. };
  32239. if (fpgm) {
  32240. sanitizeTTProgram(fpgm, ttContext);
  32241. }
  32242. if (prep) {
  32243. sanitizeTTProgram(prep, ttContext);
  32244. }
  32245. if (fpgm) {
  32246. checkInvalidFunctions(ttContext, maxFunctionDefs);
  32247. }
  32248. if (cvt && (cvt.length & 1)) {
  32249. var cvtData = new Uint8Array(cvt.length + 1);
  32250. cvtData.set(cvt.data);
  32251. cvt.data = cvtData;
  32252. }
  32253. return ttContext.hintsValid;
  32254. }
  32255. // The following steps modify the original font data, making copy
  32256. font = new Stream(new Uint8Array(font.getBytes()));
  32257. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  32258. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  32259. var header = readOpenTypeHeader(font);
  32260. var numTables = header.numTables;
  32261. var cff, cffFile;
  32262. var tables = Object.create(null);
  32263. tables['OS/2'] = null;
  32264. tables['cmap'] = null;
  32265. tables['head'] = null;
  32266. tables['hhea'] = null;
  32267. tables['hmtx'] = null;
  32268. tables['maxp'] = null;
  32269. tables['name'] = null;
  32270. tables['post'] = null;
  32271. var table;
  32272. for (var i = 0; i < numTables; i++) {
  32273. table = readTableEntry(font);
  32274. if (VALID_TABLES.indexOf(table.tag) < 0) {
  32275. continue; // skipping table if it's not a required or optional table
  32276. }
  32277. if (table.length === 0) {
  32278. continue; // skipping empty tables
  32279. }
  32280. tables[table.tag] = table;
  32281. }
  32282. var isTrueType = !tables['CFF '];
  32283. if (!isTrueType) {
  32284. // OpenType font
  32285. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  32286. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  32287. !tables['post']) {
  32288. // no major tables: throwing everything at CFFFont
  32289. cffFile = new Stream(tables['CFF '].data);
  32290. cff = new CFFFont(cffFile, properties);
  32291. adjustWidths(properties);
  32292. return this.convert(name, cff, properties);
  32293. }
  32294. delete tables['glyf'];
  32295. delete tables['loca'];
  32296. delete tables['fpgm'];
  32297. delete tables['prep'];
  32298. delete tables['cvt '];
  32299. this.isOpenType = true;
  32300. } else {
  32301. if (!tables['loca']) {
  32302. error('Required "loca" table is not found');
  32303. }
  32304. if (!tables['glyf']) {
  32305. warn('Required "glyf" table is not found -- trying to recover.');
  32306. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  32307. tables['glyf'] = {
  32308. tag: 'glyf',
  32309. data: new Uint8Array(0),
  32310. };
  32311. }
  32312. this.isOpenType = false;
  32313. }
  32314. if (!tables['maxp']) {
  32315. error('Required "maxp" table is not found');
  32316. }
  32317. font.pos = (font.start || 0) + tables['maxp'].offset;
  32318. var version = font.getInt32();
  32319. var numGlyphs = font.getUint16();
  32320. var maxFunctionDefs = 0;
  32321. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  32322. // maxZones can be invalid
  32323. font.pos += 8;
  32324. var maxZones = font.getUint16();
  32325. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  32326. tables['maxp'].data[14] = 0;
  32327. tables['maxp'].data[15] = 2;
  32328. }
  32329. font.pos += 4;
  32330. maxFunctionDefs = font.getUint16();
  32331. }
  32332. var dupFirstEntry = false;
  32333. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  32334. properties.toUnicode.get(0) > '\u0000') {
  32335. // oracle's defect (see 3427), duplicating first entry
  32336. dupFirstEntry = true;
  32337. numGlyphs++;
  32338. tables['maxp'].data[4] = numGlyphs >> 8;
  32339. tables['maxp'].data[5] = numGlyphs & 255;
  32340. }
  32341. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  32342. tables['cvt '], maxFunctionDefs);
  32343. if (!hintsValid) {
  32344. delete tables['fpgm'];
  32345. delete tables['prep'];
  32346. delete tables['cvt '];
  32347. }
  32348. // Ensure the hmtx table contains the advance width and
  32349. // sidebearings information for numGlyphs in the maxp table
  32350. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  32351. if (!tables['head']) {
  32352. error('Required "head" table is not found');
  32353. }
  32354. sanitizeHead(tables['head'], numGlyphs,
  32355. isTrueType ? tables['loca'].length : 0);
  32356. var missingGlyphs = Object.create(null);
  32357. if (isTrueType) {
  32358. var isGlyphLocationsLong = int16(tables['head'].data[50],
  32359. tables['head'].data[51]);
  32360. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  32361. numGlyphs, isGlyphLocationsLong,
  32362. hintsValid, dupFirstEntry);
  32363. }
  32364. if (!tables['hhea']) {
  32365. error('Required "hhea" table is not found');
  32366. }
  32367. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  32368. // Sometimes it's 0. That needs to be fixed
  32369. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  32370. tables['hhea'].data[10] = 0xFF;
  32371. tables['hhea'].data[11] = 0xFF;
  32372. }
  32373. // Extract some more font properties from the OpenType head and
  32374. // hhea tables; yMin and descent value are always negative.
  32375. var metricsOverride = {
  32376. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  32377. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  32378. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  32379. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  32380. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  32381. };
  32382. // PDF FontDescriptor metrics lie -- using data from actual font.
  32383. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  32384. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  32385. // The 'post' table has glyphs names.
  32386. if (tables['post']) {
  32387. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  32388. if (!valid) {
  32389. tables['post'] = null;
  32390. }
  32391. }
  32392. var charCodeToGlyphId = [], charCode;
  32393. var toUnicode = properties.toUnicode, widths = properties.widths;
  32394. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  32395. toUnicode.length === 0x10000);
  32396. // Helper function to try to skip mapping of empty glyphs.
  32397. // Note: In some cases, just relying on the glyph data doesn't work,
  32398. // hence we also use a few heuristics to fix various PDF files.
  32399. function hasGlyph(glyphId, charCode, widthCode) {
  32400. if (!missingGlyphs[glyphId]) {
  32401. return true;
  32402. }
  32403. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  32404. return true;
  32405. }
  32406. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  32407. return true;
  32408. }
  32409. return false;
  32410. }
  32411. if (properties.type === 'CIDFontType2') {
  32412. var cidToGidMap = properties.cidToGidMap || [];
  32413. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  32414. properties.cMap.forEach(function(charCode, cid) {
  32415. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  32416. var glyphId = -1;
  32417. if (isCidToGidMapEmpty) {
  32418. glyphId = cid;
  32419. } else if (cidToGidMap[cid] !== undefined) {
  32420. glyphId = cidToGidMap[cid];
  32421. }
  32422. if (glyphId >= 0 && glyphId < numGlyphs &&
  32423. hasGlyph(glyphId, charCode, cid)) {
  32424. charCodeToGlyphId[charCode] = glyphId;
  32425. }
  32426. });
  32427. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  32428. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  32429. // if the font has a `CIDToGIDMap` which has already mapped the first
  32430. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  32431. charCodeToGlyphId[0] = numGlyphs - 1;
  32432. }
  32433. } else {
  32434. // Most of the following logic in this code branch is based on the
  32435. // 9.6.6.4 of the PDF spec.
  32436. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont,
  32437. properties.hasEncoding);
  32438. var cmapPlatformId = cmapTable.platformId;
  32439. var cmapEncodingId = cmapTable.encodingId;
  32440. var cmapMappings = cmapTable.mappings;
  32441. var cmapMappingsLength = cmapMappings.length;
  32442. // The spec seems to imply that if the font is symbolic the encoding
  32443. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  32444. // where the the font is symbolic and it has an encoding.
  32445. if (properties.hasEncoding &&
  32446. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  32447. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  32448. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  32449. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  32450. // When no preferred cmap table was found and |baseEncodingName| is
  32451. // one of the predefined encodings, we seem to obtain a better
  32452. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  32453. // TODO: Note that this is a hack which should be removed as soon as
  32454. // we have proper support for more exotic cmap tables.
  32455. var baseEncoding = [];
  32456. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  32457. properties.baseEncodingName === 'WinAnsiEncoding') {
  32458. baseEncoding = getEncoding(properties.baseEncodingName);
  32459. }
  32460. var glyphsUnicodeMap = getGlyphsUnicode();
  32461. for (charCode = 0; charCode < 256; charCode++) {
  32462. var glyphName, standardGlyphName;
  32463. if (this.differences && charCode in this.differences) {
  32464. glyphName = this.differences[charCode];
  32465. } else if (charCode in baseEncoding &&
  32466. baseEncoding[charCode] !== '') {
  32467. glyphName = baseEncoding[charCode];
  32468. } else {
  32469. glyphName = StandardEncoding[charCode];
  32470. }
  32471. if (!glyphName) {
  32472. continue;
  32473. }
  32474. // Ensure that non-standard glyph names are resolved to valid ones.
  32475. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  32476. var unicodeOrCharCode, isUnicode = false;
  32477. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  32478. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  32479. isUnicode = true;
  32480. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  32481. // TODO: the encoding needs to be updated with mac os table.
  32482. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  32483. }
  32484. var found = false;
  32485. for (i = 0; i < cmapMappingsLength; ++i) {
  32486. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  32487. continue;
  32488. }
  32489. var code = isUnicode ? charCode : unicodeOrCharCode;
  32490. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  32491. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  32492. found = true;
  32493. break;
  32494. }
  32495. }
  32496. if (!found && properties.glyphNames) {
  32497. // Try to map using the post table.
  32498. var glyphId = properties.glyphNames.indexOf(glyphName);
  32499. // The post table ought to use the same kind of glyph names as the
  32500. // `differences` array, but check the standard ones as a fallback.
  32501. if (glyphId === -1 && standardGlyphName !== glyphName) {
  32502. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  32503. }
  32504. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  32505. charCodeToGlyphId[charCode] = glyphId;
  32506. found = true;
  32507. }
  32508. }
  32509. if (!found) {
  32510. charCodeToGlyphId[charCode] = 0; // notdef
  32511. }
  32512. }
  32513. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  32514. // Default Unicode semantics, use the charcodes as is.
  32515. for (i = 0; i < cmapMappingsLength; ++i) {
  32516. charCodeToGlyphId[cmapMappings[i].charCode] =
  32517. cmapMappings[i].glyphId;
  32518. }
  32519. } else {
  32520. // For (3, 0) cmap tables:
  32521. // The charcode key being stored in charCodeToGlyphId is the lower
  32522. // byte of the two-byte charcodes of the cmap table since according to
  32523. // the spec: 'each byte from the string shall be prepended with the
  32524. // high byte of the range [of charcodes in the cmap table], to form
  32525. // a two-byte character, which shall be used to select the
  32526. // associated glyph description from the subtable'.
  32527. //
  32528. // For (1, 0) cmap tables:
  32529. // 'single bytes from the string shall be used to look up the
  32530. // associated glyph descriptions from the subtable'. This means
  32531. // charcodes in the cmap will be single bytes, so no-op since
  32532. // glyph.charCode & 0xFF === glyph.charCode
  32533. for (i = 0; i < cmapMappingsLength; ++i) {
  32534. charCode = cmapMappings[i].charCode & 0xFF;
  32535. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  32536. }
  32537. }
  32538. }
  32539. if (charCodeToGlyphId.length === 0) {
  32540. // defines at least one glyph
  32541. charCodeToGlyphId[0] = 0;
  32542. }
  32543. // Converting glyphs and ids into font's cmap table
  32544. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  32545. this.toFontChar = newMapping.toFontChar;
  32546. tables['cmap'] = {
  32547. tag: 'cmap',
  32548. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  32549. };
  32550. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  32551. tables['OS/2'] = {
  32552. tag: 'OS/2',
  32553. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  32554. metricsOverride)
  32555. };
  32556. }
  32557. // Rewrite the 'post' table if needed
  32558. if (!tables['post']) {
  32559. tables['post'] = {
  32560. tag: 'post',
  32561. data: createPostTable(properties)
  32562. };
  32563. }
  32564. if (!isTrueType) {
  32565. try {
  32566. // Trying to repair CFF file
  32567. cffFile = new Stream(tables['CFF '].data);
  32568. var parser = new CFFParser(cffFile, properties,
  32569. SEAC_ANALYSIS_ENABLED);
  32570. cff = parser.parse();
  32571. var compiler = new CFFCompiler(cff);
  32572. tables['CFF '].data = compiler.compile();
  32573. } catch (e) {
  32574. warn('Failed to compile font ' + properties.loadedName);
  32575. }
  32576. }
  32577. // Re-creating 'name' table
  32578. if (!tables['name']) {
  32579. tables['name'] = {
  32580. tag: 'name',
  32581. data: createNameTable(this.name)
  32582. };
  32583. } else {
  32584. // ... using existing 'name' table as prototype
  32585. var namePrototype = readNameTable(tables['name']);
  32586. tables['name'].data = createNameTable(name, namePrototype);
  32587. }
  32588. var builder = new OpenTypeFileBuilder(header.version);
  32589. for (var tableTag in tables) {
  32590. builder.addTable(tableTag, tables[tableTag].data);
  32591. }
  32592. return builder.toArray();
  32593. },
  32594. convert: function Font_convert(fontName, font, properties) {
  32595. // TODO: Check the charstring widths to determine this.
  32596. properties.fixedPitch = false;
  32597. if (properties.builtInEncoding) {
  32598. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  32599. // data, attempt to use the `builtInEncoding` to improve text selection.
  32600. adjustToUnicode(properties, properties.builtInEncoding);
  32601. }
  32602. var mapping = font.getGlyphMapping(properties);
  32603. var newMapping = adjustMapping(mapping, properties);
  32604. this.toFontChar = newMapping.toFontChar;
  32605. var numGlyphs = font.numGlyphs;
  32606. function getCharCodes(charCodeToGlyphId, glyphId) {
  32607. var charCodes = null;
  32608. for (var charCode in charCodeToGlyphId) {
  32609. if (glyphId === charCodeToGlyphId[charCode]) {
  32610. if (!charCodes) {
  32611. charCodes = [];
  32612. }
  32613. charCodes.push(charCode | 0);
  32614. }
  32615. }
  32616. return charCodes;
  32617. }
  32618. function createCharCode(charCodeToGlyphId, glyphId) {
  32619. for (var charCode in charCodeToGlyphId) {
  32620. if (glyphId === charCodeToGlyphId[charCode]) {
  32621. return charCode | 0;
  32622. }
  32623. }
  32624. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  32625. glyphId;
  32626. return newMapping.nextAvailableFontCharCode++;
  32627. }
  32628. var seacs = font.seacs;
  32629. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  32630. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  32631. var charset = font.getCharset();
  32632. var seacMap = Object.create(null);
  32633. for (var glyphId in seacs) {
  32634. glyphId |= 0;
  32635. var seac = seacs[glyphId];
  32636. var baseGlyphName = StandardEncoding[seac[2]];
  32637. var accentGlyphName = StandardEncoding[seac[3]];
  32638. var baseGlyphId = charset.indexOf(baseGlyphName);
  32639. var accentGlyphId = charset.indexOf(accentGlyphName);
  32640. if (baseGlyphId < 0 || accentGlyphId < 0) {
  32641. continue;
  32642. }
  32643. var accentOffset = {
  32644. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  32645. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  32646. };
  32647. var charCodes = getCharCodes(mapping, glyphId);
  32648. if (!charCodes) {
  32649. // There's no point in mapping it if the char code was never mapped
  32650. // to begin with.
  32651. continue;
  32652. }
  32653. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  32654. var charCode = charCodes[i];
  32655. // Find a fontCharCode that maps to the base and accent glyphs.
  32656. // If one doesn't exists, create it.
  32657. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  32658. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  32659. baseGlyphId);
  32660. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  32661. accentGlyphId);
  32662. seacMap[charCode] = {
  32663. baseFontCharCode: baseFontCharCode,
  32664. accentFontCharCode: accentFontCharCode,
  32665. accentOffset: accentOffset
  32666. };
  32667. }
  32668. }
  32669. properties.seacMap = seacMap;
  32670. }
  32671. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  32672. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  32673. // PostScript Font Program
  32674. builder.addTable('CFF ', font.data);
  32675. // OS/2 and Windows Specific metrics
  32676. builder.addTable('OS/2', createOS2Table(properties,
  32677. newMapping.charCodeToGlyphId));
  32678. // Character to glyphs mapping
  32679. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  32680. numGlyphs));
  32681. // Font header
  32682. builder.addTable('head',
  32683. '\x00\x01\x00\x00' + // Version number
  32684. '\x00\x00\x10\x00' + // fontRevision
  32685. '\x00\x00\x00\x00' + // checksumAdjustement
  32686. '\x5F\x0F\x3C\xF5' + // magicNumber
  32687. '\x00\x00' + // Flags
  32688. safeString16(unitsPerEm) + // unitsPerEM
  32689. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  32690. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  32691. '\x00\x00' + // xMin
  32692. safeString16(properties.descent) + // yMin
  32693. '\x0F\xFF' + // xMax
  32694. safeString16(properties.ascent) + // yMax
  32695. string16(properties.italicAngle ? 2 : 0) + // macStyle
  32696. '\x00\x11' + // lowestRecPPEM
  32697. '\x00\x00' + // fontDirectionHint
  32698. '\x00\x00' + // indexToLocFormat
  32699. '\x00\x00'); // glyphDataFormat
  32700. // Horizontal header
  32701. builder.addTable('hhea',
  32702. '\x00\x01\x00\x00' + // Version number
  32703. safeString16(properties.ascent) + // Typographic Ascent
  32704. safeString16(properties.descent) + // Typographic Descent
  32705. '\x00\x00' + // Line Gap
  32706. '\xFF\xFF' + // advanceWidthMax
  32707. '\x00\x00' + // minLeftSidebearing
  32708. '\x00\x00' + // minRightSidebearing
  32709. '\x00\x00' + // xMaxExtent
  32710. safeString16(properties.capHeight) + // caretSlopeRise
  32711. safeString16(Math.tan(properties.italicAngle) *
  32712. properties.xHeight) + // caretSlopeRun
  32713. '\x00\x00' + // caretOffset
  32714. '\x00\x00' + // -reserved-
  32715. '\x00\x00' + // -reserved-
  32716. '\x00\x00' + // -reserved-
  32717. '\x00\x00' + // -reserved-
  32718. '\x00\x00' + // metricDataFormat
  32719. string16(numGlyphs)); // Number of HMetrics
  32720. // Horizontal metrics
  32721. builder.addTable('hmtx', (function fontFieldsHmtx() {
  32722. var charstrings = font.charstrings;
  32723. var cffWidths = font.cff ? font.cff.widths : null;
  32724. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  32725. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  32726. var width = 0;
  32727. if (charstrings) {
  32728. var charstring = charstrings[i - 1];
  32729. width = 'width' in charstring ? charstring.width : 0;
  32730. } else if (cffWidths) {
  32731. width = Math.ceil(cffWidths[i] || 0);
  32732. }
  32733. hmtx += string16(width) + string16(0);
  32734. }
  32735. return hmtx;
  32736. })());
  32737. // Maximum profile
  32738. builder.addTable('maxp',
  32739. '\x00\x00\x50\x00' + // Version number
  32740. string16(numGlyphs)); // Num of glyphs
  32741. // Naming tables
  32742. builder.addTable('name', createNameTable(fontName));
  32743. // PostScript information
  32744. builder.addTable('post', createPostTable(properties));
  32745. return builder.toArray();
  32746. },
  32747. get spaceWidth() {
  32748. if ('_shadowWidth' in this) {
  32749. return this._shadowWidth;
  32750. }
  32751. // trying to estimate space character width
  32752. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  32753. var width;
  32754. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  32755. var glyphName = possibleSpaceReplacements[i];
  32756. // if possible, getting width by glyph name
  32757. if (glyphName in this.widths) {
  32758. width = this.widths[glyphName];
  32759. break;
  32760. }
  32761. var glyphsUnicodeMap = getGlyphsUnicode();
  32762. var glyphUnicode = glyphsUnicodeMap[glyphName];
  32763. // finding the charcode via unicodeToCID map
  32764. var charcode = 0;
  32765. if (this.composite) {
  32766. if (this.cMap.contains(glyphUnicode)) {
  32767. charcode = this.cMap.lookup(glyphUnicode);
  32768. }
  32769. }
  32770. // ... via toUnicode map
  32771. if (!charcode && this.toUnicode) {
  32772. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  32773. }
  32774. // setting it to unicode if negative or undefined
  32775. if (charcode <= 0) {
  32776. charcode = glyphUnicode;
  32777. }
  32778. // trying to get width via charcode
  32779. width = this.widths[charcode];
  32780. if (width) {
  32781. break; // the non-zero width found
  32782. }
  32783. }
  32784. width = width || this.defaultWidth;
  32785. // Do not shadow the property here. See discussion:
  32786. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  32787. this._shadowWidth = width;
  32788. return width;
  32789. },
  32790. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  32791. var fontCharCode, width, operatorListId;
  32792. var widthCode = charcode;
  32793. if (this.cMap && this.cMap.contains(charcode)) {
  32794. widthCode = this.cMap.lookup(charcode);
  32795. }
  32796. width = this.widths[widthCode];
  32797. width = isNum(width) ? width : this.defaultWidth;
  32798. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  32799. var unicode = this.toUnicode.get(charcode) || charcode;
  32800. if (typeof unicode === 'number') {
  32801. unicode = String.fromCharCode(unicode);
  32802. }
  32803. var isInFont = charcode in this.toFontChar;
  32804. // First try the toFontChar map, if it's not there then try falling
  32805. // back to the char code.
  32806. fontCharCode = this.toFontChar[charcode] || charcode;
  32807. if (this.missingFile) {
  32808. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  32809. }
  32810. if (this.isType3Font) {
  32811. // Font char code in this case is actually a glyph name.
  32812. operatorListId = fontCharCode;
  32813. }
  32814. var accent = null;
  32815. if (this.seacMap && this.seacMap[charcode]) {
  32816. isInFont = true;
  32817. var seac = this.seacMap[charcode];
  32818. fontCharCode = seac.baseFontCharCode;
  32819. accent = {
  32820. fontChar: String.fromCharCode(seac.accentFontCharCode),
  32821. offset: seac.accentOffset
  32822. };
  32823. }
  32824. var fontChar = String.fromCharCode(fontCharCode);
  32825. var glyph = this.glyphCache[charcode];
  32826. if (!glyph ||
  32827. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  32828. operatorListId, isSpace, isInFont)) {
  32829. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  32830. operatorListId, isSpace, isInFont);
  32831. this.glyphCache[charcode] = glyph;
  32832. }
  32833. return glyph;
  32834. },
  32835. charsToGlyphs: function Font_charsToGlyphs(chars) {
  32836. var charsCache = this.charsCache;
  32837. var glyphs, glyph, charcode;
  32838. // if we translated this string before, just grab it from the cache
  32839. if (charsCache) {
  32840. glyphs = charsCache[chars];
  32841. if (glyphs) {
  32842. return glyphs;
  32843. }
  32844. }
  32845. // lazily create the translation cache
  32846. if (!charsCache) {
  32847. charsCache = this.charsCache = Object.create(null);
  32848. }
  32849. glyphs = [];
  32850. var charsCacheKey = chars;
  32851. var i = 0, ii;
  32852. if (this.cMap) {
  32853. // composite fonts have multi-byte strings convert the string from
  32854. // single-byte to multi-byte
  32855. var c = Object.create(null);
  32856. while (i < chars.length) {
  32857. this.cMap.readCharCode(chars, i, c);
  32858. charcode = c.charcode;
  32859. var length = c.length;
  32860. i += length;
  32861. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  32862. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  32863. glyph = this.charToGlyph(charcode, isSpace);
  32864. glyphs.push(glyph);
  32865. }
  32866. } else {
  32867. for (i = 0, ii = chars.length; i < ii; ++i) {
  32868. charcode = chars.charCodeAt(i);
  32869. glyph = this.charToGlyph(charcode, charcode === 0x20);
  32870. glyphs.push(glyph);
  32871. }
  32872. }
  32873. // Enter the translated string into the cache
  32874. return (charsCache[charsCacheKey] = glyphs);
  32875. }
  32876. };
  32877. return Font;
  32878. })();
  32879. var ErrorFont = (function ErrorFontClosure() {
  32880. function ErrorFont(error) {
  32881. this.error = error;
  32882. this.loadedName = 'g_font_error';
  32883. this.loading = false;
  32884. }
  32885. ErrorFont.prototype = {
  32886. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  32887. return [];
  32888. },
  32889. exportData: function ErrorFont_exportData() {
  32890. return {error: this.error};
  32891. }
  32892. };
  32893. return ErrorFont;
  32894. })();
  32895. /**
  32896. * Shared logic for building a char code to glyph id mapping for Type1 and
  32897. * simple CFF fonts. See section 9.6.6.2 of the spec.
  32898. * @param {Object} properties Font properties object.
  32899. * @param {Object} builtInEncoding The encoding contained within the actual font
  32900. * data.
  32901. * @param {Array} glyphNames Array of glyph names where the index is the
  32902. * glyph ID.
  32903. * @returns {Object} A char code to glyph ID map.
  32904. */
  32905. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  32906. var charCodeToGlyphId = Object.create(null);
  32907. var glyphId, charCode, baseEncoding;
  32908. if (properties.baseEncodingName) {
  32909. // If a valid base encoding name was used, the mapping is initialized with
  32910. // that.
  32911. baseEncoding = getEncoding(properties.baseEncodingName);
  32912. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  32913. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  32914. if (glyphId >= 0) {
  32915. charCodeToGlyphId[charCode] = glyphId;
  32916. } else {
  32917. charCodeToGlyphId[charCode] = 0; // notdef
  32918. }
  32919. }
  32920. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  32921. // For a symbolic font the encoding should be the fonts built-in
  32922. // encoding.
  32923. for (charCode in builtInEncoding) {
  32924. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  32925. }
  32926. } else {
  32927. // For non-symbolic fonts that don't have a base encoding the standard
  32928. // encoding should be used.
  32929. baseEncoding = StandardEncoding;
  32930. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  32931. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  32932. if (glyphId >= 0) {
  32933. charCodeToGlyphId[charCode] = glyphId;
  32934. } else {
  32935. charCodeToGlyphId[charCode] = 0; // notdef
  32936. }
  32937. }
  32938. }
  32939. // Lastly, merge in the differences.
  32940. var differences = properties.differences, glyphsUnicodeMap;
  32941. if (differences) {
  32942. for (charCode in differences) {
  32943. var glyphName = differences[charCode];
  32944. glyphId = glyphNames.indexOf(glyphName);
  32945. if (glyphId === -1) {
  32946. if (!glyphsUnicodeMap) {
  32947. glyphsUnicodeMap = getGlyphsUnicode();
  32948. }
  32949. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  32950. if (standardGlyphName !== glyphName) {
  32951. glyphId = glyphNames.indexOf(standardGlyphName);
  32952. }
  32953. }
  32954. if (glyphId >= 0) {
  32955. charCodeToGlyphId[charCode] = glyphId;
  32956. } else {
  32957. charCodeToGlyphId[charCode] = 0; // notdef
  32958. }
  32959. }
  32960. }
  32961. return charCodeToGlyphId;
  32962. }
  32963. // Type1Font is also a CIDFontType0.
  32964. var Type1Font = (function Type1FontClosure() {
  32965. function findBlock(streamBytes, signature, startIndex) {
  32966. var streamBytesLength = streamBytes.length;
  32967. var signatureLength = signature.length;
  32968. var scanLength = streamBytesLength - signatureLength;
  32969. var i = startIndex, j, found = false;
  32970. while (i < scanLength) {
  32971. j = 0;
  32972. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  32973. j++;
  32974. }
  32975. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  32976. i += j;
  32977. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  32978. i++;
  32979. }
  32980. found = true;
  32981. break;
  32982. }
  32983. i++;
  32984. }
  32985. return {
  32986. found: found,
  32987. length: i,
  32988. };
  32989. }
  32990. function getHeaderBlock(stream, suggestedLength) {
  32991. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  32992. var streamStartPos = stream.pos; // Save the initial stream position.
  32993. var headerBytes, headerBytesLength, block;
  32994. try {
  32995. headerBytes = stream.getBytes(suggestedLength);
  32996. headerBytesLength = headerBytes.length;
  32997. } catch (ex) {
  32998. if (ex instanceof MissingDataException) {
  32999. throw ex;
  33000. }
  33001. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  33002. // cannot hold the result of `getBytes`, and fallback to simply checking
  33003. // the entire stream (fixes issue3928.pdf).
  33004. }
  33005. if (headerBytesLength === suggestedLength) {
  33006. // Most of the time `suggestedLength` is correct, so to speed things up we
  33007. // initially only check the last few bytes to see if the header was found.
  33008. // Otherwise we (potentially) check the entire stream to prevent errors in
  33009. // `Type1Parser` (fixes issue5686.pdf).
  33010. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  33011. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  33012. if (block.found && block.length === suggestedLength) {
  33013. return {
  33014. stream: new Stream(headerBytes),
  33015. length: suggestedLength,
  33016. };
  33017. }
  33018. }
  33019. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  33020. stream.pos = streamStartPos; // Reset the stream position.
  33021. var SCAN_BLOCK_LENGTH = 2048;
  33022. var actualLength;
  33023. while (true) {
  33024. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  33025. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  33026. if (block.length === 0) {
  33027. break;
  33028. }
  33029. stream.pos += block.length; // Update the stream position.
  33030. if (block.found) {
  33031. actualLength = stream.pos - streamStartPos;
  33032. break;
  33033. }
  33034. }
  33035. stream.pos = streamStartPos; // Reset the stream position.
  33036. if (actualLength) {
  33037. return {
  33038. stream: new Stream(stream.getBytes(actualLength)),
  33039. length: actualLength,
  33040. };
  33041. }
  33042. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  33043. return {
  33044. stream: new Stream(stream.getBytes(suggestedLength)),
  33045. length: suggestedLength,
  33046. };
  33047. }
  33048. function getEexecBlock(stream, suggestedLength) {
  33049. // We should ideally parse the eexec block to ensure that `suggestedLength`
  33050. // is correct, so we don't truncate the block data if it's too small.
  33051. // However, this would also require checking if the fixed-content portion
  33052. // exists (using the 'Length3' property), and ensuring that it's valid.
  33053. //
  33054. // Given that `suggestedLength` almost always is correct, all the validation
  33055. // would require a great deal of unnecessary parsing for most fonts.
  33056. // To save time, we always fetch the entire stream instead, which also avoid
  33057. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  33058. //
  33059. // NOTE: This means that the function can include the fixed-content portion
  33060. // in the returned eexec block. In practice this does *not* seem to matter,
  33061. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  33062. var eexecBytes = stream.getBytes();
  33063. return {
  33064. stream: new Stream(eexecBytes),
  33065. length: eexecBytes.length,
  33066. };
  33067. }
  33068. function Type1Font(name, file, properties) {
  33069. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  33070. // Also, length1 and length2 might be off by 6 bytes as well.
  33071. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  33072. var PFB_HEADER_SIZE = 6;
  33073. var headerBlockLength = properties.length1;
  33074. var eexecBlockLength = properties.length2;
  33075. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  33076. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  33077. if (pfbHeaderPresent) {
  33078. file.skip(PFB_HEADER_SIZE);
  33079. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  33080. (pfbHeader[3] << 8) | pfbHeader[2];
  33081. }
  33082. // Get the data block containing glyphs and subrs information
  33083. var headerBlock = getHeaderBlock(file, headerBlockLength);
  33084. headerBlockLength = headerBlock.length;
  33085. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  33086. SEAC_ANALYSIS_ENABLED);
  33087. headerBlockParser.extractFontHeader(properties);
  33088. if (pfbHeaderPresent) {
  33089. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  33090. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  33091. (pfbHeader[3] << 8) | pfbHeader[2];
  33092. }
  33093. // Decrypt the data blocks and retrieve it's content
  33094. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  33095. eexecBlockLength = eexecBlock.length;
  33096. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  33097. SEAC_ANALYSIS_ENABLED);
  33098. var data = eexecBlockParser.extractFontProgram();
  33099. for (var info in data.properties) {
  33100. properties[info] = data.properties[info];
  33101. }
  33102. var charstrings = data.charstrings;
  33103. var type2Charstrings = this.getType2Charstrings(charstrings);
  33104. var subrs = this.getType2Subrs(data.subrs);
  33105. this.charstrings = charstrings;
  33106. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  33107. subrs, properties);
  33108. this.seacs = this.getSeacs(data.charstrings);
  33109. }
  33110. Type1Font.prototype = {
  33111. get numGlyphs() {
  33112. return this.charstrings.length + 1;
  33113. },
  33114. getCharset: function Type1Font_getCharset() {
  33115. var charset = ['.notdef'];
  33116. var charstrings = this.charstrings;
  33117. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  33118. charset.push(charstrings[glyphId].glyphName);
  33119. }
  33120. return charset;
  33121. },
  33122. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  33123. var charstrings = this.charstrings;
  33124. var glyphNames = ['.notdef'], glyphId;
  33125. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  33126. glyphNames.push(charstrings[glyphId].glyphName);
  33127. }
  33128. var encoding = properties.builtInEncoding;
  33129. if (encoding) {
  33130. var builtInEncoding = Object.create(null);
  33131. for (var charCode in encoding) {
  33132. glyphId = glyphNames.indexOf(encoding[charCode]);
  33133. if (glyphId >= 0) {
  33134. builtInEncoding[charCode] = glyphId;
  33135. }
  33136. }
  33137. }
  33138. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  33139. },
  33140. getSeacs: function Type1Font_getSeacs(charstrings) {
  33141. var i, ii;
  33142. var seacMap = [];
  33143. for (i = 0, ii = charstrings.length; i < ii; i++) {
  33144. var charstring = charstrings[i];
  33145. if (charstring.seac) {
  33146. // Offset by 1 for .notdef
  33147. seacMap[i + 1] = charstring.seac;
  33148. }
  33149. }
  33150. return seacMap;
  33151. },
  33152. getType2Charstrings: function Type1Font_getType2Charstrings(
  33153. type1Charstrings) {
  33154. var type2Charstrings = [];
  33155. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  33156. type2Charstrings.push(type1Charstrings[i].charstring);
  33157. }
  33158. return type2Charstrings;
  33159. },
  33160. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  33161. var bias = 0;
  33162. var count = type1Subrs.length;
  33163. if (count < 1133) {
  33164. bias = 107;
  33165. } else if (count < 33769) {
  33166. bias = 1131;
  33167. } else {
  33168. bias = 32768;
  33169. }
  33170. // Add a bunch of empty subrs to deal with the Type2 bias
  33171. var type2Subrs = [];
  33172. var i;
  33173. for (i = 0; i < bias; i++) {
  33174. type2Subrs.push([0x0B]);
  33175. }
  33176. for (i = 0; i < count; i++) {
  33177. type2Subrs.push(type1Subrs[i]);
  33178. }
  33179. return type2Subrs;
  33180. },
  33181. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  33182. properties) {
  33183. var cff = new CFF();
  33184. cff.header = new CFFHeader(1, 0, 4, 4);
  33185. cff.names = [name];
  33186. var topDict = new CFFTopDict();
  33187. // CFF strings IDs 0...390 are predefined names, so refering
  33188. // to entries in our own String INDEX starts at SID 391.
  33189. topDict.setByName('version', 391);
  33190. topDict.setByName('Notice', 392);
  33191. topDict.setByName('FullName', 393);
  33192. topDict.setByName('FamilyName', 394);
  33193. topDict.setByName('Weight', 395);
  33194. topDict.setByName('Encoding', null); // placeholder
  33195. topDict.setByName('FontMatrix', properties.fontMatrix);
  33196. topDict.setByName('FontBBox', properties.bbox);
  33197. topDict.setByName('charset', null); // placeholder
  33198. topDict.setByName('CharStrings', null); // placeholder
  33199. topDict.setByName('Private', null); // placeholder
  33200. cff.topDict = topDict;
  33201. var strings = new CFFStrings();
  33202. strings.add('Version 0.11'); // Version
  33203. strings.add('See original notice'); // Notice
  33204. strings.add(name); // FullName
  33205. strings.add(name); // FamilyName
  33206. strings.add('Medium'); // Weight
  33207. cff.strings = strings;
  33208. cff.globalSubrIndex = new CFFIndex();
  33209. var count = glyphs.length;
  33210. var charsetArray = [0];
  33211. var i, ii;
  33212. for (i = 0; i < count; i++) {
  33213. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  33214. // TODO: Insert the string and correctly map it. Previously it was
  33215. // thought mapping names that aren't in the standard strings to .notdef
  33216. // was fine, however in issue818 when mapping them all to .notdef the
  33217. // adieresis glyph no longer worked.
  33218. if (index === -1) {
  33219. index = 0;
  33220. }
  33221. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  33222. }
  33223. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  33224. var charStringsIndex = new CFFIndex();
  33225. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  33226. for (i = 0; i < count; i++) {
  33227. var glyph = glyphs[i];
  33228. // If the CharString outline is empty, replace it with .notdef to
  33229. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  33230. if (glyph.length === 0) {
  33231. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  33232. continue;
  33233. }
  33234. charStringsIndex.add(glyph);
  33235. }
  33236. cff.charStrings = charStringsIndex;
  33237. var privateDict = new CFFPrivateDict();
  33238. privateDict.setByName('Subrs', null); // placeholder
  33239. var fields = [
  33240. 'BlueValues',
  33241. 'OtherBlues',
  33242. 'FamilyBlues',
  33243. 'FamilyOtherBlues',
  33244. 'StemSnapH',
  33245. 'StemSnapV',
  33246. 'BlueShift',
  33247. 'BlueFuzz',
  33248. 'BlueScale',
  33249. 'LanguageGroup',
  33250. 'ExpansionFactor',
  33251. 'ForceBold',
  33252. 'StdHW',
  33253. 'StdVW'
  33254. ];
  33255. for (i = 0, ii = fields.length; i < ii; i++) {
  33256. var field = fields[i];
  33257. if (!(field in properties.privateData)) {
  33258. continue;
  33259. }
  33260. var value = properties.privateData[field];
  33261. if (isArray(value)) {
  33262. // All of the private dictionary array data in CFF must be stored as
  33263. // "delta-encoded" numbers.
  33264. for (var j = value.length - 1; j > 0; j--) {
  33265. value[j] -= value[j - 1]; // ... difference from previous value
  33266. }
  33267. }
  33268. privateDict.setByName(field, value);
  33269. }
  33270. cff.topDict.privateDict = privateDict;
  33271. var subrIndex = new CFFIndex();
  33272. for (i = 0, ii = subrs.length; i < ii; i++) {
  33273. subrIndex.add(subrs[i]);
  33274. }
  33275. privateDict.subrsIndex = subrIndex;
  33276. var compiler = new CFFCompiler(cff);
  33277. return compiler.compile();
  33278. }
  33279. };
  33280. return Type1Font;
  33281. })();
  33282. var CFFFont = (function CFFFontClosure() {
  33283. function CFFFont(file, properties) {
  33284. this.properties = properties;
  33285. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  33286. this.cff = parser.parse();
  33287. var compiler = new CFFCompiler(this.cff);
  33288. this.seacs = this.cff.seacs;
  33289. try {
  33290. this.data = compiler.compile();
  33291. } catch (e) {
  33292. warn('Failed to compile font ' + properties.loadedName);
  33293. // There may have just been an issue with the compiler, set the data
  33294. // anyway and hope the font loaded.
  33295. this.data = file;
  33296. }
  33297. }
  33298. CFFFont.prototype = {
  33299. get numGlyphs() {
  33300. return this.cff.charStrings.count;
  33301. },
  33302. getCharset: function CFFFont_getCharset() {
  33303. return this.cff.charset.charset;
  33304. },
  33305. getGlyphMapping: function CFFFont_getGlyphMapping() {
  33306. var cff = this.cff;
  33307. var properties = this.properties;
  33308. var charsets = cff.charset.charset;
  33309. var charCodeToGlyphId;
  33310. var glyphId;
  33311. if (properties.composite) {
  33312. charCodeToGlyphId = Object.create(null);
  33313. if (cff.isCIDFont) {
  33314. // If the font is actually a CID font then we should use the charset
  33315. // to map CIDs to GIDs.
  33316. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  33317. var cid = charsets[glyphId];
  33318. var charCode = properties.cMap.charCodeOf(cid);
  33319. charCodeToGlyphId[charCode] = glyphId;
  33320. }
  33321. } else {
  33322. // If it is NOT actually a CID font then CIDs should be mapped
  33323. // directly to GIDs.
  33324. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  33325. charCodeToGlyphId[glyphId] = glyphId;
  33326. }
  33327. }
  33328. return charCodeToGlyphId;
  33329. }
  33330. var encoding = cff.encoding ? cff.encoding.encoding : null;
  33331. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  33332. return charCodeToGlyphId;
  33333. }
  33334. };
  33335. return CFFFont;
  33336. })();
  33337. // Workaround for seac on Windows.
  33338. (function checkSeacSupport() {
  33339. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  33340. SEAC_ANALYSIS_ENABLED = true;
  33341. }
  33342. })();
  33343. // Workaround for Private Use Area characters in Chrome on Windows
  33344. // http://code.google.com/p/chromium/issues/detail?id=122465
  33345. // https://github.com/mozilla/pdf.js/issues/1689
  33346. (function checkChromeWindows() {
  33347. if (typeof navigator !== 'undefined' &&
  33348. /Windows.*Chrome/.test(navigator.userAgent)) {
  33349. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  33350. }
  33351. })();
  33352. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  33353. exports.ErrorFont = ErrorFont;
  33354. exports.Font = Font;
  33355. exports.FontFlags = FontFlags;
  33356. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  33357. exports.ToUnicodeMap = ToUnicodeMap;
  33358. exports.getFontType = getFontType;
  33359. }));
  33360. (function (root, factory) {
  33361. {
  33362. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  33363. root.pdfjsCoreParser);
  33364. }
  33365. }(this, function (exports, sharedUtil, coreParser) {
  33366. var error = sharedUtil.error;
  33367. var isSpace = sharedUtil.isSpace;
  33368. var EOF = coreParser.EOF;
  33369. var PostScriptParser = (function PostScriptParserClosure() {
  33370. function PostScriptParser(lexer) {
  33371. this.lexer = lexer;
  33372. this.operators = [];
  33373. this.token = null;
  33374. this.prev = null;
  33375. }
  33376. PostScriptParser.prototype = {
  33377. nextToken: function PostScriptParser_nextToken() {
  33378. this.prev = this.token;
  33379. this.token = this.lexer.getToken();
  33380. },
  33381. accept: function PostScriptParser_accept(type) {
  33382. if (this.token.type === type) {
  33383. this.nextToken();
  33384. return true;
  33385. }
  33386. return false;
  33387. },
  33388. expect: function PostScriptParser_expect(type) {
  33389. if (this.accept(type)) {
  33390. return true;
  33391. }
  33392. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  33393. type + '.');
  33394. },
  33395. parse: function PostScriptParser_parse() {
  33396. this.nextToken();
  33397. this.expect(PostScriptTokenTypes.LBRACE);
  33398. this.parseBlock();
  33399. this.expect(PostScriptTokenTypes.RBRACE);
  33400. return this.operators;
  33401. },
  33402. parseBlock: function PostScriptParser_parseBlock() {
  33403. while (true) {
  33404. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  33405. this.operators.push(this.prev.value);
  33406. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  33407. this.operators.push(this.prev.value);
  33408. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33409. this.parseCondition();
  33410. } else {
  33411. return;
  33412. }
  33413. }
  33414. },
  33415. parseCondition: function PostScriptParser_parseCondition() {
  33416. // Add two place holders that will be updated later
  33417. var conditionLocation = this.operators.length;
  33418. this.operators.push(null, null);
  33419. this.parseBlock();
  33420. this.expect(PostScriptTokenTypes.RBRACE);
  33421. if (this.accept(PostScriptTokenTypes.IF)) {
  33422. // The true block is right after the 'if' so it just falls through on
  33423. // true else it jumps and skips the true block.
  33424. this.operators[conditionLocation] = this.operators.length;
  33425. this.operators[conditionLocation + 1] = 'jz';
  33426. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33427. var jumpLocation = this.operators.length;
  33428. this.operators.push(null, null);
  33429. var endOfTrue = this.operators.length;
  33430. this.parseBlock();
  33431. this.expect(PostScriptTokenTypes.RBRACE);
  33432. this.expect(PostScriptTokenTypes.IFELSE);
  33433. // The jump is added at the end of the true block to skip the false
  33434. // block.
  33435. this.operators[jumpLocation] = this.operators.length;
  33436. this.operators[jumpLocation + 1] = 'j';
  33437. this.operators[conditionLocation] = endOfTrue;
  33438. this.operators[conditionLocation + 1] = 'jz';
  33439. } else {
  33440. error('PS Function: error parsing conditional.');
  33441. }
  33442. }
  33443. };
  33444. return PostScriptParser;
  33445. })();
  33446. var PostScriptTokenTypes = {
  33447. LBRACE: 0,
  33448. RBRACE: 1,
  33449. NUMBER: 2,
  33450. OPERATOR: 3,
  33451. IF: 4,
  33452. IFELSE: 5
  33453. };
  33454. var PostScriptToken = (function PostScriptTokenClosure() {
  33455. function PostScriptToken(type, value) {
  33456. this.type = type;
  33457. this.value = value;
  33458. }
  33459. var opCache = Object.create(null);
  33460. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  33461. var opValue = opCache[op];
  33462. if (opValue) {
  33463. return opValue;
  33464. }
  33465. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  33466. };
  33467. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  33468. '{');
  33469. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  33470. '}');
  33471. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  33472. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  33473. 'IFELSE');
  33474. return PostScriptToken;
  33475. })();
  33476. var PostScriptLexer = (function PostScriptLexerClosure() {
  33477. function PostScriptLexer(stream) {
  33478. this.stream = stream;
  33479. this.nextChar();
  33480. this.strBuf = [];
  33481. }
  33482. PostScriptLexer.prototype = {
  33483. nextChar: function PostScriptLexer_nextChar() {
  33484. return (this.currentChar = this.stream.getByte());
  33485. },
  33486. getToken: function PostScriptLexer_getToken() {
  33487. var comment = false;
  33488. var ch = this.currentChar;
  33489. // skip comments
  33490. while (true) {
  33491. if (ch < 0) {
  33492. return EOF;
  33493. }
  33494. if (comment) {
  33495. if (ch === 0x0A || ch === 0x0D) {
  33496. comment = false;
  33497. }
  33498. } else if (ch === 0x25) { // '%'
  33499. comment = true;
  33500. } else if (!isSpace(ch)) {
  33501. break;
  33502. }
  33503. ch = this.nextChar();
  33504. }
  33505. switch (ch | 0) {
  33506. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  33507. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  33508. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  33509. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  33510. this.getNumber());
  33511. case 0x7B: // '{'
  33512. this.nextChar();
  33513. return PostScriptToken.LBRACE;
  33514. case 0x7D: // '}'
  33515. this.nextChar();
  33516. return PostScriptToken.RBRACE;
  33517. }
  33518. // operator
  33519. var strBuf = this.strBuf;
  33520. strBuf.length = 0;
  33521. strBuf[0] = String.fromCharCode(ch);
  33522. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  33523. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  33524. strBuf.push(String.fromCharCode(ch));
  33525. }
  33526. var str = strBuf.join('');
  33527. switch (str.toLowerCase()) {
  33528. case 'if':
  33529. return PostScriptToken.IF;
  33530. case 'ifelse':
  33531. return PostScriptToken.IFELSE;
  33532. default:
  33533. return PostScriptToken.getOperator(str);
  33534. }
  33535. },
  33536. getNumber: function PostScriptLexer_getNumber() {
  33537. var ch = this.currentChar;
  33538. var strBuf = this.strBuf;
  33539. strBuf.length = 0;
  33540. strBuf[0] = String.fromCharCode(ch);
  33541. while ((ch = this.nextChar()) >= 0) {
  33542. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  33543. ch === 0x2D || ch === 0x2E) { // '-', '.'
  33544. strBuf.push(String.fromCharCode(ch));
  33545. } else {
  33546. break;
  33547. }
  33548. }
  33549. var value = parseFloat(strBuf.join(''));
  33550. if (isNaN(value)) {
  33551. error('Invalid floating point number: ' + value);
  33552. }
  33553. return value;
  33554. }
  33555. };
  33556. return PostScriptLexer;
  33557. })();
  33558. exports.PostScriptLexer = PostScriptLexer;
  33559. exports.PostScriptParser = PostScriptParser;
  33560. }));
  33561. (function (root, factory) {
  33562. {
  33563. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  33564. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper,
  33565. root.pdfjsDisplayWebGL);
  33566. }
  33567. }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper,
  33568. displayWebGL) {
  33569. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33570. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  33571. var ImageKind = sharedUtil.ImageKind;
  33572. var OPS = sharedUtil.OPS;
  33573. var TextRenderingMode = sharedUtil.TextRenderingMode;
  33574. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  33575. var Util = sharedUtil.Util;
  33576. var assert = sharedUtil.assert;
  33577. var info = sharedUtil.info;
  33578. var isNum = sharedUtil.isNum;
  33579. var isArray = sharedUtil.isArray;
  33580. var isLittleEndian = sharedUtil.isLittleEndian;
  33581. var error = sharedUtil.error;
  33582. var shadow = sharedUtil.shadow;
  33583. var warn = sharedUtil.warn;
  33584. var TilingPattern = displayPatternHelper.TilingPattern;
  33585. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  33586. var WebGLUtils = displayWebGL.WebGLUtils;
  33587. var hasCanvasTypedArrays = displayDOMUtils.hasCanvasTypedArrays;
  33588. // <canvas> contexts store most of the state we need natively.
  33589. // However, PDF needs a bit more state, which we store here.
  33590. // Minimal font size that would be used during canvas fillText operations.
  33591. var MIN_FONT_SIZE = 16;
  33592. // Maximum font size that would be used during canvas fillText operations.
  33593. var MAX_FONT_SIZE = 100;
  33594. var MAX_GROUP_SIZE = 4096;
  33595. // Heuristic value used when enforcing minimum line widths.
  33596. var MIN_WIDTH_FACTOR = 0.65;
  33597. var COMPILE_TYPE3_GLYPHS = true;
  33598. var MAX_SIZE_TO_COMPILE = 1000;
  33599. var FULL_CHUNK_HEIGHT = 16;
  33600. var HasCanvasTypedArraysCached = {
  33601. get value() {
  33602. return shadow(HasCanvasTypedArraysCached, 'value', hasCanvasTypedArrays());
  33603. }
  33604. };
  33605. var IsLittleEndianCached = {
  33606. get value() {
  33607. return shadow(IsLittleEndianCached, 'value', isLittleEndian());
  33608. }
  33609. };
  33610. function createScratchCanvas(width, height) {
  33611. var canvas = document.createElement('canvas');
  33612. canvas.width = width;
  33613. canvas.height = height;
  33614. return canvas;
  33615. }
  33616. function addContextCurrentTransform(ctx) {
  33617. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  33618. if (!ctx.mozCurrentTransform) {
  33619. ctx._originalSave = ctx.save;
  33620. ctx._originalRestore = ctx.restore;
  33621. ctx._originalRotate = ctx.rotate;
  33622. ctx._originalScale = ctx.scale;
  33623. ctx._originalTranslate = ctx.translate;
  33624. ctx._originalTransform = ctx.transform;
  33625. ctx._originalSetTransform = ctx.setTransform;
  33626. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  33627. ctx._transformStack = [];
  33628. Object.defineProperty(ctx, 'mozCurrentTransform', {
  33629. get: function getCurrentTransform() {
  33630. return this._transformMatrix;
  33631. }
  33632. });
  33633. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  33634. get: function getCurrentTransformInverse() {
  33635. // Calculation done using WolframAlpha:
  33636. // http://www.wolframalpha.com/input/?
  33637. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  33638. var m = this._transformMatrix;
  33639. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  33640. var ad_bc = a * d - b * c;
  33641. var bc_ad = b * c - a * d;
  33642. return [
  33643. d / ad_bc,
  33644. b / bc_ad,
  33645. c / bc_ad,
  33646. a / ad_bc,
  33647. (d * e - c * f) / bc_ad,
  33648. (b * e - a * f) / ad_bc
  33649. ];
  33650. }
  33651. });
  33652. ctx.save = function ctxSave() {
  33653. var old = this._transformMatrix;
  33654. this._transformStack.push(old);
  33655. this._transformMatrix = old.slice(0, 6);
  33656. this._originalSave();
  33657. };
  33658. ctx.restore = function ctxRestore() {
  33659. var prev = this._transformStack.pop();
  33660. if (prev) {
  33661. this._transformMatrix = prev;
  33662. this._originalRestore();
  33663. }
  33664. };
  33665. ctx.translate = function ctxTranslate(x, y) {
  33666. var m = this._transformMatrix;
  33667. m[4] = m[0] * x + m[2] * y + m[4];
  33668. m[5] = m[1] * x + m[3] * y + m[5];
  33669. this._originalTranslate(x, y);
  33670. };
  33671. ctx.scale = function ctxScale(x, y) {
  33672. var m = this._transformMatrix;
  33673. m[0] = m[0] * x;
  33674. m[1] = m[1] * x;
  33675. m[2] = m[2] * y;
  33676. m[3] = m[3] * y;
  33677. this._originalScale(x, y);
  33678. };
  33679. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  33680. var m = this._transformMatrix;
  33681. this._transformMatrix = [
  33682. m[0] * a + m[2] * b,
  33683. m[1] * a + m[3] * b,
  33684. m[0] * c + m[2] * d,
  33685. m[1] * c + m[3] * d,
  33686. m[0] * e + m[2] * f + m[4],
  33687. m[1] * e + m[3] * f + m[5]
  33688. ];
  33689. ctx._originalTransform(a, b, c, d, e, f);
  33690. };
  33691. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  33692. this._transformMatrix = [a, b, c, d, e, f];
  33693. ctx._originalSetTransform(a, b, c, d, e, f);
  33694. };
  33695. ctx.rotate = function ctxRotate(angle) {
  33696. var cosValue = Math.cos(angle);
  33697. var sinValue = Math.sin(angle);
  33698. var m = this._transformMatrix;
  33699. this._transformMatrix = [
  33700. m[0] * cosValue + m[2] * sinValue,
  33701. m[1] * cosValue + m[3] * sinValue,
  33702. m[0] * (-sinValue) + m[2] * cosValue,
  33703. m[1] * (-sinValue) + m[3] * cosValue,
  33704. m[4],
  33705. m[5]
  33706. ];
  33707. this._originalRotate(angle);
  33708. };
  33709. }
  33710. }
  33711. var CachedCanvases = (function CachedCanvasesClosure() {
  33712. function CachedCanvases() {
  33713. this.cache = Object.create(null);
  33714. }
  33715. CachedCanvases.prototype = {
  33716. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  33717. trackTransform) {
  33718. var canvasEntry;
  33719. if (this.cache[id] !== undefined) {
  33720. canvasEntry = this.cache[id];
  33721. canvasEntry.canvas.width = width;
  33722. canvasEntry.canvas.height = height;
  33723. // reset canvas transform for emulated mozCurrentTransform, if needed
  33724. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  33725. } else {
  33726. var canvas = createScratchCanvas(width, height);
  33727. var ctx = canvas.getContext('2d');
  33728. if (trackTransform) {
  33729. addContextCurrentTransform(ctx);
  33730. }
  33731. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  33732. }
  33733. return canvasEntry;
  33734. },
  33735. clear: function () {
  33736. for (var id in this.cache) {
  33737. var canvasEntry = this.cache[id];
  33738. // Zeroing the width and height causes Firefox to release graphics
  33739. // resources immediately, which can greatly reduce memory consumption.
  33740. canvasEntry.canvas.width = 0;
  33741. canvasEntry.canvas.height = 0;
  33742. delete this.cache[id];
  33743. }
  33744. }
  33745. };
  33746. return CachedCanvases;
  33747. })();
  33748. function compileType3Glyph(imgData) {
  33749. var POINT_TO_PROCESS_LIMIT = 1000;
  33750. var width = imgData.width, height = imgData.height;
  33751. var i, j, j0, width1 = width + 1;
  33752. var points = new Uint8Array(width1 * (height + 1));
  33753. var POINT_TYPES =
  33754. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  33755. // decodes bit-packed mask data
  33756. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  33757. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  33758. for (i = 0, ii = data0.length; i < ii; i++) {
  33759. var mask = 128, elem = data0[i];
  33760. while (mask > 0) {
  33761. data[pos++] = (elem & mask) ? 0 : 255;
  33762. mask >>= 1;
  33763. }
  33764. }
  33765. // finding iteresting points: every point is located between mask pixels,
  33766. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  33767. // will have flags assigned based on neighboring mask pixels:
  33768. // 4 | 8
  33769. // --P--
  33770. // 2 | 1
  33771. // We are interested only in points with the flags:
  33772. // - outside corners: 1, 2, 4, 8;
  33773. // - inside corners: 7, 11, 13, 14;
  33774. // - and, intersections: 5, 10.
  33775. var count = 0;
  33776. pos = 0;
  33777. if (data[pos] !== 0) {
  33778. points[0] = 1;
  33779. ++count;
  33780. }
  33781. for (j = 1; j < width; j++) {
  33782. if (data[pos] !== data[pos + 1]) {
  33783. points[j] = data[pos] ? 2 : 1;
  33784. ++count;
  33785. }
  33786. pos++;
  33787. }
  33788. if (data[pos] !== 0) {
  33789. points[j] = 2;
  33790. ++count;
  33791. }
  33792. for (i = 1; i < height; i++) {
  33793. pos = i * lineSize;
  33794. j0 = i * width1;
  33795. if (data[pos - lineSize] !== data[pos]) {
  33796. points[j0] = data[pos] ? 1 : 8;
  33797. ++count;
  33798. }
  33799. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  33800. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  33801. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  33802. for (j = 1; j < width; j++) {
  33803. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  33804. (data[pos - lineSize + 1] ? 8 : 0);
  33805. if (POINT_TYPES[sum]) {
  33806. points[j0 + j] = POINT_TYPES[sum];
  33807. ++count;
  33808. }
  33809. pos++;
  33810. }
  33811. if (data[pos - lineSize] !== data[pos]) {
  33812. points[j0 + j] = data[pos] ? 2 : 4;
  33813. ++count;
  33814. }
  33815. if (count > POINT_TO_PROCESS_LIMIT) {
  33816. return null;
  33817. }
  33818. }
  33819. pos = lineSize * (height - 1);
  33820. j0 = i * width1;
  33821. if (data[pos] !== 0) {
  33822. points[j0] = 8;
  33823. ++count;
  33824. }
  33825. for (j = 1; j < width; j++) {
  33826. if (data[pos] !== data[pos + 1]) {
  33827. points[j0 + j] = data[pos] ? 4 : 8;
  33828. ++count;
  33829. }
  33830. pos++;
  33831. }
  33832. if (data[pos] !== 0) {
  33833. points[j0 + j] = 4;
  33834. ++count;
  33835. }
  33836. if (count > POINT_TO_PROCESS_LIMIT) {
  33837. return null;
  33838. }
  33839. // building outlines
  33840. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  33841. var outlines = [];
  33842. for (i = 0; count && i <= height; i++) {
  33843. var p = i * width1;
  33844. var end = p + width;
  33845. while (p < end && !points[p]) {
  33846. p++;
  33847. }
  33848. if (p === end) {
  33849. continue;
  33850. }
  33851. var coords = [p % width1, i];
  33852. var type = points[p], p0 = p, pp;
  33853. do {
  33854. var step = steps[type];
  33855. do {
  33856. p += step;
  33857. } while (!points[p]);
  33858. pp = points[p];
  33859. if (pp !== 5 && pp !== 10) {
  33860. // set new direction
  33861. type = pp;
  33862. // delete mark
  33863. points[p] = 0;
  33864. } else { // type is 5 or 10, ie, a crossing
  33865. // set new direction
  33866. type = pp & ((0x33 * type) >> 4);
  33867. // set new type for "future hit"
  33868. points[p] &= (type >> 2 | type << 2);
  33869. }
  33870. coords.push(p % width1);
  33871. coords.push((p / width1) | 0);
  33872. --count;
  33873. } while (p0 !== p);
  33874. outlines.push(coords);
  33875. --i;
  33876. }
  33877. var drawOutline = function(c) {
  33878. c.save();
  33879. // the path shall be painted in [0..1]x[0..1] space
  33880. c.scale(1 / width, -1 / height);
  33881. c.translate(0, -height);
  33882. c.beginPath();
  33883. for (var i = 0, ii = outlines.length; i < ii; i++) {
  33884. var o = outlines[i];
  33885. c.moveTo(o[0], o[1]);
  33886. for (var j = 2, jj = o.length; j < jj; j += 2) {
  33887. c.lineTo(o[j], o[j+1]);
  33888. }
  33889. }
  33890. c.fill();
  33891. c.beginPath();
  33892. c.restore();
  33893. };
  33894. return drawOutline;
  33895. }
  33896. var CanvasExtraState = (function CanvasExtraStateClosure() {
  33897. function CanvasExtraState(old) {
  33898. // Are soft masks and alpha values shapes or opacities?
  33899. this.alphaIsShape = false;
  33900. this.fontSize = 0;
  33901. this.fontSizeScale = 1;
  33902. this.textMatrix = IDENTITY_MATRIX;
  33903. this.textMatrixScale = 1;
  33904. this.fontMatrix = FONT_IDENTITY_MATRIX;
  33905. this.leading = 0;
  33906. // Current point (in user coordinates)
  33907. this.x = 0;
  33908. this.y = 0;
  33909. // Start of text line (in text coordinates)
  33910. this.lineX = 0;
  33911. this.lineY = 0;
  33912. // Character and word spacing
  33913. this.charSpacing = 0;
  33914. this.wordSpacing = 0;
  33915. this.textHScale = 1;
  33916. this.textRenderingMode = TextRenderingMode.FILL;
  33917. this.textRise = 0;
  33918. // Default fore and background colors
  33919. this.fillColor = '#000000';
  33920. this.strokeColor = '#000000';
  33921. this.patternFill = false;
  33922. // Note: fill alpha applies to all non-stroking operations
  33923. this.fillAlpha = 1;
  33924. this.strokeAlpha = 1;
  33925. this.lineWidth = 1;
  33926. this.activeSMask = null;
  33927. this.resumeSMaskCtx = null; // nonclonable field (see the save method below)
  33928. this.old = old;
  33929. }
  33930. CanvasExtraState.prototype = {
  33931. clone: function CanvasExtraState_clone() {
  33932. return Object.create(this);
  33933. },
  33934. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  33935. this.x = x;
  33936. this.y = y;
  33937. }
  33938. };
  33939. return CanvasExtraState;
  33940. })();
  33941. var CanvasGraphics = (function CanvasGraphicsClosure() {
  33942. // Defines the time the executeOperatorList is going to be executing
  33943. // before it stops and shedules a continue of execution.
  33944. var EXECUTION_TIME = 15;
  33945. // Defines the number of steps before checking the execution time
  33946. var EXECUTION_STEPS = 10;
  33947. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  33948. this.ctx = canvasCtx;
  33949. this.current = new CanvasExtraState();
  33950. this.stateStack = [];
  33951. this.pendingClip = null;
  33952. this.pendingEOFill = false;
  33953. this.res = null;
  33954. this.xobjs = null;
  33955. this.commonObjs = commonObjs;
  33956. this.objs = objs;
  33957. this.imageLayer = imageLayer;
  33958. this.groupStack = [];
  33959. this.processingType3 = null;
  33960. // Patterns are painted relative to the initial page/form transform, see pdf
  33961. // spec 8.7.2 NOTE 1.
  33962. this.baseTransform = null;
  33963. this.baseTransformStack = [];
  33964. this.groupLevel = 0;
  33965. this.smaskStack = [];
  33966. this.smaskCounter = 0;
  33967. this.tempSMask = null;
  33968. this.cachedCanvases = new CachedCanvases();
  33969. if (canvasCtx) {
  33970. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  33971. // the transformation must already be set in canvasCtx._transformMatrix.
  33972. addContextCurrentTransform(canvasCtx);
  33973. }
  33974. this.cachedGetSinglePixelWidth = null;
  33975. }
  33976. function putBinaryImageData(ctx, imgData) {
  33977. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  33978. ctx.putImageData(imgData, 0, 0);
  33979. return;
  33980. }
  33981. // Put the image data to the canvas in chunks, rather than putting the
  33982. // whole image at once. This saves JS memory, because the ImageData object
  33983. // is smaller. It also possibly saves C++ memory within the implementation
  33984. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  33985. // the data passed to putImageData()). |n| shouldn't be too small, however,
  33986. // because too many putImageData() calls will slow things down.
  33987. //
  33988. // Note: as written, if the last chunk is partial, the putImageData() call
  33989. // will (conceptually) put pixels past the bounds of the canvas. But
  33990. // that's ok; any such pixels are ignored.
  33991. var height = imgData.height, width = imgData.width;
  33992. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  33993. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  33994. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  33995. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  33996. var srcPos = 0, destPos;
  33997. var src = imgData.data;
  33998. var dest = chunkImgData.data;
  33999. var i, j, thisChunkHeight, elemsInThisChunk;
  34000. // There are multiple forms in which the pixel data can be passed, and
  34001. // imgData.kind tells us which one this is.
  34002. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  34003. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  34004. var srcLength = src.byteLength;
  34005. var dest32 = HasCanvasTypedArraysCached.value ?
  34006. new Uint32Array(dest.buffer) : new Uint32ArrayView(dest);
  34007. var dest32DataLength = dest32.length;
  34008. var fullSrcDiff = (width + 7) >> 3;
  34009. var white = 0xFFFFFFFF;
  34010. var black = (IsLittleEndianCached.value ||
  34011. !HasCanvasTypedArraysCached.value) ? 0xFF000000 : 0x000000FF;
  34012. for (i = 0; i < totalChunks; i++) {
  34013. thisChunkHeight =
  34014. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  34015. destPos = 0;
  34016. for (j = 0; j < thisChunkHeight; j++) {
  34017. var srcDiff = srcLength - srcPos;
  34018. var k = 0;
  34019. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  34020. var kEndUnrolled = kEnd & ~7;
  34021. var mask = 0;
  34022. var srcByte = 0;
  34023. for (; k < kEndUnrolled; k += 8) {
  34024. srcByte = src[srcPos++];
  34025. dest32[destPos++] = (srcByte & 128) ? white : black;
  34026. dest32[destPos++] = (srcByte & 64) ? white : black;
  34027. dest32[destPos++] = (srcByte & 32) ? white : black;
  34028. dest32[destPos++] = (srcByte & 16) ? white : black;
  34029. dest32[destPos++] = (srcByte & 8) ? white : black;
  34030. dest32[destPos++] = (srcByte & 4) ? white : black;
  34031. dest32[destPos++] = (srcByte & 2) ? white : black;
  34032. dest32[destPos++] = (srcByte & 1) ? white : black;
  34033. }
  34034. for (; k < kEnd; k++) {
  34035. if (mask === 0) {
  34036. srcByte = src[srcPos++];
  34037. mask = 128;
  34038. }
  34039. dest32[destPos++] = (srcByte & mask) ? white : black;
  34040. mask >>= 1;
  34041. }
  34042. }
  34043. // We ran out of input. Make all remaining pixels transparent.
  34044. while (destPos < dest32DataLength) {
  34045. dest32[destPos++] = 0;
  34046. }
  34047. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  34048. }
  34049. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  34050. // RGBA, 32-bits per pixel.
  34051. j = 0;
  34052. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  34053. for (i = 0; i < fullChunks; i++) {
  34054. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  34055. srcPos += elemsInThisChunk;
  34056. ctx.putImageData(chunkImgData, 0, j);
  34057. j += FULL_CHUNK_HEIGHT;
  34058. }
  34059. if (i < totalChunks) {
  34060. elemsInThisChunk = width * partialChunkHeight * 4;
  34061. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  34062. ctx.putImageData(chunkImgData, 0, j);
  34063. }
  34064. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  34065. // RGB, 24-bits per pixel.
  34066. thisChunkHeight = FULL_CHUNK_HEIGHT;
  34067. elemsInThisChunk = width * thisChunkHeight;
  34068. for (i = 0; i < totalChunks; i++) {
  34069. if (i >= fullChunks) {
  34070. thisChunkHeight = partialChunkHeight;
  34071. elemsInThisChunk = width * thisChunkHeight;
  34072. }
  34073. destPos = 0;
  34074. for (j = elemsInThisChunk; j--;) {
  34075. dest[destPos++] = src[srcPos++];
  34076. dest[destPos++] = src[srcPos++];
  34077. dest[destPos++] = src[srcPos++];
  34078. dest[destPos++] = 255;
  34079. }
  34080. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  34081. }
  34082. } else {
  34083. error('bad image kind: ' + imgData.kind);
  34084. }
  34085. }
  34086. function putBinaryImageMask(ctx, imgData) {
  34087. var height = imgData.height, width = imgData.width;
  34088. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  34089. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  34090. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  34091. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  34092. var srcPos = 0;
  34093. var src = imgData.data;
  34094. var dest = chunkImgData.data;
  34095. for (var i = 0; i < totalChunks; i++) {
  34096. var thisChunkHeight =
  34097. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  34098. // Expand the mask so it can be used by the canvas. Any required
  34099. // inversion has already been handled.
  34100. var destPos = 3; // alpha component offset
  34101. for (var j = 0; j < thisChunkHeight; j++) {
  34102. var mask = 0;
  34103. for (var k = 0; k < width; k++) {
  34104. if (!mask) {
  34105. var elem = src[srcPos++];
  34106. mask = 128;
  34107. }
  34108. dest[destPos] = (elem & mask) ? 0 : 255;
  34109. destPos += 4;
  34110. mask >>= 1;
  34111. }
  34112. }
  34113. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  34114. }
  34115. }
  34116. function copyCtxState(sourceCtx, destCtx) {
  34117. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  34118. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  34119. 'globalCompositeOperation', 'font'];
  34120. for (var i = 0, ii = properties.length; i < ii; i++) {
  34121. var property = properties[i];
  34122. if (sourceCtx[property] !== undefined) {
  34123. destCtx[property] = sourceCtx[property];
  34124. }
  34125. }
  34126. if (sourceCtx.setLineDash !== undefined) {
  34127. destCtx.setLineDash(sourceCtx.getLineDash());
  34128. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  34129. }
  34130. }
  34131. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  34132. var length = bytes.length;
  34133. for (var i = 3; i < length; i += 4) {
  34134. var alpha = bytes[i];
  34135. if (alpha === 0) {
  34136. bytes[i - 3] = r0;
  34137. bytes[i - 2] = g0;
  34138. bytes[i - 1] = b0;
  34139. } else if (alpha < 255) {
  34140. var alpha_ = 255 - alpha;
  34141. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  34142. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  34143. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  34144. }
  34145. }
  34146. }
  34147. function composeSMaskAlpha(maskData, layerData, transferMap) {
  34148. var length = maskData.length;
  34149. var scale = 1 / 255;
  34150. for (var i = 3; i < length; i += 4) {
  34151. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  34152. layerData[i] = (layerData[i] * alpha * scale) | 0;
  34153. }
  34154. }
  34155. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  34156. var length = maskData.length;
  34157. for (var i = 3; i < length; i += 4) {
  34158. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  34159. (maskData[i - 2] * 152) + // * 0.59 ....
  34160. (maskData[i - 1] * 28); // * 0.11 ....
  34161. layerData[i] = transferMap ?
  34162. (layerData[i] * transferMap[y >> 8]) >> 8 :
  34163. (layerData[i] * y) >> 16;
  34164. }
  34165. }
  34166. function genericComposeSMask(maskCtx, layerCtx, width, height,
  34167. subtype, backdrop, transferMap) {
  34168. var hasBackdrop = !!backdrop;
  34169. var r0 = hasBackdrop ? backdrop[0] : 0;
  34170. var g0 = hasBackdrop ? backdrop[1] : 0;
  34171. var b0 = hasBackdrop ? backdrop[2] : 0;
  34172. var composeFn;
  34173. if (subtype === 'Luminosity') {
  34174. composeFn = composeSMaskLuminosity;
  34175. } else {
  34176. composeFn = composeSMaskAlpha;
  34177. }
  34178. // processing image in chunks to save memory
  34179. var PIXELS_TO_PROCESS = 1048576;
  34180. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  34181. for (var row = 0; row < height; row += chunkSize) {
  34182. var chunkHeight = Math.min(chunkSize, height - row);
  34183. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  34184. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  34185. if (hasBackdrop) {
  34186. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  34187. }
  34188. composeFn(maskData.data, layerData.data, transferMap);
  34189. maskCtx.putImageData(layerData, 0, row);
  34190. }
  34191. }
  34192. function composeSMask(ctx, smask, layerCtx) {
  34193. var mask = smask.canvas;
  34194. var maskCtx = smask.context;
  34195. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  34196. smask.offsetX, smask.offsetY);
  34197. var backdrop = smask.backdrop || null;
  34198. if (!smask.transferMap && WebGLUtils.isEnabled) {
  34199. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  34200. {subtype: smask.subtype, backdrop: backdrop});
  34201. ctx.setTransform(1, 0, 0, 1, 0, 0);
  34202. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  34203. return;
  34204. }
  34205. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  34206. smask.subtype, backdrop, smask.transferMap);
  34207. ctx.drawImage(mask, 0, 0);
  34208. }
  34209. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  34210. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  34211. var NORMAL_CLIP = {};
  34212. var EO_CLIP = {};
  34213. CanvasGraphics.prototype = {
  34214. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  34215. transparency) {
  34216. // For pdfs that use blend modes we have to clear the canvas else certain
  34217. // blend modes can look wrong since we'd be blending with a white
  34218. // backdrop. The problem with a transparent backdrop though is we then
  34219. // don't get sub pixel anti aliasing on text, creating temporary
  34220. // transparent canvas when we have blend modes.
  34221. var width = this.ctx.canvas.width;
  34222. var height = this.ctx.canvas.height;
  34223. this.ctx.save();
  34224. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  34225. this.ctx.fillRect(0, 0, width, height);
  34226. this.ctx.restore();
  34227. if (transparency) {
  34228. var transparentCanvas = this.cachedCanvases.getCanvas(
  34229. 'transparent', width, height, true);
  34230. this.compositeCtx = this.ctx;
  34231. this.transparentCanvas = transparentCanvas.canvas;
  34232. this.ctx = transparentCanvas.context;
  34233. this.ctx.save();
  34234. // The transform can be applied before rendering, transferring it to
  34235. // the new canvas.
  34236. this.ctx.transform.apply(this.ctx,
  34237. this.compositeCtx.mozCurrentTransform);
  34238. }
  34239. this.ctx.save();
  34240. if (transform) {
  34241. this.ctx.transform.apply(this.ctx, transform);
  34242. }
  34243. this.ctx.transform.apply(this.ctx, viewport.transform);
  34244. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  34245. if (this.imageLayer) {
  34246. this.imageLayer.beginLayout();
  34247. }
  34248. },
  34249. executeOperatorList: function CanvasGraphics_executeOperatorList(
  34250. operatorList,
  34251. executionStartIdx, continueCallback,
  34252. stepper) {
  34253. var argsArray = operatorList.argsArray;
  34254. var fnArray = operatorList.fnArray;
  34255. var i = executionStartIdx || 0;
  34256. var argsArrayLen = argsArray.length;
  34257. // Sometimes the OperatorList to execute is empty.
  34258. if (argsArrayLen === i) {
  34259. return i;
  34260. }
  34261. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  34262. typeof continueCallback === 'function');
  34263. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  34264. var steps = 0;
  34265. var commonObjs = this.commonObjs;
  34266. var objs = this.objs;
  34267. var fnId;
  34268. while (true) {
  34269. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  34270. stepper.breakIt(i, continueCallback);
  34271. return i;
  34272. }
  34273. fnId = fnArray[i];
  34274. if (fnId !== OPS.dependency) {
  34275. this[fnId].apply(this, argsArray[i]);
  34276. } else {
  34277. var deps = argsArray[i];
  34278. for (var n = 0, nn = deps.length; n < nn; n++) {
  34279. var depObjId = deps[n];
  34280. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  34281. var objsPool = common ? commonObjs : objs;
  34282. // If the promise isn't resolved yet, add the continueCallback
  34283. // to the promise and bail out.
  34284. if (!objsPool.isResolved(depObjId)) {
  34285. objsPool.get(depObjId, continueCallback);
  34286. return i;
  34287. }
  34288. }
  34289. }
  34290. i++;
  34291. // If the entire operatorList was executed, stop as were done.
  34292. if (i === argsArrayLen) {
  34293. return i;
  34294. }
  34295. // If the execution took longer then a certain amount of time and
  34296. // `continueCallback` is specified, interrupt the execution.
  34297. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  34298. if (Date.now() > endTime) {
  34299. continueCallback();
  34300. return i;
  34301. }
  34302. steps = 0;
  34303. }
  34304. // If the operatorList isn't executed completely yet OR the execution
  34305. // time was short enough, do another execution round.
  34306. }
  34307. },
  34308. endDrawing: function CanvasGraphics_endDrawing() {
  34309. // Finishing all opened operations such as SMask group painting.
  34310. if (this.current.activeSMask !== null) {
  34311. this.endSMaskGroup();
  34312. }
  34313. this.ctx.restore();
  34314. if (this.transparentCanvas) {
  34315. this.ctx = this.compositeCtx;
  34316. this.ctx.save();
  34317. this.ctx.setTransform(1, 0, 0, 1, 0, 0); // Avoid apply transform twice
  34318. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  34319. this.ctx.restore();
  34320. this.transparentCanvas = null;
  34321. }
  34322. this.cachedCanvases.clear();
  34323. WebGLUtils.clear();
  34324. if (this.imageLayer) {
  34325. this.imageLayer.endLayout();
  34326. }
  34327. },
  34328. // Graphics state
  34329. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  34330. this.current.lineWidth = width;
  34331. this.ctx.lineWidth = width;
  34332. },
  34333. setLineCap: function CanvasGraphics_setLineCap(style) {
  34334. this.ctx.lineCap = LINE_CAP_STYLES[style];
  34335. },
  34336. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  34337. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  34338. },
  34339. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  34340. this.ctx.miterLimit = limit;
  34341. },
  34342. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  34343. var ctx = this.ctx;
  34344. if (ctx.setLineDash !== undefined) {
  34345. ctx.setLineDash(dashArray);
  34346. ctx.lineDashOffset = dashPhase;
  34347. }
  34348. },
  34349. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  34350. // Maybe if we one day fully support color spaces this will be important
  34351. // for now we can ignore.
  34352. // TODO set rendering intent?
  34353. },
  34354. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  34355. // There's no way to control this with canvas, but we can safely ignore.
  34356. // TODO set flatness?
  34357. },
  34358. setGState: function CanvasGraphics_setGState(states) {
  34359. for (var i = 0, ii = states.length; i < ii; i++) {
  34360. var state = states[i];
  34361. var key = state[0];
  34362. var value = state[1];
  34363. switch (key) {
  34364. case 'LW':
  34365. this.setLineWidth(value);
  34366. break;
  34367. case 'LC':
  34368. this.setLineCap(value);
  34369. break;
  34370. case 'LJ':
  34371. this.setLineJoin(value);
  34372. break;
  34373. case 'ML':
  34374. this.setMiterLimit(value);
  34375. break;
  34376. case 'D':
  34377. this.setDash(value[0], value[1]);
  34378. break;
  34379. case 'RI':
  34380. this.setRenderingIntent(value);
  34381. break;
  34382. case 'FL':
  34383. this.setFlatness(value);
  34384. break;
  34385. case 'Font':
  34386. this.setFont(value[0], value[1]);
  34387. break;
  34388. case 'CA':
  34389. this.current.strokeAlpha = state[1];
  34390. break;
  34391. case 'ca':
  34392. this.current.fillAlpha = state[1];
  34393. this.ctx.globalAlpha = state[1];
  34394. break;
  34395. case 'BM':
  34396. if (value && value.name && (value.name !== 'Normal')) {
  34397. var mode = value.name.replace(/([A-Z])/g,
  34398. function(c) {
  34399. return '-' + c.toLowerCase();
  34400. }
  34401. ).substring(1);
  34402. this.ctx.globalCompositeOperation = mode;
  34403. if (this.ctx.globalCompositeOperation !== mode) {
  34404. warn('globalCompositeOperation "' + mode +
  34405. '" is not supported');
  34406. }
  34407. } else {
  34408. this.ctx.globalCompositeOperation = 'source-over';
  34409. }
  34410. break;
  34411. case 'SMask':
  34412. if (this.current.activeSMask) {
  34413. // If SMask is currrenly used, it needs to be suspended or
  34414. // finished. Suspend only makes sense when at least one save()
  34415. // was performed and state needs to be reverted on restore().
  34416. if (this.stateStack.length > 0 &&
  34417. (this.stateStack[this.stateStack.length - 1].activeSMask ===
  34418. this.current.activeSMask)) {
  34419. this.suspendSMaskGroup();
  34420. } else {
  34421. this.endSMaskGroup();
  34422. }
  34423. }
  34424. this.current.activeSMask = value ? this.tempSMask : null;
  34425. if (this.current.activeSMask) {
  34426. this.beginSMaskGroup();
  34427. }
  34428. this.tempSMask = null;
  34429. break;
  34430. }
  34431. }
  34432. },
  34433. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  34434. var activeSMask = this.current.activeSMask;
  34435. var drawnWidth = activeSMask.canvas.width;
  34436. var drawnHeight = activeSMask.canvas.height;
  34437. var cacheId = 'smaskGroupAt' + this.groupLevel;
  34438. var scratchCanvas = this.cachedCanvases.getCanvas(
  34439. cacheId, drawnWidth, drawnHeight, true);
  34440. var currentCtx = this.ctx;
  34441. var currentTransform = currentCtx.mozCurrentTransform;
  34442. this.ctx.save();
  34443. var groupCtx = scratchCanvas.context;
  34444. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  34445. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  34446. groupCtx.transform.apply(groupCtx, currentTransform);
  34447. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  34448. copyCtxState(currentCtx, groupCtx);
  34449. this.ctx = groupCtx;
  34450. this.setGState([
  34451. ['BM', 'Normal'],
  34452. ['ca', 1],
  34453. ['CA', 1]
  34454. ]);
  34455. this.groupStack.push(currentCtx);
  34456. this.groupLevel++;
  34457. },
  34458. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34459. // Similar to endSMaskGroup, the intermediate canvas has to be composed
  34460. // and future ctx state restored.
  34461. var groupCtx = this.ctx;
  34462. this.groupLevel--;
  34463. this.ctx = this.groupStack.pop();
  34464. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  34465. this.ctx.restore();
  34466. this.ctx.save(); // save is needed since SMask will be resumed.
  34467. copyCtxState(groupCtx, this.ctx);
  34468. // Saving state for resuming.
  34469. this.current.resumeSMaskCtx = groupCtx;
  34470. // Transform was changed in the SMask canvas, reflecting this change on
  34471. // this.ctx.
  34472. var deltaTransform = Util.transform(
  34473. this.current.activeSMask.startTransformInverse,
  34474. groupCtx.mozCurrentTransform);
  34475. this.ctx.transform.apply(this.ctx, deltaTransform);
  34476. // SMask was composed, the results at the groupCtx can be cleared.
  34477. groupCtx.save();
  34478. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  34479. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  34480. groupCtx.restore();
  34481. },
  34482. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34483. // Resuming state saved by suspendSMaskGroup. We don't need to restore
  34484. // any groupCtx state since restore() command (the only caller) will do
  34485. // that for us. See also beginSMaskGroup.
  34486. var groupCtx = this.current.resumeSMaskCtx;
  34487. var currentCtx = this.ctx;
  34488. this.ctx = groupCtx;
  34489. this.groupStack.push(currentCtx);
  34490. this.groupLevel++;
  34491. },
  34492. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34493. var groupCtx = this.ctx;
  34494. this.groupLevel--;
  34495. this.ctx = this.groupStack.pop();
  34496. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  34497. this.ctx.restore();
  34498. copyCtxState(groupCtx, this.ctx);
  34499. // Transform was changed in the SMask canvas, reflecting this change on
  34500. // this.ctx.
  34501. var deltaTransform = Util.transform(
  34502. this.current.activeSMask.startTransformInverse,
  34503. groupCtx.mozCurrentTransform);
  34504. this.ctx.transform.apply(this.ctx, deltaTransform);
  34505. },
  34506. save: function CanvasGraphics_save() {
  34507. this.ctx.save();
  34508. var old = this.current;
  34509. this.stateStack.push(old);
  34510. this.current = old.clone();
  34511. this.current.resumeSMaskCtx = null;
  34512. },
  34513. restore: function CanvasGraphics_restore() {
  34514. // SMask was suspended, we just need to resume it.
  34515. if (this.current.resumeSMaskCtx) {
  34516. this.resumeSMaskGroup();
  34517. }
  34518. // SMask has to be finished once there is no states that are using the
  34519. // same SMask.
  34520. if (this.current.activeSMask !== null && (this.stateStack.length === 0 ||
  34521. this.stateStack[this.stateStack.length - 1].activeSMask !==
  34522. this.current.activeSMask)) {
  34523. this.endSMaskGroup();
  34524. }
  34525. if (this.stateStack.length !== 0) {
  34526. this.current = this.stateStack.pop();
  34527. this.ctx.restore();
  34528. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  34529. this.pendingClip = null;
  34530. this.cachedGetSinglePixelWidth = null;
  34531. }
  34532. },
  34533. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  34534. this.ctx.transform(a, b, c, d, e, f);
  34535. this.cachedGetSinglePixelWidth = null;
  34536. },
  34537. // Path
  34538. constructPath: function CanvasGraphics_constructPath(ops, args) {
  34539. var ctx = this.ctx;
  34540. var current = this.current;
  34541. var x = current.x, y = current.y;
  34542. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  34543. switch (ops[i] | 0) {
  34544. case OPS.rectangle:
  34545. x = args[j++];
  34546. y = args[j++];
  34547. var width = args[j++];
  34548. var height = args[j++];
  34549. if (width === 0) {
  34550. width = this.getSinglePixelWidth();
  34551. }
  34552. if (height === 0) {
  34553. height = this.getSinglePixelWidth();
  34554. }
  34555. var xw = x + width;
  34556. var yh = y + height;
  34557. this.ctx.moveTo(x, y);
  34558. this.ctx.lineTo(xw, y);
  34559. this.ctx.lineTo(xw, yh);
  34560. this.ctx.lineTo(x, yh);
  34561. this.ctx.lineTo(x, y);
  34562. this.ctx.closePath();
  34563. break;
  34564. case OPS.moveTo:
  34565. x = args[j++];
  34566. y = args[j++];
  34567. ctx.moveTo(x, y);
  34568. break;
  34569. case OPS.lineTo:
  34570. x = args[j++];
  34571. y = args[j++];
  34572. ctx.lineTo(x, y);
  34573. break;
  34574. case OPS.curveTo:
  34575. x = args[j + 4];
  34576. y = args[j + 5];
  34577. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  34578. x, y);
  34579. j += 6;
  34580. break;
  34581. case OPS.curveTo2:
  34582. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  34583. args[j + 2], args[j + 3]);
  34584. x = args[j + 2];
  34585. y = args[j + 3];
  34586. j += 4;
  34587. break;
  34588. case OPS.curveTo3:
  34589. x = args[j + 2];
  34590. y = args[j + 3];
  34591. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  34592. j += 4;
  34593. break;
  34594. case OPS.closePath:
  34595. ctx.closePath();
  34596. break;
  34597. }
  34598. }
  34599. current.setCurrentPoint(x, y);
  34600. },
  34601. closePath: function CanvasGraphics_closePath() {
  34602. this.ctx.closePath();
  34603. },
  34604. stroke: function CanvasGraphics_stroke(consumePath) {
  34605. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  34606. var ctx = this.ctx;
  34607. var strokeColor = this.current.strokeColor;
  34608. // Prevent drawing too thin lines by enforcing a minimum line width.
  34609. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  34610. this.current.lineWidth);
  34611. // For stroke we want to temporarily change the global alpha to the
  34612. // stroking alpha.
  34613. ctx.globalAlpha = this.current.strokeAlpha;
  34614. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  34615. strokeColor.type === 'Pattern') {
  34616. // for patterns, we transform to pattern space, calculate
  34617. // the pattern, call stroke, and restore to user space
  34618. ctx.save();
  34619. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  34620. ctx.stroke();
  34621. ctx.restore();
  34622. } else {
  34623. ctx.stroke();
  34624. }
  34625. if (consumePath) {
  34626. this.consumePath();
  34627. }
  34628. // Restore the global alpha to the fill alpha
  34629. ctx.globalAlpha = this.current.fillAlpha;
  34630. },
  34631. closeStroke: function CanvasGraphics_closeStroke() {
  34632. this.closePath();
  34633. this.stroke();
  34634. },
  34635. fill: function CanvasGraphics_fill(consumePath) {
  34636. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  34637. var ctx = this.ctx;
  34638. var fillColor = this.current.fillColor;
  34639. var isPatternFill = this.current.patternFill;
  34640. var needRestore = false;
  34641. if (isPatternFill) {
  34642. ctx.save();
  34643. if (this.baseTransform) {
  34644. ctx.setTransform.apply(ctx, this.baseTransform);
  34645. }
  34646. ctx.fillStyle = fillColor.getPattern(ctx, this);
  34647. needRestore = true;
  34648. }
  34649. if (this.pendingEOFill) {
  34650. if (ctx.mozFillRule !== undefined) {
  34651. ctx.mozFillRule = 'evenodd';
  34652. ctx.fill();
  34653. ctx.mozFillRule = 'nonzero';
  34654. } else {
  34655. ctx.fill('evenodd');
  34656. }
  34657. this.pendingEOFill = false;
  34658. } else {
  34659. ctx.fill();
  34660. }
  34661. if (needRestore) {
  34662. ctx.restore();
  34663. }
  34664. if (consumePath) {
  34665. this.consumePath();
  34666. }
  34667. },
  34668. eoFill: function CanvasGraphics_eoFill() {
  34669. this.pendingEOFill = true;
  34670. this.fill();
  34671. },
  34672. fillStroke: function CanvasGraphics_fillStroke() {
  34673. this.fill(false);
  34674. this.stroke(false);
  34675. this.consumePath();
  34676. },
  34677. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  34678. this.pendingEOFill = true;
  34679. this.fillStroke();
  34680. },
  34681. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  34682. this.closePath();
  34683. this.fillStroke();
  34684. },
  34685. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  34686. this.pendingEOFill = true;
  34687. this.closePath();
  34688. this.fillStroke();
  34689. },
  34690. endPath: function CanvasGraphics_endPath() {
  34691. this.consumePath();
  34692. },
  34693. // Clipping
  34694. clip: function CanvasGraphics_clip() {
  34695. this.pendingClip = NORMAL_CLIP;
  34696. },
  34697. eoClip: function CanvasGraphics_eoClip() {
  34698. this.pendingClip = EO_CLIP;
  34699. },
  34700. // Text
  34701. beginText: function CanvasGraphics_beginText() {
  34702. this.current.textMatrix = IDENTITY_MATRIX;
  34703. this.current.textMatrixScale = 1;
  34704. this.current.x = this.current.lineX = 0;
  34705. this.current.y = this.current.lineY = 0;
  34706. },
  34707. endText: function CanvasGraphics_endText() {
  34708. var paths = this.pendingTextPaths;
  34709. var ctx = this.ctx;
  34710. if (paths === undefined) {
  34711. ctx.beginPath();
  34712. return;
  34713. }
  34714. ctx.save();
  34715. ctx.beginPath();
  34716. for (var i = 0; i < paths.length; i++) {
  34717. var path = paths[i];
  34718. ctx.setTransform.apply(ctx, path.transform);
  34719. ctx.translate(path.x, path.y);
  34720. path.addToPath(ctx, path.fontSize);
  34721. }
  34722. ctx.restore();
  34723. ctx.clip();
  34724. ctx.beginPath();
  34725. delete this.pendingTextPaths;
  34726. },
  34727. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  34728. this.current.charSpacing = spacing;
  34729. },
  34730. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  34731. this.current.wordSpacing = spacing;
  34732. },
  34733. setHScale: function CanvasGraphics_setHScale(scale) {
  34734. this.current.textHScale = scale / 100;
  34735. },
  34736. setLeading: function CanvasGraphics_setLeading(leading) {
  34737. this.current.leading = -leading;
  34738. },
  34739. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  34740. var fontObj = this.commonObjs.get(fontRefName);
  34741. var current = this.current;
  34742. if (!fontObj) {
  34743. error('Can\'t find font for ' + fontRefName);
  34744. }
  34745. current.fontMatrix = (fontObj.fontMatrix ?
  34746. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  34747. // A valid matrix needs all main diagonal elements to be non-zero
  34748. // This also ensures we bypass FF bugzilla bug #719844.
  34749. if (current.fontMatrix[0] === 0 ||
  34750. current.fontMatrix[3] === 0) {
  34751. warn('Invalid font matrix for font ' + fontRefName);
  34752. }
  34753. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  34754. // and in some docs this can be negative (inverted x-y axes).
  34755. if (size < 0) {
  34756. size = -size;
  34757. current.fontDirection = -1;
  34758. } else {
  34759. current.fontDirection = 1;
  34760. }
  34761. this.current.font = fontObj;
  34762. this.current.fontSize = size;
  34763. if (fontObj.isType3Font) {
  34764. return; // we don't need ctx.font for Type3 fonts
  34765. }
  34766. var name = fontObj.loadedName || 'sans-serif';
  34767. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  34768. (fontObj.bold ? 'bold' : 'normal');
  34769. var italic = fontObj.italic ? 'italic' : 'normal';
  34770. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  34771. // Some font backends cannot handle fonts below certain size.
  34772. // Keeping the font at minimal size and using the fontSizeScale to change
  34773. // the current transformation matrix before the fillText/strokeText.
  34774. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  34775. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  34776. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  34777. this.current.fontSizeScale = size / browserFontSize;
  34778. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  34779. this.ctx.font = rule;
  34780. },
  34781. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  34782. this.current.textRenderingMode = mode;
  34783. },
  34784. setTextRise: function CanvasGraphics_setTextRise(rise) {
  34785. this.current.textRise = rise;
  34786. },
  34787. moveText: function CanvasGraphics_moveText(x, y) {
  34788. this.current.x = this.current.lineX += x;
  34789. this.current.y = this.current.lineY += y;
  34790. },
  34791. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  34792. this.setLeading(-y);
  34793. this.moveText(x, y);
  34794. },
  34795. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  34796. this.current.textMatrix = [a, b, c, d, e, f];
  34797. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  34798. this.current.x = this.current.lineX = 0;
  34799. this.current.y = this.current.lineY = 0;
  34800. },
  34801. nextLine: function CanvasGraphics_nextLine() {
  34802. this.moveText(0, this.current.leading);
  34803. },
  34804. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  34805. var ctx = this.ctx;
  34806. var current = this.current;
  34807. var font = current.font;
  34808. var textRenderingMode = current.textRenderingMode;
  34809. var fontSize = current.fontSize / current.fontSizeScale;
  34810. var fillStrokeMode = textRenderingMode &
  34811. TextRenderingMode.FILL_STROKE_MASK;
  34812. var isAddToPathSet = !!(textRenderingMode &
  34813. TextRenderingMode.ADD_TO_PATH_FLAG);
  34814. var addToPath;
  34815. if (font.disableFontFace || isAddToPathSet) {
  34816. addToPath = font.getPathGenerator(this.commonObjs, character);
  34817. }
  34818. if (font.disableFontFace) {
  34819. ctx.save();
  34820. ctx.translate(x, y);
  34821. ctx.beginPath();
  34822. addToPath(ctx, fontSize);
  34823. if (fillStrokeMode === TextRenderingMode.FILL ||
  34824. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34825. ctx.fill();
  34826. }
  34827. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34828. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34829. ctx.stroke();
  34830. }
  34831. ctx.restore();
  34832. } else {
  34833. if (fillStrokeMode === TextRenderingMode.FILL ||
  34834. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34835. ctx.fillText(character, x, y);
  34836. }
  34837. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34838. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34839. ctx.strokeText(character, x, y);
  34840. }
  34841. }
  34842. if (isAddToPathSet) {
  34843. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  34844. paths.push({
  34845. transform: ctx.mozCurrentTransform,
  34846. x: x,
  34847. y: y,
  34848. fontSize: fontSize,
  34849. addToPath: addToPath
  34850. });
  34851. }
  34852. },
  34853. get isFontSubpixelAAEnabled() {
  34854. // Checks if anti-aliasing is enabled when scaled text is painted.
  34855. // On Windows GDI scaled fonts looks bad.
  34856. var ctx = document.createElement('canvas').getContext('2d');
  34857. ctx.scale(1.5, 1);
  34858. ctx.fillText('I', 0, 10);
  34859. var data = ctx.getImageData(0, 0, 10, 10).data;
  34860. var enabled = false;
  34861. for (var i = 3; i < data.length; i += 4) {
  34862. if (data[i] > 0 && data[i] < 255) {
  34863. enabled = true;
  34864. break;
  34865. }
  34866. }
  34867. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  34868. },
  34869. showText: function CanvasGraphics_showText(glyphs) {
  34870. var current = this.current;
  34871. var font = current.font;
  34872. if (font.isType3Font) {
  34873. return this.showType3Text(glyphs);
  34874. }
  34875. var fontSize = current.fontSize;
  34876. if (fontSize === 0) {
  34877. return;
  34878. }
  34879. var ctx = this.ctx;
  34880. var fontSizeScale = current.fontSizeScale;
  34881. var charSpacing = current.charSpacing;
  34882. var wordSpacing = current.wordSpacing;
  34883. var fontDirection = current.fontDirection;
  34884. var textHScale = current.textHScale * fontDirection;
  34885. var glyphsLength = glyphs.length;
  34886. var vertical = font.vertical;
  34887. var spacingDir = vertical ? 1 : -1;
  34888. var defaultVMetrics = font.defaultVMetrics;
  34889. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  34890. var simpleFillText =
  34891. current.textRenderingMode === TextRenderingMode.FILL &&
  34892. !font.disableFontFace;
  34893. ctx.save();
  34894. ctx.transform.apply(ctx, current.textMatrix);
  34895. ctx.translate(current.x, current.y + current.textRise);
  34896. if (current.patternFill) {
  34897. // TODO: Some shading patterns are not applied correctly to text,
  34898. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  34899. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  34900. }
  34901. if (fontDirection > 0) {
  34902. ctx.scale(textHScale, -1);
  34903. } else {
  34904. ctx.scale(textHScale, 1);
  34905. }
  34906. var lineWidth = current.lineWidth;
  34907. var scale = current.textMatrixScale;
  34908. if (scale === 0 || lineWidth === 0) {
  34909. var fillStrokeMode = current.textRenderingMode &
  34910. TextRenderingMode.FILL_STROKE_MASK;
  34911. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34912. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34913. this.cachedGetSinglePixelWidth = null;
  34914. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  34915. }
  34916. } else {
  34917. lineWidth /= scale;
  34918. }
  34919. if (fontSizeScale !== 1.0) {
  34920. ctx.scale(fontSizeScale, fontSizeScale);
  34921. lineWidth /= fontSizeScale;
  34922. }
  34923. ctx.lineWidth = lineWidth;
  34924. var x = 0, i;
  34925. for (i = 0; i < glyphsLength; ++i) {
  34926. var glyph = glyphs[i];
  34927. if (isNum(glyph)) {
  34928. x += spacingDir * glyph * fontSize / 1000;
  34929. continue;
  34930. }
  34931. var restoreNeeded = false;
  34932. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  34933. var character = glyph.fontChar;
  34934. var accent = glyph.accent;
  34935. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  34936. var width = glyph.width;
  34937. if (vertical) {
  34938. var vmetric, vx, vy;
  34939. vmetric = glyph.vmetric || defaultVMetrics;
  34940. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  34941. vx = -vx * widthAdvanceScale;
  34942. vy = vmetric[2] * widthAdvanceScale;
  34943. width = vmetric ? -vmetric[0] : width;
  34944. scaledX = vx / fontSizeScale;
  34945. scaledY = (x + vy) / fontSizeScale;
  34946. } else {
  34947. scaledX = x / fontSizeScale;
  34948. scaledY = 0;
  34949. }
  34950. if (font.remeasure && width > 0) {
  34951. // Some standard fonts may not have the exact width: rescale per
  34952. // character if measured width is greater than expected glyph width
  34953. // and subpixel-aa is enabled, otherwise just center the glyph.
  34954. var measuredWidth = ctx.measureText(character).width * 1000 /
  34955. fontSize * fontSizeScale;
  34956. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  34957. var characterScaleX = width / measuredWidth;
  34958. restoreNeeded = true;
  34959. ctx.save();
  34960. ctx.scale(characterScaleX, 1);
  34961. scaledX /= characterScaleX;
  34962. } else if (width !== measuredWidth) {
  34963. scaledX += (width - measuredWidth) / 2000 *
  34964. fontSize / fontSizeScale;
  34965. }
  34966. }
  34967. // Only attempt to draw the glyph if it is actually in the embedded font
  34968. // file or if there isn't a font file so the fallback font is shown.
  34969. if (glyph.isInFont || font.missingFile) {
  34970. if (simpleFillText && !accent) {
  34971. // common case
  34972. ctx.fillText(character, scaledX, scaledY);
  34973. } else {
  34974. this.paintChar(character, scaledX, scaledY);
  34975. if (accent) {
  34976. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  34977. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  34978. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  34979. }
  34980. }
  34981. }
  34982. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  34983. x += charWidth;
  34984. if (restoreNeeded) {
  34985. ctx.restore();
  34986. }
  34987. }
  34988. if (vertical) {
  34989. current.y -= x * textHScale;
  34990. } else {
  34991. current.x += x * textHScale;
  34992. }
  34993. ctx.restore();
  34994. },
  34995. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  34996. // Type3 fonts - each glyph is a "mini-PDF"
  34997. var ctx = this.ctx;
  34998. var current = this.current;
  34999. var font = current.font;
  35000. var fontSize = current.fontSize;
  35001. var fontDirection = current.fontDirection;
  35002. var spacingDir = font.vertical ? 1 : -1;
  35003. var charSpacing = current.charSpacing;
  35004. var wordSpacing = current.wordSpacing;
  35005. var textHScale = current.textHScale * fontDirection;
  35006. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  35007. var glyphsLength = glyphs.length;
  35008. var isTextInvisible =
  35009. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  35010. var i, glyph, width, spacingLength;
  35011. if (isTextInvisible || fontSize === 0) {
  35012. return;
  35013. }
  35014. this.cachedGetSinglePixelWidth = null;
  35015. ctx.save();
  35016. ctx.transform.apply(ctx, current.textMatrix);
  35017. ctx.translate(current.x, current.y);
  35018. ctx.scale(textHScale, fontDirection);
  35019. for (i = 0; i < glyphsLength; ++i) {
  35020. glyph = glyphs[i];
  35021. if (isNum(glyph)) {
  35022. spacingLength = spacingDir * glyph * fontSize / 1000;
  35023. this.ctx.translate(spacingLength, 0);
  35024. current.x += spacingLength * textHScale;
  35025. continue;
  35026. }
  35027. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  35028. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  35029. if (!operatorList) {
  35030. warn('Type3 character \"' + glyph.operatorListId +
  35031. '\" is not available');
  35032. continue;
  35033. }
  35034. this.processingType3 = glyph;
  35035. this.save();
  35036. ctx.scale(fontSize, fontSize);
  35037. ctx.transform.apply(ctx, fontMatrix);
  35038. this.executeOperatorList(operatorList);
  35039. this.restore();
  35040. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  35041. width = transformed[0] * fontSize + spacing;
  35042. ctx.translate(width, 0);
  35043. current.x += width * textHScale;
  35044. }
  35045. ctx.restore();
  35046. this.processingType3 = null;
  35047. },
  35048. // Type3 fonts
  35049. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  35050. // We can safely ignore this since the width should be the same
  35051. // as the width in the Widths array.
  35052. },
  35053. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  35054. yWidth,
  35055. llx,
  35056. lly,
  35057. urx,
  35058. ury) {
  35059. // TODO According to the spec we're also suppose to ignore any operators
  35060. // that set color or include images while processing this type3 font.
  35061. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  35062. this.clip();
  35063. this.endPath();
  35064. },
  35065. // Color
  35066. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  35067. var pattern;
  35068. if (IR[0] === 'TilingPattern') {
  35069. var color = IR[1];
  35070. var baseTransform = this.baseTransform ||
  35071. this.ctx.mozCurrentTransform.slice();
  35072. var self = this;
  35073. var canvasGraphicsFactory = {
  35074. createCanvasGraphics: function (ctx) {
  35075. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  35076. }
  35077. };
  35078. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  35079. baseTransform);
  35080. } else {
  35081. pattern = getShadingPatternFromIR(IR);
  35082. }
  35083. return pattern;
  35084. },
  35085. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  35086. this.current.strokeColor = this.getColorN_Pattern(arguments);
  35087. },
  35088. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  35089. this.current.fillColor = this.getColorN_Pattern(arguments);
  35090. this.current.patternFill = true;
  35091. },
  35092. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  35093. var color = Util.makeCssRgb(r, g, b);
  35094. this.ctx.strokeStyle = color;
  35095. this.current.strokeColor = color;
  35096. },
  35097. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  35098. var color = Util.makeCssRgb(r, g, b);
  35099. this.ctx.fillStyle = color;
  35100. this.current.fillColor = color;
  35101. this.current.patternFill = false;
  35102. },
  35103. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  35104. var ctx = this.ctx;
  35105. this.save();
  35106. var pattern = getShadingPatternFromIR(patternIR);
  35107. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  35108. var inv = ctx.mozCurrentTransformInverse;
  35109. if (inv) {
  35110. var canvas = ctx.canvas;
  35111. var width = canvas.width;
  35112. var height = canvas.height;
  35113. var bl = Util.applyTransform([0, 0], inv);
  35114. var br = Util.applyTransform([0, height], inv);
  35115. var ul = Util.applyTransform([width, 0], inv);
  35116. var ur = Util.applyTransform([width, height], inv);
  35117. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  35118. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  35119. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  35120. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  35121. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  35122. } else {
  35123. // HACK to draw the gradient onto an infinite rectangle.
  35124. // PDF gradients are drawn across the entire image while
  35125. // Canvas only allows gradients to be drawn in a rectangle
  35126. // The following bug should allow us to remove this.
  35127. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  35128. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  35129. }
  35130. this.restore();
  35131. },
  35132. // Images
  35133. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  35134. error('Should not call beginInlineImage');
  35135. },
  35136. beginImageData: function CanvasGraphics_beginImageData() {
  35137. error('Should not call beginImageData');
  35138. },
  35139. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  35140. bbox) {
  35141. this.save();
  35142. this.baseTransformStack.push(this.baseTransform);
  35143. if (isArray(matrix) && 6 === matrix.length) {
  35144. this.transform.apply(this, matrix);
  35145. }
  35146. this.baseTransform = this.ctx.mozCurrentTransform;
  35147. if (isArray(bbox) && 4 === bbox.length) {
  35148. var width = bbox[2] - bbox[0];
  35149. var height = bbox[3] - bbox[1];
  35150. this.ctx.rect(bbox[0], bbox[1], width, height);
  35151. this.clip();
  35152. this.endPath();
  35153. }
  35154. },
  35155. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  35156. this.restore();
  35157. this.baseTransform = this.baseTransformStack.pop();
  35158. },
  35159. beginGroup: function CanvasGraphics_beginGroup(group) {
  35160. this.save();
  35161. var currentCtx = this.ctx;
  35162. // TODO non-isolated groups - according to Rik at adobe non-isolated
  35163. // group results aren't usually that different and they even have tools
  35164. // that ignore this setting. Notes from Rik on implementing:
  35165. // - When you encounter an transparency group, create a new canvas with
  35166. // the dimensions of the bbox
  35167. // - copy the content from the previous canvas to the new canvas
  35168. // - draw as usual
  35169. // - remove the backdrop alpha:
  35170. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  35171. // value of your transparency group and 'alphaBackdrop' the alpha of the
  35172. // backdrop
  35173. // - remove background color:
  35174. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  35175. if (!group.isolated) {
  35176. info('TODO: Support non-isolated groups.');
  35177. }
  35178. // TODO knockout - supposedly possible with the clever use of compositing
  35179. // modes.
  35180. if (group.knockout) {
  35181. warn('Knockout groups not supported.');
  35182. }
  35183. var currentTransform = currentCtx.mozCurrentTransform;
  35184. if (group.matrix) {
  35185. currentCtx.transform.apply(currentCtx, group.matrix);
  35186. }
  35187. assert(group.bbox, 'Bounding box is required.');
  35188. // Based on the current transform figure out how big the bounding box
  35189. // will actually be.
  35190. var bounds = Util.getAxialAlignedBoundingBox(
  35191. group.bbox,
  35192. currentCtx.mozCurrentTransform);
  35193. // Clip the bounding box to the current canvas.
  35194. var canvasBounds = [0,
  35195. 0,
  35196. currentCtx.canvas.width,
  35197. currentCtx.canvas.height];
  35198. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  35199. // Use ceil in case we're between sizes so we don't create canvas that is
  35200. // too small and make the canvas at least 1x1 pixels.
  35201. var offsetX = Math.floor(bounds[0]);
  35202. var offsetY = Math.floor(bounds[1]);
  35203. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  35204. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  35205. var scaleX = 1, scaleY = 1;
  35206. if (drawnWidth > MAX_GROUP_SIZE) {
  35207. scaleX = drawnWidth / MAX_GROUP_SIZE;
  35208. drawnWidth = MAX_GROUP_SIZE;
  35209. }
  35210. if (drawnHeight > MAX_GROUP_SIZE) {
  35211. scaleY = drawnHeight / MAX_GROUP_SIZE;
  35212. drawnHeight = MAX_GROUP_SIZE;
  35213. }
  35214. var cacheId = 'groupAt' + this.groupLevel;
  35215. if (group.smask) {
  35216. // Using two cache entries is case if masks are used one after another.
  35217. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  35218. }
  35219. var scratchCanvas = this.cachedCanvases.getCanvas(
  35220. cacheId, drawnWidth, drawnHeight, true);
  35221. var groupCtx = scratchCanvas.context;
  35222. // Since we created a new canvas that is just the size of the bounding box
  35223. // we have to translate the group ctx.
  35224. groupCtx.scale(1 / scaleX, 1 / scaleY);
  35225. groupCtx.translate(-offsetX, -offsetY);
  35226. groupCtx.transform.apply(groupCtx, currentTransform);
  35227. if (group.smask) {
  35228. // Saving state and cached mask to be used in setGState.
  35229. this.smaskStack.push({
  35230. canvas: scratchCanvas.canvas,
  35231. context: groupCtx,
  35232. offsetX: offsetX,
  35233. offsetY: offsetY,
  35234. scaleX: scaleX,
  35235. scaleY: scaleY,
  35236. subtype: group.smask.subtype,
  35237. backdrop: group.smask.backdrop,
  35238. transferMap: group.smask.transferMap || null,
  35239. startTransformInverse: null, // used during suspend operation
  35240. });
  35241. } else {
  35242. // Setup the current ctx so when the group is popped we draw it at the
  35243. // right location.
  35244. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  35245. currentCtx.translate(offsetX, offsetY);
  35246. currentCtx.scale(scaleX, scaleY);
  35247. }
  35248. // The transparency group inherits all off the current graphics state
  35249. // except the blend mode, soft mask, and alpha constants.
  35250. copyCtxState(currentCtx, groupCtx);
  35251. this.ctx = groupCtx;
  35252. this.setGState([
  35253. ['BM', 'Normal'],
  35254. ['ca', 1],
  35255. ['CA', 1]
  35256. ]);
  35257. this.groupStack.push(currentCtx);
  35258. this.groupLevel++;
  35259. // Reseting mask state, masks will be applied on restore of the group.
  35260. this.current.activeSMask = null;
  35261. },
  35262. endGroup: function CanvasGraphics_endGroup(group) {
  35263. this.groupLevel--;
  35264. var groupCtx = this.ctx;
  35265. this.ctx = this.groupStack.pop();
  35266. // Turn off image smoothing to avoid sub pixel interpolation which can
  35267. // look kind of blurry for some pdfs.
  35268. if (this.ctx.imageSmoothingEnabled !== undefined) {
  35269. this.ctx.imageSmoothingEnabled = false;
  35270. } else {
  35271. this.ctx.mozImageSmoothingEnabled = false;
  35272. }
  35273. if (group.smask) {
  35274. this.tempSMask = this.smaskStack.pop();
  35275. } else {
  35276. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  35277. }
  35278. this.restore();
  35279. },
  35280. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  35281. this.save();
  35282. this.current = new CanvasExtraState();
  35283. if (this.baseTransform) {
  35284. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  35285. }
  35286. },
  35287. endAnnotations: function CanvasGraphics_endAnnotations() {
  35288. this.restore();
  35289. },
  35290. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  35291. matrix) {
  35292. this.save();
  35293. if (isArray(rect) && 4 === rect.length) {
  35294. var width = rect[2] - rect[0];
  35295. var height = rect[3] - rect[1];
  35296. this.ctx.rect(rect[0], rect[1], width, height);
  35297. this.clip();
  35298. this.endPath();
  35299. }
  35300. this.transform.apply(this, transform);
  35301. this.transform.apply(this, matrix);
  35302. },
  35303. endAnnotation: function CanvasGraphics_endAnnotation() {
  35304. this.restore();
  35305. },
  35306. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  35307. var domImage = this.objs.get(objId);
  35308. if (!domImage) {
  35309. warn('Dependent image isn\'t ready yet');
  35310. return;
  35311. }
  35312. this.save();
  35313. var ctx = this.ctx;
  35314. // scale the image to the unit square
  35315. ctx.scale(1 / w, -1 / h);
  35316. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  35317. 0, -h, w, h);
  35318. if (this.imageLayer) {
  35319. var currentTransform = ctx.mozCurrentTransformInverse;
  35320. var position = this.getCanvasPosition(0, 0);
  35321. this.imageLayer.appendImage({
  35322. objId: objId,
  35323. left: position[0],
  35324. top: position[1],
  35325. width: w / currentTransform[0],
  35326. height: h / currentTransform[3]
  35327. });
  35328. }
  35329. this.restore();
  35330. },
  35331. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  35332. var ctx = this.ctx;
  35333. var width = img.width, height = img.height;
  35334. var fillColor = this.current.fillColor;
  35335. var isPatternFill = this.current.patternFill;
  35336. var glyph = this.processingType3;
  35337. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  35338. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  35339. glyph.compiled =
  35340. compileType3Glyph({data: img.data, width: width, height: height});
  35341. } else {
  35342. glyph.compiled = null;
  35343. }
  35344. }
  35345. if (glyph && glyph.compiled) {
  35346. glyph.compiled(ctx);
  35347. return;
  35348. }
  35349. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35350. width, height);
  35351. var maskCtx = maskCanvas.context;
  35352. maskCtx.save();
  35353. putBinaryImageMask(maskCtx, img);
  35354. maskCtx.globalCompositeOperation = 'source-in';
  35355. maskCtx.fillStyle = isPatternFill ?
  35356. fillColor.getPattern(maskCtx, this) : fillColor;
  35357. maskCtx.fillRect(0, 0, width, height);
  35358. maskCtx.restore();
  35359. this.paintInlineImageXObject(maskCanvas.canvas);
  35360. },
  35361. paintImageMaskXObjectRepeat:
  35362. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  35363. scaleY, positions) {
  35364. var width = imgData.width;
  35365. var height = imgData.height;
  35366. var fillColor = this.current.fillColor;
  35367. var isPatternFill = this.current.patternFill;
  35368. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35369. width, height);
  35370. var maskCtx = maskCanvas.context;
  35371. maskCtx.save();
  35372. putBinaryImageMask(maskCtx, imgData);
  35373. maskCtx.globalCompositeOperation = 'source-in';
  35374. maskCtx.fillStyle = isPatternFill ?
  35375. fillColor.getPattern(maskCtx, this) : fillColor;
  35376. maskCtx.fillRect(0, 0, width, height);
  35377. maskCtx.restore();
  35378. var ctx = this.ctx;
  35379. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  35380. ctx.save();
  35381. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  35382. ctx.scale(1, -1);
  35383. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  35384. 0, -1, 1, 1);
  35385. ctx.restore();
  35386. }
  35387. },
  35388. paintImageMaskXObjectGroup:
  35389. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  35390. var ctx = this.ctx;
  35391. var fillColor = this.current.fillColor;
  35392. var isPatternFill = this.current.patternFill;
  35393. for (var i = 0, ii = images.length; i < ii; i++) {
  35394. var image = images[i];
  35395. var width = image.width, height = image.height;
  35396. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35397. width, height);
  35398. var maskCtx = maskCanvas.context;
  35399. maskCtx.save();
  35400. putBinaryImageMask(maskCtx, image);
  35401. maskCtx.globalCompositeOperation = 'source-in';
  35402. maskCtx.fillStyle = isPatternFill ?
  35403. fillColor.getPattern(maskCtx, this) : fillColor;
  35404. maskCtx.fillRect(0, 0, width, height);
  35405. maskCtx.restore();
  35406. ctx.save();
  35407. ctx.transform.apply(ctx, image.transform);
  35408. ctx.scale(1, -1);
  35409. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  35410. 0, -1, 1, 1);
  35411. ctx.restore();
  35412. }
  35413. },
  35414. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  35415. var imgData = this.objs.get(objId);
  35416. if (!imgData) {
  35417. warn('Dependent image isn\'t ready yet');
  35418. return;
  35419. }
  35420. this.paintInlineImageXObject(imgData);
  35421. },
  35422. paintImageXObjectRepeat:
  35423. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  35424. positions) {
  35425. var imgData = this.objs.get(objId);
  35426. if (!imgData) {
  35427. warn('Dependent image isn\'t ready yet');
  35428. return;
  35429. }
  35430. var width = imgData.width;
  35431. var height = imgData.height;
  35432. var map = [];
  35433. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  35434. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  35435. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  35436. }
  35437. this.paintInlineImageXObjectGroup(imgData, map);
  35438. },
  35439. paintInlineImageXObject:
  35440. function CanvasGraphics_paintInlineImageXObject(imgData) {
  35441. var width = imgData.width;
  35442. var height = imgData.height;
  35443. var ctx = this.ctx;
  35444. this.save();
  35445. // scale the image to the unit square
  35446. ctx.scale(1 / width, -1 / height);
  35447. var currentTransform = ctx.mozCurrentTransformInverse;
  35448. var a = currentTransform[0], b = currentTransform[1];
  35449. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  35450. var c = currentTransform[2], d = currentTransform[3];
  35451. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  35452. var imgToPaint, tmpCanvas;
  35453. // instanceof HTMLElement does not work in jsdom node.js module
  35454. if (imgData instanceof HTMLElement || !imgData.data) {
  35455. imgToPaint = imgData;
  35456. } else {
  35457. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  35458. width, height);
  35459. var tmpCtx = tmpCanvas.context;
  35460. putBinaryImageData(tmpCtx, imgData);
  35461. imgToPaint = tmpCanvas.canvas;
  35462. }
  35463. var paintWidth = width, paintHeight = height;
  35464. var tmpCanvasId = 'prescale1';
  35465. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  35466. // pixels during drawImage operation, painting on the temporary canvas(es)
  35467. // that are twice smaller in size
  35468. while ((widthScale > 2 && paintWidth > 1) ||
  35469. (heightScale > 2 && paintHeight > 1)) {
  35470. var newWidth = paintWidth, newHeight = paintHeight;
  35471. if (widthScale > 2 && paintWidth > 1) {
  35472. newWidth = Math.ceil(paintWidth / 2);
  35473. widthScale /= paintWidth / newWidth;
  35474. }
  35475. if (heightScale > 2 && paintHeight > 1) {
  35476. newHeight = Math.ceil(paintHeight / 2);
  35477. heightScale /= paintHeight / newHeight;
  35478. }
  35479. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  35480. newWidth, newHeight);
  35481. tmpCtx = tmpCanvas.context;
  35482. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  35483. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  35484. 0, 0, newWidth, newHeight);
  35485. imgToPaint = tmpCanvas.canvas;
  35486. paintWidth = newWidth;
  35487. paintHeight = newHeight;
  35488. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  35489. }
  35490. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  35491. 0, -height, width, height);
  35492. if (this.imageLayer) {
  35493. var position = this.getCanvasPosition(0, -height);
  35494. this.imageLayer.appendImage({
  35495. imgData: imgData,
  35496. left: position[0],
  35497. top: position[1],
  35498. width: width / currentTransform[0],
  35499. height: height / currentTransform[3]
  35500. });
  35501. }
  35502. this.restore();
  35503. },
  35504. paintInlineImageXObjectGroup:
  35505. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  35506. var ctx = this.ctx;
  35507. var w = imgData.width;
  35508. var h = imgData.height;
  35509. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  35510. var tmpCtx = tmpCanvas.context;
  35511. putBinaryImageData(tmpCtx, imgData);
  35512. for (var i = 0, ii = map.length; i < ii; i++) {
  35513. var entry = map[i];
  35514. ctx.save();
  35515. ctx.transform.apply(ctx, entry.transform);
  35516. ctx.scale(1, -1);
  35517. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  35518. 0, -1, 1, 1);
  35519. if (this.imageLayer) {
  35520. var position = this.getCanvasPosition(entry.x, entry.y);
  35521. this.imageLayer.appendImage({
  35522. imgData: imgData,
  35523. left: position[0],
  35524. top: position[1],
  35525. width: w,
  35526. height: h
  35527. });
  35528. }
  35529. ctx.restore();
  35530. }
  35531. },
  35532. paintSolidColorImageMask:
  35533. function CanvasGraphics_paintSolidColorImageMask() {
  35534. this.ctx.fillRect(0, 0, 1, 1);
  35535. },
  35536. paintXObject: function CanvasGraphics_paintXObject() {
  35537. warn('Unsupported \'paintXObject\' command.');
  35538. },
  35539. // Marked content
  35540. markPoint: function CanvasGraphics_markPoint(tag) {
  35541. // TODO Marked content.
  35542. },
  35543. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  35544. // TODO Marked content.
  35545. },
  35546. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  35547. // TODO Marked content.
  35548. },
  35549. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  35550. tag, properties) {
  35551. // TODO Marked content.
  35552. },
  35553. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  35554. // TODO Marked content.
  35555. },
  35556. // Compatibility
  35557. beginCompat: function CanvasGraphics_beginCompat() {
  35558. // TODO ignore undefined operators (should we do that anyway?)
  35559. },
  35560. endCompat: function CanvasGraphics_endCompat() {
  35561. // TODO stop ignoring undefined operators
  35562. },
  35563. // Helper functions
  35564. consumePath: function CanvasGraphics_consumePath() {
  35565. var ctx = this.ctx;
  35566. if (this.pendingClip) {
  35567. if (this.pendingClip === EO_CLIP) {
  35568. if (ctx.mozFillRule !== undefined) {
  35569. ctx.mozFillRule = 'evenodd';
  35570. ctx.clip();
  35571. ctx.mozFillRule = 'nonzero';
  35572. } else {
  35573. ctx.clip('evenodd');
  35574. }
  35575. } else {
  35576. ctx.clip();
  35577. }
  35578. this.pendingClip = null;
  35579. }
  35580. ctx.beginPath();
  35581. },
  35582. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  35583. if (this.cachedGetSinglePixelWidth === null) {
  35584. // NOTE: The `save` and `restore` commands used below is a workaround
  35585. // that is necessary in order to prevent `mozCurrentTransformInverse`
  35586. // from intermittently returning incorrect values in Firefox, see:
  35587. // https://github.com/mozilla/pdf.js/issues/7188.
  35588. this.ctx.save();
  35589. var inverse = this.ctx.mozCurrentTransformInverse;
  35590. this.ctx.restore();
  35591. // max of the current horizontal and vertical scale
  35592. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  35593. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  35594. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  35595. }
  35596. return this.cachedGetSinglePixelWidth;
  35597. },
  35598. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  35599. var transform = this.ctx.mozCurrentTransform;
  35600. return [
  35601. transform[0] * x + transform[2] * y + transform[4],
  35602. transform[1] * x + transform[3] * y + transform[5]
  35603. ];
  35604. }
  35605. };
  35606. for (var op in OPS) {
  35607. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  35608. }
  35609. return CanvasGraphics;
  35610. })();
  35611. exports.CanvasGraphics = CanvasGraphics;
  35612. exports.createScratchCanvas = createScratchCanvas;
  35613. }));
  35614. (function (root, factory) {
  35615. {
  35616. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  35617. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  35618. }
  35619. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  35620. var error = sharedUtil.error;
  35621. var info = sharedUtil.info;
  35622. var isArray = sharedUtil.isArray;
  35623. var isBool = sharedUtil.isBool;
  35624. var isDict = corePrimitives.isDict;
  35625. var isStream = corePrimitives.isStream;
  35626. var PostScriptLexer = corePsParser.PostScriptLexer;
  35627. var PostScriptParser = corePsParser.PostScriptParser;
  35628. var PDFFunction = (function PDFFunctionClosure() {
  35629. var CONSTRUCT_SAMPLED = 0;
  35630. var CONSTRUCT_INTERPOLATED = 2;
  35631. var CONSTRUCT_STICHED = 3;
  35632. var CONSTRUCT_POSTSCRIPT = 4;
  35633. return {
  35634. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  35635. str) {
  35636. var i, ii;
  35637. var length = 1;
  35638. for (i = 0, ii = size.length; i < ii; i++) {
  35639. length *= size[i];
  35640. }
  35641. length *= outputSize;
  35642. var array = new Array(length);
  35643. var codeSize = 0;
  35644. var codeBuf = 0;
  35645. // 32 is a valid bps so shifting won't work
  35646. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  35647. var strBytes = str.getBytes((length * bps + 7) / 8);
  35648. var strIdx = 0;
  35649. for (i = 0; i < length; i++) {
  35650. while (codeSize < bps) {
  35651. codeBuf <<= 8;
  35652. codeBuf |= strBytes[strIdx++];
  35653. codeSize += 8;
  35654. }
  35655. codeSize -= bps;
  35656. array[i] = (codeBuf >> codeSize) * sampleMul;
  35657. codeBuf &= (1 << codeSize) - 1;
  35658. }
  35659. return array;
  35660. },
  35661. getIR: function PDFFunction_getIR(xref, fn) {
  35662. var dict = fn.dict;
  35663. if (!dict) {
  35664. dict = fn;
  35665. }
  35666. var types = [this.constructSampled,
  35667. null,
  35668. this.constructInterpolated,
  35669. this.constructStiched,
  35670. this.constructPostScript];
  35671. var typeNum = dict.get('FunctionType');
  35672. var typeFn = types[typeNum];
  35673. if (!typeFn) {
  35674. error('Unknown type of function');
  35675. }
  35676. return typeFn.call(this, fn, dict, xref);
  35677. },
  35678. fromIR: function PDFFunction_fromIR(IR) {
  35679. var type = IR[0];
  35680. switch (type) {
  35681. case CONSTRUCT_SAMPLED:
  35682. return this.constructSampledFromIR(IR);
  35683. case CONSTRUCT_INTERPOLATED:
  35684. return this.constructInterpolatedFromIR(IR);
  35685. case CONSTRUCT_STICHED:
  35686. return this.constructStichedFromIR(IR);
  35687. //case CONSTRUCT_POSTSCRIPT:
  35688. default:
  35689. return this.constructPostScriptFromIR(IR);
  35690. }
  35691. },
  35692. parse: function PDFFunction_parse(xref, fn) {
  35693. var IR = this.getIR(xref, fn);
  35694. return this.fromIR(IR);
  35695. },
  35696. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  35697. if (!isArray(fnObj)) {
  35698. // not an array -- parsing as regular function
  35699. return this.parse(xref, fnObj);
  35700. }
  35701. var fnArray = [];
  35702. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  35703. var obj = xref.fetchIfRef(fnObj[j]);
  35704. fnArray.push(PDFFunction.parse(xref, obj));
  35705. }
  35706. return function (src, srcOffset, dest, destOffset) {
  35707. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  35708. fnArray[i](src, srcOffset, dest, destOffset + i);
  35709. }
  35710. };
  35711. },
  35712. constructSampled: function PDFFunction_constructSampled(str, dict) {
  35713. function toMultiArray(arr) {
  35714. var inputLength = arr.length;
  35715. var out = [];
  35716. var index = 0;
  35717. for (var i = 0; i < inputLength; i += 2) {
  35718. out[index] = [arr[i], arr[i + 1]];
  35719. ++index;
  35720. }
  35721. return out;
  35722. }
  35723. var domain = dict.getArray('Domain');
  35724. var range = dict.getArray('Range');
  35725. if (!domain || !range) {
  35726. error('No domain or range');
  35727. }
  35728. var inputSize = domain.length / 2;
  35729. var outputSize = range.length / 2;
  35730. domain = toMultiArray(domain);
  35731. range = toMultiArray(range);
  35732. var size = dict.get('Size');
  35733. var bps = dict.get('BitsPerSample');
  35734. var order = dict.get('Order') || 1;
  35735. if (order !== 1) {
  35736. // No description how cubic spline interpolation works in PDF32000:2008
  35737. // As in poppler, ignoring order, linear interpolation may work as good
  35738. info('No support for cubic spline interpolation: ' + order);
  35739. }
  35740. var encode = dict.getArray('Encode');
  35741. if (!encode) {
  35742. encode = [];
  35743. for (var i = 0; i < inputSize; ++i) {
  35744. encode.push(0);
  35745. encode.push(size[i] - 1);
  35746. }
  35747. }
  35748. encode = toMultiArray(encode);
  35749. var decode = dict.getArray('Decode');
  35750. if (!decode) {
  35751. decode = range;
  35752. } else {
  35753. decode = toMultiArray(decode);
  35754. }
  35755. var samples = this.getSampleArray(size, outputSize, bps, str);
  35756. return [
  35757. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  35758. outputSize, Math.pow(2, bps) - 1, range
  35759. ];
  35760. },
  35761. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  35762. // See chapter 3, page 109 of the PDF reference
  35763. function interpolate(x, xmin, xmax, ymin, ymax) {
  35764. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  35765. }
  35766. return function constructSampledFromIRResult(src, srcOffset,
  35767. dest, destOffset) {
  35768. // See chapter 3, page 110 of the PDF reference.
  35769. var m = IR[1];
  35770. var domain = IR[2];
  35771. var encode = IR[3];
  35772. var decode = IR[4];
  35773. var samples = IR[5];
  35774. var size = IR[6];
  35775. var n = IR[7];
  35776. //var mask = IR[8];
  35777. var range = IR[9];
  35778. // Building the cube vertices: its part and sample index
  35779. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  35780. var cubeVertices = 1 << m;
  35781. var cubeN = new Float64Array(cubeVertices);
  35782. var cubeVertex = new Uint32Array(cubeVertices);
  35783. var i, j;
  35784. for (j = 0; j < cubeVertices; j++) {
  35785. cubeN[j] = 1;
  35786. }
  35787. var k = n, pos = 1;
  35788. // Map x_i to y_j for 0 <= i < m using the sampled function.
  35789. for (i = 0; i < m; ++i) {
  35790. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  35791. var domain_2i = domain[i][0];
  35792. var domain_2i_1 = domain[i][1];
  35793. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  35794. domain_2i_1);
  35795. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  35796. // Encode_2i, Encode_2i+1)
  35797. var e = interpolate(xi, domain_2i, domain_2i_1,
  35798. encode[i][0], encode[i][1]);
  35799. // e_i' = min(max(e_i, 0), Size_i - 1)
  35800. var size_i = size[i];
  35801. e = Math.min(Math.max(e, 0), size_i - 1);
  35802. // Adjusting the cube: N and vertex sample index
  35803. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  35804. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  35805. var n1 = e - e0; // (e - e0) / (e1 - e0);
  35806. var offset0 = e0 * k;
  35807. var offset1 = offset0 + k; // e1 * k
  35808. for (j = 0; j < cubeVertices; j++) {
  35809. if (j & pos) {
  35810. cubeN[j] *= n1;
  35811. cubeVertex[j] += offset1;
  35812. } else {
  35813. cubeN[j] *= n0;
  35814. cubeVertex[j] += offset0;
  35815. }
  35816. }
  35817. k *= size_i;
  35818. pos <<= 1;
  35819. }
  35820. for (j = 0; j < n; ++j) {
  35821. // Sum all cube vertices' samples portions
  35822. var rj = 0;
  35823. for (i = 0; i < cubeVertices; i++) {
  35824. rj += samples[cubeVertex[i] + j] * cubeN[i];
  35825. }
  35826. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  35827. // Decode_2j, Decode_2j+1)
  35828. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  35829. // y_j = min(max(r_j, range_2j), range_2j+1)
  35830. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  35831. range[j][1]);
  35832. }
  35833. };
  35834. },
  35835. constructInterpolated: function PDFFunction_constructInterpolated(str,
  35836. dict) {
  35837. var c0 = dict.getArray('C0') || [0];
  35838. var c1 = dict.getArray('C1') || [1];
  35839. var n = dict.get('N');
  35840. if (!isArray(c0) || !isArray(c1)) {
  35841. error('Illegal dictionary for interpolated function');
  35842. }
  35843. var length = c0.length;
  35844. var diff = [];
  35845. for (var i = 0; i < length; ++i) {
  35846. diff.push(c1[i] - c0[i]);
  35847. }
  35848. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  35849. },
  35850. constructInterpolatedFromIR:
  35851. function PDFFunction_constructInterpolatedFromIR(IR) {
  35852. var c0 = IR[1];
  35853. var diff = IR[2];
  35854. var n = IR[3];
  35855. var length = diff.length;
  35856. return function constructInterpolatedFromIRResult(src, srcOffset,
  35857. dest, destOffset) {
  35858. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  35859. for (var j = 0; j < length; ++j) {
  35860. dest[destOffset + j] = c0[j] + (x * diff[j]);
  35861. }
  35862. };
  35863. },
  35864. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  35865. var domain = dict.getArray('Domain');
  35866. if (!domain) {
  35867. error('No domain');
  35868. }
  35869. var inputSize = domain.length / 2;
  35870. if (inputSize !== 1) {
  35871. error('Bad domain for stiched function');
  35872. }
  35873. var fnRefs = dict.get('Functions');
  35874. var fns = [];
  35875. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  35876. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  35877. }
  35878. var bounds = dict.getArray('Bounds');
  35879. var encode = dict.getArray('Encode');
  35880. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  35881. },
  35882. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  35883. var domain = IR[1];
  35884. var bounds = IR[2];
  35885. var encode = IR[3];
  35886. var fnsIR = IR[4];
  35887. var fns = [];
  35888. var tmpBuf = new Float32Array(1);
  35889. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  35890. fns.push(PDFFunction.fromIR(fnsIR[i]));
  35891. }
  35892. return function constructStichedFromIRResult(src, srcOffset,
  35893. dest, destOffset) {
  35894. var clip = function constructStichedFromIRClip(v, min, max) {
  35895. if (v > max) {
  35896. v = max;
  35897. } else if (v < min) {
  35898. v = min;
  35899. }
  35900. return v;
  35901. };
  35902. // clip to domain
  35903. var v = clip(src[srcOffset], domain[0], domain[1]);
  35904. // calculate which bound the value is in
  35905. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  35906. if (v < bounds[i]) {
  35907. break;
  35908. }
  35909. }
  35910. // encode value into domain of function
  35911. var dmin = domain[0];
  35912. if (i > 0) {
  35913. dmin = bounds[i - 1];
  35914. }
  35915. var dmax = domain[1];
  35916. if (i < bounds.length) {
  35917. dmax = bounds[i];
  35918. }
  35919. var rmin = encode[2 * i];
  35920. var rmax = encode[2 * i + 1];
  35921. // Prevent the value from becoming NaN as a result
  35922. // of division by zero (fixes issue6113.pdf).
  35923. tmpBuf[0] = dmin === dmax ? rmin :
  35924. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  35925. // call the appropriate function
  35926. fns[i](tmpBuf, 0, dest, destOffset);
  35927. };
  35928. },
  35929. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  35930. xref) {
  35931. var domain = dict.getArray('Domain');
  35932. var range = dict.getArray('Range');
  35933. if (!domain) {
  35934. error('No domain.');
  35935. }
  35936. if (!range) {
  35937. error('No range.');
  35938. }
  35939. var lexer = new PostScriptLexer(fn);
  35940. var parser = new PostScriptParser(lexer);
  35941. var code = parser.parse();
  35942. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  35943. },
  35944. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  35945. IR) {
  35946. var domain = IR[1];
  35947. var range = IR[2];
  35948. var code = IR[3];
  35949. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  35950. if (compiled) {
  35951. // Compiled function consists of simple expressions such as addition,
  35952. // subtraction, Math.max, and also contains 'var' and 'return'
  35953. // statements. See the generation in the PostScriptCompiler below.
  35954. /*jshint -W054 */
  35955. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  35956. }
  35957. info('Unable to compile PS function');
  35958. var numOutputs = range.length >> 1;
  35959. var numInputs = domain.length >> 1;
  35960. var evaluator = new PostScriptEvaluator(code);
  35961. // Cache the values for a big speed up, the cache size is limited though
  35962. // since the number of possible values can be huge from a PS function.
  35963. var cache = Object.create(null);
  35964. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  35965. // seen in our tests.
  35966. var MAX_CACHE_SIZE = 2048 * 4;
  35967. var cache_available = MAX_CACHE_SIZE;
  35968. var tmpBuf = new Float32Array(numInputs);
  35969. return function constructPostScriptFromIRResult(src, srcOffset,
  35970. dest, destOffset) {
  35971. var i, value;
  35972. var key = '';
  35973. var input = tmpBuf;
  35974. for (i = 0; i < numInputs; i++) {
  35975. value = src[srcOffset + i];
  35976. input[i] = value;
  35977. key += value + '_';
  35978. }
  35979. var cachedValue = cache[key];
  35980. if (cachedValue !== undefined) {
  35981. dest.set(cachedValue, destOffset);
  35982. return;
  35983. }
  35984. var output = new Float32Array(numOutputs);
  35985. var stack = evaluator.execute(input);
  35986. var stackIndex = stack.length - numOutputs;
  35987. for (i = 0; i < numOutputs; i++) {
  35988. value = stack[stackIndex + i];
  35989. var bound = range[i * 2];
  35990. if (value < bound) {
  35991. value = bound;
  35992. } else {
  35993. bound = range[i * 2 +1];
  35994. if (value > bound) {
  35995. value = bound;
  35996. }
  35997. }
  35998. output[i] = value;
  35999. }
  36000. if (cache_available > 0) {
  36001. cache_available--;
  36002. cache[key] = output;
  36003. }
  36004. dest.set(output, destOffset);
  36005. };
  36006. }
  36007. };
  36008. })();
  36009. function isPDFFunction(v) {
  36010. var fnDict;
  36011. if (typeof v !== 'object') {
  36012. return false;
  36013. } else if (isDict(v)) {
  36014. fnDict = v;
  36015. } else if (isStream(v)) {
  36016. fnDict = v.dict;
  36017. } else {
  36018. return false;
  36019. }
  36020. return fnDict.has('FunctionType');
  36021. }
  36022. var PostScriptStack = (function PostScriptStackClosure() {
  36023. var MAX_STACK_SIZE = 100;
  36024. function PostScriptStack(initialStack) {
  36025. this.stack = !initialStack ? [] :
  36026. Array.prototype.slice.call(initialStack, 0);
  36027. }
  36028. PostScriptStack.prototype = {
  36029. push: function PostScriptStack_push(value) {
  36030. if (this.stack.length >= MAX_STACK_SIZE) {
  36031. error('PostScript function stack overflow.');
  36032. }
  36033. this.stack.push(value);
  36034. },
  36035. pop: function PostScriptStack_pop() {
  36036. if (this.stack.length <= 0) {
  36037. error('PostScript function stack underflow.');
  36038. }
  36039. return this.stack.pop();
  36040. },
  36041. copy: function PostScriptStack_copy(n) {
  36042. if (this.stack.length + n >= MAX_STACK_SIZE) {
  36043. error('PostScript function stack overflow.');
  36044. }
  36045. var stack = this.stack;
  36046. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  36047. stack.push(stack[i]);
  36048. }
  36049. },
  36050. index: function PostScriptStack_index(n) {
  36051. this.push(this.stack[this.stack.length - n - 1]);
  36052. },
  36053. // rotate the last n stack elements p times
  36054. roll: function PostScriptStack_roll(n, p) {
  36055. var stack = this.stack;
  36056. var l = stack.length - n;
  36057. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  36058. for (i = l, j = r; i < j; i++, j--) {
  36059. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  36060. }
  36061. for (i = l, j = c - 1; i < j; i++, j--) {
  36062. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  36063. }
  36064. for (i = c, j = r; i < j; i++, j--) {
  36065. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  36066. }
  36067. }
  36068. };
  36069. return PostScriptStack;
  36070. })();
  36071. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  36072. function PostScriptEvaluator(operators) {
  36073. this.operators = operators;
  36074. }
  36075. PostScriptEvaluator.prototype = {
  36076. execute: function PostScriptEvaluator_execute(initialStack) {
  36077. var stack = new PostScriptStack(initialStack);
  36078. var counter = 0;
  36079. var operators = this.operators;
  36080. var length = operators.length;
  36081. var operator, a, b;
  36082. while (counter < length) {
  36083. operator = operators[counter++];
  36084. if (typeof operator === 'number') {
  36085. // Operator is really an operand and should be pushed to the stack.
  36086. stack.push(operator);
  36087. continue;
  36088. }
  36089. switch (operator) {
  36090. // non standard ps operators
  36091. case 'jz': // jump if false
  36092. b = stack.pop();
  36093. a = stack.pop();
  36094. if (!a) {
  36095. counter = b;
  36096. }
  36097. break;
  36098. case 'j': // jump
  36099. a = stack.pop();
  36100. counter = a;
  36101. break;
  36102. // all ps operators in alphabetical order (excluding if/ifelse)
  36103. case 'abs':
  36104. a = stack.pop();
  36105. stack.push(Math.abs(a));
  36106. break;
  36107. case 'add':
  36108. b = stack.pop();
  36109. a = stack.pop();
  36110. stack.push(a + b);
  36111. break;
  36112. case 'and':
  36113. b = stack.pop();
  36114. a = stack.pop();
  36115. if (isBool(a) && isBool(b)) {
  36116. stack.push(a && b);
  36117. } else {
  36118. stack.push(a & b);
  36119. }
  36120. break;
  36121. case 'atan':
  36122. a = stack.pop();
  36123. stack.push(Math.atan(a));
  36124. break;
  36125. case 'bitshift':
  36126. b = stack.pop();
  36127. a = stack.pop();
  36128. if (a > 0) {
  36129. stack.push(a << b);
  36130. } else {
  36131. stack.push(a >> b);
  36132. }
  36133. break;
  36134. case 'ceiling':
  36135. a = stack.pop();
  36136. stack.push(Math.ceil(a));
  36137. break;
  36138. case 'copy':
  36139. a = stack.pop();
  36140. stack.copy(a);
  36141. break;
  36142. case 'cos':
  36143. a = stack.pop();
  36144. stack.push(Math.cos(a));
  36145. break;
  36146. case 'cvi':
  36147. a = stack.pop() | 0;
  36148. stack.push(a);
  36149. break;
  36150. case 'cvr':
  36151. // noop
  36152. break;
  36153. case 'div':
  36154. b = stack.pop();
  36155. a = stack.pop();
  36156. stack.push(a / b);
  36157. break;
  36158. case 'dup':
  36159. stack.copy(1);
  36160. break;
  36161. case 'eq':
  36162. b = stack.pop();
  36163. a = stack.pop();
  36164. stack.push(a === b);
  36165. break;
  36166. case 'exch':
  36167. stack.roll(2, 1);
  36168. break;
  36169. case 'exp':
  36170. b = stack.pop();
  36171. a = stack.pop();
  36172. stack.push(Math.pow(a, b));
  36173. break;
  36174. case 'false':
  36175. stack.push(false);
  36176. break;
  36177. case 'floor':
  36178. a = stack.pop();
  36179. stack.push(Math.floor(a));
  36180. break;
  36181. case 'ge':
  36182. b = stack.pop();
  36183. a = stack.pop();
  36184. stack.push(a >= b);
  36185. break;
  36186. case 'gt':
  36187. b = stack.pop();
  36188. a = stack.pop();
  36189. stack.push(a > b);
  36190. break;
  36191. case 'idiv':
  36192. b = stack.pop();
  36193. a = stack.pop();
  36194. stack.push((a / b) | 0);
  36195. break;
  36196. case 'index':
  36197. a = stack.pop();
  36198. stack.index(a);
  36199. break;
  36200. case 'le':
  36201. b = stack.pop();
  36202. a = stack.pop();
  36203. stack.push(a <= b);
  36204. break;
  36205. case 'ln':
  36206. a = stack.pop();
  36207. stack.push(Math.log(a));
  36208. break;
  36209. case 'log':
  36210. a = stack.pop();
  36211. stack.push(Math.log(a) / Math.LN10);
  36212. break;
  36213. case 'lt':
  36214. b = stack.pop();
  36215. a = stack.pop();
  36216. stack.push(a < b);
  36217. break;
  36218. case 'mod':
  36219. b = stack.pop();
  36220. a = stack.pop();
  36221. stack.push(a % b);
  36222. break;
  36223. case 'mul':
  36224. b = stack.pop();
  36225. a = stack.pop();
  36226. stack.push(a * b);
  36227. break;
  36228. case 'ne':
  36229. b = stack.pop();
  36230. a = stack.pop();
  36231. stack.push(a !== b);
  36232. break;
  36233. case 'neg':
  36234. a = stack.pop();
  36235. stack.push(-a);
  36236. break;
  36237. case 'not':
  36238. a = stack.pop();
  36239. if (isBool(a)) {
  36240. stack.push(!a);
  36241. } else {
  36242. stack.push(~a);
  36243. }
  36244. break;
  36245. case 'or':
  36246. b = stack.pop();
  36247. a = stack.pop();
  36248. if (isBool(a) && isBool(b)) {
  36249. stack.push(a || b);
  36250. } else {
  36251. stack.push(a | b);
  36252. }
  36253. break;
  36254. case 'pop':
  36255. stack.pop();
  36256. break;
  36257. case 'roll':
  36258. b = stack.pop();
  36259. a = stack.pop();
  36260. stack.roll(a, b);
  36261. break;
  36262. case 'round':
  36263. a = stack.pop();
  36264. stack.push(Math.round(a));
  36265. break;
  36266. case 'sin':
  36267. a = stack.pop();
  36268. stack.push(Math.sin(a));
  36269. break;
  36270. case 'sqrt':
  36271. a = stack.pop();
  36272. stack.push(Math.sqrt(a));
  36273. break;
  36274. case 'sub':
  36275. b = stack.pop();
  36276. a = stack.pop();
  36277. stack.push(a - b);
  36278. break;
  36279. case 'true':
  36280. stack.push(true);
  36281. break;
  36282. case 'truncate':
  36283. a = stack.pop();
  36284. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  36285. stack.push(a);
  36286. break;
  36287. case 'xor':
  36288. b = stack.pop();
  36289. a = stack.pop();
  36290. if (isBool(a) && isBool(b)) {
  36291. stack.push(a !== b);
  36292. } else {
  36293. stack.push(a ^ b);
  36294. }
  36295. break;
  36296. default:
  36297. error('Unknown operator ' + operator);
  36298. break;
  36299. }
  36300. }
  36301. return stack.stack;
  36302. }
  36303. };
  36304. return PostScriptEvaluator;
  36305. })();
  36306. // Most of the PDFs functions consist of simple operations such as:
  36307. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  36308. //
  36309. // We can compile most of such programs, and at the same moment, we can
  36310. // optimize some expressions using basic math properties. Keeping track of
  36311. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  36312. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  36313. function AstNode(type) {
  36314. this.type = type;
  36315. }
  36316. AstNode.prototype.visit = function (visitor) {
  36317. throw new Error('abstract method');
  36318. };
  36319. function AstArgument(index, min, max) {
  36320. AstNode.call(this, 'args');
  36321. this.index = index;
  36322. this.min = min;
  36323. this.max = max;
  36324. }
  36325. AstArgument.prototype = Object.create(AstNode.prototype);
  36326. AstArgument.prototype.visit = function (visitor) {
  36327. visitor.visitArgument(this);
  36328. };
  36329. function AstLiteral(number) {
  36330. AstNode.call(this, 'literal');
  36331. this.number = number;
  36332. this.min = number;
  36333. this.max = number;
  36334. }
  36335. AstLiteral.prototype = Object.create(AstNode.prototype);
  36336. AstLiteral.prototype.visit = function (visitor) {
  36337. visitor.visitLiteral(this);
  36338. };
  36339. function AstBinaryOperation(op, arg1, arg2, min, max) {
  36340. AstNode.call(this, 'binary');
  36341. this.op = op;
  36342. this.arg1 = arg1;
  36343. this.arg2 = arg2;
  36344. this.min = min;
  36345. this.max = max;
  36346. }
  36347. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  36348. AstBinaryOperation.prototype.visit = function (visitor) {
  36349. visitor.visitBinaryOperation(this);
  36350. };
  36351. function AstMin(arg, max) {
  36352. AstNode.call(this, 'max');
  36353. this.arg = arg;
  36354. this.min = arg.min;
  36355. this.max = max;
  36356. }
  36357. AstMin.prototype = Object.create(AstNode.prototype);
  36358. AstMin.prototype.visit = function (visitor) {
  36359. visitor.visitMin(this);
  36360. };
  36361. function AstVariable(index, min, max) {
  36362. AstNode.call(this, 'var');
  36363. this.index = index;
  36364. this.min = min;
  36365. this.max = max;
  36366. }
  36367. AstVariable.prototype = Object.create(AstNode.prototype);
  36368. AstVariable.prototype.visit = function (visitor) {
  36369. visitor.visitVariable(this);
  36370. };
  36371. function AstVariableDefinition(variable, arg) {
  36372. AstNode.call(this, 'definition');
  36373. this.variable = variable;
  36374. this.arg = arg;
  36375. }
  36376. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  36377. AstVariableDefinition.prototype.visit = function (visitor) {
  36378. visitor.visitVariableDefinition(this);
  36379. };
  36380. function ExpressionBuilderVisitor() {
  36381. this.parts = [];
  36382. }
  36383. ExpressionBuilderVisitor.prototype = {
  36384. visitArgument: function (arg) {
  36385. this.parts.push('Math.max(', arg.min, ', Math.min(',
  36386. arg.max, ', src[srcOffset + ', arg.index, ']))');
  36387. },
  36388. visitVariable: function (variable) {
  36389. this.parts.push('v', variable.index);
  36390. },
  36391. visitLiteral: function (literal) {
  36392. this.parts.push(literal.number);
  36393. },
  36394. visitBinaryOperation: function (operation) {
  36395. this.parts.push('(');
  36396. operation.arg1.visit(this);
  36397. this.parts.push(' ', operation.op, ' ');
  36398. operation.arg2.visit(this);
  36399. this.parts.push(')');
  36400. },
  36401. visitVariableDefinition: function (definition) {
  36402. this.parts.push('var ');
  36403. definition.variable.visit(this);
  36404. this.parts.push(' = ');
  36405. definition.arg.visit(this);
  36406. this.parts.push(';');
  36407. },
  36408. visitMin: function (max) {
  36409. this.parts.push('Math.min(');
  36410. max.arg.visit(this);
  36411. this.parts.push(', ', max.max, ')');
  36412. },
  36413. toString: function () {
  36414. return this.parts.join('');
  36415. }
  36416. };
  36417. function buildAddOperation(num1, num2) {
  36418. if (num2.type === 'literal' && num2.number === 0) {
  36419. // optimization: second operand is 0
  36420. return num1;
  36421. }
  36422. if (num1.type === 'literal' && num1.number === 0) {
  36423. // optimization: first operand is 0
  36424. return num2;
  36425. }
  36426. if (num2.type === 'literal' && num1.type === 'literal') {
  36427. // optimization: operands operand are literals
  36428. return new AstLiteral(num1.number + num2.number);
  36429. }
  36430. return new AstBinaryOperation('+', num1, num2,
  36431. num1.min + num2.min, num1.max + num2.max);
  36432. }
  36433. function buildMulOperation(num1, num2) {
  36434. if (num2.type === 'literal') {
  36435. // optimization: second operands is a literal...
  36436. if (num2.number === 0) {
  36437. return new AstLiteral(0); // and it's 0
  36438. } else if (num2.number === 1) {
  36439. return num1; // and it's 1
  36440. } else if (num1.type === 'literal') {
  36441. // ... and first operands is a literal too
  36442. return new AstLiteral(num1.number * num2.number);
  36443. }
  36444. }
  36445. if (num1.type === 'literal') {
  36446. // optimization: first operands is a literal...
  36447. if (num1.number === 0) {
  36448. return new AstLiteral(0); // and it's 0
  36449. } else if (num1.number === 1) {
  36450. return num2; // and it's 1
  36451. }
  36452. }
  36453. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  36454. num1.max * num2.min, num1.max * num2.max);
  36455. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  36456. num1.max * num2.min, num1.max * num2.max);
  36457. return new AstBinaryOperation('*', num1, num2, min, max);
  36458. }
  36459. function buildSubOperation(num1, num2) {
  36460. if (num2.type === 'literal') {
  36461. // optimization: second operands is a literal...
  36462. if (num2.number === 0) {
  36463. return num1; // ... and it's 0
  36464. } else if (num1.type === 'literal') {
  36465. // ... and first operands is a literal too
  36466. return new AstLiteral(num1.number - num2.number);
  36467. }
  36468. }
  36469. if (num2.type === 'binary' && num2.op === '-' &&
  36470. num1.type === 'literal' && num1.number === 1 &&
  36471. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  36472. // optimization for case: 1 - (1 - x)
  36473. return num2.arg2;
  36474. }
  36475. return new AstBinaryOperation('-', num1, num2,
  36476. num1.min - num2.max, num1.max - num2.min);
  36477. }
  36478. function buildMinOperation(num1, max) {
  36479. if (num1.min >= max) {
  36480. // optimization: num1 min value is not less than required max
  36481. return new AstLiteral(max); // just returning max
  36482. } else if (num1.max <= max) {
  36483. // optimization: num1 max value is not greater than required max
  36484. return num1; // just returning an argument
  36485. }
  36486. return new AstMin(num1, max);
  36487. }
  36488. function PostScriptCompiler() {}
  36489. PostScriptCompiler.prototype = {
  36490. compile: function PostScriptCompiler_compile(code, domain, range) {
  36491. var stack = [];
  36492. var i, ii;
  36493. var instructions = [];
  36494. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  36495. var lastRegister = 0;
  36496. var n, j;
  36497. var num1, num2, ast1, ast2, tmpVar, item;
  36498. for (i = 0; i < inputSize; i++) {
  36499. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  36500. }
  36501. for (i = 0, ii = code.length; i < ii; i++) {
  36502. item = code[i];
  36503. if (typeof item === 'number') {
  36504. stack.push(new AstLiteral(item));
  36505. continue;
  36506. }
  36507. switch (item) {
  36508. case 'add':
  36509. if (stack.length < 2) {
  36510. return null;
  36511. }
  36512. num2 = stack.pop();
  36513. num1 = stack.pop();
  36514. stack.push(buildAddOperation(num1, num2));
  36515. break;
  36516. case 'cvr':
  36517. if (stack.length < 1) {
  36518. return null;
  36519. }
  36520. break;
  36521. case 'mul':
  36522. if (stack.length < 2) {
  36523. return null;
  36524. }
  36525. num2 = stack.pop();
  36526. num1 = stack.pop();
  36527. stack.push(buildMulOperation(num1, num2));
  36528. break;
  36529. case 'sub':
  36530. if (stack.length < 2) {
  36531. return null;
  36532. }
  36533. num2 = stack.pop();
  36534. num1 = stack.pop();
  36535. stack.push(buildSubOperation(num1, num2));
  36536. break;
  36537. case 'exch':
  36538. if (stack.length < 2) {
  36539. return null;
  36540. }
  36541. ast1 = stack.pop(); ast2 = stack.pop();
  36542. stack.push(ast1, ast2);
  36543. break;
  36544. case 'pop':
  36545. if (stack.length < 1) {
  36546. return null;
  36547. }
  36548. stack.pop();
  36549. break;
  36550. case 'index':
  36551. if (stack.length < 1) {
  36552. return null;
  36553. }
  36554. num1 = stack.pop();
  36555. if (num1.type !== 'literal') {
  36556. return null;
  36557. }
  36558. n = num1.number;
  36559. if (n < 0 || (n|0) !== n || stack.length < n) {
  36560. return null;
  36561. }
  36562. ast1 = stack[stack.length - n - 1];
  36563. if (ast1.type === 'literal' || ast1.type === 'var') {
  36564. stack.push(ast1);
  36565. break;
  36566. }
  36567. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  36568. stack[stack.length - n - 1] = tmpVar;
  36569. stack.push(tmpVar);
  36570. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  36571. break;
  36572. case 'dup':
  36573. if (stack.length < 1) {
  36574. return null;
  36575. }
  36576. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  36577. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  36578. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  36579. // special case of the commands sequence for the min operation
  36580. num1 = stack.pop();
  36581. stack.push(buildMinOperation(num1, code[i + 1]));
  36582. i += 6;
  36583. break;
  36584. }
  36585. ast1 = stack[stack.length - 1];
  36586. if (ast1.type === 'literal' || ast1.type === 'var') {
  36587. // we don't have to save into intermediate variable a literal or
  36588. // variable.
  36589. stack.push(ast1);
  36590. break;
  36591. }
  36592. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  36593. stack[stack.length - 1] = tmpVar;
  36594. stack.push(tmpVar);
  36595. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  36596. break;
  36597. case 'roll':
  36598. if (stack.length < 2) {
  36599. return null;
  36600. }
  36601. num2 = stack.pop();
  36602. num1 = stack.pop();
  36603. if (num2.type !== 'literal' || num1.type !== 'literal') {
  36604. // both roll operands must be numbers
  36605. return null;
  36606. }
  36607. j = num2.number;
  36608. n = num1.number;
  36609. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  36610. // ... and integers
  36611. return null;
  36612. }
  36613. j = ((j % n) + n) % n;
  36614. if (j === 0) {
  36615. break; // just skipping -- there are nothing to rotate
  36616. }
  36617. Array.prototype.push.apply(stack,
  36618. stack.splice(stack.length - n, n - j));
  36619. break;
  36620. default:
  36621. return null; // unsupported operator
  36622. }
  36623. }
  36624. if (stack.length !== outputSize) {
  36625. return null;
  36626. }
  36627. var result = [];
  36628. instructions.forEach(function (instruction) {
  36629. var statementBuilder = new ExpressionBuilderVisitor();
  36630. instruction.visit(statementBuilder);
  36631. result.push(statementBuilder.toString());
  36632. });
  36633. stack.forEach(function (expr, i) {
  36634. var statementBuilder = new ExpressionBuilderVisitor();
  36635. expr.visit(statementBuilder);
  36636. var min = range[i * 2], max = range[i * 2 + 1];
  36637. var out = [statementBuilder.toString()];
  36638. if (min > expr.min) {
  36639. out.unshift('Math.max(', min, ', ');
  36640. out.push(')');
  36641. }
  36642. if (max < expr.max) {
  36643. out.unshift('Math.min(', max, ', ');
  36644. out.push(')');
  36645. }
  36646. out.unshift('dest[destOffset + ', i, '] = ');
  36647. out.push(';');
  36648. result.push(out.join(''));
  36649. });
  36650. return result.join('\n');
  36651. }
  36652. };
  36653. return PostScriptCompiler;
  36654. })();
  36655. exports.isPDFFunction = isPDFFunction;
  36656. exports.PDFFunction = PDFFunction;
  36657. exports.PostScriptEvaluator = PostScriptEvaluator;
  36658. exports.PostScriptCompiler = PostScriptCompiler;
  36659. }));
  36660. (function (root, factory) {
  36661. {
  36662. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  36663. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  36664. root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils);
  36665. }
  36666. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  36667. displayMetadata, displayDOMUtils, amdRequire) {
  36668. var InvalidPDFException = sharedUtil.InvalidPDFException;
  36669. var MessageHandler = sharedUtil.MessageHandler;
  36670. var MissingPDFException = sharedUtil.MissingPDFException;
  36671. var PageViewport = sharedUtil.PageViewport;
  36672. var PasswordResponses = sharedUtil.PasswordResponses;
  36673. var PasswordException = sharedUtil.PasswordException;
  36674. var StatTimer = sharedUtil.StatTimer;
  36675. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  36676. var UnknownErrorException = sharedUtil.UnknownErrorException;
  36677. var Util = sharedUtil.Util;
  36678. var createPromiseCapability = sharedUtil.createPromiseCapability;
  36679. var error = sharedUtil.error;
  36680. var deprecated = sharedUtil.deprecated;
  36681. var getVerbosityLevel = sharedUtil.getVerbosityLevel;
  36682. var info = sharedUtil.info;
  36683. var isInt = sharedUtil.isInt;
  36684. var isArray = sharedUtil.isArray;
  36685. var isArrayBuffer = sharedUtil.isArrayBuffer;
  36686. var isSameOrigin = sharedUtil.isSameOrigin;
  36687. var loadJpegStream = sharedUtil.loadJpegStream;
  36688. var stringToBytes = sharedUtil.stringToBytes;
  36689. var globalScope = sharedUtil.globalScope;
  36690. var warn = sharedUtil.warn;
  36691. var FontFaceObject = displayFontLoader.FontFaceObject;
  36692. var FontLoader = displayFontLoader.FontLoader;
  36693. var CanvasGraphics = displayCanvas.CanvasGraphics;
  36694. var createScratchCanvas = displayCanvas.createScratchCanvas;
  36695. var Metadata = displayMetadata.Metadata;
  36696. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  36697. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  36698. var isWorkerDisabled = false;
  36699. var workerSrc;
  36700. var isPostMessageTransfersDisabled = false;
  36701. /**
  36702. * Document initialization / loading parameters object.
  36703. *
  36704. * @typedef {Object} DocumentInitParameters
  36705. * @property {string} url - The URL of the PDF.
  36706. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  36707. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  36708. * use atob() to convert it to a binary string first.
  36709. * @property {Object} httpHeaders - Basic authentication headers.
  36710. * @property {boolean} withCredentials - Indicates whether or not cross-site
  36711. * Access-Control requests should be made using credentials such as cookies
  36712. * or authorization headers. The default is false.
  36713. * @property {string} password - For decrypting password-protected PDFs.
  36714. * @property {TypedArray} initialData - A typed array with the first portion or
  36715. * all of the pdf data. Used by the extension since some data is already
  36716. * loaded before the switch to range requests.
  36717. * @property {number} length - The PDF file length. It's used for progress
  36718. * reports and range requests operations.
  36719. * @property {PDFDataRangeTransport} range
  36720. * @property {number} rangeChunkSize - Optional parameter to specify
  36721. * maximum number of bytes fetched per range request. The default value is
  36722. * 2^16 = 65536.
  36723. * @property {PDFWorker} worker - The worker that will be used for the loading
  36724. * and parsing of the PDF data.
  36725. */
  36726. /**
  36727. * @typedef {Object} PDFDocumentStats
  36728. * @property {Array} streamTypes - Used stream types in the document (an item
  36729. * is set to true if specific stream ID was used in the document).
  36730. * @property {Array} fontTypes - Used font type in the document (an item is set
  36731. * to true if specific font ID was used in the document).
  36732. */
  36733. /**
  36734. * This is the main entry point for loading a PDF and interacting with it.
  36735. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  36736. * is used, which means it must follow the same origin rules that any XHR does
  36737. * e.g. No cross domain requests without CORS.
  36738. *
  36739. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  36740. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  36741. * already populated with data or parameter object.
  36742. *
  36743. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  36744. * if you want to manually serve range requests for data in the PDF.
  36745. *
  36746. * @param {function} passwordCallback (deprecated) It is used to request a
  36747. * password if wrong or no password was provided. The callback receives two
  36748. * parameters: function that needs to be called with new password and reason
  36749. * (see {PasswordResponses}).
  36750. *
  36751. * @param {function} progressCallback (deprecated) It is used to be able to
  36752. * monitor the loading progress of the PDF file (necessary to implement e.g.
  36753. * a loading bar). The callback receives an {Object} with the properties:
  36754. * {number} loaded and {number} total.
  36755. *
  36756. * @return {PDFDocumentLoadingTask}
  36757. */
  36758. function getDocument(src, pdfDataRangeTransport,
  36759. passwordCallback, progressCallback) {
  36760. var task = new PDFDocumentLoadingTask();
  36761. // Support of the obsolete arguments (for compatibility with API v1.0)
  36762. if (arguments.length > 1) {
  36763. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  36764. 'passwordCallback or progressCallback argument');
  36765. }
  36766. if (pdfDataRangeTransport) {
  36767. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  36768. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  36769. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  36770. pdfDataRangeTransport.length = src.length;
  36771. pdfDataRangeTransport.initialData = src.initialData;
  36772. if (!pdfDataRangeTransport.abort) {
  36773. pdfDataRangeTransport.abort = function () {};
  36774. }
  36775. }
  36776. src = Object.create(src);
  36777. src.range = pdfDataRangeTransport;
  36778. }
  36779. task.onPassword = passwordCallback || null;
  36780. task.onProgress = progressCallback || null;
  36781. var source;
  36782. if (typeof src === 'string') {
  36783. source = { url: src };
  36784. } else if (isArrayBuffer(src)) {
  36785. source = { data: src };
  36786. } else if (src instanceof PDFDataRangeTransport) {
  36787. source = { range: src };
  36788. } else {
  36789. if (typeof src !== 'object') {
  36790. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  36791. 'string or a parameter object');
  36792. }
  36793. if (!src.url && !src.data && !src.range) {
  36794. error('Invalid parameter object: need either .data, .range or .url');
  36795. }
  36796. source = src;
  36797. }
  36798. var params = {};
  36799. var rangeTransport = null;
  36800. var worker = null;
  36801. for (var key in source) {
  36802. if (key === 'url' && typeof window !== 'undefined') {
  36803. // The full path is required in the 'url' field.
  36804. params[key] = new URL(source[key], window.location).href;
  36805. continue;
  36806. } else if (key === 'range') {
  36807. rangeTransport = source[key];
  36808. continue;
  36809. } else if (key === 'worker') {
  36810. worker = source[key];
  36811. continue;
  36812. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  36813. // Converting string or array-like data to Uint8Array.
  36814. var pdfBytes = source[key];
  36815. if (typeof pdfBytes === 'string') {
  36816. params[key] = stringToBytes(pdfBytes);
  36817. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  36818. !isNaN(pdfBytes.length)) {
  36819. params[key] = new Uint8Array(pdfBytes);
  36820. } else if (isArrayBuffer(pdfBytes)) {
  36821. params[key] = new Uint8Array(pdfBytes);
  36822. } else {
  36823. error('Invalid PDF binary data: either typed array, string or ' +
  36824. 'array-like object is expected in the data property.');
  36825. }
  36826. continue;
  36827. }
  36828. params[key] = source[key];
  36829. }
  36830. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  36831. if (!worker) {
  36832. // Worker was not provided -- creating and owning our own.
  36833. worker = new PDFWorker();
  36834. task._worker = worker;
  36835. }
  36836. var docId = task.docId;
  36837. worker.promise.then(function () {
  36838. if (task.destroyed) {
  36839. throw new Error('Loading aborted');
  36840. }
  36841. return _fetchDocument(worker, params, rangeTransport, docId).then(
  36842. function (workerId) {
  36843. if (task.destroyed) {
  36844. throw new Error('Loading aborted');
  36845. }
  36846. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  36847. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  36848. task._transport = transport;
  36849. messageHandler.send('Ready', null);
  36850. });
  36851. }).catch(task._capability.reject);
  36852. return task;
  36853. }
  36854. /**
  36855. * Starts fetching of specified PDF document/data.
  36856. * @param {PDFWorker} worker
  36857. * @param {Object} source
  36858. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  36859. * @param {string} docId Unique document id, used as MessageHandler id.
  36860. * @returns {Promise} The promise, which is resolved when worker id of
  36861. * MessageHandler is known.
  36862. * @private
  36863. */
  36864. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  36865. if (worker.destroyed) {
  36866. return Promise.reject(new Error('Worker was destroyed'));
  36867. }
  36868. source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
  36869. source.disableStream = getDefaultSetting('disableStream');
  36870. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  36871. if (pdfDataRangeTransport) {
  36872. source.length = pdfDataRangeTransport.length;
  36873. source.initialData = pdfDataRangeTransport.initialData;
  36874. }
  36875. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  36876. docId: docId,
  36877. source: source,
  36878. disableRange: getDefaultSetting('disableRange'),
  36879. maxImageSize: getDefaultSetting('maxImageSize'),
  36880. cMapUrl: getDefaultSetting('cMapUrl'),
  36881. cMapPacked: getDefaultSetting('cMapPacked'),
  36882. disableFontFace: getDefaultSetting('disableFontFace'),
  36883. disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
  36884. postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
  36885. !isPostMessageTransfersDisabled,
  36886. }).then(function (workerId) {
  36887. if (worker.destroyed) {
  36888. throw new Error('Worker was destroyed');
  36889. }
  36890. return workerId;
  36891. });
  36892. }
  36893. /**
  36894. * PDF document loading operation.
  36895. * @class
  36896. * @alias PDFDocumentLoadingTask
  36897. */
  36898. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  36899. var nextDocumentId = 0;
  36900. /** @constructs PDFDocumentLoadingTask */
  36901. function PDFDocumentLoadingTask() {
  36902. this._capability = createPromiseCapability();
  36903. this._transport = null;
  36904. this._worker = null;
  36905. /**
  36906. * Unique document loading task id -- used in MessageHandlers.
  36907. * @type {string}
  36908. */
  36909. this.docId = 'd' + (nextDocumentId++);
  36910. /**
  36911. * Shows if loading task is destroyed.
  36912. * @type {boolean}
  36913. */
  36914. this.destroyed = false;
  36915. /**
  36916. * Callback to request a password if wrong or no password was provided.
  36917. * The callback receives two parameters: function that needs to be called
  36918. * with new password and reason (see {PasswordResponses}).
  36919. */
  36920. this.onPassword = null;
  36921. /**
  36922. * Callback to be able to monitor the loading progress of the PDF file
  36923. * (necessary to implement e.g. a loading bar). The callback receives
  36924. * an {Object} with the properties: {number} loaded and {number} total.
  36925. */
  36926. this.onProgress = null;
  36927. /**
  36928. * Callback to when unsupported feature is used. The callback receives
  36929. * an {UNSUPPORTED_FEATURES} argument.
  36930. */
  36931. this.onUnsupportedFeature = null;
  36932. }
  36933. PDFDocumentLoadingTask.prototype =
  36934. /** @lends PDFDocumentLoadingTask.prototype */ {
  36935. /**
  36936. * @return {Promise}
  36937. */
  36938. get promise() {
  36939. return this._capability.promise;
  36940. },
  36941. /**
  36942. * Aborts all network requests and destroys worker.
  36943. * @return {Promise} A promise that is resolved after destruction activity
  36944. * is completed.
  36945. */
  36946. destroy: function () {
  36947. this.destroyed = true;
  36948. var transportDestroyed = !this._transport ? Promise.resolve() :
  36949. this._transport.destroy();
  36950. return transportDestroyed.then(function () {
  36951. this._transport = null;
  36952. if (this._worker) {
  36953. this._worker.destroy();
  36954. this._worker = null;
  36955. }
  36956. }.bind(this));
  36957. },
  36958. /**
  36959. * Registers callbacks to indicate the document loading completion.
  36960. *
  36961. * @param {function} onFulfilled The callback for the loading completion.
  36962. * @param {function} onRejected The callback for the loading failure.
  36963. * @return {Promise} A promise that is resolved after the onFulfilled or
  36964. * onRejected callback.
  36965. */
  36966. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  36967. return this.promise.then.apply(this.promise, arguments);
  36968. }
  36969. };
  36970. return PDFDocumentLoadingTask;
  36971. })();
  36972. /**
  36973. * Abstract class to support range requests file loading.
  36974. * @class
  36975. * @alias PDFDataRangeTransport
  36976. * @param {number} length
  36977. * @param {Uint8Array} initialData
  36978. */
  36979. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  36980. function PDFDataRangeTransport(length, initialData) {
  36981. this.length = length;
  36982. this.initialData = initialData;
  36983. this._rangeListeners = [];
  36984. this._progressListeners = [];
  36985. this._progressiveReadListeners = [];
  36986. this._readyCapability = createPromiseCapability();
  36987. }
  36988. PDFDataRangeTransport.prototype =
  36989. /** @lends PDFDataRangeTransport.prototype */ {
  36990. addRangeListener:
  36991. function PDFDataRangeTransport_addRangeListener(listener) {
  36992. this._rangeListeners.push(listener);
  36993. },
  36994. addProgressListener:
  36995. function PDFDataRangeTransport_addProgressListener(listener) {
  36996. this._progressListeners.push(listener);
  36997. },
  36998. addProgressiveReadListener:
  36999. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  37000. this._progressiveReadListeners.push(listener);
  37001. },
  37002. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  37003. var listeners = this._rangeListeners;
  37004. for (var i = 0, n = listeners.length; i < n; ++i) {
  37005. listeners[i](begin, chunk);
  37006. }
  37007. },
  37008. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  37009. this._readyCapability.promise.then(function () {
  37010. var listeners = this._progressListeners;
  37011. for (var i = 0, n = listeners.length; i < n; ++i) {
  37012. listeners[i](loaded);
  37013. }
  37014. }.bind(this));
  37015. },
  37016. onDataProgressiveRead:
  37017. function PDFDataRangeTransport_onDataProgress(chunk) {
  37018. this._readyCapability.promise.then(function () {
  37019. var listeners = this._progressiveReadListeners;
  37020. for (var i = 0, n = listeners.length; i < n; ++i) {
  37021. listeners[i](chunk);
  37022. }
  37023. }.bind(this));
  37024. },
  37025. transportReady: function PDFDataRangeTransport_transportReady() {
  37026. this._readyCapability.resolve();
  37027. },
  37028. requestDataRange:
  37029. function PDFDataRangeTransport_requestDataRange(begin, end) {
  37030. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  37031. },
  37032. abort: function PDFDataRangeTransport_abort() {
  37033. }
  37034. };
  37035. return PDFDataRangeTransport;
  37036. })();
  37037. /**
  37038. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  37039. * properties that can be read synchronously.
  37040. * @class
  37041. * @alias PDFDocumentProxy
  37042. */
  37043. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  37044. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  37045. this.pdfInfo = pdfInfo;
  37046. this.transport = transport;
  37047. this.loadingTask = loadingTask;
  37048. }
  37049. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  37050. /**
  37051. * @return {number} Total number of pages the PDF contains.
  37052. */
  37053. get numPages() {
  37054. return this.pdfInfo.numPages;
  37055. },
  37056. /**
  37057. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  37058. * unique.
  37059. */
  37060. get fingerprint() {
  37061. return this.pdfInfo.fingerprint;
  37062. },
  37063. /**
  37064. * @param {number} pageNumber The page number to get. The first page is 1.
  37065. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  37066. * object.
  37067. */
  37068. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  37069. return this.transport.getPage(pageNumber);
  37070. },
  37071. /**
  37072. * @param {{num: number, gen: number}} ref The page reference. Must have
  37073. * the 'num' and 'gen' properties.
  37074. * @return {Promise} A promise that is resolved with the page index that is
  37075. * associated with the reference.
  37076. */
  37077. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  37078. return this.transport.getPageIndex(ref);
  37079. },
  37080. /**
  37081. * @return {Promise} A promise that is resolved with a lookup table for
  37082. * mapping named destinations to reference numbers.
  37083. *
  37084. * This can be slow for large documents: use getDestination instead
  37085. */
  37086. getDestinations: function PDFDocumentProxy_getDestinations() {
  37087. return this.transport.getDestinations();
  37088. },
  37089. /**
  37090. * @param {string} id The named destination to get.
  37091. * @return {Promise} A promise that is resolved with all information
  37092. * of the given named destination.
  37093. */
  37094. getDestination: function PDFDocumentProxy_getDestination(id) {
  37095. return this.transport.getDestination(id);
  37096. },
  37097. /**
  37098. * @return {Promise} A promise that is resolved with:
  37099. * an Array containing the pageLabels that correspond to the pageIndexes,
  37100. * or `null` when no pageLabels are present in the PDF file.
  37101. */
  37102. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  37103. return this.transport.getPageLabels();
  37104. },
  37105. /**
  37106. * @return {Promise} A promise that is resolved with a lookup table for
  37107. * mapping named attachments to their content.
  37108. */
  37109. getAttachments: function PDFDocumentProxy_getAttachments() {
  37110. return this.transport.getAttachments();
  37111. },
  37112. /**
  37113. * @return {Promise} A promise that is resolved with an array of all the
  37114. * JavaScript strings in the name tree.
  37115. */
  37116. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  37117. return this.transport.getJavaScript();
  37118. },
  37119. /**
  37120. * @return {Promise} A promise that is resolved with an {Array} that is a
  37121. * tree outline (if it has one) of the PDF. The tree is in the format of:
  37122. * [
  37123. * {
  37124. * title: string,
  37125. * bold: boolean,
  37126. * italic: boolean,
  37127. * color: rgb Uint8Array,
  37128. * dest: dest obj,
  37129. * url: string,
  37130. * items: array of more items like this
  37131. * },
  37132. * ...
  37133. * ].
  37134. */
  37135. getOutline: function PDFDocumentProxy_getOutline() {
  37136. return this.transport.getOutline();
  37137. },
  37138. /**
  37139. * @return {Promise} A promise that is resolved with an {Object} that has
  37140. * info and metadata properties. Info is an {Object} filled with anything
  37141. * available in the information dictionary and similarly metadata is a
  37142. * {Metadata} object with information from the metadata section of the PDF.
  37143. */
  37144. getMetadata: function PDFDocumentProxy_getMetadata() {
  37145. return this.transport.getMetadata();
  37146. },
  37147. /**
  37148. * @return {Promise} A promise that is resolved with a TypedArray that has
  37149. * the raw data from the PDF.
  37150. */
  37151. getData: function PDFDocumentProxy_getData() {
  37152. return this.transport.getData();
  37153. },
  37154. /**
  37155. * @return {Promise} A promise that is resolved when the document's data
  37156. * is loaded. It is resolved with an {Object} that contains the length
  37157. * property that indicates size of the PDF data in bytes.
  37158. */
  37159. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  37160. return this.transport.downloadInfoCapability.promise;
  37161. },
  37162. /**
  37163. * @return {Promise} A promise this is resolved with current stats about
  37164. * document structures (see {@link PDFDocumentStats}).
  37165. */
  37166. getStats: function PDFDocumentProxy_getStats() {
  37167. return this.transport.getStats();
  37168. },
  37169. /**
  37170. * Cleans up resources allocated by the document, e.g. created @font-face.
  37171. */
  37172. cleanup: function PDFDocumentProxy_cleanup() {
  37173. this.transport.startCleanup();
  37174. },
  37175. /**
  37176. * Destroys current document instance and terminates worker.
  37177. */
  37178. destroy: function PDFDocumentProxy_destroy() {
  37179. return this.loadingTask.destroy();
  37180. }
  37181. };
  37182. return PDFDocumentProxy;
  37183. })();
  37184. /**
  37185. * Page getTextContent parameters.
  37186. *
  37187. * @typedef {Object} getTextContentParameters
  37188. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  37189. * whitespace with standard spaces (0x20). The default value is `false`.
  37190. * @param {boolean} disableCombineTextItems - do not attempt to combine
  37191. * same line {@link TextItem}'s. The default value is `false`.
  37192. */
  37193. /**
  37194. * Page text content.
  37195. *
  37196. * @typedef {Object} TextContent
  37197. * @property {array} items - array of {@link TextItem}
  37198. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  37199. * name.
  37200. */
  37201. /**
  37202. * Page text content part.
  37203. *
  37204. * @typedef {Object} TextItem
  37205. * @property {string} str - text content.
  37206. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  37207. * @property {array} transform - transformation matrix.
  37208. * @property {number} width - width in device space.
  37209. * @property {number} height - height in device space.
  37210. * @property {string} fontName - font name used by pdf.js for converted font.
  37211. */
  37212. /**
  37213. * Text style.
  37214. *
  37215. * @typedef {Object} TextStyle
  37216. * @property {number} ascent - font ascent.
  37217. * @property {number} descent - font descent.
  37218. * @property {boolean} vertical - text is in vertical mode.
  37219. * @property {string} fontFamily - possible font family
  37220. */
  37221. /**
  37222. * Page annotation parameters.
  37223. *
  37224. * @typedef {Object} GetAnnotationsParameters
  37225. * @param {string} intent - Determines the annotations that will be fetched,
  37226. * can be either 'display' (viewable annotations) or 'print'
  37227. * (printable annotations).
  37228. * If the parameter is omitted, all annotations are fetched.
  37229. */
  37230. /**
  37231. * Page render parameters.
  37232. *
  37233. * @typedef {Object} RenderParameters
  37234. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  37235. * @property {PageViewport} viewport - Rendering viewport obtained by
  37236. * calling of PDFPage.getViewport method.
  37237. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  37238. * (default value is 'display').
  37239. * @property {boolean} renderInteractiveForms - (optional) Whether or not
  37240. * interactive form elements are rendered in the display
  37241. * layer. If so, we do not render them on canvas as well.
  37242. * @property {Array} transform - (optional) Additional transform, applied
  37243. * just before viewport transform.
  37244. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  37245. * endLayout and appendImage functions.
  37246. * @property {function} continueCallback - (deprecated) A function that will be
  37247. * called each time the rendering is paused. To continue
  37248. * rendering call the function that is the first argument
  37249. * to the callback.
  37250. */
  37251. /**
  37252. * PDF page operator list.
  37253. *
  37254. * @typedef {Object} PDFOperatorList
  37255. * @property {Array} fnArray - Array containing the operator functions.
  37256. * @property {Array} argsArray - Array containing the arguments of the
  37257. * functions.
  37258. */
  37259. /**
  37260. * Proxy to a PDFPage in the worker thread.
  37261. * @class
  37262. * @alias PDFPageProxy
  37263. */
  37264. var PDFPageProxy = (function PDFPageProxyClosure() {
  37265. function PDFPageProxy(pageIndex, pageInfo, transport) {
  37266. this.pageIndex = pageIndex;
  37267. this.pageInfo = pageInfo;
  37268. this.transport = transport;
  37269. this.stats = new StatTimer();
  37270. this.stats.enabled = getDefaultSetting('enableStats');
  37271. this.commonObjs = transport.commonObjs;
  37272. this.objs = new PDFObjects();
  37273. this.cleanupAfterRender = false;
  37274. this.pendingCleanup = false;
  37275. this.intentStates = Object.create(null);
  37276. this.destroyed = false;
  37277. }
  37278. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  37279. /**
  37280. * @return {number} Page number of the page. First page is 1.
  37281. */
  37282. get pageNumber() {
  37283. return this.pageIndex + 1;
  37284. },
  37285. /**
  37286. * @return {number} The number of degrees the page is rotated clockwise.
  37287. */
  37288. get rotate() {
  37289. return this.pageInfo.rotate;
  37290. },
  37291. /**
  37292. * @return {Object} The reference that points to this page. It has 'num' and
  37293. * 'gen' properties.
  37294. */
  37295. get ref() {
  37296. return this.pageInfo.ref;
  37297. },
  37298. /**
  37299. * @return {Array} An array of the visible portion of the PDF page in the
  37300. * user space units - [x1, y1, x2, y2].
  37301. */
  37302. get view() {
  37303. return this.pageInfo.view;
  37304. },
  37305. /**
  37306. * @param {number} scale The desired scale of the viewport.
  37307. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  37308. * defaults to the page rotation.
  37309. * @return {PageViewport} Contains 'width' and 'height' properties
  37310. * along with transforms required for rendering.
  37311. */
  37312. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  37313. if (arguments.length < 2) {
  37314. rotate = this.rotate;
  37315. }
  37316. return new PageViewport(this.view, scale, rotate, 0, 0);
  37317. },
  37318. /**
  37319. * @param {GetAnnotationsParameters} params - Annotation parameters.
  37320. * @return {Promise} A promise that is resolved with an {Array} of the
  37321. * annotation objects.
  37322. */
  37323. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  37324. var intent = (params && params.intent) || null;
  37325. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  37326. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  37327. intent);
  37328. this.annotationsIntent = intent;
  37329. }
  37330. return this.annotationsPromise;
  37331. },
  37332. /**
  37333. * Begins the process of rendering a page to the desired context.
  37334. * @param {RenderParameters} params Page render parameters.
  37335. * @return {RenderTask} An object that contains the promise, which
  37336. * is resolved when the page finishes rendering.
  37337. */
  37338. render: function PDFPageProxy_render(params) {
  37339. var stats = this.stats;
  37340. stats.time('Overall');
  37341. // If there was a pending destroy cancel it so no cleanup happens during
  37342. // this call to render.
  37343. this.pendingCleanup = false;
  37344. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  37345. var renderInteractiveForms = (params.renderInteractiveForms === true ?
  37346. true : /* Default */ false);
  37347. if (!this.intentStates[renderingIntent]) {
  37348. this.intentStates[renderingIntent] = Object.create(null);
  37349. }
  37350. var intentState = this.intentStates[renderingIntent];
  37351. // If there's no displayReadyCapability yet, then the operatorList
  37352. // was never requested before. Make the request and create the promise.
  37353. if (!intentState.displayReadyCapability) {
  37354. intentState.receivingOperatorList = true;
  37355. intentState.displayReadyCapability = createPromiseCapability();
  37356. intentState.operatorList = {
  37357. fnArray: [],
  37358. argsArray: [],
  37359. lastChunk: false
  37360. };
  37361. this.stats.time('Page Request');
  37362. this.transport.messageHandler.send('RenderPageRequest', {
  37363. pageIndex: this.pageNumber - 1,
  37364. intent: renderingIntent,
  37365. renderInteractiveForms: renderInteractiveForms,
  37366. });
  37367. }
  37368. var internalRenderTask = new InternalRenderTask(complete, params,
  37369. this.objs,
  37370. this.commonObjs,
  37371. intentState.operatorList,
  37372. this.pageNumber);
  37373. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  37374. if (!intentState.renderTasks) {
  37375. intentState.renderTasks = [];
  37376. }
  37377. intentState.renderTasks.push(internalRenderTask);
  37378. var renderTask = internalRenderTask.task;
  37379. // Obsolete parameter support
  37380. if (params.continueCallback) {
  37381. deprecated('render is used with continueCallback parameter');
  37382. renderTask.onContinue = params.continueCallback;
  37383. }
  37384. var self = this;
  37385. intentState.displayReadyCapability.promise.then(
  37386. function pageDisplayReadyPromise(transparency) {
  37387. if (self.pendingCleanup) {
  37388. complete();
  37389. return;
  37390. }
  37391. stats.time('Rendering');
  37392. internalRenderTask.initializeGraphics(transparency);
  37393. internalRenderTask.operatorListChanged();
  37394. },
  37395. function pageDisplayReadPromiseError(reason) {
  37396. complete(reason);
  37397. }
  37398. );
  37399. function complete(error) {
  37400. var i = intentState.renderTasks.indexOf(internalRenderTask);
  37401. if (i >= 0) {
  37402. intentState.renderTasks.splice(i, 1);
  37403. }
  37404. if (self.cleanupAfterRender) {
  37405. self.pendingCleanup = true;
  37406. }
  37407. self._tryCleanup();
  37408. if (error) {
  37409. internalRenderTask.capability.reject(error);
  37410. } else {
  37411. internalRenderTask.capability.resolve();
  37412. }
  37413. stats.timeEnd('Rendering');
  37414. stats.timeEnd('Overall');
  37415. }
  37416. return renderTask;
  37417. },
  37418. /**
  37419. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  37420. * object that represents page's operator list.
  37421. */
  37422. getOperatorList: function PDFPageProxy_getOperatorList() {
  37423. function operatorListChanged() {
  37424. if (intentState.operatorList.lastChunk) {
  37425. intentState.opListReadCapability.resolve(intentState.operatorList);
  37426. var i = intentState.renderTasks.indexOf(opListTask);
  37427. if (i >= 0) {
  37428. intentState.renderTasks.splice(i, 1);
  37429. }
  37430. }
  37431. }
  37432. var renderingIntent = 'oplist';
  37433. if (!this.intentStates[renderingIntent]) {
  37434. this.intentStates[renderingIntent] = Object.create(null);
  37435. }
  37436. var intentState = this.intentStates[renderingIntent];
  37437. var opListTask;
  37438. if (!intentState.opListReadCapability) {
  37439. opListTask = {};
  37440. opListTask.operatorListChanged = operatorListChanged;
  37441. intentState.receivingOperatorList = true;
  37442. intentState.opListReadCapability = createPromiseCapability();
  37443. intentState.renderTasks = [];
  37444. intentState.renderTasks.push(opListTask);
  37445. intentState.operatorList = {
  37446. fnArray: [],
  37447. argsArray: [],
  37448. lastChunk: false
  37449. };
  37450. this.transport.messageHandler.send('RenderPageRequest', {
  37451. pageIndex: this.pageIndex,
  37452. intent: renderingIntent
  37453. });
  37454. }
  37455. return intentState.opListReadCapability.promise;
  37456. },
  37457. /**
  37458. * @param {getTextContentParameters} params - getTextContent parameters.
  37459. * @return {Promise} That is resolved a {@link TextContent}
  37460. * object that represent the page text content.
  37461. */
  37462. getTextContent: function PDFPageProxy_getTextContent(params) {
  37463. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  37464. pageIndex: this.pageNumber - 1,
  37465. normalizeWhitespace: (params && params.normalizeWhitespace === true ?
  37466. true : /* Default */ false),
  37467. combineTextItems: (params && params.disableCombineTextItems === true ?
  37468. false : /* Default */ true),
  37469. });
  37470. },
  37471. /**
  37472. * Destroys page object.
  37473. */
  37474. _destroy: function PDFPageProxy_destroy() {
  37475. this.destroyed = true;
  37476. this.transport.pageCache[this.pageIndex] = null;
  37477. var waitOn = [];
  37478. Object.keys(this.intentStates).forEach(function(intent) {
  37479. if (intent === 'oplist') {
  37480. // Avoid errors below, since the renderTasks are just stubs.
  37481. return;
  37482. }
  37483. var intentState = this.intentStates[intent];
  37484. intentState.renderTasks.forEach(function(renderTask) {
  37485. var renderCompleted = renderTask.capability.promise.
  37486. catch(function () {}); // ignoring failures
  37487. waitOn.push(renderCompleted);
  37488. renderTask.cancel();
  37489. });
  37490. }, this);
  37491. this.objs.clear();
  37492. this.annotationsPromise = null;
  37493. this.pendingCleanup = false;
  37494. return Promise.all(waitOn);
  37495. },
  37496. /**
  37497. * Cleans up resources allocated by the page. (deprecated)
  37498. */
  37499. destroy: function() {
  37500. deprecated('page destroy method, use cleanup() instead');
  37501. this.cleanup();
  37502. },
  37503. /**
  37504. * Cleans up resources allocated by the page.
  37505. */
  37506. cleanup: function PDFPageProxy_cleanup() {
  37507. this.pendingCleanup = true;
  37508. this._tryCleanup();
  37509. },
  37510. /**
  37511. * For internal use only. Attempts to clean up if rendering is in a state
  37512. * where that's possible.
  37513. * @ignore
  37514. */
  37515. _tryCleanup: function PDFPageProxy_tryCleanup() {
  37516. if (!this.pendingCleanup ||
  37517. Object.keys(this.intentStates).some(function(intent) {
  37518. var intentState = this.intentStates[intent];
  37519. return (intentState.renderTasks.length !== 0 ||
  37520. intentState.receivingOperatorList);
  37521. }, this)) {
  37522. return;
  37523. }
  37524. Object.keys(this.intentStates).forEach(function(intent) {
  37525. delete this.intentStates[intent];
  37526. }, this);
  37527. this.objs.clear();
  37528. this.annotationsPromise = null;
  37529. this.pendingCleanup = false;
  37530. },
  37531. /**
  37532. * For internal use only.
  37533. * @ignore
  37534. */
  37535. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  37536. intent) {
  37537. var intentState = this.intentStates[intent];
  37538. // TODO Refactor RenderPageRequest to separate rendering
  37539. // and operator list logic
  37540. if (intentState.displayReadyCapability) {
  37541. intentState.displayReadyCapability.resolve(transparency);
  37542. }
  37543. },
  37544. /**
  37545. * For internal use only.
  37546. * @ignore
  37547. */
  37548. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  37549. intent) {
  37550. var intentState = this.intentStates[intent];
  37551. var i, ii;
  37552. // Add the new chunk to the current operator list.
  37553. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  37554. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  37555. intentState.operatorList.argsArray.push(
  37556. operatorListChunk.argsArray[i]);
  37557. }
  37558. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  37559. // Notify all the rendering tasks there are more operators to be consumed.
  37560. for (i = 0; i < intentState.renderTasks.length; i++) {
  37561. intentState.renderTasks[i].operatorListChanged();
  37562. }
  37563. if (operatorListChunk.lastChunk) {
  37564. intentState.receivingOperatorList = false;
  37565. this._tryCleanup();
  37566. }
  37567. }
  37568. };
  37569. return PDFPageProxy;
  37570. })();
  37571. /**
  37572. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  37573. * WorkerTransport for them. If creation of a web worker is not possible,
  37574. * a "fake" worker will be used instead.
  37575. * @class
  37576. */
  37577. var PDFWorker = (function PDFWorkerClosure() {
  37578. var nextFakeWorkerId = 0;
  37579. function getWorkerSrc() {
  37580. if (typeof workerSrc !== 'undefined') {
  37581. return workerSrc;
  37582. }
  37583. if (getDefaultSetting('workerSrc')) {
  37584. return getDefaultSetting('workerSrc');
  37585. }
  37586. if (pdfjsFilePath) {
  37587. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  37588. }
  37589. error('No PDFJS.workerSrc specified');
  37590. }
  37591. var fakeWorkerFilesLoadedCapability;
  37592. // Loads worker code into main thread.
  37593. function setupFakeWorkerGlobal() {
  37594. var WorkerMessageHandler;
  37595. if (!fakeWorkerFilesLoadedCapability) {
  37596. fakeWorkerFilesLoadedCapability = createPromiseCapability();
  37597. // In the developer build load worker_loader which in turn loads all the
  37598. // other files and resolves the promise. In production only the
  37599. // pdf.worker.js file is needed.
  37600. WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  37601. fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
  37602. }
  37603. return fakeWorkerFilesLoadedCapability.promise;
  37604. }
  37605. function FakeWorkerPort(defer) {
  37606. this._listeners = [];
  37607. this._defer = defer;
  37608. this._deferred = Promise.resolve(undefined);
  37609. }
  37610. FakeWorkerPort.prototype = {
  37611. postMessage: function (obj, transfers) {
  37612. function cloneValue(value) {
  37613. // Trying to perform a structured clone close to the spec, including
  37614. // transfers.
  37615. if (typeof value !== 'object' || value === null) {
  37616. return value;
  37617. }
  37618. if (cloned.has(value)) { // already cloned the object
  37619. return cloned.get(value);
  37620. }
  37621. var result;
  37622. var buffer;
  37623. if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
  37624. // We found object with ArrayBuffer (typed array).
  37625. var transferable = transfers && transfers.indexOf(buffer) >= 0;
  37626. if (value === buffer) {
  37627. // Special case when we are faking typed arrays in compatibility.js.
  37628. result = value;
  37629. } else if (transferable) {
  37630. result = new value.constructor(buffer, value.byteOffset,
  37631. value.byteLength);
  37632. } else {
  37633. result = new value.constructor(value);
  37634. }
  37635. cloned.set(value, result);
  37636. return result;
  37637. }
  37638. result = isArray(value) ? [] : {};
  37639. cloned.set(value, result); // adding to cache now for cyclic references
  37640. // Cloning all value and object properties, however ignoring properties
  37641. // defined via getter.
  37642. for (var i in value) {
  37643. var desc, p = value;
  37644. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  37645. p = Object.getPrototypeOf(p);
  37646. }
  37647. if (typeof desc.value === 'undefined' ||
  37648. typeof desc.value === 'function') {
  37649. continue;
  37650. }
  37651. result[i] = cloneValue(desc.value);
  37652. }
  37653. return result;
  37654. }
  37655. if (!this._defer) {
  37656. this._listeners.forEach(function (listener) {
  37657. listener.call(this, {data: obj});
  37658. }, this);
  37659. return;
  37660. }
  37661. var cloned = new WeakMap();
  37662. var e = {data: cloneValue(obj)};
  37663. this._deferred.then(function () {
  37664. this._listeners.forEach(function (listener) {
  37665. listener.call(this, e);
  37666. }, this);
  37667. }.bind(this));
  37668. },
  37669. addEventListener: function (name, listener) {
  37670. this._listeners.push(listener);
  37671. },
  37672. removeEventListener: function (name, listener) {
  37673. var i = this._listeners.indexOf(listener);
  37674. this._listeners.splice(i, 1);
  37675. },
  37676. terminate: function () {
  37677. this._listeners = [];
  37678. }
  37679. };
  37680. function createCDNWrapper(url) {
  37681. // We will rely on blob URL's property to specify origin.
  37682. // We want this function to fail in case if createObjectURL or Blob do not
  37683. // exist or fail for some reason -- our Worker creation will fail anyway.
  37684. var wrapper = 'importScripts(\'' + url + '\');';
  37685. return URL.createObjectURL(new Blob([wrapper]));
  37686. }
  37687. function PDFWorker(name) {
  37688. this.name = name;
  37689. this.destroyed = false;
  37690. this._readyCapability = createPromiseCapability();
  37691. this._port = null;
  37692. this._webWorker = null;
  37693. this._messageHandler = null;
  37694. this._initialize();
  37695. }
  37696. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  37697. get promise() {
  37698. return this._readyCapability.promise;
  37699. },
  37700. get port() {
  37701. return this._port;
  37702. },
  37703. get messageHandler() {
  37704. return this._messageHandler;
  37705. },
  37706. _initialize: function PDFWorker_initialize() {
  37707. // If worker support isn't disabled explicit and the browser has worker
  37708. // support, create a new web worker and test if it/the browser fulfills
  37709. // all requirements to run parts of pdf.js in a web worker.
  37710. // Right now, the requirement is, that an Uint8Array is still an
  37711. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  37712. // Either workers are disabled, not supported or have thrown an exception.
  37713. // Thus, we fallback to a faked worker.
  37714. this._setupFakeWorker();
  37715. },
  37716. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  37717. if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
  37718. warn('Setting up fake worker.');
  37719. isWorkerDisabled = true;
  37720. }
  37721. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  37722. if (this.destroyed) {
  37723. this._readyCapability.reject(new Error('Worker was destroyed'));
  37724. return;
  37725. }
  37726. // We cannot turn on proper fake port simulation (this includes
  37727. // structured cloning) when typed arrays are not supported. Relying
  37728. // on a chance that messages will be sent in proper order.
  37729. var isTypedArraysPresent = Uint8Array !== Float32Array;
  37730. var port = new FakeWorkerPort(isTypedArraysPresent);
  37731. this._port = port;
  37732. // All fake workers use the same port, making id unique.
  37733. var id = 'fake' + (nextFakeWorkerId++);
  37734. // If the main thread is our worker, setup the handling for the
  37735. // messages -- the main thread sends to it self.
  37736. var workerHandler = new MessageHandler(id + '_worker', id, port);
  37737. WorkerMessageHandler.setup(workerHandler, port);
  37738. var messageHandler = new MessageHandler(id, id + '_worker', port);
  37739. this._messageHandler = messageHandler;
  37740. this._readyCapability.resolve();
  37741. }.bind(this));
  37742. },
  37743. /**
  37744. * Destroys the worker instance.
  37745. */
  37746. destroy: function PDFWorker_destroy() {
  37747. this.destroyed = true;
  37748. if (this._webWorker) {
  37749. // We need to terminate only web worker created resource.
  37750. this._webWorker.terminate();
  37751. this._webWorker = null;
  37752. }
  37753. this._port = null;
  37754. if (this._messageHandler) {
  37755. this._messageHandler.destroy();
  37756. this._messageHandler = null;
  37757. }
  37758. }
  37759. };
  37760. return PDFWorker;
  37761. })();
  37762. /**
  37763. * For internal use only.
  37764. * @ignore
  37765. */
  37766. var WorkerTransport = (function WorkerTransportClosure() {
  37767. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  37768. this.messageHandler = messageHandler;
  37769. this.loadingTask = loadingTask;
  37770. this.pdfDataRangeTransport = pdfDataRangeTransport;
  37771. this.commonObjs = new PDFObjects();
  37772. this.fontLoader = new FontLoader(loadingTask.docId);
  37773. this.destroyed = false;
  37774. this.destroyCapability = null;
  37775. this.pageCache = [];
  37776. this.pagePromises = [];
  37777. this.downloadInfoCapability = createPromiseCapability();
  37778. this.setupMessageHandler();
  37779. }
  37780. WorkerTransport.prototype = {
  37781. destroy: function WorkerTransport_destroy() {
  37782. if (this.destroyCapability) {
  37783. return this.destroyCapability.promise;
  37784. }
  37785. this.destroyed = true;
  37786. this.destroyCapability = createPromiseCapability();
  37787. var waitOn = [];
  37788. // We need to wait for all renderings to be completed, e.g.
  37789. // timeout/rAF can take a long time.
  37790. this.pageCache.forEach(function (page) {
  37791. if (page) {
  37792. waitOn.push(page._destroy());
  37793. }
  37794. });
  37795. this.pageCache = [];
  37796. this.pagePromises = [];
  37797. var self = this;
  37798. // We also need to wait for the worker to finish its long running tasks.
  37799. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  37800. waitOn.push(terminated);
  37801. Promise.all(waitOn).then(function () {
  37802. self.fontLoader.clear();
  37803. if (self.pdfDataRangeTransport) {
  37804. self.pdfDataRangeTransport.abort();
  37805. self.pdfDataRangeTransport = null;
  37806. }
  37807. if (self.messageHandler) {
  37808. self.messageHandler.destroy();
  37809. self.messageHandler = null;
  37810. }
  37811. self.destroyCapability.resolve();
  37812. }, this.destroyCapability.reject);
  37813. return this.destroyCapability.promise;
  37814. },
  37815. setupMessageHandler:
  37816. function WorkerTransport_setupMessageHandler() {
  37817. var messageHandler = this.messageHandler;
  37818. function updatePassword(password) {
  37819. messageHandler.send('UpdatePassword', password);
  37820. }
  37821. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  37822. if (pdfDataRangeTransport) {
  37823. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  37824. messageHandler.send('OnDataRange', {
  37825. begin: begin,
  37826. chunk: chunk
  37827. });
  37828. });
  37829. pdfDataRangeTransport.addProgressListener(function(loaded) {
  37830. messageHandler.send('OnDataProgress', {
  37831. loaded: loaded
  37832. });
  37833. });
  37834. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  37835. messageHandler.send('OnDataRange', {
  37836. chunk: chunk
  37837. });
  37838. });
  37839. messageHandler.on('RequestDataRange',
  37840. function transportDataRange(data) {
  37841. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  37842. }, this);
  37843. }
  37844. messageHandler.on('GetDoc', function transportDoc(data) {
  37845. var pdfInfo = data.pdfInfo;
  37846. this.numPages = data.pdfInfo.numPages;
  37847. var loadingTask = this.loadingTask;
  37848. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  37849. this.pdfDocument = pdfDocument;
  37850. loadingTask._capability.resolve(pdfDocument);
  37851. }, this);
  37852. messageHandler.on('NeedPassword',
  37853. function transportNeedPassword(exception) {
  37854. var loadingTask = this.loadingTask;
  37855. if (loadingTask.onPassword) {
  37856. return loadingTask.onPassword(updatePassword,
  37857. PasswordResponses.NEED_PASSWORD);
  37858. }
  37859. loadingTask._capability.reject(
  37860. new PasswordException(exception.message, exception.code));
  37861. }, this);
  37862. messageHandler.on('IncorrectPassword',
  37863. function transportIncorrectPassword(exception) {
  37864. var loadingTask = this.loadingTask;
  37865. if (loadingTask.onPassword) {
  37866. return loadingTask.onPassword(updatePassword,
  37867. PasswordResponses.INCORRECT_PASSWORD);
  37868. }
  37869. loadingTask._capability.reject(
  37870. new PasswordException(exception.message, exception.code));
  37871. }, this);
  37872. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  37873. this.loadingTask._capability.reject(
  37874. new InvalidPDFException(exception.message));
  37875. }, this);
  37876. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  37877. this.loadingTask._capability.reject(
  37878. new MissingPDFException(exception.message));
  37879. }, this);
  37880. messageHandler.on('UnexpectedResponse',
  37881. function transportUnexpectedResponse(exception) {
  37882. this.loadingTask._capability.reject(
  37883. new UnexpectedResponseException(exception.message, exception.status));
  37884. }, this);
  37885. messageHandler.on('UnknownError',
  37886. function transportUnknownError(exception) {
  37887. this.loadingTask._capability.reject(
  37888. new UnknownErrorException(exception.message, exception.details));
  37889. }, this);
  37890. messageHandler.on('DataLoaded', function transportPage(data) {
  37891. this.downloadInfoCapability.resolve(data);
  37892. }, this);
  37893. messageHandler.on('PDFManagerReady', function transportPage(data) {
  37894. if (this.pdfDataRangeTransport) {
  37895. this.pdfDataRangeTransport.transportReady();
  37896. }
  37897. }, this);
  37898. messageHandler.on('StartRenderPage', function transportRender(data) {
  37899. if (this.destroyed) {
  37900. return; // Ignore any pending requests if the worker was terminated.
  37901. }
  37902. var page = this.pageCache[data.pageIndex];
  37903. page.stats.timeEnd('Page Request');
  37904. page._startRenderPage(data.transparency, data.intent);
  37905. }, this);
  37906. messageHandler.on('RenderPageChunk', function transportRender(data) {
  37907. if (this.destroyed) {
  37908. return; // Ignore any pending requests if the worker was terminated.
  37909. }
  37910. var page = this.pageCache[data.pageIndex];
  37911. page._renderPageChunk(data.operatorList, data.intent);
  37912. }, this);
  37913. messageHandler.on('commonobj', function transportObj(data) {
  37914. if (this.destroyed) {
  37915. return; // Ignore any pending requests if the worker was terminated.
  37916. }
  37917. var id = data[0];
  37918. var type = data[1];
  37919. if (this.commonObjs.hasData(id)) {
  37920. return;
  37921. }
  37922. switch (type) {
  37923. case 'Font':
  37924. var exportedData = data[2];
  37925. if ('error' in exportedData) {
  37926. var exportedError = exportedData.error;
  37927. warn('Error during font loading: ' + exportedError);
  37928. this.commonObjs.resolve(id, exportedError);
  37929. break;
  37930. }
  37931. var fontRegistry = null;
  37932. if (getDefaultSetting('pdfBug') && globalScope.FontInspector &&
  37933. globalScope['FontInspector'].enabled) {
  37934. fontRegistry = {
  37935. registerFont: function (font, url) {
  37936. globalScope['FontInspector'].fontAdded(font, url);
  37937. }
  37938. };
  37939. }
  37940. var font = new FontFaceObject(exportedData, {
  37941. isEvalSuported: getDefaultSetting('isEvalSupported'),
  37942. disableFontFace: getDefaultSetting('disableFontFace'),
  37943. fontRegistry: fontRegistry
  37944. });
  37945. this.fontLoader.bind(
  37946. [font],
  37947. function fontReady(fontObjs) {
  37948. this.commonObjs.resolve(id, font);
  37949. }.bind(this)
  37950. );
  37951. break;
  37952. case 'FontPath':
  37953. this.commonObjs.resolve(id, data[2]);
  37954. break;
  37955. default:
  37956. error('Got unknown common object type ' + type);
  37957. }
  37958. }, this);
  37959. messageHandler.on('obj', function transportObj(data) {
  37960. if (this.destroyed) {
  37961. return; // Ignore any pending requests if the worker was terminated.
  37962. }
  37963. var id = data[0];
  37964. var pageIndex = data[1];
  37965. var type = data[2];
  37966. var pageProxy = this.pageCache[pageIndex];
  37967. var imageData;
  37968. if (pageProxy.objs.hasData(id)) {
  37969. return;
  37970. }
  37971. switch (type) {
  37972. case 'JpegStream':
  37973. imageData = data[3];
  37974. loadJpegStream(id, imageData, pageProxy.objs);
  37975. break;
  37976. case 'Image':
  37977. imageData = data[3];
  37978. pageProxy.objs.resolve(id, imageData);
  37979. // heuristics that will allow not to store large data
  37980. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  37981. if (imageData && 'data' in imageData &&
  37982. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  37983. pageProxy.cleanupAfterRender = true;
  37984. }
  37985. break;
  37986. default:
  37987. error('Got unknown object type ' + type);
  37988. }
  37989. }, this);
  37990. messageHandler.on('DocProgress', function transportDocProgress(data) {
  37991. if (this.destroyed) {
  37992. return; // Ignore any pending requests if the worker was terminated.
  37993. }
  37994. var loadingTask = this.loadingTask;
  37995. if (loadingTask.onProgress) {
  37996. loadingTask.onProgress({
  37997. loaded: data.loaded,
  37998. total: data.total
  37999. });
  38000. }
  38001. }, this);
  38002. messageHandler.on('PageError', function transportError(data) {
  38003. if (this.destroyed) {
  38004. return; // Ignore any pending requests if the worker was terminated.
  38005. }
  38006. var page = this.pageCache[data.pageNum - 1];
  38007. var intentState = page.intentStates[data.intent];
  38008. if (intentState.displayReadyCapability) {
  38009. intentState.displayReadyCapability.reject(data.error);
  38010. } else {
  38011. error(data.error);
  38012. }
  38013. if (intentState.operatorList) {
  38014. // Mark operator list as complete.
  38015. intentState.operatorList.lastChunk = true;
  38016. for (var i = 0; i < intentState.renderTasks.length; i++) {
  38017. intentState.renderTasks[i].operatorListChanged();
  38018. }
  38019. }
  38020. }, this);
  38021. messageHandler.on('UnsupportedFeature',
  38022. function transportUnsupportedFeature(data) {
  38023. if (this.destroyed) {
  38024. return; // Ignore any pending requests if the worker was terminated.
  38025. }
  38026. var featureId = data.featureId;
  38027. var loadingTask = this.loadingTask;
  38028. if (loadingTask.onUnsupportedFeature) {
  38029. loadingTask.onUnsupportedFeature(featureId);
  38030. }
  38031. _UnsupportedManager.notify(featureId);
  38032. }, this);
  38033. messageHandler.on('JpegDecode', function(data) {
  38034. if (this.destroyed) {
  38035. return Promise.reject(new Error('Worker was destroyed'));
  38036. }
  38037. var imageUrl = data[0];
  38038. var components = data[1];
  38039. if (components !== 3 && components !== 1) {
  38040. return Promise.reject(
  38041. new Error('Only 3 components or 1 component can be returned'));
  38042. }
  38043. return new Promise(function (resolve, reject) {
  38044. var img = new Image();
  38045. img.onload = function () {
  38046. var width = img.width;
  38047. var height = img.height;
  38048. var size = width * height;
  38049. var rgbaLength = size * 4;
  38050. var buf = new Uint8Array(size * components);
  38051. var tmpCanvas = createScratchCanvas(width, height);
  38052. var tmpCtx = tmpCanvas.getContext('2d');
  38053. tmpCtx.drawImage(img, 0, 0);
  38054. var data = tmpCtx.getImageData(0, 0, width, height).data;
  38055. var i, j;
  38056. if (components === 3) {
  38057. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  38058. buf[j] = data[i];
  38059. buf[j + 1] = data[i + 1];
  38060. buf[j + 2] = data[i + 2];
  38061. }
  38062. } else if (components === 1) {
  38063. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  38064. buf[j] = data[i];
  38065. }
  38066. }
  38067. resolve({ data: buf, width: width, height: height});
  38068. };
  38069. img.onerror = function () {
  38070. reject(new Error('JpegDecode failed to load image'));
  38071. };
  38072. img.src = imageUrl;
  38073. });
  38074. }, this);
  38075. },
  38076. getData: function WorkerTransport_getData() {
  38077. return this.messageHandler.sendWithPromise('GetData', null);
  38078. },
  38079. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  38080. if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
  38081. return Promise.reject(new Error('Invalid page request'));
  38082. }
  38083. var pageIndex = pageNumber - 1;
  38084. if (pageIndex in this.pagePromises) {
  38085. return this.pagePromises[pageIndex];
  38086. }
  38087. var promise = this.messageHandler.sendWithPromise('GetPage', {
  38088. pageIndex: pageIndex
  38089. }).then(function (pageInfo) {
  38090. if (this.destroyed) {
  38091. throw new Error('Transport destroyed');
  38092. }
  38093. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  38094. this.pageCache[pageIndex] = page;
  38095. return page;
  38096. }.bind(this));
  38097. this.pagePromises[pageIndex] = promise;
  38098. return promise;
  38099. },
  38100. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  38101. return this.messageHandler.sendWithPromise('GetPageIndex', {
  38102. ref: ref,
  38103. }).catch(function (reason) {
  38104. return Promise.reject(new Error(reason));
  38105. });
  38106. },
  38107. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  38108. return this.messageHandler.sendWithPromise('GetAnnotations', {
  38109. pageIndex: pageIndex,
  38110. intent: intent,
  38111. });
  38112. },
  38113. getDestinations: function WorkerTransport_getDestinations() {
  38114. return this.messageHandler.sendWithPromise('GetDestinations', null);
  38115. },
  38116. getDestination: function WorkerTransport_getDestination(id) {
  38117. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  38118. },
  38119. getPageLabels: function WorkerTransport_getPageLabels() {
  38120. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  38121. },
  38122. getAttachments: function WorkerTransport_getAttachments() {
  38123. return this.messageHandler.sendWithPromise('GetAttachments', null);
  38124. },
  38125. getJavaScript: function WorkerTransport_getJavaScript() {
  38126. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  38127. },
  38128. getOutline: function WorkerTransport_getOutline() {
  38129. return this.messageHandler.sendWithPromise('GetOutline', null);
  38130. },
  38131. getMetadata: function WorkerTransport_getMetadata() {
  38132. return this.messageHandler.sendWithPromise('GetMetadata', null).
  38133. then(function transportMetadata(results) {
  38134. return {
  38135. info: results[0],
  38136. metadata: (results[1] ? new Metadata(results[1]) : null)
  38137. };
  38138. });
  38139. },
  38140. getStats: function WorkerTransport_getStats() {
  38141. return this.messageHandler.sendWithPromise('GetStats', null);
  38142. },
  38143. startCleanup: function WorkerTransport_startCleanup() {
  38144. this.messageHandler.sendWithPromise('Cleanup', null).
  38145. then(function endCleanup() {
  38146. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  38147. var page = this.pageCache[i];
  38148. if (page) {
  38149. page.cleanup();
  38150. }
  38151. }
  38152. this.commonObjs.clear();
  38153. this.fontLoader.clear();
  38154. }.bind(this));
  38155. }
  38156. };
  38157. return WorkerTransport;
  38158. })();
  38159. /**
  38160. * A PDF document and page is built of many objects. E.g. there are objects
  38161. * for fonts, images, rendering code and such. These objects might get processed
  38162. * inside of a worker. The `PDFObjects` implements some basic functions to
  38163. * manage these objects.
  38164. * @ignore
  38165. */
  38166. var PDFObjects = (function PDFObjectsClosure() {
  38167. function PDFObjects() {
  38168. this.objs = Object.create(null);
  38169. }
  38170. PDFObjects.prototype = {
  38171. /**
  38172. * Internal function.
  38173. * Ensures there is an object defined for `objId`.
  38174. */
  38175. ensureObj: function PDFObjects_ensureObj(objId) {
  38176. if (this.objs[objId]) {
  38177. return this.objs[objId];
  38178. }
  38179. var obj = {
  38180. capability: createPromiseCapability(),
  38181. data: null,
  38182. resolved: false
  38183. };
  38184. this.objs[objId] = obj;
  38185. return obj;
  38186. },
  38187. /**
  38188. * If called *without* callback, this returns the data of `objId` but the
  38189. * object needs to be resolved. If it isn't, this function throws.
  38190. *
  38191. * If called *with* a callback, the callback is called with the data of the
  38192. * object once the object is resolved. That means, if you call this
  38193. * function and the object is already resolved, the callback gets called
  38194. * right away.
  38195. */
  38196. get: function PDFObjects_get(objId, callback) {
  38197. // If there is a callback, then the get can be async and the object is
  38198. // not required to be resolved right now
  38199. if (callback) {
  38200. this.ensureObj(objId).capability.promise.then(callback);
  38201. return null;
  38202. }
  38203. // If there isn't a callback, the user expects to get the resolved data
  38204. // directly.
  38205. var obj = this.objs[objId];
  38206. // If there isn't an object yet or the object isn't resolved, then the
  38207. // data isn't ready yet!
  38208. if (!obj || !obj.resolved) {
  38209. error('Requesting object that isn\'t resolved yet ' + objId);
  38210. }
  38211. return obj.data;
  38212. },
  38213. /**
  38214. * Resolves the object `objId` with optional `data`.
  38215. */
  38216. resolve: function PDFObjects_resolve(objId, data) {
  38217. var obj = this.ensureObj(objId);
  38218. obj.resolved = true;
  38219. obj.data = data;
  38220. obj.capability.resolve(data);
  38221. },
  38222. isResolved: function PDFObjects_isResolved(objId) {
  38223. var objs = this.objs;
  38224. if (!objs[objId]) {
  38225. return false;
  38226. } else {
  38227. return objs[objId].resolved;
  38228. }
  38229. },
  38230. hasData: function PDFObjects_hasData(objId) {
  38231. return this.isResolved(objId);
  38232. },
  38233. /**
  38234. * Returns the data of `objId` if object exists, null otherwise.
  38235. */
  38236. getData: function PDFObjects_getData(objId) {
  38237. var objs = this.objs;
  38238. if (!objs[objId] || !objs[objId].resolved) {
  38239. return null;
  38240. } else {
  38241. return objs[objId].data;
  38242. }
  38243. },
  38244. clear: function PDFObjects_clear() {
  38245. this.objs = Object.create(null);
  38246. }
  38247. };
  38248. return PDFObjects;
  38249. })();
  38250. /**
  38251. * Allows controlling of the rendering tasks.
  38252. * @class
  38253. * @alias RenderTask
  38254. */
  38255. var RenderTask = (function RenderTaskClosure() {
  38256. function RenderTask(internalRenderTask) {
  38257. this._internalRenderTask = internalRenderTask;
  38258. /**
  38259. * Callback for incremental rendering -- a function that will be called
  38260. * each time the rendering is paused. To continue rendering call the
  38261. * function that is the first argument to the callback.
  38262. * @type {function}
  38263. */
  38264. this.onContinue = null;
  38265. }
  38266. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  38267. /**
  38268. * Promise for rendering task completion.
  38269. * @return {Promise}
  38270. */
  38271. get promise() {
  38272. return this._internalRenderTask.capability.promise;
  38273. },
  38274. /**
  38275. * Cancels the rendering task. If the task is currently rendering it will
  38276. * not be cancelled until graphics pauses with a timeout. The promise that
  38277. * this object extends will resolved when cancelled.
  38278. */
  38279. cancel: function RenderTask_cancel() {
  38280. this._internalRenderTask.cancel();
  38281. },
  38282. /**
  38283. * Registers callbacks to indicate the rendering task completion.
  38284. *
  38285. * @param {function} onFulfilled The callback for the rendering completion.
  38286. * @param {function} onRejected The callback for the rendering failure.
  38287. * @return {Promise} A promise that is resolved after the onFulfilled or
  38288. * onRejected callback.
  38289. */
  38290. then: function RenderTask_then(onFulfilled, onRejected) {
  38291. return this.promise.then.apply(this.promise, arguments);
  38292. }
  38293. };
  38294. return RenderTask;
  38295. })();
  38296. /**
  38297. * For internal use only.
  38298. * @ignore
  38299. */
  38300. var InternalRenderTask = (function InternalRenderTaskClosure() {
  38301. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  38302. pageNumber) {
  38303. this.callback = callback;
  38304. this.params = params;
  38305. this.objs = objs;
  38306. this.commonObjs = commonObjs;
  38307. this.operatorListIdx = null;
  38308. this.operatorList = operatorList;
  38309. this.pageNumber = pageNumber;
  38310. this.running = false;
  38311. this.graphicsReadyCallback = null;
  38312. this.graphicsReady = false;
  38313. this.useRequestAnimationFrame = false;
  38314. this.cancelled = false;
  38315. this.capability = createPromiseCapability();
  38316. this.task = new RenderTask(this);
  38317. // caching this-bound methods
  38318. this._continueBound = this._continue.bind(this);
  38319. this._scheduleNextBound = this._scheduleNext.bind(this);
  38320. this._nextBound = this._next.bind(this);
  38321. }
  38322. InternalRenderTask.prototype = {
  38323. initializeGraphics:
  38324. function InternalRenderTask_initializeGraphics(transparency) {
  38325. if (this.cancelled) {
  38326. return;
  38327. }
  38328. if (getDefaultSetting('pdfBug') && globalScope.StepperManager &&
  38329. globalScope.StepperManager.enabled) {
  38330. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  38331. this.stepper.init(this.operatorList);
  38332. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  38333. }
  38334. var params = this.params;
  38335. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  38336. this.objs, params.imageLayer);
  38337. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  38338. this.operatorListIdx = 0;
  38339. this.graphicsReady = true;
  38340. if (this.graphicsReadyCallback) {
  38341. this.graphicsReadyCallback();
  38342. }
  38343. },
  38344. cancel: function InternalRenderTask_cancel() {
  38345. this.running = false;
  38346. this.cancelled = true;
  38347. this.callback('cancelled');
  38348. },
  38349. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  38350. if (!this.graphicsReady) {
  38351. if (!this.graphicsReadyCallback) {
  38352. this.graphicsReadyCallback = this._continueBound;
  38353. }
  38354. return;
  38355. }
  38356. if (this.stepper) {
  38357. this.stepper.updateOperatorList(this.operatorList);
  38358. }
  38359. if (this.running) {
  38360. return;
  38361. }
  38362. this._continue();
  38363. },
  38364. _continue: function InternalRenderTask__continue() {
  38365. this.running = true;
  38366. if (this.cancelled) {
  38367. return;
  38368. }
  38369. if (this.task.onContinue) {
  38370. this.task.onContinue.call(this.task, this._scheduleNextBound);
  38371. } else {
  38372. this._scheduleNext();
  38373. }
  38374. },
  38375. _scheduleNext: function InternalRenderTask__scheduleNext() {
  38376. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  38377. window.requestAnimationFrame(this._nextBound);
  38378. } else {
  38379. Promise.resolve(undefined).then(this._nextBound);
  38380. }
  38381. },
  38382. _next: function InternalRenderTask__next() {
  38383. if (this.cancelled) {
  38384. return;
  38385. }
  38386. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  38387. this.operatorListIdx,
  38388. this._continueBound,
  38389. this.stepper);
  38390. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  38391. this.running = false;
  38392. if (this.operatorList.lastChunk) {
  38393. this.gfx.endDrawing();
  38394. this.callback();
  38395. }
  38396. }
  38397. }
  38398. };
  38399. return InternalRenderTask;
  38400. })();
  38401. /**
  38402. * (Deprecated) Global observer of unsupported feature usages. Use
  38403. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  38404. */
  38405. var _UnsupportedManager = (function UnsupportedManagerClosure() {
  38406. var listeners = [];
  38407. return {
  38408. listen: function (cb) {
  38409. deprecated('Global UnsupportedManager.listen is used: ' +
  38410. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  38411. listeners.push(cb);
  38412. },
  38413. notify: function (featureId) {
  38414. for (var i = 0, ii = listeners.length; i < ii; i++) {
  38415. listeners[i](featureId);
  38416. }
  38417. }
  38418. };
  38419. })();
  38420. if (typeof pdfjsVersion !== 'undefined') {
  38421. exports.version = pdfjsVersion;
  38422. }
  38423. if (typeof pdfjsBuild !== 'undefined') {
  38424. exports.build = pdfjsBuild;
  38425. }
  38426. exports.getDocument = getDocument;
  38427. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  38428. exports.PDFWorker = PDFWorker;
  38429. exports.PDFDocumentProxy = PDFDocumentProxy;
  38430. exports.PDFPageProxy = PDFPageProxy;
  38431. exports._UnsupportedManager = _UnsupportedManager;
  38432. }));
  38433. (function (root, factory) {
  38434. {
  38435. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  38436. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  38437. }
  38438. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  38439. var error = sharedUtil.error;
  38440. var info = sharedUtil.info;
  38441. var isArray = sharedUtil.isArray;
  38442. var isString = sharedUtil.isString;
  38443. var shadow = sharedUtil.shadow;
  38444. var warn = sharedUtil.warn;
  38445. var isDict = corePrimitives.isDict;
  38446. var isName = corePrimitives.isName;
  38447. var isStream = corePrimitives.isStream;
  38448. var PDFFunction = coreFunction.PDFFunction;
  38449. var ColorSpace = (function ColorSpaceClosure() {
  38450. /**
  38451. * Resizes an RGB image with 3 components.
  38452. * @param {TypedArray} src - The source buffer.
  38453. * @param {Number} bpc - Number of bits per component.
  38454. * @param {Number} w1 - Original width.
  38455. * @param {Number} h1 - Original height.
  38456. * @param {Number} w2 - New width.
  38457. * @param {Number} h2 - New height.
  38458. * @param {Number} alpha01 - Size reserved for the alpha channel.
  38459. * @param {TypedArray} dest - The destination buffer.
  38460. */
  38461. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  38462. var COMPONENTS = 3;
  38463. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  38464. var xRatio = w1 / w2;
  38465. var yRatio = h1 / h2;
  38466. var i, j, py, newIndex = 0, oldIndex;
  38467. var xScaled = new Uint16Array(w2);
  38468. var w1Scanline = w1 * COMPONENTS;
  38469. for (i = 0; i < w2; i++) {
  38470. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  38471. }
  38472. for (i = 0; i < h2; i++) {
  38473. py = Math.floor(i * yRatio) * w1Scanline;
  38474. for (j = 0; j < w2; j++) {
  38475. oldIndex = py + xScaled[j];
  38476. dest[newIndex++] = src[oldIndex++];
  38477. dest[newIndex++] = src[oldIndex++];
  38478. dest[newIndex++] = src[oldIndex++];
  38479. newIndex += alpha01;
  38480. }
  38481. }
  38482. }
  38483. // Constructor should define this.numComps, this.defaultColor, this.name
  38484. function ColorSpace() {
  38485. error('should not call ColorSpace constructor');
  38486. }
  38487. ColorSpace.prototype = {
  38488. /**
  38489. * Converts the color value to the RGB color. The color components are
  38490. * located in the src array starting from the srcOffset. Returns the array
  38491. * of the rgb components, each value ranging from [0,255].
  38492. */
  38493. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  38494. var rgb = new Uint8Array(3);
  38495. this.getRgbItem(src, srcOffset, rgb, 0);
  38496. return rgb;
  38497. },
  38498. /**
  38499. * Converts the color value to the RGB color, similar to the getRgb method.
  38500. * The result placed into the dest array starting from the destOffset.
  38501. */
  38502. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  38503. dest, destOffset) {
  38504. error('Should not call ColorSpace.getRgbItem');
  38505. },
  38506. /**
  38507. * Converts the specified number of the color values to the RGB colors.
  38508. * The colors are located in the src array starting from the srcOffset.
  38509. * The result is placed into the dest array starting from the destOffset.
  38510. * The src array items shall be in [0,2^bits) range, the dest array items
  38511. * will be in [0,255] range. alpha01 indicates how many alpha components
  38512. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  38513. * array).
  38514. */
  38515. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  38516. dest, destOffset, bits,
  38517. alpha01) {
  38518. error('Should not call ColorSpace.getRgbBuffer');
  38519. },
  38520. /**
  38521. * Determines the number of bytes required to store the result of the
  38522. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  38523. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  38524. */
  38525. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  38526. alpha01) {
  38527. error('Should not call ColorSpace.getOutputLength');
  38528. },
  38529. /**
  38530. * Returns true if source data will be equal the result/output data.
  38531. */
  38532. isPassthrough: function ColorSpace_isPassthrough(bits) {
  38533. return false;
  38534. },
  38535. /**
  38536. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  38537. * how many alpha components there are in the dest array; it will be either
  38538. * 0 (RGB array) or 1 (RGBA array).
  38539. */
  38540. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  38541. originalHeight, width, height,
  38542. actualHeight, bpc, comps, alpha01) {
  38543. var count = originalWidth * originalHeight;
  38544. var rgbBuf = null;
  38545. var numComponentColors = 1 << bpc;
  38546. var needsResizing = originalHeight !== height || originalWidth !== width;
  38547. var i, ii;
  38548. if (this.isPassthrough(bpc)) {
  38549. rgbBuf = comps;
  38550. } else if (this.numComps === 1 && count > numComponentColors &&
  38551. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  38552. // Optimization: create a color map when there is just one component and
  38553. // we are converting more colors than the size of the color map. We
  38554. // don't build the map if the colorspace is gray or rgb since those
  38555. // methods are faster than building a map. This mainly offers big speed
  38556. // ups for indexed and alternate colorspaces.
  38557. //
  38558. // TODO it may be worth while to cache the color map. While running
  38559. // testing I never hit a cache so I will leave that out for now (perhaps
  38560. // we are reparsing colorspaces too much?).
  38561. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  38562. new Uint16Array(numComponentColors);
  38563. var key;
  38564. for (i = 0; i < numComponentColors; i++) {
  38565. allColors[i] = i;
  38566. }
  38567. var colorMap = new Uint8Array(numComponentColors * 3);
  38568. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  38569. /* alpha01 = */ 0);
  38570. var destPos, rgbPos;
  38571. if (!needsResizing) {
  38572. // Fill in the RGB values directly into |dest|.
  38573. destPos = 0;
  38574. for (i = 0; i < count; ++i) {
  38575. key = comps[i] * 3;
  38576. dest[destPos++] = colorMap[key];
  38577. dest[destPos++] = colorMap[key + 1];
  38578. dest[destPos++] = colorMap[key + 2];
  38579. destPos += alpha01;
  38580. }
  38581. } else {
  38582. rgbBuf = new Uint8Array(count * 3);
  38583. rgbPos = 0;
  38584. for (i = 0; i < count; ++i) {
  38585. key = comps[i] * 3;
  38586. rgbBuf[rgbPos++] = colorMap[key];
  38587. rgbBuf[rgbPos++] = colorMap[key + 1];
  38588. rgbBuf[rgbPos++] = colorMap[key + 2];
  38589. }
  38590. }
  38591. } else {
  38592. if (!needsResizing) {
  38593. // Fill in the RGB values directly into |dest|.
  38594. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  38595. alpha01);
  38596. } else {
  38597. rgbBuf = new Uint8Array(count * 3);
  38598. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  38599. /* alpha01 = */ 0);
  38600. }
  38601. }
  38602. if (rgbBuf) {
  38603. if (needsResizing) {
  38604. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight,
  38605. width, height, alpha01, dest);
  38606. } else {
  38607. rgbPos = 0;
  38608. destPos = 0;
  38609. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  38610. dest[destPos++] = rgbBuf[rgbPos++];
  38611. dest[destPos++] = rgbBuf[rgbPos++];
  38612. dest[destPos++] = rgbBuf[rgbPos++];
  38613. destPos += alpha01;
  38614. }
  38615. }
  38616. }
  38617. },
  38618. /**
  38619. * True if the colorspace has components in the default range of [0, 1].
  38620. * This should be true for all colorspaces except for lab color spaces
  38621. * which are [0,100], [-128, 127], [-128, 127].
  38622. */
  38623. usesZeroToOneRange: true
  38624. };
  38625. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  38626. var IR = ColorSpace.parseToIR(cs, xref, res);
  38627. if (IR instanceof AlternateCS) {
  38628. return IR;
  38629. }
  38630. return ColorSpace.fromIR(IR);
  38631. };
  38632. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  38633. var name = isArray(IR) ? IR[0] : IR;
  38634. var whitePoint, blackPoint, gamma;
  38635. switch (name) {
  38636. case 'DeviceGrayCS':
  38637. return this.singletons.gray;
  38638. case 'DeviceRgbCS':
  38639. return this.singletons.rgb;
  38640. case 'DeviceCmykCS':
  38641. return this.singletons.cmyk;
  38642. case 'CalGrayCS':
  38643. whitePoint = IR[1];
  38644. blackPoint = IR[2];
  38645. gamma = IR[3];
  38646. return new CalGrayCS(whitePoint, blackPoint, gamma);
  38647. case 'CalRGBCS':
  38648. whitePoint = IR[1];
  38649. blackPoint = IR[2];
  38650. gamma = IR[3];
  38651. var matrix = IR[4];
  38652. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  38653. case 'PatternCS':
  38654. var basePatternCS = IR[1];
  38655. if (basePatternCS) {
  38656. basePatternCS = ColorSpace.fromIR(basePatternCS);
  38657. }
  38658. return new PatternCS(basePatternCS);
  38659. case 'IndexedCS':
  38660. var baseIndexedCS = IR[1];
  38661. var hiVal = IR[2];
  38662. var lookup = IR[3];
  38663. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  38664. case 'AlternateCS':
  38665. var numComps = IR[1];
  38666. var alt = IR[2];
  38667. var tintFnIR = IR[3];
  38668. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  38669. PDFFunction.fromIR(tintFnIR));
  38670. case 'LabCS':
  38671. whitePoint = IR[1];
  38672. blackPoint = IR[2];
  38673. var range = IR[3];
  38674. return new LabCS(whitePoint, blackPoint, range);
  38675. default:
  38676. error('Unknown name ' + name);
  38677. }
  38678. return null;
  38679. };
  38680. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38681. if (isName(cs)) {
  38682. var colorSpaces = res.get('ColorSpace');
  38683. if (isDict(colorSpaces)) {
  38684. var refcs = colorSpaces.get(cs.name);
  38685. if (refcs) {
  38686. cs = refcs;
  38687. }
  38688. }
  38689. }
  38690. cs = xref.fetchIfRef(cs);
  38691. var mode;
  38692. if (isName(cs)) {
  38693. mode = cs.name;
  38694. this.mode = mode;
  38695. switch (mode) {
  38696. case 'DeviceGray':
  38697. case 'G':
  38698. return 'DeviceGrayCS';
  38699. case 'DeviceRGB':
  38700. case 'RGB':
  38701. return 'DeviceRgbCS';
  38702. case 'DeviceCMYK':
  38703. case 'CMYK':
  38704. return 'DeviceCmykCS';
  38705. case 'Pattern':
  38706. return ['PatternCS', null];
  38707. default:
  38708. error('unrecognized colorspace ' + mode);
  38709. }
  38710. } else if (isArray(cs)) {
  38711. mode = xref.fetchIfRef(cs[0]).name;
  38712. this.mode = mode;
  38713. var numComps, params, alt, whitePoint, blackPoint, gamma;
  38714. switch (mode) {
  38715. case 'DeviceGray':
  38716. case 'G':
  38717. return 'DeviceGrayCS';
  38718. case 'DeviceRGB':
  38719. case 'RGB':
  38720. return 'DeviceRgbCS';
  38721. case 'DeviceCMYK':
  38722. case 'CMYK':
  38723. return 'DeviceCmykCS';
  38724. case 'CalGray':
  38725. params = xref.fetchIfRef(cs[1]);
  38726. whitePoint = params.getArray('WhitePoint');
  38727. blackPoint = params.getArray('BlackPoint');
  38728. gamma = params.get('Gamma');
  38729. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  38730. case 'CalRGB':
  38731. params = xref.fetchIfRef(cs[1]);
  38732. whitePoint = params.getArray('WhitePoint');
  38733. blackPoint = params.getArray('BlackPoint');
  38734. gamma = params.getArray('Gamma');
  38735. var matrix = params.getArray('Matrix');
  38736. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  38737. case 'ICCBased':
  38738. var stream = xref.fetchIfRef(cs[1]);
  38739. var dict = stream.dict;
  38740. numComps = dict.get('N');
  38741. alt = dict.get('Alternate');
  38742. if (alt) {
  38743. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38744. // Parse the /Alternate CS to ensure that the number of components
  38745. // are correct, and also (indirectly) that it is not a PatternCS.
  38746. var altCS = ColorSpace.fromIR(altIR);
  38747. if (altCS.numComps === numComps) {
  38748. return altIR;
  38749. }
  38750. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38751. }
  38752. if (numComps === 1) {
  38753. return 'DeviceGrayCS';
  38754. } else if (numComps === 3) {
  38755. return 'DeviceRgbCS';
  38756. } else if (numComps === 4) {
  38757. return 'DeviceCmykCS';
  38758. }
  38759. break;
  38760. case 'Pattern':
  38761. var basePatternCS = cs[1] || null;
  38762. if (basePatternCS) {
  38763. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38764. }
  38765. return ['PatternCS', basePatternCS];
  38766. case 'Indexed':
  38767. case 'I':
  38768. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38769. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38770. var lookup = xref.fetchIfRef(cs[3]);
  38771. if (isStream(lookup)) {
  38772. lookup = lookup.getBytes();
  38773. }
  38774. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38775. case 'Separation':
  38776. case 'DeviceN':
  38777. var name = xref.fetchIfRef(cs[1]);
  38778. numComps = 1;
  38779. if (isName(name)) {
  38780. numComps = 1;
  38781. } else if (isArray(name)) {
  38782. numComps = name.length;
  38783. }
  38784. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38785. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38786. return ['AlternateCS', numComps, alt, tintFnIR];
  38787. case 'Lab':
  38788. params = xref.fetchIfRef(cs[1]);
  38789. whitePoint = params.getArray('WhitePoint');
  38790. blackPoint = params.getArray('BlackPoint');
  38791. var range = params.getArray('Range');
  38792. return ['LabCS', whitePoint, blackPoint, range];
  38793. default:
  38794. error('unimplemented color space object "' + mode + '"');
  38795. }
  38796. } else {
  38797. error('unrecognized color space object: "' + cs + '"');
  38798. }
  38799. return null;
  38800. };
  38801. /**
  38802. * Checks if a decode map matches the default decode map for a color space.
  38803. * This handles the general decode maps where there are two values per
  38804. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38805. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38806. * slightly different.
  38807. * @param {Array} decode Decode map (usually from an image).
  38808. * @param {Number} n Number of components the color space has.
  38809. */
  38810. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38811. if (!isArray(decode)) {
  38812. return true;
  38813. }
  38814. if (n * 2 !== decode.length) {
  38815. warn('The decode map is not the correct length');
  38816. return true;
  38817. }
  38818. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38819. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38820. return false;
  38821. }
  38822. }
  38823. return true;
  38824. };
  38825. ColorSpace.singletons = {
  38826. get gray() {
  38827. return shadow(this, 'gray', new DeviceGrayCS());
  38828. },
  38829. get rgb() {
  38830. return shadow(this, 'rgb', new DeviceRgbCS());
  38831. },
  38832. get cmyk() {
  38833. return shadow(this, 'cmyk', new DeviceCmykCS());
  38834. }
  38835. };
  38836. return ColorSpace;
  38837. })();
  38838. /**
  38839. * Alternate color space handles both Separation and DeviceN color spaces. A
  38840. * Separation color space is actually just a DeviceN with one color component.
  38841. * Both color spaces use a tinting function to convert colors to a base color
  38842. * space.
  38843. */
  38844. var AlternateCS = (function AlternateCSClosure() {
  38845. function AlternateCS(numComps, base, tintFn) {
  38846. this.name = 'Alternate';
  38847. this.numComps = numComps;
  38848. this.defaultColor = new Float32Array(numComps);
  38849. for (var i = 0; i < numComps; ++i) {
  38850. this.defaultColor[i] = 1;
  38851. }
  38852. this.base = base;
  38853. this.tintFn = tintFn;
  38854. this.tmpBuf = new Float32Array(base.numComps);
  38855. }
  38856. AlternateCS.prototype = {
  38857. getRgb: ColorSpace.prototype.getRgb,
  38858. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38859. dest, destOffset) {
  38860. var tmpBuf = this.tmpBuf;
  38861. this.tintFn(src, srcOffset, tmpBuf, 0);
  38862. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38863. },
  38864. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38865. dest, destOffset, bits,
  38866. alpha01) {
  38867. var tintFn = this.tintFn;
  38868. var base = this.base;
  38869. var scale = 1 / ((1 << bits) - 1);
  38870. var baseNumComps = base.numComps;
  38871. var usesZeroToOneRange = base.usesZeroToOneRange;
  38872. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38873. alpha01 === 0;
  38874. var pos = isPassthrough ? destOffset : 0;
  38875. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38876. var numComps = this.numComps;
  38877. var scaled = new Float32Array(numComps);
  38878. var tinted = new Float32Array(baseNumComps);
  38879. var i, j;
  38880. if (usesZeroToOneRange) {
  38881. for (i = 0; i < count; i++) {
  38882. for (j = 0; j < numComps; j++) {
  38883. scaled[j] = src[srcOffset++] * scale;
  38884. }
  38885. tintFn(scaled, 0, tinted, 0);
  38886. for (j = 0; j < baseNumComps; j++) {
  38887. baseBuf[pos++] = tinted[j] * 255;
  38888. }
  38889. }
  38890. } else {
  38891. for (i = 0; i < count; i++) {
  38892. for (j = 0; j < numComps; j++) {
  38893. scaled[j] = src[srcOffset++] * scale;
  38894. }
  38895. tintFn(scaled, 0, tinted, 0);
  38896. base.getRgbItem(tinted, 0, baseBuf, pos);
  38897. pos += baseNumComps;
  38898. }
  38899. }
  38900. if (!isPassthrough) {
  38901. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38902. }
  38903. },
  38904. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38905. alpha01) {
  38906. return this.base.getOutputLength(inputLength *
  38907. this.base.numComps / this.numComps,
  38908. alpha01);
  38909. },
  38910. isPassthrough: ColorSpace.prototype.isPassthrough,
  38911. fillRgb: ColorSpace.prototype.fillRgb,
  38912. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38913. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38914. },
  38915. usesZeroToOneRange: true
  38916. };
  38917. return AlternateCS;
  38918. })();
  38919. var PatternCS = (function PatternCSClosure() {
  38920. function PatternCS(baseCS) {
  38921. this.name = 'Pattern';
  38922. this.base = baseCS;
  38923. }
  38924. PatternCS.prototype = {};
  38925. return PatternCS;
  38926. })();
  38927. var IndexedCS = (function IndexedCSClosure() {
  38928. function IndexedCS(base, highVal, lookup) {
  38929. this.name = 'Indexed';
  38930. this.numComps = 1;
  38931. this.defaultColor = new Uint8Array([0]);
  38932. this.base = base;
  38933. this.highVal = highVal;
  38934. var baseNumComps = base.numComps;
  38935. var length = baseNumComps * highVal;
  38936. var lookupArray;
  38937. if (isStream(lookup)) {
  38938. lookupArray = new Uint8Array(length);
  38939. var bytes = lookup.getBytes(length);
  38940. lookupArray.set(bytes);
  38941. } else if (isString(lookup)) {
  38942. lookupArray = new Uint8Array(length);
  38943. for (var i = 0; i < length; ++i) {
  38944. lookupArray[i] = lookup.charCodeAt(i);
  38945. }
  38946. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38947. lookupArray = lookup;
  38948. } else {
  38949. error('Unrecognized lookup table: ' + lookup);
  38950. }
  38951. this.lookup = lookupArray;
  38952. }
  38953. IndexedCS.prototype = {
  38954. getRgb: ColorSpace.prototype.getRgb,
  38955. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38956. dest, destOffset) {
  38957. var numComps = this.base.numComps;
  38958. var start = src[srcOffset] * numComps;
  38959. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38960. },
  38961. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38962. dest, destOffset, bits,
  38963. alpha01) {
  38964. var base = this.base;
  38965. var numComps = base.numComps;
  38966. var outputDelta = base.getOutputLength(numComps, alpha01);
  38967. var lookup = this.lookup;
  38968. for (var i = 0; i < count; ++i) {
  38969. var lookupPos = src[srcOffset++] * numComps;
  38970. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38971. destOffset += outputDelta;
  38972. }
  38973. },
  38974. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38975. return this.base.getOutputLength(inputLength * this.base.numComps,
  38976. alpha01);
  38977. },
  38978. isPassthrough: ColorSpace.prototype.isPassthrough,
  38979. fillRgb: ColorSpace.prototype.fillRgb,
  38980. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38981. // indexed color maps shouldn't be changed
  38982. return true;
  38983. },
  38984. usesZeroToOneRange: true
  38985. };
  38986. return IndexedCS;
  38987. })();
  38988. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38989. function DeviceGrayCS() {
  38990. this.name = 'DeviceGray';
  38991. this.numComps = 1;
  38992. this.defaultColor = new Float32Array([0]);
  38993. }
  38994. DeviceGrayCS.prototype = {
  38995. getRgb: ColorSpace.prototype.getRgb,
  38996. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38997. dest, destOffset) {
  38998. var c = (src[srcOffset] * 255) | 0;
  38999. c = c < 0 ? 0 : c > 255 ? 255 : c;
  39000. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  39001. },
  39002. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  39003. dest, destOffset, bits,
  39004. alpha01) {
  39005. var scale = 255 / ((1 << bits) - 1);
  39006. var j = srcOffset, q = destOffset;
  39007. for (var i = 0; i < count; ++i) {
  39008. var c = (scale * src[j++]) | 0;
  39009. dest[q++] = c;
  39010. dest[q++] = c;
  39011. dest[q++] = c;
  39012. q += alpha01;
  39013. }
  39014. },
  39015. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  39016. alpha01) {
  39017. return inputLength * (3 + alpha01);
  39018. },
  39019. isPassthrough: ColorSpace.prototype.isPassthrough,
  39020. fillRgb: ColorSpace.prototype.fillRgb,
  39021. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  39022. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39023. },
  39024. usesZeroToOneRange: true
  39025. };
  39026. return DeviceGrayCS;
  39027. })();
  39028. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  39029. function DeviceRgbCS() {
  39030. this.name = 'DeviceRGB';
  39031. this.numComps = 3;
  39032. this.defaultColor = new Float32Array([0, 0, 0]);
  39033. }
  39034. DeviceRgbCS.prototype = {
  39035. getRgb: ColorSpace.prototype.getRgb,
  39036. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  39037. dest, destOffset) {
  39038. var r = (src[srcOffset] * 255) | 0;
  39039. var g = (src[srcOffset + 1] * 255) | 0;
  39040. var b = (src[srcOffset + 2] * 255) | 0;
  39041. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  39042. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  39043. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  39044. },
  39045. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  39046. dest, destOffset, bits,
  39047. alpha01) {
  39048. if (bits === 8 && alpha01 === 0) {
  39049. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  39050. return;
  39051. }
  39052. var scale = 255 / ((1 << bits) - 1);
  39053. var j = srcOffset, q = destOffset;
  39054. for (var i = 0; i < count; ++i) {
  39055. dest[q++] = (scale * src[j++]) | 0;
  39056. dest[q++] = (scale * src[j++]) | 0;
  39057. dest[q++] = (scale * src[j++]) | 0;
  39058. q += alpha01;
  39059. }
  39060. },
  39061. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  39062. alpha01) {
  39063. return (inputLength * (3 + alpha01) / 3) | 0;
  39064. },
  39065. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  39066. return bits === 8;
  39067. },
  39068. fillRgb: ColorSpace.prototype.fillRgb,
  39069. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  39070. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39071. },
  39072. usesZeroToOneRange: true
  39073. };
  39074. return DeviceRgbCS;
  39075. })();
  39076. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  39077. // The coefficients below was found using numerical analysis: the method of
  39078. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  39079. // where color_value is the tabular value from the table of sampled RGB colors
  39080. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  39081. // CMYK color conversion using the estimation below:
  39082. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  39083. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  39084. var c = src[srcOffset + 0] * srcScale;
  39085. var m = src[srcOffset + 1] * srcScale;
  39086. var y = src[srcOffset + 2] * srcScale;
  39087. var k = src[srcOffset + 3] * srcScale;
  39088. var r =
  39089. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  39090. 18.82290502165302 * y + 212.25662451639585 * k +
  39091. -285.2331026137004) +
  39092. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  39093. -17.873870861415444 * k - 5.497006427196366) +
  39094. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  39095. 17.5119270841813) +
  39096. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  39097. var g =
  39098. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  39099. 6.871425592049007 * y + 31.159100130055922 * k +
  39100. -79.2970844816548) +
  39101. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  39102. 131.35250912493976 * k - 190.9453302588951) +
  39103. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  39104. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  39105. var b =
  39106. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  39107. 30.89978309703729 * y - 0.23883238689178934 * k +
  39108. -14.183576799673286) +
  39109. m * (10.49593273432072 * m + 63.02378494754052 * y +
  39110. 50.606957656360734 * k - 112.23884253719248) +
  39111. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  39112. -193.58209356861505) +
  39113. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  39114. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  39115. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  39116. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  39117. }
  39118. function DeviceCmykCS() {
  39119. this.name = 'DeviceCMYK';
  39120. this.numComps = 4;
  39121. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  39122. }
  39123. DeviceCmykCS.prototype = {
  39124. getRgb: ColorSpace.prototype.getRgb,
  39125. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  39126. dest, destOffset) {
  39127. convertToRgb(src, srcOffset, 1, dest, destOffset);
  39128. },
  39129. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  39130. dest, destOffset, bits,
  39131. alpha01) {
  39132. var scale = 1 / ((1 << bits) - 1);
  39133. for (var i = 0; i < count; i++) {
  39134. convertToRgb(src, srcOffset, scale, dest, destOffset);
  39135. srcOffset += 4;
  39136. destOffset += 3 + alpha01;
  39137. }
  39138. },
  39139. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  39140. alpha01) {
  39141. return (inputLength / 4 * (3 + alpha01)) | 0;
  39142. },
  39143. isPassthrough: ColorSpace.prototype.isPassthrough,
  39144. fillRgb: ColorSpace.prototype.fillRgb,
  39145. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  39146. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39147. },
  39148. usesZeroToOneRange: true
  39149. };
  39150. return DeviceCmykCS;
  39151. })();
  39152. //
  39153. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  39154. //
  39155. var CalGrayCS = (function CalGrayCSClosure() {
  39156. function CalGrayCS(whitePoint, blackPoint, gamma) {
  39157. this.name = 'CalGray';
  39158. this.numComps = 1;
  39159. this.defaultColor = new Float32Array([0]);
  39160. if (!whitePoint) {
  39161. error('WhitePoint missing - required for color space CalGray');
  39162. }
  39163. blackPoint = blackPoint || [0, 0, 0];
  39164. gamma = gamma || 1;
  39165. // Translate arguments to spec variables.
  39166. this.XW = whitePoint[0];
  39167. this.YW = whitePoint[1];
  39168. this.ZW = whitePoint[2];
  39169. this.XB = blackPoint[0];
  39170. this.YB = blackPoint[1];
  39171. this.ZB = blackPoint[2];
  39172. this.G = gamma;
  39173. // Validate variables as per spec.
  39174. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39175. error('Invalid WhitePoint components for ' + this.name +
  39176. ', no fallback available');
  39177. }
  39178. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39179. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  39180. this.XB = this.YB = this.ZB = 0;
  39181. }
  39182. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  39183. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  39184. ', ZB: ' + this.ZB + ', only default values are supported.');
  39185. }
  39186. if (this.G < 1) {
  39187. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  39188. ', falling back to default');
  39189. this.G = 1;
  39190. }
  39191. }
  39192. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39193. // A represents a gray component of a calibrated gray space.
  39194. // A <---> AG in the spec
  39195. var A = src[srcOffset] * scale;
  39196. var AG = Math.pow(A, cs.G);
  39197. // Computes L as per spec. ( = cs.YW * AG )
  39198. // Except if other than default BlackPoint values are used.
  39199. var L = cs.YW * AG;
  39200. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  39201. // Convert values to rgb range [0, 255].
  39202. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  39203. dest[destOffset] = val;
  39204. dest[destOffset + 1] = val;
  39205. dest[destOffset + 2] = val;
  39206. }
  39207. CalGrayCS.prototype = {
  39208. getRgb: ColorSpace.prototype.getRgb,
  39209. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  39210. dest, destOffset) {
  39211. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39212. },
  39213. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  39214. dest, destOffset, bits,
  39215. alpha01) {
  39216. var scale = 1 / ((1 << bits) - 1);
  39217. for (var i = 0; i < count; ++i) {
  39218. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39219. srcOffset += 1;
  39220. destOffset += 3 + alpha01;
  39221. }
  39222. },
  39223. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  39224. return inputLength * (3 + alpha01);
  39225. },
  39226. isPassthrough: ColorSpace.prototype.isPassthrough,
  39227. fillRgb: ColorSpace.prototype.fillRgb,
  39228. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  39229. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39230. },
  39231. usesZeroToOneRange: true
  39232. };
  39233. return CalGrayCS;
  39234. })();
  39235. //
  39236. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  39237. //
  39238. var CalRGBCS = (function CalRGBCSClosure() {
  39239. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  39240. // matrices.
  39241. var BRADFORD_SCALE_MATRIX = new Float32Array([
  39242. 0.8951, 0.2664, -0.1614,
  39243. -0.7502, 1.7135, 0.0367,
  39244. 0.0389, -0.0685, 1.0296]);
  39245. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  39246. 0.9869929, -0.1470543, 0.1599627,
  39247. 0.4323053, 0.5183603, 0.0492912,
  39248. -0.0085287, 0.0400428, 0.9684867]);
  39249. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  39250. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  39251. 3.2404542, -1.5371385, -0.4985314,
  39252. -0.9692660, 1.8760108, 0.0415560,
  39253. 0.0556434, -0.2040259, 1.0572252]);
  39254. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  39255. var tempNormalizeMatrix = new Float32Array(3);
  39256. var tempConvertMatrix1 = new Float32Array(3);
  39257. var tempConvertMatrix2 = new Float32Array(3);
  39258. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  39259. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  39260. this.name = 'CalRGB';
  39261. this.numComps = 3;
  39262. this.defaultColor = new Float32Array(3);
  39263. if (!whitePoint) {
  39264. error('WhitePoint missing - required for color space CalRGB');
  39265. }
  39266. blackPoint = blackPoint || new Float32Array(3);
  39267. gamma = gamma || new Float32Array([1, 1, 1]);
  39268. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  39269. // Translate arguments to spec variables.
  39270. var XW = whitePoint[0];
  39271. var YW = whitePoint[1];
  39272. var ZW = whitePoint[2];
  39273. this.whitePoint = whitePoint;
  39274. var XB = blackPoint[0];
  39275. var YB = blackPoint[1];
  39276. var ZB = blackPoint[2];
  39277. this.blackPoint = blackPoint;
  39278. this.GR = gamma[0];
  39279. this.GG = gamma[1];
  39280. this.GB = gamma[2];
  39281. this.MXA = matrix[0];
  39282. this.MYA = matrix[1];
  39283. this.MZA = matrix[2];
  39284. this.MXB = matrix[3];
  39285. this.MYB = matrix[4];
  39286. this.MZB = matrix[5];
  39287. this.MXC = matrix[6];
  39288. this.MYC = matrix[7];
  39289. this.MZC = matrix[8];
  39290. // Validate variables as per spec.
  39291. if (XW < 0 || ZW < 0 || YW !== 1) {
  39292. error('Invalid WhitePoint components for ' + this.name +
  39293. ', no fallback available');
  39294. }
  39295. if (XB < 0 || YB < 0 || ZB < 0) {
  39296. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  39297. ', ' + ZB + '], falling back to default');
  39298. this.blackPoint = new Float32Array(3);
  39299. }
  39300. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  39301. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  39302. '] for ' + this.name + ', falling back to default');
  39303. this.GR = this.GG = this.GB = 1;
  39304. }
  39305. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  39306. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  39307. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  39308. info('Invalid Matrix for ' + this.name + ' [' +
  39309. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  39310. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  39311. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  39312. '], falling back to default');
  39313. this.MXA = this.MYB = this.MZC = 1;
  39314. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  39315. }
  39316. }
  39317. function matrixProduct(a, b, result) {
  39318. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  39319. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  39320. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  39321. }
  39322. function convertToFlat(sourceWhitePoint, LMS, result) {
  39323. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  39324. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  39325. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  39326. }
  39327. function convertToD65(sourceWhitePoint, LMS, result) {
  39328. var D65X = 0.95047;
  39329. var D65Y = 1;
  39330. var D65Z = 1.08883;
  39331. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  39332. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  39333. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  39334. }
  39335. function sRGBTransferFunction(color) {
  39336. // See http://en.wikipedia.org/wiki/SRGB.
  39337. if (color <= 0.0031308){
  39338. return adjustToRange(0, 1, 12.92 * color);
  39339. }
  39340. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  39341. }
  39342. function adjustToRange(min, max, value) {
  39343. return Math.max(min, Math.min(max, value));
  39344. }
  39345. function decodeL(L) {
  39346. if (L < 0) {
  39347. return -decodeL(-L);
  39348. }
  39349. if (L > 8.0) {
  39350. return Math.pow(((L + 16) / 116), 3);
  39351. }
  39352. return L * DECODE_L_CONSTANT;
  39353. }
  39354. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  39355. // In case the blackPoint is already the default blackPoint then there is
  39356. // no need to do compensation.
  39357. if (sourceBlackPoint[0] === 0 &&
  39358. sourceBlackPoint[1] === 0 &&
  39359. sourceBlackPoint[2] === 0) {
  39360. result[0] = XYZ_Flat[0];
  39361. result[1] = XYZ_Flat[1];
  39362. result[2] = XYZ_Flat[2];
  39363. return;
  39364. }
  39365. // For the blackPoint calculation details, please see
  39366. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39367. // AdobeBPC.pdf.
  39368. // The destination blackPoint is the default blackPoint [0, 0, 0].
  39369. var zeroDecodeL = decodeL(0);
  39370. var X_DST = zeroDecodeL;
  39371. var X_SRC = decodeL(sourceBlackPoint[0]);
  39372. var Y_DST = zeroDecodeL;
  39373. var Y_SRC = decodeL(sourceBlackPoint[1]);
  39374. var Z_DST = zeroDecodeL;
  39375. var Z_SRC = decodeL(sourceBlackPoint[2]);
  39376. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  39377. var X_Offset = 1 - X_Scale;
  39378. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  39379. var Y_Offset = 1 - Y_Scale;
  39380. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  39381. var Z_Offset = 1 - Z_Scale;
  39382. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  39383. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  39384. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  39385. }
  39386. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  39387. // In case the whitePoint is already flat then there is no need to do
  39388. // normalization.
  39389. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  39390. result[0] = XYZ_In[0];
  39391. result[1] = XYZ_In[1];
  39392. result[2] = XYZ_In[2];
  39393. return;
  39394. }
  39395. var LMS = result;
  39396. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39397. var LMS_Flat = tempNormalizeMatrix;
  39398. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  39399. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  39400. }
  39401. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  39402. var LMS = result;
  39403. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39404. var LMS_D65 = tempNormalizeMatrix;
  39405. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  39406. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  39407. }
  39408. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39409. // A, B and C represent a red, green and blue components of a calibrated
  39410. // rgb space.
  39411. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  39412. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  39413. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  39414. // A <---> AGR in the spec
  39415. // B <---> BGG in the spec
  39416. // C <---> CGB in the spec
  39417. var AGR = Math.pow(A, cs.GR);
  39418. var BGG = Math.pow(B, cs.GG);
  39419. var CGB = Math.pow(C, cs.GB);
  39420. // Computes intermediate variables L, M, N as per spec.
  39421. // To decode X, Y, Z values map L, M, N directly to them.
  39422. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  39423. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  39424. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  39425. // The following calculations are based on this document:
  39426. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39427. // AdobeBPC.pdf.
  39428. var XYZ = tempConvertMatrix1;
  39429. XYZ[0] = X;
  39430. XYZ[1] = Y;
  39431. XYZ[2] = Z;
  39432. var XYZ_Flat = tempConvertMatrix2;
  39433. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  39434. var XYZ_Black = tempConvertMatrix1;
  39435. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  39436. var XYZ_D65 = tempConvertMatrix2;
  39437. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  39438. var SRGB = tempConvertMatrix1;
  39439. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  39440. var sR = sRGBTransferFunction(SRGB[0]);
  39441. var sG = sRGBTransferFunction(SRGB[1]);
  39442. var sB = sRGBTransferFunction(SRGB[2]);
  39443. // Convert the values to rgb range [0, 255].
  39444. dest[destOffset] = Math.round(sR * 255);
  39445. dest[destOffset + 1] = Math.round(sG * 255);
  39446. dest[destOffset + 2] = Math.round(sB * 255);
  39447. }
  39448. CalRGBCS.prototype = {
  39449. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  39450. var rgb = new Uint8Array(3);
  39451. this.getRgbItem(src, srcOffset, rgb, 0);
  39452. return rgb;
  39453. },
  39454. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  39455. dest, destOffset) {
  39456. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39457. },
  39458. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  39459. dest, destOffset, bits,
  39460. alpha01) {
  39461. var scale = 1 / ((1 << bits) - 1);
  39462. for (var i = 0; i < count; ++i) {
  39463. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39464. srcOffset += 3;
  39465. destOffset += 3 + alpha01;
  39466. }
  39467. },
  39468. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  39469. return (inputLength * (3 + alpha01) / 3) | 0;
  39470. },
  39471. isPassthrough: ColorSpace.prototype.isPassthrough,
  39472. fillRgb: ColorSpace.prototype.fillRgb,
  39473. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  39474. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39475. },
  39476. usesZeroToOneRange: true
  39477. };
  39478. return CalRGBCS;
  39479. })();
  39480. //
  39481. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  39482. //
  39483. var LabCS = (function LabCSClosure() {
  39484. function LabCS(whitePoint, blackPoint, range) {
  39485. this.name = 'Lab';
  39486. this.numComps = 3;
  39487. this.defaultColor = new Float32Array([0, 0, 0]);
  39488. if (!whitePoint) {
  39489. error('WhitePoint missing - required for color space Lab');
  39490. }
  39491. blackPoint = blackPoint || [0, 0, 0];
  39492. range = range || [-100, 100, -100, 100];
  39493. // Translate args to spec variables
  39494. this.XW = whitePoint[0];
  39495. this.YW = whitePoint[1];
  39496. this.ZW = whitePoint[2];
  39497. this.amin = range[0];
  39498. this.amax = range[1];
  39499. this.bmin = range[2];
  39500. this.bmax = range[3];
  39501. // These are here just for completeness - the spec doesn't offer any
  39502. // formulas that use BlackPoint in Lab
  39503. this.XB = blackPoint[0];
  39504. this.YB = blackPoint[1];
  39505. this.ZB = blackPoint[2];
  39506. // Validate vars as per spec
  39507. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39508. error('Invalid WhitePoint components, no fallback available');
  39509. }
  39510. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39511. info('Invalid BlackPoint, falling back to default');
  39512. this.XB = this.YB = this.ZB = 0;
  39513. }
  39514. if (this.amin > this.amax || this.bmin > this.bmax) {
  39515. info('Invalid Range, falling back to defaults');
  39516. this.amin = -100;
  39517. this.amax = 100;
  39518. this.bmin = -100;
  39519. this.bmax = 100;
  39520. }
  39521. }
  39522. // Function g(x) from spec
  39523. function fn_g(x) {
  39524. if (x >= 6 / 29) {
  39525. return x * x * x;
  39526. } else {
  39527. return (108 / 841) * (x - 4 / 29);
  39528. }
  39529. }
  39530. function decode(value, high1, low2, high2) {
  39531. return low2 + (value) * (high2 - low2) / (high1);
  39532. }
  39533. // If decoding is needed maxVal should be 2^bits per component - 1.
  39534. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  39535. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  39536. // not the usual [0, 1]. If a command like setFillColor is used the src
  39537. // values will already be within the correct range. However, if we are
  39538. // converting an image we have to map the values to the correct range given
  39539. // above.
  39540. // Ls,as,bs <---> L*,a*,b* in the spec
  39541. var Ls = src[srcOffset];
  39542. var as = src[srcOffset + 1];
  39543. var bs = src[srcOffset + 2];
  39544. if (maxVal !== false) {
  39545. Ls = decode(Ls, maxVal, 0, 100);
  39546. as = decode(as, maxVal, cs.amin, cs.amax);
  39547. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  39548. }
  39549. // Adjust limits of 'as' and 'bs'
  39550. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  39551. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  39552. // Computes intermediate variables X,Y,Z as per spec
  39553. var M = (Ls + 16) / 116;
  39554. var L = M + (as / 500);
  39555. var N = M - (bs / 200);
  39556. var X = cs.XW * fn_g(L);
  39557. var Y = cs.YW * fn_g(M);
  39558. var Z = cs.ZW * fn_g(N);
  39559. var r, g, b;
  39560. // Using different conversions for D50 and D65 white points,
  39561. // per http://www.color.org/srgb.pdf
  39562. if (cs.ZW < 1) {
  39563. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  39564. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  39565. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  39566. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  39567. } else {
  39568. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  39569. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  39570. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  39571. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  39572. }
  39573. // clamp color values to [0,1] range then convert to [0,255] range.
  39574. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  39575. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  39576. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  39577. }
  39578. LabCS.prototype = {
  39579. getRgb: ColorSpace.prototype.getRgb,
  39580. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  39581. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  39582. },
  39583. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  39584. dest, destOffset, bits,
  39585. alpha01) {
  39586. var maxVal = (1 << bits) - 1;
  39587. for (var i = 0; i < count; i++) {
  39588. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  39589. srcOffset += 3;
  39590. destOffset += 3 + alpha01;
  39591. }
  39592. },
  39593. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  39594. return (inputLength * (3 + alpha01) / 3) | 0;
  39595. },
  39596. isPassthrough: ColorSpace.prototype.isPassthrough,
  39597. fillRgb: ColorSpace.prototype.fillRgb,
  39598. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  39599. // XXX: Decoding is handled with the lab conversion because of the strange
  39600. // ranges that are used.
  39601. return true;
  39602. },
  39603. usesZeroToOneRange: false
  39604. };
  39605. return LabCS;
  39606. })();
  39607. exports.ColorSpace = ColorSpace;
  39608. }));
  39609. (function (root, factory) {
  39610. {
  39611. factory((root.pdfjsDisplayGlobal = {}), root.pdfjsSharedUtil,
  39612. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayAPI,
  39613. root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer,
  39614. root.pdfjsDisplayMetadata, root.pdfjsDisplaySVG);
  39615. }
  39616. }(this, function (exports, sharedUtil, displayDOMUtils, displayAPI,
  39617. displayAnnotationLayer, displayTextLayer, displayMetadata,
  39618. displaySVG) {
  39619. var globalScope = sharedUtil.globalScope;
  39620. var deprecated = sharedUtil.deprecated;
  39621. var warn = sharedUtil.warn;
  39622. var LinkTarget = displayDOMUtils.LinkTarget;
  39623. var isWorker = (typeof window === 'undefined');
  39624. // The global PDFJS object is now deprecated and will not be supported in
  39625. // the future. The members below are maintained for backward compatibility
  39626. // and shall not be extended or modified. If the global.js is included as
  39627. // a module, we will create a global PDFJS object instance or use existing.
  39628. if (!globalScope.PDFJS) {
  39629. globalScope.PDFJS = {};
  39630. }
  39631. var PDFJS = globalScope.PDFJS;
  39632. if (typeof pdfjsVersion !== 'undefined') {
  39633. PDFJS.version = pdfjsVersion;
  39634. }
  39635. if (typeof pdfjsBuild !== 'undefined') {
  39636. PDFJS.build = pdfjsBuild;
  39637. }
  39638. PDFJS.pdfBug = false;
  39639. if (PDFJS.verbosity !== undefined) {
  39640. sharedUtil.setVerbosityLevel(PDFJS.verbosity);
  39641. }
  39642. delete PDFJS.verbosity;
  39643. Object.defineProperty(PDFJS, 'verbosity', {
  39644. get: function () { return sharedUtil.getVerbosityLevel(); },
  39645. set: function (level) { sharedUtil.setVerbosityLevel(level); },
  39646. enumerable: true,
  39647. configurable: true
  39648. });
  39649. PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
  39650. PDFJS.OPS = sharedUtil.OPS;
  39651. PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39652. PDFJS.isValidUrl = sharedUtil.isValidUrl;
  39653. PDFJS.shadow = sharedUtil.shadow;
  39654. PDFJS.createBlob = sharedUtil.createBlob;
  39655. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  39656. return sharedUtil.createObjectURL(data, contentType,
  39657. PDFJS.disableCreateObjectURL);
  39658. };
  39659. Object.defineProperty(PDFJS, 'isLittleEndian', {
  39660. configurable: true,
  39661. get: function PDFJS_isLittleEndian() {
  39662. var value = sharedUtil.isLittleEndian();
  39663. return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
  39664. }
  39665. });
  39666. PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
  39667. PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
  39668. PDFJS.PasswordException = sharedUtil.PasswordException;
  39669. PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
  39670. PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
  39671. PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
  39672. PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39673. PDFJS.Util = sharedUtil.Util;
  39674. PDFJS.PageViewport = sharedUtil.PageViewport;
  39675. PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
  39676. /**
  39677. * The maximum allowed image size in total pixels e.g. width * height. Images
  39678. * above this value will not be drawn. Use -1 for no limit.
  39679. * @var {number}
  39680. */
  39681. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  39682. -1 : PDFJS.maxImageSize);
  39683. /**
  39684. * The url of where the predefined Adobe CMaps are located. Include trailing
  39685. * slash.
  39686. * @var {string}
  39687. */
  39688. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  39689. /**
  39690. * Specifies if CMaps are binary packed.
  39691. * @var {boolean}
  39692. */
  39693. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  39694. /**
  39695. * By default fonts are converted to OpenType fonts and loaded via font face
  39696. * rules. If disabled, the font will be rendered using a built in font
  39697. * renderer that constructs the glyphs with primitive path commands.
  39698. * @var {boolean}
  39699. */
  39700. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  39701. false : PDFJS.disableFontFace);
  39702. /**
  39703. * Path for image resources, mainly for annotation icons. Include trailing
  39704. * slash.
  39705. * @var {string}
  39706. */
  39707. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  39708. '' : PDFJS.imageResourcesPath);
  39709. /**
  39710. * Disable the web worker and run all code on the main thread. This will
  39711. * happen automatically if the browser doesn't support workers or sending
  39712. * typed arrays to workers.
  39713. * @var {boolean}
  39714. */
  39715. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  39716. false : PDFJS.disableWorker);
  39717. /**
  39718. * Path and filename of the worker file. Required when the worker is enabled
  39719. * in development mode. If unspecified in the production build, the worker
  39720. * will be loaded based on the location of the pdf.js file. It is recommended
  39721. * that the workerSrc is set in a custom application to prevent issues caused
  39722. * by third-party frameworks and libraries.
  39723. * @var {string}
  39724. */
  39725. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  39726. /**
  39727. * Disable range request loading of PDF files. When enabled and if the server
  39728. * supports partial content requests then the PDF will be fetched in chunks.
  39729. * Enabled (false) by default.
  39730. * @var {boolean}
  39731. */
  39732. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  39733. false : PDFJS.disableRange);
  39734. /**
  39735. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  39736. * in chunks. This default behavior can be disabled.
  39737. * @var {boolean}
  39738. */
  39739. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  39740. false : PDFJS.disableStream);
  39741. /**
  39742. * Disable pre-fetching of PDF file data. When range requests are enabled
  39743. * PDF.js will automatically keep fetching more data even if it isn't needed
  39744. * to display the current page. This default behavior can be disabled.
  39745. *
  39746. * NOTE: It is also necessary to disable streaming, see above,
  39747. * in order for disabling of pre-fetching to work correctly.
  39748. * @var {boolean}
  39749. */
  39750. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  39751. false : PDFJS.disableAutoFetch);
  39752. /**
  39753. * Enables special hooks for debugging PDF.js.
  39754. * @var {boolean}
  39755. */
  39756. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  39757. /**
  39758. * Enables transfer usage in postMessage for ArrayBuffers.
  39759. * @var {boolean}
  39760. */
  39761. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  39762. true : PDFJS.postMessageTransfers);
  39763. /**
  39764. * Disables URL.createObjectURL usage.
  39765. * @var {boolean}
  39766. */
  39767. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  39768. false : PDFJS.disableCreateObjectURL);
  39769. /**
  39770. * Disables WebGL usage.
  39771. * @var {boolean}
  39772. */
  39773. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  39774. true : PDFJS.disableWebGL);
  39775. /**
  39776. * Specifies the |target| attribute for external links.
  39777. * The constants from PDFJS.LinkTarget should be used:
  39778. * - NONE [default]
  39779. * - SELF
  39780. * - BLANK
  39781. * - PARENT
  39782. * - TOP
  39783. * @var {number}
  39784. */
  39785. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  39786. LinkTarget.NONE : PDFJS.externalLinkTarget);
  39787. /**
  39788. * Specifies the |rel| attribute for external links. Defaults to stripping
  39789. * the referrer.
  39790. * @var {string}
  39791. */
  39792. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  39793. 'noreferrer' : PDFJS.externalLinkRel);
  39794. /**
  39795. * Determines if we can eval strings as JS. Primarily used to improve
  39796. * performance for font rendering.
  39797. * @var {boolean}
  39798. */
  39799. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  39800. true : PDFJS.isEvalSupported);
  39801. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  39802. delete PDFJS.openExternalLinksInNewWindow;
  39803. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  39804. get: function () {
  39805. return PDFJS.externalLinkTarget === LinkTarget.BLANK;
  39806. },
  39807. set: function (value) {
  39808. if (value) {
  39809. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  39810. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  39811. }
  39812. if (PDFJS.externalLinkTarget !== LinkTarget.NONE) {
  39813. warn('PDFJS.externalLinkTarget is already initialized');
  39814. return;
  39815. }
  39816. PDFJS.externalLinkTarget = value ? LinkTarget.BLANK : LinkTarget.NONE;
  39817. },
  39818. enumerable: true,
  39819. configurable: true
  39820. });
  39821. if (savedOpenExternalLinksInNewWindow) {
  39822. /**
  39823. * (Deprecated) Opens external links in a new window if enabled.
  39824. * The default behavior opens external links in the PDF.js window.
  39825. *
  39826. * NOTE: This property has been deprecated, please use
  39827. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  39828. * @var {boolean}
  39829. */
  39830. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  39831. }
  39832. PDFJS.getDocument = displayAPI.getDocument;
  39833. PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
  39834. PDFJS.PDFWorker = displayAPI.PDFWorker;
  39835. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  39836. configurable: true,
  39837. get: function PDFJS_hasCanvasTypedArrays() {
  39838. var value = displayDOMUtils.hasCanvasTypedArrays();
  39839. return sharedUtil.shadow(PDFJS, 'hasCanvasTypedArrays', value);
  39840. }
  39841. });
  39842. PDFJS.CustomStyle = displayDOMUtils.CustomStyle;
  39843. PDFJS.LinkTarget = LinkTarget;
  39844. PDFJS.addLinkAttributes = displayDOMUtils.addLinkAttributes;
  39845. PDFJS.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  39846. PDFJS.isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet;
  39847. PDFJS.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
  39848. PDFJS.renderTextLayer = displayTextLayer.renderTextLayer;
  39849. PDFJS.Metadata = displayMetadata.Metadata;
  39850. PDFJS.SVGGraphics = displaySVG.SVGGraphics;
  39851. PDFJS.UnsupportedManager = displayAPI._UnsupportedManager;
  39852. exports.globalScope = globalScope;
  39853. exports.isWorker = isWorker;
  39854. exports.PDFJS = globalScope.PDFJS;
  39855. }));
  39856. (function (root, factory) {
  39857. {
  39858. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  39859. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  39860. root.pdfjsCoreJpx);
  39861. }
  39862. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  39863. coreStream, coreJpx) {
  39864. var ImageKind = sharedUtil.ImageKind;
  39865. var assert = sharedUtil.assert;
  39866. var error = sharedUtil.error;
  39867. var info = sharedUtil.info;
  39868. var isArray = sharedUtil.isArray;
  39869. var warn = sharedUtil.warn;
  39870. var Name = corePrimitives.Name;
  39871. var isStream = corePrimitives.isStream;
  39872. var ColorSpace = coreColorSpace.ColorSpace;
  39873. var DecodeStream = coreStream.DecodeStream;
  39874. var JpegStream = coreStream.JpegStream;
  39875. var JpxImage = coreJpx.JpxImage;
  39876. var PDFImage = (function PDFImageClosure() {
  39877. /**
  39878. * Decodes the image using native decoder if possible. Resolves the promise
  39879. * when the image data is ready.
  39880. */
  39881. function handleImageData(image, nativeDecoder) {
  39882. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  39883. return nativeDecoder.decode(image);
  39884. } else {
  39885. return Promise.resolve(image);
  39886. }
  39887. }
  39888. /**
  39889. * Decode and clamp a value. The formula is different from the spec because we
  39890. * don't decode to float range [0,1], we decode it in the [0,max] range.
  39891. */
  39892. function decodeAndClamp(value, addend, coefficient, max) {
  39893. value = addend + value * coefficient;
  39894. // Clamp the value to the range
  39895. return (value < 0 ? 0 : (value > max ? max : value));
  39896. }
  39897. /**
  39898. * Resizes an image mask with 1 component.
  39899. * @param {TypedArray} src - The source buffer.
  39900. * @param {Number} bpc - Number of bits per component.
  39901. * @param {Number} w1 - Original width.
  39902. * @param {Number} h1 - Original height.
  39903. * @param {Number} w2 - New width.
  39904. * @param {Number} h2 - New height.
  39905. * @returns {TypedArray} The resized image mask buffer.
  39906. */
  39907. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  39908. var length = w2 * h2;
  39909. var dest = (bpc <= 8 ? new Uint8Array(length) :
  39910. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39911. var xRatio = w1 / w2;
  39912. var yRatio = h1 / h2;
  39913. var i, j, py, newIndex = 0, oldIndex;
  39914. var xScaled = new Uint16Array(w2);
  39915. var w1Scanline = w1;
  39916. for (i = 0; i < w2; i++) {
  39917. xScaled[i] = Math.floor(i * xRatio);
  39918. }
  39919. for (i = 0; i < h2; i++) {
  39920. py = Math.floor(i * yRatio) * w1Scanline;
  39921. for (j = 0; j < w2; j++) {
  39922. oldIndex = py + xScaled[j];
  39923. dest[newIndex++] = src[oldIndex];
  39924. }
  39925. }
  39926. return dest;
  39927. }
  39928. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  39929. this.image = image;
  39930. var dict = image.dict;
  39931. if (dict.has('Filter')) {
  39932. var filter = dict.get('Filter').name;
  39933. if (filter === 'JPXDecode') {
  39934. var jpxImage = new JpxImage();
  39935. jpxImage.parseImageProperties(image.stream);
  39936. image.stream.reset();
  39937. image.bitsPerComponent = jpxImage.bitsPerComponent;
  39938. image.numComps = jpxImage.componentsCount;
  39939. } else if (filter === 'JBIG2Decode') {
  39940. image.bitsPerComponent = 1;
  39941. image.numComps = 1;
  39942. }
  39943. }
  39944. // TODO cache rendered images?
  39945. this.width = dict.get('Width', 'W');
  39946. this.height = dict.get('Height', 'H');
  39947. if (this.width < 1 || this.height < 1) {
  39948. error('Invalid image width: ' + this.width + ' or height: ' +
  39949. this.height);
  39950. }
  39951. this.interpolate = dict.get('Interpolate', 'I') || false;
  39952. this.imageMask = dict.get('ImageMask', 'IM') || false;
  39953. this.matte = dict.get('Matte') || false;
  39954. var bitsPerComponent = image.bitsPerComponent;
  39955. if (!bitsPerComponent) {
  39956. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  39957. if (!bitsPerComponent) {
  39958. if (this.imageMask) {
  39959. bitsPerComponent = 1;
  39960. } else {
  39961. error('Bits per component missing in image: ' + this.imageMask);
  39962. }
  39963. }
  39964. }
  39965. this.bpc = bitsPerComponent;
  39966. if (!this.imageMask) {
  39967. var colorSpace = dict.get('ColorSpace', 'CS');
  39968. if (!colorSpace) {
  39969. info('JPX images (which do not require color spaces)');
  39970. switch (image.numComps) {
  39971. case 1:
  39972. colorSpace = Name.get('DeviceGray');
  39973. break;
  39974. case 3:
  39975. colorSpace = Name.get('DeviceRGB');
  39976. break;
  39977. case 4:
  39978. colorSpace = Name.get('DeviceCMYK');
  39979. break;
  39980. default:
  39981. error('JPX images with ' + this.numComps +
  39982. ' color components not supported.');
  39983. }
  39984. }
  39985. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39986. this.numComps = this.colorSpace.numComps;
  39987. }
  39988. this.decode = dict.getArray('Decode', 'D');
  39989. this.needsDecode = false;
  39990. if (this.decode &&
  39991. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39992. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39993. this.needsDecode = true;
  39994. // Do some preprocessing to avoid more math.
  39995. var max = (1 << bitsPerComponent) - 1;
  39996. this.decodeCoefficients = [];
  39997. this.decodeAddends = [];
  39998. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39999. var dmin = this.decode[i];
  40000. var dmax = this.decode[i + 1];
  40001. this.decodeCoefficients[j] = dmax - dmin;
  40002. this.decodeAddends[j] = max * dmin;
  40003. }
  40004. }
  40005. if (smask) {
  40006. this.smask = new PDFImage(xref, res, smask, false);
  40007. } else if (mask) {
  40008. if (isStream(mask)) {
  40009. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  40010. if (!imageMask) {
  40011. warn('Ignoring /Mask in image without /ImageMask.');
  40012. } else {
  40013. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  40014. }
  40015. } else {
  40016. // Color key mask (just an array).
  40017. this.mask = mask;
  40018. }
  40019. }
  40020. }
  40021. /**
  40022. * Handles processing of image data and returns the Promise that is resolved
  40023. * with a PDFImage when the image is ready to be used.
  40024. */
  40025. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  40026. res, image, inline,
  40027. nativeDecoder) {
  40028. var imagePromise = handleImageData(image, nativeDecoder);
  40029. var smaskPromise;
  40030. var maskPromise;
  40031. var smask = image.dict.get('SMask');
  40032. var mask = image.dict.get('Mask');
  40033. if (smask) {
  40034. smaskPromise = handleImageData(smask, nativeDecoder);
  40035. maskPromise = Promise.resolve(null);
  40036. } else {
  40037. smaskPromise = Promise.resolve(null);
  40038. if (mask) {
  40039. if (isStream(mask)) {
  40040. maskPromise = handleImageData(mask, nativeDecoder);
  40041. } else if (isArray(mask)) {
  40042. maskPromise = Promise.resolve(mask);
  40043. } else {
  40044. warn('Unsupported mask format.');
  40045. maskPromise = Promise.resolve(null);
  40046. }
  40047. } else {
  40048. maskPromise = Promise.resolve(null);
  40049. }
  40050. }
  40051. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  40052. function(results) {
  40053. var imageData = results[0];
  40054. var smaskData = results[1];
  40055. var maskData = results[2];
  40056. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  40057. });
  40058. };
  40059. PDFImage.createMask =
  40060. function PDFImage_createMask(imgArray, width, height,
  40061. imageIsFromDecodeStream, inverseDecode) {
  40062. // |imgArray| might not contain full data for every pixel of the mask, so
  40063. // we need to distinguish between |computedLength| and |actualLength|.
  40064. // In particular, if inverseDecode is true, then the array we return must
  40065. // have a length of |computedLength|.
  40066. var computedLength = ((width + 7) >> 3) * height;
  40067. var actualLength = imgArray.byteLength;
  40068. var haveFullData = computedLength === actualLength;
  40069. var data, i;
  40070. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  40071. // imgArray came from a DecodeStream and its data is in an appropriate
  40072. // form, so we can just transfer it.
  40073. data = imgArray;
  40074. } else if (!inverseDecode) {
  40075. data = new Uint8Array(actualLength);
  40076. data.set(imgArray);
  40077. } else {
  40078. data = new Uint8Array(computedLength);
  40079. data.set(imgArray);
  40080. for (i = actualLength; i < computedLength; i++) {
  40081. data[i] = 0xff;
  40082. }
  40083. }
  40084. // If necessary, invert the original mask data (but not any extra we might
  40085. // have added above). It's safe to modify the array -- whether it's the
  40086. // original or a copy, we're about to transfer it anyway, so nothing else
  40087. // in this thread can be relying on its contents.
  40088. if (inverseDecode) {
  40089. for (i = 0; i < actualLength; i++) {
  40090. data[i] = ~data[i];
  40091. }
  40092. }
  40093. return {data: data, width: width, height: height};
  40094. };
  40095. PDFImage.prototype = {
  40096. get drawWidth() {
  40097. return Math.max(this.width,
  40098. this.smask && this.smask.width || 0,
  40099. this.mask && this.mask.width || 0);
  40100. },
  40101. get drawHeight() {
  40102. return Math.max(this.height,
  40103. this.smask && this.smask.height || 0,
  40104. this.mask && this.mask.height || 0);
  40105. },
  40106. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  40107. var bpc = this.bpc;
  40108. var numComps = this.numComps;
  40109. var decodeAddends = this.decodeAddends;
  40110. var decodeCoefficients = this.decodeCoefficients;
  40111. var max = (1 << bpc) - 1;
  40112. var i, ii;
  40113. if (bpc === 1) {
  40114. // If the buffer needed decode that means it just needs to be inverted.
  40115. for (i = 0, ii = buffer.length; i < ii; i++) {
  40116. buffer[i] = +!(buffer[i]);
  40117. }
  40118. return;
  40119. }
  40120. var index = 0;
  40121. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  40122. for (var j = 0; j < numComps; j++) {
  40123. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  40124. decodeCoefficients[j], max);
  40125. index++;
  40126. }
  40127. }
  40128. },
  40129. getComponents: function PDFImage_getComponents(buffer) {
  40130. var bpc = this.bpc;
  40131. // This image doesn't require any extra work.
  40132. if (bpc === 8) {
  40133. return buffer;
  40134. }
  40135. var width = this.width;
  40136. var height = this.height;
  40137. var numComps = this.numComps;
  40138. var length = width * height * numComps;
  40139. var bufferPos = 0;
  40140. var output = (bpc <= 8 ? new Uint8Array(length) :
  40141. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  40142. var rowComps = width * numComps;
  40143. var max = (1 << bpc) - 1;
  40144. var i = 0, ii, buf;
  40145. if (bpc === 1) {
  40146. // Optimization for reading 1 bpc images.
  40147. var mask, loop1End, loop2End;
  40148. for (var j = 0; j < height; j++) {
  40149. loop1End = i + (rowComps & ~7);
  40150. loop2End = i + rowComps;
  40151. // unroll loop for all full bytes
  40152. while (i < loop1End) {
  40153. buf = buffer[bufferPos++];
  40154. output[i] = (buf >> 7) & 1;
  40155. output[i + 1] = (buf >> 6) & 1;
  40156. output[i + 2] = (buf >> 5) & 1;
  40157. output[i + 3] = (buf >> 4) & 1;
  40158. output[i + 4] = (buf >> 3) & 1;
  40159. output[i + 5] = (buf >> 2) & 1;
  40160. output[i + 6] = (buf >> 1) & 1;
  40161. output[i + 7] = buf & 1;
  40162. i += 8;
  40163. }
  40164. // handle remaining bits
  40165. if (i < loop2End) {
  40166. buf = buffer[bufferPos++];
  40167. mask = 128;
  40168. while (i < loop2End) {
  40169. output[i++] = +!!(buf & mask);
  40170. mask >>= 1;
  40171. }
  40172. }
  40173. }
  40174. } else {
  40175. // The general case that handles all other bpc values.
  40176. var bits = 0;
  40177. buf = 0;
  40178. for (i = 0, ii = length; i < ii; ++i) {
  40179. if (i % rowComps === 0) {
  40180. buf = 0;
  40181. bits = 0;
  40182. }
  40183. while (bits < bpc) {
  40184. buf = (buf << 8) | buffer[bufferPos++];
  40185. bits += 8;
  40186. }
  40187. var remainingBits = bits - bpc;
  40188. var value = buf >> remainingBits;
  40189. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  40190. buf = buf & ((1 << remainingBits) - 1);
  40191. bits = remainingBits;
  40192. }
  40193. }
  40194. return output;
  40195. },
  40196. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  40197. actualHeight, image) {
  40198. var smask = this.smask;
  40199. var mask = this.mask;
  40200. var alphaBuf, sw, sh, i, ii, j;
  40201. if (smask) {
  40202. sw = smask.width;
  40203. sh = smask.height;
  40204. alphaBuf = new Uint8Array(sw * sh);
  40205. smask.fillGrayBuffer(alphaBuf);
  40206. if (sw !== width || sh !== height) {
  40207. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh,
  40208. width, height);
  40209. }
  40210. } else if (mask) {
  40211. if (mask instanceof PDFImage) {
  40212. sw = mask.width;
  40213. sh = mask.height;
  40214. alphaBuf = new Uint8Array(sw * sh);
  40215. mask.numComps = 1;
  40216. mask.fillGrayBuffer(alphaBuf);
  40217. // Need to invert values in rgbaBuf
  40218. for (i = 0, ii = sw * sh; i < ii; ++i) {
  40219. alphaBuf[i] = 255 - alphaBuf[i];
  40220. }
  40221. if (sw !== width || sh !== height) {
  40222. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
  40223. width, height);
  40224. }
  40225. } else if (isArray(mask)) {
  40226. // Color key mask: if any of the components are outside the range
  40227. // then they should be painted.
  40228. alphaBuf = new Uint8Array(width * height);
  40229. var numComps = this.numComps;
  40230. for (i = 0, ii = width * height; i < ii; ++i) {
  40231. var opacity = 0;
  40232. var imageOffset = i * numComps;
  40233. for (j = 0; j < numComps; ++j) {
  40234. var color = image[imageOffset + j];
  40235. var maskOffset = j * 2;
  40236. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  40237. opacity = 255;
  40238. break;
  40239. }
  40240. }
  40241. alphaBuf[i] = opacity;
  40242. }
  40243. } else {
  40244. error('Unknown mask format.');
  40245. }
  40246. }
  40247. if (alphaBuf) {
  40248. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40249. rgbaBuf[j] = alphaBuf[i];
  40250. }
  40251. } else {
  40252. // No mask.
  40253. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40254. rgbaBuf[j] = 255;
  40255. }
  40256. }
  40257. },
  40258. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  40259. var matte = this.smask && this.smask.matte;
  40260. if (!matte) {
  40261. return;
  40262. }
  40263. var matteRgb = this.colorSpace.getRgb(matte, 0);
  40264. var matteR = matteRgb[0];
  40265. var matteG = matteRgb[1];
  40266. var matteB = matteRgb[2];
  40267. var length = width * height * 4;
  40268. var r, g, b;
  40269. for (var i = 0; i < length; i += 4) {
  40270. var alpha = buffer[i + 3];
  40271. if (alpha === 0) {
  40272. // according formula we have to get Infinity in all components
  40273. // making it white (typical paper color) should be okay
  40274. buffer[i] = 255;
  40275. buffer[i + 1] = 255;
  40276. buffer[i + 2] = 255;
  40277. continue;
  40278. }
  40279. var k = 255 / alpha;
  40280. r = (buffer[i] - matteR) * k + matteR;
  40281. g = (buffer[i + 1] - matteG) * k + matteG;
  40282. b = (buffer[i + 2] - matteB) * k + matteB;
  40283. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  40284. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  40285. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  40286. }
  40287. },
  40288. createImageData: function PDFImage_createImageData(forceRGBA) {
  40289. var drawWidth = this.drawWidth;
  40290. var drawHeight = this.drawHeight;
  40291. var imgData = { // other fields are filled in below
  40292. width: drawWidth,
  40293. height: drawHeight
  40294. };
  40295. var numComps = this.numComps;
  40296. var originalWidth = this.width;
  40297. var originalHeight = this.height;
  40298. var bpc = this.bpc;
  40299. // Rows start at byte boundary.
  40300. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  40301. var imgArray;
  40302. if (!forceRGBA) {
  40303. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  40304. // without any complications, we pass a same-sized copy to the main
  40305. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  40306. // of memory for many scanned documents. It's also much faster.
  40307. //
  40308. // Similarly, if it is a 24-bit-per pixel RGB image without any
  40309. // complications, we avoid expanding by 1.333x to RGBA form.
  40310. var kind;
  40311. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  40312. kind = ImageKind.GRAYSCALE_1BPP;
  40313. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  40314. !this.needsDecode) {
  40315. kind = ImageKind.RGB_24BPP;
  40316. }
  40317. if (kind && !this.smask && !this.mask &&
  40318. drawWidth === originalWidth && drawHeight === originalHeight) {
  40319. imgData.kind = kind;
  40320. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40321. // If imgArray came from a DecodeStream, we're safe to transfer it
  40322. // (and thus detach its underlying buffer) because it will constitute
  40323. // the entire DecodeStream's data. But if it came from a Stream, we
  40324. // need to copy it because it'll only be a portion of the Stream's
  40325. // data, and the rest will be read later on.
  40326. if (this.image instanceof DecodeStream) {
  40327. imgData.data = imgArray;
  40328. } else {
  40329. var newArray = new Uint8Array(imgArray.length);
  40330. newArray.set(imgArray);
  40331. imgData.data = newArray;
  40332. }
  40333. if (this.needsDecode) {
  40334. // Invert the buffer (which must be grayscale if we reached here).
  40335. assert(kind === ImageKind.GRAYSCALE_1BPP);
  40336. var buffer = imgData.data;
  40337. for (var i = 0, ii = buffer.length; i < ii; i++) {
  40338. buffer[i] ^= 0xff;
  40339. }
  40340. }
  40341. return imgData;
  40342. }
  40343. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  40344. (this.colorSpace.name === 'DeviceGray' ||
  40345. this.colorSpace.name === 'DeviceRGB' ||
  40346. this.colorSpace.name === 'DeviceCMYK')) {
  40347. imgData.kind = ImageKind.RGB_24BPP;
  40348. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  40349. drawWidth, drawHeight, true);
  40350. return imgData;
  40351. }
  40352. }
  40353. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40354. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  40355. var actualHeight = 0 | (imgArray.length / rowBytes *
  40356. drawHeight / originalHeight);
  40357. var comps = this.getComponents(imgArray);
  40358. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  40359. // more compact RGB_24BPP form if allowable.
  40360. var alpha01, maybeUndoPreblend;
  40361. if (!forceRGBA && !this.smask && !this.mask) {
  40362. imgData.kind = ImageKind.RGB_24BPP;
  40363. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  40364. alpha01 = 0;
  40365. maybeUndoPreblend = false;
  40366. } else {
  40367. imgData.kind = ImageKind.RGBA_32BPP;
  40368. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  40369. alpha01 = 1;
  40370. maybeUndoPreblend = true;
  40371. // Color key masking (opacity) must be performed before decoding.
  40372. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  40373. comps);
  40374. }
  40375. if (this.needsDecode) {
  40376. this.decodeBuffer(comps);
  40377. }
  40378. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  40379. drawWidth, drawHeight, actualHeight, bpc, comps,
  40380. alpha01);
  40381. if (maybeUndoPreblend) {
  40382. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  40383. }
  40384. return imgData;
  40385. },
  40386. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  40387. var numComps = this.numComps;
  40388. if (numComps !== 1) {
  40389. error('Reading gray scale from a color image: ' + numComps);
  40390. }
  40391. var width = this.width;
  40392. var height = this.height;
  40393. var bpc = this.bpc;
  40394. // rows start at byte boundary
  40395. var rowBytes = (width * numComps * bpc + 7) >> 3;
  40396. var imgArray = this.getImageBytes(height * rowBytes);
  40397. var comps = this.getComponents(imgArray);
  40398. var i, length;
  40399. if (bpc === 1) {
  40400. // inline decoding (= inversion) for 1 bpc images
  40401. length = width * height;
  40402. if (this.needsDecode) {
  40403. // invert and scale to {0, 255}
  40404. for (i = 0; i < length; ++i) {
  40405. buffer[i] = (comps[i] - 1) & 255;
  40406. }
  40407. } else {
  40408. // scale to {0, 255}
  40409. for (i = 0; i < length; ++i) {
  40410. buffer[i] = (-comps[i]) & 255;
  40411. }
  40412. }
  40413. return;
  40414. }
  40415. if (this.needsDecode) {
  40416. this.decodeBuffer(comps);
  40417. }
  40418. length = width * height;
  40419. // we aren't using a colorspace so we need to scale the value
  40420. var scale = 255 / ((1 << bpc) - 1);
  40421. for (i = 0; i < length; ++i) {
  40422. buffer[i] = (scale * comps[i]) | 0;
  40423. }
  40424. },
  40425. getImageBytes: function PDFImage_getImageBytes(length,
  40426. drawWidth, drawHeight,
  40427. forceRGB) {
  40428. this.image.reset();
  40429. this.image.drawWidth = drawWidth || this.width;
  40430. this.image.drawHeight = drawHeight || this.height;
  40431. this.image.forceRGB = !!forceRGB;
  40432. return this.image.getBytes(length);
  40433. }
  40434. };
  40435. return PDFImage;
  40436. })();
  40437. exports.PDFImage = PDFImage;
  40438. }));
  40439. (function (root, factory) {
  40440. {
  40441. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  40442. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  40443. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  40444. }
  40445. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  40446. coreChunkedStream, coreColorSpace) {
  40447. var InvalidPDFException = sharedUtil.InvalidPDFException;
  40448. var MissingDataException = sharedUtil.MissingDataException;
  40449. var XRefParseException = sharedUtil.XRefParseException;
  40450. var assert = sharedUtil.assert;
  40451. var bytesToString = sharedUtil.bytesToString;
  40452. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40453. var error = sharedUtil.error;
  40454. var info = sharedUtil.info;
  40455. var isArray = sharedUtil.isArray;
  40456. var isInt = sharedUtil.isInt;
  40457. var isString = sharedUtil.isString;
  40458. var shadow = sharedUtil.shadow;
  40459. var stringToPDFString = sharedUtil.stringToPDFString;
  40460. var stringToUTF8String = sharedUtil.stringToUTF8String;
  40461. var warn = sharedUtil.warn;
  40462. var isValidUrl = sharedUtil.isValidUrl;
  40463. var Util = sharedUtil.Util;
  40464. var Ref = corePrimitives.Ref;
  40465. var RefSet = corePrimitives.RefSet;
  40466. var RefSetCache = corePrimitives.RefSetCache;
  40467. var isName = corePrimitives.isName;
  40468. var isCmd = corePrimitives.isCmd;
  40469. var isDict = corePrimitives.isDict;
  40470. var isRef = corePrimitives.isRef;
  40471. var isRefsEqual = corePrimitives.isRefsEqual;
  40472. var isStream = corePrimitives.isStream;
  40473. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  40474. var Lexer = coreParser.Lexer;
  40475. var Parser = coreParser.Parser;
  40476. var ChunkedStream = coreChunkedStream.ChunkedStream;
  40477. var ColorSpace = coreColorSpace.ColorSpace;
  40478. var Catalog = (function CatalogClosure() {
  40479. function Catalog(pdfManager, xref, pageFactory) {
  40480. this.pdfManager = pdfManager;
  40481. this.xref = xref;
  40482. this.catDict = xref.getCatalogObj();
  40483. this.fontCache = new RefSetCache();
  40484. assert(isDict(this.catDict),
  40485. 'catalog object is not a dictionary');
  40486. // TODO refactor to move getPage() to the PDFDocument.
  40487. this.pageFactory = pageFactory;
  40488. this.pagePromises = [];
  40489. }
  40490. Catalog.prototype = {
  40491. get metadata() {
  40492. var streamRef = this.catDict.getRaw('Metadata');
  40493. if (!isRef(streamRef)) {
  40494. return shadow(this, 'metadata', null);
  40495. }
  40496. var encryptMetadata = (!this.xref.encrypt ? false :
  40497. this.xref.encrypt.encryptMetadata);
  40498. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  40499. var metadata;
  40500. if (stream && isDict(stream.dict)) {
  40501. var type = stream.dict.get('Type');
  40502. var subtype = stream.dict.get('Subtype');
  40503. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  40504. // XXX: This should examine the charset the XML document defines,
  40505. // however since there are currently no real means to decode
  40506. // arbitrary charsets, let's just hope that the author of the PDF
  40507. // was reasonable enough to stick with the XML default charset,
  40508. // which is UTF-8.
  40509. try {
  40510. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  40511. } catch (e) {
  40512. info('Skipping invalid metadata.');
  40513. }
  40514. }
  40515. }
  40516. return shadow(this, 'metadata', metadata);
  40517. },
  40518. get toplevelPagesDict() {
  40519. var pagesObj = this.catDict.get('Pages');
  40520. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  40521. // shadow the prototype getter
  40522. return shadow(this, 'toplevelPagesDict', pagesObj);
  40523. },
  40524. get documentOutline() {
  40525. var obj = null;
  40526. try {
  40527. obj = this.readDocumentOutline();
  40528. } catch (ex) {
  40529. if (ex instanceof MissingDataException) {
  40530. throw ex;
  40531. }
  40532. warn('Unable to read document outline');
  40533. }
  40534. return shadow(this, 'documentOutline', obj);
  40535. },
  40536. readDocumentOutline: function Catalog_readDocumentOutline() {
  40537. var obj = this.catDict.get('Outlines');
  40538. if (!isDict(obj)) {
  40539. return null;
  40540. }
  40541. obj = obj.getRaw('First');
  40542. if (!isRef(obj)) {
  40543. return null;
  40544. }
  40545. var root = { items: [] };
  40546. var queue = [{obj: obj, parent: root}];
  40547. // To avoid recursion, keep track of the already processed items.
  40548. var processed = new RefSet();
  40549. processed.put(obj);
  40550. var xref = this.xref, blackColor = new Uint8Array(3);
  40551. while (queue.length > 0) {
  40552. var i = queue.shift();
  40553. var outlineDict = xref.fetchIfRef(i.obj);
  40554. if (outlineDict === null) {
  40555. continue;
  40556. }
  40557. assert(outlineDict.has('Title'), 'Invalid outline item');
  40558. var actionDict = outlineDict.get('A'), dest = null, url = null;
  40559. if (actionDict) {
  40560. var destEntry = actionDict.get('D');
  40561. if (destEntry) {
  40562. dest = destEntry;
  40563. } else {
  40564. var uriEntry = actionDict.get('URI');
  40565. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  40566. url = uriEntry;
  40567. }
  40568. }
  40569. } else if (outlineDict.has('Dest')) {
  40570. dest = outlineDict.getRaw('Dest');
  40571. if (isName(dest)) {
  40572. dest = dest.name;
  40573. }
  40574. }
  40575. var title = outlineDict.get('Title');
  40576. var flags = outlineDict.get('F') || 0;
  40577. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  40578. // We only need to parse the color when it's valid, and non-default.
  40579. if (isArray(color) && color.length === 3 &&
  40580. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  40581. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  40582. }
  40583. var outlineItem = {
  40584. dest: dest,
  40585. url: url,
  40586. title: stringToPDFString(title),
  40587. color: rgbColor,
  40588. count: outlineDict.get('Count'),
  40589. bold: !!(flags & 2),
  40590. italic: !!(flags & 1),
  40591. items: []
  40592. };
  40593. i.parent.items.push(outlineItem);
  40594. obj = outlineDict.getRaw('First');
  40595. if (isRef(obj) && !processed.has(obj)) {
  40596. queue.push({obj: obj, parent: outlineItem});
  40597. processed.put(obj);
  40598. }
  40599. obj = outlineDict.getRaw('Next');
  40600. if (isRef(obj) && !processed.has(obj)) {
  40601. queue.push({obj: obj, parent: i.parent});
  40602. processed.put(obj);
  40603. }
  40604. }
  40605. return (root.items.length > 0 ? root.items : null);
  40606. },
  40607. get numPages() {
  40608. var obj = this.toplevelPagesDict.get('Count');
  40609. assert(
  40610. isInt(obj),
  40611. 'page count in top level pages object is not an integer'
  40612. );
  40613. // shadow the prototype getter
  40614. return shadow(this, 'num', obj);
  40615. },
  40616. get destinations() {
  40617. function fetchDestination(dest) {
  40618. return isDict(dest) ? dest.get('D') : dest;
  40619. }
  40620. var xref = this.xref;
  40621. var dests = {}, nameTreeRef, nameDictionaryRef;
  40622. var obj = this.catDict.get('Names');
  40623. if (obj && obj.has('Dests')) {
  40624. nameTreeRef = obj.getRaw('Dests');
  40625. } else if (this.catDict.has('Dests')) {
  40626. nameDictionaryRef = this.catDict.get('Dests');
  40627. }
  40628. if (nameDictionaryRef) {
  40629. // reading simple destination dictionary
  40630. obj = nameDictionaryRef;
  40631. obj.forEach(function catalogForEach(key, value) {
  40632. if (!value) {
  40633. return;
  40634. }
  40635. dests[key] = fetchDestination(value);
  40636. });
  40637. }
  40638. if (nameTreeRef) {
  40639. var nameTree = new NameTree(nameTreeRef, xref);
  40640. var names = nameTree.getAll();
  40641. for (var name in names) {
  40642. dests[name] = fetchDestination(names[name]);
  40643. }
  40644. }
  40645. return shadow(this, 'destinations', dests);
  40646. },
  40647. getDestination: function Catalog_getDestination(destinationId) {
  40648. function fetchDestination(dest) {
  40649. return isDict(dest) ? dest.get('D') : dest;
  40650. }
  40651. var xref = this.xref;
  40652. var dest = null, nameTreeRef, nameDictionaryRef;
  40653. var obj = this.catDict.get('Names');
  40654. if (obj && obj.has('Dests')) {
  40655. nameTreeRef = obj.getRaw('Dests');
  40656. } else if (this.catDict.has('Dests')) {
  40657. nameDictionaryRef = this.catDict.get('Dests');
  40658. }
  40659. if (nameDictionaryRef) { // Simple destination dictionary.
  40660. var value = nameDictionaryRef.get(destinationId);
  40661. if (value) {
  40662. dest = fetchDestination(value);
  40663. }
  40664. }
  40665. if (nameTreeRef) {
  40666. var nameTree = new NameTree(nameTreeRef, xref);
  40667. dest = fetchDestination(nameTree.get(destinationId));
  40668. }
  40669. return dest;
  40670. },
  40671. get pageLabels() {
  40672. var obj = null;
  40673. try {
  40674. obj = this.readPageLabels();
  40675. } catch (ex) {
  40676. if (ex instanceof MissingDataException) {
  40677. throw ex;
  40678. }
  40679. warn('Unable to read page labels.');
  40680. }
  40681. return shadow(this, 'pageLabels', obj);
  40682. },
  40683. readPageLabels: function Catalog_readPageLabels() {
  40684. var obj = this.catDict.getRaw('PageLabels');
  40685. if (!obj) {
  40686. return null;
  40687. }
  40688. var pageLabels = new Array(this.numPages);
  40689. var style = null;
  40690. var prefix = '';
  40691. var start = 1;
  40692. var numberTree = new NumberTree(obj, this.xref);
  40693. var nums = numberTree.getAll();
  40694. var currentLabel = '', currentIndex = 1;
  40695. for (var i = 0, ii = this.numPages; i < ii; i++) {
  40696. if (i in nums) {
  40697. var labelDict = nums[i];
  40698. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  40699. var type = labelDict.get('Type');
  40700. assert(!type || isName(type, 'PageLabel'),
  40701. 'Invalid type in PageLabel dictionary.');
  40702. var s = labelDict.get('S');
  40703. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  40704. style = (s ? s.name : null);
  40705. prefix = labelDict.get('P') || '';
  40706. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  40707. start = labelDict.get('St') || 1;
  40708. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  40709. currentIndex = start;
  40710. }
  40711. switch (style) {
  40712. case 'D':
  40713. currentLabel = currentIndex;
  40714. break;
  40715. case 'R':
  40716. case 'r':
  40717. currentLabel = Util.toRoman(currentIndex, style === 'r');
  40718. break;
  40719. case 'A':
  40720. case 'a':
  40721. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  40722. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  40723. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  40724. var letterIndex = currentIndex - 1;
  40725. var character = String.fromCharCode(baseCharCode +
  40726. (letterIndex % LIMIT));
  40727. var charBuf = [];
  40728. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  40729. charBuf.push(character);
  40730. }
  40731. currentLabel = charBuf.join('');
  40732. break;
  40733. default:
  40734. assert(!style,
  40735. 'Invalid style "' + style + '" in PageLabel dictionary.');
  40736. }
  40737. pageLabels[i] = prefix + currentLabel;
  40738. currentLabel = '';
  40739. currentIndex++;
  40740. }
  40741. return pageLabels;
  40742. },
  40743. get attachments() {
  40744. var xref = this.xref;
  40745. var attachments = null, nameTreeRef;
  40746. var obj = this.catDict.get('Names');
  40747. if (obj) {
  40748. nameTreeRef = obj.getRaw('EmbeddedFiles');
  40749. }
  40750. if (nameTreeRef) {
  40751. var nameTree = new NameTree(nameTreeRef, xref);
  40752. var names = nameTree.getAll();
  40753. for (var name in names) {
  40754. var fs = new FileSpec(names[name], xref);
  40755. if (!attachments) {
  40756. attachments = Object.create(null);
  40757. }
  40758. attachments[stringToPDFString(name)] = fs.serializable;
  40759. }
  40760. }
  40761. return shadow(this, 'attachments', attachments);
  40762. },
  40763. get javaScript() {
  40764. var xref = this.xref;
  40765. var obj = this.catDict.get('Names');
  40766. var javaScript = [];
  40767. function appendIfJavaScriptDict(jsDict) {
  40768. var type = jsDict.get('S');
  40769. if (!isName(type, 'JavaScript')) {
  40770. return;
  40771. }
  40772. var js = jsDict.get('JS');
  40773. if (isStream(js)) {
  40774. js = bytesToString(js.getBytes());
  40775. } else if (!isString(js)) {
  40776. return;
  40777. }
  40778. javaScript.push(stringToPDFString(js));
  40779. }
  40780. if (obj && obj.has('JavaScript')) {
  40781. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  40782. var names = nameTree.getAll();
  40783. for (var name in names) {
  40784. // We don't really use the JavaScript right now. This code is
  40785. // defensive so we don't cause errors on document load.
  40786. var jsDict = names[name];
  40787. if (isDict(jsDict)) {
  40788. appendIfJavaScriptDict(jsDict);
  40789. }
  40790. }
  40791. }
  40792. // Append OpenAction actions to javaScript array
  40793. var openactionDict = this.catDict.get('OpenAction');
  40794. if (isDict(openactionDict, 'Action')) {
  40795. var actionType = openactionDict.get('S');
  40796. if (isName(actionType, 'Named')) {
  40797. // The named Print action is not a part of the PDF 1.7 specification,
  40798. // but is supported by many PDF readers/writers (including Adobe's).
  40799. var action = openactionDict.get('N');
  40800. if (isName(action, 'Print')) {
  40801. javaScript.push('print({});');
  40802. }
  40803. } else {
  40804. appendIfJavaScriptDict(openactionDict);
  40805. }
  40806. }
  40807. return shadow(this, 'javaScript', javaScript);
  40808. },
  40809. cleanup: function Catalog_cleanup() {
  40810. var promises = [];
  40811. this.fontCache.forEach(function (promise) {
  40812. promises.push(promise);
  40813. });
  40814. return Promise.all(promises).then(function (translatedFonts) {
  40815. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  40816. var font = translatedFonts[i].dict;
  40817. delete font.translated;
  40818. }
  40819. this.fontCache.clear();
  40820. }.bind(this));
  40821. },
  40822. getPage: function Catalog_getPage(pageIndex) {
  40823. if (!(pageIndex in this.pagePromises)) {
  40824. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  40825. function (a) {
  40826. var dict = a[0];
  40827. var ref = a[1];
  40828. return this.pageFactory.createPage(pageIndex, dict, ref,
  40829. this.fontCache);
  40830. }.bind(this)
  40831. );
  40832. }
  40833. return this.pagePromises[pageIndex];
  40834. },
  40835. getPageDict: function Catalog_getPageDict(pageIndex) {
  40836. var capability = createPromiseCapability();
  40837. var nodesToVisit = [this.catDict.getRaw('Pages')];
  40838. var currentPageIndex = 0;
  40839. var xref = this.xref;
  40840. var checkAllKids = false;
  40841. function next() {
  40842. while (nodesToVisit.length) {
  40843. var currentNode = nodesToVisit.pop();
  40844. if (isRef(currentNode)) {
  40845. xref.fetchAsync(currentNode).then(function (obj) {
  40846. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  40847. if (pageIndex === currentPageIndex) {
  40848. capability.resolve([obj, currentNode]);
  40849. } else {
  40850. currentPageIndex++;
  40851. next();
  40852. }
  40853. return;
  40854. }
  40855. nodesToVisit.push(obj);
  40856. next();
  40857. }, capability.reject);
  40858. return;
  40859. }
  40860. // Must be a child page dictionary.
  40861. assert(
  40862. isDict(currentNode),
  40863. 'page dictionary kid reference points to wrong type of object'
  40864. );
  40865. var count = currentNode.get('Count');
  40866. // If the current node doesn't have any children, avoid getting stuck
  40867. // in an empty node further down in the tree (see issue5644.pdf).
  40868. if (count === 0) {
  40869. checkAllKids = true;
  40870. }
  40871. // Skip nodes where the page can't be.
  40872. if (currentPageIndex + count <= pageIndex) {
  40873. currentPageIndex += count;
  40874. continue;
  40875. }
  40876. var kids = currentNode.get('Kids');
  40877. assert(isArray(kids), 'page dictionary kids object is not an array');
  40878. if (!checkAllKids && count === kids.length) {
  40879. // Nodes that don't have the page have been skipped and this is the
  40880. // bottom of the tree which means the page requested must be a
  40881. // descendant of this pages node. Ideally we would just resolve the
  40882. // promise with the page ref here, but there is the case where more
  40883. // pages nodes could link to single a page (see issue 3666 pdf). To
  40884. // handle this push it back on the queue so if it is a pages node it
  40885. // will be descended into.
  40886. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  40887. currentPageIndex = pageIndex;
  40888. continue;
  40889. } else {
  40890. for (var last = kids.length - 1; last >= 0; last--) {
  40891. nodesToVisit.push(kids[last]);
  40892. }
  40893. }
  40894. }
  40895. capability.reject('Page index ' + pageIndex + ' not found.');
  40896. }
  40897. next();
  40898. return capability.promise;
  40899. },
  40900. getPageIndex: function Catalog_getPageIndex(pageRef) {
  40901. // The page tree nodes have the count of all the leaves below them. To get
  40902. // how many pages are before we just have to walk up the tree and keep
  40903. // adding the count of siblings to the left of the node.
  40904. var xref = this.xref;
  40905. function pagesBeforeRef(kidRef) {
  40906. var total = 0;
  40907. var parentRef;
  40908. return xref.fetchAsync(kidRef).then(function (node) {
  40909. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
  40910. !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  40911. throw new Error('The reference does not point to a /Page Dict.');
  40912. }
  40913. if (!node) {
  40914. return null;
  40915. }
  40916. assert(isDict(node), 'node must be a Dict.');
  40917. parentRef = node.getRaw('Parent');
  40918. return node.getAsync('Parent');
  40919. }).then(function (parent) {
  40920. if (!parent) {
  40921. return null;
  40922. }
  40923. assert(isDict(parent), 'parent must be a Dict.');
  40924. return parent.getAsync('Kids');
  40925. }).then(function (kids) {
  40926. if (!kids) {
  40927. return null;
  40928. }
  40929. var kidPromises = [];
  40930. var found = false;
  40931. for (var i = 0; i < kids.length; i++) {
  40932. var kid = kids[i];
  40933. assert(isRef(kid), 'kid must be a Ref.');
  40934. if (kid.num === kidRef.num) {
  40935. found = true;
  40936. break;
  40937. }
  40938. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  40939. if (kid.has('Count')) {
  40940. var count = kid.get('Count');
  40941. total += count;
  40942. } else { // page leaf node
  40943. total++;
  40944. }
  40945. }));
  40946. }
  40947. if (!found) {
  40948. error('kid ref not found in parents kids');
  40949. }
  40950. return Promise.all(kidPromises).then(function () {
  40951. return [total, parentRef];
  40952. });
  40953. });
  40954. }
  40955. var total = 0;
  40956. function next(ref) {
  40957. return pagesBeforeRef(ref).then(function (args) {
  40958. if (!args) {
  40959. return total;
  40960. }
  40961. var count = args[0];
  40962. var parentRef = args[1];
  40963. total += count;
  40964. return next(parentRef);
  40965. });
  40966. }
  40967. return next(pageRef);
  40968. }
  40969. };
  40970. return Catalog;
  40971. })();
  40972. var XRef = (function XRefClosure() {
  40973. function XRef(stream, password) {
  40974. this.stream = stream;
  40975. this.entries = [];
  40976. this.xrefstms = Object.create(null);
  40977. // prepare the XRef cache
  40978. this.cache = [];
  40979. this.password = password;
  40980. this.stats = {
  40981. streamTypes: [],
  40982. fontTypes: []
  40983. };
  40984. }
  40985. XRef.prototype = {
  40986. setStartXRef: function XRef_setStartXRef(startXRef) {
  40987. // Store the starting positions of xref tables as we process them
  40988. // so we can recover from missing data errors
  40989. this.startXRefQueue = [startXRef];
  40990. },
  40991. parse: function XRef_parse(recoveryMode) {
  40992. var trailerDict;
  40993. if (!recoveryMode) {
  40994. trailerDict = this.readXRef();
  40995. } else {
  40996. warn('Indexing all PDF objects');
  40997. trailerDict = this.indexObjects();
  40998. }
  40999. trailerDict.assignXref(this);
  41000. this.trailer = trailerDict;
  41001. var encrypt = trailerDict.get('Encrypt');
  41002. if (encrypt) {
  41003. var ids = trailerDict.get('ID');
  41004. var fileId = (ids && ids.length) ? ids[0] : '';
  41005. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  41006. this.password);
  41007. }
  41008. // get the root dictionary (catalog) object
  41009. if (!(this.root = trailerDict.get('Root'))) {
  41010. error('Invalid root reference');
  41011. }
  41012. },
  41013. processXRefTable: function XRef_processXRefTable(parser) {
  41014. if (!('tableState' in this)) {
  41015. // Stores state of the table as we process it so we can resume
  41016. // from middle of table in case of missing data error
  41017. this.tableState = {
  41018. entryNum: 0,
  41019. streamPos: parser.lexer.stream.pos,
  41020. parserBuf1: parser.buf1,
  41021. parserBuf2: parser.buf2
  41022. };
  41023. }
  41024. var obj = this.readXRefTable(parser);
  41025. // Sanity check
  41026. if (!isCmd(obj, 'trailer')) {
  41027. error('Invalid XRef table: could not find trailer dictionary');
  41028. }
  41029. // Read trailer dictionary, e.g.
  41030. // trailer
  41031. // << /Size 22
  41032. // /Root 20R
  41033. // /Info 10R
  41034. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  41035. // >>
  41036. // The parser goes through the entire stream << ... >> and provides
  41037. // a getter interface for the key-value table
  41038. var dict = parser.getObj();
  41039. // The pdflib PDF generator can generate a nested trailer dictionary
  41040. if (!isDict(dict) && dict.dict) {
  41041. dict = dict.dict;
  41042. }
  41043. if (!isDict(dict)) {
  41044. error('Invalid XRef table: could not parse trailer dictionary');
  41045. }
  41046. delete this.tableState;
  41047. return dict;
  41048. },
  41049. readXRefTable: function XRef_readXRefTable(parser) {
  41050. // Example of cross-reference table:
  41051. // xref
  41052. // 0 1 <-- subsection header (first obj #, obj count)
  41053. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  41054. // 23 2 <-- subsection header ... and so on ...
  41055. // 0000025518 00002 n
  41056. // 0000025635 00000 n
  41057. // trailer
  41058. // ...
  41059. var stream = parser.lexer.stream;
  41060. var tableState = this.tableState;
  41061. stream.pos = tableState.streamPos;
  41062. parser.buf1 = tableState.parserBuf1;
  41063. parser.buf2 = tableState.parserBuf2;
  41064. // Outer loop is over subsection headers
  41065. var obj;
  41066. while (true) {
  41067. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  41068. if (isCmd(obj = parser.getObj(), 'trailer')) {
  41069. break;
  41070. }
  41071. tableState.firstEntryNum = obj;
  41072. tableState.entryCount = parser.getObj();
  41073. }
  41074. var first = tableState.firstEntryNum;
  41075. var count = tableState.entryCount;
  41076. if (!isInt(first) || !isInt(count)) {
  41077. error('Invalid XRef table: wrong types in subsection header');
  41078. }
  41079. // Inner loop is over objects themselves
  41080. for (var i = tableState.entryNum; i < count; i++) {
  41081. tableState.streamPos = stream.pos;
  41082. tableState.entryNum = i;
  41083. tableState.parserBuf1 = parser.buf1;
  41084. tableState.parserBuf2 = parser.buf2;
  41085. var entry = {};
  41086. entry.offset = parser.getObj();
  41087. entry.gen = parser.getObj();
  41088. var type = parser.getObj();
  41089. if (isCmd(type, 'f')) {
  41090. entry.free = true;
  41091. } else if (isCmd(type, 'n')) {
  41092. entry.uncompressed = true;
  41093. }
  41094. // Validate entry obj
  41095. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  41096. !(entry.free || entry.uncompressed)) {
  41097. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  41098. }
  41099. // The first xref table entry, i.e. obj 0, should be free. Attempting
  41100. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  41101. if (i === 0 && entry.free && first === 1) {
  41102. first = 0;
  41103. }
  41104. if (!this.entries[i + first]) {
  41105. this.entries[i + first] = entry;
  41106. }
  41107. }
  41108. tableState.entryNum = 0;
  41109. tableState.streamPos = stream.pos;
  41110. tableState.parserBuf1 = parser.buf1;
  41111. tableState.parserBuf2 = parser.buf2;
  41112. delete tableState.firstEntryNum;
  41113. delete tableState.entryCount;
  41114. }
  41115. // Sanity check: as per spec, first object must be free
  41116. if (this.entries[0] && !this.entries[0].free) {
  41117. error('Invalid XRef table: unexpected first object');
  41118. }
  41119. return obj;
  41120. },
  41121. processXRefStream: function XRef_processXRefStream(stream) {
  41122. if (!('streamState' in this)) {
  41123. // Stores state of the stream as we process it so we can resume
  41124. // from middle of stream in case of missing data error
  41125. var streamParameters = stream.dict;
  41126. var byteWidths = streamParameters.get('W');
  41127. var range = streamParameters.get('Index');
  41128. if (!range) {
  41129. range = [0, streamParameters.get('Size')];
  41130. }
  41131. this.streamState = {
  41132. entryRanges: range,
  41133. byteWidths: byteWidths,
  41134. entryNum: 0,
  41135. streamPos: stream.pos
  41136. };
  41137. }
  41138. this.readXRefStream(stream);
  41139. delete this.streamState;
  41140. return stream.dict;
  41141. },
  41142. readXRefStream: function XRef_readXRefStream(stream) {
  41143. var i, j;
  41144. var streamState = this.streamState;
  41145. stream.pos = streamState.streamPos;
  41146. var byteWidths = streamState.byteWidths;
  41147. var typeFieldWidth = byteWidths[0];
  41148. var offsetFieldWidth = byteWidths[1];
  41149. var generationFieldWidth = byteWidths[2];
  41150. var entryRanges = streamState.entryRanges;
  41151. while (entryRanges.length > 0) {
  41152. var first = entryRanges[0];
  41153. var n = entryRanges[1];
  41154. if (!isInt(first) || !isInt(n)) {
  41155. error('Invalid XRef range fields: ' + first + ', ' + n);
  41156. }
  41157. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  41158. !isInt(generationFieldWidth)) {
  41159. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  41160. }
  41161. for (i = streamState.entryNum; i < n; ++i) {
  41162. streamState.entryNum = i;
  41163. streamState.streamPos = stream.pos;
  41164. var type = 0, offset = 0, generation = 0;
  41165. for (j = 0; j < typeFieldWidth; ++j) {
  41166. type = (type << 8) | stream.getByte();
  41167. }
  41168. // if type field is absent, its default value is 1
  41169. if (typeFieldWidth === 0) {
  41170. type = 1;
  41171. }
  41172. for (j = 0; j < offsetFieldWidth; ++j) {
  41173. offset = (offset << 8) | stream.getByte();
  41174. }
  41175. for (j = 0; j < generationFieldWidth; ++j) {
  41176. generation = (generation << 8) | stream.getByte();
  41177. }
  41178. var entry = {};
  41179. entry.offset = offset;
  41180. entry.gen = generation;
  41181. switch (type) {
  41182. case 0:
  41183. entry.free = true;
  41184. break;
  41185. case 1:
  41186. entry.uncompressed = true;
  41187. break;
  41188. case 2:
  41189. break;
  41190. default:
  41191. error('Invalid XRef entry type: ' + type);
  41192. }
  41193. if (!this.entries[first + i]) {
  41194. this.entries[first + i] = entry;
  41195. }
  41196. }
  41197. streamState.entryNum = 0;
  41198. streamState.streamPos = stream.pos;
  41199. entryRanges.splice(0, 2);
  41200. }
  41201. },
  41202. indexObjects: function XRef_indexObjects() {
  41203. // Simple scan through the PDF content to find objects,
  41204. // trailers and XRef streams.
  41205. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  41206. var PERCENT = 0x25, LT = 0x3C;
  41207. function readToken(data, offset) {
  41208. var token = '', ch = data[offset];
  41209. while (ch !== LF && ch !== CR && ch !== LT) {
  41210. if (++offset >= data.length) {
  41211. break;
  41212. }
  41213. token += String.fromCharCode(ch);
  41214. ch = data[offset];
  41215. }
  41216. return token;
  41217. }
  41218. function skipUntil(data, offset, what) {
  41219. var length = what.length, dataLength = data.length;
  41220. var skipped = 0;
  41221. // finding byte sequence
  41222. while (offset < dataLength) {
  41223. var i = 0;
  41224. while (i < length && data[offset + i] === what[i]) {
  41225. ++i;
  41226. }
  41227. if (i >= length) {
  41228. break; // sequence found
  41229. }
  41230. offset++;
  41231. skipped++;
  41232. }
  41233. return skipped;
  41234. }
  41235. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  41236. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  41237. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  41238. 101, 102]);
  41239. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  41240. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  41241. // Clear out any existing entries, since they may be bogus.
  41242. this.entries.length = 0;
  41243. var stream = this.stream;
  41244. stream.pos = 0;
  41245. var buffer = stream.getBytes();
  41246. var position = stream.start, length = buffer.length;
  41247. var trailers = [], xrefStms = [];
  41248. while (position < length) {
  41249. var ch = buffer[position];
  41250. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  41251. ++position;
  41252. continue;
  41253. }
  41254. if (ch === PERCENT) { // %-comment
  41255. do {
  41256. ++position;
  41257. if (position >= length) {
  41258. break;
  41259. }
  41260. ch = buffer[position];
  41261. } while (ch !== LF && ch !== CR);
  41262. continue;
  41263. }
  41264. var token = readToken(buffer, position);
  41265. var m;
  41266. if (token.indexOf('xref') === 0 &&
  41267. (token.length === 4 || /\s/.test(token[4]))) {
  41268. position += skipUntil(buffer, position, trailerBytes);
  41269. trailers.push(position);
  41270. position += skipUntil(buffer, position, startxrefBytes);
  41271. } else if ((m = objRegExp.exec(token))) {
  41272. if (typeof this.entries[m[1]] === 'undefined') {
  41273. this.entries[m[1]] = {
  41274. offset: position - stream.start,
  41275. gen: m[2] | 0,
  41276. uncompressed: true
  41277. };
  41278. }
  41279. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  41280. var content = buffer.subarray(position, position + contentLength);
  41281. // checking XRef stream suspect
  41282. // (it shall have '/XRef' and next char is not a letter)
  41283. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  41284. if (xrefTagOffset < contentLength &&
  41285. content[xrefTagOffset + 5] < 64) {
  41286. xrefStms.push(position - stream.start);
  41287. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  41288. }
  41289. position += contentLength;
  41290. } else if (token.indexOf('trailer') === 0 &&
  41291. (token.length === 7 || /\s/.test(token[7]))) {
  41292. trailers.push(position);
  41293. position += skipUntil(buffer, position, startxrefBytes);
  41294. } else {
  41295. position += token.length + 1;
  41296. }
  41297. }
  41298. // reading XRef streams
  41299. var i, ii;
  41300. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  41301. this.startXRefQueue.push(xrefStms[i]);
  41302. this.readXRef(/* recoveryMode */ true);
  41303. }
  41304. // finding main trailer
  41305. var dict;
  41306. for (i = 0, ii = trailers.length; i < ii; ++i) {
  41307. stream.pos = trailers[i];
  41308. var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
  41309. /* xref = */ this, /* recoveryMode = */ true);
  41310. var obj = parser.getObj();
  41311. if (!isCmd(obj, 'trailer')) {
  41312. continue;
  41313. }
  41314. // read the trailer dictionary
  41315. dict = parser.getObj();
  41316. if (!isDict(dict)) {
  41317. continue;
  41318. }
  41319. // taking the first one with 'ID'
  41320. if (dict.has('ID')) {
  41321. return dict;
  41322. }
  41323. }
  41324. // no tailer with 'ID', taking last one (if exists)
  41325. if (dict) {
  41326. return dict;
  41327. }
  41328. // nothing helps
  41329. // calling error() would reject worker with an UnknownErrorException.
  41330. throw new InvalidPDFException('Invalid PDF structure');
  41331. },
  41332. readXRef: function XRef_readXRef(recoveryMode) {
  41333. var stream = this.stream;
  41334. try {
  41335. while (this.startXRefQueue.length) {
  41336. var startXRef = this.startXRefQueue[0];
  41337. stream.pos = startXRef + stream.start;
  41338. var parser = new Parser(new Lexer(stream), true, this);
  41339. var obj = parser.getObj();
  41340. var dict;
  41341. // Get dictionary
  41342. if (isCmd(obj, 'xref')) {
  41343. // Parse end-of-file XRef
  41344. dict = this.processXRefTable(parser);
  41345. if (!this.topDict) {
  41346. this.topDict = dict;
  41347. }
  41348. // Recursively get other XRefs 'XRefStm', if any
  41349. obj = dict.get('XRefStm');
  41350. if (isInt(obj)) {
  41351. var pos = obj;
  41352. // ignore previously loaded xref streams
  41353. // (possible infinite recursion)
  41354. if (!(pos in this.xrefstms)) {
  41355. this.xrefstms[pos] = 1;
  41356. this.startXRefQueue.push(pos);
  41357. }
  41358. }
  41359. } else if (isInt(obj)) {
  41360. // Parse in-stream XRef
  41361. if (!isInt(parser.getObj()) ||
  41362. !isCmd(parser.getObj(), 'obj') ||
  41363. !isStream(obj = parser.getObj())) {
  41364. error('Invalid XRef stream');
  41365. }
  41366. dict = this.processXRefStream(obj);
  41367. if (!this.topDict) {
  41368. this.topDict = dict;
  41369. }
  41370. if (!dict) {
  41371. error('Failed to read XRef stream');
  41372. }
  41373. } else {
  41374. error('Invalid XRef stream header');
  41375. }
  41376. // Recursively get previous dictionary, if any
  41377. obj = dict.get('Prev');
  41378. if (isInt(obj)) {
  41379. this.startXRefQueue.push(obj);
  41380. } else if (isRef(obj)) {
  41381. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  41382. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  41383. this.startXRefQueue.push(obj.num);
  41384. }
  41385. this.startXRefQueue.shift();
  41386. }
  41387. return this.topDict;
  41388. } catch (e) {
  41389. if (e instanceof MissingDataException) {
  41390. throw e;
  41391. }
  41392. info('(while reading XRef): ' + e);
  41393. }
  41394. if (recoveryMode) {
  41395. return;
  41396. }
  41397. throw new XRefParseException();
  41398. },
  41399. getEntry: function XRef_getEntry(i) {
  41400. var xrefEntry = this.entries[i];
  41401. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  41402. return xrefEntry;
  41403. }
  41404. return null;
  41405. },
  41406. fetchIfRef: function XRef_fetchIfRef(obj) {
  41407. if (!isRef(obj)) {
  41408. return obj;
  41409. }
  41410. return this.fetch(obj);
  41411. },
  41412. fetch: function XRef_fetch(ref, suppressEncryption) {
  41413. assert(isRef(ref), 'ref object is not a reference');
  41414. var num = ref.num;
  41415. if (num in this.cache) {
  41416. var cacheEntry = this.cache[num];
  41417. return cacheEntry;
  41418. }
  41419. var xrefEntry = this.getEntry(num);
  41420. // the referenced entry can be free
  41421. if (xrefEntry === null) {
  41422. return (this.cache[num] = null);
  41423. }
  41424. if (xrefEntry.uncompressed) {
  41425. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  41426. } else {
  41427. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  41428. }
  41429. if (isDict(xrefEntry)){
  41430. xrefEntry.objId = ref.toString();
  41431. } else if (isStream(xrefEntry)) {
  41432. xrefEntry.dict.objId = ref.toString();
  41433. }
  41434. return xrefEntry;
  41435. },
  41436. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  41437. suppressEncryption) {
  41438. var gen = ref.gen;
  41439. var num = ref.num;
  41440. if (xrefEntry.gen !== gen) {
  41441. error('inconsistent generation in XRef');
  41442. }
  41443. var stream = this.stream.makeSubStream(xrefEntry.offset +
  41444. this.stream.start);
  41445. var parser = new Parser(new Lexer(stream), true, this);
  41446. var obj1 = parser.getObj();
  41447. var obj2 = parser.getObj();
  41448. var obj3 = parser.getObj();
  41449. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  41450. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  41451. !isCmd(obj3)) {
  41452. error('bad XRef entry');
  41453. }
  41454. if (!isCmd(obj3, 'obj')) {
  41455. // some bad PDFs use "obj1234" and really mean 1234
  41456. if (obj3.cmd.indexOf('obj') === 0) {
  41457. num = parseInt(obj3.cmd.substring(3), 10);
  41458. if (!isNaN(num)) {
  41459. return num;
  41460. }
  41461. }
  41462. error('bad XRef entry');
  41463. }
  41464. if (this.encrypt && !suppressEncryption) {
  41465. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  41466. } else {
  41467. xrefEntry = parser.getObj();
  41468. }
  41469. if (!isStream(xrefEntry)) {
  41470. this.cache[num] = xrefEntry;
  41471. }
  41472. return xrefEntry;
  41473. },
  41474. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  41475. suppressEncryption) {
  41476. var tableOffset = xrefEntry.offset;
  41477. var stream = this.fetch(new Ref(tableOffset, 0));
  41478. if (!isStream(stream)) {
  41479. error('bad ObjStm stream');
  41480. }
  41481. var first = stream.dict.get('First');
  41482. var n = stream.dict.get('N');
  41483. if (!isInt(first) || !isInt(n)) {
  41484. error('invalid first and n parameters for ObjStm stream');
  41485. }
  41486. var parser = new Parser(new Lexer(stream), false, this);
  41487. parser.allowStreams = true;
  41488. var i, entries = [], num, nums = [];
  41489. // read the object numbers to populate cache
  41490. for (i = 0; i < n; ++i) {
  41491. num = parser.getObj();
  41492. if (!isInt(num)) {
  41493. error('invalid object number in the ObjStm stream: ' + num);
  41494. }
  41495. nums.push(num);
  41496. var offset = parser.getObj();
  41497. if (!isInt(offset)) {
  41498. error('invalid object offset in the ObjStm stream: ' + offset);
  41499. }
  41500. }
  41501. // read stream objects for cache
  41502. for (i = 0; i < n; ++i) {
  41503. entries.push(parser.getObj());
  41504. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  41505. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  41506. if (isCmd(parser.buf1, 'endobj')) {
  41507. parser.shift();
  41508. }
  41509. num = nums[i];
  41510. var entry = this.entries[num];
  41511. if (entry && entry.offset === tableOffset && entry.gen === i) {
  41512. this.cache[num] = entries[i];
  41513. }
  41514. }
  41515. xrefEntry = entries[xrefEntry.gen];
  41516. if (xrefEntry === undefined) {
  41517. error('bad XRef entry for compressed object');
  41518. }
  41519. return xrefEntry;
  41520. },
  41521. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  41522. if (!isRef(obj)) {
  41523. return Promise.resolve(obj);
  41524. }
  41525. return this.fetchAsync(obj);
  41526. },
  41527. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  41528. var streamManager = this.stream.manager;
  41529. var xref = this;
  41530. return new Promise(function tryFetch(resolve, reject) {
  41531. try {
  41532. resolve(xref.fetch(ref, suppressEncryption));
  41533. } catch (e) {
  41534. if (e instanceof MissingDataException) {
  41535. streamManager.requestRange(e.begin, e.end).then(function () {
  41536. tryFetch(resolve, reject);
  41537. }, reject);
  41538. return;
  41539. }
  41540. reject(e);
  41541. }
  41542. });
  41543. },
  41544. getCatalogObj: function XRef_getCatalogObj() {
  41545. return this.root;
  41546. }
  41547. };
  41548. return XRef;
  41549. })();
  41550. /**
  41551. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  41552. * see the specification (7.9.6 and 7.9.7) for additional details.
  41553. * TODO: implement all the Dict functions and make this more efficient.
  41554. */
  41555. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  41556. function NameOrNumberTree(root, xref) {
  41557. throw new Error('Cannot initialize NameOrNumberTree.');
  41558. }
  41559. NameOrNumberTree.prototype = {
  41560. getAll: function NameOrNumberTree_getAll() {
  41561. var dict = Object.create(null);
  41562. if (!this.root) {
  41563. return dict;
  41564. }
  41565. var xref = this.xref;
  41566. // Reading Name/Number tree.
  41567. var processed = new RefSet();
  41568. processed.put(this.root);
  41569. var queue = [this.root];
  41570. while (queue.length > 0) {
  41571. var i, n;
  41572. var obj = xref.fetchIfRef(queue.shift());
  41573. if (!isDict(obj)) {
  41574. continue;
  41575. }
  41576. if (obj.has('Kids')) {
  41577. var kids = obj.get('Kids');
  41578. for (i = 0, n = kids.length; i < n; i++) {
  41579. var kid = kids[i];
  41580. assert(!processed.has(kid),
  41581. 'Duplicate entry in "' + this._type + '" tree.');
  41582. queue.push(kid);
  41583. processed.put(kid);
  41584. }
  41585. continue;
  41586. }
  41587. var entries = obj.get(this._type);
  41588. if (isArray(entries)) {
  41589. for (i = 0, n = entries.length; i < n; i += 2) {
  41590. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  41591. }
  41592. }
  41593. }
  41594. return dict;
  41595. },
  41596. get: function NameOrNumberTree_get(key) {
  41597. if (!this.root) {
  41598. return null;
  41599. }
  41600. var xref = this.xref;
  41601. var kidsOrEntries = xref.fetchIfRef(this.root);
  41602. var loopCount = 0;
  41603. var MAX_LEVELS = 10;
  41604. var l, r, m;
  41605. // Perform a binary search to quickly find the entry that
  41606. // contains the key we are looking for.
  41607. while (kidsOrEntries.has('Kids')) {
  41608. if (++loopCount > MAX_LEVELS) {
  41609. warn('Search depth limit reached for "' + this._type + '" tree.');
  41610. return null;
  41611. }
  41612. var kids = kidsOrEntries.get('Kids');
  41613. if (!isArray(kids)) {
  41614. return null;
  41615. }
  41616. l = 0;
  41617. r = kids.length - 1;
  41618. while (l <= r) {
  41619. m = (l + r) >> 1;
  41620. var kid = xref.fetchIfRef(kids[m]);
  41621. var limits = kid.get('Limits');
  41622. if (key < xref.fetchIfRef(limits[0])) {
  41623. r = m - 1;
  41624. } else if (key > xref.fetchIfRef(limits[1])) {
  41625. l = m + 1;
  41626. } else {
  41627. kidsOrEntries = xref.fetchIfRef(kids[m]);
  41628. break;
  41629. }
  41630. }
  41631. if (l > r) {
  41632. return null;
  41633. }
  41634. }
  41635. // If we get here, then we have found the right entry. Now go through the
  41636. // entries in the dictionary until we find the key we're looking for.
  41637. var entries = kidsOrEntries.get(this._type);
  41638. if (isArray(entries)) {
  41639. // Perform a binary search to reduce the lookup time.
  41640. l = 0;
  41641. r = entries.length - 2;
  41642. while (l <= r) {
  41643. // Check only even indices (0, 2, 4, ...) because the
  41644. // odd indices contain the actual data.
  41645. m = (l + r) & ~1;
  41646. var currentKey = xref.fetchIfRef(entries[m]);
  41647. if (key < currentKey) {
  41648. r = m - 2;
  41649. } else if (key > currentKey) {
  41650. l = m + 2;
  41651. } else {
  41652. return xref.fetchIfRef(entries[m + 1]);
  41653. }
  41654. }
  41655. }
  41656. return null;
  41657. }
  41658. };
  41659. return NameOrNumberTree;
  41660. })();
  41661. var NameTree = (function NameTreeClosure() {
  41662. function NameTree(root, xref) {
  41663. this.root = root;
  41664. this.xref = xref;
  41665. this._type = 'Names';
  41666. }
  41667. Util.inherit(NameTree, NameOrNumberTree, {});
  41668. return NameTree;
  41669. })();
  41670. var NumberTree = (function NumberTreeClosure() {
  41671. function NumberTree(root, xref) {
  41672. this.root = root;
  41673. this.xref = xref;
  41674. this._type = 'Nums';
  41675. }
  41676. Util.inherit(NumberTree, NameOrNumberTree, {});
  41677. return NumberTree;
  41678. })();
  41679. /**
  41680. * "A PDF file can refer to the contents of another file by using a File
  41681. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  41682. * NOTE: Only embedded files are supported (as part of the attachments support)
  41683. * TODO: support the 'URL' file system (with caching if !/V), portable
  41684. * collections attributes and related files (/RF)
  41685. */
  41686. var FileSpec = (function FileSpecClosure() {
  41687. function FileSpec(root, xref) {
  41688. if (!root || !isDict(root)) {
  41689. return;
  41690. }
  41691. this.xref = xref;
  41692. this.root = root;
  41693. if (root.has('FS')) {
  41694. this.fs = root.get('FS');
  41695. }
  41696. this.description = root.has('Desc') ?
  41697. stringToPDFString(root.get('Desc')) :
  41698. '';
  41699. if (root.has('RF')) {
  41700. warn('Related file specifications are not supported');
  41701. }
  41702. this.contentAvailable = true;
  41703. if (!root.has('EF')) {
  41704. this.contentAvailable = false;
  41705. warn('Non-embedded file specifications are not supported');
  41706. }
  41707. }
  41708. function pickPlatformItem(dict) {
  41709. // Look for the filename in this order:
  41710. // UF, F, Unix, Mac, DOS
  41711. if (dict.has('UF')) {
  41712. return dict.get('UF');
  41713. } else if (dict.has('F')) {
  41714. return dict.get('F');
  41715. } else if (dict.has('Unix')) {
  41716. return dict.get('Unix');
  41717. } else if (dict.has('Mac')) {
  41718. return dict.get('Mac');
  41719. } else if (dict.has('DOS')) {
  41720. return dict.get('DOS');
  41721. } else {
  41722. return null;
  41723. }
  41724. }
  41725. FileSpec.prototype = {
  41726. get filename() {
  41727. if (!this._filename && this.root) {
  41728. var filename = pickPlatformItem(this.root) || 'unnamed';
  41729. this._filename = stringToPDFString(filename).
  41730. replace(/\\\\/g, '\\').
  41731. replace(/\\\//g, '/').
  41732. replace(/\\/g, '/');
  41733. }
  41734. return this._filename;
  41735. },
  41736. get content() {
  41737. if (!this.contentAvailable) {
  41738. return null;
  41739. }
  41740. if (!this.contentRef && this.root) {
  41741. this.contentRef = pickPlatformItem(this.root.get('EF'));
  41742. }
  41743. var content = null;
  41744. if (this.contentRef) {
  41745. var xref = this.xref;
  41746. var fileObj = xref.fetchIfRef(this.contentRef);
  41747. if (fileObj && isStream(fileObj)) {
  41748. content = fileObj.getBytes();
  41749. } else {
  41750. warn('Embedded file specification points to non-existing/invalid ' +
  41751. 'content');
  41752. }
  41753. } else {
  41754. warn('Embedded file specification does not have a content');
  41755. }
  41756. return content;
  41757. },
  41758. get serializable() {
  41759. return {
  41760. filename: this.filename,
  41761. content: this.content
  41762. };
  41763. }
  41764. };
  41765. return FileSpec;
  41766. })();
  41767. /**
  41768. * A helper for loading missing data in object graphs. It traverses the graph
  41769. * depth first and queues up any objects that have missing data. Once it has
  41770. * has traversed as many objects that are available it attempts to bundle the
  41771. * missing data requests and then resume from the nodes that weren't ready.
  41772. *
  41773. * NOTE: It provides protection from circular references by keeping track of
  41774. * of loaded references. However, you must be careful not to load any graphs
  41775. * that have references to the catalog or other pages since that will cause the
  41776. * entire PDF document object graph to be traversed.
  41777. */
  41778. var ObjectLoader = (function() {
  41779. function mayHaveChildren(value) {
  41780. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  41781. }
  41782. function addChildren(node, nodesToVisit) {
  41783. var value;
  41784. if (isDict(node) || isStream(node)) {
  41785. var map;
  41786. if (isDict(node)) {
  41787. map = node.map;
  41788. } else {
  41789. map = node.dict.map;
  41790. }
  41791. for (var key in map) {
  41792. value = map[key];
  41793. if (mayHaveChildren(value)) {
  41794. nodesToVisit.push(value);
  41795. }
  41796. }
  41797. } else if (isArray(node)) {
  41798. for (var i = 0, ii = node.length; i < ii; i++) {
  41799. value = node[i];
  41800. if (mayHaveChildren(value)) {
  41801. nodesToVisit.push(value);
  41802. }
  41803. }
  41804. }
  41805. }
  41806. function ObjectLoader(obj, keys, xref) {
  41807. this.obj = obj;
  41808. this.keys = keys;
  41809. this.xref = xref;
  41810. this.refSet = null;
  41811. this.capability = null;
  41812. }
  41813. ObjectLoader.prototype = {
  41814. load: function ObjectLoader_load() {
  41815. var keys = this.keys;
  41816. this.capability = createPromiseCapability();
  41817. // Don't walk the graph if all the data is already loaded.
  41818. if (!(this.xref.stream instanceof ChunkedStream) ||
  41819. this.xref.stream.getMissingChunks().length === 0) {
  41820. this.capability.resolve();
  41821. return this.capability.promise;
  41822. }
  41823. this.refSet = new RefSet();
  41824. // Setup the initial nodes to visit.
  41825. var nodesToVisit = [];
  41826. for (var i = 0; i < keys.length; i++) {
  41827. nodesToVisit.push(this.obj[keys[i]]);
  41828. }
  41829. this._walk(nodesToVisit);
  41830. return this.capability.promise;
  41831. },
  41832. _walk: function ObjectLoader_walk(nodesToVisit) {
  41833. var nodesToRevisit = [];
  41834. var pendingRequests = [];
  41835. // DFS walk of the object graph.
  41836. while (nodesToVisit.length) {
  41837. var currentNode = nodesToVisit.pop();
  41838. // Only references or chunked streams can cause missing data exceptions.
  41839. if (isRef(currentNode)) {
  41840. // Skip nodes that have already been visited.
  41841. if (this.refSet.has(currentNode)) {
  41842. continue;
  41843. }
  41844. try {
  41845. var ref = currentNode;
  41846. this.refSet.put(ref);
  41847. currentNode = this.xref.fetch(currentNode);
  41848. } catch (e) {
  41849. if (!(e instanceof MissingDataException)) {
  41850. throw e;
  41851. }
  41852. nodesToRevisit.push(currentNode);
  41853. pendingRequests.push({ begin: e.begin, end: e.end });
  41854. }
  41855. }
  41856. if (currentNode && currentNode.getBaseStreams) {
  41857. var baseStreams = currentNode.getBaseStreams();
  41858. var foundMissingData = false;
  41859. for (var i = 0; i < baseStreams.length; i++) {
  41860. var stream = baseStreams[i];
  41861. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  41862. foundMissingData = true;
  41863. pendingRequests.push({
  41864. begin: stream.start,
  41865. end: stream.end
  41866. });
  41867. }
  41868. }
  41869. if (foundMissingData) {
  41870. nodesToRevisit.push(currentNode);
  41871. }
  41872. }
  41873. addChildren(currentNode, nodesToVisit);
  41874. }
  41875. if (pendingRequests.length) {
  41876. this.xref.stream.manager.requestRanges(pendingRequests).then(
  41877. function pendingRequestCallback() {
  41878. nodesToVisit = nodesToRevisit;
  41879. for (var i = 0; i < nodesToRevisit.length; i++) {
  41880. var node = nodesToRevisit[i];
  41881. // Remove any reference nodes from the currrent refset so they
  41882. // aren't skipped when we revist them.
  41883. if (isRef(node)) {
  41884. this.refSet.remove(node);
  41885. }
  41886. }
  41887. this._walk(nodesToVisit);
  41888. }.bind(this), this.capability.reject);
  41889. return;
  41890. }
  41891. // Everything is loaded.
  41892. this.refSet = null;
  41893. this.capability.resolve();
  41894. }
  41895. };
  41896. return ObjectLoader;
  41897. })();
  41898. exports.Catalog = Catalog;
  41899. exports.ObjectLoader = ObjectLoader;
  41900. exports.XRef = XRef;
  41901. exports.FileSpec = FileSpec;
  41902. }));
  41903. (function (root, factory) {
  41904. {
  41905. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  41906. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  41907. root.pdfjsCoreColorSpace);
  41908. }
  41909. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  41910. coreColorSpace) {
  41911. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41912. var MissingDataException = sharedUtil.MissingDataException;
  41913. var Util = sharedUtil.Util;
  41914. var assert = sharedUtil.assert;
  41915. var error = sharedUtil.error;
  41916. var info = sharedUtil.info;
  41917. var warn = sharedUtil.warn;
  41918. var isStream = corePrimitives.isStream;
  41919. var PDFFunction = coreFunction.PDFFunction;
  41920. var ColorSpace = coreColorSpace.ColorSpace;
  41921. var ShadingType = {
  41922. FUNCTION_BASED: 1,
  41923. AXIAL: 2,
  41924. RADIAL: 3,
  41925. FREE_FORM_MESH: 4,
  41926. LATTICE_FORM_MESH: 5,
  41927. COONS_PATCH_MESH: 6,
  41928. TENSOR_PATCH_MESH: 7
  41929. };
  41930. var Pattern = (function PatternClosure() {
  41931. // Constructor should define this.getPattern
  41932. function Pattern() {
  41933. error('should not call Pattern constructor');
  41934. }
  41935. Pattern.prototype = {
  41936. // Input: current Canvas context
  41937. // Output: the appropriate fillStyle or strokeStyle
  41938. getPattern: function Pattern_getPattern(ctx) {
  41939. error('Should not call Pattern.getStyle: ' + ctx);
  41940. }
  41941. };
  41942. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  41943. res, handler) {
  41944. var dict = isStream(shading) ? shading.dict : shading;
  41945. var type = dict.get('ShadingType');
  41946. try {
  41947. switch (type) {
  41948. case ShadingType.AXIAL:
  41949. case ShadingType.RADIAL:
  41950. // Both radial and axial shadings are handled by RadialAxial shading.
  41951. return new Shadings.RadialAxial(dict, matrix, xref, res);
  41952. case ShadingType.FREE_FORM_MESH:
  41953. case ShadingType.LATTICE_FORM_MESH:
  41954. case ShadingType.COONS_PATCH_MESH:
  41955. case ShadingType.TENSOR_PATCH_MESH:
  41956. return new Shadings.Mesh(shading, matrix, xref, res);
  41957. default:
  41958. throw new Error('Unsupported ShadingType: ' + type);
  41959. }
  41960. } catch (ex) {
  41961. if (ex instanceof MissingDataException) {
  41962. throw ex;
  41963. }
  41964. handler.send('UnsupportedFeature',
  41965. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  41966. warn(ex);
  41967. return new Shadings.Dummy();
  41968. }
  41969. };
  41970. return Pattern;
  41971. })();
  41972. var Shadings = {};
  41973. // A small number to offset the first/last color stops so we can insert ones to
  41974. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  41975. Shadings.SMALL_NUMBER = 1e-6;
  41976. // Radial and axial shading have very similar implementations
  41977. // If needed, the implementations can be broken into two classes
  41978. Shadings.RadialAxial = (function RadialAxialClosure() {
  41979. function RadialAxial(dict, matrix, xref, res) {
  41980. this.matrix = matrix;
  41981. this.coordsArr = dict.getArray('Coords');
  41982. this.shadingType = dict.get('ShadingType');
  41983. this.type = 'Pattern';
  41984. var cs = dict.get('ColorSpace', 'CS');
  41985. cs = ColorSpace.parse(cs, xref, res);
  41986. this.cs = cs;
  41987. var t0 = 0.0, t1 = 1.0;
  41988. if (dict.has('Domain')) {
  41989. var domainArr = dict.getArray('Domain');
  41990. t0 = domainArr[0];
  41991. t1 = domainArr[1];
  41992. }
  41993. var extendStart = false, extendEnd = false;
  41994. if (dict.has('Extend')) {
  41995. var extendArr = dict.getArray('Extend');
  41996. extendStart = extendArr[0];
  41997. extendEnd = extendArr[1];
  41998. }
  41999. if (this.shadingType === ShadingType.RADIAL &&
  42000. (!extendStart || !extendEnd)) {
  42001. // Radial gradient only currently works if either circle is fully within
  42002. // the other circle.
  42003. var x1 = this.coordsArr[0];
  42004. var y1 = this.coordsArr[1];
  42005. var r1 = this.coordsArr[2];
  42006. var x2 = this.coordsArr[3];
  42007. var y2 = this.coordsArr[4];
  42008. var r2 = this.coordsArr[5];
  42009. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  42010. if (r1 <= r2 + distance &&
  42011. r2 <= r1 + distance) {
  42012. warn('Unsupported radial gradient.');
  42013. }
  42014. }
  42015. this.extendStart = extendStart;
  42016. this.extendEnd = extendEnd;
  42017. var fnObj = dict.get('Function');
  42018. var fn = PDFFunction.parseArray(xref, fnObj);
  42019. // 10 samples seems good enough for now, but probably won't work
  42020. // if there are sharp color changes. Ideally, we would implement
  42021. // the spec faithfully and add lossless optimizations.
  42022. var diff = t1 - t0;
  42023. var step = diff / 10;
  42024. var colorStops = this.colorStops = [];
  42025. // Protect against bad domains so we don't end up in an infinte loop below.
  42026. if (t0 >= t1 || step <= 0) {
  42027. // Acrobat doesn't seem to handle these cases so we'll ignore for
  42028. // now.
  42029. info('Bad shading domain.');
  42030. return;
  42031. }
  42032. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  42033. var rgbColor;
  42034. for (var i = t0; i <= t1; i += step) {
  42035. ratio[0] = i;
  42036. fn(ratio, 0, color, 0);
  42037. rgbColor = cs.getRgb(color, 0);
  42038. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  42039. colorStops.push([(i - t0) / diff, cssColor]);
  42040. }
  42041. var background = 'transparent';
  42042. if (dict.has('Background')) {
  42043. rgbColor = cs.getRgb(dict.get('Background'), 0);
  42044. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  42045. }
  42046. if (!extendStart) {
  42047. // Insert a color stop at the front and offset the first real color stop
  42048. // so it doesn't conflict with the one we insert.
  42049. colorStops.unshift([0, background]);
  42050. colorStops[1][0] += Shadings.SMALL_NUMBER;
  42051. }
  42052. if (!extendEnd) {
  42053. // Same idea as above in extendStart but for the end.
  42054. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  42055. colorStops.push([1, background]);
  42056. }
  42057. this.colorStops = colorStops;
  42058. }
  42059. RadialAxial.prototype = {
  42060. getIR: function RadialAxial_getIR() {
  42061. var coordsArr = this.coordsArr;
  42062. var shadingType = this.shadingType;
  42063. var type, p0, p1, r0, r1;
  42064. if (shadingType === ShadingType.AXIAL) {
  42065. p0 = [coordsArr[0], coordsArr[1]];
  42066. p1 = [coordsArr[2], coordsArr[3]];
  42067. r0 = null;
  42068. r1 = null;
  42069. type = 'axial';
  42070. } else if (shadingType === ShadingType.RADIAL) {
  42071. p0 = [coordsArr[0], coordsArr[1]];
  42072. p1 = [coordsArr[3], coordsArr[4]];
  42073. r0 = coordsArr[2];
  42074. r1 = coordsArr[5];
  42075. type = 'radial';
  42076. } else {
  42077. error('getPattern type unknown: ' + shadingType);
  42078. }
  42079. var matrix = this.matrix;
  42080. if (matrix) {
  42081. p0 = Util.applyTransform(p0, matrix);
  42082. p1 = Util.applyTransform(p1, matrix);
  42083. if (shadingType === ShadingType.RADIAL) {
  42084. var scale = Util.singularValueDecompose2dScale(matrix);
  42085. r0 *= scale[0];
  42086. r1 *= scale[1];
  42087. }
  42088. }
  42089. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  42090. }
  42091. };
  42092. return RadialAxial;
  42093. })();
  42094. // All mesh shading. For now, they will be presented as set of the triangles
  42095. // to be drawn on the canvas and rgb color for each vertex.
  42096. Shadings.Mesh = (function MeshClosure() {
  42097. function MeshStreamReader(stream, context) {
  42098. this.stream = stream;
  42099. this.context = context;
  42100. this.buffer = 0;
  42101. this.bufferLength = 0;
  42102. var numComps = context.numComps;
  42103. this.tmpCompsBuf = new Float32Array(numComps);
  42104. var csNumComps = context.colorSpace.numComps;
  42105. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  42106. this.tmpCompsBuf;
  42107. }
  42108. MeshStreamReader.prototype = {
  42109. get hasData() {
  42110. if (this.stream.end) {
  42111. return this.stream.pos < this.stream.end;
  42112. }
  42113. if (this.bufferLength > 0) {
  42114. return true;
  42115. }
  42116. var nextByte = this.stream.getByte();
  42117. if (nextByte < 0) {
  42118. return false;
  42119. }
  42120. this.buffer = nextByte;
  42121. this.bufferLength = 8;
  42122. return true;
  42123. },
  42124. readBits: function MeshStreamReader_readBits(n) {
  42125. var buffer = this.buffer;
  42126. var bufferLength = this.bufferLength;
  42127. if (n === 32) {
  42128. if (bufferLength === 0) {
  42129. return ((this.stream.getByte() << 24) |
  42130. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  42131. this.stream.getByte()) >>> 0;
  42132. }
  42133. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  42134. (this.stream.getByte() << 8) | this.stream.getByte();
  42135. var nextByte = this.stream.getByte();
  42136. this.buffer = nextByte & ((1 << bufferLength) - 1);
  42137. return ((buffer << (8 - bufferLength)) |
  42138. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  42139. }
  42140. if (n === 8 && bufferLength === 0) {
  42141. return this.stream.getByte();
  42142. }
  42143. while (bufferLength < n) {
  42144. buffer = (buffer << 8) | this.stream.getByte();
  42145. bufferLength += 8;
  42146. }
  42147. bufferLength -= n;
  42148. this.bufferLength = bufferLength;
  42149. this.buffer = buffer & ((1 << bufferLength) - 1);
  42150. return buffer >> bufferLength;
  42151. },
  42152. align: function MeshStreamReader_align() {
  42153. this.buffer = 0;
  42154. this.bufferLength = 0;
  42155. },
  42156. readFlag: function MeshStreamReader_readFlag() {
  42157. return this.readBits(this.context.bitsPerFlag);
  42158. },
  42159. readCoordinate: function MeshStreamReader_readCoordinate() {
  42160. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  42161. var xi = this.readBits(bitsPerCoordinate);
  42162. var yi = this.readBits(bitsPerCoordinate);
  42163. var decode = this.context.decode;
  42164. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  42165. 2.3283064365386963e-10; // 2 ^ -32
  42166. return [
  42167. xi * scale * (decode[1] - decode[0]) + decode[0],
  42168. yi * scale * (decode[3] - decode[2]) + decode[2]
  42169. ];
  42170. },
  42171. readComponents: function MeshStreamReader_readComponents() {
  42172. var numComps = this.context.numComps;
  42173. var bitsPerComponent = this.context.bitsPerComponent;
  42174. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  42175. 2.3283064365386963e-10; // 2 ^ -32
  42176. var decode = this.context.decode;
  42177. var components = this.tmpCompsBuf;
  42178. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  42179. var ci = this.readBits(bitsPerComponent);
  42180. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  42181. }
  42182. var color = this.tmpCsCompsBuf;
  42183. if (this.context.colorFn) {
  42184. this.context.colorFn(components, 0, color, 0);
  42185. }
  42186. return this.context.colorSpace.getRgb(color, 0);
  42187. }
  42188. };
  42189. function decodeType4Shading(mesh, reader) {
  42190. var coords = mesh.coords;
  42191. var colors = mesh.colors;
  42192. var operators = [];
  42193. var ps = []; // not maintaining cs since that will match ps
  42194. var verticesLeft = 0; // assuming we have all data to start a new triangle
  42195. while (reader.hasData) {
  42196. var f = reader.readFlag();
  42197. var coord = reader.readCoordinate();
  42198. var color = reader.readComponents();
  42199. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  42200. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  42201. switch (f) {
  42202. case 0:
  42203. verticesLeft = 3;
  42204. break;
  42205. case 1:
  42206. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  42207. verticesLeft = 1;
  42208. break;
  42209. case 2:
  42210. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  42211. verticesLeft = 1;
  42212. break;
  42213. }
  42214. operators.push(f);
  42215. }
  42216. ps.push(coords.length);
  42217. coords.push(coord);
  42218. colors.push(color);
  42219. verticesLeft--;
  42220. reader.align();
  42221. }
  42222. mesh.figures.push({
  42223. type: 'triangles',
  42224. coords: new Int32Array(ps),
  42225. colors: new Int32Array(ps),
  42226. });
  42227. }
  42228. function decodeType5Shading(mesh, reader, verticesPerRow) {
  42229. var coords = mesh.coords;
  42230. var colors = mesh.colors;
  42231. var ps = []; // not maintaining cs since that will match ps
  42232. while (reader.hasData) {
  42233. var coord = reader.readCoordinate();
  42234. var color = reader.readComponents();
  42235. ps.push(coords.length);
  42236. coords.push(coord);
  42237. colors.push(color);
  42238. }
  42239. mesh.figures.push({
  42240. type: 'lattice',
  42241. coords: new Int32Array(ps),
  42242. colors: new Int32Array(ps),
  42243. verticesPerRow: verticesPerRow
  42244. });
  42245. }
  42246. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  42247. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  42248. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  42249. var getB = (function getBClosure() {
  42250. function buildB(count) {
  42251. var lut = [];
  42252. for (var i = 0; i <= count; i++) {
  42253. var t = i / count, t_ = 1 - t;
  42254. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  42255. 3 * t * t * t_, t * t * t]));
  42256. }
  42257. return lut;
  42258. }
  42259. var cache = [];
  42260. return function getB(count) {
  42261. if (!cache[count]) {
  42262. cache[count] = buildB(count);
  42263. }
  42264. return cache[count];
  42265. };
  42266. })();
  42267. function buildFigureFromPatch(mesh, index) {
  42268. var figure = mesh.figures[index];
  42269. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  42270. var coords = mesh.coords, colors = mesh.colors;
  42271. var pi = figure.coords;
  42272. var ci = figure.colors;
  42273. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  42274. coords[pi[12]][0], coords[pi[15]][0]);
  42275. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  42276. coords[pi[12]][1], coords[pi[15]][1]);
  42277. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  42278. coords[pi[12]][0], coords[pi[15]][0]);
  42279. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  42280. coords[pi[12]][1], coords[pi[15]][1]);
  42281. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  42282. (mesh.bounds[2] - mesh.bounds[0]));
  42283. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  42284. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  42285. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  42286. (mesh.bounds[3] - mesh.bounds[1]));
  42287. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  42288. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  42289. var verticesPerRow = splitXBy + 1;
  42290. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  42291. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  42292. var k = 0;
  42293. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  42294. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  42295. c2 = colors[ci[2]], c3 = colors[ci[3]];
  42296. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  42297. for (var row = 0; row <= splitYBy; row++) {
  42298. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  42299. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  42300. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  42301. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  42302. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  42303. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  42304. for (var col = 0; col <= splitXBy; col++, k++) {
  42305. if ((row === 0 || row === splitYBy) &&
  42306. (col === 0 || col === splitXBy)) {
  42307. continue;
  42308. }
  42309. var x = 0, y = 0;
  42310. var q = 0;
  42311. for (var i = 0; i <= 3; i++) {
  42312. for (var j = 0; j <= 3; j++, q++) {
  42313. var m = bRow[row][i] * bCol[col][j];
  42314. x += coords[pi[q]][0] * m;
  42315. y += coords[pi[q]][1] * m;
  42316. }
  42317. }
  42318. figureCoords[k] = coords.length;
  42319. coords.push([x, y]);
  42320. figureColors[k] = colors.length;
  42321. var newColor = new Uint8Array(3);
  42322. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  42323. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  42324. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  42325. colors.push(newColor);
  42326. }
  42327. }
  42328. figureCoords[0] = pi[0];
  42329. figureColors[0] = ci[0];
  42330. figureCoords[splitXBy] = pi[3];
  42331. figureColors[splitXBy] = ci[1];
  42332. figureCoords[verticesPerRow * splitYBy] = pi[12];
  42333. figureColors[verticesPerRow * splitYBy] = ci[2];
  42334. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  42335. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  42336. mesh.figures[index] = {
  42337. type: 'lattice',
  42338. coords: figureCoords,
  42339. colors: figureColors,
  42340. verticesPerRow: verticesPerRow
  42341. };
  42342. }
  42343. function decodeType6Shading(mesh, reader) {
  42344. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  42345. var coords = mesh.coords;
  42346. var colors = mesh.colors;
  42347. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  42348. var cs = new Int32Array(4); // c00, c30, c03, c33
  42349. while (reader.hasData) {
  42350. var f = reader.readFlag();
  42351. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  42352. var i, ii;
  42353. var pi = coords.length;
  42354. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  42355. coords.push(reader.readCoordinate());
  42356. }
  42357. var ci = colors.length;
  42358. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  42359. colors.push(reader.readComponents());
  42360. }
  42361. var tmp1, tmp2, tmp3, tmp4;
  42362. switch (f) {
  42363. case 0:
  42364. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  42365. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  42366. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  42367. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  42368. cs[2] = ci + 1; cs[3] = ci + 2;
  42369. cs[0] = ci; cs[1] = ci + 3;
  42370. break;
  42371. case 1:
  42372. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  42373. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42374. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42375. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  42376. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42377. tmp1 = cs[2]; tmp2 = cs[3];
  42378. cs[2] = tmp2; cs[3] = ci;
  42379. cs[0] = tmp1; cs[1] = ci + 1;
  42380. break;
  42381. case 2:
  42382. tmp1 = ps[15];
  42383. tmp2 = ps[11];
  42384. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42385. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42386. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  42387. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42388. tmp1 = cs[3];
  42389. cs[2] = cs[1]; cs[3] = ci;
  42390. cs[0] = tmp1; cs[1] = ci + 1;
  42391. break;
  42392. case 3:
  42393. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42394. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42395. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  42396. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42397. cs[2] = cs[0]; cs[3] = ci;
  42398. cs[0] = cs[1]; cs[1] = ci + 1;
  42399. break;
  42400. }
  42401. // set p11, p12, p21, p22
  42402. ps[5] = coords.length;
  42403. coords.push([
  42404. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  42405. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  42406. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  42407. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  42408. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  42409. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  42410. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  42411. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  42412. ]);
  42413. ps[6] = coords.length;
  42414. coords.push([
  42415. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  42416. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  42417. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  42418. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  42419. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  42420. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  42421. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  42422. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  42423. ]);
  42424. ps[9] = coords.length;
  42425. coords.push([
  42426. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  42427. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  42428. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  42429. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  42430. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  42431. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  42432. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  42433. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  42434. ]);
  42435. ps[10] = coords.length;
  42436. coords.push([
  42437. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  42438. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  42439. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  42440. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  42441. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  42442. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  42443. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  42444. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  42445. ]);
  42446. mesh.figures.push({
  42447. type: 'patch',
  42448. coords: new Int32Array(ps), // making copies of ps and cs
  42449. colors: new Int32Array(cs)
  42450. });
  42451. }
  42452. }
  42453. function decodeType7Shading(mesh, reader) {
  42454. var coords = mesh.coords;
  42455. var colors = mesh.colors;
  42456. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  42457. var cs = new Int32Array(4); // c00, c30, c03, c33
  42458. while (reader.hasData) {
  42459. var f = reader.readFlag();
  42460. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  42461. var i, ii;
  42462. var pi = coords.length;
  42463. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  42464. coords.push(reader.readCoordinate());
  42465. }
  42466. var ci = colors.length;
  42467. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  42468. colors.push(reader.readComponents());
  42469. }
  42470. var tmp1, tmp2, tmp3, tmp4;
  42471. switch (f) {
  42472. case 0:
  42473. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  42474. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  42475. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  42476. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  42477. cs[2] = ci + 1; cs[3] = ci + 2;
  42478. cs[0] = ci; cs[1] = ci + 3;
  42479. break;
  42480. case 1:
  42481. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  42482. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42483. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42484. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42485. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42486. tmp1 = cs[2]; tmp2 = cs[3];
  42487. cs[2] = tmp2; cs[3] = ci;
  42488. cs[0] = tmp1; cs[1] = ci + 1;
  42489. break;
  42490. case 2:
  42491. tmp1 = ps[15];
  42492. tmp2 = ps[11];
  42493. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42494. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42495. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42496. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42497. tmp1 = cs[3];
  42498. cs[2] = cs[1]; cs[3] = ci;
  42499. cs[0] = tmp1; cs[1] = ci + 1;
  42500. break;
  42501. case 3:
  42502. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42503. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42504. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42505. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42506. cs[2] = cs[0]; cs[3] = ci;
  42507. cs[0] = cs[1]; cs[1] = ci + 1;
  42508. break;
  42509. }
  42510. mesh.figures.push({
  42511. type: 'patch',
  42512. coords: new Int32Array(ps), // making copies of ps and cs
  42513. colors: new Int32Array(cs)
  42514. });
  42515. }
  42516. }
  42517. function updateBounds(mesh) {
  42518. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  42519. maxX = minX, maxY = minY;
  42520. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  42521. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  42522. minX = minX > x ? x : minX;
  42523. minY = minY > y ? y : minY;
  42524. maxX = maxX < x ? x : maxX;
  42525. maxY = maxY < y ? y : maxY;
  42526. }
  42527. mesh.bounds = [minX, minY, maxX, maxY];
  42528. }
  42529. function packData(mesh) {
  42530. var i, ii, j, jj;
  42531. var coords = mesh.coords;
  42532. var coordsPacked = new Float32Array(coords.length * 2);
  42533. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  42534. var xy = coords[i];
  42535. coordsPacked[j++] = xy[0];
  42536. coordsPacked[j++] = xy[1];
  42537. }
  42538. mesh.coords = coordsPacked;
  42539. var colors = mesh.colors;
  42540. var colorsPacked = new Uint8Array(colors.length * 3);
  42541. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  42542. var c = colors[i];
  42543. colorsPacked[j++] = c[0];
  42544. colorsPacked[j++] = c[1];
  42545. colorsPacked[j++] = c[2];
  42546. }
  42547. mesh.colors = colorsPacked;
  42548. var figures = mesh.figures;
  42549. for (i = 0, ii = figures.length; i < ii; i++) {
  42550. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  42551. for (j = 0, jj = ps.length; j < jj; j++) {
  42552. ps[j] *= 2;
  42553. cs[j] *= 3;
  42554. }
  42555. }
  42556. }
  42557. function Mesh(stream, matrix, xref, res) {
  42558. assert(isStream(stream), 'Mesh data is not a stream');
  42559. var dict = stream.dict;
  42560. this.matrix = matrix;
  42561. this.shadingType = dict.get('ShadingType');
  42562. this.type = 'Pattern';
  42563. this.bbox = dict.getArray('BBox');
  42564. var cs = dict.get('ColorSpace', 'CS');
  42565. cs = ColorSpace.parse(cs, xref, res);
  42566. this.cs = cs;
  42567. this.background = dict.has('Background') ?
  42568. cs.getRgb(dict.get('Background'), 0) : null;
  42569. var fnObj = dict.get('Function');
  42570. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  42571. this.coords = [];
  42572. this.colors = [];
  42573. this.figures = [];
  42574. var decodeContext = {
  42575. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  42576. bitsPerComponent: dict.get('BitsPerComponent'),
  42577. bitsPerFlag: dict.get('BitsPerFlag'),
  42578. decode: dict.getArray('Decode'),
  42579. colorFn: fn,
  42580. colorSpace: cs,
  42581. numComps: fn ? 1 : cs.numComps
  42582. };
  42583. var reader = new MeshStreamReader(stream, decodeContext);
  42584. var patchMesh = false;
  42585. switch (this.shadingType) {
  42586. case ShadingType.FREE_FORM_MESH:
  42587. decodeType4Shading(this, reader);
  42588. break;
  42589. case ShadingType.LATTICE_FORM_MESH:
  42590. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  42591. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  42592. decodeType5Shading(this, reader, verticesPerRow);
  42593. break;
  42594. case ShadingType.COONS_PATCH_MESH:
  42595. decodeType6Shading(this, reader);
  42596. patchMesh = true;
  42597. break;
  42598. case ShadingType.TENSOR_PATCH_MESH:
  42599. decodeType7Shading(this, reader);
  42600. patchMesh = true;
  42601. break;
  42602. default:
  42603. error('Unsupported mesh type.');
  42604. break;
  42605. }
  42606. if (patchMesh) {
  42607. // dirty bounds calculation for determining, how dense shall be triangles
  42608. updateBounds(this);
  42609. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  42610. buildFigureFromPatch(this, i);
  42611. }
  42612. }
  42613. // calculate bounds
  42614. updateBounds(this);
  42615. packData(this);
  42616. }
  42617. Mesh.prototype = {
  42618. getIR: function Mesh_getIR() {
  42619. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  42620. this.bounds, this.matrix, this.bbox, this.background];
  42621. }
  42622. };
  42623. return Mesh;
  42624. })();
  42625. Shadings.Dummy = (function DummyClosure() {
  42626. function Dummy() {
  42627. this.type = 'Pattern';
  42628. }
  42629. Dummy.prototype = {
  42630. getIR: function Dummy_getIR() {
  42631. return ['Dummy'];
  42632. }
  42633. };
  42634. return Dummy;
  42635. })();
  42636. function getTilingPatternIR(operatorList, dict, args) {
  42637. var matrix = dict.getArray('Matrix');
  42638. var bbox = dict.getArray('BBox');
  42639. var xstep = dict.get('XStep');
  42640. var ystep = dict.get('YStep');
  42641. var paintType = dict.get('PaintType');
  42642. var tilingType = dict.get('TilingType');
  42643. return [
  42644. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  42645. paintType, tilingType
  42646. ];
  42647. }
  42648. exports.Pattern = Pattern;
  42649. exports.getTilingPatternIR = getTilingPatternIR;
  42650. }));
  42651. (function (root, factory) {
  42652. {
  42653. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  42654. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  42655. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  42656. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  42657. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  42658. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  42659. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  42660. }
  42661. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  42662. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  42663. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  42664. coreEncodings, coreStandardFonts, coreUnicode,
  42665. coreGlyphList) {
  42666. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  42667. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  42668. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  42669. var ImageKind = sharedUtil.ImageKind;
  42670. var OPS = sharedUtil.OPS;
  42671. var TextRenderingMode = sharedUtil.TextRenderingMode;
  42672. var Util = sharedUtil.Util;
  42673. var assert = sharedUtil.assert;
  42674. var createPromiseCapability = sharedUtil.createPromiseCapability;
  42675. var error = sharedUtil.error;
  42676. var info = sharedUtil.info;
  42677. var isArray = sharedUtil.isArray;
  42678. var isNum = sharedUtil.isNum;
  42679. var isString = sharedUtil.isString;
  42680. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  42681. var warn = sharedUtil.warn;
  42682. var Dict = corePrimitives.Dict;
  42683. var Name = corePrimitives.Name;
  42684. var isCmd = corePrimitives.isCmd;
  42685. var isDict = corePrimitives.isDict;
  42686. var isName = corePrimitives.isName;
  42687. var isRef = corePrimitives.isRef;
  42688. var isStream = corePrimitives.isStream;
  42689. var DecodeStream = coreStream.DecodeStream;
  42690. var JpegStream = coreStream.JpegStream;
  42691. var Stream = coreStream.Stream;
  42692. var Lexer = coreParser.Lexer;
  42693. var Parser = coreParser.Parser;
  42694. var isEOF = coreParser.isEOF;
  42695. var PDFImage = coreImage.PDFImage;
  42696. var ColorSpace = coreColorSpace.ColorSpace;
  42697. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  42698. var ErrorFont = coreFonts.ErrorFont;
  42699. var FontFlags = coreFonts.FontFlags;
  42700. var Font = coreFonts.Font;
  42701. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  42702. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  42703. var getFontType = coreFonts.getFontType;
  42704. var isPDFFunction = coreFunction.isPDFFunction;
  42705. var PDFFunction = coreFunction.PDFFunction;
  42706. var Pattern = corePattern.Pattern;
  42707. var getTilingPatternIR = corePattern.getTilingPatternIR;
  42708. var CMapFactory = coreCMap.CMapFactory;
  42709. var IdentityCMap = coreCMap.IdentityCMap;
  42710. var getMetrics = coreMetrics.getMetrics;
  42711. var bidi = coreBidi.bidi;
  42712. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  42713. var StandardEncoding = coreEncodings.StandardEncoding;
  42714. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  42715. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  42716. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  42717. var getEncoding = coreEncodings.getEncoding;
  42718. var getStdFontMap = coreStandardFonts.getStdFontMap;
  42719. var getSerifFonts = coreStandardFonts.getSerifFonts;
  42720. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  42721. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  42722. var reverseIfRtl = coreUnicode.reverseIfRtl;
  42723. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  42724. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  42725. var PartialEvaluator = (function PartialEvaluatorClosure() {
  42726. var DefaultPartialEvaluatorOptions = {
  42727. forceDataSchema: false,
  42728. maxImageSize: -1,
  42729. disableFontFace: false,
  42730. cMapOptions: { url: null, packed: false }
  42731. };
  42732. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  42733. this.xref = xref;
  42734. this.resources = resources;
  42735. this.handler = handler;
  42736. this.forceDataSchema = forceDataSchema;
  42737. }
  42738. NativeImageDecoder.prototype = {
  42739. canDecode: function (image) {
  42740. return image instanceof JpegStream &&
  42741. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  42742. },
  42743. decode: function (image) {
  42744. // For natively supported JPEGs send them to the main thread for decoding.
  42745. var dict = image.dict;
  42746. var colorSpace = dict.get('ColorSpace', 'CS');
  42747. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  42748. var numComps = colorSpace.numComps;
  42749. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  42750. [image.getIR(this.forceDataSchema), numComps]);
  42751. return decodePromise.then(function (message) {
  42752. var data = message.data;
  42753. return new Stream(data, 0, data.length, image.dict);
  42754. });
  42755. }
  42756. };
  42757. /**
  42758. * Checks if the image can be decoded and displayed by the browser without any
  42759. * further processing such as color space conversions.
  42760. */
  42761. NativeImageDecoder.isSupported =
  42762. function NativeImageDecoder_isSupported(image, xref, res) {
  42763. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  42764. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  42765. cs.isDefaultDecode(image.dict.getArray('Decode', 'D'));
  42766. };
  42767. /**
  42768. * Checks if the image can be decoded by the browser.
  42769. */
  42770. NativeImageDecoder.isDecodable =
  42771. function NativeImageDecoder_isDecodable(image, xref, res) {
  42772. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  42773. return (cs.numComps === 1 || cs.numComps === 3) &&
  42774. cs.isDefaultDecode(image.dict.getArray('Decode', 'D'));
  42775. };
  42776. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  42777. uniquePrefix, idCounters, fontCache, options) {
  42778. this.pdfManager = pdfManager;
  42779. this.xref = xref;
  42780. this.handler = handler;
  42781. this.pageIndex = pageIndex;
  42782. this.uniquePrefix = uniquePrefix;
  42783. this.idCounters = idCounters;
  42784. this.fontCache = fontCache;
  42785. this.options = options || DefaultPartialEvaluatorOptions;
  42786. }
  42787. // Trying to minimize Date.now() usage and check every 100 time
  42788. var TIME_SLOT_DURATION_MS = 20;
  42789. var CHECK_TIME_EVERY = 100;
  42790. function TimeSlotManager() {
  42791. this.reset();
  42792. }
  42793. TimeSlotManager.prototype = {
  42794. check: function TimeSlotManager_check() {
  42795. if (++this.checked < CHECK_TIME_EVERY) {
  42796. return false;
  42797. }
  42798. this.checked = 0;
  42799. return this.endTime <= Date.now();
  42800. },
  42801. reset: function TimeSlotManager_reset() {
  42802. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  42803. this.checked = 0;
  42804. }
  42805. };
  42806. var deferred = Promise.resolve();
  42807. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  42808. PartialEvaluator.prototype = {
  42809. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  42810. if (!isDict(resources)) {
  42811. return false;
  42812. }
  42813. var processed = Object.create(null);
  42814. if (resources.objId) {
  42815. processed[resources.objId] = true;
  42816. }
  42817. var nodes = [resources], xref = this.xref;
  42818. while (nodes.length) {
  42819. var key, i, ii;
  42820. var node = nodes.shift();
  42821. // First check the current resources for blend modes.
  42822. var graphicStates = node.get('ExtGState');
  42823. if (isDict(graphicStates)) {
  42824. var graphicStatesKeys = graphicStates.getKeys();
  42825. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  42826. key = graphicStatesKeys[i];
  42827. var graphicState = graphicStates.get(key);
  42828. var bm = graphicState.get('BM');
  42829. if (isName(bm) && bm.name !== 'Normal') {
  42830. return true;
  42831. }
  42832. }
  42833. }
  42834. // Descend into the XObjects to look for more resources and blend modes.
  42835. var xObjects = node.get('XObject');
  42836. if (!isDict(xObjects)) {
  42837. continue;
  42838. }
  42839. var xObjectsKeys = xObjects.getKeys();
  42840. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  42841. key = xObjectsKeys[i];
  42842. var xObject = xObjects.getRaw(key);
  42843. if (isRef(xObject)) {
  42844. if (processed[xObject.toString()]) {
  42845. // The XObject has already been processed, and by avoiding a
  42846. // redundant `xref.fetch` we can *significantly* reduce the load
  42847. // time for badly generated PDF files (fixes issue6961.pdf).
  42848. continue;
  42849. }
  42850. xObject = xref.fetch(xObject);
  42851. }
  42852. if (!isStream(xObject)) {
  42853. continue;
  42854. }
  42855. if (xObject.dict.objId) {
  42856. if (processed[xObject.dict.objId]) {
  42857. // stream has objId and is processed already
  42858. continue;
  42859. }
  42860. processed[xObject.dict.objId] = true;
  42861. }
  42862. var xResources = xObject.dict.get('Resources');
  42863. // Checking objId to detect an infinite loop.
  42864. if (isDict(xResources) &&
  42865. (!xResources.objId || !processed[xResources.objId])) {
  42866. nodes.push(xResources);
  42867. if (xResources.objId) {
  42868. processed[xResources.objId] = true;
  42869. }
  42870. }
  42871. }
  42872. }
  42873. return false;
  42874. },
  42875. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  42876. xobj, smask,
  42877. operatorList,
  42878. task,
  42879. initialState) {
  42880. var matrix = xobj.dict.getArray('Matrix');
  42881. var bbox = xobj.dict.getArray('BBox');
  42882. var group = xobj.dict.get('Group');
  42883. if (group) {
  42884. var groupOptions = {
  42885. matrix: matrix,
  42886. bbox: bbox,
  42887. smask: smask,
  42888. isolated: false,
  42889. knockout: false
  42890. };
  42891. var groupSubtype = group.get('S');
  42892. var colorSpace;
  42893. if (isName(groupSubtype, 'Transparency')) {
  42894. groupOptions.isolated = (group.get('I') || false);
  42895. groupOptions.knockout = (group.get('K') || false);
  42896. colorSpace = (group.has('CS') ?
  42897. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  42898. }
  42899. if (smask && smask.backdrop) {
  42900. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  42901. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  42902. }
  42903. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  42904. }
  42905. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  42906. return this.getOperatorList(xobj, task,
  42907. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  42908. then(function () {
  42909. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  42910. if (group) {
  42911. operatorList.addOp(OPS.endGroup, [groupOptions]);
  42912. }
  42913. });
  42914. },
  42915. buildPaintImageXObject:
  42916. function PartialEvaluator_buildPaintImageXObject(resources, image,
  42917. inline, operatorList,
  42918. cacheKey, imageCache) {
  42919. var self = this;
  42920. var dict = image.dict;
  42921. var w = dict.get('Width', 'W');
  42922. var h = dict.get('Height', 'H');
  42923. if (!(w && isNum(w)) || !(h && isNum(h))) {
  42924. warn('Image dimensions are missing, or not numbers.');
  42925. return;
  42926. }
  42927. var maxImageSize = this.options.maxImageSize;
  42928. if (maxImageSize !== -1 && w * h > maxImageSize) {
  42929. warn('Image exceeded maximum allowed size and was removed.');
  42930. return;
  42931. }
  42932. var imageMask = (dict.get('ImageMask', 'IM') || false);
  42933. var imgData, args;
  42934. if (imageMask) {
  42935. // This depends on a tmpCanvas being filled with the
  42936. // current fillStyle, such that processing the pixel
  42937. // data can't be done here. Instead of creating a
  42938. // complete PDFImage, only read the information needed
  42939. // for later.
  42940. var width = dict.get('Width', 'W');
  42941. var height = dict.get('Height', 'H');
  42942. var bitStrideLength = (width + 7) >> 3;
  42943. var imgArray = image.getBytes(bitStrideLength * height);
  42944. var decode = dict.getArray('Decode', 'D');
  42945. var inverseDecode = (!!decode && decode[0] > 0);
  42946. imgData = PDFImage.createMask(imgArray, width, height,
  42947. image instanceof DecodeStream,
  42948. inverseDecode);
  42949. imgData.cached = true;
  42950. args = [imgData];
  42951. operatorList.addOp(OPS.paintImageMaskXObject, args);
  42952. if (cacheKey) {
  42953. imageCache[cacheKey] = {
  42954. fn: OPS.paintImageMaskXObject,
  42955. args: args
  42956. };
  42957. }
  42958. return;
  42959. }
  42960. var softMask = (dict.get('SMask', 'SM') || false);
  42961. var mask = (dict.get('Mask') || false);
  42962. var SMALL_IMAGE_DIMENSIONS = 200;
  42963. // Inlining small images into the queue as RGB data
  42964. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  42965. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  42966. var imageObj = new PDFImage(this.xref, resources, image,
  42967. inline, null, null);
  42968. // We force the use of RGBA_32BPP images here, because we can't handle
  42969. // any other kind.
  42970. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  42971. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  42972. return;
  42973. }
  42974. // If there is no imageMask, create the PDFImage and a lot
  42975. // of image processing can be done here.
  42976. var uniquePrefix = (this.uniquePrefix || '');
  42977. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  42978. operatorList.addDependency(objId);
  42979. args = [objId, w, h];
  42980. if (!softMask && !mask && image instanceof JpegStream &&
  42981. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  42982. // These JPEGs don't need any more processing so we can just send it.
  42983. operatorList.addOp(OPS.paintJpegXObject, args);
  42984. this.handler.send('obj',
  42985. [objId, this.pageIndex, 'JpegStream',
  42986. image.getIR(this.options.forceDataSchema)]);
  42987. return;
  42988. }
  42989. // Creates native image decoder only if a JPEG image or mask is present.
  42990. var nativeImageDecoder = null;
  42991. if (image instanceof JpegStream || mask instanceof JpegStream ||
  42992. softMask instanceof JpegStream) {
  42993. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  42994. self.handler, self.options.forceDataSchema);
  42995. }
  42996. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  42997. nativeImageDecoder).
  42998. then(function(imageObj) {
  42999. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  43000. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  43001. [imgData.data.buffer]);
  43002. }).then(undefined, function (reason) {
  43003. warn('Unable to decode image: ' + reason);
  43004. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  43005. });
  43006. operatorList.addOp(OPS.paintImageXObject, args);
  43007. if (cacheKey) {
  43008. imageCache[cacheKey] = {
  43009. fn: OPS.paintImageXObject,
  43010. args: args
  43011. };
  43012. }
  43013. },
  43014. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  43015. operatorList, task,
  43016. stateManager) {
  43017. var smaskContent = smask.get('G');
  43018. var smaskOptions = {
  43019. subtype: smask.get('S').name,
  43020. backdrop: smask.get('BC')
  43021. };
  43022. // The SMask might have a alpha/luminosity value transfer function --
  43023. // we will build a map of integer values in range 0..255 to be fast.
  43024. var transferObj = smask.get('TR');
  43025. if (isPDFFunction(transferObj)) {
  43026. var transferFn = PDFFunction.parse(this.xref, transferObj);
  43027. var transferMap = new Uint8Array(256);
  43028. var tmp = new Float32Array(1);
  43029. for (var i = 0; i < 256; i++) {
  43030. tmp[0] = i / 255;
  43031. transferFn(tmp, 0, tmp, 0);
  43032. transferMap[i] = (tmp[0] * 255) | 0;
  43033. }
  43034. smaskOptions.transferMap = transferMap;
  43035. }
  43036. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  43037. operatorList, task, stateManager.state.clone());
  43038. },
  43039. handleTilingType:
  43040. function PartialEvaluator_handleTilingType(fn, args, resources,
  43041. pattern, patternDict,
  43042. operatorList, task) {
  43043. // Create an IR of the pattern code.
  43044. var tilingOpList = new OperatorList();
  43045. // Merge the available resources, to prevent issues when the patternDict
  43046. // is missing some /Resources entries (fixes issue6541.pdf).
  43047. var resourcesArray = [patternDict.get('Resources'), resources];
  43048. var patternResources = Dict.merge(this.xref, resourcesArray);
  43049. return this.getOperatorList(pattern, task, patternResources,
  43050. tilingOpList).then(function () {
  43051. // Add the dependencies to the parent operator list so they are
  43052. // resolved before sub operator list is executed synchronously.
  43053. operatorList.addDependencies(tilingOpList.dependencies);
  43054. operatorList.addOp(fn, getTilingPatternIR({
  43055. fnArray: tilingOpList.fnArray,
  43056. argsArray: tilingOpList.argsArray
  43057. }, patternDict, args));
  43058. });
  43059. },
  43060. handleSetFont:
  43061. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  43062. operatorList, task, state) {
  43063. // TODO(mack): Not needed?
  43064. var fontName;
  43065. if (fontArgs) {
  43066. fontArgs = fontArgs.slice();
  43067. fontName = fontArgs[0].name;
  43068. }
  43069. var self = this;
  43070. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  43071. function (translated) {
  43072. if (!translated.font.isType3Font) {
  43073. return translated;
  43074. }
  43075. return translated.loadType3Data(self, resources, operatorList, task).
  43076. then(function () {
  43077. return translated;
  43078. }, function (reason) {
  43079. // Error in the font data -- sending unsupported feature notification.
  43080. self.handler.send('UnsupportedFeature',
  43081. {featureId: UNSUPPORTED_FEATURES.font});
  43082. return new TranslatedFont('g_font_error',
  43083. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  43084. });
  43085. }).then(function (translated) {
  43086. state.font = translated.font;
  43087. translated.send(self.handler);
  43088. return translated.loadedName;
  43089. });
  43090. },
  43091. handleText: function PartialEvaluator_handleText(chars, state) {
  43092. var font = state.font;
  43093. var glyphs = font.charsToGlyphs(chars);
  43094. var isAddToPathSet = !!(state.textRenderingMode &
  43095. TextRenderingMode.ADD_TO_PATH_FLAG);
  43096. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  43097. var buildPath = function (fontChar) {
  43098. if (!font.renderer.hasBuiltPath(fontChar)) {
  43099. var path = font.renderer.getPathJs(fontChar);
  43100. this.handler.send('commonobj', [
  43101. font.loadedName + '_path_' + fontChar,
  43102. 'FontPath',
  43103. path
  43104. ]);
  43105. }
  43106. }.bind(this);
  43107. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  43108. var glyph = glyphs[i];
  43109. buildPath(glyph.fontChar);
  43110. // If the glyph has an accent we need to build a path for its
  43111. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  43112. var accent = glyph.accent;
  43113. if (accent && accent.fontChar) {
  43114. buildPath(accent.fontChar);
  43115. }
  43116. }
  43117. }
  43118. return glyphs;
  43119. },
  43120. setGState: function PartialEvaluator_setGState(resources, gState,
  43121. operatorList, task,
  43122. xref, stateManager) {
  43123. // This array holds the converted/processed state data.
  43124. var gStateObj = [];
  43125. var gStateKeys = gState.getKeys();
  43126. var self = this;
  43127. var promise = Promise.resolve();
  43128. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  43129. var key = gStateKeys[i];
  43130. var value = gState.get(key);
  43131. switch (key) {
  43132. case 'Type':
  43133. break;
  43134. case 'LW':
  43135. case 'LC':
  43136. case 'LJ':
  43137. case 'ML':
  43138. case 'D':
  43139. case 'RI':
  43140. case 'FL':
  43141. case 'CA':
  43142. case 'ca':
  43143. gStateObj.push([key, value]);
  43144. break;
  43145. case 'Font':
  43146. promise = promise.then(function () {
  43147. return self.handleSetFont(resources, null, value[0], operatorList,
  43148. task, stateManager.state).
  43149. then(function (loadedName) {
  43150. operatorList.addDependency(loadedName);
  43151. gStateObj.push([key, [loadedName, value[1]]]);
  43152. });
  43153. });
  43154. break;
  43155. case 'BM':
  43156. gStateObj.push([key, value]);
  43157. break;
  43158. case 'SMask':
  43159. if (isName(value, 'None')) {
  43160. gStateObj.push([key, false]);
  43161. break;
  43162. }
  43163. if (isDict(value)) {
  43164. promise = promise.then(function (dict) {
  43165. return self.handleSMask(dict, resources, operatorList,
  43166. task, stateManager);
  43167. }.bind(this, value));
  43168. gStateObj.push([key, true]);
  43169. } else {
  43170. warn('Unsupported SMask type');
  43171. }
  43172. break;
  43173. // Only generate info log messages for the following since
  43174. // they are unlikely to have a big impact on the rendering.
  43175. case 'OP':
  43176. case 'op':
  43177. case 'OPM':
  43178. case 'BG':
  43179. case 'BG2':
  43180. case 'UCR':
  43181. case 'UCR2':
  43182. case 'TR':
  43183. case 'TR2':
  43184. case 'HT':
  43185. case 'SM':
  43186. case 'SA':
  43187. case 'AIS':
  43188. case 'TK':
  43189. // TODO implement these operators.
  43190. info('graphic state operator ' + key);
  43191. break;
  43192. default:
  43193. info('Unknown graphic state operator ' + key);
  43194. break;
  43195. }
  43196. }
  43197. return promise.then(function () {
  43198. if (gStateObj.length > 0) {
  43199. operatorList.addOp(OPS.setGState, [gStateObj]);
  43200. }
  43201. });
  43202. },
  43203. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  43204. resources) {
  43205. function errorFont() {
  43206. return Promise.resolve(new TranslatedFont('g_font_error',
  43207. new ErrorFont('Font ' + fontName + ' is not available'), font));
  43208. }
  43209. var fontRef;
  43210. if (font) { // Loading by ref.
  43211. assert(isRef(font));
  43212. fontRef = font;
  43213. } else { // Loading by name.
  43214. var fontRes = resources.get('Font');
  43215. if (fontRes) {
  43216. fontRef = fontRes.getRaw(fontName);
  43217. } else {
  43218. warn('fontRes not available');
  43219. return errorFont();
  43220. }
  43221. }
  43222. if (!fontRef) {
  43223. warn('fontRef not available');
  43224. return errorFont();
  43225. }
  43226. if (this.fontCache.has(fontRef)) {
  43227. return this.fontCache.get(fontRef);
  43228. }
  43229. font = xref.fetchIfRef(fontRef);
  43230. if (!isDict(font)) {
  43231. return errorFont();
  43232. }
  43233. // We are holding `font.translated` references just for `fontRef`s that
  43234. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  43235. if (font.translated) {
  43236. return font.translated;
  43237. }
  43238. var fontCapability = createPromiseCapability();
  43239. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  43240. var descriptor = preEvaluatedFont.descriptor;
  43241. var fontRefIsRef = isRef(fontRef), fontID;
  43242. if (fontRefIsRef) {
  43243. fontID = fontRef.toString();
  43244. }
  43245. if (isDict(descriptor)) {
  43246. if (!descriptor.fontAliases) {
  43247. descriptor.fontAliases = Object.create(null);
  43248. }
  43249. var fontAliases = descriptor.fontAliases;
  43250. var hash = preEvaluatedFont.hash;
  43251. if (fontAliases[hash]) {
  43252. var aliasFontRef = fontAliases[hash].aliasRef;
  43253. if (fontRefIsRef && aliasFontRef &&
  43254. this.fontCache.has(aliasFontRef)) {
  43255. this.fontCache.putAlias(fontRef, aliasFontRef);
  43256. return this.fontCache.get(fontRef);
  43257. }
  43258. } else {
  43259. fontAliases[hash] = {
  43260. fontID: Font.getFontID()
  43261. };
  43262. }
  43263. if (fontRefIsRef) {
  43264. fontAliases[hash].aliasRef = fontRef;
  43265. }
  43266. fontID = fontAliases[hash].fontID;
  43267. }
  43268. // Workaround for bad PDF generators that reference fonts incorrectly,
  43269. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  43270. // In this case we should not put the font into `this.fontCache` (which is
  43271. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  43272. //
  43273. // However, if we don't cache the font it's not possible to remove it
  43274. // when `cleanup` is triggered from the API, which causes issues on
  43275. // subsequent rendering operations (see issue7403.pdf).
  43276. // A simple workaround would be to just not hold `font.translated`
  43277. // references in this case, but this would force us to unnecessarily load
  43278. // the same fonts over and over.
  43279. //
  43280. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  43281. // key in `this.fontCache`, to allow the font to be cached.
  43282. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  43283. // keys. Also, since `fontRef` is used when getting cached fonts,
  43284. // we'll not accidentally match fonts cached with the `fontID`.
  43285. if (fontRefIsRef) {
  43286. this.fontCache.put(fontRef, fontCapability.promise);
  43287. } else {
  43288. if (!fontID) {
  43289. fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
  43290. }
  43291. this.fontCache.put('id_' + fontID, fontCapability.promise);
  43292. }
  43293. assert(fontID, 'The "fontID" must be defined.');
  43294. // Keep track of each font we translated so the caller can
  43295. // load them asynchronously before calling display on a page.
  43296. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  43297. font.translated = fontCapability.promise;
  43298. // TODO move promises into translate font
  43299. var translatedPromise;
  43300. try {
  43301. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  43302. } catch (e) {
  43303. translatedPromise = Promise.reject(e);
  43304. }
  43305. var self = this;
  43306. translatedPromise.then(function (translatedFont) {
  43307. if (translatedFont.fontType !== undefined) {
  43308. var xrefFontStats = xref.stats.fontTypes;
  43309. xrefFontStats[translatedFont.fontType] = true;
  43310. }
  43311. fontCapability.resolve(new TranslatedFont(font.loadedName,
  43312. translatedFont, font));
  43313. }, function (reason) {
  43314. // TODO fontCapability.reject?
  43315. // Error in the font data -- sending unsupported feature notification.
  43316. self.handler.send('UnsupportedFeature',
  43317. {featureId: UNSUPPORTED_FEATURES.font});
  43318. try {
  43319. // error, but it's still nice to have font type reported
  43320. var descriptor = preEvaluatedFont.descriptor;
  43321. var fontFile3 = descriptor && descriptor.get('FontFile3');
  43322. var subtype = fontFile3 && fontFile3.get('Subtype');
  43323. var fontType = getFontType(preEvaluatedFont.type,
  43324. subtype && subtype.name);
  43325. var xrefFontStats = xref.stats.fontTypes;
  43326. xrefFontStats[fontType] = true;
  43327. } catch (ex) { }
  43328. fontCapability.resolve(new TranslatedFont(font.loadedName,
  43329. new ErrorFont(reason instanceof Error ? reason.message : reason),
  43330. font));
  43331. });
  43332. return fontCapability.promise;
  43333. },
  43334. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  43335. var lastIndex = operatorList.length - 1;
  43336. if (!args) {
  43337. args = [];
  43338. }
  43339. if (lastIndex < 0 ||
  43340. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  43341. operatorList.addOp(OPS.constructPath, [[fn], args]);
  43342. } else {
  43343. var opArgs = operatorList.argsArray[lastIndex];
  43344. opArgs[0].push(fn);
  43345. Array.prototype.push.apply(opArgs[1], args);
  43346. }
  43347. },
  43348. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  43349. cs, patterns, resources, task, xref) {
  43350. // compile tiling patterns
  43351. var patternName = args[args.length - 1];
  43352. // SCN/scn applies patterns along with normal colors
  43353. var pattern;
  43354. if (isName(patternName) &&
  43355. (pattern = patterns.get(patternName.name))) {
  43356. var dict = (isStream(pattern) ? pattern.dict : pattern);
  43357. var typeNum = dict.get('PatternType');
  43358. if (typeNum === TILING_PATTERN) {
  43359. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  43360. return this.handleTilingType(fn, color, resources, pattern,
  43361. dict, operatorList, task);
  43362. } else if (typeNum === SHADING_PATTERN) {
  43363. var shading = dict.get('Shading');
  43364. var matrix = dict.getArray('Matrix');
  43365. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  43366. this.handler);
  43367. operatorList.addOp(fn, pattern.getIR());
  43368. return Promise.resolve();
  43369. } else {
  43370. return Promise.reject('Unknown PatternType: ' + typeNum);
  43371. }
  43372. }
  43373. // TODO shall we fail here?
  43374. operatorList.addOp(fn, args);
  43375. return Promise.resolve();
  43376. },
  43377. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  43378. task,
  43379. resources,
  43380. operatorList,
  43381. initialState) {
  43382. var self = this;
  43383. var xref = this.xref;
  43384. var imageCache = Object.create(null);
  43385. assert(operatorList);
  43386. resources = (resources || Dict.empty);
  43387. var xobjs = (resources.get('XObject') || Dict.empty);
  43388. var patterns = (resources.get('Pattern') || Dict.empty);
  43389. var stateManager = new StateManager(initialState || new EvalState());
  43390. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  43391. var timeSlotManager = new TimeSlotManager();
  43392. return new Promise(function promiseBody(resolve, reject) {
  43393. var next = function (promise) {
  43394. promise.then(function () {
  43395. try {
  43396. promiseBody(resolve, reject);
  43397. } catch (ex) {
  43398. reject(ex);
  43399. }
  43400. }, reject);
  43401. };
  43402. task.ensureNotTerminated();
  43403. timeSlotManager.reset();
  43404. var stop, operation = {}, i, ii, cs;
  43405. while (!(stop = timeSlotManager.check())) {
  43406. // The arguments parsed by read() are used beyond this loop, so we
  43407. // cannot reuse the same array on each iteration. Therefore we pass
  43408. // in |null| as the initial value (see the comment on
  43409. // EvaluatorPreprocessor_read() for why).
  43410. operation.args = null;
  43411. if (!(preprocessor.read(operation))) {
  43412. break;
  43413. }
  43414. var args = operation.args;
  43415. var fn = operation.fn;
  43416. switch (fn | 0) {
  43417. case OPS.paintXObject:
  43418. if (args[0].code) {
  43419. break;
  43420. }
  43421. // eagerly compile XForm objects
  43422. var name = args[0].name;
  43423. if (!name) {
  43424. warn('XObject must be referred to by name.');
  43425. continue;
  43426. }
  43427. if (imageCache[name] !== undefined) {
  43428. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  43429. args = null;
  43430. continue;
  43431. }
  43432. var xobj = xobjs.get(name);
  43433. if (xobj) {
  43434. assert(isStream(xobj), 'XObject should be a stream');
  43435. var type = xobj.dict.get('Subtype');
  43436. assert(isName(type), 'XObject should have a Name subtype');
  43437. if (type.name === 'Form') {
  43438. stateManager.save();
  43439. next(self.buildFormXObject(resources, xobj, null,
  43440. operatorList, task,
  43441. stateManager.state.clone()).
  43442. then(function () {
  43443. stateManager.restore();
  43444. }));
  43445. return;
  43446. } else if (type.name === 'Image') {
  43447. self.buildPaintImageXObject(resources, xobj, false,
  43448. operatorList, name, imageCache);
  43449. args = null;
  43450. continue;
  43451. } else if (type.name === 'PS') {
  43452. // PostScript XObjects are unused when viewing documents.
  43453. // See section 4.7.1 of Adobe's PDF reference.
  43454. info('Ignored XObject subtype PS');
  43455. continue;
  43456. } else {
  43457. error('Unhandled XObject subtype ' + type.name);
  43458. }
  43459. }
  43460. break;
  43461. case OPS.setFont:
  43462. var fontSize = args[1];
  43463. // eagerly collect all fonts
  43464. next(self.handleSetFont(resources, args, null, operatorList,
  43465. task, stateManager.state).
  43466. then(function (loadedName) {
  43467. operatorList.addDependency(loadedName);
  43468. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  43469. }));
  43470. return;
  43471. case OPS.endInlineImage:
  43472. var cacheKey = args[0].cacheKey;
  43473. if (cacheKey) {
  43474. var cacheEntry = imageCache[cacheKey];
  43475. if (cacheEntry !== undefined) {
  43476. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  43477. args = null;
  43478. continue;
  43479. }
  43480. }
  43481. self.buildPaintImageXObject(resources, args[0], true,
  43482. operatorList, cacheKey, imageCache);
  43483. args = null;
  43484. continue;
  43485. case OPS.showText:
  43486. args[0] = self.handleText(args[0], stateManager.state);
  43487. break;
  43488. case OPS.showSpacedText:
  43489. var arr = args[0];
  43490. var combinedGlyphs = [];
  43491. var arrLength = arr.length;
  43492. var state = stateManager.state;
  43493. for (i = 0; i < arrLength; ++i) {
  43494. var arrItem = arr[i];
  43495. if (isString(arrItem)) {
  43496. Array.prototype.push.apply(combinedGlyphs,
  43497. self.handleText(arrItem, state));
  43498. } else if (isNum(arrItem)) {
  43499. combinedGlyphs.push(arrItem);
  43500. }
  43501. }
  43502. args[0] = combinedGlyphs;
  43503. fn = OPS.showText;
  43504. break;
  43505. case OPS.nextLineShowText:
  43506. operatorList.addOp(OPS.nextLine);
  43507. args[0] = self.handleText(args[0], stateManager.state);
  43508. fn = OPS.showText;
  43509. break;
  43510. case OPS.nextLineSetSpacingShowText:
  43511. operatorList.addOp(OPS.nextLine);
  43512. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  43513. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  43514. args[0] = self.handleText(args[0], stateManager.state);
  43515. fn = OPS.showText;
  43516. break;
  43517. case OPS.setTextRenderingMode:
  43518. stateManager.state.textRenderingMode = args[0];
  43519. break;
  43520. case OPS.setFillColorSpace:
  43521. stateManager.state.fillColorSpace =
  43522. ColorSpace.parse(args[0], xref, resources);
  43523. continue;
  43524. case OPS.setStrokeColorSpace:
  43525. stateManager.state.strokeColorSpace =
  43526. ColorSpace.parse(args[0], xref, resources);
  43527. continue;
  43528. case OPS.setFillColor:
  43529. cs = stateManager.state.fillColorSpace;
  43530. args = cs.getRgb(args, 0);
  43531. fn = OPS.setFillRGBColor;
  43532. break;
  43533. case OPS.setStrokeColor:
  43534. cs = stateManager.state.strokeColorSpace;
  43535. args = cs.getRgb(args, 0);
  43536. fn = OPS.setStrokeRGBColor;
  43537. break;
  43538. case OPS.setFillGray:
  43539. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  43540. args = ColorSpace.singletons.gray.getRgb(args, 0);
  43541. fn = OPS.setFillRGBColor;
  43542. break;
  43543. case OPS.setStrokeGray:
  43544. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  43545. args = ColorSpace.singletons.gray.getRgb(args, 0);
  43546. fn = OPS.setStrokeRGBColor;
  43547. break;
  43548. case OPS.setFillCMYKColor:
  43549. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  43550. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  43551. fn = OPS.setFillRGBColor;
  43552. break;
  43553. case OPS.setStrokeCMYKColor:
  43554. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  43555. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  43556. fn = OPS.setStrokeRGBColor;
  43557. break;
  43558. case OPS.setFillRGBColor:
  43559. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  43560. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  43561. break;
  43562. case OPS.setStrokeRGBColor:
  43563. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  43564. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  43565. break;
  43566. case OPS.setFillColorN:
  43567. cs = stateManager.state.fillColorSpace;
  43568. if (cs.name === 'Pattern') {
  43569. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  43570. cs, patterns, resources, task, xref));
  43571. return;
  43572. }
  43573. args = cs.getRgb(args, 0);
  43574. fn = OPS.setFillRGBColor;
  43575. break;
  43576. case OPS.setStrokeColorN:
  43577. cs = stateManager.state.strokeColorSpace;
  43578. if (cs.name === 'Pattern') {
  43579. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  43580. cs, patterns, resources, task, xref));
  43581. return;
  43582. }
  43583. args = cs.getRgb(args, 0);
  43584. fn = OPS.setStrokeRGBColor;
  43585. break;
  43586. case OPS.shadingFill:
  43587. var shadingRes = resources.get('Shading');
  43588. if (!shadingRes) {
  43589. error('No shading resource found');
  43590. }
  43591. var shading = shadingRes.get(args[0].name);
  43592. if (!shading) {
  43593. error('No shading object found');
  43594. }
  43595. var shadingFill = Pattern.parseShading(shading, null, xref,
  43596. resources, self.handler);
  43597. var patternIR = shadingFill.getIR();
  43598. args = [patternIR];
  43599. fn = OPS.shadingFill;
  43600. break;
  43601. case OPS.setGState:
  43602. var dictName = args[0];
  43603. var extGState = resources.get('ExtGState');
  43604. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  43605. break;
  43606. }
  43607. var gState = extGState.get(dictName.name);
  43608. next(self.setGState(resources, gState, operatorList, task, xref,
  43609. stateManager));
  43610. return;
  43611. case OPS.moveTo:
  43612. case OPS.lineTo:
  43613. case OPS.curveTo:
  43614. case OPS.curveTo2:
  43615. case OPS.curveTo3:
  43616. case OPS.closePath:
  43617. self.buildPath(operatorList, fn, args);
  43618. continue;
  43619. case OPS.rectangle:
  43620. self.buildPath(operatorList, fn, args);
  43621. continue;
  43622. case OPS.markPoint:
  43623. case OPS.markPointProps:
  43624. case OPS.beginMarkedContent:
  43625. case OPS.beginMarkedContentProps:
  43626. case OPS.endMarkedContent:
  43627. case OPS.beginCompat:
  43628. case OPS.endCompat:
  43629. // Ignore operators where the corresponding handlers are known to
  43630. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  43631. // serialization errors and is also a bit more efficient.
  43632. // We could also try to serialize all objects in a general way,
  43633. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  43634. // but doing so is meaningless without knowing the semantics.
  43635. continue;
  43636. default:
  43637. // Note: Ignore the operator if it has `Dict` arguments, since
  43638. // those are non-serializable, otherwise postMessage will throw
  43639. // "An object could not be cloned.".
  43640. if (args !== null) {
  43641. for (i = 0, ii = args.length; i < ii; i++) {
  43642. if (args[i] instanceof Dict) {
  43643. break;
  43644. }
  43645. }
  43646. if (i < ii) {
  43647. warn('getOperatorList - ignoring operator: ' + fn);
  43648. continue;
  43649. }
  43650. }
  43651. }
  43652. operatorList.addOp(fn, args);
  43653. }
  43654. if (stop) {
  43655. next(deferred);
  43656. return;
  43657. }
  43658. // Some PDFs don't close all restores inside object/form.
  43659. // Closing those for them.
  43660. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  43661. operatorList.addOp(OPS.restore, []);
  43662. }
  43663. resolve();
  43664. });
  43665. },
  43666. getTextContent:
  43667. function PartialEvaluator_getTextContent(stream, task, resources,
  43668. stateManager,
  43669. normalizeWhitespace,
  43670. combineTextItems) {
  43671. stateManager = (stateManager || new StateManager(new TextState()));
  43672. var WhitespaceRegexp = /\s/g;
  43673. var textContent = {
  43674. items: [],
  43675. styles: Object.create(null)
  43676. };
  43677. var textContentItem = {
  43678. initialized: false,
  43679. str: [],
  43680. width: 0,
  43681. height: 0,
  43682. vertical: false,
  43683. lastAdvanceWidth: 0,
  43684. lastAdvanceHeight: 0,
  43685. textAdvanceScale: 0,
  43686. spaceWidth: 0,
  43687. fakeSpaceMin: Infinity,
  43688. fakeMultiSpaceMin: Infinity,
  43689. fakeMultiSpaceMax: -0,
  43690. textRunBreakAllowed: false,
  43691. transform: null,
  43692. fontName: null
  43693. };
  43694. var SPACE_FACTOR = 0.3;
  43695. var MULTI_SPACE_FACTOR = 1.5;
  43696. var MULTI_SPACE_FACTOR_MAX = 4;
  43697. var self = this;
  43698. var xref = this.xref;
  43699. resources = (xref.fetchIfRef(resources) || Dict.empty);
  43700. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  43701. var xobjs = null;
  43702. var xobjsCache = Object.create(null);
  43703. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  43704. var textState;
  43705. function ensureTextContentItem() {
  43706. if (textContentItem.initialized) {
  43707. return textContentItem;
  43708. }
  43709. var font = textState.font;
  43710. if (!(font.loadedName in textContent.styles)) {
  43711. textContent.styles[font.loadedName] = {
  43712. fontFamily: font.fallbackName,
  43713. ascent: font.ascent,
  43714. descent: font.descent,
  43715. vertical: font.vertical
  43716. };
  43717. }
  43718. textContentItem.fontName = font.loadedName;
  43719. // 9.4.4 Text Space Details
  43720. var tsm = [textState.fontSize * textState.textHScale, 0,
  43721. 0, textState.fontSize,
  43722. 0, textState.textRise];
  43723. if (font.isType3Font &&
  43724. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  43725. textState.fontSize === 1) {
  43726. var glyphHeight = font.bbox[3] - font.bbox[1];
  43727. if (glyphHeight > 0) {
  43728. glyphHeight = glyphHeight * textState.fontMatrix[3];
  43729. tsm[3] *= glyphHeight;
  43730. }
  43731. }
  43732. var trm = Util.transform(textState.ctm,
  43733. Util.transform(textState.textMatrix, tsm));
  43734. textContentItem.transform = trm;
  43735. if (!font.vertical) {
  43736. textContentItem.width = 0;
  43737. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  43738. textContentItem.vertical = false;
  43739. } else {
  43740. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  43741. textContentItem.height = 0;
  43742. textContentItem.vertical = true;
  43743. }
  43744. var a = textState.textLineMatrix[0];
  43745. var b = textState.textLineMatrix[1];
  43746. var scaleLineX = Math.sqrt(a * a + b * b);
  43747. a = textState.ctm[0];
  43748. b = textState.ctm[1];
  43749. var scaleCtmX = Math.sqrt(a * a + b * b);
  43750. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  43751. textContentItem.lastAdvanceWidth = 0;
  43752. textContentItem.lastAdvanceHeight = 0;
  43753. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  43754. if (spaceWidth) {
  43755. textContentItem.spaceWidth = spaceWidth;
  43756. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  43757. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  43758. textContentItem.fakeMultiSpaceMax =
  43759. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  43760. // It's okay for monospace fonts to fake as much space as needed.
  43761. textContentItem.textRunBreakAllowed = !font.isMonospace;
  43762. } else {
  43763. textContentItem.spaceWidth = 0;
  43764. textContentItem.fakeSpaceMin = Infinity;
  43765. textContentItem.fakeMultiSpaceMin = Infinity;
  43766. textContentItem.fakeMultiSpaceMax = 0;
  43767. textContentItem.textRunBreakAllowed = false;
  43768. }
  43769. textContentItem.initialized = true;
  43770. return textContentItem;
  43771. }
  43772. function replaceWhitespace(str) {
  43773. // Replaces all whitespaces with standard spaces (0x20), to avoid
  43774. // alignment issues between the textLayer and the canvas if the text
  43775. // contains e.g. tabs (fixes issue6612.pdf).
  43776. var i = 0, ii = str.length, code;
  43777. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  43778. i++;
  43779. }
  43780. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  43781. }
  43782. function runBidiTransform(textChunk) {
  43783. var str = textChunk.str.join('');
  43784. var bidiResult = bidi(str, -1, textChunk.vertical);
  43785. return {
  43786. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  43787. bidiResult.str),
  43788. dir: bidiResult.dir,
  43789. width: textChunk.width,
  43790. height: textChunk.height,
  43791. transform: textChunk.transform,
  43792. fontName: textChunk.fontName
  43793. };
  43794. }
  43795. function handleSetFont(fontName, fontRef) {
  43796. return self.loadFont(fontName, fontRef, xref, resources).
  43797. then(function (translated) {
  43798. textState.font = translated.font;
  43799. textState.fontMatrix = translated.font.fontMatrix ||
  43800. FONT_IDENTITY_MATRIX;
  43801. });
  43802. }
  43803. function buildTextContentItem(chars) {
  43804. var font = textState.font;
  43805. var textChunk = ensureTextContentItem();
  43806. var width = 0;
  43807. var height = 0;
  43808. var glyphs = font.charsToGlyphs(chars);
  43809. var defaultVMetrics = font.defaultVMetrics;
  43810. for (var i = 0; i < glyphs.length; i++) {
  43811. var glyph = glyphs[i];
  43812. var vMetricX = null;
  43813. var vMetricY = null;
  43814. var glyphWidth = null;
  43815. if (font.vertical) {
  43816. if (glyph.vmetric) {
  43817. glyphWidth = glyph.vmetric[0];
  43818. vMetricX = glyph.vmetric[1];
  43819. vMetricY = glyph.vmetric[2];
  43820. } else {
  43821. glyphWidth = glyph.width;
  43822. vMetricX = glyph.width * 0.5;
  43823. vMetricY = defaultVMetrics[2];
  43824. }
  43825. } else {
  43826. glyphWidth = glyph.width;
  43827. }
  43828. var glyphUnicode = glyph.unicode;
  43829. var NormalizedUnicodes = getNormalizedUnicodes();
  43830. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  43831. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  43832. }
  43833. glyphUnicode = reverseIfRtl(glyphUnicode);
  43834. // The following will calculate the x and y of the individual glyphs.
  43835. // if (font.vertical) {
  43836. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  43837. // textState.fontMatrix[0];
  43838. // tsm[5] -= vMetricY * textState.fontSize *
  43839. // textState.fontMatrix[0];
  43840. // }
  43841. // var trm = Util.transform(textState.textMatrix, tsm);
  43842. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  43843. // var x = pt[0];
  43844. // var y = pt[1];
  43845. var charSpacing = textState.charSpacing;
  43846. if (glyph.isSpace) {
  43847. var wordSpacing = textState.wordSpacing;
  43848. charSpacing += wordSpacing;
  43849. if (wordSpacing > 0) {
  43850. addFakeSpaces(wordSpacing, textChunk.str);
  43851. }
  43852. }
  43853. var tx = 0;
  43854. var ty = 0;
  43855. if (!font.vertical) {
  43856. var w0 = glyphWidth * textState.fontMatrix[0];
  43857. tx = (w0 * textState.fontSize + charSpacing) *
  43858. textState.textHScale;
  43859. width += tx;
  43860. } else {
  43861. var w1 = glyphWidth * textState.fontMatrix[0];
  43862. ty = w1 * textState.fontSize + charSpacing;
  43863. height += ty;
  43864. }
  43865. textState.translateTextMatrix(tx, ty);
  43866. textChunk.str.push(glyphUnicode);
  43867. }
  43868. if (!font.vertical) {
  43869. textChunk.lastAdvanceWidth = width;
  43870. textChunk.width += width * textChunk.textAdvanceScale;
  43871. } else {
  43872. textChunk.lastAdvanceHeight = height;
  43873. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  43874. }
  43875. return textChunk;
  43876. }
  43877. function addFakeSpaces(width, strBuf) {
  43878. if (width < textContentItem.fakeSpaceMin) {
  43879. return;
  43880. }
  43881. if (width < textContentItem.fakeMultiSpaceMin) {
  43882. strBuf.push(' ');
  43883. return;
  43884. }
  43885. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  43886. while (fakeSpaces-- > 0) {
  43887. strBuf.push(' ');
  43888. }
  43889. }
  43890. function flushTextContentItem() {
  43891. if (!textContentItem.initialized) {
  43892. return;
  43893. }
  43894. textContent.items.push(runBidiTransform(textContentItem));
  43895. textContentItem.initialized = false;
  43896. textContentItem.str.length = 0;
  43897. }
  43898. var timeSlotManager = new TimeSlotManager();
  43899. return new Promise(function promiseBody(resolve, reject) {
  43900. var next = function (promise) {
  43901. promise.then(function () {
  43902. try {
  43903. promiseBody(resolve, reject);
  43904. } catch (ex) {
  43905. reject(ex);
  43906. }
  43907. }, reject);
  43908. };
  43909. task.ensureNotTerminated();
  43910. timeSlotManager.reset();
  43911. var stop, operation = {}, args = [];
  43912. while (!(stop = timeSlotManager.check())) {
  43913. // The arguments parsed by read() are not used beyond this loop, so
  43914. // we can reuse the same array on every iteration, thus avoiding
  43915. // unnecessary allocations.
  43916. args.length = 0;
  43917. operation.args = args;
  43918. if (!(preprocessor.read(operation))) {
  43919. break;
  43920. }
  43921. textState = stateManager.state;
  43922. var fn = operation.fn;
  43923. args = operation.args;
  43924. var advance, diff;
  43925. switch (fn | 0) {
  43926. case OPS.setFont:
  43927. // Optimization to ignore multiple identical Tf commands.
  43928. var fontNameArg = args[0].name, fontSizeArg = args[1];
  43929. if (textState.font && fontNameArg === textState.fontName &&
  43930. fontSizeArg === textState.fontSize) {
  43931. break;
  43932. }
  43933. flushTextContentItem();
  43934. textState.fontName = fontNameArg;
  43935. textState.fontSize = fontSizeArg;
  43936. next(handleSetFont(fontNameArg, null));
  43937. return;
  43938. case OPS.setTextRise:
  43939. flushTextContentItem();
  43940. textState.textRise = args[0];
  43941. break;
  43942. case OPS.setHScale:
  43943. flushTextContentItem();
  43944. textState.textHScale = args[0] / 100;
  43945. break;
  43946. case OPS.setLeading:
  43947. flushTextContentItem();
  43948. textState.leading = args[0];
  43949. break;
  43950. case OPS.moveText:
  43951. // Optimization to treat same line movement as advance
  43952. var isSameTextLine = !textState.font ? false :
  43953. ((textState.font.vertical ? args[0] : args[1]) === 0);
  43954. advance = args[0] - args[1];
  43955. if (combineTextItems &&
  43956. isSameTextLine && textContentItem.initialized &&
  43957. advance > 0 &&
  43958. advance <= textContentItem.fakeMultiSpaceMax) {
  43959. textState.translateTextLineMatrix(args[0], args[1]);
  43960. textContentItem.width +=
  43961. (args[0] - textContentItem.lastAdvanceWidth);
  43962. textContentItem.height +=
  43963. (args[1] - textContentItem.lastAdvanceHeight);
  43964. diff = (args[0] - textContentItem.lastAdvanceWidth) -
  43965. (args[1] - textContentItem.lastAdvanceHeight);
  43966. addFakeSpaces(diff, textContentItem.str);
  43967. break;
  43968. }
  43969. flushTextContentItem();
  43970. textState.translateTextLineMatrix(args[0], args[1]);
  43971. textState.textMatrix = textState.textLineMatrix.slice();
  43972. break;
  43973. case OPS.setLeadingMoveText:
  43974. flushTextContentItem();
  43975. textState.leading = -args[1];
  43976. textState.translateTextLineMatrix(args[0], args[1]);
  43977. textState.textMatrix = textState.textLineMatrix.slice();
  43978. break;
  43979. case OPS.nextLine:
  43980. flushTextContentItem();
  43981. textState.carriageReturn();
  43982. break;
  43983. case OPS.setTextMatrix:
  43984. // Optimization to treat same line movement as advance.
  43985. advance = textState.calcTextLineMatrixAdvance(
  43986. args[0], args[1], args[2], args[3], args[4], args[5]);
  43987. if (combineTextItems &&
  43988. advance !== null && textContentItem.initialized &&
  43989. advance.value > 0 &&
  43990. advance.value <= textContentItem.fakeMultiSpaceMax) {
  43991. textState.translateTextLineMatrix(advance.width,
  43992. advance.height);
  43993. textContentItem.width +=
  43994. (advance.width - textContentItem.lastAdvanceWidth);
  43995. textContentItem.height +=
  43996. (advance.height - textContentItem.lastAdvanceHeight);
  43997. diff = (advance.width - textContentItem.lastAdvanceWidth) -
  43998. (advance.height - textContentItem.lastAdvanceHeight);
  43999. addFakeSpaces(diff, textContentItem.str);
  44000. break;
  44001. }
  44002. flushTextContentItem();
  44003. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  44004. args[4], args[5]);
  44005. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  44006. args[4], args[5]);
  44007. break;
  44008. case OPS.setCharSpacing:
  44009. textState.charSpacing = args[0];
  44010. break;
  44011. case OPS.setWordSpacing:
  44012. textState.wordSpacing = args[0];
  44013. break;
  44014. case OPS.beginText:
  44015. flushTextContentItem();
  44016. textState.textMatrix = IDENTITY_MATRIX.slice();
  44017. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  44018. break;
  44019. case OPS.showSpacedText:
  44020. var items = args[0];
  44021. var offset;
  44022. for (var j = 0, jj = items.length; j < jj; j++) {
  44023. if (typeof items[j] === 'string') {
  44024. buildTextContentItem(items[j]);
  44025. } else {
  44026. ensureTextContentItem();
  44027. // PDF Specification 5.3.2 states:
  44028. // The number is expressed in thousandths of a unit of text
  44029. // space.
  44030. // This amount is subtracted from the current horizontal or
  44031. // vertical coordinate, depending on the writing mode.
  44032. // In the default coordinate system, a positive adjustment
  44033. // has the effect of moving the next glyph painted either to
  44034. // the left or down by the given amount.
  44035. advance = items[j] * textState.fontSize / 1000;
  44036. var breakTextRun = false;
  44037. if (textState.font.vertical) {
  44038. offset = advance *
  44039. (textState.textHScale * textState.textMatrix[2] +
  44040. textState.textMatrix[3]);
  44041. textState.translateTextMatrix(0, advance);
  44042. breakTextRun = textContentItem.textRunBreakAllowed &&
  44043. advance > textContentItem.fakeMultiSpaceMax;
  44044. if (!breakTextRun) {
  44045. // Value needs to be added to height to paint down.
  44046. textContentItem.height += offset;
  44047. }
  44048. } else {
  44049. advance = -advance;
  44050. offset = advance * (
  44051. textState.textHScale * textState.textMatrix[0] +
  44052. textState.textMatrix[1]);
  44053. textState.translateTextMatrix(advance, 0);
  44054. breakTextRun = textContentItem.textRunBreakAllowed &&
  44055. advance > textContentItem.fakeMultiSpaceMax;
  44056. if (!breakTextRun) {
  44057. // Value needs to be subtracted from width to paint left.
  44058. textContentItem.width += offset;
  44059. }
  44060. }
  44061. if (breakTextRun) {
  44062. flushTextContentItem();
  44063. } else if (advance > 0) {
  44064. addFakeSpaces(advance, textContentItem.str);
  44065. }
  44066. }
  44067. }
  44068. break;
  44069. case OPS.showText:
  44070. buildTextContentItem(args[0]);
  44071. break;
  44072. case OPS.nextLineShowText:
  44073. flushTextContentItem();
  44074. textState.carriageReturn();
  44075. buildTextContentItem(args[0]);
  44076. break;
  44077. case OPS.nextLineSetSpacingShowText:
  44078. flushTextContentItem();
  44079. textState.wordSpacing = args[0];
  44080. textState.charSpacing = args[1];
  44081. textState.carriageReturn();
  44082. buildTextContentItem(args[2]);
  44083. break;
  44084. case OPS.paintXObject:
  44085. flushTextContentItem();
  44086. if (args[0].code) {
  44087. break;
  44088. }
  44089. if (!xobjs) {
  44090. xobjs = (resources.get('XObject') || Dict.empty);
  44091. }
  44092. var name = args[0].name;
  44093. if (xobjsCache.key === name) {
  44094. if (xobjsCache.texts) {
  44095. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  44096. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  44097. }
  44098. break;
  44099. }
  44100. var xobj = xobjs.get(name);
  44101. if (!xobj) {
  44102. break;
  44103. }
  44104. assert(isStream(xobj), 'XObject should be a stream');
  44105. var type = xobj.dict.get('Subtype');
  44106. assert(isName(type), 'XObject should have a Name subtype');
  44107. if ('Form' !== type.name) {
  44108. xobjsCache.key = name;
  44109. xobjsCache.texts = null;
  44110. break;
  44111. }
  44112. stateManager.save();
  44113. var matrix = xobj.dict.getArray('Matrix');
  44114. if (isArray(matrix) && matrix.length === 6) {
  44115. stateManager.transform(matrix);
  44116. }
  44117. next(self.getTextContent(xobj, task,
  44118. xobj.dict.get('Resources') || resources, stateManager,
  44119. normalizeWhitespace, combineTextItems).then(
  44120. function (formTextContent) {
  44121. Util.appendToArray(textContent.items, formTextContent.items);
  44122. Util.extendObj(textContent.styles, formTextContent.styles);
  44123. stateManager.restore();
  44124. xobjsCache.key = name;
  44125. xobjsCache.texts = formTextContent;
  44126. }));
  44127. return;
  44128. case OPS.setGState:
  44129. flushTextContentItem();
  44130. var dictName = args[0];
  44131. var extGState = resources.get('ExtGState');
  44132. if (!isDict(extGState) || !isName(dictName)) {
  44133. break;
  44134. }
  44135. var gState = extGState.get(dictName.name);
  44136. if (!isDict(gState)) {
  44137. break;
  44138. }
  44139. var gStateFont = gState.get('Font');
  44140. if (gStateFont) {
  44141. textState.fontName = null;
  44142. textState.fontSize = gStateFont[1];
  44143. next(handleSetFont(null, gStateFont[0]));
  44144. return;
  44145. }
  44146. break;
  44147. } // switch
  44148. } // while
  44149. if (stop) {
  44150. next(deferred);
  44151. return;
  44152. }
  44153. flushTextContentItem();
  44154. resolve(textContent);
  44155. });
  44156. },
  44157. extractDataStructures:
  44158. function PartialEvaluator_extractDataStructures(dict, baseDict,
  44159. xref, properties) {
  44160. // 9.10.2
  44161. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  44162. var toUnicodePromise = toUnicode ?
  44163. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  44164. if (properties.composite) {
  44165. // CIDSystemInfo helps to match CID to glyphs
  44166. var cidSystemInfo = dict.get('CIDSystemInfo');
  44167. if (isDict(cidSystemInfo)) {
  44168. properties.cidSystemInfo = {
  44169. registry: cidSystemInfo.get('Registry'),
  44170. ordering: cidSystemInfo.get('Ordering'),
  44171. supplement: cidSystemInfo.get('Supplement')
  44172. };
  44173. }
  44174. var cidToGidMap = dict.get('CIDToGIDMap');
  44175. if (isStream(cidToGidMap)) {
  44176. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  44177. }
  44178. }
  44179. // Based on 9.6.6 of the spec the encoding can come from multiple places
  44180. // and depends on the font type. The base encoding and differences are
  44181. // read here, but the encoding that is actually used is chosen during
  44182. // glyph mapping in the font.
  44183. // TODO: Loading the built in encoding in the font would allow the
  44184. // differences to be merged in here not require us to hold on to it.
  44185. var differences = [];
  44186. var baseEncodingName = null;
  44187. var encoding;
  44188. if (dict.has('Encoding')) {
  44189. encoding = dict.get('Encoding');
  44190. if (isDict(encoding)) {
  44191. baseEncodingName = encoding.get('BaseEncoding');
  44192. baseEncodingName = (isName(baseEncodingName) ?
  44193. baseEncodingName.name : null);
  44194. // Load the differences between the base and original
  44195. if (encoding.has('Differences')) {
  44196. var diffEncoding = encoding.get('Differences');
  44197. var index = 0;
  44198. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  44199. var data = xref.fetchIfRef(diffEncoding[j]);
  44200. if (isNum(data)) {
  44201. index = data;
  44202. } else if (isName(data)) {
  44203. differences[index++] = data.name;
  44204. } else {
  44205. error('Invalid entry in \'Differences\' array: ' + data);
  44206. }
  44207. }
  44208. }
  44209. } else if (isName(encoding)) {
  44210. baseEncodingName = encoding.name;
  44211. } else {
  44212. error('Encoding is not a Name nor a Dict');
  44213. }
  44214. // According to table 114 if the encoding is a named encoding it must be
  44215. // one of these predefined encodings.
  44216. if ((baseEncodingName !== 'MacRomanEncoding' &&
  44217. baseEncodingName !== 'MacExpertEncoding' &&
  44218. baseEncodingName !== 'WinAnsiEncoding')) {
  44219. baseEncodingName = null;
  44220. }
  44221. }
  44222. if (baseEncodingName) {
  44223. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  44224. } else {
  44225. encoding = (properties.type === 'TrueType' ?
  44226. WinAnsiEncoding : StandardEncoding);
  44227. // The Symbolic attribute can be misused for regular fonts
  44228. // Heuristic: we have to check if the font is a standard one also
  44229. if (!!(properties.flags & FontFlags.Symbolic)) {
  44230. encoding = MacRomanEncoding;
  44231. if (!properties.file) {
  44232. if (/Symbol/i.test(properties.name)) {
  44233. encoding = SymbolSetEncoding;
  44234. } else if (/Dingbats/i.test(properties.name)) {
  44235. encoding = ZapfDingbatsEncoding;
  44236. }
  44237. }
  44238. }
  44239. properties.defaultEncoding = encoding;
  44240. }
  44241. properties.differences = differences;
  44242. properties.baseEncodingName = baseEncodingName;
  44243. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  44244. properties.dict = dict;
  44245. return toUnicodePromise.then(function(toUnicode) {
  44246. properties.toUnicode = toUnicode;
  44247. return this.buildToUnicode(properties);
  44248. }.bind(this)).then(function (toUnicode) {
  44249. properties.toUnicode = toUnicode;
  44250. return properties;
  44251. });
  44252. },
  44253. /**
  44254. * Builds a char code to unicode map based on section 9.10 of the spec.
  44255. * @param {Object} properties Font properties object.
  44256. * @return {Promise} A Promise that is resolved with a
  44257. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  44258. */
  44259. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  44260. properties.hasIncludedToUnicodeMap =
  44261. !!properties.toUnicode && properties.toUnicode.length > 0;
  44262. // Section 9.10.2 Mapping Character Codes to Unicode Values
  44263. if (properties.hasIncludedToUnicodeMap) {
  44264. return Promise.resolve(properties.toUnicode);
  44265. }
  44266. // According to the spec if the font is a simple font we should only map
  44267. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  44268. // the differences array only contains adobe standard or symbol set names,
  44269. // in pratice it seems better to always try to create a toUnicode
  44270. // map based of the default encoding.
  44271. var toUnicode, charcode, glyphName;
  44272. if (!properties.composite /* is simple font */) {
  44273. toUnicode = [];
  44274. var encoding = properties.defaultEncoding.slice();
  44275. var baseEncodingName = properties.baseEncodingName;
  44276. // Merge in the differences array.
  44277. var differences = properties.differences;
  44278. for (charcode in differences) {
  44279. glyphName = differences[charcode];
  44280. if (glyphName === '.notdef') {
  44281. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  44282. // where there should be spaces (fixes issue5256.pdf).
  44283. continue;
  44284. }
  44285. encoding[charcode] = glyphName;
  44286. }
  44287. var glyphsUnicodeMap = getGlyphsUnicode();
  44288. for (charcode in encoding) {
  44289. // a) Map the character code to a character name.
  44290. glyphName = encoding[charcode];
  44291. // b) Look up the character name in the Adobe Glyph List (see the
  44292. // Bibliography) to obtain the corresponding Unicode value.
  44293. if (glyphName === '') {
  44294. continue;
  44295. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  44296. // (undocumented) c) Few heuristics to recognize unknown glyphs
  44297. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  44298. var code = 0;
  44299. switch (glyphName[0]) {
  44300. case 'G': // Gxx glyph
  44301. if (glyphName.length === 3) {
  44302. code = parseInt(glyphName.substr(1), 16);
  44303. }
  44304. break;
  44305. case 'g': // g00xx glyph
  44306. if (glyphName.length === 5) {
  44307. code = parseInt(glyphName.substr(1), 16);
  44308. }
  44309. break;
  44310. case 'C': // Cddd glyph
  44311. case 'c': // cddd glyph
  44312. if (glyphName.length >= 3) {
  44313. code = +glyphName.substr(1);
  44314. }
  44315. break;
  44316. default:
  44317. // 'uniXXXX'/'uXXXX{XX}' glyphs
  44318. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  44319. if (unicode !== -1) {
  44320. code = unicode;
  44321. }
  44322. }
  44323. if (code) {
  44324. // If |baseEncodingName| is one the predefined encodings,
  44325. // and |code| equals |charcode|, using the glyph defined in the
  44326. // baseEncoding seems to yield a better |toUnicode| mapping
  44327. // (fixes issue 5070).
  44328. if (baseEncodingName && code === +charcode) {
  44329. var baseEncoding = getEncoding(baseEncodingName);
  44330. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  44331. toUnicode[charcode] =
  44332. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  44333. continue;
  44334. }
  44335. }
  44336. toUnicode[charcode] = String.fromCharCode(code);
  44337. }
  44338. continue;
  44339. }
  44340. toUnicode[charcode] =
  44341. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  44342. }
  44343. return Promise.resolve(new ToUnicodeMap(toUnicode));
  44344. }
  44345. // If the font is a composite font that uses one of the predefined CMaps
  44346. // listed in Table 118 (except Identity–H and Identity–V) or whose
  44347. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  44348. // Adobe-Korea1 character collection:
  44349. if (properties.composite && (
  44350. (properties.cMap.builtInCMap &&
  44351. !(properties.cMap instanceof IdentityCMap)) ||
  44352. (properties.cidSystemInfo.registry === 'Adobe' &&
  44353. (properties.cidSystemInfo.ordering === 'GB1' ||
  44354. properties.cidSystemInfo.ordering === 'CNS1' ||
  44355. properties.cidSystemInfo.ordering === 'Japan1' ||
  44356. properties.cidSystemInfo.ordering === 'Korea1')))) {
  44357. // Then:
  44358. // a) Map the character code to a character identifier (CID) according
  44359. // to the font’s CMap.
  44360. // b) Obtain the registry and ordering of the character collection used
  44361. // by the font’s CMap (for example, Adobe and Japan1) from its
  44362. // CIDSystemInfo dictionary.
  44363. var registry = properties.cidSystemInfo.registry;
  44364. var ordering = properties.cidSystemInfo.ordering;
  44365. // c) Construct a second CMap name by concatenating the registry and
  44366. // ordering obtained in step (b) in the format registry–ordering–UCS2
  44367. // (for example, Adobe–Japan1–UCS2).
  44368. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  44369. // d) Obtain the CMap with the name constructed in step (c) (available
  44370. // from the ASN Web site; see the Bibliography).
  44371. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  44372. null).then(
  44373. function (ucs2CMap) {
  44374. var cMap = properties.cMap;
  44375. toUnicode = [];
  44376. cMap.forEach(function(charcode, cid) {
  44377. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  44378. // e) Map the CID obtained in step (a) according to the CMap
  44379. // obtained in step (d), producing a Unicode value.
  44380. var ucs2 = ucs2CMap.lookup(cid);
  44381. if (ucs2) {
  44382. toUnicode[charcode] =
  44383. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  44384. ucs2.charCodeAt(1));
  44385. }
  44386. });
  44387. return new ToUnicodeMap(toUnicode);
  44388. });
  44389. }
  44390. // The viewer's choice, just use an identity map.
  44391. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  44392. properties.lastChar));
  44393. },
  44394. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  44395. var cmapObj = toUnicode;
  44396. if (isName(cmapObj)) {
  44397. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  44398. function (cmap) {
  44399. if (cmap instanceof IdentityCMap) {
  44400. return new IdentityToUnicodeMap(0, 0xFFFF);
  44401. }
  44402. return new ToUnicodeMap(cmap.getMap());
  44403. });
  44404. } else if (isStream(cmapObj)) {
  44405. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  44406. function (cmap) {
  44407. if (cmap instanceof IdentityCMap) {
  44408. return new IdentityToUnicodeMap(0, 0xFFFF);
  44409. }
  44410. var map = new Array(cmap.length);
  44411. // Convert UTF-16BE
  44412. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  44413. // to iterate over all keys.
  44414. cmap.forEach(function(charCode, token) {
  44415. var str = [];
  44416. for (var k = 0; k < token.length; k += 2) {
  44417. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  44418. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  44419. str.push(w1);
  44420. continue;
  44421. }
  44422. k += 2;
  44423. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  44424. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  44425. }
  44426. map[charCode] = String.fromCharCode.apply(String, str);
  44427. });
  44428. return new ToUnicodeMap(map);
  44429. });
  44430. }
  44431. return Promise.resolve(null);
  44432. },
  44433. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  44434. // Extract the encoding from the CIDToGIDMap
  44435. var glyphsData = cidToGidStream.getBytes();
  44436. // Set encoding 0 to later verify the font has an encoding
  44437. var result = [];
  44438. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  44439. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  44440. if (glyphID === 0) {
  44441. continue;
  44442. }
  44443. var code = j >> 1;
  44444. result[code] = glyphID;
  44445. }
  44446. return result;
  44447. },
  44448. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  44449. descriptor,
  44450. properties) {
  44451. var glyphsWidths = [];
  44452. var defaultWidth = 0;
  44453. var glyphsVMetrics = [];
  44454. var defaultVMetrics;
  44455. var i, ii, j, jj, start, code, widths;
  44456. if (properties.composite) {
  44457. defaultWidth = dict.get('DW') || 1000;
  44458. widths = dict.get('W');
  44459. if (widths) {
  44460. for (i = 0, ii = widths.length; i < ii; i++) {
  44461. start = widths[i++];
  44462. code = xref.fetchIfRef(widths[i]);
  44463. if (isArray(code)) {
  44464. for (j = 0, jj = code.length; j < jj; j++) {
  44465. glyphsWidths[start++] = code[j];
  44466. }
  44467. } else {
  44468. var width = widths[++i];
  44469. for (j = start; j <= code; j++) {
  44470. glyphsWidths[j] = width;
  44471. }
  44472. }
  44473. }
  44474. }
  44475. if (properties.vertical) {
  44476. var vmetrics = (dict.get('DW2') || [880, -1000]);
  44477. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  44478. vmetrics = dict.get('W2');
  44479. if (vmetrics) {
  44480. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  44481. start = vmetrics[i++];
  44482. code = xref.fetchIfRef(vmetrics[i]);
  44483. if (isArray(code)) {
  44484. for (j = 0, jj = code.length; j < jj; j++) {
  44485. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  44486. }
  44487. } else {
  44488. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  44489. for (j = start; j <= code; j++) {
  44490. glyphsVMetrics[j] = vmetric;
  44491. }
  44492. }
  44493. }
  44494. }
  44495. }
  44496. } else {
  44497. var firstChar = properties.firstChar;
  44498. widths = dict.get('Widths');
  44499. if (widths) {
  44500. j = firstChar;
  44501. for (i = 0, ii = widths.length; i < ii; i++) {
  44502. glyphsWidths[j++] = widths[i];
  44503. }
  44504. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  44505. } else {
  44506. // Trying get the BaseFont metrics (see comment above).
  44507. var baseFontName = dict.get('BaseFont');
  44508. if (isName(baseFontName)) {
  44509. var metrics = this.getBaseFontMetrics(baseFontName.name);
  44510. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  44511. properties);
  44512. defaultWidth = metrics.defaultWidth;
  44513. }
  44514. }
  44515. }
  44516. // Heuristic: detection of monospace font by checking all non-zero widths
  44517. var isMonospace = true;
  44518. var firstWidth = defaultWidth;
  44519. for (var glyph in glyphsWidths) {
  44520. var glyphWidth = glyphsWidths[glyph];
  44521. if (!glyphWidth) {
  44522. continue;
  44523. }
  44524. if (!firstWidth) {
  44525. firstWidth = glyphWidth;
  44526. continue;
  44527. }
  44528. if (firstWidth !== glyphWidth) {
  44529. isMonospace = false;
  44530. break;
  44531. }
  44532. }
  44533. if (isMonospace) {
  44534. properties.flags |= FontFlags.FixedPitch;
  44535. }
  44536. properties.defaultWidth = defaultWidth;
  44537. properties.widths = glyphsWidths;
  44538. properties.defaultVMetrics = defaultVMetrics;
  44539. properties.vmetrics = glyphsVMetrics;
  44540. },
  44541. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  44542. // Simulating descriptor flags attribute
  44543. var fontNameWoStyle = baseFontName.split('-')[0];
  44544. return (fontNameWoStyle in getSerifFonts()) ||
  44545. (fontNameWoStyle.search(/serif/gi) !== -1);
  44546. },
  44547. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  44548. var defaultWidth = 0;
  44549. var widths = [];
  44550. var monospace = false;
  44551. var stdFontMap = getStdFontMap();
  44552. var lookupName = (stdFontMap[name] || name);
  44553. var Metrics = getMetrics();
  44554. if (!(lookupName in Metrics)) {
  44555. // Use default fonts for looking up font metrics if the passed
  44556. // font is not a base font
  44557. if (this.isSerifFont(name)) {
  44558. lookupName = 'Times-Roman';
  44559. } else {
  44560. lookupName = 'Helvetica';
  44561. }
  44562. }
  44563. var glyphWidths = Metrics[lookupName];
  44564. if (isNum(glyphWidths)) {
  44565. defaultWidth = glyphWidths;
  44566. monospace = true;
  44567. } else {
  44568. widths = glyphWidths(); // expand lazy widths array
  44569. }
  44570. return {
  44571. defaultWidth: defaultWidth,
  44572. monospace: monospace,
  44573. widths: widths
  44574. };
  44575. },
  44576. buildCharCodeToWidth:
  44577. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  44578. properties) {
  44579. var widths = Object.create(null);
  44580. var differences = properties.differences;
  44581. var encoding = properties.defaultEncoding;
  44582. for (var charCode = 0; charCode < 256; charCode++) {
  44583. if (charCode in differences &&
  44584. widthsByGlyphName[differences[charCode]]) {
  44585. widths[charCode] = widthsByGlyphName[differences[charCode]];
  44586. continue;
  44587. }
  44588. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  44589. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  44590. continue;
  44591. }
  44592. }
  44593. return widths;
  44594. },
  44595. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  44596. var baseDict = dict;
  44597. var type = dict.get('Subtype');
  44598. assert(isName(type), 'invalid font Subtype');
  44599. var composite = false;
  44600. var uint8array;
  44601. if (type.name === 'Type0') {
  44602. // If font is a composite
  44603. // - get the descendant font
  44604. // - set the type according to the descendant font
  44605. // - get the FontDescriptor from the descendant font
  44606. var df = dict.get('DescendantFonts');
  44607. if (!df) {
  44608. error('Descendant fonts are not specified');
  44609. }
  44610. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  44611. type = dict.get('Subtype');
  44612. assert(isName(type), 'invalid font Subtype');
  44613. composite = true;
  44614. }
  44615. var descriptor = dict.get('FontDescriptor');
  44616. if (descriptor) {
  44617. var hash = new MurmurHash3_64();
  44618. var encoding = baseDict.getRaw('Encoding');
  44619. if (isName(encoding)) {
  44620. hash.update(encoding.name);
  44621. } else if (isRef(encoding)) {
  44622. hash.update(encoding.toString());
  44623. } else if (isDict(encoding)) {
  44624. var keys = encoding.getKeys();
  44625. for (var i = 0, ii = keys.length; i < ii; i++) {
  44626. var entry = encoding.getRaw(keys[i]);
  44627. if (isName(entry)) {
  44628. hash.update(entry.name);
  44629. } else if (isRef(entry)) {
  44630. hash.update(entry.toString());
  44631. } else if (isArray(entry)) { // 'Differences' entry.
  44632. // Ideally we should check the contents of the array, but to avoid
  44633. // parsing it here and then again in |extractDataStructures|,
  44634. // we only use the array length for now (fixes bug1157493.pdf).
  44635. hash.update(entry.length.toString());
  44636. }
  44637. }
  44638. }
  44639. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  44640. if (isStream(toUnicode)) {
  44641. var stream = toUnicode.str || toUnicode;
  44642. uint8array = stream.buffer ?
  44643. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  44644. new Uint8Array(stream.bytes.buffer,
  44645. stream.start, stream.end - stream.start);
  44646. hash.update(uint8array);
  44647. } else if (isName(toUnicode)) {
  44648. hash.update(toUnicode.name);
  44649. }
  44650. var widths = dict.get('Widths') || baseDict.get('Widths');
  44651. if (widths) {
  44652. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  44653. hash.update(uint8array);
  44654. }
  44655. }
  44656. return {
  44657. descriptor: descriptor,
  44658. dict: dict,
  44659. baseDict: baseDict,
  44660. composite: composite,
  44661. type: type.name,
  44662. hash: hash ? hash.hexdigest() : ''
  44663. };
  44664. },
  44665. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  44666. xref) {
  44667. var baseDict = preEvaluatedFont.baseDict;
  44668. var dict = preEvaluatedFont.dict;
  44669. var composite = preEvaluatedFont.composite;
  44670. var descriptor = preEvaluatedFont.descriptor;
  44671. var type = preEvaluatedFont.type;
  44672. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  44673. var cMapOptions = this.options.cMapOptions;
  44674. var properties;
  44675. if (!descriptor) {
  44676. if (type === 'Type3') {
  44677. // FontDescriptor is only required for Type3 fonts when the document
  44678. // is a tagged pdf. Create a barbebones one to get by.
  44679. descriptor = new Dict(null);
  44680. descriptor.set('FontName', Name.get(type));
  44681. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  44682. } else {
  44683. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  44684. // FontDescriptor was not required.
  44685. // This case is here for compatibility.
  44686. var baseFontName = dict.get('BaseFont');
  44687. if (!isName(baseFontName)) {
  44688. error('Base font is not specified');
  44689. }
  44690. // Using base font name as a font name.
  44691. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  44692. var metrics = this.getBaseFontMetrics(baseFontName);
  44693. // Simulating descriptor flags attribute
  44694. var fontNameWoStyle = baseFontName.split('-')[0];
  44695. var flags =
  44696. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  44697. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  44698. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  44699. FontFlags.Nonsymbolic);
  44700. properties = {
  44701. type: type,
  44702. name: baseFontName,
  44703. widths: metrics.widths,
  44704. defaultWidth: metrics.defaultWidth,
  44705. flags: flags,
  44706. firstChar: 0,
  44707. lastChar: maxCharIndex
  44708. };
  44709. return this.extractDataStructures(dict, dict, xref, properties).then(
  44710. function (properties) {
  44711. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  44712. properties);
  44713. return new Font(baseFontName, null, properties);
  44714. }.bind(this));
  44715. }
  44716. }
  44717. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  44718. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  44719. // to ignore this rule when a variant of a standard font is used.
  44720. // TODO Fill the width array depending on which of the base font this is
  44721. // a variant.
  44722. var firstChar = (dict.get('FirstChar') || 0);
  44723. var lastChar = (dict.get('LastChar') || maxCharIndex);
  44724. var fontName = descriptor.get('FontName');
  44725. var baseFont = dict.get('BaseFont');
  44726. // Some bad PDFs have a string as the font name.
  44727. if (isString(fontName)) {
  44728. fontName = Name.get(fontName);
  44729. }
  44730. if (isString(baseFont)) {
  44731. baseFont = Name.get(baseFont);
  44732. }
  44733. if (type !== 'Type3') {
  44734. var fontNameStr = fontName && fontName.name;
  44735. var baseFontStr = baseFont && baseFont.name;
  44736. if (fontNameStr !== baseFontStr) {
  44737. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  44738. '" but should be the same as the Font\'s BaseFont "' +
  44739. baseFontStr + '"');
  44740. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  44741. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  44742. if (fontNameStr && baseFontStr &&
  44743. baseFontStr.indexOf(fontNameStr) === 0) {
  44744. fontName = baseFont;
  44745. }
  44746. }
  44747. }
  44748. fontName = (fontName || baseFont);
  44749. assert(isName(fontName), 'invalid font name');
  44750. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  44751. if (fontFile) {
  44752. if (fontFile.dict) {
  44753. var subtype = fontFile.dict.get('Subtype');
  44754. if (subtype) {
  44755. subtype = subtype.name;
  44756. }
  44757. var length1 = fontFile.dict.get('Length1');
  44758. var length2 = fontFile.dict.get('Length2');
  44759. var length3 = fontFile.dict.get('Length3');
  44760. }
  44761. }
  44762. properties = {
  44763. type: type,
  44764. name: fontName.name,
  44765. subtype: subtype,
  44766. file: fontFile,
  44767. length1: length1,
  44768. length2: length2,
  44769. length3: length3,
  44770. loadedName: baseDict.loadedName,
  44771. composite: composite,
  44772. wideChars: composite,
  44773. fixedPitch: false,
  44774. fontMatrix: (dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX),
  44775. firstChar: firstChar || 0,
  44776. lastChar: (lastChar || maxCharIndex),
  44777. bbox: descriptor.getArray('FontBBox'),
  44778. ascent: descriptor.get('Ascent'),
  44779. descent: descriptor.get('Descent'),
  44780. xHeight: descriptor.get('XHeight'),
  44781. capHeight: descriptor.get('CapHeight'),
  44782. flags: descriptor.get('Flags'),
  44783. italicAngle: descriptor.get('ItalicAngle'),
  44784. coded: false
  44785. };
  44786. var cMapPromise;
  44787. if (composite) {
  44788. var cidEncoding = baseDict.get('Encoding');
  44789. if (isName(cidEncoding)) {
  44790. properties.cidEncoding = cidEncoding.name;
  44791. }
  44792. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  44793. function (cMap) {
  44794. properties.cMap = cMap;
  44795. properties.vertical = properties.cMap.vertical;
  44796. });
  44797. } else {
  44798. cMapPromise = Promise.resolve(undefined);
  44799. }
  44800. return cMapPromise.then(function () {
  44801. return this.extractDataStructures(dict, baseDict, xref, properties);
  44802. }.bind(this)).then(function (properties) {
  44803. this.extractWidths(dict, xref, descriptor, properties);
  44804. if (type === 'Type3') {
  44805. properties.isType3Font = true;
  44806. }
  44807. return new Font(fontName.name, fontFile, properties);
  44808. }.bind(this));
  44809. }
  44810. };
  44811. return PartialEvaluator;
  44812. })();
  44813. var TranslatedFont = (function TranslatedFontClosure() {
  44814. function TranslatedFont(loadedName, font, dict) {
  44815. this.loadedName = loadedName;
  44816. this.font = font;
  44817. this.dict = dict;
  44818. this.type3Loaded = null;
  44819. this.sent = false;
  44820. }
  44821. TranslatedFont.prototype = {
  44822. send: function (handler) {
  44823. if (this.sent) {
  44824. return;
  44825. }
  44826. var fontData = this.font.exportData();
  44827. handler.send('commonobj', [
  44828. this.loadedName,
  44829. 'Font',
  44830. fontData
  44831. ]);
  44832. this.sent = true;
  44833. },
  44834. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  44835. assert(this.font.isType3Font);
  44836. if (this.type3Loaded) {
  44837. return this.type3Loaded;
  44838. }
  44839. var translatedFont = this.font;
  44840. var loadCharProcsPromise = Promise.resolve();
  44841. var charProcs = this.dict.get('CharProcs');
  44842. var fontResources = this.dict.get('Resources') || resources;
  44843. var charProcKeys = charProcs.getKeys();
  44844. var charProcOperatorList = Object.create(null);
  44845. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  44846. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  44847. var glyphStream = charProcs.get(key);
  44848. var operatorList = new OperatorList();
  44849. return evaluator.getOperatorList(glyphStream, task, fontResources,
  44850. operatorList).then(function () {
  44851. charProcOperatorList[key] = operatorList.getIR();
  44852. // Add the dependencies to the parent operator list so they are
  44853. // resolved before sub operator list is executed synchronously.
  44854. parentOperatorList.addDependencies(operatorList.dependencies);
  44855. }, function (reason) {
  44856. warn('Type3 font resource \"' + key + '\" is not available');
  44857. var operatorList = new OperatorList();
  44858. charProcOperatorList[key] = operatorList.getIR();
  44859. });
  44860. }.bind(this, charProcKeys[i]));
  44861. }
  44862. this.type3Loaded = loadCharProcsPromise.then(function () {
  44863. translatedFont.charProcOperatorList = charProcOperatorList;
  44864. });
  44865. return this.type3Loaded;
  44866. }
  44867. };
  44868. return TranslatedFont;
  44869. })();
  44870. var OperatorList = (function OperatorListClosure() {
  44871. var CHUNK_SIZE = 1000;
  44872. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  44873. function getTransfers(queue) {
  44874. var transfers = [];
  44875. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44876. for (var i = 0, ii = queue.length; i < ii; i++) {
  44877. switch (fnArray[i]) {
  44878. case OPS.paintInlineImageXObject:
  44879. case OPS.paintInlineImageXObjectGroup:
  44880. case OPS.paintImageMaskXObject:
  44881. var arg = argsArray[i][0]; // first param in imgData
  44882. if (!arg.cached) {
  44883. transfers.push(arg.data.buffer);
  44884. }
  44885. break;
  44886. }
  44887. }
  44888. return transfers;
  44889. }
  44890. function OperatorList(intent, messageHandler, pageIndex) {
  44891. this.messageHandler = messageHandler;
  44892. this.fnArray = [];
  44893. this.argsArray = [];
  44894. this.dependencies = Object.create(null);
  44895. this._totalLength = 0;
  44896. this.pageIndex = pageIndex;
  44897. this.intent = intent;
  44898. }
  44899. OperatorList.prototype = {
  44900. get length() {
  44901. return this.argsArray.length;
  44902. },
  44903. /**
  44904. * @returns {number} The total length of the entire operator list,
  44905. * since `this.length === 0` after flushing.
  44906. */
  44907. get totalLength() {
  44908. return (this._totalLength + this.length);
  44909. },
  44910. addOp: function(fn, args) {
  44911. this.fnArray.push(fn);
  44912. this.argsArray.push(args);
  44913. if (this.messageHandler) {
  44914. if (this.fnArray.length >= CHUNK_SIZE) {
  44915. this.flush();
  44916. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  44917. (fn === OPS.restore || fn === OPS.endText)) {
  44918. // heuristic to flush on boundary of restore or endText
  44919. this.flush();
  44920. }
  44921. }
  44922. },
  44923. addDependency: function(dependency) {
  44924. if (dependency in this.dependencies) {
  44925. return;
  44926. }
  44927. this.dependencies[dependency] = true;
  44928. this.addOp(OPS.dependency, [dependency]);
  44929. },
  44930. addDependencies: function(dependencies) {
  44931. for (var key in dependencies) {
  44932. this.addDependency(key);
  44933. }
  44934. },
  44935. addOpList: function(opList) {
  44936. Util.extendObj(this.dependencies, opList.dependencies);
  44937. for (var i = 0, ii = opList.length; i < ii; i++) {
  44938. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  44939. }
  44940. },
  44941. getIR: function() {
  44942. return {
  44943. fnArray: this.fnArray,
  44944. argsArray: this.argsArray,
  44945. length: this.length
  44946. };
  44947. },
  44948. flush: function(lastChunk) {
  44949. if (this.intent !== 'oplist') {
  44950. new QueueOptimizer().optimize(this);
  44951. }
  44952. var transfers = getTransfers(this);
  44953. var length = this.length;
  44954. this._totalLength += length;
  44955. this.messageHandler.send('RenderPageChunk', {
  44956. operatorList: {
  44957. fnArray: this.fnArray,
  44958. argsArray: this.argsArray,
  44959. lastChunk: lastChunk,
  44960. length: length
  44961. },
  44962. pageIndex: this.pageIndex,
  44963. intent: this.intent
  44964. }, transfers);
  44965. this.dependencies = Object.create(null);
  44966. this.fnArray.length = 0;
  44967. this.argsArray.length = 0;
  44968. }
  44969. };
  44970. return OperatorList;
  44971. })();
  44972. var StateManager = (function StateManagerClosure() {
  44973. function StateManager(initialState) {
  44974. this.state = initialState;
  44975. this.stateStack = [];
  44976. }
  44977. StateManager.prototype = {
  44978. save: function () {
  44979. var old = this.state;
  44980. this.stateStack.push(this.state);
  44981. this.state = old.clone();
  44982. },
  44983. restore: function () {
  44984. var prev = this.stateStack.pop();
  44985. if (prev) {
  44986. this.state = prev;
  44987. }
  44988. },
  44989. transform: function (args) {
  44990. this.state.ctm = Util.transform(this.state.ctm, args);
  44991. }
  44992. };
  44993. return StateManager;
  44994. })();
  44995. var TextState = (function TextStateClosure() {
  44996. function TextState() {
  44997. this.ctm = new Float32Array(IDENTITY_MATRIX);
  44998. this.fontName = null;
  44999. this.fontSize = 0;
  45000. this.font = null;
  45001. this.fontMatrix = FONT_IDENTITY_MATRIX;
  45002. this.textMatrix = IDENTITY_MATRIX.slice();
  45003. this.textLineMatrix = IDENTITY_MATRIX.slice();
  45004. this.charSpacing = 0;
  45005. this.wordSpacing = 0;
  45006. this.leading = 0;
  45007. this.textHScale = 1;
  45008. this.textRise = 0;
  45009. }
  45010. TextState.prototype = {
  45011. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  45012. var m = this.textMatrix;
  45013. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  45014. },
  45015. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  45016. var m = this.textLineMatrix;
  45017. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  45018. },
  45019. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  45020. var m = this.textMatrix;
  45021. m[4] = m[0] * x + m[2] * y + m[4];
  45022. m[5] = m[1] * x + m[3] * y + m[5];
  45023. },
  45024. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  45025. var m = this.textLineMatrix;
  45026. m[4] = m[0] * x + m[2] * y + m[4];
  45027. m[5] = m[1] * x + m[3] * y + m[5];
  45028. },
  45029. calcTextLineMatrixAdvance:
  45030. function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  45031. var font = this.font;
  45032. if (!font) {
  45033. return null;
  45034. }
  45035. var m = this.textLineMatrix;
  45036. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  45037. return null;
  45038. }
  45039. var txDiff = e - m[4], tyDiff = f - m[5];
  45040. if ((font.vertical && txDiff !== 0) || (!font.vertical && tyDiff !== 0)) {
  45041. return null;
  45042. }
  45043. var tx, ty, denominator = a * d - b * c;
  45044. if (font.vertical) {
  45045. tx = -tyDiff * c / denominator;
  45046. ty = tyDiff * a / denominator;
  45047. } else {
  45048. tx = txDiff * d / denominator;
  45049. ty = -txDiff * b / denominator;
  45050. }
  45051. return { width: tx, height: ty, value: (font.vertical ? ty : tx), };
  45052. },
  45053. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  45054. // 9.4.4 Text Space Details
  45055. var tsm = [this.fontSize * this.textHScale, 0,
  45056. 0, this.fontSize,
  45057. 0, this.textRise];
  45058. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  45059. },
  45060. carriageReturn: function TextState_carriageReturn() {
  45061. this.translateTextLineMatrix(0, -this.leading);
  45062. this.textMatrix = this.textLineMatrix.slice();
  45063. },
  45064. clone: function TextState_clone() {
  45065. var clone = Object.create(this);
  45066. clone.textMatrix = this.textMatrix.slice();
  45067. clone.textLineMatrix = this.textLineMatrix.slice();
  45068. clone.fontMatrix = this.fontMatrix.slice();
  45069. return clone;
  45070. }
  45071. };
  45072. return TextState;
  45073. })();
  45074. var EvalState = (function EvalStateClosure() {
  45075. function EvalState() {
  45076. this.ctm = new Float32Array(IDENTITY_MATRIX);
  45077. this.font = null;
  45078. this.textRenderingMode = TextRenderingMode.FILL;
  45079. this.fillColorSpace = ColorSpace.singletons.gray;
  45080. this.strokeColorSpace = ColorSpace.singletons.gray;
  45081. }
  45082. EvalState.prototype = {
  45083. clone: function CanvasExtraState_clone() {
  45084. return Object.create(this);
  45085. },
  45086. };
  45087. return EvalState;
  45088. })();
  45089. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  45090. // Specifies properties for each command
  45091. //
  45092. // If variableArgs === true: [0, `numArgs`] expected
  45093. // If variableArgs === false: exactly `numArgs` expected
  45094. var getOPMap = getLookupTableFactory(function (t) {
  45095. // Graphic state
  45096. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  45097. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  45098. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  45099. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  45100. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  45101. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  45102. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  45103. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  45104. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  45105. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  45106. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  45107. // Path
  45108. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  45109. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  45110. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  45111. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  45112. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  45113. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  45114. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  45115. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  45116. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  45117. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  45118. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  45119. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  45120. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  45121. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  45122. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  45123. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  45124. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  45125. // Clipping
  45126. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  45127. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  45128. // Text
  45129. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  45130. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  45131. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  45132. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  45133. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  45134. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  45135. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  45136. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  45137. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  45138. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  45139. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  45140. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  45141. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  45142. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  45143. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  45144. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  45145. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  45146. variableArgs: false };
  45147. // Type3 fonts
  45148. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  45149. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  45150. variableArgs: false };
  45151. // Color
  45152. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  45153. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  45154. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  45155. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  45156. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  45157. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  45158. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  45159. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  45160. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  45161. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  45162. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  45163. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  45164. // Shading
  45165. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  45166. // Images
  45167. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  45168. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  45169. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  45170. // XObjects
  45171. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  45172. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  45173. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  45174. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  45175. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  45176. variableArgs: false };
  45177. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  45178. // Compatibility
  45179. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  45180. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  45181. // (reserved partial commands for the lexer)
  45182. t['BM'] = null;
  45183. t['BD'] = null;
  45184. t['true'] = null;
  45185. t['fa'] = null;
  45186. t['fal'] = null;
  45187. t['fals'] = null;
  45188. t['false'] = null;
  45189. t['nu'] = null;
  45190. t['nul'] = null;
  45191. t['null'] = null;
  45192. });
  45193. function EvaluatorPreprocessor(stream, xref, stateManager) {
  45194. this.opMap = getOPMap();
  45195. // TODO(mduan): pass array of knownCommands rather than this.opMap
  45196. // dictionary
  45197. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  45198. this.stateManager = stateManager;
  45199. this.nonProcessedArgs = [];
  45200. }
  45201. EvaluatorPreprocessor.prototype = {
  45202. get savedStatesDepth() {
  45203. return this.stateManager.stateStack.length;
  45204. },
  45205. // |operation| is an object with two fields:
  45206. //
  45207. // - |fn| is an out param.
  45208. //
  45209. // - |args| is an inout param. On entry, it should have one of two values.
  45210. //
  45211. // - An empty array. This indicates that the caller is providing the
  45212. // array in which the args will be stored in. The caller should use
  45213. // this value if it can reuse a single array for each call to read().
  45214. //
  45215. // - |null|. This indicates that the caller needs this function to create
  45216. // the array in which any args are stored in. If there are zero args,
  45217. // this function will leave |operation.args| as |null| (thus avoiding
  45218. // allocations that would occur if we used an empty array to represent
  45219. // zero arguments). Otherwise, it will replace |null| with a new array
  45220. // containing the arguments. The caller should use this value if it
  45221. // cannot reuse an array for each call to read().
  45222. //
  45223. // These two modes are present because this function is very hot and so
  45224. // avoiding allocations where possible is worthwhile.
  45225. //
  45226. read: function EvaluatorPreprocessor_read(operation) {
  45227. var args = operation.args;
  45228. while (true) {
  45229. var obj = this.parser.getObj();
  45230. if (isCmd(obj)) {
  45231. var cmd = obj.cmd;
  45232. // Check that the command is valid
  45233. var opSpec = this.opMap[cmd];
  45234. if (!opSpec) {
  45235. warn('Unknown command "' + cmd + '"');
  45236. continue;
  45237. }
  45238. var fn = opSpec.id;
  45239. var numArgs = opSpec.numArgs;
  45240. var argsLength = args !== null ? args.length : 0;
  45241. if (!opSpec.variableArgs) {
  45242. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  45243. if (argsLength !== numArgs) {
  45244. var nonProcessedArgs = this.nonProcessedArgs;
  45245. while (argsLength > numArgs) {
  45246. nonProcessedArgs.push(args.shift());
  45247. argsLength--;
  45248. }
  45249. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  45250. if (!args) {
  45251. args = [];
  45252. }
  45253. args.unshift(nonProcessedArgs.pop());
  45254. argsLength++;
  45255. }
  45256. }
  45257. if (argsLength < numArgs) {
  45258. // If we receive too few args, it's not possible to possible
  45259. // to execute the command, so skip the command
  45260. info('Command ' + fn + ': because expected ' +
  45261. numArgs + ' args, but received ' + argsLength +
  45262. ' args; skipping');
  45263. args = null;
  45264. continue;
  45265. }
  45266. } else if (argsLength > numArgs) {
  45267. info('Command ' + fn + ': expected [0,' + numArgs +
  45268. '] args, but received ' + argsLength + ' args');
  45269. }
  45270. // TODO figure out how to type-check vararg functions
  45271. this.preprocessCommand(fn, args);
  45272. operation.fn = fn;
  45273. operation.args = args;
  45274. return true;
  45275. } else {
  45276. if (isEOF(obj)) {
  45277. return false; // no more commands
  45278. }
  45279. // argument
  45280. if (obj !== null) {
  45281. if (!args) {
  45282. args = [];
  45283. }
  45284. args.push(obj);
  45285. assert(args.length <= 33, 'Too many arguments');
  45286. }
  45287. }
  45288. }
  45289. },
  45290. preprocessCommand:
  45291. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  45292. switch (fn | 0) {
  45293. case OPS.save:
  45294. this.stateManager.save();
  45295. break;
  45296. case OPS.restore:
  45297. this.stateManager.restore();
  45298. break;
  45299. case OPS.transform:
  45300. this.stateManager.transform(args);
  45301. break;
  45302. }
  45303. }
  45304. };
  45305. return EvaluatorPreprocessor;
  45306. })();
  45307. var QueueOptimizer = (function QueueOptimizerClosure() {
  45308. function addState(parentState, pattern, fn) {
  45309. var state = parentState;
  45310. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  45311. var item = pattern[i];
  45312. state = (state[item] || (state[item] = []));
  45313. }
  45314. state[pattern[pattern.length - 1]] = fn;
  45315. }
  45316. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  45317. argsArray) {
  45318. // Handles special case of mainly LaTeX documents which use image masks to
  45319. // draw lines with the current fill style.
  45320. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  45321. // have been found at iFirstSave.
  45322. var iFirstPIMXO = iFirstSave + 2;
  45323. for (var i = 0; i < count; i++) {
  45324. var arg = argsArray[iFirstPIMXO + 4 * i];
  45325. var imageMask = arg.length === 1 && arg[0];
  45326. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  45327. (!imageMask.data.length ||
  45328. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  45329. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  45330. continue;
  45331. }
  45332. break;
  45333. }
  45334. return count - i;
  45335. }
  45336. var InitialState = [];
  45337. // This replaces (save, transform, paintInlineImageXObject, restore)+
  45338. // sequences with one |paintInlineImageXObjectGroup| operation.
  45339. addState(InitialState,
  45340. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  45341. function foundInlineImageGroup(context) {
  45342. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  45343. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  45344. var MAX_WIDTH = 1000;
  45345. var IMAGE_PADDING = 1;
  45346. var fnArray = context.fnArray, argsArray = context.argsArray;
  45347. var curr = context.iCurr;
  45348. var iFirstSave = curr - 3;
  45349. var iFirstTransform = curr - 2;
  45350. var iFirstPIIXO = curr - 1;
  45351. // Look for the quartets.
  45352. var i = iFirstSave + 4;
  45353. var ii = fnArray.length;
  45354. while (i + 3 < ii) {
  45355. if (fnArray[i] !== OPS.save ||
  45356. fnArray[i + 1] !== OPS.transform ||
  45357. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  45358. fnArray[i + 3] !== OPS.restore) {
  45359. break; // ops don't match
  45360. }
  45361. i += 4;
  45362. }
  45363. // At this point, i is the index of the first op past the last valid
  45364. // quartet.
  45365. var count = Math.min((i - iFirstSave) / 4,
  45366. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  45367. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  45368. return i;
  45369. }
  45370. // assuming that heights of those image is too small (~1 pixel)
  45371. // packing as much as possible by lines
  45372. var maxX = 0;
  45373. var map = [], maxLineHeight = 0;
  45374. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  45375. var q;
  45376. for (q = 0; q < count; q++) {
  45377. var transform = argsArray[iFirstTransform + (q << 2)];
  45378. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  45379. if (currentX + img.width > MAX_WIDTH) {
  45380. // starting new line
  45381. maxX = Math.max(maxX, currentX);
  45382. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  45383. currentX = 0;
  45384. maxLineHeight = 0;
  45385. }
  45386. map.push({
  45387. transform: transform,
  45388. x: currentX, y: currentY,
  45389. w: img.width, h: img.height
  45390. });
  45391. currentX += img.width + 2 * IMAGE_PADDING;
  45392. maxLineHeight = Math.max(maxLineHeight, img.height);
  45393. }
  45394. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  45395. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  45396. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  45397. var imgRowSize = imgWidth << 2;
  45398. for (q = 0; q < count; q++) {
  45399. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  45400. // Copy image by lines and extends pixels into padding.
  45401. var rowSize = map[q].w << 2;
  45402. var dataOffset = 0;
  45403. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  45404. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  45405. for (var k = 0, kk = map[q].h; k < kk; k++) {
  45406. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  45407. dataOffset += rowSize;
  45408. offset += imgRowSize;
  45409. }
  45410. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  45411. while (offset >= 0) {
  45412. data[offset - 4] = data[offset];
  45413. data[offset - 3] = data[offset + 1];
  45414. data[offset - 2] = data[offset + 2];
  45415. data[offset - 1] = data[offset + 3];
  45416. data[offset + rowSize] = data[offset + rowSize - 4];
  45417. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  45418. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  45419. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  45420. offset -= imgRowSize;
  45421. }
  45422. }
  45423. // Replace queue items.
  45424. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  45425. argsArray.splice(iFirstSave, count * 4,
  45426. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  45427. data: imgData }, map]);
  45428. return iFirstSave + 1;
  45429. });
  45430. // This replaces (save, transform, paintImageMaskXObject, restore)+
  45431. // sequences with one |paintImageMaskXObjectGroup| or one
  45432. // |paintImageMaskXObjectRepeat| operation.
  45433. addState(InitialState,
  45434. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  45435. function foundImageMaskGroup(context) {
  45436. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  45437. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  45438. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  45439. var fnArray = context.fnArray, argsArray = context.argsArray;
  45440. var curr = context.iCurr;
  45441. var iFirstSave = curr - 3;
  45442. var iFirstTransform = curr - 2;
  45443. var iFirstPIMXO = curr - 1;
  45444. // Look for the quartets.
  45445. var i = iFirstSave + 4;
  45446. var ii = fnArray.length;
  45447. while (i + 3 < ii) {
  45448. if (fnArray[i] !== OPS.save ||
  45449. fnArray[i + 1] !== OPS.transform ||
  45450. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  45451. fnArray[i + 3] !== OPS.restore) {
  45452. break; // ops don't match
  45453. }
  45454. i += 4;
  45455. }
  45456. // At this point, i is the index of the first op past the last valid
  45457. // quartet.
  45458. var count = (i - iFirstSave) / 4;
  45459. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  45460. argsArray);
  45461. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  45462. return i;
  45463. }
  45464. var q;
  45465. var isSameImage = false;
  45466. var iTransform, transformArgs;
  45467. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  45468. if (argsArray[iFirstTransform][1] === 0 &&
  45469. argsArray[iFirstTransform][2] === 0) {
  45470. isSameImage = true;
  45471. var firstTransformArg0 = argsArray[iFirstTransform][0];
  45472. var firstTransformArg3 = argsArray[iFirstTransform][3];
  45473. iTransform = iFirstTransform + 4;
  45474. var iPIMXO = iFirstPIMXO + 4;
  45475. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  45476. transformArgs = argsArray[iTransform];
  45477. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  45478. transformArgs[0] !== firstTransformArg0 ||
  45479. transformArgs[1] !== 0 ||
  45480. transformArgs[2] !== 0 ||
  45481. transformArgs[3] !== firstTransformArg3) {
  45482. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  45483. isSameImage = false;
  45484. } else {
  45485. count = q;
  45486. }
  45487. break; // different image or transform
  45488. }
  45489. }
  45490. }
  45491. if (isSameImage) {
  45492. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  45493. var positions = new Float32Array(count * 2);
  45494. iTransform = iFirstTransform;
  45495. for (q = 0; q < count; q++, iTransform += 4) {
  45496. transformArgs = argsArray[iTransform];
  45497. positions[(q << 1)] = transformArgs[4];
  45498. positions[(q << 1) + 1] = transformArgs[5];
  45499. }
  45500. // Replace queue items.
  45501. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  45502. argsArray.splice(iFirstSave, count * 4,
  45503. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  45504. } else {
  45505. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  45506. var images = [];
  45507. for (q = 0; q < count; q++) {
  45508. transformArgs = argsArray[iFirstTransform + (q << 2)];
  45509. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  45510. images.push({ data: maskParams.data, width: maskParams.width,
  45511. height: maskParams.height,
  45512. transform: transformArgs });
  45513. }
  45514. // Replace queue items.
  45515. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  45516. argsArray.splice(iFirstSave, count * 4, [images]);
  45517. }
  45518. return iFirstSave + 1;
  45519. });
  45520. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  45521. // with one paintImageXObjectRepeat operation, if the |transform| and
  45522. // |paintImageXObjectRepeat| ops are appropriate.
  45523. addState(InitialState,
  45524. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  45525. function (context) {
  45526. var MIN_IMAGES_IN_BLOCK = 3;
  45527. var MAX_IMAGES_IN_BLOCK = 1000;
  45528. var fnArray = context.fnArray, argsArray = context.argsArray;
  45529. var curr = context.iCurr;
  45530. var iFirstSave = curr - 3;
  45531. var iFirstTransform = curr - 2;
  45532. var iFirstPIXO = curr - 1;
  45533. var iFirstRestore = curr;
  45534. if (argsArray[iFirstTransform][1] !== 0 ||
  45535. argsArray[iFirstTransform][2] !== 0) {
  45536. return iFirstRestore + 1; // transform has the wrong form
  45537. }
  45538. // Look for the quartets.
  45539. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  45540. var firstTransformArg0 = argsArray[iFirstTransform][0];
  45541. var firstTransformArg3 = argsArray[iFirstTransform][3];
  45542. var i = iFirstSave + 4;
  45543. var ii = fnArray.length;
  45544. while (i + 3 < ii) {
  45545. if (fnArray[i] !== OPS.save ||
  45546. fnArray[i + 1] !== OPS.transform ||
  45547. fnArray[i + 2] !== OPS.paintImageXObject ||
  45548. fnArray[i + 3] !== OPS.restore) {
  45549. break; // ops don't match
  45550. }
  45551. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  45552. argsArray[i + 1][1] !== 0 ||
  45553. argsArray[i + 1][2] !== 0 ||
  45554. argsArray[i + 1][3] !== firstTransformArg3) {
  45555. break; // transforms don't match
  45556. }
  45557. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  45558. break; // images don't match
  45559. }
  45560. i += 4;
  45561. }
  45562. // At this point, i is the index of the first op past the last valid
  45563. // quartet.
  45564. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  45565. if (count < MIN_IMAGES_IN_BLOCK) {
  45566. return i;
  45567. }
  45568. // Extract the (x,y) positions from all of the matching transforms.
  45569. var positions = new Float32Array(count * 2);
  45570. var iTransform = iFirstTransform;
  45571. for (var q = 0; q < count; q++, iTransform += 4) {
  45572. var transformArgs = argsArray[iTransform];
  45573. positions[(q << 1)] = transformArgs[4];
  45574. positions[(q << 1) + 1] = transformArgs[5];
  45575. }
  45576. // Replace queue items.
  45577. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  45578. positions];
  45579. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  45580. argsArray.splice(iFirstSave, count * 4, args);
  45581. return iFirstSave + 1;
  45582. });
  45583. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  45584. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  45585. // sequences, if the font for each one is the same.
  45586. addState(InitialState,
  45587. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  45588. function (context) {
  45589. var MIN_CHARS_IN_BLOCK = 3;
  45590. var MAX_CHARS_IN_BLOCK = 1000;
  45591. var fnArray = context.fnArray, argsArray = context.argsArray;
  45592. var curr = context.iCurr;
  45593. var iFirstBeginText = curr - 4;
  45594. var iFirstSetFont = curr - 3;
  45595. var iFirstSetTextMatrix = curr - 2;
  45596. var iFirstShowText = curr - 1;
  45597. var iFirstEndText = curr;
  45598. // Look for the quintets.
  45599. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  45600. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  45601. var i = iFirstBeginText + 5;
  45602. var ii = fnArray.length;
  45603. while (i + 4 < ii) {
  45604. if (fnArray[i] !== OPS.beginText ||
  45605. fnArray[i + 1] !== OPS.setFont ||
  45606. fnArray[i + 2] !== OPS.setTextMatrix ||
  45607. fnArray[i + 3] !== OPS.showText ||
  45608. fnArray[i + 4] !== OPS.endText) {
  45609. break; // ops don't match
  45610. }
  45611. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  45612. argsArray[i + 1][1] !== firstSetFontArg1) {
  45613. break; // fonts don't match
  45614. }
  45615. i += 5;
  45616. }
  45617. // At this point, i is the index of the first op past the last valid
  45618. // quintet.
  45619. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  45620. if (count < MIN_CHARS_IN_BLOCK) {
  45621. return i;
  45622. }
  45623. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  45624. // showText, endText), include that as well. (E.g. <something> might be
  45625. // |dependency|.)
  45626. var iFirst = iFirstBeginText;
  45627. if (iFirstBeginText >= 4 &&
  45628. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  45629. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  45630. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  45631. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  45632. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  45633. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  45634. count++;
  45635. iFirst -= 5;
  45636. }
  45637. // Remove (endText, beginText, setFont) trios.
  45638. var iEndText = iFirst + 4;
  45639. for (var q = 1; q < count; q++) {
  45640. fnArray.splice(iEndText, 3);
  45641. argsArray.splice(iEndText, 3);
  45642. iEndText += 2;
  45643. }
  45644. return iEndText + 1;
  45645. });
  45646. function QueueOptimizer() {}
  45647. QueueOptimizer.prototype = {
  45648. optimize: function QueueOptimizer_optimize(queue) {
  45649. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  45650. var context = {
  45651. iCurr: 0,
  45652. fnArray: fnArray,
  45653. argsArray: argsArray
  45654. };
  45655. var state;
  45656. var i = 0, ii = fnArray.length;
  45657. while (i < ii) {
  45658. state = (state || InitialState)[fnArray[i]];
  45659. if (typeof state === 'function') { // we found some handler
  45660. context.iCurr = i;
  45661. // state() returns the index of the first non-matching op (if we
  45662. // didn't match) or the first op past the modified ops (if we did
  45663. // match and replace).
  45664. i = state(context);
  45665. state = undefined; // reset the state machine
  45666. ii = context.fnArray.length;
  45667. } else {
  45668. i++;
  45669. }
  45670. }
  45671. }
  45672. };
  45673. return QueueOptimizer;
  45674. })();
  45675. exports.OperatorList = OperatorList;
  45676. exports.PartialEvaluator = PartialEvaluator;
  45677. }));
  45678. (function (root, factory) {
  45679. {
  45680. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  45681. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  45682. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  45683. }
  45684. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  45685. coreColorSpace, coreObj, coreEvaluator) {
  45686. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  45687. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  45688. var AnnotationFlag = sharedUtil.AnnotationFlag;
  45689. var AnnotationType = sharedUtil.AnnotationType;
  45690. var OPS = sharedUtil.OPS;
  45691. var Util = sharedUtil.Util;
  45692. var isBool = sharedUtil.isBool;
  45693. var isString = sharedUtil.isString;
  45694. var isArray = sharedUtil.isArray;
  45695. var isInt = sharedUtil.isInt;
  45696. var isValidUrl = sharedUtil.isValidUrl;
  45697. var stringToBytes = sharedUtil.stringToBytes;
  45698. var stringToPDFString = sharedUtil.stringToPDFString;
  45699. var stringToUTF8String = sharedUtil.stringToUTF8String;
  45700. var warn = sharedUtil.warn;
  45701. var Dict = corePrimitives.Dict;
  45702. var isDict = corePrimitives.isDict;
  45703. var isName = corePrimitives.isName;
  45704. var isRef = corePrimitives.isRef;
  45705. var Stream = coreStream.Stream;
  45706. var ColorSpace = coreColorSpace.ColorSpace;
  45707. var ObjectLoader = coreObj.ObjectLoader;
  45708. var FileSpec = coreObj.FileSpec;
  45709. var OperatorList = coreEvaluator.OperatorList;
  45710. /**
  45711. * @class
  45712. * @alias AnnotationFactory
  45713. */
  45714. function AnnotationFactory() {}
  45715. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  45716. /**
  45717. * @param {XRef} xref
  45718. * @param {Object} ref
  45719. * @param {string} uniquePrefix
  45720. * @param {Object} idCounters
  45721. * @returns {Annotation}
  45722. */
  45723. create: function AnnotationFactory_create(xref, ref,
  45724. uniquePrefix, idCounters) {
  45725. var dict = xref.fetchIfRef(ref);
  45726. if (!isDict(dict)) {
  45727. return;
  45728. }
  45729. var id = isRef(ref) ? ref.toString() :
  45730. 'annot_' + (uniquePrefix || '') + (++idCounters.obj);
  45731. // Determine the annotation's subtype.
  45732. var subtype = dict.get('Subtype');
  45733. subtype = isName(subtype) ? subtype.name : null;
  45734. // Return the right annotation object based on the subtype and field type.
  45735. var parameters = {
  45736. xref: xref,
  45737. dict: dict,
  45738. ref: isRef(ref) ? ref : null,
  45739. subtype: subtype,
  45740. id: id,
  45741. };
  45742. switch (subtype) {
  45743. case 'Link':
  45744. return new LinkAnnotation(parameters);
  45745. case 'Text':
  45746. return new TextAnnotation(parameters);
  45747. case 'Widget':
  45748. var fieldType = Util.getInheritableProperty(dict, 'FT');
  45749. fieldType = isName(fieldType) ? fieldType.name : null;
  45750. switch (fieldType) {
  45751. case 'Tx':
  45752. return new TextWidgetAnnotation(parameters);
  45753. }
  45754. warn('Unimplemented widget field type "' + fieldType + '", ' +
  45755. 'falling back to base field type.');
  45756. return new WidgetAnnotation(parameters);
  45757. case 'Popup':
  45758. return new PopupAnnotation(parameters);
  45759. case 'Highlight':
  45760. return new HighlightAnnotation(parameters);
  45761. case 'Underline':
  45762. return new UnderlineAnnotation(parameters);
  45763. case 'Squiggly':
  45764. return new SquigglyAnnotation(parameters);
  45765. case 'StrikeOut':
  45766. return new StrikeOutAnnotation(parameters);
  45767. case 'FileAttachment':
  45768. return new FileAttachmentAnnotation(parameters);
  45769. default:
  45770. if (!subtype) {
  45771. warn('Annotation is missing the required /Subtype.');
  45772. } else {
  45773. warn('Unimplemented annotation type "' + subtype + '", ' +
  45774. 'falling back to base annotation.');
  45775. }
  45776. return new Annotation(parameters);
  45777. }
  45778. }
  45779. };
  45780. var Annotation = (function AnnotationClosure() {
  45781. // 12.5.5: Algorithm: Appearance streams
  45782. function getTransformMatrix(rect, bbox, matrix) {
  45783. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  45784. var minX = bounds[0];
  45785. var minY = bounds[1];
  45786. var maxX = bounds[2];
  45787. var maxY = bounds[3];
  45788. if (minX === maxX || minY === maxY) {
  45789. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  45790. // just apply the transform for rect
  45791. return [1, 0, 0, 1, rect[0], rect[1]];
  45792. }
  45793. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  45794. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  45795. return [
  45796. xRatio,
  45797. 0,
  45798. 0,
  45799. yRatio,
  45800. rect[0] - minX * xRatio,
  45801. rect[1] - minY * yRatio
  45802. ];
  45803. }
  45804. function getDefaultAppearance(dict) {
  45805. var appearanceState = dict.get('AP');
  45806. if (!isDict(appearanceState)) {
  45807. return;
  45808. }
  45809. var appearance;
  45810. var appearances = appearanceState.get('N');
  45811. if (isDict(appearances)) {
  45812. var as = dict.get('AS');
  45813. if (as && appearances.has(as.name)) {
  45814. appearance = appearances.get(as.name);
  45815. }
  45816. } else {
  45817. appearance = appearances;
  45818. }
  45819. return appearance;
  45820. }
  45821. function Annotation(params) {
  45822. var dict = params.dict;
  45823. this.setFlags(dict.get('F'));
  45824. this.setRectangle(dict.getArray('Rect'));
  45825. this.setColor(dict.getArray('C'));
  45826. this.setBorderStyle(dict);
  45827. this.appearance = getDefaultAppearance(dict);
  45828. // Expose public properties using a data object.
  45829. this.data = {};
  45830. this.data.id = params.id;
  45831. this.data.subtype = params.subtype;
  45832. this.data.annotationFlags = this.flags;
  45833. this.data.rect = this.rectangle;
  45834. this.data.color = this.color;
  45835. this.data.borderStyle = this.borderStyle;
  45836. this.data.hasAppearance = !!this.appearance;
  45837. }
  45838. Annotation.prototype = {
  45839. /**
  45840. * @private
  45841. */
  45842. _hasFlag: function Annotation_hasFlag(flags, flag) {
  45843. return !!(flags & flag);
  45844. },
  45845. /**
  45846. * @private
  45847. */
  45848. _isViewable: function Annotation_isViewable(flags) {
  45849. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  45850. !this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
  45851. !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  45852. },
  45853. /**
  45854. * @private
  45855. */
  45856. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  45857. return this._hasFlag(flags, AnnotationFlag.PRINT) &&
  45858. !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  45859. !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  45860. },
  45861. /**
  45862. * @return {boolean}
  45863. */
  45864. get viewable() {
  45865. if (this.flags === 0) {
  45866. return true;
  45867. }
  45868. return this._isViewable(this.flags);
  45869. },
  45870. /**
  45871. * @return {boolean}
  45872. */
  45873. get printable() {
  45874. if (this.flags === 0) {
  45875. return false;
  45876. }
  45877. return this._isPrintable(this.flags);
  45878. },
  45879. /**
  45880. * Set the flags.
  45881. *
  45882. * @public
  45883. * @memberof Annotation
  45884. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  45885. * characteristics
  45886. * @see {@link shared/util.js}
  45887. */
  45888. setFlags: function Annotation_setFlags(flags) {
  45889. this.flags = (isInt(flags) && flags > 0) ? flags : 0;
  45890. },
  45891. /**
  45892. * Check if a provided flag is set.
  45893. *
  45894. * @public
  45895. * @memberof Annotation
  45896. * @param {number} flag - Hexadecimal representation for an annotation
  45897. * characteristic
  45898. * @return {boolean}
  45899. * @see {@link shared/util.js}
  45900. */
  45901. hasFlag: function Annotation_hasFlag(flag) {
  45902. return this._hasFlag(this.flags, flag);
  45903. },
  45904. /**
  45905. * Set the rectangle.
  45906. *
  45907. * @public
  45908. * @memberof Annotation
  45909. * @param {Array} rectangle - The rectangle array with exactly four entries
  45910. */
  45911. setRectangle: function Annotation_setRectangle(rectangle) {
  45912. if (isArray(rectangle) && rectangle.length === 4) {
  45913. this.rectangle = Util.normalizeRect(rectangle);
  45914. } else {
  45915. this.rectangle = [0, 0, 0, 0];
  45916. }
  45917. },
  45918. /**
  45919. * Set the color and take care of color space conversion.
  45920. *
  45921. * @public
  45922. * @memberof Annotation
  45923. * @param {Array} color - The color array containing either 0
  45924. * (transparent), 1 (grayscale), 3 (RGB) or
  45925. * 4 (CMYK) elements
  45926. */
  45927. setColor: function Annotation_setColor(color) {
  45928. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  45929. if (!isArray(color)) {
  45930. this.color = rgbColor;
  45931. return;
  45932. }
  45933. switch (color.length) {
  45934. case 0: // Transparent, which we indicate with a null value
  45935. this.color = null;
  45936. break;
  45937. case 1: // Convert grayscale to RGB
  45938. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  45939. this.color = rgbColor;
  45940. break;
  45941. case 3: // Convert RGB percentages to RGB
  45942. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  45943. this.color = rgbColor;
  45944. break;
  45945. case 4: // Convert CMYK to RGB
  45946. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  45947. this.color = rgbColor;
  45948. break;
  45949. default:
  45950. this.color = rgbColor;
  45951. break;
  45952. }
  45953. },
  45954. /**
  45955. * Set the border style (as AnnotationBorderStyle object).
  45956. *
  45957. * @public
  45958. * @memberof Annotation
  45959. * @param {Dict} borderStyle - The border style dictionary
  45960. */
  45961. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  45962. this.borderStyle = new AnnotationBorderStyle();
  45963. if (!isDict(borderStyle)) {
  45964. return;
  45965. }
  45966. if (borderStyle.has('BS')) {
  45967. var dict = borderStyle.get('BS');
  45968. var dictType = dict.get('Type');
  45969. if (!dictType || isName(dictType, 'Border')) {
  45970. this.borderStyle.setWidth(dict.get('W'));
  45971. this.borderStyle.setStyle(dict.get('S'));
  45972. this.borderStyle.setDashArray(dict.getArray('D'));
  45973. }
  45974. } else if (borderStyle.has('Border')) {
  45975. var array = borderStyle.getArray('Border');
  45976. if (isArray(array) && array.length >= 3) {
  45977. this.borderStyle.setHorizontalCornerRadius(array[0]);
  45978. this.borderStyle.setVerticalCornerRadius(array[1]);
  45979. this.borderStyle.setWidth(array[2]);
  45980. if (array.length === 4) { // Dash array available
  45981. this.borderStyle.setDashArray(array[3]);
  45982. }
  45983. }
  45984. } else {
  45985. // There are no border entries in the dictionary. According to the
  45986. // specification, we should draw a solid border of width 1 in that
  45987. // case, but Adobe Reader did not implement that part of the
  45988. // specification and instead draws no border at all, so we do the same.
  45989. // See also https://github.com/mozilla/pdf.js/issues/6179.
  45990. this.borderStyle.setWidth(0);
  45991. }
  45992. },
  45993. /**
  45994. * Prepare the annotation for working with a popup in the display layer.
  45995. *
  45996. * @private
  45997. * @memberof Annotation
  45998. * @param {Dict} dict - The annotation's data dictionary
  45999. */
  46000. _preparePopup: function Annotation_preparePopup(dict) {
  46001. if (!dict.has('C')) {
  46002. // Fall back to the default background color.
  46003. this.data.color = null;
  46004. }
  46005. this.data.hasPopup = dict.has('Popup');
  46006. this.data.title = stringToPDFString(dict.get('T') || '');
  46007. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  46008. },
  46009. loadResources: function Annotation_loadResources(keys) {
  46010. return new Promise(function (resolve, reject) {
  46011. this.appearance.dict.getAsync('Resources').then(function (resources) {
  46012. if (!resources) {
  46013. resolve();
  46014. return;
  46015. }
  46016. var objectLoader = new ObjectLoader(resources.map,
  46017. keys,
  46018. resources.xref);
  46019. objectLoader.load().then(function() {
  46020. resolve(resources);
  46021. }, reject);
  46022. }, reject);
  46023. }.bind(this));
  46024. },
  46025. getOperatorList: function Annotation_getOperatorList(evaluator, task,
  46026. renderForms) {
  46027. if (!this.appearance) {
  46028. return Promise.resolve(new OperatorList());
  46029. }
  46030. var data = this.data;
  46031. var appearanceDict = this.appearance.dict;
  46032. var resourcesPromise = this.loadResources([
  46033. 'ExtGState',
  46034. 'ColorSpace',
  46035. 'Pattern',
  46036. 'Shading',
  46037. 'XObject',
  46038. 'Font'
  46039. // ProcSet
  46040. // Properties
  46041. ]);
  46042. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  46043. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0 ,0];
  46044. var transform = getTransformMatrix(data.rect, bbox, matrix);
  46045. var self = this;
  46046. return resourcesPromise.then(function(resources) {
  46047. var opList = new OperatorList();
  46048. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  46049. return evaluator.getOperatorList(self.appearance, task,
  46050. resources, opList).
  46051. then(function () {
  46052. opList.addOp(OPS.endAnnotation, []);
  46053. self.appearance.reset();
  46054. return opList;
  46055. });
  46056. });
  46057. }
  46058. };
  46059. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  46060. annotations, opList, partialEvaluator, task, intent, renderForms) {
  46061. var annotationPromises = [];
  46062. for (var i = 0, n = annotations.length; i < n; ++i) {
  46063. if ((intent === 'display' && annotations[i].viewable) ||
  46064. (intent === 'print' && annotations[i].printable)) {
  46065. annotationPromises.push(
  46066. annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  46067. }
  46068. }
  46069. return Promise.all(annotationPromises).then(function(operatorLists) {
  46070. opList.addOp(OPS.beginAnnotations, []);
  46071. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  46072. opList.addOpList(operatorLists[i]);
  46073. }
  46074. opList.addOp(OPS.endAnnotations, []);
  46075. });
  46076. };
  46077. return Annotation;
  46078. })();
  46079. /**
  46080. * Contains all data regarding an annotation's border style.
  46081. *
  46082. * @class
  46083. */
  46084. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  46085. /**
  46086. * @constructor
  46087. * @private
  46088. */
  46089. function AnnotationBorderStyle() {
  46090. this.width = 1;
  46091. this.style = AnnotationBorderStyleType.SOLID;
  46092. this.dashArray = [3];
  46093. this.horizontalCornerRadius = 0;
  46094. this.verticalCornerRadius = 0;
  46095. }
  46096. AnnotationBorderStyle.prototype = {
  46097. /**
  46098. * Set the width.
  46099. *
  46100. * @public
  46101. * @memberof AnnotationBorderStyle
  46102. * @param {integer} width - The width
  46103. */
  46104. setWidth: function AnnotationBorderStyle_setWidth(width) {
  46105. if (width === (width | 0)) {
  46106. this.width = width;
  46107. }
  46108. },
  46109. /**
  46110. * Set the style.
  46111. *
  46112. * @public
  46113. * @memberof AnnotationBorderStyle
  46114. * @param {Object} style - The style object
  46115. * @see {@link shared/util.js}
  46116. */
  46117. setStyle: function AnnotationBorderStyle_setStyle(style) {
  46118. if (!style) {
  46119. return;
  46120. }
  46121. switch (style.name) {
  46122. case 'S':
  46123. this.style = AnnotationBorderStyleType.SOLID;
  46124. break;
  46125. case 'D':
  46126. this.style = AnnotationBorderStyleType.DASHED;
  46127. break;
  46128. case 'B':
  46129. this.style = AnnotationBorderStyleType.BEVELED;
  46130. break;
  46131. case 'I':
  46132. this.style = AnnotationBorderStyleType.INSET;
  46133. break;
  46134. case 'U':
  46135. this.style = AnnotationBorderStyleType.UNDERLINE;
  46136. break;
  46137. default:
  46138. break;
  46139. }
  46140. },
  46141. /**
  46142. * Set the dash array.
  46143. *
  46144. * @public
  46145. * @memberof AnnotationBorderStyle
  46146. * @param {Array} dashArray - The dash array with at least one element
  46147. */
  46148. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  46149. // We validate the dash array, but we do not use it because CSS does not
  46150. // allow us to change spacing of dashes. For more information, visit
  46151. // http://www.w3.org/TR/css3-background/#the-border-style.
  46152. if (isArray(dashArray) && dashArray.length > 0) {
  46153. // According to the PDF specification: the elements in a dashArray
  46154. // shall be numbers that are nonnegative and not all equal to zero.
  46155. var isValid = true;
  46156. var allZeros = true;
  46157. for (var i = 0, len = dashArray.length; i < len; i++) {
  46158. var element = dashArray[i];
  46159. var validNumber = (+element >= 0);
  46160. if (!validNumber) {
  46161. isValid = false;
  46162. break;
  46163. } else if (element > 0) {
  46164. allZeros = false;
  46165. }
  46166. }
  46167. if (isValid && !allZeros) {
  46168. this.dashArray = dashArray;
  46169. } else {
  46170. this.width = 0; // Adobe behavior when the array is invalid.
  46171. }
  46172. } else if (dashArray) {
  46173. this.width = 0; // Adobe behavior when the array is invalid.
  46174. }
  46175. },
  46176. /**
  46177. * Set the horizontal corner radius (from a Border dictionary).
  46178. *
  46179. * @public
  46180. * @memberof AnnotationBorderStyle
  46181. * @param {integer} radius - The horizontal corner radius
  46182. */
  46183. setHorizontalCornerRadius:
  46184. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  46185. if (radius === (radius | 0)) {
  46186. this.horizontalCornerRadius = radius;
  46187. }
  46188. },
  46189. /**
  46190. * Set the vertical corner radius (from a Border dictionary).
  46191. *
  46192. * @public
  46193. * @memberof AnnotationBorderStyle
  46194. * @param {integer} radius - The vertical corner radius
  46195. */
  46196. setVerticalCornerRadius:
  46197. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  46198. if (radius === (radius | 0)) {
  46199. this.verticalCornerRadius = radius;
  46200. }
  46201. }
  46202. };
  46203. return AnnotationBorderStyle;
  46204. })();
  46205. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  46206. function WidgetAnnotation(params) {
  46207. Annotation.call(this, params);
  46208. var dict = params.dict;
  46209. var data = this.data;
  46210. data.annotationType = AnnotationType.WIDGET;
  46211. data.fieldValue = stringToPDFString(
  46212. Util.getInheritableProperty(dict, 'V') || '');
  46213. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  46214. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  46215. var fieldType = Util.getInheritableProperty(dict, 'FT');
  46216. data.fieldType = isName(fieldType) ? fieldType.name : null;
  46217. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  46218. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  46219. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  46220. data.fieldFlags = 0;
  46221. }
  46222. // Hide signatures because we cannot validate them.
  46223. if (data.fieldType === 'Sig') {
  46224. this.setFlags(AnnotationFlag.HIDDEN);
  46225. }
  46226. // Building the full field name by collecting the field and
  46227. // its ancestors 'T' data and joining them using '.'.
  46228. var fieldName = [];
  46229. var namedItem = dict;
  46230. var ref = params.ref;
  46231. while (namedItem) {
  46232. var parent = namedItem.get('Parent');
  46233. var parentRef = namedItem.getRaw('Parent');
  46234. var name = namedItem.get('T');
  46235. if (name) {
  46236. fieldName.unshift(stringToPDFString(name));
  46237. } else if (parent && ref) {
  46238. // The field name is absent, that means more than one field
  46239. // with the same name may exist. Replacing the empty name
  46240. // with the '`' plus index in the parent's 'Kids' array.
  46241. // This is not in the PDF spec but necessary to id the
  46242. // the input controls.
  46243. var kids = parent.get('Kids');
  46244. var j, jj;
  46245. for (j = 0, jj = kids.length; j < jj; j++) {
  46246. var kidRef = kids[j];
  46247. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  46248. break;
  46249. }
  46250. }
  46251. fieldName.unshift('`' + j);
  46252. }
  46253. namedItem = parent;
  46254. ref = parentRef;
  46255. }
  46256. data.fullName = fieldName.join('.');
  46257. }
  46258. Util.inherit(WidgetAnnotation, Annotation, {
  46259. /**
  46260. * Check if a provided field flag is set.
  46261. *
  46262. * @public
  46263. * @memberof WidgetAnnotation
  46264. * @param {number} flag - Hexadecimal representation for an annotation
  46265. * field characteristic
  46266. * @return {boolean}
  46267. * @see {@link shared/util.js}
  46268. */
  46269. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  46270. return !!(this.data.fieldFlags & flag);
  46271. },
  46272. });
  46273. return WidgetAnnotation;
  46274. })();
  46275. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  46276. function TextWidgetAnnotation(params) {
  46277. WidgetAnnotation.call(this, params);
  46278. // Determine the alignment of text in the field.
  46279. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  46280. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  46281. alignment = null;
  46282. }
  46283. this.data.textAlignment = alignment;
  46284. // Determine the maximum length of text in the field.
  46285. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  46286. if (!isInt(maximumLength) || maximumLength < 0) {
  46287. maximumLength = null;
  46288. }
  46289. this.data.maxLen = maximumLength;
  46290. // Process field flags for the display layer.
  46291. this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  46292. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  46293. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
  46294. !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) &&
  46295. !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) &&
  46296. !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) &&
  46297. this.data.maxLen !== null;
  46298. }
  46299. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  46300. getOperatorList:
  46301. function TextWidgetAnnotation_getOperatorList(evaluator, task,
  46302. renderForms) {
  46303. var operatorList = new OperatorList();
  46304. // Do not render form elements on the canvas when interactive forms are
  46305. // enabled. The display layer is responsible for rendering them instead.
  46306. if (renderForms) {
  46307. return Promise.resolve(operatorList);
  46308. }
  46309. if (this.appearance) {
  46310. return Annotation.prototype.getOperatorList.call(this, evaluator, task,
  46311. renderForms);
  46312. }
  46313. // Even if there is an appearance stream, ignore it. This is the
  46314. // behaviour used by Adobe Reader.
  46315. if (!this.data.defaultAppearance) {
  46316. return Promise.resolve(operatorList);
  46317. }
  46318. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  46319. return evaluator.getOperatorList(stream, task, this.fieldResources,
  46320. operatorList).
  46321. then(function () {
  46322. return operatorList;
  46323. });
  46324. }
  46325. });
  46326. return TextWidgetAnnotation;
  46327. })();
  46328. var TextAnnotation = (function TextAnnotationClosure() {
  46329. var DEFAULT_ICON_SIZE = 22; // px
  46330. function TextAnnotation(parameters) {
  46331. Annotation.call(this, parameters);
  46332. this.data.annotationType = AnnotationType.TEXT;
  46333. if (this.data.hasAppearance) {
  46334. this.data.name = 'NoIcon';
  46335. } else {
  46336. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  46337. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  46338. this.data.name = parameters.dict.has('Name') ?
  46339. parameters.dict.get('Name').name : 'Note';
  46340. }
  46341. this._preparePopup(parameters.dict);
  46342. }
  46343. Util.inherit(TextAnnotation, Annotation, {});
  46344. return TextAnnotation;
  46345. })();
  46346. var LinkAnnotation = (function LinkAnnotationClosure() {
  46347. function LinkAnnotation(params) {
  46348. Annotation.call(this, params);
  46349. var dict = params.dict;
  46350. var data = this.data;
  46351. data.annotationType = AnnotationType.LINK;
  46352. var action = dict.get('A'), url, dest;
  46353. if (action && isDict(action)) {
  46354. var linkType = action.get('S').name;
  46355. switch (linkType) {
  46356. case 'URI':
  46357. url = action.get('URI');
  46358. if (isName(url)) {
  46359. // Some bad PDFs do not put parentheses around relative URLs.
  46360. url = '/' + url.name;
  46361. } else if (url) {
  46362. url = addDefaultProtocolToUrl(url);
  46363. }
  46364. // TODO: pdf spec mentions urls can be relative to a Base
  46365. // entry in the dictionary.
  46366. break;
  46367. case 'GoTo':
  46368. dest = action.get('D');
  46369. break;
  46370. case 'GoToR':
  46371. var urlDict = action.get('F');
  46372. if (isDict(urlDict)) {
  46373. // We assume that we found a FileSpec dictionary
  46374. // and fetch the URL without checking any further.
  46375. url = urlDict.get('F') || null;
  46376. } else if (isString(urlDict)) {
  46377. url = urlDict;
  46378. }
  46379. // NOTE: the destination is relative to the *remote* document.
  46380. var remoteDest = action.get('D');
  46381. if (remoteDest) {
  46382. if (isName(remoteDest)) {
  46383. remoteDest = remoteDest.name;
  46384. }
  46385. if (isString(url)) {
  46386. var baseUrl = url.split('#')[0];
  46387. if (isString(remoteDest)) {
  46388. // In practice, a named destination may contain only a number.
  46389. // If that happens, use the '#nameddest=' form to avoid the link
  46390. // redirecting to a page, instead of the correct destination.
  46391. url = baseUrl + '#' +
  46392. (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  46393. } else if (isArray(remoteDest)) {
  46394. url = baseUrl + '#' + JSON.stringify(remoteDest);
  46395. }
  46396. }
  46397. }
  46398. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  46399. var newWindow = action.get('NewWindow');
  46400. if (isBool(newWindow)) {
  46401. data.newWindow = newWindow;
  46402. }
  46403. break;
  46404. case 'Named':
  46405. data.action = action.get('N').name;
  46406. break;
  46407. default:
  46408. warn('unrecognized link type: ' + linkType);
  46409. }
  46410. } else if (dict.has('Dest')) { // Simple destination link.
  46411. dest = dict.get('Dest');
  46412. }
  46413. if (url) {
  46414. if (isValidUrl(url, /* allowRelative = */ false)) {
  46415. data.url = tryConvertUrlEncoding(url);
  46416. }
  46417. }
  46418. if (dest) {
  46419. data.dest = isName(dest) ? dest.name : dest;
  46420. }
  46421. }
  46422. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  46423. function addDefaultProtocolToUrl(url) {
  46424. if (isString(url) && url.indexOf('www.') === 0) {
  46425. return ('http://' + url);
  46426. }
  46427. return url;
  46428. }
  46429. function tryConvertUrlEncoding(url) {
  46430. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  46431. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  46432. try {
  46433. return stringToUTF8String(url);
  46434. } catch (e) {
  46435. return url;
  46436. }
  46437. }
  46438. Util.inherit(LinkAnnotation, Annotation, {});
  46439. return LinkAnnotation;
  46440. })();
  46441. var PopupAnnotation = (function PopupAnnotationClosure() {
  46442. function PopupAnnotation(parameters) {
  46443. Annotation.call(this, parameters);
  46444. this.data.annotationType = AnnotationType.POPUP;
  46445. var dict = parameters.dict;
  46446. var parentItem = dict.get('Parent');
  46447. if (!parentItem) {
  46448. warn('Popup annotation has a missing or invalid parent annotation.');
  46449. return;
  46450. }
  46451. this.data.parentId = dict.getRaw('Parent').toString();
  46452. this.data.title = stringToPDFString(parentItem.get('T') || '');
  46453. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  46454. if (!parentItem.has('C')) {
  46455. // Fall back to the default background color.
  46456. this.data.color = null;
  46457. } else {
  46458. this.setColor(parentItem.getArray('C'));
  46459. this.data.color = this.color;
  46460. }
  46461. // If the Popup annotation is not viewable, but the parent annotation is,
  46462. // that is most likely a bug. Fallback to inherit the flags from the parent
  46463. // annotation (this is consistent with the behaviour in Adobe Reader).
  46464. if (!this.viewable) {
  46465. var parentFlags = parentItem.get('F');
  46466. if (this._isViewable(parentFlags)) {
  46467. this.setFlags(parentFlags);
  46468. }
  46469. }
  46470. }
  46471. Util.inherit(PopupAnnotation, Annotation, {});
  46472. return PopupAnnotation;
  46473. })();
  46474. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  46475. function HighlightAnnotation(parameters) {
  46476. Annotation.call(this, parameters);
  46477. this.data.annotationType = AnnotationType.HIGHLIGHT;
  46478. this._preparePopup(parameters.dict);
  46479. // PDF viewers completely ignore any border styles.
  46480. this.data.borderStyle.setWidth(0);
  46481. }
  46482. Util.inherit(HighlightAnnotation, Annotation, {});
  46483. return HighlightAnnotation;
  46484. })();
  46485. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  46486. function UnderlineAnnotation(parameters) {
  46487. Annotation.call(this, parameters);
  46488. this.data.annotationType = AnnotationType.UNDERLINE;
  46489. this._preparePopup(parameters.dict);
  46490. // PDF viewers completely ignore any border styles.
  46491. this.data.borderStyle.setWidth(0);
  46492. }
  46493. Util.inherit(UnderlineAnnotation, Annotation, {});
  46494. return UnderlineAnnotation;
  46495. })();
  46496. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  46497. function SquigglyAnnotation(parameters) {
  46498. Annotation.call(this, parameters);
  46499. this.data.annotationType = AnnotationType.SQUIGGLY;
  46500. this._preparePopup(parameters.dict);
  46501. // PDF viewers completely ignore any border styles.
  46502. this.data.borderStyle.setWidth(0);
  46503. }
  46504. Util.inherit(SquigglyAnnotation, Annotation, {});
  46505. return SquigglyAnnotation;
  46506. })();
  46507. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  46508. function StrikeOutAnnotation(parameters) {
  46509. Annotation.call(this, parameters);
  46510. this.data.annotationType = AnnotationType.STRIKEOUT;
  46511. this._preparePopup(parameters.dict);
  46512. // PDF viewers completely ignore any border styles.
  46513. this.data.borderStyle.setWidth(0);
  46514. }
  46515. Util.inherit(StrikeOutAnnotation, Annotation, {});
  46516. return StrikeOutAnnotation;
  46517. })();
  46518. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  46519. function FileAttachmentAnnotation(parameters) {
  46520. Annotation.call(this, parameters);
  46521. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  46522. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  46523. this.data.file = file.serializable;
  46524. this._preparePopup(parameters.dict);
  46525. }
  46526. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  46527. return FileAttachmentAnnotation;
  46528. })();
  46529. exports.Annotation = Annotation;
  46530. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  46531. exports.AnnotationFactory = AnnotationFactory;
  46532. }));
  46533. (function (root, factory) {
  46534. {
  46535. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  46536. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  46537. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  46538. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  46539. }
  46540. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  46541. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  46542. var MissingDataException = sharedUtil.MissingDataException;
  46543. var Util = sharedUtil.Util;
  46544. var assert = sharedUtil.assert;
  46545. var error = sharedUtil.error;
  46546. var info = sharedUtil.info;
  46547. var isArray = sharedUtil.isArray;
  46548. var isArrayBuffer = sharedUtil.isArrayBuffer;
  46549. var isString = sharedUtil.isString;
  46550. var shadow = sharedUtil.shadow;
  46551. var stringToBytes = sharedUtil.stringToBytes;
  46552. var stringToPDFString = sharedUtil.stringToPDFString;
  46553. var warn = sharedUtil.warn;
  46554. var isSpace = sharedUtil.isSpace;
  46555. var Dict = corePrimitives.Dict;
  46556. var isDict = corePrimitives.isDict;
  46557. var isName = corePrimitives.isName;
  46558. var isStream = corePrimitives.isStream;
  46559. var NullStream = coreStream.NullStream;
  46560. var Stream = coreStream.Stream;
  46561. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  46562. var Catalog = coreObj.Catalog;
  46563. var ObjectLoader = coreObj.ObjectLoader;
  46564. var XRef = coreObj.XRef;
  46565. var Linearization = coreParser.Linearization;
  46566. var calculateMD5 = coreCrypto.calculateMD5;
  46567. var OperatorList = coreEvaluator.OperatorList;
  46568. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  46569. var Annotation = coreAnnotation.Annotation;
  46570. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  46571. var Page = (function PageClosure() {
  46572. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  46573. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  46574. this.pdfManager = pdfManager;
  46575. this.pageIndex = pageIndex;
  46576. this.pageDict = pageDict;
  46577. this.xref = xref;
  46578. this.ref = ref;
  46579. this.fontCache = fontCache;
  46580. this.uniquePrefix = 'p' + this.pageIndex + '_';
  46581. this.idCounters = {
  46582. obj: 0
  46583. };
  46584. this.evaluatorOptions = pdfManager.evaluatorOptions;
  46585. this.resourcesPromise = null;
  46586. }
  46587. Page.prototype = {
  46588. getPageProp: function Page_getPageProp(key) {
  46589. return this.pageDict.get(key);
  46590. },
  46591. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  46592. var dict = this.pageDict, valueArray = null, loopCount = 0;
  46593. var MAX_LOOP_COUNT = 100;
  46594. // Always walk up the entire parent chain, to be able to find
  46595. // e.g. \Resources placed on multiple levels of the tree.
  46596. while (dict) {
  46597. var value = dict.get(key);
  46598. if (value) {
  46599. if (!valueArray) {
  46600. valueArray = [];
  46601. }
  46602. valueArray.push(value);
  46603. }
  46604. if (++loopCount > MAX_LOOP_COUNT) {
  46605. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  46606. break;
  46607. }
  46608. dict = dict.get('Parent');
  46609. }
  46610. if (!valueArray) {
  46611. return Dict.empty;
  46612. }
  46613. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  46614. loopCount > MAX_LOOP_COUNT) {
  46615. return valueArray[0];
  46616. }
  46617. return Dict.merge(this.xref, valueArray);
  46618. },
  46619. get content() {
  46620. return this.getPageProp('Contents');
  46621. },
  46622. get resources() {
  46623. // For robustness: The spec states that a \Resources entry has to be
  46624. // present, but can be empty. Some document omit it still, in this case
  46625. // we return an empty dictionary.
  46626. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  46627. },
  46628. get mediaBox() {
  46629. var obj = this.getInheritedPageProp('MediaBox');
  46630. // Reset invalid media box to letter size.
  46631. if (!isArray(obj) || obj.length !== 4) {
  46632. obj = LETTER_SIZE_MEDIABOX;
  46633. }
  46634. return shadow(this, 'mediaBox', obj);
  46635. },
  46636. get view() {
  46637. var mediaBox = this.mediaBox;
  46638. var cropBox = this.getInheritedPageProp('CropBox');
  46639. if (!isArray(cropBox) || cropBox.length !== 4) {
  46640. return shadow(this, 'view', mediaBox);
  46641. }
  46642. // From the spec, 6th ed., p.963:
  46643. // "The crop, bleed, trim, and art boxes should not ordinarily
  46644. // extend beyond the boundaries of the media box. If they do, they are
  46645. // effectively reduced to their intersection with the media box."
  46646. cropBox = Util.intersect(cropBox, mediaBox);
  46647. if (!cropBox) {
  46648. return shadow(this, 'view', mediaBox);
  46649. }
  46650. return shadow(this, 'view', cropBox);
  46651. },
  46652. get rotate() {
  46653. var rotate = this.getInheritedPageProp('Rotate') || 0;
  46654. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  46655. if (rotate % 90 !== 0) {
  46656. rotate = 0;
  46657. } else if (rotate >= 360) {
  46658. rotate = rotate % 360;
  46659. } else if (rotate < 0) {
  46660. // The spec doesn't cover negatives, assume its counterclockwise
  46661. // rotation. The following is the other implementation of modulo.
  46662. rotate = ((rotate % 360) + 360) % 360;
  46663. }
  46664. return shadow(this, 'rotate', rotate);
  46665. },
  46666. getContentStream: function Page_getContentStream() {
  46667. var content = this.content;
  46668. var stream;
  46669. if (isArray(content)) {
  46670. // fetching items
  46671. var xref = this.xref;
  46672. var i, n = content.length;
  46673. var streams = [];
  46674. for (i = 0; i < n; ++i) {
  46675. streams.push(xref.fetchIfRef(content[i]));
  46676. }
  46677. stream = new StreamsSequenceStream(streams);
  46678. } else if (isStream(content)) {
  46679. stream = content;
  46680. } else {
  46681. // replacing non-existent page content with empty one
  46682. stream = new NullStream();
  46683. }
  46684. return stream;
  46685. },
  46686. loadResources: function Page_loadResources(keys) {
  46687. if (!this.resourcesPromise) {
  46688. // TODO: add async getInheritedPageProp and remove this.
  46689. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  46690. }
  46691. return this.resourcesPromise.then(function resourceSuccess() {
  46692. var objectLoader = new ObjectLoader(this.resources.map,
  46693. keys,
  46694. this.xref);
  46695. return objectLoader.load();
  46696. }.bind(this));
  46697. },
  46698. getOperatorList: function Page_getOperatorList(handler, task, intent,
  46699. renderInteractiveForms) {
  46700. var self = this;
  46701. var pdfManager = this.pdfManager;
  46702. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  46703. []);
  46704. var resourcesPromise = this.loadResources([
  46705. 'ExtGState',
  46706. 'ColorSpace',
  46707. 'Pattern',
  46708. 'Shading',
  46709. 'XObject',
  46710. 'Font'
  46711. // ProcSet
  46712. // Properties
  46713. ]);
  46714. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  46715. handler, this.pageIndex,
  46716. this.uniquePrefix,
  46717. this.idCounters,
  46718. this.fontCache,
  46719. this.evaluatorOptions);
  46720. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  46721. var pageListPromise = dataPromises.then(function(data) {
  46722. var contentStream = data[0];
  46723. var opList = new OperatorList(intent, handler, self.pageIndex);
  46724. handler.send('StartRenderPage', {
  46725. transparency: partialEvaluator.hasBlendModes(self.resources),
  46726. pageIndex: self.pageIndex,
  46727. intent: intent
  46728. });
  46729. return partialEvaluator.getOperatorList(contentStream, task,
  46730. self.resources, opList).then(function () {
  46731. return opList;
  46732. });
  46733. });
  46734. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  46735. return Promise.all([pageListPromise, annotationsPromise]).then(
  46736. function(datas) {
  46737. var pageOpList = datas[0];
  46738. var annotations = datas[1];
  46739. if (annotations.length === 0) {
  46740. pageOpList.flush(true);
  46741. return pageOpList;
  46742. }
  46743. var annotationsReadyPromise = Annotation.appendToOperatorList(
  46744. annotations, pageOpList, partialEvaluator, task, intent,
  46745. renderInteractiveForms);
  46746. return annotationsReadyPromise.then(function () {
  46747. pageOpList.flush(true);
  46748. return pageOpList;
  46749. });
  46750. });
  46751. },
  46752. extractTextContent: function Page_extractTextContent(task,
  46753. normalizeWhitespace,
  46754. combineTextItems) {
  46755. var handler = {
  46756. on: function nullHandlerOn() {},
  46757. send: function nullHandlerSend() {}
  46758. };
  46759. var self = this;
  46760. var pdfManager = this.pdfManager;
  46761. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  46762. []);
  46763. var resourcesPromise = this.loadResources([
  46764. 'ExtGState',
  46765. 'XObject',
  46766. 'Font'
  46767. ]);
  46768. var dataPromises = Promise.all([contentStreamPromise,
  46769. resourcesPromise]);
  46770. return dataPromises.then(function(data) {
  46771. var contentStream = data[0];
  46772. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  46773. handler, self.pageIndex,
  46774. self.uniquePrefix,
  46775. self.idCounters,
  46776. self.fontCache,
  46777. self.evaluatorOptions);
  46778. return partialEvaluator.getTextContent(contentStream,
  46779. task,
  46780. self.resources,
  46781. /* stateManager = */ null,
  46782. normalizeWhitespace,
  46783. combineTextItems);
  46784. });
  46785. },
  46786. getAnnotationsData: function Page_getAnnotationsData(intent) {
  46787. var annotations = this.annotations;
  46788. var annotationsData = [];
  46789. for (var i = 0, n = annotations.length; i < n; ++i) {
  46790. if (intent) {
  46791. if (!(intent === 'display' && annotations[i].viewable) &&
  46792. !(intent === 'print' && annotations[i].printable)) {
  46793. continue;
  46794. }
  46795. }
  46796. annotationsData.push(annotations[i].data);
  46797. }
  46798. return annotationsData;
  46799. },
  46800. get annotations() {
  46801. var annotations = [];
  46802. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  46803. var annotationFactory = new AnnotationFactory();
  46804. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  46805. var annotationRef = annotationRefs[i];
  46806. var annotation = annotationFactory.create(this.xref, annotationRef,
  46807. this.uniquePrefix,
  46808. this.idCounters);
  46809. if (annotation) {
  46810. annotations.push(annotation);
  46811. }
  46812. }
  46813. return shadow(this, 'annotations', annotations);
  46814. }
  46815. };
  46816. return Page;
  46817. })();
  46818. /**
  46819. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  46820. * `PDFDoc`, this one doesn't have any job management code.
  46821. * Right now there exists one PDFDocument on the main thread + one object
  46822. * for each worker. If there is no worker support enabled, there are two
  46823. * `PDFDocument` objects on the main thread created.
  46824. */
  46825. var PDFDocument = (function PDFDocumentClosure() {
  46826. var FINGERPRINT_FIRST_BYTES = 1024;
  46827. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  46828. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  46829. function PDFDocument(pdfManager, arg, password) {
  46830. if (isStream(arg)) {
  46831. init.call(this, pdfManager, arg, password);
  46832. } else if (isArrayBuffer(arg)) {
  46833. init.call(this, pdfManager, new Stream(arg), password);
  46834. } else {
  46835. error('PDFDocument: Unknown argument type');
  46836. }
  46837. }
  46838. function init(pdfManager, stream, password) {
  46839. assert(stream.length > 0, 'stream must have data');
  46840. this.pdfManager = pdfManager;
  46841. this.stream = stream;
  46842. var xref = new XRef(this.stream, password, pdfManager);
  46843. this.xref = xref;
  46844. }
  46845. function find(stream, needle, limit, backwards) {
  46846. var pos = stream.pos;
  46847. var end = stream.end;
  46848. var strBuf = [];
  46849. if (pos + limit > end) {
  46850. limit = end - pos;
  46851. }
  46852. for (var n = 0; n < limit; ++n) {
  46853. strBuf.push(String.fromCharCode(stream.getByte()));
  46854. }
  46855. var str = strBuf.join('');
  46856. stream.pos = pos;
  46857. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  46858. if (index === -1) {
  46859. return false; /* not found */
  46860. }
  46861. stream.pos += index;
  46862. return true; /* found */
  46863. }
  46864. var DocumentInfoValidators = {
  46865. get entries() {
  46866. // Lazily build this since all the validation functions below are not
  46867. // defined until after this file loads.
  46868. return shadow(this, 'entries', {
  46869. Title: isString,
  46870. Author: isString,
  46871. Subject: isString,
  46872. Keywords: isString,
  46873. Creator: isString,
  46874. Producer: isString,
  46875. CreationDate: isString,
  46876. ModDate: isString,
  46877. Trapped: isName
  46878. });
  46879. }
  46880. };
  46881. PDFDocument.prototype = {
  46882. parse: function PDFDocument_parse(recoveryMode) {
  46883. this.setup(recoveryMode);
  46884. var version = this.catalog.catDict.get('Version');
  46885. if (isName(version)) {
  46886. this.pdfFormatVersion = version.name;
  46887. }
  46888. try {
  46889. // checking if AcroForm is present
  46890. this.acroForm = this.catalog.catDict.get('AcroForm');
  46891. if (this.acroForm) {
  46892. this.xfa = this.acroForm.get('XFA');
  46893. var fields = this.acroForm.get('Fields');
  46894. if ((!fields || !isArray(fields) || fields.length === 0) &&
  46895. !this.xfa) {
  46896. // no fields and no XFA -- not a form (?)
  46897. this.acroForm = null;
  46898. }
  46899. }
  46900. } catch (ex) {
  46901. info('Something wrong with AcroForm entry');
  46902. this.acroForm = null;
  46903. }
  46904. },
  46905. get linearization() {
  46906. var linearization = null;
  46907. if (this.stream.length) {
  46908. try {
  46909. linearization = Linearization.create(this.stream);
  46910. } catch (err) {
  46911. if (err instanceof MissingDataException) {
  46912. throw err;
  46913. }
  46914. info(err);
  46915. }
  46916. }
  46917. // shadow the prototype getter with a data property
  46918. return shadow(this, 'linearization', linearization);
  46919. },
  46920. get startXRef() {
  46921. var stream = this.stream;
  46922. var startXRef = 0;
  46923. var linearization = this.linearization;
  46924. if (linearization) {
  46925. // Find end of first obj.
  46926. stream.reset();
  46927. if (find(stream, 'endobj', 1024)) {
  46928. startXRef = stream.pos + 6;
  46929. }
  46930. } else {
  46931. // Find startxref by jumping backward from the end of the file.
  46932. var step = 1024;
  46933. var found = false, pos = stream.end;
  46934. while (!found && pos > 0) {
  46935. pos -= step - 'startxref'.length;
  46936. if (pos < 0) {
  46937. pos = 0;
  46938. }
  46939. stream.pos = pos;
  46940. found = find(stream, 'startxref', step, true);
  46941. }
  46942. if (found) {
  46943. stream.skip(9);
  46944. var ch;
  46945. do {
  46946. ch = stream.getByte();
  46947. } while (isSpace(ch));
  46948. var str = '';
  46949. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  46950. str += String.fromCharCode(ch);
  46951. ch = stream.getByte();
  46952. }
  46953. startXRef = parseInt(str, 10);
  46954. if (isNaN(startXRef)) {
  46955. startXRef = 0;
  46956. }
  46957. }
  46958. }
  46959. // shadow the prototype getter with a data property
  46960. return shadow(this, 'startXRef', startXRef);
  46961. },
  46962. get mainXRefEntriesOffset() {
  46963. var mainXRefEntriesOffset = 0;
  46964. var linearization = this.linearization;
  46965. if (linearization) {
  46966. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  46967. }
  46968. // shadow the prototype getter with a data property
  46969. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  46970. },
  46971. // Find the header, remove leading garbage and setup the stream
  46972. // starting from the header.
  46973. checkHeader: function PDFDocument_checkHeader() {
  46974. var stream = this.stream;
  46975. stream.reset();
  46976. if (find(stream, '%PDF-', 1024)) {
  46977. // Found the header, trim off any garbage before it.
  46978. stream.moveStart();
  46979. // Reading file format version
  46980. var MAX_VERSION_LENGTH = 12;
  46981. var version = '', ch;
  46982. while ((ch = stream.getByte()) > 0x20) { // SPACE
  46983. if (version.length >= MAX_VERSION_LENGTH) {
  46984. break;
  46985. }
  46986. version += String.fromCharCode(ch);
  46987. }
  46988. if (!this.pdfFormatVersion) {
  46989. // removing "%PDF-"-prefix
  46990. this.pdfFormatVersion = version.substring(5);
  46991. }
  46992. return;
  46993. }
  46994. // May not be a PDF file, continue anyway.
  46995. },
  46996. parseStartXRef: function PDFDocument_parseStartXRef() {
  46997. var startXRef = this.startXRef;
  46998. this.xref.setStartXRef(startXRef);
  46999. },
  47000. setup: function PDFDocument_setup(recoveryMode) {
  47001. this.xref.parse(recoveryMode);
  47002. var self = this;
  47003. var pageFactory = {
  47004. createPage: function (pageIndex, dict, ref, fontCache) {
  47005. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  47006. fontCache);
  47007. }
  47008. };
  47009. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  47010. },
  47011. get numPages() {
  47012. var linearization = this.linearization;
  47013. var num = linearization ? linearization.numPages : this.catalog.numPages;
  47014. // shadow the prototype getter
  47015. return shadow(this, 'numPages', num);
  47016. },
  47017. get documentInfo() {
  47018. var docInfo = {
  47019. PDFFormatVersion: this.pdfFormatVersion,
  47020. IsAcroFormPresent: !!this.acroForm,
  47021. IsXFAPresent: !!this.xfa
  47022. };
  47023. var infoDict;
  47024. try {
  47025. infoDict = this.xref.trailer.get('Info');
  47026. } catch (err) {
  47027. info('The document information dictionary is invalid.');
  47028. }
  47029. if (infoDict) {
  47030. var validEntries = DocumentInfoValidators.entries;
  47031. // Only fill the document info with valid entries from the spec.
  47032. for (var key in validEntries) {
  47033. if (infoDict.has(key)) {
  47034. var value = infoDict.get(key);
  47035. // Make sure the value conforms to the spec.
  47036. if (validEntries[key](value)) {
  47037. docInfo[key] = (typeof value !== 'string' ?
  47038. value : stringToPDFString(value));
  47039. } else {
  47040. info('Bad value in document info for "' + key + '"');
  47041. }
  47042. }
  47043. }
  47044. }
  47045. return shadow(this, 'documentInfo', docInfo);
  47046. },
  47047. get fingerprint() {
  47048. var xref = this.xref, hash, fileID = '';
  47049. var idArray = xref.trailer.get('ID');
  47050. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  47051. idArray[0] !== EMPTY_FINGERPRINT) {
  47052. hash = stringToBytes(idArray[0]);
  47053. } else {
  47054. if (this.stream.ensureRange) {
  47055. this.stream.ensureRange(0,
  47056. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  47057. }
  47058. hash = calculateMD5(this.stream.bytes.subarray(0,
  47059. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  47060. }
  47061. for (var i = 0, n = hash.length; i < n; i++) {
  47062. var hex = hash[i].toString(16);
  47063. fileID += hex.length === 1 ? '0' + hex : hex;
  47064. }
  47065. return shadow(this, 'fingerprint', fileID);
  47066. },
  47067. getPage: function PDFDocument_getPage(pageIndex) {
  47068. return this.catalog.getPage(pageIndex);
  47069. },
  47070. cleanup: function PDFDocument_cleanup() {
  47071. return this.catalog.cleanup();
  47072. }
  47073. };
  47074. return PDFDocument;
  47075. })();
  47076. exports.Page = Page;
  47077. exports.PDFDocument = PDFDocument;
  47078. }));
  47079. (function (root, factory) {
  47080. {
  47081. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  47082. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  47083. root.pdfjsCoreDocument);
  47084. }
  47085. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  47086. coreDocument) {
  47087. var NotImplementedException = sharedUtil.NotImplementedException;
  47088. var MissingDataException = sharedUtil.MissingDataException;
  47089. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47090. var Util = sharedUtil.Util;
  47091. var Stream = coreStream.Stream;
  47092. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  47093. var PDFDocument = coreDocument.PDFDocument;
  47094. var BasePdfManager = (function BasePdfManagerClosure() {
  47095. function BasePdfManager() {
  47096. throw new Error('Cannot initialize BaseManagerManager');
  47097. }
  47098. BasePdfManager.prototype = {
  47099. get docId() {
  47100. return this._docId;
  47101. },
  47102. onLoadedStream: function BasePdfManager_onLoadedStream() {
  47103. throw new NotImplementedException();
  47104. },
  47105. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  47106. return this.ensure(this.pdfDocument, prop, args);
  47107. },
  47108. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  47109. return this.ensure(this.pdfDocument.xref, prop, args);
  47110. },
  47111. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  47112. return this.ensure(this.pdfDocument.catalog, prop, args);
  47113. },
  47114. getPage: function BasePdfManager_getPage(pageIndex) {
  47115. return this.pdfDocument.getPage(pageIndex);
  47116. },
  47117. cleanup: function BasePdfManager_cleanup() {
  47118. return this.pdfDocument.cleanup();
  47119. },
  47120. ensure: function BasePdfManager_ensure(obj, prop, args) {
  47121. return new NotImplementedException();
  47122. },
  47123. requestRange: function BasePdfManager_requestRange(begin, end) {
  47124. return new NotImplementedException();
  47125. },
  47126. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  47127. return new NotImplementedException();
  47128. },
  47129. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  47130. return new NotImplementedException();
  47131. },
  47132. updatePassword: function BasePdfManager_updatePassword(password) {
  47133. this.pdfDocument.xref.password = this.password = password;
  47134. if (this._passwordChangedCapability) {
  47135. this._passwordChangedCapability.resolve();
  47136. }
  47137. },
  47138. passwordChanged: function BasePdfManager_passwordChanged() {
  47139. this._passwordChangedCapability = createPromiseCapability();
  47140. return this._passwordChangedCapability.promise;
  47141. },
  47142. terminate: function BasePdfManager_terminate() {
  47143. return new NotImplementedException();
  47144. }
  47145. };
  47146. return BasePdfManager;
  47147. })();
  47148. var LocalPdfManager = (function LocalPdfManagerClosure() {
  47149. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  47150. this._docId = docId;
  47151. this.evaluatorOptions = evaluatorOptions;
  47152. var stream = new Stream(data);
  47153. this.pdfDocument = new PDFDocument(this, stream, password);
  47154. this._loadedStreamCapability = createPromiseCapability();
  47155. this._loadedStreamCapability.resolve(stream);
  47156. }
  47157. Util.inherit(LocalPdfManager, BasePdfManager, {
  47158. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  47159. return new Promise(function (resolve, reject) {
  47160. try {
  47161. var value = obj[prop];
  47162. var result;
  47163. if (typeof value === 'function') {
  47164. result = value.apply(obj, args);
  47165. } else {
  47166. result = value;
  47167. }
  47168. resolve(result);
  47169. } catch (e) {
  47170. reject(e);
  47171. }
  47172. });
  47173. },
  47174. requestRange: function LocalPdfManager_requestRange(begin, end) {
  47175. return Promise.resolve();
  47176. },
  47177. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  47178. return;
  47179. },
  47180. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  47181. return this._loadedStreamCapability.promise;
  47182. },
  47183. terminate: function LocalPdfManager_terminate() {
  47184. return;
  47185. }
  47186. });
  47187. return LocalPdfManager;
  47188. })();
  47189. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  47190. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  47191. this._docId = docId;
  47192. this.msgHandler = args.msgHandler;
  47193. this.evaluatorOptions = evaluatorOptions;
  47194. var params = {
  47195. msgHandler: args.msgHandler,
  47196. url: args.url,
  47197. length: args.length,
  47198. disableAutoFetch: args.disableAutoFetch,
  47199. rangeChunkSize: args.rangeChunkSize
  47200. };
  47201. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  47202. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  47203. args.password);
  47204. }
  47205. Util.inherit(NetworkPdfManager, BasePdfManager, {
  47206. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  47207. var pdfManager = this;
  47208. return new Promise(function (resolve, reject) {
  47209. function ensureHelper() {
  47210. try {
  47211. var result;
  47212. var value = obj[prop];
  47213. if (typeof value === 'function') {
  47214. result = value.apply(obj, args);
  47215. } else {
  47216. result = value;
  47217. }
  47218. resolve(result);
  47219. } catch(e) {
  47220. if (!(e instanceof MissingDataException)) {
  47221. reject(e);
  47222. return;
  47223. }
  47224. pdfManager.streamManager.requestRange(e.begin, e.end).
  47225. then(ensureHelper, reject);
  47226. }
  47227. }
  47228. ensureHelper();
  47229. });
  47230. },
  47231. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  47232. return this.streamManager.requestRange(begin, end);
  47233. },
  47234. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  47235. this.streamManager.requestAllChunks();
  47236. },
  47237. sendProgressiveData:
  47238. function NetworkPdfManager_sendProgressiveData(chunk) {
  47239. this.streamManager.onReceiveData({ chunk: chunk });
  47240. },
  47241. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  47242. return this.streamManager.onLoadedStream();
  47243. },
  47244. terminate: function NetworkPdfManager_terminate() {
  47245. this.streamManager.abort();
  47246. }
  47247. });
  47248. return NetworkPdfManager;
  47249. })();
  47250. exports.LocalPdfManager = LocalPdfManager;
  47251. exports.NetworkPdfManager = NetworkPdfManager;
  47252. }));
  47253. (function (root, factory) {
  47254. {
  47255. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  47256. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  47257. }
  47258. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  47259. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  47260. var InvalidPDFException = sharedUtil.InvalidPDFException;
  47261. var MessageHandler = sharedUtil.MessageHandler;
  47262. var MissingPDFException = sharedUtil.MissingPDFException;
  47263. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  47264. var PasswordException = sharedUtil.PasswordException;
  47265. var PasswordResponses = sharedUtil.PasswordResponses;
  47266. var UnknownErrorException = sharedUtil.UnknownErrorException;
  47267. var XRefParseException = sharedUtil.XRefParseException;
  47268. var arrayByteLength = sharedUtil.arrayByteLength;
  47269. var arraysToBytes = sharedUtil.arraysToBytes;
  47270. var assert = sharedUtil.assert;
  47271. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47272. var error = sharedUtil.error;
  47273. var info = sharedUtil.info;
  47274. var warn = sharedUtil.warn;
  47275. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  47276. var Ref = corePrimitives.Ref;
  47277. var LocalPdfManager = corePdfManager.LocalPdfManager;
  47278. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  47279. var globalScope = sharedUtil.globalScope;
  47280. var WorkerTask = (function WorkerTaskClosure() {
  47281. function WorkerTask(name) {
  47282. this.name = name;
  47283. this.terminated = false;
  47284. this._capability = createPromiseCapability();
  47285. }
  47286. WorkerTask.prototype = {
  47287. get finished() {
  47288. return this._capability.promise;
  47289. },
  47290. finish: function () {
  47291. this._capability.resolve();
  47292. },
  47293. terminate: function () {
  47294. this.terminated = true;
  47295. },
  47296. ensureNotTerminated: function () {
  47297. if (this.terminated) {
  47298. throw new Error('Worker task was terminated');
  47299. }
  47300. }
  47301. };
  47302. return WorkerTask;
  47303. })();
  47304. /** @implements {IPDFStream} */
  47305. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  47306. function PDFWorkerStream(params, msgHandler) {
  47307. this._queuedChunks = [];
  47308. var initialData = params.initialData;
  47309. if (initialData && initialData.length > 0) {
  47310. this._queuedChunks.push(initialData);
  47311. }
  47312. this._msgHandler = msgHandler;
  47313. this._isRangeSupported = !(params.disableRange);
  47314. this._isStreamingSupported = !(params.disableStream);
  47315. this._contentLength = params.length;
  47316. this._fullRequestReader = null;
  47317. this._rangeReaders = [];
  47318. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  47319. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  47320. }
  47321. PDFWorkerStream.prototype = {
  47322. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  47323. if (args.begin === undefined) {
  47324. if (this._fullRequestReader) {
  47325. this._fullRequestReader._enqueue(args.chunk);
  47326. } else {
  47327. this._queuedChunks.push(args.chunk);
  47328. }
  47329. } else {
  47330. var found = this._rangeReaders.some(function (rangeReader) {
  47331. if (rangeReader._begin !== args.begin) {
  47332. return false;
  47333. }
  47334. rangeReader._enqueue(args.chunk);
  47335. return true;
  47336. });
  47337. assert(found);
  47338. }
  47339. },
  47340. _onProgress: function PDFWorkerStream_onProgress(evt) {
  47341. if (this._rangeReaders.length > 0) {
  47342. // Reporting to first range reader.
  47343. var firstReader = this._rangeReaders[0];
  47344. if (firstReader.onProgress) {
  47345. firstReader.onProgress({loaded: evt.loaded});
  47346. }
  47347. }
  47348. },
  47349. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  47350. var i = this._rangeReaders.indexOf(reader);
  47351. if (i >= 0) {
  47352. this._rangeReaders.splice(i, 1);
  47353. }
  47354. },
  47355. getFullReader: function PDFWorkerStream_getFullReader() {
  47356. assert(!this._fullRequestReader);
  47357. var queuedChunks = this._queuedChunks;
  47358. this._queuedChunks = null;
  47359. return new PDFWorkerStreamReader(this, queuedChunks);
  47360. },
  47361. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  47362. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  47363. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  47364. this._rangeReaders.push(reader);
  47365. return reader;
  47366. },
  47367. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  47368. if (this._fullRequestReader) {
  47369. this._fullRequestReader.cancel(reason);
  47370. }
  47371. var readers = this._rangeReaders.slice(0);
  47372. readers.forEach(function (rangeReader) {
  47373. rangeReader.cancel(reason);
  47374. });
  47375. }
  47376. };
  47377. /** @implements {IPDFStreamReader} */
  47378. function PDFWorkerStreamReader(stream, queuedChunks) {
  47379. this._stream = stream;
  47380. this._done = false;
  47381. this._queuedChunks = queuedChunks || [];
  47382. this._requests = [];
  47383. this._headersReady = Promise.resolve();
  47384. stream._fullRequestReader = this;
  47385. this.onProgress = null; // not used
  47386. }
  47387. PDFWorkerStreamReader.prototype = {
  47388. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  47389. if (this._done) {
  47390. return; // ignore new data
  47391. }
  47392. if (this._requests.length > 0) {
  47393. var requestCapability = this._requests.shift();
  47394. requestCapability.resolve({value: chunk, done: false});
  47395. return;
  47396. }
  47397. this._queuedChunks.push(chunk);
  47398. },
  47399. get headersReady() {
  47400. return this._headersReady;
  47401. },
  47402. get isRangeSupported() {
  47403. return this._stream._isRangeSupported;
  47404. },
  47405. get isStreamingSupported() {
  47406. return this._stream._isStreamingSupported;
  47407. },
  47408. get contentLength() {
  47409. return this._stream._contentLength;
  47410. },
  47411. read: function PDFWorkerStreamReader_read() {
  47412. if (this._queuedChunks.length > 0) {
  47413. var chunk = this._queuedChunks.shift();
  47414. return Promise.resolve({value: chunk, done: false});
  47415. }
  47416. if (this._done) {
  47417. return Promise.resolve({value: undefined, done: true});
  47418. }
  47419. var requestCapability = createPromiseCapability();
  47420. this._requests.push(requestCapability);
  47421. return requestCapability.promise;
  47422. },
  47423. cancel: function PDFWorkerStreamReader_cancel(reason) {
  47424. this._done = true;
  47425. this._requests.forEach(function (requestCapability) {
  47426. requestCapability.resolve({value: undefined, done: true});
  47427. });
  47428. this._requests = [];
  47429. }
  47430. };
  47431. /** @implements {IPDFStreamRangeReader} */
  47432. function PDFWorkerStreamRangeReader(stream, begin, end) {
  47433. this._stream = stream;
  47434. this._begin = begin;
  47435. this._end = end;
  47436. this._queuedChunk = null;
  47437. this._requests = [];
  47438. this._done = false;
  47439. this.onProgress = null;
  47440. }
  47441. PDFWorkerStreamRangeReader.prototype = {
  47442. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  47443. if (this._done) {
  47444. return; // ignore new data
  47445. }
  47446. if (this._requests.length === 0) {
  47447. this._queuedChunk = chunk;
  47448. } else {
  47449. var requestsCapability = this._requests.shift();
  47450. requestsCapability.resolve({value: chunk, done: false});
  47451. this._requests.forEach(function (requestCapability) {
  47452. requestCapability.resolve({value: undefined, done: true});
  47453. });
  47454. this._requests = [];
  47455. }
  47456. this._done = true;
  47457. this._stream._removeRangeReader(this);
  47458. },
  47459. get isStreamingSupported() {
  47460. return false;
  47461. },
  47462. read: function PDFWorkerStreamRangeReader_read() {
  47463. if (this._queuedChunk) {
  47464. return Promise.resolve({value: this._queuedChunk, done: false});
  47465. }
  47466. if (this._done) {
  47467. return Promise.resolve({value: undefined, done: true});
  47468. }
  47469. var requestCapability = createPromiseCapability();
  47470. this._requests.push(requestCapability);
  47471. return requestCapability.promise;
  47472. },
  47473. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  47474. this._done = true;
  47475. this._requests.forEach(function (requestCapability) {
  47476. requestCapability.resolve({value: undefined, done: true});
  47477. });
  47478. this._requests = [];
  47479. this._stream._removeRangeReader(this);
  47480. }
  47481. };
  47482. return PDFWorkerStream;
  47483. })();
  47484. /** @type IPDFStream */
  47485. var PDFNetworkStream;
  47486. /**
  47487. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  47488. * @param {IPDFStream} cls - the PDF data transport.
  47489. */
  47490. function setPDFNetworkStreamClass(cls) {
  47491. PDFNetworkStream = cls;
  47492. }
  47493. var WorkerMessageHandler = {
  47494. setup: function wphSetup(handler, port) {
  47495. var testMessageProcessed = false;
  47496. handler.on('test', function wphSetupTest(data) {
  47497. if (testMessageProcessed) {
  47498. return; // we already processed 'test' message once
  47499. }
  47500. testMessageProcessed = true;
  47501. // check if Uint8Array can be sent to worker
  47502. if (!(data instanceof Uint8Array)) {
  47503. handler.send('test', 'main', false);
  47504. return;
  47505. }
  47506. // making sure postMessage transfers are working
  47507. var supportTransfers = data[0] === 255;
  47508. handler.postMessageTransfers = supportTransfers;
  47509. // check if the response property is supported by xhr
  47510. var xhr = new XMLHttpRequest();
  47511. var responseExists = 'response' in xhr;
  47512. // check if the property is actually implemented
  47513. try {
  47514. var dummy = xhr.responseType;
  47515. } catch (e) {
  47516. responseExists = false;
  47517. }
  47518. if (!responseExists) {
  47519. handler.send('test', false);
  47520. return;
  47521. }
  47522. handler.send('test', {
  47523. supportTypedArray: true,
  47524. supportTransfers: supportTransfers
  47525. });
  47526. });
  47527. handler.on('configure', function wphConfigure(data) {
  47528. setVerbosityLevel(data.verbosity);
  47529. });
  47530. handler.on('GetDocRequest', function wphSetupDoc(data) {
  47531. return WorkerMessageHandler.createDocumentHandler(data, port);
  47532. });
  47533. },
  47534. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  47535. // This context is actually holds references on pdfManager and handler,
  47536. // until the latter is destroyed.
  47537. var pdfManager;
  47538. var terminated = false;
  47539. var cancelXHRs = null;
  47540. var WorkerTasks = [];
  47541. var docId = docParams.docId;
  47542. var workerHandlerName = docParams.docId + '_worker';
  47543. var handler = new MessageHandler(workerHandlerName, docId, port);
  47544. // Ensure that postMessage transfers are correctly enabled/disabled,
  47545. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  47546. handler.postMessageTransfers = docParams.postMessageTransfers;
  47547. function ensureNotTerminated() {
  47548. if (terminated) {
  47549. throw new Error('Worker was terminated');
  47550. }
  47551. }
  47552. function startWorkerTask(task) {
  47553. WorkerTasks.push(task);
  47554. }
  47555. function finishWorkerTask(task) {
  47556. task.finish();
  47557. var i = WorkerTasks.indexOf(task);
  47558. WorkerTasks.splice(i, 1);
  47559. }
  47560. function loadDocument(recoveryMode) {
  47561. var loadDocumentCapability = createPromiseCapability();
  47562. var parseSuccess = function parseSuccess() {
  47563. var numPagesPromise = pdfManager.ensureDoc('numPages');
  47564. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  47565. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  47566. Promise.all([numPagesPromise, fingerprintPromise,
  47567. encryptedPromise]).then(function onDocReady(results) {
  47568. var doc = {
  47569. numPages: results[0],
  47570. fingerprint: results[1],
  47571. encrypted: !!results[2],
  47572. };
  47573. loadDocumentCapability.resolve(doc);
  47574. },
  47575. parseFailure);
  47576. };
  47577. var parseFailure = function parseFailure(e) {
  47578. loadDocumentCapability.reject(e);
  47579. };
  47580. pdfManager.ensureDoc('checkHeader', []).then(function() {
  47581. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  47582. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  47583. parseSuccess, parseFailure);
  47584. }, parseFailure);
  47585. }, parseFailure);
  47586. return loadDocumentCapability.promise;
  47587. }
  47588. function getPdfManager(data, evaluatorOptions) {
  47589. var pdfManagerCapability = createPromiseCapability();
  47590. var pdfManager;
  47591. var source = data.source;
  47592. if (source.data) {
  47593. try {
  47594. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  47595. evaluatorOptions);
  47596. pdfManagerCapability.resolve(pdfManager);
  47597. } catch (ex) {
  47598. pdfManagerCapability.reject(ex);
  47599. }
  47600. return pdfManagerCapability.promise;
  47601. }
  47602. var pdfStream;
  47603. try {
  47604. if (source.chunkedViewerLoading) {
  47605. pdfStream = new PDFWorkerStream(source, handler);
  47606. } else {
  47607. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  47608. pdfStream = new PDFNetworkStream(data);
  47609. }
  47610. } catch (ex) {
  47611. pdfManagerCapability.reject(ex);
  47612. return pdfManagerCapability.promise;
  47613. }
  47614. var fullRequest = pdfStream.getFullReader();
  47615. fullRequest.headersReady.then(function () {
  47616. if (!fullRequest.isStreamingSupported ||
  47617. !fullRequest.isRangeSupported) {
  47618. // If stream or range are disabled, it's our only way to report
  47619. // loading progress.
  47620. fullRequest.onProgress = function (evt) {
  47621. handler.send('DocProgress', {
  47622. loaded: evt.loaded,
  47623. total: evt.total
  47624. });
  47625. };
  47626. }
  47627. if (!fullRequest.isRangeSupported) {
  47628. return;
  47629. }
  47630. // We don't need auto-fetch when streaming is enabled.
  47631. var disableAutoFetch = source.disableAutoFetch ||
  47632. fullRequest.isStreamingSupported;
  47633. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  47634. msgHandler: handler,
  47635. url: source.url,
  47636. password: source.password,
  47637. length: fullRequest.contentLength,
  47638. disableAutoFetch: disableAutoFetch,
  47639. rangeChunkSize: source.rangeChunkSize
  47640. }, evaluatorOptions);
  47641. pdfManagerCapability.resolve(pdfManager);
  47642. cancelXHRs = null;
  47643. }).catch(function (reason) {
  47644. pdfManagerCapability.reject(reason);
  47645. cancelXHRs = null;
  47646. });
  47647. var cachedChunks = [], loaded = 0;
  47648. var flushChunks = function () {
  47649. var pdfFile = arraysToBytes(cachedChunks);
  47650. if (source.length && pdfFile.length !== source.length) {
  47651. warn('reported HTTP length is different from actual');
  47652. }
  47653. // the data is array, instantiating directly from it
  47654. try {
  47655. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  47656. evaluatorOptions);
  47657. pdfManagerCapability.resolve(pdfManager);
  47658. } catch (ex) {
  47659. pdfManagerCapability.reject(ex);
  47660. }
  47661. cachedChunks = [];
  47662. };
  47663. var readPromise = new Promise(function (resolve, reject) {
  47664. var readChunk = function (chunk) {
  47665. try {
  47666. ensureNotTerminated();
  47667. if (chunk.done) {
  47668. if (!pdfManager) {
  47669. flushChunks();
  47670. }
  47671. cancelXHRs = null;
  47672. return;
  47673. }
  47674. var data = chunk.value;
  47675. loaded += arrayByteLength(data);
  47676. if (!fullRequest.isStreamingSupported) {
  47677. handler.send('DocProgress', {
  47678. loaded: loaded,
  47679. total: Math.max(loaded, fullRequest.contentLength || 0)
  47680. });
  47681. }
  47682. if (pdfManager) {
  47683. pdfManager.sendProgressiveData(data);
  47684. } else {
  47685. cachedChunks.push(data);
  47686. }
  47687. fullRequest.read().then(readChunk, reject);
  47688. } catch (e) {
  47689. reject(e);
  47690. }
  47691. };
  47692. fullRequest.read().then(readChunk, reject);
  47693. });
  47694. readPromise.catch(function (e) {
  47695. pdfManagerCapability.reject(e);
  47696. cancelXHRs = null;
  47697. });
  47698. cancelXHRs = function () {
  47699. pdfStream.cancelAllRequests('abort');
  47700. };
  47701. return pdfManagerCapability.promise;
  47702. }
  47703. var setupDoc = function(data) {
  47704. var onSuccess = function(doc) {
  47705. ensureNotTerminated();
  47706. handler.send('GetDoc', { pdfInfo: doc });
  47707. };
  47708. var onFailure = function(e) {
  47709. if (e instanceof PasswordException) {
  47710. if (e.code === PasswordResponses.NEED_PASSWORD) {
  47711. handler.send('NeedPassword', e);
  47712. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  47713. handler.send('IncorrectPassword', e);
  47714. }
  47715. } else if (e instanceof InvalidPDFException) {
  47716. handler.send('InvalidPDF', e);
  47717. } else if (e instanceof MissingPDFException) {
  47718. handler.send('MissingPDF', e);
  47719. } else if (e instanceof UnexpectedResponseException) {
  47720. handler.send('UnexpectedResponse', e);
  47721. } else {
  47722. handler.send('UnknownError',
  47723. new UnknownErrorException(e.message, e.toString()));
  47724. }
  47725. };
  47726. ensureNotTerminated();
  47727. var cMapOptions = {
  47728. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  47729. packed: data.cMapPacked === true
  47730. };
  47731. var evaluatorOptions = {
  47732. forceDataSchema: data.disableCreateObjectURL,
  47733. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  47734. disableFontFace: data.disableFontFace,
  47735. cMapOptions: cMapOptions
  47736. };
  47737. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  47738. if (terminated) {
  47739. // We were in a process of setting up the manager, but it got
  47740. // terminated in the middle.
  47741. newPdfManager.terminate();
  47742. throw new Error('Worker was terminated');
  47743. }
  47744. pdfManager = newPdfManager;
  47745. handler.send('PDFManagerReady', null);
  47746. pdfManager.onLoadedStream().then(function(stream) {
  47747. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  47748. });
  47749. }).then(function pdfManagerReady() {
  47750. ensureNotTerminated();
  47751. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  47752. ensureNotTerminated();
  47753. // Try again with recoveryMode == true
  47754. if (!(ex instanceof XRefParseException)) {
  47755. if (ex instanceof PasswordException) {
  47756. // after password exception prepare to receive a new password
  47757. // to repeat loading
  47758. pdfManager.passwordChanged().then(pdfManagerReady);
  47759. }
  47760. onFailure(ex);
  47761. return;
  47762. }
  47763. pdfManager.requestLoadedStream();
  47764. pdfManager.onLoadedStream().then(function() {
  47765. ensureNotTerminated();
  47766. loadDocument(true).then(onSuccess, onFailure);
  47767. });
  47768. }, onFailure);
  47769. }, onFailure);
  47770. };
  47771. handler.on('GetPage', function wphSetupGetPage(data) {
  47772. return pdfManager.getPage(data.pageIndex).then(function(page) {
  47773. var rotatePromise = pdfManager.ensure(page, 'rotate');
  47774. var refPromise = pdfManager.ensure(page, 'ref');
  47775. var viewPromise = pdfManager.ensure(page, 'view');
  47776. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  47777. function(results) {
  47778. return {
  47779. rotate: results[0],
  47780. ref: results[1],
  47781. view: results[2]
  47782. };
  47783. });
  47784. });
  47785. });
  47786. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  47787. var ref = new Ref(data.ref.num, data.ref.gen);
  47788. var catalog = pdfManager.pdfDocument.catalog;
  47789. return catalog.getPageIndex(ref);
  47790. });
  47791. handler.on('GetDestinations',
  47792. function wphSetupGetDestinations(data) {
  47793. return pdfManager.ensureCatalog('destinations');
  47794. }
  47795. );
  47796. handler.on('GetDestination',
  47797. function wphSetupGetDestination(data) {
  47798. return pdfManager.ensureCatalog('getDestination', [data.id]);
  47799. }
  47800. );
  47801. handler.on('GetPageLabels',
  47802. function wphSetupGetPageLabels(data) {
  47803. return pdfManager.ensureCatalog('pageLabels');
  47804. }
  47805. );
  47806. handler.on('GetAttachments',
  47807. function wphSetupGetAttachments(data) {
  47808. return pdfManager.ensureCatalog('attachments');
  47809. }
  47810. );
  47811. handler.on('GetJavaScript',
  47812. function wphSetupGetJavaScript(data) {
  47813. return pdfManager.ensureCatalog('javaScript');
  47814. }
  47815. );
  47816. handler.on('GetOutline',
  47817. function wphSetupGetOutline(data) {
  47818. return pdfManager.ensureCatalog('documentOutline');
  47819. }
  47820. );
  47821. handler.on('GetMetadata',
  47822. function wphSetupGetMetadata(data) {
  47823. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  47824. pdfManager.ensureCatalog('metadata')]);
  47825. }
  47826. );
  47827. handler.on('GetData', function wphSetupGetData(data) {
  47828. pdfManager.requestLoadedStream();
  47829. return pdfManager.onLoadedStream().then(function(stream) {
  47830. return stream.bytes;
  47831. });
  47832. });
  47833. handler.on('GetStats',
  47834. function wphSetupGetStats(data) {
  47835. return pdfManager.pdfDocument.xref.stats;
  47836. }
  47837. );
  47838. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  47839. pdfManager.updatePassword(data);
  47840. });
  47841. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  47842. return pdfManager.getPage(data.pageIndex).then(function(page) {
  47843. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  47844. });
  47845. });
  47846. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  47847. var pageIndex = data.pageIndex;
  47848. pdfManager.getPage(pageIndex).then(function(page) {
  47849. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  47850. startWorkerTask(task);
  47851. var pageNum = pageIndex + 1;
  47852. var start = Date.now();
  47853. // Pre compile the pdf page and fetch the fonts/images.
  47854. page.getOperatorList(handler, task, data.intent,
  47855. data.renderInteractiveForms).then(
  47856. function(operatorList) {
  47857. finishWorkerTask(task);
  47858. info('page=' + pageNum + ' - getOperatorList: time=' +
  47859. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  47860. }, function(e) {
  47861. finishWorkerTask(task);
  47862. if (task.terminated) {
  47863. return; // ignoring errors from the terminated thread
  47864. }
  47865. // For compatibility with older behavior, generating unknown
  47866. // unsupported feature notification on errors.
  47867. handler.send('UnsupportedFeature',
  47868. {featureId: UNSUPPORTED_FEATURES.unknown});
  47869. var minimumStackMessage =
  47870. 'worker.js: while trying to getPage() and getOperatorList()';
  47871. var wrappedException;
  47872. // Turn the error into an obj that can be serialized
  47873. if (typeof e === 'string') {
  47874. wrappedException = {
  47875. message: e,
  47876. stack: minimumStackMessage
  47877. };
  47878. } else if (typeof e === 'object') {
  47879. wrappedException = {
  47880. message: e.message || e.toString(),
  47881. stack: e.stack || minimumStackMessage
  47882. };
  47883. } else {
  47884. wrappedException = {
  47885. message: 'Unknown exception type: ' + (typeof e),
  47886. stack: minimumStackMessage
  47887. };
  47888. }
  47889. handler.send('PageError', {
  47890. pageNum: pageNum,
  47891. error: wrappedException,
  47892. intent: data.intent
  47893. });
  47894. });
  47895. });
  47896. }, this);
  47897. handler.on('GetTextContent', function wphExtractText(data) {
  47898. var pageIndex = data.pageIndex;
  47899. var normalizeWhitespace = data.normalizeWhitespace;
  47900. var combineTextItems = data.combineTextItems;
  47901. return pdfManager.getPage(pageIndex).then(function(page) {
  47902. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  47903. startWorkerTask(task);
  47904. var pageNum = pageIndex + 1;
  47905. var start = Date.now();
  47906. return page.extractTextContent(task, normalizeWhitespace,
  47907. combineTextItems).then(
  47908. function(textContent) {
  47909. finishWorkerTask(task);
  47910. info('text indexing: page=' + pageNum + ' - time=' +
  47911. (Date.now() - start) + 'ms');
  47912. return textContent;
  47913. }, function (reason) {
  47914. finishWorkerTask(task);
  47915. if (task.terminated) {
  47916. return; // ignoring errors from the terminated thread
  47917. }
  47918. throw reason;
  47919. });
  47920. });
  47921. });
  47922. handler.on('Cleanup', function wphCleanup(data) {
  47923. return pdfManager.cleanup();
  47924. });
  47925. handler.on('Terminate', function wphTerminate(data) {
  47926. terminated = true;
  47927. if (pdfManager) {
  47928. pdfManager.terminate();
  47929. pdfManager = null;
  47930. }
  47931. if (cancelXHRs) {
  47932. cancelXHRs();
  47933. }
  47934. var waitOn = [];
  47935. WorkerTasks.forEach(function (task) {
  47936. waitOn.push(task.finished);
  47937. task.terminate();
  47938. });
  47939. return Promise.all(waitOn).then(function () {
  47940. // Notice that even if we destroying handler, resolved response promise
  47941. // must be sent back.
  47942. handler.destroy();
  47943. handler = null;
  47944. });
  47945. });
  47946. handler.on('Ready', function wphReady(data) {
  47947. setupDoc(docParams);
  47948. docParams = null; // we don't need docParams anymore -- saving memory.
  47949. });
  47950. return workerHandlerName;
  47951. }
  47952. };
  47953. function initializeWorker() {
  47954. if (!('console' in globalScope)) {
  47955. var consoleTimer = {};
  47956. var workerConsole = {
  47957. log: function log() {
  47958. var args = Array.prototype.slice.call(arguments);
  47959. globalScope.postMessage({
  47960. targetName: 'main',
  47961. action: 'console_log',
  47962. data: args
  47963. });
  47964. },
  47965. error: function error() {
  47966. var args = Array.prototype.slice.call(arguments);
  47967. globalScope.postMessage({
  47968. targetName: 'main',
  47969. action: 'console_error',
  47970. data: args
  47971. });
  47972. throw 'pdf.js execution error';
  47973. },
  47974. time: function time(name) {
  47975. consoleTimer[name] = Date.now();
  47976. },
  47977. timeEnd: function timeEnd(name) {
  47978. var time = consoleTimer[name];
  47979. if (!time) {
  47980. error('Unknown timer name ' + name);
  47981. }
  47982. this.log('Timer:', name, Date.now() - time);
  47983. }
  47984. };
  47985. globalScope.console = workerConsole;
  47986. }
  47987. var handler = new MessageHandler('worker', 'main', self);
  47988. WorkerMessageHandler.setup(handler, self);
  47989. handler.send('ready', null);
  47990. }
  47991. // Worker thread (and not node.js)?
  47992. if (typeof window === 'undefined' &&
  47993. !(typeof module !== 'undefined' && module.require)) {
  47994. initializeWorker();
  47995. }
  47996. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  47997. exports.WorkerTask = WorkerTask;
  47998. exports.WorkerMessageHandler = WorkerMessageHandler;
  47999. }));
  48000. var NetworkManager = (function NetworkManagerClosure() {
  48001. var OK_RESPONSE = 200;
  48002. var PARTIAL_CONTENT_RESPONSE = 206;
  48003. function NetworkManager(url, args) {
  48004. this.url = url;
  48005. args = args || {};
  48006. this.isHttp = /^https?:/i.test(url);
  48007. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  48008. this.withCredentials = args.withCredentials || false;
  48009. this.getXhr = args.getXhr ||
  48010. function NetworkManager_getXhr() {
  48011. return new XMLHttpRequest();
  48012. };
  48013. this.currXhrId = 0;
  48014. this.pendingRequests = Object.create(null);
  48015. this.loadedRequests = Object.create(null);
  48016. }
  48017. function getArrayBuffer(xhr) {
  48018. var data = xhr.response;
  48019. if (typeof data !== 'string') {
  48020. return data;
  48021. }
  48022. var length = data.length;
  48023. var array = new Uint8Array(length);
  48024. for (var i = 0; i < length; i++) {
  48025. array[i] = data.charCodeAt(i) & 0xFF;
  48026. }
  48027. return array.buffer;
  48028. }
  48029. var supportsMozChunked = (function supportsMozChunkedClosure() {
  48030. try {
  48031. var x = new XMLHttpRequest();
  48032. // Firefox 37- required .open() to be called before setting responseType.
  48033. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  48034. // Even though the URL is not visited, .open() could fail if the URL is
  48035. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  48036. // When this error occurs, this feature detection method will mistakenly
  48037. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  48038. x.open('GET', 'https://example.com');
  48039. x.responseType = 'moz-chunked-arraybuffer';
  48040. return x.responseType === 'moz-chunked-arraybuffer';
  48041. } catch (e) {
  48042. return false;
  48043. }
  48044. })();
  48045. NetworkManager.prototype = {
  48046. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  48047. var args = {
  48048. begin: begin,
  48049. end: end
  48050. };
  48051. for (var prop in listeners) {
  48052. args[prop] = listeners[prop];
  48053. }
  48054. return this.request(args);
  48055. },
  48056. requestFull: function NetworkManager_requestFull(listeners) {
  48057. return this.request(listeners);
  48058. },
  48059. request: function NetworkManager_request(args) {
  48060. var xhr = this.getXhr();
  48061. var xhrId = this.currXhrId++;
  48062. var pendingRequest = this.pendingRequests[xhrId] = {
  48063. xhr: xhr
  48064. };
  48065. xhr.open('GET', this.url);
  48066. xhr.withCredentials = this.withCredentials;
  48067. for (var property in this.httpHeaders) {
  48068. var value = this.httpHeaders[property];
  48069. if (typeof value === 'undefined') {
  48070. continue;
  48071. }
  48072. xhr.setRequestHeader(property, value);
  48073. }
  48074. if (this.isHttp && 'begin' in args && 'end' in args) {
  48075. var rangeStr = args.begin + '-' + (args.end - 1);
  48076. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  48077. pendingRequest.expectedStatus = 206;
  48078. } else {
  48079. pendingRequest.expectedStatus = 200;
  48080. }
  48081. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  48082. if (useMozChunkedLoading) {
  48083. xhr.responseType = 'moz-chunked-arraybuffer';
  48084. pendingRequest.onProgressiveData = args.onProgressiveData;
  48085. pendingRequest.mozChunked = true;
  48086. } else {
  48087. xhr.responseType = 'arraybuffer';
  48088. }
  48089. if (args.onError) {
  48090. xhr.onerror = function(evt) {
  48091. args.onError(xhr.status);
  48092. };
  48093. }
  48094. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  48095. xhr.onprogress = this.onProgress.bind(this, xhrId);
  48096. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  48097. pendingRequest.onDone = args.onDone;
  48098. pendingRequest.onError = args.onError;
  48099. pendingRequest.onProgress = args.onProgress;
  48100. xhr.send(null);
  48101. return xhrId;
  48102. },
  48103. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  48104. var pendingRequest = this.pendingRequests[xhrId];
  48105. if (!pendingRequest) {
  48106. // Maybe abortRequest was called...
  48107. return;
  48108. }
  48109. if (pendingRequest.mozChunked) {
  48110. var chunk = getArrayBuffer(pendingRequest.xhr);
  48111. pendingRequest.onProgressiveData(chunk);
  48112. }
  48113. var onProgress = pendingRequest.onProgress;
  48114. if (onProgress) {
  48115. onProgress(evt);
  48116. }
  48117. },
  48118. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  48119. var pendingRequest = this.pendingRequests[xhrId];
  48120. if (!pendingRequest) {
  48121. // Maybe abortRequest was called...
  48122. return;
  48123. }
  48124. var xhr = pendingRequest.xhr;
  48125. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  48126. pendingRequest.onHeadersReceived();
  48127. delete pendingRequest.onHeadersReceived;
  48128. }
  48129. if (xhr.readyState !== 4) {
  48130. return;
  48131. }
  48132. if (!(xhrId in this.pendingRequests)) {
  48133. // The XHR request might have been aborted in onHeadersReceived()
  48134. // callback, in which case we should abort request
  48135. return;
  48136. }
  48137. delete this.pendingRequests[xhrId];
  48138. // success status == 0 can be on ftp, file and other protocols
  48139. if (xhr.status === 0 && this.isHttp) {
  48140. if (pendingRequest.onError) {
  48141. pendingRequest.onError(xhr.status);
  48142. }
  48143. return;
  48144. }
  48145. var xhrStatus = xhr.status || OK_RESPONSE;
  48146. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  48147. // "A server MAY ignore the Range header". This means it's possible to
  48148. // get a 200 rather than a 206 response from a range request.
  48149. var ok_response_on_range_request =
  48150. xhrStatus === OK_RESPONSE &&
  48151. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  48152. if (!ok_response_on_range_request &&
  48153. xhrStatus !== pendingRequest.expectedStatus) {
  48154. if (pendingRequest.onError) {
  48155. pendingRequest.onError(xhr.status);
  48156. }
  48157. return;
  48158. }
  48159. this.loadedRequests[xhrId] = true;
  48160. var chunk = getArrayBuffer(xhr);
  48161. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  48162. var rangeHeader = xhr.getResponseHeader('Content-Range');
  48163. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  48164. var begin = parseInt(matches[1], 10);
  48165. pendingRequest.onDone({
  48166. begin: begin,
  48167. chunk: chunk
  48168. });
  48169. } else if (pendingRequest.onProgressiveData) {
  48170. pendingRequest.onDone(null);
  48171. } else if (chunk) {
  48172. pendingRequest.onDone({
  48173. begin: 0,
  48174. chunk: chunk
  48175. });
  48176. } else if (pendingRequest.onError) {
  48177. pendingRequest.onError(xhr.status);
  48178. }
  48179. },
  48180. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  48181. for (var xhrId in this.pendingRequests) {
  48182. return true;
  48183. }
  48184. return false;
  48185. },
  48186. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  48187. return this.pendingRequests[xhrId].xhr;
  48188. },
  48189. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  48190. return !!(this.pendingRequests[xhrId].onProgressiveData);
  48191. },
  48192. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  48193. return xhrId in this.pendingRequests;
  48194. },
  48195. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  48196. return xhrId in this.loadedRequests;
  48197. },
  48198. abortAllRequests: function NetworkManager_abortAllRequests() {
  48199. for (var xhrId in this.pendingRequests) {
  48200. this.abortRequest(xhrId | 0);
  48201. }
  48202. },
  48203. abortRequest: function NetworkManager_abortRequest(xhrId) {
  48204. var xhr = this.pendingRequests[xhrId].xhr;
  48205. delete this.pendingRequests[xhrId];
  48206. xhr.abort();
  48207. }
  48208. };
  48209. return NetworkManager;
  48210. })();
  48211. (function (root, factory) {
  48212. {
  48213. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  48214. root.pdfjsCoreWorker);
  48215. }
  48216. }(this, function (exports, sharedUtil, coreWorker) {
  48217. var assert = sharedUtil.assert;
  48218. var createPromiseCapability = sharedUtil.createPromiseCapability;
  48219. var isInt = sharedUtil.isInt;
  48220. var MissingPDFException = sharedUtil.MissingPDFException;
  48221. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  48222. /** @implements {IPDFStream} */
  48223. function PDFNetworkStream(options) {
  48224. this._options = options;
  48225. var source = options.source;
  48226. this._manager = new NetworkManager(source.url, {
  48227. httpHeaders: source.httpHeaders,
  48228. withCredentials: source.withCredentials
  48229. });
  48230. this._rangeChunkSize = source.rangeChunkSize;
  48231. this._fullRequestReader = null;
  48232. this._rangeRequestReaders = [];
  48233. }
  48234. PDFNetworkStream.prototype = {
  48235. _onRangeRequestReaderClosed:
  48236. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  48237. var i = this._rangeRequestReaders.indexOf(reader);
  48238. if (i >= 0) {
  48239. this._rangeRequestReaders.splice(i, 1);
  48240. }
  48241. },
  48242. getFullReader: function PDFNetworkStream_getFullReader() {
  48243. assert(!this._fullRequestReader);
  48244. this._fullRequestReader =
  48245. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  48246. return this._fullRequestReader;
  48247. },
  48248. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  48249. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  48250. begin, end);
  48251. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  48252. this._rangeRequestReaders.push(reader);
  48253. return reader;
  48254. },
  48255. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  48256. if (this._fullRequestReader) {
  48257. this._fullRequestReader.cancel(reason);
  48258. }
  48259. var readers = this._rangeRequestReaders.slice(0);
  48260. readers.forEach(function (reader) {
  48261. reader.cancel(reason);
  48262. });
  48263. }
  48264. };
  48265. /** @implements {IPDFStreamReader} */
  48266. function PDFNetworkStreamFullRequestReader(manager, options) {
  48267. this._manager = manager;
  48268. var source = options.source;
  48269. var args = {
  48270. onHeadersReceived: this._onHeadersReceived.bind(this),
  48271. onProgressiveData: source.disableStream ? null :
  48272. this._onProgressiveData.bind(this),
  48273. onDone: this._onDone.bind(this),
  48274. onError: this._onError.bind(this),
  48275. onProgress: this._onProgress.bind(this)
  48276. };
  48277. this._url = source.url;
  48278. this._fullRequestId = manager.requestFull(args);
  48279. this._headersReceivedCapability = createPromiseCapability();
  48280. this._disableRange = options.disableRange || false;
  48281. this._contentLength = source.length; // optional
  48282. this._rangeChunkSize = source.rangeChunkSize;
  48283. if (!this._rangeChunkSize && !this._disableRange) {
  48284. this._disableRange = true;
  48285. }
  48286. this._isStreamingSupported = false;
  48287. this._isRangeSupported = false;
  48288. this._cachedChunks = [];
  48289. this._requests = [];
  48290. this._done = false;
  48291. this._storedError = undefined;
  48292. this.onProgress = null;
  48293. }
  48294. PDFNetworkStreamFullRequestReader.prototype = {
  48295. _validateRangeRequestCapabilities: function
  48296. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  48297. if (this._disableRange) {
  48298. return false;
  48299. }
  48300. var networkManager = this._manager;
  48301. var fullRequestXhrId = this._fullRequestId;
  48302. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  48303. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  48304. return false;
  48305. }
  48306. var contentEncoding =
  48307. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  48308. if (contentEncoding !== 'identity') {
  48309. return false;
  48310. }
  48311. var length = fullRequestXhr.getResponseHeader('Content-Length');
  48312. length = parseInt(length, 10);
  48313. if (!isInt(length)) {
  48314. return false;
  48315. }
  48316. this._contentLength = length; // setting right content length
  48317. if (length <= 2 * this._rangeChunkSize) {
  48318. // The file size is smaller than the size of two chunks, so it does
  48319. // not make any sense to abort the request and retry with a range
  48320. // request.
  48321. return false;
  48322. }
  48323. return true;
  48324. },
  48325. _onHeadersReceived:
  48326. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  48327. if (this._validateRangeRequestCapabilities()) {
  48328. this._isRangeSupported = true;
  48329. }
  48330. var networkManager = this._manager;
  48331. var fullRequestXhrId = this._fullRequestId;
  48332. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  48333. // We can continue fetching when progressive loading is enabled,
  48334. // and we don't need the autoFetch feature.
  48335. this._isStreamingSupported = true;
  48336. } else if (this._isRangeSupported) {
  48337. // NOTE: by cancelling the full request, and then issuing range
  48338. // requests, there will be an issue for sites where you can only
  48339. // request the pdf once. However, if this is the case, then the
  48340. // server should not be returning that it can support range
  48341. // requests.
  48342. networkManager.abortRequest(fullRequestXhrId);
  48343. }
  48344. this._headersReceivedCapability.resolve();
  48345. },
  48346. _onProgressiveData:
  48347. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  48348. if (this._requests.length > 0) {
  48349. var requestCapability = this._requests.shift();
  48350. requestCapability.resolve({value: chunk, done: false});
  48351. } else {
  48352. this._cachedChunks.push(chunk);
  48353. }
  48354. },
  48355. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  48356. if (args) {
  48357. this._onProgressiveData(args.chunk);
  48358. }
  48359. this._done = true;
  48360. if (this._cachedChunks.length > 0) {
  48361. return;
  48362. }
  48363. this._requests.forEach(function (requestCapability) {
  48364. requestCapability.resolve({value: undefined, done: true});
  48365. });
  48366. this._requests = [];
  48367. },
  48368. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  48369. var url = this._url;
  48370. var exception;
  48371. if (status === 404 || status === 0 && /^file:/.test(url)) {
  48372. exception = new MissingPDFException('Missing PDF "' + url + '".');
  48373. } else {
  48374. exception = new UnexpectedResponseException(
  48375. 'Unexpected server response (' + status +
  48376. ') while retrieving PDF "' + url + '".', status);
  48377. }
  48378. this._storedError = exception;
  48379. this._headersReceivedCapability.reject(exception);
  48380. this._requests.forEach(function (requestCapability) {
  48381. requestCapability.reject(exception);
  48382. });
  48383. this._requests = [];
  48384. this._cachedChunks = [];
  48385. },
  48386. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  48387. if (this.onProgress) {
  48388. this.onProgress({
  48389. loaded: data.loaded,
  48390. total: data.lengthComputable ? data.total : this._contentLength
  48391. });
  48392. }
  48393. },
  48394. get isRangeSupported() {
  48395. return this._isRangeSupported;
  48396. },
  48397. get isStreamingSupported() {
  48398. return this._isStreamingSupported;
  48399. },
  48400. get contentLength() {
  48401. return this._contentLength;
  48402. },
  48403. get headersReady() {
  48404. return this._headersReceivedCapability.promise;
  48405. },
  48406. read: function PDFNetworkStreamFullRequestReader_read() {
  48407. if (this._storedError) {
  48408. return Promise.reject(this._storedError);
  48409. }
  48410. if (this._cachedChunks.length > 0) {
  48411. var chunk = this._cachedChunks.shift();
  48412. return Promise.resolve(chunk);
  48413. }
  48414. if (this._done) {
  48415. return Promise.resolve({value: undefined, done: true});
  48416. }
  48417. var requestCapability = createPromiseCapability();
  48418. this._requests.push(requestCapability);
  48419. return requestCapability.promise;
  48420. },
  48421. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  48422. this._done = true;
  48423. this._headersReceivedCapability.reject(reason);
  48424. this._requests.forEach(function (requestCapability) {
  48425. requestCapability.resolve({value: undefined, done: true});
  48426. });
  48427. this._requests = [];
  48428. if (this._manager.isPendingRequest(this._fullRequestId)) {
  48429. this._manager.abortRequest(this._fullRequestId);
  48430. }
  48431. this._fullRequestReader = null;
  48432. }
  48433. };
  48434. /** @implements {IPDFStreamRangeReader} */
  48435. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  48436. this._manager = manager;
  48437. var args = {
  48438. onDone: this._onDone.bind(this),
  48439. onProgress: this._onProgress.bind(this)
  48440. };
  48441. this._requestId = manager.requestRange(begin, end, args);
  48442. this._requests = [];
  48443. this._queuedChunk = null;
  48444. this._done = false;
  48445. this.onProgress = null;
  48446. this.onClosed = null;
  48447. }
  48448. PDFNetworkStreamRangeRequestReader.prototype = {
  48449. _close: function PDFNetworkStreamRangeRequestReader_close() {
  48450. if (this.onClosed) {
  48451. this.onClosed(this);
  48452. }
  48453. },
  48454. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  48455. var chunk = data.chunk;
  48456. if (this._requests.length > 0) {
  48457. var requestCapability = this._requests.shift();
  48458. requestCapability.resolve({value: chunk, done: false});
  48459. } else {
  48460. this._queuedChunk = chunk;
  48461. }
  48462. this._done = true;
  48463. this._requests.forEach(function (requestCapability) {
  48464. requestCapability.resolve({value: undefined, done: true});
  48465. });
  48466. this._requests = [];
  48467. this._close();
  48468. },
  48469. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  48470. if (!this.isStreamingSupported && this.onProgress) {
  48471. this.onProgress({
  48472. loaded: evt.loaded
  48473. });
  48474. }
  48475. },
  48476. get isStreamingSupported() {
  48477. return false; // TODO allow progressive range bytes loading
  48478. },
  48479. read: function PDFNetworkStreamRangeRequestReader_read() {
  48480. if (this._queuedChunk !== null) {
  48481. var chunk = this._queuedChunk;
  48482. this._queuedChunk = null;
  48483. return Promise.resolve({value: chunk, done: false});
  48484. }
  48485. if (this._done) {
  48486. return Promise.resolve({value: undefined, done: true});
  48487. }
  48488. var requestCapability = createPromiseCapability();
  48489. this._requests.push(requestCapability);
  48490. return requestCapability.promise;
  48491. },
  48492. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  48493. this._done = true;
  48494. this._requests.forEach(function (requestCapability) {
  48495. requestCapability.resolve({value: undefined, done: true});
  48496. });
  48497. this._requests = [];
  48498. if (this._manager.isPendingRequest(this._requestId)) {
  48499. this._manager.abortRequest(this._requestId);
  48500. }
  48501. this._close();
  48502. }
  48503. };
  48504. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  48505. exports.PDFNetworkStream = PDFNetworkStream;
  48506. exports.NetworkManager = NetworkManager;
  48507. }));
  48508. }).call(pdfjsLibs);
  48509. exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
  48510. exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
  48511. exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
  48512. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  48513. exports.PDFDataRangeTransport =
  48514. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  48515. exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
  48516. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  48517. exports.AnnotationLayer =
  48518. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  48519. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  48520. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  48521. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  48522. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  48523. exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
  48524. exports.UnexpectedResponseException =
  48525. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  48526. exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
  48527. exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  48528. exports.isValidUrl = pdfjsLibs.pdfjsSharedUtil.isValidUrl;
  48529. exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
  48530. exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
  48531. exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
  48532. exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
  48533. exports.getFilenameFromUrl =
  48534. pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
  48535. exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
  48536. }));