pdf.combined.js 1.7 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543
  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.6.222';
  30. var pdfjsBuild = 'd714873';
  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 =
  1701. function Util_getInheritableProperty(dict, name, getArray) {
  1702. while (dict && !dict.has(name)) {
  1703. dict = dict.get('Parent');
  1704. }
  1705. if (!dict) {
  1706. return null;
  1707. }
  1708. return getArray ? dict.getArray(name) : 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 JpegImageClosure() {
  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 JpegImage() {
  10659. this.decodeTransform = null;
  10660. this.colorTransform = -1;
  10661. }
  10662. function buildHuffmanTable(codeLengths, values) {
  10663. var k = 0, code = [], i, j, length = 16;
  10664. while (length > 0 && !codeLengths[length - 1]) {
  10665. length--;
  10666. }
  10667. code.push({children: [], index: 0});
  10668. var p = code[0], q;
  10669. for (i = 0; i < length; i++) {
  10670. for (j = 0; j < codeLengths[i]; j++) {
  10671. p = code.pop();
  10672. p.children[p.index] = values[k];
  10673. while (p.index > 0) {
  10674. p = code.pop();
  10675. }
  10676. p.index++;
  10677. code.push(p);
  10678. while (code.length <= i) {
  10679. code.push(q = {children: [], index: 0});
  10680. p.children[p.index] = q.children;
  10681. p = q;
  10682. }
  10683. k++;
  10684. }
  10685. if (i + 1 < length) {
  10686. // p here points to last code
  10687. code.push(q = {children: [], index: 0});
  10688. p.children[p.index] = q.children;
  10689. p = q;
  10690. }
  10691. }
  10692. return code[0].children;
  10693. }
  10694. function getBlockBufferOffset(component, row, col) {
  10695. return 64 * ((component.blocksPerLine + 1) * row + col);
  10696. }
  10697. function decodeScan(data, offset, frame, components, resetInterval,
  10698. spectralStart, spectralEnd, successivePrev, successive) {
  10699. var mcusPerLine = frame.mcusPerLine;
  10700. var progressive = frame.progressive;
  10701. var startOffset = offset, bitsData = 0, bitsCount = 0;
  10702. function readBit() {
  10703. if (bitsCount > 0) {
  10704. bitsCount--;
  10705. return (bitsData >> bitsCount) & 1;
  10706. }
  10707. bitsData = data[offset++];
  10708. if (bitsData === 0xFF) {
  10709. var nextByte = data[offset++];
  10710. if (nextByte) {
  10711. error('JPEG error: unexpected marker ' +
  10712. ((bitsData << 8) | nextByte).toString(16));
  10713. }
  10714. // unstuff 0
  10715. }
  10716. bitsCount = 7;
  10717. return bitsData >>> 7;
  10718. }
  10719. function decodeHuffman(tree) {
  10720. var node = tree;
  10721. while (true) {
  10722. node = node[readBit()];
  10723. if (typeof node === 'number') {
  10724. return node;
  10725. }
  10726. if (typeof node !== 'object') {
  10727. error('JPEG error: invalid huffman sequence');
  10728. }
  10729. }
  10730. }
  10731. function receive(length) {
  10732. var n = 0;
  10733. while (length > 0) {
  10734. n = (n << 1) | readBit();
  10735. length--;
  10736. }
  10737. return n;
  10738. }
  10739. function receiveAndExtend(length) {
  10740. if (length === 1) {
  10741. return readBit() === 1 ? 1 : -1;
  10742. }
  10743. var n = receive(length);
  10744. if (n >= 1 << (length - 1)) {
  10745. return n;
  10746. }
  10747. return n + (-1 << length) + 1;
  10748. }
  10749. function decodeBaseline(component, offset) {
  10750. var t = decodeHuffman(component.huffmanTableDC);
  10751. var diff = t === 0 ? 0 : receiveAndExtend(t);
  10752. component.blockData[offset] = (component.pred += diff);
  10753. var k = 1;
  10754. while (k < 64) {
  10755. var rs = decodeHuffman(component.huffmanTableAC);
  10756. var s = rs & 15, r = rs >> 4;
  10757. if (s === 0) {
  10758. if (r < 15) {
  10759. break;
  10760. }
  10761. k += 16;
  10762. continue;
  10763. }
  10764. k += r;
  10765. var z = dctZigZag[k];
  10766. component.blockData[offset + z] = receiveAndExtend(s);
  10767. k++;
  10768. }
  10769. }
  10770. function decodeDCFirst(component, offset) {
  10771. var t = decodeHuffman(component.huffmanTableDC);
  10772. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  10773. component.blockData[offset] = (component.pred += diff);
  10774. }
  10775. function decodeDCSuccessive(component, offset) {
  10776. component.blockData[offset] |= readBit() << successive;
  10777. }
  10778. var eobrun = 0;
  10779. function decodeACFirst(component, offset) {
  10780. if (eobrun > 0) {
  10781. eobrun--;
  10782. return;
  10783. }
  10784. var k = spectralStart, e = spectralEnd;
  10785. while (k <= e) {
  10786. var rs = decodeHuffman(component.huffmanTableAC);
  10787. var s = rs & 15, r = rs >> 4;
  10788. if (s === 0) {
  10789. if (r < 15) {
  10790. eobrun = receive(r) + (1 << r) - 1;
  10791. break;
  10792. }
  10793. k += 16;
  10794. continue;
  10795. }
  10796. k += r;
  10797. var z = dctZigZag[k];
  10798. component.blockData[offset + z] =
  10799. receiveAndExtend(s) * (1 << successive);
  10800. k++;
  10801. }
  10802. }
  10803. var successiveACState = 0, successiveACNextValue;
  10804. function decodeACSuccessive(component, offset) {
  10805. var k = spectralStart;
  10806. var e = spectralEnd;
  10807. var r = 0;
  10808. var s;
  10809. var rs;
  10810. while (k <= e) {
  10811. var z = dctZigZag[k];
  10812. switch (successiveACState) {
  10813. case 0: // initial state
  10814. rs = decodeHuffman(component.huffmanTableAC);
  10815. s = rs & 15;
  10816. r = rs >> 4;
  10817. if (s === 0) {
  10818. if (r < 15) {
  10819. eobrun = receive(r) + (1 << r);
  10820. successiveACState = 4;
  10821. } else {
  10822. r = 16;
  10823. successiveACState = 1;
  10824. }
  10825. } else {
  10826. if (s !== 1) {
  10827. error('JPEG error: invalid ACn encoding');
  10828. }
  10829. successiveACNextValue = receiveAndExtend(s);
  10830. successiveACState = r ? 2 : 3;
  10831. }
  10832. continue;
  10833. case 1: // skipping r zero items
  10834. case 2:
  10835. if (component.blockData[offset + z]) {
  10836. component.blockData[offset + z] += (readBit() << successive);
  10837. } else {
  10838. r--;
  10839. if (r === 0) {
  10840. successiveACState = successiveACState === 2 ? 3 : 0;
  10841. }
  10842. }
  10843. break;
  10844. case 3: // set value for a zero item
  10845. if (component.blockData[offset + z]) {
  10846. component.blockData[offset + z] += (readBit() << successive);
  10847. } else {
  10848. component.blockData[offset + z] =
  10849. successiveACNextValue << successive;
  10850. successiveACState = 0;
  10851. }
  10852. break;
  10853. case 4: // eob
  10854. if (component.blockData[offset + z]) {
  10855. component.blockData[offset + z] += (readBit() << successive);
  10856. }
  10857. break;
  10858. }
  10859. k++;
  10860. }
  10861. if (successiveACState === 4) {
  10862. eobrun--;
  10863. if (eobrun === 0) {
  10864. successiveACState = 0;
  10865. }
  10866. }
  10867. }
  10868. function decodeMcu(component, decode, mcu, row, col) {
  10869. var mcuRow = (mcu / mcusPerLine) | 0;
  10870. var mcuCol = mcu % mcusPerLine;
  10871. var blockRow = mcuRow * component.v + row;
  10872. var blockCol = mcuCol * component.h + col;
  10873. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10874. decode(component, offset);
  10875. }
  10876. function decodeBlock(component, decode, mcu) {
  10877. var blockRow = (mcu / component.blocksPerLine) | 0;
  10878. var blockCol = mcu % component.blocksPerLine;
  10879. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10880. decode(component, offset);
  10881. }
  10882. var componentsLength = components.length;
  10883. var component, i, j, k, n;
  10884. var decodeFn;
  10885. if (progressive) {
  10886. if (spectralStart === 0) {
  10887. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  10888. } else {
  10889. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  10890. }
  10891. } else {
  10892. decodeFn = decodeBaseline;
  10893. }
  10894. var mcu = 0, marker;
  10895. var mcuExpected;
  10896. if (componentsLength === 1) {
  10897. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  10898. } else {
  10899. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  10900. }
  10901. if (!resetInterval) {
  10902. resetInterval = mcuExpected;
  10903. }
  10904. var h, v;
  10905. while (mcu < mcuExpected) {
  10906. // reset interval stuff
  10907. for (i = 0; i < componentsLength; i++) {
  10908. components[i].pred = 0;
  10909. }
  10910. eobrun = 0;
  10911. if (componentsLength === 1) {
  10912. component = components[0];
  10913. for (n = 0; n < resetInterval; n++) {
  10914. decodeBlock(component, decodeFn, mcu);
  10915. mcu++;
  10916. }
  10917. } else {
  10918. for (n = 0; n < resetInterval; n++) {
  10919. for (i = 0; i < componentsLength; i++) {
  10920. component = components[i];
  10921. h = component.h;
  10922. v = component.v;
  10923. for (j = 0; j < v; j++) {
  10924. for (k = 0; k < h; k++) {
  10925. decodeMcu(component, decodeFn, mcu, j, k);
  10926. }
  10927. }
  10928. }
  10929. mcu++;
  10930. }
  10931. }
  10932. // find marker
  10933. bitsCount = 0;
  10934. marker = (data[offset] << 8) | data[offset + 1];
  10935. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  10936. // those to attempt to find a valid marker (fixes issue4090.pdf).
  10937. while (data[offset] === 0x00 && offset < data.length - 1) {
  10938. offset++;
  10939. marker = (data[offset] << 8) | data[offset + 1];
  10940. }
  10941. if (marker <= 0xFF00) {
  10942. error('JPEG error: marker was not found');
  10943. }
  10944. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  10945. offset += 2;
  10946. } else {
  10947. break;
  10948. }
  10949. }
  10950. return offset - startOffset;
  10951. }
  10952. // A port of poppler's IDCT method which in turn is taken from:
  10953. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  10954. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  10955. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  10956. // 988-991.
  10957. function quantizeAndInverse(component, blockBufferOffset, p) {
  10958. var qt = component.quantizationTable, blockData = component.blockData;
  10959. var v0, v1, v2, v3, v4, v5, v6, v7;
  10960. var p0, p1, p2, p3, p4, p5, p6, p7;
  10961. var t;
  10962. if (!qt) {
  10963. error('JPEG error: missing required Quantization Table.');
  10964. }
  10965. // inverse DCT on rows
  10966. for (var row = 0; row < 64; row += 8) {
  10967. // gather block data
  10968. p0 = blockData[blockBufferOffset + row];
  10969. p1 = blockData[blockBufferOffset + row + 1];
  10970. p2 = blockData[blockBufferOffset + row + 2];
  10971. p3 = blockData[blockBufferOffset + row + 3];
  10972. p4 = blockData[blockBufferOffset + row + 4];
  10973. p5 = blockData[blockBufferOffset + row + 5];
  10974. p6 = blockData[blockBufferOffset + row + 6];
  10975. p7 = blockData[blockBufferOffset + row + 7];
  10976. // dequant p0
  10977. p0 *= qt[row];
  10978. // check for all-zero AC coefficients
  10979. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  10980. t = (dctSqrt2 * p0 + 512) >> 10;
  10981. p[row] = t;
  10982. p[row + 1] = t;
  10983. p[row + 2] = t;
  10984. p[row + 3] = t;
  10985. p[row + 4] = t;
  10986. p[row + 5] = t;
  10987. p[row + 6] = t;
  10988. p[row + 7] = t;
  10989. continue;
  10990. }
  10991. // dequant p1 ... p7
  10992. p1 *= qt[row + 1];
  10993. p2 *= qt[row + 2];
  10994. p3 *= qt[row + 3];
  10995. p4 *= qt[row + 4];
  10996. p5 *= qt[row + 5];
  10997. p6 *= qt[row + 6];
  10998. p7 *= qt[row + 7];
  10999. // stage 4
  11000. v0 = (dctSqrt2 * p0 + 128) >> 8;
  11001. v1 = (dctSqrt2 * p4 + 128) >> 8;
  11002. v2 = p2;
  11003. v3 = p6;
  11004. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  11005. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  11006. v5 = p3 << 4;
  11007. v6 = p5 << 4;
  11008. // stage 3
  11009. v0 = (v0 + v1 + 1) >> 1;
  11010. v1 = v0 - v1;
  11011. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  11012. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  11013. v3 = t;
  11014. v4 = (v4 + v6 + 1) >> 1;
  11015. v6 = v4 - v6;
  11016. v7 = (v7 + v5 + 1) >> 1;
  11017. v5 = v7 - v5;
  11018. // stage 2
  11019. v0 = (v0 + v3 + 1) >> 1;
  11020. v3 = v0 - v3;
  11021. v1 = (v1 + v2 + 1) >> 1;
  11022. v2 = v1 - v2;
  11023. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11024. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11025. v7 = t;
  11026. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11027. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11028. v6 = t;
  11029. // stage 1
  11030. p[row] = v0 + v7;
  11031. p[row + 7] = v0 - v7;
  11032. p[row + 1] = v1 + v6;
  11033. p[row + 6] = v1 - v6;
  11034. p[row + 2] = v2 + v5;
  11035. p[row + 5] = v2 - v5;
  11036. p[row + 3] = v3 + v4;
  11037. p[row + 4] = v3 - v4;
  11038. }
  11039. // inverse DCT on columns
  11040. for (var col = 0; col < 8; ++col) {
  11041. p0 = p[col];
  11042. p1 = p[col + 8];
  11043. p2 = p[col + 16];
  11044. p3 = p[col + 24];
  11045. p4 = p[col + 32];
  11046. p5 = p[col + 40];
  11047. p6 = p[col + 48];
  11048. p7 = p[col + 56];
  11049. // check for all-zero AC coefficients
  11050. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  11051. t = (dctSqrt2 * p0 + 8192) >> 14;
  11052. // convert to 8 bit
  11053. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  11054. blockData[blockBufferOffset + col] = t;
  11055. blockData[blockBufferOffset + col + 8] = t;
  11056. blockData[blockBufferOffset + col + 16] = t;
  11057. blockData[blockBufferOffset + col + 24] = t;
  11058. blockData[blockBufferOffset + col + 32] = t;
  11059. blockData[blockBufferOffset + col + 40] = t;
  11060. blockData[blockBufferOffset + col + 48] = t;
  11061. blockData[blockBufferOffset + col + 56] = t;
  11062. continue;
  11063. }
  11064. // stage 4
  11065. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  11066. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  11067. v2 = p2;
  11068. v3 = p6;
  11069. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  11070. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  11071. v5 = p3;
  11072. v6 = p5;
  11073. // stage 3
  11074. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  11075. // converting to UInt8 range later.
  11076. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  11077. v1 = v0 - v1;
  11078. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  11079. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  11080. v3 = t;
  11081. v4 = (v4 + v6 + 1) >> 1;
  11082. v6 = v4 - v6;
  11083. v7 = (v7 + v5 + 1) >> 1;
  11084. v5 = v7 - v5;
  11085. // stage 2
  11086. v0 = (v0 + v3 + 1) >> 1;
  11087. v3 = v0 - v3;
  11088. v1 = (v1 + v2 + 1) >> 1;
  11089. v2 = v1 - v2;
  11090. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11091. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11092. v7 = t;
  11093. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11094. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11095. v6 = t;
  11096. // stage 1
  11097. p0 = v0 + v7;
  11098. p7 = v0 - v7;
  11099. p1 = v1 + v6;
  11100. p6 = v1 - v6;
  11101. p2 = v2 + v5;
  11102. p5 = v2 - v5;
  11103. p3 = v3 + v4;
  11104. p4 = v3 - v4;
  11105. // convert to 8-bit integers
  11106. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  11107. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  11108. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  11109. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  11110. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  11111. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  11112. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  11113. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  11114. // store block data
  11115. blockData[blockBufferOffset + col] = p0;
  11116. blockData[blockBufferOffset + col + 8] = p1;
  11117. blockData[blockBufferOffset + col + 16] = p2;
  11118. blockData[blockBufferOffset + col + 24] = p3;
  11119. blockData[blockBufferOffset + col + 32] = p4;
  11120. blockData[blockBufferOffset + col + 40] = p5;
  11121. blockData[blockBufferOffset + col + 48] = p6;
  11122. blockData[blockBufferOffset + col + 56] = p7;
  11123. }
  11124. }
  11125. function buildComponentData(frame, component) {
  11126. var blocksPerLine = component.blocksPerLine;
  11127. var blocksPerColumn = component.blocksPerColumn;
  11128. var computationBuffer = new Int16Array(64);
  11129. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  11130. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  11131. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  11132. quantizeAndInverse(component, offset, computationBuffer);
  11133. }
  11134. }
  11135. return component.blockData;
  11136. }
  11137. function clamp0to255(a) {
  11138. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  11139. }
  11140. JpegImage.prototype = {
  11141. parse: function parse(data) {
  11142. function readUint16() {
  11143. var value = (data[offset] << 8) | data[offset + 1];
  11144. offset += 2;
  11145. return value;
  11146. }
  11147. function readDataBlock() {
  11148. var length = readUint16();
  11149. var array = data.subarray(offset, offset + length - 2);
  11150. offset += array.length;
  11151. return array;
  11152. }
  11153. function prepareComponents(frame) {
  11154. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  11155. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  11156. for (var i = 0; i < frame.components.length; i++) {
  11157. component = frame.components[i];
  11158. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  11159. component.h / frame.maxH);
  11160. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  11161. component.v / frame.maxV);
  11162. var blocksPerLineForMcu = mcusPerLine * component.h;
  11163. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  11164. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  11165. (blocksPerLineForMcu + 1);
  11166. component.blockData = new Int16Array(blocksBufferSize);
  11167. component.blocksPerLine = blocksPerLine;
  11168. component.blocksPerColumn = blocksPerColumn;
  11169. }
  11170. frame.mcusPerLine = mcusPerLine;
  11171. frame.mcusPerColumn = mcusPerColumn;
  11172. }
  11173. var offset = 0;
  11174. var jfif = null;
  11175. var adobe = null;
  11176. var frame, resetInterval;
  11177. var quantizationTables = [];
  11178. var huffmanTablesAC = [], huffmanTablesDC = [];
  11179. var fileMarker = readUint16();
  11180. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  11181. error('JPEG error: SOI not found');
  11182. }
  11183. fileMarker = readUint16();
  11184. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  11185. var i, j, l;
  11186. switch(fileMarker) {
  11187. case 0xFFE0: // APP0 (Application Specific)
  11188. case 0xFFE1: // APP1
  11189. case 0xFFE2: // APP2
  11190. case 0xFFE3: // APP3
  11191. case 0xFFE4: // APP4
  11192. case 0xFFE5: // APP5
  11193. case 0xFFE6: // APP6
  11194. case 0xFFE7: // APP7
  11195. case 0xFFE8: // APP8
  11196. case 0xFFE9: // APP9
  11197. case 0xFFEA: // APP10
  11198. case 0xFFEB: // APP11
  11199. case 0xFFEC: // APP12
  11200. case 0xFFED: // APP13
  11201. case 0xFFEE: // APP14
  11202. case 0xFFEF: // APP15
  11203. case 0xFFFE: // COM (Comment)
  11204. var appData = readDataBlock();
  11205. if (fileMarker === 0xFFE0) {
  11206. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  11207. appData[2] === 0x49 && appData[3] === 0x46 &&
  11208. appData[4] === 0) { // 'JFIF\x00'
  11209. jfif = {
  11210. version: { major: appData[5], minor: appData[6] },
  11211. densityUnits: appData[7],
  11212. xDensity: (appData[8] << 8) | appData[9],
  11213. yDensity: (appData[10] << 8) | appData[11],
  11214. thumbWidth: appData[12],
  11215. thumbHeight: appData[13],
  11216. thumbData: appData.subarray(14, 14 +
  11217. 3 * appData[12] * appData[13])
  11218. };
  11219. }
  11220. }
  11221. // TODO APP1 - Exif
  11222. if (fileMarker === 0xFFEE) {
  11223. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  11224. appData[2] === 0x6F && appData[3] === 0x62 &&
  11225. appData[4] === 0x65) { // 'Adobe'
  11226. adobe = {
  11227. version: (appData[5] << 8) | appData[6],
  11228. flags0: (appData[7] << 8) | appData[8],
  11229. flags1: (appData[9] << 8) | appData[10],
  11230. transformCode: appData[11]
  11231. };
  11232. }
  11233. }
  11234. break;
  11235. case 0xFFDB: // DQT (Define Quantization Tables)
  11236. var quantizationTablesLength = readUint16();
  11237. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  11238. var z;
  11239. while (offset < quantizationTablesEnd) {
  11240. var quantizationTableSpec = data[offset++];
  11241. var tableData = new Uint16Array(64);
  11242. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  11243. for (j = 0; j < 64; j++) {
  11244. z = dctZigZag[j];
  11245. tableData[z] = data[offset++];
  11246. }
  11247. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  11248. for (j = 0; j < 64; j++) {
  11249. z = dctZigZag[j];
  11250. tableData[z] = readUint16();
  11251. }
  11252. } else {
  11253. error('JPEG error: DQT - invalid table spec');
  11254. }
  11255. quantizationTables[quantizationTableSpec & 15] = tableData;
  11256. }
  11257. break;
  11258. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  11259. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  11260. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  11261. if (frame) {
  11262. error('JPEG error: Only single frame JPEGs supported');
  11263. }
  11264. readUint16(); // skip data length
  11265. frame = {};
  11266. frame.extended = (fileMarker === 0xFFC1);
  11267. frame.progressive = (fileMarker === 0xFFC2);
  11268. frame.precision = data[offset++];
  11269. frame.scanLines = readUint16();
  11270. frame.samplesPerLine = readUint16();
  11271. frame.components = [];
  11272. frame.componentIds = {};
  11273. var componentsCount = data[offset++], componentId;
  11274. var maxH = 0, maxV = 0;
  11275. for (i = 0; i < componentsCount; i++) {
  11276. componentId = data[offset];
  11277. var h = data[offset + 1] >> 4;
  11278. var v = data[offset + 1] & 15;
  11279. if (maxH < h) {
  11280. maxH = h;
  11281. }
  11282. if (maxV < v) {
  11283. maxV = v;
  11284. }
  11285. var qId = data[offset + 2];
  11286. l = frame.components.push({
  11287. h: h,
  11288. v: v,
  11289. quantizationId: qId,
  11290. quantizationTable: null, // See comment below.
  11291. });
  11292. frame.componentIds[componentId] = l - 1;
  11293. offset += 3;
  11294. }
  11295. frame.maxH = maxH;
  11296. frame.maxV = maxV;
  11297. prepareComponents(frame);
  11298. break;
  11299. case 0xFFC4: // DHT (Define Huffman Tables)
  11300. var huffmanLength = readUint16();
  11301. for (i = 2; i < huffmanLength;) {
  11302. var huffmanTableSpec = data[offset++];
  11303. var codeLengths = new Uint8Array(16);
  11304. var codeLengthSum = 0;
  11305. for (j = 0; j < 16; j++, offset++) {
  11306. codeLengthSum += (codeLengths[j] = data[offset]);
  11307. }
  11308. var huffmanValues = new Uint8Array(codeLengthSum);
  11309. for (j = 0; j < codeLengthSum; j++, offset++) {
  11310. huffmanValues[j] = data[offset];
  11311. }
  11312. i += 17 + codeLengthSum;
  11313. ((huffmanTableSpec >> 4) === 0 ?
  11314. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  11315. buildHuffmanTable(codeLengths, huffmanValues);
  11316. }
  11317. break;
  11318. case 0xFFDD: // DRI (Define Restart Interval)
  11319. readUint16(); // skip data length
  11320. resetInterval = readUint16();
  11321. break;
  11322. case 0xFFDA: // SOS (Start of Scan)
  11323. var scanLength = readUint16();
  11324. var selectorsCount = data[offset++];
  11325. var components = [], component;
  11326. for (i = 0; i < selectorsCount; i++) {
  11327. var componentIndex = frame.componentIds[data[offset++]];
  11328. component = frame.components[componentIndex];
  11329. var tableSpec = data[offset++];
  11330. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  11331. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  11332. components.push(component);
  11333. }
  11334. var spectralStart = data[offset++];
  11335. var spectralEnd = data[offset++];
  11336. var successiveApproximation = data[offset++];
  11337. var processed = decodeScan(data, offset,
  11338. frame, components, resetInterval,
  11339. spectralStart, spectralEnd,
  11340. successiveApproximation >> 4, successiveApproximation & 15);
  11341. offset += processed;
  11342. break;
  11343. case 0xFFFF: // Fill bytes
  11344. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  11345. offset--;
  11346. }
  11347. break;
  11348. default:
  11349. if (data[offset - 3] === 0xFF &&
  11350. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  11351. // could be incorrect encoding -- last 0xFF byte of the previous
  11352. // block was eaten by the encoder
  11353. offset -= 3;
  11354. break;
  11355. }
  11356. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  11357. }
  11358. fileMarker = readUint16();
  11359. }
  11360. this.width = frame.samplesPerLine;
  11361. this.height = frame.scanLines;
  11362. this.jfif = jfif;
  11363. this.adobe = adobe;
  11364. this.components = [];
  11365. for (i = 0; i < frame.components.length; i++) {
  11366. component = frame.components[i];
  11367. // Prevent errors when DQT markers are placed after SOF{n} markers,
  11368. // by assigning the `quantizationTable` entry after the entire image
  11369. // has been parsed (fixes issue7406.pdf).
  11370. var quantizationTable = quantizationTables[component.quantizationId];
  11371. if (quantizationTable) {
  11372. component.quantizationTable = quantizationTable;
  11373. }
  11374. this.components.push({
  11375. output: buildComponentData(frame, component),
  11376. scaleX: component.h / frame.maxH,
  11377. scaleY: component.v / frame.maxV,
  11378. blocksPerLine: component.blocksPerLine,
  11379. blocksPerColumn: component.blocksPerColumn
  11380. });
  11381. }
  11382. this.numComponents = this.components.length;
  11383. },
  11384. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  11385. var scaleX = this.width / width, scaleY = this.height / height;
  11386. var component, componentScaleX, componentScaleY, blocksPerScanline;
  11387. var x, y, i, j, k;
  11388. var index;
  11389. var offset = 0;
  11390. var output;
  11391. var numComponents = this.components.length;
  11392. var dataLength = width * height * numComponents;
  11393. var data = new Uint8Array(dataLength);
  11394. var xScaleBlockOffset = new Uint32Array(width);
  11395. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  11396. for (i = 0; i < numComponents; i++) {
  11397. component = this.components[i];
  11398. componentScaleX = component.scaleX * scaleX;
  11399. componentScaleY = component.scaleY * scaleY;
  11400. offset = i;
  11401. output = component.output;
  11402. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  11403. // precalculate the xScaleBlockOffset
  11404. for (x = 0; x < width; x++) {
  11405. j = 0 | (x * componentScaleX);
  11406. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  11407. }
  11408. // linearize the blocks of the component
  11409. for (y = 0; y < height; y++) {
  11410. j = 0 | (y * componentScaleY);
  11411. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  11412. for (x = 0; x < width; x++) {
  11413. data[offset] = output[index + xScaleBlockOffset[x]];
  11414. offset += numComponents;
  11415. }
  11416. }
  11417. }
  11418. // decodeTransform contains pairs of multiplier (-256..256) and additive
  11419. var transform = this.decodeTransform;
  11420. if (transform) {
  11421. for (i = 0; i < dataLength;) {
  11422. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  11423. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  11424. }
  11425. }
  11426. }
  11427. return data;
  11428. },
  11429. _isColorConversionNeeded: function isColorConversionNeeded() {
  11430. if (this.adobe && this.adobe.transformCode) {
  11431. // The adobe transform marker overrides any previous setting
  11432. return true;
  11433. } else if (this.numComponents === 3) {
  11434. if (!this.adobe && this.colorTransform === 0) {
  11435. // If the Adobe transform marker is not present and the image
  11436. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  11437. // then the colours should *not* be transformed.
  11438. return false;
  11439. }
  11440. return true;
  11441. } else { // `this.numComponents !== 3`
  11442. if (!this.adobe && this.colorTransform === 1) {
  11443. // If the Adobe transform marker is not present and the image
  11444. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  11445. // then the colours should be transformed.
  11446. return true;
  11447. }
  11448. return false;
  11449. }
  11450. },
  11451. _convertYccToRgb: function convertYccToRgb(data) {
  11452. var Y, Cb, Cr;
  11453. for (var i = 0, length = data.length; i < length; i += 3) {
  11454. Y = data[i ];
  11455. Cb = data[i + 1];
  11456. Cr = data[i + 2];
  11457. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  11458. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  11459. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  11460. }
  11461. return data;
  11462. },
  11463. _convertYcckToRgb: function convertYcckToRgb(data) {
  11464. var Y, Cb, Cr, k;
  11465. var offset = 0;
  11466. for (var i = 0, length = data.length; i < length; i += 4) {
  11467. Y = data[i];
  11468. Cb = data[i + 1];
  11469. Cr = data[i + 2];
  11470. k = data[i + 3];
  11471. var r = -122.67195406894 +
  11472. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  11473. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  11474. 0.154362151871126) +
  11475. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  11476. 0.00477271405408747 * k + 1.53380253221734) +
  11477. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  11478. 0.48357088451265) +
  11479. k * (-0.000336197177618394 * k + 0.484791561490776);
  11480. var g = 107.268039397724 +
  11481. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  11482. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  11483. 0.176491792462875) +
  11484. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  11485. 0.000770482631801132 * k - 0.151051492775562) +
  11486. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  11487. 0.25802910206845) +
  11488. k * (-0.000318913117588328 * k - 0.213742400323665);
  11489. var b = -20.810012546947 +
  11490. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  11491. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  11492. 0.814272968359295) +
  11493. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  11494. 0.000560833691242812 * k - 0.195152027534049) +
  11495. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  11496. 0.116935020465145) +
  11497. k * (-0.000343531996510555 * k + 0.24165260232407);
  11498. data[offset++] = clamp0to255(r);
  11499. data[offset++] = clamp0to255(g);
  11500. data[offset++] = clamp0to255(b);
  11501. }
  11502. return data;
  11503. },
  11504. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  11505. var Y, Cb, Cr;
  11506. for (var i = 0, length = data.length; i < length; i += 4) {
  11507. Y = data[i];
  11508. Cb = data[i + 1];
  11509. Cr = data[i + 2];
  11510. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  11511. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  11512. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  11513. // K in data[i + 3] is unchanged
  11514. }
  11515. return data;
  11516. },
  11517. _convertCmykToRgb: function convertCmykToRgb(data) {
  11518. var c, m, y, k;
  11519. var offset = 0;
  11520. var min = -255 * 255 * 255;
  11521. var scale = 1 / 255 / 255;
  11522. for (var i = 0, length = data.length; i < length; i += 4) {
  11523. c = data[i];
  11524. m = data[i + 1];
  11525. y = data[i + 2];
  11526. k = data[i + 3];
  11527. var r =
  11528. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11529. 18.82290502165302 * y + 212.25662451639585 * k -
  11530. 72734.4411664936) +
  11531. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  11532. 17.873870861415444 * k - 1401.7366389350734) +
  11533. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11534. 4465.541406466231) -
  11535. k * (21.86122147463605 * k + 48317.86113160301);
  11536. var g =
  11537. c * (8.841041422036149 * c + 60.118027045597366 * m +
  11538. 6.871425592049007 * y + 31.159100130055922 * k -
  11539. 20220.756542821975) +
  11540. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11541. 131.35250912493976 * k - 48691.05921601825) +
  11542. y * (4.444339102852739 * y + 9.8632861493405 * k -
  11543. 6341.191035517494) -
  11544. k * (20.737325471181034 * k + 47890.15695978492);
  11545. var b =
  11546. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11547. 30.89978309703729 * y - 0.23883238689178934 * k -
  11548. 3616.812083916688) +
  11549. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11550. 50.606957656360734 * k - 28620.90484698408) +
  11551. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  11552. 49363.43385999684) -
  11553. k * (22.33816807309886 * k + 45932.16563550634);
  11554. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  11555. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  11556. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  11557. }
  11558. return data;
  11559. },
  11560. getData: function getData(width, height, forceRGBoutput) {
  11561. if (this.numComponents > 4) {
  11562. error('JPEG error: Unsupported color mode');
  11563. }
  11564. // type of data: Uint8Array(width * height * numComponents)
  11565. var data = this._getLinearizedBlockData(width, height);
  11566. if (this.numComponents === 1 && forceRGBoutput) {
  11567. var dataLength = data.length;
  11568. var rgbData = new Uint8Array(dataLength * 3);
  11569. var offset = 0;
  11570. for (var i = 0; i < dataLength; i++) {
  11571. var grayColor = data[i];
  11572. rgbData[offset++] = grayColor;
  11573. rgbData[offset++] = grayColor;
  11574. rgbData[offset++] = grayColor;
  11575. }
  11576. return rgbData;
  11577. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  11578. return this._convertYccToRgb(data);
  11579. } else if (this.numComponents === 4) {
  11580. if (this._isColorConversionNeeded()) {
  11581. if (forceRGBoutput) {
  11582. return this._convertYcckToRgb(data);
  11583. } else {
  11584. return this._convertYcckToCmyk(data);
  11585. }
  11586. } else if (forceRGBoutput) {
  11587. return this._convertCmykToRgb(data);
  11588. }
  11589. }
  11590. return data;
  11591. }
  11592. };
  11593. return JpegImage;
  11594. })();
  11595. exports.JpegImage = JpegImage;
  11596. }));
  11597. (function (root, factory) {
  11598. {
  11599. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11600. root.pdfjsCoreArithmeticDecoder);
  11601. }
  11602. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11603. var info = sharedUtil.info;
  11604. var warn = sharedUtil.warn;
  11605. var error = sharedUtil.error;
  11606. var log2 = sharedUtil.log2;
  11607. var readUint16 = sharedUtil.readUint16;
  11608. var readUint32 = sharedUtil.readUint32;
  11609. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11610. var JpxImage = (function JpxImageClosure() {
  11611. // Table E.1
  11612. var SubbandsGainLog2 = {
  11613. 'LL': 0,
  11614. 'LH': 1,
  11615. 'HL': 1,
  11616. 'HH': 2
  11617. };
  11618. function JpxImage() {
  11619. this.failOnCorruptedImage = false;
  11620. }
  11621. JpxImage.prototype = {
  11622. parse: function JpxImage_parse(data) {
  11623. var head = readUint16(data, 0);
  11624. // No box header, immediate start of codestream (SOC)
  11625. if (head === 0xFF4F) {
  11626. this.parseCodestream(data, 0, data.length);
  11627. return;
  11628. }
  11629. var position = 0, length = data.length;
  11630. while (position < length) {
  11631. var headerSize = 8;
  11632. var lbox = readUint32(data, position);
  11633. var tbox = readUint32(data, position + 4);
  11634. position += headerSize;
  11635. if (lbox === 1) {
  11636. // XLBox: read UInt64 according to spec.
  11637. // JavaScript's int precision of 53 bit should be sufficient here.
  11638. lbox = readUint32(data, position) * 4294967296 +
  11639. readUint32(data, position + 4);
  11640. position += 8;
  11641. headerSize += 8;
  11642. }
  11643. if (lbox === 0) {
  11644. lbox = length - position + headerSize;
  11645. }
  11646. if (lbox < headerSize) {
  11647. error('JPX Error: Invalid box field size');
  11648. }
  11649. var dataLength = lbox - headerSize;
  11650. var jumpDataLength = true;
  11651. switch (tbox) {
  11652. case 0x6A703268: // 'jp2h'
  11653. jumpDataLength = false; // parsing child boxes
  11654. break;
  11655. case 0x636F6C72: // 'colr'
  11656. // Colorspaces are not used, the CS from the PDF is used.
  11657. var method = data[position];
  11658. if (method === 1) {
  11659. // enumerated colorspace
  11660. var colorspace = readUint32(data, position + 3);
  11661. switch (colorspace) {
  11662. case 16: // this indicates a sRGB colorspace
  11663. case 17: // this indicates a grayscale colorspace
  11664. case 18: // this indicates a YUV colorspace
  11665. break;
  11666. default:
  11667. warn('Unknown colorspace ' + colorspace);
  11668. break;
  11669. }
  11670. } else if (method === 2) {
  11671. info('ICC profile not supported');
  11672. }
  11673. break;
  11674. case 0x6A703263: // 'jp2c'
  11675. this.parseCodestream(data, position, position + dataLength);
  11676. break;
  11677. case 0x6A502020: // 'jP\024\024'
  11678. if (0x0d0a870a !== readUint32(data, position)) {
  11679. warn('Invalid JP2 signature');
  11680. }
  11681. break;
  11682. // The following header types are valid but currently not used:
  11683. case 0x6A501A1A: // 'jP\032\032'
  11684. case 0x66747970: // 'ftyp'
  11685. case 0x72726571: // 'rreq'
  11686. case 0x72657320: // 'res '
  11687. case 0x69686472: // 'ihdr'
  11688. break;
  11689. default:
  11690. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11691. (tbox >> 16) & 0xFF,
  11692. (tbox >> 8) & 0xFF,
  11693. tbox & 0xFF);
  11694. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11695. break;
  11696. }
  11697. if (jumpDataLength) {
  11698. position += dataLength;
  11699. }
  11700. }
  11701. },
  11702. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11703. var newByte = stream.getByte();
  11704. while (newByte >= 0) {
  11705. var oldByte = newByte;
  11706. newByte = stream.getByte();
  11707. var code = (oldByte << 8) | newByte;
  11708. // Image and tile size (SIZ)
  11709. if (code === 0xFF51) {
  11710. stream.skip(4);
  11711. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11712. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11713. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11714. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11715. stream.skip(16);
  11716. var Csiz = stream.getUint16(); // Byte 36
  11717. this.width = Xsiz - XOsiz;
  11718. this.height = Ysiz - YOsiz;
  11719. this.componentsCount = Csiz;
  11720. // Results are always returned as Uint8Arrays
  11721. this.bitsPerComponent = 8;
  11722. return;
  11723. }
  11724. }
  11725. error('JPX Error: No size marker found in JPX stream');
  11726. },
  11727. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11728. var context = {};
  11729. var doNotRecover = false;
  11730. try {
  11731. var position = start;
  11732. while (position + 1 < end) {
  11733. var code = readUint16(data, position);
  11734. position += 2;
  11735. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11736. switch (code) {
  11737. case 0xFF4F: // Start of codestream (SOC)
  11738. context.mainHeader = true;
  11739. break;
  11740. case 0xFFD9: // End of codestream (EOC)
  11741. break;
  11742. case 0xFF51: // Image and tile size (SIZ)
  11743. length = readUint16(data, position);
  11744. var siz = {};
  11745. siz.Xsiz = readUint32(data, position + 4);
  11746. siz.Ysiz = readUint32(data, position + 8);
  11747. siz.XOsiz = readUint32(data, position + 12);
  11748. siz.YOsiz = readUint32(data, position + 16);
  11749. siz.XTsiz = readUint32(data, position + 20);
  11750. siz.YTsiz = readUint32(data, position + 24);
  11751. siz.XTOsiz = readUint32(data, position + 28);
  11752. siz.YTOsiz = readUint32(data, position + 32);
  11753. var componentsCount = readUint16(data, position + 36);
  11754. siz.Csiz = componentsCount;
  11755. var components = [];
  11756. j = position + 38;
  11757. for (var i = 0; i < componentsCount; i++) {
  11758. var component = {
  11759. precision: (data[j] & 0x7F) + 1,
  11760. isSigned: !!(data[j] & 0x80),
  11761. XRsiz: data[j + 1],
  11762. YRsiz: data[j + 1]
  11763. };
  11764. calculateComponentDimensions(component, siz);
  11765. components.push(component);
  11766. }
  11767. context.SIZ = siz;
  11768. context.components = components;
  11769. calculateTileGrids(context, components);
  11770. context.QCC = [];
  11771. context.COC = [];
  11772. break;
  11773. case 0xFF5C: // Quantization default (QCD)
  11774. length = readUint16(data, position);
  11775. var qcd = {};
  11776. j = position + 2;
  11777. sqcd = data[j++];
  11778. switch (sqcd & 0x1F) {
  11779. case 0:
  11780. spqcdSize = 8;
  11781. scalarExpounded = true;
  11782. break;
  11783. case 1:
  11784. spqcdSize = 16;
  11785. scalarExpounded = false;
  11786. break;
  11787. case 2:
  11788. spqcdSize = 16;
  11789. scalarExpounded = true;
  11790. break;
  11791. default:
  11792. throw new Error('Invalid SQcd value ' + sqcd);
  11793. }
  11794. qcd.noQuantization = (spqcdSize === 8);
  11795. qcd.scalarExpounded = scalarExpounded;
  11796. qcd.guardBits = sqcd >> 5;
  11797. spqcds = [];
  11798. while (j < length + position) {
  11799. var spqcd = {};
  11800. if (spqcdSize === 8) {
  11801. spqcd.epsilon = data[j++] >> 3;
  11802. spqcd.mu = 0;
  11803. } else {
  11804. spqcd.epsilon = data[j] >> 3;
  11805. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11806. j += 2;
  11807. }
  11808. spqcds.push(spqcd);
  11809. }
  11810. qcd.SPqcds = spqcds;
  11811. if (context.mainHeader) {
  11812. context.QCD = qcd;
  11813. } else {
  11814. context.currentTile.QCD = qcd;
  11815. context.currentTile.QCC = [];
  11816. }
  11817. break;
  11818. case 0xFF5D: // Quantization component (QCC)
  11819. length = readUint16(data, position);
  11820. var qcc = {};
  11821. j = position + 2;
  11822. var cqcc;
  11823. if (context.SIZ.Csiz < 257) {
  11824. cqcc = data[j++];
  11825. } else {
  11826. cqcc = readUint16(data, j);
  11827. j += 2;
  11828. }
  11829. sqcd = data[j++];
  11830. switch (sqcd & 0x1F) {
  11831. case 0:
  11832. spqcdSize = 8;
  11833. scalarExpounded = true;
  11834. break;
  11835. case 1:
  11836. spqcdSize = 16;
  11837. scalarExpounded = false;
  11838. break;
  11839. case 2:
  11840. spqcdSize = 16;
  11841. scalarExpounded = true;
  11842. break;
  11843. default:
  11844. throw new Error('Invalid SQcd value ' + sqcd);
  11845. }
  11846. qcc.noQuantization = (spqcdSize === 8);
  11847. qcc.scalarExpounded = scalarExpounded;
  11848. qcc.guardBits = sqcd >> 5;
  11849. spqcds = [];
  11850. while (j < (length + position)) {
  11851. spqcd = {};
  11852. if (spqcdSize === 8) {
  11853. spqcd.epsilon = data[j++] >> 3;
  11854. spqcd.mu = 0;
  11855. } else {
  11856. spqcd.epsilon = data[j] >> 3;
  11857. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11858. j += 2;
  11859. }
  11860. spqcds.push(spqcd);
  11861. }
  11862. qcc.SPqcds = spqcds;
  11863. if (context.mainHeader) {
  11864. context.QCC[cqcc] = qcc;
  11865. } else {
  11866. context.currentTile.QCC[cqcc] = qcc;
  11867. }
  11868. break;
  11869. case 0xFF52: // Coding style default (COD)
  11870. length = readUint16(data, position);
  11871. var cod = {};
  11872. j = position + 2;
  11873. var scod = data[j++];
  11874. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11875. cod.sopMarkerUsed = !!(scod & 2);
  11876. cod.ephMarkerUsed = !!(scod & 4);
  11877. cod.progressionOrder = data[j++];
  11878. cod.layersCount = readUint16(data, j);
  11879. j += 2;
  11880. cod.multipleComponentTransform = data[j++];
  11881. cod.decompositionLevelsCount = data[j++];
  11882. cod.xcb = (data[j++] & 0xF) + 2;
  11883. cod.ycb = (data[j++] & 0xF) + 2;
  11884. var blockStyle = data[j++];
  11885. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  11886. cod.resetContextProbabilities = !!(blockStyle & 2);
  11887. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  11888. cod.verticalyStripe = !!(blockStyle & 8);
  11889. cod.predictableTermination = !!(blockStyle & 16);
  11890. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  11891. cod.reversibleTransformation = data[j++];
  11892. if (cod.entropyCoderWithCustomPrecincts) {
  11893. var precinctsSizes = [];
  11894. while (j < length + position) {
  11895. var precinctsSize = data[j++];
  11896. precinctsSizes.push({
  11897. PPx: precinctsSize & 0xF,
  11898. PPy: precinctsSize >> 4
  11899. });
  11900. }
  11901. cod.precinctsSizes = precinctsSizes;
  11902. }
  11903. var unsupported = [];
  11904. if (cod.selectiveArithmeticCodingBypass) {
  11905. unsupported.push('selectiveArithmeticCodingBypass');
  11906. }
  11907. if (cod.resetContextProbabilities) {
  11908. unsupported.push('resetContextProbabilities');
  11909. }
  11910. if (cod.terminationOnEachCodingPass) {
  11911. unsupported.push('terminationOnEachCodingPass');
  11912. }
  11913. if (cod.verticalyStripe) {
  11914. unsupported.push('verticalyStripe');
  11915. }
  11916. if (cod.predictableTermination) {
  11917. unsupported.push('predictableTermination');
  11918. }
  11919. if (unsupported.length > 0) {
  11920. doNotRecover = true;
  11921. throw new Error('Unsupported COD options (' +
  11922. unsupported.join(', ') + ')');
  11923. }
  11924. if (context.mainHeader) {
  11925. context.COD = cod;
  11926. } else {
  11927. context.currentTile.COD = cod;
  11928. context.currentTile.COC = [];
  11929. }
  11930. break;
  11931. case 0xFF90: // Start of tile-part (SOT)
  11932. length = readUint16(data, position);
  11933. tile = {};
  11934. tile.index = readUint16(data, position + 2);
  11935. tile.length = readUint32(data, position + 4);
  11936. tile.dataEnd = tile.length + position - 2;
  11937. tile.partIndex = data[position + 8];
  11938. tile.partsCount = data[position + 9];
  11939. context.mainHeader = false;
  11940. if (tile.partIndex === 0) {
  11941. // reset component specific settings
  11942. tile.COD = context.COD;
  11943. tile.COC = context.COC.slice(0); // clone of the global COC
  11944. tile.QCD = context.QCD;
  11945. tile.QCC = context.QCC.slice(0); // clone of the global COC
  11946. }
  11947. context.currentTile = tile;
  11948. break;
  11949. case 0xFF93: // Start of data (SOD)
  11950. tile = context.currentTile;
  11951. if (tile.partIndex === 0) {
  11952. initializeTile(context, tile.index);
  11953. buildPackets(context);
  11954. }
  11955. // moving to the end of the data
  11956. length = tile.dataEnd - position;
  11957. parseTilePackets(context, data, position, length);
  11958. break;
  11959. case 0xFF55: // Tile-part lengths, main header (TLM)
  11960. case 0xFF57: // Packet length, main header (PLM)
  11961. case 0xFF58: // Packet length, tile-part header (PLT)
  11962. case 0xFF64: // Comment (COM)
  11963. length = readUint16(data, position);
  11964. // skipping content
  11965. break;
  11966. case 0xFF53: // Coding style component (COC)
  11967. throw new Error('Codestream code 0xFF53 (COC) is ' +
  11968. 'not implemented');
  11969. default:
  11970. throw new Error('Unknown codestream code: ' + code.toString(16));
  11971. }
  11972. position += length;
  11973. }
  11974. } catch (e) {
  11975. if (doNotRecover || this.failOnCorruptedImage) {
  11976. error('JPX Error: ' + e.message);
  11977. } else {
  11978. warn('JPX: Trying to recover from: ' + e.message);
  11979. }
  11980. }
  11981. this.tiles = transformComponents(context);
  11982. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  11983. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  11984. this.componentsCount = context.SIZ.Csiz;
  11985. }
  11986. };
  11987. function calculateComponentDimensions(component, siz) {
  11988. // Section B.2 Component mapping
  11989. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  11990. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  11991. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  11992. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  11993. component.width = component.x1 - component.x0;
  11994. component.height = component.y1 - component.y0;
  11995. }
  11996. function calculateTileGrids(context, components) {
  11997. var siz = context.SIZ;
  11998. // Section B.3 Division into tile and tile-components
  11999. var tile, tiles = [];
  12000. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  12001. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  12002. for (var q = 0; q < numYtiles; q++) {
  12003. for (var p = 0; p < numXtiles; p++) {
  12004. tile = {};
  12005. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12006. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12007. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12008. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12009. tile.width = tile.tx1 - tile.tx0;
  12010. tile.height = tile.ty1 - tile.ty0;
  12011. tile.components = [];
  12012. tiles.push(tile);
  12013. }
  12014. }
  12015. context.tiles = tiles;
  12016. var componentsCount = siz.Csiz;
  12017. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12018. var component = components[i];
  12019. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12020. var tileComponent = {};
  12021. tile = tiles[j];
  12022. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12023. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12024. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12025. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12026. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12027. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12028. tile.components[i] = tileComponent;
  12029. }
  12030. }
  12031. }
  12032. function getBlocksDimensions(context, component, r) {
  12033. var codOrCoc = component.codingStyleParameters;
  12034. var result = {};
  12035. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12036. result.PPx = 15;
  12037. result.PPy = 15;
  12038. } else {
  12039. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12040. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12041. }
  12042. // calculate codeblock size as described in section B.7
  12043. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12044. Math.min(codOrCoc.xcb, result.PPx));
  12045. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12046. Math.min(codOrCoc.ycb, result.PPy));
  12047. return result;
  12048. }
  12049. function buildPrecincts(context, resolution, dimensions) {
  12050. // Section B.6 Division resolution to precincts
  12051. var precinctWidth = 1 << dimensions.PPx;
  12052. var precinctHeight = 1 << dimensions.PPy;
  12053. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12054. // to precincts. Precinct partition divides a resolution according to width
  12055. // and height parameters. The subband that belongs to the resolution level
  12056. // has a different size than the level, unless it is the zero resolution.
  12057. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12058. // The precinct partitioning for a particular subband is derived from a
  12059. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12060. // resolution level)... The LL band associated with each resolution level is
  12061. // divided into precincts... Each of the resulting precinct regions is then
  12062. // mapped into its child subbands (if any) at the next lower resolution
  12063. // level. This is accomplished by using the coordinate transformation
  12064. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12065. // coordinates of a point in the LL band and child subband, respectively.
  12066. var isZeroRes = resolution.resLevel === 0;
  12067. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12068. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12069. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12070. Math.ceil(resolution.trx1 / precinctWidth) -
  12071. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12072. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12073. Math.ceil(resolution.try1 / precinctHeight) -
  12074. Math.floor(resolution.try0 / precinctHeight) : 0);
  12075. var numprecincts = numprecinctswide * numprecinctshigh;
  12076. resolution.precinctParameters = {
  12077. precinctWidth: precinctWidth,
  12078. precinctHeight: precinctHeight,
  12079. numprecinctswide: numprecinctswide,
  12080. numprecinctshigh: numprecinctshigh,
  12081. numprecincts: numprecincts,
  12082. precinctWidthInSubband: precinctWidthInSubband,
  12083. precinctHeightInSubband: precinctHeightInSubband
  12084. };
  12085. }
  12086. function buildCodeblocks(context, subband, dimensions) {
  12087. // Section B.7 Division sub-band into code-blocks
  12088. var xcb_ = dimensions.xcb_;
  12089. var ycb_ = dimensions.ycb_;
  12090. var codeblockWidth = 1 << xcb_;
  12091. var codeblockHeight = 1 << ycb_;
  12092. var cbx0 = subband.tbx0 >> xcb_;
  12093. var cby0 = subband.tby0 >> ycb_;
  12094. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12095. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12096. var precinctParameters = subband.resolution.precinctParameters;
  12097. var codeblocks = [];
  12098. var precincts = [];
  12099. var i, j, codeblock, precinctNumber;
  12100. for (j = cby0; j < cby1; j++) {
  12101. for (i = cbx0; i < cbx1; i++) {
  12102. codeblock = {
  12103. cbx: i,
  12104. cby: j,
  12105. tbx0: codeblockWidth * i,
  12106. tby0: codeblockHeight * j,
  12107. tbx1: codeblockWidth * (i + 1),
  12108. tby1: codeblockHeight * (j + 1)
  12109. };
  12110. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12111. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12112. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12113. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12114. // Calculate precinct number for this codeblock, codeblock position
  12115. // should be relative to its subband, use actual dimension and position
  12116. // See comment about codeblock group width and height
  12117. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12118. precinctParameters.precinctWidthInSubband);
  12119. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12120. precinctParameters.precinctHeightInSubband);
  12121. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12122. codeblock.precinctNumber = precinctNumber;
  12123. codeblock.subbandType = subband.type;
  12124. codeblock.Lblock = 3;
  12125. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12126. codeblock.tby1_ <= codeblock.tby0_) {
  12127. continue;
  12128. }
  12129. codeblocks.push(codeblock);
  12130. // building precinct for the sub-band
  12131. var precinct = precincts[precinctNumber];
  12132. if (precinct !== undefined) {
  12133. if (i < precinct.cbxMin) {
  12134. precinct.cbxMin = i;
  12135. } else if (i > precinct.cbxMax) {
  12136. precinct.cbxMax = i;
  12137. }
  12138. if (j < precinct.cbyMin) {
  12139. precinct.cbxMin = j;
  12140. } else if (j > precinct.cbyMax) {
  12141. precinct.cbyMax = j;
  12142. }
  12143. } else {
  12144. precincts[precinctNumber] = precinct = {
  12145. cbxMin: i,
  12146. cbyMin: j,
  12147. cbxMax: i,
  12148. cbyMax: j
  12149. };
  12150. }
  12151. codeblock.precinct = precinct;
  12152. }
  12153. }
  12154. subband.codeblockParameters = {
  12155. codeblockWidth: xcb_,
  12156. codeblockHeight: ycb_,
  12157. numcodeblockwide: cbx1 - cbx0 + 1,
  12158. numcodeblockhigh: cby1 - cby0 + 1
  12159. };
  12160. subband.codeblocks = codeblocks;
  12161. subband.precincts = precincts;
  12162. }
  12163. function createPacket(resolution, precinctNumber, layerNumber) {
  12164. var precinctCodeblocks = [];
  12165. // Section B.10.8 Order of info in packet
  12166. var subbands = resolution.subbands;
  12167. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12168. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12169. var subband = subbands[i];
  12170. var codeblocks = subband.codeblocks;
  12171. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12172. var codeblock = codeblocks[j];
  12173. if (codeblock.precinctNumber !== precinctNumber) {
  12174. continue;
  12175. }
  12176. precinctCodeblocks.push(codeblock);
  12177. }
  12178. }
  12179. return {
  12180. layerNumber: layerNumber,
  12181. codeblocks: precinctCodeblocks
  12182. };
  12183. }
  12184. function LayerResolutionComponentPositionIterator(context) {
  12185. var siz = context.SIZ;
  12186. var tileIndex = context.currentTile.index;
  12187. var tile = context.tiles[tileIndex];
  12188. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12189. var componentsCount = siz.Csiz;
  12190. var maxDecompositionLevelsCount = 0;
  12191. for (var q = 0; q < componentsCount; q++) {
  12192. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12193. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12194. }
  12195. var l = 0, r = 0, i = 0, k = 0;
  12196. this.nextPacket = function JpxImage_nextPacket() {
  12197. // Section B.12.1.1 Layer-resolution-component-position
  12198. for (; l < layersCount; l++) {
  12199. for (; r <= maxDecompositionLevelsCount; r++) {
  12200. for (; i < componentsCount; i++) {
  12201. var component = tile.components[i];
  12202. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12203. continue;
  12204. }
  12205. var resolution = component.resolutions[r];
  12206. var numprecincts = resolution.precinctParameters.numprecincts;
  12207. for (; k < numprecincts;) {
  12208. var packet = createPacket(resolution, k, l);
  12209. k++;
  12210. return packet;
  12211. }
  12212. k = 0;
  12213. }
  12214. i = 0;
  12215. }
  12216. r = 0;
  12217. }
  12218. error('JPX Error: Out of packets');
  12219. };
  12220. }
  12221. function ResolutionLayerComponentPositionIterator(context) {
  12222. var siz = context.SIZ;
  12223. var tileIndex = context.currentTile.index;
  12224. var tile = context.tiles[tileIndex];
  12225. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12226. var componentsCount = siz.Csiz;
  12227. var maxDecompositionLevelsCount = 0;
  12228. for (var q = 0; q < componentsCount; q++) {
  12229. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12230. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12231. }
  12232. var r = 0, l = 0, i = 0, k = 0;
  12233. this.nextPacket = function JpxImage_nextPacket() {
  12234. // Section B.12.1.2 Resolution-layer-component-position
  12235. for (; r <= maxDecompositionLevelsCount; r++) {
  12236. for (; l < layersCount; l++) {
  12237. for (; i < componentsCount; i++) {
  12238. var component = tile.components[i];
  12239. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12240. continue;
  12241. }
  12242. var resolution = component.resolutions[r];
  12243. var numprecincts = resolution.precinctParameters.numprecincts;
  12244. for (; k < numprecincts;) {
  12245. var packet = createPacket(resolution, k, l);
  12246. k++;
  12247. return packet;
  12248. }
  12249. k = 0;
  12250. }
  12251. i = 0;
  12252. }
  12253. l = 0;
  12254. }
  12255. error('JPX Error: Out of packets');
  12256. };
  12257. }
  12258. function ResolutionPositionComponentLayerIterator(context) {
  12259. var siz = context.SIZ;
  12260. var tileIndex = context.currentTile.index;
  12261. var tile = context.tiles[tileIndex];
  12262. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12263. var componentsCount = siz.Csiz;
  12264. var l, r, c, p;
  12265. var maxDecompositionLevelsCount = 0;
  12266. for (c = 0; c < componentsCount; c++) {
  12267. var component = tile.components[c];
  12268. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12269. component.codingStyleParameters.decompositionLevelsCount);
  12270. }
  12271. var maxNumPrecinctsInLevel = new Int32Array(
  12272. maxDecompositionLevelsCount + 1);
  12273. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12274. var maxNumPrecincts = 0;
  12275. for (c = 0; c < componentsCount; ++c) {
  12276. var resolutions = tile.components[c].resolutions;
  12277. if (r < resolutions.length) {
  12278. maxNumPrecincts = Math.max(maxNumPrecincts,
  12279. resolutions[r].precinctParameters.numprecincts);
  12280. }
  12281. }
  12282. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12283. }
  12284. l = 0;
  12285. r = 0;
  12286. c = 0;
  12287. p = 0;
  12288. this.nextPacket = function JpxImage_nextPacket() {
  12289. // Section B.12.1.3 Resolution-position-component-layer
  12290. for (; r <= maxDecompositionLevelsCount; r++) {
  12291. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12292. for (; c < componentsCount; c++) {
  12293. var component = tile.components[c];
  12294. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12295. continue;
  12296. }
  12297. var resolution = component.resolutions[r];
  12298. var numprecincts = resolution.precinctParameters.numprecincts;
  12299. if (p >= numprecincts) {
  12300. continue;
  12301. }
  12302. for (; l < layersCount;) {
  12303. var packet = createPacket(resolution, p, l);
  12304. l++;
  12305. return packet;
  12306. }
  12307. l = 0;
  12308. }
  12309. c = 0;
  12310. }
  12311. p = 0;
  12312. }
  12313. error('JPX Error: Out of packets');
  12314. };
  12315. }
  12316. function PositionComponentResolutionLayerIterator(context) {
  12317. var siz = context.SIZ;
  12318. var tileIndex = context.currentTile.index;
  12319. var tile = context.tiles[tileIndex];
  12320. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12321. var componentsCount = siz.Csiz;
  12322. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12323. var precinctsIterationSizes = precinctsSizes;
  12324. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12325. this.nextPacket = function JpxImage_nextPacket() {
  12326. // Section B.12.1.4 Position-component-resolution-layer
  12327. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12328. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12329. for (; c < componentsCount; c++) {
  12330. var component = tile.components[c];
  12331. var decompositionLevelsCount =
  12332. component.codingStyleParameters.decompositionLevelsCount;
  12333. for (; r <= decompositionLevelsCount; r++) {
  12334. var resolution = component.resolutions[r];
  12335. var sizeInImageScale =
  12336. precinctsSizes.components[c].resolutions[r];
  12337. var k = getPrecinctIndexIfExist(
  12338. px,
  12339. py,
  12340. sizeInImageScale,
  12341. precinctsIterationSizes,
  12342. resolution);
  12343. if (k === null) {
  12344. continue;
  12345. }
  12346. for (; l < layersCount;) {
  12347. var packet = createPacket(resolution, k, l);
  12348. l++;
  12349. return packet;
  12350. }
  12351. l = 0;
  12352. }
  12353. r = 0;
  12354. }
  12355. c = 0;
  12356. }
  12357. px = 0;
  12358. }
  12359. error('JPX Error: Out of packets');
  12360. };
  12361. }
  12362. function ComponentPositionResolutionLayerIterator(context) {
  12363. var siz = context.SIZ;
  12364. var tileIndex = context.currentTile.index;
  12365. var tile = context.tiles[tileIndex];
  12366. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12367. var componentsCount = siz.Csiz;
  12368. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12369. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12370. this.nextPacket = function JpxImage_nextPacket() {
  12371. // Section B.12.1.5 Component-position-resolution-layer
  12372. for (; c < componentsCount; ++c) {
  12373. var component = tile.components[c];
  12374. var precinctsIterationSizes = precinctsSizes.components[c];
  12375. var decompositionLevelsCount =
  12376. component.codingStyleParameters.decompositionLevelsCount;
  12377. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12378. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12379. for (; r <= decompositionLevelsCount; r++) {
  12380. var resolution = component.resolutions[r];
  12381. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12382. var k = getPrecinctIndexIfExist(
  12383. px,
  12384. py,
  12385. sizeInImageScale,
  12386. precinctsIterationSizes,
  12387. resolution);
  12388. if (k === null) {
  12389. continue;
  12390. }
  12391. for (; l < layersCount;) {
  12392. var packet = createPacket(resolution, k, l);
  12393. l++;
  12394. return packet;
  12395. }
  12396. l = 0;
  12397. }
  12398. r = 0;
  12399. }
  12400. px = 0;
  12401. }
  12402. py = 0;
  12403. }
  12404. error('JPX Error: Out of packets');
  12405. };
  12406. }
  12407. function getPrecinctIndexIfExist(
  12408. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12409. var posX = pxIndex * precinctIterationSizes.minWidth;
  12410. var posY = pyIndex * precinctIterationSizes.minHeight;
  12411. if (posX % sizeInImageScale.width !== 0 ||
  12412. posY % sizeInImageScale.height !== 0) {
  12413. return null;
  12414. }
  12415. var startPrecinctRowIndex =
  12416. (posY / sizeInImageScale.width) *
  12417. resolution.precinctParameters.numprecinctswide;
  12418. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12419. }
  12420. function getPrecinctSizesInImageScale(tile) {
  12421. var componentsCount = tile.components.length;
  12422. var minWidth = Number.MAX_VALUE;
  12423. var minHeight = Number.MAX_VALUE;
  12424. var maxNumWide = 0;
  12425. var maxNumHigh = 0;
  12426. var sizePerComponent = new Array(componentsCount);
  12427. for (var c = 0; c < componentsCount; c++) {
  12428. var component = tile.components[c];
  12429. var decompositionLevelsCount =
  12430. component.codingStyleParameters.decompositionLevelsCount;
  12431. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12432. var minWidthCurrentComponent = Number.MAX_VALUE;
  12433. var minHeightCurrentComponent = Number.MAX_VALUE;
  12434. var maxNumWideCurrentComponent = 0;
  12435. var maxNumHighCurrentComponent = 0;
  12436. var scale = 1;
  12437. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12438. var resolution = component.resolutions[r];
  12439. var widthCurrentResolution =
  12440. scale * resolution.precinctParameters.precinctWidth;
  12441. var heightCurrentResolution =
  12442. scale * resolution.precinctParameters.precinctHeight;
  12443. minWidthCurrentComponent = Math.min(
  12444. minWidthCurrentComponent,
  12445. widthCurrentResolution);
  12446. minHeightCurrentComponent = Math.min(
  12447. minHeightCurrentComponent,
  12448. heightCurrentResolution);
  12449. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12450. resolution.precinctParameters.numprecinctswide);
  12451. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12452. resolution.precinctParameters.numprecinctshigh);
  12453. sizePerResolution[r] = {
  12454. width: widthCurrentResolution,
  12455. height: heightCurrentResolution
  12456. };
  12457. scale <<= 1;
  12458. }
  12459. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12460. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12461. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12462. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12463. sizePerComponent[c] = {
  12464. resolutions: sizePerResolution,
  12465. minWidth: minWidthCurrentComponent,
  12466. minHeight: minHeightCurrentComponent,
  12467. maxNumWide: maxNumWideCurrentComponent,
  12468. maxNumHigh: maxNumHighCurrentComponent
  12469. };
  12470. }
  12471. return {
  12472. components: sizePerComponent,
  12473. minWidth: minWidth,
  12474. minHeight: minHeight,
  12475. maxNumWide: maxNumWide,
  12476. maxNumHigh: maxNumHigh
  12477. };
  12478. }
  12479. function buildPackets(context) {
  12480. var siz = context.SIZ;
  12481. var tileIndex = context.currentTile.index;
  12482. var tile = context.tiles[tileIndex];
  12483. var componentsCount = siz.Csiz;
  12484. // Creating resolutions and sub-bands for each component
  12485. for (var c = 0; c < componentsCount; c++) {
  12486. var component = tile.components[c];
  12487. var decompositionLevelsCount =
  12488. component.codingStyleParameters.decompositionLevelsCount;
  12489. // Section B.5 Resolution levels and sub-bands
  12490. var resolutions = [];
  12491. var subbands = [];
  12492. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12493. var blocksDimensions = getBlocksDimensions(context, component, r);
  12494. var resolution = {};
  12495. var scale = 1 << (decompositionLevelsCount - r);
  12496. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12497. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12498. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12499. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12500. resolution.resLevel = r;
  12501. buildPrecincts(context, resolution, blocksDimensions);
  12502. resolutions.push(resolution);
  12503. var subband;
  12504. if (r === 0) {
  12505. // one sub-band (LL) with last decomposition
  12506. subband = {};
  12507. subband.type = 'LL';
  12508. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12509. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12510. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12511. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12512. subband.resolution = resolution;
  12513. buildCodeblocks(context, subband, blocksDimensions);
  12514. subbands.push(subband);
  12515. resolution.subbands = [subband];
  12516. } else {
  12517. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12518. var resolutionSubbands = [];
  12519. // three sub-bands (HL, LH and HH) with rest of decompositions
  12520. subband = {};
  12521. subband.type = 'HL';
  12522. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12523. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12524. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12525. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12526. subband.resolution = resolution;
  12527. buildCodeblocks(context, subband, blocksDimensions);
  12528. subbands.push(subband);
  12529. resolutionSubbands.push(subband);
  12530. subband = {};
  12531. subband.type = 'LH';
  12532. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12533. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12534. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12535. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12536. subband.resolution = resolution;
  12537. buildCodeblocks(context, subband, blocksDimensions);
  12538. subbands.push(subband);
  12539. resolutionSubbands.push(subband);
  12540. subband = {};
  12541. subband.type = 'HH';
  12542. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12543. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12544. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12545. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12546. subband.resolution = resolution;
  12547. buildCodeblocks(context, subband, blocksDimensions);
  12548. subbands.push(subband);
  12549. resolutionSubbands.push(subband);
  12550. resolution.subbands = resolutionSubbands;
  12551. }
  12552. }
  12553. component.resolutions = resolutions;
  12554. component.subbands = subbands;
  12555. }
  12556. // Generate the packets sequence
  12557. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12558. switch (progressionOrder) {
  12559. case 0:
  12560. tile.packetsIterator =
  12561. new LayerResolutionComponentPositionIterator(context);
  12562. break;
  12563. case 1:
  12564. tile.packetsIterator =
  12565. new ResolutionLayerComponentPositionIterator(context);
  12566. break;
  12567. case 2:
  12568. tile.packetsIterator =
  12569. new ResolutionPositionComponentLayerIterator(context);
  12570. break;
  12571. case 3:
  12572. tile.packetsIterator =
  12573. new PositionComponentResolutionLayerIterator(context);
  12574. break;
  12575. case 4:
  12576. tile.packetsIterator =
  12577. new ComponentPositionResolutionLayerIterator(context);
  12578. break;
  12579. default:
  12580. error('JPX Error: Unsupported progression order ' + progressionOrder);
  12581. }
  12582. }
  12583. function parseTilePackets(context, data, offset, dataLength) {
  12584. var position = 0;
  12585. var buffer, bufferSize = 0, skipNextBit = false;
  12586. function readBits(count) {
  12587. while (bufferSize < count) {
  12588. var b = data[offset + position];
  12589. position++;
  12590. if (skipNextBit) {
  12591. buffer = (buffer << 7) | b;
  12592. bufferSize += 7;
  12593. skipNextBit = false;
  12594. } else {
  12595. buffer = (buffer << 8) | b;
  12596. bufferSize += 8;
  12597. }
  12598. if (b === 0xFF) {
  12599. skipNextBit = true;
  12600. }
  12601. }
  12602. bufferSize -= count;
  12603. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12604. }
  12605. function skipMarkerIfEqual(value) {
  12606. if (data[offset + position - 1] === 0xFF &&
  12607. data[offset + position] === value) {
  12608. skipBytes(1);
  12609. return true;
  12610. } else if (data[offset + position] === 0xFF &&
  12611. data[offset + position + 1] === value) {
  12612. skipBytes(2);
  12613. return true;
  12614. }
  12615. return false;
  12616. }
  12617. function skipBytes(count) {
  12618. position += count;
  12619. }
  12620. function alignToByte() {
  12621. bufferSize = 0;
  12622. if (skipNextBit) {
  12623. position++;
  12624. skipNextBit = false;
  12625. }
  12626. }
  12627. function readCodingpasses() {
  12628. if (readBits(1) === 0) {
  12629. return 1;
  12630. }
  12631. if (readBits(1) === 0) {
  12632. return 2;
  12633. }
  12634. var value = readBits(2);
  12635. if (value < 3) {
  12636. return value + 3;
  12637. }
  12638. value = readBits(5);
  12639. if (value < 31) {
  12640. return value + 6;
  12641. }
  12642. value = readBits(7);
  12643. return value + 37;
  12644. }
  12645. var tileIndex = context.currentTile.index;
  12646. var tile = context.tiles[tileIndex];
  12647. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12648. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12649. var packetsIterator = tile.packetsIterator;
  12650. while (position < dataLength) {
  12651. alignToByte();
  12652. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12653. // Skip also marker segment length and packet sequence ID
  12654. skipBytes(4);
  12655. }
  12656. var packet = packetsIterator.nextPacket();
  12657. if (!readBits(1)) {
  12658. continue;
  12659. }
  12660. var layerNumber = packet.layerNumber;
  12661. var queue = [], codeblock;
  12662. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12663. codeblock = packet.codeblocks[i];
  12664. var precinct = codeblock.precinct;
  12665. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12666. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12667. var codeblockIncluded = false;
  12668. var firstTimeInclusion = false;
  12669. var valueReady;
  12670. if (codeblock['included'] !== undefined) {
  12671. codeblockIncluded = !!readBits(1);
  12672. } else {
  12673. // reading inclusion tree
  12674. precinct = codeblock.precinct;
  12675. var inclusionTree, zeroBitPlanesTree;
  12676. if (precinct['inclusionTree'] !== undefined) {
  12677. inclusionTree = precinct.inclusionTree;
  12678. } else {
  12679. // building inclusion and zero bit-planes trees
  12680. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12681. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12682. inclusionTree = new InclusionTree(width, height, layerNumber);
  12683. zeroBitPlanesTree = new TagTree(width, height);
  12684. precinct.inclusionTree = inclusionTree;
  12685. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12686. }
  12687. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12688. while (true) {
  12689. if (readBits(1)) {
  12690. valueReady = !inclusionTree.nextLevel();
  12691. if (valueReady) {
  12692. codeblock.included = true;
  12693. codeblockIncluded = firstTimeInclusion = true;
  12694. break;
  12695. }
  12696. } else {
  12697. inclusionTree.incrementValue(layerNumber);
  12698. break;
  12699. }
  12700. }
  12701. }
  12702. }
  12703. if (!codeblockIncluded) {
  12704. continue;
  12705. }
  12706. if (firstTimeInclusion) {
  12707. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12708. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12709. while (true) {
  12710. if (readBits(1)) {
  12711. valueReady = !zeroBitPlanesTree.nextLevel();
  12712. if (valueReady) {
  12713. break;
  12714. }
  12715. } else {
  12716. zeroBitPlanesTree.incrementValue();
  12717. }
  12718. }
  12719. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12720. }
  12721. var codingpasses = readCodingpasses();
  12722. while (readBits(1)) {
  12723. codeblock.Lblock++;
  12724. }
  12725. var codingpassesLog2 = log2(codingpasses);
  12726. // rounding down log2
  12727. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12728. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12729. var codedDataLength = readBits(bits);
  12730. queue.push({
  12731. codeblock: codeblock,
  12732. codingpasses: codingpasses,
  12733. dataLength: codedDataLength
  12734. });
  12735. }
  12736. alignToByte();
  12737. if (ephMarkerUsed) {
  12738. skipMarkerIfEqual(0x92);
  12739. }
  12740. while (queue.length > 0) {
  12741. var packetItem = queue.shift();
  12742. codeblock = packetItem.codeblock;
  12743. if (codeblock['data'] === undefined) {
  12744. codeblock.data = [];
  12745. }
  12746. codeblock.data.push({
  12747. data: data,
  12748. start: offset + position,
  12749. end: offset + position + packetItem.dataLength,
  12750. codingpasses: packetItem.codingpasses
  12751. });
  12752. position += packetItem.dataLength;
  12753. }
  12754. }
  12755. return position;
  12756. }
  12757. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12758. delta, mb, reversible, segmentationSymbolUsed) {
  12759. var x0 = subband.tbx0;
  12760. var y0 = subband.tby0;
  12761. var width = subband.tbx1 - subband.tbx0;
  12762. var codeblocks = subband.codeblocks;
  12763. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12764. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12765. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12766. var codeblock = codeblocks[i];
  12767. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12768. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12769. if (blockWidth === 0 || blockHeight === 0) {
  12770. continue;
  12771. }
  12772. if (codeblock['data'] === undefined) {
  12773. continue;
  12774. }
  12775. var bitModel, currentCodingpassType;
  12776. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12777. codeblock.zeroBitPlanes, mb);
  12778. currentCodingpassType = 2; // first bit plane starts from cleanup
  12779. // collect data
  12780. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12781. var j, jj, dataItem;
  12782. for (j = 0, jj = data.length; j < jj; j++) {
  12783. dataItem = data[j];
  12784. totalLength += dataItem.end - dataItem.start;
  12785. codingpasses += dataItem.codingpasses;
  12786. }
  12787. var encodedData = new Uint8Array(totalLength);
  12788. var position = 0;
  12789. for (j = 0, jj = data.length; j < jj; j++) {
  12790. dataItem = data[j];
  12791. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12792. encodedData.set(chunk, position);
  12793. position += chunk.length;
  12794. }
  12795. // decoding the item
  12796. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12797. bitModel.setDecoder(decoder);
  12798. for (j = 0; j < codingpasses; j++) {
  12799. switch (currentCodingpassType) {
  12800. case 0:
  12801. bitModel.runSignificancePropagationPass();
  12802. break;
  12803. case 1:
  12804. bitModel.runMagnitudeRefinementPass();
  12805. break;
  12806. case 2:
  12807. bitModel.runCleanupPass();
  12808. if (segmentationSymbolUsed) {
  12809. bitModel.checkSegmentationSymbol();
  12810. }
  12811. break;
  12812. }
  12813. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12814. }
  12815. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12816. var sign = bitModel.coefficentsSign;
  12817. var magnitude = bitModel.coefficentsMagnitude;
  12818. var bitsDecoded = bitModel.bitsDecoded;
  12819. var magnitudeCorrection = reversible ? 0 : 0.5;
  12820. var k, n, nb;
  12821. position = 0;
  12822. // Do the interleaving of Section F.3.3 here, so we do not need
  12823. // to copy later. LL level is not interleaved, just copied.
  12824. var interleave = (subband.type !== 'LL');
  12825. for (j = 0; j < blockHeight; j++) {
  12826. var row = (offset / width) | 0; // row in the non-interleaved subband
  12827. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12828. for (k = 0; k < blockWidth; k++) {
  12829. n = magnitude[position];
  12830. if (n !== 0) {
  12831. n = (n + magnitudeCorrection) * delta;
  12832. if (sign[position] !== 0) {
  12833. n = -n;
  12834. }
  12835. nb = bitsDecoded[position];
  12836. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12837. if (reversible && (nb >= mb)) {
  12838. coefficients[pos] = n;
  12839. } else {
  12840. coefficients[pos] = n * (1 << (mb - nb));
  12841. }
  12842. }
  12843. offset++;
  12844. position++;
  12845. }
  12846. offset += width - blockWidth;
  12847. }
  12848. }
  12849. }
  12850. function transformTile(context, tile, c) {
  12851. var component = tile.components[c];
  12852. var codingStyleParameters = component.codingStyleParameters;
  12853. var quantizationParameters = component.quantizationParameters;
  12854. var decompositionLevelsCount =
  12855. codingStyleParameters.decompositionLevelsCount;
  12856. var spqcds = quantizationParameters.SPqcds;
  12857. var scalarExpounded = quantizationParameters.scalarExpounded;
  12858. var guardBits = quantizationParameters.guardBits;
  12859. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12860. var precision = context.components[c].precision;
  12861. var reversible = codingStyleParameters.reversibleTransformation;
  12862. var transform = (reversible ? new ReversibleTransform() :
  12863. new IrreversibleTransform());
  12864. var subbandCoefficients = [];
  12865. var b = 0;
  12866. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12867. var resolution = component.resolutions[i];
  12868. var width = resolution.trx1 - resolution.trx0;
  12869. var height = resolution.try1 - resolution.try0;
  12870. // Allocate space for the whole sublevel.
  12871. var coefficients = new Float32Array(width * height);
  12872. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12873. var mu, epsilon;
  12874. if (!scalarExpounded) {
  12875. // formula E-5
  12876. mu = spqcds[0].mu;
  12877. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12878. } else {
  12879. mu = spqcds[b].mu;
  12880. epsilon = spqcds[b].epsilon;
  12881. b++;
  12882. }
  12883. var subband = resolution.subbands[j];
  12884. var gainLog2 = SubbandsGainLog2[subband.type];
  12885. // calculate quantization coefficient (Section E.1.1.1)
  12886. var delta = (reversible ? 1 :
  12887. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  12888. var mb = (guardBits + epsilon - 1);
  12889. // In the first resolution level, copyCoefficients will fill the
  12890. // whole array with coefficients. In the succeeding passes,
  12891. // copyCoefficients will consecutively fill in the values that belong
  12892. // to the interleaved positions of the HL, LH, and HH coefficients.
  12893. // The LL coefficients will then be interleaved in Transform.iterate().
  12894. copyCoefficients(coefficients, width, height, subband, delta, mb,
  12895. reversible, segmentationSymbolUsed);
  12896. }
  12897. subbandCoefficients.push({
  12898. width: width,
  12899. height: height,
  12900. items: coefficients
  12901. });
  12902. }
  12903. var result = transform.calculate(subbandCoefficients,
  12904. component.tcx0, component.tcy0);
  12905. return {
  12906. left: component.tcx0,
  12907. top: component.tcy0,
  12908. width: result.width,
  12909. height: result.height,
  12910. items: result.items
  12911. };
  12912. }
  12913. function transformComponents(context) {
  12914. var siz = context.SIZ;
  12915. var components = context.components;
  12916. var componentsCount = siz.Csiz;
  12917. var resultImages = [];
  12918. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  12919. var tile = context.tiles[i];
  12920. var transformedTiles = [];
  12921. var c;
  12922. for (c = 0; c < componentsCount; c++) {
  12923. transformedTiles[c] = transformTile(context, tile, c);
  12924. }
  12925. var tile0 = transformedTiles[0];
  12926. var out = new Uint8Array(tile0.items.length * componentsCount);
  12927. var result = {
  12928. left: tile0.left,
  12929. top: tile0.top,
  12930. width: tile0.width,
  12931. height: tile0.height,
  12932. items: out
  12933. };
  12934. // Section G.2.2 Inverse multi component transform
  12935. var shift, offset, max, min, maxK;
  12936. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  12937. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  12938. var fourComponents = componentsCount === 4;
  12939. var y0items = transformedTiles[0].items;
  12940. var y1items = transformedTiles[1].items;
  12941. var y2items = transformedTiles[2].items;
  12942. var y3items = fourComponents ? transformedTiles[3].items : null;
  12943. // HACK: The multiple component transform formulas below assume that
  12944. // all components have the same precision. With this in mind, we
  12945. // compute shift and offset only once.
  12946. shift = components[0].precision - 8;
  12947. offset = (128 << shift) + 0.5;
  12948. max = 255 * (1 << shift);
  12949. maxK = max * 0.5;
  12950. min = -maxK;
  12951. var component0 = tile.components[0];
  12952. var alpha01 = componentsCount - 3;
  12953. jj = y0items.length;
  12954. if (!component0.codingStyleParameters.reversibleTransformation) {
  12955. // inverse irreversible multiple component transform
  12956. for (j = 0; j < jj; j++, pos += alpha01) {
  12957. y0 = y0items[j] + offset;
  12958. y1 = y1items[j];
  12959. y2 = y2items[j];
  12960. r = y0 + 1.402 * y2;
  12961. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  12962. b = y0 + 1.772 * y1;
  12963. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12964. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12965. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12966. }
  12967. } else {
  12968. // inverse reversible multiple component transform
  12969. for (j = 0; j < jj; j++, pos += alpha01) {
  12970. y0 = y0items[j] + offset;
  12971. y1 = y1items[j];
  12972. y2 = y2items[j];
  12973. g = y0 - ((y2 + y1) >> 2);
  12974. r = g + y2;
  12975. b = g + y1;
  12976. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12977. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12978. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12979. }
  12980. }
  12981. if (fourComponents) {
  12982. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  12983. k = y3items[j];
  12984. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  12985. }
  12986. }
  12987. } else { // no multi-component transform
  12988. for (c = 0; c < componentsCount; c++) {
  12989. var items = transformedTiles[c].items;
  12990. shift = components[c].precision - 8;
  12991. offset = (128 << shift) + 0.5;
  12992. max = (127.5 * (1 << shift));
  12993. min = -max;
  12994. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  12995. val = items[j];
  12996. out[pos] = val <= min ? 0 :
  12997. val >= max ? 255 : (val + offset) >> shift;
  12998. pos += componentsCount;
  12999. }
  13000. }
  13001. }
  13002. resultImages.push(result);
  13003. }
  13004. return resultImages;
  13005. }
  13006. function initializeTile(context, tileIndex) {
  13007. var siz = context.SIZ;
  13008. var componentsCount = siz.Csiz;
  13009. var tile = context.tiles[tileIndex];
  13010. for (var c = 0; c < componentsCount; c++) {
  13011. var component = tile.components[c];
  13012. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13013. context.currentTile.QCC[c] : context.currentTile.QCD);
  13014. component.quantizationParameters = qcdOrQcc;
  13015. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13016. context.currentTile.COC[c] : context.currentTile.COD);
  13017. component.codingStyleParameters = codOrCoc;
  13018. }
  13019. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13020. }
  13021. // Section B.10.2 Tag trees
  13022. var TagTree = (function TagTreeClosure() {
  13023. function TagTree(width, height) {
  13024. var levelsLength = log2(Math.max(width, height)) + 1;
  13025. this.levels = [];
  13026. for (var i = 0; i < levelsLength; i++) {
  13027. var level = {
  13028. width: width,
  13029. height: height,
  13030. items: []
  13031. };
  13032. this.levels.push(level);
  13033. width = Math.ceil(width / 2);
  13034. height = Math.ceil(height / 2);
  13035. }
  13036. }
  13037. TagTree.prototype = {
  13038. reset: function TagTree_reset(i, j) {
  13039. var currentLevel = 0, value = 0, level;
  13040. while (currentLevel < this.levels.length) {
  13041. level = this.levels[currentLevel];
  13042. var index = i + j * level.width;
  13043. if (level.items[index] !== undefined) {
  13044. value = level.items[index];
  13045. break;
  13046. }
  13047. level.index = index;
  13048. i >>= 1;
  13049. j >>= 1;
  13050. currentLevel++;
  13051. }
  13052. currentLevel--;
  13053. level = this.levels[currentLevel];
  13054. level.items[level.index] = value;
  13055. this.currentLevel = currentLevel;
  13056. delete this.value;
  13057. },
  13058. incrementValue: function TagTree_incrementValue() {
  13059. var level = this.levels[this.currentLevel];
  13060. level.items[level.index]++;
  13061. },
  13062. nextLevel: function TagTree_nextLevel() {
  13063. var currentLevel = this.currentLevel;
  13064. var level = this.levels[currentLevel];
  13065. var value = level.items[level.index];
  13066. currentLevel--;
  13067. if (currentLevel < 0) {
  13068. this.value = value;
  13069. return false;
  13070. }
  13071. this.currentLevel = currentLevel;
  13072. level = this.levels[currentLevel];
  13073. level.items[level.index] = value;
  13074. return true;
  13075. }
  13076. };
  13077. return TagTree;
  13078. })();
  13079. var InclusionTree = (function InclusionTreeClosure() {
  13080. function InclusionTree(width, height, defaultValue) {
  13081. var levelsLength = log2(Math.max(width, height)) + 1;
  13082. this.levels = [];
  13083. for (var i = 0; i < levelsLength; i++) {
  13084. var items = new Uint8Array(width * height);
  13085. for (var j = 0, jj = items.length; j < jj; j++) {
  13086. items[j] = defaultValue;
  13087. }
  13088. var level = {
  13089. width: width,
  13090. height: height,
  13091. items: items
  13092. };
  13093. this.levels.push(level);
  13094. width = Math.ceil(width / 2);
  13095. height = Math.ceil(height / 2);
  13096. }
  13097. }
  13098. InclusionTree.prototype = {
  13099. reset: function InclusionTree_reset(i, j, stopValue) {
  13100. var currentLevel = 0;
  13101. while (currentLevel < this.levels.length) {
  13102. var level = this.levels[currentLevel];
  13103. var index = i + j * level.width;
  13104. level.index = index;
  13105. var value = level.items[index];
  13106. if (value === 0xFF) {
  13107. break;
  13108. }
  13109. if (value > stopValue) {
  13110. this.currentLevel = currentLevel;
  13111. // already know about this one, propagating the value to top levels
  13112. this.propagateValues();
  13113. return false;
  13114. }
  13115. i >>= 1;
  13116. j >>= 1;
  13117. currentLevel++;
  13118. }
  13119. this.currentLevel = currentLevel - 1;
  13120. return true;
  13121. },
  13122. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13123. var level = this.levels[this.currentLevel];
  13124. level.items[level.index] = stopValue + 1;
  13125. this.propagateValues();
  13126. },
  13127. propagateValues: function InclusionTree_propagateValues() {
  13128. var levelIndex = this.currentLevel;
  13129. var level = this.levels[levelIndex];
  13130. var currentValue = level.items[level.index];
  13131. while (--levelIndex >= 0) {
  13132. level = this.levels[levelIndex];
  13133. level.items[level.index] = currentValue;
  13134. }
  13135. },
  13136. nextLevel: function InclusionTree_nextLevel() {
  13137. var currentLevel = this.currentLevel;
  13138. var level = this.levels[currentLevel];
  13139. var value = level.items[level.index];
  13140. level.items[level.index] = 0xFF;
  13141. currentLevel--;
  13142. if (currentLevel < 0) {
  13143. return false;
  13144. }
  13145. this.currentLevel = currentLevel;
  13146. level = this.levels[currentLevel];
  13147. level.items[level.index] = value;
  13148. return true;
  13149. }
  13150. };
  13151. return InclusionTree;
  13152. })();
  13153. // Section D. Coefficient bit modeling
  13154. var BitModel = (function BitModelClosure() {
  13155. var UNIFORM_CONTEXT = 17;
  13156. var RUNLENGTH_CONTEXT = 18;
  13157. // Table D-1
  13158. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13159. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13160. var LLAndLHContextsLabel = new Uint8Array([
  13161. 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,
  13162. 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,
  13163. 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
  13164. ]);
  13165. var HLContextLabel = new Uint8Array([
  13166. 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,
  13167. 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,
  13168. 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
  13169. ]);
  13170. var HHContextLabel = new Uint8Array([
  13171. 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,
  13172. 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,
  13173. 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
  13174. ]);
  13175. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13176. this.width = width;
  13177. this.height = height;
  13178. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13179. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13180. var coefficientCount = width * height;
  13181. // coefficients outside the encoding region treated as insignificant
  13182. // add border state cells for significanceState
  13183. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13184. this.coefficentsSign = new Uint8Array(coefficientCount);
  13185. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13186. mb > 6 ? new Uint16Array(coefficientCount) :
  13187. new Uint8Array(coefficientCount);
  13188. this.processingFlags = new Uint8Array(coefficientCount);
  13189. var bitsDecoded = new Uint8Array(coefficientCount);
  13190. if (zeroBitPlanes !== 0) {
  13191. for (var i = 0; i < coefficientCount; i++) {
  13192. bitsDecoded[i] = zeroBitPlanes;
  13193. }
  13194. }
  13195. this.bitsDecoded = bitsDecoded;
  13196. this.reset();
  13197. }
  13198. BitModel.prototype = {
  13199. setDecoder: function BitModel_setDecoder(decoder) {
  13200. this.decoder = decoder;
  13201. },
  13202. reset: function BitModel_reset() {
  13203. // We have 17 contexts that are accessed via context labels,
  13204. // plus the uniform and runlength context.
  13205. this.contexts = new Int8Array(19);
  13206. // Contexts are packed into 1 byte:
  13207. // highest 7 bits carry the index, lowest bit carries mps
  13208. this.contexts[0] = (4 << 1) | 0;
  13209. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13210. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13211. },
  13212. setNeighborsSignificance:
  13213. function BitModel_setNeighborsSignificance(row, column, index) {
  13214. var neighborsSignificance = this.neighborsSignificance;
  13215. var width = this.width, height = this.height;
  13216. var left = (column > 0);
  13217. var right = (column + 1 < width);
  13218. var i;
  13219. if (row > 0) {
  13220. i = index - width;
  13221. if (left) {
  13222. neighborsSignificance[i - 1] += 0x10;
  13223. }
  13224. if (right) {
  13225. neighborsSignificance[i + 1] += 0x10;
  13226. }
  13227. neighborsSignificance[i] += 0x04;
  13228. }
  13229. if (row + 1 < height) {
  13230. i = index + width;
  13231. if (left) {
  13232. neighborsSignificance[i - 1] += 0x10;
  13233. }
  13234. if (right) {
  13235. neighborsSignificance[i + 1] += 0x10;
  13236. }
  13237. neighborsSignificance[i] += 0x04;
  13238. }
  13239. if (left) {
  13240. neighborsSignificance[index - 1] += 0x01;
  13241. }
  13242. if (right) {
  13243. neighborsSignificance[index + 1] += 0x01;
  13244. }
  13245. neighborsSignificance[index] |= 0x80;
  13246. },
  13247. runSignificancePropagationPass:
  13248. function BitModel_runSignificancePropagationPass() {
  13249. var decoder = this.decoder;
  13250. var width = this.width, height = this.height;
  13251. var coefficentsMagnitude = this.coefficentsMagnitude;
  13252. var coefficentsSign = this.coefficentsSign;
  13253. var neighborsSignificance = this.neighborsSignificance;
  13254. var processingFlags = this.processingFlags;
  13255. var contexts = this.contexts;
  13256. var labels = this.contextLabelTable;
  13257. var bitsDecoded = this.bitsDecoded;
  13258. var processedInverseMask = ~1;
  13259. var processedMask = 1;
  13260. var firstMagnitudeBitMask = 2;
  13261. for (var i0 = 0; i0 < height; i0 += 4) {
  13262. for (var j = 0; j < width; j++) {
  13263. var index = i0 * width + j;
  13264. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13265. var i = i0 + i1;
  13266. if (i >= height) {
  13267. break;
  13268. }
  13269. // clear processed flag first
  13270. processingFlags[index] &= processedInverseMask;
  13271. if (coefficentsMagnitude[index] ||
  13272. !neighborsSignificance[index]) {
  13273. continue;
  13274. }
  13275. var contextLabel = labels[neighborsSignificance[index]];
  13276. var decision = decoder.readBit(contexts, contextLabel);
  13277. if (decision) {
  13278. var sign = this.decodeSignBit(i, j, index);
  13279. coefficentsSign[index] = sign;
  13280. coefficentsMagnitude[index] = 1;
  13281. this.setNeighborsSignificance(i, j, index);
  13282. processingFlags[index] |= firstMagnitudeBitMask;
  13283. }
  13284. bitsDecoded[index]++;
  13285. processingFlags[index] |= processedMask;
  13286. }
  13287. }
  13288. }
  13289. },
  13290. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13291. var width = this.width, height = this.height;
  13292. var coefficentsMagnitude = this.coefficentsMagnitude;
  13293. var coefficentsSign = this.coefficentsSign;
  13294. var contribution, sign0, sign1, significance1;
  13295. var contextLabel, decoded;
  13296. // calculate horizontal contribution
  13297. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13298. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13299. sign1 = coefficentsSign[index + 1];
  13300. if (significance1) {
  13301. sign0 = coefficentsSign[index - 1];
  13302. contribution = 1 - sign1 - sign0;
  13303. } else {
  13304. contribution = 1 - sign1 - sign1;
  13305. }
  13306. } else if (significance1) {
  13307. sign0 = coefficentsSign[index - 1];
  13308. contribution = 1 - sign0 - sign0;
  13309. } else {
  13310. contribution = 0;
  13311. }
  13312. var horizontalContribution = 3 * contribution;
  13313. // calculate vertical contribution and combine with the horizontal
  13314. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13315. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13316. sign1 = coefficentsSign[index + width];
  13317. if (significance1) {
  13318. sign0 = coefficentsSign[index - width];
  13319. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13320. } else {
  13321. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13322. }
  13323. } else if (significance1) {
  13324. sign0 = coefficentsSign[index - width];
  13325. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13326. } else {
  13327. contribution = horizontalContribution;
  13328. }
  13329. if (contribution >= 0) {
  13330. contextLabel = 9 + contribution;
  13331. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13332. } else {
  13333. contextLabel = 9 - contribution;
  13334. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13335. }
  13336. return decoded;
  13337. },
  13338. runMagnitudeRefinementPass:
  13339. function BitModel_runMagnitudeRefinementPass() {
  13340. var decoder = this.decoder;
  13341. var width = this.width, height = this.height;
  13342. var coefficentsMagnitude = this.coefficentsMagnitude;
  13343. var neighborsSignificance = this.neighborsSignificance;
  13344. var contexts = this.contexts;
  13345. var bitsDecoded = this.bitsDecoded;
  13346. var processingFlags = this.processingFlags;
  13347. var processedMask = 1;
  13348. var firstMagnitudeBitMask = 2;
  13349. var length = width * height;
  13350. var width4 = width * 4;
  13351. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13352. indexNext = Math.min(length, index0 + width4);
  13353. for (var j = 0; j < width; j++) {
  13354. for (var index = index0 + j; index < indexNext; index += width) {
  13355. // significant but not those that have just become
  13356. if (!coefficentsMagnitude[index] ||
  13357. (processingFlags[index] & processedMask) !== 0) {
  13358. continue;
  13359. }
  13360. var contextLabel = 16;
  13361. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13362. processingFlags[index] ^= firstMagnitudeBitMask;
  13363. // first refinement
  13364. var significance = neighborsSignificance[index] & 127;
  13365. contextLabel = significance === 0 ? 15 : 14;
  13366. }
  13367. var bit = decoder.readBit(contexts, contextLabel);
  13368. coefficentsMagnitude[index] =
  13369. (coefficentsMagnitude[index] << 1) | bit;
  13370. bitsDecoded[index]++;
  13371. processingFlags[index] |= processedMask;
  13372. }
  13373. }
  13374. }
  13375. },
  13376. runCleanupPass: function BitModel_runCleanupPass() {
  13377. var decoder = this.decoder;
  13378. var width = this.width, height = this.height;
  13379. var neighborsSignificance = this.neighborsSignificance;
  13380. var coefficentsMagnitude = this.coefficentsMagnitude;
  13381. var coefficentsSign = this.coefficentsSign;
  13382. var contexts = this.contexts;
  13383. var labels = this.contextLabelTable;
  13384. var bitsDecoded = this.bitsDecoded;
  13385. var processingFlags = this.processingFlags;
  13386. var processedMask = 1;
  13387. var firstMagnitudeBitMask = 2;
  13388. var oneRowDown = width;
  13389. var twoRowsDown = width * 2;
  13390. var threeRowsDown = width * 3;
  13391. var iNext;
  13392. for (var i0 = 0; i0 < height; i0 = iNext) {
  13393. iNext = Math.min(i0 + 4, height);
  13394. var indexBase = i0 * width;
  13395. var checkAllEmpty = i0 + 3 < height;
  13396. for (var j = 0; j < width; j++) {
  13397. var index0 = indexBase + j;
  13398. // using the property: labels[neighborsSignificance[index]] === 0
  13399. // when neighborsSignificance[index] === 0
  13400. var allEmpty = (checkAllEmpty &&
  13401. processingFlags[index0] === 0 &&
  13402. processingFlags[index0 + oneRowDown] === 0 &&
  13403. processingFlags[index0 + twoRowsDown] === 0 &&
  13404. processingFlags[index0 + threeRowsDown] === 0 &&
  13405. neighborsSignificance[index0] === 0 &&
  13406. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13407. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13408. neighborsSignificance[index0 + threeRowsDown] === 0);
  13409. var i1 = 0, index = index0;
  13410. var i = i0, sign;
  13411. if (allEmpty) {
  13412. var hasSignificantCoefficent =
  13413. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13414. if (!hasSignificantCoefficent) {
  13415. bitsDecoded[index0]++;
  13416. bitsDecoded[index0 + oneRowDown]++;
  13417. bitsDecoded[index0 + twoRowsDown]++;
  13418. bitsDecoded[index0 + threeRowsDown]++;
  13419. continue; // next column
  13420. }
  13421. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13422. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13423. if (i1 !== 0) {
  13424. i = i0 + i1;
  13425. index += i1 * width;
  13426. }
  13427. sign = this.decodeSignBit(i, j, index);
  13428. coefficentsSign[index] = sign;
  13429. coefficentsMagnitude[index] = 1;
  13430. this.setNeighborsSignificance(i, j, index);
  13431. processingFlags[index] |= firstMagnitudeBitMask;
  13432. index = index0;
  13433. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13434. bitsDecoded[index]++;
  13435. }
  13436. i1++;
  13437. }
  13438. for (i = i0 + i1; i < iNext; i++, index += width) {
  13439. if (coefficentsMagnitude[index] ||
  13440. (processingFlags[index] & processedMask) !== 0) {
  13441. continue;
  13442. }
  13443. var contextLabel = labels[neighborsSignificance[index]];
  13444. var decision = decoder.readBit(contexts, contextLabel);
  13445. if (decision === 1) {
  13446. sign = this.decodeSignBit(i, j, index);
  13447. coefficentsSign[index] = sign;
  13448. coefficentsMagnitude[index] = 1;
  13449. this.setNeighborsSignificance(i, j, index);
  13450. processingFlags[index] |= firstMagnitudeBitMask;
  13451. }
  13452. bitsDecoded[index]++;
  13453. }
  13454. }
  13455. }
  13456. },
  13457. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13458. var decoder = this.decoder;
  13459. var contexts = this.contexts;
  13460. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13461. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13462. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13463. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13464. if (symbol !== 0xA) {
  13465. error('JPX Error: Invalid segmentation symbol');
  13466. }
  13467. }
  13468. };
  13469. return BitModel;
  13470. })();
  13471. // Section F, Discrete wavelet transformation
  13472. var Transform = (function TransformClosure() {
  13473. function Transform() {}
  13474. Transform.prototype.calculate =
  13475. function transformCalculate(subbands, u0, v0) {
  13476. var ll = subbands[0];
  13477. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13478. ll = this.iterate(ll, subbands[i], u0, v0);
  13479. }
  13480. return ll;
  13481. };
  13482. Transform.prototype.extend = function extend(buffer, offset, size) {
  13483. // Section F.3.7 extending... using max extension of 4
  13484. var i1 = offset - 1, j1 = offset + 1;
  13485. var i2 = offset + size - 2, j2 = offset + size;
  13486. buffer[i1--] = buffer[j1++];
  13487. buffer[j2++] = buffer[i2--];
  13488. buffer[i1--] = buffer[j1++];
  13489. buffer[j2++] = buffer[i2--];
  13490. buffer[i1--] = buffer[j1++];
  13491. buffer[j2++] = buffer[i2--];
  13492. buffer[i1] = buffer[j1];
  13493. buffer[j2] = buffer[i2];
  13494. };
  13495. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13496. u0, v0) {
  13497. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13498. var width = hl_lh_hh.width;
  13499. var height = hl_lh_hh.height;
  13500. var items = hl_lh_hh.items;
  13501. var i, j, k, l, u, v;
  13502. // Interleave LL according to Section F.3.3
  13503. for (k = 0, i = 0; i < llHeight; i++) {
  13504. l = i * 2 * width;
  13505. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13506. items[l] = llItems[k];
  13507. }
  13508. }
  13509. // The LL band is not needed anymore.
  13510. llItems = ll.items = null;
  13511. var bufferPadding = 4;
  13512. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13513. // Section F.3.4 HOR_SR
  13514. if (width === 1) {
  13515. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13516. if ((u0 & 1) !== 0) {
  13517. for (v = 0, k = 0; v < height; v++, k += width) {
  13518. items[k] *= 0.5;
  13519. }
  13520. }
  13521. } else {
  13522. for (v = 0, k = 0; v < height; v++, k += width) {
  13523. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13524. this.extend(rowBuffer, bufferPadding, width);
  13525. this.filter(rowBuffer, bufferPadding, width);
  13526. items.set(
  13527. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13528. k);
  13529. }
  13530. }
  13531. // Accesses to the items array can take long, because it may not fit into
  13532. // CPU cache and has to be fetched from main memory. Since subsequent
  13533. // accesses to the items array are not local when reading columns, we
  13534. // have a cache miss every time. To reduce cache misses, get up to
  13535. // 'numBuffers' items at a time and store them into the individual
  13536. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13537. var numBuffers = 16;
  13538. var colBuffers = [];
  13539. for (i = 0; i < numBuffers; i++) {
  13540. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13541. }
  13542. var b, currentBuffer = 0;
  13543. ll = bufferPadding + height;
  13544. // Section F.3.5 VER_SR
  13545. if (height === 1) {
  13546. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13547. if ((v0 & 1) !== 0) {
  13548. for (u = 0; u < width; u++) {
  13549. items[u] *= 0.5;
  13550. }
  13551. }
  13552. } else {
  13553. for (u = 0; u < width; u++) {
  13554. // if we ran out of buffers, copy several image columns at once
  13555. if (currentBuffer === 0) {
  13556. numBuffers = Math.min(width - u, numBuffers);
  13557. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13558. for (b = 0; b < numBuffers; b++) {
  13559. colBuffers[b][l] = items[k + b];
  13560. }
  13561. }
  13562. currentBuffer = numBuffers;
  13563. }
  13564. currentBuffer--;
  13565. var buffer = colBuffers[currentBuffer];
  13566. this.extend(buffer, bufferPadding, height);
  13567. this.filter(buffer, bufferPadding, height);
  13568. // If this is last buffer in this group of buffers, flush all buffers.
  13569. if (currentBuffer === 0) {
  13570. k = u - numBuffers + 1;
  13571. for (l = bufferPadding; l < ll; k += width, l++) {
  13572. for (b = 0; b < numBuffers; b++) {
  13573. items[k + b] = colBuffers[b][l];
  13574. }
  13575. }
  13576. }
  13577. }
  13578. }
  13579. return {
  13580. width: width,
  13581. height: height,
  13582. items: items
  13583. };
  13584. };
  13585. return Transform;
  13586. })();
  13587. // Section 3.8.2 Irreversible 9-7 filter
  13588. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13589. function IrreversibleTransform() {
  13590. Transform.call(this);
  13591. }
  13592. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13593. IrreversibleTransform.prototype.filter =
  13594. function irreversibleTransformFilter(x, offset, length) {
  13595. var len = length >> 1;
  13596. offset = offset | 0;
  13597. var j, n, current, next;
  13598. var alpha = -1.586134342059924;
  13599. var beta = -0.052980118572961;
  13600. var gamma = 0.882911075530934;
  13601. var delta = 0.443506852043971;
  13602. var K = 1.230174104914001;
  13603. var K_ = 1 / K;
  13604. // step 1 is combined with step 3
  13605. // step 2
  13606. j = offset - 3;
  13607. for (n = len + 4; n--; j += 2) {
  13608. x[j] *= K_;
  13609. }
  13610. // step 1 & 3
  13611. j = offset - 2;
  13612. current = delta * x[j -1];
  13613. for (n = len + 3; n--; j += 2) {
  13614. next = delta * x[j + 1];
  13615. x[j] = K * x[j] - current - next;
  13616. if (n--) {
  13617. j += 2;
  13618. current = delta * x[j + 1];
  13619. x[j] = K * x[j] - current - next;
  13620. } else {
  13621. break;
  13622. }
  13623. }
  13624. // step 4
  13625. j = offset - 1;
  13626. current = gamma * x[j - 1];
  13627. for (n = len + 2; n--; j += 2) {
  13628. next = gamma * x[j + 1];
  13629. x[j] -= current + next;
  13630. if (n--) {
  13631. j += 2;
  13632. current = gamma * x[j + 1];
  13633. x[j] -= current + next;
  13634. } else {
  13635. break;
  13636. }
  13637. }
  13638. // step 5
  13639. j = offset;
  13640. current = beta * x[j - 1];
  13641. for (n = len + 1; n--; j += 2) {
  13642. next = beta * x[j + 1];
  13643. x[j] -= current + next;
  13644. if (n--) {
  13645. j += 2;
  13646. current = beta * x[j + 1];
  13647. x[j] -= current + next;
  13648. } else {
  13649. break;
  13650. }
  13651. }
  13652. // step 6
  13653. if (len !== 0) {
  13654. j = offset + 1;
  13655. current = alpha * x[j - 1];
  13656. for (n = len; n--; j += 2) {
  13657. next = alpha * x[j + 1];
  13658. x[j] -= current + next;
  13659. if (n--) {
  13660. j += 2;
  13661. current = alpha * x[j + 1];
  13662. x[j] -= current + next;
  13663. } else {
  13664. break;
  13665. }
  13666. }
  13667. }
  13668. };
  13669. return IrreversibleTransform;
  13670. })();
  13671. // Section 3.8.1 Reversible 5-3 filter
  13672. var ReversibleTransform = (function ReversibleTransformClosure() {
  13673. function ReversibleTransform() {
  13674. Transform.call(this);
  13675. }
  13676. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13677. ReversibleTransform.prototype.filter =
  13678. function reversibleTransformFilter(x, offset, length) {
  13679. var len = length >> 1;
  13680. offset = offset | 0;
  13681. var j, n;
  13682. for (j = offset, n = len + 1; n--; j += 2) {
  13683. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13684. }
  13685. for (j = offset + 1, n = len; n--; j += 2) {
  13686. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13687. }
  13688. };
  13689. return ReversibleTransform;
  13690. })();
  13691. return JpxImage;
  13692. })();
  13693. exports.JpxImage = JpxImage;
  13694. }));
  13695. (function (root, factory) {
  13696. {
  13697. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13698. }
  13699. }(this, function (exports, sharedUtil) {
  13700. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13701. // The Metrics object contains glyph widths (in glyph space units).
  13702. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13703. // space unit corresponds to 1/1000th of text space unit.
  13704. var getMetrics = getLookupTableFactory(function (t) {
  13705. t['Courier'] = 600;
  13706. t['Courier-Bold'] = 600;
  13707. t['Courier-BoldOblique'] = 600;
  13708. t['Courier-Oblique'] = 600;
  13709. t['Helvetica'] = getLookupTableFactory(function (t) {
  13710. t['space'] = 278;
  13711. t['exclam'] = 278;
  13712. t['quotedbl'] = 355;
  13713. t['numbersign'] = 556;
  13714. t['dollar'] = 556;
  13715. t['percent'] = 889;
  13716. t['ampersand'] = 667;
  13717. t['quoteright'] = 222;
  13718. t['parenleft'] = 333;
  13719. t['parenright'] = 333;
  13720. t['asterisk'] = 389;
  13721. t['plus'] = 584;
  13722. t['comma'] = 278;
  13723. t['hyphen'] = 333;
  13724. t['period'] = 278;
  13725. t['slash'] = 278;
  13726. t['zero'] = 556;
  13727. t['one'] = 556;
  13728. t['two'] = 556;
  13729. t['three'] = 556;
  13730. t['four'] = 556;
  13731. t['five'] = 556;
  13732. t['six'] = 556;
  13733. t['seven'] = 556;
  13734. t['eight'] = 556;
  13735. t['nine'] = 556;
  13736. t['colon'] = 278;
  13737. t['semicolon'] = 278;
  13738. t['less'] = 584;
  13739. t['equal'] = 584;
  13740. t['greater'] = 584;
  13741. t['question'] = 556;
  13742. t['at'] = 1015;
  13743. t['A'] = 667;
  13744. t['B'] = 667;
  13745. t['C'] = 722;
  13746. t['D'] = 722;
  13747. t['E'] = 667;
  13748. t['F'] = 611;
  13749. t['G'] = 778;
  13750. t['H'] = 722;
  13751. t['I'] = 278;
  13752. t['J'] = 500;
  13753. t['K'] = 667;
  13754. t['L'] = 556;
  13755. t['M'] = 833;
  13756. t['N'] = 722;
  13757. t['O'] = 778;
  13758. t['P'] = 667;
  13759. t['Q'] = 778;
  13760. t['R'] = 722;
  13761. t['S'] = 667;
  13762. t['T'] = 611;
  13763. t['U'] = 722;
  13764. t['V'] = 667;
  13765. t['W'] = 944;
  13766. t['X'] = 667;
  13767. t['Y'] = 667;
  13768. t['Z'] = 611;
  13769. t['bracketleft'] = 278;
  13770. t['backslash'] = 278;
  13771. t['bracketright'] = 278;
  13772. t['asciicircum'] = 469;
  13773. t['underscore'] = 556;
  13774. t['quoteleft'] = 222;
  13775. t['a'] = 556;
  13776. t['b'] = 556;
  13777. t['c'] = 500;
  13778. t['d'] = 556;
  13779. t['e'] = 556;
  13780. t['f'] = 278;
  13781. t['g'] = 556;
  13782. t['h'] = 556;
  13783. t['i'] = 222;
  13784. t['j'] = 222;
  13785. t['k'] = 500;
  13786. t['l'] = 222;
  13787. t['m'] = 833;
  13788. t['n'] = 556;
  13789. t['o'] = 556;
  13790. t['p'] = 556;
  13791. t['q'] = 556;
  13792. t['r'] = 333;
  13793. t['s'] = 500;
  13794. t['t'] = 278;
  13795. t['u'] = 556;
  13796. t['v'] = 500;
  13797. t['w'] = 722;
  13798. t['x'] = 500;
  13799. t['y'] = 500;
  13800. t['z'] = 500;
  13801. t['braceleft'] = 334;
  13802. t['bar'] = 260;
  13803. t['braceright'] = 334;
  13804. t['asciitilde'] = 584;
  13805. t['exclamdown'] = 333;
  13806. t['cent'] = 556;
  13807. t['sterling'] = 556;
  13808. t['fraction'] = 167;
  13809. t['yen'] = 556;
  13810. t['florin'] = 556;
  13811. t['section'] = 556;
  13812. t['currency'] = 556;
  13813. t['quotesingle'] = 191;
  13814. t['quotedblleft'] = 333;
  13815. t['guillemotleft'] = 556;
  13816. t['guilsinglleft'] = 333;
  13817. t['guilsinglright'] = 333;
  13818. t['fi'] = 500;
  13819. t['fl'] = 500;
  13820. t['endash'] = 556;
  13821. t['dagger'] = 556;
  13822. t['daggerdbl'] = 556;
  13823. t['periodcentered'] = 278;
  13824. t['paragraph'] = 537;
  13825. t['bullet'] = 350;
  13826. t['quotesinglbase'] = 222;
  13827. t['quotedblbase'] = 333;
  13828. t['quotedblright'] = 333;
  13829. t['guillemotright'] = 556;
  13830. t['ellipsis'] = 1000;
  13831. t['perthousand'] = 1000;
  13832. t['questiondown'] = 611;
  13833. t['grave'] = 333;
  13834. t['acute'] = 333;
  13835. t['circumflex'] = 333;
  13836. t['tilde'] = 333;
  13837. t['macron'] = 333;
  13838. t['breve'] = 333;
  13839. t['dotaccent'] = 333;
  13840. t['dieresis'] = 333;
  13841. t['ring'] = 333;
  13842. t['cedilla'] = 333;
  13843. t['hungarumlaut'] = 333;
  13844. t['ogonek'] = 333;
  13845. t['caron'] = 333;
  13846. t['emdash'] = 1000;
  13847. t['AE'] = 1000;
  13848. t['ordfeminine'] = 370;
  13849. t['Lslash'] = 556;
  13850. t['Oslash'] = 778;
  13851. t['OE'] = 1000;
  13852. t['ordmasculine'] = 365;
  13853. t['ae'] = 889;
  13854. t['dotlessi'] = 278;
  13855. t['lslash'] = 222;
  13856. t['oslash'] = 611;
  13857. t['oe'] = 944;
  13858. t['germandbls'] = 611;
  13859. t['Idieresis'] = 278;
  13860. t['eacute'] = 556;
  13861. t['abreve'] = 556;
  13862. t['uhungarumlaut'] = 556;
  13863. t['ecaron'] = 556;
  13864. t['Ydieresis'] = 667;
  13865. t['divide'] = 584;
  13866. t['Yacute'] = 667;
  13867. t['Acircumflex'] = 667;
  13868. t['aacute'] = 556;
  13869. t['Ucircumflex'] = 722;
  13870. t['yacute'] = 500;
  13871. t['scommaaccent'] = 500;
  13872. t['ecircumflex'] = 556;
  13873. t['Uring'] = 722;
  13874. t['Udieresis'] = 722;
  13875. t['aogonek'] = 556;
  13876. t['Uacute'] = 722;
  13877. t['uogonek'] = 556;
  13878. t['Edieresis'] = 667;
  13879. t['Dcroat'] = 722;
  13880. t['commaaccent'] = 250;
  13881. t['copyright'] = 737;
  13882. t['Emacron'] = 667;
  13883. t['ccaron'] = 500;
  13884. t['aring'] = 556;
  13885. t['Ncommaaccent'] = 722;
  13886. t['lacute'] = 222;
  13887. t['agrave'] = 556;
  13888. t['Tcommaaccent'] = 611;
  13889. t['Cacute'] = 722;
  13890. t['atilde'] = 556;
  13891. t['Edotaccent'] = 667;
  13892. t['scaron'] = 500;
  13893. t['scedilla'] = 500;
  13894. t['iacute'] = 278;
  13895. t['lozenge'] = 471;
  13896. t['Rcaron'] = 722;
  13897. t['Gcommaaccent'] = 778;
  13898. t['ucircumflex'] = 556;
  13899. t['acircumflex'] = 556;
  13900. t['Amacron'] = 667;
  13901. t['rcaron'] = 333;
  13902. t['ccedilla'] = 500;
  13903. t['Zdotaccent'] = 611;
  13904. t['Thorn'] = 667;
  13905. t['Omacron'] = 778;
  13906. t['Racute'] = 722;
  13907. t['Sacute'] = 667;
  13908. t['dcaron'] = 643;
  13909. t['Umacron'] = 722;
  13910. t['uring'] = 556;
  13911. t['threesuperior'] = 333;
  13912. t['Ograve'] = 778;
  13913. t['Agrave'] = 667;
  13914. t['Abreve'] = 667;
  13915. t['multiply'] = 584;
  13916. t['uacute'] = 556;
  13917. t['Tcaron'] = 611;
  13918. t['partialdiff'] = 476;
  13919. t['ydieresis'] = 500;
  13920. t['Nacute'] = 722;
  13921. t['icircumflex'] = 278;
  13922. t['Ecircumflex'] = 667;
  13923. t['adieresis'] = 556;
  13924. t['edieresis'] = 556;
  13925. t['cacute'] = 500;
  13926. t['nacute'] = 556;
  13927. t['umacron'] = 556;
  13928. t['Ncaron'] = 722;
  13929. t['Iacute'] = 278;
  13930. t['plusminus'] = 584;
  13931. t['brokenbar'] = 260;
  13932. t['registered'] = 737;
  13933. t['Gbreve'] = 778;
  13934. t['Idotaccent'] = 278;
  13935. t['summation'] = 600;
  13936. t['Egrave'] = 667;
  13937. t['racute'] = 333;
  13938. t['omacron'] = 556;
  13939. t['Zacute'] = 611;
  13940. t['Zcaron'] = 611;
  13941. t['greaterequal'] = 549;
  13942. t['Eth'] = 722;
  13943. t['Ccedilla'] = 722;
  13944. t['lcommaaccent'] = 222;
  13945. t['tcaron'] = 317;
  13946. t['eogonek'] = 556;
  13947. t['Uogonek'] = 722;
  13948. t['Aacute'] = 667;
  13949. t['Adieresis'] = 667;
  13950. t['egrave'] = 556;
  13951. t['zacute'] = 500;
  13952. t['iogonek'] = 222;
  13953. t['Oacute'] = 778;
  13954. t['oacute'] = 556;
  13955. t['amacron'] = 556;
  13956. t['sacute'] = 500;
  13957. t['idieresis'] = 278;
  13958. t['Ocircumflex'] = 778;
  13959. t['Ugrave'] = 722;
  13960. t['Delta'] = 612;
  13961. t['thorn'] = 556;
  13962. t['twosuperior'] = 333;
  13963. t['Odieresis'] = 778;
  13964. t['mu'] = 556;
  13965. t['igrave'] = 278;
  13966. t['ohungarumlaut'] = 556;
  13967. t['Eogonek'] = 667;
  13968. t['dcroat'] = 556;
  13969. t['threequarters'] = 834;
  13970. t['Scedilla'] = 667;
  13971. t['lcaron'] = 299;
  13972. t['Kcommaaccent'] = 667;
  13973. t['Lacute'] = 556;
  13974. t['trademark'] = 1000;
  13975. t['edotaccent'] = 556;
  13976. t['Igrave'] = 278;
  13977. t['Imacron'] = 278;
  13978. t['Lcaron'] = 556;
  13979. t['onehalf'] = 834;
  13980. t['lessequal'] = 549;
  13981. t['ocircumflex'] = 556;
  13982. t['ntilde'] = 556;
  13983. t['Uhungarumlaut'] = 722;
  13984. t['Eacute'] = 667;
  13985. t['emacron'] = 556;
  13986. t['gbreve'] = 556;
  13987. t['onequarter'] = 834;
  13988. t['Scaron'] = 667;
  13989. t['Scommaaccent'] = 667;
  13990. t['Ohungarumlaut'] = 778;
  13991. t['degree'] = 400;
  13992. t['ograve'] = 556;
  13993. t['Ccaron'] = 722;
  13994. t['ugrave'] = 556;
  13995. t['radical'] = 453;
  13996. t['Dcaron'] = 722;
  13997. t['rcommaaccent'] = 333;
  13998. t['Ntilde'] = 722;
  13999. t['otilde'] = 556;
  14000. t['Rcommaaccent'] = 722;
  14001. t['Lcommaaccent'] = 556;
  14002. t['Atilde'] = 667;
  14003. t['Aogonek'] = 667;
  14004. t['Aring'] = 667;
  14005. t['Otilde'] = 778;
  14006. t['zdotaccent'] = 500;
  14007. t['Ecaron'] = 667;
  14008. t['Iogonek'] = 278;
  14009. t['kcommaaccent'] = 500;
  14010. t['minus'] = 584;
  14011. t['Icircumflex'] = 278;
  14012. t['ncaron'] = 556;
  14013. t['tcommaaccent'] = 278;
  14014. t['logicalnot'] = 584;
  14015. t['odieresis'] = 556;
  14016. t['udieresis'] = 556;
  14017. t['notequal'] = 549;
  14018. t['gcommaaccent'] = 556;
  14019. t['eth'] = 556;
  14020. t['zcaron'] = 500;
  14021. t['ncommaaccent'] = 556;
  14022. t['onesuperior'] = 333;
  14023. t['imacron'] = 278;
  14024. t['Euro'] = 556;
  14025. });
  14026. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  14027. t['space'] = 278;
  14028. t['exclam'] = 333;
  14029. t['quotedbl'] = 474;
  14030. t['numbersign'] = 556;
  14031. t['dollar'] = 556;
  14032. t['percent'] = 889;
  14033. t['ampersand'] = 722;
  14034. t['quoteright'] = 278;
  14035. t['parenleft'] = 333;
  14036. t['parenright'] = 333;
  14037. t['asterisk'] = 389;
  14038. t['plus'] = 584;
  14039. t['comma'] = 278;
  14040. t['hyphen'] = 333;
  14041. t['period'] = 278;
  14042. t['slash'] = 278;
  14043. t['zero'] = 556;
  14044. t['one'] = 556;
  14045. t['two'] = 556;
  14046. t['three'] = 556;
  14047. t['four'] = 556;
  14048. t['five'] = 556;
  14049. t['six'] = 556;
  14050. t['seven'] = 556;
  14051. t['eight'] = 556;
  14052. t['nine'] = 556;
  14053. t['colon'] = 333;
  14054. t['semicolon'] = 333;
  14055. t['less'] = 584;
  14056. t['equal'] = 584;
  14057. t['greater'] = 584;
  14058. t['question'] = 611;
  14059. t['at'] = 975;
  14060. t['A'] = 722;
  14061. t['B'] = 722;
  14062. t['C'] = 722;
  14063. t['D'] = 722;
  14064. t['E'] = 667;
  14065. t['F'] = 611;
  14066. t['G'] = 778;
  14067. t['H'] = 722;
  14068. t['I'] = 278;
  14069. t['J'] = 556;
  14070. t['K'] = 722;
  14071. t['L'] = 611;
  14072. t['M'] = 833;
  14073. t['N'] = 722;
  14074. t['O'] = 778;
  14075. t['P'] = 667;
  14076. t['Q'] = 778;
  14077. t['R'] = 722;
  14078. t['S'] = 667;
  14079. t['T'] = 611;
  14080. t['U'] = 722;
  14081. t['V'] = 667;
  14082. t['W'] = 944;
  14083. t['X'] = 667;
  14084. t['Y'] = 667;
  14085. t['Z'] = 611;
  14086. t['bracketleft'] = 333;
  14087. t['backslash'] = 278;
  14088. t['bracketright'] = 333;
  14089. t['asciicircum'] = 584;
  14090. t['underscore'] = 556;
  14091. t['quoteleft'] = 278;
  14092. t['a'] = 556;
  14093. t['b'] = 611;
  14094. t['c'] = 556;
  14095. t['d'] = 611;
  14096. t['e'] = 556;
  14097. t['f'] = 333;
  14098. t['g'] = 611;
  14099. t['h'] = 611;
  14100. t['i'] = 278;
  14101. t['j'] = 278;
  14102. t['k'] = 556;
  14103. t['l'] = 278;
  14104. t['m'] = 889;
  14105. t['n'] = 611;
  14106. t['o'] = 611;
  14107. t['p'] = 611;
  14108. t['q'] = 611;
  14109. t['r'] = 389;
  14110. t['s'] = 556;
  14111. t['t'] = 333;
  14112. t['u'] = 611;
  14113. t['v'] = 556;
  14114. t['w'] = 778;
  14115. t['x'] = 556;
  14116. t['y'] = 556;
  14117. t['z'] = 500;
  14118. t['braceleft'] = 389;
  14119. t['bar'] = 280;
  14120. t['braceright'] = 389;
  14121. t['asciitilde'] = 584;
  14122. t['exclamdown'] = 333;
  14123. t['cent'] = 556;
  14124. t['sterling'] = 556;
  14125. t['fraction'] = 167;
  14126. t['yen'] = 556;
  14127. t['florin'] = 556;
  14128. t['section'] = 556;
  14129. t['currency'] = 556;
  14130. t['quotesingle'] = 238;
  14131. t['quotedblleft'] = 500;
  14132. t['guillemotleft'] = 556;
  14133. t['guilsinglleft'] = 333;
  14134. t['guilsinglright'] = 333;
  14135. t['fi'] = 611;
  14136. t['fl'] = 611;
  14137. t['endash'] = 556;
  14138. t['dagger'] = 556;
  14139. t['daggerdbl'] = 556;
  14140. t['periodcentered'] = 278;
  14141. t['paragraph'] = 556;
  14142. t['bullet'] = 350;
  14143. t['quotesinglbase'] = 278;
  14144. t['quotedblbase'] = 500;
  14145. t['quotedblright'] = 500;
  14146. t['guillemotright'] = 556;
  14147. t['ellipsis'] = 1000;
  14148. t['perthousand'] = 1000;
  14149. t['questiondown'] = 611;
  14150. t['grave'] = 333;
  14151. t['acute'] = 333;
  14152. t['circumflex'] = 333;
  14153. t['tilde'] = 333;
  14154. t['macron'] = 333;
  14155. t['breve'] = 333;
  14156. t['dotaccent'] = 333;
  14157. t['dieresis'] = 333;
  14158. t['ring'] = 333;
  14159. t['cedilla'] = 333;
  14160. t['hungarumlaut'] = 333;
  14161. t['ogonek'] = 333;
  14162. t['caron'] = 333;
  14163. t['emdash'] = 1000;
  14164. t['AE'] = 1000;
  14165. t['ordfeminine'] = 370;
  14166. t['Lslash'] = 611;
  14167. t['Oslash'] = 778;
  14168. t['OE'] = 1000;
  14169. t['ordmasculine'] = 365;
  14170. t['ae'] = 889;
  14171. t['dotlessi'] = 278;
  14172. t['lslash'] = 278;
  14173. t['oslash'] = 611;
  14174. t['oe'] = 944;
  14175. t['germandbls'] = 611;
  14176. t['Idieresis'] = 278;
  14177. t['eacute'] = 556;
  14178. t['abreve'] = 556;
  14179. t['uhungarumlaut'] = 611;
  14180. t['ecaron'] = 556;
  14181. t['Ydieresis'] = 667;
  14182. t['divide'] = 584;
  14183. t['Yacute'] = 667;
  14184. t['Acircumflex'] = 722;
  14185. t['aacute'] = 556;
  14186. t['Ucircumflex'] = 722;
  14187. t['yacute'] = 556;
  14188. t['scommaaccent'] = 556;
  14189. t['ecircumflex'] = 556;
  14190. t['Uring'] = 722;
  14191. t['Udieresis'] = 722;
  14192. t['aogonek'] = 556;
  14193. t['Uacute'] = 722;
  14194. t['uogonek'] = 611;
  14195. t['Edieresis'] = 667;
  14196. t['Dcroat'] = 722;
  14197. t['commaaccent'] = 250;
  14198. t['copyright'] = 737;
  14199. t['Emacron'] = 667;
  14200. t['ccaron'] = 556;
  14201. t['aring'] = 556;
  14202. t['Ncommaaccent'] = 722;
  14203. t['lacute'] = 278;
  14204. t['agrave'] = 556;
  14205. t['Tcommaaccent'] = 611;
  14206. t['Cacute'] = 722;
  14207. t['atilde'] = 556;
  14208. t['Edotaccent'] = 667;
  14209. t['scaron'] = 556;
  14210. t['scedilla'] = 556;
  14211. t['iacute'] = 278;
  14212. t['lozenge'] = 494;
  14213. t['Rcaron'] = 722;
  14214. t['Gcommaaccent'] = 778;
  14215. t['ucircumflex'] = 611;
  14216. t['acircumflex'] = 556;
  14217. t['Amacron'] = 722;
  14218. t['rcaron'] = 389;
  14219. t['ccedilla'] = 556;
  14220. t['Zdotaccent'] = 611;
  14221. t['Thorn'] = 667;
  14222. t['Omacron'] = 778;
  14223. t['Racute'] = 722;
  14224. t['Sacute'] = 667;
  14225. t['dcaron'] = 743;
  14226. t['Umacron'] = 722;
  14227. t['uring'] = 611;
  14228. t['threesuperior'] = 333;
  14229. t['Ograve'] = 778;
  14230. t['Agrave'] = 722;
  14231. t['Abreve'] = 722;
  14232. t['multiply'] = 584;
  14233. t['uacute'] = 611;
  14234. t['Tcaron'] = 611;
  14235. t['partialdiff'] = 494;
  14236. t['ydieresis'] = 556;
  14237. t['Nacute'] = 722;
  14238. t['icircumflex'] = 278;
  14239. t['Ecircumflex'] = 667;
  14240. t['adieresis'] = 556;
  14241. t['edieresis'] = 556;
  14242. t['cacute'] = 556;
  14243. t['nacute'] = 611;
  14244. t['umacron'] = 611;
  14245. t['Ncaron'] = 722;
  14246. t['Iacute'] = 278;
  14247. t['plusminus'] = 584;
  14248. t['brokenbar'] = 280;
  14249. t['registered'] = 737;
  14250. t['Gbreve'] = 778;
  14251. t['Idotaccent'] = 278;
  14252. t['summation'] = 600;
  14253. t['Egrave'] = 667;
  14254. t['racute'] = 389;
  14255. t['omacron'] = 611;
  14256. t['Zacute'] = 611;
  14257. t['Zcaron'] = 611;
  14258. t['greaterequal'] = 549;
  14259. t['Eth'] = 722;
  14260. t['Ccedilla'] = 722;
  14261. t['lcommaaccent'] = 278;
  14262. t['tcaron'] = 389;
  14263. t['eogonek'] = 556;
  14264. t['Uogonek'] = 722;
  14265. t['Aacute'] = 722;
  14266. t['Adieresis'] = 722;
  14267. t['egrave'] = 556;
  14268. t['zacute'] = 500;
  14269. t['iogonek'] = 278;
  14270. t['Oacute'] = 778;
  14271. t['oacute'] = 611;
  14272. t['amacron'] = 556;
  14273. t['sacute'] = 556;
  14274. t['idieresis'] = 278;
  14275. t['Ocircumflex'] = 778;
  14276. t['Ugrave'] = 722;
  14277. t['Delta'] = 612;
  14278. t['thorn'] = 611;
  14279. t['twosuperior'] = 333;
  14280. t['Odieresis'] = 778;
  14281. t['mu'] = 611;
  14282. t['igrave'] = 278;
  14283. t['ohungarumlaut'] = 611;
  14284. t['Eogonek'] = 667;
  14285. t['dcroat'] = 611;
  14286. t['threequarters'] = 834;
  14287. t['Scedilla'] = 667;
  14288. t['lcaron'] = 400;
  14289. t['Kcommaaccent'] = 722;
  14290. t['Lacute'] = 611;
  14291. t['trademark'] = 1000;
  14292. t['edotaccent'] = 556;
  14293. t['Igrave'] = 278;
  14294. t['Imacron'] = 278;
  14295. t['Lcaron'] = 611;
  14296. t['onehalf'] = 834;
  14297. t['lessequal'] = 549;
  14298. t['ocircumflex'] = 611;
  14299. t['ntilde'] = 611;
  14300. t['Uhungarumlaut'] = 722;
  14301. t['Eacute'] = 667;
  14302. t['emacron'] = 556;
  14303. t['gbreve'] = 611;
  14304. t['onequarter'] = 834;
  14305. t['Scaron'] = 667;
  14306. t['Scommaaccent'] = 667;
  14307. t['Ohungarumlaut'] = 778;
  14308. t['degree'] = 400;
  14309. t['ograve'] = 611;
  14310. t['Ccaron'] = 722;
  14311. t['ugrave'] = 611;
  14312. t['radical'] = 549;
  14313. t['Dcaron'] = 722;
  14314. t['rcommaaccent'] = 389;
  14315. t['Ntilde'] = 722;
  14316. t['otilde'] = 611;
  14317. t['Rcommaaccent'] = 722;
  14318. t['Lcommaaccent'] = 611;
  14319. t['Atilde'] = 722;
  14320. t['Aogonek'] = 722;
  14321. t['Aring'] = 722;
  14322. t['Otilde'] = 778;
  14323. t['zdotaccent'] = 500;
  14324. t['Ecaron'] = 667;
  14325. t['Iogonek'] = 278;
  14326. t['kcommaaccent'] = 556;
  14327. t['minus'] = 584;
  14328. t['Icircumflex'] = 278;
  14329. t['ncaron'] = 611;
  14330. t['tcommaaccent'] = 333;
  14331. t['logicalnot'] = 584;
  14332. t['odieresis'] = 611;
  14333. t['udieresis'] = 611;
  14334. t['notequal'] = 549;
  14335. t['gcommaaccent'] = 611;
  14336. t['eth'] = 611;
  14337. t['zcaron'] = 500;
  14338. t['ncommaaccent'] = 611;
  14339. t['onesuperior'] = 333;
  14340. t['imacron'] = 278;
  14341. t['Euro'] = 556;
  14342. });
  14343. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14344. t['space'] = 278;
  14345. t['exclam'] = 333;
  14346. t['quotedbl'] = 474;
  14347. t['numbersign'] = 556;
  14348. t['dollar'] = 556;
  14349. t['percent'] = 889;
  14350. t['ampersand'] = 722;
  14351. t['quoteright'] = 278;
  14352. t['parenleft'] = 333;
  14353. t['parenright'] = 333;
  14354. t['asterisk'] = 389;
  14355. t['plus'] = 584;
  14356. t['comma'] = 278;
  14357. t['hyphen'] = 333;
  14358. t['period'] = 278;
  14359. t['slash'] = 278;
  14360. t['zero'] = 556;
  14361. t['one'] = 556;
  14362. t['two'] = 556;
  14363. t['three'] = 556;
  14364. t['four'] = 556;
  14365. t['five'] = 556;
  14366. t['six'] = 556;
  14367. t['seven'] = 556;
  14368. t['eight'] = 556;
  14369. t['nine'] = 556;
  14370. t['colon'] = 333;
  14371. t['semicolon'] = 333;
  14372. t['less'] = 584;
  14373. t['equal'] = 584;
  14374. t['greater'] = 584;
  14375. t['question'] = 611;
  14376. t['at'] = 975;
  14377. t['A'] = 722;
  14378. t['B'] = 722;
  14379. t['C'] = 722;
  14380. t['D'] = 722;
  14381. t['E'] = 667;
  14382. t['F'] = 611;
  14383. t['G'] = 778;
  14384. t['H'] = 722;
  14385. t['I'] = 278;
  14386. t['J'] = 556;
  14387. t['K'] = 722;
  14388. t['L'] = 611;
  14389. t['M'] = 833;
  14390. t['N'] = 722;
  14391. t['O'] = 778;
  14392. t['P'] = 667;
  14393. t['Q'] = 778;
  14394. t['R'] = 722;
  14395. t['S'] = 667;
  14396. t['T'] = 611;
  14397. t['U'] = 722;
  14398. t['V'] = 667;
  14399. t['W'] = 944;
  14400. t['X'] = 667;
  14401. t['Y'] = 667;
  14402. t['Z'] = 611;
  14403. t['bracketleft'] = 333;
  14404. t['backslash'] = 278;
  14405. t['bracketright'] = 333;
  14406. t['asciicircum'] = 584;
  14407. t['underscore'] = 556;
  14408. t['quoteleft'] = 278;
  14409. t['a'] = 556;
  14410. t['b'] = 611;
  14411. t['c'] = 556;
  14412. t['d'] = 611;
  14413. t['e'] = 556;
  14414. t['f'] = 333;
  14415. t['g'] = 611;
  14416. t['h'] = 611;
  14417. t['i'] = 278;
  14418. t['j'] = 278;
  14419. t['k'] = 556;
  14420. t['l'] = 278;
  14421. t['m'] = 889;
  14422. t['n'] = 611;
  14423. t['o'] = 611;
  14424. t['p'] = 611;
  14425. t['q'] = 611;
  14426. t['r'] = 389;
  14427. t['s'] = 556;
  14428. t['t'] = 333;
  14429. t['u'] = 611;
  14430. t['v'] = 556;
  14431. t['w'] = 778;
  14432. t['x'] = 556;
  14433. t['y'] = 556;
  14434. t['z'] = 500;
  14435. t['braceleft'] = 389;
  14436. t['bar'] = 280;
  14437. t['braceright'] = 389;
  14438. t['asciitilde'] = 584;
  14439. t['exclamdown'] = 333;
  14440. t['cent'] = 556;
  14441. t['sterling'] = 556;
  14442. t['fraction'] = 167;
  14443. t['yen'] = 556;
  14444. t['florin'] = 556;
  14445. t['section'] = 556;
  14446. t['currency'] = 556;
  14447. t['quotesingle'] = 238;
  14448. t['quotedblleft'] = 500;
  14449. t['guillemotleft'] = 556;
  14450. t['guilsinglleft'] = 333;
  14451. t['guilsinglright'] = 333;
  14452. t['fi'] = 611;
  14453. t['fl'] = 611;
  14454. t['endash'] = 556;
  14455. t['dagger'] = 556;
  14456. t['daggerdbl'] = 556;
  14457. t['periodcentered'] = 278;
  14458. t['paragraph'] = 556;
  14459. t['bullet'] = 350;
  14460. t['quotesinglbase'] = 278;
  14461. t['quotedblbase'] = 500;
  14462. t['quotedblright'] = 500;
  14463. t['guillemotright'] = 556;
  14464. t['ellipsis'] = 1000;
  14465. t['perthousand'] = 1000;
  14466. t['questiondown'] = 611;
  14467. t['grave'] = 333;
  14468. t['acute'] = 333;
  14469. t['circumflex'] = 333;
  14470. t['tilde'] = 333;
  14471. t['macron'] = 333;
  14472. t['breve'] = 333;
  14473. t['dotaccent'] = 333;
  14474. t['dieresis'] = 333;
  14475. t['ring'] = 333;
  14476. t['cedilla'] = 333;
  14477. t['hungarumlaut'] = 333;
  14478. t['ogonek'] = 333;
  14479. t['caron'] = 333;
  14480. t['emdash'] = 1000;
  14481. t['AE'] = 1000;
  14482. t['ordfeminine'] = 370;
  14483. t['Lslash'] = 611;
  14484. t['Oslash'] = 778;
  14485. t['OE'] = 1000;
  14486. t['ordmasculine'] = 365;
  14487. t['ae'] = 889;
  14488. t['dotlessi'] = 278;
  14489. t['lslash'] = 278;
  14490. t['oslash'] = 611;
  14491. t['oe'] = 944;
  14492. t['germandbls'] = 611;
  14493. t['Idieresis'] = 278;
  14494. t['eacute'] = 556;
  14495. t['abreve'] = 556;
  14496. t['uhungarumlaut'] = 611;
  14497. t['ecaron'] = 556;
  14498. t['Ydieresis'] = 667;
  14499. t['divide'] = 584;
  14500. t['Yacute'] = 667;
  14501. t['Acircumflex'] = 722;
  14502. t['aacute'] = 556;
  14503. t['Ucircumflex'] = 722;
  14504. t['yacute'] = 556;
  14505. t['scommaaccent'] = 556;
  14506. t['ecircumflex'] = 556;
  14507. t['Uring'] = 722;
  14508. t['Udieresis'] = 722;
  14509. t['aogonek'] = 556;
  14510. t['Uacute'] = 722;
  14511. t['uogonek'] = 611;
  14512. t['Edieresis'] = 667;
  14513. t['Dcroat'] = 722;
  14514. t['commaaccent'] = 250;
  14515. t['copyright'] = 737;
  14516. t['Emacron'] = 667;
  14517. t['ccaron'] = 556;
  14518. t['aring'] = 556;
  14519. t['Ncommaaccent'] = 722;
  14520. t['lacute'] = 278;
  14521. t['agrave'] = 556;
  14522. t['Tcommaaccent'] = 611;
  14523. t['Cacute'] = 722;
  14524. t['atilde'] = 556;
  14525. t['Edotaccent'] = 667;
  14526. t['scaron'] = 556;
  14527. t['scedilla'] = 556;
  14528. t['iacute'] = 278;
  14529. t['lozenge'] = 494;
  14530. t['Rcaron'] = 722;
  14531. t['Gcommaaccent'] = 778;
  14532. t['ucircumflex'] = 611;
  14533. t['acircumflex'] = 556;
  14534. t['Amacron'] = 722;
  14535. t['rcaron'] = 389;
  14536. t['ccedilla'] = 556;
  14537. t['Zdotaccent'] = 611;
  14538. t['Thorn'] = 667;
  14539. t['Omacron'] = 778;
  14540. t['Racute'] = 722;
  14541. t['Sacute'] = 667;
  14542. t['dcaron'] = 743;
  14543. t['Umacron'] = 722;
  14544. t['uring'] = 611;
  14545. t['threesuperior'] = 333;
  14546. t['Ograve'] = 778;
  14547. t['Agrave'] = 722;
  14548. t['Abreve'] = 722;
  14549. t['multiply'] = 584;
  14550. t['uacute'] = 611;
  14551. t['Tcaron'] = 611;
  14552. t['partialdiff'] = 494;
  14553. t['ydieresis'] = 556;
  14554. t['Nacute'] = 722;
  14555. t['icircumflex'] = 278;
  14556. t['Ecircumflex'] = 667;
  14557. t['adieresis'] = 556;
  14558. t['edieresis'] = 556;
  14559. t['cacute'] = 556;
  14560. t['nacute'] = 611;
  14561. t['umacron'] = 611;
  14562. t['Ncaron'] = 722;
  14563. t['Iacute'] = 278;
  14564. t['plusminus'] = 584;
  14565. t['brokenbar'] = 280;
  14566. t['registered'] = 737;
  14567. t['Gbreve'] = 778;
  14568. t['Idotaccent'] = 278;
  14569. t['summation'] = 600;
  14570. t['Egrave'] = 667;
  14571. t['racute'] = 389;
  14572. t['omacron'] = 611;
  14573. t['Zacute'] = 611;
  14574. t['Zcaron'] = 611;
  14575. t['greaterequal'] = 549;
  14576. t['Eth'] = 722;
  14577. t['Ccedilla'] = 722;
  14578. t['lcommaaccent'] = 278;
  14579. t['tcaron'] = 389;
  14580. t['eogonek'] = 556;
  14581. t['Uogonek'] = 722;
  14582. t['Aacute'] = 722;
  14583. t['Adieresis'] = 722;
  14584. t['egrave'] = 556;
  14585. t['zacute'] = 500;
  14586. t['iogonek'] = 278;
  14587. t['Oacute'] = 778;
  14588. t['oacute'] = 611;
  14589. t['amacron'] = 556;
  14590. t['sacute'] = 556;
  14591. t['idieresis'] = 278;
  14592. t['Ocircumflex'] = 778;
  14593. t['Ugrave'] = 722;
  14594. t['Delta'] = 612;
  14595. t['thorn'] = 611;
  14596. t['twosuperior'] = 333;
  14597. t['Odieresis'] = 778;
  14598. t['mu'] = 611;
  14599. t['igrave'] = 278;
  14600. t['ohungarumlaut'] = 611;
  14601. t['Eogonek'] = 667;
  14602. t['dcroat'] = 611;
  14603. t['threequarters'] = 834;
  14604. t['Scedilla'] = 667;
  14605. t['lcaron'] = 400;
  14606. t['Kcommaaccent'] = 722;
  14607. t['Lacute'] = 611;
  14608. t['trademark'] = 1000;
  14609. t['edotaccent'] = 556;
  14610. t['Igrave'] = 278;
  14611. t['Imacron'] = 278;
  14612. t['Lcaron'] = 611;
  14613. t['onehalf'] = 834;
  14614. t['lessequal'] = 549;
  14615. t['ocircumflex'] = 611;
  14616. t['ntilde'] = 611;
  14617. t['Uhungarumlaut'] = 722;
  14618. t['Eacute'] = 667;
  14619. t['emacron'] = 556;
  14620. t['gbreve'] = 611;
  14621. t['onequarter'] = 834;
  14622. t['Scaron'] = 667;
  14623. t['Scommaaccent'] = 667;
  14624. t['Ohungarumlaut'] = 778;
  14625. t['degree'] = 400;
  14626. t['ograve'] = 611;
  14627. t['Ccaron'] = 722;
  14628. t['ugrave'] = 611;
  14629. t['radical'] = 549;
  14630. t['Dcaron'] = 722;
  14631. t['rcommaaccent'] = 389;
  14632. t['Ntilde'] = 722;
  14633. t['otilde'] = 611;
  14634. t['Rcommaaccent'] = 722;
  14635. t['Lcommaaccent'] = 611;
  14636. t['Atilde'] = 722;
  14637. t['Aogonek'] = 722;
  14638. t['Aring'] = 722;
  14639. t['Otilde'] = 778;
  14640. t['zdotaccent'] = 500;
  14641. t['Ecaron'] = 667;
  14642. t['Iogonek'] = 278;
  14643. t['kcommaaccent'] = 556;
  14644. t['minus'] = 584;
  14645. t['Icircumflex'] = 278;
  14646. t['ncaron'] = 611;
  14647. t['tcommaaccent'] = 333;
  14648. t['logicalnot'] = 584;
  14649. t['odieresis'] = 611;
  14650. t['udieresis'] = 611;
  14651. t['notequal'] = 549;
  14652. t['gcommaaccent'] = 611;
  14653. t['eth'] = 611;
  14654. t['zcaron'] = 500;
  14655. t['ncommaaccent'] = 611;
  14656. t['onesuperior'] = 333;
  14657. t['imacron'] = 278;
  14658. t['Euro'] = 556;
  14659. });
  14660. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14661. t['space'] = 278;
  14662. t['exclam'] = 278;
  14663. t['quotedbl'] = 355;
  14664. t['numbersign'] = 556;
  14665. t['dollar'] = 556;
  14666. t['percent'] = 889;
  14667. t['ampersand'] = 667;
  14668. t['quoteright'] = 222;
  14669. t['parenleft'] = 333;
  14670. t['parenright'] = 333;
  14671. t['asterisk'] = 389;
  14672. t['plus'] = 584;
  14673. t['comma'] = 278;
  14674. t['hyphen'] = 333;
  14675. t['period'] = 278;
  14676. t['slash'] = 278;
  14677. t['zero'] = 556;
  14678. t['one'] = 556;
  14679. t['two'] = 556;
  14680. t['three'] = 556;
  14681. t['four'] = 556;
  14682. t['five'] = 556;
  14683. t['six'] = 556;
  14684. t['seven'] = 556;
  14685. t['eight'] = 556;
  14686. t['nine'] = 556;
  14687. t['colon'] = 278;
  14688. t['semicolon'] = 278;
  14689. t['less'] = 584;
  14690. t['equal'] = 584;
  14691. t['greater'] = 584;
  14692. t['question'] = 556;
  14693. t['at'] = 1015;
  14694. t['A'] = 667;
  14695. t['B'] = 667;
  14696. t['C'] = 722;
  14697. t['D'] = 722;
  14698. t['E'] = 667;
  14699. t['F'] = 611;
  14700. t['G'] = 778;
  14701. t['H'] = 722;
  14702. t['I'] = 278;
  14703. t['J'] = 500;
  14704. t['K'] = 667;
  14705. t['L'] = 556;
  14706. t['M'] = 833;
  14707. t['N'] = 722;
  14708. t['O'] = 778;
  14709. t['P'] = 667;
  14710. t['Q'] = 778;
  14711. t['R'] = 722;
  14712. t['S'] = 667;
  14713. t['T'] = 611;
  14714. t['U'] = 722;
  14715. t['V'] = 667;
  14716. t['W'] = 944;
  14717. t['X'] = 667;
  14718. t['Y'] = 667;
  14719. t['Z'] = 611;
  14720. t['bracketleft'] = 278;
  14721. t['backslash'] = 278;
  14722. t['bracketright'] = 278;
  14723. t['asciicircum'] = 469;
  14724. t['underscore'] = 556;
  14725. t['quoteleft'] = 222;
  14726. t['a'] = 556;
  14727. t['b'] = 556;
  14728. t['c'] = 500;
  14729. t['d'] = 556;
  14730. t['e'] = 556;
  14731. t['f'] = 278;
  14732. t['g'] = 556;
  14733. t['h'] = 556;
  14734. t['i'] = 222;
  14735. t['j'] = 222;
  14736. t['k'] = 500;
  14737. t['l'] = 222;
  14738. t['m'] = 833;
  14739. t['n'] = 556;
  14740. t['o'] = 556;
  14741. t['p'] = 556;
  14742. t['q'] = 556;
  14743. t['r'] = 333;
  14744. t['s'] = 500;
  14745. t['t'] = 278;
  14746. t['u'] = 556;
  14747. t['v'] = 500;
  14748. t['w'] = 722;
  14749. t['x'] = 500;
  14750. t['y'] = 500;
  14751. t['z'] = 500;
  14752. t['braceleft'] = 334;
  14753. t['bar'] = 260;
  14754. t['braceright'] = 334;
  14755. t['asciitilde'] = 584;
  14756. t['exclamdown'] = 333;
  14757. t['cent'] = 556;
  14758. t['sterling'] = 556;
  14759. t['fraction'] = 167;
  14760. t['yen'] = 556;
  14761. t['florin'] = 556;
  14762. t['section'] = 556;
  14763. t['currency'] = 556;
  14764. t['quotesingle'] = 191;
  14765. t['quotedblleft'] = 333;
  14766. t['guillemotleft'] = 556;
  14767. t['guilsinglleft'] = 333;
  14768. t['guilsinglright'] = 333;
  14769. t['fi'] = 500;
  14770. t['fl'] = 500;
  14771. t['endash'] = 556;
  14772. t['dagger'] = 556;
  14773. t['daggerdbl'] = 556;
  14774. t['periodcentered'] = 278;
  14775. t['paragraph'] = 537;
  14776. t['bullet'] = 350;
  14777. t['quotesinglbase'] = 222;
  14778. t['quotedblbase'] = 333;
  14779. t['quotedblright'] = 333;
  14780. t['guillemotright'] = 556;
  14781. t['ellipsis'] = 1000;
  14782. t['perthousand'] = 1000;
  14783. t['questiondown'] = 611;
  14784. t['grave'] = 333;
  14785. t['acute'] = 333;
  14786. t['circumflex'] = 333;
  14787. t['tilde'] = 333;
  14788. t['macron'] = 333;
  14789. t['breve'] = 333;
  14790. t['dotaccent'] = 333;
  14791. t['dieresis'] = 333;
  14792. t['ring'] = 333;
  14793. t['cedilla'] = 333;
  14794. t['hungarumlaut'] = 333;
  14795. t['ogonek'] = 333;
  14796. t['caron'] = 333;
  14797. t['emdash'] = 1000;
  14798. t['AE'] = 1000;
  14799. t['ordfeminine'] = 370;
  14800. t['Lslash'] = 556;
  14801. t['Oslash'] = 778;
  14802. t['OE'] = 1000;
  14803. t['ordmasculine'] = 365;
  14804. t['ae'] = 889;
  14805. t['dotlessi'] = 278;
  14806. t['lslash'] = 222;
  14807. t['oslash'] = 611;
  14808. t['oe'] = 944;
  14809. t['germandbls'] = 611;
  14810. t['Idieresis'] = 278;
  14811. t['eacute'] = 556;
  14812. t['abreve'] = 556;
  14813. t['uhungarumlaut'] = 556;
  14814. t['ecaron'] = 556;
  14815. t['Ydieresis'] = 667;
  14816. t['divide'] = 584;
  14817. t['Yacute'] = 667;
  14818. t['Acircumflex'] = 667;
  14819. t['aacute'] = 556;
  14820. t['Ucircumflex'] = 722;
  14821. t['yacute'] = 500;
  14822. t['scommaaccent'] = 500;
  14823. t['ecircumflex'] = 556;
  14824. t['Uring'] = 722;
  14825. t['Udieresis'] = 722;
  14826. t['aogonek'] = 556;
  14827. t['Uacute'] = 722;
  14828. t['uogonek'] = 556;
  14829. t['Edieresis'] = 667;
  14830. t['Dcroat'] = 722;
  14831. t['commaaccent'] = 250;
  14832. t['copyright'] = 737;
  14833. t['Emacron'] = 667;
  14834. t['ccaron'] = 500;
  14835. t['aring'] = 556;
  14836. t['Ncommaaccent'] = 722;
  14837. t['lacute'] = 222;
  14838. t['agrave'] = 556;
  14839. t['Tcommaaccent'] = 611;
  14840. t['Cacute'] = 722;
  14841. t['atilde'] = 556;
  14842. t['Edotaccent'] = 667;
  14843. t['scaron'] = 500;
  14844. t['scedilla'] = 500;
  14845. t['iacute'] = 278;
  14846. t['lozenge'] = 471;
  14847. t['Rcaron'] = 722;
  14848. t['Gcommaaccent'] = 778;
  14849. t['ucircumflex'] = 556;
  14850. t['acircumflex'] = 556;
  14851. t['Amacron'] = 667;
  14852. t['rcaron'] = 333;
  14853. t['ccedilla'] = 500;
  14854. t['Zdotaccent'] = 611;
  14855. t['Thorn'] = 667;
  14856. t['Omacron'] = 778;
  14857. t['Racute'] = 722;
  14858. t['Sacute'] = 667;
  14859. t['dcaron'] = 643;
  14860. t['Umacron'] = 722;
  14861. t['uring'] = 556;
  14862. t['threesuperior'] = 333;
  14863. t['Ograve'] = 778;
  14864. t['Agrave'] = 667;
  14865. t['Abreve'] = 667;
  14866. t['multiply'] = 584;
  14867. t['uacute'] = 556;
  14868. t['Tcaron'] = 611;
  14869. t['partialdiff'] = 476;
  14870. t['ydieresis'] = 500;
  14871. t['Nacute'] = 722;
  14872. t['icircumflex'] = 278;
  14873. t['Ecircumflex'] = 667;
  14874. t['adieresis'] = 556;
  14875. t['edieresis'] = 556;
  14876. t['cacute'] = 500;
  14877. t['nacute'] = 556;
  14878. t['umacron'] = 556;
  14879. t['Ncaron'] = 722;
  14880. t['Iacute'] = 278;
  14881. t['plusminus'] = 584;
  14882. t['brokenbar'] = 260;
  14883. t['registered'] = 737;
  14884. t['Gbreve'] = 778;
  14885. t['Idotaccent'] = 278;
  14886. t['summation'] = 600;
  14887. t['Egrave'] = 667;
  14888. t['racute'] = 333;
  14889. t['omacron'] = 556;
  14890. t['Zacute'] = 611;
  14891. t['Zcaron'] = 611;
  14892. t['greaterequal'] = 549;
  14893. t['Eth'] = 722;
  14894. t['Ccedilla'] = 722;
  14895. t['lcommaaccent'] = 222;
  14896. t['tcaron'] = 317;
  14897. t['eogonek'] = 556;
  14898. t['Uogonek'] = 722;
  14899. t['Aacute'] = 667;
  14900. t['Adieresis'] = 667;
  14901. t['egrave'] = 556;
  14902. t['zacute'] = 500;
  14903. t['iogonek'] = 222;
  14904. t['Oacute'] = 778;
  14905. t['oacute'] = 556;
  14906. t['amacron'] = 556;
  14907. t['sacute'] = 500;
  14908. t['idieresis'] = 278;
  14909. t['Ocircumflex'] = 778;
  14910. t['Ugrave'] = 722;
  14911. t['Delta'] = 612;
  14912. t['thorn'] = 556;
  14913. t['twosuperior'] = 333;
  14914. t['Odieresis'] = 778;
  14915. t['mu'] = 556;
  14916. t['igrave'] = 278;
  14917. t['ohungarumlaut'] = 556;
  14918. t['Eogonek'] = 667;
  14919. t['dcroat'] = 556;
  14920. t['threequarters'] = 834;
  14921. t['Scedilla'] = 667;
  14922. t['lcaron'] = 299;
  14923. t['Kcommaaccent'] = 667;
  14924. t['Lacute'] = 556;
  14925. t['trademark'] = 1000;
  14926. t['edotaccent'] = 556;
  14927. t['Igrave'] = 278;
  14928. t['Imacron'] = 278;
  14929. t['Lcaron'] = 556;
  14930. t['onehalf'] = 834;
  14931. t['lessequal'] = 549;
  14932. t['ocircumflex'] = 556;
  14933. t['ntilde'] = 556;
  14934. t['Uhungarumlaut'] = 722;
  14935. t['Eacute'] = 667;
  14936. t['emacron'] = 556;
  14937. t['gbreve'] = 556;
  14938. t['onequarter'] = 834;
  14939. t['Scaron'] = 667;
  14940. t['Scommaaccent'] = 667;
  14941. t['Ohungarumlaut'] = 778;
  14942. t['degree'] = 400;
  14943. t['ograve'] = 556;
  14944. t['Ccaron'] = 722;
  14945. t['ugrave'] = 556;
  14946. t['radical'] = 453;
  14947. t['Dcaron'] = 722;
  14948. t['rcommaaccent'] = 333;
  14949. t['Ntilde'] = 722;
  14950. t['otilde'] = 556;
  14951. t['Rcommaaccent'] = 722;
  14952. t['Lcommaaccent'] = 556;
  14953. t['Atilde'] = 667;
  14954. t['Aogonek'] = 667;
  14955. t['Aring'] = 667;
  14956. t['Otilde'] = 778;
  14957. t['zdotaccent'] = 500;
  14958. t['Ecaron'] = 667;
  14959. t['Iogonek'] = 278;
  14960. t['kcommaaccent'] = 500;
  14961. t['minus'] = 584;
  14962. t['Icircumflex'] = 278;
  14963. t['ncaron'] = 556;
  14964. t['tcommaaccent'] = 278;
  14965. t['logicalnot'] = 584;
  14966. t['odieresis'] = 556;
  14967. t['udieresis'] = 556;
  14968. t['notequal'] = 549;
  14969. t['gcommaaccent'] = 556;
  14970. t['eth'] = 556;
  14971. t['zcaron'] = 500;
  14972. t['ncommaaccent'] = 556;
  14973. t['onesuperior'] = 333;
  14974. t['imacron'] = 278;
  14975. t['Euro'] = 556;
  14976. });
  14977. t['Symbol'] = getLookupTableFactory(function (t) {
  14978. t['space'] = 250;
  14979. t['exclam'] = 333;
  14980. t['universal'] = 713;
  14981. t['numbersign'] = 500;
  14982. t['existential'] = 549;
  14983. t['percent'] = 833;
  14984. t['ampersand'] = 778;
  14985. t['suchthat'] = 439;
  14986. t['parenleft'] = 333;
  14987. t['parenright'] = 333;
  14988. t['asteriskmath'] = 500;
  14989. t['plus'] = 549;
  14990. t['comma'] = 250;
  14991. t['minus'] = 549;
  14992. t['period'] = 250;
  14993. t['slash'] = 278;
  14994. t['zero'] = 500;
  14995. t['one'] = 500;
  14996. t['two'] = 500;
  14997. t['three'] = 500;
  14998. t['four'] = 500;
  14999. t['five'] = 500;
  15000. t['six'] = 500;
  15001. t['seven'] = 500;
  15002. t['eight'] = 500;
  15003. t['nine'] = 500;
  15004. t['colon'] = 278;
  15005. t['semicolon'] = 278;
  15006. t['less'] = 549;
  15007. t['equal'] = 549;
  15008. t['greater'] = 549;
  15009. t['question'] = 444;
  15010. t['congruent'] = 549;
  15011. t['Alpha'] = 722;
  15012. t['Beta'] = 667;
  15013. t['Chi'] = 722;
  15014. t['Delta'] = 612;
  15015. t['Epsilon'] = 611;
  15016. t['Phi'] = 763;
  15017. t['Gamma'] = 603;
  15018. t['Eta'] = 722;
  15019. t['Iota'] = 333;
  15020. t['theta1'] = 631;
  15021. t['Kappa'] = 722;
  15022. t['Lambda'] = 686;
  15023. t['Mu'] = 889;
  15024. t['Nu'] = 722;
  15025. t['Omicron'] = 722;
  15026. t['Pi'] = 768;
  15027. t['Theta'] = 741;
  15028. t['Rho'] = 556;
  15029. t['Sigma'] = 592;
  15030. t['Tau'] = 611;
  15031. t['Upsilon'] = 690;
  15032. t['sigma1'] = 439;
  15033. t['Omega'] = 768;
  15034. t['Xi'] = 645;
  15035. t['Psi'] = 795;
  15036. t['Zeta'] = 611;
  15037. t['bracketleft'] = 333;
  15038. t['therefore'] = 863;
  15039. t['bracketright'] = 333;
  15040. t['perpendicular'] = 658;
  15041. t['underscore'] = 500;
  15042. t['radicalex'] = 500;
  15043. t['alpha'] = 631;
  15044. t['beta'] = 549;
  15045. t['chi'] = 549;
  15046. t['delta'] = 494;
  15047. t['epsilon'] = 439;
  15048. t['phi'] = 521;
  15049. t['gamma'] = 411;
  15050. t['eta'] = 603;
  15051. t['iota'] = 329;
  15052. t['phi1'] = 603;
  15053. t['kappa'] = 549;
  15054. t['lambda'] = 549;
  15055. t['mu'] = 576;
  15056. t['nu'] = 521;
  15057. t['omicron'] = 549;
  15058. t['pi'] = 549;
  15059. t['theta'] = 521;
  15060. t['rho'] = 549;
  15061. t['sigma'] = 603;
  15062. t['tau'] = 439;
  15063. t['upsilon'] = 576;
  15064. t['omega1'] = 713;
  15065. t['omega'] = 686;
  15066. t['xi'] = 493;
  15067. t['psi'] = 686;
  15068. t['zeta'] = 494;
  15069. t['braceleft'] = 480;
  15070. t['bar'] = 200;
  15071. t['braceright'] = 480;
  15072. t['similar'] = 549;
  15073. t['Euro'] = 750;
  15074. t['Upsilon1'] = 620;
  15075. t['minute'] = 247;
  15076. t['lessequal'] = 549;
  15077. t['fraction'] = 167;
  15078. t['infinity'] = 713;
  15079. t['florin'] = 500;
  15080. t['club'] = 753;
  15081. t['diamond'] = 753;
  15082. t['heart'] = 753;
  15083. t['spade'] = 753;
  15084. t['arrowboth'] = 1042;
  15085. t['arrowleft'] = 987;
  15086. t['arrowup'] = 603;
  15087. t['arrowright'] = 987;
  15088. t['arrowdown'] = 603;
  15089. t['degree'] = 400;
  15090. t['plusminus'] = 549;
  15091. t['second'] = 411;
  15092. t['greaterequal'] = 549;
  15093. t['multiply'] = 549;
  15094. t['proportional'] = 713;
  15095. t['partialdiff'] = 494;
  15096. t['bullet'] = 460;
  15097. t['divide'] = 549;
  15098. t['notequal'] = 549;
  15099. t['equivalence'] = 549;
  15100. t['approxequal'] = 549;
  15101. t['ellipsis'] = 1000;
  15102. t['arrowvertex'] = 603;
  15103. t['arrowhorizex'] = 1000;
  15104. t['carriagereturn'] = 658;
  15105. t['aleph'] = 823;
  15106. t['Ifraktur'] = 686;
  15107. t['Rfraktur'] = 795;
  15108. t['weierstrass'] = 987;
  15109. t['circlemultiply'] = 768;
  15110. t['circleplus'] = 768;
  15111. t['emptyset'] = 823;
  15112. t['intersection'] = 768;
  15113. t['union'] = 768;
  15114. t['propersuperset'] = 713;
  15115. t['reflexsuperset'] = 713;
  15116. t['notsubset'] = 713;
  15117. t['propersubset'] = 713;
  15118. t['reflexsubset'] = 713;
  15119. t['element'] = 713;
  15120. t['notelement'] = 713;
  15121. t['angle'] = 768;
  15122. t['gradient'] = 713;
  15123. t['registerserif'] = 790;
  15124. t['copyrightserif'] = 790;
  15125. t['trademarkserif'] = 890;
  15126. t['product'] = 823;
  15127. t['radical'] = 549;
  15128. t['dotmath'] = 250;
  15129. t['logicalnot'] = 713;
  15130. t['logicaland'] = 603;
  15131. t['logicalor'] = 603;
  15132. t['arrowdblboth'] = 1042;
  15133. t['arrowdblleft'] = 987;
  15134. t['arrowdblup'] = 603;
  15135. t['arrowdblright'] = 987;
  15136. t['arrowdbldown'] = 603;
  15137. t['lozenge'] = 494;
  15138. t['angleleft'] = 329;
  15139. t['registersans'] = 790;
  15140. t['copyrightsans'] = 790;
  15141. t['trademarksans'] = 786;
  15142. t['summation'] = 713;
  15143. t['parenlefttp'] = 384;
  15144. t['parenleftex'] = 384;
  15145. t['parenleftbt'] = 384;
  15146. t['bracketlefttp'] = 384;
  15147. t['bracketleftex'] = 384;
  15148. t['bracketleftbt'] = 384;
  15149. t['bracelefttp'] = 494;
  15150. t['braceleftmid'] = 494;
  15151. t['braceleftbt'] = 494;
  15152. t['braceex'] = 494;
  15153. t['angleright'] = 329;
  15154. t['integral'] = 274;
  15155. t['integraltp'] = 686;
  15156. t['integralex'] = 686;
  15157. t['integralbt'] = 686;
  15158. t['parenrighttp'] = 384;
  15159. t['parenrightex'] = 384;
  15160. t['parenrightbt'] = 384;
  15161. t['bracketrighttp'] = 384;
  15162. t['bracketrightex'] = 384;
  15163. t['bracketrightbt'] = 384;
  15164. t['bracerighttp'] = 494;
  15165. t['bracerightmid'] = 494;
  15166. t['bracerightbt'] = 494;
  15167. t['apple'] = 790;
  15168. });
  15169. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15170. t['space'] = 250;
  15171. t['exclam'] = 333;
  15172. t['quotedbl'] = 408;
  15173. t['numbersign'] = 500;
  15174. t['dollar'] = 500;
  15175. t['percent'] = 833;
  15176. t['ampersand'] = 778;
  15177. t['quoteright'] = 333;
  15178. t['parenleft'] = 333;
  15179. t['parenright'] = 333;
  15180. t['asterisk'] = 500;
  15181. t['plus'] = 564;
  15182. t['comma'] = 250;
  15183. t['hyphen'] = 333;
  15184. t['period'] = 250;
  15185. t['slash'] = 278;
  15186. t['zero'] = 500;
  15187. t['one'] = 500;
  15188. t['two'] = 500;
  15189. t['three'] = 500;
  15190. t['four'] = 500;
  15191. t['five'] = 500;
  15192. t['six'] = 500;
  15193. t['seven'] = 500;
  15194. t['eight'] = 500;
  15195. t['nine'] = 500;
  15196. t['colon'] = 278;
  15197. t['semicolon'] = 278;
  15198. t['less'] = 564;
  15199. t['equal'] = 564;
  15200. t['greater'] = 564;
  15201. t['question'] = 444;
  15202. t['at'] = 921;
  15203. t['A'] = 722;
  15204. t['B'] = 667;
  15205. t['C'] = 667;
  15206. t['D'] = 722;
  15207. t['E'] = 611;
  15208. t['F'] = 556;
  15209. t['G'] = 722;
  15210. t['H'] = 722;
  15211. t['I'] = 333;
  15212. t['J'] = 389;
  15213. t['K'] = 722;
  15214. t['L'] = 611;
  15215. t['M'] = 889;
  15216. t['N'] = 722;
  15217. t['O'] = 722;
  15218. t['P'] = 556;
  15219. t['Q'] = 722;
  15220. t['R'] = 667;
  15221. t['S'] = 556;
  15222. t['T'] = 611;
  15223. t['U'] = 722;
  15224. t['V'] = 722;
  15225. t['W'] = 944;
  15226. t['X'] = 722;
  15227. t['Y'] = 722;
  15228. t['Z'] = 611;
  15229. t['bracketleft'] = 333;
  15230. t['backslash'] = 278;
  15231. t['bracketright'] = 333;
  15232. t['asciicircum'] = 469;
  15233. t['underscore'] = 500;
  15234. t['quoteleft'] = 333;
  15235. t['a'] = 444;
  15236. t['b'] = 500;
  15237. t['c'] = 444;
  15238. t['d'] = 500;
  15239. t['e'] = 444;
  15240. t['f'] = 333;
  15241. t['g'] = 500;
  15242. t['h'] = 500;
  15243. t['i'] = 278;
  15244. t['j'] = 278;
  15245. t['k'] = 500;
  15246. t['l'] = 278;
  15247. t['m'] = 778;
  15248. t['n'] = 500;
  15249. t['o'] = 500;
  15250. t['p'] = 500;
  15251. t['q'] = 500;
  15252. t['r'] = 333;
  15253. t['s'] = 389;
  15254. t['t'] = 278;
  15255. t['u'] = 500;
  15256. t['v'] = 500;
  15257. t['w'] = 722;
  15258. t['x'] = 500;
  15259. t['y'] = 500;
  15260. t['z'] = 444;
  15261. t['braceleft'] = 480;
  15262. t['bar'] = 200;
  15263. t['braceright'] = 480;
  15264. t['asciitilde'] = 541;
  15265. t['exclamdown'] = 333;
  15266. t['cent'] = 500;
  15267. t['sterling'] = 500;
  15268. t['fraction'] = 167;
  15269. t['yen'] = 500;
  15270. t['florin'] = 500;
  15271. t['section'] = 500;
  15272. t['currency'] = 500;
  15273. t['quotesingle'] = 180;
  15274. t['quotedblleft'] = 444;
  15275. t['guillemotleft'] = 500;
  15276. t['guilsinglleft'] = 333;
  15277. t['guilsinglright'] = 333;
  15278. t['fi'] = 556;
  15279. t['fl'] = 556;
  15280. t['endash'] = 500;
  15281. t['dagger'] = 500;
  15282. t['daggerdbl'] = 500;
  15283. t['periodcentered'] = 250;
  15284. t['paragraph'] = 453;
  15285. t['bullet'] = 350;
  15286. t['quotesinglbase'] = 333;
  15287. t['quotedblbase'] = 444;
  15288. t['quotedblright'] = 444;
  15289. t['guillemotright'] = 500;
  15290. t['ellipsis'] = 1000;
  15291. t['perthousand'] = 1000;
  15292. t['questiondown'] = 444;
  15293. t['grave'] = 333;
  15294. t['acute'] = 333;
  15295. t['circumflex'] = 333;
  15296. t['tilde'] = 333;
  15297. t['macron'] = 333;
  15298. t['breve'] = 333;
  15299. t['dotaccent'] = 333;
  15300. t['dieresis'] = 333;
  15301. t['ring'] = 333;
  15302. t['cedilla'] = 333;
  15303. t['hungarumlaut'] = 333;
  15304. t['ogonek'] = 333;
  15305. t['caron'] = 333;
  15306. t['emdash'] = 1000;
  15307. t['AE'] = 889;
  15308. t['ordfeminine'] = 276;
  15309. t['Lslash'] = 611;
  15310. t['Oslash'] = 722;
  15311. t['OE'] = 889;
  15312. t['ordmasculine'] = 310;
  15313. t['ae'] = 667;
  15314. t['dotlessi'] = 278;
  15315. t['lslash'] = 278;
  15316. t['oslash'] = 500;
  15317. t['oe'] = 722;
  15318. t['germandbls'] = 500;
  15319. t['Idieresis'] = 333;
  15320. t['eacute'] = 444;
  15321. t['abreve'] = 444;
  15322. t['uhungarumlaut'] = 500;
  15323. t['ecaron'] = 444;
  15324. t['Ydieresis'] = 722;
  15325. t['divide'] = 564;
  15326. t['Yacute'] = 722;
  15327. t['Acircumflex'] = 722;
  15328. t['aacute'] = 444;
  15329. t['Ucircumflex'] = 722;
  15330. t['yacute'] = 500;
  15331. t['scommaaccent'] = 389;
  15332. t['ecircumflex'] = 444;
  15333. t['Uring'] = 722;
  15334. t['Udieresis'] = 722;
  15335. t['aogonek'] = 444;
  15336. t['Uacute'] = 722;
  15337. t['uogonek'] = 500;
  15338. t['Edieresis'] = 611;
  15339. t['Dcroat'] = 722;
  15340. t['commaaccent'] = 250;
  15341. t['copyright'] = 760;
  15342. t['Emacron'] = 611;
  15343. t['ccaron'] = 444;
  15344. t['aring'] = 444;
  15345. t['Ncommaaccent'] = 722;
  15346. t['lacute'] = 278;
  15347. t['agrave'] = 444;
  15348. t['Tcommaaccent'] = 611;
  15349. t['Cacute'] = 667;
  15350. t['atilde'] = 444;
  15351. t['Edotaccent'] = 611;
  15352. t['scaron'] = 389;
  15353. t['scedilla'] = 389;
  15354. t['iacute'] = 278;
  15355. t['lozenge'] = 471;
  15356. t['Rcaron'] = 667;
  15357. t['Gcommaaccent'] = 722;
  15358. t['ucircumflex'] = 500;
  15359. t['acircumflex'] = 444;
  15360. t['Amacron'] = 722;
  15361. t['rcaron'] = 333;
  15362. t['ccedilla'] = 444;
  15363. t['Zdotaccent'] = 611;
  15364. t['Thorn'] = 556;
  15365. t['Omacron'] = 722;
  15366. t['Racute'] = 667;
  15367. t['Sacute'] = 556;
  15368. t['dcaron'] = 588;
  15369. t['Umacron'] = 722;
  15370. t['uring'] = 500;
  15371. t['threesuperior'] = 300;
  15372. t['Ograve'] = 722;
  15373. t['Agrave'] = 722;
  15374. t['Abreve'] = 722;
  15375. t['multiply'] = 564;
  15376. t['uacute'] = 500;
  15377. t['Tcaron'] = 611;
  15378. t['partialdiff'] = 476;
  15379. t['ydieresis'] = 500;
  15380. t['Nacute'] = 722;
  15381. t['icircumflex'] = 278;
  15382. t['Ecircumflex'] = 611;
  15383. t['adieresis'] = 444;
  15384. t['edieresis'] = 444;
  15385. t['cacute'] = 444;
  15386. t['nacute'] = 500;
  15387. t['umacron'] = 500;
  15388. t['Ncaron'] = 722;
  15389. t['Iacute'] = 333;
  15390. t['plusminus'] = 564;
  15391. t['brokenbar'] = 200;
  15392. t['registered'] = 760;
  15393. t['Gbreve'] = 722;
  15394. t['Idotaccent'] = 333;
  15395. t['summation'] = 600;
  15396. t['Egrave'] = 611;
  15397. t['racute'] = 333;
  15398. t['omacron'] = 500;
  15399. t['Zacute'] = 611;
  15400. t['Zcaron'] = 611;
  15401. t['greaterequal'] = 549;
  15402. t['Eth'] = 722;
  15403. t['Ccedilla'] = 667;
  15404. t['lcommaaccent'] = 278;
  15405. t['tcaron'] = 326;
  15406. t['eogonek'] = 444;
  15407. t['Uogonek'] = 722;
  15408. t['Aacute'] = 722;
  15409. t['Adieresis'] = 722;
  15410. t['egrave'] = 444;
  15411. t['zacute'] = 444;
  15412. t['iogonek'] = 278;
  15413. t['Oacute'] = 722;
  15414. t['oacute'] = 500;
  15415. t['amacron'] = 444;
  15416. t['sacute'] = 389;
  15417. t['idieresis'] = 278;
  15418. t['Ocircumflex'] = 722;
  15419. t['Ugrave'] = 722;
  15420. t['Delta'] = 612;
  15421. t['thorn'] = 500;
  15422. t['twosuperior'] = 300;
  15423. t['Odieresis'] = 722;
  15424. t['mu'] = 500;
  15425. t['igrave'] = 278;
  15426. t['ohungarumlaut'] = 500;
  15427. t['Eogonek'] = 611;
  15428. t['dcroat'] = 500;
  15429. t['threequarters'] = 750;
  15430. t['Scedilla'] = 556;
  15431. t['lcaron'] = 344;
  15432. t['Kcommaaccent'] = 722;
  15433. t['Lacute'] = 611;
  15434. t['trademark'] = 980;
  15435. t['edotaccent'] = 444;
  15436. t['Igrave'] = 333;
  15437. t['Imacron'] = 333;
  15438. t['Lcaron'] = 611;
  15439. t['onehalf'] = 750;
  15440. t['lessequal'] = 549;
  15441. t['ocircumflex'] = 500;
  15442. t['ntilde'] = 500;
  15443. t['Uhungarumlaut'] = 722;
  15444. t['Eacute'] = 611;
  15445. t['emacron'] = 444;
  15446. t['gbreve'] = 500;
  15447. t['onequarter'] = 750;
  15448. t['Scaron'] = 556;
  15449. t['Scommaaccent'] = 556;
  15450. t['Ohungarumlaut'] = 722;
  15451. t['degree'] = 400;
  15452. t['ograve'] = 500;
  15453. t['Ccaron'] = 667;
  15454. t['ugrave'] = 500;
  15455. t['radical'] = 453;
  15456. t['Dcaron'] = 722;
  15457. t['rcommaaccent'] = 333;
  15458. t['Ntilde'] = 722;
  15459. t['otilde'] = 500;
  15460. t['Rcommaaccent'] = 667;
  15461. t['Lcommaaccent'] = 611;
  15462. t['Atilde'] = 722;
  15463. t['Aogonek'] = 722;
  15464. t['Aring'] = 722;
  15465. t['Otilde'] = 722;
  15466. t['zdotaccent'] = 444;
  15467. t['Ecaron'] = 611;
  15468. t['Iogonek'] = 333;
  15469. t['kcommaaccent'] = 500;
  15470. t['minus'] = 564;
  15471. t['Icircumflex'] = 333;
  15472. t['ncaron'] = 500;
  15473. t['tcommaaccent'] = 278;
  15474. t['logicalnot'] = 564;
  15475. t['odieresis'] = 500;
  15476. t['udieresis'] = 500;
  15477. t['notequal'] = 549;
  15478. t['gcommaaccent'] = 500;
  15479. t['eth'] = 500;
  15480. t['zcaron'] = 444;
  15481. t['ncommaaccent'] = 500;
  15482. t['onesuperior'] = 300;
  15483. t['imacron'] = 278;
  15484. t['Euro'] = 500;
  15485. });
  15486. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15487. t['space'] = 250;
  15488. t['exclam'] = 333;
  15489. t['quotedbl'] = 555;
  15490. t['numbersign'] = 500;
  15491. t['dollar'] = 500;
  15492. t['percent'] = 1000;
  15493. t['ampersand'] = 833;
  15494. t['quoteright'] = 333;
  15495. t['parenleft'] = 333;
  15496. t['parenright'] = 333;
  15497. t['asterisk'] = 500;
  15498. t['plus'] = 570;
  15499. t['comma'] = 250;
  15500. t['hyphen'] = 333;
  15501. t['period'] = 250;
  15502. t['slash'] = 278;
  15503. t['zero'] = 500;
  15504. t['one'] = 500;
  15505. t['two'] = 500;
  15506. t['three'] = 500;
  15507. t['four'] = 500;
  15508. t['five'] = 500;
  15509. t['six'] = 500;
  15510. t['seven'] = 500;
  15511. t['eight'] = 500;
  15512. t['nine'] = 500;
  15513. t['colon'] = 333;
  15514. t['semicolon'] = 333;
  15515. t['less'] = 570;
  15516. t['equal'] = 570;
  15517. t['greater'] = 570;
  15518. t['question'] = 500;
  15519. t['at'] = 930;
  15520. t['A'] = 722;
  15521. t['B'] = 667;
  15522. t['C'] = 722;
  15523. t['D'] = 722;
  15524. t['E'] = 667;
  15525. t['F'] = 611;
  15526. t['G'] = 778;
  15527. t['H'] = 778;
  15528. t['I'] = 389;
  15529. t['J'] = 500;
  15530. t['K'] = 778;
  15531. t['L'] = 667;
  15532. t['M'] = 944;
  15533. t['N'] = 722;
  15534. t['O'] = 778;
  15535. t['P'] = 611;
  15536. t['Q'] = 778;
  15537. t['R'] = 722;
  15538. t['S'] = 556;
  15539. t['T'] = 667;
  15540. t['U'] = 722;
  15541. t['V'] = 722;
  15542. t['W'] = 1000;
  15543. t['X'] = 722;
  15544. t['Y'] = 722;
  15545. t['Z'] = 667;
  15546. t['bracketleft'] = 333;
  15547. t['backslash'] = 278;
  15548. t['bracketright'] = 333;
  15549. t['asciicircum'] = 581;
  15550. t['underscore'] = 500;
  15551. t['quoteleft'] = 333;
  15552. t['a'] = 500;
  15553. t['b'] = 556;
  15554. t['c'] = 444;
  15555. t['d'] = 556;
  15556. t['e'] = 444;
  15557. t['f'] = 333;
  15558. t['g'] = 500;
  15559. t['h'] = 556;
  15560. t['i'] = 278;
  15561. t['j'] = 333;
  15562. t['k'] = 556;
  15563. t['l'] = 278;
  15564. t['m'] = 833;
  15565. t['n'] = 556;
  15566. t['o'] = 500;
  15567. t['p'] = 556;
  15568. t['q'] = 556;
  15569. t['r'] = 444;
  15570. t['s'] = 389;
  15571. t['t'] = 333;
  15572. t['u'] = 556;
  15573. t['v'] = 500;
  15574. t['w'] = 722;
  15575. t['x'] = 500;
  15576. t['y'] = 500;
  15577. t['z'] = 444;
  15578. t['braceleft'] = 394;
  15579. t['bar'] = 220;
  15580. t['braceright'] = 394;
  15581. t['asciitilde'] = 520;
  15582. t['exclamdown'] = 333;
  15583. t['cent'] = 500;
  15584. t['sterling'] = 500;
  15585. t['fraction'] = 167;
  15586. t['yen'] = 500;
  15587. t['florin'] = 500;
  15588. t['section'] = 500;
  15589. t['currency'] = 500;
  15590. t['quotesingle'] = 278;
  15591. t['quotedblleft'] = 500;
  15592. t['guillemotleft'] = 500;
  15593. t['guilsinglleft'] = 333;
  15594. t['guilsinglright'] = 333;
  15595. t['fi'] = 556;
  15596. t['fl'] = 556;
  15597. t['endash'] = 500;
  15598. t['dagger'] = 500;
  15599. t['daggerdbl'] = 500;
  15600. t['periodcentered'] = 250;
  15601. t['paragraph'] = 540;
  15602. t['bullet'] = 350;
  15603. t['quotesinglbase'] = 333;
  15604. t['quotedblbase'] = 500;
  15605. t['quotedblright'] = 500;
  15606. t['guillemotright'] = 500;
  15607. t['ellipsis'] = 1000;
  15608. t['perthousand'] = 1000;
  15609. t['questiondown'] = 500;
  15610. t['grave'] = 333;
  15611. t['acute'] = 333;
  15612. t['circumflex'] = 333;
  15613. t['tilde'] = 333;
  15614. t['macron'] = 333;
  15615. t['breve'] = 333;
  15616. t['dotaccent'] = 333;
  15617. t['dieresis'] = 333;
  15618. t['ring'] = 333;
  15619. t['cedilla'] = 333;
  15620. t['hungarumlaut'] = 333;
  15621. t['ogonek'] = 333;
  15622. t['caron'] = 333;
  15623. t['emdash'] = 1000;
  15624. t['AE'] = 1000;
  15625. t['ordfeminine'] = 300;
  15626. t['Lslash'] = 667;
  15627. t['Oslash'] = 778;
  15628. t['OE'] = 1000;
  15629. t['ordmasculine'] = 330;
  15630. t['ae'] = 722;
  15631. t['dotlessi'] = 278;
  15632. t['lslash'] = 278;
  15633. t['oslash'] = 500;
  15634. t['oe'] = 722;
  15635. t['germandbls'] = 556;
  15636. t['Idieresis'] = 389;
  15637. t['eacute'] = 444;
  15638. t['abreve'] = 500;
  15639. t['uhungarumlaut'] = 556;
  15640. t['ecaron'] = 444;
  15641. t['Ydieresis'] = 722;
  15642. t['divide'] = 570;
  15643. t['Yacute'] = 722;
  15644. t['Acircumflex'] = 722;
  15645. t['aacute'] = 500;
  15646. t['Ucircumflex'] = 722;
  15647. t['yacute'] = 500;
  15648. t['scommaaccent'] = 389;
  15649. t['ecircumflex'] = 444;
  15650. t['Uring'] = 722;
  15651. t['Udieresis'] = 722;
  15652. t['aogonek'] = 500;
  15653. t['Uacute'] = 722;
  15654. t['uogonek'] = 556;
  15655. t['Edieresis'] = 667;
  15656. t['Dcroat'] = 722;
  15657. t['commaaccent'] = 250;
  15658. t['copyright'] = 747;
  15659. t['Emacron'] = 667;
  15660. t['ccaron'] = 444;
  15661. t['aring'] = 500;
  15662. t['Ncommaaccent'] = 722;
  15663. t['lacute'] = 278;
  15664. t['agrave'] = 500;
  15665. t['Tcommaaccent'] = 667;
  15666. t['Cacute'] = 722;
  15667. t['atilde'] = 500;
  15668. t['Edotaccent'] = 667;
  15669. t['scaron'] = 389;
  15670. t['scedilla'] = 389;
  15671. t['iacute'] = 278;
  15672. t['lozenge'] = 494;
  15673. t['Rcaron'] = 722;
  15674. t['Gcommaaccent'] = 778;
  15675. t['ucircumflex'] = 556;
  15676. t['acircumflex'] = 500;
  15677. t['Amacron'] = 722;
  15678. t['rcaron'] = 444;
  15679. t['ccedilla'] = 444;
  15680. t['Zdotaccent'] = 667;
  15681. t['Thorn'] = 611;
  15682. t['Omacron'] = 778;
  15683. t['Racute'] = 722;
  15684. t['Sacute'] = 556;
  15685. t['dcaron'] = 672;
  15686. t['Umacron'] = 722;
  15687. t['uring'] = 556;
  15688. t['threesuperior'] = 300;
  15689. t['Ograve'] = 778;
  15690. t['Agrave'] = 722;
  15691. t['Abreve'] = 722;
  15692. t['multiply'] = 570;
  15693. t['uacute'] = 556;
  15694. t['Tcaron'] = 667;
  15695. t['partialdiff'] = 494;
  15696. t['ydieresis'] = 500;
  15697. t['Nacute'] = 722;
  15698. t['icircumflex'] = 278;
  15699. t['Ecircumflex'] = 667;
  15700. t['adieresis'] = 500;
  15701. t['edieresis'] = 444;
  15702. t['cacute'] = 444;
  15703. t['nacute'] = 556;
  15704. t['umacron'] = 556;
  15705. t['Ncaron'] = 722;
  15706. t['Iacute'] = 389;
  15707. t['plusminus'] = 570;
  15708. t['brokenbar'] = 220;
  15709. t['registered'] = 747;
  15710. t['Gbreve'] = 778;
  15711. t['Idotaccent'] = 389;
  15712. t['summation'] = 600;
  15713. t['Egrave'] = 667;
  15714. t['racute'] = 444;
  15715. t['omacron'] = 500;
  15716. t['Zacute'] = 667;
  15717. t['Zcaron'] = 667;
  15718. t['greaterequal'] = 549;
  15719. t['Eth'] = 722;
  15720. t['Ccedilla'] = 722;
  15721. t['lcommaaccent'] = 278;
  15722. t['tcaron'] = 416;
  15723. t['eogonek'] = 444;
  15724. t['Uogonek'] = 722;
  15725. t['Aacute'] = 722;
  15726. t['Adieresis'] = 722;
  15727. t['egrave'] = 444;
  15728. t['zacute'] = 444;
  15729. t['iogonek'] = 278;
  15730. t['Oacute'] = 778;
  15731. t['oacute'] = 500;
  15732. t['amacron'] = 500;
  15733. t['sacute'] = 389;
  15734. t['idieresis'] = 278;
  15735. t['Ocircumflex'] = 778;
  15736. t['Ugrave'] = 722;
  15737. t['Delta'] = 612;
  15738. t['thorn'] = 556;
  15739. t['twosuperior'] = 300;
  15740. t['Odieresis'] = 778;
  15741. t['mu'] = 556;
  15742. t['igrave'] = 278;
  15743. t['ohungarumlaut'] = 500;
  15744. t['Eogonek'] = 667;
  15745. t['dcroat'] = 556;
  15746. t['threequarters'] = 750;
  15747. t['Scedilla'] = 556;
  15748. t['lcaron'] = 394;
  15749. t['Kcommaaccent'] = 778;
  15750. t['Lacute'] = 667;
  15751. t['trademark'] = 1000;
  15752. t['edotaccent'] = 444;
  15753. t['Igrave'] = 389;
  15754. t['Imacron'] = 389;
  15755. t['Lcaron'] = 667;
  15756. t['onehalf'] = 750;
  15757. t['lessequal'] = 549;
  15758. t['ocircumflex'] = 500;
  15759. t['ntilde'] = 556;
  15760. t['Uhungarumlaut'] = 722;
  15761. t['Eacute'] = 667;
  15762. t['emacron'] = 444;
  15763. t['gbreve'] = 500;
  15764. t['onequarter'] = 750;
  15765. t['Scaron'] = 556;
  15766. t['Scommaaccent'] = 556;
  15767. t['Ohungarumlaut'] = 778;
  15768. t['degree'] = 400;
  15769. t['ograve'] = 500;
  15770. t['Ccaron'] = 722;
  15771. t['ugrave'] = 556;
  15772. t['radical'] = 549;
  15773. t['Dcaron'] = 722;
  15774. t['rcommaaccent'] = 444;
  15775. t['Ntilde'] = 722;
  15776. t['otilde'] = 500;
  15777. t['Rcommaaccent'] = 722;
  15778. t['Lcommaaccent'] = 667;
  15779. t['Atilde'] = 722;
  15780. t['Aogonek'] = 722;
  15781. t['Aring'] = 722;
  15782. t['Otilde'] = 778;
  15783. t['zdotaccent'] = 444;
  15784. t['Ecaron'] = 667;
  15785. t['Iogonek'] = 389;
  15786. t['kcommaaccent'] = 556;
  15787. t['minus'] = 570;
  15788. t['Icircumflex'] = 389;
  15789. t['ncaron'] = 556;
  15790. t['tcommaaccent'] = 333;
  15791. t['logicalnot'] = 570;
  15792. t['odieresis'] = 500;
  15793. t['udieresis'] = 556;
  15794. t['notequal'] = 549;
  15795. t['gcommaaccent'] = 500;
  15796. t['eth'] = 500;
  15797. t['zcaron'] = 444;
  15798. t['ncommaaccent'] = 556;
  15799. t['onesuperior'] = 300;
  15800. t['imacron'] = 278;
  15801. t['Euro'] = 500;
  15802. });
  15803. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15804. t['space'] = 250;
  15805. t['exclam'] = 389;
  15806. t['quotedbl'] = 555;
  15807. t['numbersign'] = 500;
  15808. t['dollar'] = 500;
  15809. t['percent'] = 833;
  15810. t['ampersand'] = 778;
  15811. t['quoteright'] = 333;
  15812. t['parenleft'] = 333;
  15813. t['parenright'] = 333;
  15814. t['asterisk'] = 500;
  15815. t['plus'] = 570;
  15816. t['comma'] = 250;
  15817. t['hyphen'] = 333;
  15818. t['period'] = 250;
  15819. t['slash'] = 278;
  15820. t['zero'] = 500;
  15821. t['one'] = 500;
  15822. t['two'] = 500;
  15823. t['three'] = 500;
  15824. t['four'] = 500;
  15825. t['five'] = 500;
  15826. t['six'] = 500;
  15827. t['seven'] = 500;
  15828. t['eight'] = 500;
  15829. t['nine'] = 500;
  15830. t['colon'] = 333;
  15831. t['semicolon'] = 333;
  15832. t['less'] = 570;
  15833. t['equal'] = 570;
  15834. t['greater'] = 570;
  15835. t['question'] = 500;
  15836. t['at'] = 832;
  15837. t['A'] = 667;
  15838. t['B'] = 667;
  15839. t['C'] = 667;
  15840. t['D'] = 722;
  15841. t['E'] = 667;
  15842. t['F'] = 667;
  15843. t['G'] = 722;
  15844. t['H'] = 778;
  15845. t['I'] = 389;
  15846. t['J'] = 500;
  15847. t['K'] = 667;
  15848. t['L'] = 611;
  15849. t['M'] = 889;
  15850. t['N'] = 722;
  15851. t['O'] = 722;
  15852. t['P'] = 611;
  15853. t['Q'] = 722;
  15854. t['R'] = 667;
  15855. t['S'] = 556;
  15856. t['T'] = 611;
  15857. t['U'] = 722;
  15858. t['V'] = 667;
  15859. t['W'] = 889;
  15860. t['X'] = 667;
  15861. t['Y'] = 611;
  15862. t['Z'] = 611;
  15863. t['bracketleft'] = 333;
  15864. t['backslash'] = 278;
  15865. t['bracketright'] = 333;
  15866. t['asciicircum'] = 570;
  15867. t['underscore'] = 500;
  15868. t['quoteleft'] = 333;
  15869. t['a'] = 500;
  15870. t['b'] = 500;
  15871. t['c'] = 444;
  15872. t['d'] = 500;
  15873. t['e'] = 444;
  15874. t['f'] = 333;
  15875. t['g'] = 500;
  15876. t['h'] = 556;
  15877. t['i'] = 278;
  15878. t['j'] = 278;
  15879. t['k'] = 500;
  15880. t['l'] = 278;
  15881. t['m'] = 778;
  15882. t['n'] = 556;
  15883. t['o'] = 500;
  15884. t['p'] = 500;
  15885. t['q'] = 500;
  15886. t['r'] = 389;
  15887. t['s'] = 389;
  15888. t['t'] = 278;
  15889. t['u'] = 556;
  15890. t['v'] = 444;
  15891. t['w'] = 667;
  15892. t['x'] = 500;
  15893. t['y'] = 444;
  15894. t['z'] = 389;
  15895. t['braceleft'] = 348;
  15896. t['bar'] = 220;
  15897. t['braceright'] = 348;
  15898. t['asciitilde'] = 570;
  15899. t['exclamdown'] = 389;
  15900. t['cent'] = 500;
  15901. t['sterling'] = 500;
  15902. t['fraction'] = 167;
  15903. t['yen'] = 500;
  15904. t['florin'] = 500;
  15905. t['section'] = 500;
  15906. t['currency'] = 500;
  15907. t['quotesingle'] = 278;
  15908. t['quotedblleft'] = 500;
  15909. t['guillemotleft'] = 500;
  15910. t['guilsinglleft'] = 333;
  15911. t['guilsinglright'] = 333;
  15912. t['fi'] = 556;
  15913. t['fl'] = 556;
  15914. t['endash'] = 500;
  15915. t['dagger'] = 500;
  15916. t['daggerdbl'] = 500;
  15917. t['periodcentered'] = 250;
  15918. t['paragraph'] = 500;
  15919. t['bullet'] = 350;
  15920. t['quotesinglbase'] = 333;
  15921. t['quotedblbase'] = 500;
  15922. t['quotedblright'] = 500;
  15923. t['guillemotright'] = 500;
  15924. t['ellipsis'] = 1000;
  15925. t['perthousand'] = 1000;
  15926. t['questiondown'] = 500;
  15927. t['grave'] = 333;
  15928. t['acute'] = 333;
  15929. t['circumflex'] = 333;
  15930. t['tilde'] = 333;
  15931. t['macron'] = 333;
  15932. t['breve'] = 333;
  15933. t['dotaccent'] = 333;
  15934. t['dieresis'] = 333;
  15935. t['ring'] = 333;
  15936. t['cedilla'] = 333;
  15937. t['hungarumlaut'] = 333;
  15938. t['ogonek'] = 333;
  15939. t['caron'] = 333;
  15940. t['emdash'] = 1000;
  15941. t['AE'] = 944;
  15942. t['ordfeminine'] = 266;
  15943. t['Lslash'] = 611;
  15944. t['Oslash'] = 722;
  15945. t['OE'] = 944;
  15946. t['ordmasculine'] = 300;
  15947. t['ae'] = 722;
  15948. t['dotlessi'] = 278;
  15949. t['lslash'] = 278;
  15950. t['oslash'] = 500;
  15951. t['oe'] = 722;
  15952. t['germandbls'] = 500;
  15953. t['Idieresis'] = 389;
  15954. t['eacute'] = 444;
  15955. t['abreve'] = 500;
  15956. t['uhungarumlaut'] = 556;
  15957. t['ecaron'] = 444;
  15958. t['Ydieresis'] = 611;
  15959. t['divide'] = 570;
  15960. t['Yacute'] = 611;
  15961. t['Acircumflex'] = 667;
  15962. t['aacute'] = 500;
  15963. t['Ucircumflex'] = 722;
  15964. t['yacute'] = 444;
  15965. t['scommaaccent'] = 389;
  15966. t['ecircumflex'] = 444;
  15967. t['Uring'] = 722;
  15968. t['Udieresis'] = 722;
  15969. t['aogonek'] = 500;
  15970. t['Uacute'] = 722;
  15971. t['uogonek'] = 556;
  15972. t['Edieresis'] = 667;
  15973. t['Dcroat'] = 722;
  15974. t['commaaccent'] = 250;
  15975. t['copyright'] = 747;
  15976. t['Emacron'] = 667;
  15977. t['ccaron'] = 444;
  15978. t['aring'] = 500;
  15979. t['Ncommaaccent'] = 722;
  15980. t['lacute'] = 278;
  15981. t['agrave'] = 500;
  15982. t['Tcommaaccent'] = 611;
  15983. t['Cacute'] = 667;
  15984. t['atilde'] = 500;
  15985. t['Edotaccent'] = 667;
  15986. t['scaron'] = 389;
  15987. t['scedilla'] = 389;
  15988. t['iacute'] = 278;
  15989. t['lozenge'] = 494;
  15990. t['Rcaron'] = 667;
  15991. t['Gcommaaccent'] = 722;
  15992. t['ucircumflex'] = 556;
  15993. t['acircumflex'] = 500;
  15994. t['Amacron'] = 667;
  15995. t['rcaron'] = 389;
  15996. t['ccedilla'] = 444;
  15997. t['Zdotaccent'] = 611;
  15998. t['Thorn'] = 611;
  15999. t['Omacron'] = 722;
  16000. t['Racute'] = 667;
  16001. t['Sacute'] = 556;
  16002. t['dcaron'] = 608;
  16003. t['Umacron'] = 722;
  16004. t['uring'] = 556;
  16005. t['threesuperior'] = 300;
  16006. t['Ograve'] = 722;
  16007. t['Agrave'] = 667;
  16008. t['Abreve'] = 667;
  16009. t['multiply'] = 570;
  16010. t['uacute'] = 556;
  16011. t['Tcaron'] = 611;
  16012. t['partialdiff'] = 494;
  16013. t['ydieresis'] = 444;
  16014. t['Nacute'] = 722;
  16015. t['icircumflex'] = 278;
  16016. t['Ecircumflex'] = 667;
  16017. t['adieresis'] = 500;
  16018. t['edieresis'] = 444;
  16019. t['cacute'] = 444;
  16020. t['nacute'] = 556;
  16021. t['umacron'] = 556;
  16022. t['Ncaron'] = 722;
  16023. t['Iacute'] = 389;
  16024. t['plusminus'] = 570;
  16025. t['brokenbar'] = 220;
  16026. t['registered'] = 747;
  16027. t['Gbreve'] = 722;
  16028. t['Idotaccent'] = 389;
  16029. t['summation'] = 600;
  16030. t['Egrave'] = 667;
  16031. t['racute'] = 389;
  16032. t['omacron'] = 500;
  16033. t['Zacute'] = 611;
  16034. t['Zcaron'] = 611;
  16035. t['greaterequal'] = 549;
  16036. t['Eth'] = 722;
  16037. t['Ccedilla'] = 667;
  16038. t['lcommaaccent'] = 278;
  16039. t['tcaron'] = 366;
  16040. t['eogonek'] = 444;
  16041. t['Uogonek'] = 722;
  16042. t['Aacute'] = 667;
  16043. t['Adieresis'] = 667;
  16044. t['egrave'] = 444;
  16045. t['zacute'] = 389;
  16046. t['iogonek'] = 278;
  16047. t['Oacute'] = 722;
  16048. t['oacute'] = 500;
  16049. t['amacron'] = 500;
  16050. t['sacute'] = 389;
  16051. t['idieresis'] = 278;
  16052. t['Ocircumflex'] = 722;
  16053. t['Ugrave'] = 722;
  16054. t['Delta'] = 612;
  16055. t['thorn'] = 500;
  16056. t['twosuperior'] = 300;
  16057. t['Odieresis'] = 722;
  16058. t['mu'] = 576;
  16059. t['igrave'] = 278;
  16060. t['ohungarumlaut'] = 500;
  16061. t['Eogonek'] = 667;
  16062. t['dcroat'] = 500;
  16063. t['threequarters'] = 750;
  16064. t['Scedilla'] = 556;
  16065. t['lcaron'] = 382;
  16066. t['Kcommaaccent'] = 667;
  16067. t['Lacute'] = 611;
  16068. t['trademark'] = 1000;
  16069. t['edotaccent'] = 444;
  16070. t['Igrave'] = 389;
  16071. t['Imacron'] = 389;
  16072. t['Lcaron'] = 611;
  16073. t['onehalf'] = 750;
  16074. t['lessequal'] = 549;
  16075. t['ocircumflex'] = 500;
  16076. t['ntilde'] = 556;
  16077. t['Uhungarumlaut'] = 722;
  16078. t['Eacute'] = 667;
  16079. t['emacron'] = 444;
  16080. t['gbreve'] = 500;
  16081. t['onequarter'] = 750;
  16082. t['Scaron'] = 556;
  16083. t['Scommaaccent'] = 556;
  16084. t['Ohungarumlaut'] = 722;
  16085. t['degree'] = 400;
  16086. t['ograve'] = 500;
  16087. t['Ccaron'] = 667;
  16088. t['ugrave'] = 556;
  16089. t['radical'] = 549;
  16090. t['Dcaron'] = 722;
  16091. t['rcommaaccent'] = 389;
  16092. t['Ntilde'] = 722;
  16093. t['otilde'] = 500;
  16094. t['Rcommaaccent'] = 667;
  16095. t['Lcommaaccent'] = 611;
  16096. t['Atilde'] = 667;
  16097. t['Aogonek'] = 667;
  16098. t['Aring'] = 667;
  16099. t['Otilde'] = 722;
  16100. t['zdotaccent'] = 389;
  16101. t['Ecaron'] = 667;
  16102. t['Iogonek'] = 389;
  16103. t['kcommaaccent'] = 500;
  16104. t['minus'] = 606;
  16105. t['Icircumflex'] = 389;
  16106. t['ncaron'] = 556;
  16107. t['tcommaaccent'] = 278;
  16108. t['logicalnot'] = 606;
  16109. t['odieresis'] = 500;
  16110. t['udieresis'] = 556;
  16111. t['notequal'] = 549;
  16112. t['gcommaaccent'] = 500;
  16113. t['eth'] = 500;
  16114. t['zcaron'] = 389;
  16115. t['ncommaaccent'] = 556;
  16116. t['onesuperior'] = 300;
  16117. t['imacron'] = 278;
  16118. t['Euro'] = 500;
  16119. });
  16120. t['Times-Italic'] = getLookupTableFactory(function (t) {
  16121. t['space'] = 250;
  16122. t['exclam'] = 333;
  16123. t['quotedbl'] = 420;
  16124. t['numbersign'] = 500;
  16125. t['dollar'] = 500;
  16126. t['percent'] = 833;
  16127. t['ampersand'] = 778;
  16128. t['quoteright'] = 333;
  16129. t['parenleft'] = 333;
  16130. t['parenright'] = 333;
  16131. t['asterisk'] = 500;
  16132. t['plus'] = 675;
  16133. t['comma'] = 250;
  16134. t['hyphen'] = 333;
  16135. t['period'] = 250;
  16136. t['slash'] = 278;
  16137. t['zero'] = 500;
  16138. t['one'] = 500;
  16139. t['two'] = 500;
  16140. t['three'] = 500;
  16141. t['four'] = 500;
  16142. t['five'] = 500;
  16143. t['six'] = 500;
  16144. t['seven'] = 500;
  16145. t['eight'] = 500;
  16146. t['nine'] = 500;
  16147. t['colon'] = 333;
  16148. t['semicolon'] = 333;
  16149. t['less'] = 675;
  16150. t['equal'] = 675;
  16151. t['greater'] = 675;
  16152. t['question'] = 500;
  16153. t['at'] = 920;
  16154. t['A'] = 611;
  16155. t['B'] = 611;
  16156. t['C'] = 667;
  16157. t['D'] = 722;
  16158. t['E'] = 611;
  16159. t['F'] = 611;
  16160. t['G'] = 722;
  16161. t['H'] = 722;
  16162. t['I'] = 333;
  16163. t['J'] = 444;
  16164. t['K'] = 667;
  16165. t['L'] = 556;
  16166. t['M'] = 833;
  16167. t['N'] = 667;
  16168. t['O'] = 722;
  16169. t['P'] = 611;
  16170. t['Q'] = 722;
  16171. t['R'] = 611;
  16172. t['S'] = 500;
  16173. t['T'] = 556;
  16174. t['U'] = 722;
  16175. t['V'] = 611;
  16176. t['W'] = 833;
  16177. t['X'] = 611;
  16178. t['Y'] = 556;
  16179. t['Z'] = 556;
  16180. t['bracketleft'] = 389;
  16181. t['backslash'] = 278;
  16182. t['bracketright'] = 389;
  16183. t['asciicircum'] = 422;
  16184. t['underscore'] = 500;
  16185. t['quoteleft'] = 333;
  16186. t['a'] = 500;
  16187. t['b'] = 500;
  16188. t['c'] = 444;
  16189. t['d'] = 500;
  16190. t['e'] = 444;
  16191. t['f'] = 278;
  16192. t['g'] = 500;
  16193. t['h'] = 500;
  16194. t['i'] = 278;
  16195. t['j'] = 278;
  16196. t['k'] = 444;
  16197. t['l'] = 278;
  16198. t['m'] = 722;
  16199. t['n'] = 500;
  16200. t['o'] = 500;
  16201. t['p'] = 500;
  16202. t['q'] = 500;
  16203. t['r'] = 389;
  16204. t['s'] = 389;
  16205. t['t'] = 278;
  16206. t['u'] = 500;
  16207. t['v'] = 444;
  16208. t['w'] = 667;
  16209. t['x'] = 444;
  16210. t['y'] = 444;
  16211. t['z'] = 389;
  16212. t['braceleft'] = 400;
  16213. t['bar'] = 275;
  16214. t['braceright'] = 400;
  16215. t['asciitilde'] = 541;
  16216. t['exclamdown'] = 389;
  16217. t['cent'] = 500;
  16218. t['sterling'] = 500;
  16219. t['fraction'] = 167;
  16220. t['yen'] = 500;
  16221. t['florin'] = 500;
  16222. t['section'] = 500;
  16223. t['currency'] = 500;
  16224. t['quotesingle'] = 214;
  16225. t['quotedblleft'] = 556;
  16226. t['guillemotleft'] = 500;
  16227. t['guilsinglleft'] = 333;
  16228. t['guilsinglright'] = 333;
  16229. t['fi'] = 500;
  16230. t['fl'] = 500;
  16231. t['endash'] = 500;
  16232. t['dagger'] = 500;
  16233. t['daggerdbl'] = 500;
  16234. t['periodcentered'] = 250;
  16235. t['paragraph'] = 523;
  16236. t['bullet'] = 350;
  16237. t['quotesinglbase'] = 333;
  16238. t['quotedblbase'] = 556;
  16239. t['quotedblright'] = 556;
  16240. t['guillemotright'] = 500;
  16241. t['ellipsis'] = 889;
  16242. t['perthousand'] = 1000;
  16243. t['questiondown'] = 500;
  16244. t['grave'] = 333;
  16245. t['acute'] = 333;
  16246. t['circumflex'] = 333;
  16247. t['tilde'] = 333;
  16248. t['macron'] = 333;
  16249. t['breve'] = 333;
  16250. t['dotaccent'] = 333;
  16251. t['dieresis'] = 333;
  16252. t['ring'] = 333;
  16253. t['cedilla'] = 333;
  16254. t['hungarumlaut'] = 333;
  16255. t['ogonek'] = 333;
  16256. t['caron'] = 333;
  16257. t['emdash'] = 889;
  16258. t['AE'] = 889;
  16259. t['ordfeminine'] = 276;
  16260. t['Lslash'] = 556;
  16261. t['Oslash'] = 722;
  16262. t['OE'] = 944;
  16263. t['ordmasculine'] = 310;
  16264. t['ae'] = 667;
  16265. t['dotlessi'] = 278;
  16266. t['lslash'] = 278;
  16267. t['oslash'] = 500;
  16268. t['oe'] = 667;
  16269. t['germandbls'] = 500;
  16270. t['Idieresis'] = 333;
  16271. t['eacute'] = 444;
  16272. t['abreve'] = 500;
  16273. t['uhungarumlaut'] = 500;
  16274. t['ecaron'] = 444;
  16275. t['Ydieresis'] = 556;
  16276. t['divide'] = 675;
  16277. t['Yacute'] = 556;
  16278. t['Acircumflex'] = 611;
  16279. t['aacute'] = 500;
  16280. t['Ucircumflex'] = 722;
  16281. t['yacute'] = 444;
  16282. t['scommaaccent'] = 389;
  16283. t['ecircumflex'] = 444;
  16284. t['Uring'] = 722;
  16285. t['Udieresis'] = 722;
  16286. t['aogonek'] = 500;
  16287. t['Uacute'] = 722;
  16288. t['uogonek'] = 500;
  16289. t['Edieresis'] = 611;
  16290. t['Dcroat'] = 722;
  16291. t['commaaccent'] = 250;
  16292. t['copyright'] = 760;
  16293. t['Emacron'] = 611;
  16294. t['ccaron'] = 444;
  16295. t['aring'] = 500;
  16296. t['Ncommaaccent'] = 667;
  16297. t['lacute'] = 278;
  16298. t['agrave'] = 500;
  16299. t['Tcommaaccent'] = 556;
  16300. t['Cacute'] = 667;
  16301. t['atilde'] = 500;
  16302. t['Edotaccent'] = 611;
  16303. t['scaron'] = 389;
  16304. t['scedilla'] = 389;
  16305. t['iacute'] = 278;
  16306. t['lozenge'] = 471;
  16307. t['Rcaron'] = 611;
  16308. t['Gcommaaccent'] = 722;
  16309. t['ucircumflex'] = 500;
  16310. t['acircumflex'] = 500;
  16311. t['Amacron'] = 611;
  16312. t['rcaron'] = 389;
  16313. t['ccedilla'] = 444;
  16314. t['Zdotaccent'] = 556;
  16315. t['Thorn'] = 611;
  16316. t['Omacron'] = 722;
  16317. t['Racute'] = 611;
  16318. t['Sacute'] = 500;
  16319. t['dcaron'] = 544;
  16320. t['Umacron'] = 722;
  16321. t['uring'] = 500;
  16322. t['threesuperior'] = 300;
  16323. t['Ograve'] = 722;
  16324. t['Agrave'] = 611;
  16325. t['Abreve'] = 611;
  16326. t['multiply'] = 675;
  16327. t['uacute'] = 500;
  16328. t['Tcaron'] = 556;
  16329. t['partialdiff'] = 476;
  16330. t['ydieresis'] = 444;
  16331. t['Nacute'] = 667;
  16332. t['icircumflex'] = 278;
  16333. t['Ecircumflex'] = 611;
  16334. t['adieresis'] = 500;
  16335. t['edieresis'] = 444;
  16336. t['cacute'] = 444;
  16337. t['nacute'] = 500;
  16338. t['umacron'] = 500;
  16339. t['Ncaron'] = 667;
  16340. t['Iacute'] = 333;
  16341. t['plusminus'] = 675;
  16342. t['brokenbar'] = 275;
  16343. t['registered'] = 760;
  16344. t['Gbreve'] = 722;
  16345. t['Idotaccent'] = 333;
  16346. t['summation'] = 600;
  16347. t['Egrave'] = 611;
  16348. t['racute'] = 389;
  16349. t['omacron'] = 500;
  16350. t['Zacute'] = 556;
  16351. t['Zcaron'] = 556;
  16352. t['greaterequal'] = 549;
  16353. t['Eth'] = 722;
  16354. t['Ccedilla'] = 667;
  16355. t['lcommaaccent'] = 278;
  16356. t['tcaron'] = 300;
  16357. t['eogonek'] = 444;
  16358. t['Uogonek'] = 722;
  16359. t['Aacute'] = 611;
  16360. t['Adieresis'] = 611;
  16361. t['egrave'] = 444;
  16362. t['zacute'] = 389;
  16363. t['iogonek'] = 278;
  16364. t['Oacute'] = 722;
  16365. t['oacute'] = 500;
  16366. t['amacron'] = 500;
  16367. t['sacute'] = 389;
  16368. t['idieresis'] = 278;
  16369. t['Ocircumflex'] = 722;
  16370. t['Ugrave'] = 722;
  16371. t['Delta'] = 612;
  16372. t['thorn'] = 500;
  16373. t['twosuperior'] = 300;
  16374. t['Odieresis'] = 722;
  16375. t['mu'] = 500;
  16376. t['igrave'] = 278;
  16377. t['ohungarumlaut'] = 500;
  16378. t['Eogonek'] = 611;
  16379. t['dcroat'] = 500;
  16380. t['threequarters'] = 750;
  16381. t['Scedilla'] = 500;
  16382. t['lcaron'] = 300;
  16383. t['Kcommaaccent'] = 667;
  16384. t['Lacute'] = 556;
  16385. t['trademark'] = 980;
  16386. t['edotaccent'] = 444;
  16387. t['Igrave'] = 333;
  16388. t['Imacron'] = 333;
  16389. t['Lcaron'] = 611;
  16390. t['onehalf'] = 750;
  16391. t['lessequal'] = 549;
  16392. t['ocircumflex'] = 500;
  16393. t['ntilde'] = 500;
  16394. t['Uhungarumlaut'] = 722;
  16395. t['Eacute'] = 611;
  16396. t['emacron'] = 444;
  16397. t['gbreve'] = 500;
  16398. t['onequarter'] = 750;
  16399. t['Scaron'] = 500;
  16400. t['Scommaaccent'] = 500;
  16401. t['Ohungarumlaut'] = 722;
  16402. t['degree'] = 400;
  16403. t['ograve'] = 500;
  16404. t['Ccaron'] = 667;
  16405. t['ugrave'] = 500;
  16406. t['radical'] = 453;
  16407. t['Dcaron'] = 722;
  16408. t['rcommaaccent'] = 389;
  16409. t['Ntilde'] = 667;
  16410. t['otilde'] = 500;
  16411. t['Rcommaaccent'] = 611;
  16412. t['Lcommaaccent'] = 556;
  16413. t['Atilde'] = 611;
  16414. t['Aogonek'] = 611;
  16415. t['Aring'] = 611;
  16416. t['Otilde'] = 722;
  16417. t['zdotaccent'] = 389;
  16418. t['Ecaron'] = 611;
  16419. t['Iogonek'] = 333;
  16420. t['kcommaaccent'] = 444;
  16421. t['minus'] = 675;
  16422. t['Icircumflex'] = 333;
  16423. t['ncaron'] = 500;
  16424. t['tcommaaccent'] = 278;
  16425. t['logicalnot'] = 675;
  16426. t['odieresis'] = 500;
  16427. t['udieresis'] = 500;
  16428. t['notequal'] = 549;
  16429. t['gcommaaccent'] = 500;
  16430. t['eth'] = 500;
  16431. t['zcaron'] = 389;
  16432. t['ncommaaccent'] = 500;
  16433. t['onesuperior'] = 300;
  16434. t['imacron'] = 278;
  16435. t['Euro'] = 500;
  16436. });
  16437. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16438. t['space'] = 278;
  16439. t['a1'] = 974;
  16440. t['a2'] = 961;
  16441. t['a202'] = 974;
  16442. t['a3'] = 980;
  16443. t['a4'] = 719;
  16444. t['a5'] = 789;
  16445. t['a119'] = 790;
  16446. t['a118'] = 791;
  16447. t['a117'] = 690;
  16448. t['a11'] = 960;
  16449. t['a12'] = 939;
  16450. t['a13'] = 549;
  16451. t['a14'] = 855;
  16452. t['a15'] = 911;
  16453. t['a16'] = 933;
  16454. t['a105'] = 911;
  16455. t['a17'] = 945;
  16456. t['a18'] = 974;
  16457. t['a19'] = 755;
  16458. t['a20'] = 846;
  16459. t['a21'] = 762;
  16460. t['a22'] = 761;
  16461. t['a23'] = 571;
  16462. t['a24'] = 677;
  16463. t['a25'] = 763;
  16464. t['a26'] = 760;
  16465. t['a27'] = 759;
  16466. t['a28'] = 754;
  16467. t['a6'] = 494;
  16468. t['a7'] = 552;
  16469. t['a8'] = 537;
  16470. t['a9'] = 577;
  16471. t['a10'] = 692;
  16472. t['a29'] = 786;
  16473. t['a30'] = 788;
  16474. t['a31'] = 788;
  16475. t['a32'] = 790;
  16476. t['a33'] = 793;
  16477. t['a34'] = 794;
  16478. t['a35'] = 816;
  16479. t['a36'] = 823;
  16480. t['a37'] = 789;
  16481. t['a38'] = 841;
  16482. t['a39'] = 823;
  16483. t['a40'] = 833;
  16484. t['a41'] = 816;
  16485. t['a42'] = 831;
  16486. t['a43'] = 923;
  16487. t['a44'] = 744;
  16488. t['a45'] = 723;
  16489. t['a46'] = 749;
  16490. t['a47'] = 790;
  16491. t['a48'] = 792;
  16492. t['a49'] = 695;
  16493. t['a50'] = 776;
  16494. t['a51'] = 768;
  16495. t['a52'] = 792;
  16496. t['a53'] = 759;
  16497. t['a54'] = 707;
  16498. t['a55'] = 708;
  16499. t['a56'] = 682;
  16500. t['a57'] = 701;
  16501. t['a58'] = 826;
  16502. t['a59'] = 815;
  16503. t['a60'] = 789;
  16504. t['a61'] = 789;
  16505. t['a62'] = 707;
  16506. t['a63'] = 687;
  16507. t['a64'] = 696;
  16508. t['a65'] = 689;
  16509. t['a66'] = 786;
  16510. t['a67'] = 787;
  16511. t['a68'] = 713;
  16512. t['a69'] = 791;
  16513. t['a70'] = 785;
  16514. t['a71'] = 791;
  16515. t['a72'] = 873;
  16516. t['a73'] = 761;
  16517. t['a74'] = 762;
  16518. t['a203'] = 762;
  16519. t['a75'] = 759;
  16520. t['a204'] = 759;
  16521. t['a76'] = 892;
  16522. t['a77'] = 892;
  16523. t['a78'] = 788;
  16524. t['a79'] = 784;
  16525. t['a81'] = 438;
  16526. t['a82'] = 138;
  16527. t['a83'] = 277;
  16528. t['a84'] = 415;
  16529. t['a97'] = 392;
  16530. t['a98'] = 392;
  16531. t['a99'] = 668;
  16532. t['a100'] = 668;
  16533. t['a89'] = 390;
  16534. t['a90'] = 390;
  16535. t['a93'] = 317;
  16536. t['a94'] = 317;
  16537. t['a91'] = 276;
  16538. t['a92'] = 276;
  16539. t['a205'] = 509;
  16540. t['a85'] = 509;
  16541. t['a206'] = 410;
  16542. t['a86'] = 410;
  16543. t['a87'] = 234;
  16544. t['a88'] = 234;
  16545. t['a95'] = 334;
  16546. t['a96'] = 334;
  16547. t['a101'] = 732;
  16548. t['a102'] = 544;
  16549. t['a103'] = 544;
  16550. t['a104'] = 910;
  16551. t['a106'] = 667;
  16552. t['a107'] = 760;
  16553. t['a108'] = 760;
  16554. t['a112'] = 776;
  16555. t['a111'] = 595;
  16556. t['a110'] = 694;
  16557. t['a109'] = 626;
  16558. t['a120'] = 788;
  16559. t['a121'] = 788;
  16560. t['a122'] = 788;
  16561. t['a123'] = 788;
  16562. t['a124'] = 788;
  16563. t['a125'] = 788;
  16564. t['a126'] = 788;
  16565. t['a127'] = 788;
  16566. t['a128'] = 788;
  16567. t['a129'] = 788;
  16568. t['a130'] = 788;
  16569. t['a131'] = 788;
  16570. t['a132'] = 788;
  16571. t['a133'] = 788;
  16572. t['a134'] = 788;
  16573. t['a135'] = 788;
  16574. t['a136'] = 788;
  16575. t['a137'] = 788;
  16576. t['a138'] = 788;
  16577. t['a139'] = 788;
  16578. t['a140'] = 788;
  16579. t['a141'] = 788;
  16580. t['a142'] = 788;
  16581. t['a143'] = 788;
  16582. t['a144'] = 788;
  16583. t['a145'] = 788;
  16584. t['a146'] = 788;
  16585. t['a147'] = 788;
  16586. t['a148'] = 788;
  16587. t['a149'] = 788;
  16588. t['a150'] = 788;
  16589. t['a151'] = 788;
  16590. t['a152'] = 788;
  16591. t['a153'] = 788;
  16592. t['a154'] = 788;
  16593. t['a155'] = 788;
  16594. t['a156'] = 788;
  16595. t['a157'] = 788;
  16596. t['a158'] = 788;
  16597. t['a159'] = 788;
  16598. t['a160'] = 894;
  16599. t['a161'] = 838;
  16600. t['a163'] = 1016;
  16601. t['a164'] = 458;
  16602. t['a196'] = 748;
  16603. t['a165'] = 924;
  16604. t['a192'] = 748;
  16605. t['a166'] = 918;
  16606. t['a167'] = 927;
  16607. t['a168'] = 928;
  16608. t['a169'] = 928;
  16609. t['a170'] = 834;
  16610. t['a171'] = 873;
  16611. t['a172'] = 828;
  16612. t['a173'] = 924;
  16613. t['a162'] = 924;
  16614. t['a174'] = 917;
  16615. t['a175'] = 930;
  16616. t['a176'] = 931;
  16617. t['a177'] = 463;
  16618. t['a178'] = 883;
  16619. t['a179'] = 836;
  16620. t['a193'] = 836;
  16621. t['a180'] = 867;
  16622. t['a199'] = 867;
  16623. t['a181'] = 696;
  16624. t['a200'] = 696;
  16625. t['a182'] = 874;
  16626. t['a201'] = 874;
  16627. t['a183'] = 760;
  16628. t['a184'] = 946;
  16629. t['a197'] = 771;
  16630. t['a185'] = 865;
  16631. t['a194'] = 771;
  16632. t['a198'] = 888;
  16633. t['a186'] = 967;
  16634. t['a195'] = 888;
  16635. t['a187'] = 831;
  16636. t['a188'] = 873;
  16637. t['a189'] = 927;
  16638. t['a190'] = 970;
  16639. t['a191'] = 918;
  16640. });
  16641. });
  16642. exports.getMetrics = getMetrics;
  16643. }));
  16644. (function (root, factory) {
  16645. {
  16646. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16647. }
  16648. }(this, function (exports, sharedUtil) {
  16649. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16650. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16651. // Workaround for missing math precision in JS.
  16652. var MASK_HIGH = 0xffff0000;
  16653. var MASK_LOW = 0xffff;
  16654. function MurmurHash3_64 (seed) {
  16655. var SEED = 0xc3d2e1f0;
  16656. this.h1 = seed ? seed & 0xffffffff : SEED;
  16657. this.h2 = seed ? seed & 0xffffffff : SEED;
  16658. }
  16659. var alwaysUseUint32ArrayView = false;
  16660. // old webkits have issues with non-aligned arrays
  16661. try {
  16662. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16663. } catch (e) {
  16664. alwaysUseUint32ArrayView = true;
  16665. }
  16666. MurmurHash3_64.prototype = {
  16667. update: function MurmurHash3_64_update(input) {
  16668. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16669. var i;
  16670. if (typeof input === 'string') {
  16671. var data = new Uint8Array(input.length * 2);
  16672. var length = 0;
  16673. for (i = 0; i < input.length; i++) {
  16674. var code = input.charCodeAt(i);
  16675. if (code <= 0xff) {
  16676. data[length++] = code;
  16677. }
  16678. else {
  16679. data[length++] = code >>> 8;
  16680. data[length++] = code & 0xff;
  16681. }
  16682. }
  16683. } else if (input instanceof Uint8Array) {
  16684. data = input;
  16685. length = data.length;
  16686. } else if (typeof input === 'object' && ('length' in input)) {
  16687. // processing regular arrays as well, e.g. for IE9
  16688. data = input;
  16689. length = data.length;
  16690. useUint32ArrayView = true;
  16691. } else {
  16692. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16693. 'Input must be a string or array.');
  16694. }
  16695. var blockCounts = length >> 2;
  16696. var tailLength = length - blockCounts * 4;
  16697. // we don't care about endianness here
  16698. var dataUint32 = useUint32ArrayView ?
  16699. new Uint32ArrayView(data, blockCounts) :
  16700. new Uint32Array(data.buffer, 0, blockCounts);
  16701. var k1 = 0;
  16702. var k2 = 0;
  16703. var h1 = this.h1;
  16704. var h2 = this.h2;
  16705. var C1 = 0xcc9e2d51;
  16706. var C2 = 0x1b873593;
  16707. var C1_LOW = C1 & MASK_LOW;
  16708. var C2_LOW = C2 & MASK_LOW;
  16709. for (i = 0; i < blockCounts; i++) {
  16710. if (i & 1) {
  16711. k1 = dataUint32[i];
  16712. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16713. k1 = k1 << 15 | k1 >>> 17;
  16714. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16715. h1 ^= k1;
  16716. h1 = h1 << 13 | h1 >>> 19;
  16717. h1 = h1 * 5 + 0xe6546b64;
  16718. } else {
  16719. k2 = dataUint32[i];
  16720. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16721. k2 = k2 << 15 | k2 >>> 17;
  16722. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16723. h2 ^= k2;
  16724. h2 = h2 << 13 | h2 >>> 19;
  16725. h2 = h2 * 5 + 0xe6546b64;
  16726. }
  16727. }
  16728. k1 = 0;
  16729. switch (tailLength) {
  16730. case 3:
  16731. k1 ^= data[blockCounts * 4 + 2] << 16;
  16732. /* falls through */
  16733. case 2:
  16734. k1 ^= data[blockCounts * 4 + 1] << 8;
  16735. /* falls through */
  16736. case 1:
  16737. k1 ^= data[blockCounts * 4];
  16738. /* falls through */
  16739. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16740. k1 = k1 << 15 | k1 >>> 17;
  16741. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16742. if (blockCounts & 1) {
  16743. h1 ^= k1;
  16744. } else {
  16745. h2 ^= k1;
  16746. }
  16747. }
  16748. this.h1 = h1;
  16749. this.h2 = h2;
  16750. return this;
  16751. },
  16752. hexdigest: function MurmurHash3_64_hexdigest () {
  16753. var h1 = this.h1;
  16754. var h2 = this.h2;
  16755. h1 ^= h2 >>> 1;
  16756. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16757. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16758. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16759. h1 ^= h2 >>> 1;
  16760. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16761. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16762. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16763. h1 ^= h2 >>> 1;
  16764. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16765. var hex = (arr[i] >>> 0).toString(16);
  16766. while (hex.length < 8) {
  16767. hex = '0' + hex;
  16768. }
  16769. str += hex;
  16770. }
  16771. return str;
  16772. }
  16773. };
  16774. return MurmurHash3_64;
  16775. })();
  16776. exports.MurmurHash3_64 = MurmurHash3_64;
  16777. }));
  16778. (function (root, factory) {
  16779. {
  16780. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16781. }
  16782. }(this, function (exports, sharedUtil) {
  16783. var isArray = sharedUtil.isArray;
  16784. var Name = (function NameClosure() {
  16785. function Name(name) {
  16786. this.name = name;
  16787. }
  16788. Name.prototype = {};
  16789. var nameCache = Object.create(null);
  16790. Name.get = function Name_get(name) {
  16791. var nameValue = nameCache[name];
  16792. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16793. };
  16794. return Name;
  16795. })();
  16796. var Cmd = (function CmdClosure() {
  16797. function Cmd(cmd) {
  16798. this.cmd = cmd;
  16799. }
  16800. Cmd.prototype = {};
  16801. var cmdCache = Object.create(null);
  16802. Cmd.get = function Cmd_get(cmd) {
  16803. var cmdValue = cmdCache[cmd];
  16804. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16805. };
  16806. return Cmd;
  16807. })();
  16808. var Dict = (function DictClosure() {
  16809. var nonSerializable = function nonSerializableClosure() {
  16810. return nonSerializable; // creating closure on some variable
  16811. };
  16812. // xref is optional
  16813. function Dict(xref) {
  16814. // Map should only be used internally, use functions below to access.
  16815. this.map = Object.create(null);
  16816. this.xref = xref;
  16817. this.objId = null;
  16818. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16819. }
  16820. Dict.prototype = {
  16821. assignXref: function Dict_assignXref(newXref) {
  16822. this.xref = newXref;
  16823. },
  16824. // automatically dereferences Ref objects
  16825. get: function Dict_get(key1, key2, key3) {
  16826. var value;
  16827. var xref = this.xref;
  16828. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16829. typeof key2 === 'undefined') {
  16830. return xref ? xref.fetchIfRef(value) : value;
  16831. }
  16832. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16833. typeof key3 === 'undefined') {
  16834. return xref ? xref.fetchIfRef(value) : value;
  16835. }
  16836. value = this.map[key3] || null;
  16837. return xref ? xref.fetchIfRef(value) : value;
  16838. },
  16839. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16840. getAsync: function Dict_getAsync(key1, key2, key3) {
  16841. var value;
  16842. var xref = this.xref;
  16843. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16844. typeof key2 === 'undefined') {
  16845. if (xref) {
  16846. return xref.fetchIfRefAsync(value);
  16847. }
  16848. return Promise.resolve(value);
  16849. }
  16850. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16851. typeof key3 === 'undefined') {
  16852. if (xref) {
  16853. return xref.fetchIfRefAsync(value);
  16854. }
  16855. return Promise.resolve(value);
  16856. }
  16857. value = this.map[key3] || null;
  16858. if (xref) {
  16859. return xref.fetchIfRefAsync(value);
  16860. }
  16861. return Promise.resolve(value);
  16862. },
  16863. // Same as get(), but dereferences all elements if the result is an Array.
  16864. getArray: function Dict_getArray(key1, key2, key3) {
  16865. var value = this.get(key1, key2, key3);
  16866. var xref = this.xref;
  16867. if (!isArray(value) || !xref) {
  16868. return value;
  16869. }
  16870. value = value.slice(); // Ensure that we don't modify the Dict data.
  16871. for (var i = 0, ii = value.length; i < ii; i++) {
  16872. if (!isRef(value[i])) {
  16873. continue;
  16874. }
  16875. value[i] = xref.fetch(value[i]);
  16876. }
  16877. return value;
  16878. },
  16879. // no dereferencing
  16880. getRaw: function Dict_getRaw(key) {
  16881. return this.map[key];
  16882. },
  16883. getKeys: function Dict_getKeys() {
  16884. return Object.keys(this.map);
  16885. },
  16886. set: function Dict_set(key, value) {
  16887. this.map[key] = value;
  16888. },
  16889. has: function Dict_has(key) {
  16890. return key in this.map;
  16891. },
  16892. forEach: function Dict_forEach(callback) {
  16893. for (var key in this.map) {
  16894. callback(key, this.get(key));
  16895. }
  16896. }
  16897. };
  16898. Dict.empty = new Dict(null);
  16899. Dict.merge = function Dict_merge(xref, dictArray) {
  16900. var mergedDict = new Dict(xref);
  16901. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  16902. var dict = dictArray[i];
  16903. if (!isDict(dict)) {
  16904. continue;
  16905. }
  16906. for (var keyName in dict.map) {
  16907. if (mergedDict.map[keyName]) {
  16908. continue;
  16909. }
  16910. mergedDict.map[keyName] = dict.map[keyName];
  16911. }
  16912. }
  16913. return mergedDict;
  16914. };
  16915. return Dict;
  16916. })();
  16917. var Ref = (function RefClosure() {
  16918. function Ref(num, gen) {
  16919. this.num = num;
  16920. this.gen = gen;
  16921. }
  16922. Ref.prototype = {
  16923. toString: function Ref_toString() {
  16924. // This function is hot, so we make the string as compact as possible.
  16925. // |this.gen| is almost always zero, so we treat that case specially.
  16926. var str = this.num + 'R';
  16927. if (this.gen !== 0) {
  16928. str += this.gen;
  16929. }
  16930. return str;
  16931. }
  16932. };
  16933. return Ref;
  16934. })();
  16935. // The reference is identified by number and generation.
  16936. // This structure stores only one instance of the reference.
  16937. var RefSet = (function RefSetClosure() {
  16938. function RefSet() {
  16939. this.dict = Object.create(null);
  16940. }
  16941. RefSet.prototype = {
  16942. has: function RefSet_has(ref) {
  16943. return ref.toString() in this.dict;
  16944. },
  16945. put: function RefSet_put(ref) {
  16946. this.dict[ref.toString()] = true;
  16947. },
  16948. remove: function RefSet_remove(ref) {
  16949. delete this.dict[ref.toString()];
  16950. }
  16951. };
  16952. return RefSet;
  16953. })();
  16954. var RefSetCache = (function RefSetCacheClosure() {
  16955. function RefSetCache() {
  16956. this.dict = Object.create(null);
  16957. }
  16958. RefSetCache.prototype = {
  16959. get: function RefSetCache_get(ref) {
  16960. return this.dict[ref.toString()];
  16961. },
  16962. has: function RefSetCache_has(ref) {
  16963. return ref.toString() in this.dict;
  16964. },
  16965. put: function RefSetCache_put(ref, obj) {
  16966. this.dict[ref.toString()] = obj;
  16967. },
  16968. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  16969. this.dict[ref.toString()] = this.get(aliasRef);
  16970. },
  16971. forEach: function RefSetCache_forEach(fn, thisArg) {
  16972. for (var i in this.dict) {
  16973. fn.call(thisArg, this.dict[i]);
  16974. }
  16975. },
  16976. clear: function RefSetCache_clear() {
  16977. this.dict = Object.create(null);
  16978. }
  16979. };
  16980. return RefSetCache;
  16981. })();
  16982. function isName(v, name) {
  16983. return v instanceof Name && (name === undefined || v.name === name);
  16984. }
  16985. function isCmd(v, cmd) {
  16986. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  16987. }
  16988. function isDict(v, type) {
  16989. return v instanceof Dict &&
  16990. (type === undefined || isName(v.get('Type'), type));
  16991. }
  16992. function isRef(v) {
  16993. return v instanceof Ref;
  16994. }
  16995. function isRefsEqual(v1, v2) {
  16996. return v1.num === v2.num && v1.gen === v2.gen;
  16997. }
  16998. function isStream(v) {
  16999. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  17000. }
  17001. exports.Cmd = Cmd;
  17002. exports.Dict = Dict;
  17003. exports.Name = Name;
  17004. exports.Ref = Ref;
  17005. exports.RefSet = RefSet;
  17006. exports.RefSetCache = RefSetCache;
  17007. exports.isCmd = isCmd;
  17008. exports.isDict = isDict;
  17009. exports.isName = isName;
  17010. exports.isRef = isRef;
  17011. exports.isRefsEqual = isRefsEqual;
  17012. exports.isStream = isStream;
  17013. }));
  17014. (function (root, factory) {
  17015. {
  17016. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  17017. }
  17018. }(this, function (exports, sharedUtil) {
  17019. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17020. /**
  17021. * Hold a map of decoded fonts and of the standard fourteen Type1
  17022. * fonts and their acronyms.
  17023. */
  17024. var getStdFontMap = getLookupTableFactory(function (t) {
  17025. t['ArialNarrow'] = 'Helvetica';
  17026. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  17027. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  17028. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  17029. t['ArialBlack'] = 'Helvetica';
  17030. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  17031. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  17032. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  17033. t['Arial'] = 'Helvetica';
  17034. t['Arial-Bold'] = 'Helvetica-Bold';
  17035. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  17036. t['Arial-Italic'] = 'Helvetica-Oblique';
  17037. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  17038. t['Arial-BoldMT'] = 'Helvetica-Bold';
  17039. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  17040. t['ArialMT'] = 'Helvetica';
  17041. t['Courier-Bold'] = 'Courier-Bold';
  17042. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  17043. t['Courier-Italic'] = 'Courier-Oblique';
  17044. t['CourierNew'] = 'Courier';
  17045. t['CourierNew-Bold'] = 'Courier-Bold';
  17046. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  17047. t['CourierNew-Italic'] = 'Courier-Oblique';
  17048. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  17049. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  17050. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  17051. t['CourierNewPSMT'] = 'Courier';
  17052. t['Helvetica'] = 'Helvetica';
  17053. t['Helvetica-Bold'] = 'Helvetica-Bold';
  17054. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  17055. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  17056. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  17057. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  17058. t['Symbol-Bold'] = 'Symbol';
  17059. t['Symbol-BoldItalic'] = 'Symbol';
  17060. t['Symbol-Italic'] = 'Symbol';
  17061. t['TimesNewRoman'] = 'Times-Roman';
  17062. t['TimesNewRoman-Bold'] = 'Times-Bold';
  17063. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  17064. t['TimesNewRoman-Italic'] = 'Times-Italic';
  17065. t['TimesNewRomanPS'] = 'Times-Roman';
  17066. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  17067. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  17068. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  17069. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  17070. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  17071. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  17072. t['TimesNewRomanPSMT'] = 'Times-Roman';
  17073. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  17074. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  17075. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  17076. });
  17077. /**
  17078. * Holds the map of the non-standard fonts that might be included as
  17079. * a standard fonts without glyph data.
  17080. */
  17081. var getNonStdFontMap = getLookupTableFactory(function (t) {
  17082. t['CenturyGothic'] = 'Helvetica';
  17083. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  17084. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  17085. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  17086. t['ComicSansMS'] = 'Comic Sans MS';
  17087. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  17088. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  17089. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  17090. t['LucidaConsole'] = 'Courier';
  17091. t['LucidaConsole-Bold'] = 'Courier-Bold';
  17092. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  17093. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  17094. t['MS-Gothic'] = 'MS Gothic';
  17095. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  17096. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  17097. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  17098. t['MS-Mincho'] = 'MS Mincho';
  17099. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  17100. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  17101. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  17102. t['MS-PGothic'] = 'MS PGothic';
  17103. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  17104. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  17105. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  17106. t['MS-PMincho'] = 'MS PMincho';
  17107. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  17108. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  17109. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  17110. t['Wingdings'] = 'ZapfDingbats';
  17111. });
  17112. var getSerifFonts = getLookupTableFactory(function (t) {
  17113. t['Adobe Jenson'] = true;
  17114. t['Adobe Text'] = true;
  17115. t['Albertus'] = true;
  17116. t['Aldus'] = true;
  17117. t['Alexandria'] = true;
  17118. t['Algerian'] = true;
  17119. t['American Typewriter'] = true;
  17120. t['Antiqua'] = true;
  17121. t['Apex'] = true;
  17122. t['Arno'] = true;
  17123. t['Aster'] = true;
  17124. t['Aurora'] = true;
  17125. t['Baskerville'] = true;
  17126. t['Bell'] = true;
  17127. t['Bembo'] = true;
  17128. t['Bembo Schoolbook'] = true;
  17129. t['Benguiat'] = true;
  17130. t['Berkeley Old Style'] = true;
  17131. t['Bernhard Modern'] = true;
  17132. t['Berthold City'] = true;
  17133. t['Bodoni'] = true;
  17134. t['Bauer Bodoni'] = true;
  17135. t['Book Antiqua'] = true;
  17136. t['Bookman'] = true;
  17137. t['Bordeaux Roman'] = true;
  17138. t['Californian FB'] = true;
  17139. t['Calisto'] = true;
  17140. t['Calvert'] = true;
  17141. t['Capitals'] = true;
  17142. t['Cambria'] = true;
  17143. t['Cartier'] = true;
  17144. t['Caslon'] = true;
  17145. t['Catull'] = true;
  17146. t['Centaur'] = true;
  17147. t['Century Old Style'] = true;
  17148. t['Century Schoolbook'] = true;
  17149. t['Chaparral'] = true;
  17150. t['Charis SIL'] = true;
  17151. t['Cheltenham'] = true;
  17152. t['Cholla Slab'] = true;
  17153. t['Clarendon'] = true;
  17154. t['Clearface'] = true;
  17155. t['Cochin'] = true;
  17156. t['Colonna'] = true;
  17157. t['Computer Modern'] = true;
  17158. t['Concrete Roman'] = true;
  17159. t['Constantia'] = true;
  17160. t['Cooper Black'] = true;
  17161. t['Corona'] = true;
  17162. t['Ecotype'] = true;
  17163. t['Egyptienne'] = true;
  17164. t['Elephant'] = true;
  17165. t['Excelsior'] = true;
  17166. t['Fairfield'] = true;
  17167. t['FF Scala'] = true;
  17168. t['Folkard'] = true;
  17169. t['Footlight'] = true;
  17170. t['FreeSerif'] = true;
  17171. t['Friz Quadrata'] = true;
  17172. t['Garamond'] = true;
  17173. t['Gentium'] = true;
  17174. t['Georgia'] = true;
  17175. t['Gloucester'] = true;
  17176. t['Goudy Old Style'] = true;
  17177. t['Goudy Schoolbook'] = true;
  17178. t['Goudy Pro Font'] = true;
  17179. t['Granjon'] = true;
  17180. t['Guardian Egyptian'] = true;
  17181. t['Heather'] = true;
  17182. t['Hercules'] = true;
  17183. t['High Tower Text'] = true;
  17184. t['Hiroshige'] = true;
  17185. t['Hoefler Text'] = true;
  17186. t['Humana Serif'] = true;
  17187. t['Imprint'] = true;
  17188. t['Ionic No. 5'] = true;
  17189. t['Janson'] = true;
  17190. t['Joanna'] = true;
  17191. t['Korinna'] = true;
  17192. t['Lexicon'] = true;
  17193. t['Liberation Serif'] = true;
  17194. t['Linux Libertine'] = true;
  17195. t['Literaturnaya'] = true;
  17196. t['Lucida'] = true;
  17197. t['Lucida Bright'] = true;
  17198. t['Melior'] = true;
  17199. t['Memphis'] = true;
  17200. t['Miller'] = true;
  17201. t['Minion'] = true;
  17202. t['Modern'] = true;
  17203. t['Mona Lisa'] = true;
  17204. t['Mrs Eaves'] = true;
  17205. t['MS Serif'] = true;
  17206. t['Museo Slab'] = true;
  17207. t['New York'] = true;
  17208. t['Nimbus Roman'] = true;
  17209. t['NPS Rawlinson Roadway'] = true;
  17210. t['Palatino'] = true;
  17211. t['Perpetua'] = true;
  17212. t['Plantin'] = true;
  17213. t['Plantin Schoolbook'] = true;
  17214. t['Playbill'] = true;
  17215. t['Poor Richard'] = true;
  17216. t['Rawlinson Roadway'] = true;
  17217. t['Renault'] = true;
  17218. t['Requiem'] = true;
  17219. t['Rockwell'] = true;
  17220. t['Roman'] = true;
  17221. t['Rotis Serif'] = true;
  17222. t['Sabon'] = true;
  17223. t['Scala'] = true;
  17224. t['Seagull'] = true;
  17225. t['Sistina'] = true;
  17226. t['Souvenir'] = true;
  17227. t['STIX'] = true;
  17228. t['Stone Informal'] = true;
  17229. t['Stone Serif'] = true;
  17230. t['Sylfaen'] = true;
  17231. t['Times'] = true;
  17232. t['Trajan'] = true;
  17233. t['Trinité'] = true;
  17234. t['Trump Mediaeval'] = true;
  17235. t['Utopia'] = true;
  17236. t['Vale Type'] = true;
  17237. t['Bitstream Vera'] = true;
  17238. t['Vera Serif'] = true;
  17239. t['Versailles'] = true;
  17240. t['Wanted'] = true;
  17241. t['Weiss'] = true;
  17242. t['Wide Latin'] = true;
  17243. t['Windsor'] = true;
  17244. t['XITS'] = true;
  17245. });
  17246. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17247. t['Dingbats'] = true;
  17248. t['Symbol'] = true;
  17249. t['ZapfDingbats'] = true;
  17250. });
  17251. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17252. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17253. // for all glyphs, but common for some set of the standard fonts.
  17254. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17255. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17256. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17257. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17258. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17259. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17260. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17261. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17262. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17263. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17264. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17265. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17266. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17267. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17268. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17269. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17270. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17271. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17272. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17273. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17274. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17275. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17276. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17277. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17278. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17279. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17280. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17281. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17282. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17283. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17284. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17285. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17286. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17287. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17288. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17289. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17290. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17291. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17292. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17293. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17294. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17295. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17296. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17297. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17298. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17299. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17300. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17301. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17302. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17303. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17304. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17305. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17306. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17307. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17308. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17309. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17310. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17311. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17312. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17313. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17314. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17315. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17316. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17317. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17318. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17319. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17320. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17321. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17322. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17323. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17324. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17325. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17326. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17327. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17328. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17329. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17330. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17331. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17332. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17333. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17334. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17335. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17336. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17337. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17338. t[3416] = 8377;
  17339. });
  17340. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17341. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17342. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17343. var getSupplementalGlyphMapForArialBlack =
  17344. getLookupTableFactory(function (t) {
  17345. t[227] = 322; t[264] = 261; t[291] = 346;
  17346. });
  17347. exports.getStdFontMap = getStdFontMap;
  17348. exports.getNonStdFontMap = getNonStdFontMap;
  17349. exports.getSerifFonts = getSerifFonts;
  17350. exports.getSymbolsFonts = getSymbolsFonts;
  17351. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17352. exports.getSupplementalGlyphMapForArialBlack =
  17353. getSupplementalGlyphMapForArialBlack;
  17354. }));
  17355. (function (root, factory) {
  17356. {
  17357. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17358. }
  17359. }(this, function (exports, sharedUtil) {
  17360. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17361. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17362. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17363. // chars to the similar equivalents in the normal characters range.
  17364. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17365. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17366. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17367. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17368. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17369. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17370. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17371. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17372. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17373. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17374. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17375. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17376. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17377. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17378. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17379. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17380. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17381. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17382. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17383. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17384. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17385. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17386. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17387. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17388. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17389. });
  17390. function mapSpecialUnicodeValues(code) {
  17391. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17392. return 0;
  17393. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17394. return (getSpecialPUASymbols()[code] || code);
  17395. }
  17396. return code;
  17397. }
  17398. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17399. var unicode = glyphsUnicodeMap[name];
  17400. if (unicode !== undefined) {
  17401. return unicode;
  17402. }
  17403. if (!name) {
  17404. return -1;
  17405. }
  17406. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17407. if (name[0] === 'u') {
  17408. var nameLen = name.length, hexStr;
  17409. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17410. hexStr = name.substr(3);
  17411. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17412. hexStr = name.substr(1);
  17413. } else {
  17414. return -1;
  17415. }
  17416. // Check for upper-case hexadecimal characters, to avoid false positives.
  17417. if (hexStr === hexStr.toUpperCase()) {
  17418. unicode = parseInt(hexStr, 16);
  17419. if (unicode >= 0) {
  17420. return unicode;
  17421. }
  17422. }
  17423. }
  17424. return -1;
  17425. }
  17426. var UnicodeRanges = [
  17427. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17428. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17429. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17430. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17431. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17432. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17433. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17434. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17435. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17436. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17437. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17438. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17439. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17440. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17441. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17442. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17443. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17444. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17445. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17446. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17447. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17448. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17449. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17450. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17451. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17452. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17453. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17454. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17455. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17456. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17457. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17458. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17459. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17460. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17461. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17462. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17463. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17464. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17465. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17466. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17467. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17468. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17469. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17470. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17471. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17472. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17473. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17474. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17475. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17476. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17477. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17478. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17479. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17480. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17481. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17482. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17483. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17484. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17485. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17486. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17487. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17488. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17489. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17490. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17491. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17492. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17493. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17494. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17495. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17496. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17497. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17498. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17499. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17500. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17501. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17502. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17503. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17504. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17505. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17506. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17507. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17508. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17509. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17510. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17511. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17512. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17513. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17514. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17515. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17516. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17517. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17518. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17519. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17520. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17521. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17522. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17523. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17524. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17525. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17526. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17527. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17528. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17529. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17530. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17531. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17532. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17533. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17534. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17535. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17536. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17537. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17538. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17539. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17540. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17541. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17542. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17543. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17544. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17545. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17546. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17547. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17548. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17549. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17550. ];
  17551. function getUnicodeRangeFor(value) {
  17552. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17553. var range = UnicodeRanges[i];
  17554. if (value >= range.begin && value < range.end) {
  17555. return i;
  17556. }
  17557. }
  17558. return -1;
  17559. }
  17560. function isRTLRangeFor(value) {
  17561. var range = UnicodeRanges[13];
  17562. if (value >= range.begin && value < range.end) {
  17563. return true;
  17564. }
  17565. range = UnicodeRanges[11];
  17566. if (value >= range.begin && value < range.end) {
  17567. return true;
  17568. }
  17569. return false;
  17570. }
  17571. // The normalization table is obtained by filtering the Unicode characters
  17572. // database with <compat> entries.
  17573. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17574. t['\u00A8'] = '\u0020\u0308';
  17575. t['\u00AF'] = '\u0020\u0304';
  17576. t['\u00B4'] = '\u0020\u0301';
  17577. t['\u00B5'] = '\u03BC';
  17578. t['\u00B8'] = '\u0020\u0327';
  17579. t['\u0132'] = '\u0049\u004A';
  17580. t['\u0133'] = '\u0069\u006A';
  17581. t['\u013F'] = '\u004C\u00B7';
  17582. t['\u0140'] = '\u006C\u00B7';
  17583. t['\u0149'] = '\u02BC\u006E';
  17584. t['\u017F'] = '\u0073';
  17585. t['\u01C4'] = '\u0044\u017D';
  17586. t['\u01C5'] = '\u0044\u017E';
  17587. t['\u01C6'] = '\u0064\u017E';
  17588. t['\u01C7'] = '\u004C\u004A';
  17589. t['\u01C8'] = '\u004C\u006A';
  17590. t['\u01C9'] = '\u006C\u006A';
  17591. t['\u01CA'] = '\u004E\u004A';
  17592. t['\u01CB'] = '\u004E\u006A';
  17593. t['\u01CC'] = '\u006E\u006A';
  17594. t['\u01F1'] = '\u0044\u005A';
  17595. t['\u01F2'] = '\u0044\u007A';
  17596. t['\u01F3'] = '\u0064\u007A';
  17597. t['\u02D8'] = '\u0020\u0306';
  17598. t['\u02D9'] = '\u0020\u0307';
  17599. t['\u02DA'] = '\u0020\u030A';
  17600. t['\u02DB'] = '\u0020\u0328';
  17601. t['\u02DC'] = '\u0020\u0303';
  17602. t['\u02DD'] = '\u0020\u030B';
  17603. t['\u037A'] = '\u0020\u0345';
  17604. t['\u0384'] = '\u0020\u0301';
  17605. t['\u03D0'] = '\u03B2';
  17606. t['\u03D1'] = '\u03B8';
  17607. t['\u03D2'] = '\u03A5';
  17608. t['\u03D5'] = '\u03C6';
  17609. t['\u03D6'] = '\u03C0';
  17610. t['\u03F0'] = '\u03BA';
  17611. t['\u03F1'] = '\u03C1';
  17612. t['\u03F2'] = '\u03C2';
  17613. t['\u03F4'] = '\u0398';
  17614. t['\u03F5'] = '\u03B5';
  17615. t['\u03F9'] = '\u03A3';
  17616. t['\u0587'] = '\u0565\u0582';
  17617. t['\u0675'] = '\u0627\u0674';
  17618. t['\u0676'] = '\u0648\u0674';
  17619. t['\u0677'] = '\u06C7\u0674';
  17620. t['\u0678'] = '\u064A\u0674';
  17621. t['\u0E33'] = '\u0E4D\u0E32';
  17622. t['\u0EB3'] = '\u0ECD\u0EB2';
  17623. t['\u0EDC'] = '\u0EAB\u0E99';
  17624. t['\u0EDD'] = '\u0EAB\u0EA1';
  17625. t['\u0F77'] = '\u0FB2\u0F81';
  17626. t['\u0F79'] = '\u0FB3\u0F81';
  17627. t['\u1E9A'] = '\u0061\u02BE';
  17628. t['\u1FBD'] = '\u0020\u0313';
  17629. t['\u1FBF'] = '\u0020\u0313';
  17630. t['\u1FC0'] = '\u0020\u0342';
  17631. t['\u1FFE'] = '\u0020\u0314';
  17632. t['\u2002'] = '\u0020';
  17633. t['\u2003'] = '\u0020';
  17634. t['\u2004'] = '\u0020';
  17635. t['\u2005'] = '\u0020';
  17636. t['\u2006'] = '\u0020';
  17637. t['\u2008'] = '\u0020';
  17638. t['\u2009'] = '\u0020';
  17639. t['\u200A'] = '\u0020';
  17640. t['\u2017'] = '\u0020\u0333';
  17641. t['\u2024'] = '\u002E';
  17642. t['\u2025'] = '\u002E\u002E';
  17643. t['\u2026'] = '\u002E\u002E\u002E';
  17644. t['\u2033'] = '\u2032\u2032';
  17645. t['\u2034'] = '\u2032\u2032\u2032';
  17646. t['\u2036'] = '\u2035\u2035';
  17647. t['\u2037'] = '\u2035\u2035\u2035';
  17648. t['\u203C'] = '\u0021\u0021';
  17649. t['\u203E'] = '\u0020\u0305';
  17650. t['\u2047'] = '\u003F\u003F';
  17651. t['\u2048'] = '\u003F\u0021';
  17652. t['\u2049'] = '\u0021\u003F';
  17653. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17654. t['\u205F'] = '\u0020';
  17655. t['\u20A8'] = '\u0052\u0073';
  17656. t['\u2100'] = '\u0061\u002F\u0063';
  17657. t['\u2101'] = '\u0061\u002F\u0073';
  17658. t['\u2103'] = '\u00B0\u0043';
  17659. t['\u2105'] = '\u0063\u002F\u006F';
  17660. t['\u2106'] = '\u0063\u002F\u0075';
  17661. t['\u2107'] = '\u0190';
  17662. t['\u2109'] = '\u00B0\u0046';
  17663. t['\u2116'] = '\u004E\u006F';
  17664. t['\u2121'] = '\u0054\u0045\u004C';
  17665. t['\u2135'] = '\u05D0';
  17666. t['\u2136'] = '\u05D1';
  17667. t['\u2137'] = '\u05D2';
  17668. t['\u2138'] = '\u05D3';
  17669. t['\u213B'] = '\u0046\u0041\u0058';
  17670. t['\u2160'] = '\u0049';
  17671. t['\u2161'] = '\u0049\u0049';
  17672. t['\u2162'] = '\u0049\u0049\u0049';
  17673. t['\u2163'] = '\u0049\u0056';
  17674. t['\u2164'] = '\u0056';
  17675. t['\u2165'] = '\u0056\u0049';
  17676. t['\u2166'] = '\u0056\u0049\u0049';
  17677. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17678. t['\u2168'] = '\u0049\u0058';
  17679. t['\u2169'] = '\u0058';
  17680. t['\u216A'] = '\u0058\u0049';
  17681. t['\u216B'] = '\u0058\u0049\u0049';
  17682. t['\u216C'] = '\u004C';
  17683. t['\u216D'] = '\u0043';
  17684. t['\u216E'] = '\u0044';
  17685. t['\u216F'] = '\u004D';
  17686. t['\u2170'] = '\u0069';
  17687. t['\u2171'] = '\u0069\u0069';
  17688. t['\u2172'] = '\u0069\u0069\u0069';
  17689. t['\u2173'] = '\u0069\u0076';
  17690. t['\u2174'] = '\u0076';
  17691. t['\u2175'] = '\u0076\u0069';
  17692. t['\u2176'] = '\u0076\u0069\u0069';
  17693. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17694. t['\u2178'] = '\u0069\u0078';
  17695. t['\u2179'] = '\u0078';
  17696. t['\u217A'] = '\u0078\u0069';
  17697. t['\u217B'] = '\u0078\u0069\u0069';
  17698. t['\u217C'] = '\u006C';
  17699. t['\u217D'] = '\u0063';
  17700. t['\u217E'] = '\u0064';
  17701. t['\u217F'] = '\u006D';
  17702. t['\u222C'] = '\u222B\u222B';
  17703. t['\u222D'] = '\u222B\u222B\u222B';
  17704. t['\u222F'] = '\u222E\u222E';
  17705. t['\u2230'] = '\u222E\u222E\u222E';
  17706. t['\u2474'] = '\u0028\u0031\u0029';
  17707. t['\u2475'] = '\u0028\u0032\u0029';
  17708. t['\u2476'] = '\u0028\u0033\u0029';
  17709. t['\u2477'] = '\u0028\u0034\u0029';
  17710. t['\u2478'] = '\u0028\u0035\u0029';
  17711. t['\u2479'] = '\u0028\u0036\u0029';
  17712. t['\u247A'] = '\u0028\u0037\u0029';
  17713. t['\u247B'] = '\u0028\u0038\u0029';
  17714. t['\u247C'] = '\u0028\u0039\u0029';
  17715. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17716. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17717. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17718. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17719. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17720. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17721. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17722. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17723. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17724. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17725. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17726. t['\u2488'] = '\u0031\u002E';
  17727. t['\u2489'] = '\u0032\u002E';
  17728. t['\u248A'] = '\u0033\u002E';
  17729. t['\u248B'] = '\u0034\u002E';
  17730. t['\u248C'] = '\u0035\u002E';
  17731. t['\u248D'] = '\u0036\u002E';
  17732. t['\u248E'] = '\u0037\u002E';
  17733. t['\u248F'] = '\u0038\u002E';
  17734. t['\u2490'] = '\u0039\u002E';
  17735. t['\u2491'] = '\u0031\u0030\u002E';
  17736. t['\u2492'] = '\u0031\u0031\u002E';
  17737. t['\u2493'] = '\u0031\u0032\u002E';
  17738. t['\u2494'] = '\u0031\u0033\u002E';
  17739. t['\u2495'] = '\u0031\u0034\u002E';
  17740. t['\u2496'] = '\u0031\u0035\u002E';
  17741. t['\u2497'] = '\u0031\u0036\u002E';
  17742. t['\u2498'] = '\u0031\u0037\u002E';
  17743. t['\u2499'] = '\u0031\u0038\u002E';
  17744. t['\u249A'] = '\u0031\u0039\u002E';
  17745. t['\u249B'] = '\u0032\u0030\u002E';
  17746. t['\u249C'] = '\u0028\u0061\u0029';
  17747. t['\u249D'] = '\u0028\u0062\u0029';
  17748. t['\u249E'] = '\u0028\u0063\u0029';
  17749. t['\u249F'] = '\u0028\u0064\u0029';
  17750. t['\u24A0'] = '\u0028\u0065\u0029';
  17751. t['\u24A1'] = '\u0028\u0066\u0029';
  17752. t['\u24A2'] = '\u0028\u0067\u0029';
  17753. t['\u24A3'] = '\u0028\u0068\u0029';
  17754. t['\u24A4'] = '\u0028\u0069\u0029';
  17755. t['\u24A5'] = '\u0028\u006A\u0029';
  17756. t['\u24A6'] = '\u0028\u006B\u0029';
  17757. t['\u24A7'] = '\u0028\u006C\u0029';
  17758. t['\u24A8'] = '\u0028\u006D\u0029';
  17759. t['\u24A9'] = '\u0028\u006E\u0029';
  17760. t['\u24AA'] = '\u0028\u006F\u0029';
  17761. t['\u24AB'] = '\u0028\u0070\u0029';
  17762. t['\u24AC'] = '\u0028\u0071\u0029';
  17763. t['\u24AD'] = '\u0028\u0072\u0029';
  17764. t['\u24AE'] = '\u0028\u0073\u0029';
  17765. t['\u24AF'] = '\u0028\u0074\u0029';
  17766. t['\u24B0'] = '\u0028\u0075\u0029';
  17767. t['\u24B1'] = '\u0028\u0076\u0029';
  17768. t['\u24B2'] = '\u0028\u0077\u0029';
  17769. t['\u24B3'] = '\u0028\u0078\u0029';
  17770. t['\u24B4'] = '\u0028\u0079\u0029';
  17771. t['\u24B5'] = '\u0028\u007A\u0029';
  17772. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17773. t['\u2A74'] = '\u003A\u003A\u003D';
  17774. t['\u2A75'] = '\u003D\u003D';
  17775. t['\u2A76'] = '\u003D\u003D\u003D';
  17776. t['\u2E9F'] = '\u6BCD';
  17777. t['\u2EF3'] = '\u9F9F';
  17778. t['\u2F00'] = '\u4E00';
  17779. t['\u2F01'] = '\u4E28';
  17780. t['\u2F02'] = '\u4E36';
  17781. t['\u2F03'] = '\u4E3F';
  17782. t['\u2F04'] = '\u4E59';
  17783. t['\u2F05'] = '\u4E85';
  17784. t['\u2F06'] = '\u4E8C';
  17785. t['\u2F07'] = '\u4EA0';
  17786. t['\u2F08'] = '\u4EBA';
  17787. t['\u2F09'] = '\u513F';
  17788. t['\u2F0A'] = '\u5165';
  17789. t['\u2F0B'] = '\u516B';
  17790. t['\u2F0C'] = '\u5182';
  17791. t['\u2F0D'] = '\u5196';
  17792. t['\u2F0E'] = '\u51AB';
  17793. t['\u2F0F'] = '\u51E0';
  17794. t['\u2F10'] = '\u51F5';
  17795. t['\u2F11'] = '\u5200';
  17796. t['\u2F12'] = '\u529B';
  17797. t['\u2F13'] = '\u52F9';
  17798. t['\u2F14'] = '\u5315';
  17799. t['\u2F15'] = '\u531A';
  17800. t['\u2F16'] = '\u5338';
  17801. t['\u2F17'] = '\u5341';
  17802. t['\u2F18'] = '\u535C';
  17803. t['\u2F19'] = '\u5369';
  17804. t['\u2F1A'] = '\u5382';
  17805. t['\u2F1B'] = '\u53B6';
  17806. t['\u2F1C'] = '\u53C8';
  17807. t['\u2F1D'] = '\u53E3';
  17808. t['\u2F1E'] = '\u56D7';
  17809. t['\u2F1F'] = '\u571F';
  17810. t['\u2F20'] = '\u58EB';
  17811. t['\u2F21'] = '\u5902';
  17812. t['\u2F22'] = '\u590A';
  17813. t['\u2F23'] = '\u5915';
  17814. t['\u2F24'] = '\u5927';
  17815. t['\u2F25'] = '\u5973';
  17816. t['\u2F26'] = '\u5B50';
  17817. t['\u2F27'] = '\u5B80';
  17818. t['\u2F28'] = '\u5BF8';
  17819. t['\u2F29'] = '\u5C0F';
  17820. t['\u2F2A'] = '\u5C22';
  17821. t['\u2F2B'] = '\u5C38';
  17822. t['\u2F2C'] = '\u5C6E';
  17823. t['\u2F2D'] = '\u5C71';
  17824. t['\u2F2E'] = '\u5DDB';
  17825. t['\u2F2F'] = '\u5DE5';
  17826. t['\u2F30'] = '\u5DF1';
  17827. t['\u2F31'] = '\u5DFE';
  17828. t['\u2F32'] = '\u5E72';
  17829. t['\u2F33'] = '\u5E7A';
  17830. t['\u2F34'] = '\u5E7F';
  17831. t['\u2F35'] = '\u5EF4';
  17832. t['\u2F36'] = '\u5EFE';
  17833. t['\u2F37'] = '\u5F0B';
  17834. t['\u2F38'] = '\u5F13';
  17835. t['\u2F39'] = '\u5F50';
  17836. t['\u2F3A'] = '\u5F61';
  17837. t['\u2F3B'] = '\u5F73';
  17838. t['\u2F3C'] = '\u5FC3';
  17839. t['\u2F3D'] = '\u6208';
  17840. t['\u2F3E'] = '\u6236';
  17841. t['\u2F3F'] = '\u624B';
  17842. t['\u2F40'] = '\u652F';
  17843. t['\u2F41'] = '\u6534';
  17844. t['\u2F42'] = '\u6587';
  17845. t['\u2F43'] = '\u6597';
  17846. t['\u2F44'] = '\u65A4';
  17847. t['\u2F45'] = '\u65B9';
  17848. t['\u2F46'] = '\u65E0';
  17849. t['\u2F47'] = '\u65E5';
  17850. t['\u2F48'] = '\u66F0';
  17851. t['\u2F49'] = '\u6708';
  17852. t['\u2F4A'] = '\u6728';
  17853. t['\u2F4B'] = '\u6B20';
  17854. t['\u2F4C'] = '\u6B62';
  17855. t['\u2F4D'] = '\u6B79';
  17856. t['\u2F4E'] = '\u6BB3';
  17857. t['\u2F4F'] = '\u6BCB';
  17858. t['\u2F50'] = '\u6BD4';
  17859. t['\u2F51'] = '\u6BDB';
  17860. t['\u2F52'] = '\u6C0F';
  17861. t['\u2F53'] = '\u6C14';
  17862. t['\u2F54'] = '\u6C34';
  17863. t['\u2F55'] = '\u706B';
  17864. t['\u2F56'] = '\u722A';
  17865. t['\u2F57'] = '\u7236';
  17866. t['\u2F58'] = '\u723B';
  17867. t['\u2F59'] = '\u723F';
  17868. t['\u2F5A'] = '\u7247';
  17869. t['\u2F5B'] = '\u7259';
  17870. t['\u2F5C'] = '\u725B';
  17871. t['\u2F5D'] = '\u72AC';
  17872. t['\u2F5E'] = '\u7384';
  17873. t['\u2F5F'] = '\u7389';
  17874. t['\u2F60'] = '\u74DC';
  17875. t['\u2F61'] = '\u74E6';
  17876. t['\u2F62'] = '\u7518';
  17877. t['\u2F63'] = '\u751F';
  17878. t['\u2F64'] = '\u7528';
  17879. t['\u2F65'] = '\u7530';
  17880. t['\u2F66'] = '\u758B';
  17881. t['\u2F67'] = '\u7592';
  17882. t['\u2F68'] = '\u7676';
  17883. t['\u2F69'] = '\u767D';
  17884. t['\u2F6A'] = '\u76AE';
  17885. t['\u2F6B'] = '\u76BF';
  17886. t['\u2F6C'] = '\u76EE';
  17887. t['\u2F6D'] = '\u77DB';
  17888. t['\u2F6E'] = '\u77E2';
  17889. t['\u2F6F'] = '\u77F3';
  17890. t['\u2F70'] = '\u793A';
  17891. t['\u2F71'] = '\u79B8';
  17892. t['\u2F72'] = '\u79BE';
  17893. t['\u2F73'] = '\u7A74';
  17894. t['\u2F74'] = '\u7ACB';
  17895. t['\u2F75'] = '\u7AF9';
  17896. t['\u2F76'] = '\u7C73';
  17897. t['\u2F77'] = '\u7CF8';
  17898. t['\u2F78'] = '\u7F36';
  17899. t['\u2F79'] = '\u7F51';
  17900. t['\u2F7A'] = '\u7F8A';
  17901. t['\u2F7B'] = '\u7FBD';
  17902. t['\u2F7C'] = '\u8001';
  17903. t['\u2F7D'] = '\u800C';
  17904. t['\u2F7E'] = '\u8012';
  17905. t['\u2F7F'] = '\u8033';
  17906. t['\u2F80'] = '\u807F';
  17907. t['\u2F81'] = '\u8089';
  17908. t['\u2F82'] = '\u81E3';
  17909. t['\u2F83'] = '\u81EA';
  17910. t['\u2F84'] = '\u81F3';
  17911. t['\u2F85'] = '\u81FC';
  17912. t['\u2F86'] = '\u820C';
  17913. t['\u2F87'] = '\u821B';
  17914. t['\u2F88'] = '\u821F';
  17915. t['\u2F89'] = '\u826E';
  17916. t['\u2F8A'] = '\u8272';
  17917. t['\u2F8B'] = '\u8278';
  17918. t['\u2F8C'] = '\u864D';
  17919. t['\u2F8D'] = '\u866B';
  17920. t['\u2F8E'] = '\u8840';
  17921. t['\u2F8F'] = '\u884C';
  17922. t['\u2F90'] = '\u8863';
  17923. t['\u2F91'] = '\u897E';
  17924. t['\u2F92'] = '\u898B';
  17925. t['\u2F93'] = '\u89D2';
  17926. t['\u2F94'] = '\u8A00';
  17927. t['\u2F95'] = '\u8C37';
  17928. t['\u2F96'] = '\u8C46';
  17929. t['\u2F97'] = '\u8C55';
  17930. t['\u2F98'] = '\u8C78';
  17931. t['\u2F99'] = '\u8C9D';
  17932. t['\u2F9A'] = '\u8D64';
  17933. t['\u2F9B'] = '\u8D70';
  17934. t['\u2F9C'] = '\u8DB3';
  17935. t['\u2F9D'] = '\u8EAB';
  17936. t['\u2F9E'] = '\u8ECA';
  17937. t['\u2F9F'] = '\u8F9B';
  17938. t['\u2FA0'] = '\u8FB0';
  17939. t['\u2FA1'] = '\u8FB5';
  17940. t['\u2FA2'] = '\u9091';
  17941. t['\u2FA3'] = '\u9149';
  17942. t['\u2FA4'] = '\u91C6';
  17943. t['\u2FA5'] = '\u91CC';
  17944. t['\u2FA6'] = '\u91D1';
  17945. t['\u2FA7'] = '\u9577';
  17946. t['\u2FA8'] = '\u9580';
  17947. t['\u2FA9'] = '\u961C';
  17948. t['\u2FAA'] = '\u96B6';
  17949. t['\u2FAB'] = '\u96B9';
  17950. t['\u2FAC'] = '\u96E8';
  17951. t['\u2FAD'] = '\u9751';
  17952. t['\u2FAE'] = '\u975E';
  17953. t['\u2FAF'] = '\u9762';
  17954. t['\u2FB0'] = '\u9769';
  17955. t['\u2FB1'] = '\u97CB';
  17956. t['\u2FB2'] = '\u97ED';
  17957. t['\u2FB3'] = '\u97F3';
  17958. t['\u2FB4'] = '\u9801';
  17959. t['\u2FB5'] = '\u98A8';
  17960. t['\u2FB6'] = '\u98DB';
  17961. t['\u2FB7'] = '\u98DF';
  17962. t['\u2FB8'] = '\u9996';
  17963. t['\u2FB9'] = '\u9999';
  17964. t['\u2FBA'] = '\u99AC';
  17965. t['\u2FBB'] = '\u9AA8';
  17966. t['\u2FBC'] = '\u9AD8';
  17967. t['\u2FBD'] = '\u9ADF';
  17968. t['\u2FBE'] = '\u9B25';
  17969. t['\u2FBF'] = '\u9B2F';
  17970. t['\u2FC0'] = '\u9B32';
  17971. t['\u2FC1'] = '\u9B3C';
  17972. t['\u2FC2'] = '\u9B5A';
  17973. t['\u2FC3'] = '\u9CE5';
  17974. t['\u2FC4'] = '\u9E75';
  17975. t['\u2FC5'] = '\u9E7F';
  17976. t['\u2FC6'] = '\u9EA5';
  17977. t['\u2FC7'] = '\u9EBB';
  17978. t['\u2FC8'] = '\u9EC3';
  17979. t['\u2FC9'] = '\u9ECD';
  17980. t['\u2FCA'] = '\u9ED1';
  17981. t['\u2FCB'] = '\u9EF9';
  17982. t['\u2FCC'] = '\u9EFD';
  17983. t['\u2FCD'] = '\u9F0E';
  17984. t['\u2FCE'] = '\u9F13';
  17985. t['\u2FCF'] = '\u9F20';
  17986. t['\u2FD0'] = '\u9F3B';
  17987. t['\u2FD1'] = '\u9F4A';
  17988. t['\u2FD2'] = '\u9F52';
  17989. t['\u2FD3'] = '\u9F8D';
  17990. t['\u2FD4'] = '\u9F9C';
  17991. t['\u2FD5'] = '\u9FA0';
  17992. t['\u3036'] = '\u3012';
  17993. t['\u3038'] = '\u5341';
  17994. t['\u3039'] = '\u5344';
  17995. t['\u303A'] = '\u5345';
  17996. t['\u309B'] = '\u0020\u3099';
  17997. t['\u309C'] = '\u0020\u309A';
  17998. t['\u3131'] = '\u1100';
  17999. t['\u3132'] = '\u1101';
  18000. t['\u3133'] = '\u11AA';
  18001. t['\u3134'] = '\u1102';
  18002. t['\u3135'] = '\u11AC';
  18003. t['\u3136'] = '\u11AD';
  18004. t['\u3137'] = '\u1103';
  18005. t['\u3138'] = '\u1104';
  18006. t['\u3139'] = '\u1105';
  18007. t['\u313A'] = '\u11B0';
  18008. t['\u313B'] = '\u11B1';
  18009. t['\u313C'] = '\u11B2';
  18010. t['\u313D'] = '\u11B3';
  18011. t['\u313E'] = '\u11B4';
  18012. t['\u313F'] = '\u11B5';
  18013. t['\u3140'] = '\u111A';
  18014. t['\u3141'] = '\u1106';
  18015. t['\u3142'] = '\u1107';
  18016. t['\u3143'] = '\u1108';
  18017. t['\u3144'] = '\u1121';
  18018. t['\u3145'] = '\u1109';
  18019. t['\u3146'] = '\u110A';
  18020. t['\u3147'] = '\u110B';
  18021. t['\u3148'] = '\u110C';
  18022. t['\u3149'] = '\u110D';
  18023. t['\u314A'] = '\u110E';
  18024. t['\u314B'] = '\u110F';
  18025. t['\u314C'] = '\u1110';
  18026. t['\u314D'] = '\u1111';
  18027. t['\u314E'] = '\u1112';
  18028. t['\u314F'] = '\u1161';
  18029. t['\u3150'] = '\u1162';
  18030. t['\u3151'] = '\u1163';
  18031. t['\u3152'] = '\u1164';
  18032. t['\u3153'] = '\u1165';
  18033. t['\u3154'] = '\u1166';
  18034. t['\u3155'] = '\u1167';
  18035. t['\u3156'] = '\u1168';
  18036. t['\u3157'] = '\u1169';
  18037. t['\u3158'] = '\u116A';
  18038. t['\u3159'] = '\u116B';
  18039. t['\u315A'] = '\u116C';
  18040. t['\u315B'] = '\u116D';
  18041. t['\u315C'] = '\u116E';
  18042. t['\u315D'] = '\u116F';
  18043. t['\u315E'] = '\u1170';
  18044. t['\u315F'] = '\u1171';
  18045. t['\u3160'] = '\u1172';
  18046. t['\u3161'] = '\u1173';
  18047. t['\u3162'] = '\u1174';
  18048. t['\u3163'] = '\u1175';
  18049. t['\u3164'] = '\u1160';
  18050. t['\u3165'] = '\u1114';
  18051. t['\u3166'] = '\u1115';
  18052. t['\u3167'] = '\u11C7';
  18053. t['\u3168'] = '\u11C8';
  18054. t['\u3169'] = '\u11CC';
  18055. t['\u316A'] = '\u11CE';
  18056. t['\u316B'] = '\u11D3';
  18057. t['\u316C'] = '\u11D7';
  18058. t['\u316D'] = '\u11D9';
  18059. t['\u316E'] = '\u111C';
  18060. t['\u316F'] = '\u11DD';
  18061. t['\u3170'] = '\u11DF';
  18062. t['\u3171'] = '\u111D';
  18063. t['\u3172'] = '\u111E';
  18064. t['\u3173'] = '\u1120';
  18065. t['\u3174'] = '\u1122';
  18066. t['\u3175'] = '\u1123';
  18067. t['\u3176'] = '\u1127';
  18068. t['\u3177'] = '\u1129';
  18069. t['\u3178'] = '\u112B';
  18070. t['\u3179'] = '\u112C';
  18071. t['\u317A'] = '\u112D';
  18072. t['\u317B'] = '\u112E';
  18073. t['\u317C'] = '\u112F';
  18074. t['\u317D'] = '\u1132';
  18075. t['\u317E'] = '\u1136';
  18076. t['\u317F'] = '\u1140';
  18077. t['\u3180'] = '\u1147';
  18078. t['\u3181'] = '\u114C';
  18079. t['\u3182'] = '\u11F1';
  18080. t['\u3183'] = '\u11F2';
  18081. t['\u3184'] = '\u1157';
  18082. t['\u3185'] = '\u1158';
  18083. t['\u3186'] = '\u1159';
  18084. t['\u3187'] = '\u1184';
  18085. t['\u3188'] = '\u1185';
  18086. t['\u3189'] = '\u1188';
  18087. t['\u318A'] = '\u1191';
  18088. t['\u318B'] = '\u1192';
  18089. t['\u318C'] = '\u1194';
  18090. t['\u318D'] = '\u119E';
  18091. t['\u318E'] = '\u11A1';
  18092. t['\u3200'] = '\u0028\u1100\u0029';
  18093. t['\u3201'] = '\u0028\u1102\u0029';
  18094. t['\u3202'] = '\u0028\u1103\u0029';
  18095. t['\u3203'] = '\u0028\u1105\u0029';
  18096. t['\u3204'] = '\u0028\u1106\u0029';
  18097. t['\u3205'] = '\u0028\u1107\u0029';
  18098. t['\u3206'] = '\u0028\u1109\u0029';
  18099. t['\u3207'] = '\u0028\u110B\u0029';
  18100. t['\u3208'] = '\u0028\u110C\u0029';
  18101. t['\u3209'] = '\u0028\u110E\u0029';
  18102. t['\u320A'] = '\u0028\u110F\u0029';
  18103. t['\u320B'] = '\u0028\u1110\u0029';
  18104. t['\u320C'] = '\u0028\u1111\u0029';
  18105. t['\u320D'] = '\u0028\u1112\u0029';
  18106. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  18107. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  18108. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  18109. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  18110. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  18111. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  18112. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  18113. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  18114. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  18115. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  18116. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  18117. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  18118. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  18119. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  18120. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  18121. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  18122. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  18123. t['\u3220'] = '\u0028\u4E00\u0029';
  18124. t['\u3221'] = '\u0028\u4E8C\u0029';
  18125. t['\u3222'] = '\u0028\u4E09\u0029';
  18126. t['\u3223'] = '\u0028\u56DB\u0029';
  18127. t['\u3224'] = '\u0028\u4E94\u0029';
  18128. t['\u3225'] = '\u0028\u516D\u0029';
  18129. t['\u3226'] = '\u0028\u4E03\u0029';
  18130. t['\u3227'] = '\u0028\u516B\u0029';
  18131. t['\u3228'] = '\u0028\u4E5D\u0029';
  18132. t['\u3229'] = '\u0028\u5341\u0029';
  18133. t['\u322A'] = '\u0028\u6708\u0029';
  18134. t['\u322B'] = '\u0028\u706B\u0029';
  18135. t['\u322C'] = '\u0028\u6C34\u0029';
  18136. t['\u322D'] = '\u0028\u6728\u0029';
  18137. t['\u322E'] = '\u0028\u91D1\u0029';
  18138. t['\u322F'] = '\u0028\u571F\u0029';
  18139. t['\u3230'] = '\u0028\u65E5\u0029';
  18140. t['\u3231'] = '\u0028\u682A\u0029';
  18141. t['\u3232'] = '\u0028\u6709\u0029';
  18142. t['\u3233'] = '\u0028\u793E\u0029';
  18143. t['\u3234'] = '\u0028\u540D\u0029';
  18144. t['\u3235'] = '\u0028\u7279\u0029';
  18145. t['\u3236'] = '\u0028\u8CA1\u0029';
  18146. t['\u3237'] = '\u0028\u795D\u0029';
  18147. t['\u3238'] = '\u0028\u52B4\u0029';
  18148. t['\u3239'] = '\u0028\u4EE3\u0029';
  18149. t['\u323A'] = '\u0028\u547C\u0029';
  18150. t['\u323B'] = '\u0028\u5B66\u0029';
  18151. t['\u323C'] = '\u0028\u76E3\u0029';
  18152. t['\u323D'] = '\u0028\u4F01\u0029';
  18153. t['\u323E'] = '\u0028\u8CC7\u0029';
  18154. t['\u323F'] = '\u0028\u5354\u0029';
  18155. t['\u3240'] = '\u0028\u796D\u0029';
  18156. t['\u3241'] = '\u0028\u4F11\u0029';
  18157. t['\u3242'] = '\u0028\u81EA\u0029';
  18158. t['\u3243'] = '\u0028\u81F3\u0029';
  18159. t['\u32C0'] = '\u0031\u6708';
  18160. t['\u32C1'] = '\u0032\u6708';
  18161. t['\u32C2'] = '\u0033\u6708';
  18162. t['\u32C3'] = '\u0034\u6708';
  18163. t['\u32C4'] = '\u0035\u6708';
  18164. t['\u32C5'] = '\u0036\u6708';
  18165. t['\u32C6'] = '\u0037\u6708';
  18166. t['\u32C7'] = '\u0038\u6708';
  18167. t['\u32C8'] = '\u0039\u6708';
  18168. t['\u32C9'] = '\u0031\u0030\u6708';
  18169. t['\u32CA'] = '\u0031\u0031\u6708';
  18170. t['\u32CB'] = '\u0031\u0032\u6708';
  18171. t['\u3358'] = '\u0030\u70B9';
  18172. t['\u3359'] = '\u0031\u70B9';
  18173. t['\u335A'] = '\u0032\u70B9';
  18174. t['\u335B'] = '\u0033\u70B9';
  18175. t['\u335C'] = '\u0034\u70B9';
  18176. t['\u335D'] = '\u0035\u70B9';
  18177. t['\u335E'] = '\u0036\u70B9';
  18178. t['\u335F'] = '\u0037\u70B9';
  18179. t['\u3360'] = '\u0038\u70B9';
  18180. t['\u3361'] = '\u0039\u70B9';
  18181. t['\u3362'] = '\u0031\u0030\u70B9';
  18182. t['\u3363'] = '\u0031\u0031\u70B9';
  18183. t['\u3364'] = '\u0031\u0032\u70B9';
  18184. t['\u3365'] = '\u0031\u0033\u70B9';
  18185. t['\u3366'] = '\u0031\u0034\u70B9';
  18186. t['\u3367'] = '\u0031\u0035\u70B9';
  18187. t['\u3368'] = '\u0031\u0036\u70B9';
  18188. t['\u3369'] = '\u0031\u0037\u70B9';
  18189. t['\u336A'] = '\u0031\u0038\u70B9';
  18190. t['\u336B'] = '\u0031\u0039\u70B9';
  18191. t['\u336C'] = '\u0032\u0030\u70B9';
  18192. t['\u336D'] = '\u0032\u0031\u70B9';
  18193. t['\u336E'] = '\u0032\u0032\u70B9';
  18194. t['\u336F'] = '\u0032\u0033\u70B9';
  18195. t['\u3370'] = '\u0032\u0034\u70B9';
  18196. t['\u33E0'] = '\u0031\u65E5';
  18197. t['\u33E1'] = '\u0032\u65E5';
  18198. t['\u33E2'] = '\u0033\u65E5';
  18199. t['\u33E3'] = '\u0034\u65E5';
  18200. t['\u33E4'] = '\u0035\u65E5';
  18201. t['\u33E5'] = '\u0036\u65E5';
  18202. t['\u33E6'] = '\u0037\u65E5';
  18203. t['\u33E7'] = '\u0038\u65E5';
  18204. t['\u33E8'] = '\u0039\u65E5';
  18205. t['\u33E9'] = '\u0031\u0030\u65E5';
  18206. t['\u33EA'] = '\u0031\u0031\u65E5';
  18207. t['\u33EB'] = '\u0031\u0032\u65E5';
  18208. t['\u33EC'] = '\u0031\u0033\u65E5';
  18209. t['\u33ED'] = '\u0031\u0034\u65E5';
  18210. t['\u33EE'] = '\u0031\u0035\u65E5';
  18211. t['\u33EF'] = '\u0031\u0036\u65E5';
  18212. t['\u33F0'] = '\u0031\u0037\u65E5';
  18213. t['\u33F1'] = '\u0031\u0038\u65E5';
  18214. t['\u33F2'] = '\u0031\u0039\u65E5';
  18215. t['\u33F3'] = '\u0032\u0030\u65E5';
  18216. t['\u33F4'] = '\u0032\u0031\u65E5';
  18217. t['\u33F5'] = '\u0032\u0032\u65E5';
  18218. t['\u33F6'] = '\u0032\u0033\u65E5';
  18219. t['\u33F7'] = '\u0032\u0034\u65E5';
  18220. t['\u33F8'] = '\u0032\u0035\u65E5';
  18221. t['\u33F9'] = '\u0032\u0036\u65E5';
  18222. t['\u33FA'] = '\u0032\u0037\u65E5';
  18223. t['\u33FB'] = '\u0032\u0038\u65E5';
  18224. t['\u33FC'] = '\u0032\u0039\u65E5';
  18225. t['\u33FD'] = '\u0033\u0030\u65E5';
  18226. t['\u33FE'] = '\u0033\u0031\u65E5';
  18227. t['\uFB00'] = '\u0066\u0066';
  18228. t['\uFB01'] = '\u0066\u0069';
  18229. t['\uFB02'] = '\u0066\u006C';
  18230. t['\uFB03'] = '\u0066\u0066\u0069';
  18231. t['\uFB04'] = '\u0066\u0066\u006C';
  18232. t['\uFB05'] = '\u017F\u0074';
  18233. t['\uFB06'] = '\u0073\u0074';
  18234. t['\uFB13'] = '\u0574\u0576';
  18235. t['\uFB14'] = '\u0574\u0565';
  18236. t['\uFB15'] = '\u0574\u056B';
  18237. t['\uFB16'] = '\u057E\u0576';
  18238. t['\uFB17'] = '\u0574\u056D';
  18239. t['\uFB4F'] = '\u05D0\u05DC';
  18240. t['\uFB50'] = '\u0671';
  18241. t['\uFB51'] = '\u0671';
  18242. t['\uFB52'] = '\u067B';
  18243. t['\uFB53'] = '\u067B';
  18244. t['\uFB54'] = '\u067B';
  18245. t['\uFB55'] = '\u067B';
  18246. t['\uFB56'] = '\u067E';
  18247. t['\uFB57'] = '\u067E';
  18248. t['\uFB58'] = '\u067E';
  18249. t['\uFB59'] = '\u067E';
  18250. t['\uFB5A'] = '\u0680';
  18251. t['\uFB5B'] = '\u0680';
  18252. t['\uFB5C'] = '\u0680';
  18253. t['\uFB5D'] = '\u0680';
  18254. t['\uFB5E'] = '\u067A';
  18255. t['\uFB5F'] = '\u067A';
  18256. t['\uFB60'] = '\u067A';
  18257. t['\uFB61'] = '\u067A';
  18258. t['\uFB62'] = '\u067F';
  18259. t['\uFB63'] = '\u067F';
  18260. t['\uFB64'] = '\u067F';
  18261. t['\uFB65'] = '\u067F';
  18262. t['\uFB66'] = '\u0679';
  18263. t['\uFB67'] = '\u0679';
  18264. t['\uFB68'] = '\u0679';
  18265. t['\uFB69'] = '\u0679';
  18266. t['\uFB6A'] = '\u06A4';
  18267. t['\uFB6B'] = '\u06A4';
  18268. t['\uFB6C'] = '\u06A4';
  18269. t['\uFB6D'] = '\u06A4';
  18270. t['\uFB6E'] = '\u06A6';
  18271. t['\uFB6F'] = '\u06A6';
  18272. t['\uFB70'] = '\u06A6';
  18273. t['\uFB71'] = '\u06A6';
  18274. t['\uFB72'] = '\u0684';
  18275. t['\uFB73'] = '\u0684';
  18276. t['\uFB74'] = '\u0684';
  18277. t['\uFB75'] = '\u0684';
  18278. t['\uFB76'] = '\u0683';
  18279. t['\uFB77'] = '\u0683';
  18280. t['\uFB78'] = '\u0683';
  18281. t['\uFB79'] = '\u0683';
  18282. t['\uFB7A'] = '\u0686';
  18283. t['\uFB7B'] = '\u0686';
  18284. t['\uFB7C'] = '\u0686';
  18285. t['\uFB7D'] = '\u0686';
  18286. t['\uFB7E'] = '\u0687';
  18287. t['\uFB7F'] = '\u0687';
  18288. t['\uFB80'] = '\u0687';
  18289. t['\uFB81'] = '\u0687';
  18290. t['\uFB82'] = '\u068D';
  18291. t['\uFB83'] = '\u068D';
  18292. t['\uFB84'] = '\u068C';
  18293. t['\uFB85'] = '\u068C';
  18294. t['\uFB86'] = '\u068E';
  18295. t['\uFB87'] = '\u068E';
  18296. t['\uFB88'] = '\u0688';
  18297. t['\uFB89'] = '\u0688';
  18298. t['\uFB8A'] = '\u0698';
  18299. t['\uFB8B'] = '\u0698';
  18300. t['\uFB8C'] = '\u0691';
  18301. t['\uFB8D'] = '\u0691';
  18302. t['\uFB8E'] = '\u06A9';
  18303. t['\uFB8F'] = '\u06A9';
  18304. t['\uFB90'] = '\u06A9';
  18305. t['\uFB91'] = '\u06A9';
  18306. t['\uFB92'] = '\u06AF';
  18307. t['\uFB93'] = '\u06AF';
  18308. t['\uFB94'] = '\u06AF';
  18309. t['\uFB95'] = '\u06AF';
  18310. t['\uFB96'] = '\u06B3';
  18311. t['\uFB97'] = '\u06B3';
  18312. t['\uFB98'] = '\u06B3';
  18313. t['\uFB99'] = '\u06B3';
  18314. t['\uFB9A'] = '\u06B1';
  18315. t['\uFB9B'] = '\u06B1';
  18316. t['\uFB9C'] = '\u06B1';
  18317. t['\uFB9D'] = '\u06B1';
  18318. t['\uFB9E'] = '\u06BA';
  18319. t['\uFB9F'] = '\u06BA';
  18320. t['\uFBA0'] = '\u06BB';
  18321. t['\uFBA1'] = '\u06BB';
  18322. t['\uFBA2'] = '\u06BB';
  18323. t['\uFBA3'] = '\u06BB';
  18324. t['\uFBA4'] = '\u06C0';
  18325. t['\uFBA5'] = '\u06C0';
  18326. t['\uFBA6'] = '\u06C1';
  18327. t['\uFBA7'] = '\u06C1';
  18328. t['\uFBA8'] = '\u06C1';
  18329. t['\uFBA9'] = '\u06C1';
  18330. t['\uFBAA'] = '\u06BE';
  18331. t['\uFBAB'] = '\u06BE';
  18332. t['\uFBAC'] = '\u06BE';
  18333. t['\uFBAD'] = '\u06BE';
  18334. t['\uFBAE'] = '\u06D2';
  18335. t['\uFBAF'] = '\u06D2';
  18336. t['\uFBB0'] = '\u06D3';
  18337. t['\uFBB1'] = '\u06D3';
  18338. t['\uFBD3'] = '\u06AD';
  18339. t['\uFBD4'] = '\u06AD';
  18340. t['\uFBD5'] = '\u06AD';
  18341. t['\uFBD6'] = '\u06AD';
  18342. t['\uFBD7'] = '\u06C7';
  18343. t['\uFBD8'] = '\u06C7';
  18344. t['\uFBD9'] = '\u06C6';
  18345. t['\uFBDA'] = '\u06C6';
  18346. t['\uFBDB'] = '\u06C8';
  18347. t['\uFBDC'] = '\u06C8';
  18348. t['\uFBDD'] = '\u0677';
  18349. t['\uFBDE'] = '\u06CB';
  18350. t['\uFBDF'] = '\u06CB';
  18351. t['\uFBE0'] = '\u06C5';
  18352. t['\uFBE1'] = '\u06C5';
  18353. t['\uFBE2'] = '\u06C9';
  18354. t['\uFBE3'] = '\u06C9';
  18355. t['\uFBE4'] = '\u06D0';
  18356. t['\uFBE5'] = '\u06D0';
  18357. t['\uFBE6'] = '\u06D0';
  18358. t['\uFBE7'] = '\u06D0';
  18359. t['\uFBE8'] = '\u0649';
  18360. t['\uFBE9'] = '\u0649';
  18361. t['\uFBEA'] = '\u0626\u0627';
  18362. t['\uFBEB'] = '\u0626\u0627';
  18363. t['\uFBEC'] = '\u0626\u06D5';
  18364. t['\uFBED'] = '\u0626\u06D5';
  18365. t['\uFBEE'] = '\u0626\u0648';
  18366. t['\uFBEF'] = '\u0626\u0648';
  18367. t['\uFBF0'] = '\u0626\u06C7';
  18368. t['\uFBF1'] = '\u0626\u06C7';
  18369. t['\uFBF2'] = '\u0626\u06C6';
  18370. t['\uFBF3'] = '\u0626\u06C6';
  18371. t['\uFBF4'] = '\u0626\u06C8';
  18372. t['\uFBF5'] = '\u0626\u06C8';
  18373. t['\uFBF6'] = '\u0626\u06D0';
  18374. t['\uFBF7'] = '\u0626\u06D0';
  18375. t['\uFBF8'] = '\u0626\u06D0';
  18376. t['\uFBF9'] = '\u0626\u0649';
  18377. t['\uFBFA'] = '\u0626\u0649';
  18378. t['\uFBFB'] = '\u0626\u0649';
  18379. t['\uFBFC'] = '\u06CC';
  18380. t['\uFBFD'] = '\u06CC';
  18381. t['\uFBFE'] = '\u06CC';
  18382. t['\uFBFF'] = '\u06CC';
  18383. t['\uFC00'] = '\u0626\u062C';
  18384. t['\uFC01'] = '\u0626\u062D';
  18385. t['\uFC02'] = '\u0626\u0645';
  18386. t['\uFC03'] = '\u0626\u0649';
  18387. t['\uFC04'] = '\u0626\u064A';
  18388. t['\uFC05'] = '\u0628\u062C';
  18389. t['\uFC06'] = '\u0628\u062D';
  18390. t['\uFC07'] = '\u0628\u062E';
  18391. t['\uFC08'] = '\u0628\u0645';
  18392. t['\uFC09'] = '\u0628\u0649';
  18393. t['\uFC0A'] = '\u0628\u064A';
  18394. t['\uFC0B'] = '\u062A\u062C';
  18395. t['\uFC0C'] = '\u062A\u062D';
  18396. t['\uFC0D'] = '\u062A\u062E';
  18397. t['\uFC0E'] = '\u062A\u0645';
  18398. t['\uFC0F'] = '\u062A\u0649';
  18399. t['\uFC10'] = '\u062A\u064A';
  18400. t['\uFC11'] = '\u062B\u062C';
  18401. t['\uFC12'] = '\u062B\u0645';
  18402. t['\uFC13'] = '\u062B\u0649';
  18403. t['\uFC14'] = '\u062B\u064A';
  18404. t['\uFC15'] = '\u062C\u062D';
  18405. t['\uFC16'] = '\u062C\u0645';
  18406. t['\uFC17'] = '\u062D\u062C';
  18407. t['\uFC18'] = '\u062D\u0645';
  18408. t['\uFC19'] = '\u062E\u062C';
  18409. t['\uFC1A'] = '\u062E\u062D';
  18410. t['\uFC1B'] = '\u062E\u0645';
  18411. t['\uFC1C'] = '\u0633\u062C';
  18412. t['\uFC1D'] = '\u0633\u062D';
  18413. t['\uFC1E'] = '\u0633\u062E';
  18414. t['\uFC1F'] = '\u0633\u0645';
  18415. t['\uFC20'] = '\u0635\u062D';
  18416. t['\uFC21'] = '\u0635\u0645';
  18417. t['\uFC22'] = '\u0636\u062C';
  18418. t['\uFC23'] = '\u0636\u062D';
  18419. t['\uFC24'] = '\u0636\u062E';
  18420. t['\uFC25'] = '\u0636\u0645';
  18421. t['\uFC26'] = '\u0637\u062D';
  18422. t['\uFC27'] = '\u0637\u0645';
  18423. t['\uFC28'] = '\u0638\u0645';
  18424. t['\uFC29'] = '\u0639\u062C';
  18425. t['\uFC2A'] = '\u0639\u0645';
  18426. t['\uFC2B'] = '\u063A\u062C';
  18427. t['\uFC2C'] = '\u063A\u0645';
  18428. t['\uFC2D'] = '\u0641\u062C';
  18429. t['\uFC2E'] = '\u0641\u062D';
  18430. t['\uFC2F'] = '\u0641\u062E';
  18431. t['\uFC30'] = '\u0641\u0645';
  18432. t['\uFC31'] = '\u0641\u0649';
  18433. t['\uFC32'] = '\u0641\u064A';
  18434. t['\uFC33'] = '\u0642\u062D';
  18435. t['\uFC34'] = '\u0642\u0645';
  18436. t['\uFC35'] = '\u0642\u0649';
  18437. t['\uFC36'] = '\u0642\u064A';
  18438. t['\uFC37'] = '\u0643\u0627';
  18439. t['\uFC38'] = '\u0643\u062C';
  18440. t['\uFC39'] = '\u0643\u062D';
  18441. t['\uFC3A'] = '\u0643\u062E';
  18442. t['\uFC3B'] = '\u0643\u0644';
  18443. t['\uFC3C'] = '\u0643\u0645';
  18444. t['\uFC3D'] = '\u0643\u0649';
  18445. t['\uFC3E'] = '\u0643\u064A';
  18446. t['\uFC3F'] = '\u0644\u062C';
  18447. t['\uFC40'] = '\u0644\u062D';
  18448. t['\uFC41'] = '\u0644\u062E';
  18449. t['\uFC42'] = '\u0644\u0645';
  18450. t['\uFC43'] = '\u0644\u0649';
  18451. t['\uFC44'] = '\u0644\u064A';
  18452. t['\uFC45'] = '\u0645\u062C';
  18453. t['\uFC46'] = '\u0645\u062D';
  18454. t['\uFC47'] = '\u0645\u062E';
  18455. t['\uFC48'] = '\u0645\u0645';
  18456. t['\uFC49'] = '\u0645\u0649';
  18457. t['\uFC4A'] = '\u0645\u064A';
  18458. t['\uFC4B'] = '\u0646\u062C';
  18459. t['\uFC4C'] = '\u0646\u062D';
  18460. t['\uFC4D'] = '\u0646\u062E';
  18461. t['\uFC4E'] = '\u0646\u0645';
  18462. t['\uFC4F'] = '\u0646\u0649';
  18463. t['\uFC50'] = '\u0646\u064A';
  18464. t['\uFC51'] = '\u0647\u062C';
  18465. t['\uFC52'] = '\u0647\u0645';
  18466. t['\uFC53'] = '\u0647\u0649';
  18467. t['\uFC54'] = '\u0647\u064A';
  18468. t['\uFC55'] = '\u064A\u062C';
  18469. t['\uFC56'] = '\u064A\u062D';
  18470. t['\uFC57'] = '\u064A\u062E';
  18471. t['\uFC58'] = '\u064A\u0645';
  18472. t['\uFC59'] = '\u064A\u0649';
  18473. t['\uFC5A'] = '\u064A\u064A';
  18474. t['\uFC5B'] = '\u0630\u0670';
  18475. t['\uFC5C'] = '\u0631\u0670';
  18476. t['\uFC5D'] = '\u0649\u0670';
  18477. t['\uFC5E'] = '\u0020\u064C\u0651';
  18478. t['\uFC5F'] = '\u0020\u064D\u0651';
  18479. t['\uFC60'] = '\u0020\u064E\u0651';
  18480. t['\uFC61'] = '\u0020\u064F\u0651';
  18481. t['\uFC62'] = '\u0020\u0650\u0651';
  18482. t['\uFC63'] = '\u0020\u0651\u0670';
  18483. t['\uFC64'] = '\u0626\u0631';
  18484. t['\uFC65'] = '\u0626\u0632';
  18485. t['\uFC66'] = '\u0626\u0645';
  18486. t['\uFC67'] = '\u0626\u0646';
  18487. t['\uFC68'] = '\u0626\u0649';
  18488. t['\uFC69'] = '\u0626\u064A';
  18489. t['\uFC6A'] = '\u0628\u0631';
  18490. t['\uFC6B'] = '\u0628\u0632';
  18491. t['\uFC6C'] = '\u0628\u0645';
  18492. t['\uFC6D'] = '\u0628\u0646';
  18493. t['\uFC6E'] = '\u0628\u0649';
  18494. t['\uFC6F'] = '\u0628\u064A';
  18495. t['\uFC70'] = '\u062A\u0631';
  18496. t['\uFC71'] = '\u062A\u0632';
  18497. t['\uFC72'] = '\u062A\u0645';
  18498. t['\uFC73'] = '\u062A\u0646';
  18499. t['\uFC74'] = '\u062A\u0649';
  18500. t['\uFC75'] = '\u062A\u064A';
  18501. t['\uFC76'] = '\u062B\u0631';
  18502. t['\uFC77'] = '\u062B\u0632';
  18503. t['\uFC78'] = '\u062B\u0645';
  18504. t['\uFC79'] = '\u062B\u0646';
  18505. t['\uFC7A'] = '\u062B\u0649';
  18506. t['\uFC7B'] = '\u062B\u064A';
  18507. t['\uFC7C'] = '\u0641\u0649';
  18508. t['\uFC7D'] = '\u0641\u064A';
  18509. t['\uFC7E'] = '\u0642\u0649';
  18510. t['\uFC7F'] = '\u0642\u064A';
  18511. t['\uFC80'] = '\u0643\u0627';
  18512. t['\uFC81'] = '\u0643\u0644';
  18513. t['\uFC82'] = '\u0643\u0645';
  18514. t['\uFC83'] = '\u0643\u0649';
  18515. t['\uFC84'] = '\u0643\u064A';
  18516. t['\uFC85'] = '\u0644\u0645';
  18517. t['\uFC86'] = '\u0644\u0649';
  18518. t['\uFC87'] = '\u0644\u064A';
  18519. t['\uFC88'] = '\u0645\u0627';
  18520. t['\uFC89'] = '\u0645\u0645';
  18521. t['\uFC8A'] = '\u0646\u0631';
  18522. t['\uFC8B'] = '\u0646\u0632';
  18523. t['\uFC8C'] = '\u0646\u0645';
  18524. t['\uFC8D'] = '\u0646\u0646';
  18525. t['\uFC8E'] = '\u0646\u0649';
  18526. t['\uFC8F'] = '\u0646\u064A';
  18527. t['\uFC90'] = '\u0649\u0670';
  18528. t['\uFC91'] = '\u064A\u0631';
  18529. t['\uFC92'] = '\u064A\u0632';
  18530. t['\uFC93'] = '\u064A\u0645';
  18531. t['\uFC94'] = '\u064A\u0646';
  18532. t['\uFC95'] = '\u064A\u0649';
  18533. t['\uFC96'] = '\u064A\u064A';
  18534. t['\uFC97'] = '\u0626\u062C';
  18535. t['\uFC98'] = '\u0626\u062D';
  18536. t['\uFC99'] = '\u0626\u062E';
  18537. t['\uFC9A'] = '\u0626\u0645';
  18538. t['\uFC9B'] = '\u0626\u0647';
  18539. t['\uFC9C'] = '\u0628\u062C';
  18540. t['\uFC9D'] = '\u0628\u062D';
  18541. t['\uFC9E'] = '\u0628\u062E';
  18542. t['\uFC9F'] = '\u0628\u0645';
  18543. t['\uFCA0'] = '\u0628\u0647';
  18544. t['\uFCA1'] = '\u062A\u062C';
  18545. t['\uFCA2'] = '\u062A\u062D';
  18546. t['\uFCA3'] = '\u062A\u062E';
  18547. t['\uFCA4'] = '\u062A\u0645';
  18548. t['\uFCA5'] = '\u062A\u0647';
  18549. t['\uFCA6'] = '\u062B\u0645';
  18550. t['\uFCA7'] = '\u062C\u062D';
  18551. t['\uFCA8'] = '\u062C\u0645';
  18552. t['\uFCA9'] = '\u062D\u062C';
  18553. t['\uFCAA'] = '\u062D\u0645';
  18554. t['\uFCAB'] = '\u062E\u062C';
  18555. t['\uFCAC'] = '\u062E\u0645';
  18556. t['\uFCAD'] = '\u0633\u062C';
  18557. t['\uFCAE'] = '\u0633\u062D';
  18558. t['\uFCAF'] = '\u0633\u062E';
  18559. t['\uFCB0'] = '\u0633\u0645';
  18560. t['\uFCB1'] = '\u0635\u062D';
  18561. t['\uFCB2'] = '\u0635\u062E';
  18562. t['\uFCB3'] = '\u0635\u0645';
  18563. t['\uFCB4'] = '\u0636\u062C';
  18564. t['\uFCB5'] = '\u0636\u062D';
  18565. t['\uFCB6'] = '\u0636\u062E';
  18566. t['\uFCB7'] = '\u0636\u0645';
  18567. t['\uFCB8'] = '\u0637\u062D';
  18568. t['\uFCB9'] = '\u0638\u0645';
  18569. t['\uFCBA'] = '\u0639\u062C';
  18570. t['\uFCBB'] = '\u0639\u0645';
  18571. t['\uFCBC'] = '\u063A\u062C';
  18572. t['\uFCBD'] = '\u063A\u0645';
  18573. t['\uFCBE'] = '\u0641\u062C';
  18574. t['\uFCBF'] = '\u0641\u062D';
  18575. t['\uFCC0'] = '\u0641\u062E';
  18576. t['\uFCC1'] = '\u0641\u0645';
  18577. t['\uFCC2'] = '\u0642\u062D';
  18578. t['\uFCC3'] = '\u0642\u0645';
  18579. t['\uFCC4'] = '\u0643\u062C';
  18580. t['\uFCC5'] = '\u0643\u062D';
  18581. t['\uFCC6'] = '\u0643\u062E';
  18582. t['\uFCC7'] = '\u0643\u0644';
  18583. t['\uFCC8'] = '\u0643\u0645';
  18584. t['\uFCC9'] = '\u0644\u062C';
  18585. t['\uFCCA'] = '\u0644\u062D';
  18586. t['\uFCCB'] = '\u0644\u062E';
  18587. t['\uFCCC'] = '\u0644\u0645';
  18588. t['\uFCCD'] = '\u0644\u0647';
  18589. t['\uFCCE'] = '\u0645\u062C';
  18590. t['\uFCCF'] = '\u0645\u062D';
  18591. t['\uFCD0'] = '\u0645\u062E';
  18592. t['\uFCD1'] = '\u0645\u0645';
  18593. t['\uFCD2'] = '\u0646\u062C';
  18594. t['\uFCD3'] = '\u0646\u062D';
  18595. t['\uFCD4'] = '\u0646\u062E';
  18596. t['\uFCD5'] = '\u0646\u0645';
  18597. t['\uFCD6'] = '\u0646\u0647';
  18598. t['\uFCD7'] = '\u0647\u062C';
  18599. t['\uFCD8'] = '\u0647\u0645';
  18600. t['\uFCD9'] = '\u0647\u0670';
  18601. t['\uFCDA'] = '\u064A\u062C';
  18602. t['\uFCDB'] = '\u064A\u062D';
  18603. t['\uFCDC'] = '\u064A\u062E';
  18604. t['\uFCDD'] = '\u064A\u0645';
  18605. t['\uFCDE'] = '\u064A\u0647';
  18606. t['\uFCDF'] = '\u0626\u0645';
  18607. t['\uFCE0'] = '\u0626\u0647';
  18608. t['\uFCE1'] = '\u0628\u0645';
  18609. t['\uFCE2'] = '\u0628\u0647';
  18610. t['\uFCE3'] = '\u062A\u0645';
  18611. t['\uFCE4'] = '\u062A\u0647';
  18612. t['\uFCE5'] = '\u062B\u0645';
  18613. t['\uFCE6'] = '\u062B\u0647';
  18614. t['\uFCE7'] = '\u0633\u0645';
  18615. t['\uFCE8'] = '\u0633\u0647';
  18616. t['\uFCE9'] = '\u0634\u0645';
  18617. t['\uFCEA'] = '\u0634\u0647';
  18618. t['\uFCEB'] = '\u0643\u0644';
  18619. t['\uFCEC'] = '\u0643\u0645';
  18620. t['\uFCED'] = '\u0644\u0645';
  18621. t['\uFCEE'] = '\u0646\u0645';
  18622. t['\uFCEF'] = '\u0646\u0647';
  18623. t['\uFCF0'] = '\u064A\u0645';
  18624. t['\uFCF1'] = '\u064A\u0647';
  18625. t['\uFCF2'] = '\u0640\u064E\u0651';
  18626. t['\uFCF3'] = '\u0640\u064F\u0651';
  18627. t['\uFCF4'] = '\u0640\u0650\u0651';
  18628. t['\uFCF5'] = '\u0637\u0649';
  18629. t['\uFCF6'] = '\u0637\u064A';
  18630. t['\uFCF7'] = '\u0639\u0649';
  18631. t['\uFCF8'] = '\u0639\u064A';
  18632. t['\uFCF9'] = '\u063A\u0649';
  18633. t['\uFCFA'] = '\u063A\u064A';
  18634. t['\uFCFB'] = '\u0633\u0649';
  18635. t['\uFCFC'] = '\u0633\u064A';
  18636. t['\uFCFD'] = '\u0634\u0649';
  18637. t['\uFCFE'] = '\u0634\u064A';
  18638. t['\uFCFF'] = '\u062D\u0649';
  18639. t['\uFD00'] = '\u062D\u064A';
  18640. t['\uFD01'] = '\u062C\u0649';
  18641. t['\uFD02'] = '\u062C\u064A';
  18642. t['\uFD03'] = '\u062E\u0649';
  18643. t['\uFD04'] = '\u062E\u064A';
  18644. t['\uFD05'] = '\u0635\u0649';
  18645. t['\uFD06'] = '\u0635\u064A';
  18646. t['\uFD07'] = '\u0636\u0649';
  18647. t['\uFD08'] = '\u0636\u064A';
  18648. t['\uFD09'] = '\u0634\u062C';
  18649. t['\uFD0A'] = '\u0634\u062D';
  18650. t['\uFD0B'] = '\u0634\u062E';
  18651. t['\uFD0C'] = '\u0634\u0645';
  18652. t['\uFD0D'] = '\u0634\u0631';
  18653. t['\uFD0E'] = '\u0633\u0631';
  18654. t['\uFD0F'] = '\u0635\u0631';
  18655. t['\uFD10'] = '\u0636\u0631';
  18656. t['\uFD11'] = '\u0637\u0649';
  18657. t['\uFD12'] = '\u0637\u064A';
  18658. t['\uFD13'] = '\u0639\u0649';
  18659. t['\uFD14'] = '\u0639\u064A';
  18660. t['\uFD15'] = '\u063A\u0649';
  18661. t['\uFD16'] = '\u063A\u064A';
  18662. t['\uFD17'] = '\u0633\u0649';
  18663. t['\uFD18'] = '\u0633\u064A';
  18664. t['\uFD19'] = '\u0634\u0649';
  18665. t['\uFD1A'] = '\u0634\u064A';
  18666. t['\uFD1B'] = '\u062D\u0649';
  18667. t['\uFD1C'] = '\u062D\u064A';
  18668. t['\uFD1D'] = '\u062C\u0649';
  18669. t['\uFD1E'] = '\u062C\u064A';
  18670. t['\uFD1F'] = '\u062E\u0649';
  18671. t['\uFD20'] = '\u062E\u064A';
  18672. t['\uFD21'] = '\u0635\u0649';
  18673. t['\uFD22'] = '\u0635\u064A';
  18674. t['\uFD23'] = '\u0636\u0649';
  18675. t['\uFD24'] = '\u0636\u064A';
  18676. t['\uFD25'] = '\u0634\u062C';
  18677. t['\uFD26'] = '\u0634\u062D';
  18678. t['\uFD27'] = '\u0634\u062E';
  18679. t['\uFD28'] = '\u0634\u0645';
  18680. t['\uFD29'] = '\u0634\u0631';
  18681. t['\uFD2A'] = '\u0633\u0631';
  18682. t['\uFD2B'] = '\u0635\u0631';
  18683. t['\uFD2C'] = '\u0636\u0631';
  18684. t['\uFD2D'] = '\u0634\u062C';
  18685. t['\uFD2E'] = '\u0634\u062D';
  18686. t['\uFD2F'] = '\u0634\u062E';
  18687. t['\uFD30'] = '\u0634\u0645';
  18688. t['\uFD31'] = '\u0633\u0647';
  18689. t['\uFD32'] = '\u0634\u0647';
  18690. t['\uFD33'] = '\u0637\u0645';
  18691. t['\uFD34'] = '\u0633\u062C';
  18692. t['\uFD35'] = '\u0633\u062D';
  18693. t['\uFD36'] = '\u0633\u062E';
  18694. t['\uFD37'] = '\u0634\u062C';
  18695. t['\uFD38'] = '\u0634\u062D';
  18696. t['\uFD39'] = '\u0634\u062E';
  18697. t['\uFD3A'] = '\u0637\u0645';
  18698. t['\uFD3B'] = '\u0638\u0645';
  18699. t['\uFD3C'] = '\u0627\u064B';
  18700. t['\uFD3D'] = '\u0627\u064B';
  18701. t['\uFD50'] = '\u062A\u062C\u0645';
  18702. t['\uFD51'] = '\u062A\u062D\u062C';
  18703. t['\uFD52'] = '\u062A\u062D\u062C';
  18704. t['\uFD53'] = '\u062A\u062D\u0645';
  18705. t['\uFD54'] = '\u062A\u062E\u0645';
  18706. t['\uFD55'] = '\u062A\u0645\u062C';
  18707. t['\uFD56'] = '\u062A\u0645\u062D';
  18708. t['\uFD57'] = '\u062A\u0645\u062E';
  18709. t['\uFD58'] = '\u062C\u0645\u062D';
  18710. t['\uFD59'] = '\u062C\u0645\u062D';
  18711. t['\uFD5A'] = '\u062D\u0645\u064A';
  18712. t['\uFD5B'] = '\u062D\u0645\u0649';
  18713. t['\uFD5C'] = '\u0633\u062D\u062C';
  18714. t['\uFD5D'] = '\u0633\u062C\u062D';
  18715. t['\uFD5E'] = '\u0633\u062C\u0649';
  18716. t['\uFD5F'] = '\u0633\u0645\u062D';
  18717. t['\uFD60'] = '\u0633\u0645\u062D';
  18718. t['\uFD61'] = '\u0633\u0645\u062C';
  18719. t['\uFD62'] = '\u0633\u0645\u0645';
  18720. t['\uFD63'] = '\u0633\u0645\u0645';
  18721. t['\uFD64'] = '\u0635\u062D\u062D';
  18722. t['\uFD65'] = '\u0635\u062D\u062D';
  18723. t['\uFD66'] = '\u0635\u0645\u0645';
  18724. t['\uFD67'] = '\u0634\u062D\u0645';
  18725. t['\uFD68'] = '\u0634\u062D\u0645';
  18726. t['\uFD69'] = '\u0634\u062C\u064A';
  18727. t['\uFD6A'] = '\u0634\u0645\u062E';
  18728. t['\uFD6B'] = '\u0634\u0645\u062E';
  18729. t['\uFD6C'] = '\u0634\u0645\u0645';
  18730. t['\uFD6D'] = '\u0634\u0645\u0645';
  18731. t['\uFD6E'] = '\u0636\u062D\u0649';
  18732. t['\uFD6F'] = '\u0636\u062E\u0645';
  18733. t['\uFD70'] = '\u0636\u062E\u0645';
  18734. t['\uFD71'] = '\u0637\u0645\u062D';
  18735. t['\uFD72'] = '\u0637\u0645\u062D';
  18736. t['\uFD73'] = '\u0637\u0645\u0645';
  18737. t['\uFD74'] = '\u0637\u0645\u064A';
  18738. t['\uFD75'] = '\u0639\u062C\u0645';
  18739. t['\uFD76'] = '\u0639\u0645\u0645';
  18740. t['\uFD77'] = '\u0639\u0645\u0645';
  18741. t['\uFD78'] = '\u0639\u0645\u0649';
  18742. t['\uFD79'] = '\u063A\u0645\u0645';
  18743. t['\uFD7A'] = '\u063A\u0645\u064A';
  18744. t['\uFD7B'] = '\u063A\u0645\u0649';
  18745. t['\uFD7C'] = '\u0641\u062E\u0645';
  18746. t['\uFD7D'] = '\u0641\u062E\u0645';
  18747. t['\uFD7E'] = '\u0642\u0645\u062D';
  18748. t['\uFD7F'] = '\u0642\u0645\u0645';
  18749. t['\uFD80'] = '\u0644\u062D\u0645';
  18750. t['\uFD81'] = '\u0644\u062D\u064A';
  18751. t['\uFD82'] = '\u0644\u062D\u0649';
  18752. t['\uFD83'] = '\u0644\u062C\u062C';
  18753. t['\uFD84'] = '\u0644\u062C\u062C';
  18754. t['\uFD85'] = '\u0644\u062E\u0645';
  18755. t['\uFD86'] = '\u0644\u062E\u0645';
  18756. t['\uFD87'] = '\u0644\u0645\u062D';
  18757. t['\uFD88'] = '\u0644\u0645\u062D';
  18758. t['\uFD89'] = '\u0645\u062D\u062C';
  18759. t['\uFD8A'] = '\u0645\u062D\u0645';
  18760. t['\uFD8B'] = '\u0645\u062D\u064A';
  18761. t['\uFD8C'] = '\u0645\u062C\u062D';
  18762. t['\uFD8D'] = '\u0645\u062C\u0645';
  18763. t['\uFD8E'] = '\u0645\u062E\u062C';
  18764. t['\uFD8F'] = '\u0645\u062E\u0645';
  18765. t['\uFD92'] = '\u0645\u062C\u062E';
  18766. t['\uFD93'] = '\u0647\u0645\u062C';
  18767. t['\uFD94'] = '\u0647\u0645\u0645';
  18768. t['\uFD95'] = '\u0646\u062D\u0645';
  18769. t['\uFD96'] = '\u0646\u062D\u0649';
  18770. t['\uFD97'] = '\u0646\u062C\u0645';
  18771. t['\uFD98'] = '\u0646\u062C\u0645';
  18772. t['\uFD99'] = '\u0646\u062C\u0649';
  18773. t['\uFD9A'] = '\u0646\u0645\u064A';
  18774. t['\uFD9B'] = '\u0646\u0645\u0649';
  18775. t['\uFD9C'] = '\u064A\u0645\u0645';
  18776. t['\uFD9D'] = '\u064A\u0645\u0645';
  18777. t['\uFD9E'] = '\u0628\u062E\u064A';
  18778. t['\uFD9F'] = '\u062A\u062C\u064A';
  18779. t['\uFDA0'] = '\u062A\u062C\u0649';
  18780. t['\uFDA1'] = '\u062A\u062E\u064A';
  18781. t['\uFDA2'] = '\u062A\u062E\u0649';
  18782. t['\uFDA3'] = '\u062A\u0645\u064A';
  18783. t['\uFDA4'] = '\u062A\u0645\u0649';
  18784. t['\uFDA5'] = '\u062C\u0645\u064A';
  18785. t['\uFDA6'] = '\u062C\u062D\u0649';
  18786. t['\uFDA7'] = '\u062C\u0645\u0649';
  18787. t['\uFDA8'] = '\u0633\u062E\u0649';
  18788. t['\uFDA9'] = '\u0635\u062D\u064A';
  18789. t['\uFDAA'] = '\u0634\u062D\u064A';
  18790. t['\uFDAB'] = '\u0636\u062D\u064A';
  18791. t['\uFDAC'] = '\u0644\u062C\u064A';
  18792. t['\uFDAD'] = '\u0644\u0645\u064A';
  18793. t['\uFDAE'] = '\u064A\u062D\u064A';
  18794. t['\uFDAF'] = '\u064A\u062C\u064A';
  18795. t['\uFDB0'] = '\u064A\u0645\u064A';
  18796. t['\uFDB1'] = '\u0645\u0645\u064A';
  18797. t['\uFDB2'] = '\u0642\u0645\u064A';
  18798. t['\uFDB3'] = '\u0646\u062D\u064A';
  18799. t['\uFDB4'] = '\u0642\u0645\u062D';
  18800. t['\uFDB5'] = '\u0644\u062D\u0645';
  18801. t['\uFDB6'] = '\u0639\u0645\u064A';
  18802. t['\uFDB7'] = '\u0643\u0645\u064A';
  18803. t['\uFDB8'] = '\u0646\u062C\u062D';
  18804. t['\uFDB9'] = '\u0645\u062E\u064A';
  18805. t['\uFDBA'] = '\u0644\u062C\u0645';
  18806. t['\uFDBB'] = '\u0643\u0645\u0645';
  18807. t['\uFDBC'] = '\u0644\u062C\u0645';
  18808. t['\uFDBD'] = '\u0646\u062C\u062D';
  18809. t['\uFDBE'] = '\u062C\u062D\u064A';
  18810. t['\uFDBF'] = '\u062D\u062C\u064A';
  18811. t['\uFDC0'] = '\u0645\u062C\u064A';
  18812. t['\uFDC1'] = '\u0641\u0645\u064A';
  18813. t['\uFDC2'] = '\u0628\u062D\u064A';
  18814. t['\uFDC3'] = '\u0643\u0645\u0645';
  18815. t['\uFDC4'] = '\u0639\u062C\u0645';
  18816. t['\uFDC5'] = '\u0635\u0645\u0645';
  18817. t['\uFDC6'] = '\u0633\u062E\u064A';
  18818. t['\uFDC7'] = '\u0646\u062C\u064A';
  18819. t['\uFE49'] = '\u203E';
  18820. t['\uFE4A'] = '\u203E';
  18821. t['\uFE4B'] = '\u203E';
  18822. t['\uFE4C'] = '\u203E';
  18823. t['\uFE4D'] = '\u005F';
  18824. t['\uFE4E'] = '\u005F';
  18825. t['\uFE4F'] = '\u005F';
  18826. t['\uFE80'] = '\u0621';
  18827. t['\uFE81'] = '\u0622';
  18828. t['\uFE82'] = '\u0622';
  18829. t['\uFE83'] = '\u0623';
  18830. t['\uFE84'] = '\u0623';
  18831. t['\uFE85'] = '\u0624';
  18832. t['\uFE86'] = '\u0624';
  18833. t['\uFE87'] = '\u0625';
  18834. t['\uFE88'] = '\u0625';
  18835. t['\uFE89'] = '\u0626';
  18836. t['\uFE8A'] = '\u0626';
  18837. t['\uFE8B'] = '\u0626';
  18838. t['\uFE8C'] = '\u0626';
  18839. t['\uFE8D'] = '\u0627';
  18840. t['\uFE8E'] = '\u0627';
  18841. t['\uFE8F'] = '\u0628';
  18842. t['\uFE90'] = '\u0628';
  18843. t['\uFE91'] = '\u0628';
  18844. t['\uFE92'] = '\u0628';
  18845. t['\uFE93'] = '\u0629';
  18846. t['\uFE94'] = '\u0629';
  18847. t['\uFE95'] = '\u062A';
  18848. t['\uFE96'] = '\u062A';
  18849. t['\uFE97'] = '\u062A';
  18850. t['\uFE98'] = '\u062A';
  18851. t['\uFE99'] = '\u062B';
  18852. t['\uFE9A'] = '\u062B';
  18853. t['\uFE9B'] = '\u062B';
  18854. t['\uFE9C'] = '\u062B';
  18855. t['\uFE9D'] = '\u062C';
  18856. t['\uFE9E'] = '\u062C';
  18857. t['\uFE9F'] = '\u062C';
  18858. t['\uFEA0'] = '\u062C';
  18859. t['\uFEA1'] = '\u062D';
  18860. t['\uFEA2'] = '\u062D';
  18861. t['\uFEA3'] = '\u062D';
  18862. t['\uFEA4'] = '\u062D';
  18863. t['\uFEA5'] = '\u062E';
  18864. t['\uFEA6'] = '\u062E';
  18865. t['\uFEA7'] = '\u062E';
  18866. t['\uFEA8'] = '\u062E';
  18867. t['\uFEA9'] = '\u062F';
  18868. t['\uFEAA'] = '\u062F';
  18869. t['\uFEAB'] = '\u0630';
  18870. t['\uFEAC'] = '\u0630';
  18871. t['\uFEAD'] = '\u0631';
  18872. t['\uFEAE'] = '\u0631';
  18873. t['\uFEAF'] = '\u0632';
  18874. t['\uFEB0'] = '\u0632';
  18875. t['\uFEB1'] = '\u0633';
  18876. t['\uFEB2'] = '\u0633';
  18877. t['\uFEB3'] = '\u0633';
  18878. t['\uFEB4'] = '\u0633';
  18879. t['\uFEB5'] = '\u0634';
  18880. t['\uFEB6'] = '\u0634';
  18881. t['\uFEB7'] = '\u0634';
  18882. t['\uFEB8'] = '\u0634';
  18883. t['\uFEB9'] = '\u0635';
  18884. t['\uFEBA'] = '\u0635';
  18885. t['\uFEBB'] = '\u0635';
  18886. t['\uFEBC'] = '\u0635';
  18887. t['\uFEBD'] = '\u0636';
  18888. t['\uFEBE'] = '\u0636';
  18889. t['\uFEBF'] = '\u0636';
  18890. t['\uFEC0'] = '\u0636';
  18891. t['\uFEC1'] = '\u0637';
  18892. t['\uFEC2'] = '\u0637';
  18893. t['\uFEC3'] = '\u0637';
  18894. t['\uFEC4'] = '\u0637';
  18895. t['\uFEC5'] = '\u0638';
  18896. t['\uFEC6'] = '\u0638';
  18897. t['\uFEC7'] = '\u0638';
  18898. t['\uFEC8'] = '\u0638';
  18899. t['\uFEC9'] = '\u0639';
  18900. t['\uFECA'] = '\u0639';
  18901. t['\uFECB'] = '\u0639';
  18902. t['\uFECC'] = '\u0639';
  18903. t['\uFECD'] = '\u063A';
  18904. t['\uFECE'] = '\u063A';
  18905. t['\uFECF'] = '\u063A';
  18906. t['\uFED0'] = '\u063A';
  18907. t['\uFED1'] = '\u0641';
  18908. t['\uFED2'] = '\u0641';
  18909. t['\uFED3'] = '\u0641';
  18910. t['\uFED4'] = '\u0641';
  18911. t['\uFED5'] = '\u0642';
  18912. t['\uFED6'] = '\u0642';
  18913. t['\uFED7'] = '\u0642';
  18914. t['\uFED8'] = '\u0642';
  18915. t['\uFED9'] = '\u0643';
  18916. t['\uFEDA'] = '\u0643';
  18917. t['\uFEDB'] = '\u0643';
  18918. t['\uFEDC'] = '\u0643';
  18919. t['\uFEDD'] = '\u0644';
  18920. t['\uFEDE'] = '\u0644';
  18921. t['\uFEDF'] = '\u0644';
  18922. t['\uFEE0'] = '\u0644';
  18923. t['\uFEE1'] = '\u0645';
  18924. t['\uFEE2'] = '\u0645';
  18925. t['\uFEE3'] = '\u0645';
  18926. t['\uFEE4'] = '\u0645';
  18927. t['\uFEE5'] = '\u0646';
  18928. t['\uFEE6'] = '\u0646';
  18929. t['\uFEE7'] = '\u0646';
  18930. t['\uFEE8'] = '\u0646';
  18931. t['\uFEE9'] = '\u0647';
  18932. t['\uFEEA'] = '\u0647';
  18933. t['\uFEEB'] = '\u0647';
  18934. t['\uFEEC'] = '\u0647';
  18935. t['\uFEED'] = '\u0648';
  18936. t['\uFEEE'] = '\u0648';
  18937. t['\uFEEF'] = '\u0649';
  18938. t['\uFEF0'] = '\u0649';
  18939. t['\uFEF1'] = '\u064A';
  18940. t['\uFEF2'] = '\u064A';
  18941. t['\uFEF3'] = '\u064A';
  18942. t['\uFEF4'] = '\u064A';
  18943. t['\uFEF5'] = '\u0644\u0622';
  18944. t['\uFEF6'] = '\u0644\u0622';
  18945. t['\uFEF7'] = '\u0644\u0623';
  18946. t['\uFEF8'] = '\u0644\u0623';
  18947. t['\uFEF9'] = '\u0644\u0625';
  18948. t['\uFEFA'] = '\u0644\u0625';
  18949. t['\uFEFB'] = '\u0644\u0627';
  18950. t['\uFEFC'] = '\u0644\u0627';
  18951. });
  18952. function reverseIfRtl(chars) {
  18953. var charsLength = chars.length;
  18954. //reverse an arabic ligature
  18955. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18956. return chars;
  18957. }
  18958. var s = '';
  18959. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18960. s += chars[ii];
  18961. }
  18962. return s;
  18963. }
  18964. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  18965. exports.reverseIfRtl = reverseIfRtl;
  18966. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  18967. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  18968. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  18969. }));
  18970. (function (root, factory) {
  18971. {
  18972. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedUtil);
  18973. }
  18974. }(this, function (exports, sharedUtil) {
  18975. var removeNullCharacters = sharedUtil.removeNullCharacters;
  18976. var warn = sharedUtil.warn;
  18977. /**
  18978. * Optimised CSS custom property getter/setter.
  18979. * @class
  18980. */
  18981. var CustomStyle = (function CustomStyleClosure() {
  18982. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  18983. // animate-css-transforms-firefox-webkit.html
  18984. // in some versions of IE9 it is critical that ms appear in this list
  18985. // before Moz
  18986. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  18987. var _cache = Object.create(null);
  18988. function CustomStyle() {}
  18989. CustomStyle.getProp = function get(propName, element) {
  18990. // check cache only when no element is given
  18991. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  18992. return _cache[propName];
  18993. }
  18994. element = element || document.documentElement;
  18995. var style = element.style, prefixed, uPropName;
  18996. // test standard property first
  18997. if (typeof style[propName] === 'string') {
  18998. return (_cache[propName] = propName);
  18999. }
  19000. // capitalize
  19001. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  19002. // test vendor specific properties
  19003. for (var i = 0, l = prefixes.length; i < l; i++) {
  19004. prefixed = prefixes[i] + uPropName;
  19005. if (typeof style[prefixed] === 'string') {
  19006. return (_cache[propName] = prefixed);
  19007. }
  19008. }
  19009. //if all fails then set to undefined
  19010. return (_cache[propName] = 'undefined');
  19011. };
  19012. CustomStyle.setProp = function set(propName, element, str) {
  19013. var prop = this.getProp(propName);
  19014. if (prop !== 'undefined') {
  19015. element.style[prop] = str;
  19016. }
  19017. };
  19018. return CustomStyle;
  19019. })();
  19020. function hasCanvasTypedArrays() {
  19021. var canvas = document.createElement('canvas');
  19022. canvas.width = canvas.height = 1;
  19023. var ctx = canvas.getContext('2d');
  19024. var imageData = ctx.createImageData(1, 1);
  19025. return (typeof imageData.data.buffer !== 'undefined');
  19026. }
  19027. var LinkTarget = {
  19028. NONE: 0, // Default value.
  19029. SELF: 1,
  19030. BLANK: 2,
  19031. PARENT: 3,
  19032. TOP: 4,
  19033. };
  19034. var LinkTargetStringMap = [
  19035. '',
  19036. '_self',
  19037. '_blank',
  19038. '_parent',
  19039. '_top'
  19040. ];
  19041. /**
  19042. * @typedef ExternalLinkParameters
  19043. * @typedef {Object} ExternalLinkParameters
  19044. * @property {string} url - An absolute URL.
  19045. * @property {LinkTarget} target - The link target.
  19046. * @property {string} rel - The link relationship.
  19047. */
  19048. /**
  19049. * Adds various attributes (href, title, target, rel) to hyperlinks.
  19050. * @param {HTMLLinkElement} link - The link element.
  19051. * @param {ExternalLinkParameters} params
  19052. */
  19053. function addLinkAttributes(link, params) {
  19054. var url = params && params.url;
  19055. link.href = link.title = (url ? removeNullCharacters(url) : '');
  19056. if (url) {
  19057. var target = params.target;
  19058. if (typeof target === 'undefined') {
  19059. target = getDefaultSetting('externalLinkTarget');
  19060. }
  19061. link.target = LinkTargetStringMap[target];
  19062. var rel = params.rel;
  19063. if (typeof rel === 'undefined') {
  19064. rel = getDefaultSetting('externalLinkRel');
  19065. }
  19066. link.rel = rel;
  19067. }
  19068. }
  19069. // Gets the file name from a given URL.
  19070. function getFilenameFromUrl(url) {
  19071. var anchor = url.indexOf('#');
  19072. var query = url.indexOf('?');
  19073. var end = Math.min(
  19074. anchor > 0 ? anchor : url.length,
  19075. query > 0 ? query : url.length);
  19076. return url.substring(url.lastIndexOf('/', end) + 1, end);
  19077. }
  19078. function getDefaultSetting(id) {
  19079. // The list of the settings and their default is maintained for backward
  19080. // compatibility and shall not be extended or modified. See also global.js.
  19081. var globalSettings = sharedUtil.globalScope.PDFJS;
  19082. switch (id) {
  19083. case 'pdfBug':
  19084. return globalSettings ? globalSettings.pdfBug : false;
  19085. case 'disableAutoFetch':
  19086. return globalSettings ? globalSettings.disableAutoFetch : false;
  19087. case 'disableStream':
  19088. return globalSettings ? globalSettings.disableStream : false;
  19089. case 'disableRange':
  19090. return globalSettings ? globalSettings.disableRange : false;
  19091. case 'disableFontFace':
  19092. return globalSettings ? globalSettings.disableFontFace : false;
  19093. case 'disableCreateObjectURL':
  19094. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  19095. case 'disableWebGL':
  19096. return globalSettings ? globalSettings.disableWebGL : true;
  19097. case 'cMapUrl':
  19098. return globalSettings ? globalSettings.cMapUrl : null;
  19099. case 'cMapPacked':
  19100. return globalSettings ? globalSettings.cMapPacked : false;
  19101. case 'postMessageTransfers':
  19102. return globalSettings ? globalSettings.postMessageTransfers : true;
  19103. case 'workerSrc':
  19104. return globalSettings ? globalSettings.workerSrc : null;
  19105. case 'disableWorker':
  19106. return globalSettings ? globalSettings.disableWorker : false;
  19107. case 'maxImageSize':
  19108. return globalSettings ? globalSettings.maxImageSize : -1;
  19109. case 'imageResourcesPath':
  19110. return globalSettings ? globalSettings.imageResourcesPath : '';
  19111. case 'isEvalSupported':
  19112. return globalSettings ? globalSettings.isEvalSupported : true;
  19113. case 'externalLinkTarget':
  19114. if (!globalSettings) {
  19115. return LinkTarget.NONE;
  19116. }
  19117. switch (globalSettings.externalLinkTarget) {
  19118. case LinkTarget.NONE:
  19119. case LinkTarget.SELF:
  19120. case LinkTarget.BLANK:
  19121. case LinkTarget.PARENT:
  19122. case LinkTarget.TOP:
  19123. return globalSettings.externalLinkTarget;
  19124. }
  19125. warn('PDFJS.externalLinkTarget is invalid: ' +
  19126. globalSettings.externalLinkTarget);
  19127. // Reset the external link target, to suppress further warnings.
  19128. globalSettings.externalLinkTarget = LinkTarget.NONE;
  19129. return LinkTarget.NONE;
  19130. case 'externalLinkRel':
  19131. return globalSettings ? globalSettings.externalLinkRel : 'noreferrer';
  19132. case 'enableStats':
  19133. return !!(globalSettings && globalSettings.enableStats);
  19134. default:
  19135. throw new Error('Unknown default setting: ' + id);
  19136. }
  19137. }
  19138. function isExternalLinkTargetSet() {
  19139. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  19140. switch (externalLinkTarget) {
  19141. case LinkTarget.NONE:
  19142. return false;
  19143. case LinkTarget.SELF:
  19144. case LinkTarget.BLANK:
  19145. case LinkTarget.PARENT:
  19146. case LinkTarget.TOP:
  19147. return true;
  19148. }
  19149. }
  19150. exports.CustomStyle = CustomStyle;
  19151. exports.addLinkAttributes = addLinkAttributes;
  19152. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  19153. exports.getFilenameFromUrl = getFilenameFromUrl;
  19154. exports.LinkTarget = LinkTarget;
  19155. exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
  19156. exports.getDefaultSetting = getDefaultSetting;
  19157. }));
  19158. (function (root, factory) {
  19159. {
  19160. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil);
  19161. }
  19162. }(this, function (exports, sharedUtil) {
  19163. var assert = sharedUtil.assert;
  19164. var bytesToString = sharedUtil.bytesToString;
  19165. var string32 = sharedUtil.string32;
  19166. var shadow = sharedUtil.shadow;
  19167. var warn = sharedUtil.warn;
  19168. function FontLoader(docId) {
  19169. this.docId = docId;
  19170. this.styleElement = null;
  19171. this.nativeFontFaces = [];
  19172. this.loadTestFontId = 0;
  19173. this.loadingContext = {
  19174. requests: [],
  19175. nextRequestId: 0
  19176. };
  19177. }
  19178. FontLoader.prototype = {
  19179. insertRule: function fontLoaderInsertRule(rule) {
  19180. var styleElement = this.styleElement;
  19181. if (!styleElement) {
  19182. styleElement = this.styleElement = document.createElement('style');
  19183. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  19184. document.documentElement.getElementsByTagName('head')[0].appendChild(
  19185. styleElement);
  19186. }
  19187. var styleSheet = styleElement.sheet;
  19188. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  19189. },
  19190. clear: function fontLoaderClear() {
  19191. var styleElement = this.styleElement;
  19192. if (styleElement) {
  19193. styleElement.parentNode.removeChild(styleElement);
  19194. styleElement = this.styleElement = null;
  19195. }
  19196. this.nativeFontFaces.forEach(function(nativeFontFace) {
  19197. document.fonts.delete(nativeFontFace);
  19198. });
  19199. this.nativeFontFaces.length = 0;
  19200. },
  19201. get loadTestFont() {
  19202. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  19203. // height.
  19204. return shadow(this, 'loadTestFont', atob(
  19205. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  19206. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  19207. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  19208. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  19209. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  19210. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  19211. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  19212. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  19213. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  19214. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  19215. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  19216. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  19217. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  19218. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19219. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19220. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  19221. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  19222. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  19223. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  19224. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  19225. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  19226. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  19227. ));
  19228. },
  19229. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  19230. this.nativeFontFaces.push(nativeFontFace);
  19231. document.fonts.add(nativeFontFace);
  19232. },
  19233. bind: function fontLoaderBind(fonts, callback) {
  19234. var rules = [];
  19235. var fontsToLoad = [];
  19236. var fontLoadPromises = [];
  19237. var getNativeFontPromise = function(nativeFontFace) {
  19238. // Return a promise that is always fulfilled, even when the font fails to
  19239. // load.
  19240. return nativeFontFace.loaded.catch(function(e) {
  19241. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  19242. });
  19243. };
  19244. // Firefox Font Loading API does not work with mozPrintCallback --
  19245. // disabling it in this case.
  19246. var isFontLoadingAPISupported = FontLoader.isFontLoadingAPISupported &&
  19247. !FontLoader.isSyncFontLoadingSupported;
  19248. for (var i = 0, ii = fonts.length; i < ii; i++) {
  19249. var font = fonts[i];
  19250. // Add the font to the DOM only once or skip if the font
  19251. // is already loaded.
  19252. if (font.attached || font.loading === false) {
  19253. continue;
  19254. }
  19255. font.attached = true;
  19256. if (isFontLoadingAPISupported) {
  19257. var nativeFontFace = font.createNativeFontFace();
  19258. if (nativeFontFace) {
  19259. this.addNativeFontFace(nativeFontFace);
  19260. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  19261. }
  19262. } else {
  19263. var rule = font.createFontFaceRule();
  19264. if (rule) {
  19265. this.insertRule(rule);
  19266. rules.push(rule);
  19267. fontsToLoad.push(font);
  19268. }
  19269. }
  19270. }
  19271. var request = this.queueLoadingCallback(callback);
  19272. if (isFontLoadingAPISupported) {
  19273. Promise.all(fontLoadPromises).then(function() {
  19274. request.complete();
  19275. });
  19276. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  19277. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  19278. } else {
  19279. request.complete();
  19280. }
  19281. },
  19282. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  19283. function LoadLoader_completeRequest() {
  19284. assert(!request.end, 'completeRequest() cannot be called twice');
  19285. request.end = Date.now();
  19286. // sending all completed requests in order how they were queued
  19287. while (context.requests.length > 0 && context.requests[0].end) {
  19288. var otherRequest = context.requests.shift();
  19289. setTimeout(otherRequest.callback, 0);
  19290. }
  19291. }
  19292. var context = this.loadingContext;
  19293. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  19294. var request = {
  19295. id: requestId,
  19296. complete: LoadLoader_completeRequest,
  19297. callback: callback,
  19298. started: Date.now()
  19299. };
  19300. context.requests.push(request);
  19301. return request;
  19302. },
  19303. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  19304. fonts,
  19305. request) {
  19306. /** Hack begin */
  19307. // There's currently no event when a font has finished downloading so the
  19308. // following code is a dirty hack to 'guess' when a font is
  19309. // ready. It's assumed fonts are loaded in order, so add a known test
  19310. // font after the desired fonts and then test for the loading of that
  19311. // test font.
  19312. function int32(data, offset) {
  19313. return (data.charCodeAt(offset) << 24) |
  19314. (data.charCodeAt(offset + 1) << 16) |
  19315. (data.charCodeAt(offset + 2) << 8) |
  19316. (data.charCodeAt(offset + 3) & 0xff);
  19317. }
  19318. function spliceString(s, offset, remove, insert) {
  19319. var chunk1 = s.substr(0, offset);
  19320. var chunk2 = s.substr(offset + remove);
  19321. return chunk1 + insert + chunk2;
  19322. }
  19323. var i, ii;
  19324. var canvas = document.createElement('canvas');
  19325. canvas.width = 1;
  19326. canvas.height = 1;
  19327. var ctx = canvas.getContext('2d');
  19328. var called = 0;
  19329. function isFontReady(name, callback) {
  19330. called++;
  19331. // With setTimeout clamping this gives the font ~100ms to load.
  19332. if(called > 30) {
  19333. warn('Load test font never loaded.');
  19334. callback();
  19335. return;
  19336. }
  19337. ctx.font = '30px ' + name;
  19338. ctx.fillText('.', 0, 20);
  19339. var imageData = ctx.getImageData(0, 0, 1, 1);
  19340. if (imageData.data[3] > 0) {
  19341. callback();
  19342. return;
  19343. }
  19344. setTimeout(isFontReady.bind(null, name, callback));
  19345. }
  19346. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  19347. // Chromium seems to cache fonts based on a hash of the actual font data,
  19348. // so the font must be modified for each load test else it will appear to
  19349. // be loaded already.
  19350. // TODO: This could maybe be made faster by avoiding the btoa of the full
  19351. // font by splitting it in chunks before hand and padding the font id.
  19352. var data = this.loadTestFont;
  19353. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  19354. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  19355. loadTestFontId);
  19356. // CFF checksum is important for IE, adjusting it
  19357. var CFF_CHECKSUM_OFFSET = 16;
  19358. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  19359. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  19360. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  19361. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  19362. }
  19363. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  19364. checksum = (checksum - XXXX_VALUE +
  19365. int32(loadTestFontId + 'XXX', i)) | 0;
  19366. }
  19367. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  19368. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  19369. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  19370. url + '}';
  19371. this.insertRule(rule);
  19372. var names = [];
  19373. for (i = 0, ii = fonts.length; i < ii; i++) {
  19374. names.push(fonts[i].loadedName);
  19375. }
  19376. names.push(loadTestFontId);
  19377. var div = document.createElement('div');
  19378. div.setAttribute('style',
  19379. 'visibility: hidden;' +
  19380. 'width: 10px; height: 10px;' +
  19381. 'position: absolute; top: 0px; left: 0px;');
  19382. for (i = 0, ii = names.length; i < ii; ++i) {
  19383. var span = document.createElement('span');
  19384. span.textContent = 'Hi';
  19385. span.style.fontFamily = names[i];
  19386. div.appendChild(span);
  19387. }
  19388. document.body.appendChild(div);
  19389. isFontReady(loadTestFontId, function() {
  19390. document.body.removeChild(div);
  19391. request.complete();
  19392. });
  19393. /** Hack end */
  19394. }
  19395. };
  19396. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
  19397. !!document.fonts;
  19398. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  19399. get: function () {
  19400. if (typeof navigator === 'undefined') {
  19401. // node.js - we can pretend sync font loading is supported.
  19402. return shadow(FontLoader, 'isSyncFontLoadingSupported', true);
  19403. }
  19404. var supported = false;
  19405. // User agent string sniffing is bad, but there is no reliable way to tell
  19406. // if font is fully loaded and ready to be used with canvas.
  19407. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  19408. if (m && m[1] >= 14) {
  19409. supported = true;
  19410. }
  19411. // TODO other browsers
  19412. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  19413. },
  19414. enumerable: true,
  19415. configurable: true
  19416. });
  19417. var IsEvalSupportedCached = {
  19418. get value() {
  19419. return shadow(this, 'value', sharedUtil.isEvalSupported());
  19420. }
  19421. };
  19422. var FontFaceObject = (function FontFaceObjectClosure() {
  19423. function FontFaceObject(translatedData, options) {
  19424. this.compiledGlyphs = Object.create(null);
  19425. // importing translated data
  19426. for (var i in translatedData) {
  19427. this[i] = translatedData[i];
  19428. }
  19429. this.options = options;
  19430. }
  19431. FontFaceObject.prototype = {
  19432. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  19433. if (!this.data) {
  19434. return null;
  19435. }
  19436. if (this.options.disableFontFace) {
  19437. this.disableFontFace = true;
  19438. return null;
  19439. }
  19440. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  19441. if (this.options.fontRegistry) {
  19442. this.options.fontRegistry.registerFont(this);
  19443. }
  19444. return nativeFontFace;
  19445. },
  19446. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  19447. if (!this.data) {
  19448. return null;
  19449. }
  19450. if (this.options.disableFontFace) {
  19451. this.disableFontFace = true;
  19452. return null;
  19453. }
  19454. var data = bytesToString(new Uint8Array(this.data));
  19455. var fontName = this.loadedName;
  19456. // Add the font-face rule to the document
  19457. var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
  19458. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  19459. if (this.options.fontRegistry) {
  19460. this.options.fontRegistry.registerFont(this, url);
  19461. }
  19462. return rule;
  19463. },
  19464. getPathGenerator:
  19465. function FontFaceObject_getPathGenerator(objs, character) {
  19466. if (!(character in this.compiledGlyphs)) {
  19467. var cmds = objs.get(this.loadedName + '_path_' + character);
  19468. var current, i, len;
  19469. // If we can, compile cmds into JS for MAXIMUM SPEED
  19470. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  19471. var args, js = '';
  19472. for (i = 0, len = cmds.length; i < len; i++) {
  19473. current = cmds[i];
  19474. if (current.args !== undefined) {
  19475. args = current.args.join(',');
  19476. } else {
  19477. args = '';
  19478. }
  19479. js += 'c.' + current.cmd + '(' + args + ');\n';
  19480. }
  19481. /* jshint -W054 */
  19482. this.compiledGlyphs[character] = new Function('c', 'size', js);
  19483. } else {
  19484. // But fall back on using Function.prototype.apply() if we're
  19485. // blocked from using eval() for whatever reason (like CSP policies)
  19486. this.compiledGlyphs[character] = function(c, size) {
  19487. for (i = 0, len = cmds.length; i < len; i++) {
  19488. current = cmds[i];
  19489. if (current.cmd === 'scale') {
  19490. current.args = [size, -size];
  19491. }
  19492. c[current.cmd].apply(c, current.args);
  19493. }
  19494. };
  19495. }
  19496. }
  19497. return this.compiledGlyphs[character];
  19498. }
  19499. };
  19500. return FontFaceObject;
  19501. })();
  19502. exports.FontFaceObject = FontFaceObject;
  19503. exports.FontLoader = FontLoader;
  19504. }));
  19505. (function (root, factory) {
  19506. {
  19507. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  19508. }
  19509. }(this, function (exports, sharedUtil) {
  19510. var error = sharedUtil.error;
  19511. function fixMetadata(meta) {
  19512. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  19513. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  19514. function(code, d1, d2, d3) {
  19515. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  19516. });
  19517. var chars = '';
  19518. for (var i = 0; i < bytes.length; i += 2) {
  19519. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  19520. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  19521. code !== 38 && false ? String.fromCharCode(code) :
  19522. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  19523. }
  19524. return '>' + chars;
  19525. });
  19526. }
  19527. function Metadata(meta) {
  19528. if (typeof meta === 'string') {
  19529. // Ghostscript produces invalid metadata
  19530. meta = fixMetadata(meta);
  19531. var parser = new DOMParser();
  19532. meta = parser.parseFromString(meta, 'application/xml');
  19533. } else if (!(meta instanceof Document)) {
  19534. error('Metadata: Invalid metadata object');
  19535. }
  19536. this.metaDocument = meta;
  19537. this.metadata = Object.create(null);
  19538. this.parse();
  19539. }
  19540. Metadata.prototype = {
  19541. parse: function Metadata_parse() {
  19542. var doc = this.metaDocument;
  19543. var rdf = doc.documentElement;
  19544. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  19545. rdf = rdf.firstChild;
  19546. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  19547. rdf = rdf.nextSibling;
  19548. }
  19549. }
  19550. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  19551. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  19552. return;
  19553. }
  19554. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  19555. for (i = 0, length = children.length; i < length; i++) {
  19556. desc = children[i];
  19557. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  19558. continue;
  19559. }
  19560. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  19561. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  19562. entry = desc.childNodes[ii];
  19563. name = entry.nodeName.toLowerCase();
  19564. this.metadata[name] = entry.textContent.trim();
  19565. }
  19566. }
  19567. }
  19568. },
  19569. get: function Metadata_get(name) {
  19570. return this.metadata[name] || null;
  19571. },
  19572. has: function Metadata_has(name) {
  19573. return typeof this.metadata[name] !== 'undefined';
  19574. }
  19575. };
  19576. exports.Metadata = Metadata;
  19577. }));
  19578. (function (root, factory) {
  19579. {
  19580. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  19581. }
  19582. }(this, function (exports, sharedUtil) {
  19583. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  19584. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  19585. var ImageKind = sharedUtil.ImageKind;
  19586. var OPS = sharedUtil.OPS;
  19587. var Util = sharedUtil.Util;
  19588. var isNum = sharedUtil.isNum;
  19589. var isArray = sharedUtil.isArray;
  19590. var warn = sharedUtil.warn;
  19591. var createObjectURL = sharedUtil.createObjectURL;
  19592. var SVG_DEFAULTS = {
  19593. fontStyle: 'normal',
  19594. fontWeight: 'normal',
  19595. fillColor: '#000000'
  19596. };
  19597. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  19598. var PNG_HEADER =
  19599. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  19600. var CHUNK_WRAPPER_SIZE = 12;
  19601. var crcTable = new Int32Array(256);
  19602. for (var i = 0; i < 256; i++) {
  19603. var c = i;
  19604. for (var h = 0; h < 8; h++) {
  19605. if (c & 1) {
  19606. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  19607. } else {
  19608. c = (c >> 1) & 0x7fffffff;
  19609. }
  19610. }
  19611. crcTable[i] = c;
  19612. }
  19613. function crc32(data, start, end) {
  19614. var crc = -1;
  19615. for (var i = start; i < end; i++) {
  19616. var a = (crc ^ data[i]) & 0xff;
  19617. var b = crcTable[a];
  19618. crc = (crc >>> 8) ^ b;
  19619. }
  19620. return crc ^ -1;
  19621. }
  19622. function writePngChunk(type, body, data, offset) {
  19623. var p = offset;
  19624. var len = body.length;
  19625. data[p] = len >> 24 & 0xff;
  19626. data[p + 1] = len >> 16 & 0xff;
  19627. data[p + 2] = len >> 8 & 0xff;
  19628. data[p + 3] = len & 0xff;
  19629. p += 4;
  19630. data[p] = type.charCodeAt(0) & 0xff;
  19631. data[p + 1] = type.charCodeAt(1) & 0xff;
  19632. data[p + 2] = type.charCodeAt(2) & 0xff;
  19633. data[p + 3] = type.charCodeAt(3) & 0xff;
  19634. p += 4;
  19635. data.set(body, p);
  19636. p += body.length;
  19637. var crc = crc32(data, offset + 4, p);
  19638. data[p] = crc >> 24 & 0xff;
  19639. data[p + 1] = crc >> 16 & 0xff;
  19640. data[p + 2] = crc >> 8 & 0xff;
  19641. data[p + 3] = crc & 0xff;
  19642. }
  19643. function adler32(data, start, end) {
  19644. var a = 1;
  19645. var b = 0;
  19646. for (var i = start; i < end; ++i) {
  19647. a = (a + (data[i] & 0xff)) % 65521;
  19648. b = (b + a) % 65521;
  19649. }
  19650. return (b << 16) | a;
  19651. }
  19652. function encode(imgData, kind, forceDataSchema) {
  19653. var width = imgData.width;
  19654. var height = imgData.height;
  19655. var bitDepth, colorType, lineSize;
  19656. var bytes = imgData.data;
  19657. switch (kind) {
  19658. case ImageKind.GRAYSCALE_1BPP:
  19659. colorType = 0;
  19660. bitDepth = 1;
  19661. lineSize = (width + 7) >> 3;
  19662. break;
  19663. case ImageKind.RGB_24BPP:
  19664. colorType = 2;
  19665. bitDepth = 8;
  19666. lineSize = width * 3;
  19667. break;
  19668. case ImageKind.RGBA_32BPP:
  19669. colorType = 6;
  19670. bitDepth = 8;
  19671. lineSize = width * 4;
  19672. break;
  19673. default:
  19674. throw new Error('invalid format');
  19675. }
  19676. // prefix every row with predictor 0
  19677. var literals = new Uint8Array((1 + lineSize) * height);
  19678. var offsetLiterals = 0, offsetBytes = 0;
  19679. var y, i;
  19680. for (y = 0; y < height; ++y) {
  19681. literals[offsetLiterals++] = 0; // no prediction
  19682. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  19683. offsetLiterals);
  19684. offsetBytes += lineSize;
  19685. offsetLiterals += lineSize;
  19686. }
  19687. if (kind === ImageKind.GRAYSCALE_1BPP) {
  19688. // inverting for B/W
  19689. offsetLiterals = 0;
  19690. for (y = 0; y < height; y++) {
  19691. offsetLiterals++; // skipping predictor
  19692. for (i = 0; i < lineSize; i++) {
  19693. literals[offsetLiterals++] ^= 0xFF;
  19694. }
  19695. }
  19696. }
  19697. var ihdr = new Uint8Array([
  19698. width >> 24 & 0xff,
  19699. width >> 16 & 0xff,
  19700. width >> 8 & 0xff,
  19701. width & 0xff,
  19702. height >> 24 & 0xff,
  19703. height >> 16 & 0xff,
  19704. height >> 8 & 0xff,
  19705. height & 0xff,
  19706. bitDepth, // bit depth
  19707. colorType, // color type
  19708. 0x00, // compression method
  19709. 0x00, // filter method
  19710. 0x00 // interlace method
  19711. ]);
  19712. var len = literals.length;
  19713. var maxBlockLength = 0xFFFF;
  19714. var deflateBlocks = Math.ceil(len / maxBlockLength);
  19715. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  19716. var pi = 0;
  19717. idat[pi++] = 0x78; // compression method and flags
  19718. idat[pi++] = 0x9c; // flags
  19719. var pos = 0;
  19720. while (len > maxBlockLength) {
  19721. // writing non-final DEFLATE blocks type 0 and length of 65535
  19722. idat[pi++] = 0x00;
  19723. idat[pi++] = 0xff;
  19724. idat[pi++] = 0xff;
  19725. idat[pi++] = 0x00;
  19726. idat[pi++] = 0x00;
  19727. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  19728. pi += maxBlockLength;
  19729. pos += maxBlockLength;
  19730. len -= maxBlockLength;
  19731. }
  19732. // writing non-final DEFLATE blocks type 0
  19733. idat[pi++] = 0x01;
  19734. idat[pi++] = len & 0xff;
  19735. idat[pi++] = len >> 8 & 0xff;
  19736. idat[pi++] = (~len & 0xffff) & 0xff;
  19737. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  19738. idat.set(literals.subarray(pos), pi);
  19739. pi += literals.length - pos;
  19740. var adler = adler32(literals, 0, literals.length); // checksum
  19741. idat[pi++] = adler >> 24 & 0xff;
  19742. idat[pi++] = adler >> 16 & 0xff;
  19743. idat[pi++] = adler >> 8 & 0xff;
  19744. idat[pi++] = adler & 0xff;
  19745. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  19746. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  19747. ihdr.length + idat.length;
  19748. var data = new Uint8Array(pngLength);
  19749. var offset = 0;
  19750. data.set(PNG_HEADER, offset);
  19751. offset += PNG_HEADER.length;
  19752. writePngChunk('IHDR', ihdr, data, offset);
  19753. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  19754. writePngChunk('IDATA', idat, data, offset);
  19755. offset += CHUNK_WRAPPER_SIZE + idat.length;
  19756. writePngChunk('IEND', new Uint8Array(0), data, offset);
  19757. return createObjectURL(data, 'image/png', forceDataSchema);
  19758. }
  19759. return function convertImgDataToPng(imgData, forceDataSchema) {
  19760. var kind = (imgData.kind === undefined ?
  19761. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  19762. return encode(imgData, kind, forceDataSchema);
  19763. };
  19764. })();
  19765. var SVGExtraState = (function SVGExtraStateClosure() {
  19766. function SVGExtraState() {
  19767. this.fontSizeScale = 1;
  19768. this.fontWeight = SVG_DEFAULTS.fontWeight;
  19769. this.fontSize = 0;
  19770. this.textMatrix = IDENTITY_MATRIX;
  19771. this.fontMatrix = FONT_IDENTITY_MATRIX;
  19772. this.leading = 0;
  19773. // Current point (in user coordinates)
  19774. this.x = 0;
  19775. this.y = 0;
  19776. // Start of text line (in text coordinates)
  19777. this.lineX = 0;
  19778. this.lineY = 0;
  19779. // Character and word spacing
  19780. this.charSpacing = 0;
  19781. this.wordSpacing = 0;
  19782. this.textHScale = 1;
  19783. this.textRise = 0;
  19784. // Default foreground and background colors
  19785. this.fillColor = SVG_DEFAULTS.fillColor;
  19786. this.strokeColor = '#000000';
  19787. this.fillAlpha = 1;
  19788. this.strokeAlpha = 1;
  19789. this.lineWidth = 1;
  19790. this.lineJoin = '';
  19791. this.lineCap = '';
  19792. this.miterLimit = 0;
  19793. this.dashArray = [];
  19794. this.dashPhase = 0;
  19795. this.dependencies = [];
  19796. // Clipping
  19797. this.clipId = '';
  19798. this.pendingClip = false;
  19799. this.maskId = '';
  19800. }
  19801. SVGExtraState.prototype = {
  19802. clone: function SVGExtraState_clone() {
  19803. return Object.create(this);
  19804. },
  19805. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  19806. this.x = x;
  19807. this.y = y;
  19808. }
  19809. };
  19810. return SVGExtraState;
  19811. })();
  19812. var SVGGraphics = (function SVGGraphicsClosure() {
  19813. function createScratchSVG(width, height) {
  19814. var NS = 'http://www.w3.org/2000/svg';
  19815. var svg = document.createElementNS(NS, 'svg:svg');
  19816. svg.setAttributeNS(null, 'version', '1.1');
  19817. svg.setAttributeNS(null, 'width', width + 'px');
  19818. svg.setAttributeNS(null, 'height', height + 'px');
  19819. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  19820. return svg;
  19821. }
  19822. function opListToTree(opList) {
  19823. var opTree = [];
  19824. var tmp = [];
  19825. var opListLen = opList.length;
  19826. for (var x = 0; x < opListLen; x++) {
  19827. if (opList[x].fn === 'save') {
  19828. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  19829. tmp.push(opTree);
  19830. opTree = opTree[opTree.length - 1].items;
  19831. continue;
  19832. }
  19833. if(opList[x].fn === 'restore') {
  19834. opTree = tmp.pop();
  19835. } else {
  19836. opTree.push(opList[x]);
  19837. }
  19838. }
  19839. return opTree;
  19840. }
  19841. /**
  19842. * Formats float number.
  19843. * @param value {number} number to format.
  19844. * @returns {string}
  19845. */
  19846. function pf(value) {
  19847. if (value === (value | 0)) { // integer number
  19848. return value.toString();
  19849. }
  19850. var s = value.toFixed(10);
  19851. var i = s.length - 1;
  19852. if (s[i] !== '0') {
  19853. return s;
  19854. }
  19855. // removing trailing zeros
  19856. do {
  19857. i--;
  19858. } while (s[i] === '0');
  19859. return s.substr(0, s[i] === '.' ? i : i + 1);
  19860. }
  19861. /**
  19862. * Formats transform matrix. The standard rotation, scale and translate
  19863. * matrices are replaced by their shorter forms, and for identity matrix
  19864. * returns empty string to save the memory.
  19865. * @param m {Array} matrix to format.
  19866. * @returns {string}
  19867. */
  19868. function pm(m) {
  19869. if (m[4] === 0 && m[5] === 0) {
  19870. if (m[1] === 0 && m[2] === 0) {
  19871. if (m[0] === 1 && m[3] === 1) {
  19872. return '';
  19873. }
  19874. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  19875. }
  19876. if (m[0] === m[3] && m[1] === -m[2]) {
  19877. var a = Math.acos(m[0]) * 180 / Math.PI;
  19878. return 'rotate(' + pf(a) + ')';
  19879. }
  19880. } else {
  19881. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  19882. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19883. }
  19884. }
  19885. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  19886. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19887. }
  19888. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  19889. this.current = new SVGExtraState();
  19890. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  19891. this.transformStack = [];
  19892. this.extraStack = [];
  19893. this.commonObjs = commonObjs;
  19894. this.objs = objs;
  19895. this.pendingEOFill = false;
  19896. this.embedFonts = false;
  19897. this.embeddedFonts = Object.create(null);
  19898. this.cssStyle = null;
  19899. this.forceDataSchema = !!forceDataSchema;
  19900. }
  19901. var NS = 'http://www.w3.org/2000/svg';
  19902. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  19903. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  19904. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  19905. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  19906. var clipCount = 0;
  19907. var maskCount = 0;
  19908. SVGGraphics.prototype = {
  19909. save: function SVGGraphics_save() {
  19910. this.transformStack.push(this.transformMatrix);
  19911. var old = this.current;
  19912. this.extraStack.push(old);
  19913. this.current = old.clone();
  19914. },
  19915. restore: function SVGGraphics_restore() {
  19916. this.transformMatrix = this.transformStack.pop();
  19917. this.current = this.extraStack.pop();
  19918. this.tgrp = document.createElementNS(NS, 'svg:g');
  19919. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19920. this.pgrp.appendChild(this.tgrp);
  19921. },
  19922. group: function SVGGraphics_group(items) {
  19923. this.save();
  19924. this.executeOpTree(items);
  19925. this.restore();
  19926. },
  19927. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  19928. var fnArray = operatorList.fnArray;
  19929. var fnArrayLen = fnArray.length;
  19930. var argsArray = operatorList.argsArray;
  19931. var self = this;
  19932. for (var i = 0; i < fnArrayLen; i++) {
  19933. if (OPS.dependency === fnArray[i]) {
  19934. var deps = argsArray[i];
  19935. for (var n = 0, nn = deps.length; n < nn; n++) {
  19936. var obj = deps[n];
  19937. var common = obj.substring(0, 2) === 'g_';
  19938. var promise;
  19939. if (common) {
  19940. promise = new Promise(function(resolve) {
  19941. self.commonObjs.get(obj, resolve);
  19942. });
  19943. } else {
  19944. promise = new Promise(function(resolve) {
  19945. self.objs.get(obj, resolve);
  19946. });
  19947. }
  19948. this.current.dependencies.push(promise);
  19949. }
  19950. }
  19951. }
  19952. return Promise.all(this.current.dependencies);
  19953. },
  19954. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  19955. var transformMatrix = [a, b, c, d, e, f];
  19956. this.transformMatrix = Util.transform(this.transformMatrix,
  19957. transformMatrix);
  19958. this.tgrp = document.createElementNS(NS, 'svg:g');
  19959. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19960. },
  19961. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  19962. this.svg = createScratchSVG(viewport.width, viewport.height);
  19963. this.viewport = viewport;
  19964. return this.loadDependencies(operatorList).then(function () {
  19965. this.transformMatrix = IDENTITY_MATRIX;
  19966. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  19967. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  19968. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  19969. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19970. this.defs = document.createElementNS(NS, 'svg:defs');
  19971. this.pgrp.appendChild(this.defs);
  19972. this.pgrp.appendChild(this.tgrp);
  19973. this.svg.appendChild(this.pgrp);
  19974. var opTree = this.convertOpList(operatorList);
  19975. this.executeOpTree(opTree);
  19976. return this.svg;
  19977. }.bind(this));
  19978. },
  19979. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  19980. var argsArray = operatorList.argsArray;
  19981. var fnArray = operatorList.fnArray;
  19982. var fnArrayLen = fnArray.length;
  19983. var REVOPS = [];
  19984. var opList = [];
  19985. for (var op in OPS) {
  19986. REVOPS[OPS[op]] = op;
  19987. }
  19988. for (var x = 0; x < fnArrayLen; x++) {
  19989. var fnId = fnArray[x];
  19990. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  19991. }
  19992. return opListToTree(opList);
  19993. },
  19994. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  19995. var opTreeLen = opTree.length;
  19996. for(var x = 0; x < opTreeLen; x++) {
  19997. var fn = opTree[x].fn;
  19998. var fnId = opTree[x].fnId;
  19999. var args = opTree[x].args;
  20000. switch (fnId | 0) {
  20001. case OPS.beginText:
  20002. this.beginText();
  20003. break;
  20004. case OPS.setLeading:
  20005. this.setLeading(args);
  20006. break;
  20007. case OPS.setLeadingMoveText:
  20008. this.setLeadingMoveText(args[0], args[1]);
  20009. break;
  20010. case OPS.setFont:
  20011. this.setFont(args);
  20012. break;
  20013. case OPS.showText:
  20014. this.showText(args[0]);
  20015. break;
  20016. case OPS.showSpacedText:
  20017. this.showText(args[0]);
  20018. break;
  20019. case OPS.endText:
  20020. this.endText();
  20021. break;
  20022. case OPS.moveText:
  20023. this.moveText(args[0], args[1]);
  20024. break;
  20025. case OPS.setCharSpacing:
  20026. this.setCharSpacing(args[0]);
  20027. break;
  20028. case OPS.setWordSpacing:
  20029. this.setWordSpacing(args[0]);
  20030. break;
  20031. case OPS.setHScale:
  20032. this.setHScale(args[0]);
  20033. break;
  20034. case OPS.setTextMatrix:
  20035. this.setTextMatrix(args[0], args[1], args[2],
  20036. args[3], args[4], args[5]);
  20037. break;
  20038. case OPS.setLineWidth:
  20039. this.setLineWidth(args[0]);
  20040. break;
  20041. case OPS.setLineJoin:
  20042. this.setLineJoin(args[0]);
  20043. break;
  20044. case OPS.setLineCap:
  20045. this.setLineCap(args[0]);
  20046. break;
  20047. case OPS.setMiterLimit:
  20048. this.setMiterLimit(args[0]);
  20049. break;
  20050. case OPS.setFillRGBColor:
  20051. this.setFillRGBColor(args[0], args[1], args[2]);
  20052. break;
  20053. case OPS.setStrokeRGBColor:
  20054. this.setStrokeRGBColor(args[0], args[1], args[2]);
  20055. break;
  20056. case OPS.setDash:
  20057. this.setDash(args[0], args[1]);
  20058. break;
  20059. case OPS.setGState:
  20060. this.setGState(args[0]);
  20061. break;
  20062. case OPS.fill:
  20063. this.fill();
  20064. break;
  20065. case OPS.eoFill:
  20066. this.eoFill();
  20067. break;
  20068. case OPS.stroke:
  20069. this.stroke();
  20070. break;
  20071. case OPS.fillStroke:
  20072. this.fillStroke();
  20073. break;
  20074. case OPS.eoFillStroke:
  20075. this.eoFillStroke();
  20076. break;
  20077. case OPS.clip:
  20078. this.clip('nonzero');
  20079. break;
  20080. case OPS.eoClip:
  20081. this.clip('evenodd');
  20082. break;
  20083. case OPS.paintSolidColorImageMask:
  20084. this.paintSolidColorImageMask();
  20085. break;
  20086. case OPS.paintJpegXObject:
  20087. this.paintJpegXObject(args[0], args[1], args[2]);
  20088. break;
  20089. case OPS.paintImageXObject:
  20090. this.paintImageXObject(args[0]);
  20091. break;
  20092. case OPS.paintInlineImageXObject:
  20093. this.paintInlineImageXObject(args[0]);
  20094. break;
  20095. case OPS.paintImageMaskXObject:
  20096. this.paintImageMaskXObject(args[0]);
  20097. break;
  20098. case OPS.paintFormXObjectBegin:
  20099. this.paintFormXObjectBegin(args[0], args[1]);
  20100. break;
  20101. case OPS.paintFormXObjectEnd:
  20102. this.paintFormXObjectEnd();
  20103. break;
  20104. case OPS.closePath:
  20105. this.closePath();
  20106. break;
  20107. case OPS.closeStroke:
  20108. this.closeStroke();
  20109. break;
  20110. case OPS.closeFillStroke:
  20111. this.closeFillStroke();
  20112. break;
  20113. case OPS.nextLine:
  20114. this.nextLine();
  20115. break;
  20116. case OPS.transform:
  20117. this.transform(args[0], args[1], args[2], args[3],
  20118. args[4], args[5]);
  20119. break;
  20120. case OPS.constructPath:
  20121. this.constructPath(args[0], args[1]);
  20122. break;
  20123. case OPS.endPath:
  20124. this.endPath();
  20125. break;
  20126. case 92:
  20127. this.group(opTree[x].items);
  20128. break;
  20129. default:
  20130. warn('Unimplemented method '+ fn);
  20131. break;
  20132. }
  20133. }
  20134. },
  20135. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  20136. this.current.wordSpacing = wordSpacing;
  20137. },
  20138. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  20139. this.current.charSpacing = charSpacing;
  20140. },
  20141. nextLine: function SVGGraphics_nextLine() {
  20142. this.moveText(0, this.current.leading);
  20143. },
  20144. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  20145. var current = this.current;
  20146. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  20147. this.current.x = this.current.lineX = 0;
  20148. this.current.y = this.current.lineY = 0;
  20149. current.xcoords = [];
  20150. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20151. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20152. current.tspan.setAttributeNS(null, 'font-size',
  20153. pf(current.fontSize) + 'px');
  20154. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20155. current.txtElement = document.createElementNS(NS, 'svg:text');
  20156. current.txtElement.appendChild(current.tspan);
  20157. },
  20158. beginText: function SVGGraphics_beginText() {
  20159. this.current.x = this.current.lineX = 0;
  20160. this.current.y = this.current.lineY = 0;
  20161. this.current.textMatrix = IDENTITY_MATRIX;
  20162. this.current.lineMatrix = IDENTITY_MATRIX;
  20163. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  20164. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  20165. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  20166. this.current.xcoords = [];
  20167. },
  20168. moveText: function SVGGraphics_moveText(x, y) {
  20169. var current = this.current;
  20170. this.current.x = this.current.lineX += x;
  20171. this.current.y = this.current.lineY += y;
  20172. current.xcoords = [];
  20173. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20174. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20175. current.tspan.setAttributeNS(null, 'font-size',
  20176. pf(current.fontSize) + 'px');
  20177. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20178. },
  20179. showText: function SVGGraphics_showText(glyphs) {
  20180. var current = this.current;
  20181. var font = current.font;
  20182. var fontSize = current.fontSize;
  20183. if (fontSize === 0) {
  20184. return;
  20185. }
  20186. var charSpacing = current.charSpacing;
  20187. var wordSpacing = current.wordSpacing;
  20188. var fontDirection = current.fontDirection;
  20189. var textHScale = current.textHScale * fontDirection;
  20190. var glyphsLength = glyphs.length;
  20191. var vertical = font.vertical;
  20192. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  20193. var x = 0, i;
  20194. for (i = 0; i < glyphsLength; ++i) {
  20195. var glyph = glyphs[i];
  20196. if (glyph === null) {
  20197. // word break
  20198. x += fontDirection * wordSpacing;
  20199. continue;
  20200. } else if (isNum(glyph)) {
  20201. x += -glyph * fontSize * 0.001;
  20202. continue;
  20203. }
  20204. current.xcoords.push(current.x + x * textHScale);
  20205. var width = glyph.width;
  20206. var character = glyph.fontChar;
  20207. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  20208. x += charWidth;
  20209. current.tspan.textContent += character;
  20210. }
  20211. if (vertical) {
  20212. current.y -= x * textHScale;
  20213. } else {
  20214. current.x += x * textHScale;
  20215. }
  20216. current.tspan.setAttributeNS(null, 'x',
  20217. current.xcoords.map(pf).join(' '));
  20218. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20219. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  20220. current.tspan.setAttributeNS(null, 'font-size',
  20221. pf(current.fontSize) + 'px');
  20222. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  20223. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  20224. }
  20225. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  20226. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  20227. }
  20228. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  20229. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  20230. }
  20231. current.txtElement.setAttributeNS(null, 'transform',
  20232. pm(current.textMatrix) +
  20233. ' scale(1, -1)' );
  20234. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  20235. current.txtElement.appendChild(current.tspan);
  20236. current.txtgrp.appendChild(current.txtElement);
  20237. this.tgrp.appendChild(current.txtElement);
  20238. },
  20239. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  20240. this.setLeading(-y);
  20241. this.moveText(x, y);
  20242. },
  20243. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  20244. if (!this.cssStyle) {
  20245. this.cssStyle = document.createElementNS(NS, 'svg:style');
  20246. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  20247. this.defs.appendChild(this.cssStyle);
  20248. }
  20249. var url = createObjectURL(fontObj.data, fontObj.mimetype,
  20250. this.forceDataSchema);
  20251. this.cssStyle.textContent +=
  20252. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  20253. ' src: url(' + url + '); }\n';
  20254. },
  20255. setFont: function SVGGraphics_setFont(details) {
  20256. var current = this.current;
  20257. var fontObj = this.commonObjs.get(details[0]);
  20258. var size = details[1];
  20259. this.current.font = fontObj;
  20260. if (this.embedFonts && fontObj.data &&
  20261. !this.embeddedFonts[fontObj.loadedName]) {
  20262. this.addFontStyle(fontObj);
  20263. this.embeddedFonts[fontObj.loadedName] = fontObj;
  20264. }
  20265. current.fontMatrix = (fontObj.fontMatrix ?
  20266. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  20267. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  20268. (fontObj.bold ? 'bold' : 'normal');
  20269. var italic = fontObj.italic ? 'italic' : 'normal';
  20270. if (size < 0) {
  20271. size = -size;
  20272. current.fontDirection = -1;
  20273. } else {
  20274. current.fontDirection = 1;
  20275. }
  20276. current.fontSize = size;
  20277. current.fontFamily = fontObj.loadedName;
  20278. current.fontWeight = bold;
  20279. current.fontStyle = italic;
  20280. current.tspan = document.createElementNS(NS, 'svg:tspan');
  20281. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  20282. current.xcoords = [];
  20283. },
  20284. endText: function SVGGraphics_endText() {
  20285. if (this.current.pendingClip) {
  20286. this.cgrp.appendChild(this.tgrp);
  20287. this.pgrp.appendChild(this.cgrp);
  20288. } else {
  20289. this.pgrp.appendChild(this.tgrp);
  20290. }
  20291. this.tgrp = document.createElementNS(NS, 'svg:g');
  20292. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20293. },
  20294. // Path properties
  20295. setLineWidth: function SVGGraphics_setLineWidth(width) {
  20296. this.current.lineWidth = width;
  20297. },
  20298. setLineCap: function SVGGraphics_setLineCap(style) {
  20299. this.current.lineCap = LINE_CAP_STYLES[style];
  20300. },
  20301. setLineJoin: function SVGGraphics_setLineJoin(style) {
  20302. this.current.lineJoin = LINE_JOIN_STYLES[style];
  20303. },
  20304. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  20305. this.current.miterLimit = limit;
  20306. },
  20307. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  20308. var color = Util.makeCssRgb(r, g, b);
  20309. this.current.strokeColor = color;
  20310. },
  20311. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  20312. var color = Util.makeCssRgb(r, g, b);
  20313. this.current.fillColor = color;
  20314. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  20315. this.current.xcoords = [];
  20316. },
  20317. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  20318. this.current.dashArray = dashArray;
  20319. this.current.dashPhase = dashPhase;
  20320. },
  20321. constructPath: function SVGGraphics_constructPath(ops, args) {
  20322. var current = this.current;
  20323. var x = current.x, y = current.y;
  20324. current.path = document.createElementNS(NS, 'svg:path');
  20325. var d = [];
  20326. var opLength = ops.length;
  20327. for (var i = 0, j = 0; i < opLength; i++) {
  20328. switch (ops[i] | 0) {
  20329. case OPS.rectangle:
  20330. x = args[j++];
  20331. y = args[j++];
  20332. var width = args[j++];
  20333. var height = args[j++];
  20334. var xw = x + width;
  20335. var yh = y + height;
  20336. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  20337. 'L', pf(x), pf(yh), 'Z');
  20338. break;
  20339. case OPS.moveTo:
  20340. x = args[j++];
  20341. y = args[j++];
  20342. d.push('M', pf(x), pf(y));
  20343. break;
  20344. case OPS.lineTo:
  20345. x = args[j++];
  20346. y = args[j++];
  20347. d.push('L', pf(x) , pf(y));
  20348. break;
  20349. case OPS.curveTo:
  20350. x = args[j + 4];
  20351. y = args[j + 5];
  20352. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  20353. pf(args[j + 3]), pf(x), pf(y));
  20354. j += 6;
  20355. break;
  20356. case OPS.curveTo2:
  20357. x = args[j + 2];
  20358. y = args[j + 3];
  20359. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  20360. pf(args[j + 2]), pf(args[j + 3]));
  20361. j += 4;
  20362. break;
  20363. case OPS.curveTo3:
  20364. x = args[j + 2];
  20365. y = args[j + 3];
  20366. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  20367. pf(x), pf(y));
  20368. j += 4;
  20369. break;
  20370. case OPS.closePath:
  20371. d.push('Z');
  20372. break;
  20373. }
  20374. }
  20375. current.path.setAttributeNS(null, 'd', d.join(' '));
  20376. current.path.setAttributeNS(null, 'stroke-miterlimit',
  20377. pf(current.miterLimit));
  20378. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  20379. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  20380. current.path.setAttributeNS(null, 'stroke-width',
  20381. pf(current.lineWidth) + 'px');
  20382. current.path.setAttributeNS(null, 'stroke-dasharray',
  20383. current.dashArray.map(pf).join(' '));
  20384. current.path.setAttributeNS(null, 'stroke-dashoffset',
  20385. pf(current.dashPhase) + 'px');
  20386. current.path.setAttributeNS(null, 'fill', 'none');
  20387. this.tgrp.appendChild(current.path);
  20388. if (current.pendingClip) {
  20389. this.cgrp.appendChild(this.tgrp);
  20390. this.pgrp.appendChild(this.cgrp);
  20391. } else {
  20392. this.pgrp.appendChild(this.tgrp);
  20393. }
  20394. // Saving a reference in current.element so that it can be addressed
  20395. // in 'fill' and 'stroke'
  20396. current.element = current.path;
  20397. current.setCurrentPoint(x, y);
  20398. },
  20399. endPath: function SVGGraphics_endPath() {
  20400. var current = this.current;
  20401. if (current.pendingClip) {
  20402. this.cgrp.appendChild(this.tgrp);
  20403. this.pgrp.appendChild(this.cgrp);
  20404. } else {
  20405. this.pgrp.appendChild(this.tgrp);
  20406. }
  20407. this.tgrp = document.createElementNS(NS, 'svg:g');
  20408. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20409. },
  20410. clip: function SVGGraphics_clip(type) {
  20411. var current = this.current;
  20412. // Add current path to clipping path
  20413. current.clipId = 'clippath' + clipCount;
  20414. clipCount++;
  20415. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  20416. this.clippath.setAttributeNS(null, 'id', current.clipId);
  20417. var clipElement = current.element.cloneNode();
  20418. if (type === 'evenodd') {
  20419. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  20420. } else {
  20421. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  20422. }
  20423. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  20424. this.clippath.appendChild(clipElement);
  20425. this.defs.appendChild(this.clippath);
  20426. // Create a new group with that attribute
  20427. current.pendingClip = true;
  20428. this.cgrp = document.createElementNS(NS, 'svg:g');
  20429. this.cgrp.setAttributeNS(null, 'clip-path',
  20430. 'url(#' + current.clipId + ')');
  20431. this.pgrp.appendChild(this.cgrp);
  20432. },
  20433. closePath: function SVGGraphics_closePath() {
  20434. var current = this.current;
  20435. var d = current.path.getAttributeNS(null, 'd');
  20436. d += 'Z';
  20437. current.path.setAttributeNS(null, 'd', d);
  20438. },
  20439. setLeading: function SVGGraphics_setLeading(leading) {
  20440. this.current.leading = -leading;
  20441. },
  20442. setTextRise: function SVGGraphics_setTextRise(textRise) {
  20443. this.current.textRise = textRise;
  20444. },
  20445. setHScale: function SVGGraphics_setHScale(scale) {
  20446. this.current.textHScale = scale / 100;
  20447. },
  20448. setGState: function SVGGraphics_setGState(states) {
  20449. for (var i = 0, ii = states.length; i < ii; i++) {
  20450. var state = states[i];
  20451. var key = state[0];
  20452. var value = state[1];
  20453. switch (key) {
  20454. case 'LW':
  20455. this.setLineWidth(value);
  20456. break;
  20457. case 'LC':
  20458. this.setLineCap(value);
  20459. break;
  20460. case 'LJ':
  20461. this.setLineJoin(value);
  20462. break;
  20463. case 'ML':
  20464. this.setMiterLimit(value);
  20465. break;
  20466. case 'D':
  20467. this.setDash(value[0], value[1]);
  20468. break;
  20469. case 'RI':
  20470. break;
  20471. case 'FL':
  20472. break;
  20473. case 'Font':
  20474. this.setFont(value);
  20475. break;
  20476. case 'CA':
  20477. break;
  20478. case 'ca':
  20479. break;
  20480. case 'BM':
  20481. break;
  20482. case 'SMask':
  20483. break;
  20484. }
  20485. }
  20486. },
  20487. fill: function SVGGraphics_fill() {
  20488. var current = this.current;
  20489. current.element.setAttributeNS(null, 'fill', current.fillColor);
  20490. },
  20491. stroke: function SVGGraphics_stroke() {
  20492. var current = this.current;
  20493. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  20494. current.element.setAttributeNS(null, 'fill', 'none');
  20495. },
  20496. eoFill: function SVGGraphics_eoFill() {
  20497. var current = this.current;
  20498. current.element.setAttributeNS(null, 'fill', current.fillColor);
  20499. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  20500. },
  20501. fillStroke: function SVGGraphics_fillStroke() {
  20502. // Order is important since stroke wants fill to be none.
  20503. // First stroke, then if fill needed, it will be overwritten.
  20504. this.stroke();
  20505. this.fill();
  20506. },
  20507. eoFillStroke: function SVGGraphics_eoFillStroke() {
  20508. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  20509. this.fillStroke();
  20510. },
  20511. closeStroke: function SVGGraphics_closeStroke() {
  20512. this.closePath();
  20513. this.stroke();
  20514. },
  20515. closeFillStroke: function SVGGraphics_closeFillStroke() {
  20516. this.closePath();
  20517. this.fillStroke();
  20518. },
  20519. paintSolidColorImageMask:
  20520. function SVGGraphics_paintSolidColorImageMask() {
  20521. var current = this.current;
  20522. var rect = document.createElementNS(NS, 'svg:rect');
  20523. rect.setAttributeNS(null, 'x', '0');
  20524. rect.setAttributeNS(null, 'y', '0');
  20525. rect.setAttributeNS(null, 'width', '1px');
  20526. rect.setAttributeNS(null, 'height', '1px');
  20527. rect.setAttributeNS(null, 'fill', current.fillColor);
  20528. this.tgrp.appendChild(rect);
  20529. },
  20530. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  20531. var current = this.current;
  20532. var imgObj = this.objs.get(objId);
  20533. var imgEl = document.createElementNS(NS, 'svg:image');
  20534. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  20535. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  20536. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  20537. imgEl.setAttributeNS(null, 'x', '0');
  20538. imgEl.setAttributeNS(null, 'y', pf(-h));
  20539. imgEl.setAttributeNS(null, 'transform',
  20540. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  20541. this.tgrp.appendChild(imgEl);
  20542. if (current.pendingClip) {
  20543. this.cgrp.appendChild(this.tgrp);
  20544. this.pgrp.appendChild(this.cgrp);
  20545. } else {
  20546. this.pgrp.appendChild(this.tgrp);
  20547. }
  20548. },
  20549. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  20550. var imgData = this.objs.get(objId);
  20551. if (!imgData) {
  20552. warn('Dependent image isn\'t ready yet');
  20553. return;
  20554. }
  20555. this.paintInlineImageXObject(imgData);
  20556. },
  20557. paintInlineImageXObject:
  20558. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  20559. var current = this.current;
  20560. var width = imgData.width;
  20561. var height = imgData.height;
  20562. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  20563. var cliprect = document.createElementNS(NS, 'svg:rect');
  20564. cliprect.setAttributeNS(null, 'x', '0');
  20565. cliprect.setAttributeNS(null, 'y', '0');
  20566. cliprect.setAttributeNS(null, 'width', pf(width));
  20567. cliprect.setAttributeNS(null, 'height', pf(height));
  20568. current.element = cliprect;
  20569. this.clip('nonzero');
  20570. var imgEl = document.createElementNS(NS, 'svg:image');
  20571. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  20572. imgEl.setAttributeNS(null, 'x', '0');
  20573. imgEl.setAttributeNS(null, 'y', pf(-height));
  20574. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  20575. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  20576. imgEl.setAttributeNS(null, 'transform',
  20577. 'scale(' + pf(1 / width) + ' ' +
  20578. pf(-1 / height) + ')');
  20579. if (mask) {
  20580. mask.appendChild(imgEl);
  20581. } else {
  20582. this.tgrp.appendChild(imgEl);
  20583. }
  20584. if (current.pendingClip) {
  20585. this.cgrp.appendChild(this.tgrp);
  20586. this.pgrp.appendChild(this.cgrp);
  20587. } else {
  20588. this.pgrp.appendChild(this.tgrp);
  20589. }
  20590. },
  20591. paintImageMaskXObject:
  20592. function SVGGraphics_paintImageMaskXObject(imgData) {
  20593. var current = this.current;
  20594. var width = imgData.width;
  20595. var height = imgData.height;
  20596. var fillColor = current.fillColor;
  20597. current.maskId = 'mask' + maskCount++;
  20598. var mask = document.createElementNS(NS, 'svg:mask');
  20599. mask.setAttributeNS(null, 'id', current.maskId);
  20600. var rect = document.createElementNS(NS, 'svg:rect');
  20601. rect.setAttributeNS(null, 'x', '0');
  20602. rect.setAttributeNS(null, 'y', '0');
  20603. rect.setAttributeNS(null, 'width', pf(width));
  20604. rect.setAttributeNS(null, 'height', pf(height));
  20605. rect.setAttributeNS(null, 'fill', fillColor);
  20606. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  20607. this.defs.appendChild(mask);
  20608. this.tgrp.appendChild(rect);
  20609. this.paintInlineImageXObject(imgData, mask);
  20610. },
  20611. paintFormXObjectBegin:
  20612. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  20613. this.save();
  20614. if (isArray(matrix) && matrix.length === 6) {
  20615. this.transform(matrix[0], matrix[1], matrix[2],
  20616. matrix[3], matrix[4], matrix[5]);
  20617. }
  20618. if (isArray(bbox) && bbox.length === 4) {
  20619. var width = bbox[2] - bbox[0];
  20620. var height = bbox[3] - bbox[1];
  20621. var cliprect = document.createElementNS(NS, 'svg:rect');
  20622. cliprect.setAttributeNS(null, 'x', bbox[0]);
  20623. cliprect.setAttributeNS(null, 'y', bbox[1]);
  20624. cliprect.setAttributeNS(null, 'width', pf(width));
  20625. cliprect.setAttributeNS(null, 'height', pf(height));
  20626. this.current.element = cliprect;
  20627. this.clip('nonzero');
  20628. this.endPath();
  20629. }
  20630. },
  20631. paintFormXObjectEnd:
  20632. function SVGGraphics_paintFormXObjectEnd() {
  20633. this.restore();
  20634. }
  20635. };
  20636. return SVGGraphics;
  20637. })();
  20638. exports.SVGGraphics = SVGGraphics;
  20639. }));
  20640. (function (root, factory) {
  20641. {
  20642. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  20643. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  20644. root.pdfjsCoreJpx);
  20645. }
  20646. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  20647. coreJpx) {
  20648. var Util = sharedUtil.Util;
  20649. var error = sharedUtil.error;
  20650. var info = sharedUtil.info;
  20651. var isInt = sharedUtil.isInt;
  20652. var isArray = sharedUtil.isArray;
  20653. var createObjectURL = sharedUtil.createObjectURL;
  20654. var shadow = sharedUtil.shadow;
  20655. var warn = sharedUtil.warn;
  20656. var isSpace = sharedUtil.isSpace;
  20657. var Dict = corePrimitives.Dict;
  20658. var isDict = corePrimitives.isDict;
  20659. var Jbig2Image = coreJbig2.Jbig2Image;
  20660. var JpegImage = coreJpg.JpegImage;
  20661. var JpxImage = coreJpx.JpxImage;
  20662. var Stream = (function StreamClosure() {
  20663. function Stream(arrayBuffer, start, length, dict) {
  20664. this.bytes = (arrayBuffer instanceof Uint8Array ?
  20665. arrayBuffer : new Uint8Array(arrayBuffer));
  20666. this.start = start || 0;
  20667. this.pos = this.start;
  20668. this.end = (start + length) || this.bytes.length;
  20669. this.dict = dict;
  20670. }
  20671. // required methods for a stream. if a particular stream does not
  20672. // implement these, an error should be thrown
  20673. Stream.prototype = {
  20674. get length() {
  20675. return this.end - this.start;
  20676. },
  20677. get isEmpty() {
  20678. return this.length === 0;
  20679. },
  20680. getByte: function Stream_getByte() {
  20681. if (this.pos >= this.end) {
  20682. return -1;
  20683. }
  20684. return this.bytes[this.pos++];
  20685. },
  20686. getUint16: function Stream_getUint16() {
  20687. var b0 = this.getByte();
  20688. var b1 = this.getByte();
  20689. if (b0 === -1 || b1 === -1) {
  20690. return -1;
  20691. }
  20692. return (b0 << 8) + b1;
  20693. },
  20694. getInt32: function Stream_getInt32() {
  20695. var b0 = this.getByte();
  20696. var b1 = this.getByte();
  20697. var b2 = this.getByte();
  20698. var b3 = this.getByte();
  20699. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20700. },
  20701. // returns subarray of original buffer
  20702. // should only be read
  20703. getBytes: function Stream_getBytes(length) {
  20704. var bytes = this.bytes;
  20705. var pos = this.pos;
  20706. var strEnd = this.end;
  20707. if (!length) {
  20708. return bytes.subarray(pos, strEnd);
  20709. }
  20710. var end = pos + length;
  20711. if (end > strEnd) {
  20712. end = strEnd;
  20713. }
  20714. this.pos = end;
  20715. return bytes.subarray(pos, end);
  20716. },
  20717. peekByte: function Stream_peekByte() {
  20718. var peekedByte = this.getByte();
  20719. this.pos--;
  20720. return peekedByte;
  20721. },
  20722. peekBytes: function Stream_peekBytes(length) {
  20723. var bytes = this.getBytes(length);
  20724. this.pos -= bytes.length;
  20725. return bytes;
  20726. },
  20727. skip: function Stream_skip(n) {
  20728. if (!n) {
  20729. n = 1;
  20730. }
  20731. this.pos += n;
  20732. },
  20733. reset: function Stream_reset() {
  20734. this.pos = this.start;
  20735. },
  20736. moveStart: function Stream_moveStart() {
  20737. this.start = this.pos;
  20738. },
  20739. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  20740. return new Stream(this.bytes.buffer, start, length, dict);
  20741. },
  20742. isStream: true
  20743. };
  20744. return Stream;
  20745. })();
  20746. var StringStream = (function StringStreamClosure() {
  20747. function StringStream(str) {
  20748. var length = str.length;
  20749. var bytes = new Uint8Array(length);
  20750. for (var n = 0; n < length; ++n) {
  20751. bytes[n] = str.charCodeAt(n);
  20752. }
  20753. Stream.call(this, bytes);
  20754. }
  20755. StringStream.prototype = Stream.prototype;
  20756. return StringStream;
  20757. })();
  20758. // super class for the decoding streams
  20759. var DecodeStream = (function DecodeStreamClosure() {
  20760. // Lots of DecodeStreams are created whose buffers are never used. For these
  20761. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  20762. // having special cases that would be required if we used |null| for an empty
  20763. // buffer.
  20764. var emptyBuffer = new Uint8Array(0);
  20765. function DecodeStream(maybeMinBufferLength) {
  20766. this.pos = 0;
  20767. this.bufferLength = 0;
  20768. this.eof = false;
  20769. this.buffer = emptyBuffer;
  20770. this.minBufferLength = 512;
  20771. if (maybeMinBufferLength) {
  20772. // Compute the first power of two that is as big as maybeMinBufferLength.
  20773. while (this.minBufferLength < maybeMinBufferLength) {
  20774. this.minBufferLength *= 2;
  20775. }
  20776. }
  20777. }
  20778. DecodeStream.prototype = {
  20779. get isEmpty() {
  20780. while (!this.eof && this.bufferLength === 0) {
  20781. this.readBlock();
  20782. }
  20783. return this.bufferLength === 0;
  20784. },
  20785. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  20786. var buffer = this.buffer;
  20787. if (requested <= buffer.byteLength) {
  20788. return buffer;
  20789. }
  20790. var size = this.minBufferLength;
  20791. while (size < requested) {
  20792. size *= 2;
  20793. }
  20794. var buffer2 = new Uint8Array(size);
  20795. buffer2.set(buffer);
  20796. return (this.buffer = buffer2);
  20797. },
  20798. getByte: function DecodeStream_getByte() {
  20799. var pos = this.pos;
  20800. while (this.bufferLength <= pos) {
  20801. if (this.eof) {
  20802. return -1;
  20803. }
  20804. this.readBlock();
  20805. }
  20806. return this.buffer[this.pos++];
  20807. },
  20808. getUint16: function DecodeStream_getUint16() {
  20809. var b0 = this.getByte();
  20810. var b1 = this.getByte();
  20811. if (b0 === -1 || b1 === -1) {
  20812. return -1;
  20813. }
  20814. return (b0 << 8) + b1;
  20815. },
  20816. getInt32: function DecodeStream_getInt32() {
  20817. var b0 = this.getByte();
  20818. var b1 = this.getByte();
  20819. var b2 = this.getByte();
  20820. var b3 = this.getByte();
  20821. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20822. },
  20823. getBytes: function DecodeStream_getBytes(length) {
  20824. var end, pos = this.pos;
  20825. if (length) {
  20826. this.ensureBuffer(pos + length);
  20827. end = pos + length;
  20828. while (!this.eof && this.bufferLength < end) {
  20829. this.readBlock();
  20830. }
  20831. var bufEnd = this.bufferLength;
  20832. if (end > bufEnd) {
  20833. end = bufEnd;
  20834. }
  20835. } else {
  20836. while (!this.eof) {
  20837. this.readBlock();
  20838. }
  20839. end = this.bufferLength;
  20840. }
  20841. this.pos = end;
  20842. return this.buffer.subarray(pos, end);
  20843. },
  20844. peekByte: function DecodeStream_peekByte() {
  20845. var peekedByte = this.getByte();
  20846. this.pos--;
  20847. return peekedByte;
  20848. },
  20849. peekBytes: function DecodeStream_peekBytes(length) {
  20850. var bytes = this.getBytes(length);
  20851. this.pos -= bytes.length;
  20852. return bytes;
  20853. },
  20854. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  20855. var end = start + length;
  20856. while (this.bufferLength <= end && !this.eof) {
  20857. this.readBlock();
  20858. }
  20859. return new Stream(this.buffer, start, length, dict);
  20860. },
  20861. skip: function DecodeStream_skip(n) {
  20862. if (!n) {
  20863. n = 1;
  20864. }
  20865. this.pos += n;
  20866. },
  20867. reset: function DecodeStream_reset() {
  20868. this.pos = 0;
  20869. },
  20870. getBaseStreams: function DecodeStream_getBaseStreams() {
  20871. if (this.str && this.str.getBaseStreams) {
  20872. return this.str.getBaseStreams();
  20873. }
  20874. return [];
  20875. }
  20876. };
  20877. return DecodeStream;
  20878. })();
  20879. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  20880. function StreamsSequenceStream(streams) {
  20881. this.streams = streams;
  20882. DecodeStream.call(this, /* maybeLength = */ null);
  20883. }
  20884. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  20885. StreamsSequenceStream.prototype.readBlock =
  20886. function streamSequenceStreamReadBlock() {
  20887. var streams = this.streams;
  20888. if (streams.length === 0) {
  20889. this.eof = true;
  20890. return;
  20891. }
  20892. var stream = streams.shift();
  20893. var chunk = stream.getBytes();
  20894. var bufferLength = this.bufferLength;
  20895. var newLength = bufferLength + chunk.length;
  20896. var buffer = this.ensureBuffer(newLength);
  20897. buffer.set(chunk, bufferLength);
  20898. this.bufferLength = newLength;
  20899. };
  20900. StreamsSequenceStream.prototype.getBaseStreams =
  20901. function StreamsSequenceStream_getBaseStreams() {
  20902. var baseStreams = [];
  20903. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  20904. var stream = this.streams[i];
  20905. if (stream.getBaseStreams) {
  20906. Util.appendToArray(baseStreams, stream.getBaseStreams());
  20907. }
  20908. }
  20909. return baseStreams;
  20910. };
  20911. return StreamsSequenceStream;
  20912. })();
  20913. var FlateStream = (function FlateStreamClosure() {
  20914. var codeLenCodeMap = new Int32Array([
  20915. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  20916. ]);
  20917. var lengthDecode = new Int32Array([
  20918. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  20919. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  20920. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  20921. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  20922. ]);
  20923. var distDecode = new Int32Array([
  20924. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  20925. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  20926. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  20927. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  20928. ]);
  20929. var fixedLitCodeTab = [new Int32Array([
  20930. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  20931. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  20932. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  20933. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  20934. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  20935. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  20936. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  20937. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  20938. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  20939. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  20940. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  20941. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  20942. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  20943. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  20944. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  20945. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  20946. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  20947. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  20948. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  20949. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  20950. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  20951. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  20952. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  20953. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  20954. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  20955. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  20956. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  20957. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  20958. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  20959. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  20960. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  20961. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  20962. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  20963. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  20964. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  20965. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  20966. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  20967. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  20968. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  20969. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  20970. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  20971. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  20972. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  20973. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  20974. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  20975. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  20976. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  20977. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  20978. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  20979. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  20980. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  20981. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  20982. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  20983. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  20984. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  20985. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  20986. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  20987. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  20988. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  20989. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  20990. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  20991. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  20992. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  20993. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  20994. ]), 9];
  20995. var fixedDistCodeTab = [new Int32Array([
  20996. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  20997. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  20998. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  20999. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  21000. ]), 5];
  21001. function FlateStream(str, maybeLength) {
  21002. this.str = str;
  21003. this.dict = str.dict;
  21004. var cmf = str.getByte();
  21005. var flg = str.getByte();
  21006. if (cmf === -1 || flg === -1) {
  21007. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  21008. }
  21009. if ((cmf & 0x0f) !== 0x08) {
  21010. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  21011. }
  21012. if ((((cmf << 8) + flg) % 31) !== 0) {
  21013. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  21014. }
  21015. if (flg & 0x20) {
  21016. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  21017. }
  21018. this.codeSize = 0;
  21019. this.codeBuf = 0;
  21020. DecodeStream.call(this, maybeLength);
  21021. }
  21022. FlateStream.prototype = Object.create(DecodeStream.prototype);
  21023. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  21024. var str = this.str;
  21025. var codeSize = this.codeSize;
  21026. var codeBuf = this.codeBuf;
  21027. var b;
  21028. while (codeSize < bits) {
  21029. if ((b = str.getByte()) === -1) {
  21030. error('Bad encoding in flate stream');
  21031. }
  21032. codeBuf |= b << codeSize;
  21033. codeSize += 8;
  21034. }
  21035. b = codeBuf & ((1 << bits) - 1);
  21036. this.codeBuf = codeBuf >> bits;
  21037. this.codeSize = codeSize -= bits;
  21038. return b;
  21039. };
  21040. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  21041. var str = this.str;
  21042. var codes = table[0];
  21043. var maxLen = table[1];
  21044. var codeSize = this.codeSize;
  21045. var codeBuf = this.codeBuf;
  21046. var b;
  21047. while (codeSize < maxLen) {
  21048. if ((b = str.getByte()) === -1) {
  21049. // premature end of stream. code might however still be valid.
  21050. // codeSize < codeLen check below guards against incomplete codeVal.
  21051. break;
  21052. }
  21053. codeBuf |= (b << codeSize);
  21054. codeSize += 8;
  21055. }
  21056. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  21057. var codeLen = code >> 16;
  21058. var codeVal = code & 0xffff;
  21059. if (codeLen < 1 || codeSize < codeLen) {
  21060. error('Bad encoding in flate stream');
  21061. }
  21062. this.codeBuf = (codeBuf >> codeLen);
  21063. this.codeSize = (codeSize - codeLen);
  21064. return codeVal;
  21065. };
  21066. FlateStream.prototype.generateHuffmanTable =
  21067. function flateStreamGenerateHuffmanTable(lengths) {
  21068. var n = lengths.length;
  21069. // find max code length
  21070. var maxLen = 0;
  21071. var i;
  21072. for (i = 0; i < n; ++i) {
  21073. if (lengths[i] > maxLen) {
  21074. maxLen = lengths[i];
  21075. }
  21076. }
  21077. // build the table
  21078. var size = 1 << maxLen;
  21079. var codes = new Int32Array(size);
  21080. for (var len = 1, code = 0, skip = 2;
  21081. len <= maxLen;
  21082. ++len, code <<= 1, skip <<= 1) {
  21083. for (var val = 0; val < n; ++val) {
  21084. if (lengths[val] === len) {
  21085. // bit-reverse the code
  21086. var code2 = 0;
  21087. var t = code;
  21088. for (i = 0; i < len; ++i) {
  21089. code2 = (code2 << 1) | (t & 1);
  21090. t >>= 1;
  21091. }
  21092. // fill the table entries
  21093. for (i = code2; i < size; i += skip) {
  21094. codes[i] = (len << 16) | val;
  21095. }
  21096. ++code;
  21097. }
  21098. }
  21099. }
  21100. return [codes, maxLen];
  21101. };
  21102. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  21103. var buffer, len;
  21104. var str = this.str;
  21105. // read block header
  21106. var hdr = this.getBits(3);
  21107. if (hdr & 1) {
  21108. this.eof = true;
  21109. }
  21110. hdr >>= 1;
  21111. if (hdr === 0) { // uncompressed block
  21112. var b;
  21113. if ((b = str.getByte()) === -1) {
  21114. error('Bad block header in flate stream');
  21115. }
  21116. var blockLen = b;
  21117. if ((b = str.getByte()) === -1) {
  21118. error('Bad block header in flate stream');
  21119. }
  21120. blockLen |= (b << 8);
  21121. if ((b = str.getByte()) === -1) {
  21122. error('Bad block header in flate stream');
  21123. }
  21124. var check = b;
  21125. if ((b = str.getByte()) === -1) {
  21126. error('Bad block header in flate stream');
  21127. }
  21128. check |= (b << 8);
  21129. if (check !== (~blockLen & 0xffff) &&
  21130. (blockLen !== 0 || check !== 0)) {
  21131. // Ignoring error for bad "empty" block (see issue 1277)
  21132. error('Bad uncompressed block length in flate stream');
  21133. }
  21134. this.codeBuf = 0;
  21135. this.codeSize = 0;
  21136. var bufferLength = this.bufferLength;
  21137. buffer = this.ensureBuffer(bufferLength + blockLen);
  21138. var end = bufferLength + blockLen;
  21139. this.bufferLength = end;
  21140. if (blockLen === 0) {
  21141. if (str.peekByte() === -1) {
  21142. this.eof = true;
  21143. }
  21144. } else {
  21145. for (var n = bufferLength; n < end; ++n) {
  21146. if ((b = str.getByte()) === -1) {
  21147. this.eof = true;
  21148. break;
  21149. }
  21150. buffer[n] = b;
  21151. }
  21152. }
  21153. return;
  21154. }
  21155. var litCodeTable;
  21156. var distCodeTable;
  21157. if (hdr === 1) { // compressed block, fixed codes
  21158. litCodeTable = fixedLitCodeTab;
  21159. distCodeTable = fixedDistCodeTab;
  21160. } else if (hdr === 2) { // compressed block, dynamic codes
  21161. var numLitCodes = this.getBits(5) + 257;
  21162. var numDistCodes = this.getBits(5) + 1;
  21163. var numCodeLenCodes = this.getBits(4) + 4;
  21164. // build the code lengths code table
  21165. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  21166. var i;
  21167. for (i = 0; i < numCodeLenCodes; ++i) {
  21168. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  21169. }
  21170. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  21171. // build the literal and distance code tables
  21172. len = 0;
  21173. i = 0;
  21174. var codes = numLitCodes + numDistCodes;
  21175. var codeLengths = new Uint8Array(codes);
  21176. var bitsLength, bitsOffset, what;
  21177. while (i < codes) {
  21178. var code = this.getCode(codeLenCodeTab);
  21179. if (code === 16) {
  21180. bitsLength = 2; bitsOffset = 3; what = len;
  21181. } else if (code === 17) {
  21182. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  21183. } else if (code === 18) {
  21184. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  21185. } else {
  21186. codeLengths[i++] = len = code;
  21187. continue;
  21188. }
  21189. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  21190. while (repeatLength-- > 0) {
  21191. codeLengths[i++] = what;
  21192. }
  21193. }
  21194. litCodeTable =
  21195. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  21196. distCodeTable =
  21197. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  21198. } else {
  21199. error('Unknown block type in flate stream');
  21200. }
  21201. buffer = this.buffer;
  21202. var limit = buffer ? buffer.length : 0;
  21203. var pos = this.bufferLength;
  21204. while (true) {
  21205. var code1 = this.getCode(litCodeTable);
  21206. if (code1 < 256) {
  21207. if (pos + 1 >= limit) {
  21208. buffer = this.ensureBuffer(pos + 1);
  21209. limit = buffer.length;
  21210. }
  21211. buffer[pos++] = code1;
  21212. continue;
  21213. }
  21214. if (code1 === 256) {
  21215. this.bufferLength = pos;
  21216. return;
  21217. }
  21218. code1 -= 257;
  21219. code1 = lengthDecode[code1];
  21220. var code2 = code1 >> 16;
  21221. if (code2 > 0) {
  21222. code2 = this.getBits(code2);
  21223. }
  21224. len = (code1 & 0xffff) + code2;
  21225. code1 = this.getCode(distCodeTable);
  21226. code1 = distDecode[code1];
  21227. code2 = code1 >> 16;
  21228. if (code2 > 0) {
  21229. code2 = this.getBits(code2);
  21230. }
  21231. var dist = (code1 & 0xffff) + code2;
  21232. if (pos + len >= limit) {
  21233. buffer = this.ensureBuffer(pos + len);
  21234. limit = buffer.length;
  21235. }
  21236. for (var k = 0; k < len; ++k, ++pos) {
  21237. buffer[pos] = buffer[pos - dist];
  21238. }
  21239. }
  21240. };
  21241. return FlateStream;
  21242. })();
  21243. var PredictorStream = (function PredictorStreamClosure() {
  21244. function PredictorStream(str, maybeLength, params) {
  21245. if (!isDict(params)) {
  21246. return str; // no prediction
  21247. }
  21248. var predictor = this.predictor = params.get('Predictor') || 1;
  21249. if (predictor <= 1) {
  21250. return str; // no prediction
  21251. }
  21252. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  21253. error('Unsupported predictor: ' + predictor);
  21254. }
  21255. if (predictor === 2) {
  21256. this.readBlock = this.readBlockTiff;
  21257. } else {
  21258. this.readBlock = this.readBlockPng;
  21259. }
  21260. this.str = str;
  21261. this.dict = str.dict;
  21262. var colors = this.colors = params.get('Colors') || 1;
  21263. var bits = this.bits = params.get('BitsPerComponent') || 8;
  21264. var columns = this.columns = params.get('Columns') || 1;
  21265. this.pixBytes = (colors * bits + 7) >> 3;
  21266. this.rowBytes = (columns * colors * bits + 7) >> 3;
  21267. DecodeStream.call(this, maybeLength);
  21268. return this;
  21269. }
  21270. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  21271. PredictorStream.prototype.readBlockTiff =
  21272. function predictorStreamReadBlockTiff() {
  21273. var rowBytes = this.rowBytes;
  21274. var bufferLength = this.bufferLength;
  21275. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21276. var bits = this.bits;
  21277. var colors = this.colors;
  21278. var rawBytes = this.str.getBytes(rowBytes);
  21279. this.eof = !rawBytes.length;
  21280. if (this.eof) {
  21281. return;
  21282. }
  21283. var inbuf = 0, outbuf = 0;
  21284. var inbits = 0, outbits = 0;
  21285. var pos = bufferLength;
  21286. var i;
  21287. if (bits === 1) {
  21288. for (i = 0; i < rowBytes; ++i) {
  21289. var c = rawBytes[i];
  21290. inbuf = (inbuf << 8) | c;
  21291. // bitwise addition is exclusive or
  21292. // first shift inbuf and then add
  21293. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  21294. // truncate inbuf (assumes colors < 16)
  21295. inbuf &= 0xFFFF;
  21296. }
  21297. } else if (bits === 8) {
  21298. for (i = 0; i < colors; ++i) {
  21299. buffer[pos++] = rawBytes[i];
  21300. }
  21301. for (; i < rowBytes; ++i) {
  21302. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  21303. pos++;
  21304. }
  21305. } else {
  21306. var compArray = new Uint8Array(colors + 1);
  21307. var bitMask = (1 << bits) - 1;
  21308. var j = 0, k = bufferLength;
  21309. var columns = this.columns;
  21310. for (i = 0; i < columns; ++i) {
  21311. for (var kk = 0; kk < colors; ++kk) {
  21312. if (inbits < bits) {
  21313. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  21314. inbits += 8;
  21315. }
  21316. compArray[kk] = (compArray[kk] +
  21317. (inbuf >> (inbits - bits))) & bitMask;
  21318. inbits -= bits;
  21319. outbuf = (outbuf << bits) | compArray[kk];
  21320. outbits += bits;
  21321. if (outbits >= 8) {
  21322. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  21323. outbits -= 8;
  21324. }
  21325. }
  21326. }
  21327. if (outbits > 0) {
  21328. buffer[k++] = (outbuf << (8 - outbits)) +
  21329. (inbuf & ((1 << (8 - outbits)) - 1));
  21330. }
  21331. }
  21332. this.bufferLength += rowBytes;
  21333. };
  21334. PredictorStream.prototype.readBlockPng =
  21335. function predictorStreamReadBlockPng() {
  21336. var rowBytes = this.rowBytes;
  21337. var pixBytes = this.pixBytes;
  21338. var predictor = this.str.getByte();
  21339. var rawBytes = this.str.getBytes(rowBytes);
  21340. this.eof = !rawBytes.length;
  21341. if (this.eof) {
  21342. return;
  21343. }
  21344. var bufferLength = this.bufferLength;
  21345. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21346. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  21347. if (prevRow.length === 0) {
  21348. prevRow = new Uint8Array(rowBytes);
  21349. }
  21350. var i, j = bufferLength, up, c;
  21351. switch (predictor) {
  21352. case 0:
  21353. for (i = 0; i < rowBytes; ++i) {
  21354. buffer[j++] = rawBytes[i];
  21355. }
  21356. break;
  21357. case 1:
  21358. for (i = 0; i < pixBytes; ++i) {
  21359. buffer[j++] = rawBytes[i];
  21360. }
  21361. for (; i < rowBytes; ++i) {
  21362. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  21363. j++;
  21364. }
  21365. break;
  21366. case 2:
  21367. for (i = 0; i < rowBytes; ++i) {
  21368. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  21369. }
  21370. break;
  21371. case 3:
  21372. for (i = 0; i < pixBytes; ++i) {
  21373. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  21374. }
  21375. for (; i < rowBytes; ++i) {
  21376. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  21377. rawBytes[i]) & 0xFF;
  21378. j++;
  21379. }
  21380. break;
  21381. case 4:
  21382. // we need to save the up left pixels values. the simplest way
  21383. // is to create a new buffer
  21384. for (i = 0; i < pixBytes; ++i) {
  21385. up = prevRow[i];
  21386. c = rawBytes[i];
  21387. buffer[j++] = up + c;
  21388. }
  21389. for (; i < rowBytes; ++i) {
  21390. up = prevRow[i];
  21391. var upLeft = prevRow[i - pixBytes];
  21392. var left = buffer[j - pixBytes];
  21393. var p = left + up - upLeft;
  21394. var pa = p - left;
  21395. if (pa < 0) {
  21396. pa = -pa;
  21397. }
  21398. var pb = p - up;
  21399. if (pb < 0) {
  21400. pb = -pb;
  21401. }
  21402. var pc = p - upLeft;
  21403. if (pc < 0) {
  21404. pc = -pc;
  21405. }
  21406. c = rawBytes[i];
  21407. if (pa <= pb && pa <= pc) {
  21408. buffer[j++] = left + c;
  21409. } else if (pb <= pc) {
  21410. buffer[j++] = up + c;
  21411. } else {
  21412. buffer[j++] = upLeft + c;
  21413. }
  21414. }
  21415. break;
  21416. default:
  21417. error('Unsupported predictor: ' + predictor);
  21418. }
  21419. this.bufferLength += rowBytes;
  21420. };
  21421. return PredictorStream;
  21422. })();
  21423. /**
  21424. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  21425. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  21426. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  21427. * a library to decode these images and the stream behaves like all the other
  21428. * DecodeStreams.
  21429. */
  21430. var JpegStream = (function JpegStreamClosure() {
  21431. function JpegStream(stream, maybeLength, dict) {
  21432. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  21433. // Note: this seems to mainly affect inline images.
  21434. var ch;
  21435. while ((ch = stream.getByte()) !== -1) {
  21436. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  21437. stream.skip(-1); // Reset the stream position to the SOI.
  21438. break;
  21439. }
  21440. }
  21441. this.stream = stream;
  21442. this.maybeLength = maybeLength;
  21443. this.dict = dict;
  21444. DecodeStream.call(this, maybeLength);
  21445. }
  21446. JpegStream.prototype = Object.create(DecodeStream.prototype);
  21447. Object.defineProperty(JpegStream.prototype, 'bytes', {
  21448. get: function JpegStream_bytes() {
  21449. // If this.maybeLength is null, we'll get the entire stream.
  21450. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21451. },
  21452. configurable: true
  21453. });
  21454. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  21455. if (this.bufferLength) {
  21456. return;
  21457. }
  21458. var jpegImage = new JpegImage();
  21459. // Checking if values need to be transformed before conversion.
  21460. var decodeArr = this.dict.getArray('Decode', 'D');
  21461. if (this.forceRGB && isArray(decodeArr)) {
  21462. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  21463. var decodeArrLength = decodeArr.length;
  21464. var transform = new Int32Array(decodeArrLength);
  21465. var transformNeeded = false;
  21466. var maxValue = (1 << bitsPerComponent) - 1;
  21467. for (var i = 0; i < decodeArrLength; i += 2) {
  21468. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  21469. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  21470. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  21471. transformNeeded = true;
  21472. }
  21473. }
  21474. if (transformNeeded) {
  21475. jpegImage.decodeTransform = transform;
  21476. }
  21477. }
  21478. // Fetching the 'ColorTransform' entry, if it exists.
  21479. var decodeParams = this.dict.get('DecodeParms', 'DP');
  21480. if (isDict(decodeParams)) {
  21481. var colorTransform = decodeParams.get('ColorTransform');
  21482. if (isInt(colorTransform)) {
  21483. jpegImage.colorTransform = colorTransform;
  21484. }
  21485. }
  21486. jpegImage.parse(this.bytes);
  21487. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  21488. this.forceRGB);
  21489. this.buffer = data;
  21490. this.bufferLength = data.length;
  21491. this.eof = true;
  21492. };
  21493. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  21494. this.ensureBuffer();
  21495. return this.buffer;
  21496. };
  21497. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  21498. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  21499. };
  21500. return JpegStream;
  21501. })();
  21502. /**
  21503. * For JPEG 2000's we use a library to decode these images and
  21504. * the stream behaves like all the other DecodeStreams.
  21505. */
  21506. var JpxStream = (function JpxStreamClosure() {
  21507. function JpxStream(stream, maybeLength, dict) {
  21508. this.stream = stream;
  21509. this.maybeLength = maybeLength;
  21510. this.dict = dict;
  21511. DecodeStream.call(this, maybeLength);
  21512. }
  21513. JpxStream.prototype = Object.create(DecodeStream.prototype);
  21514. Object.defineProperty(JpxStream.prototype, 'bytes', {
  21515. get: function JpxStream_bytes() {
  21516. // If this.maybeLength is null, we'll get the entire stream.
  21517. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21518. },
  21519. configurable: true
  21520. });
  21521. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  21522. if (this.bufferLength) {
  21523. return;
  21524. }
  21525. var jpxImage = new JpxImage();
  21526. jpxImage.parse(this.bytes);
  21527. var width = jpxImage.width;
  21528. var height = jpxImage.height;
  21529. var componentsCount = jpxImage.componentsCount;
  21530. var tileCount = jpxImage.tiles.length;
  21531. if (tileCount === 1) {
  21532. this.buffer = jpxImage.tiles[0].items;
  21533. } else {
  21534. var data = new Uint8Array(width * height * componentsCount);
  21535. for (var k = 0; k < tileCount; k++) {
  21536. var tileComponents = jpxImage.tiles[k];
  21537. var tileWidth = tileComponents.width;
  21538. var tileHeight = tileComponents.height;
  21539. var tileLeft = tileComponents.left;
  21540. var tileTop = tileComponents.top;
  21541. var src = tileComponents.items;
  21542. var srcPosition = 0;
  21543. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  21544. var imgRowSize = width * componentsCount;
  21545. var tileRowSize = tileWidth * componentsCount;
  21546. for (var j = 0; j < tileHeight; j++) {
  21547. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  21548. data.set(rowBytes, dataPosition);
  21549. srcPosition += tileRowSize;
  21550. dataPosition += imgRowSize;
  21551. }
  21552. }
  21553. this.buffer = data;
  21554. }
  21555. this.bufferLength = this.buffer.length;
  21556. this.eof = true;
  21557. };
  21558. return JpxStream;
  21559. })();
  21560. /**
  21561. * For JBIG2's we use a library to decode these images and
  21562. * the stream behaves like all the other DecodeStreams.
  21563. */
  21564. var Jbig2Stream = (function Jbig2StreamClosure() {
  21565. function Jbig2Stream(stream, maybeLength, dict) {
  21566. this.stream = stream;
  21567. this.maybeLength = maybeLength;
  21568. this.dict = dict;
  21569. DecodeStream.call(this, maybeLength);
  21570. }
  21571. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  21572. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  21573. get: function Jbig2Stream_bytes() {
  21574. // If this.maybeLength is null, we'll get the entire stream.
  21575. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21576. },
  21577. configurable: true
  21578. });
  21579. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  21580. if (this.bufferLength) {
  21581. return;
  21582. }
  21583. var jbig2Image = new Jbig2Image();
  21584. var chunks = [];
  21585. var decodeParams = this.dict.getArray('DecodeParms', 'DP');
  21586. // According to the PDF specification, DecodeParms can be either
  21587. // a dictionary, or an array whose elements are dictionaries.
  21588. if (isArray(decodeParams)) {
  21589. if (decodeParams.length > 1) {
  21590. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  21591. 'not supported.');
  21592. }
  21593. decodeParams = decodeParams[0];
  21594. }
  21595. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  21596. var globalsStream = decodeParams.get('JBIG2Globals');
  21597. var globals = globalsStream.getBytes();
  21598. chunks.push({data: globals, start: 0, end: globals.length});
  21599. }
  21600. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  21601. var data = jbig2Image.parseChunks(chunks);
  21602. var dataLength = data.length;
  21603. // JBIG2 had black as 1 and white as 0, inverting the colors
  21604. for (var i = 0; i < dataLength; i++) {
  21605. data[i] ^= 0xFF;
  21606. }
  21607. this.buffer = data;
  21608. this.bufferLength = dataLength;
  21609. this.eof = true;
  21610. };
  21611. return Jbig2Stream;
  21612. })();
  21613. var DecryptStream = (function DecryptStreamClosure() {
  21614. function DecryptStream(str, maybeLength, decrypt) {
  21615. this.str = str;
  21616. this.dict = str.dict;
  21617. this.decrypt = decrypt;
  21618. this.nextChunk = null;
  21619. this.initialized = false;
  21620. DecodeStream.call(this, maybeLength);
  21621. }
  21622. var chunkSize = 512;
  21623. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  21624. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  21625. var chunk;
  21626. if (this.initialized) {
  21627. chunk = this.nextChunk;
  21628. } else {
  21629. chunk = this.str.getBytes(chunkSize);
  21630. this.initialized = true;
  21631. }
  21632. if (!chunk || chunk.length === 0) {
  21633. this.eof = true;
  21634. return;
  21635. }
  21636. this.nextChunk = this.str.getBytes(chunkSize);
  21637. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  21638. var decrypt = this.decrypt;
  21639. chunk = decrypt(chunk, !hasMoreData);
  21640. var bufferLength = this.bufferLength;
  21641. var i, n = chunk.length;
  21642. var buffer = this.ensureBuffer(bufferLength + n);
  21643. for (i = 0; i < n; i++) {
  21644. buffer[bufferLength++] = chunk[i];
  21645. }
  21646. this.bufferLength = bufferLength;
  21647. };
  21648. return DecryptStream;
  21649. })();
  21650. var Ascii85Stream = (function Ascii85StreamClosure() {
  21651. function Ascii85Stream(str, maybeLength) {
  21652. this.str = str;
  21653. this.dict = str.dict;
  21654. this.input = new Uint8Array(5);
  21655. // Most streams increase in size when decoded, but Ascii85 streams
  21656. // typically shrink by ~20%.
  21657. if (maybeLength) {
  21658. maybeLength = 0.8 * maybeLength;
  21659. }
  21660. DecodeStream.call(this, maybeLength);
  21661. }
  21662. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  21663. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  21664. var TILDA_CHAR = 0x7E; // '~'
  21665. var Z_LOWER_CHAR = 0x7A; // 'z'
  21666. var EOF = -1;
  21667. var str = this.str;
  21668. var c = str.getByte();
  21669. while (isSpace(c)) {
  21670. c = str.getByte();
  21671. }
  21672. if (c === EOF || c === TILDA_CHAR) {
  21673. this.eof = true;
  21674. return;
  21675. }
  21676. var bufferLength = this.bufferLength, buffer;
  21677. var i;
  21678. // special code for z
  21679. if (c === Z_LOWER_CHAR) {
  21680. buffer = this.ensureBuffer(bufferLength + 4);
  21681. for (i = 0; i < 4; ++i) {
  21682. buffer[bufferLength + i] = 0;
  21683. }
  21684. this.bufferLength += 4;
  21685. } else {
  21686. var input = this.input;
  21687. input[0] = c;
  21688. for (i = 1; i < 5; ++i) {
  21689. c = str.getByte();
  21690. while (isSpace(c)) {
  21691. c = str.getByte();
  21692. }
  21693. input[i] = c;
  21694. if (c === EOF || c === TILDA_CHAR) {
  21695. break;
  21696. }
  21697. }
  21698. buffer = this.ensureBuffer(bufferLength + i - 1);
  21699. this.bufferLength += i - 1;
  21700. // partial ending;
  21701. if (i < 5) {
  21702. for (; i < 5; ++i) {
  21703. input[i] = 0x21 + 84;
  21704. }
  21705. this.eof = true;
  21706. }
  21707. var t = 0;
  21708. for (i = 0; i < 5; ++i) {
  21709. t = t * 85 + (input[i] - 0x21);
  21710. }
  21711. for (i = 3; i >= 0; --i) {
  21712. buffer[bufferLength + i] = t & 0xFF;
  21713. t >>= 8;
  21714. }
  21715. }
  21716. };
  21717. return Ascii85Stream;
  21718. })();
  21719. var AsciiHexStream = (function AsciiHexStreamClosure() {
  21720. function AsciiHexStream(str, maybeLength) {
  21721. this.str = str;
  21722. this.dict = str.dict;
  21723. this.firstDigit = -1;
  21724. // Most streams increase in size when decoded, but AsciiHex streams shrink
  21725. // by 50%.
  21726. if (maybeLength) {
  21727. maybeLength = 0.5 * maybeLength;
  21728. }
  21729. DecodeStream.call(this, maybeLength);
  21730. }
  21731. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  21732. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  21733. var UPSTREAM_BLOCK_SIZE = 8000;
  21734. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  21735. if (!bytes.length) {
  21736. this.eof = true;
  21737. return;
  21738. }
  21739. var maxDecodeLength = (bytes.length + 1) >> 1;
  21740. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  21741. var bufferLength = this.bufferLength;
  21742. var firstDigit = this.firstDigit;
  21743. for (var i = 0, ii = bytes.length; i < ii; i++) {
  21744. var ch = bytes[i], digit;
  21745. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  21746. digit = ch & 0x0F;
  21747. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  21748. // 'A'-'Z', 'a'-'z'
  21749. digit = (ch & 0x0F) + 9;
  21750. } else if (ch === 0x3E) { // '>'
  21751. this.eof = true;
  21752. break;
  21753. } else { // probably whitespace
  21754. continue; // ignoring
  21755. }
  21756. if (firstDigit < 0) {
  21757. firstDigit = digit;
  21758. } else {
  21759. buffer[bufferLength++] = (firstDigit << 4) | digit;
  21760. firstDigit = -1;
  21761. }
  21762. }
  21763. if (firstDigit >= 0 && this.eof) {
  21764. // incomplete byte
  21765. buffer[bufferLength++] = (firstDigit << 4);
  21766. firstDigit = -1;
  21767. }
  21768. this.firstDigit = firstDigit;
  21769. this.bufferLength = bufferLength;
  21770. };
  21771. return AsciiHexStream;
  21772. })();
  21773. var RunLengthStream = (function RunLengthStreamClosure() {
  21774. function RunLengthStream(str, maybeLength) {
  21775. this.str = str;
  21776. this.dict = str.dict;
  21777. DecodeStream.call(this, maybeLength);
  21778. }
  21779. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  21780. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  21781. // The repeatHeader has following format. The first byte defines type of run
  21782. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  21783. // (in addition to the second byte from the header), n = 129 through 255 -
  21784. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  21785. var repeatHeader = this.str.getBytes(2);
  21786. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  21787. this.eof = true;
  21788. return;
  21789. }
  21790. var buffer;
  21791. var bufferLength = this.bufferLength;
  21792. var n = repeatHeader[0];
  21793. if (n < 128) {
  21794. // copy n bytes
  21795. buffer = this.ensureBuffer(bufferLength + n + 1);
  21796. buffer[bufferLength++] = repeatHeader[1];
  21797. if (n > 0) {
  21798. var source = this.str.getBytes(n);
  21799. buffer.set(source, bufferLength);
  21800. bufferLength += n;
  21801. }
  21802. } else {
  21803. n = 257 - n;
  21804. var b = repeatHeader[1];
  21805. buffer = this.ensureBuffer(bufferLength + n + 1);
  21806. for (var i = 0; i < n; i++) {
  21807. buffer[bufferLength++] = b;
  21808. }
  21809. }
  21810. this.bufferLength = bufferLength;
  21811. };
  21812. return RunLengthStream;
  21813. })();
  21814. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  21815. var ccittEOL = -2;
  21816. var ccittEOF = -1;
  21817. var twoDimPass = 0;
  21818. var twoDimHoriz = 1;
  21819. var twoDimVert0 = 2;
  21820. var twoDimVertR1 = 3;
  21821. var twoDimVertL1 = 4;
  21822. var twoDimVertR2 = 5;
  21823. var twoDimVertL2 = 6;
  21824. var twoDimVertR3 = 7;
  21825. var twoDimVertL3 = 8;
  21826. var twoDimTable = [
  21827. [-1, -1], [-1, -1], // 000000x
  21828. [7, twoDimVertL3], // 0000010
  21829. [7, twoDimVertR3], // 0000011
  21830. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  21831. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  21832. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  21833. [4, twoDimPass], [4, twoDimPass],
  21834. [4, twoDimPass], [4, twoDimPass],
  21835. [4, twoDimPass], [4, twoDimPass],
  21836. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  21837. [3, twoDimHoriz], [3, twoDimHoriz],
  21838. [3, twoDimHoriz], [3, twoDimHoriz],
  21839. [3, twoDimHoriz], [3, twoDimHoriz],
  21840. [3, twoDimHoriz], [3, twoDimHoriz],
  21841. [3, twoDimHoriz], [3, twoDimHoriz],
  21842. [3, twoDimHoriz], [3, twoDimHoriz],
  21843. [3, twoDimHoriz], [3, twoDimHoriz],
  21844. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  21845. [3, twoDimVertL1], [3, twoDimVertL1],
  21846. [3, twoDimVertL1], [3, twoDimVertL1],
  21847. [3, twoDimVertL1], [3, twoDimVertL1],
  21848. [3, twoDimVertL1], [3, twoDimVertL1],
  21849. [3, twoDimVertL1], [3, twoDimVertL1],
  21850. [3, twoDimVertL1], [3, twoDimVertL1],
  21851. [3, twoDimVertL1], [3, twoDimVertL1],
  21852. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  21853. [3, twoDimVertR1], [3, twoDimVertR1],
  21854. [3, twoDimVertR1], [3, twoDimVertR1],
  21855. [3, twoDimVertR1], [3, twoDimVertR1],
  21856. [3, twoDimVertR1], [3, twoDimVertR1],
  21857. [3, twoDimVertR1], [3, twoDimVertR1],
  21858. [3, twoDimVertR1], [3, twoDimVertR1],
  21859. [3, twoDimVertR1], [3, twoDimVertR1],
  21860. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  21861. [1, twoDimVert0], [1, twoDimVert0],
  21862. [1, twoDimVert0], [1, twoDimVert0],
  21863. [1, twoDimVert0], [1, twoDimVert0],
  21864. [1, twoDimVert0], [1, twoDimVert0],
  21865. [1, twoDimVert0], [1, twoDimVert0],
  21866. [1, twoDimVert0], [1, twoDimVert0],
  21867. [1, twoDimVert0], [1, twoDimVert0],
  21868. [1, twoDimVert0], [1, twoDimVert0],
  21869. [1, twoDimVert0], [1, twoDimVert0],
  21870. [1, twoDimVert0], [1, twoDimVert0],
  21871. [1, twoDimVert0], [1, twoDimVert0],
  21872. [1, twoDimVert0], [1, twoDimVert0],
  21873. [1, twoDimVert0], [1, twoDimVert0],
  21874. [1, twoDimVert0], [1, twoDimVert0],
  21875. [1, twoDimVert0], [1, twoDimVert0],
  21876. [1, twoDimVert0], [1, twoDimVert0],
  21877. [1, twoDimVert0], [1, twoDimVert0],
  21878. [1, twoDimVert0], [1, twoDimVert0],
  21879. [1, twoDimVert0], [1, twoDimVert0],
  21880. [1, twoDimVert0], [1, twoDimVert0],
  21881. [1, twoDimVert0], [1, twoDimVert0],
  21882. [1, twoDimVert0], [1, twoDimVert0],
  21883. [1, twoDimVert0], [1, twoDimVert0],
  21884. [1, twoDimVert0], [1, twoDimVert0],
  21885. [1, twoDimVert0], [1, twoDimVert0],
  21886. [1, twoDimVert0], [1, twoDimVert0],
  21887. [1, twoDimVert0], [1, twoDimVert0],
  21888. [1, twoDimVert0], [1, twoDimVert0],
  21889. [1, twoDimVert0], [1, twoDimVert0],
  21890. [1, twoDimVert0], [1, twoDimVert0],
  21891. [1, twoDimVert0], [1, twoDimVert0]
  21892. ];
  21893. var whiteTable1 = [
  21894. [-1, -1], // 00000
  21895. [12, ccittEOL], // 00001
  21896. [-1, -1], [-1, -1], // 0001x
  21897. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  21898. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  21899. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  21900. [11, 1792], [11, 1792], // 1000x
  21901. [12, 1984], // 10010
  21902. [12, 2048], // 10011
  21903. [12, 2112], // 10100
  21904. [12, 2176], // 10101
  21905. [12, 2240], // 10110
  21906. [12, 2304], // 10111
  21907. [11, 1856], [11, 1856], // 1100x
  21908. [11, 1920], [11, 1920], // 1101x
  21909. [12, 2368], // 11100
  21910. [12, 2432], // 11101
  21911. [12, 2496], // 11110
  21912. [12, 2560] // 11111
  21913. ];
  21914. var whiteTable2 = [
  21915. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  21916. [8, 29], [8, 29], // 00000010x
  21917. [8, 30], [8, 30], // 00000011x
  21918. [8, 45], [8, 45], // 00000100x
  21919. [8, 46], [8, 46], // 00000101x
  21920. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  21921. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  21922. [8, 47], [8, 47], // 00001010x
  21923. [8, 48], [8, 48], // 00001011x
  21924. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  21925. [6, 13], [6, 13], [6, 13], [6, 13],
  21926. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  21927. [8, 33], [8, 33], // 00010010x
  21928. [8, 34], [8, 34], // 00010011x
  21929. [8, 35], [8, 35], // 00010100x
  21930. [8, 36], [8, 36], // 00010101x
  21931. [8, 37], [8, 37], // 00010110x
  21932. [8, 38], [8, 38], // 00010111x
  21933. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  21934. [8, 31], [8, 31], // 00011010x
  21935. [8, 32], [8, 32], // 00011011x
  21936. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  21937. [6, 1], [6, 1], [6, 1], [6, 1],
  21938. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  21939. [6, 12], [6, 12], [6, 12], [6, 12],
  21940. [8, 53], [8, 53], // 00100100x
  21941. [8, 54], [8, 54], // 00100101x
  21942. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  21943. [8, 39], [8, 39], // 00101000x
  21944. [8, 40], [8, 40], // 00101001x
  21945. [8, 41], [8, 41], // 00101010x
  21946. [8, 42], [8, 42], // 00101011x
  21947. [8, 43], [8, 43], // 00101100x
  21948. [8, 44], [8, 44], // 00101101x
  21949. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  21950. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  21951. [8, 61], [8, 61], // 00110010x
  21952. [8, 62], [8, 62], // 00110011x
  21953. [8, 63], [8, 63], // 00110100x
  21954. [8, 0], [8, 0], // 00110101x
  21955. [8, 320], [8, 320], // 00110110x
  21956. [8, 384], [8, 384], // 00110111x
  21957. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  21958. [5, 10], [5, 10], [5, 10], [5, 10],
  21959. [5, 10], [5, 10], [5, 10], [5, 10],
  21960. [5, 10], [5, 10], [5, 10], [5, 10],
  21961. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  21962. [5, 11], [5, 11], [5, 11], [5, 11],
  21963. [5, 11], [5, 11], [5, 11], [5, 11],
  21964. [5, 11], [5, 11], [5, 11], [5, 11],
  21965. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  21966. [8, 59], [8, 59], // 01001010x
  21967. [8, 60], [8, 60], // 01001011x
  21968. [9, 1472], // 010011000
  21969. [9, 1536], // 010011001
  21970. [9, 1600], // 010011010
  21971. [9, 1728], // 010011011
  21972. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  21973. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  21974. [8, 49], [8, 49], // 01010010x
  21975. [8, 50], [8, 50], // 01010011x
  21976. [8, 51], [8, 51], // 01010100x
  21977. [8, 52], [8, 52], // 01010101x
  21978. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  21979. [8, 55], [8, 55], // 01011000x
  21980. [8, 56], [8, 56], // 01011001x
  21981. [8, 57], [8, 57], // 01011010x
  21982. [8, 58], [8, 58], // 01011011x
  21983. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  21984. [6, 192], [6, 192], [6, 192], [6, 192],
  21985. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  21986. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  21987. [8, 448], [8, 448], // 01100100x
  21988. [8, 512], [8, 512], // 01100101x
  21989. [9, 704], // 011001100
  21990. [9, 768], // 011001101
  21991. [8, 640], [8, 640], // 01100111x
  21992. [8, 576], [8, 576], // 01101000x
  21993. [9, 832], // 011010010
  21994. [9, 896], // 011010011
  21995. [9, 960], // 011010100
  21996. [9, 1024], // 011010101
  21997. [9, 1088], // 011010110
  21998. [9, 1152], // 011010111
  21999. [9, 1216], // 011011000
  22000. [9, 1280], // 011011001
  22001. [9, 1344], // 011011010
  22002. [9, 1408], // 011011011
  22003. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  22004. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  22005. [4, 2], [4, 2], [4, 2], [4, 2],
  22006. [4, 2], [4, 2], [4, 2], [4, 2],
  22007. [4, 2], [4, 2], [4, 2], [4, 2],
  22008. [4, 2], [4, 2], [4, 2], [4, 2],
  22009. [4, 2], [4, 2], [4, 2], [4, 2],
  22010. [4, 2], [4, 2], [4, 2], [4, 2],
  22011. [4, 2], [4, 2], [4, 2], [4, 2],
  22012. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  22013. [4, 3], [4, 3], [4, 3], [4, 3],
  22014. [4, 3], [4, 3], [4, 3], [4, 3],
  22015. [4, 3], [4, 3], [4, 3], [4, 3],
  22016. [4, 3], [4, 3], [4, 3], [4, 3],
  22017. [4, 3], [4, 3], [4, 3], [4, 3],
  22018. [4, 3], [4, 3], [4, 3], [4, 3],
  22019. [4, 3], [4, 3], [4, 3], [4, 3],
  22020. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  22021. [5, 128], [5, 128], [5, 128], [5, 128],
  22022. [5, 128], [5, 128], [5, 128], [5, 128],
  22023. [5, 128], [5, 128], [5, 128], [5, 128],
  22024. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  22025. [5, 8], [5, 8], [5, 8], [5, 8],
  22026. [5, 8], [5, 8], [5, 8], [5, 8],
  22027. [5, 8], [5, 8], [5, 8], [5, 8],
  22028. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  22029. [5, 9], [5, 9], [5, 9], [5, 9],
  22030. [5, 9], [5, 9], [5, 9], [5, 9],
  22031. [5, 9], [5, 9], [5, 9], [5, 9],
  22032. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  22033. [6, 16], [6, 16], [6, 16], [6, 16],
  22034. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  22035. [6, 17], [6, 17], [6, 17], [6, 17],
  22036. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  22037. [4, 4], [4, 4], [4, 4], [4, 4],
  22038. [4, 4], [4, 4], [4, 4], [4, 4],
  22039. [4, 4], [4, 4], [4, 4], [4, 4],
  22040. [4, 4], [4, 4], [4, 4], [4, 4],
  22041. [4, 4], [4, 4], [4, 4], [4, 4],
  22042. [4, 4], [4, 4], [4, 4], [4, 4],
  22043. [4, 4], [4, 4], [4, 4], [4, 4],
  22044. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  22045. [4, 5], [4, 5], [4, 5], [4, 5],
  22046. [4, 5], [4, 5], [4, 5], [4, 5],
  22047. [4, 5], [4, 5], [4, 5], [4, 5],
  22048. [4, 5], [4, 5], [4, 5], [4, 5],
  22049. [4, 5], [4, 5], [4, 5], [4, 5],
  22050. [4, 5], [4, 5], [4, 5], [4, 5],
  22051. [4, 5], [4, 5], [4, 5], [4, 5],
  22052. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  22053. [6, 14], [6, 14], [6, 14], [6, 14],
  22054. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  22055. [6, 15], [6, 15], [6, 15], [6, 15],
  22056. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  22057. [5, 64], [5, 64], [5, 64], [5, 64],
  22058. [5, 64], [5, 64], [5, 64], [5, 64],
  22059. [5, 64], [5, 64], [5, 64], [5, 64],
  22060. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  22061. [4, 6], [4, 6], [4, 6], [4, 6],
  22062. [4, 6], [4, 6], [4, 6], [4, 6],
  22063. [4, 6], [4, 6], [4, 6], [4, 6],
  22064. [4, 6], [4, 6], [4, 6], [4, 6],
  22065. [4, 6], [4, 6], [4, 6], [4, 6],
  22066. [4, 6], [4, 6], [4, 6], [4, 6],
  22067. [4, 6], [4, 6], [4, 6], [4, 6],
  22068. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  22069. [4, 7], [4, 7], [4, 7], [4, 7],
  22070. [4, 7], [4, 7], [4, 7], [4, 7],
  22071. [4, 7], [4, 7], [4, 7], [4, 7],
  22072. [4, 7], [4, 7], [4, 7], [4, 7],
  22073. [4, 7], [4, 7], [4, 7], [4, 7],
  22074. [4, 7], [4, 7], [4, 7], [4, 7],
  22075. [4, 7], [4, 7], [4, 7], [4, 7]
  22076. ];
  22077. var blackTable1 = [
  22078. [-1, -1], [-1, -1], // 000000000000x
  22079. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  22080. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  22081. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  22082. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  22083. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  22084. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  22085. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  22086. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  22087. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  22088. [12, 1984], [12, 1984], // 000000010010x
  22089. [12, 2048], [12, 2048], // 000000010011x
  22090. [12, 2112], [12, 2112], // 000000010100x
  22091. [12, 2176], [12, 2176], // 000000010101x
  22092. [12, 2240], [12, 2240], // 000000010110x
  22093. [12, 2304], [12, 2304], // 000000010111x
  22094. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  22095. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  22096. [12, 2368], [12, 2368], // 000000011100x
  22097. [12, 2432], [12, 2432], // 000000011101x
  22098. [12, 2496], [12, 2496], // 000000011110x
  22099. [12, 2560], [12, 2560], // 000000011111x
  22100. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  22101. [10, 18], [10, 18], [10, 18], [10, 18],
  22102. [12, 52], [12, 52], // 000000100100x
  22103. [13, 640], // 0000001001010
  22104. [13, 704], // 0000001001011
  22105. [13, 768], // 0000001001100
  22106. [13, 832], // 0000001001101
  22107. [12, 55], [12, 55], // 000000100111x
  22108. [12, 56], [12, 56], // 000000101000x
  22109. [13, 1280], // 0000001010010
  22110. [13, 1344], // 0000001010011
  22111. [13, 1408], // 0000001010100
  22112. [13, 1472], // 0000001010101
  22113. [12, 59], [12, 59], // 000000101011x
  22114. [12, 60], [12, 60], // 000000101100x
  22115. [13, 1536], // 0000001011010
  22116. [13, 1600], // 0000001011011
  22117. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  22118. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  22119. [13, 1664], // 0000001100100
  22120. [13, 1728], // 0000001100101
  22121. [12, 320], [12, 320], // 000000110011x
  22122. [12, 384], [12, 384], // 000000110100x
  22123. [12, 448], [12, 448], // 000000110101x
  22124. [13, 512], // 0000001101100
  22125. [13, 576], // 0000001101101
  22126. [12, 53], [12, 53], // 000000110111x
  22127. [12, 54], [12, 54], // 000000111000x
  22128. [13, 896], // 0000001110010
  22129. [13, 960], // 0000001110011
  22130. [13, 1024], // 0000001110100
  22131. [13, 1088], // 0000001110101
  22132. [13, 1152], // 0000001110110
  22133. [13, 1216], // 0000001110111
  22134. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  22135. [10, 64], [10, 64], [10, 64], [10, 64]
  22136. ];
  22137. var blackTable2 = [
  22138. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  22139. [8, 13], [8, 13], [8, 13], [8, 13],
  22140. [8, 13], [8, 13], [8, 13], [8, 13],
  22141. [8, 13], [8, 13], [8, 13], [8, 13],
  22142. [11, 23], [11, 23], // 00000101000x
  22143. [12, 50], // 000001010010
  22144. [12, 51], // 000001010011
  22145. [12, 44], // 000001010100
  22146. [12, 45], // 000001010101
  22147. [12, 46], // 000001010110
  22148. [12, 47], // 000001010111
  22149. [12, 57], // 000001011000
  22150. [12, 58], // 000001011001
  22151. [12, 61], // 000001011010
  22152. [12, 256], // 000001011011
  22153. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  22154. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  22155. [12, 48], // 000001100100
  22156. [12, 49], // 000001100101
  22157. [12, 62], // 000001100110
  22158. [12, 63], // 000001100111
  22159. [12, 30], // 000001101000
  22160. [12, 31], // 000001101001
  22161. [12, 32], // 000001101010
  22162. [12, 33], // 000001101011
  22163. [12, 40], // 000001101100
  22164. [12, 41], // 000001101101
  22165. [11, 22], [11, 22], // 00000110111x
  22166. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  22167. [8, 14], [8, 14], [8, 14], [8, 14],
  22168. [8, 14], [8, 14], [8, 14], [8, 14],
  22169. [8, 14], [8, 14], [8, 14], [8, 14],
  22170. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  22171. [7, 10], [7, 10], [7, 10], [7, 10],
  22172. [7, 10], [7, 10], [7, 10], [7, 10],
  22173. [7, 10], [7, 10], [7, 10], [7, 10],
  22174. [7, 10], [7, 10], [7, 10], [7, 10],
  22175. [7, 10], [7, 10], [7, 10], [7, 10],
  22176. [7, 10], [7, 10], [7, 10], [7, 10],
  22177. [7, 10], [7, 10], [7, 10], [7, 10],
  22178. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  22179. [7, 11], [7, 11], [7, 11], [7, 11],
  22180. [7, 11], [7, 11], [7, 11], [7, 11],
  22181. [7, 11], [7, 11], [7, 11], [7, 11],
  22182. [7, 11], [7, 11], [7, 11], [7, 11],
  22183. [7, 11], [7, 11], [7, 11], [7, 11],
  22184. [7, 11], [7, 11], [7, 11], [7, 11],
  22185. [7, 11], [7, 11], [7, 11], [7, 11],
  22186. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  22187. [9, 15], [9, 15], [9, 15], [9, 15],
  22188. [12, 128], // 000011001000
  22189. [12, 192], // 000011001001
  22190. [12, 26], // 000011001010
  22191. [12, 27], // 000011001011
  22192. [12, 28], // 000011001100
  22193. [12, 29], // 000011001101
  22194. [11, 19], [11, 19], // 00001100111x
  22195. [11, 20], [11, 20], // 00001101000x
  22196. [12, 34], // 000011010010
  22197. [12, 35], // 000011010011
  22198. [12, 36], // 000011010100
  22199. [12, 37], // 000011010101
  22200. [12, 38], // 000011010110
  22201. [12, 39], // 000011010111
  22202. [11, 21], [11, 21], // 00001101100x
  22203. [12, 42], // 000011011010
  22204. [12, 43], // 000011011011
  22205. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  22206. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  22207. [7, 12], [7, 12], [7, 12], [7, 12],
  22208. [7, 12], [7, 12], [7, 12], [7, 12],
  22209. [7, 12], [7, 12], [7, 12], [7, 12],
  22210. [7, 12], [7, 12], [7, 12], [7, 12],
  22211. [7, 12], [7, 12], [7, 12], [7, 12],
  22212. [7, 12], [7, 12], [7, 12], [7, 12],
  22213. [7, 12], [7, 12], [7, 12], [7, 12]
  22214. ];
  22215. var blackTable3 = [
  22216. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  22217. [6, 9], // 000100
  22218. [6, 8], // 000101
  22219. [5, 7], [5, 7], // 00011x
  22220. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  22221. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  22222. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  22223. [3, 1], [3, 1], [3, 1], [3, 1],
  22224. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  22225. [3, 4], [3, 4], [3, 4], [3, 4],
  22226. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  22227. [2, 3], [2, 3], [2, 3], [2, 3],
  22228. [2, 3], [2, 3], [2, 3], [2, 3],
  22229. [2, 3], [2, 3], [2, 3], [2, 3],
  22230. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  22231. [2, 2], [2, 2], [2, 2], [2, 2],
  22232. [2, 2], [2, 2], [2, 2], [2, 2],
  22233. [2, 2], [2, 2], [2, 2], [2, 2]
  22234. ];
  22235. function CCITTFaxStream(str, maybeLength, params) {
  22236. this.str = str;
  22237. this.dict = str.dict;
  22238. params = params || Dict.empty;
  22239. this.encoding = params.get('K') || 0;
  22240. this.eoline = params.get('EndOfLine') || false;
  22241. this.byteAlign = params.get('EncodedByteAlign') || false;
  22242. this.columns = params.get('Columns') || 1728;
  22243. this.rows = params.get('Rows') || 0;
  22244. var eoblock = params.get('EndOfBlock');
  22245. if (eoblock === null || eoblock === undefined) {
  22246. eoblock = true;
  22247. }
  22248. this.eoblock = eoblock;
  22249. this.black = params.get('BlackIs1') || false;
  22250. this.codingLine = new Uint32Array(this.columns + 1);
  22251. this.refLine = new Uint32Array(this.columns + 2);
  22252. this.codingLine[0] = this.columns;
  22253. this.codingPos = 0;
  22254. this.row = 0;
  22255. this.nextLine2D = this.encoding < 0;
  22256. this.inputBits = 0;
  22257. this.inputBuf = 0;
  22258. this.outputBits = 0;
  22259. var code1;
  22260. while ((code1 = this.lookBits(12)) === 0) {
  22261. this.eatBits(1);
  22262. }
  22263. if (code1 === 1) {
  22264. this.eatBits(12);
  22265. }
  22266. if (this.encoding > 0) {
  22267. this.nextLine2D = !this.lookBits(1);
  22268. this.eatBits(1);
  22269. }
  22270. DecodeStream.call(this, maybeLength);
  22271. }
  22272. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  22273. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  22274. while (!this.eof) {
  22275. var c = this.lookChar();
  22276. this.ensureBuffer(this.bufferLength + 1);
  22277. this.buffer[this.bufferLength++] = c;
  22278. }
  22279. };
  22280. CCITTFaxStream.prototype.addPixels =
  22281. function ccittFaxStreamAddPixels(a1, blackPixels) {
  22282. var codingLine = this.codingLine;
  22283. var codingPos = this.codingPos;
  22284. if (a1 > codingLine[codingPos]) {
  22285. if (a1 > this.columns) {
  22286. info('row is wrong length');
  22287. this.err = true;
  22288. a1 = this.columns;
  22289. }
  22290. if ((codingPos & 1) ^ blackPixels) {
  22291. ++codingPos;
  22292. }
  22293. codingLine[codingPos] = a1;
  22294. }
  22295. this.codingPos = codingPos;
  22296. };
  22297. CCITTFaxStream.prototype.addPixelsNeg =
  22298. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  22299. var codingLine = this.codingLine;
  22300. var codingPos = this.codingPos;
  22301. if (a1 > codingLine[codingPos]) {
  22302. if (a1 > this.columns) {
  22303. info('row is wrong length');
  22304. this.err = true;
  22305. a1 = this.columns;
  22306. }
  22307. if ((codingPos & 1) ^ blackPixels) {
  22308. ++codingPos;
  22309. }
  22310. codingLine[codingPos] = a1;
  22311. } else if (a1 < codingLine[codingPos]) {
  22312. if (a1 < 0) {
  22313. info('invalid code');
  22314. this.err = true;
  22315. a1 = 0;
  22316. }
  22317. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  22318. --codingPos;
  22319. }
  22320. codingLine[codingPos] = a1;
  22321. }
  22322. this.codingPos = codingPos;
  22323. };
  22324. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  22325. var refLine = this.refLine;
  22326. var codingLine = this.codingLine;
  22327. var columns = this.columns;
  22328. var refPos, blackPixels, bits, i;
  22329. if (this.outputBits === 0) {
  22330. if (this.eof) {
  22331. return null;
  22332. }
  22333. this.err = false;
  22334. var code1, code2, code3;
  22335. if (this.nextLine2D) {
  22336. for (i = 0; codingLine[i] < columns; ++i) {
  22337. refLine[i] = codingLine[i];
  22338. }
  22339. refLine[i++] = columns;
  22340. refLine[i] = columns;
  22341. codingLine[0] = 0;
  22342. this.codingPos = 0;
  22343. refPos = 0;
  22344. blackPixels = 0;
  22345. while (codingLine[this.codingPos] < columns) {
  22346. code1 = this.getTwoDimCode();
  22347. switch (code1) {
  22348. case twoDimPass:
  22349. this.addPixels(refLine[refPos + 1], blackPixels);
  22350. if (refLine[refPos + 1] < columns) {
  22351. refPos += 2;
  22352. }
  22353. break;
  22354. case twoDimHoriz:
  22355. code1 = code2 = 0;
  22356. if (blackPixels) {
  22357. do {
  22358. code1 += (code3 = this.getBlackCode());
  22359. } while (code3 >= 64);
  22360. do {
  22361. code2 += (code3 = this.getWhiteCode());
  22362. } while (code3 >= 64);
  22363. } else {
  22364. do {
  22365. code1 += (code3 = this.getWhiteCode());
  22366. } while (code3 >= 64);
  22367. do {
  22368. code2 += (code3 = this.getBlackCode());
  22369. } while (code3 >= 64);
  22370. }
  22371. this.addPixels(codingLine[this.codingPos] +
  22372. code1, blackPixels);
  22373. if (codingLine[this.codingPos] < columns) {
  22374. this.addPixels(codingLine[this.codingPos] + code2,
  22375. blackPixels ^ 1);
  22376. }
  22377. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22378. refLine[refPos] < columns) {
  22379. refPos += 2;
  22380. }
  22381. break;
  22382. case twoDimVertR3:
  22383. this.addPixels(refLine[refPos] + 3, 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 twoDimVertR2:
  22394. this.addPixels(refLine[refPos] + 2, blackPixels);
  22395. blackPixels ^= 1;
  22396. if (codingLine[this.codingPos] < columns) {
  22397. ++refPos;
  22398. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22399. refLine[refPos] < columns) {
  22400. refPos += 2;
  22401. }
  22402. }
  22403. break;
  22404. case twoDimVertR1:
  22405. this.addPixels(refLine[refPos] + 1, blackPixels);
  22406. blackPixels ^= 1;
  22407. if (codingLine[this.codingPos] < columns) {
  22408. ++refPos;
  22409. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22410. refLine[refPos] < columns) {
  22411. refPos += 2;
  22412. }
  22413. }
  22414. break;
  22415. case twoDimVert0:
  22416. this.addPixels(refLine[refPos], blackPixels);
  22417. blackPixels ^= 1;
  22418. if (codingLine[this.codingPos] < columns) {
  22419. ++refPos;
  22420. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22421. refLine[refPos] < columns) {
  22422. refPos += 2;
  22423. }
  22424. }
  22425. break;
  22426. case twoDimVertL3:
  22427. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  22428. blackPixels ^= 1;
  22429. if (codingLine[this.codingPos] < columns) {
  22430. if (refPos > 0) {
  22431. --refPos;
  22432. } else {
  22433. ++refPos;
  22434. }
  22435. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22436. refLine[refPos] < columns) {
  22437. refPos += 2;
  22438. }
  22439. }
  22440. break;
  22441. case twoDimVertL2:
  22442. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  22443. blackPixels ^= 1;
  22444. if (codingLine[this.codingPos] < columns) {
  22445. if (refPos > 0) {
  22446. --refPos;
  22447. } else {
  22448. ++refPos;
  22449. }
  22450. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22451. refLine[refPos] < columns) {
  22452. refPos += 2;
  22453. }
  22454. }
  22455. break;
  22456. case twoDimVertL1:
  22457. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  22458. blackPixels ^= 1;
  22459. if (codingLine[this.codingPos] < columns) {
  22460. if (refPos > 0) {
  22461. --refPos;
  22462. } else {
  22463. ++refPos;
  22464. }
  22465. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22466. refLine[refPos] < columns) {
  22467. refPos += 2;
  22468. }
  22469. }
  22470. break;
  22471. case ccittEOF:
  22472. this.addPixels(columns, 0);
  22473. this.eof = true;
  22474. break;
  22475. default:
  22476. info('bad 2d code');
  22477. this.addPixels(columns, 0);
  22478. this.err = true;
  22479. }
  22480. }
  22481. } else {
  22482. codingLine[0] = 0;
  22483. this.codingPos = 0;
  22484. blackPixels = 0;
  22485. while (codingLine[this.codingPos] < columns) {
  22486. code1 = 0;
  22487. if (blackPixels) {
  22488. do {
  22489. code1 += (code3 = this.getBlackCode());
  22490. } while (code3 >= 64);
  22491. } else {
  22492. do {
  22493. code1 += (code3 = this.getWhiteCode());
  22494. } while (code3 >= 64);
  22495. }
  22496. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  22497. blackPixels ^= 1;
  22498. }
  22499. }
  22500. var gotEOL = false;
  22501. if (this.byteAlign) {
  22502. this.inputBits &= ~7;
  22503. }
  22504. if (!this.eoblock && this.row === this.rows - 1) {
  22505. this.eof = true;
  22506. } else {
  22507. code1 = this.lookBits(12);
  22508. if (this.eoline) {
  22509. while (code1 !== ccittEOF && code1 !== 1) {
  22510. this.eatBits(1);
  22511. code1 = this.lookBits(12);
  22512. }
  22513. } else {
  22514. while (code1 === 0) {
  22515. this.eatBits(1);
  22516. code1 = this.lookBits(12);
  22517. }
  22518. }
  22519. if (code1 === 1) {
  22520. this.eatBits(12);
  22521. gotEOL = true;
  22522. } else if (code1 === ccittEOF) {
  22523. this.eof = true;
  22524. }
  22525. }
  22526. if (!this.eof && this.encoding > 0) {
  22527. this.nextLine2D = !this.lookBits(1);
  22528. this.eatBits(1);
  22529. }
  22530. if (this.eoblock && gotEOL && this.byteAlign) {
  22531. code1 = this.lookBits(12);
  22532. if (code1 === 1) {
  22533. this.eatBits(12);
  22534. if (this.encoding > 0) {
  22535. this.lookBits(1);
  22536. this.eatBits(1);
  22537. }
  22538. if (this.encoding >= 0) {
  22539. for (i = 0; i < 4; ++i) {
  22540. code1 = this.lookBits(12);
  22541. if (code1 !== 1) {
  22542. info('bad rtc code: ' + code1);
  22543. }
  22544. this.eatBits(12);
  22545. if (this.encoding > 0) {
  22546. this.lookBits(1);
  22547. this.eatBits(1);
  22548. }
  22549. }
  22550. }
  22551. this.eof = true;
  22552. }
  22553. } else if (this.err && this.eoline) {
  22554. while (true) {
  22555. code1 = this.lookBits(13);
  22556. if (code1 === ccittEOF) {
  22557. this.eof = true;
  22558. return null;
  22559. }
  22560. if ((code1 >> 1) === 1) {
  22561. break;
  22562. }
  22563. this.eatBits(1);
  22564. }
  22565. this.eatBits(12);
  22566. if (this.encoding > 0) {
  22567. this.eatBits(1);
  22568. this.nextLine2D = !(code1 & 1);
  22569. }
  22570. }
  22571. if (codingLine[0] > 0) {
  22572. this.outputBits = codingLine[this.codingPos = 0];
  22573. } else {
  22574. this.outputBits = codingLine[this.codingPos = 1];
  22575. }
  22576. this.row++;
  22577. }
  22578. var c;
  22579. if (this.outputBits >= 8) {
  22580. c = (this.codingPos & 1) ? 0 : 0xFF;
  22581. this.outputBits -= 8;
  22582. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  22583. this.codingPos++;
  22584. this.outputBits = (codingLine[this.codingPos] -
  22585. codingLine[this.codingPos - 1]);
  22586. }
  22587. } else {
  22588. bits = 8;
  22589. c = 0;
  22590. do {
  22591. if (this.outputBits > bits) {
  22592. c <<= bits;
  22593. if (!(this.codingPos & 1)) {
  22594. c |= 0xFF >> (8 - bits);
  22595. }
  22596. this.outputBits -= bits;
  22597. bits = 0;
  22598. } else {
  22599. c <<= this.outputBits;
  22600. if (!(this.codingPos & 1)) {
  22601. c |= 0xFF >> (8 - this.outputBits);
  22602. }
  22603. bits -= this.outputBits;
  22604. this.outputBits = 0;
  22605. if (codingLine[this.codingPos] < columns) {
  22606. this.codingPos++;
  22607. this.outputBits = (codingLine[this.codingPos] -
  22608. codingLine[this.codingPos - 1]);
  22609. } else if (bits > 0) {
  22610. c <<= bits;
  22611. bits = 0;
  22612. }
  22613. }
  22614. } while (bits);
  22615. }
  22616. if (this.black) {
  22617. c ^= 0xFF;
  22618. }
  22619. return c;
  22620. };
  22621. // This functions returns the code found from the table.
  22622. // The start and end parameters set the boundaries for searching the table.
  22623. // The limit parameter is optional. Function returns an array with three
  22624. // values. The first array element indicates whether a valid code is being
  22625. // returned. The second array element is the actual code. The third array
  22626. // element indicates whether EOF was reached.
  22627. CCITTFaxStream.prototype.findTableCode =
  22628. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  22629. var limitValue = limit || 0;
  22630. for (var i = start; i <= end; ++i) {
  22631. var code = this.lookBits(i);
  22632. if (code === ccittEOF) {
  22633. return [true, 1, false];
  22634. }
  22635. if (i < end) {
  22636. code <<= end - i;
  22637. }
  22638. if (!limitValue || code >= limitValue) {
  22639. var p = table[code - limitValue];
  22640. if (p[0] === i) {
  22641. this.eatBits(i);
  22642. return [true, p[1], true];
  22643. }
  22644. }
  22645. }
  22646. return [false, 0, false];
  22647. };
  22648. CCITTFaxStream.prototype.getTwoDimCode =
  22649. function ccittFaxStreamGetTwoDimCode() {
  22650. var code = 0;
  22651. var p;
  22652. if (this.eoblock) {
  22653. code = this.lookBits(7);
  22654. p = twoDimTable[code];
  22655. if (p && p[0] > 0) {
  22656. this.eatBits(p[0]);
  22657. return p[1];
  22658. }
  22659. } else {
  22660. var result = this.findTableCode(1, 7, twoDimTable);
  22661. if (result[0] && result[2]) {
  22662. return result[1];
  22663. }
  22664. }
  22665. info('Bad two dim code');
  22666. return ccittEOF;
  22667. };
  22668. CCITTFaxStream.prototype.getWhiteCode =
  22669. function ccittFaxStreamGetWhiteCode() {
  22670. var code = 0;
  22671. var p;
  22672. if (this.eoblock) {
  22673. code = this.lookBits(12);
  22674. if (code === ccittEOF) {
  22675. return 1;
  22676. }
  22677. if ((code >> 5) === 0) {
  22678. p = whiteTable1[code];
  22679. } else {
  22680. p = whiteTable2[code >> 3];
  22681. }
  22682. if (p[0] > 0) {
  22683. this.eatBits(p[0]);
  22684. return p[1];
  22685. }
  22686. } else {
  22687. var result = this.findTableCode(1, 9, whiteTable2);
  22688. if (result[0]) {
  22689. return result[1];
  22690. }
  22691. result = this.findTableCode(11, 12, whiteTable1);
  22692. if (result[0]) {
  22693. return result[1];
  22694. }
  22695. }
  22696. info('bad white code');
  22697. this.eatBits(1);
  22698. return 1;
  22699. };
  22700. CCITTFaxStream.prototype.getBlackCode =
  22701. function ccittFaxStreamGetBlackCode() {
  22702. var code, p;
  22703. if (this.eoblock) {
  22704. code = this.lookBits(13);
  22705. if (code === ccittEOF) {
  22706. return 1;
  22707. }
  22708. if ((code >> 7) === 0) {
  22709. p = blackTable1[code];
  22710. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  22711. p = blackTable2[(code >> 1) - 64];
  22712. } else {
  22713. p = blackTable3[code >> 7];
  22714. }
  22715. if (p[0] > 0) {
  22716. this.eatBits(p[0]);
  22717. return p[1];
  22718. }
  22719. } else {
  22720. var result = this.findTableCode(2, 6, blackTable3);
  22721. if (result[0]) {
  22722. return result[1];
  22723. }
  22724. result = this.findTableCode(7, 12, blackTable2, 64);
  22725. if (result[0]) {
  22726. return result[1];
  22727. }
  22728. result = this.findTableCode(10, 13, blackTable1);
  22729. if (result[0]) {
  22730. return result[1];
  22731. }
  22732. }
  22733. info('bad black code');
  22734. this.eatBits(1);
  22735. return 1;
  22736. };
  22737. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  22738. var c;
  22739. while (this.inputBits < n) {
  22740. if ((c = this.str.getByte()) === -1) {
  22741. if (this.inputBits === 0) {
  22742. return ccittEOF;
  22743. }
  22744. return ((this.inputBuf << (n - this.inputBits)) &
  22745. (0xFFFF >> (16 - n)));
  22746. }
  22747. this.inputBuf = (this.inputBuf << 8) | c;
  22748. this.inputBits += 8;
  22749. }
  22750. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  22751. };
  22752. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  22753. if ((this.inputBits -= n) < 0) {
  22754. this.inputBits = 0;
  22755. }
  22756. };
  22757. return CCITTFaxStream;
  22758. })();
  22759. var LZWStream = (function LZWStreamClosure() {
  22760. function LZWStream(str, maybeLength, earlyChange) {
  22761. this.str = str;
  22762. this.dict = str.dict;
  22763. this.cachedData = 0;
  22764. this.bitsCached = 0;
  22765. var maxLzwDictionarySize = 4096;
  22766. var lzwState = {
  22767. earlyChange: earlyChange,
  22768. codeLength: 9,
  22769. nextCode: 258,
  22770. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  22771. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  22772. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  22773. currentSequence: new Uint8Array(maxLzwDictionarySize),
  22774. currentSequenceLength: 0
  22775. };
  22776. for (var i = 0; i < 256; ++i) {
  22777. lzwState.dictionaryValues[i] = i;
  22778. lzwState.dictionaryLengths[i] = 1;
  22779. }
  22780. this.lzwState = lzwState;
  22781. DecodeStream.call(this, maybeLength);
  22782. }
  22783. LZWStream.prototype = Object.create(DecodeStream.prototype);
  22784. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  22785. var bitsCached = this.bitsCached;
  22786. var cachedData = this.cachedData;
  22787. while (bitsCached < n) {
  22788. var c = this.str.getByte();
  22789. if (c === -1) {
  22790. this.eof = true;
  22791. return null;
  22792. }
  22793. cachedData = (cachedData << 8) | c;
  22794. bitsCached += 8;
  22795. }
  22796. this.bitsCached = (bitsCached -= n);
  22797. this.cachedData = cachedData;
  22798. this.lastCode = null;
  22799. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  22800. };
  22801. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  22802. var blockSize = 512;
  22803. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  22804. var i, j, q;
  22805. var lzwState = this.lzwState;
  22806. if (!lzwState) {
  22807. return; // eof was found
  22808. }
  22809. var earlyChange = lzwState.earlyChange;
  22810. var nextCode = lzwState.nextCode;
  22811. var dictionaryValues = lzwState.dictionaryValues;
  22812. var dictionaryLengths = lzwState.dictionaryLengths;
  22813. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  22814. var codeLength = lzwState.codeLength;
  22815. var prevCode = lzwState.prevCode;
  22816. var currentSequence = lzwState.currentSequence;
  22817. var currentSequenceLength = lzwState.currentSequenceLength;
  22818. var decodedLength = 0;
  22819. var currentBufferLength = this.bufferLength;
  22820. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22821. for (i = 0; i < blockSize; i++) {
  22822. var code = this.readBits(codeLength);
  22823. var hasPrev = currentSequenceLength > 0;
  22824. if (code < 256) {
  22825. currentSequence[0] = code;
  22826. currentSequenceLength = 1;
  22827. } else if (code >= 258) {
  22828. if (code < nextCode) {
  22829. currentSequenceLength = dictionaryLengths[code];
  22830. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  22831. currentSequence[j] = dictionaryValues[q];
  22832. q = dictionaryPrevCodes[q];
  22833. }
  22834. } else {
  22835. currentSequence[currentSequenceLength++] = currentSequence[0];
  22836. }
  22837. } else if (code === 256) {
  22838. codeLength = 9;
  22839. nextCode = 258;
  22840. currentSequenceLength = 0;
  22841. continue;
  22842. } else {
  22843. this.eof = true;
  22844. delete this.lzwState;
  22845. break;
  22846. }
  22847. if (hasPrev) {
  22848. dictionaryPrevCodes[nextCode] = prevCode;
  22849. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  22850. dictionaryValues[nextCode] = currentSequence[0];
  22851. nextCode++;
  22852. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  22853. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  22854. 0.6931471805599453 + 1, 12) | 0;
  22855. }
  22856. prevCode = code;
  22857. decodedLength += currentSequenceLength;
  22858. if (estimatedDecodedSize < decodedLength) {
  22859. do {
  22860. estimatedDecodedSize += decodedSizeDelta;
  22861. } while (estimatedDecodedSize < decodedLength);
  22862. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22863. }
  22864. for (j = 0; j < currentSequenceLength; j++) {
  22865. buffer[currentBufferLength++] = currentSequence[j];
  22866. }
  22867. }
  22868. lzwState.nextCode = nextCode;
  22869. lzwState.codeLength = codeLength;
  22870. lzwState.prevCode = prevCode;
  22871. lzwState.currentSequenceLength = currentSequenceLength;
  22872. this.bufferLength = currentBufferLength;
  22873. };
  22874. return LZWStream;
  22875. })();
  22876. var NullStream = (function NullStreamClosure() {
  22877. function NullStream() {
  22878. Stream.call(this, new Uint8Array(0));
  22879. }
  22880. NullStream.prototype = Stream.prototype;
  22881. return NullStream;
  22882. })();
  22883. exports.Ascii85Stream = Ascii85Stream;
  22884. exports.AsciiHexStream = AsciiHexStream;
  22885. exports.CCITTFaxStream = CCITTFaxStream;
  22886. exports.DecryptStream = DecryptStream;
  22887. exports.DecodeStream = DecodeStream;
  22888. exports.FlateStream = FlateStream;
  22889. exports.Jbig2Stream = Jbig2Stream;
  22890. exports.JpegStream = JpegStream;
  22891. exports.JpxStream = JpxStream;
  22892. exports.NullStream = NullStream;
  22893. exports.PredictorStream = PredictorStream;
  22894. exports.RunLengthStream = RunLengthStream;
  22895. exports.Stream = Stream;
  22896. exports.StreamsSequenceStream = StreamsSequenceStream;
  22897. exports.StringStream = StringStream;
  22898. exports.LZWStream = LZWStream;
  22899. }));
  22900. (function (root, factory) {
  22901. {
  22902. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  22903. root.pdfjsDisplayDOMUtils);
  22904. }
  22905. }(this, function (exports, sharedUtil, displayDOMUtils) {
  22906. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  22907. var AnnotationType = sharedUtil.AnnotationType;
  22908. var Util = sharedUtil.Util;
  22909. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  22910. var LinkTarget = displayDOMUtils.LinkTarget;
  22911. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  22912. var warn = sharedUtil.warn;
  22913. var CustomStyle = displayDOMUtils.CustomStyle;
  22914. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  22915. /**
  22916. * @typedef {Object} AnnotationElementParameters
  22917. * @property {Object} data
  22918. * @property {HTMLDivElement} layer
  22919. * @property {PDFPage} page
  22920. * @property {PageViewport} viewport
  22921. * @property {IPDFLinkService} linkService
  22922. * @property {DownloadManager} downloadManager
  22923. * @property {string} imageResourcesPath
  22924. * @property {boolean} renderInteractiveForms
  22925. */
  22926. /**
  22927. * @class
  22928. * @alias AnnotationElementFactory
  22929. */
  22930. function AnnotationElementFactory() {}
  22931. AnnotationElementFactory.prototype =
  22932. /** @lends AnnotationElementFactory.prototype */ {
  22933. /**
  22934. * @param {AnnotationElementParameters} parameters
  22935. * @returns {AnnotationElement}
  22936. */
  22937. create: function AnnotationElementFactory_create(parameters) {
  22938. var subtype = parameters.data.annotationType;
  22939. switch (subtype) {
  22940. case AnnotationType.LINK:
  22941. return new LinkAnnotationElement(parameters);
  22942. case AnnotationType.TEXT:
  22943. return new TextAnnotationElement(parameters);
  22944. case AnnotationType.WIDGET:
  22945. var fieldType = parameters.data.fieldType;
  22946. switch (fieldType) {
  22947. case 'Tx':
  22948. return new TextWidgetAnnotationElement(parameters);
  22949. case 'Ch':
  22950. return new ChoiceWidgetAnnotationElement(parameters);
  22951. }
  22952. return new WidgetAnnotationElement(parameters);
  22953. case AnnotationType.POPUP:
  22954. return new PopupAnnotationElement(parameters);
  22955. case AnnotationType.HIGHLIGHT:
  22956. return new HighlightAnnotationElement(parameters);
  22957. case AnnotationType.UNDERLINE:
  22958. return new UnderlineAnnotationElement(parameters);
  22959. case AnnotationType.SQUIGGLY:
  22960. return new SquigglyAnnotationElement(parameters);
  22961. case AnnotationType.STRIKEOUT:
  22962. return new StrikeOutAnnotationElement(parameters);
  22963. case AnnotationType.FILEATTACHMENT:
  22964. return new FileAttachmentAnnotationElement(parameters);
  22965. default:
  22966. return new AnnotationElement(parameters);
  22967. }
  22968. }
  22969. };
  22970. /**
  22971. * @class
  22972. * @alias AnnotationElement
  22973. */
  22974. var AnnotationElement = (function AnnotationElementClosure() {
  22975. function AnnotationElement(parameters, isRenderable) {
  22976. this.isRenderable = isRenderable || false;
  22977. this.data = parameters.data;
  22978. this.layer = parameters.layer;
  22979. this.page = parameters.page;
  22980. this.viewport = parameters.viewport;
  22981. this.linkService = parameters.linkService;
  22982. this.downloadManager = parameters.downloadManager;
  22983. this.imageResourcesPath = parameters.imageResourcesPath;
  22984. this.renderInteractiveForms = parameters.renderInteractiveForms;
  22985. if (isRenderable) {
  22986. this.container = this._createContainer();
  22987. }
  22988. }
  22989. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  22990. /**
  22991. * Create an empty container for the annotation's HTML element.
  22992. *
  22993. * @private
  22994. * @memberof AnnotationElement
  22995. * @returns {HTMLSectionElement}
  22996. */
  22997. _createContainer: function AnnotationElement_createContainer() {
  22998. var data = this.data, page = this.page, viewport = this.viewport;
  22999. var container = document.createElement('section');
  23000. var width = data.rect[2] - data.rect[0];
  23001. var height = data.rect[3] - data.rect[1];
  23002. container.setAttribute('data-annotation-id', data.id);
  23003. // Do *not* modify `data.rect`, since that will corrupt the annotation
  23004. // position on subsequent calls to `_createContainer` (see issue 6804).
  23005. var rect = Util.normalizeRect([
  23006. data.rect[0],
  23007. page.view[3] - data.rect[1] + page.view[1],
  23008. data.rect[2],
  23009. page.view[3] - data.rect[3] + page.view[1]
  23010. ]);
  23011. CustomStyle.setProp('transform', container,
  23012. 'matrix(' + viewport.transform.join(',') + ')');
  23013. CustomStyle.setProp('transformOrigin', container,
  23014. -rect[0] + 'px ' + -rect[1] + 'px');
  23015. if (data.borderStyle.width > 0) {
  23016. container.style.borderWidth = data.borderStyle.width + 'px';
  23017. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  23018. // Underline styles only have a bottom border, so we do not need
  23019. // to adjust for all borders. This yields a similar result as
  23020. // Adobe Acrobat/Reader.
  23021. width = width - 2 * data.borderStyle.width;
  23022. height = height - 2 * data.borderStyle.width;
  23023. }
  23024. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  23025. var verticalRadius = data.borderStyle.verticalCornerRadius;
  23026. if (horizontalRadius > 0 || verticalRadius > 0) {
  23027. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  23028. CustomStyle.setProp('borderRadius', container, radius);
  23029. }
  23030. switch (data.borderStyle.style) {
  23031. case AnnotationBorderStyleType.SOLID:
  23032. container.style.borderStyle = 'solid';
  23033. break;
  23034. case AnnotationBorderStyleType.DASHED:
  23035. container.style.borderStyle = 'dashed';
  23036. break;
  23037. case AnnotationBorderStyleType.BEVELED:
  23038. warn('Unimplemented border style: beveled');
  23039. break;
  23040. case AnnotationBorderStyleType.INSET:
  23041. warn('Unimplemented border style: inset');
  23042. break;
  23043. case AnnotationBorderStyleType.UNDERLINE:
  23044. container.style.borderBottomStyle = 'solid';
  23045. break;
  23046. default:
  23047. break;
  23048. }
  23049. if (data.color) {
  23050. container.style.borderColor =
  23051. Util.makeCssRgb(data.color[0] | 0,
  23052. data.color[1] | 0,
  23053. data.color[2] | 0);
  23054. } else {
  23055. // Transparent (invisible) border, so do not draw it at all.
  23056. container.style.borderWidth = 0;
  23057. }
  23058. }
  23059. container.style.left = rect[0] + 'px';
  23060. container.style.top = rect[1] + 'px';
  23061. container.style.width = width + 'px';
  23062. container.style.height = height + 'px';
  23063. return container;
  23064. },
  23065. /**
  23066. * Create a popup for the annotation's HTML element. This is used for
  23067. * annotations that do not have a Popup entry in the dictionary, but
  23068. * are of a type that works with popups (such as Highlight annotations).
  23069. *
  23070. * @private
  23071. * @param {HTMLSectionElement} container
  23072. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  23073. * @param {Object} data
  23074. * @memberof AnnotationElement
  23075. */
  23076. _createPopup:
  23077. function AnnotationElement_createPopup(container, trigger, data) {
  23078. // If no trigger element is specified, create it.
  23079. if (!trigger) {
  23080. trigger = document.createElement('div');
  23081. trigger.style.height = container.style.height;
  23082. trigger.style.width = container.style.width;
  23083. container.appendChild(trigger);
  23084. }
  23085. var popupElement = new PopupElement({
  23086. container: container,
  23087. trigger: trigger,
  23088. color: data.color,
  23089. title: data.title,
  23090. contents: data.contents,
  23091. hideWrapper: true
  23092. });
  23093. var popup = popupElement.render();
  23094. // Position the popup next to the annotation's container.
  23095. popup.style.left = container.style.width;
  23096. container.appendChild(popup);
  23097. },
  23098. /**
  23099. * Render the annotation's HTML element in the empty container.
  23100. *
  23101. * @public
  23102. * @memberof AnnotationElement
  23103. */
  23104. render: function AnnotationElement_render() {
  23105. throw new Error('Abstract method AnnotationElement.render called');
  23106. }
  23107. };
  23108. return AnnotationElement;
  23109. })();
  23110. /**
  23111. * @class
  23112. * @alias LinkAnnotationElement
  23113. */
  23114. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  23115. function LinkAnnotationElement(parameters) {
  23116. AnnotationElement.call(this, parameters, true);
  23117. }
  23118. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  23119. /**
  23120. * Render the link annotation's HTML element in the empty container.
  23121. *
  23122. * @public
  23123. * @memberof LinkAnnotationElement
  23124. * @returns {HTMLSectionElement}
  23125. */
  23126. render: function LinkAnnotationElement_render() {
  23127. this.container.className = 'linkAnnotation';
  23128. var link = document.createElement('a');
  23129. addLinkAttributes(link, {
  23130. url: this.data.url,
  23131. target: (this.data.newWindow ? LinkTarget.BLANK : undefined),
  23132. });
  23133. if (!this.data.url) {
  23134. if (this.data.action) {
  23135. this._bindNamedAction(link, this.data.action);
  23136. } else {
  23137. this._bindLink(link, (this.data.dest || null));
  23138. }
  23139. }
  23140. this.container.appendChild(link);
  23141. return this.container;
  23142. },
  23143. /**
  23144. * Bind internal links to the link element.
  23145. *
  23146. * @private
  23147. * @param {Object} link
  23148. * @param {Object} destination
  23149. * @memberof LinkAnnotationElement
  23150. */
  23151. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  23152. var self = this;
  23153. link.href = this.linkService.getDestinationHash(destination);
  23154. link.onclick = function() {
  23155. if (destination) {
  23156. self.linkService.navigateTo(destination);
  23157. }
  23158. return false;
  23159. };
  23160. if (destination) {
  23161. link.className = 'internalLink';
  23162. }
  23163. },
  23164. /**
  23165. * Bind named actions to the link element.
  23166. *
  23167. * @private
  23168. * @param {Object} link
  23169. * @param {Object} action
  23170. * @memberof LinkAnnotationElement
  23171. */
  23172. _bindNamedAction:
  23173. function LinkAnnotationElement_bindNamedAction(link, action) {
  23174. var self = this;
  23175. link.href = this.linkService.getAnchorUrl('');
  23176. link.onclick = function() {
  23177. self.linkService.executeNamedAction(action);
  23178. return false;
  23179. };
  23180. link.className = 'internalLink';
  23181. }
  23182. });
  23183. return LinkAnnotationElement;
  23184. })();
  23185. /**
  23186. * @class
  23187. * @alias TextAnnotationElement
  23188. */
  23189. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  23190. function TextAnnotationElement(parameters) {
  23191. var isRenderable = !!(parameters.data.hasPopup ||
  23192. parameters.data.title || parameters.data.contents);
  23193. AnnotationElement.call(this, parameters, isRenderable);
  23194. }
  23195. Util.inherit(TextAnnotationElement, AnnotationElement, {
  23196. /**
  23197. * Render the text annotation's HTML element in the empty container.
  23198. *
  23199. * @public
  23200. * @memberof TextAnnotationElement
  23201. * @returns {HTMLSectionElement}
  23202. */
  23203. render: function TextAnnotationElement_render() {
  23204. this.container.className = 'textAnnotation';
  23205. var image = document.createElement('img');
  23206. image.style.height = this.container.style.height;
  23207. image.style.width = this.container.style.width;
  23208. image.src = this.imageResourcesPath + 'annotation-' +
  23209. this.data.name.toLowerCase() + '.svg';
  23210. image.alt = '[{{type}} Annotation]';
  23211. image.dataset.l10nId = 'text_annotation_type';
  23212. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  23213. if (!this.data.hasPopup) {
  23214. this._createPopup(this.container, image, this.data);
  23215. }
  23216. this.container.appendChild(image);
  23217. return this.container;
  23218. }
  23219. });
  23220. return TextAnnotationElement;
  23221. })();
  23222. /**
  23223. * @class
  23224. * @alias WidgetAnnotationElement
  23225. */
  23226. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  23227. function WidgetAnnotationElement(parameters, isRenderable) {
  23228. AnnotationElement.call(this, parameters, isRenderable);
  23229. }
  23230. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  23231. /**
  23232. * Render the widget annotation's HTML element in the empty container.
  23233. *
  23234. * @public
  23235. * @memberof WidgetAnnotationElement
  23236. * @returns {HTMLSectionElement}
  23237. */
  23238. render: function WidgetAnnotationElement_render() {
  23239. // Show only the container for unsupported field types.
  23240. return this.container;
  23241. }
  23242. });
  23243. return WidgetAnnotationElement;
  23244. })();
  23245. /**
  23246. * @class
  23247. * @alias TextWidgetAnnotationElement
  23248. */
  23249. var TextWidgetAnnotationElement = (
  23250. function TextWidgetAnnotationElementClosure() {
  23251. var TEXT_ALIGNMENT = ['left', 'center', 'right'];
  23252. function TextWidgetAnnotationElement(parameters) {
  23253. var isRenderable = parameters.renderInteractiveForms ||
  23254. (!parameters.data.hasAppearance && !!parameters.data.fieldValue);
  23255. WidgetAnnotationElement.call(this, parameters, isRenderable);
  23256. }
  23257. Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  23258. /**
  23259. * Render the text widget annotation's HTML element in the empty container.
  23260. *
  23261. * @public
  23262. * @memberof TextWidgetAnnotationElement
  23263. * @returns {HTMLSectionElement}
  23264. */
  23265. render: function TextWidgetAnnotationElement_render() {
  23266. this.container.className = 'textWidgetAnnotation';
  23267. var element = null;
  23268. if (this.renderInteractiveForms) {
  23269. // NOTE: We cannot set the values using `element.value` below, since it
  23270. // prevents the AnnotationLayer rasterizer in `test/driver.js`
  23271. // from parsing the elements correctly for the reference tests.
  23272. if (this.data.multiLine) {
  23273. element = document.createElement('textarea');
  23274. element.textContent = this.data.fieldValue;
  23275. } else {
  23276. element = document.createElement('input');
  23277. element.type = 'text';
  23278. element.setAttribute('value', this.data.fieldValue);
  23279. }
  23280. element.disabled = this.data.readOnly;
  23281. if (this.data.maxLen !== null) {
  23282. element.maxLength = this.data.maxLen;
  23283. }
  23284. if (this.data.comb) {
  23285. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  23286. var combWidth = fieldWidth / this.data.maxLen;
  23287. element.classList.add('comb');
  23288. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  23289. }
  23290. } else {
  23291. element = document.createElement('div');
  23292. element.textContent = this.data.fieldValue;
  23293. element.style.verticalAlign = 'middle';
  23294. element.style.display = 'table-cell';
  23295. var font = null;
  23296. if (this.data.fontRefName) {
  23297. font = this.page.commonObjs.getData(this.data.fontRefName);
  23298. }
  23299. this._setTextStyle(element, font);
  23300. }
  23301. if (this.data.textAlignment !== null) {
  23302. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  23303. }
  23304. this.container.appendChild(element);
  23305. return this.container;
  23306. },
  23307. /**
  23308. * Apply text styles to the text in the element.
  23309. *
  23310. * @private
  23311. * @param {HTMLDivElement} element
  23312. * @param {Object} font
  23313. * @memberof TextWidgetAnnotationElement
  23314. */
  23315. _setTextStyle:
  23316. function TextWidgetAnnotationElement_setTextStyle(element, font) {
  23317. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  23318. var style = element.style;
  23319. style.fontSize = this.data.fontSize + 'px';
  23320. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  23321. if (!font) {
  23322. return;
  23323. }
  23324. style.fontWeight = (font.black ?
  23325. (font.bold ? '900' : 'bold') :
  23326. (font.bold ? 'bold' : 'normal'));
  23327. style.fontStyle = (font.italic ? 'italic' : 'normal');
  23328. // Use a reasonable default font if the font doesn't specify a fallback.
  23329. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  23330. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  23331. style.fontFamily = fontFamily + fallbackName;
  23332. }
  23333. });
  23334. return TextWidgetAnnotationElement;
  23335. })();
  23336. /**
  23337. * @class
  23338. * @alias ChoiceWidgetAnnotationElement
  23339. */
  23340. var ChoiceWidgetAnnotationElement = (
  23341. function ChoiceWidgetAnnotationElementClosure() {
  23342. function ChoiceWidgetAnnotationElement(parameters) {
  23343. WidgetAnnotationElement.call(this, parameters,
  23344. parameters.renderInteractiveForms);
  23345. }
  23346. Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
  23347. /**
  23348. * Render the choice widget annotation's HTML element in the empty
  23349. * container.
  23350. *
  23351. * @public
  23352. * @memberof ChoiceWidgetAnnotationElement
  23353. * @returns {HTMLSectionElement}
  23354. */
  23355. render: function ChoiceWidgetAnnotationElement_render() {
  23356. this.container.className = 'choiceWidgetAnnotation';
  23357. var selectElement = document.createElement('select');
  23358. selectElement.disabled = this.data.readOnly;
  23359. if (!this.data.combo) {
  23360. // List boxes have a size and (optionally) multiple selection.
  23361. selectElement.size = this.data.options.length;
  23362. if (this.data.multiSelect) {
  23363. selectElement.multiple = true;
  23364. }
  23365. }
  23366. // Insert the options into the choice field.
  23367. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  23368. var option = this.data.options[i];
  23369. var optionElement = document.createElement('option');
  23370. optionElement.textContent = option.displayValue;
  23371. optionElement.value = option.exportValue;
  23372. if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
  23373. optionElement.setAttribute('selected', true);
  23374. }
  23375. selectElement.appendChild(optionElement);
  23376. }
  23377. this.container.appendChild(selectElement);
  23378. return this.container;
  23379. }
  23380. });
  23381. return ChoiceWidgetAnnotationElement;
  23382. })();
  23383. /**
  23384. * @class
  23385. * @alias PopupAnnotationElement
  23386. */
  23387. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  23388. function PopupAnnotationElement(parameters) {
  23389. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  23390. AnnotationElement.call(this, parameters, isRenderable);
  23391. }
  23392. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  23393. /**
  23394. * Render the popup annotation's HTML element in the empty container.
  23395. *
  23396. * @public
  23397. * @memberof PopupAnnotationElement
  23398. * @returns {HTMLSectionElement}
  23399. */
  23400. render: function PopupAnnotationElement_render() {
  23401. this.container.className = 'popupAnnotation';
  23402. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  23403. var parentElement = this.layer.querySelector(selector);
  23404. if (!parentElement) {
  23405. return this.container;
  23406. }
  23407. var popup = new PopupElement({
  23408. container: this.container,
  23409. trigger: parentElement,
  23410. color: this.data.color,
  23411. title: this.data.title,
  23412. contents: this.data.contents
  23413. });
  23414. // Position the popup next to the parent annotation's container.
  23415. // PDF viewers ignore a popup annotation's rectangle.
  23416. var parentLeft = parseFloat(parentElement.style.left);
  23417. var parentWidth = parseFloat(parentElement.style.width);
  23418. CustomStyle.setProp('transformOrigin', this.container,
  23419. -(parentLeft + parentWidth) + 'px -' +
  23420. parentElement.style.top);
  23421. this.container.style.left = (parentLeft + parentWidth) + 'px';
  23422. this.container.appendChild(popup.render());
  23423. return this.container;
  23424. }
  23425. });
  23426. return PopupAnnotationElement;
  23427. })();
  23428. /**
  23429. * @class
  23430. * @alias PopupElement
  23431. */
  23432. var PopupElement = (function PopupElementClosure() {
  23433. var BACKGROUND_ENLIGHT = 0.7;
  23434. function PopupElement(parameters) {
  23435. this.container = parameters.container;
  23436. this.trigger = parameters.trigger;
  23437. this.color = parameters.color;
  23438. this.title = parameters.title;
  23439. this.contents = parameters.contents;
  23440. this.hideWrapper = parameters.hideWrapper || false;
  23441. this.pinned = false;
  23442. }
  23443. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  23444. /**
  23445. * Render the popup's HTML element.
  23446. *
  23447. * @public
  23448. * @memberof PopupElement
  23449. * @returns {HTMLSectionElement}
  23450. */
  23451. render: function PopupElement_render() {
  23452. var wrapper = document.createElement('div');
  23453. wrapper.className = 'popupWrapper';
  23454. // For Popup annotations we hide the entire section because it contains
  23455. // only the popup. However, for Text annotations without a separate Popup
  23456. // annotation, we cannot hide the entire container as the image would
  23457. // disappear too. In that special case, hiding the wrapper suffices.
  23458. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  23459. this.hideElement.setAttribute('hidden', true);
  23460. var popup = document.createElement('div');
  23461. popup.className = 'popup';
  23462. var color = this.color;
  23463. if (color) {
  23464. // Enlighten the color.
  23465. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  23466. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  23467. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  23468. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  23469. }
  23470. var contents = this._formatContents(this.contents);
  23471. var title = document.createElement('h1');
  23472. title.textContent = this.title;
  23473. // Attach the event listeners to the trigger element.
  23474. this.trigger.addEventListener('click', this._toggle.bind(this));
  23475. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  23476. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  23477. popup.addEventListener('click', this._hide.bind(this, true));
  23478. popup.appendChild(title);
  23479. popup.appendChild(contents);
  23480. wrapper.appendChild(popup);
  23481. return wrapper;
  23482. },
  23483. /**
  23484. * Format the contents of the popup by adding newlines where necessary.
  23485. *
  23486. * @private
  23487. * @param {string} contents
  23488. * @memberof PopupElement
  23489. * @returns {HTMLParagraphElement}
  23490. */
  23491. _formatContents: function PopupElement_formatContents(contents) {
  23492. var p = document.createElement('p');
  23493. var lines = contents.split(/(?:\r\n?|\n)/);
  23494. for (var i = 0, ii = lines.length; i < ii; ++i) {
  23495. var line = lines[i];
  23496. p.appendChild(document.createTextNode(line));
  23497. if (i < (ii - 1)) {
  23498. p.appendChild(document.createElement('br'));
  23499. }
  23500. }
  23501. return p;
  23502. },
  23503. /**
  23504. * Toggle the visibility of the popup.
  23505. *
  23506. * @private
  23507. * @memberof PopupElement
  23508. */
  23509. _toggle: function PopupElement_toggle() {
  23510. if (this.pinned) {
  23511. this._hide(true);
  23512. } else {
  23513. this._show(true);
  23514. }
  23515. },
  23516. /**
  23517. * Show the popup.
  23518. *
  23519. * @private
  23520. * @param {boolean} pin
  23521. * @memberof PopupElement
  23522. */
  23523. _show: function PopupElement_show(pin) {
  23524. if (pin) {
  23525. this.pinned = true;
  23526. }
  23527. if (this.hideElement.hasAttribute('hidden')) {
  23528. this.hideElement.removeAttribute('hidden');
  23529. this.container.style.zIndex += 1;
  23530. }
  23531. },
  23532. /**
  23533. * Hide the popup.
  23534. *
  23535. * @private
  23536. * @param {boolean} unpin
  23537. * @memberof PopupElement
  23538. */
  23539. _hide: function PopupElement_hide(unpin) {
  23540. if (unpin) {
  23541. this.pinned = false;
  23542. }
  23543. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  23544. this.hideElement.setAttribute('hidden', true);
  23545. this.container.style.zIndex -= 1;
  23546. }
  23547. }
  23548. };
  23549. return PopupElement;
  23550. })();
  23551. /**
  23552. * @class
  23553. * @alias HighlightAnnotationElement
  23554. */
  23555. var HighlightAnnotationElement = (
  23556. function HighlightAnnotationElementClosure() {
  23557. function HighlightAnnotationElement(parameters) {
  23558. var isRenderable = !!(parameters.data.hasPopup ||
  23559. parameters.data.title || parameters.data.contents);
  23560. AnnotationElement.call(this, parameters, isRenderable);
  23561. }
  23562. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  23563. /**
  23564. * Render the highlight annotation's HTML element in the empty container.
  23565. *
  23566. * @public
  23567. * @memberof HighlightAnnotationElement
  23568. * @returns {HTMLSectionElement}
  23569. */
  23570. render: function HighlightAnnotationElement_render() {
  23571. this.container.className = 'highlightAnnotation';
  23572. if (!this.data.hasPopup) {
  23573. this._createPopup(this.container, null, this.data);
  23574. }
  23575. return this.container;
  23576. }
  23577. });
  23578. return HighlightAnnotationElement;
  23579. })();
  23580. /**
  23581. * @class
  23582. * @alias UnderlineAnnotationElement
  23583. */
  23584. var UnderlineAnnotationElement = (
  23585. function UnderlineAnnotationElementClosure() {
  23586. function UnderlineAnnotationElement(parameters) {
  23587. var isRenderable = !!(parameters.data.hasPopup ||
  23588. parameters.data.title || parameters.data.contents);
  23589. AnnotationElement.call(this, parameters, isRenderable);
  23590. }
  23591. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  23592. /**
  23593. * Render the underline annotation's HTML element in the empty container.
  23594. *
  23595. * @public
  23596. * @memberof UnderlineAnnotationElement
  23597. * @returns {HTMLSectionElement}
  23598. */
  23599. render: function UnderlineAnnotationElement_render() {
  23600. this.container.className = 'underlineAnnotation';
  23601. if (!this.data.hasPopup) {
  23602. this._createPopup(this.container, null, this.data);
  23603. }
  23604. return this.container;
  23605. }
  23606. });
  23607. return UnderlineAnnotationElement;
  23608. })();
  23609. /**
  23610. * @class
  23611. * @alias SquigglyAnnotationElement
  23612. */
  23613. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  23614. function SquigglyAnnotationElement(parameters) {
  23615. var isRenderable = !!(parameters.data.hasPopup ||
  23616. parameters.data.title || parameters.data.contents);
  23617. AnnotationElement.call(this, parameters, isRenderable);
  23618. }
  23619. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  23620. /**
  23621. * Render the squiggly annotation's HTML element in the empty container.
  23622. *
  23623. * @public
  23624. * @memberof SquigglyAnnotationElement
  23625. * @returns {HTMLSectionElement}
  23626. */
  23627. render: function SquigglyAnnotationElement_render() {
  23628. this.container.className = 'squigglyAnnotation';
  23629. if (!this.data.hasPopup) {
  23630. this._createPopup(this.container, null, this.data);
  23631. }
  23632. return this.container;
  23633. }
  23634. });
  23635. return SquigglyAnnotationElement;
  23636. })();
  23637. /**
  23638. * @class
  23639. * @alias StrikeOutAnnotationElement
  23640. */
  23641. var StrikeOutAnnotationElement = (
  23642. function StrikeOutAnnotationElementClosure() {
  23643. function StrikeOutAnnotationElement(parameters) {
  23644. var isRenderable = !!(parameters.data.hasPopup ||
  23645. parameters.data.title || parameters.data.contents);
  23646. AnnotationElement.call(this, parameters, isRenderable);
  23647. }
  23648. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  23649. /**
  23650. * Render the strikeout annotation's HTML element in the empty container.
  23651. *
  23652. * @public
  23653. * @memberof StrikeOutAnnotationElement
  23654. * @returns {HTMLSectionElement}
  23655. */
  23656. render: function StrikeOutAnnotationElement_render() {
  23657. this.container.className = 'strikeoutAnnotation';
  23658. if (!this.data.hasPopup) {
  23659. this._createPopup(this.container, null, this.data);
  23660. }
  23661. return this.container;
  23662. }
  23663. });
  23664. return StrikeOutAnnotationElement;
  23665. })();
  23666. /**
  23667. * @class
  23668. * @alias FileAttachmentAnnotationElement
  23669. */
  23670. var FileAttachmentAnnotationElement = (
  23671. function FileAttachmentAnnotationElementClosure() {
  23672. function FileAttachmentAnnotationElement(parameters) {
  23673. AnnotationElement.call(this, parameters, true);
  23674. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  23675. this.content = parameters.data.file.content;
  23676. }
  23677. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  23678. /**
  23679. * Render the file attachment annotation's HTML element in the empty
  23680. * container.
  23681. *
  23682. * @public
  23683. * @memberof FileAttachmentAnnotationElement
  23684. * @returns {HTMLSectionElement}
  23685. */
  23686. render: function FileAttachmentAnnotationElement_render() {
  23687. this.container.className = 'fileAttachmentAnnotation';
  23688. var trigger = document.createElement('div');
  23689. trigger.style.height = this.container.style.height;
  23690. trigger.style.width = this.container.style.width;
  23691. trigger.addEventListener('dblclick', this._download.bind(this));
  23692. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  23693. this._createPopup(this.container, trigger, this.data);
  23694. }
  23695. this.container.appendChild(trigger);
  23696. return this.container;
  23697. },
  23698. /**
  23699. * Download the file attachment associated with this annotation.
  23700. *
  23701. * @private
  23702. * @memberof FileAttachmentAnnotationElement
  23703. */
  23704. _download: function FileAttachmentAnnotationElement_download() {
  23705. if (!this.downloadManager) {
  23706. warn('Download cannot be started due to unavailable download manager');
  23707. return;
  23708. }
  23709. this.downloadManager.downloadData(this.content, this.filename, '');
  23710. }
  23711. });
  23712. return FileAttachmentAnnotationElement;
  23713. })();
  23714. /**
  23715. * @typedef {Object} AnnotationLayerParameters
  23716. * @property {PageViewport} viewport
  23717. * @property {HTMLDivElement} div
  23718. * @property {Array} annotations
  23719. * @property {PDFPage} page
  23720. * @property {IPDFLinkService} linkService
  23721. * @property {string} imageResourcesPath
  23722. * @property {boolean} renderInteractiveForms
  23723. */
  23724. /**
  23725. * @class
  23726. * @alias AnnotationLayer
  23727. */
  23728. var AnnotationLayer = (function AnnotationLayerClosure() {
  23729. return {
  23730. /**
  23731. * Render a new annotation layer with all annotation elements.
  23732. *
  23733. * @public
  23734. * @param {AnnotationLayerParameters} parameters
  23735. * @memberof AnnotationLayer
  23736. */
  23737. render: function AnnotationLayer_render(parameters) {
  23738. var annotationElementFactory = new AnnotationElementFactory();
  23739. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  23740. var data = parameters.annotations[i];
  23741. if (!data) {
  23742. continue;
  23743. }
  23744. var properties = {
  23745. data: data,
  23746. layer: parameters.div,
  23747. page: parameters.page,
  23748. viewport: parameters.viewport,
  23749. linkService: parameters.linkService,
  23750. downloadManager: parameters.downloadManager,
  23751. imageResourcesPath: parameters.imageResourcesPath ||
  23752. getDefaultSetting('imageResourcesPath'),
  23753. renderInteractiveForms: parameters.renderInteractiveForms || false,
  23754. };
  23755. var element = annotationElementFactory.create(properties);
  23756. if (element.isRenderable) {
  23757. parameters.div.appendChild(element.render());
  23758. }
  23759. }
  23760. },
  23761. /**
  23762. * Update the annotation elements on existing annotation layer.
  23763. *
  23764. * @public
  23765. * @param {AnnotationLayerParameters} parameters
  23766. * @memberof AnnotationLayer
  23767. */
  23768. update: function AnnotationLayer_update(parameters) {
  23769. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  23770. var data = parameters.annotations[i];
  23771. var element = parameters.div.querySelector(
  23772. '[data-annotation-id="' + data.id + '"]');
  23773. if (element) {
  23774. CustomStyle.setProp('transform', element,
  23775. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  23776. }
  23777. }
  23778. parameters.div.removeAttribute('hidden');
  23779. }
  23780. };
  23781. })();
  23782. exports.AnnotationLayer = AnnotationLayer;
  23783. }));
  23784. (function (root, factory) {
  23785. {
  23786. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  23787. root.pdfjsDisplayDOMUtils);
  23788. }
  23789. }(this, function (exports, sharedUtil, displayDOMUtils) {
  23790. var Util = sharedUtil.Util;
  23791. var createPromiseCapability = sharedUtil.createPromiseCapability;
  23792. var CustomStyle = displayDOMUtils.CustomStyle;
  23793. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  23794. /**
  23795. * Text layer render parameters.
  23796. *
  23797. * @typedef {Object} TextLayerRenderParameters
  23798. * @property {TextContent} textContent - Text content to render (the object is
  23799. * returned by the page's getTextContent() method).
  23800. * @property {HTMLElement} container - HTML element that will contain text runs.
  23801. * @property {PageViewport} viewport - The target viewport to properly
  23802. * layout the text runs.
  23803. * @property {Array} textDivs - (optional) HTML elements that are correspond
  23804. * the text items of the textContent input. This is output and shall be
  23805. * initially be set to empty array.
  23806. * @property {number} timeout - (optional) Delay in milliseconds before
  23807. * rendering of the text runs occurs.
  23808. * @property {boolean} enhanceTextSelection - (optional) Whether to turn on the
  23809. * text selection enhancement.
  23810. */
  23811. var renderTextLayer = (function renderTextLayerClosure() {
  23812. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  23813. var NonWhitespaceRegexp = /\S/;
  23814. function isAllWhitespace(str) {
  23815. return !NonWhitespaceRegexp.test(str);
  23816. }
  23817. // Text layers may contain many thousand div's, and using `styleBuf` avoids
  23818. // creating many intermediate strings when building their 'style' properties.
  23819. var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0,
  23820. 'px; font-family: ', '', ';'];
  23821. function appendText(task, geom, styles) {
  23822. // Initialize all used properties to keep the caches monomorphic.
  23823. var textDiv = document.createElement('div');
  23824. var textDivProperties = {
  23825. style: null,
  23826. angle: 0,
  23827. canvasWidth: 0,
  23828. isWhitespace: false,
  23829. originalTransform: null,
  23830. paddingBottom: 0,
  23831. paddingLeft: 0,
  23832. paddingRight: 0,
  23833. paddingTop: 0,
  23834. scale: 1,
  23835. };
  23836. task._textDivs.push(textDiv);
  23837. if (isAllWhitespace(geom.str)) {
  23838. textDivProperties.isWhitespace = true;
  23839. task._textDivProperties.set(textDiv, textDivProperties);
  23840. return;
  23841. }
  23842. var tx = Util.transform(task._viewport.transform, geom.transform);
  23843. var angle = Math.atan2(tx[1], tx[0]);
  23844. var style = styles[geom.fontName];
  23845. if (style.vertical) {
  23846. angle += Math.PI / 2;
  23847. }
  23848. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  23849. var fontAscent = fontHeight;
  23850. if (style.ascent) {
  23851. fontAscent = style.ascent * fontAscent;
  23852. } else if (style.descent) {
  23853. fontAscent = (1 + style.descent) * fontAscent;
  23854. }
  23855. var left;
  23856. var top;
  23857. if (angle === 0) {
  23858. left = tx[4];
  23859. top = tx[5] - fontAscent;
  23860. } else {
  23861. left = tx[4] + (fontAscent * Math.sin(angle));
  23862. top = tx[5] - (fontAscent * Math.cos(angle));
  23863. }
  23864. styleBuf[1] = left;
  23865. styleBuf[3] = top;
  23866. styleBuf[5] = fontHeight;
  23867. styleBuf[7] = style.fontFamily;
  23868. textDivProperties.style = styleBuf.join('');
  23869. textDiv.setAttribute('style', textDivProperties.style);
  23870. textDiv.textContent = geom.str;
  23871. // |fontName| is only used by the Font Inspector. This test will succeed
  23872. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  23873. // not worth the effort to do a more accurate test. We only use `dataset`
  23874. // here to make the font name available for the debugger.
  23875. if (getDefaultSetting('pdfBug')) {
  23876. textDiv.dataset.fontName = geom.fontName;
  23877. }
  23878. if (angle !== 0) {
  23879. textDivProperties.angle = angle * (180 / Math.PI);
  23880. }
  23881. // We don't bother scaling single-char text divs, because it has very
  23882. // little effect on text highlighting. This makes scrolling on docs with
  23883. // lots of such divs a lot faster.
  23884. if (geom.str.length > 1) {
  23885. if (style.vertical) {
  23886. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  23887. } else {
  23888. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  23889. }
  23890. }
  23891. task._textDivProperties.set(textDiv, textDivProperties);
  23892. if (task._enhanceTextSelection) {
  23893. var angleCos = 1, angleSin = 0;
  23894. if (angle !== 0) {
  23895. angleCos = Math.cos(angle);
  23896. angleSin = Math.sin(angle);
  23897. }
  23898. var divWidth = (style.vertical ? geom.height : geom.width) *
  23899. task._viewport.scale;
  23900. var divHeight = fontHeight;
  23901. var m, b;
  23902. if (angle !== 0) {
  23903. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  23904. b = Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  23905. } else {
  23906. b = [left, top, left + divWidth, top + divHeight];
  23907. }
  23908. task._bounds.push({
  23909. left: b[0],
  23910. top: b[1],
  23911. right: b[2],
  23912. bottom: b[3],
  23913. div: textDiv,
  23914. size: [divWidth, divHeight],
  23915. m: m
  23916. });
  23917. }
  23918. }
  23919. function render(task) {
  23920. if (task._canceled) {
  23921. return;
  23922. }
  23923. var textLayerFrag = task._container;
  23924. var textDivs = task._textDivs;
  23925. var capability = task._capability;
  23926. var textDivsLength = textDivs.length;
  23927. // No point in rendering many divs as it would make the browser
  23928. // unusable even after the divs are rendered.
  23929. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  23930. task._renderingDone = true;
  23931. capability.resolve();
  23932. return;
  23933. }
  23934. var canvas = document.createElement('canvas');
  23935. var ctx = canvas.getContext('2d', {alpha: false});
  23936. var lastFontSize;
  23937. var lastFontFamily;
  23938. for (var i = 0; i < textDivsLength; i++) {
  23939. var textDiv = textDivs[i];
  23940. var textDivProperties = task._textDivProperties.get(textDiv);
  23941. if (textDivProperties.isWhitespace) {
  23942. continue;
  23943. }
  23944. var fontSize = textDiv.style.fontSize;
  23945. var fontFamily = textDiv.style.fontFamily;
  23946. // Only build font string and set to context if different from last.
  23947. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  23948. ctx.font = fontSize + ' ' + fontFamily;
  23949. lastFontSize = fontSize;
  23950. lastFontFamily = fontFamily;
  23951. }
  23952. var width = ctx.measureText(textDiv.textContent).width;
  23953. textLayerFrag.appendChild(textDiv);
  23954. var transform = '';
  23955. if (textDivProperties.canvasWidth !== 0 && width > 0) {
  23956. textDivProperties.scale = textDivProperties.canvasWidth / width;
  23957. transform = 'scaleX(' + textDivProperties.scale + ')';
  23958. }
  23959. if (textDivProperties.angle !== 0) {
  23960. transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
  23961. }
  23962. if (transform !== '') {
  23963. textDivProperties.originalTransform = transform;
  23964. CustomStyle.setProp('transform', textDiv, transform);
  23965. }
  23966. task._textDivProperties.set(textDiv, textDivProperties);
  23967. }
  23968. task._renderingDone = true;
  23969. capability.resolve();
  23970. }
  23971. function expand(task) {
  23972. var bounds = task._bounds;
  23973. var viewport = task._viewport;
  23974. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  23975. for (var i = 0; i < expanded.length; i++) {
  23976. var div = bounds[i].div;
  23977. var divProperties = task._textDivProperties.get(div);
  23978. if (divProperties.angle === 0) {
  23979. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  23980. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  23981. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  23982. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  23983. task._textDivProperties.set(div, divProperties);
  23984. continue;
  23985. }
  23986. // Box is rotated -- trying to find padding so rotated div will not
  23987. // exceed its expanded bounds.
  23988. var e = expanded[i], b = bounds[i];
  23989. var m = b.m, c = m[0], s = m[1];
  23990. // Finding intersections with expanded box.
  23991. var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  23992. var ts = new Float64Array(64);
  23993. points.forEach(function (p, i) {
  23994. var t = Util.applyTransform(p, m);
  23995. ts[i + 0] = c && (e.left - t[0]) / c;
  23996. ts[i + 4] = s && (e.top - t[1]) / s;
  23997. ts[i + 8] = c && (e.right - t[0]) / c;
  23998. ts[i + 12] = s && (e.bottom - t[1]) / s;
  23999. ts[i + 16] = s && (e.left - t[0]) / -s;
  24000. ts[i + 20] = c && (e.top - t[1]) / c;
  24001. ts[i + 24] = s && (e.right - t[0]) / -s;
  24002. ts[i + 28] = c && (e.bottom - t[1]) / c;
  24003. ts[i + 32] = c && (e.left - t[0]) / -c;
  24004. ts[i + 36] = s && (e.top - t[1]) / -s;
  24005. ts[i + 40] = c && (e.right - t[0]) / -c;
  24006. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  24007. ts[i + 48] = s && (e.left - t[0]) / s;
  24008. ts[i + 52] = c && (e.top - t[1]) / -c;
  24009. ts[i + 56] = s && (e.right - t[0]) / s;
  24010. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  24011. });
  24012. var findPositiveMin = function (ts, offset, count) {
  24013. var result = 0;
  24014. for (var i = 0; i < count; i++) {
  24015. var t = ts[offset++];
  24016. if (t > 0) {
  24017. result = result ? Math.min(t, result) : t;
  24018. }
  24019. }
  24020. return result;
  24021. };
  24022. // Not based on math, but to simplify calculations, using cos and sin
  24023. // absolute values to not exceed the box (it can but insignificantly).
  24024. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  24025. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  24026. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  24027. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  24028. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  24029. task._textDivProperties.set(div, divProperties);
  24030. }
  24031. }
  24032. function expandBounds(width, height, boxes) {
  24033. var bounds = boxes.map(function (box, i) {
  24034. return {
  24035. x1: box.left,
  24036. y1: box.top,
  24037. x2: box.right,
  24038. y2: box.bottom,
  24039. index: i,
  24040. x1New: undefined,
  24041. x2New: undefined
  24042. };
  24043. });
  24044. expandBoundsLTR(width, bounds);
  24045. var expanded = new Array(boxes.length);
  24046. bounds.forEach(function (b) {
  24047. var i = b.index;
  24048. expanded[i] = {
  24049. left: b.x1New,
  24050. top: 0,
  24051. right: b.x2New,
  24052. bottom: 0
  24053. };
  24054. });
  24055. // Rotating on 90 degrees and extending extended boxes. Reusing the bounds
  24056. // array and objects.
  24057. boxes.map(function (box, i) {
  24058. var e = expanded[i], b = bounds[i];
  24059. b.x1 = box.top;
  24060. b.y1 = width - e.right;
  24061. b.x2 = box.bottom;
  24062. b.y2 = width - e.left;
  24063. b.index = i;
  24064. b.x1New = undefined;
  24065. b.x2New = undefined;
  24066. });
  24067. expandBoundsLTR(height, bounds);
  24068. bounds.forEach(function (b) {
  24069. var i = b.index;
  24070. expanded[i].top = b.x1New;
  24071. expanded[i].bottom = b.x2New;
  24072. });
  24073. return expanded;
  24074. }
  24075. function expandBoundsLTR(width, bounds) {
  24076. // Sorting by x1 coordinate and walk by the bounds in the same order.
  24077. bounds.sort(function (a, b) { return a.x1 - b.x1 || a.index - b.index; });
  24078. // First we see on the horizon is a fake boundary.
  24079. var fakeBoundary = {
  24080. x1: -Infinity,
  24081. y1: -Infinity,
  24082. x2: 0,
  24083. y2: Infinity,
  24084. index: -1,
  24085. x1New: 0,
  24086. x2New: 0
  24087. };
  24088. var horizon = [{
  24089. start: -Infinity,
  24090. end: Infinity,
  24091. boundary: fakeBoundary
  24092. }];
  24093. bounds.forEach(function (boundary) {
  24094. // Searching for the affected part of horizon.
  24095. // TODO red-black tree or simple binary search
  24096. var i = 0;
  24097. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  24098. i++;
  24099. }
  24100. var j = horizon.length - 1;
  24101. while(j >= 0 && horizon[j].start >= boundary.y2) {
  24102. j--;
  24103. }
  24104. var horizonPart, affectedBoundary;
  24105. var q, k, maxXNew = -Infinity;
  24106. for (q = i; q <= j; q++) {
  24107. horizonPart = horizon[q];
  24108. affectedBoundary = horizonPart.boundary;
  24109. var xNew;
  24110. if (affectedBoundary.x2 > boundary.x1) {
  24111. // In the middle of the previous element, new x shall be at the
  24112. // boundary start. Extending if further if the affected bondary
  24113. // placed on top of the current one.
  24114. xNew = affectedBoundary.index > boundary.index ?
  24115. affectedBoundary.x1New : boundary.x1;
  24116. } else if (affectedBoundary.x2New === undefined) {
  24117. // We have some space in between, new x in middle will be a fair
  24118. // choice.
  24119. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  24120. } else {
  24121. // Affected boundary has x2new set, using it as new x.
  24122. xNew = affectedBoundary.x2New;
  24123. }
  24124. if (xNew > maxXNew) {
  24125. maxXNew = xNew;
  24126. }
  24127. }
  24128. // Set new x1 for current boundary.
  24129. boundary.x1New = maxXNew;
  24130. // Adjusts new x2 for the affected boundaries.
  24131. for (q = i; q <= j; q++) {
  24132. horizonPart = horizon[q];
  24133. affectedBoundary = horizonPart.boundary;
  24134. if (affectedBoundary.x2New === undefined) {
  24135. // Was not set yet, choosing new x if possible.
  24136. if (affectedBoundary.x2 > boundary.x1) {
  24137. // Current and affected boundaries intersect. If affected boundary
  24138. // is placed on top of the current, shrinking the affected.
  24139. if (affectedBoundary.index > boundary.index) {
  24140. affectedBoundary.x2New = affectedBoundary.x2;
  24141. }
  24142. } else {
  24143. affectedBoundary.x2New = maxXNew;
  24144. }
  24145. } else if (affectedBoundary.x2New > maxXNew) {
  24146. // Affected boundary is touching new x, pushing it back.
  24147. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  24148. }
  24149. }
  24150. // Fixing the horizon.
  24151. var changedHorizon = [], lastBoundary = null;
  24152. for (q = i; q <= j; q++) {
  24153. horizonPart = horizon[q];
  24154. affectedBoundary = horizonPart.boundary;
  24155. // Checking which boundary will be visible.
  24156. var useBoundary = affectedBoundary.x2 > boundary.x2 ?
  24157. affectedBoundary : boundary;
  24158. if (lastBoundary === useBoundary) {
  24159. // Merging with previous.
  24160. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  24161. } else {
  24162. changedHorizon.push({
  24163. start: horizonPart.start,
  24164. end: horizonPart.end,
  24165. boundary: useBoundary
  24166. });
  24167. lastBoundary = useBoundary;
  24168. }
  24169. }
  24170. if (horizon[i].start < boundary.y1) {
  24171. changedHorizon[0].start = boundary.y1;
  24172. changedHorizon.unshift({
  24173. start: horizon[i].start,
  24174. end: boundary.y1,
  24175. boundary: horizon[i].boundary
  24176. });
  24177. }
  24178. if (boundary.y2 < horizon[j].end) {
  24179. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  24180. changedHorizon.push({
  24181. start: boundary.y2,
  24182. end: horizon[j].end,
  24183. boundary: horizon[j].boundary
  24184. });
  24185. }
  24186. // Set x2 new of boundary that is no longer visible (see overlapping case
  24187. // above).
  24188. // TODO more efficient, e.g. via reference counting.
  24189. for (q = i; q <= j; q++) {
  24190. horizonPart = horizon[q];
  24191. affectedBoundary = horizonPart.boundary;
  24192. if (affectedBoundary.x2New !== undefined) {
  24193. continue;
  24194. }
  24195. var used = false;
  24196. for (k = i - 1; !used && k >= 0 &&
  24197. horizon[k].start >= affectedBoundary.y1; k--) {
  24198. used = horizon[k].boundary === affectedBoundary;
  24199. }
  24200. for (k = j + 1; !used && k < horizon.length &&
  24201. horizon[k].end <= affectedBoundary.y2; k++) {
  24202. used = horizon[k].boundary === affectedBoundary;
  24203. }
  24204. for (k = 0; !used && k < changedHorizon.length; k++) {
  24205. used = changedHorizon[k].boundary === affectedBoundary;
  24206. }
  24207. if (!used) {
  24208. affectedBoundary.x2New = maxXNew;
  24209. }
  24210. }
  24211. Array.prototype.splice.apply(horizon,
  24212. [i, j - i + 1].concat(changedHorizon));
  24213. });
  24214. // Set new x2 for all unset boundaries.
  24215. horizon.forEach(function (horizonPart) {
  24216. var affectedBoundary = horizonPart.boundary;
  24217. if (affectedBoundary.x2New === undefined) {
  24218. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  24219. }
  24220. });
  24221. }
  24222. /**
  24223. * Text layer rendering task.
  24224. *
  24225. * @param {TextContent} textContent
  24226. * @param {HTMLElement} container
  24227. * @param {PageViewport} viewport
  24228. * @param {Array} textDivs
  24229. * @param {boolean} enhanceTextSelection
  24230. * @private
  24231. */
  24232. function TextLayerRenderTask(textContent, container, viewport, textDivs,
  24233. enhanceTextSelection) {
  24234. this._textContent = textContent;
  24235. this._container = container;
  24236. this._viewport = viewport;
  24237. this._textDivs = textDivs || [];
  24238. this._textDivProperties = new WeakMap();
  24239. this._renderingDone = false;
  24240. this._canceled = false;
  24241. this._capability = createPromiseCapability();
  24242. this._renderTimer = null;
  24243. this._bounds = [];
  24244. this._enhanceTextSelection = !!enhanceTextSelection;
  24245. }
  24246. TextLayerRenderTask.prototype = {
  24247. get promise() {
  24248. return this._capability.promise;
  24249. },
  24250. cancel: function TextLayer_cancel() {
  24251. this._canceled = true;
  24252. if (this._renderTimer !== null) {
  24253. clearTimeout(this._renderTimer);
  24254. this._renderTimer = null;
  24255. }
  24256. this._capability.reject('canceled');
  24257. },
  24258. _render: function TextLayer_render(timeout) {
  24259. var textItems = this._textContent.items;
  24260. var textStyles = this._textContent.styles;
  24261. for (var i = 0, len = textItems.length; i < len; i++) {
  24262. appendText(this, textItems[i], textStyles);
  24263. }
  24264. if (!timeout) { // Render right away
  24265. render(this);
  24266. } else { // Schedule
  24267. var self = this;
  24268. this._renderTimer = setTimeout(function() {
  24269. render(self);
  24270. self._renderTimer = null;
  24271. }, timeout);
  24272. }
  24273. },
  24274. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  24275. if (!this._enhanceTextSelection || !this._renderingDone) {
  24276. return;
  24277. }
  24278. if (this._bounds !== null) {
  24279. expand(this);
  24280. this._bounds = null;
  24281. }
  24282. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  24283. var div = this._textDivs[i];
  24284. var divProperties = this._textDivProperties.get(div);
  24285. if (divProperties.isWhitespace) {
  24286. continue;
  24287. }
  24288. if (expandDivs) {
  24289. var transform = '', padding = '';
  24290. if (divProperties.scale !== 1) {
  24291. transform = 'scaleX(' + divProperties.scale + ')';
  24292. }
  24293. if (divProperties.angle !== 0) {
  24294. transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
  24295. }
  24296. if (divProperties.paddingLeft !== 0) {
  24297. padding += ' padding-left: ' +
  24298. (divProperties.paddingLeft / divProperties.scale) + 'px;';
  24299. transform += ' translateX(' +
  24300. (-divProperties.paddingLeft / divProperties.scale) + 'px)';
  24301. }
  24302. if (divProperties.paddingTop !== 0) {
  24303. padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
  24304. transform += ' translateY(' + (-divProperties.paddingTop) + 'px)';
  24305. }
  24306. if (divProperties.paddingRight !== 0) {
  24307. padding += ' padding-right: ' +
  24308. (divProperties.paddingRight / divProperties.scale) + 'px;';
  24309. }
  24310. if (divProperties.paddingBottom !== 0) {
  24311. padding += ' padding-bottom: ' +
  24312. divProperties.paddingBottom + 'px;';
  24313. }
  24314. if (padding !== '') {
  24315. div.setAttribute('style', divProperties.style + padding);
  24316. }
  24317. if (transform !== '') {
  24318. CustomStyle.setProp('transform', div, transform);
  24319. }
  24320. } else {
  24321. div.style.padding = 0;
  24322. CustomStyle.setProp('transform', div,
  24323. divProperties.originalTransform || '');
  24324. }
  24325. }
  24326. },
  24327. };
  24328. /**
  24329. * Starts rendering of the text layer.
  24330. *
  24331. * @param {TextLayerRenderParameters} renderParameters
  24332. * @returns {TextLayerRenderTask}
  24333. */
  24334. function renderTextLayer(renderParameters) {
  24335. var task = new TextLayerRenderTask(renderParameters.textContent,
  24336. renderParameters.container,
  24337. renderParameters.viewport,
  24338. renderParameters.textDivs,
  24339. renderParameters.enhanceTextSelection);
  24340. task._render(renderParameters.timeout);
  24341. return task;
  24342. }
  24343. return renderTextLayer;
  24344. })();
  24345. exports.renderTextLayer = renderTextLayer;
  24346. }));
  24347. (function (root, factory) {
  24348. {
  24349. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil,
  24350. root.pdfjsDisplayDOMUtils);
  24351. }
  24352. }(this, function (exports, sharedUtil, displayDOMUtils) {
  24353. var shadow = sharedUtil.shadow;
  24354. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  24355. var WebGLUtils = (function WebGLUtilsClosure() {
  24356. function loadShader(gl, code, shaderType) {
  24357. var shader = gl.createShader(shaderType);
  24358. gl.shaderSource(shader, code);
  24359. gl.compileShader(shader);
  24360. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  24361. if (!compiled) {
  24362. var errorMsg = gl.getShaderInfoLog(shader);
  24363. throw new Error('Error during shader compilation: ' + errorMsg);
  24364. }
  24365. return shader;
  24366. }
  24367. function createVertexShader(gl, code) {
  24368. return loadShader(gl, code, gl.VERTEX_SHADER);
  24369. }
  24370. function createFragmentShader(gl, code) {
  24371. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  24372. }
  24373. function createProgram(gl, shaders) {
  24374. var program = gl.createProgram();
  24375. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  24376. gl.attachShader(program, shaders[i]);
  24377. }
  24378. gl.linkProgram(program);
  24379. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  24380. if (!linked) {
  24381. var errorMsg = gl.getProgramInfoLog(program);
  24382. throw new Error('Error during program linking: ' + errorMsg);
  24383. }
  24384. return program;
  24385. }
  24386. function createTexture(gl, image, textureId) {
  24387. gl.activeTexture(textureId);
  24388. var texture = gl.createTexture();
  24389. gl.bindTexture(gl.TEXTURE_2D, texture);
  24390. // Set the parameters so we can render any size image.
  24391. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  24392. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  24393. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  24394. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  24395. // Upload the image into the texture.
  24396. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  24397. return texture;
  24398. }
  24399. var currentGL, currentCanvas;
  24400. function generateGL() {
  24401. if (currentGL) {
  24402. return;
  24403. }
  24404. currentCanvas = document.createElement('canvas');
  24405. currentGL = currentCanvas.getContext('webgl',
  24406. { premultipliedalpha: false });
  24407. }
  24408. var smaskVertexShaderCode = '\
  24409. attribute vec2 a_position; \
  24410. attribute vec2 a_texCoord; \
  24411. \
  24412. uniform vec2 u_resolution; \
  24413. \
  24414. varying vec2 v_texCoord; \
  24415. \
  24416. void main() { \
  24417. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  24418. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  24419. \
  24420. v_texCoord = a_texCoord; \
  24421. } ';
  24422. var smaskFragmentShaderCode = '\
  24423. precision mediump float; \
  24424. \
  24425. uniform vec4 u_backdrop; \
  24426. uniform int u_subtype; \
  24427. uniform sampler2D u_image; \
  24428. uniform sampler2D u_mask; \
  24429. \
  24430. varying vec2 v_texCoord; \
  24431. \
  24432. void main() { \
  24433. vec4 imageColor = texture2D(u_image, v_texCoord); \
  24434. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  24435. if (u_backdrop.a > 0.0) { \
  24436. maskColor.rgb = maskColor.rgb * maskColor.a + \
  24437. u_backdrop.rgb * (1.0 - maskColor.a); \
  24438. } \
  24439. float lum; \
  24440. if (u_subtype == 0) { \
  24441. lum = maskColor.a; \
  24442. } else { \
  24443. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  24444. maskColor.b * 0.11; \
  24445. } \
  24446. imageColor.a *= lum; \
  24447. imageColor.rgb *= imageColor.a; \
  24448. gl_FragColor = imageColor; \
  24449. } ';
  24450. var smaskCache = null;
  24451. function initSmaskGL() {
  24452. var canvas, gl;
  24453. generateGL();
  24454. canvas = currentCanvas;
  24455. currentCanvas = null;
  24456. gl = currentGL;
  24457. currentGL = null;
  24458. // setup a GLSL program
  24459. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  24460. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  24461. var program = createProgram(gl, [vertexShader, fragmentShader]);
  24462. gl.useProgram(program);
  24463. var cache = {};
  24464. cache.gl = gl;
  24465. cache.canvas = canvas;
  24466. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  24467. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  24468. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  24469. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  24470. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  24471. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  24472. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  24473. // provide texture coordinates for the rectangle.
  24474. var texCoordBuffer = gl.createBuffer();
  24475. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  24476. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  24477. 0.0, 0.0,
  24478. 1.0, 0.0,
  24479. 0.0, 1.0,
  24480. 0.0, 1.0,
  24481. 1.0, 0.0,
  24482. 1.0, 1.0]), gl.STATIC_DRAW);
  24483. gl.enableVertexAttribArray(texCoordLocation);
  24484. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  24485. gl.uniform1i(texLayerLocation, 0);
  24486. gl.uniform1i(texMaskLocation, 1);
  24487. smaskCache = cache;
  24488. }
  24489. function composeSMask(layer, mask, properties) {
  24490. var width = layer.width, height = layer.height;
  24491. if (!smaskCache) {
  24492. initSmaskGL();
  24493. }
  24494. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  24495. canvas.width = width;
  24496. canvas.height = height;
  24497. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  24498. gl.uniform2f(cache.resolutionLocation, width, height);
  24499. if (properties.backdrop) {
  24500. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  24501. properties.backdrop[1], properties.backdrop[2], 1);
  24502. } else {
  24503. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  24504. }
  24505. gl.uniform1i(cache.subtypeLocation,
  24506. properties.subtype === 'Luminosity' ? 1 : 0);
  24507. // Create a textures
  24508. var texture = createTexture(gl, layer, gl.TEXTURE0);
  24509. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  24510. // Create a buffer and put a single clipspace rectangle in
  24511. // it (2 triangles)
  24512. var buffer = gl.createBuffer();
  24513. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  24514. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  24515. 0, 0,
  24516. width, 0,
  24517. 0, height,
  24518. 0, height,
  24519. width, 0,
  24520. width, height]), gl.STATIC_DRAW);
  24521. gl.enableVertexAttribArray(cache.positionLocation);
  24522. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  24523. // draw
  24524. gl.clearColor(0, 0, 0, 0);
  24525. gl.enable(gl.BLEND);
  24526. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  24527. gl.clear(gl.COLOR_BUFFER_BIT);
  24528. gl.drawArrays(gl.TRIANGLES, 0, 6);
  24529. gl.flush();
  24530. gl.deleteTexture(texture);
  24531. gl.deleteTexture(maskTexture);
  24532. gl.deleteBuffer(buffer);
  24533. return canvas;
  24534. }
  24535. var figuresVertexShaderCode = '\
  24536. attribute vec2 a_position; \
  24537. attribute vec3 a_color; \
  24538. \
  24539. uniform vec2 u_resolution; \
  24540. uniform vec2 u_scale; \
  24541. uniform vec2 u_offset; \
  24542. \
  24543. varying vec4 v_color; \
  24544. \
  24545. void main() { \
  24546. vec2 position = (a_position + u_offset) * u_scale; \
  24547. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  24548. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  24549. \
  24550. v_color = vec4(a_color / 255.0, 1.0); \
  24551. } ';
  24552. var figuresFragmentShaderCode = '\
  24553. precision mediump float; \
  24554. \
  24555. varying vec4 v_color; \
  24556. \
  24557. void main() { \
  24558. gl_FragColor = v_color; \
  24559. } ';
  24560. var figuresCache = null;
  24561. function initFiguresGL() {
  24562. var canvas, gl;
  24563. generateGL();
  24564. canvas = currentCanvas;
  24565. currentCanvas = null;
  24566. gl = currentGL;
  24567. currentGL = null;
  24568. // setup a GLSL program
  24569. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  24570. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  24571. var program = createProgram(gl, [vertexShader, fragmentShader]);
  24572. gl.useProgram(program);
  24573. var cache = {};
  24574. cache.gl = gl;
  24575. cache.canvas = canvas;
  24576. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  24577. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  24578. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  24579. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  24580. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  24581. figuresCache = cache;
  24582. }
  24583. function drawFigures(width, height, backgroundColor, figures, context) {
  24584. if (!figuresCache) {
  24585. initFiguresGL();
  24586. }
  24587. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  24588. canvas.width = width;
  24589. canvas.height = height;
  24590. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  24591. gl.uniform2f(cache.resolutionLocation, width, height);
  24592. // count triangle points
  24593. var count = 0;
  24594. var i, ii, rows;
  24595. for (i = 0, ii = figures.length; i < ii; i++) {
  24596. switch (figures[i].type) {
  24597. case 'lattice':
  24598. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  24599. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  24600. break;
  24601. case 'triangles':
  24602. count += figures[i].coords.length;
  24603. break;
  24604. }
  24605. }
  24606. // transfer data
  24607. var coords = new Float32Array(count * 2);
  24608. var colors = new Uint8Array(count * 3);
  24609. var coordsMap = context.coords, colorsMap = context.colors;
  24610. var pIndex = 0, cIndex = 0;
  24611. for (i = 0, ii = figures.length; i < ii; i++) {
  24612. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  24613. switch (figure.type) {
  24614. case 'lattice':
  24615. var cols = figure.verticesPerRow;
  24616. rows = (ps.length / cols) | 0;
  24617. for (var row = 1; row < rows; row++) {
  24618. var offset = row * cols + 1;
  24619. for (var col = 1; col < cols; col++, offset++) {
  24620. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  24621. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  24622. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  24623. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  24624. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  24625. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  24626. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  24627. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  24628. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  24629. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  24630. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  24631. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  24632. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  24633. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  24634. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  24635. coords[pIndex + 6] = coords[pIndex + 2];
  24636. coords[pIndex + 7] = coords[pIndex + 3];
  24637. coords[pIndex + 8] = coords[pIndex + 4];
  24638. coords[pIndex + 9] = coords[pIndex + 5];
  24639. coords[pIndex + 10] = coordsMap[ps[offset]];
  24640. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  24641. colors[cIndex + 9] = colors[cIndex + 3];
  24642. colors[cIndex + 10] = colors[cIndex + 4];
  24643. colors[cIndex + 11] = colors[cIndex + 5];
  24644. colors[cIndex + 12] = colors[cIndex + 6];
  24645. colors[cIndex + 13] = colors[cIndex + 7];
  24646. colors[cIndex + 14] = colors[cIndex + 8];
  24647. colors[cIndex + 15] = colorsMap[cs[offset]];
  24648. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  24649. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  24650. pIndex += 12;
  24651. cIndex += 18;
  24652. }
  24653. }
  24654. break;
  24655. case 'triangles':
  24656. for (var j = 0, jj = ps.length; j < jj; j++) {
  24657. coords[pIndex] = coordsMap[ps[j]];
  24658. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  24659. colors[cIndex] = colorsMap[cs[j]];
  24660. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  24661. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  24662. pIndex += 2;
  24663. cIndex += 3;
  24664. }
  24665. break;
  24666. }
  24667. }
  24668. // draw
  24669. if (backgroundColor) {
  24670. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  24671. backgroundColor[2] / 255, 1.0);
  24672. } else {
  24673. gl.clearColor(0, 0, 0, 0);
  24674. }
  24675. gl.clear(gl.COLOR_BUFFER_BIT);
  24676. var coordsBuffer = gl.createBuffer();
  24677. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  24678. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  24679. gl.enableVertexAttribArray(cache.positionLocation);
  24680. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  24681. var colorsBuffer = gl.createBuffer();
  24682. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  24683. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  24684. gl.enableVertexAttribArray(cache.colorLocation);
  24685. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  24686. 0, 0);
  24687. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  24688. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  24689. gl.drawArrays(gl.TRIANGLES, 0, count);
  24690. gl.flush();
  24691. gl.deleteBuffer(coordsBuffer);
  24692. gl.deleteBuffer(colorsBuffer);
  24693. return canvas;
  24694. }
  24695. function cleanup() {
  24696. if (smaskCache && smaskCache.canvas) {
  24697. smaskCache.canvas.width = 0;
  24698. smaskCache.canvas.height = 0;
  24699. }
  24700. if (figuresCache && figuresCache.canvas) {
  24701. figuresCache.canvas.width = 0;
  24702. figuresCache.canvas.height = 0;
  24703. }
  24704. smaskCache = null;
  24705. figuresCache = null;
  24706. }
  24707. return {
  24708. get isEnabled() {
  24709. if (getDefaultSetting('disableWebGL')) {
  24710. return false;
  24711. }
  24712. var enabled = false;
  24713. try {
  24714. generateGL();
  24715. enabled = !!currentGL;
  24716. } catch (e) { }
  24717. return shadow(this, 'isEnabled', enabled);
  24718. },
  24719. composeSMask: composeSMask,
  24720. drawFigures: drawFigures,
  24721. clear: cleanup
  24722. };
  24723. })();
  24724. exports.WebGLUtils = WebGLUtils;
  24725. }));
  24726. (function (root, factory) {
  24727. {
  24728. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  24729. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  24730. }
  24731. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  24732. var PasswordException = sharedUtil.PasswordException;
  24733. var PasswordResponses = sharedUtil.PasswordResponses;
  24734. var bytesToString = sharedUtil.bytesToString;
  24735. var error = sharedUtil.error;
  24736. var isInt = sharedUtil.isInt;
  24737. var stringToBytes = sharedUtil.stringToBytes;
  24738. var utf8StringToString = sharedUtil.utf8StringToString;
  24739. var warn = sharedUtil.warn;
  24740. var Name = corePrimitives.Name;
  24741. var isName = corePrimitives.isName;
  24742. var isDict = corePrimitives.isDict;
  24743. var DecryptStream = coreStream.DecryptStream;
  24744. var ARCFourCipher = (function ARCFourCipherClosure() {
  24745. function ARCFourCipher(key) {
  24746. this.a = 0;
  24747. this.b = 0;
  24748. var s = new Uint8Array(256);
  24749. var i, j = 0, tmp, keyLength = key.length;
  24750. for (i = 0; i < 256; ++i) {
  24751. s[i] = i;
  24752. }
  24753. for (i = 0; i < 256; ++i) {
  24754. tmp = s[i];
  24755. j = (j + tmp + key[i % keyLength]) & 0xFF;
  24756. s[i] = s[j];
  24757. s[j] = tmp;
  24758. }
  24759. this.s = s;
  24760. }
  24761. ARCFourCipher.prototype = {
  24762. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  24763. var i, n = data.length, tmp, tmp2;
  24764. var a = this.a, b = this.b, s = this.s;
  24765. var output = new Uint8Array(n);
  24766. for (i = 0; i < n; ++i) {
  24767. a = (a + 1) & 0xFF;
  24768. tmp = s[a];
  24769. b = (b + tmp) & 0xFF;
  24770. tmp2 = s[b];
  24771. s[a] = tmp2;
  24772. s[b] = tmp;
  24773. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  24774. }
  24775. this.a = a;
  24776. this.b = b;
  24777. return output;
  24778. }
  24779. };
  24780. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  24781. return ARCFourCipher;
  24782. })();
  24783. var calculateMD5 = (function calculateMD5Closure() {
  24784. var r = new Uint8Array([
  24785. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  24786. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  24787. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  24788. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  24789. var k = new Int32Array([
  24790. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  24791. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  24792. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  24793. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  24794. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  24795. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  24796. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  24797. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  24798. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  24799. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  24800. -145523070, -1120210379, 718787259, -343485551]);
  24801. function hash(data, offset, length) {
  24802. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  24803. // pre-processing
  24804. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  24805. var padded = new Uint8Array(paddedLength);
  24806. var i, j, n;
  24807. for (i = 0; i < length; ++i) {
  24808. padded[i] = data[offset++];
  24809. }
  24810. padded[i++] = 0x80;
  24811. n = paddedLength - 8;
  24812. while (i < n) {
  24813. padded[i++] = 0;
  24814. }
  24815. padded[i++] = (length << 3) & 0xFF;
  24816. padded[i++] = (length >> 5) & 0xFF;
  24817. padded[i++] = (length >> 13) & 0xFF;
  24818. padded[i++] = (length >> 21) & 0xFF;
  24819. padded[i++] = (length >>> 29) & 0xFF;
  24820. padded[i++] = 0;
  24821. padded[i++] = 0;
  24822. padded[i++] = 0;
  24823. var w = new Int32Array(16);
  24824. for (i = 0; i < paddedLength;) {
  24825. for (j = 0; j < 16; ++j, i += 4) {
  24826. w[j] = (padded[i] | (padded[i + 1] << 8) |
  24827. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  24828. }
  24829. var a = h0, b = h1, c = h2, d = h3, f, g;
  24830. for (j = 0; j < 64; ++j) {
  24831. if (j < 16) {
  24832. f = (b & c) | ((~b) & d);
  24833. g = j;
  24834. } else if (j < 32) {
  24835. f = (d & b) | ((~d) & c);
  24836. g = (5 * j + 1) & 15;
  24837. } else if (j < 48) {
  24838. f = b ^ c ^ d;
  24839. g = (3 * j + 5) & 15;
  24840. } else {
  24841. f = c ^ (b | (~d));
  24842. g = (7 * j) & 15;
  24843. }
  24844. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  24845. d = c;
  24846. c = b;
  24847. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  24848. a = tmp;
  24849. }
  24850. h0 = (h0 + a) | 0;
  24851. h1 = (h1 + b) | 0;
  24852. h2 = (h2 + c) | 0;
  24853. h3 = (h3 + d) | 0;
  24854. }
  24855. return new Uint8Array([
  24856. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  24857. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  24858. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  24859. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  24860. ]);
  24861. }
  24862. return hash;
  24863. })();
  24864. var Word64 = (function Word64Closure() {
  24865. function Word64(highInteger, lowInteger) {
  24866. this.high = highInteger | 0;
  24867. this.low = lowInteger | 0;
  24868. }
  24869. Word64.prototype = {
  24870. and: function Word64_and(word) {
  24871. this.high &= word.high;
  24872. this.low &= word.low;
  24873. },
  24874. xor: function Word64_xor(word) {
  24875. this.high ^= word.high;
  24876. this.low ^= word.low;
  24877. },
  24878. or: function Word64_or(word) {
  24879. this.high |= word.high;
  24880. this.low |= word.low;
  24881. },
  24882. shiftRight: function Word64_shiftRight(places) {
  24883. if (places >= 32) {
  24884. this.low = (this.high >>> (places - 32)) | 0;
  24885. this.high = 0;
  24886. } else {
  24887. this.low = (this.low >>> places) | (this.high << (32 - places));
  24888. this.high = (this.high >>> places) | 0;
  24889. }
  24890. },
  24891. shiftLeft: function Word64_shiftLeft(places) {
  24892. if (places >= 32) {
  24893. this.high = this.low << (places - 32);
  24894. this.low = 0;
  24895. } else {
  24896. this.high = (this.high << places) | (this.low >>> (32 - places));
  24897. this.low = this.low << places;
  24898. }
  24899. },
  24900. rotateRight: function Word64_rotateRight(places) {
  24901. var low, high;
  24902. if (places & 32) {
  24903. high = this.low;
  24904. low = this.high;
  24905. } else {
  24906. low = this.low;
  24907. high = this.high;
  24908. }
  24909. places &= 31;
  24910. this.low = (low >>> places) | (high << (32 - places));
  24911. this.high = (high >>> places) | (low << (32 - places));
  24912. },
  24913. not: function Word64_not() {
  24914. this.high = ~this.high;
  24915. this.low = ~this.low;
  24916. },
  24917. add: function Word64_add(word) {
  24918. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  24919. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  24920. if (lowAdd > 0xFFFFFFFF) {
  24921. highAdd += 1;
  24922. }
  24923. this.low = lowAdd | 0;
  24924. this.high = highAdd | 0;
  24925. },
  24926. copyTo: function Word64_copyTo(bytes, offset) {
  24927. bytes[offset] = (this.high >>> 24) & 0xFF;
  24928. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  24929. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  24930. bytes[offset + 3] = this.high & 0xFF;
  24931. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  24932. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  24933. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  24934. bytes[offset + 7] = this.low & 0xFF;
  24935. },
  24936. assign: function Word64_assign(word) {
  24937. this.high = word.high;
  24938. this.low = word.low;
  24939. }
  24940. };
  24941. return Word64;
  24942. })();
  24943. var calculateSHA256 = (function calculateSHA256Closure() {
  24944. function rotr(x, n) {
  24945. return (x >>> n) | (x << 32 - n);
  24946. }
  24947. function ch(x, y, z) {
  24948. return (x & y) ^ (~x & z);
  24949. }
  24950. function maj(x, y, z) {
  24951. return (x & y) ^ (x & z) ^ (y & z);
  24952. }
  24953. function sigma(x) {
  24954. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  24955. }
  24956. function sigmaPrime(x) {
  24957. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  24958. }
  24959. function littleSigma(x) {
  24960. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  24961. }
  24962. function littleSigmaPrime(x) {
  24963. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  24964. }
  24965. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  24966. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  24967. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  24968. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  24969. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  24970. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  24971. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  24972. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  24973. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  24974. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  24975. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  24976. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  24977. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  24978. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  24979. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  24980. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  24981. function hash(data, offset, length) {
  24982. // initial hash values
  24983. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  24984. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  24985. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  24986. // pre-processing
  24987. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  24988. var padded = new Uint8Array(paddedLength);
  24989. var i, j, n;
  24990. for (i = 0; i < length; ++i) {
  24991. padded[i] = data[offset++];
  24992. }
  24993. padded[i++] = 0x80;
  24994. n = paddedLength - 8;
  24995. while (i < n) {
  24996. padded[i++] = 0;
  24997. }
  24998. padded[i++] = 0;
  24999. padded[i++] = 0;
  25000. padded[i++] = 0;
  25001. padded[i++] = (length >>> 29) & 0xFF;
  25002. padded[i++] = (length >> 21) & 0xFF;
  25003. padded[i++] = (length >> 13) & 0xFF;
  25004. padded[i++] = (length >> 5) & 0xFF;
  25005. padded[i++] = (length << 3) & 0xFF;
  25006. var w = new Uint32Array(64);
  25007. // for each 512 bit block
  25008. for (i = 0; i < paddedLength;) {
  25009. for (j = 0; j < 16; ++j) {
  25010. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  25011. (padded[i + 2] << 8) | (padded[i + 3]));
  25012. i += 4;
  25013. }
  25014. for (j = 16; j < 64; ++j) {
  25015. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  25016. littleSigma(w[j - 15]) + w[j - 16] | 0;
  25017. }
  25018. var a = h0, b = h1, c = h2, d = h3, e = h4,
  25019. f = h5, g = h6, h = h7, t1, t2;
  25020. for (j = 0; j < 64; ++j) {
  25021. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  25022. t2 = sigma(a) + maj(a, b, c);
  25023. h = g;
  25024. g = f;
  25025. f = e;
  25026. e = (d + t1) | 0;
  25027. d = c;
  25028. c = b;
  25029. b = a;
  25030. a = (t1 + t2) | 0;
  25031. }
  25032. h0 = (h0 + a) | 0;
  25033. h1 = (h1 + b) | 0;
  25034. h2 = (h2 + c) | 0;
  25035. h3 = (h3 + d) | 0;
  25036. h4 = (h4 + e) | 0;
  25037. h5 = (h5 + f) | 0;
  25038. h6 = (h6 + g) | 0;
  25039. h7 = (h7 + h) | 0;
  25040. }
  25041. return new Uint8Array([
  25042. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  25043. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  25044. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  25045. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  25046. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  25047. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  25048. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  25049. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  25050. ]);
  25051. }
  25052. return hash;
  25053. })();
  25054. var calculateSHA512 = (function calculateSHA512Closure() {
  25055. function ch(result, x, y, z, tmp) {
  25056. result.assign(x);
  25057. result.and(y);
  25058. tmp.assign(x);
  25059. tmp.not();
  25060. tmp.and(z);
  25061. result.xor(tmp);
  25062. }
  25063. function maj(result, x, y, z, tmp) {
  25064. result.assign(x);
  25065. result.and(y);
  25066. tmp.assign(x);
  25067. tmp.and(z);
  25068. result.xor(tmp);
  25069. tmp.assign(y);
  25070. tmp.and(z);
  25071. result.xor(tmp);
  25072. }
  25073. function sigma(result, x, tmp) {
  25074. result.assign(x);
  25075. result.rotateRight(28);
  25076. tmp.assign(x);
  25077. tmp.rotateRight(34);
  25078. result.xor(tmp);
  25079. tmp.assign(x);
  25080. tmp.rotateRight(39);
  25081. result.xor(tmp);
  25082. }
  25083. function sigmaPrime(result, x, tmp) {
  25084. result.assign(x);
  25085. result.rotateRight(14);
  25086. tmp.assign(x);
  25087. tmp.rotateRight(18);
  25088. result.xor(tmp);
  25089. tmp.assign(x);
  25090. tmp.rotateRight(41);
  25091. result.xor(tmp);
  25092. }
  25093. function littleSigma(result, x, tmp) {
  25094. result.assign(x);
  25095. result.rotateRight(1);
  25096. tmp.assign(x);
  25097. tmp.rotateRight(8);
  25098. result.xor(tmp);
  25099. tmp.assign(x);
  25100. tmp.shiftRight(7);
  25101. result.xor(tmp);
  25102. }
  25103. function littleSigmaPrime(result, x, tmp) {
  25104. result.assign(x);
  25105. result.rotateRight(19);
  25106. tmp.assign(x);
  25107. tmp.rotateRight(61);
  25108. result.xor(tmp);
  25109. tmp.assign(x);
  25110. tmp.shiftRight(6);
  25111. result.xor(tmp);
  25112. }
  25113. var k = [
  25114. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  25115. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  25116. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  25117. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  25118. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  25119. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  25120. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  25121. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  25122. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  25123. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  25124. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  25125. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  25126. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  25127. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  25128. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  25129. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  25130. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  25131. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  25132. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  25133. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  25134. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  25135. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  25136. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  25137. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  25138. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  25139. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  25140. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  25141. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  25142. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  25143. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  25144. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  25145. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  25146. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  25147. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  25148. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  25149. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  25150. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  25151. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  25152. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  25153. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  25154. function hash(data, offset, length, mode384) {
  25155. mode384 = !!mode384;
  25156. // initial hash values
  25157. var h0, h1, h2, h3, h4, h5, h6, h7;
  25158. if (!mode384) {
  25159. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  25160. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  25161. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  25162. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  25163. h4 = new Word64(0x510e527f, 0xade682d1);
  25164. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  25165. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  25166. h7 = new Word64(0x5be0cd19, 0x137e2179);
  25167. }
  25168. else {
  25169. // SHA384 is exactly the same
  25170. // except with different starting values and a trimmed result
  25171. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  25172. h1 = new Word64(0x629a292a, 0x367cd507);
  25173. h2 = new Word64(0x9159015a, 0x3070dd17);
  25174. h3 = new Word64(0x152fecd8, 0xf70e5939);
  25175. h4 = new Word64(0x67332667, 0xffc00b31);
  25176. h5 = new Word64(0x8eb44a87, 0x68581511);
  25177. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  25178. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  25179. }
  25180. // pre-processing
  25181. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  25182. var padded = new Uint8Array(paddedLength);
  25183. var i, j, n;
  25184. for (i = 0; i < length; ++i) {
  25185. padded[i] = data[offset++];
  25186. }
  25187. padded[i++] = 0x80;
  25188. n = paddedLength - 16;
  25189. while (i < n) {
  25190. padded[i++] = 0;
  25191. }
  25192. padded[i++] = 0;
  25193. padded[i++] = 0;
  25194. padded[i++] = 0;
  25195. padded[i++] = 0;
  25196. padded[i++] = 0;
  25197. padded[i++] = 0;
  25198. padded[i++] = 0;
  25199. padded[i++] = 0;
  25200. padded[i++] = 0;
  25201. padded[i++] = 0;
  25202. padded[i++] = 0;
  25203. padded[i++] = (length >>> 29) & 0xFF;
  25204. padded[i++] = (length >> 21) & 0xFF;
  25205. padded[i++] = (length >> 13) & 0xFF;
  25206. padded[i++] = (length >> 5) & 0xFF;
  25207. padded[i++] = (length << 3) & 0xFF;
  25208. var w = new Array(80);
  25209. for (i = 0; i < 80; i++) {
  25210. w[i] = new Word64(0, 0);
  25211. }
  25212. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  25213. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  25214. var g = new Word64(0, 0), h = new Word64(0, 0);
  25215. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  25216. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  25217. // for each 1024 bit block
  25218. for (i = 0; i < paddedLength;) {
  25219. for (j = 0; j < 16; ++j) {
  25220. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  25221. (padded[i + 2] << 8) | (padded[i + 3]);
  25222. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  25223. (padded[i + 6]) << 8 | (padded[i + 7]);
  25224. i += 8;
  25225. }
  25226. for (j = 16; j < 80; ++j) {
  25227. tmp3 = w[j];
  25228. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  25229. tmp3.add(w[j - 7]);
  25230. littleSigma(tmp1, w[j - 15], tmp2);
  25231. tmp3.add(tmp1);
  25232. tmp3.add(w[j - 16]);
  25233. }
  25234. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  25235. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  25236. for (j = 0; j < 80; ++j) {
  25237. t1.assign(h);
  25238. sigmaPrime(tmp1, e, tmp2);
  25239. t1.add(tmp1);
  25240. ch(tmp1, e, f, g, tmp2);
  25241. t1.add(tmp1);
  25242. t1.add(k[j]);
  25243. t1.add(w[j]);
  25244. sigma(t2, a, tmp2);
  25245. maj(tmp1, a, b, c, tmp2);
  25246. t2.add(tmp1);
  25247. tmp3 = h;
  25248. h = g;
  25249. g = f;
  25250. f = e;
  25251. d.add(t1);
  25252. e = d;
  25253. d = c;
  25254. c = b;
  25255. b = a;
  25256. tmp3.assign(t1);
  25257. tmp3.add(t2);
  25258. a = tmp3;
  25259. }
  25260. h0.add(a);
  25261. h1.add(b);
  25262. h2.add(c);
  25263. h3.add(d);
  25264. h4.add(e);
  25265. h5.add(f);
  25266. h6.add(g);
  25267. h7.add(h);
  25268. }
  25269. var result;
  25270. if (!mode384) {
  25271. result = new Uint8Array(64);
  25272. h0.copyTo(result,0);
  25273. h1.copyTo(result,8);
  25274. h2.copyTo(result,16);
  25275. h3.copyTo(result,24);
  25276. h4.copyTo(result,32);
  25277. h5.copyTo(result,40);
  25278. h6.copyTo(result,48);
  25279. h7.copyTo(result,56);
  25280. }
  25281. else {
  25282. result = new Uint8Array(48);
  25283. h0.copyTo(result,0);
  25284. h1.copyTo(result,8);
  25285. h2.copyTo(result,16);
  25286. h3.copyTo(result,24);
  25287. h4.copyTo(result,32);
  25288. h5.copyTo(result,40);
  25289. }
  25290. return result;
  25291. }
  25292. return hash;
  25293. })();
  25294. var calculateSHA384 = (function calculateSHA384Closure() {
  25295. function hash(data, offset, length) {
  25296. return calculateSHA512(data, offset, length, true);
  25297. }
  25298. return hash;
  25299. })();
  25300. var NullCipher = (function NullCipherClosure() {
  25301. function NullCipher() {
  25302. }
  25303. NullCipher.prototype = {
  25304. decryptBlock: function NullCipher_decryptBlock(data) {
  25305. return data;
  25306. }
  25307. };
  25308. return NullCipher;
  25309. })();
  25310. var AES128Cipher = (function AES128CipherClosure() {
  25311. var rcon = new Uint8Array([
  25312. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25313. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25314. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25315. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25316. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  25317. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  25318. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  25319. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  25320. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  25321. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  25322. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  25323. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  25324. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  25325. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  25326. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  25327. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  25328. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  25329. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25330. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25331. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25332. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25333. 0x74, 0xe8, 0xcb, 0x8d]);
  25334. var s = new Uint8Array([
  25335. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  25336. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  25337. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  25338. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  25339. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  25340. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  25341. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  25342. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  25343. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  25344. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  25345. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  25346. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  25347. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  25348. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  25349. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  25350. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  25351. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  25352. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  25353. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  25354. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  25355. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  25356. 0xb0, 0x54, 0xbb, 0x16]);
  25357. var inv_s = new Uint8Array([
  25358. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  25359. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  25360. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  25361. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  25362. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  25363. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  25364. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  25365. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  25366. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  25367. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  25368. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  25369. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  25370. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  25371. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  25372. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  25373. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  25374. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  25375. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  25376. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  25377. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  25378. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  25379. 0x55, 0x21, 0x0c, 0x7d]);
  25380. var mixCol = new Uint8Array(256);
  25381. for (var i = 0; i < 256; i++) {
  25382. if (i < 128) {
  25383. mixCol[i] = i << 1;
  25384. } else {
  25385. mixCol[i] = (i << 1) ^ 0x1b;
  25386. }
  25387. }
  25388. var mix = new Uint32Array([
  25389. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  25390. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  25391. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  25392. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  25393. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  25394. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  25395. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  25396. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  25397. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  25398. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  25399. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  25400. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  25401. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  25402. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  25403. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  25404. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  25405. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  25406. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  25407. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  25408. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  25409. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  25410. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  25411. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  25412. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  25413. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  25414. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  25415. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  25416. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  25417. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  25418. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  25419. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  25420. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  25421. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  25422. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  25423. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  25424. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  25425. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  25426. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  25427. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  25428. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  25429. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  25430. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  25431. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  25432. function expandKey128(cipherKey) {
  25433. var b = 176, result = new Uint8Array(b);
  25434. result.set(cipherKey);
  25435. for (var j = 16, i = 1; j < b; ++i) {
  25436. // RotWord
  25437. var t1 = result[j - 3], t2 = result[j - 2],
  25438. t3 = result[j - 1], t4 = result[j - 4];
  25439. // SubWord
  25440. t1 = s[t1];
  25441. t2 = s[t2];
  25442. t3 = s[t3];
  25443. t4 = s[t4];
  25444. // Rcon
  25445. t1 = t1 ^ rcon[i];
  25446. for (var n = 0; n < 4; ++n) {
  25447. result[j] = (t1 ^= result[j - 16]);
  25448. j++;
  25449. result[j] = (t2 ^= result[j - 16]);
  25450. j++;
  25451. result[j] = (t3 ^= result[j - 16]);
  25452. j++;
  25453. result[j] = (t4 ^= result[j - 16]);
  25454. j++;
  25455. }
  25456. }
  25457. return result;
  25458. }
  25459. function decrypt128(input, key) {
  25460. var state = new Uint8Array(16);
  25461. state.set(input);
  25462. var i, j, k;
  25463. var t, u, v;
  25464. // AddRoundKey
  25465. for (j = 0, k = 160; j < 16; ++j, ++k) {
  25466. state[j] ^= key[k];
  25467. }
  25468. for (i = 9; i >= 1; --i) {
  25469. // InvShiftRows
  25470. t = state[13];
  25471. state[13] = state[9];
  25472. state[9] = state[5];
  25473. state[5] = state[1];
  25474. state[1] = t;
  25475. t = state[14];
  25476. u = state[10];
  25477. state[14] = state[6];
  25478. state[10] = state[2];
  25479. state[6] = t;
  25480. state[2] = u;
  25481. t = state[15];
  25482. u = state[11];
  25483. v = state[7];
  25484. state[15] = state[3];
  25485. state[11] = t;
  25486. state[7] = u;
  25487. state[3] = v;
  25488. // InvSubBytes
  25489. for (j = 0; j < 16; ++j) {
  25490. state[j] = inv_s[state[j]];
  25491. }
  25492. // AddRoundKey
  25493. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25494. state[j] ^= key[k];
  25495. }
  25496. // InvMixColumns
  25497. for (j = 0; j < 16; j += 4) {
  25498. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25499. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25500. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25501. (s3 >>> 24) ^ (s3 << 8));
  25502. state[j] = (t >>> 24) & 0xFF;
  25503. state[j + 1] = (t >> 16) & 0xFF;
  25504. state[j + 2] = (t >> 8) & 0xFF;
  25505. state[j + 3] = t & 0xFF;
  25506. }
  25507. }
  25508. // InvShiftRows
  25509. t = state[13];
  25510. state[13] = state[9];
  25511. state[9] = state[5];
  25512. state[5] = state[1];
  25513. state[1] = t;
  25514. t = state[14];
  25515. u = state[10];
  25516. state[14] = state[6];
  25517. state[10] = state[2];
  25518. state[6] = t;
  25519. state[2] = u;
  25520. t = state[15];
  25521. u = state[11];
  25522. v = state[7];
  25523. state[15] = state[3];
  25524. state[11] = t;
  25525. state[7] = u;
  25526. state[3] = v;
  25527. for (j = 0; j < 16; ++j) {
  25528. // InvSubBytes
  25529. state[j] = inv_s[state[j]];
  25530. // AddRoundKey
  25531. state[j] ^= key[j];
  25532. }
  25533. return state;
  25534. }
  25535. function encrypt128(input, key) {
  25536. var t, u, v, k;
  25537. var state = new Uint8Array(16);
  25538. state.set(input);
  25539. for (j = 0; j < 16; ++j) {
  25540. // AddRoundKey
  25541. state[j] ^= key[j];
  25542. }
  25543. for (i = 1; i < 10; i++) {
  25544. //SubBytes
  25545. for (j = 0; j < 16; ++j) {
  25546. state[j] = s[state[j]];
  25547. }
  25548. //ShiftRows
  25549. v = state[1];
  25550. state[1] = state[5];
  25551. state[5] = state[9];
  25552. state[9] = state[13];
  25553. state[13] = v;
  25554. v = state[2];
  25555. u = state[6];
  25556. state[2] = state[10];
  25557. state[6] = state[14];
  25558. state[10] = v;
  25559. state[14] = u;
  25560. v = state[3];
  25561. u = state[7];
  25562. t = state[11];
  25563. state[3] = state[15];
  25564. state[7] = v;
  25565. state[11] = u;
  25566. state[15] = t;
  25567. //MixColumns
  25568. for (var j = 0; j < 16; j += 4) {
  25569. var s0 = state[j + 0], s1 = state[j + 1];
  25570. var s2 = state[j + 2], s3 = state[j + 3];
  25571. t = s0 ^ s1 ^ s2 ^ s3;
  25572. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25573. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25574. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25575. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25576. }
  25577. //AddRoundKey
  25578. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25579. state[j] ^= key[k];
  25580. }
  25581. }
  25582. //SubBytes
  25583. for (j = 0; j < 16; ++j) {
  25584. state[j] = s[state[j]];
  25585. }
  25586. //ShiftRows
  25587. v = state[1];
  25588. state[1] = state[5];
  25589. state[5] = state[9];
  25590. state[9] = state[13];
  25591. state[13] = v;
  25592. v = state[2];
  25593. u = state[6];
  25594. state[2] = state[10];
  25595. state[6] = state[14];
  25596. state[10] = v;
  25597. state[14] = u;
  25598. v = state[3];
  25599. u = state[7];
  25600. t = state[11];
  25601. state[3] = state[15];
  25602. state[7] = v;
  25603. state[11] = u;
  25604. state[15] = t;
  25605. //AddRoundKey
  25606. for (j = 0, k = 160; j < 16; ++j, ++k) {
  25607. state[j] ^= key[k];
  25608. }
  25609. return state;
  25610. }
  25611. function AES128Cipher(key) {
  25612. this.key = expandKey128(key);
  25613. this.buffer = new Uint8Array(16);
  25614. this.bufferPosition = 0;
  25615. }
  25616. function decryptBlock2(data, finalize) {
  25617. var i, j, ii, sourceLength = data.length,
  25618. buffer = this.buffer, bufferLength = this.bufferPosition,
  25619. result = [], iv = this.iv;
  25620. for (i = 0; i < sourceLength; ++i) {
  25621. buffer[bufferLength] = data[i];
  25622. ++bufferLength;
  25623. if (bufferLength < 16) {
  25624. continue;
  25625. }
  25626. // buffer is full, decrypting
  25627. var plain = decrypt128(buffer, this.key);
  25628. // xor-ing the IV vector to get plain text
  25629. for (j = 0; j < 16; ++j) {
  25630. plain[j] ^= iv[j];
  25631. }
  25632. iv = buffer;
  25633. result.push(plain);
  25634. buffer = new Uint8Array(16);
  25635. bufferLength = 0;
  25636. }
  25637. // saving incomplete buffer
  25638. this.buffer = buffer;
  25639. this.bufferLength = bufferLength;
  25640. this.iv = iv;
  25641. if (result.length === 0) {
  25642. return new Uint8Array([]);
  25643. }
  25644. // combining plain text blocks into one
  25645. var outputLength = 16 * result.length;
  25646. if (finalize) {
  25647. // undo a padding that is described in RFC 2898
  25648. var lastBlock = result[result.length - 1];
  25649. var psLen = lastBlock[15];
  25650. if (psLen <= 16) {
  25651. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  25652. if (lastBlock[i] !== psLen) {
  25653. // Invalid padding, assume that the block has no padding.
  25654. psLen = 0;
  25655. break;
  25656. }
  25657. }
  25658. outputLength -= psLen;
  25659. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  25660. }
  25661. }
  25662. var output = new Uint8Array(outputLength);
  25663. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25664. output.set(result[i], j);
  25665. }
  25666. return output;
  25667. }
  25668. AES128Cipher.prototype = {
  25669. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  25670. var i, sourceLength = data.length;
  25671. var buffer = this.buffer, bufferLength = this.bufferPosition;
  25672. // waiting for IV values -- they are at the start of the stream
  25673. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  25674. buffer[bufferLength] = data[i];
  25675. }
  25676. if (bufferLength < 16) {
  25677. // need more data
  25678. this.bufferLength = bufferLength;
  25679. return new Uint8Array([]);
  25680. }
  25681. this.iv = buffer;
  25682. this.buffer = new Uint8Array(16);
  25683. this.bufferLength = 0;
  25684. // starting decryption
  25685. this.decryptBlock = decryptBlock2;
  25686. return this.decryptBlock(data.subarray(16), finalize);
  25687. },
  25688. encrypt: function AES128Cipher_encrypt(data, iv) {
  25689. var i, j, ii, sourceLength = data.length,
  25690. buffer = this.buffer, bufferLength = this.bufferPosition,
  25691. result = [];
  25692. if (!iv) {
  25693. iv = new Uint8Array(16);
  25694. }
  25695. for (i = 0; i < sourceLength; ++i) {
  25696. buffer[bufferLength] = data[i];
  25697. ++bufferLength;
  25698. if (bufferLength < 16) {
  25699. continue;
  25700. }
  25701. for (j = 0; j < 16; ++j) {
  25702. buffer[j] ^= iv[j];
  25703. }
  25704. // buffer is full, encrypting
  25705. var cipher = encrypt128(buffer, this.key);
  25706. iv = cipher;
  25707. result.push(cipher);
  25708. buffer = new Uint8Array(16);
  25709. bufferLength = 0;
  25710. }
  25711. // saving incomplete buffer
  25712. this.buffer = buffer;
  25713. this.bufferLength = bufferLength;
  25714. this.iv = iv;
  25715. if (result.length === 0) {
  25716. return new Uint8Array([]);
  25717. }
  25718. // combining plain text blocks into one
  25719. var outputLength = 16 * result.length;
  25720. var output = new Uint8Array(outputLength);
  25721. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25722. output.set(result[i], j);
  25723. }
  25724. return output;
  25725. }
  25726. };
  25727. return AES128Cipher;
  25728. })();
  25729. var AES256Cipher = (function AES256CipherClosure() {
  25730. var rcon = new Uint8Array([
  25731. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25732. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25733. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25734. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25735. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  25736. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  25737. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  25738. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  25739. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  25740. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  25741. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  25742. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  25743. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  25744. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  25745. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  25746. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  25747. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  25748. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  25749. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  25750. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  25751. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  25752. 0x74, 0xe8, 0xcb, 0x8d]);
  25753. var s = new Uint8Array([
  25754. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  25755. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  25756. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  25757. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  25758. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  25759. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  25760. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  25761. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  25762. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  25763. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  25764. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  25765. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  25766. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  25767. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  25768. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  25769. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  25770. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  25771. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  25772. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  25773. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  25774. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  25775. 0xb0, 0x54, 0xbb, 0x16]);
  25776. var inv_s = new Uint8Array([
  25777. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  25778. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  25779. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  25780. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  25781. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  25782. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  25783. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  25784. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  25785. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  25786. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  25787. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  25788. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  25789. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  25790. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  25791. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  25792. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  25793. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  25794. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  25795. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  25796. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  25797. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  25798. 0x55, 0x21, 0x0c, 0x7d]);
  25799. var mixCol = new Uint8Array(256);
  25800. for (var i = 0; i < 256; i++) {
  25801. if (i < 128) {
  25802. mixCol[i] = i << 1;
  25803. } else {
  25804. mixCol[i] = (i << 1) ^ 0x1b;
  25805. }
  25806. }
  25807. var mix = new Uint32Array([
  25808. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  25809. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  25810. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  25811. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  25812. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  25813. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  25814. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  25815. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  25816. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  25817. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  25818. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  25819. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  25820. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  25821. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  25822. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  25823. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  25824. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  25825. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  25826. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  25827. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  25828. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  25829. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  25830. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  25831. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  25832. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  25833. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  25834. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  25835. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  25836. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  25837. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  25838. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  25839. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  25840. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  25841. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  25842. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  25843. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  25844. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  25845. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  25846. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  25847. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  25848. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  25849. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  25850. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  25851. function expandKey256(cipherKey) {
  25852. var b = 240, result = new Uint8Array(b);
  25853. var r = 1;
  25854. result.set(cipherKey);
  25855. for (var j = 32, i = 1; j < b; ++i) {
  25856. if (j % 32 === 16) {
  25857. t1 = s[t1];
  25858. t2 = s[t2];
  25859. t3 = s[t3];
  25860. t4 = s[t4];
  25861. } else if (j % 32 === 0) {
  25862. // RotWord
  25863. var t1 = result[j - 3], t2 = result[j - 2],
  25864. t3 = result[j - 1], t4 = result[j - 4];
  25865. // SubWord
  25866. t1 = s[t1];
  25867. t2 = s[t2];
  25868. t3 = s[t3];
  25869. t4 = s[t4];
  25870. // Rcon
  25871. t1 = t1 ^ r;
  25872. if ((r <<= 1) >= 256) {
  25873. r = (r ^ 0x1b) & 0xFF;
  25874. }
  25875. }
  25876. for (var n = 0; n < 4; ++n) {
  25877. result[j] = (t1 ^= result[j - 32]);
  25878. j++;
  25879. result[j] = (t2 ^= result[j - 32]);
  25880. j++;
  25881. result[j] = (t3 ^= result[j - 32]);
  25882. j++;
  25883. result[j] = (t4 ^= result[j - 32]);
  25884. j++;
  25885. }
  25886. }
  25887. return result;
  25888. }
  25889. function decrypt256(input, key) {
  25890. var state = new Uint8Array(16);
  25891. state.set(input);
  25892. var i, j, k;
  25893. var t, u, v;
  25894. // AddRoundKey
  25895. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25896. state[j] ^= key[k];
  25897. }
  25898. for (i = 13; i >= 1; --i) {
  25899. // InvShiftRows
  25900. t = state[13];
  25901. state[13] = state[9];
  25902. state[9] = state[5];
  25903. state[5] = state[1];
  25904. state[1] = t;
  25905. t = state[14];
  25906. u = state[10];
  25907. state[14] = state[6];
  25908. state[10] = state[2];
  25909. state[6] = t;
  25910. state[2] = u;
  25911. t = state[15];
  25912. u = state[11];
  25913. v = state[7];
  25914. state[15] = state[3];
  25915. state[11] = t;
  25916. state[7] = u;
  25917. state[3] = v;
  25918. // InvSubBytes
  25919. for (j = 0; j < 16; ++j) {
  25920. state[j] = inv_s[state[j]];
  25921. }
  25922. // AddRoundKey
  25923. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25924. state[j] ^= key[k];
  25925. }
  25926. // InvMixColumns
  25927. for (j = 0; j < 16; j += 4) {
  25928. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25929. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25930. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25931. (s3 >>> 24) ^ (s3 << 8));
  25932. state[j] = (t >>> 24) & 0xFF;
  25933. state[j + 1] = (t >> 16) & 0xFF;
  25934. state[j + 2] = (t >> 8) & 0xFF;
  25935. state[j + 3] = t & 0xFF;
  25936. }
  25937. }
  25938. // InvShiftRows
  25939. t = state[13];
  25940. state[13] = state[9];
  25941. state[9] = state[5];
  25942. state[5] = state[1];
  25943. state[1] = t;
  25944. t = state[14];
  25945. u = state[10];
  25946. state[14] = state[6];
  25947. state[10] = state[2];
  25948. state[6] = t;
  25949. state[2] = u;
  25950. t = state[15];
  25951. u = state[11];
  25952. v = state[7];
  25953. state[15] = state[3];
  25954. state[11] = t;
  25955. state[7] = u;
  25956. state[3] = v;
  25957. for (j = 0; j < 16; ++j) {
  25958. // InvSubBytes
  25959. state[j] = inv_s[state[j]];
  25960. // AddRoundKey
  25961. state[j] ^= key[j];
  25962. }
  25963. return state;
  25964. }
  25965. function encrypt256(input, key) {
  25966. var t, u, v, k;
  25967. var state = new Uint8Array(16);
  25968. state.set(input);
  25969. for (j = 0; j < 16; ++j) {
  25970. // AddRoundKey
  25971. state[j] ^= key[j];
  25972. }
  25973. for (i = 1; i < 14; i++) {
  25974. //SubBytes
  25975. for (j = 0; j < 16; ++j) {
  25976. state[j] = s[state[j]];
  25977. }
  25978. //ShiftRows
  25979. v = state[1];
  25980. state[1] = state[5];
  25981. state[5] = state[9];
  25982. state[9] = state[13];
  25983. state[13] = v;
  25984. v = state[2];
  25985. u = state[6];
  25986. state[2] = state[10];
  25987. state[6] = state[14];
  25988. state[10] = v;
  25989. state[14] = u;
  25990. v = state[3];
  25991. u = state[7];
  25992. t = state[11];
  25993. state[3] = state[15];
  25994. state[7] = v;
  25995. state[11] = u;
  25996. state[15] = t;
  25997. //MixColumns
  25998. for (var j = 0; j < 16; j += 4) {
  25999. var s0 = state[j + 0], s1 = state[j + 1];
  26000. var s2 = state[j + 2], s3 = state[j + 3];
  26001. t = s0 ^ s1 ^ s2 ^ s3;
  26002. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  26003. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  26004. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  26005. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  26006. }
  26007. //AddRoundKey
  26008. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  26009. state[j] ^= key[k];
  26010. }
  26011. }
  26012. //SubBytes
  26013. for (j = 0; j < 16; ++j) {
  26014. state[j] = s[state[j]];
  26015. }
  26016. //ShiftRows
  26017. v = state[1];
  26018. state[1] = state[5];
  26019. state[5] = state[9];
  26020. state[9] = state[13];
  26021. state[13] = v;
  26022. v = state[2];
  26023. u = state[6];
  26024. state[2] = state[10];
  26025. state[6] = state[14];
  26026. state[10] = v;
  26027. state[14] = u;
  26028. v = state[3];
  26029. u = state[7];
  26030. t = state[11];
  26031. state[3] = state[15];
  26032. state[7] = v;
  26033. state[11] = u;
  26034. state[15] = t;
  26035. //AddRoundKey
  26036. for (j = 0, k = 224; j < 16; ++j, ++k) {
  26037. state[j] ^= key[k];
  26038. }
  26039. return state;
  26040. }
  26041. function AES256Cipher(key) {
  26042. this.key = expandKey256(key);
  26043. this.buffer = new Uint8Array(16);
  26044. this.bufferPosition = 0;
  26045. }
  26046. function decryptBlock2(data, finalize) {
  26047. var i, j, ii, sourceLength = data.length,
  26048. buffer = this.buffer, bufferLength = this.bufferPosition,
  26049. result = [], iv = this.iv;
  26050. for (i = 0; i < sourceLength; ++i) {
  26051. buffer[bufferLength] = data[i];
  26052. ++bufferLength;
  26053. if (bufferLength < 16) {
  26054. continue;
  26055. }
  26056. // buffer is full, decrypting
  26057. var plain = decrypt256(buffer, this.key);
  26058. // xor-ing the IV vector to get plain text
  26059. for (j = 0; j < 16; ++j) {
  26060. plain[j] ^= iv[j];
  26061. }
  26062. iv = buffer;
  26063. result.push(plain);
  26064. buffer = new Uint8Array(16);
  26065. bufferLength = 0;
  26066. }
  26067. // saving incomplete buffer
  26068. this.buffer = buffer;
  26069. this.bufferLength = bufferLength;
  26070. this.iv = iv;
  26071. if (result.length === 0) {
  26072. return new Uint8Array([]);
  26073. }
  26074. // combining plain text blocks into one
  26075. var outputLength = 16 * result.length;
  26076. if (finalize) {
  26077. // undo a padding that is described in RFC 2898
  26078. var lastBlock = result[result.length - 1];
  26079. var psLen = lastBlock[15];
  26080. if (psLen <= 16) {
  26081. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  26082. if (lastBlock[i] !== psLen) {
  26083. // Invalid padding, assume that the block has no padding.
  26084. psLen = 0;
  26085. break;
  26086. }
  26087. }
  26088. outputLength -= psLen;
  26089. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  26090. }
  26091. }
  26092. var output = new Uint8Array(outputLength);
  26093. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  26094. output.set(result[i], j);
  26095. }
  26096. return output;
  26097. }
  26098. AES256Cipher.prototype = {
  26099. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  26100. var i, sourceLength = data.length;
  26101. var buffer = this.buffer, bufferLength = this.bufferPosition;
  26102. // if not supplied an IV wait for IV values
  26103. // they are at the start of the stream
  26104. if (iv) {
  26105. this.iv = iv;
  26106. } else {
  26107. for (i = 0; bufferLength < 16 &&
  26108. i < sourceLength; ++i, ++bufferLength) {
  26109. buffer[bufferLength] = data[i];
  26110. }
  26111. if (bufferLength < 16) {
  26112. //need more data
  26113. this.bufferLength = bufferLength;
  26114. return new Uint8Array([]);
  26115. }
  26116. this.iv = buffer;
  26117. data = data.subarray(16);
  26118. }
  26119. this.buffer = new Uint8Array(16);
  26120. this.bufferLength = 0;
  26121. // starting decryption
  26122. this.decryptBlock = decryptBlock2;
  26123. return this.decryptBlock(data, finalize);
  26124. },
  26125. encrypt: function AES256Cipher_encrypt(data, iv) {
  26126. var i, j, ii, sourceLength = data.length,
  26127. buffer = this.buffer, bufferLength = this.bufferPosition,
  26128. result = [];
  26129. if (!iv) {
  26130. iv = new Uint8Array(16);
  26131. }
  26132. for (i = 0; i < sourceLength; ++i) {
  26133. buffer[bufferLength] = data[i];
  26134. ++bufferLength;
  26135. if (bufferLength < 16) {
  26136. continue;
  26137. }
  26138. for (j = 0; j < 16; ++j) {
  26139. buffer[j] ^= iv[j];
  26140. }
  26141. // buffer is full, encrypting
  26142. var cipher = encrypt256(buffer, this.key);
  26143. this.iv = cipher;
  26144. result.push(cipher);
  26145. buffer = new Uint8Array(16);
  26146. bufferLength = 0;
  26147. }
  26148. // saving incomplete buffer
  26149. this.buffer = buffer;
  26150. this.bufferLength = bufferLength;
  26151. this.iv = iv;
  26152. if (result.length === 0) {
  26153. return new Uint8Array([]);
  26154. }
  26155. // combining plain text blocks into one
  26156. var outputLength = 16 * result.length;
  26157. var output = new Uint8Array(outputLength);
  26158. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  26159. output.set(result[i], j);
  26160. }
  26161. return output;
  26162. }
  26163. };
  26164. return AES256Cipher;
  26165. })();
  26166. var PDF17 = (function PDF17Closure() {
  26167. function compareByteArrays(array1, array2) {
  26168. if (array1.length !== array2.length) {
  26169. return false;
  26170. }
  26171. for (var i = 0; i < array1.length; i++) {
  26172. if (array1[i] !== array2[i]) {
  26173. return false;
  26174. }
  26175. }
  26176. return true;
  26177. }
  26178. function PDF17() {
  26179. }
  26180. PDF17.prototype = {
  26181. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  26182. ownerValidationSalt,
  26183. userBytes,
  26184. ownerPassword) {
  26185. var hashData = new Uint8Array(password.length + 56);
  26186. hashData.set(password, 0);
  26187. hashData.set(ownerValidationSalt, password.length);
  26188. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  26189. var result = calculateSHA256(hashData, 0, hashData.length);
  26190. return compareByteArrays(result, ownerPassword);
  26191. },
  26192. checkUserPassword: function PDF17_checkUserPassword(password,
  26193. userValidationSalt,
  26194. userPassword) {
  26195. var hashData = new Uint8Array(password.length + 8);
  26196. hashData.set(password, 0);
  26197. hashData.set(userValidationSalt, password.length);
  26198. var result = calculateSHA256(hashData, 0, hashData.length);
  26199. return compareByteArrays(result, userPassword);
  26200. },
  26201. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  26202. ownerEncryption) {
  26203. var hashData = new Uint8Array(password.length + 56);
  26204. hashData.set(password, 0);
  26205. hashData.set(ownerKeySalt, password.length);
  26206. hashData.set(userBytes, password.length + ownerKeySalt.length);
  26207. var key = calculateSHA256(hashData, 0, hashData.length);
  26208. var cipher = new AES256Cipher(key);
  26209. return cipher.decryptBlock(ownerEncryption,
  26210. false,
  26211. new Uint8Array(16));
  26212. },
  26213. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  26214. userEncryption) {
  26215. var hashData = new Uint8Array(password.length + 8);
  26216. hashData.set(password, 0);
  26217. hashData.set(userKeySalt, password.length);
  26218. //key is the decryption key for the UE string
  26219. var key = calculateSHA256(hashData, 0, hashData.length);
  26220. var cipher = new AES256Cipher(key);
  26221. return cipher.decryptBlock(userEncryption,
  26222. false,
  26223. new Uint8Array(16));
  26224. }
  26225. };
  26226. return PDF17;
  26227. })();
  26228. var PDF20 = (function PDF20Closure() {
  26229. function concatArrays(array1, array2) {
  26230. var t = new Uint8Array(array1.length + array2.length);
  26231. t.set(array1, 0);
  26232. t.set(array2, array1.length);
  26233. return t;
  26234. }
  26235. function calculatePDF20Hash(password, input, userBytes) {
  26236. //This refers to Algorithm 2.B as defined in ISO 32000-2
  26237. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  26238. var e = [0];
  26239. var i = 0;
  26240. while (i < 64 || e[e.length - 1] > i - 32) {
  26241. var arrayLength = password.length + k.length + userBytes.length;
  26242. var k1 = new Uint8Array(arrayLength * 64);
  26243. var array = concatArrays(password, k);
  26244. array = concatArrays(array, userBytes);
  26245. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  26246. k1.set(array, pos);
  26247. }
  26248. //AES128 CBC NO PADDING with
  26249. //first 16 bytes of k as the key and the second 16 as the iv.
  26250. var cipher = new AES128Cipher(k.subarray(0, 16));
  26251. e = cipher.encrypt(k1, k.subarray(16, 32));
  26252. //Now we have to take the first 16 bytes of an unsigned
  26253. //big endian integer... and compute the remainder
  26254. //modulo 3.... That is a fairly large number and
  26255. //JavaScript isn't going to handle that well...
  26256. //So we're using a trick that allows us to perform
  26257. //modulo math byte by byte
  26258. var remainder = 0;
  26259. for (var z = 0; z < 16; z++) {
  26260. remainder *= (256 % 3);
  26261. remainder %= 3;
  26262. remainder += ((e[z] >>> 0) % 3);
  26263. remainder %= 3;
  26264. }
  26265. if (remainder === 0) {
  26266. k = calculateSHA256(e, 0, e.length);
  26267. }
  26268. else if (remainder === 1) {
  26269. k = calculateSHA384(e, 0, e.length);
  26270. }
  26271. else if (remainder === 2) {
  26272. k = calculateSHA512(e, 0, e.length);
  26273. }
  26274. i++;
  26275. }
  26276. return k.subarray(0, 32);
  26277. }
  26278. function PDF20() {
  26279. }
  26280. function compareByteArrays(array1, array2) {
  26281. if (array1.length !== array2.length) {
  26282. return false;
  26283. }
  26284. for (var i = 0; i < array1.length; i++) {
  26285. if (array1[i] !== array2[i]) {
  26286. return false;
  26287. }
  26288. }
  26289. return true;
  26290. }
  26291. PDF20.prototype = {
  26292. hash: function PDF20_hash(password, concatBytes, userBytes) {
  26293. return calculatePDF20Hash(password, concatBytes, userBytes);
  26294. },
  26295. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  26296. ownerValidationSalt,
  26297. userBytes,
  26298. ownerPassword) {
  26299. var hashData = new Uint8Array(password.length + 56);
  26300. hashData.set(password, 0);
  26301. hashData.set(ownerValidationSalt, password.length);
  26302. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  26303. var result = calculatePDF20Hash(password, hashData, userBytes);
  26304. return compareByteArrays(result, ownerPassword);
  26305. },
  26306. checkUserPassword: function PDF20_checkUserPassword(password,
  26307. userValidationSalt,
  26308. userPassword) {
  26309. var hashData = new Uint8Array(password.length + 8);
  26310. hashData.set(password, 0);
  26311. hashData.set(userValidationSalt, password.length);
  26312. var result = calculatePDF20Hash(password, hashData, []);
  26313. return compareByteArrays(result, userPassword);
  26314. },
  26315. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  26316. ownerEncryption) {
  26317. var hashData = new Uint8Array(password.length + 56);
  26318. hashData.set(password, 0);
  26319. hashData.set(ownerKeySalt, password.length);
  26320. hashData.set(userBytes, password.length + ownerKeySalt.length);
  26321. var key = calculatePDF20Hash(password, hashData, userBytes);
  26322. var cipher = new AES256Cipher(key);
  26323. return cipher.decryptBlock(ownerEncryption,
  26324. false,
  26325. new Uint8Array(16));
  26326. },
  26327. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  26328. userEncryption) {
  26329. var hashData = new Uint8Array(password.length + 8);
  26330. hashData.set(password, 0);
  26331. hashData.set(userKeySalt, password.length);
  26332. //key is the decryption key for the UE string
  26333. var key = calculatePDF20Hash(password, hashData, []);
  26334. var cipher = new AES256Cipher(key);
  26335. return cipher.decryptBlock(userEncryption,
  26336. false,
  26337. new Uint8Array(16));
  26338. }
  26339. };
  26340. return PDF20;
  26341. })();
  26342. var CipherTransform = (function CipherTransformClosure() {
  26343. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  26344. this.stringCipherConstructor = stringCipherConstructor;
  26345. this.streamCipherConstructor = streamCipherConstructor;
  26346. }
  26347. CipherTransform.prototype = {
  26348. createStream: function CipherTransform_createStream(stream, length) {
  26349. var cipher = new this.streamCipherConstructor();
  26350. return new DecryptStream(stream, length,
  26351. function cipherTransformDecryptStream(data, finalize) {
  26352. return cipher.decryptBlock(data, finalize);
  26353. }
  26354. );
  26355. },
  26356. decryptString: function CipherTransform_decryptString(s) {
  26357. var cipher = new this.stringCipherConstructor();
  26358. var data = stringToBytes(s);
  26359. data = cipher.decryptBlock(data, true);
  26360. return bytesToString(data);
  26361. }
  26362. };
  26363. return CipherTransform;
  26364. })();
  26365. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  26366. var defaultPasswordBytes = new Uint8Array([
  26367. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  26368. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  26369. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  26370. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  26371. function createEncryptionKey20(revision, password, ownerPassword,
  26372. ownerValidationSalt, ownerKeySalt, uBytes,
  26373. userPassword, userValidationSalt, userKeySalt,
  26374. ownerEncryption, userEncryption, perms) {
  26375. if (password) {
  26376. var passwordLength = Math.min(127, password.length);
  26377. password = password.subarray(0, passwordLength);
  26378. } else {
  26379. password = [];
  26380. }
  26381. var pdfAlgorithm;
  26382. if (revision === 6) {
  26383. pdfAlgorithm = new PDF20();
  26384. } else {
  26385. pdfAlgorithm = new PDF17();
  26386. }
  26387. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  26388. userPassword)) {
  26389. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  26390. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  26391. ownerValidationSalt,
  26392. uBytes,
  26393. ownerPassword)) {
  26394. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  26395. ownerEncryption);
  26396. }
  26397. return null;
  26398. }
  26399. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  26400. flags, revision, keyLength, encryptMetadata) {
  26401. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  26402. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  26403. if (password) {
  26404. n = Math.min(32, password.length);
  26405. for (; i < n; ++i) {
  26406. hashData[i] = password[i];
  26407. }
  26408. }
  26409. j = 0;
  26410. while (i < 32) {
  26411. hashData[i++] = defaultPasswordBytes[j++];
  26412. }
  26413. // as now the padded password in the hashData[0..i]
  26414. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  26415. hashData[i++] = ownerPassword[j];
  26416. }
  26417. hashData[i++] = flags & 0xFF;
  26418. hashData[i++] = (flags >> 8) & 0xFF;
  26419. hashData[i++] = (flags >> 16) & 0xFF;
  26420. hashData[i++] = (flags >>> 24) & 0xFF;
  26421. for (j = 0, n = fileId.length; j < n; ++j) {
  26422. hashData[i++] = fileId[j];
  26423. }
  26424. if (revision >= 4 && !encryptMetadata) {
  26425. hashData[i++] = 0xFF;
  26426. hashData[i++] = 0xFF;
  26427. hashData[i++] = 0xFF;
  26428. hashData[i++] = 0xFF;
  26429. }
  26430. var hash = calculateMD5(hashData, 0, i);
  26431. var keyLengthInBytes = keyLength >> 3;
  26432. if (revision >= 3) {
  26433. for (j = 0; j < 50; ++j) {
  26434. hash = calculateMD5(hash, 0, keyLengthInBytes);
  26435. }
  26436. }
  26437. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  26438. var cipher, checkData;
  26439. if (revision >= 3) {
  26440. for (i = 0; i < 32; ++i) {
  26441. hashData[i] = defaultPasswordBytes[i];
  26442. }
  26443. for (j = 0, n = fileId.length; j < n; ++j) {
  26444. hashData[i++] = fileId[j];
  26445. }
  26446. cipher = new ARCFourCipher(encryptionKey);
  26447. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  26448. n = encryptionKey.length;
  26449. var derivedKey = new Uint8Array(n), k;
  26450. for (j = 1; j <= 19; ++j) {
  26451. for (k = 0; k < n; ++k) {
  26452. derivedKey[k] = encryptionKey[k] ^ j;
  26453. }
  26454. cipher = new ARCFourCipher(derivedKey);
  26455. checkData = cipher.encryptBlock(checkData);
  26456. }
  26457. for (j = 0, n = checkData.length; j < n; ++j) {
  26458. if (userPassword[j] !== checkData[j]) {
  26459. return null;
  26460. }
  26461. }
  26462. } else {
  26463. cipher = new ARCFourCipher(encryptionKey);
  26464. checkData = cipher.encryptBlock(defaultPasswordBytes);
  26465. for (j = 0, n = checkData.length; j < n; ++j) {
  26466. if (userPassword[j] !== checkData[j]) {
  26467. return null;
  26468. }
  26469. }
  26470. }
  26471. return encryptionKey;
  26472. }
  26473. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  26474. var hashData = new Uint8Array(32), i = 0, j, n;
  26475. n = Math.min(32, password.length);
  26476. for (; i < n; ++i) {
  26477. hashData[i] = password[i];
  26478. }
  26479. j = 0;
  26480. while (i < 32) {
  26481. hashData[i++] = defaultPasswordBytes[j++];
  26482. }
  26483. var hash = calculateMD5(hashData, 0, i);
  26484. var keyLengthInBytes = keyLength >> 3;
  26485. if (revision >= 3) {
  26486. for (j = 0; j < 50; ++j) {
  26487. hash = calculateMD5(hash, 0, hash.length);
  26488. }
  26489. }
  26490. var cipher, userPassword;
  26491. if (revision >= 3) {
  26492. userPassword = ownerPassword;
  26493. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  26494. for (j = 19; j >= 0; j--) {
  26495. for (k = 0; k < keyLengthInBytes; ++k) {
  26496. derivedKey[k] = hash[k] ^ j;
  26497. }
  26498. cipher = new ARCFourCipher(derivedKey);
  26499. userPassword = cipher.encryptBlock(userPassword);
  26500. }
  26501. } else {
  26502. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  26503. userPassword = cipher.encryptBlock(ownerPassword);
  26504. }
  26505. return userPassword;
  26506. }
  26507. var identityName = Name.get('Identity');
  26508. function CipherTransformFactory(dict, fileId, password) {
  26509. var filter = dict.get('Filter');
  26510. if (!isName(filter, 'Standard')) {
  26511. error('unknown encryption method');
  26512. }
  26513. this.dict = dict;
  26514. var algorithm = dict.get('V');
  26515. if (!isInt(algorithm) ||
  26516. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  26517. algorithm !== 5)) {
  26518. error('unsupported encryption algorithm');
  26519. }
  26520. this.algorithm = algorithm;
  26521. var keyLength = dict.get('Length');
  26522. if (!keyLength) {
  26523. // Spec asks to rely on encryption dictionary's Length entry, however
  26524. // some PDFs don't have it. Trying to recover.
  26525. if (algorithm <= 3) {
  26526. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  26527. keyLength = 40;
  26528. } else {
  26529. // Trying to find default handler -- it usually has Length.
  26530. var cfDict = dict.get('CF');
  26531. var streamCryptoName = dict.get('StmF');
  26532. if (isDict(cfDict) && isName(streamCryptoName)) {
  26533. var handlerDict = cfDict.get(streamCryptoName.name);
  26534. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  26535. if (keyLength < 40) {
  26536. // Sometimes it's incorrect value of bits, generators specify bytes.
  26537. keyLength <<= 3;
  26538. }
  26539. }
  26540. }
  26541. }
  26542. if (!isInt(keyLength) ||
  26543. keyLength < 40 || (keyLength % 8) !== 0) {
  26544. error('invalid key length');
  26545. }
  26546. // prepare keys
  26547. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  26548. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  26549. var flags = dict.get('P');
  26550. var revision = dict.get('R');
  26551. // meaningful when V is 4 or 5
  26552. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  26553. dict.get('EncryptMetadata') !== false);
  26554. this.encryptMetadata = encryptMetadata;
  26555. var fileIdBytes = stringToBytes(fileId);
  26556. var passwordBytes;
  26557. if (password) {
  26558. if (revision === 6) {
  26559. try {
  26560. password = utf8StringToString(password);
  26561. } catch (ex) {
  26562. warn('CipherTransformFactory: ' +
  26563. 'Unable to convert UTF8 encoded password.');
  26564. }
  26565. }
  26566. passwordBytes = stringToBytes(password);
  26567. }
  26568. var encryptionKey;
  26569. if (algorithm !== 5) {
  26570. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  26571. ownerPassword, userPassword, flags,
  26572. revision, keyLength, encryptMetadata);
  26573. }
  26574. else {
  26575. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  26576. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  26577. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  26578. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  26579. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  26580. var ownerEncryption = stringToBytes(dict.get('OE'));
  26581. var userEncryption = stringToBytes(dict.get('UE'));
  26582. var perms = stringToBytes(dict.get('Perms'));
  26583. encryptionKey =
  26584. createEncryptionKey20(revision, passwordBytes,
  26585. ownerPassword, ownerValidationSalt,
  26586. ownerKeySalt, uBytes,
  26587. userPassword, userValidationSalt,
  26588. userKeySalt, ownerEncryption,
  26589. userEncryption, perms);
  26590. }
  26591. if (!encryptionKey && !password) {
  26592. throw new PasswordException('No password given',
  26593. PasswordResponses.NEED_PASSWORD);
  26594. } else if (!encryptionKey && password) {
  26595. // Attempting use the password as an owner password
  26596. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  26597. revision, keyLength);
  26598. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  26599. ownerPassword, userPassword, flags,
  26600. revision, keyLength, encryptMetadata);
  26601. }
  26602. if (!encryptionKey) {
  26603. throw new PasswordException('Incorrect Password',
  26604. PasswordResponses.INCORRECT_PASSWORD);
  26605. }
  26606. this.encryptionKey = encryptionKey;
  26607. if (algorithm >= 4) {
  26608. this.cf = dict.get('CF');
  26609. this.stmf = dict.get('StmF') || identityName;
  26610. this.strf = dict.get('StrF') || identityName;
  26611. this.eff = dict.get('EFF') || this.stmf;
  26612. }
  26613. }
  26614. function buildObjectKey(num, gen, encryptionKey, isAes) {
  26615. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  26616. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  26617. key[i] = encryptionKey[i];
  26618. }
  26619. key[i++] = num & 0xFF;
  26620. key[i++] = (num >> 8) & 0xFF;
  26621. key[i++] = (num >> 16) & 0xFF;
  26622. key[i++] = gen & 0xFF;
  26623. key[i++] = (gen >> 8) & 0xFF;
  26624. if (isAes) {
  26625. key[i++] = 0x73;
  26626. key[i++] = 0x41;
  26627. key[i++] = 0x6C;
  26628. key[i++] = 0x54;
  26629. }
  26630. var hash = calculateMD5(key, 0, i);
  26631. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  26632. }
  26633. function buildCipherConstructor(cf, name, num, gen, key) {
  26634. var cryptFilter = cf.get(name.name);
  26635. var cfm;
  26636. if (cryptFilter !== null && cryptFilter !== undefined) {
  26637. cfm = cryptFilter.get('CFM');
  26638. }
  26639. if (!cfm || cfm.name === 'None') {
  26640. return function cipherTransformFactoryBuildCipherConstructorNone() {
  26641. return new NullCipher();
  26642. };
  26643. }
  26644. if ('V2' === cfm.name) {
  26645. return function cipherTransformFactoryBuildCipherConstructorV2() {
  26646. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  26647. };
  26648. }
  26649. if ('AESV2' === cfm.name) {
  26650. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  26651. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  26652. };
  26653. }
  26654. if ('AESV3' === cfm.name) {
  26655. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  26656. return new AES256Cipher(key);
  26657. };
  26658. }
  26659. error('Unknown crypto method');
  26660. }
  26661. CipherTransformFactory.prototype = {
  26662. createCipherTransform:
  26663. function CipherTransformFactory_createCipherTransform(num, gen) {
  26664. if (this.algorithm === 4 || this.algorithm === 5) {
  26665. return new CipherTransform(
  26666. buildCipherConstructor(this.cf, this.stmf,
  26667. num, gen, this.encryptionKey),
  26668. buildCipherConstructor(this.cf, this.strf,
  26669. num, gen, this.encryptionKey));
  26670. }
  26671. // algorithms 1 and 2
  26672. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  26673. var cipherConstructor = function buildCipherCipherConstructor() {
  26674. return new ARCFourCipher(key);
  26675. };
  26676. return new CipherTransform(cipherConstructor, cipherConstructor);
  26677. }
  26678. };
  26679. return CipherTransformFactory;
  26680. })();
  26681. exports.AES128Cipher = AES128Cipher;
  26682. exports.AES256Cipher = AES256Cipher;
  26683. exports.ARCFourCipher = ARCFourCipher;
  26684. exports.CipherTransformFactory = CipherTransformFactory;
  26685. exports.PDF17 = PDF17;
  26686. exports.PDF20 = PDF20;
  26687. exports.calculateMD5 = calculateMD5;
  26688. exports.calculateSHA256 = calculateSHA256;
  26689. exports.calculateSHA384 = calculateSHA384;
  26690. exports.calculateSHA512 = calculateSHA512;
  26691. }));
  26692. (function (root, factory) {
  26693. {
  26694. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  26695. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  26696. root.pdfjsCoreCFFParser);
  26697. }
  26698. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  26699. coreEncodings, coreCFFParser) {
  26700. var Util = sharedUtil.Util;
  26701. var bytesToString = sharedUtil.bytesToString;
  26702. var error = sharedUtil.error;
  26703. var Stream = coreStream.Stream;
  26704. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  26705. var StandardEncoding = coreEncodings.StandardEncoding;
  26706. var CFFParser = coreCFFParser.CFFParser;
  26707. var FontRendererFactory = (function FontRendererFactoryClosure() {
  26708. function getLong(data, offset) {
  26709. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26710. (data[offset + 2] << 8) | data[offset + 3];
  26711. }
  26712. function getUshort(data, offset) {
  26713. return (data[offset] << 8) | data[offset + 1];
  26714. }
  26715. function parseCmap(data, start, end) {
  26716. var offset = (getUshort(data, start + 2) === 1 ?
  26717. getLong(data, start + 8) : getLong(data, start + 16));
  26718. var format = getUshort(data, start + offset);
  26719. var length, ranges, p, i;
  26720. if (format === 4) {
  26721. length = getUshort(data, start + offset + 2);
  26722. var segCount = getUshort(data, start + offset + 6) >> 1;
  26723. p = start + offset + 14;
  26724. ranges = [];
  26725. for (i = 0; i < segCount; i++, p += 2) {
  26726. ranges[i] = {end: getUshort(data, p)};
  26727. }
  26728. p += 2;
  26729. for (i = 0; i < segCount; i++, p += 2) {
  26730. ranges[i].start = getUshort(data, p);
  26731. }
  26732. for (i = 0; i < segCount; i++, p += 2) {
  26733. ranges[i].idDelta = getUshort(data, p);
  26734. }
  26735. for (i = 0; i < segCount; i++, p += 2) {
  26736. var idOffset = getUshort(data, p);
  26737. if (idOffset === 0) {
  26738. continue;
  26739. }
  26740. ranges[i].ids = [];
  26741. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  26742. ranges[i].ids[j] = getUshort(data, p + idOffset);
  26743. idOffset += 2;
  26744. }
  26745. }
  26746. return ranges;
  26747. } else if (format === 12) {
  26748. length = getLong(data, start + offset + 4);
  26749. var groups = getLong(data, start + offset + 12);
  26750. p = start + offset + 16;
  26751. ranges = [];
  26752. for (i = 0; i < groups; i++) {
  26753. ranges.push({
  26754. start: getLong(data, p),
  26755. end: getLong(data, p + 4),
  26756. idDelta: getLong(data, p + 8) - getLong(data, p)
  26757. });
  26758. p += 12;
  26759. }
  26760. return ranges;
  26761. }
  26762. error('not supported cmap: ' + format);
  26763. }
  26764. function parseCff(data, start, end, seacAnalysisEnabled) {
  26765. var properties = {};
  26766. var parser = new CFFParser(new Stream(data, start, end - start),
  26767. properties, seacAnalysisEnabled);
  26768. var cff = parser.parse();
  26769. return {
  26770. glyphs: cff.charStrings.objects,
  26771. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  26772. cff.topDict.privateDict.subrsIndex.objects),
  26773. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  26774. };
  26775. }
  26776. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  26777. var itemSize, itemDecode;
  26778. if (isGlyphLocationsLong) {
  26779. itemSize = 4;
  26780. itemDecode = function fontItemDecodeLong(data, offset) {
  26781. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26782. (data[offset + 2] << 8) | data[offset + 3];
  26783. };
  26784. } else {
  26785. itemSize = 2;
  26786. itemDecode = function fontItemDecode(data, offset) {
  26787. return (data[offset] << 9) | (data[offset + 1] << 1);
  26788. };
  26789. }
  26790. var glyphs = [];
  26791. var startOffset = itemDecode(loca, 0);
  26792. for (var j = itemSize; j < loca.length; j += itemSize) {
  26793. var endOffset = itemDecode(loca, j);
  26794. glyphs.push(glyf.subarray(startOffset, endOffset));
  26795. startOffset = endOffset;
  26796. }
  26797. return glyphs;
  26798. }
  26799. function lookupCmap(ranges, unicode) {
  26800. var code = unicode.charCodeAt(0), gid = 0;
  26801. var l = 0, r = ranges.length - 1;
  26802. while (l < r) {
  26803. var c = (l + r + 1) >> 1;
  26804. if (code < ranges[c].start) {
  26805. r = c - 1;
  26806. } else {
  26807. l = c;
  26808. }
  26809. }
  26810. if (ranges[l].start <= code && code <= ranges[l].end) {
  26811. gid = (ranges[l].idDelta + (ranges[l].ids ?
  26812. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  26813. }
  26814. return {
  26815. charCode: code,
  26816. glyphId: gid,
  26817. };
  26818. }
  26819. function compileGlyf(code, cmds, font) {
  26820. function moveTo(x, y) {
  26821. cmds.push({cmd: 'moveTo', args: [x, y]});
  26822. }
  26823. function lineTo(x, y) {
  26824. cmds.push({cmd: 'lineTo', args: [x, y]});
  26825. }
  26826. function quadraticCurveTo(xa, ya, x, y) {
  26827. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  26828. }
  26829. var i = 0;
  26830. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26831. var flags;
  26832. var x = 0, y = 0;
  26833. i += 10;
  26834. if (numberOfContours < 0) {
  26835. // composite glyph
  26836. do {
  26837. flags = (code[i] << 8) | code[i + 1];
  26838. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  26839. i += 4;
  26840. var arg1, arg2;
  26841. if ((flags & 0x01)) {
  26842. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26843. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  26844. i += 4;
  26845. } else {
  26846. arg1 = code[i++]; arg2 = code[i++];
  26847. }
  26848. if ((flags & 0x02)) {
  26849. x = arg1;
  26850. y = arg2;
  26851. } else {
  26852. x = 0; y = 0; // TODO "they are points" ?
  26853. }
  26854. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  26855. if ((flags & 0x08)) {
  26856. scaleX =
  26857. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26858. i += 2;
  26859. } else if ((flags & 0x40)) {
  26860. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26861. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26862. i += 4;
  26863. } else if ((flags & 0x80)) {
  26864. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26865. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26866. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  26867. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  26868. i += 8;
  26869. }
  26870. var subglyph = font.glyphs[glyphIndex];
  26871. if (subglyph) {
  26872. cmds.push({cmd: 'save'});
  26873. cmds.push({cmd: 'transform',
  26874. args: [scaleX, scale01, scale10, scaleY, x, y]});
  26875. compileGlyf(subglyph, cmds, font);
  26876. cmds.push({cmd: 'restore'});
  26877. }
  26878. } while ((flags & 0x20));
  26879. } else {
  26880. // simple glyph
  26881. var endPtsOfContours = [];
  26882. var j, jj;
  26883. for (j = 0; j < numberOfContours; j++) {
  26884. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  26885. i += 2;
  26886. }
  26887. var instructionLength = (code[i] << 8) | code[i + 1];
  26888. i += 2 + instructionLength; // skipping the instructions
  26889. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  26890. var points = [];
  26891. while (points.length < numberOfPoints) {
  26892. flags = code[i++];
  26893. var repeat = 1;
  26894. if ((flags & 0x08)) {
  26895. repeat += code[i++];
  26896. }
  26897. while (repeat-- > 0) {
  26898. points.push({flags: flags});
  26899. }
  26900. }
  26901. for (j = 0; j < numberOfPoints; j++) {
  26902. switch (points[j].flags & 0x12) {
  26903. case 0x00:
  26904. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26905. i += 2;
  26906. break;
  26907. case 0x02:
  26908. x -= code[i++];
  26909. break;
  26910. case 0x12:
  26911. x += code[i++];
  26912. break;
  26913. }
  26914. points[j].x = x;
  26915. }
  26916. for (j = 0; j < numberOfPoints; j++) {
  26917. switch (points[j].flags & 0x24) {
  26918. case 0x00:
  26919. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26920. i += 2;
  26921. break;
  26922. case 0x04:
  26923. y -= code[i++];
  26924. break;
  26925. case 0x24:
  26926. y += code[i++];
  26927. break;
  26928. }
  26929. points[j].y = y;
  26930. }
  26931. var startPoint = 0;
  26932. for (i = 0; i < numberOfContours; i++) {
  26933. var endPoint = endPtsOfContours[i];
  26934. // contours might have implicit points, which is located in the middle
  26935. // between two neighboring off-curve points
  26936. var contour = points.slice(startPoint, endPoint + 1);
  26937. if ((contour[0].flags & 1)) {
  26938. contour.push(contour[0]); // using start point at the contour end
  26939. } else if ((contour[contour.length - 1].flags & 1)) {
  26940. // first is off-curve point, trying to use one from the end
  26941. contour.unshift(contour[contour.length - 1]);
  26942. } else {
  26943. // start and end are off-curve points, creating implicit one
  26944. var p = {
  26945. flags: 1,
  26946. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  26947. y: (contour[0].y + contour[contour.length - 1].y) / 2
  26948. };
  26949. contour.unshift(p);
  26950. contour.push(p);
  26951. }
  26952. moveTo(contour[0].x, contour[0].y);
  26953. for (j = 1, jj = contour.length; j < jj; j++) {
  26954. if ((contour[j].flags & 1)) {
  26955. lineTo(contour[j].x, contour[j].y);
  26956. } else if ((contour[j + 1].flags & 1)){
  26957. quadraticCurveTo(contour[j].x, contour[j].y,
  26958. contour[j + 1].x, contour[j + 1].y);
  26959. j++;
  26960. } else {
  26961. quadraticCurveTo(contour[j].x, contour[j].y,
  26962. (contour[j].x + contour[j + 1].x) / 2,
  26963. (contour[j].y + contour[j + 1].y) / 2);
  26964. }
  26965. }
  26966. startPoint = endPoint + 1;
  26967. }
  26968. }
  26969. }
  26970. function compileCharString(code, cmds, font) {
  26971. var stack = [];
  26972. var x = 0, y = 0;
  26973. var stems = 0;
  26974. function moveTo(x, y) {
  26975. cmds.push({cmd: 'moveTo', args: [x, y]});
  26976. }
  26977. function lineTo(x, y) {
  26978. cmds.push({cmd: 'lineTo', args: [x, y]});
  26979. }
  26980. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  26981. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  26982. }
  26983. function parse(code) {
  26984. var i = 0;
  26985. while (i < code.length) {
  26986. var stackClean = false;
  26987. var v = code[i++];
  26988. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  26989. switch (v) {
  26990. case 1: // hstem
  26991. stems += stack.length >> 1;
  26992. stackClean = true;
  26993. break;
  26994. case 3: // vstem
  26995. stems += stack.length >> 1;
  26996. stackClean = true;
  26997. break;
  26998. case 4: // vmoveto
  26999. y += stack.pop();
  27000. moveTo(x, y);
  27001. stackClean = true;
  27002. break;
  27003. case 5: // rlineto
  27004. while (stack.length > 0) {
  27005. x += stack.shift();
  27006. y += stack.shift();
  27007. lineTo(x, y);
  27008. }
  27009. break;
  27010. case 6: // hlineto
  27011. while (stack.length > 0) {
  27012. x += stack.shift();
  27013. lineTo(x, y);
  27014. if (stack.length === 0) {
  27015. break;
  27016. }
  27017. y += stack.shift();
  27018. lineTo(x, y);
  27019. }
  27020. break;
  27021. case 7: // vlineto
  27022. while (stack.length > 0) {
  27023. y += stack.shift();
  27024. lineTo(x, y);
  27025. if (stack.length === 0) {
  27026. break;
  27027. }
  27028. x += stack.shift();
  27029. lineTo(x, y);
  27030. }
  27031. break;
  27032. case 8: // rrcurveto
  27033. while (stack.length > 0) {
  27034. xa = x + stack.shift(); ya = y + stack.shift();
  27035. xb = xa + stack.shift(); yb = ya + stack.shift();
  27036. x = xb + stack.shift(); y = yb + stack.shift();
  27037. bezierCurveTo(xa, ya, xb, yb, x, y);
  27038. }
  27039. break;
  27040. case 10: // callsubr
  27041. n = stack.pop() + font.subrsBias;
  27042. subrCode = font.subrs[n];
  27043. if (subrCode) {
  27044. parse(subrCode);
  27045. }
  27046. break;
  27047. case 11: // return
  27048. return;
  27049. case 12:
  27050. v = code[i++];
  27051. switch (v) {
  27052. case 34: // flex
  27053. xa = x + stack.shift();
  27054. xb = xa + stack.shift(); y1 = y + stack.shift();
  27055. x = xb + stack.shift();
  27056. bezierCurveTo(xa, y, xb, y1, x, y1);
  27057. xa = x + stack.shift();
  27058. xb = xa + stack.shift();
  27059. x = xb + stack.shift();
  27060. bezierCurveTo(xa, y1, xb, y, x, y);
  27061. break;
  27062. case 35: // flex
  27063. xa = x + stack.shift(); ya = y + stack.shift();
  27064. xb = xa + stack.shift(); yb = ya + stack.shift();
  27065. x = xb + stack.shift(); y = yb + stack.shift();
  27066. bezierCurveTo(xa, ya, xb, yb, x, y);
  27067. xa = x + stack.shift(); ya = y + stack.shift();
  27068. xb = xa + stack.shift(); yb = ya + stack.shift();
  27069. x = xb + stack.shift(); y = yb + stack.shift();
  27070. bezierCurveTo(xa, ya, xb, yb, x, y);
  27071. stack.pop(); // fd
  27072. break;
  27073. case 36: // hflex1
  27074. xa = x + stack.shift(); y1 = y + stack.shift();
  27075. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  27076. x = xb + stack.shift();
  27077. bezierCurveTo(xa, y1, xb, y2, x, y2);
  27078. xa = x + stack.shift();
  27079. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  27080. x = xb + stack.shift();
  27081. bezierCurveTo(xa, y2, xb, y3, x, y);
  27082. break;
  27083. case 37: // flex1
  27084. var x0 = x, y0 = y;
  27085. xa = x + stack.shift(); ya = y + stack.shift();
  27086. xb = xa + stack.shift(); yb = ya + stack.shift();
  27087. x = xb + stack.shift(); y = yb + stack.shift();
  27088. bezierCurveTo(xa, ya, xb, yb, x, y);
  27089. xa = x + stack.shift(); ya = y + stack.shift();
  27090. xb = xa + stack.shift(); yb = ya + stack.shift();
  27091. x = xb; y = yb;
  27092. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  27093. x += stack.shift();
  27094. } else {
  27095. y += stack.shift();
  27096. }
  27097. bezierCurveTo(xa, ya, xb, yb, x, y);
  27098. break;
  27099. default:
  27100. error('unknown operator: 12 ' + v);
  27101. }
  27102. break;
  27103. case 14: // endchar
  27104. if (stack.length >= 4) {
  27105. var achar = stack.pop();
  27106. var bchar = stack.pop();
  27107. y = stack.pop();
  27108. x = stack.pop();
  27109. cmds.push({cmd: 'save'});
  27110. cmds.push({cmd: 'translate', args: [x, y]});
  27111. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  27112. font.glyphNameMap[StandardEncoding[achar]]));
  27113. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  27114. cmds.push({cmd: 'restore'});
  27115. cmap = lookupCmap(font.cmap, String.fromCharCode(
  27116. font.glyphNameMap[StandardEncoding[bchar]]));
  27117. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  27118. }
  27119. return;
  27120. case 18: // hstemhm
  27121. stems += stack.length >> 1;
  27122. stackClean = true;
  27123. break;
  27124. case 19: // hintmask
  27125. stems += stack.length >> 1;
  27126. i += (stems + 7) >> 3;
  27127. stackClean = true;
  27128. break;
  27129. case 20: // cntrmask
  27130. stems += stack.length >> 1;
  27131. i += (stems + 7) >> 3;
  27132. stackClean = true;
  27133. break;
  27134. case 21: // rmoveto
  27135. y += stack.pop();
  27136. x += stack.pop();
  27137. moveTo(x, y);
  27138. stackClean = true;
  27139. break;
  27140. case 22: // hmoveto
  27141. x += stack.pop();
  27142. moveTo(x, y);
  27143. stackClean = true;
  27144. break;
  27145. case 23: // vstemhm
  27146. stems += stack.length >> 1;
  27147. stackClean = true;
  27148. break;
  27149. case 24: // rcurveline
  27150. while (stack.length > 2) {
  27151. xa = x + stack.shift(); ya = y + stack.shift();
  27152. xb = xa + stack.shift(); yb = ya + stack.shift();
  27153. x = xb + stack.shift(); y = yb + stack.shift();
  27154. bezierCurveTo(xa, ya, xb, yb, x, y);
  27155. }
  27156. x += stack.shift();
  27157. y += stack.shift();
  27158. lineTo(x, y);
  27159. break;
  27160. case 25: // rlinecurve
  27161. while (stack.length > 6) {
  27162. x += stack.shift();
  27163. y += stack.shift();
  27164. lineTo(x, y);
  27165. }
  27166. xa = x + stack.shift(); ya = y + stack.shift();
  27167. xb = xa + stack.shift(); yb = ya + stack.shift();
  27168. x = xb + stack.shift(); y = yb + stack.shift();
  27169. bezierCurveTo(xa, ya, xb, yb, x, y);
  27170. break;
  27171. case 26: // vvcurveto
  27172. if (stack.length % 2) {
  27173. x += stack.shift();
  27174. }
  27175. while (stack.length > 0) {
  27176. xa = x; ya = y + stack.shift();
  27177. xb = xa + stack.shift(); yb = ya + stack.shift();
  27178. x = xb; y = yb + stack.shift();
  27179. bezierCurveTo(xa, ya, xb, yb, x, y);
  27180. }
  27181. break;
  27182. case 27: // hhcurveto
  27183. if (stack.length % 2) {
  27184. y += stack.shift();
  27185. }
  27186. while (stack.length > 0) {
  27187. xa = x + stack.shift(); ya = y;
  27188. xb = xa + stack.shift(); yb = ya + stack.shift();
  27189. x = xb + stack.shift(); y = yb;
  27190. bezierCurveTo(xa, ya, xb, yb, x, y);
  27191. }
  27192. break;
  27193. case 28:
  27194. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  27195. i += 2;
  27196. break;
  27197. case 29: // callgsubr
  27198. n = stack.pop() + font.gsubrsBias;
  27199. subrCode = font.gsubrs[n];
  27200. if (subrCode) {
  27201. parse(subrCode);
  27202. }
  27203. break;
  27204. case 30: // vhcurveto
  27205. while (stack.length > 0) {
  27206. xa = x; ya = y + stack.shift();
  27207. xb = xa + stack.shift(); yb = ya + stack.shift();
  27208. x = xb + stack.shift();
  27209. y = yb + (stack.length === 1 ? stack.shift() : 0);
  27210. bezierCurveTo(xa, ya, xb, yb, x, y);
  27211. if (stack.length === 0) {
  27212. break;
  27213. }
  27214. xa = x + stack.shift(); ya = y;
  27215. xb = xa + stack.shift(); yb = ya + stack.shift();
  27216. y = yb + stack.shift();
  27217. x = xb + (stack.length === 1 ? stack.shift() : 0);
  27218. bezierCurveTo(xa, ya, xb, yb, x, y);
  27219. }
  27220. break;
  27221. case 31: // hvcurveto
  27222. while (stack.length > 0) {
  27223. xa = x + stack.shift(); ya = y;
  27224. xb = xa + stack.shift(); yb = ya + stack.shift();
  27225. y = yb + stack.shift();
  27226. x = xb + (stack.length === 1 ? stack.shift() : 0);
  27227. bezierCurveTo(xa, ya, xb, yb, x, y);
  27228. if (stack.length === 0) {
  27229. break;
  27230. }
  27231. xa = x; ya = y + stack.shift();
  27232. xb = xa + stack.shift(); yb = ya + stack.shift();
  27233. x = xb + stack.shift();
  27234. y = yb + (stack.length === 1 ? stack.shift() : 0);
  27235. bezierCurveTo(xa, ya, xb, yb, x, y);
  27236. }
  27237. break;
  27238. default:
  27239. if (v < 32) {
  27240. error('unknown operator: ' + v);
  27241. }
  27242. if (v < 247) {
  27243. stack.push(v - 139);
  27244. } else if (v < 251) {
  27245. stack.push((v - 247) * 256 + code[i++] + 108);
  27246. } else if (v < 255) {
  27247. stack.push(-(v - 251) * 256 - code[i++] - 108);
  27248. } else {
  27249. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  27250. (code[i + 2] << 8) | code[i + 3]) / 65536);
  27251. i += 4;
  27252. }
  27253. break;
  27254. }
  27255. if (stackClean) {
  27256. stack.length = 0;
  27257. }
  27258. }
  27259. }
  27260. parse(code);
  27261. }
  27262. var noop = '';
  27263. function CompiledFont(fontMatrix) {
  27264. this.compiledGlyphs = Object.create(null);
  27265. this.compiledCharCodeToGlyphId = Object.create(null);
  27266. this.fontMatrix = fontMatrix;
  27267. }
  27268. CompiledFont.prototype = {
  27269. getPathJs: function (unicode) {
  27270. var cmap = lookupCmap(this.cmap, unicode);
  27271. var fn = this.compiledGlyphs[cmap.glyphId];
  27272. if (!fn) {
  27273. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  27274. this.compiledGlyphs[cmap.glyphId] = fn;
  27275. }
  27276. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  27277. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  27278. }
  27279. return fn;
  27280. },
  27281. compileGlyph: function (code) {
  27282. if (!code || code.length === 0 || code[0] === 14) {
  27283. return noop;
  27284. }
  27285. var cmds = [];
  27286. cmds.push({cmd: 'save'});
  27287. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  27288. cmds.push({cmd: 'scale', args: ['size', '-size']});
  27289. this.compileGlyphImpl(code, cmds);
  27290. cmds.push({cmd: 'restore'});
  27291. return cmds;
  27292. },
  27293. compileGlyphImpl: function () {
  27294. error('Children classes should implement this.');
  27295. },
  27296. hasBuiltPath: function (unicode) {
  27297. var cmap = lookupCmap(this.cmap, unicode);
  27298. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  27299. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  27300. }
  27301. };
  27302. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  27303. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  27304. CompiledFont.call(this, fontMatrix);
  27305. this.glyphs = glyphs;
  27306. this.cmap = cmap;
  27307. }
  27308. Util.inherit(TrueTypeCompiled, CompiledFont, {
  27309. compileGlyphImpl: function (code, cmds) {
  27310. compileGlyf(code, cmds, this);
  27311. }
  27312. });
  27313. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  27314. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  27315. CompiledFont.call(this, fontMatrix);
  27316. this.glyphs = cffInfo.glyphs;
  27317. this.gsubrs = cffInfo.gsubrs || [];
  27318. this.subrs = cffInfo.subrs || [];
  27319. this.cmap = cmap;
  27320. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  27321. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  27322. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  27323. this.subrsBias = (this.subrs.length < 1240 ?
  27324. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  27325. }
  27326. Util.inherit(Type2Compiled, CompiledFont, {
  27327. compileGlyphImpl: function (code, cmds) {
  27328. compileCharString(code, cmds, this);
  27329. }
  27330. });
  27331. return {
  27332. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  27333. var data = new Uint8Array(font.data);
  27334. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  27335. var numTables = getUshort(data, 4);
  27336. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  27337. var tag = bytesToString(data.subarray(p, p + 4));
  27338. var offset = getLong(data, p + 8);
  27339. var length = getLong(data, p + 12);
  27340. switch (tag) {
  27341. case 'cmap':
  27342. cmap = parseCmap(data, offset, offset + length);
  27343. break;
  27344. case 'glyf':
  27345. glyf = data.subarray(offset, offset + length);
  27346. break;
  27347. case 'loca':
  27348. loca = data.subarray(offset, offset + length);
  27349. break;
  27350. case 'head':
  27351. unitsPerEm = getUshort(data, offset + 18);
  27352. indexToLocFormat = getUshort(data, offset + 50);
  27353. break;
  27354. case 'CFF ':
  27355. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  27356. break;
  27357. }
  27358. }
  27359. if (glyf) {
  27360. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  27361. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  27362. return new TrueTypeCompiled(
  27363. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  27364. } else {
  27365. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  27366. }
  27367. }
  27368. };
  27369. })();
  27370. exports.FontRendererFactory = FontRendererFactory;
  27371. }));
  27372. (function (root, factory) {
  27373. {
  27374. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  27375. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  27376. }
  27377. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  27378. var MissingDataException = sharedUtil.MissingDataException;
  27379. var StreamType = sharedUtil.StreamType;
  27380. var assert = sharedUtil.assert;
  27381. var error = sharedUtil.error;
  27382. var info = sharedUtil.info;
  27383. var isArray = sharedUtil.isArray;
  27384. var isInt = sharedUtil.isInt;
  27385. var isNum = sharedUtil.isNum;
  27386. var isString = sharedUtil.isString;
  27387. var warn = sharedUtil.warn;
  27388. var Cmd = corePrimitives.Cmd;
  27389. var Dict = corePrimitives.Dict;
  27390. var Name = corePrimitives.Name;
  27391. var Ref = corePrimitives.Ref;
  27392. var isCmd = corePrimitives.isCmd;
  27393. var isDict = corePrimitives.isDict;
  27394. var isName = corePrimitives.isName;
  27395. var Ascii85Stream = coreStream.Ascii85Stream;
  27396. var AsciiHexStream = coreStream.AsciiHexStream;
  27397. var CCITTFaxStream = coreStream.CCITTFaxStream;
  27398. var FlateStream = coreStream.FlateStream;
  27399. var Jbig2Stream = coreStream.Jbig2Stream;
  27400. var JpegStream = coreStream.JpegStream;
  27401. var JpxStream = coreStream.JpxStream;
  27402. var LZWStream = coreStream.LZWStream;
  27403. var NullStream = coreStream.NullStream;
  27404. var PredictorStream = coreStream.PredictorStream;
  27405. var RunLengthStream = coreStream.RunLengthStream;
  27406. var EOF = {};
  27407. function isEOF(v) {
  27408. return (v === EOF);
  27409. }
  27410. var MAX_LENGTH_TO_CACHE = 1000;
  27411. var Parser = (function ParserClosure() {
  27412. function Parser(lexer, allowStreams, xref, recoveryMode) {
  27413. this.lexer = lexer;
  27414. this.allowStreams = allowStreams;
  27415. this.xref = xref;
  27416. this.recoveryMode = recoveryMode || false;
  27417. this.imageCache = Object.create(null);
  27418. this.refill();
  27419. }
  27420. Parser.prototype = {
  27421. refill: function Parser_refill() {
  27422. this.buf1 = this.lexer.getObj();
  27423. this.buf2 = this.lexer.getObj();
  27424. },
  27425. shift: function Parser_shift() {
  27426. if (isCmd(this.buf2, 'ID')) {
  27427. this.buf1 = this.buf2;
  27428. this.buf2 = null;
  27429. } else {
  27430. this.buf1 = this.buf2;
  27431. this.buf2 = this.lexer.getObj();
  27432. }
  27433. },
  27434. tryShift: function Parser_tryShift() {
  27435. try {
  27436. this.shift();
  27437. return true;
  27438. } catch (e) {
  27439. if (e instanceof MissingDataException) {
  27440. throw e;
  27441. }
  27442. // Upon failure, the caller should reset this.lexer.pos to a known good
  27443. // state and call this.shift() twice to reset the buffers.
  27444. return false;
  27445. }
  27446. },
  27447. getObj: function Parser_getObj(cipherTransform) {
  27448. var buf1 = this.buf1;
  27449. this.shift();
  27450. if (buf1 instanceof Cmd) {
  27451. switch (buf1.cmd) {
  27452. case 'BI': // inline image
  27453. return this.makeInlineImage(cipherTransform);
  27454. case '[': // array
  27455. var array = [];
  27456. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  27457. array.push(this.getObj(cipherTransform));
  27458. }
  27459. if (isEOF(this.buf1)) {
  27460. if (!this.recoveryMode) {
  27461. error('End of file inside array');
  27462. }
  27463. return array;
  27464. }
  27465. this.shift();
  27466. return array;
  27467. case '<<': // dictionary or stream
  27468. var dict = new Dict(this.xref);
  27469. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  27470. if (!isName(this.buf1)) {
  27471. info('Malformed dictionary: key must be a name object');
  27472. this.shift();
  27473. continue;
  27474. }
  27475. var key = this.buf1.name;
  27476. this.shift();
  27477. if (isEOF(this.buf1)) {
  27478. break;
  27479. }
  27480. dict.set(key, this.getObj(cipherTransform));
  27481. }
  27482. if (isEOF(this.buf1)) {
  27483. if (!this.recoveryMode) {
  27484. error('End of file inside dictionary');
  27485. }
  27486. return dict;
  27487. }
  27488. // Stream objects are not allowed inside content streams or
  27489. // object streams.
  27490. if (isCmd(this.buf2, 'stream')) {
  27491. return (this.allowStreams ?
  27492. this.makeStream(dict, cipherTransform) : dict);
  27493. }
  27494. this.shift();
  27495. return dict;
  27496. default: // simple object
  27497. return buf1;
  27498. }
  27499. }
  27500. if (isInt(buf1)) { // indirect reference or integer
  27501. var num = buf1;
  27502. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  27503. var ref = new Ref(num, this.buf1);
  27504. this.shift();
  27505. this.shift();
  27506. return ref;
  27507. }
  27508. return num;
  27509. }
  27510. if (isString(buf1)) { // string
  27511. var str = buf1;
  27512. if (cipherTransform) {
  27513. str = cipherTransform.decryptString(str);
  27514. }
  27515. return str;
  27516. }
  27517. // simple object
  27518. return buf1;
  27519. },
  27520. /**
  27521. * Find the end of the stream by searching for the /EI\s/.
  27522. * @returns {number} The inline stream length.
  27523. */
  27524. findDefaultInlineStreamEnd:
  27525. function Parser_findDefaultInlineStreamEnd(stream) {
  27526. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  27527. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  27528. while ((ch = stream.getByte()) !== -1) {
  27529. if (state === 0) {
  27530. state = (ch === E) ? 1 : 0;
  27531. } else if (state === 1) {
  27532. state = (ch === I) ? 2 : 0;
  27533. } else {
  27534. assert(state === 2);
  27535. if (ch === SPACE || ch === LF || ch === CR) {
  27536. // Let's check the next five bytes are ASCII... just be sure.
  27537. n = 5;
  27538. followingBytes = stream.peekBytes(n);
  27539. for (i = 0; i < n; i++) {
  27540. ch = followingBytes[i];
  27541. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  27542. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  27543. // it's binary stuff. Resetting the state.
  27544. state = 0;
  27545. break;
  27546. }
  27547. }
  27548. if (state === 2) {
  27549. break; // Finished!
  27550. }
  27551. } else {
  27552. state = 0;
  27553. }
  27554. }
  27555. }
  27556. return ((stream.pos - 4) - startPos);
  27557. },
  27558. /**
  27559. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  27560. * @returns {number} The inline stream length.
  27561. */
  27562. findDCTDecodeInlineStreamEnd:
  27563. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  27564. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  27565. while ((b = stream.getByte()) !== -1) {
  27566. if (b !== 0xFF) { // Not a valid marker.
  27567. continue;
  27568. }
  27569. switch (stream.getByte()) {
  27570. case 0x00: // Byte stuffing.
  27571. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  27572. break;
  27573. case 0xFF: // Fill byte.
  27574. // Avoid skipping a valid marker, resetting the stream position.
  27575. stream.skip(-1);
  27576. break;
  27577. case 0xD9: // EOI
  27578. foundEOI = true;
  27579. break;
  27580. case 0xC0: // SOF0
  27581. case 0xC1: // SOF1
  27582. case 0xC2: // SOF2
  27583. case 0xC3: // SOF3
  27584. case 0xC5: // SOF5
  27585. case 0xC6: // SOF6
  27586. case 0xC7: // SOF7
  27587. case 0xC9: // SOF9
  27588. case 0xCA: // SOF10
  27589. case 0xCB: // SOF11
  27590. case 0xCD: // SOF13
  27591. case 0xCE: // SOF14
  27592. case 0xCF: // SOF15
  27593. case 0xC4: // DHT
  27594. case 0xCC: // DAC
  27595. case 0xDA: // SOS
  27596. case 0xDB: // DQT
  27597. case 0xDC: // DNL
  27598. case 0xDD: // DRI
  27599. case 0xDE: // DHP
  27600. case 0xDF: // EXP
  27601. case 0xE0: // APP0
  27602. case 0xE1: // APP1
  27603. case 0xE2: // APP2
  27604. case 0xE3: // APP3
  27605. case 0xE4: // APP4
  27606. case 0xE5: // APP5
  27607. case 0xE6: // APP6
  27608. case 0xE7: // APP7
  27609. case 0xE8: // APP8
  27610. case 0xE9: // APP9
  27611. case 0xEA: // APP10
  27612. case 0xEB: // APP11
  27613. case 0xEC: // APP12
  27614. case 0xED: // APP13
  27615. case 0xEE: // APP14
  27616. case 0xEF: // APP15
  27617. case 0xFE: // COM
  27618. // The marker should be followed by the length of the segment.
  27619. markerLength = stream.getUint16();
  27620. if (markerLength > 2) {
  27621. // |markerLength| contains the byte length of the marker segment,
  27622. // including its own length (2 bytes) and excluding the marker.
  27623. stream.skip(markerLength - 2); // Jump to the next marker.
  27624. } else {
  27625. // The marker length is invalid, resetting the stream position.
  27626. stream.skip(-2);
  27627. }
  27628. break;
  27629. }
  27630. if (foundEOI) {
  27631. break;
  27632. }
  27633. }
  27634. length = stream.pos - startPos;
  27635. if (b === -1) {
  27636. warn('Inline DCTDecode image stream: ' +
  27637. 'EOI marker not found, searching for /EI/ instead.');
  27638. stream.skip(-length); // Reset the stream position.
  27639. return this.findDefaultInlineStreamEnd(stream);
  27640. }
  27641. this.inlineStreamSkipEI(stream);
  27642. return length;
  27643. },
  27644. /**
  27645. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  27646. * @returns {number} The inline stream length.
  27647. */
  27648. findASCII85DecodeInlineStreamEnd:
  27649. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  27650. var TILDE = 0x7E, GT = 0x3E;
  27651. var startPos = stream.pos, ch, length;
  27652. while ((ch = stream.getByte()) !== -1) {
  27653. if (ch === TILDE && stream.peekByte() === GT) {
  27654. stream.skip();
  27655. break;
  27656. }
  27657. }
  27658. length = stream.pos - startPos;
  27659. if (ch === -1) {
  27660. warn('Inline ASCII85Decode image stream: ' +
  27661. 'EOD marker not found, searching for /EI/ instead.');
  27662. stream.skip(-length); // Reset the stream position.
  27663. return this.findDefaultInlineStreamEnd(stream);
  27664. }
  27665. this.inlineStreamSkipEI(stream);
  27666. return length;
  27667. },
  27668. /**
  27669. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  27670. * @returns {number} The inline stream length.
  27671. */
  27672. findASCIIHexDecodeInlineStreamEnd:
  27673. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  27674. var GT = 0x3E;
  27675. var startPos = stream.pos, ch, length;
  27676. while ((ch = stream.getByte()) !== -1) {
  27677. if (ch === GT) {
  27678. break;
  27679. }
  27680. }
  27681. length = stream.pos - startPos;
  27682. if (ch === -1) {
  27683. warn('Inline ASCIIHexDecode image stream: ' +
  27684. 'EOD marker not found, searching for /EI/ instead.');
  27685. stream.skip(-length); // Reset the stream position.
  27686. return this.findDefaultInlineStreamEnd(stream);
  27687. }
  27688. this.inlineStreamSkipEI(stream);
  27689. return length;
  27690. },
  27691. /**
  27692. * Skip over the /EI/ for streams where we search for an EOD marker.
  27693. */
  27694. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  27695. var E = 0x45, I = 0x49;
  27696. var state = 0, ch;
  27697. while ((ch = stream.getByte()) !== -1) {
  27698. if (state === 0) {
  27699. state = (ch === E) ? 1 : 0;
  27700. } else if (state === 1) {
  27701. state = (ch === I) ? 2 : 0;
  27702. } else if (state === 2) {
  27703. break;
  27704. }
  27705. }
  27706. },
  27707. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  27708. var lexer = this.lexer;
  27709. var stream = lexer.stream;
  27710. // Parse dictionary.
  27711. var dict = new Dict(this.xref);
  27712. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  27713. if (!isName(this.buf1)) {
  27714. error('Dictionary key must be a name object');
  27715. }
  27716. var key = this.buf1.name;
  27717. this.shift();
  27718. if (isEOF(this.buf1)) {
  27719. break;
  27720. }
  27721. dict.set(key, this.getObj(cipherTransform));
  27722. }
  27723. // Extract the name of the first (i.e. the current) image filter.
  27724. var filter = dict.get('Filter', 'F'), filterName;
  27725. if (isName(filter)) {
  27726. filterName = filter.name;
  27727. } else if (isArray(filter) && isName(filter[0])) {
  27728. filterName = filter[0].name;
  27729. }
  27730. // Parse image stream.
  27731. var startPos = stream.pos, length, i, ii;
  27732. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  27733. length = this.findDCTDecodeInlineStreamEnd(stream);
  27734. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  27735. length = this.findASCII85DecodeInlineStreamEnd(stream);
  27736. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  27737. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  27738. } else {
  27739. length = this.findDefaultInlineStreamEnd(stream);
  27740. }
  27741. var imageStream = stream.makeSubStream(startPos, length, dict);
  27742. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  27743. // adler32 checksum.
  27744. var adler32;
  27745. if (length < MAX_LENGTH_TO_CACHE) {
  27746. var imageBytes = imageStream.getBytes();
  27747. imageStream.reset();
  27748. var a = 1;
  27749. var b = 0;
  27750. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  27751. // No modulo required in the loop if imageBytes.length < 5552.
  27752. a += imageBytes[i] & 0xff;
  27753. b += a;
  27754. }
  27755. adler32 = ((b % 65521) << 16) | (a % 65521);
  27756. if (this.imageCache.adler32 === adler32) {
  27757. this.buf2 = Cmd.get('EI');
  27758. this.shift();
  27759. this.imageCache[adler32].reset();
  27760. return this.imageCache[adler32];
  27761. }
  27762. }
  27763. if (cipherTransform) {
  27764. imageStream = cipherTransform.createStream(imageStream, length);
  27765. }
  27766. imageStream = this.filter(imageStream, dict, length);
  27767. imageStream.dict = dict;
  27768. if (adler32 !== undefined) {
  27769. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  27770. this.imageCache[adler32] = imageStream;
  27771. }
  27772. this.buf2 = Cmd.get('EI');
  27773. this.shift();
  27774. return imageStream;
  27775. },
  27776. makeStream: function Parser_makeStream(dict, cipherTransform) {
  27777. var lexer = this.lexer;
  27778. var stream = lexer.stream;
  27779. // get stream start position
  27780. lexer.skipToNextLine();
  27781. var pos = stream.pos - 1;
  27782. // get length
  27783. var length = dict.get('Length');
  27784. if (!isInt(length)) {
  27785. info('Bad ' + length + ' attribute in stream');
  27786. length = 0;
  27787. }
  27788. // skip over the stream data
  27789. stream.pos = pos + length;
  27790. lexer.nextChar();
  27791. // Shift '>>' and check whether the new object marks the end of the stream
  27792. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  27793. this.shift(); // 'stream'
  27794. } else {
  27795. // bad stream length, scanning for endstream
  27796. stream.pos = pos;
  27797. var SCAN_BLOCK_SIZE = 2048;
  27798. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  27799. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  27800. 0x61, 0x6D];
  27801. var skipped = 0, found = false, i, j;
  27802. while (stream.pos < stream.end) {
  27803. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  27804. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  27805. if (scanLength <= 0) {
  27806. break;
  27807. }
  27808. found = false;
  27809. i = 0;
  27810. while (i < scanLength) {
  27811. j = 0;
  27812. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  27813. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  27814. j++;
  27815. }
  27816. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  27817. found = true;
  27818. break;
  27819. }
  27820. i++;
  27821. }
  27822. if (found) {
  27823. skipped += i;
  27824. stream.pos += i;
  27825. break;
  27826. }
  27827. skipped += scanLength;
  27828. stream.pos += scanLength;
  27829. }
  27830. if (!found) {
  27831. error('Missing endstream');
  27832. }
  27833. length = skipped;
  27834. lexer.nextChar();
  27835. this.shift();
  27836. this.shift();
  27837. }
  27838. this.shift(); // 'endstream'
  27839. stream = stream.makeSubStream(pos, length, dict);
  27840. if (cipherTransform) {
  27841. stream = cipherTransform.createStream(stream, length);
  27842. }
  27843. stream = this.filter(stream, dict, length);
  27844. stream.dict = dict;
  27845. return stream;
  27846. },
  27847. filter: function Parser_filter(stream, dict, length) {
  27848. var filter = dict.get('Filter', 'F');
  27849. var params = dict.get('DecodeParms', 'DP');
  27850. if (isName(filter)) {
  27851. return this.makeFilter(stream, filter.name, length, params);
  27852. }
  27853. var maybeLength = length;
  27854. if (isArray(filter)) {
  27855. var filterArray = filter;
  27856. var paramsArray = params;
  27857. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  27858. filter = filterArray[i];
  27859. if (!isName(filter)) {
  27860. error('Bad filter name: ' + filter);
  27861. }
  27862. params = null;
  27863. if (isArray(paramsArray) && (i in paramsArray)) {
  27864. params = paramsArray[i];
  27865. }
  27866. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  27867. // after the first stream the length variable is invalid
  27868. maybeLength = null;
  27869. }
  27870. }
  27871. return stream;
  27872. },
  27873. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  27874. // Since the 'Length' entry in the stream dictionary can be completely
  27875. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  27876. // when we can be absolutely certain that it actually is empty.
  27877. if (maybeLength === 0) {
  27878. warn('Empty "' + name + '" stream.');
  27879. return new NullStream(stream);
  27880. }
  27881. try {
  27882. if (params && this.xref) {
  27883. params = this.xref.fetchIfRef(params);
  27884. }
  27885. var xrefStreamStats = this.xref.stats.streamTypes;
  27886. if (name === 'FlateDecode' || name === 'Fl') {
  27887. xrefStreamStats[StreamType.FLATE] = true;
  27888. if (params) {
  27889. return new PredictorStream(new FlateStream(stream, maybeLength),
  27890. maybeLength, params);
  27891. }
  27892. return new FlateStream(stream, maybeLength);
  27893. }
  27894. if (name === 'LZWDecode' || name === 'LZW') {
  27895. xrefStreamStats[StreamType.LZW] = true;
  27896. var earlyChange = 1;
  27897. if (params) {
  27898. if (params.has('EarlyChange')) {
  27899. earlyChange = params.get('EarlyChange');
  27900. }
  27901. return new PredictorStream(
  27902. new LZWStream(stream, maybeLength, earlyChange),
  27903. maybeLength, params);
  27904. }
  27905. return new LZWStream(stream, maybeLength, earlyChange);
  27906. }
  27907. if (name === 'DCTDecode' || name === 'DCT') {
  27908. xrefStreamStats[StreamType.DCT] = true;
  27909. return new JpegStream(stream, maybeLength, stream.dict);
  27910. }
  27911. if (name === 'JPXDecode' || name === 'JPX') {
  27912. xrefStreamStats[StreamType.JPX] = true;
  27913. return new JpxStream(stream, maybeLength, stream.dict);
  27914. }
  27915. if (name === 'ASCII85Decode' || name === 'A85') {
  27916. xrefStreamStats[StreamType.A85] = true;
  27917. return new Ascii85Stream(stream, maybeLength);
  27918. }
  27919. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  27920. xrefStreamStats[StreamType.AHX] = true;
  27921. return new AsciiHexStream(stream, maybeLength);
  27922. }
  27923. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  27924. xrefStreamStats[StreamType.CCF] = true;
  27925. return new CCITTFaxStream(stream, maybeLength, params);
  27926. }
  27927. if (name === 'RunLengthDecode' || name === 'RL') {
  27928. xrefStreamStats[StreamType.RL] = true;
  27929. return new RunLengthStream(stream, maybeLength);
  27930. }
  27931. if (name === 'JBIG2Decode') {
  27932. xrefStreamStats[StreamType.JBIG] = true;
  27933. return new Jbig2Stream(stream, maybeLength, stream.dict);
  27934. }
  27935. warn('filter "' + name + '" not supported yet');
  27936. return stream;
  27937. } catch (ex) {
  27938. if (ex instanceof MissingDataException) {
  27939. throw ex;
  27940. }
  27941. warn('Invalid stream: \"' + ex + '\"');
  27942. return new NullStream(stream);
  27943. }
  27944. }
  27945. };
  27946. return Parser;
  27947. })();
  27948. var Lexer = (function LexerClosure() {
  27949. function Lexer(stream, knownCommands) {
  27950. this.stream = stream;
  27951. this.nextChar();
  27952. // While lexing, we build up many strings one char at a time. Using += for
  27953. // this can result in lots of garbage strings. It's better to build an
  27954. // array of single-char strings and then join() them together at the end.
  27955. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  27956. // purpose uses less memory than using a new array for each string.
  27957. this.strBuf = [];
  27958. // The PDFs might have "glued" commands with other commands, operands or
  27959. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  27960. // commands and their prefixes. The prefixes are built the following way:
  27961. // if there a command that is a prefix of the other valid command or
  27962. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  27963. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  27964. // other commands or literals as a prefix. The knowCommands is optional.
  27965. this.knownCommands = knownCommands;
  27966. }
  27967. // A '1' in this array means the character is white space. A '1' or
  27968. // '2' means the character ends a name or command.
  27969. var specialChars = [
  27970. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  27971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  27972. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  27973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  27974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  27975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  27976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  27977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  27978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  27979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  27980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  27981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  27982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  27983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  27984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  27985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  27986. ];
  27987. function toHexDigit(ch) {
  27988. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  27989. return ch & 0x0F;
  27990. }
  27991. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  27992. // 'A'-'F', 'a'-'f'
  27993. return (ch & 0x0F) + 9;
  27994. }
  27995. return -1;
  27996. }
  27997. Lexer.prototype = {
  27998. nextChar: function Lexer_nextChar() {
  27999. return (this.currentChar = this.stream.getByte());
  28000. },
  28001. peekChar: function Lexer_peekChar() {
  28002. return this.stream.peekByte();
  28003. },
  28004. getNumber: function Lexer_getNumber() {
  28005. var ch = this.currentChar;
  28006. var eNotation = false;
  28007. var divideBy = 0; // different from 0 if it's a floating point value
  28008. var sign = 1;
  28009. if (ch === 0x2D) { // '-'
  28010. sign = -1;
  28011. ch = this.nextChar();
  28012. if (ch === 0x2D) { // '-'
  28013. // Ignore double negative (this is consistent with Adobe Reader).
  28014. ch = this.nextChar();
  28015. }
  28016. } else if (ch === 0x2B) { // '+'
  28017. ch = this.nextChar();
  28018. }
  28019. if (ch === 0x2E) { // '.'
  28020. divideBy = 10;
  28021. ch = this.nextChar();
  28022. }
  28023. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28024. error('Invalid number: ' + String.fromCharCode(ch));
  28025. return 0;
  28026. }
  28027. var baseValue = ch - 0x30; // '0'
  28028. var powerValue = 0;
  28029. var powerValueSign = 1;
  28030. while ((ch = this.nextChar()) >= 0) {
  28031. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28032. var currentDigit = ch - 0x30; // '0'
  28033. if (eNotation) { // We are after an 'e' or 'E'
  28034. powerValue = powerValue * 10 + currentDigit;
  28035. } else {
  28036. if (divideBy !== 0) { // We are after a point
  28037. divideBy *= 10;
  28038. }
  28039. baseValue = baseValue * 10 + currentDigit;
  28040. }
  28041. } else if (ch === 0x2E) { // '.'
  28042. if (divideBy === 0) {
  28043. divideBy = 1;
  28044. } else {
  28045. // A number can have only one '.'
  28046. break;
  28047. }
  28048. } else if (ch === 0x2D) { // '-'
  28049. // ignore minus signs in the middle of numbers to match
  28050. // Adobe's behavior
  28051. warn('Badly formatted number');
  28052. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  28053. // 'E' can be either a scientific notation or the beginning of a new
  28054. // operator
  28055. ch = this.peekChar();
  28056. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  28057. powerValueSign = (ch === 0x2D) ? -1 : 1;
  28058. this.nextChar(); // Consume the sign character
  28059. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28060. // The 'E' must be the beginning of a new operator
  28061. break;
  28062. }
  28063. eNotation = true;
  28064. } else {
  28065. // the last character doesn't belong to us
  28066. break;
  28067. }
  28068. }
  28069. if (divideBy !== 0) {
  28070. baseValue /= divideBy;
  28071. }
  28072. if (eNotation) {
  28073. baseValue *= Math.pow(10, powerValueSign * powerValue);
  28074. }
  28075. return sign * baseValue;
  28076. },
  28077. getString: function Lexer_getString() {
  28078. var numParen = 1;
  28079. var done = false;
  28080. var strBuf = this.strBuf;
  28081. strBuf.length = 0;
  28082. var ch = this.nextChar();
  28083. while (true) {
  28084. var charBuffered = false;
  28085. switch (ch | 0) {
  28086. case -1:
  28087. warn('Unterminated string');
  28088. done = true;
  28089. break;
  28090. case 0x28: // '('
  28091. ++numParen;
  28092. strBuf.push('(');
  28093. break;
  28094. case 0x29: // ')'
  28095. if (--numParen === 0) {
  28096. this.nextChar(); // consume strings ')'
  28097. done = true;
  28098. } else {
  28099. strBuf.push(')');
  28100. }
  28101. break;
  28102. case 0x5C: // '\\'
  28103. ch = this.nextChar();
  28104. switch (ch) {
  28105. case -1:
  28106. warn('Unterminated string');
  28107. done = true;
  28108. break;
  28109. case 0x6E: // 'n'
  28110. strBuf.push('\n');
  28111. break;
  28112. case 0x72: // 'r'
  28113. strBuf.push('\r');
  28114. break;
  28115. case 0x74: // 't'
  28116. strBuf.push('\t');
  28117. break;
  28118. case 0x62: // 'b'
  28119. strBuf.push('\b');
  28120. break;
  28121. case 0x66: // 'f'
  28122. strBuf.push('\f');
  28123. break;
  28124. case 0x5C: // '\'
  28125. case 0x28: // '('
  28126. case 0x29: // ')'
  28127. strBuf.push(String.fromCharCode(ch));
  28128. break;
  28129. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28130. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28131. var x = ch & 0x0F;
  28132. ch = this.nextChar();
  28133. charBuffered = true;
  28134. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28135. x = (x << 3) + (ch & 0x0F);
  28136. ch = this.nextChar();
  28137. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28138. charBuffered = false;
  28139. x = (x << 3) + (ch & 0x0F);
  28140. }
  28141. }
  28142. strBuf.push(String.fromCharCode(x));
  28143. break;
  28144. case 0x0D: // CR
  28145. if (this.peekChar() === 0x0A) { // LF
  28146. this.nextChar();
  28147. }
  28148. break;
  28149. case 0x0A: // LF
  28150. break;
  28151. default:
  28152. strBuf.push(String.fromCharCode(ch));
  28153. break;
  28154. }
  28155. break;
  28156. default:
  28157. strBuf.push(String.fromCharCode(ch));
  28158. break;
  28159. }
  28160. if (done) {
  28161. break;
  28162. }
  28163. if (!charBuffered) {
  28164. ch = this.nextChar();
  28165. }
  28166. }
  28167. return strBuf.join('');
  28168. },
  28169. getName: function Lexer_getName() {
  28170. var ch, previousCh;
  28171. var strBuf = this.strBuf;
  28172. strBuf.length = 0;
  28173. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28174. if (ch === 0x23) { // '#'
  28175. ch = this.nextChar();
  28176. if (specialChars[ch]) {
  28177. warn('Lexer_getName: ' +
  28178. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  28179. strBuf.push('#');
  28180. break;
  28181. }
  28182. var x = toHexDigit(ch);
  28183. if (x !== -1) {
  28184. previousCh = ch;
  28185. ch = this.nextChar();
  28186. var x2 = toHexDigit(ch);
  28187. if (x2 === -1) {
  28188. warn('Lexer_getName: Illegal digit (' +
  28189. String.fromCharCode(ch) +') in hexadecimal number.');
  28190. strBuf.push('#', String.fromCharCode(previousCh));
  28191. if (specialChars[ch]) {
  28192. break;
  28193. }
  28194. strBuf.push(String.fromCharCode(ch));
  28195. continue;
  28196. }
  28197. strBuf.push(String.fromCharCode((x << 4) | x2));
  28198. } else {
  28199. strBuf.push('#', String.fromCharCode(ch));
  28200. }
  28201. } else {
  28202. strBuf.push(String.fromCharCode(ch));
  28203. }
  28204. }
  28205. if (strBuf.length > 127) {
  28206. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  28207. }
  28208. return Name.get(strBuf.join(''));
  28209. },
  28210. getHexString: function Lexer_getHexString() {
  28211. var strBuf = this.strBuf;
  28212. strBuf.length = 0;
  28213. var ch = this.currentChar;
  28214. var isFirstHex = true;
  28215. var firstDigit;
  28216. var secondDigit;
  28217. while (true) {
  28218. if (ch < 0) {
  28219. warn('Unterminated hex string');
  28220. break;
  28221. } else if (ch === 0x3E) { // '>'
  28222. this.nextChar();
  28223. break;
  28224. } else if (specialChars[ch] === 1) {
  28225. ch = this.nextChar();
  28226. continue;
  28227. } else {
  28228. if (isFirstHex) {
  28229. firstDigit = toHexDigit(ch);
  28230. if (firstDigit === -1) {
  28231. warn('Ignoring invalid character "' + ch + '" in hex string');
  28232. ch = this.nextChar();
  28233. continue;
  28234. }
  28235. } else {
  28236. secondDigit = toHexDigit(ch);
  28237. if (secondDigit === -1) {
  28238. warn('Ignoring invalid character "' + ch + '" in hex string');
  28239. ch = this.nextChar();
  28240. continue;
  28241. }
  28242. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28243. }
  28244. isFirstHex = !isFirstHex;
  28245. ch = this.nextChar();
  28246. }
  28247. }
  28248. return strBuf.join('');
  28249. },
  28250. getObj: function Lexer_getObj() {
  28251. // skip whitespace and comments
  28252. var comment = false;
  28253. var ch = this.currentChar;
  28254. while (true) {
  28255. if (ch < 0) {
  28256. return EOF;
  28257. }
  28258. if (comment) {
  28259. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28260. comment = false;
  28261. }
  28262. } else if (ch === 0x25) { // '%'
  28263. comment = true;
  28264. } else if (specialChars[ch] !== 1) {
  28265. break;
  28266. }
  28267. ch = this.nextChar();
  28268. }
  28269. // start reading token
  28270. switch (ch | 0) {
  28271. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28272. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28273. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28274. return this.getNumber();
  28275. case 0x28: // '('
  28276. return this.getString();
  28277. case 0x2F: // '/'
  28278. return this.getName();
  28279. // array punctuation
  28280. case 0x5B: // '['
  28281. this.nextChar();
  28282. return Cmd.get('[');
  28283. case 0x5D: // ']'
  28284. this.nextChar();
  28285. return Cmd.get(']');
  28286. // hex string or dict punctuation
  28287. case 0x3C: // '<'
  28288. ch = this.nextChar();
  28289. if (ch === 0x3C) {
  28290. // dict punctuation
  28291. this.nextChar();
  28292. return Cmd.get('<<');
  28293. }
  28294. return this.getHexString();
  28295. // dict punctuation
  28296. case 0x3E: // '>'
  28297. ch = this.nextChar();
  28298. if (ch === 0x3E) {
  28299. this.nextChar();
  28300. return Cmd.get('>>');
  28301. }
  28302. return Cmd.get('>');
  28303. case 0x7B: // '{'
  28304. this.nextChar();
  28305. return Cmd.get('{');
  28306. case 0x7D: // '}'
  28307. this.nextChar();
  28308. return Cmd.get('}');
  28309. case 0x29: // ')'
  28310. error('Illegal character: ' + ch);
  28311. break;
  28312. }
  28313. // command
  28314. var str = String.fromCharCode(ch);
  28315. var knownCommands = this.knownCommands;
  28316. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28317. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28318. // stop if known command is found and next character does not make
  28319. // the str a command
  28320. var possibleCommand = str + String.fromCharCode(ch);
  28321. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  28322. break;
  28323. }
  28324. if (str.length === 128) {
  28325. error('Command token too long: ' + str.length);
  28326. }
  28327. str = possibleCommand;
  28328. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28329. }
  28330. if (str === 'true') {
  28331. return true;
  28332. }
  28333. if (str === 'false') {
  28334. return false;
  28335. }
  28336. if (str === 'null') {
  28337. return null;
  28338. }
  28339. return Cmd.get(str);
  28340. },
  28341. skipToNextLine: function Lexer_skipToNextLine() {
  28342. var ch = this.currentChar;
  28343. while (ch >= 0) {
  28344. if (ch === 0x0D) { // CR
  28345. ch = this.nextChar();
  28346. if (ch === 0x0A) { // LF
  28347. this.nextChar();
  28348. }
  28349. break;
  28350. } else if (ch === 0x0A) { // LF
  28351. this.nextChar();
  28352. break;
  28353. }
  28354. ch = this.nextChar();
  28355. }
  28356. }
  28357. };
  28358. return Lexer;
  28359. })();
  28360. var Linearization = {
  28361. create: function LinearizationCreate(stream) {
  28362. function getInt(name, allowZeroValue) {
  28363. var obj = linDict.get(name);
  28364. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  28365. return obj;
  28366. }
  28367. throw new Error('The "' + name + '" parameter in the linearization ' +
  28368. 'dictionary is invalid.');
  28369. }
  28370. function getHints() {
  28371. var hints = linDict.get('H'), hintsLength, item;
  28372. if (isArray(hints) &&
  28373. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  28374. for (var index = 0; index < hintsLength; index++) {
  28375. if (!(isInt(item = hints[index]) && item > 0)) {
  28376. throw new Error('Hint (' + index +
  28377. ') in the linearization dictionary is invalid.');
  28378. }
  28379. }
  28380. return hints;
  28381. }
  28382. throw new Error('Hint array in the linearization dictionary is invalid.');
  28383. }
  28384. var parser = new Parser(new Lexer(stream), false, null);
  28385. var obj1 = parser.getObj();
  28386. var obj2 = parser.getObj();
  28387. var obj3 = parser.getObj();
  28388. var linDict = parser.getObj();
  28389. var obj, length;
  28390. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  28391. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  28392. return null; // No valid linearization dictionary found.
  28393. } else if ((length = getInt('L')) !== stream.length) {
  28394. throw new Error('The "L" parameter in the linearization dictionary ' +
  28395. 'does not equal the stream length.');
  28396. }
  28397. return {
  28398. length: length,
  28399. hints: getHints(),
  28400. objectNumberFirst: getInt('O'),
  28401. endFirst: getInt('E'),
  28402. numPages: getInt('N'),
  28403. mainXRefEntriesOffset: getInt('T'),
  28404. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  28405. };
  28406. }
  28407. };
  28408. exports.EOF = EOF;
  28409. exports.Lexer = Lexer;
  28410. exports.Linearization = Linearization;
  28411. exports.Parser = Parser;
  28412. exports.isEOF = isEOF;
  28413. }));
  28414. (function (root, factory) {
  28415. {
  28416. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  28417. root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  28418. }
  28419. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  28420. var warn = sharedUtil.warn;
  28421. var isSpace = sharedUtil.isSpace;
  28422. var Stream = coreStream.Stream;
  28423. var getEncoding = coreEncodings.getEncoding;
  28424. // Hinting is currently disabled due to unknown problems on windows
  28425. // in tracemonkey and various other pdfs with type1 fonts.
  28426. var HINTING_ENABLED = false;
  28427. /*
  28428. * CharStrings are encoded following the the CharString Encoding sequence
  28429. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  28430. * The value in a byte indicates a command, a number, or subsequent bytes
  28431. * that are to be interpreted in a special way.
  28432. *
  28433. * CharString Number Encoding:
  28434. * A CharString byte containing the values from 32 through 255 inclusive
  28435. * indicate an integer. These values are decoded in four ranges.
  28436. *
  28437. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  28438. * indicate the integer v - 139. Thus, the integer values from -107 through
  28439. * 107 inclusive may be encoded in single byte.
  28440. *
  28441. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  28442. * indicates an integer involving the next byte, w, according to the formula:
  28443. * [(v - 247) x 256] + w + 108
  28444. *
  28445. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  28446. * indicates an integer involving the next byte, w, according to the formula:
  28447. * -[(v - 251) * 256] - w - 108
  28448. *
  28449. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  28450. * are a two complement signed integer. The first of these bytes contains the
  28451. * highest order bits, the second byte contains the next higher order bits
  28452. * and the fourth byte contain the lowest order bits.
  28453. *
  28454. *
  28455. * CharString Command Encoding:
  28456. * CharStrings commands are encoded in 1 or 2 bytes.
  28457. *
  28458. * Single byte commands are encoded in 1 byte that contains a value between
  28459. * 0 and 31 inclusive.
  28460. * If a command byte contains the value 12, then the value in the next byte
  28461. * indicates a command. This "escape" mechanism allows many extra commands
  28462. * to be encoded and this encoding technique helps to minimize the length of
  28463. * the charStrings.
  28464. */
  28465. var Type1CharString = (function Type1CharStringClosure() {
  28466. var COMMAND_MAP = {
  28467. 'hstem': [1],
  28468. 'vstem': [3],
  28469. 'vmoveto': [4],
  28470. 'rlineto': [5],
  28471. 'hlineto': [6],
  28472. 'vlineto': [7],
  28473. 'rrcurveto': [8],
  28474. 'callsubr': [10],
  28475. 'flex': [12, 35],
  28476. 'drop' : [12, 18],
  28477. 'endchar': [14],
  28478. 'rmoveto': [21],
  28479. 'hmoveto': [22],
  28480. 'vhcurveto': [30],
  28481. 'hvcurveto': [31]
  28482. };
  28483. function Type1CharString() {
  28484. this.width = 0;
  28485. this.lsb = 0;
  28486. this.flexing = false;
  28487. this.output = [];
  28488. this.stack = [];
  28489. }
  28490. Type1CharString.prototype = {
  28491. convert: function Type1CharString_convert(encoded, subrs,
  28492. seacAnalysisEnabled) {
  28493. var count = encoded.length;
  28494. var error = false;
  28495. var wx, sbx, subrNumber;
  28496. for (var i = 0; i < count; i++) {
  28497. var value = encoded[i];
  28498. if (value < 32) {
  28499. if (value === 12) {
  28500. value = (value << 8) + encoded[++i];
  28501. }
  28502. switch (value) {
  28503. case 1: // hstem
  28504. if (!HINTING_ENABLED) {
  28505. this.stack = [];
  28506. break;
  28507. }
  28508. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28509. break;
  28510. case 3: // vstem
  28511. if (!HINTING_ENABLED) {
  28512. this.stack = [];
  28513. break;
  28514. }
  28515. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28516. break;
  28517. case 4: // vmoveto
  28518. if (this.flexing) {
  28519. if (this.stack.length < 1) {
  28520. error = true;
  28521. break;
  28522. }
  28523. // Add the dx for flex and but also swap the values so they are
  28524. // the right order.
  28525. var dy = this.stack.pop();
  28526. this.stack.push(0, dy);
  28527. break;
  28528. }
  28529. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  28530. break;
  28531. case 5: // rlineto
  28532. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  28533. break;
  28534. case 6: // hlineto
  28535. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  28536. break;
  28537. case 7: // vlineto
  28538. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  28539. break;
  28540. case 8: // rrcurveto
  28541. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  28542. break;
  28543. case 9: // closepath
  28544. // closepath is a Type1 command that does not take argument and is
  28545. // useless in Type2 and it can simply be ignored.
  28546. this.stack = [];
  28547. break;
  28548. case 10: // callsubr
  28549. if (this.stack.length < 1) {
  28550. error = true;
  28551. break;
  28552. }
  28553. subrNumber = this.stack.pop();
  28554. error = this.convert(subrs[subrNumber], subrs,
  28555. seacAnalysisEnabled);
  28556. break;
  28557. case 11: // return
  28558. return error;
  28559. case 13: // hsbw
  28560. if (this.stack.length < 2) {
  28561. error = true;
  28562. break;
  28563. }
  28564. // To convert to type2 we have to move the width value to the
  28565. // first part of the charstring and then use hmoveto with lsb.
  28566. wx = this.stack.pop();
  28567. sbx = this.stack.pop();
  28568. this.lsb = sbx;
  28569. this.width = wx;
  28570. this.stack.push(wx, sbx);
  28571. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  28572. break;
  28573. case 14: // endchar
  28574. this.output.push(COMMAND_MAP.endchar[0]);
  28575. break;
  28576. case 21: // rmoveto
  28577. if (this.flexing) {
  28578. break;
  28579. }
  28580. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  28581. break;
  28582. case 22: // hmoveto
  28583. if (this.flexing) {
  28584. // Add the dy for flex.
  28585. this.stack.push(0);
  28586. break;
  28587. }
  28588. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  28589. break;
  28590. case 30: // vhcurveto
  28591. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  28592. break;
  28593. case 31: // hvcurveto
  28594. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  28595. break;
  28596. case (12 << 8) + 0: // dotsection
  28597. // dotsection is a Type1 command to specify some hinting feature
  28598. // for dots that do not take a parameter and it can safely be
  28599. // ignored for Type2.
  28600. this.stack = [];
  28601. break;
  28602. case (12 << 8) + 1: // vstem3
  28603. if (!HINTING_ENABLED) {
  28604. this.stack = [];
  28605. break;
  28606. }
  28607. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28608. // multiple parameters, so instead of returning [vh]stem3 take a
  28609. // shortcut and return [vhstem] instead.
  28610. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28611. break;
  28612. case (12 << 8) + 2: // hstem3
  28613. if (!HINTING_ENABLED) {
  28614. this.stack = [];
  28615. break;
  28616. }
  28617. // See vstem3.
  28618. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28619. break;
  28620. case (12 << 8) + 6: // seac
  28621. // seac is like type 2's special endchar but it doesn't use the
  28622. // first argument asb, so remove it.
  28623. if (seacAnalysisEnabled) {
  28624. this.seac = this.stack.splice(-4, 4);
  28625. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28626. } else {
  28627. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28628. }
  28629. break;
  28630. case (12 << 8) + 7: // sbw
  28631. if (this.stack.length < 4) {
  28632. error = true;
  28633. break;
  28634. }
  28635. // To convert to type2 we have to move the width value to the
  28636. // first part of the charstring and then use rmoveto with
  28637. // (dx, dy). The height argument will not be used for vmtx and
  28638. // vhea tables reconstruction -- ignoring it.
  28639. var wy = this.stack.pop();
  28640. wx = this.stack.pop();
  28641. var sby = this.stack.pop();
  28642. sbx = this.stack.pop();
  28643. this.lsb = sbx;
  28644. this.width = wx;
  28645. this.stack.push(wx, sbx, sby);
  28646. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28647. break;
  28648. case (12 << 8) + 12: // div
  28649. if (this.stack.length < 2) {
  28650. error = true;
  28651. break;
  28652. }
  28653. var num2 = this.stack.pop();
  28654. var num1 = this.stack.pop();
  28655. this.stack.push(num1 / num2);
  28656. break;
  28657. case (12 << 8) + 16: // callothersubr
  28658. if (this.stack.length < 2) {
  28659. error = true;
  28660. break;
  28661. }
  28662. subrNumber = this.stack.pop();
  28663. var numArgs = this.stack.pop();
  28664. if (subrNumber === 0 && numArgs === 3) {
  28665. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28666. this.stack.push(
  28667. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28668. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28669. flexArgs[4], // bcp2x
  28670. flexArgs[5], // bcp2y
  28671. flexArgs[6], // p2x
  28672. flexArgs[7], // p2y
  28673. flexArgs[8], // bcp3x
  28674. flexArgs[9], // bcp3y
  28675. flexArgs[10], // bcp4x
  28676. flexArgs[11], // bcp4y
  28677. flexArgs[12], // p3x
  28678. flexArgs[13], // p3y
  28679. flexArgs[14] // flexDepth
  28680. // 15 = finalx unused by flex
  28681. // 16 = finaly unused by flex
  28682. );
  28683. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28684. this.flexing = false;
  28685. this.stack.push(flexArgs[15], flexArgs[16]);
  28686. } else if (subrNumber === 1 && numArgs === 0) {
  28687. this.flexing = true;
  28688. }
  28689. break;
  28690. case (12 << 8) + 17: // pop
  28691. // Ignore this since it is only used with othersubr.
  28692. break;
  28693. case (12 << 8) + 33: // setcurrentpoint
  28694. // Ignore for now.
  28695. this.stack = [];
  28696. break;
  28697. default:
  28698. warn('Unknown type 1 charstring command of "' + value + '"');
  28699. break;
  28700. }
  28701. if (error) {
  28702. break;
  28703. }
  28704. continue;
  28705. } else if (value <= 246) {
  28706. value = value - 139;
  28707. } else if (value <= 250) {
  28708. value = ((value - 247) * 256) + encoded[++i] + 108;
  28709. } else if (value <= 254) {
  28710. value = -((value - 251) * 256) - encoded[++i] - 108;
  28711. } else {
  28712. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28713. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28714. }
  28715. this.stack.push(value);
  28716. }
  28717. return error;
  28718. },
  28719. executeCommand: function(howManyArgs, command, keepStack) {
  28720. var stackLength = this.stack.length;
  28721. if (howManyArgs > stackLength) {
  28722. return true;
  28723. }
  28724. var start = stackLength - howManyArgs;
  28725. for (var i = start; i < stackLength; i++) {
  28726. var value = this.stack[i];
  28727. if (value === (value | 0)) { // int
  28728. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28729. } else { // fixed point
  28730. value = (65536 * value) | 0;
  28731. this.output.push(255,
  28732. (value >> 24) & 0xFF,
  28733. (value >> 16) & 0xFF,
  28734. (value >> 8) & 0xFF,
  28735. value & 0xFF);
  28736. }
  28737. }
  28738. this.output.push.apply(this.output, command);
  28739. if (keepStack) {
  28740. this.stack.splice(start, howManyArgs);
  28741. } else {
  28742. this.stack.length = 0;
  28743. }
  28744. return false;
  28745. }
  28746. };
  28747. return Type1CharString;
  28748. })();
  28749. /*
  28750. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28751. * program. Some of its logic depends on the Type2 charstrings
  28752. * structure.
  28753. * Note: this doesn't really parse the font since that would require evaluation
  28754. * of PostScript, but it is possible in most cases to extract what we need
  28755. * without a full parse.
  28756. */
  28757. var Type1Parser = (function Type1ParserClosure() {
  28758. /*
  28759. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28760. * of Plaintext Bytes. The function took a key as a parameter which can be
  28761. * for decrypting the eexec block of for decoding charStrings.
  28762. */
  28763. var EEXEC_ENCRYPT_KEY = 55665;
  28764. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28765. function isHexDigit(code) {
  28766. return code >= 48 && code <= 57 || // '0'-'9'
  28767. code >= 65 && code <= 70 || // 'A'-'F'
  28768. code >= 97 && code <= 102; // 'a'-'f'
  28769. }
  28770. function decrypt(data, key, discardNumber) {
  28771. if (discardNumber >= data.length) {
  28772. return new Uint8Array(0);
  28773. }
  28774. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  28775. for (i = 0; i < discardNumber; i++) {
  28776. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  28777. }
  28778. var count = data.length - discardNumber;
  28779. var decrypted = new Uint8Array(count);
  28780. for (i = discardNumber, j = 0; j < count; i++, j++) {
  28781. var value = data[i];
  28782. decrypted[j] = value ^ (r >> 8);
  28783. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28784. }
  28785. return decrypted;
  28786. }
  28787. function decryptAscii(data, key, discardNumber) {
  28788. var r = key | 0, c1 = 52845, c2 = 22719;
  28789. var count = data.length, maybeLength = count >>> 1;
  28790. var decrypted = new Uint8Array(maybeLength);
  28791. var i, j;
  28792. for (i = 0, j = 0; i < count; i++) {
  28793. var digit1 = data[i];
  28794. if (!isHexDigit(digit1)) {
  28795. continue;
  28796. }
  28797. i++;
  28798. var digit2;
  28799. while (i < count && !isHexDigit(digit2 = data[i])) {
  28800. i++;
  28801. }
  28802. if (i < count) {
  28803. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28804. decrypted[j++] = value ^ (r >> 8);
  28805. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28806. }
  28807. }
  28808. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28809. }
  28810. function isSpecial(c) {
  28811. return c === 0x2F || // '/'
  28812. c === 0x5B || c === 0x5D || // '[', ']'
  28813. c === 0x7B || c === 0x7D || // '{', '}'
  28814. c === 0x28 || c === 0x29; // '(', ')'
  28815. }
  28816. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  28817. if (encrypted) {
  28818. var data = stream.getBytes();
  28819. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28820. isHexDigit(data[2]) && isHexDigit(data[3]));
  28821. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28822. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28823. }
  28824. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  28825. this.stream = stream;
  28826. this.nextChar();
  28827. }
  28828. Type1Parser.prototype = {
  28829. readNumberArray: function Type1Parser_readNumberArray() {
  28830. this.getToken(); // read '[' or '{' (arrays can start with either)
  28831. var array = [];
  28832. while (true) {
  28833. var token = this.getToken();
  28834. if (token === null || token === ']' || token === '}') {
  28835. break;
  28836. }
  28837. array.push(parseFloat(token || 0));
  28838. }
  28839. return array;
  28840. },
  28841. readNumber: function Type1Parser_readNumber() {
  28842. var token = this.getToken();
  28843. return parseFloat(token || 0);
  28844. },
  28845. readInt: function Type1Parser_readInt() {
  28846. // Use '| 0' to prevent setting a double into length such as the double
  28847. // does not flow into the loop variable.
  28848. var token = this.getToken();
  28849. return parseInt(token || 0, 10) | 0;
  28850. },
  28851. readBoolean: function Type1Parser_readBoolean() {
  28852. var token = this.getToken();
  28853. // Use 1 and 0 since that's what type2 charstrings use.
  28854. return token === 'true' ? 1 : 0;
  28855. },
  28856. nextChar : function Type1_nextChar() {
  28857. return (this.currentChar = this.stream.getByte());
  28858. },
  28859. getToken: function Type1Parser_getToken() {
  28860. // Eat whitespace and comments.
  28861. var comment = false;
  28862. var ch = this.currentChar;
  28863. while (true) {
  28864. if (ch === -1) {
  28865. return null;
  28866. }
  28867. if (comment) {
  28868. if (ch === 0x0A || ch === 0x0D) {
  28869. comment = false;
  28870. }
  28871. } else if (ch === 0x25) { // '%'
  28872. comment = true;
  28873. } else if (!isSpace(ch)) {
  28874. break;
  28875. }
  28876. ch = this.nextChar();
  28877. }
  28878. if (isSpecial(ch)) {
  28879. this.nextChar();
  28880. return String.fromCharCode(ch);
  28881. }
  28882. var token = '';
  28883. do {
  28884. token += String.fromCharCode(ch);
  28885. ch = this.nextChar();
  28886. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  28887. return token;
  28888. },
  28889. /*
  28890. * Returns an object containing a Subrs array and a CharStrings
  28891. * array extracted from and eexec encrypted block of data
  28892. */
  28893. extractFontProgram: function Type1Parser_extractFontProgram() {
  28894. var stream = this.stream;
  28895. var subrs = [], charstrings = [];
  28896. var privateData = Object.create(null);
  28897. privateData['lenIV'] = 4;
  28898. var program = {
  28899. subrs: [],
  28900. charstrings: [],
  28901. properties: {
  28902. 'privateData': privateData
  28903. }
  28904. };
  28905. var token, length, data, lenIV, encoded;
  28906. while ((token = this.getToken()) !== null) {
  28907. if (token !== '/') {
  28908. continue;
  28909. }
  28910. token = this.getToken();
  28911. switch (token) {
  28912. case 'CharStrings':
  28913. // The number immediately following CharStrings must be greater or
  28914. // equal to the number of CharStrings.
  28915. this.getToken();
  28916. this.getToken(); // read in 'dict'
  28917. this.getToken(); // read in 'dup'
  28918. this.getToken(); // read in 'begin'
  28919. while(true) {
  28920. token = this.getToken();
  28921. if (token === null || token === 'end') {
  28922. break;
  28923. }
  28924. if (token !== '/') {
  28925. continue;
  28926. }
  28927. var glyph = this.getToken();
  28928. length = this.readInt();
  28929. this.getToken(); // read in 'RD' or '-|'
  28930. data = stream.makeSubStream(stream.pos, length);
  28931. lenIV = program.properties.privateData['lenIV'];
  28932. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28933. // Skip past the required space and binary data.
  28934. stream.skip(length);
  28935. this.nextChar();
  28936. token = this.getToken(); // read in 'ND' or '|-'
  28937. if (token === 'noaccess') {
  28938. this.getToken(); // read in 'def'
  28939. }
  28940. charstrings.push({
  28941. glyph: glyph,
  28942. encoded: encoded
  28943. });
  28944. }
  28945. break;
  28946. case 'Subrs':
  28947. var num = this.readInt();
  28948. this.getToken(); // read in 'array'
  28949. while ((token = this.getToken()) === 'dup') {
  28950. var index = this.readInt();
  28951. length = this.readInt();
  28952. this.getToken(); // read in 'RD' or '-|'
  28953. data = stream.makeSubStream(stream.pos, length);
  28954. lenIV = program.properties.privateData['lenIV'];
  28955. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28956. // Skip past the required space and binary data.
  28957. stream.skip(length);
  28958. this.nextChar();
  28959. token = this.getToken(); // read in 'NP' or '|'
  28960. if (token === 'noaccess') {
  28961. this.getToken(); // read in 'put'
  28962. }
  28963. subrs[index] = encoded;
  28964. }
  28965. break;
  28966. case 'BlueValues':
  28967. case 'OtherBlues':
  28968. case 'FamilyBlues':
  28969. case 'FamilyOtherBlues':
  28970. var blueArray = this.readNumberArray();
  28971. // *Blue* values may contain invalid data: disables reading of
  28972. // those values when hinting is disabled.
  28973. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  28974. HINTING_ENABLED) {
  28975. program.properties.privateData[token] = blueArray;
  28976. }
  28977. break;
  28978. case 'StemSnapH':
  28979. case 'StemSnapV':
  28980. program.properties.privateData[token] = this.readNumberArray();
  28981. break;
  28982. case 'StdHW':
  28983. case 'StdVW':
  28984. program.properties.privateData[token] =
  28985. this.readNumberArray()[0];
  28986. break;
  28987. case 'BlueShift':
  28988. case 'lenIV':
  28989. case 'BlueFuzz':
  28990. case 'BlueScale':
  28991. case 'LanguageGroup':
  28992. case 'ExpansionFactor':
  28993. program.properties.privateData[token] = this.readNumber();
  28994. break;
  28995. case 'ForceBold':
  28996. program.properties.privateData[token] = this.readBoolean();
  28997. break;
  28998. }
  28999. }
  29000. for (var i = 0; i < charstrings.length; i++) {
  29001. glyph = charstrings[i].glyph;
  29002. encoded = charstrings[i].encoded;
  29003. var charString = new Type1CharString();
  29004. var error = charString.convert(encoded, subrs,
  29005. this.seacAnalysisEnabled);
  29006. var output = charString.output;
  29007. if (error) {
  29008. // It seems when FreeType encounters an error while evaluating a glyph
  29009. // that it completely ignores the glyph so we'll mimic that behaviour
  29010. // here and put an endchar to make the validator happy.
  29011. output = [14];
  29012. }
  29013. program.charstrings.push({
  29014. glyphName: glyph,
  29015. charstring: output,
  29016. width: charString.width,
  29017. lsb: charString.lsb,
  29018. seac: charString.seac
  29019. });
  29020. }
  29021. return program;
  29022. },
  29023. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  29024. var token;
  29025. while ((token = this.getToken()) !== null) {
  29026. if (token !== '/') {
  29027. continue;
  29028. }
  29029. token = this.getToken();
  29030. switch (token) {
  29031. case 'FontMatrix':
  29032. var matrix = this.readNumberArray();
  29033. properties.fontMatrix = matrix;
  29034. break;
  29035. case 'Encoding':
  29036. var encodingArg = this.getToken();
  29037. var encoding;
  29038. if (!/^\d+$/.test(encodingArg)) {
  29039. // encoding name is specified
  29040. encoding = getEncoding(encodingArg);
  29041. } else {
  29042. encoding = [];
  29043. var size = parseInt(encodingArg, 10) | 0;
  29044. this.getToken(); // read in 'array'
  29045. for (var j = 0; j < size; j++) {
  29046. token = this.getToken();
  29047. // skipping till first dup or def (e.g. ignoring for statement)
  29048. while (token !== 'dup' && token !== 'def') {
  29049. token = this.getToken();
  29050. if (token === null) {
  29051. return; // invalid header
  29052. }
  29053. }
  29054. if (token === 'def') {
  29055. break; // read all array data
  29056. }
  29057. var index = this.readInt();
  29058. this.getToken(); // read in '/'
  29059. var glyph = this.getToken();
  29060. encoding[index] = glyph;
  29061. this.getToken(); // read the in 'put'
  29062. }
  29063. }
  29064. properties.builtInEncoding = encoding;
  29065. break;
  29066. case 'FontBBox':
  29067. var fontBBox = this.readNumberArray();
  29068. // adjusting ascent/descent
  29069. properties.ascent = fontBBox[3];
  29070. properties.descent = fontBBox[1];
  29071. properties.ascentScaled = true;
  29072. break;
  29073. }
  29074. }
  29075. }
  29076. };
  29077. return Type1Parser;
  29078. })();
  29079. exports.Type1Parser = Type1Parser;
  29080. }));
  29081. (function (root, factory) {
  29082. {
  29083. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  29084. root.pdfjsDisplayWebGL);
  29085. }
  29086. }(this, function (exports, sharedUtil, displayWebGL) {
  29087. var Util = sharedUtil.Util;
  29088. var info = sharedUtil.info;
  29089. var isArray = sharedUtil.isArray;
  29090. var error = sharedUtil.error;
  29091. var WebGLUtils = displayWebGL.WebGLUtils;
  29092. var ShadingIRs = {};
  29093. ShadingIRs.RadialAxial = {
  29094. fromIR: function RadialAxial_fromIR(raw) {
  29095. var type = raw[1];
  29096. var colorStops = raw[2];
  29097. var p0 = raw[3];
  29098. var p1 = raw[4];
  29099. var r0 = raw[5];
  29100. var r1 = raw[6];
  29101. return {
  29102. type: 'Pattern',
  29103. getPattern: function RadialAxial_getPattern(ctx) {
  29104. var grad;
  29105. if (type === 'axial') {
  29106. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  29107. } else if (type === 'radial') {
  29108. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  29109. }
  29110. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  29111. var c = colorStops[i];
  29112. grad.addColorStop(c[0], c[1]);
  29113. }
  29114. return grad;
  29115. }
  29116. };
  29117. }
  29118. };
  29119. var createMeshCanvas = (function createMeshCanvasClosure() {
  29120. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  29121. // Very basic Gouraud-shaded triangle rasterization algorithm.
  29122. var coords = context.coords, colors = context.colors;
  29123. var bytes = data.data, rowSize = data.width * 4;
  29124. var tmp;
  29125. if (coords[p1 + 1] > coords[p2 + 1]) {
  29126. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  29127. }
  29128. if (coords[p2 + 1] > coords[p3 + 1]) {
  29129. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  29130. }
  29131. if (coords[p1 + 1] > coords[p2 + 1]) {
  29132. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  29133. }
  29134. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  29135. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  29136. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  29137. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  29138. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  29139. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  29140. if (y1 >= y3) {
  29141. return;
  29142. }
  29143. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  29144. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  29145. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  29146. var minY = Math.round(y1), maxY = Math.round(y3);
  29147. var xa, car, cag, cab;
  29148. var xb, cbr, cbg, cbb;
  29149. var k;
  29150. for (var y = minY; y <= maxY; y++) {
  29151. if (y < y2) {
  29152. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  29153. xa = x1 - (x1 - x2) * k;
  29154. car = c1r - (c1r - c2r) * k;
  29155. cag = c1g - (c1g - c2g) * k;
  29156. cab = c1b - (c1b - c2b) * k;
  29157. } else {
  29158. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  29159. xa = x2 - (x2 - x3) * k;
  29160. car = c2r - (c2r - c3r) * k;
  29161. cag = c2g - (c2g - c3g) * k;
  29162. cab = c2b - (c2b - c3b) * k;
  29163. }
  29164. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  29165. xb = x1 - (x1 - x3) * k;
  29166. cbr = c1r - (c1r - c3r) * k;
  29167. cbg = c1g - (c1g - c3g) * k;
  29168. cbb = c1b - (c1b - c3b) * k;
  29169. var x1_ = Math.round(Math.min(xa, xb));
  29170. var x2_ = Math.round(Math.max(xa, xb));
  29171. var j = rowSize * y + x1_ * 4;
  29172. for (var x = x1_; x <= x2_; x++) {
  29173. k = (xa - x) / (xa - xb);
  29174. k = k < 0 ? 0 : k > 1 ? 1 : k;
  29175. bytes[j++] = (car - (car - cbr) * k) | 0;
  29176. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  29177. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  29178. bytes[j++] = 255;
  29179. }
  29180. }
  29181. }
  29182. function drawFigure(data, figure, context) {
  29183. var ps = figure.coords;
  29184. var cs = figure.colors;
  29185. var i, ii;
  29186. switch (figure.type) {
  29187. case 'lattice':
  29188. var verticesPerRow = figure.verticesPerRow;
  29189. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  29190. var cols = verticesPerRow - 1;
  29191. for (i = 0; i < rows; i++) {
  29192. var q = i * verticesPerRow;
  29193. for (var j = 0; j < cols; j++, q++) {
  29194. drawTriangle(data, context,
  29195. ps[q], ps[q + 1], ps[q + verticesPerRow],
  29196. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  29197. drawTriangle(data, context,
  29198. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  29199. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  29200. }
  29201. }
  29202. break;
  29203. case 'triangles':
  29204. for (i = 0, ii = ps.length; i < ii; i += 3) {
  29205. drawTriangle(data, context,
  29206. ps[i], ps[i + 1], ps[i + 2],
  29207. cs[i], cs[i + 1], cs[i + 2]);
  29208. }
  29209. break;
  29210. default:
  29211. error('illigal figure');
  29212. break;
  29213. }
  29214. }
  29215. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  29216. backgroundColor, cachedCanvases) {
  29217. // we will increase scale on some weird factor to let antialiasing take
  29218. // care of "rough" edges
  29219. var EXPECTED_SCALE = 1.1;
  29220. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  29221. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  29222. // We need to keep transparent border around our pattern for fill():
  29223. // createPattern with 'no-repeat' will bleed edges across entire area.
  29224. var BORDER_SIZE = 2;
  29225. var offsetX = Math.floor(bounds[0]);
  29226. var offsetY = Math.floor(bounds[1]);
  29227. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  29228. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  29229. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  29230. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  29231. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  29232. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  29233. var scaleX = boundsWidth / width;
  29234. var scaleY = boundsHeight / height;
  29235. var context = {
  29236. coords: coords,
  29237. colors: colors,
  29238. offsetX: -offsetX,
  29239. offsetY: -offsetY,
  29240. scaleX: 1 / scaleX,
  29241. scaleY: 1 / scaleY
  29242. };
  29243. var paddedWidth = width + BORDER_SIZE * 2;
  29244. var paddedHeight = height + BORDER_SIZE * 2;
  29245. var canvas, tmpCanvas, i, ii;
  29246. if (WebGLUtils.isEnabled) {
  29247. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  29248. figures, context);
  29249. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  29250. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
  29251. false);
  29252. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  29253. canvas = tmpCanvas.canvas;
  29254. } else {
  29255. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
  29256. false);
  29257. var tmpCtx = tmpCanvas.context;
  29258. var data = tmpCtx.createImageData(width, height);
  29259. if (backgroundColor) {
  29260. var bytes = data.data;
  29261. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  29262. bytes[i] = backgroundColor[0];
  29263. bytes[i + 1] = backgroundColor[1];
  29264. bytes[i + 2] = backgroundColor[2];
  29265. bytes[i + 3] = 255;
  29266. }
  29267. }
  29268. for (i = 0; i < figures.length; i++) {
  29269. drawFigure(data, figures[i], context);
  29270. }
  29271. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  29272. canvas = tmpCanvas.canvas;
  29273. }
  29274. return {canvas: canvas,
  29275. offsetX: offsetX - BORDER_SIZE * scaleX,
  29276. offsetY: offsetY - BORDER_SIZE * scaleY,
  29277. scaleX: scaleX, scaleY: scaleY};
  29278. }
  29279. return createMeshCanvas;
  29280. })();
  29281. ShadingIRs.Mesh = {
  29282. fromIR: function Mesh_fromIR(raw) {
  29283. //var type = raw[1];
  29284. var coords = raw[2];
  29285. var colors = raw[3];
  29286. var figures = raw[4];
  29287. var bounds = raw[5];
  29288. var matrix = raw[6];
  29289. //var bbox = raw[7];
  29290. var background = raw[8];
  29291. return {
  29292. type: 'Pattern',
  29293. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  29294. var scale;
  29295. if (shadingFill) {
  29296. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  29297. } else {
  29298. // Obtain scale from matrix and current transformation matrix.
  29299. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  29300. if (matrix) {
  29301. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  29302. scale = [scale[0] * matrixScale[0],
  29303. scale[1] * matrixScale[1]];
  29304. }
  29305. }
  29306. // Rasterizing on the main thread since sending/queue large canvases
  29307. // might cause OOM.
  29308. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  29309. colors, figures, shadingFill ? null : background,
  29310. owner.cachedCanvases);
  29311. if (!shadingFill) {
  29312. ctx.setTransform.apply(ctx, owner.baseTransform);
  29313. if (matrix) {
  29314. ctx.transform.apply(ctx, matrix);
  29315. }
  29316. }
  29317. ctx.translate(temporaryPatternCanvas.offsetX,
  29318. temporaryPatternCanvas.offsetY);
  29319. ctx.scale(temporaryPatternCanvas.scaleX,
  29320. temporaryPatternCanvas.scaleY);
  29321. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  29322. }
  29323. };
  29324. }
  29325. };
  29326. ShadingIRs.Dummy = {
  29327. fromIR: function Dummy_fromIR() {
  29328. return {
  29329. type: 'Pattern',
  29330. getPattern: function Dummy_fromIR_getPattern() {
  29331. return 'hotpink';
  29332. }
  29333. };
  29334. }
  29335. };
  29336. function getShadingPatternFromIR(raw) {
  29337. var shadingIR = ShadingIRs[raw[0]];
  29338. if (!shadingIR) {
  29339. error('Unknown IR type: ' + raw[0]);
  29340. }
  29341. return shadingIR.fromIR(raw);
  29342. }
  29343. var TilingPattern = (function TilingPatternClosure() {
  29344. var PaintType = {
  29345. COLORED: 1,
  29346. UNCOLORED: 2
  29347. };
  29348. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  29349. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  29350. this.operatorList = IR[2];
  29351. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  29352. this.bbox = IR[4];
  29353. this.xstep = IR[5];
  29354. this.ystep = IR[6];
  29355. this.paintType = IR[7];
  29356. this.tilingType = IR[8];
  29357. this.color = color;
  29358. this.canvasGraphicsFactory = canvasGraphicsFactory;
  29359. this.baseTransform = baseTransform;
  29360. this.type = 'Pattern';
  29361. this.ctx = ctx;
  29362. }
  29363. TilingPattern.prototype = {
  29364. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  29365. var operatorList = this.operatorList;
  29366. var bbox = this.bbox;
  29367. var xstep = this.xstep;
  29368. var ystep = this.ystep;
  29369. var paintType = this.paintType;
  29370. var tilingType = this.tilingType;
  29371. var color = this.color;
  29372. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  29373. info('TilingType: ' + tilingType);
  29374. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  29375. var topLeft = [x0, y0];
  29376. // we want the canvas to be as large as the step size
  29377. var botRight = [x0 + xstep, y0 + ystep];
  29378. var width = botRight[0] - topLeft[0];
  29379. var height = botRight[1] - topLeft[1];
  29380. // Obtain scale from matrix and current transformation matrix.
  29381. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  29382. var curMatrixScale = Util.singularValueDecompose2dScale(
  29383. this.baseTransform);
  29384. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  29385. matrixScale[1] * curMatrixScale[1]];
  29386. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  29387. // Use width and height values that are as close as possible to the end
  29388. // result when the pattern is used. Too low value makes the pattern look
  29389. // blurry. Too large value makes it look too crispy.
  29390. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  29391. MAX_PATTERN_SIZE);
  29392. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  29393. MAX_PATTERN_SIZE);
  29394. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  29395. width, height, true);
  29396. var tmpCtx = tmpCanvas.context;
  29397. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  29398. graphics.groupLevel = owner.groupLevel;
  29399. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  29400. this.setScale(width, height, xstep, ystep);
  29401. this.transformToScale(graphics);
  29402. // transform coordinates to pattern space
  29403. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  29404. graphics.transform.apply(graphics, tmpTranslate);
  29405. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  29406. graphics.executeOperatorList(operatorList);
  29407. return tmpCanvas.canvas;
  29408. },
  29409. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  29410. this.scale = [width / xstep, height / ystep];
  29411. },
  29412. transformToScale: function TilingPattern_transformToScale(graphics) {
  29413. var scale = this.scale;
  29414. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  29415. graphics.transform.apply(graphics, tmpScale);
  29416. },
  29417. scaleToContext: function TilingPattern_scaleToContext() {
  29418. var scale = this.scale;
  29419. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  29420. },
  29421. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  29422. if (bbox && isArray(bbox) && bbox.length === 4) {
  29423. var bboxWidth = x1 - x0;
  29424. var bboxHeight = y1 - y0;
  29425. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  29426. graphics.clip();
  29427. graphics.endPath();
  29428. }
  29429. },
  29430. setFillAndStrokeStyleToContext:
  29431. function setFillAndStrokeStyleToContext(context, paintType, color) {
  29432. switch (paintType) {
  29433. case PaintType.COLORED:
  29434. var ctx = this.ctx;
  29435. context.fillStyle = ctx.fillStyle;
  29436. context.strokeStyle = ctx.strokeStyle;
  29437. break;
  29438. case PaintType.UNCOLORED:
  29439. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  29440. context.fillStyle = cssColor;
  29441. context.strokeStyle = cssColor;
  29442. break;
  29443. default:
  29444. error('Unsupported paint type: ' + paintType);
  29445. }
  29446. },
  29447. getPattern: function TilingPattern_getPattern(ctx, owner) {
  29448. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  29449. ctx = this.ctx;
  29450. ctx.setTransform.apply(ctx, this.baseTransform);
  29451. ctx.transform.apply(ctx, this.matrix);
  29452. this.scaleToContext();
  29453. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  29454. }
  29455. };
  29456. return TilingPattern;
  29457. })();
  29458. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  29459. exports.TilingPattern = TilingPattern;
  29460. }));
  29461. (function (root, factory) {
  29462. {
  29463. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  29464. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  29465. }
  29466. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  29467. var Util = sharedUtil.Util;
  29468. var assert = sharedUtil.assert;
  29469. var warn = sharedUtil.warn;
  29470. var error = sharedUtil.error;
  29471. var isInt = sharedUtil.isInt;
  29472. var isString = sharedUtil.isString;
  29473. var MissingDataException = sharedUtil.MissingDataException;
  29474. var isName = corePrimitives.isName;
  29475. var isCmd = corePrimitives.isCmd;
  29476. var isStream = corePrimitives.isStream;
  29477. var StringStream = coreStream.StringStream;
  29478. var Lexer = coreParser.Lexer;
  29479. var isEOF = coreParser.isEOF;
  29480. var BUILT_IN_CMAPS = [
  29481. // << Start unicode maps.
  29482. 'Adobe-GB1-UCS2',
  29483. 'Adobe-CNS1-UCS2',
  29484. 'Adobe-Japan1-UCS2',
  29485. 'Adobe-Korea1-UCS2',
  29486. // >> End unicode maps.
  29487. '78-EUC-H',
  29488. '78-EUC-V',
  29489. '78-H',
  29490. '78-RKSJ-H',
  29491. '78-RKSJ-V',
  29492. '78-V',
  29493. '78ms-RKSJ-H',
  29494. '78ms-RKSJ-V',
  29495. '83pv-RKSJ-H',
  29496. '90ms-RKSJ-H',
  29497. '90ms-RKSJ-V',
  29498. '90msp-RKSJ-H',
  29499. '90msp-RKSJ-V',
  29500. '90pv-RKSJ-H',
  29501. '90pv-RKSJ-V',
  29502. 'Add-H',
  29503. 'Add-RKSJ-H',
  29504. 'Add-RKSJ-V',
  29505. 'Add-V',
  29506. 'Adobe-CNS1-0',
  29507. 'Adobe-CNS1-1',
  29508. 'Adobe-CNS1-2',
  29509. 'Adobe-CNS1-3',
  29510. 'Adobe-CNS1-4',
  29511. 'Adobe-CNS1-5',
  29512. 'Adobe-CNS1-6',
  29513. 'Adobe-GB1-0',
  29514. 'Adobe-GB1-1',
  29515. 'Adobe-GB1-2',
  29516. 'Adobe-GB1-3',
  29517. 'Adobe-GB1-4',
  29518. 'Adobe-GB1-5',
  29519. 'Adobe-Japan1-0',
  29520. 'Adobe-Japan1-1',
  29521. 'Adobe-Japan1-2',
  29522. 'Adobe-Japan1-3',
  29523. 'Adobe-Japan1-4',
  29524. 'Adobe-Japan1-5',
  29525. 'Adobe-Japan1-6',
  29526. 'Adobe-Korea1-0',
  29527. 'Adobe-Korea1-1',
  29528. 'Adobe-Korea1-2',
  29529. 'B5-H',
  29530. 'B5-V',
  29531. 'B5pc-H',
  29532. 'B5pc-V',
  29533. 'CNS-EUC-H',
  29534. 'CNS-EUC-V',
  29535. 'CNS1-H',
  29536. 'CNS1-V',
  29537. 'CNS2-H',
  29538. 'CNS2-V',
  29539. 'ETHK-B5-H',
  29540. 'ETHK-B5-V',
  29541. 'ETen-B5-H',
  29542. 'ETen-B5-V',
  29543. 'ETenms-B5-H',
  29544. 'ETenms-B5-V',
  29545. 'EUC-H',
  29546. 'EUC-V',
  29547. 'Ext-H',
  29548. 'Ext-RKSJ-H',
  29549. 'Ext-RKSJ-V',
  29550. 'Ext-V',
  29551. 'GB-EUC-H',
  29552. 'GB-EUC-V',
  29553. 'GB-H',
  29554. 'GB-V',
  29555. 'GBK-EUC-H',
  29556. 'GBK-EUC-V',
  29557. 'GBK2K-H',
  29558. 'GBK2K-V',
  29559. 'GBKp-EUC-H',
  29560. 'GBKp-EUC-V',
  29561. 'GBT-EUC-H',
  29562. 'GBT-EUC-V',
  29563. 'GBT-H',
  29564. 'GBT-V',
  29565. 'GBTpc-EUC-H',
  29566. 'GBTpc-EUC-V',
  29567. 'GBpc-EUC-H',
  29568. 'GBpc-EUC-V',
  29569. 'H',
  29570. 'HKdla-B5-H',
  29571. 'HKdla-B5-V',
  29572. 'HKdlb-B5-H',
  29573. 'HKdlb-B5-V',
  29574. 'HKgccs-B5-H',
  29575. 'HKgccs-B5-V',
  29576. 'HKm314-B5-H',
  29577. 'HKm314-B5-V',
  29578. 'HKm471-B5-H',
  29579. 'HKm471-B5-V',
  29580. 'HKscs-B5-H',
  29581. 'HKscs-B5-V',
  29582. 'Hankaku',
  29583. 'Hiragana',
  29584. 'KSC-EUC-H',
  29585. 'KSC-EUC-V',
  29586. 'KSC-H',
  29587. 'KSC-Johab-H',
  29588. 'KSC-Johab-V',
  29589. 'KSC-V',
  29590. 'KSCms-UHC-H',
  29591. 'KSCms-UHC-HW-H',
  29592. 'KSCms-UHC-HW-V',
  29593. 'KSCms-UHC-V',
  29594. 'KSCpc-EUC-H',
  29595. 'KSCpc-EUC-V',
  29596. 'Katakana',
  29597. 'NWP-H',
  29598. 'NWP-V',
  29599. 'RKSJ-H',
  29600. 'RKSJ-V',
  29601. 'Roman',
  29602. 'UniCNS-UCS2-H',
  29603. 'UniCNS-UCS2-V',
  29604. 'UniCNS-UTF16-H',
  29605. 'UniCNS-UTF16-V',
  29606. 'UniCNS-UTF32-H',
  29607. 'UniCNS-UTF32-V',
  29608. 'UniCNS-UTF8-H',
  29609. 'UniCNS-UTF8-V',
  29610. 'UniGB-UCS2-H',
  29611. 'UniGB-UCS2-V',
  29612. 'UniGB-UTF16-H',
  29613. 'UniGB-UTF16-V',
  29614. 'UniGB-UTF32-H',
  29615. 'UniGB-UTF32-V',
  29616. 'UniGB-UTF8-H',
  29617. 'UniGB-UTF8-V',
  29618. 'UniJIS-UCS2-H',
  29619. 'UniJIS-UCS2-HW-H',
  29620. 'UniJIS-UCS2-HW-V',
  29621. 'UniJIS-UCS2-V',
  29622. 'UniJIS-UTF16-H',
  29623. 'UniJIS-UTF16-V',
  29624. 'UniJIS-UTF32-H',
  29625. 'UniJIS-UTF32-V',
  29626. 'UniJIS-UTF8-H',
  29627. 'UniJIS-UTF8-V',
  29628. 'UniJIS2004-UTF16-H',
  29629. 'UniJIS2004-UTF16-V',
  29630. 'UniJIS2004-UTF32-H',
  29631. 'UniJIS2004-UTF32-V',
  29632. 'UniJIS2004-UTF8-H',
  29633. 'UniJIS2004-UTF8-V',
  29634. 'UniJISPro-UCS2-HW-V',
  29635. 'UniJISPro-UCS2-V',
  29636. 'UniJISPro-UTF8-V',
  29637. 'UniJISX0213-UTF32-H',
  29638. 'UniJISX0213-UTF32-V',
  29639. 'UniJISX02132004-UTF32-H',
  29640. 'UniJISX02132004-UTF32-V',
  29641. 'UniKS-UCS2-H',
  29642. 'UniKS-UCS2-V',
  29643. 'UniKS-UTF16-H',
  29644. 'UniKS-UTF16-V',
  29645. 'UniKS-UTF32-H',
  29646. 'UniKS-UTF32-V',
  29647. 'UniKS-UTF8-H',
  29648. 'UniKS-UTF8-V',
  29649. 'V',
  29650. 'WP-Symbol'];
  29651. // CMap, not to be confused with TrueType's cmap.
  29652. var CMap = (function CMapClosure() {
  29653. function CMap(builtInCMap) {
  29654. // Codespace ranges are stored as follows:
  29655. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  29656. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  29657. this.codespaceRanges = [[], [], [], []];
  29658. this.numCodespaceRanges = 0;
  29659. // Map entries have one of two forms.
  29660. // - cid chars are 16-bit unsigned integers, stored as integers.
  29661. // - bf chars are variable-length byte sequences, stored as strings, with
  29662. // one byte per character.
  29663. this._map = [];
  29664. this.name = '';
  29665. this.vertical = false;
  29666. this.useCMap = null;
  29667. this.builtInCMap = builtInCMap;
  29668. }
  29669. CMap.prototype = {
  29670. addCodespaceRange: function(n, low, high) {
  29671. this.codespaceRanges[n - 1].push(low, high);
  29672. this.numCodespaceRanges++;
  29673. },
  29674. mapCidRange: function(low, high, dstLow) {
  29675. while (low <= high) {
  29676. this._map[low++] = dstLow++;
  29677. }
  29678. },
  29679. mapBfRange: function(low, high, dstLow) {
  29680. var lastByte = dstLow.length - 1;
  29681. while (low <= high) {
  29682. this._map[low++] = dstLow;
  29683. // Only the last byte has to be incremented.
  29684. dstLow = dstLow.substr(0, lastByte) +
  29685. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  29686. }
  29687. },
  29688. mapBfRangeToArray: function(low, high, array) {
  29689. var i = 0, ii = array.length;
  29690. while (low <= high && i < ii) {
  29691. this._map[low] = array[i++];
  29692. ++low;
  29693. }
  29694. },
  29695. // This is used for both bf and cid chars.
  29696. mapOne: function(src, dst) {
  29697. this._map[src] = dst;
  29698. },
  29699. lookup: function(code) {
  29700. return this._map[code];
  29701. },
  29702. contains: function(code) {
  29703. return this._map[code] !== undefined;
  29704. },
  29705. forEach: function(callback) {
  29706. // Most maps have fewer than 65536 entries, and for those we use normal
  29707. // array iteration. But really sparse tables are possible -- e.g. with
  29708. // indices in the *billions*. For such tables we use for..in, which isn't
  29709. // ideal because it stringifies the indices for all present elements, but
  29710. // it does avoid iterating over every undefined entry.
  29711. var map = this._map;
  29712. var length = map.length;
  29713. var i;
  29714. if (length <= 0x10000) {
  29715. for (i = 0; i < length; i++) {
  29716. if (map[i] !== undefined) {
  29717. callback(i, map[i]);
  29718. }
  29719. }
  29720. } else {
  29721. for (i in this._map) {
  29722. callback(i, map[i]);
  29723. }
  29724. }
  29725. },
  29726. charCodeOf: function(value) {
  29727. return this._map.indexOf(value);
  29728. },
  29729. getMap: function() {
  29730. return this._map;
  29731. },
  29732. readCharCode: function(str, offset, out) {
  29733. var c = 0;
  29734. var codespaceRanges = this.codespaceRanges;
  29735. var codespaceRangesLen = this.codespaceRanges.length;
  29736. // 9.7.6.2 CMap Mapping
  29737. // The code length is at most 4.
  29738. for (var n = 0; n < codespaceRangesLen; n++) {
  29739. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  29740. // Check each codespace range to see if it falls within.
  29741. var codespaceRange = codespaceRanges[n];
  29742. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  29743. var low = codespaceRange[k++];
  29744. var high = codespaceRange[k++];
  29745. if (c >= low && c <= high) {
  29746. out.charcode = c;
  29747. out.length = n + 1;
  29748. return;
  29749. }
  29750. }
  29751. }
  29752. out.charcode = 0;
  29753. out.length = 1;
  29754. },
  29755. get length() {
  29756. return this._map.length;
  29757. },
  29758. get isIdentityCMap() {
  29759. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  29760. return false;
  29761. }
  29762. if (this._map.length !== 0x10000) {
  29763. return false;
  29764. }
  29765. for (var i = 0; i < 0x10000; i++) {
  29766. if (this._map[i] !== i) {
  29767. return false;
  29768. }
  29769. }
  29770. return true;
  29771. }
  29772. };
  29773. return CMap;
  29774. })();
  29775. // A special case of CMap, where the _map array implicitly has a length of
  29776. // 65536 and each element is equal to its index.
  29777. var IdentityCMap = (function IdentityCMapClosure() {
  29778. function IdentityCMap(vertical, n) {
  29779. CMap.call(this);
  29780. this.vertical = vertical;
  29781. this.addCodespaceRange(n, 0, 0xffff);
  29782. }
  29783. Util.inherit(IdentityCMap, CMap, {});
  29784. IdentityCMap.prototype = {
  29785. addCodespaceRange: CMap.prototype.addCodespaceRange,
  29786. mapCidRange: function(low, high, dstLow) {
  29787. error('should not call mapCidRange');
  29788. },
  29789. mapBfRange: function(low, high, dstLow) {
  29790. error('should not call mapBfRange');
  29791. },
  29792. mapBfRangeToArray: function(low, high, array) {
  29793. error('should not call mapBfRangeToArray');
  29794. },
  29795. mapOne: function(src, dst) {
  29796. error('should not call mapCidOne');
  29797. },
  29798. lookup: function(code) {
  29799. return (isInt(code) && code <= 0xffff) ? code : undefined;
  29800. },
  29801. contains: function(code) {
  29802. return isInt(code) && code <= 0xffff;
  29803. },
  29804. forEach: function(callback) {
  29805. for (var i = 0; i <= 0xffff; i++) {
  29806. callback(i, i);
  29807. }
  29808. },
  29809. charCodeOf: function(value) {
  29810. return (isInt(value) && value <= 0xffff) ? value : -1;
  29811. },
  29812. getMap: function() {
  29813. // Sometimes identity maps must be instantiated, but it's rare.
  29814. var map = new Array(0x10000);
  29815. for (var i = 0; i <= 0xffff; i++) {
  29816. map[i] = i;
  29817. }
  29818. return map;
  29819. },
  29820. readCharCode: CMap.prototype.readCharCode,
  29821. get length() {
  29822. return 0x10000;
  29823. },
  29824. get isIdentityCMap() {
  29825. error('should not access .isIdentityCMap');
  29826. }
  29827. };
  29828. return IdentityCMap;
  29829. })();
  29830. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  29831. function fetchBinaryData(url) {
  29832. return new Promise(function (resolve, reject) {
  29833. var request = new XMLHttpRequest();
  29834. request.open('GET', url, true);
  29835. request.responseType = 'arraybuffer';
  29836. request.onreadystatechange = function () {
  29837. if (request.readyState === XMLHttpRequest.DONE) {
  29838. if (!request.response || request.status !== 200 &&
  29839. request.status !== 0) {
  29840. reject(new Error('Unable to get binary cMap at: ' + url));
  29841. } else {
  29842. resolve(new Uint8Array(request.response));
  29843. }
  29844. }
  29845. };
  29846. request.send(null);
  29847. });
  29848. }
  29849. function hexToInt(a, size) {
  29850. var n = 0;
  29851. for (var i = 0; i <= size; i++) {
  29852. n = (n << 8) | a[i];
  29853. }
  29854. return n >>> 0;
  29855. }
  29856. function hexToStr(a, size) {
  29857. // This code is hot. Special-case some common values to avoid creating an
  29858. // object with subarray().
  29859. if (size === 1) {
  29860. return String.fromCharCode(a[0], a[1]);
  29861. }
  29862. if (size === 3) {
  29863. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  29864. }
  29865. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  29866. }
  29867. function addHex(a, b, size) {
  29868. var c = 0;
  29869. for (var i = size; i >= 0; i--) {
  29870. c += a[i] + b[i];
  29871. a[i] = c & 255;
  29872. c >>= 8;
  29873. }
  29874. }
  29875. function incHex(a, size) {
  29876. var c = 1;
  29877. for (var i = size; i >= 0 && c > 0; i--) {
  29878. c += a[i];
  29879. a[i] = c & 255;
  29880. c >>= 8;
  29881. }
  29882. }
  29883. var MAX_NUM_SIZE = 16;
  29884. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  29885. function BinaryCMapStream(data) {
  29886. this.buffer = data;
  29887. this.pos = 0;
  29888. this.end = data.length;
  29889. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  29890. }
  29891. BinaryCMapStream.prototype = {
  29892. readByte: function () {
  29893. if (this.pos >= this.end) {
  29894. return -1;
  29895. }
  29896. return this.buffer[this.pos++];
  29897. },
  29898. readNumber: function () {
  29899. var n = 0;
  29900. var last;
  29901. do {
  29902. var b = this.readByte();
  29903. if (b < 0) {
  29904. error('unexpected EOF in bcmap');
  29905. }
  29906. last = !(b & 0x80);
  29907. n = (n << 7) | (b & 0x7F);
  29908. } while (!last);
  29909. return n;
  29910. },
  29911. readSigned: function () {
  29912. var n = this.readNumber();
  29913. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  29914. },
  29915. readHex: function (num, size) {
  29916. num.set(this.buffer.subarray(this.pos,
  29917. this.pos + size + 1));
  29918. this.pos += size + 1;
  29919. },
  29920. readHexNumber: function (num, size) {
  29921. var last;
  29922. var stack = this.tmpBuf, sp = 0;
  29923. do {
  29924. var b = this.readByte();
  29925. if (b < 0) {
  29926. error('unexpected EOF in bcmap');
  29927. }
  29928. last = !(b & 0x80);
  29929. stack[sp++] = b & 0x7F;
  29930. } while (!last);
  29931. var i = size, buffer = 0, bufferSize = 0;
  29932. while (i >= 0) {
  29933. while (bufferSize < 8 && stack.length > 0) {
  29934. buffer = (stack[--sp] << bufferSize) | buffer;
  29935. bufferSize += 7;
  29936. }
  29937. num[i] = buffer & 255;
  29938. i--;
  29939. buffer >>= 8;
  29940. bufferSize -= 8;
  29941. }
  29942. },
  29943. readHexSigned: function (num, size) {
  29944. this.readHexNumber(num, size);
  29945. var sign = num[size] & 1 ? 255 : 0;
  29946. var c = 0;
  29947. for (var i = 0; i <= size; i++) {
  29948. c = ((c & 1) << 8) | num[i];
  29949. num[i] = (c >> 1) ^ sign;
  29950. }
  29951. },
  29952. readString: function () {
  29953. var len = this.readNumber();
  29954. var s = '';
  29955. for (var i = 0; i < len; i++) {
  29956. s += String.fromCharCode(this.readNumber());
  29957. }
  29958. return s;
  29959. }
  29960. };
  29961. function processBinaryCMap(url, cMap, extend) {
  29962. return fetchBinaryData(url).then(function (data) {
  29963. var stream = new BinaryCMapStream(data);
  29964. var header = stream.readByte();
  29965. cMap.vertical = !!(header & 1);
  29966. var useCMap = null;
  29967. var start = new Uint8Array(MAX_NUM_SIZE);
  29968. var end = new Uint8Array(MAX_NUM_SIZE);
  29969. var char = new Uint8Array(MAX_NUM_SIZE);
  29970. var charCode = new Uint8Array(MAX_NUM_SIZE);
  29971. var tmp = new Uint8Array(MAX_NUM_SIZE);
  29972. var code;
  29973. var b;
  29974. while ((b = stream.readByte()) >= 0) {
  29975. var type = b >> 5;
  29976. if (type === 7) { // metadata, e.g. comment or usecmap
  29977. switch (b & 0x1F) {
  29978. case 0:
  29979. stream.readString(); // skipping comment
  29980. break;
  29981. case 1:
  29982. useCMap = stream.readString();
  29983. break;
  29984. }
  29985. continue;
  29986. }
  29987. var sequence = !!(b & 0x10);
  29988. var dataSize = b & 15;
  29989. assert(dataSize + 1 <= MAX_NUM_SIZE);
  29990. var ucs2DataSize = 1;
  29991. var subitemsCount = stream.readNumber();
  29992. var i;
  29993. switch (type) {
  29994. case 0: // codespacerange
  29995. stream.readHex(start, dataSize);
  29996. stream.readHexNumber(end, dataSize);
  29997. addHex(end, start, dataSize);
  29998. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29999. hexToInt(end, dataSize));
  30000. for (i = 1; i < subitemsCount; i++) {
  30001. incHex(end, dataSize);
  30002. stream.readHexNumber(start, dataSize);
  30003. addHex(start, end, dataSize);
  30004. stream.readHexNumber(end, dataSize);
  30005. addHex(end, start, dataSize);
  30006. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  30007. hexToInt(end, dataSize));
  30008. }
  30009. break;
  30010. case 1: // notdefrange
  30011. stream.readHex(start, dataSize);
  30012. stream.readHexNumber(end, dataSize);
  30013. addHex(end, start, dataSize);
  30014. code = stream.readNumber();
  30015. // undefined range, skipping
  30016. for (i = 1; i < subitemsCount; i++) {
  30017. incHex(end, dataSize);
  30018. stream.readHexNumber(start, dataSize);
  30019. addHex(start, end, dataSize);
  30020. stream.readHexNumber(end, dataSize);
  30021. addHex(end, start, dataSize);
  30022. code = stream.readNumber();
  30023. // nop
  30024. }
  30025. break;
  30026. case 2: // cidchar
  30027. stream.readHex(char, dataSize);
  30028. code = stream.readNumber();
  30029. cMap.mapOne(hexToInt(char, dataSize), code);
  30030. for (i = 1; i < subitemsCount; i++) {
  30031. incHex(char, dataSize);
  30032. if (!sequence) {
  30033. stream.readHexNumber(tmp, dataSize);
  30034. addHex(char, tmp, dataSize);
  30035. }
  30036. code = stream.readSigned() + (code + 1);
  30037. cMap.mapOne(hexToInt(char, dataSize), code);
  30038. }
  30039. break;
  30040. case 3: // cidrange
  30041. stream.readHex(start, dataSize);
  30042. stream.readHexNumber(end, dataSize);
  30043. addHex(end, start, dataSize);
  30044. code = stream.readNumber();
  30045. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  30046. code);
  30047. for (i = 1; i < subitemsCount; i++) {
  30048. incHex(end, dataSize);
  30049. if (!sequence) {
  30050. stream.readHexNumber(start, dataSize);
  30051. addHex(start, end, dataSize);
  30052. } else {
  30053. start.set(end);
  30054. }
  30055. stream.readHexNumber(end, dataSize);
  30056. addHex(end, start, dataSize);
  30057. code = stream.readNumber();
  30058. cMap.mapCidRange(hexToInt(start, dataSize),
  30059. hexToInt(end, dataSize), code);
  30060. }
  30061. break;
  30062. case 4: // bfchar
  30063. stream.readHex(char, ucs2DataSize);
  30064. stream.readHex(charCode, dataSize);
  30065. cMap.mapOne(hexToInt(char, ucs2DataSize),
  30066. hexToStr(charCode, dataSize));
  30067. for (i = 1; i < subitemsCount; i++) {
  30068. incHex(char, ucs2DataSize);
  30069. if (!sequence) {
  30070. stream.readHexNumber(tmp, ucs2DataSize);
  30071. addHex(char, tmp, ucs2DataSize);
  30072. }
  30073. incHex(charCode, dataSize);
  30074. stream.readHexSigned(tmp, dataSize);
  30075. addHex(charCode, tmp, dataSize);
  30076. cMap.mapOne(hexToInt(char, ucs2DataSize),
  30077. hexToStr(charCode, dataSize));
  30078. }
  30079. break;
  30080. case 5: // bfrange
  30081. stream.readHex(start, ucs2DataSize);
  30082. stream.readHexNumber(end, ucs2DataSize);
  30083. addHex(end, start, ucs2DataSize);
  30084. stream.readHex(charCode, dataSize);
  30085. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  30086. hexToInt(end, ucs2DataSize),
  30087. hexToStr(charCode, dataSize));
  30088. for (i = 1; i < subitemsCount; i++) {
  30089. incHex(end, ucs2DataSize);
  30090. if (!sequence) {
  30091. stream.readHexNumber(start, ucs2DataSize);
  30092. addHex(start, end, ucs2DataSize);
  30093. } else {
  30094. start.set(end);
  30095. }
  30096. stream.readHexNumber(end, ucs2DataSize);
  30097. addHex(end, start, ucs2DataSize);
  30098. stream.readHex(charCode, dataSize);
  30099. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  30100. hexToInt(end, ucs2DataSize),
  30101. hexToStr(charCode, dataSize));
  30102. }
  30103. break;
  30104. default:
  30105. error('Unknown type: ' + type);
  30106. break;
  30107. }
  30108. }
  30109. if (useCMap) {
  30110. return extend(useCMap);
  30111. }
  30112. return cMap;
  30113. });
  30114. }
  30115. function BinaryCMapReader() {}
  30116. BinaryCMapReader.prototype = {
  30117. read: processBinaryCMap
  30118. };
  30119. return BinaryCMapReader;
  30120. })();
  30121. var CMapFactory = (function CMapFactoryClosure() {
  30122. function strToInt(str) {
  30123. var a = 0;
  30124. for (var i = 0; i < str.length; i++) {
  30125. a = (a << 8) | str.charCodeAt(i);
  30126. }
  30127. return a >>> 0;
  30128. }
  30129. function expectString(obj) {
  30130. if (!isString(obj)) {
  30131. error('Malformed CMap: expected string.');
  30132. }
  30133. }
  30134. function expectInt(obj) {
  30135. if (!isInt(obj)) {
  30136. error('Malformed CMap: expected int.');
  30137. }
  30138. }
  30139. function parseBfChar(cMap, lexer) {
  30140. while (true) {
  30141. var obj = lexer.getObj();
  30142. if (isEOF(obj)) {
  30143. break;
  30144. }
  30145. if (isCmd(obj, 'endbfchar')) {
  30146. return;
  30147. }
  30148. expectString(obj);
  30149. var src = strToInt(obj);
  30150. obj = lexer.getObj();
  30151. // TODO are /dstName used?
  30152. expectString(obj);
  30153. var dst = obj;
  30154. cMap.mapOne(src, dst);
  30155. }
  30156. }
  30157. function parseBfRange(cMap, lexer) {
  30158. while (true) {
  30159. var obj = lexer.getObj();
  30160. if (isEOF(obj)) {
  30161. break;
  30162. }
  30163. if (isCmd(obj, 'endbfrange')) {
  30164. return;
  30165. }
  30166. expectString(obj);
  30167. var low = strToInt(obj);
  30168. obj = lexer.getObj();
  30169. expectString(obj);
  30170. var high = strToInt(obj);
  30171. obj = lexer.getObj();
  30172. if (isInt(obj) || isString(obj)) {
  30173. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  30174. cMap.mapBfRange(low, high, dstLow);
  30175. } else if (isCmd(obj, '[')) {
  30176. obj = lexer.getObj();
  30177. var array = [];
  30178. while (!isCmd(obj, ']') && !isEOF(obj)) {
  30179. array.push(obj);
  30180. obj = lexer.getObj();
  30181. }
  30182. cMap.mapBfRangeToArray(low, high, array);
  30183. } else {
  30184. break;
  30185. }
  30186. }
  30187. error('Invalid bf range.');
  30188. }
  30189. function parseCidChar(cMap, lexer) {
  30190. while (true) {
  30191. var obj = lexer.getObj();
  30192. if (isEOF(obj)) {
  30193. break;
  30194. }
  30195. if (isCmd(obj, 'endcidchar')) {
  30196. return;
  30197. }
  30198. expectString(obj);
  30199. var src = strToInt(obj);
  30200. obj = lexer.getObj();
  30201. expectInt(obj);
  30202. var dst = obj;
  30203. cMap.mapOne(src, dst);
  30204. }
  30205. }
  30206. function parseCidRange(cMap, lexer) {
  30207. while (true) {
  30208. var obj = lexer.getObj();
  30209. if (isEOF(obj)) {
  30210. break;
  30211. }
  30212. if (isCmd(obj, 'endcidrange')) {
  30213. return;
  30214. }
  30215. expectString(obj);
  30216. var low = strToInt(obj);
  30217. obj = lexer.getObj();
  30218. expectString(obj);
  30219. var high = strToInt(obj);
  30220. obj = lexer.getObj();
  30221. expectInt(obj);
  30222. var dstLow = obj;
  30223. cMap.mapCidRange(low, high, dstLow);
  30224. }
  30225. }
  30226. function parseCodespaceRange(cMap, lexer) {
  30227. while (true) {
  30228. var obj = lexer.getObj();
  30229. if (isEOF(obj)) {
  30230. break;
  30231. }
  30232. if (isCmd(obj, 'endcodespacerange')) {
  30233. return;
  30234. }
  30235. if (!isString(obj)) {
  30236. break;
  30237. }
  30238. var low = strToInt(obj);
  30239. obj = lexer.getObj();
  30240. if (!isString(obj)) {
  30241. break;
  30242. }
  30243. var high = strToInt(obj);
  30244. cMap.addCodespaceRange(obj.length, low, high);
  30245. }
  30246. error('Invalid codespace range.');
  30247. }
  30248. function parseWMode(cMap, lexer) {
  30249. var obj = lexer.getObj();
  30250. if (isInt(obj)) {
  30251. cMap.vertical = !!obj;
  30252. }
  30253. }
  30254. function parseCMapName(cMap, lexer) {
  30255. var obj = lexer.getObj();
  30256. if (isName(obj) && isString(obj.name)) {
  30257. cMap.name = obj.name;
  30258. }
  30259. }
  30260. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  30261. var previous;
  30262. var embededUseCMap;
  30263. objLoop: while (true) {
  30264. try {
  30265. var obj = lexer.getObj();
  30266. if (isEOF(obj)) {
  30267. break;
  30268. } else if (isName(obj)) {
  30269. if (obj.name === 'WMode') {
  30270. parseWMode(cMap, lexer);
  30271. } else if (obj.name === 'CMapName') {
  30272. parseCMapName(cMap, lexer);
  30273. }
  30274. previous = obj;
  30275. } else if (isCmd(obj)) {
  30276. switch (obj.cmd) {
  30277. case 'endcmap':
  30278. break objLoop;
  30279. case 'usecmap':
  30280. if (isName(previous)) {
  30281. embededUseCMap = previous.name;
  30282. }
  30283. break;
  30284. case 'begincodespacerange':
  30285. parseCodespaceRange(cMap, lexer);
  30286. break;
  30287. case 'beginbfchar':
  30288. parseBfChar(cMap, lexer);
  30289. break;
  30290. case 'begincidchar':
  30291. parseCidChar(cMap, lexer);
  30292. break;
  30293. case 'beginbfrange':
  30294. parseBfRange(cMap, lexer);
  30295. break;
  30296. case 'begincidrange':
  30297. parseCidRange(cMap, lexer);
  30298. break;
  30299. }
  30300. }
  30301. } catch (ex) {
  30302. if (ex instanceof MissingDataException) {
  30303. throw ex;
  30304. }
  30305. warn('Invalid cMap data: ' + ex);
  30306. continue;
  30307. }
  30308. }
  30309. if (!useCMap && embededUseCMap) {
  30310. // Load the usecmap definition from the file only if there wasn't one
  30311. // specified.
  30312. useCMap = embededUseCMap;
  30313. }
  30314. if (useCMap) {
  30315. return extendCMap(cMap, builtInCMapParams, useCMap);
  30316. }
  30317. return Promise.resolve(cMap);
  30318. }
  30319. function extendCMap(cMap, builtInCMapParams, useCMap) {
  30320. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  30321. function(newCMap) {
  30322. cMap.useCMap = newCMap;
  30323. // If there aren't any code space ranges defined clone all the parent ones
  30324. // into this cMap.
  30325. if (cMap.numCodespaceRanges === 0) {
  30326. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  30327. for (var i = 0; i < useCodespaceRanges.length; i++) {
  30328. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  30329. }
  30330. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  30331. }
  30332. // Merge the map into the current one, making sure not to override
  30333. // any previously defined entries.
  30334. cMap.useCMap.forEach(function(key, value) {
  30335. if (!cMap.contains(key)) {
  30336. cMap.mapOne(key, cMap.useCMap.lookup(key));
  30337. }
  30338. });
  30339. return cMap;
  30340. });
  30341. }
  30342. function parseBinaryCMap(name, builtInCMapParams) {
  30343. var url = builtInCMapParams.url + name + '.bcmap';
  30344. var cMap = new CMap(true);
  30345. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  30346. return extendCMap(cMap, builtInCMapParams, useCMap);
  30347. });
  30348. }
  30349. function createBuiltInCMap(name, builtInCMapParams) {
  30350. if (name === 'Identity-H') {
  30351. return Promise.resolve(new IdentityCMap(false, 2));
  30352. } else if (name === 'Identity-V') {
  30353. return Promise.resolve(new IdentityCMap(true, 2));
  30354. }
  30355. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  30356. return Promise.reject(new Error('Unknown cMap name: ' + name));
  30357. }
  30358. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  30359. if (builtInCMapParams.packed) {
  30360. return parseBinaryCMap(name, builtInCMapParams);
  30361. }
  30362. return new Promise(function (resolve, reject) {
  30363. var url = builtInCMapParams.url + name;
  30364. var request = new XMLHttpRequest();
  30365. request.onreadystatechange = function () {
  30366. if (request.readyState === XMLHttpRequest.DONE) {
  30367. if (request.status === 200 || request.status === 0) {
  30368. var cMap = new CMap(true);
  30369. var lexer = new Lexer(new StringStream(request.responseText));
  30370. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  30371. function (parsedCMap) {
  30372. resolve(parsedCMap);
  30373. });
  30374. } else {
  30375. reject(new Error('Unable to get cMap at: ' + url));
  30376. }
  30377. }
  30378. };
  30379. request.open('GET', url, true);
  30380. request.send(null);
  30381. });
  30382. }
  30383. return {
  30384. create: function (encoding, builtInCMapParams, useCMap) {
  30385. if (isName(encoding)) {
  30386. return createBuiltInCMap(encoding.name, builtInCMapParams);
  30387. } else if (isStream(encoding)) {
  30388. var cMap = new CMap();
  30389. var lexer = new Lexer(encoding);
  30390. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  30391. function (parsedCMap) {
  30392. if (parsedCMap.isIdentityCMap) {
  30393. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  30394. }
  30395. return parsedCMap;
  30396. });
  30397. }
  30398. return Promise.reject(new Error('Encoding required.'));
  30399. }
  30400. };
  30401. })();
  30402. exports.CMap = CMap;
  30403. exports.CMapFactory = CMapFactory;
  30404. exports.IdentityCMap = IdentityCMap;
  30405. }));
  30406. (function (root, factory) {
  30407. {
  30408. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  30409. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList,
  30410. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  30411. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  30412. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  30413. }
  30414. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  30415. coreGlyphList, coreFontRenderer, coreEncodings,
  30416. coreStandardFonts, coreUnicode, coreType1Parser,
  30417. coreCFFParser) {
  30418. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  30419. var FontType = sharedUtil.FontType;
  30420. var assert = sharedUtil.assert;
  30421. var bytesToString = sharedUtil.bytesToString;
  30422. var error = sharedUtil.error;
  30423. var info = sharedUtil.info;
  30424. var isArray = sharedUtil.isArray;
  30425. var isInt = sharedUtil.isInt;
  30426. var isNum = sharedUtil.isNum;
  30427. var readUint32 = sharedUtil.readUint32;
  30428. var shadow = sharedUtil.shadow;
  30429. var string32 = sharedUtil.string32;
  30430. var warn = sharedUtil.warn;
  30431. var MissingDataException = sharedUtil.MissingDataException;
  30432. var isSpace = sharedUtil.isSpace;
  30433. var Stream = coreStream.Stream;
  30434. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  30435. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  30436. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  30437. var StandardEncoding = coreEncodings.StandardEncoding;
  30438. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  30439. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  30440. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  30441. var getEncoding = coreEncodings.getEncoding;
  30442. var getStdFontMap = coreStandardFonts.getStdFontMap;
  30443. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  30444. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  30445. var getSupplementalGlyphMapForArialBlack =
  30446. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  30447. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  30448. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  30449. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  30450. var Type1Parser = coreType1Parser.Type1Parser;
  30451. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  30452. var CFFParser = coreCFFParser.CFFParser;
  30453. var CFFCompiler = coreCFFParser.CFFCompiler;
  30454. var CFF = coreCFFParser.CFF;
  30455. var CFFHeader = coreCFFParser.CFFHeader;
  30456. var CFFTopDict = coreCFFParser.CFFTopDict;
  30457. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  30458. var CFFStrings = coreCFFParser.CFFStrings;
  30459. var CFFIndex = coreCFFParser.CFFIndex;
  30460. var CFFCharset = coreCFFParser.CFFCharset;
  30461. // Unicode Private Use Area
  30462. var PRIVATE_USE_OFFSET_START = 0xE000;
  30463. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  30464. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  30465. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  30466. // except for Type 3 fonts
  30467. var PDF_GLYPH_SPACE_UNITS = 1000;
  30468. // Accented charactars are not displayed properly on Windows, using this flag
  30469. // to control analysis of seac charstrings.
  30470. var SEAC_ANALYSIS_ENABLED = false;
  30471. var FontFlags = {
  30472. FixedPitch: 1,
  30473. Serif: 2,
  30474. Symbolic: 4,
  30475. Script: 8,
  30476. Nonsymbolic: 32,
  30477. Italic: 64,
  30478. AllCap: 65536,
  30479. SmallCap: 131072,
  30480. ForceBold: 262144
  30481. };
  30482. var MacStandardGlyphOrdering = [
  30483. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  30484. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  30485. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  30486. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  30487. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  30488. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  30489. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  30490. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  30491. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  30492. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  30493. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  30494. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  30495. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30496. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  30497. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  30498. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  30499. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  30500. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  30501. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  30502. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  30503. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  30504. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  30505. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  30506. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  30507. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  30508. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  30509. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  30510. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  30511. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  30512. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  30513. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  30514. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  30515. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  30516. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  30517. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  30518. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  30519. function adjustWidths(properties) {
  30520. if (!properties.fontMatrix) {
  30521. return;
  30522. }
  30523. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  30524. return;
  30525. }
  30526. // adjusting width to fontMatrix scale
  30527. var scale = 0.001 / properties.fontMatrix[0];
  30528. var glyphsWidths = properties.widths;
  30529. for (var glyph in glyphsWidths) {
  30530. glyphsWidths[glyph] *= scale;
  30531. }
  30532. properties.defaultWidth *= scale;
  30533. }
  30534. function adjustToUnicode(properties, builtInEncoding) {
  30535. if (properties.hasIncludedToUnicodeMap) {
  30536. return; // The font dictionary has a `ToUnicode` entry.
  30537. }
  30538. if (properties.hasEncoding) {
  30539. return; // The font dictionary has an `Encoding` entry.
  30540. }
  30541. if (builtInEncoding === properties.defaultEncoding) {
  30542. return; // No point in trying to adjust `toUnicode` if the encodings match.
  30543. }
  30544. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  30545. return;
  30546. }
  30547. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  30548. for (var charCode in builtInEncoding) {
  30549. var glyphName = builtInEncoding[charCode];
  30550. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  30551. if (unicode !== -1) {
  30552. toUnicode[charCode] = String.fromCharCode(unicode);
  30553. }
  30554. }
  30555. properties.toUnicode.amend(toUnicode);
  30556. }
  30557. function getFontType(type, subtype) {
  30558. switch (type) {
  30559. case 'Type1':
  30560. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  30561. case 'CIDFontType0':
  30562. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  30563. FontType.CIDFONTTYPE0;
  30564. case 'OpenType':
  30565. return FontType.OPENTYPE;
  30566. case 'TrueType':
  30567. return FontType.TRUETYPE;
  30568. case 'CIDFontType2':
  30569. return FontType.CIDFONTTYPE2;
  30570. case 'MMType1':
  30571. return FontType.MMTYPE1;
  30572. case 'Type0':
  30573. return FontType.TYPE0;
  30574. default:
  30575. return FontType.UNKNOWN;
  30576. }
  30577. }
  30578. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  30579. // in a 'uniXXXX' format -- attempting to recover proper ones.
  30580. function recoverGlyphName(name, glyphsUnicodeMap) {
  30581. if (glyphsUnicodeMap[name] !== undefined) {
  30582. return name;
  30583. }
  30584. // The glyph name is non-standard, trying to recover.
  30585. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  30586. if (unicode !== -1) {
  30587. for (var key in glyphsUnicodeMap) {
  30588. if (glyphsUnicodeMap[key] === unicode) {
  30589. return key;
  30590. }
  30591. }
  30592. }
  30593. info('Unable to recover a standard glyph name for: ' + name);
  30594. return name;
  30595. }
  30596. var Glyph = (function GlyphClosure() {
  30597. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  30598. isSpace, isInFont) {
  30599. this.fontChar = fontChar;
  30600. this.unicode = unicode;
  30601. this.accent = accent;
  30602. this.width = width;
  30603. this.vmetric = vmetric;
  30604. this.operatorListId = operatorListId;
  30605. this.isSpace = isSpace;
  30606. this.isInFont = isInFont;
  30607. }
  30608. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  30609. vmetric, operatorListId, isSpace,
  30610. isInFont) {
  30611. return this.fontChar === fontChar &&
  30612. this.unicode === unicode &&
  30613. this.accent === accent &&
  30614. this.width === width &&
  30615. this.vmetric === vmetric &&
  30616. this.operatorListId === operatorListId &&
  30617. this.isSpace === isSpace &&
  30618. this.isInFont === isInFont;
  30619. };
  30620. return Glyph;
  30621. })();
  30622. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  30623. function ToUnicodeMap(cmap) {
  30624. // The elements of this._map can be integers or strings, depending on how
  30625. // |cmap| was created.
  30626. this._map = cmap;
  30627. }
  30628. ToUnicodeMap.prototype = {
  30629. get length() {
  30630. return this._map.length;
  30631. },
  30632. forEach: function(callback) {
  30633. for (var charCode in this._map) {
  30634. callback(charCode, this._map[charCode].charCodeAt(0));
  30635. }
  30636. },
  30637. has: function(i) {
  30638. return this._map[i] !== undefined;
  30639. },
  30640. get: function(i) {
  30641. return this._map[i];
  30642. },
  30643. charCodeOf: function(v) {
  30644. return this._map.indexOf(v);
  30645. },
  30646. amend: function (map) {
  30647. for (var charCode in map) {
  30648. this._map[charCode] = map[charCode];
  30649. }
  30650. },
  30651. };
  30652. return ToUnicodeMap;
  30653. })();
  30654. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  30655. function IdentityToUnicodeMap(firstChar, lastChar) {
  30656. this.firstChar = firstChar;
  30657. this.lastChar = lastChar;
  30658. }
  30659. IdentityToUnicodeMap.prototype = {
  30660. get length() {
  30661. return (this.lastChar + 1) - this.firstChar;
  30662. },
  30663. forEach: function (callback) {
  30664. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  30665. callback(i, i);
  30666. }
  30667. },
  30668. has: function (i) {
  30669. return this.firstChar <= i && i <= this.lastChar;
  30670. },
  30671. get: function (i) {
  30672. if (this.firstChar <= i && i <= this.lastChar) {
  30673. return String.fromCharCode(i);
  30674. }
  30675. return undefined;
  30676. },
  30677. charCodeOf: function (v) {
  30678. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  30679. },
  30680. amend: function (map) {
  30681. error('Should not call amend()');
  30682. },
  30683. };
  30684. return IdentityToUnicodeMap;
  30685. })();
  30686. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  30687. function writeInt16(dest, offset, num) {
  30688. dest[offset] = (num >> 8) & 0xFF;
  30689. dest[offset + 1] = num & 0xFF;
  30690. }
  30691. function writeInt32(dest, offset, num) {
  30692. dest[offset] = (num >> 24) & 0xFF;
  30693. dest[offset + 1] = (num >> 16) & 0xFF;
  30694. dest[offset + 2] = (num >> 8) & 0xFF;
  30695. dest[offset + 3] = num & 0xFF;
  30696. }
  30697. function writeData(dest, offset, data) {
  30698. var i, ii;
  30699. if (data instanceof Uint8Array) {
  30700. dest.set(data, offset);
  30701. } else if (typeof data === 'string') {
  30702. for (i = 0, ii = data.length; i < ii; i++) {
  30703. dest[offset++] = data.charCodeAt(i) & 0xFF;
  30704. }
  30705. } else {
  30706. // treating everything else as array
  30707. for (i = 0, ii = data.length; i < ii; i++) {
  30708. dest[offset++] = data[i] & 0xFF;
  30709. }
  30710. }
  30711. }
  30712. function OpenTypeFileBuilder(sfnt) {
  30713. this.sfnt = sfnt;
  30714. this.tables = Object.create(null);
  30715. }
  30716. OpenTypeFileBuilder.getSearchParams =
  30717. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  30718. var maxPower2 = 1, log2 = 0;
  30719. while ((maxPower2 ^ entriesCount) > maxPower2) {
  30720. maxPower2 <<= 1;
  30721. log2++;
  30722. }
  30723. var searchRange = maxPower2 * entrySize;
  30724. return {
  30725. range: searchRange,
  30726. entry: log2,
  30727. rangeShift: entrySize * entriesCount - searchRange
  30728. };
  30729. };
  30730. var OTF_HEADER_SIZE = 12;
  30731. var OTF_TABLE_ENTRY_SIZE = 16;
  30732. OpenTypeFileBuilder.prototype = {
  30733. toArray: function OpenTypeFileBuilder_toArray() {
  30734. var sfnt = this.sfnt;
  30735. // Tables needs to be written by ascendant alphabetic order
  30736. var tables = this.tables;
  30737. var tablesNames = Object.keys(tables);
  30738. tablesNames.sort();
  30739. var numTables = tablesNames.length;
  30740. var i, j, jj, table, tableName;
  30741. // layout the tables data
  30742. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  30743. var tableOffsets = [offset];
  30744. for (i = 0; i < numTables; i++) {
  30745. table = tables[tablesNames[i]];
  30746. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  30747. offset += paddedLength;
  30748. tableOffsets.push(offset);
  30749. }
  30750. var file = new Uint8Array(offset);
  30751. // write the table data first (mostly for checksum)
  30752. for (i = 0; i < numTables; i++) {
  30753. table = tables[tablesNames[i]];
  30754. writeData(file, tableOffsets[i], table);
  30755. }
  30756. // sfnt version (4 bytes)
  30757. if (sfnt === 'true') {
  30758. // Windows hates the Mac TrueType sfnt version number
  30759. sfnt = string32(0x00010000);
  30760. }
  30761. file[0] = sfnt.charCodeAt(0) & 0xFF;
  30762. file[1] = sfnt.charCodeAt(1) & 0xFF;
  30763. file[2] = sfnt.charCodeAt(2) & 0xFF;
  30764. file[3] = sfnt.charCodeAt(3) & 0xFF;
  30765. // numTables (2 bytes)
  30766. writeInt16(file, 4, numTables);
  30767. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  30768. // searchRange (2 bytes)
  30769. writeInt16(file, 6, searchParams.range);
  30770. // entrySelector (2 bytes)
  30771. writeInt16(file, 8, searchParams.entry);
  30772. // rangeShift (2 bytes)
  30773. writeInt16(file, 10, searchParams.rangeShift);
  30774. offset = OTF_HEADER_SIZE;
  30775. // writing table entries
  30776. for (i = 0; i < numTables; i++) {
  30777. tableName = tablesNames[i];
  30778. file[offset] = tableName.charCodeAt(0) & 0xFF;
  30779. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  30780. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  30781. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  30782. // checksum
  30783. var checksum = 0;
  30784. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  30785. var quad = readUint32(file, j);
  30786. checksum = (checksum + quad) >>> 0;
  30787. }
  30788. writeInt32(file, offset + 4, checksum);
  30789. // offset
  30790. writeInt32(file, offset + 8, tableOffsets[i]);
  30791. // length
  30792. writeInt32(file, offset + 12, tables[tableName].length);
  30793. offset += OTF_TABLE_ENTRY_SIZE;
  30794. }
  30795. return file;
  30796. },
  30797. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  30798. if (tag in this.tables) {
  30799. throw new Error('Table ' + tag + ' already exists');
  30800. }
  30801. this.tables[tag] = data;
  30802. }
  30803. };
  30804. return OpenTypeFileBuilder;
  30805. })();
  30806. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  30807. // issues when they are painted on the canvas, e.g. complex-script shaping or
  30808. // control/whitespace characters. The ranges are listed in pairs: the first item
  30809. // is a code of the first problematic code, the second one is the next
  30810. // non-problematic code. The ranges must be in sorted order.
  30811. var ProblematicCharRanges = new Int32Array([
  30812. // Control characters.
  30813. 0x0000, 0x0020,
  30814. 0x007F, 0x00A1,
  30815. 0x00AD, 0x00AE,
  30816. // Chars that is used in complex-script shaping.
  30817. 0x0600, 0x0780,
  30818. 0x08A0, 0x10A0,
  30819. 0x1780, 0x1800,
  30820. 0x1C00, 0x1C50,
  30821. // General punctuation chars.
  30822. 0x2000, 0x2010,
  30823. 0x2011, 0x2012,
  30824. 0x2028, 0x2030,
  30825. 0x205F, 0x2070,
  30826. 0x25CC, 0x25CD,
  30827. 0x3000, 0x3001,
  30828. // Chars that is used in complex-script shaping.
  30829. 0xAA60, 0xAA80,
  30830. // Specials Unicode block.
  30831. 0xFFF0, 0x10000
  30832. ]);
  30833. /**
  30834. * 'Font' is the class the outside world should use, it encapsulate all the font
  30835. * decoding logics whatever type it is (assuming the font type is supported).
  30836. *
  30837. * For example to read a Type1 font and to attach it to the document:
  30838. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  30839. * type1Font.bind();
  30840. */
  30841. var Font = (function FontClosure() {
  30842. function Font(name, file, properties) {
  30843. var charCode, glyphName, unicode;
  30844. this.name = name;
  30845. this.loadedName = properties.loadedName;
  30846. this.isType3Font = properties.isType3Font;
  30847. this.sizes = [];
  30848. this.missingFile = false;
  30849. this.glyphCache = Object.create(null);
  30850. var names = name.split('+');
  30851. names = names.length > 1 ? names[1] : names[0];
  30852. names = names.split(/[-,_]/g)[0];
  30853. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  30854. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  30855. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  30856. var type = properties.type;
  30857. var subtype = properties.subtype;
  30858. this.type = type;
  30859. this.fallbackName = (this.isMonospace ? 'monospace' :
  30860. (this.isSerifFont ? 'serif' : 'sans-serif'));
  30861. this.differences = properties.differences;
  30862. this.widths = properties.widths;
  30863. this.defaultWidth = properties.defaultWidth;
  30864. this.composite = properties.composite;
  30865. this.wideChars = properties.wideChars;
  30866. this.cMap = properties.cMap;
  30867. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  30868. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  30869. this.fontMatrix = properties.fontMatrix;
  30870. this.bbox = properties.bbox;
  30871. this.toUnicode = properties.toUnicode;
  30872. this.toFontChar = [];
  30873. if (properties.type === 'Type3') {
  30874. for (charCode = 0; charCode < 256; charCode++) {
  30875. this.toFontChar[charCode] = (this.differences[charCode] ||
  30876. properties.defaultEncoding[charCode]);
  30877. }
  30878. this.fontType = FontType.TYPE3;
  30879. return;
  30880. }
  30881. this.cidEncoding = properties.cidEncoding;
  30882. this.vertical = properties.vertical;
  30883. if (this.vertical) {
  30884. this.vmetrics = properties.vmetrics;
  30885. this.defaultVMetrics = properties.defaultVMetrics;
  30886. }
  30887. var glyphsUnicodeMap;
  30888. if (!file || file.isEmpty) {
  30889. if (file) {
  30890. // Some bad PDF generators will include empty font files,
  30891. // attempting to recover by assuming that no file exists.
  30892. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  30893. }
  30894. this.missingFile = true;
  30895. // The file data is not specified. Trying to fix the font name
  30896. // to be used with the canvas.font.
  30897. var fontName = name.replace(/[,_]/g, '-');
  30898. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  30899. var isStandardFont = !!stdFontMap[fontName] ||
  30900. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  30901. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  30902. this.bold = (fontName.search(/bold/gi) !== -1);
  30903. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  30904. (fontName.search(/italic/gi) !== -1));
  30905. // Use 'name' instead of 'fontName' here because the original
  30906. // name ArialBlack for example will be replaced by Helvetica.
  30907. this.black = (name.search(/Black/g) !== -1);
  30908. // if at least one width is present, remeasure all chars when exists
  30909. this.remeasure = Object.keys(this.widths).length > 0;
  30910. if (isStandardFont && type === 'CIDFontType2' &&
  30911. properties.cidEncoding.indexOf('Identity-') === 0) {
  30912. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  30913. // Standard fonts might be embedded as CID font without glyph mapping.
  30914. // Building one based on GlyphMapForStandardFonts.
  30915. var map = [];
  30916. for (charCode in GlyphMapForStandardFonts) {
  30917. map[+charCode] = GlyphMapForStandardFonts[charCode];
  30918. }
  30919. if (/ArialBlack/i.test(name)) {
  30920. var SupplementalGlyphMapForArialBlack =
  30921. getSupplementalGlyphMapForArialBlack();
  30922. for (charCode in SupplementalGlyphMapForArialBlack) {
  30923. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  30924. }
  30925. }
  30926. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  30927. if (!isIdentityUnicode) {
  30928. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  30929. map[+charCode] = unicodeCharCode;
  30930. });
  30931. }
  30932. this.toFontChar = map;
  30933. this.toUnicode = new ToUnicodeMap(map);
  30934. } else if (/Symbol/i.test(fontName)) {
  30935. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  30936. properties.differences);
  30937. } else if (/Dingbats/i.test(fontName)) {
  30938. if (/Wingdings/i.test(name)) {
  30939. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  30940. }
  30941. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  30942. getDingbatsGlyphsUnicode(),
  30943. properties.differences);
  30944. } else if (isStandardFont) {
  30945. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  30946. getGlyphsUnicode(),
  30947. properties.differences);
  30948. } else {
  30949. glyphsUnicodeMap = getGlyphsUnicode();
  30950. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  30951. if (!this.composite) {
  30952. glyphName = (properties.differences[charCode] ||
  30953. properties.defaultEncoding[charCode]);
  30954. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  30955. if (unicode !== -1) {
  30956. unicodeCharCode = unicode;
  30957. }
  30958. }
  30959. this.toFontChar[charCode] = unicodeCharCode;
  30960. }.bind(this));
  30961. }
  30962. this.loadedName = fontName.split('-')[0];
  30963. this.loading = false;
  30964. this.fontType = getFontType(type, subtype);
  30965. return;
  30966. }
  30967. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  30968. if (subtype === 'Type1C') {
  30969. if (type !== 'Type1' && type !== 'MMType1') {
  30970. // Some TrueType fonts by mistake claim Type1C
  30971. if (isTrueTypeFile(file)) {
  30972. subtype = 'TrueType';
  30973. } else {
  30974. type = 'Type1';
  30975. }
  30976. } else if (isOpenTypeFile(file)) {
  30977. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  30978. type = subtype = 'OpenType';
  30979. }
  30980. }
  30981. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  30982. type = 'CIDFontType0';
  30983. }
  30984. if (subtype === 'OpenType') {
  30985. type = 'OpenType';
  30986. }
  30987. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  30988. if (type === 'CIDFontType0') {
  30989. if (isType1File(file)) {
  30990. subtype = 'CIDFontType0';
  30991. } else if (isOpenTypeFile(file)) {
  30992. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  30993. type = subtype = 'OpenType';
  30994. } else {
  30995. subtype = 'CIDFontType0C';
  30996. }
  30997. }
  30998. var data;
  30999. switch (type) {
  31000. case 'MMType1':
  31001. info('MMType1 font (' + name + '), falling back to Type1.');
  31002. /* falls through */
  31003. case 'Type1':
  31004. case 'CIDFontType0':
  31005. this.mimetype = 'font/opentype';
  31006. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  31007. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  31008. adjustWidths(properties);
  31009. // Wrap the CFF data inside an OTF font file
  31010. data = this.convert(name, cff, properties);
  31011. break;
  31012. case 'OpenType':
  31013. case 'TrueType':
  31014. case 'CIDFontType2':
  31015. this.mimetype = 'font/opentype';
  31016. // Repair the TrueType file. It is can be damaged in the point of
  31017. // view of the sanitizer
  31018. data = this.checkAndRepair(name, file, properties);
  31019. if (this.isOpenType) {
  31020. adjustWidths(properties);
  31021. type = 'OpenType';
  31022. }
  31023. break;
  31024. default:
  31025. error('Font ' + type + ' is not supported');
  31026. break;
  31027. }
  31028. this.data = data;
  31029. this.fontType = getFontType(type, subtype);
  31030. // Transfer some properties again that could change during font conversion
  31031. this.fontMatrix = properties.fontMatrix;
  31032. this.widths = properties.widths;
  31033. this.defaultWidth = properties.defaultWidth;
  31034. this.toUnicode = properties.toUnicode;
  31035. this.encoding = properties.baseEncoding;
  31036. this.seacMap = properties.seacMap;
  31037. this.loading = true;
  31038. }
  31039. Font.getFontID = (function () {
  31040. var ID = 1;
  31041. return function Font_getFontID() {
  31042. return String(ID++);
  31043. };
  31044. })();
  31045. function int16(b0, b1) {
  31046. return (b0 << 8) + b1;
  31047. }
  31048. function signedInt16(b0, b1) {
  31049. var value = (b0 << 8) + b1;
  31050. return value & (1 << 15) ? value - 0x10000 : value;
  31051. }
  31052. function int32(b0, b1, b2, b3) {
  31053. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  31054. }
  31055. function string16(value) {
  31056. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  31057. }
  31058. function safeString16(value) {
  31059. // clamp value to the 16-bit int range
  31060. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  31061. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  31062. }
  31063. function isTrueTypeFile(file) {
  31064. var header = file.peekBytes(4);
  31065. return readUint32(header, 0) === 0x00010000;
  31066. }
  31067. function isOpenTypeFile(file) {
  31068. var header = file.peekBytes(4);
  31069. return bytesToString(header) === 'OTTO';
  31070. }
  31071. function isType1File(file) {
  31072. var header = file.peekBytes(2);
  31073. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  31074. if (header[0] === 0x25 && header[1] === 0x21) {
  31075. return true;
  31076. }
  31077. // ... obviously some fonts violate that part of the specification,
  31078. // please refer to the comment in |Type1Font| below.
  31079. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  31080. return true;
  31081. }
  31082. return false;
  31083. }
  31084. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  31085. var toFontChar = [], unicode;
  31086. for (var i = 0, ii = encoding.length; i < ii; i++) {
  31087. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  31088. if (unicode !== -1) {
  31089. toFontChar[i] = unicode;
  31090. }
  31091. }
  31092. for (var charCode in differences) {
  31093. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  31094. if (unicode !== -1) {
  31095. toFontChar[+charCode] = unicode;
  31096. }
  31097. }
  31098. return toFontChar;
  31099. }
  31100. /**
  31101. * Helper function for |adjustMapping|.
  31102. * @return {boolean}
  31103. */
  31104. function isProblematicUnicodeLocation(code) {
  31105. // Using binary search to find a range start.
  31106. var i = 0, j = ProblematicCharRanges.length - 1;
  31107. while (i < j) {
  31108. var c = (i + j + 1) >> 1;
  31109. if (code < ProblematicCharRanges[c]) {
  31110. j = c - 1;
  31111. } else {
  31112. i = c;
  31113. }
  31114. }
  31115. // Even index means code in problematic range.
  31116. return !(i & 1);
  31117. }
  31118. /**
  31119. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  31120. * with their unicode value. It also moves char codes that are in known
  31121. * problematic locations.
  31122. * @return {Object} Two properties:
  31123. * 'toFontChar' - maps original char codes(the value that will be read
  31124. * from commands such as show text) to the char codes that will be used in the
  31125. * font that we build
  31126. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  31127. */
  31128. function adjustMapping(charCodeToGlyphId, properties) {
  31129. var toUnicode = properties.toUnicode;
  31130. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  31131. var isIdentityUnicode =
  31132. properties.toUnicode instanceof IdentityToUnicodeMap;
  31133. var newMap = Object.create(null);
  31134. var toFontChar = [];
  31135. var usedFontCharCodes = [];
  31136. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  31137. for (var originalCharCode in charCodeToGlyphId) {
  31138. originalCharCode |= 0;
  31139. var glyphId = charCodeToGlyphId[originalCharCode];
  31140. var fontCharCode = originalCharCode;
  31141. // First try to map the value to a unicode position if a non identity map
  31142. // was created.
  31143. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  31144. var unicode = toUnicode.get(fontCharCode);
  31145. // TODO: Try to map ligatures to the correct spot.
  31146. if (unicode.length === 1) {
  31147. fontCharCode = unicode.charCodeAt(0);
  31148. }
  31149. }
  31150. // Try to move control characters, special characters and already mapped
  31151. // characters to the private use area since they will not be drawn by
  31152. // canvas if left in their current position. Also, move characters if the
  31153. // font was symbolic and there is only an identity unicode map since the
  31154. // characters probably aren't in the correct position (fixes an issue
  31155. // with firefox and thuluthfont).
  31156. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  31157. isProblematicUnicodeLocation(fontCharCode) ||
  31158. (isSymbolic && isIdentityUnicode)) &&
  31159. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  31160. // Loop to try and find a free spot in the private use area.
  31161. do {
  31162. fontCharCode = nextAvailableFontCharCode++;
  31163. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  31164. fontCharCode = 0xF020;
  31165. nextAvailableFontCharCode = fontCharCode + 1;
  31166. }
  31167. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  31168. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  31169. }
  31170. newMap[fontCharCode] = glyphId;
  31171. toFontChar[originalCharCode] = fontCharCode;
  31172. usedFontCharCodes[fontCharCode] = true;
  31173. }
  31174. return {
  31175. toFontChar: toFontChar,
  31176. charCodeToGlyphId: newMap,
  31177. nextAvailableFontCharCode: nextAvailableFontCharCode
  31178. };
  31179. }
  31180. function getRanges(glyphs, numGlyphs) {
  31181. // Array.sort() sorts by characters, not numerically, so convert to an
  31182. // array of characters.
  31183. var codes = [];
  31184. for (var charCode in glyphs) {
  31185. // Remove an invalid glyph ID mappings to make OTS happy.
  31186. if (glyphs[charCode] >= numGlyphs) {
  31187. continue;
  31188. }
  31189. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  31190. }
  31191. codes.sort(function fontGetRangesSort(a, b) {
  31192. return a.fontCharCode - b.fontCharCode;
  31193. });
  31194. // Split the sorted codes into ranges.
  31195. var ranges = [];
  31196. var length = codes.length;
  31197. for (var n = 0; n < length; ) {
  31198. var start = codes[n].fontCharCode;
  31199. var codeIndices = [codes[n].glyphId];
  31200. ++n;
  31201. var end = start;
  31202. while (n < length && end + 1 === codes[n].fontCharCode) {
  31203. codeIndices.push(codes[n].glyphId);
  31204. ++end;
  31205. ++n;
  31206. if (end === 0xFFFF) {
  31207. break;
  31208. }
  31209. }
  31210. ranges.push([start, end, codeIndices]);
  31211. }
  31212. return ranges;
  31213. }
  31214. function createCmapTable(glyphs, numGlyphs) {
  31215. var ranges = getRanges(glyphs, numGlyphs);
  31216. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  31217. var cmap = '\x00\x00' + // version
  31218. string16(numTables) + // numTables
  31219. '\x00\x03' + // platformID
  31220. '\x00\x01' + // encodingID
  31221. string32(4 + numTables * 8); // start of the table record
  31222. var i, ii, j, jj;
  31223. for (i = ranges.length - 1; i >= 0; --i) {
  31224. if (ranges[i][0] <= 0xFFFF) { break; }
  31225. }
  31226. var bmpLength = i + 1;
  31227. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  31228. ranges[i][1] = 0xFFFE;
  31229. }
  31230. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  31231. var segCount = bmpLength + trailingRangesCount;
  31232. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  31233. // Fill up the 4 parallel arrays describing the segments.
  31234. var startCount = '';
  31235. var endCount = '';
  31236. var idDeltas = '';
  31237. var idRangeOffsets = '';
  31238. var glyphsIds = '';
  31239. var bias = 0;
  31240. var range, start, end, codes;
  31241. for (i = 0, ii = bmpLength; i < ii; i++) {
  31242. range = ranges[i];
  31243. start = range[0];
  31244. end = range[1];
  31245. startCount += string16(start);
  31246. endCount += string16(end);
  31247. codes = range[2];
  31248. var contiguous = true;
  31249. for (j = 1, jj = codes.length; j < jj; ++j) {
  31250. if (codes[j] !== codes[j - 1] + 1) {
  31251. contiguous = false;
  31252. break;
  31253. }
  31254. }
  31255. if (!contiguous) {
  31256. var offset = (segCount - i) * 2 + bias * 2;
  31257. bias += (end - start + 1);
  31258. idDeltas += string16(0);
  31259. idRangeOffsets += string16(offset);
  31260. for (j = 0, jj = codes.length; j < jj; ++j) {
  31261. glyphsIds += string16(codes[j]);
  31262. }
  31263. } else {
  31264. var startCode = codes[0];
  31265. idDeltas += string16((startCode - start) & 0xFFFF);
  31266. idRangeOffsets += string16(0);
  31267. }
  31268. }
  31269. if (trailingRangesCount > 0) {
  31270. endCount += '\xFF\xFF';
  31271. startCount += '\xFF\xFF';
  31272. idDeltas += '\x00\x01';
  31273. idRangeOffsets += '\x00\x00';
  31274. }
  31275. var format314 = '\x00\x00' + // language
  31276. string16(2 * segCount) +
  31277. string16(searchParams.range) +
  31278. string16(searchParams.entry) +
  31279. string16(searchParams.rangeShift) +
  31280. endCount + '\x00\x00' + startCount +
  31281. idDeltas + idRangeOffsets + glyphsIds;
  31282. var format31012 = '';
  31283. var header31012 = '';
  31284. if (numTables > 1) {
  31285. cmap += '\x00\x03' + // platformID
  31286. '\x00\x0A' + // encodingID
  31287. string32(4 + numTables * 8 +
  31288. 4 + format314.length); // start of the table record
  31289. format31012 = '';
  31290. for (i = 0, ii = ranges.length; i < ii; i++) {
  31291. range = ranges[i];
  31292. start = range[0];
  31293. codes = range[2];
  31294. var code = codes[0];
  31295. for (j = 1, jj = codes.length; j < jj; ++j) {
  31296. if (codes[j] !== codes[j - 1] + 1) {
  31297. end = range[0] + j - 1;
  31298. format31012 += string32(start) + // startCharCode
  31299. string32(end) + // endCharCode
  31300. string32(code); // startGlyphID
  31301. start = end + 1;
  31302. code = codes[j];
  31303. }
  31304. }
  31305. format31012 += string32(start) + // startCharCode
  31306. string32(range[1]) + // endCharCode
  31307. string32(code); // startGlyphID
  31308. }
  31309. header31012 = '\x00\x0C' + // format
  31310. '\x00\x00' + // reserved
  31311. string32(format31012.length + 16) + // length
  31312. '\x00\x00\x00\x00' + // language
  31313. string32(format31012.length / 12); // nGroups
  31314. }
  31315. return cmap + '\x00\x04' + // format
  31316. string16(format314.length + 4) + // length
  31317. format314 + header31012 + format31012;
  31318. }
  31319. function validateOS2Table(os2) {
  31320. var stream = new Stream(os2.data);
  31321. var version = stream.getUint16();
  31322. // TODO verify all OS/2 tables fields, but currently we validate only those
  31323. // that give us issues
  31324. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  31325. var selection = stream.getUint16();
  31326. if (version < 4 && (selection & 0x0300)) {
  31327. return false;
  31328. }
  31329. var firstChar = stream.getUint16();
  31330. var lastChar = stream.getUint16();
  31331. if (firstChar > lastChar) {
  31332. return false;
  31333. }
  31334. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  31335. var usWinAscent = stream.getUint16();
  31336. if (usWinAscent === 0) { // makes font unreadable by windows
  31337. return false;
  31338. }
  31339. // OS/2 appears to be valid, resetting some fields
  31340. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  31341. return true;
  31342. }
  31343. function createOS2Table(properties, charstrings, override) {
  31344. override = override || {
  31345. unitsPerEm: 0,
  31346. yMax: 0,
  31347. yMin: 0,
  31348. ascent: 0,
  31349. descent: 0
  31350. };
  31351. var ulUnicodeRange1 = 0;
  31352. var ulUnicodeRange2 = 0;
  31353. var ulUnicodeRange3 = 0;
  31354. var ulUnicodeRange4 = 0;
  31355. var firstCharIndex = null;
  31356. var lastCharIndex = 0;
  31357. if (charstrings) {
  31358. for (var code in charstrings) {
  31359. code |= 0;
  31360. if (firstCharIndex > code || !firstCharIndex) {
  31361. firstCharIndex = code;
  31362. }
  31363. if (lastCharIndex < code) {
  31364. lastCharIndex = code;
  31365. }
  31366. var position = getUnicodeRangeFor(code);
  31367. if (position < 32) {
  31368. ulUnicodeRange1 |= 1 << position;
  31369. } else if (position < 64) {
  31370. ulUnicodeRange2 |= 1 << position - 32;
  31371. } else if (position < 96) {
  31372. ulUnicodeRange3 |= 1 << position - 64;
  31373. } else if (position < 123) {
  31374. ulUnicodeRange4 |= 1 << position - 96;
  31375. } else {
  31376. error('Unicode ranges Bits > 123 are reserved for internal usage');
  31377. }
  31378. }
  31379. } else {
  31380. // TODO
  31381. firstCharIndex = 0;
  31382. lastCharIndex = 255;
  31383. }
  31384. var bbox = properties.bbox || [0, 0, 0, 0];
  31385. var unitsPerEm = (override.unitsPerEm ||
  31386. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  31387. // if the font units differ to the PDF glyph space units
  31388. // then scale up the values
  31389. var scale = (properties.ascentScaled ? 1.0 :
  31390. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  31391. var typoAscent = (override.ascent ||
  31392. Math.round(scale * (properties.ascent || bbox[3])));
  31393. var typoDescent = (override.descent ||
  31394. Math.round(scale * (properties.descent || bbox[1])));
  31395. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  31396. typoDescent = -typoDescent; // fixing incorrect descent
  31397. }
  31398. var winAscent = override.yMax || typoAscent;
  31399. var winDescent = -override.yMin || -typoDescent;
  31400. return '\x00\x03' + // version
  31401. '\x02\x24' + // xAvgCharWidth
  31402. '\x01\xF4' + // usWeightClass
  31403. '\x00\x05' + // usWidthClass
  31404. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  31405. '\x02\x8A' + // ySubscriptXSize
  31406. '\x02\xBB' + // ySubscriptYSize
  31407. '\x00\x00' + // ySubscriptXOffset
  31408. '\x00\x8C' + // ySubscriptYOffset
  31409. '\x02\x8A' + // ySuperScriptXSize
  31410. '\x02\xBB' + // ySuperScriptYSize
  31411. '\x00\x00' + // ySuperScriptXOffset
  31412. '\x01\xDF' + // ySuperScriptYOffset
  31413. '\x00\x31' + // yStrikeOutSize
  31414. '\x01\x02' + // yStrikeOutPosition
  31415. '\x00\x00' + // sFamilyClass
  31416. '\x00\x00\x06' +
  31417. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  31418. '\x00\x00\x00\x00\x00\x00' + // Panose
  31419. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  31420. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  31421. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  31422. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  31423. '\x2A\x32\x31\x2A' + // achVendID
  31424. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  31425. string16(firstCharIndex ||
  31426. properties.firstChar) + // usFirstCharIndex
  31427. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  31428. string16(typoAscent) + // sTypoAscender
  31429. string16(typoDescent) + // sTypoDescender
  31430. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  31431. string16(winAscent) + // usWinAscent
  31432. string16(winDescent) + // usWinDescent
  31433. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  31434. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  31435. string16(properties.xHeight) + // sxHeight
  31436. string16(properties.capHeight) + // sCapHeight
  31437. string16(0) + // usDefaultChar
  31438. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  31439. '\x00\x03'; // usMaxContext
  31440. }
  31441. function createPostTable(properties) {
  31442. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  31443. return ('\x00\x03\x00\x00' + // Version number
  31444. string32(angle) + // italicAngle
  31445. '\x00\x00' + // underlinePosition
  31446. '\x00\x00' + // underlineThickness
  31447. string32(properties.fixedPitch) + // isFixedPitch
  31448. '\x00\x00\x00\x00' + // minMemType42
  31449. '\x00\x00\x00\x00' + // maxMemType42
  31450. '\x00\x00\x00\x00' + // minMemType1
  31451. '\x00\x00\x00\x00'); // maxMemType1
  31452. }
  31453. function createNameTable(name, proto) {
  31454. if (!proto) {
  31455. proto = [[], []]; // no strings and unicode strings
  31456. }
  31457. var strings = [
  31458. proto[0][0] || 'Original licence', // 0.Copyright
  31459. proto[0][1] || name, // 1.Font family
  31460. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  31461. proto[0][3] || 'uniqueID', // 3.Unique ID
  31462. proto[0][4] || name, // 4.Full font name
  31463. proto[0][5] || 'Version 0.11', // 5.Version
  31464. proto[0][6] || '', // 6.Postscript name
  31465. proto[0][7] || 'Unknown', // 7.Trademark
  31466. proto[0][8] || 'Unknown', // 8.Manufacturer
  31467. proto[0][9] || 'Unknown' // 9.Designer
  31468. ];
  31469. // Mac want 1-byte per character strings while Windows want
  31470. // 2-bytes per character, so duplicate the names table
  31471. var stringsUnicode = [];
  31472. var i, ii, j, jj, str;
  31473. for (i = 0, ii = strings.length; i < ii; i++) {
  31474. str = proto[1][i] || strings[i];
  31475. var strBufUnicode = [];
  31476. for (j = 0, jj = str.length; j < jj; j++) {
  31477. strBufUnicode.push(string16(str.charCodeAt(j)));
  31478. }
  31479. stringsUnicode.push(strBufUnicode.join(''));
  31480. }
  31481. var names = [strings, stringsUnicode];
  31482. var platforms = ['\x00\x01', '\x00\x03'];
  31483. var encodings = ['\x00\x00', '\x00\x01'];
  31484. var languages = ['\x00\x00', '\x04\x09'];
  31485. var namesRecordCount = strings.length * platforms.length;
  31486. var nameTable =
  31487. '\x00\x00' + // format
  31488. string16(namesRecordCount) + // Number of names Record
  31489. string16(namesRecordCount * 12 + 6); // Storage
  31490. // Build the name records field
  31491. var strOffset = 0;
  31492. for (i = 0, ii = platforms.length; i < ii; i++) {
  31493. var strs = names[i];
  31494. for (j = 0, jj = strs.length; j < jj; j++) {
  31495. str = strs[j];
  31496. var nameRecord =
  31497. platforms[i] + // platform ID
  31498. encodings[i] + // encoding ID
  31499. languages[i] + // language ID
  31500. string16(j) + // name ID
  31501. string16(str.length) +
  31502. string16(strOffset);
  31503. nameTable += nameRecord;
  31504. strOffset += str.length;
  31505. }
  31506. }
  31507. nameTable += strings.join('') + stringsUnicode.join('');
  31508. return nameTable;
  31509. }
  31510. Font.prototype = {
  31511. name: null,
  31512. font: null,
  31513. mimetype: null,
  31514. encoding: null,
  31515. get renderer() {
  31516. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  31517. return shadow(this, 'renderer', renderer);
  31518. },
  31519. exportData: function Font_exportData() {
  31520. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  31521. var data = {};
  31522. for (var i in this) {
  31523. if (this.hasOwnProperty(i)) {
  31524. data[i] = this[i];
  31525. }
  31526. }
  31527. return data;
  31528. },
  31529. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  31530. function readTableEntry(file) {
  31531. var tag = bytesToString(file.getBytes(4));
  31532. var checksum = file.getInt32() >>> 0;
  31533. var offset = file.getInt32() >>> 0;
  31534. var length = file.getInt32() >>> 0;
  31535. // Read the table associated data
  31536. var previousPosition = file.pos;
  31537. file.pos = file.start ? file.start : 0;
  31538. file.skip(offset);
  31539. var data = file.getBytes(length);
  31540. file.pos = previousPosition;
  31541. if (tag === 'head') {
  31542. // clearing checksum adjustment
  31543. data[8] = data[9] = data[10] = data[11] = 0;
  31544. data[17] |= 0x20; //Set font optimized for cleartype flag
  31545. }
  31546. return {
  31547. tag: tag,
  31548. checksum: checksum,
  31549. length: length,
  31550. offset: offset,
  31551. data: data
  31552. };
  31553. }
  31554. function readOpenTypeHeader(ttf) {
  31555. return {
  31556. version: bytesToString(ttf.getBytes(4)),
  31557. numTables: ttf.getUint16(),
  31558. searchRange: ttf.getUint16(),
  31559. entrySelector: ttf.getUint16(),
  31560. rangeShift: ttf.getUint16()
  31561. };
  31562. }
  31563. /**
  31564. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  31565. * PDF spec
  31566. */
  31567. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  31568. if (!cmap) {
  31569. warn('No cmap table available.');
  31570. return {
  31571. platformId: -1,
  31572. encodingId: -1,
  31573. mappings: [],
  31574. hasShortCmap: false
  31575. };
  31576. }
  31577. var segment;
  31578. var start = (font.start ? font.start : 0) + cmap.offset;
  31579. font.pos = start;
  31580. var version = font.getUint16();
  31581. var numTables = font.getUint16();
  31582. var potentialTable;
  31583. var canBreak = false;
  31584. // There's an order of preference in terms of which cmap subtable to
  31585. // use:
  31586. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  31587. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  31588. // The following takes advantage of the fact that the tables are sorted
  31589. // to work.
  31590. for (var i = 0; i < numTables; i++) {
  31591. var platformId = font.getUint16();
  31592. var encodingId = font.getUint16();
  31593. var offset = font.getInt32() >>> 0;
  31594. var useTable = false;
  31595. if (platformId === 0 && encodingId === 0) {
  31596. useTable = true;
  31597. // Continue the loop since there still may be a higher priority
  31598. // table.
  31599. } else if (platformId === 1 && encodingId === 0) {
  31600. useTable = true;
  31601. // Continue the loop since there still may be a higher priority
  31602. // table.
  31603. } else if (platformId === 3 && encodingId === 1 &&
  31604. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  31605. useTable = true;
  31606. if (!isSymbolicFont) {
  31607. canBreak = true;
  31608. }
  31609. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  31610. useTable = true;
  31611. canBreak = true;
  31612. }
  31613. if (useTable) {
  31614. potentialTable = {
  31615. platformId: platformId,
  31616. encodingId: encodingId,
  31617. offset: offset
  31618. };
  31619. }
  31620. if (canBreak) {
  31621. break;
  31622. }
  31623. }
  31624. if (potentialTable) {
  31625. font.pos = start + potentialTable.offset;
  31626. }
  31627. if (!potentialTable || font.peekByte() === -1) {
  31628. warn('Could not find a preferred cmap table.');
  31629. return {
  31630. platformId: -1,
  31631. encodingId: -1,
  31632. mappings: [],
  31633. hasShortCmap: false
  31634. };
  31635. }
  31636. var format = font.getUint16();
  31637. var length = font.getUint16();
  31638. var language = font.getUint16();
  31639. var hasShortCmap = false;
  31640. var mappings = [];
  31641. var j, glyphId;
  31642. // TODO(mack): refactor this cmap subtable reading logic out
  31643. if (format === 0) {
  31644. for (j = 0; j < 256; j++) {
  31645. var index = font.getByte();
  31646. if (!index) {
  31647. continue;
  31648. }
  31649. mappings.push({
  31650. charCode: j,
  31651. glyphId: index
  31652. });
  31653. }
  31654. hasShortCmap = true;
  31655. } else if (format === 4) {
  31656. // re-creating the table in format 4 since the encoding
  31657. // might be changed
  31658. var segCount = (font.getUint16() >> 1);
  31659. font.getBytes(6); // skipping range fields
  31660. var segIndex, segments = [];
  31661. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31662. segments.push({ end: font.getUint16() });
  31663. }
  31664. font.getUint16();
  31665. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31666. segments[segIndex].start = font.getUint16();
  31667. }
  31668. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31669. segments[segIndex].delta = font.getUint16();
  31670. }
  31671. var offsetsCount = 0;
  31672. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31673. segment = segments[segIndex];
  31674. var rangeOffset = font.getUint16();
  31675. if (!rangeOffset) {
  31676. segment.offsetIndex = -1;
  31677. continue;
  31678. }
  31679. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  31680. segment.offsetIndex = offsetIndex;
  31681. offsetsCount = Math.max(offsetsCount, offsetIndex +
  31682. segment.end - segment.start + 1);
  31683. }
  31684. var offsets = [];
  31685. for (j = 0; j < offsetsCount; j++) {
  31686. offsets.push(font.getUint16());
  31687. }
  31688. for (segIndex = 0; segIndex < segCount; segIndex++) {
  31689. segment = segments[segIndex];
  31690. start = segment.start;
  31691. var end = segment.end;
  31692. var delta = segment.delta;
  31693. offsetIndex = segment.offsetIndex;
  31694. for (j = start; j <= end; j++) {
  31695. if (j === 0xFFFF) {
  31696. continue;
  31697. }
  31698. glyphId = (offsetIndex < 0 ?
  31699. j : offsets[offsetIndex + j - start]);
  31700. glyphId = (glyphId + delta) & 0xFFFF;
  31701. if (glyphId === 0) {
  31702. continue;
  31703. }
  31704. mappings.push({
  31705. charCode: j,
  31706. glyphId: glyphId
  31707. });
  31708. }
  31709. }
  31710. } else if (format === 6) {
  31711. // Format 6 is a 2-bytes dense mapping, which means the font data
  31712. // lives glue together even if they are pretty far in the unicode
  31713. // table. (This looks weird, so I can have missed something), this
  31714. // works on Linux but seems to fails on Mac so let's rewrite the
  31715. // cmap table to a 3-1-4 style
  31716. var firstCode = font.getUint16();
  31717. var entryCount = font.getUint16();
  31718. for (j = 0; j < entryCount; j++) {
  31719. glyphId = font.getUint16();
  31720. var charCode = firstCode + j;
  31721. mappings.push({
  31722. charCode: charCode,
  31723. glyphId: glyphId
  31724. });
  31725. }
  31726. } else {
  31727. warn('cmap table has unsupported format: ' + format);
  31728. return {
  31729. platformId: -1,
  31730. encodingId: -1,
  31731. mappings: [],
  31732. hasShortCmap: false
  31733. };
  31734. }
  31735. // removing duplicate entries
  31736. mappings.sort(function (a, b) {
  31737. return a.charCode - b.charCode;
  31738. });
  31739. for (i = 1; i < mappings.length; i++) {
  31740. if (mappings[i - 1].charCode === mappings[i].charCode) {
  31741. mappings.splice(i, 1);
  31742. i--;
  31743. }
  31744. }
  31745. return {
  31746. platformId: potentialTable.platformId,
  31747. encodingId: potentialTable.encodingId,
  31748. mappings: mappings,
  31749. hasShortCmap: hasShortCmap
  31750. };
  31751. }
  31752. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  31753. if (!header) {
  31754. if (metrics) {
  31755. metrics.data = null;
  31756. }
  31757. return;
  31758. }
  31759. font.pos = (font.start ? font.start : 0) + header.offset;
  31760. font.pos += header.length - 2;
  31761. var numOfMetrics = font.getUint16();
  31762. if (numOfMetrics > numGlyphs) {
  31763. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  31764. 'greater than the numGlyphs (' + numGlyphs + ')');
  31765. // Reduce numOfMetrics if it is greater than numGlyphs
  31766. numOfMetrics = numGlyphs;
  31767. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  31768. header.data[35] = numOfMetrics & 0x00ff;
  31769. }
  31770. var numOfSidebearings = numGlyphs - numOfMetrics;
  31771. var numMissing = numOfSidebearings -
  31772. ((metrics.length - numOfMetrics * 4) >> 1);
  31773. if (numMissing > 0) {
  31774. // For each missing glyph, we set both the width and lsb to 0 (zero).
  31775. // Since we need to add two properties for each glyph, this explains
  31776. // the use of |numMissing * 2| when initializing the typed array.
  31777. var entries = new Uint8Array(metrics.length + numMissing * 2);
  31778. entries.set(metrics.data);
  31779. metrics.data = entries;
  31780. }
  31781. }
  31782. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  31783. hintsValid) {
  31784. if (sourceEnd - sourceStart <= 12) {
  31785. // glyph with data less than 12 is invalid one
  31786. return 0;
  31787. }
  31788. var glyf = source.subarray(sourceStart, sourceEnd);
  31789. var contoursCount = (glyf[0] << 8) | glyf[1];
  31790. if (contoursCount & 0x8000) {
  31791. // complex glyph, writing as is
  31792. dest.set(glyf, destStart);
  31793. return glyf.length;
  31794. }
  31795. var i, j = 10, flagsCount = 0;
  31796. for (i = 0; i < contoursCount; i++) {
  31797. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  31798. flagsCount = endPoint + 1;
  31799. j += 2;
  31800. }
  31801. // skipping instructions
  31802. var instructionsStart = j;
  31803. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  31804. j += 2 + instructionsLength;
  31805. var instructionsEnd = j;
  31806. // validating flags
  31807. var coordinatesLength = 0;
  31808. for (i = 0; i < flagsCount; i++) {
  31809. var flag = glyf[j++];
  31810. if (flag & 0xC0) {
  31811. // reserved flags must be zero, cleaning up
  31812. glyf[j - 1] = flag & 0x3F;
  31813. }
  31814. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  31815. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  31816. coordinatesLength += xyLength;
  31817. if (flag & 8) {
  31818. var repeat = glyf[j++];
  31819. i += repeat;
  31820. coordinatesLength += repeat * xyLength;
  31821. }
  31822. }
  31823. // glyph without coordinates will be rejected
  31824. if (coordinatesLength === 0) {
  31825. return 0;
  31826. }
  31827. var glyphDataLength = j + coordinatesLength;
  31828. if (glyphDataLength > glyf.length) {
  31829. // not enough data for coordinates
  31830. return 0;
  31831. }
  31832. if (!hintsValid && instructionsLength > 0) {
  31833. dest.set(glyf.subarray(0, instructionsStart), destStart);
  31834. dest.set([0, 0], destStart + instructionsStart);
  31835. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  31836. destStart + instructionsStart + 2);
  31837. glyphDataLength -= instructionsLength;
  31838. if (glyf.length - glyphDataLength > 3) {
  31839. glyphDataLength = (glyphDataLength + 3) & ~3;
  31840. }
  31841. return glyphDataLength;
  31842. }
  31843. if (glyf.length - glyphDataLength > 3) {
  31844. // truncating and aligning to 4 bytes the long glyph data
  31845. glyphDataLength = (glyphDataLength + 3) & ~3;
  31846. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  31847. return glyphDataLength;
  31848. }
  31849. // glyph data is fine
  31850. dest.set(glyf, destStart);
  31851. return glyf.length;
  31852. }
  31853. function sanitizeHead(head, numGlyphs, locaLength) {
  31854. var data = head.data;
  31855. // Validate version:
  31856. // Should always be 0x00010000
  31857. var version = int32(data[0], data[1], data[2], data[3]);
  31858. if (version >> 16 !== 1) {
  31859. info('Attempting to fix invalid version in head table: ' + version);
  31860. data[0] = 0;
  31861. data[1] = 1;
  31862. data[2] = 0;
  31863. data[3] = 0;
  31864. }
  31865. var indexToLocFormat = int16(data[50], data[51]);
  31866. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  31867. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  31868. indexToLocFormat);
  31869. // The value of indexToLocFormat should be 0 if the loca table
  31870. // consists of short offsets, and should be 1 if the loca table
  31871. // consists of long offsets.
  31872. //
  31873. // The number of entries in the loca table should be numGlyphs + 1.
  31874. //
  31875. // Using this information, we can work backwards to deduce if the
  31876. // size of each offset in the loca table, and thus figure out the
  31877. // appropriate value for indexToLocFormat.
  31878. var numGlyphsPlusOne = numGlyphs + 1;
  31879. if (locaLength === numGlyphsPlusOne << 1) {
  31880. // 0x0000 indicates the loca table consists of short offsets
  31881. data[50] = 0;
  31882. data[51] = 0;
  31883. } else if (locaLength === numGlyphsPlusOne << 2) {
  31884. // 0x0001 indicates the loca table consists of long offsets
  31885. data[50] = 0;
  31886. data[51] = 1;
  31887. } else {
  31888. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  31889. }
  31890. }
  31891. }
  31892. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  31893. isGlyphLocationsLong, hintsValid,
  31894. dupFirstEntry) {
  31895. var itemSize, itemDecode, itemEncode;
  31896. if (isGlyphLocationsLong) {
  31897. itemSize = 4;
  31898. itemDecode = function fontItemDecodeLong(data, offset) {
  31899. return (data[offset] << 24) | (data[offset + 1] << 16) |
  31900. (data[offset + 2] << 8) | data[offset + 3];
  31901. };
  31902. itemEncode = function fontItemEncodeLong(data, offset, value) {
  31903. data[offset] = (value >>> 24) & 0xFF;
  31904. data[offset + 1] = (value >> 16) & 0xFF;
  31905. data[offset + 2] = (value >> 8) & 0xFF;
  31906. data[offset + 3] = value & 0xFF;
  31907. };
  31908. } else {
  31909. itemSize = 2;
  31910. itemDecode = function fontItemDecode(data, offset) {
  31911. return (data[offset] << 9) | (data[offset + 1] << 1);
  31912. };
  31913. itemEncode = function fontItemEncode(data, offset, value) {
  31914. data[offset] = (value >> 9) & 0xFF;
  31915. data[offset + 1] = (value >> 1) & 0xFF;
  31916. };
  31917. }
  31918. var locaData = loca.data;
  31919. var locaDataSize = itemSize * (1 + numGlyphs);
  31920. // is loca.data too short or long?
  31921. if (locaData.length !== locaDataSize) {
  31922. locaData = new Uint8Array(locaDataSize);
  31923. locaData.set(loca.data.subarray(0, locaDataSize));
  31924. loca.data = locaData;
  31925. }
  31926. // removing the invalid glyphs
  31927. var oldGlyfData = glyf.data;
  31928. var oldGlyfDataLength = oldGlyfData.length;
  31929. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  31930. var startOffset = itemDecode(locaData, 0);
  31931. var writeOffset = 0;
  31932. var missingGlyphData = Object.create(null);
  31933. itemEncode(locaData, 0, writeOffset);
  31934. var i, j;
  31935. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  31936. var endOffset = itemDecode(locaData, j);
  31937. if (endOffset > oldGlyfDataLength &&
  31938. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  31939. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  31940. // the glyf table size, which makes last glyph out of range.
  31941. endOffset = oldGlyfDataLength;
  31942. }
  31943. if (endOffset > oldGlyfDataLength) {
  31944. // glyph end offset points outside glyf data, rejecting the glyph
  31945. itemEncode(locaData, j, writeOffset);
  31946. startOffset = endOffset;
  31947. continue;
  31948. }
  31949. if (startOffset === endOffset) {
  31950. missingGlyphData[i] = true;
  31951. }
  31952. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  31953. newGlyfData, writeOffset, hintsValid);
  31954. writeOffset += newLength;
  31955. itemEncode(locaData, j, writeOffset);
  31956. startOffset = endOffset;
  31957. }
  31958. if (writeOffset === 0) {
  31959. // glyf table cannot be empty -- redoing the glyf and loca tables
  31960. // to have single glyph with one point
  31961. var simpleGlyph = new Uint8Array(
  31962. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  31963. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  31964. itemEncode(locaData, j, simpleGlyph.length);
  31965. }
  31966. glyf.data = simpleGlyph;
  31967. return missingGlyphData;
  31968. }
  31969. if (dupFirstEntry) {
  31970. var firstEntryLength = itemDecode(locaData, itemSize);
  31971. if (newGlyfData.length > firstEntryLength + writeOffset) {
  31972. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  31973. } else {
  31974. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  31975. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  31976. }
  31977. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  31978. itemEncode(loca.data, locaData.length - itemSize,
  31979. writeOffset + firstEntryLength);
  31980. } else {
  31981. glyf.data = newGlyfData.subarray(0, writeOffset);
  31982. }
  31983. return missingGlyphData;
  31984. }
  31985. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  31986. var start = (font.start ? font.start : 0) + post.offset;
  31987. font.pos = start;
  31988. var length = post.length, end = start + length;
  31989. var version = font.getInt32();
  31990. // skip rest to the tables
  31991. font.getBytes(28);
  31992. var glyphNames;
  31993. var valid = true;
  31994. var i;
  31995. switch (version) {
  31996. case 0x00010000:
  31997. glyphNames = MacStandardGlyphOrdering;
  31998. break;
  31999. case 0x00020000:
  32000. var numGlyphs = font.getUint16();
  32001. if (numGlyphs !== maxpNumGlyphs) {
  32002. valid = false;
  32003. break;
  32004. }
  32005. var glyphNameIndexes = [];
  32006. for (i = 0; i < numGlyphs; ++i) {
  32007. var index = font.getUint16();
  32008. if (index >= 32768) {
  32009. valid = false;
  32010. break;
  32011. }
  32012. glyphNameIndexes.push(index);
  32013. }
  32014. if (!valid) {
  32015. break;
  32016. }
  32017. var customNames = [];
  32018. var strBuf = [];
  32019. while (font.pos < end) {
  32020. var stringLength = font.getByte();
  32021. strBuf.length = stringLength;
  32022. for (i = 0; i < stringLength; ++i) {
  32023. strBuf[i] = String.fromCharCode(font.getByte());
  32024. }
  32025. customNames.push(strBuf.join(''));
  32026. }
  32027. glyphNames = [];
  32028. for (i = 0; i < numGlyphs; ++i) {
  32029. var j = glyphNameIndexes[i];
  32030. if (j < 258) {
  32031. glyphNames.push(MacStandardGlyphOrdering[j]);
  32032. continue;
  32033. }
  32034. glyphNames.push(customNames[j - 258]);
  32035. }
  32036. break;
  32037. case 0x00030000:
  32038. break;
  32039. default:
  32040. warn('Unknown/unsupported post table version ' + version);
  32041. valid = false;
  32042. if (properties.defaultEncoding) {
  32043. glyphNames = properties.defaultEncoding;
  32044. }
  32045. break;
  32046. }
  32047. properties.glyphNames = glyphNames;
  32048. return valid;
  32049. }
  32050. function readNameTable(nameTable) {
  32051. var start = (font.start ? font.start : 0) + nameTable.offset;
  32052. font.pos = start;
  32053. var names = [[], []];
  32054. var length = nameTable.length, end = start + length;
  32055. var format = font.getUint16();
  32056. var FORMAT_0_HEADER_LENGTH = 6;
  32057. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  32058. // unsupported name table format or table "too" small
  32059. return names;
  32060. }
  32061. var numRecords = font.getUint16();
  32062. var stringsStart = font.getUint16();
  32063. var records = [];
  32064. var NAME_RECORD_LENGTH = 12;
  32065. var i, ii;
  32066. for (i = 0; i < numRecords &&
  32067. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  32068. var r = {
  32069. platform: font.getUint16(),
  32070. encoding: font.getUint16(),
  32071. language: font.getUint16(),
  32072. name: font.getUint16(),
  32073. length: font.getUint16(),
  32074. offset: font.getUint16()
  32075. };
  32076. // using only Macintosh and Windows platform/encoding names
  32077. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  32078. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  32079. records.push(r);
  32080. }
  32081. }
  32082. for (i = 0, ii = records.length; i < ii; i++) {
  32083. var record = records[i];
  32084. if (record.length <= 0) {
  32085. continue; // Nothing to process, ignoring.
  32086. }
  32087. var pos = start + stringsStart + record.offset;
  32088. if (pos + record.length > end) {
  32089. continue; // outside of name table, ignoring
  32090. }
  32091. font.pos = pos;
  32092. var nameIndex = record.name;
  32093. if (record.encoding) {
  32094. // unicode
  32095. var str = '';
  32096. for (var j = 0, jj = record.length; j < jj; j += 2) {
  32097. str += String.fromCharCode(font.getUint16());
  32098. }
  32099. names[1][nameIndex] = str;
  32100. } else {
  32101. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  32102. }
  32103. }
  32104. return names;
  32105. }
  32106. var TTOpsStackDeltas = [
  32107. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  32108. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  32109. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  32110. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  32111. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  32112. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  32113. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  32114. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  32115. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  32116. // 0xC0-DF == -1 and 0xE0-FF == -2
  32117. function sanitizeTTProgram(table, ttContext) {
  32118. var data = table.data;
  32119. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  32120. var stack = [];
  32121. var callstack = [];
  32122. var functionsCalled = [];
  32123. var tooComplexToFollowFunctions =
  32124. ttContext.tooComplexToFollowFunctions;
  32125. var inFDEF = false, ifLevel = 0, inELSE = 0;
  32126. for (var ii = data.length; i < ii;) {
  32127. var op = data[i++];
  32128. // The TrueType instruction set docs can be found at
  32129. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  32130. if (op === 0x40) { // NPUSHB - pushes n bytes
  32131. n = data[i++];
  32132. if (inFDEF || inELSE) {
  32133. i += n;
  32134. } else {
  32135. for (j = 0; j < n; j++) {
  32136. stack.push(data[i++]);
  32137. }
  32138. }
  32139. } else if (op === 0x41) { // NPUSHW - pushes n words
  32140. n = data[i++];
  32141. if (inFDEF || inELSE) {
  32142. i += n * 2;
  32143. } else {
  32144. for (j = 0; j < n; j++) {
  32145. b = data[i++];
  32146. stack.push((b << 8) | data[i++]);
  32147. }
  32148. }
  32149. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  32150. n = op - 0xB0 + 1;
  32151. if (inFDEF || inELSE) {
  32152. i += n;
  32153. } else {
  32154. for (j = 0; j < n; j++) {
  32155. stack.push(data[i++]);
  32156. }
  32157. }
  32158. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  32159. n = op - 0xB8 + 1;
  32160. if (inFDEF || inELSE) {
  32161. i += n * 2;
  32162. } else {
  32163. for (j = 0; j < n; j++) {
  32164. b = data[i++];
  32165. stack.push((b << 8) | data[i++]);
  32166. }
  32167. }
  32168. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  32169. if (!inFDEF && !inELSE) {
  32170. // collecting inforamtion about which functions are used
  32171. funcId = stack[stack.length - 1];
  32172. ttContext.functionsUsed[funcId] = true;
  32173. if (funcId in ttContext.functionsStackDeltas) {
  32174. stack.length += ttContext.functionsStackDeltas[funcId];
  32175. } else if (funcId in ttContext.functionsDefined &&
  32176. functionsCalled.indexOf(funcId) < 0) {
  32177. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  32178. functionsCalled.push(funcId);
  32179. pc = ttContext.functionsDefined[funcId];
  32180. if (!pc) {
  32181. warn('TT: CALL non-existent function');
  32182. ttContext.hintsValid = false;
  32183. return;
  32184. }
  32185. data = pc.data;
  32186. i = pc.i;
  32187. }
  32188. }
  32189. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  32190. if (inFDEF || inELSE) {
  32191. warn('TT: nested FDEFs not allowed');
  32192. tooComplexToFollowFunctions = true;
  32193. }
  32194. inFDEF = true;
  32195. // collecting inforamtion about which functions are defined
  32196. lastDeff = i;
  32197. funcId = stack.pop();
  32198. ttContext.functionsDefined[funcId] = {data: data, i: i};
  32199. } else if (op === 0x2D) { // ENDF - end of function
  32200. if (inFDEF) {
  32201. inFDEF = false;
  32202. lastEndf = i;
  32203. } else {
  32204. pc = callstack.pop();
  32205. if (!pc) {
  32206. warn('TT: ENDF bad stack');
  32207. ttContext.hintsValid = false;
  32208. return;
  32209. }
  32210. funcId = functionsCalled.pop();
  32211. data = pc.data;
  32212. i = pc.i;
  32213. ttContext.functionsStackDeltas[funcId] =
  32214. stack.length - pc.stackTop;
  32215. }
  32216. } else if (op === 0x89) { // IDEF - instruction definition
  32217. if (inFDEF || inELSE) {
  32218. warn('TT: nested IDEFs not allowed');
  32219. tooComplexToFollowFunctions = true;
  32220. }
  32221. inFDEF = true;
  32222. // recording it as a function to track ENDF
  32223. lastDeff = i;
  32224. } else if (op === 0x58) { // IF
  32225. ++ifLevel;
  32226. } else if (op === 0x1B) { // ELSE
  32227. inELSE = ifLevel;
  32228. } else if (op === 0x59) { // EIF
  32229. if (inELSE === ifLevel) {
  32230. inELSE = 0;
  32231. }
  32232. --ifLevel;
  32233. } else if (op === 0x1C) { // JMPR
  32234. if (!inFDEF && !inELSE) {
  32235. var offset = stack[stack.length - 1];
  32236. // only jumping forward to prevent infinite loop
  32237. if (offset > 0) {
  32238. i += offset - 1;
  32239. }
  32240. }
  32241. }
  32242. // Adjusting stack not extactly, but just enough to get function id
  32243. if (!inFDEF && !inELSE) {
  32244. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  32245. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  32246. if (op >= 0x71 && op <= 0x75) {
  32247. n = stack.pop();
  32248. if (n === n) {
  32249. stackDelta = -n * 2;
  32250. }
  32251. }
  32252. while (stackDelta < 0 && stack.length > 0) {
  32253. stack.pop();
  32254. stackDelta++;
  32255. }
  32256. while (stackDelta > 0) {
  32257. stack.push(NaN); // pushing any number into stack
  32258. stackDelta--;
  32259. }
  32260. }
  32261. }
  32262. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  32263. var content = [data];
  32264. if (i > data.length) {
  32265. content.push(new Uint8Array(i - data.length));
  32266. }
  32267. if (lastDeff > lastEndf) {
  32268. warn('TT: complementing a missing function tail');
  32269. // new function definition started, but not finished
  32270. // complete function by [CLEAR, ENDF]
  32271. content.push(new Uint8Array([0x22, 0x2D]));
  32272. }
  32273. foldTTTable(table, content);
  32274. }
  32275. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  32276. if (ttContext.tooComplexToFollowFunctions) {
  32277. return;
  32278. }
  32279. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  32280. warn('TT: more functions defined than expected');
  32281. ttContext.hintsValid = false;
  32282. return;
  32283. }
  32284. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  32285. if (j > maxFunctionDefs) {
  32286. warn('TT: invalid function id: ' + j);
  32287. ttContext.hintsValid = false;
  32288. return;
  32289. }
  32290. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  32291. warn('TT: undefined function: ' + j);
  32292. ttContext.hintsValid = false;
  32293. return;
  32294. }
  32295. }
  32296. }
  32297. function foldTTTable(table, content) {
  32298. if (content.length > 1) {
  32299. // concatenating the content items
  32300. var newLength = 0;
  32301. var j, jj;
  32302. for (j = 0, jj = content.length; j < jj; j++) {
  32303. newLength += content[j].length;
  32304. }
  32305. newLength = (newLength + 3) & ~3;
  32306. var result = new Uint8Array(newLength);
  32307. var pos = 0;
  32308. for (j = 0, jj = content.length; j < jj; j++) {
  32309. result.set(content[j], pos);
  32310. pos += content[j].length;
  32311. }
  32312. table.data = result;
  32313. table.length = newLength;
  32314. }
  32315. }
  32316. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  32317. var ttContext = {
  32318. functionsDefined: [],
  32319. functionsUsed: [],
  32320. functionsStackDeltas: [],
  32321. tooComplexToFollowFunctions: false,
  32322. hintsValid: true
  32323. };
  32324. if (fpgm) {
  32325. sanitizeTTProgram(fpgm, ttContext);
  32326. }
  32327. if (prep) {
  32328. sanitizeTTProgram(prep, ttContext);
  32329. }
  32330. if (fpgm) {
  32331. checkInvalidFunctions(ttContext, maxFunctionDefs);
  32332. }
  32333. if (cvt && (cvt.length & 1)) {
  32334. var cvtData = new Uint8Array(cvt.length + 1);
  32335. cvtData.set(cvt.data);
  32336. cvt.data = cvtData;
  32337. }
  32338. return ttContext.hintsValid;
  32339. }
  32340. // The following steps modify the original font data, making copy
  32341. font = new Stream(new Uint8Array(font.getBytes()));
  32342. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  32343. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  32344. var header = readOpenTypeHeader(font);
  32345. var numTables = header.numTables;
  32346. var cff, cffFile;
  32347. var tables = Object.create(null);
  32348. tables['OS/2'] = null;
  32349. tables['cmap'] = null;
  32350. tables['head'] = null;
  32351. tables['hhea'] = null;
  32352. tables['hmtx'] = null;
  32353. tables['maxp'] = null;
  32354. tables['name'] = null;
  32355. tables['post'] = null;
  32356. var table;
  32357. for (var i = 0; i < numTables; i++) {
  32358. table = readTableEntry(font);
  32359. if (VALID_TABLES.indexOf(table.tag) < 0) {
  32360. continue; // skipping table if it's not a required or optional table
  32361. }
  32362. if (table.length === 0) {
  32363. continue; // skipping empty tables
  32364. }
  32365. tables[table.tag] = table;
  32366. }
  32367. var isTrueType = !tables['CFF '];
  32368. if (!isTrueType) {
  32369. // OpenType font
  32370. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  32371. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  32372. !tables['post']) {
  32373. // no major tables: throwing everything at CFFFont
  32374. cffFile = new Stream(tables['CFF '].data);
  32375. cff = new CFFFont(cffFile, properties);
  32376. adjustWidths(properties);
  32377. return this.convert(name, cff, properties);
  32378. }
  32379. delete tables['glyf'];
  32380. delete tables['loca'];
  32381. delete tables['fpgm'];
  32382. delete tables['prep'];
  32383. delete tables['cvt '];
  32384. this.isOpenType = true;
  32385. } else {
  32386. if (!tables['loca']) {
  32387. error('Required "loca" table is not found');
  32388. }
  32389. if (!tables['glyf']) {
  32390. warn('Required "glyf" table is not found -- trying to recover.');
  32391. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  32392. tables['glyf'] = {
  32393. tag: 'glyf',
  32394. data: new Uint8Array(0),
  32395. };
  32396. }
  32397. this.isOpenType = false;
  32398. }
  32399. if (!tables['maxp']) {
  32400. error('Required "maxp" table is not found');
  32401. }
  32402. font.pos = (font.start || 0) + tables['maxp'].offset;
  32403. var version = font.getInt32();
  32404. var numGlyphs = font.getUint16();
  32405. var maxFunctionDefs = 0;
  32406. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  32407. // maxZones can be invalid
  32408. font.pos += 8;
  32409. var maxZones = font.getUint16();
  32410. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  32411. tables['maxp'].data[14] = 0;
  32412. tables['maxp'].data[15] = 2;
  32413. }
  32414. font.pos += 4;
  32415. maxFunctionDefs = font.getUint16();
  32416. }
  32417. var dupFirstEntry = false;
  32418. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  32419. properties.toUnicode.get(0) > '\u0000') {
  32420. // oracle's defect (see 3427), duplicating first entry
  32421. dupFirstEntry = true;
  32422. numGlyphs++;
  32423. tables['maxp'].data[4] = numGlyphs >> 8;
  32424. tables['maxp'].data[5] = numGlyphs & 255;
  32425. }
  32426. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  32427. tables['cvt '], maxFunctionDefs);
  32428. if (!hintsValid) {
  32429. delete tables['fpgm'];
  32430. delete tables['prep'];
  32431. delete tables['cvt '];
  32432. }
  32433. // Ensure the hmtx table contains the advance width and
  32434. // sidebearings information for numGlyphs in the maxp table
  32435. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  32436. if (!tables['head']) {
  32437. error('Required "head" table is not found');
  32438. }
  32439. sanitizeHead(tables['head'], numGlyphs,
  32440. isTrueType ? tables['loca'].length : 0);
  32441. var missingGlyphs = Object.create(null);
  32442. if (isTrueType) {
  32443. var isGlyphLocationsLong = int16(tables['head'].data[50],
  32444. tables['head'].data[51]);
  32445. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  32446. numGlyphs, isGlyphLocationsLong,
  32447. hintsValid, dupFirstEntry);
  32448. }
  32449. if (!tables['hhea']) {
  32450. error('Required "hhea" table is not found');
  32451. }
  32452. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  32453. // Sometimes it's 0. That needs to be fixed
  32454. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  32455. tables['hhea'].data[10] = 0xFF;
  32456. tables['hhea'].data[11] = 0xFF;
  32457. }
  32458. // Extract some more font properties from the OpenType head and
  32459. // hhea tables; yMin and descent value are always negative.
  32460. var metricsOverride = {
  32461. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  32462. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  32463. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  32464. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  32465. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  32466. };
  32467. // PDF FontDescriptor metrics lie -- using data from actual font.
  32468. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  32469. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  32470. // The 'post' table has glyphs names.
  32471. if (tables['post']) {
  32472. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  32473. if (!valid) {
  32474. tables['post'] = null;
  32475. }
  32476. }
  32477. var charCodeToGlyphId = [], charCode;
  32478. var toUnicode = properties.toUnicode, widths = properties.widths;
  32479. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  32480. toUnicode.length === 0x10000);
  32481. // Helper function to try to skip mapping of empty glyphs.
  32482. // Note: In some cases, just relying on the glyph data doesn't work,
  32483. // hence we also use a few heuristics to fix various PDF files.
  32484. function hasGlyph(glyphId, charCode, widthCode) {
  32485. if (!missingGlyphs[glyphId]) {
  32486. return true;
  32487. }
  32488. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  32489. return true;
  32490. }
  32491. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  32492. return true;
  32493. }
  32494. return false;
  32495. }
  32496. if (properties.type === 'CIDFontType2') {
  32497. var cidToGidMap = properties.cidToGidMap || [];
  32498. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  32499. properties.cMap.forEach(function(charCode, cid) {
  32500. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  32501. var glyphId = -1;
  32502. if (isCidToGidMapEmpty) {
  32503. glyphId = cid;
  32504. } else if (cidToGidMap[cid] !== undefined) {
  32505. glyphId = cidToGidMap[cid];
  32506. }
  32507. if (glyphId >= 0 && glyphId < numGlyphs &&
  32508. hasGlyph(glyphId, charCode, cid)) {
  32509. charCodeToGlyphId[charCode] = glyphId;
  32510. }
  32511. });
  32512. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  32513. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  32514. // if the font has a `CIDToGIDMap` which has already mapped the first
  32515. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  32516. charCodeToGlyphId[0] = numGlyphs - 1;
  32517. }
  32518. } else {
  32519. // Most of the following logic in this code branch is based on the
  32520. // 9.6.6.4 of the PDF spec.
  32521. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont,
  32522. properties.hasEncoding);
  32523. var cmapPlatformId = cmapTable.platformId;
  32524. var cmapEncodingId = cmapTable.encodingId;
  32525. var cmapMappings = cmapTable.mappings;
  32526. var cmapMappingsLength = cmapMappings.length;
  32527. // The spec seems to imply that if the font is symbolic the encoding
  32528. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  32529. // where the the font is symbolic and it has an encoding.
  32530. if (properties.hasEncoding &&
  32531. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  32532. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  32533. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  32534. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  32535. // When no preferred cmap table was found and |baseEncodingName| is
  32536. // one of the predefined encodings, we seem to obtain a better
  32537. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  32538. // TODO: Note that this is a hack which should be removed as soon as
  32539. // we have proper support for more exotic cmap tables.
  32540. var baseEncoding = [];
  32541. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  32542. properties.baseEncodingName === 'WinAnsiEncoding') {
  32543. baseEncoding = getEncoding(properties.baseEncodingName);
  32544. }
  32545. var glyphsUnicodeMap = getGlyphsUnicode();
  32546. for (charCode = 0; charCode < 256; charCode++) {
  32547. var glyphName, standardGlyphName;
  32548. if (this.differences && charCode in this.differences) {
  32549. glyphName = this.differences[charCode];
  32550. } else if (charCode in baseEncoding &&
  32551. baseEncoding[charCode] !== '') {
  32552. glyphName = baseEncoding[charCode];
  32553. } else {
  32554. glyphName = StandardEncoding[charCode];
  32555. }
  32556. if (!glyphName) {
  32557. continue;
  32558. }
  32559. // Ensure that non-standard glyph names are resolved to valid ones.
  32560. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  32561. var unicodeOrCharCode, isUnicode = false;
  32562. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  32563. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  32564. isUnicode = true;
  32565. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  32566. // TODO: the encoding needs to be updated with mac os table.
  32567. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  32568. }
  32569. var found = false;
  32570. for (i = 0; i < cmapMappingsLength; ++i) {
  32571. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  32572. continue;
  32573. }
  32574. var code = isUnicode ? charCode : unicodeOrCharCode;
  32575. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  32576. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  32577. found = true;
  32578. break;
  32579. }
  32580. }
  32581. if (!found && properties.glyphNames) {
  32582. // Try to map using the post table.
  32583. var glyphId = properties.glyphNames.indexOf(glyphName);
  32584. // The post table ought to use the same kind of glyph names as the
  32585. // `differences` array, but check the standard ones as a fallback.
  32586. if (glyphId === -1 && standardGlyphName !== glyphName) {
  32587. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  32588. }
  32589. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  32590. charCodeToGlyphId[charCode] = glyphId;
  32591. found = true;
  32592. }
  32593. }
  32594. if (!found) {
  32595. charCodeToGlyphId[charCode] = 0; // notdef
  32596. }
  32597. }
  32598. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  32599. // Default Unicode semantics, use the charcodes as is.
  32600. for (i = 0; i < cmapMappingsLength; ++i) {
  32601. charCodeToGlyphId[cmapMappings[i].charCode] =
  32602. cmapMappings[i].glyphId;
  32603. }
  32604. } else {
  32605. // For (3, 0) cmap tables:
  32606. // The charcode key being stored in charCodeToGlyphId is the lower
  32607. // byte of the two-byte charcodes of the cmap table since according to
  32608. // the spec: 'each byte from the string shall be prepended with the
  32609. // high byte of the range [of charcodes in the cmap table], to form
  32610. // a two-byte character, which shall be used to select the
  32611. // associated glyph description from the subtable'.
  32612. //
  32613. // For (1, 0) cmap tables:
  32614. // 'single bytes from the string shall be used to look up the
  32615. // associated glyph descriptions from the subtable'. This means
  32616. // charcodes in the cmap will be single bytes, so no-op since
  32617. // glyph.charCode & 0xFF === glyph.charCode
  32618. for (i = 0; i < cmapMappingsLength; ++i) {
  32619. charCode = cmapMappings[i].charCode & 0xFF;
  32620. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  32621. }
  32622. }
  32623. }
  32624. if (charCodeToGlyphId.length === 0) {
  32625. // defines at least one glyph
  32626. charCodeToGlyphId[0] = 0;
  32627. }
  32628. // Converting glyphs and ids into font's cmap table
  32629. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  32630. this.toFontChar = newMapping.toFontChar;
  32631. tables['cmap'] = {
  32632. tag: 'cmap',
  32633. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  32634. };
  32635. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  32636. tables['OS/2'] = {
  32637. tag: 'OS/2',
  32638. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  32639. metricsOverride)
  32640. };
  32641. }
  32642. // Rewrite the 'post' table if needed
  32643. if (!tables['post']) {
  32644. tables['post'] = {
  32645. tag: 'post',
  32646. data: createPostTable(properties)
  32647. };
  32648. }
  32649. if (!isTrueType) {
  32650. try {
  32651. // Trying to repair CFF file
  32652. cffFile = new Stream(tables['CFF '].data);
  32653. var parser = new CFFParser(cffFile, properties,
  32654. SEAC_ANALYSIS_ENABLED);
  32655. cff = parser.parse();
  32656. var compiler = new CFFCompiler(cff);
  32657. tables['CFF '].data = compiler.compile();
  32658. } catch (e) {
  32659. warn('Failed to compile font ' + properties.loadedName);
  32660. }
  32661. }
  32662. // Re-creating 'name' table
  32663. if (!tables['name']) {
  32664. tables['name'] = {
  32665. tag: 'name',
  32666. data: createNameTable(this.name)
  32667. };
  32668. } else {
  32669. // ... using existing 'name' table as prototype
  32670. var namePrototype = readNameTable(tables['name']);
  32671. tables['name'].data = createNameTable(name, namePrototype);
  32672. }
  32673. var builder = new OpenTypeFileBuilder(header.version);
  32674. for (var tableTag in tables) {
  32675. builder.addTable(tableTag, tables[tableTag].data);
  32676. }
  32677. return builder.toArray();
  32678. },
  32679. convert: function Font_convert(fontName, font, properties) {
  32680. // TODO: Check the charstring widths to determine this.
  32681. properties.fixedPitch = false;
  32682. if (properties.builtInEncoding) {
  32683. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  32684. // data, attempt to use the `builtInEncoding` to improve text selection.
  32685. adjustToUnicode(properties, properties.builtInEncoding);
  32686. }
  32687. var mapping = font.getGlyphMapping(properties);
  32688. var newMapping = adjustMapping(mapping, properties);
  32689. this.toFontChar = newMapping.toFontChar;
  32690. var numGlyphs = font.numGlyphs;
  32691. function getCharCodes(charCodeToGlyphId, glyphId) {
  32692. var charCodes = null;
  32693. for (var charCode in charCodeToGlyphId) {
  32694. if (glyphId === charCodeToGlyphId[charCode]) {
  32695. if (!charCodes) {
  32696. charCodes = [];
  32697. }
  32698. charCodes.push(charCode | 0);
  32699. }
  32700. }
  32701. return charCodes;
  32702. }
  32703. function createCharCode(charCodeToGlyphId, glyphId) {
  32704. for (var charCode in charCodeToGlyphId) {
  32705. if (glyphId === charCodeToGlyphId[charCode]) {
  32706. return charCode | 0;
  32707. }
  32708. }
  32709. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  32710. glyphId;
  32711. return newMapping.nextAvailableFontCharCode++;
  32712. }
  32713. var seacs = font.seacs;
  32714. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  32715. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  32716. var charset = font.getCharset();
  32717. var seacMap = Object.create(null);
  32718. for (var glyphId in seacs) {
  32719. glyphId |= 0;
  32720. var seac = seacs[glyphId];
  32721. var baseGlyphName = StandardEncoding[seac[2]];
  32722. var accentGlyphName = StandardEncoding[seac[3]];
  32723. var baseGlyphId = charset.indexOf(baseGlyphName);
  32724. var accentGlyphId = charset.indexOf(accentGlyphName);
  32725. if (baseGlyphId < 0 || accentGlyphId < 0) {
  32726. continue;
  32727. }
  32728. var accentOffset = {
  32729. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  32730. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  32731. };
  32732. var charCodes = getCharCodes(mapping, glyphId);
  32733. if (!charCodes) {
  32734. // There's no point in mapping it if the char code was never mapped
  32735. // to begin with.
  32736. continue;
  32737. }
  32738. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  32739. var charCode = charCodes[i];
  32740. // Find a fontCharCode that maps to the base and accent glyphs.
  32741. // If one doesn't exists, create it.
  32742. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  32743. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  32744. baseGlyphId);
  32745. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  32746. accentGlyphId);
  32747. seacMap[charCode] = {
  32748. baseFontCharCode: baseFontCharCode,
  32749. accentFontCharCode: accentFontCharCode,
  32750. accentOffset: accentOffset
  32751. };
  32752. }
  32753. }
  32754. properties.seacMap = seacMap;
  32755. }
  32756. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  32757. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  32758. // PostScript Font Program
  32759. builder.addTable('CFF ', font.data);
  32760. // OS/2 and Windows Specific metrics
  32761. builder.addTable('OS/2', createOS2Table(properties,
  32762. newMapping.charCodeToGlyphId));
  32763. // Character to glyphs mapping
  32764. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  32765. numGlyphs));
  32766. // Font header
  32767. builder.addTable('head',
  32768. '\x00\x01\x00\x00' + // Version number
  32769. '\x00\x00\x10\x00' + // fontRevision
  32770. '\x00\x00\x00\x00' + // checksumAdjustement
  32771. '\x5F\x0F\x3C\xF5' + // magicNumber
  32772. '\x00\x00' + // Flags
  32773. safeString16(unitsPerEm) + // unitsPerEM
  32774. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  32775. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  32776. '\x00\x00' + // xMin
  32777. safeString16(properties.descent) + // yMin
  32778. '\x0F\xFF' + // xMax
  32779. safeString16(properties.ascent) + // yMax
  32780. string16(properties.italicAngle ? 2 : 0) + // macStyle
  32781. '\x00\x11' + // lowestRecPPEM
  32782. '\x00\x00' + // fontDirectionHint
  32783. '\x00\x00' + // indexToLocFormat
  32784. '\x00\x00'); // glyphDataFormat
  32785. // Horizontal header
  32786. builder.addTable('hhea',
  32787. '\x00\x01\x00\x00' + // Version number
  32788. safeString16(properties.ascent) + // Typographic Ascent
  32789. safeString16(properties.descent) + // Typographic Descent
  32790. '\x00\x00' + // Line Gap
  32791. '\xFF\xFF' + // advanceWidthMax
  32792. '\x00\x00' + // minLeftSidebearing
  32793. '\x00\x00' + // minRightSidebearing
  32794. '\x00\x00' + // xMaxExtent
  32795. safeString16(properties.capHeight) + // caretSlopeRise
  32796. safeString16(Math.tan(properties.italicAngle) *
  32797. properties.xHeight) + // caretSlopeRun
  32798. '\x00\x00' + // caretOffset
  32799. '\x00\x00' + // -reserved-
  32800. '\x00\x00' + // -reserved-
  32801. '\x00\x00' + // -reserved-
  32802. '\x00\x00' + // -reserved-
  32803. '\x00\x00' + // metricDataFormat
  32804. string16(numGlyphs)); // Number of HMetrics
  32805. // Horizontal metrics
  32806. builder.addTable('hmtx', (function fontFieldsHmtx() {
  32807. var charstrings = font.charstrings;
  32808. var cffWidths = font.cff ? font.cff.widths : null;
  32809. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  32810. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  32811. var width = 0;
  32812. if (charstrings) {
  32813. var charstring = charstrings[i - 1];
  32814. width = 'width' in charstring ? charstring.width : 0;
  32815. } else if (cffWidths) {
  32816. width = Math.ceil(cffWidths[i] || 0);
  32817. }
  32818. hmtx += string16(width) + string16(0);
  32819. }
  32820. return hmtx;
  32821. })());
  32822. // Maximum profile
  32823. builder.addTable('maxp',
  32824. '\x00\x00\x50\x00' + // Version number
  32825. string16(numGlyphs)); // Num of glyphs
  32826. // Naming tables
  32827. builder.addTable('name', createNameTable(fontName));
  32828. // PostScript information
  32829. builder.addTable('post', createPostTable(properties));
  32830. return builder.toArray();
  32831. },
  32832. get spaceWidth() {
  32833. if ('_shadowWidth' in this) {
  32834. return this._shadowWidth;
  32835. }
  32836. // trying to estimate space character width
  32837. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  32838. var width;
  32839. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  32840. var glyphName = possibleSpaceReplacements[i];
  32841. // if possible, getting width by glyph name
  32842. if (glyphName in this.widths) {
  32843. width = this.widths[glyphName];
  32844. break;
  32845. }
  32846. var glyphsUnicodeMap = getGlyphsUnicode();
  32847. var glyphUnicode = glyphsUnicodeMap[glyphName];
  32848. // finding the charcode via unicodeToCID map
  32849. var charcode = 0;
  32850. if (this.composite) {
  32851. if (this.cMap.contains(glyphUnicode)) {
  32852. charcode = this.cMap.lookup(glyphUnicode);
  32853. }
  32854. }
  32855. // ... via toUnicode map
  32856. if (!charcode && this.toUnicode) {
  32857. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  32858. }
  32859. // setting it to unicode if negative or undefined
  32860. if (charcode <= 0) {
  32861. charcode = glyphUnicode;
  32862. }
  32863. // trying to get width via charcode
  32864. width = this.widths[charcode];
  32865. if (width) {
  32866. break; // the non-zero width found
  32867. }
  32868. }
  32869. width = width || this.defaultWidth;
  32870. // Do not shadow the property here. See discussion:
  32871. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  32872. this._shadowWidth = width;
  32873. return width;
  32874. },
  32875. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  32876. var fontCharCode, width, operatorListId;
  32877. var widthCode = charcode;
  32878. if (this.cMap && this.cMap.contains(charcode)) {
  32879. widthCode = this.cMap.lookup(charcode);
  32880. }
  32881. width = this.widths[widthCode];
  32882. width = isNum(width) ? width : this.defaultWidth;
  32883. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  32884. var unicode = this.toUnicode.get(charcode) || charcode;
  32885. if (typeof unicode === 'number') {
  32886. unicode = String.fromCharCode(unicode);
  32887. }
  32888. var isInFont = charcode in this.toFontChar;
  32889. // First try the toFontChar map, if it's not there then try falling
  32890. // back to the char code.
  32891. fontCharCode = this.toFontChar[charcode] || charcode;
  32892. if (this.missingFile) {
  32893. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  32894. }
  32895. if (this.isType3Font) {
  32896. // Font char code in this case is actually a glyph name.
  32897. operatorListId = fontCharCode;
  32898. }
  32899. var accent = null;
  32900. if (this.seacMap && this.seacMap[charcode]) {
  32901. isInFont = true;
  32902. var seac = this.seacMap[charcode];
  32903. fontCharCode = seac.baseFontCharCode;
  32904. accent = {
  32905. fontChar: String.fromCharCode(seac.accentFontCharCode),
  32906. offset: seac.accentOffset
  32907. };
  32908. }
  32909. var fontChar = String.fromCharCode(fontCharCode);
  32910. var glyph = this.glyphCache[charcode];
  32911. if (!glyph ||
  32912. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  32913. operatorListId, isSpace, isInFont)) {
  32914. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  32915. operatorListId, isSpace, isInFont);
  32916. this.glyphCache[charcode] = glyph;
  32917. }
  32918. return glyph;
  32919. },
  32920. charsToGlyphs: function Font_charsToGlyphs(chars) {
  32921. var charsCache = this.charsCache;
  32922. var glyphs, glyph, charcode;
  32923. // if we translated this string before, just grab it from the cache
  32924. if (charsCache) {
  32925. glyphs = charsCache[chars];
  32926. if (glyphs) {
  32927. return glyphs;
  32928. }
  32929. }
  32930. // lazily create the translation cache
  32931. if (!charsCache) {
  32932. charsCache = this.charsCache = Object.create(null);
  32933. }
  32934. glyphs = [];
  32935. var charsCacheKey = chars;
  32936. var i = 0, ii;
  32937. if (this.cMap) {
  32938. // composite fonts have multi-byte strings convert the string from
  32939. // single-byte to multi-byte
  32940. var c = Object.create(null);
  32941. while (i < chars.length) {
  32942. this.cMap.readCharCode(chars, i, c);
  32943. charcode = c.charcode;
  32944. var length = c.length;
  32945. i += length;
  32946. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  32947. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  32948. glyph = this.charToGlyph(charcode, isSpace);
  32949. glyphs.push(glyph);
  32950. }
  32951. } else {
  32952. for (i = 0, ii = chars.length; i < ii; ++i) {
  32953. charcode = chars.charCodeAt(i);
  32954. glyph = this.charToGlyph(charcode, charcode === 0x20);
  32955. glyphs.push(glyph);
  32956. }
  32957. }
  32958. // Enter the translated string into the cache
  32959. return (charsCache[charsCacheKey] = glyphs);
  32960. }
  32961. };
  32962. return Font;
  32963. })();
  32964. var ErrorFont = (function ErrorFontClosure() {
  32965. function ErrorFont(error) {
  32966. this.error = error;
  32967. this.loadedName = 'g_font_error';
  32968. this.loading = false;
  32969. }
  32970. ErrorFont.prototype = {
  32971. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  32972. return [];
  32973. },
  32974. exportData: function ErrorFont_exportData() {
  32975. return {error: this.error};
  32976. }
  32977. };
  32978. return ErrorFont;
  32979. })();
  32980. /**
  32981. * Shared logic for building a char code to glyph id mapping for Type1 and
  32982. * simple CFF fonts. See section 9.6.6.2 of the spec.
  32983. * @param {Object} properties Font properties object.
  32984. * @param {Object} builtInEncoding The encoding contained within the actual font
  32985. * data.
  32986. * @param {Array} glyphNames Array of glyph names where the index is the
  32987. * glyph ID.
  32988. * @returns {Object} A char code to glyph ID map.
  32989. */
  32990. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  32991. var charCodeToGlyphId = Object.create(null);
  32992. var glyphId, charCode, baseEncoding;
  32993. if (properties.baseEncodingName) {
  32994. // If a valid base encoding name was used, the mapping is initialized with
  32995. // that.
  32996. baseEncoding = getEncoding(properties.baseEncodingName);
  32997. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  32998. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  32999. if (glyphId >= 0) {
  33000. charCodeToGlyphId[charCode] = glyphId;
  33001. } else {
  33002. charCodeToGlyphId[charCode] = 0; // notdef
  33003. }
  33004. }
  33005. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  33006. // For a symbolic font the encoding should be the fonts built-in
  33007. // encoding.
  33008. for (charCode in builtInEncoding) {
  33009. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  33010. }
  33011. } else {
  33012. // For non-symbolic fonts that don't have a base encoding the standard
  33013. // encoding should be used.
  33014. baseEncoding = StandardEncoding;
  33015. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  33016. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  33017. if (glyphId >= 0) {
  33018. charCodeToGlyphId[charCode] = glyphId;
  33019. } else {
  33020. charCodeToGlyphId[charCode] = 0; // notdef
  33021. }
  33022. }
  33023. }
  33024. // Lastly, merge in the differences.
  33025. var differences = properties.differences, glyphsUnicodeMap;
  33026. if (differences) {
  33027. for (charCode in differences) {
  33028. var glyphName = differences[charCode];
  33029. glyphId = glyphNames.indexOf(glyphName);
  33030. if (glyphId === -1) {
  33031. if (!glyphsUnicodeMap) {
  33032. glyphsUnicodeMap = getGlyphsUnicode();
  33033. }
  33034. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  33035. if (standardGlyphName !== glyphName) {
  33036. glyphId = glyphNames.indexOf(standardGlyphName);
  33037. }
  33038. }
  33039. if (glyphId >= 0) {
  33040. charCodeToGlyphId[charCode] = glyphId;
  33041. } else {
  33042. charCodeToGlyphId[charCode] = 0; // notdef
  33043. }
  33044. }
  33045. }
  33046. return charCodeToGlyphId;
  33047. }
  33048. // Type1Font is also a CIDFontType0.
  33049. var Type1Font = (function Type1FontClosure() {
  33050. function findBlock(streamBytes, signature, startIndex) {
  33051. var streamBytesLength = streamBytes.length;
  33052. var signatureLength = signature.length;
  33053. var scanLength = streamBytesLength - signatureLength;
  33054. var i = startIndex, j, found = false;
  33055. while (i < scanLength) {
  33056. j = 0;
  33057. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  33058. j++;
  33059. }
  33060. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  33061. i += j;
  33062. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  33063. i++;
  33064. }
  33065. found = true;
  33066. break;
  33067. }
  33068. i++;
  33069. }
  33070. return {
  33071. found: found,
  33072. length: i,
  33073. };
  33074. }
  33075. function getHeaderBlock(stream, suggestedLength) {
  33076. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  33077. var streamStartPos = stream.pos; // Save the initial stream position.
  33078. var headerBytes, headerBytesLength, block;
  33079. try {
  33080. headerBytes = stream.getBytes(suggestedLength);
  33081. headerBytesLength = headerBytes.length;
  33082. } catch (ex) {
  33083. if (ex instanceof MissingDataException) {
  33084. throw ex;
  33085. }
  33086. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  33087. // cannot hold the result of `getBytes`, and fallback to simply checking
  33088. // the entire stream (fixes issue3928.pdf).
  33089. }
  33090. if (headerBytesLength === suggestedLength) {
  33091. // Most of the time `suggestedLength` is correct, so to speed things up we
  33092. // initially only check the last few bytes to see if the header was found.
  33093. // Otherwise we (potentially) check the entire stream to prevent errors in
  33094. // `Type1Parser` (fixes issue5686.pdf).
  33095. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  33096. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  33097. if (block.found && block.length === suggestedLength) {
  33098. return {
  33099. stream: new Stream(headerBytes),
  33100. length: suggestedLength,
  33101. };
  33102. }
  33103. }
  33104. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  33105. stream.pos = streamStartPos; // Reset the stream position.
  33106. var SCAN_BLOCK_LENGTH = 2048;
  33107. var actualLength;
  33108. while (true) {
  33109. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  33110. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  33111. if (block.length === 0) {
  33112. break;
  33113. }
  33114. stream.pos += block.length; // Update the stream position.
  33115. if (block.found) {
  33116. actualLength = stream.pos - streamStartPos;
  33117. break;
  33118. }
  33119. }
  33120. stream.pos = streamStartPos; // Reset the stream position.
  33121. if (actualLength) {
  33122. return {
  33123. stream: new Stream(stream.getBytes(actualLength)),
  33124. length: actualLength,
  33125. };
  33126. }
  33127. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  33128. return {
  33129. stream: new Stream(stream.getBytes(suggestedLength)),
  33130. length: suggestedLength,
  33131. };
  33132. }
  33133. function getEexecBlock(stream, suggestedLength) {
  33134. // We should ideally parse the eexec block to ensure that `suggestedLength`
  33135. // is correct, so we don't truncate the block data if it's too small.
  33136. // However, this would also require checking if the fixed-content portion
  33137. // exists (using the 'Length3' property), and ensuring that it's valid.
  33138. //
  33139. // Given that `suggestedLength` almost always is correct, all the validation
  33140. // would require a great deal of unnecessary parsing for most fonts.
  33141. // To save time, we always fetch the entire stream instead, which also avoid
  33142. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  33143. //
  33144. // NOTE: This means that the function can include the fixed-content portion
  33145. // in the returned eexec block. In practice this does *not* seem to matter,
  33146. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  33147. var eexecBytes = stream.getBytes();
  33148. return {
  33149. stream: new Stream(eexecBytes),
  33150. length: eexecBytes.length,
  33151. };
  33152. }
  33153. function Type1Font(name, file, properties) {
  33154. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  33155. // Also, length1 and length2 might be off by 6 bytes as well.
  33156. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  33157. var PFB_HEADER_SIZE = 6;
  33158. var headerBlockLength = properties.length1;
  33159. var eexecBlockLength = properties.length2;
  33160. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  33161. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  33162. if (pfbHeaderPresent) {
  33163. file.skip(PFB_HEADER_SIZE);
  33164. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  33165. (pfbHeader[3] << 8) | pfbHeader[2];
  33166. }
  33167. // Get the data block containing glyphs and subrs information
  33168. var headerBlock = getHeaderBlock(file, headerBlockLength);
  33169. headerBlockLength = headerBlock.length;
  33170. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  33171. SEAC_ANALYSIS_ENABLED);
  33172. headerBlockParser.extractFontHeader(properties);
  33173. if (pfbHeaderPresent) {
  33174. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  33175. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  33176. (pfbHeader[3] << 8) | pfbHeader[2];
  33177. }
  33178. // Decrypt the data blocks and retrieve it's content
  33179. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  33180. eexecBlockLength = eexecBlock.length;
  33181. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  33182. SEAC_ANALYSIS_ENABLED);
  33183. var data = eexecBlockParser.extractFontProgram();
  33184. for (var info in data.properties) {
  33185. properties[info] = data.properties[info];
  33186. }
  33187. var charstrings = data.charstrings;
  33188. var type2Charstrings = this.getType2Charstrings(charstrings);
  33189. var subrs = this.getType2Subrs(data.subrs);
  33190. this.charstrings = charstrings;
  33191. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  33192. subrs, properties);
  33193. this.seacs = this.getSeacs(data.charstrings);
  33194. }
  33195. Type1Font.prototype = {
  33196. get numGlyphs() {
  33197. return this.charstrings.length + 1;
  33198. },
  33199. getCharset: function Type1Font_getCharset() {
  33200. var charset = ['.notdef'];
  33201. var charstrings = this.charstrings;
  33202. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  33203. charset.push(charstrings[glyphId].glyphName);
  33204. }
  33205. return charset;
  33206. },
  33207. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  33208. var charstrings = this.charstrings;
  33209. var glyphNames = ['.notdef'], glyphId;
  33210. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  33211. glyphNames.push(charstrings[glyphId].glyphName);
  33212. }
  33213. var encoding = properties.builtInEncoding;
  33214. if (encoding) {
  33215. var builtInEncoding = Object.create(null);
  33216. for (var charCode in encoding) {
  33217. glyphId = glyphNames.indexOf(encoding[charCode]);
  33218. if (glyphId >= 0) {
  33219. builtInEncoding[charCode] = glyphId;
  33220. }
  33221. }
  33222. }
  33223. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  33224. },
  33225. getSeacs: function Type1Font_getSeacs(charstrings) {
  33226. var i, ii;
  33227. var seacMap = [];
  33228. for (i = 0, ii = charstrings.length; i < ii; i++) {
  33229. var charstring = charstrings[i];
  33230. if (charstring.seac) {
  33231. // Offset by 1 for .notdef
  33232. seacMap[i + 1] = charstring.seac;
  33233. }
  33234. }
  33235. return seacMap;
  33236. },
  33237. getType2Charstrings: function Type1Font_getType2Charstrings(
  33238. type1Charstrings) {
  33239. var type2Charstrings = [];
  33240. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  33241. type2Charstrings.push(type1Charstrings[i].charstring);
  33242. }
  33243. return type2Charstrings;
  33244. },
  33245. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  33246. var bias = 0;
  33247. var count = type1Subrs.length;
  33248. if (count < 1133) {
  33249. bias = 107;
  33250. } else if (count < 33769) {
  33251. bias = 1131;
  33252. } else {
  33253. bias = 32768;
  33254. }
  33255. // Add a bunch of empty subrs to deal with the Type2 bias
  33256. var type2Subrs = [];
  33257. var i;
  33258. for (i = 0; i < bias; i++) {
  33259. type2Subrs.push([0x0B]);
  33260. }
  33261. for (i = 0; i < count; i++) {
  33262. type2Subrs.push(type1Subrs[i]);
  33263. }
  33264. return type2Subrs;
  33265. },
  33266. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  33267. properties) {
  33268. var cff = new CFF();
  33269. cff.header = new CFFHeader(1, 0, 4, 4);
  33270. cff.names = [name];
  33271. var topDict = new CFFTopDict();
  33272. // CFF strings IDs 0...390 are predefined names, so refering
  33273. // to entries in our own String INDEX starts at SID 391.
  33274. topDict.setByName('version', 391);
  33275. topDict.setByName('Notice', 392);
  33276. topDict.setByName('FullName', 393);
  33277. topDict.setByName('FamilyName', 394);
  33278. topDict.setByName('Weight', 395);
  33279. topDict.setByName('Encoding', null); // placeholder
  33280. topDict.setByName('FontMatrix', properties.fontMatrix);
  33281. topDict.setByName('FontBBox', properties.bbox);
  33282. topDict.setByName('charset', null); // placeholder
  33283. topDict.setByName('CharStrings', null); // placeholder
  33284. topDict.setByName('Private', null); // placeholder
  33285. cff.topDict = topDict;
  33286. var strings = new CFFStrings();
  33287. strings.add('Version 0.11'); // Version
  33288. strings.add('See original notice'); // Notice
  33289. strings.add(name); // FullName
  33290. strings.add(name); // FamilyName
  33291. strings.add('Medium'); // Weight
  33292. cff.strings = strings;
  33293. cff.globalSubrIndex = new CFFIndex();
  33294. var count = glyphs.length;
  33295. var charsetArray = [0];
  33296. var i, ii;
  33297. for (i = 0; i < count; i++) {
  33298. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  33299. // TODO: Insert the string and correctly map it. Previously it was
  33300. // thought mapping names that aren't in the standard strings to .notdef
  33301. // was fine, however in issue818 when mapping them all to .notdef the
  33302. // adieresis glyph no longer worked.
  33303. if (index === -1) {
  33304. index = 0;
  33305. }
  33306. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  33307. }
  33308. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  33309. var charStringsIndex = new CFFIndex();
  33310. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  33311. for (i = 0; i < count; i++) {
  33312. var glyph = glyphs[i];
  33313. // If the CharString outline is empty, replace it with .notdef to
  33314. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  33315. if (glyph.length === 0) {
  33316. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  33317. continue;
  33318. }
  33319. charStringsIndex.add(glyph);
  33320. }
  33321. cff.charStrings = charStringsIndex;
  33322. var privateDict = new CFFPrivateDict();
  33323. privateDict.setByName('Subrs', null); // placeholder
  33324. var fields = [
  33325. 'BlueValues',
  33326. 'OtherBlues',
  33327. 'FamilyBlues',
  33328. 'FamilyOtherBlues',
  33329. 'StemSnapH',
  33330. 'StemSnapV',
  33331. 'BlueShift',
  33332. 'BlueFuzz',
  33333. 'BlueScale',
  33334. 'LanguageGroup',
  33335. 'ExpansionFactor',
  33336. 'ForceBold',
  33337. 'StdHW',
  33338. 'StdVW'
  33339. ];
  33340. for (i = 0, ii = fields.length; i < ii; i++) {
  33341. var field = fields[i];
  33342. if (!(field in properties.privateData)) {
  33343. continue;
  33344. }
  33345. var value = properties.privateData[field];
  33346. if (isArray(value)) {
  33347. // All of the private dictionary array data in CFF must be stored as
  33348. // "delta-encoded" numbers.
  33349. for (var j = value.length - 1; j > 0; j--) {
  33350. value[j] -= value[j - 1]; // ... difference from previous value
  33351. }
  33352. }
  33353. privateDict.setByName(field, value);
  33354. }
  33355. cff.topDict.privateDict = privateDict;
  33356. var subrIndex = new CFFIndex();
  33357. for (i = 0, ii = subrs.length; i < ii; i++) {
  33358. subrIndex.add(subrs[i]);
  33359. }
  33360. privateDict.subrsIndex = subrIndex;
  33361. var compiler = new CFFCompiler(cff);
  33362. return compiler.compile();
  33363. }
  33364. };
  33365. return Type1Font;
  33366. })();
  33367. var CFFFont = (function CFFFontClosure() {
  33368. function CFFFont(file, properties) {
  33369. this.properties = properties;
  33370. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  33371. this.cff = parser.parse();
  33372. var compiler = new CFFCompiler(this.cff);
  33373. this.seacs = this.cff.seacs;
  33374. try {
  33375. this.data = compiler.compile();
  33376. } catch (e) {
  33377. warn('Failed to compile font ' + properties.loadedName);
  33378. // There may have just been an issue with the compiler, set the data
  33379. // anyway and hope the font loaded.
  33380. this.data = file;
  33381. }
  33382. }
  33383. CFFFont.prototype = {
  33384. get numGlyphs() {
  33385. return this.cff.charStrings.count;
  33386. },
  33387. getCharset: function CFFFont_getCharset() {
  33388. return this.cff.charset.charset;
  33389. },
  33390. getGlyphMapping: function CFFFont_getGlyphMapping() {
  33391. var cff = this.cff;
  33392. var properties = this.properties;
  33393. var charsets = cff.charset.charset;
  33394. var charCodeToGlyphId;
  33395. var glyphId;
  33396. if (properties.composite) {
  33397. charCodeToGlyphId = Object.create(null);
  33398. if (cff.isCIDFont) {
  33399. // If the font is actually a CID font then we should use the charset
  33400. // to map CIDs to GIDs.
  33401. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  33402. var cid = charsets[glyphId];
  33403. var charCode = properties.cMap.charCodeOf(cid);
  33404. charCodeToGlyphId[charCode] = glyphId;
  33405. }
  33406. } else {
  33407. // If it is NOT actually a CID font then CIDs should be mapped
  33408. // directly to GIDs.
  33409. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  33410. charCodeToGlyphId[glyphId] = glyphId;
  33411. }
  33412. }
  33413. return charCodeToGlyphId;
  33414. }
  33415. var encoding = cff.encoding ? cff.encoding.encoding : null;
  33416. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  33417. return charCodeToGlyphId;
  33418. }
  33419. };
  33420. return CFFFont;
  33421. })();
  33422. // Workaround for seac on Windows.
  33423. (function checkSeacSupport() {
  33424. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  33425. SEAC_ANALYSIS_ENABLED = true;
  33426. }
  33427. })();
  33428. // Workaround for Private Use Area characters in Chrome on Windows
  33429. // http://code.google.com/p/chromium/issues/detail?id=122465
  33430. // https://github.com/mozilla/pdf.js/issues/1689
  33431. (function checkChromeWindows() {
  33432. if (typeof navigator !== 'undefined' &&
  33433. /Windows.*Chrome/.test(navigator.userAgent)) {
  33434. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  33435. }
  33436. })();
  33437. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  33438. exports.ErrorFont = ErrorFont;
  33439. exports.Font = Font;
  33440. exports.FontFlags = FontFlags;
  33441. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  33442. exports.ToUnicodeMap = ToUnicodeMap;
  33443. exports.getFontType = getFontType;
  33444. }));
  33445. (function (root, factory) {
  33446. {
  33447. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  33448. root.pdfjsCoreParser);
  33449. }
  33450. }(this, function (exports, sharedUtil, coreParser) {
  33451. var error = sharedUtil.error;
  33452. var isSpace = sharedUtil.isSpace;
  33453. var EOF = coreParser.EOF;
  33454. var PostScriptParser = (function PostScriptParserClosure() {
  33455. function PostScriptParser(lexer) {
  33456. this.lexer = lexer;
  33457. this.operators = [];
  33458. this.token = null;
  33459. this.prev = null;
  33460. }
  33461. PostScriptParser.prototype = {
  33462. nextToken: function PostScriptParser_nextToken() {
  33463. this.prev = this.token;
  33464. this.token = this.lexer.getToken();
  33465. },
  33466. accept: function PostScriptParser_accept(type) {
  33467. if (this.token.type === type) {
  33468. this.nextToken();
  33469. return true;
  33470. }
  33471. return false;
  33472. },
  33473. expect: function PostScriptParser_expect(type) {
  33474. if (this.accept(type)) {
  33475. return true;
  33476. }
  33477. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  33478. type + '.');
  33479. },
  33480. parse: function PostScriptParser_parse() {
  33481. this.nextToken();
  33482. this.expect(PostScriptTokenTypes.LBRACE);
  33483. this.parseBlock();
  33484. this.expect(PostScriptTokenTypes.RBRACE);
  33485. return this.operators;
  33486. },
  33487. parseBlock: function PostScriptParser_parseBlock() {
  33488. while (true) {
  33489. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  33490. this.operators.push(this.prev.value);
  33491. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  33492. this.operators.push(this.prev.value);
  33493. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33494. this.parseCondition();
  33495. } else {
  33496. return;
  33497. }
  33498. }
  33499. },
  33500. parseCondition: function PostScriptParser_parseCondition() {
  33501. // Add two place holders that will be updated later
  33502. var conditionLocation = this.operators.length;
  33503. this.operators.push(null, null);
  33504. this.parseBlock();
  33505. this.expect(PostScriptTokenTypes.RBRACE);
  33506. if (this.accept(PostScriptTokenTypes.IF)) {
  33507. // The true block is right after the 'if' so it just falls through on
  33508. // true else it jumps and skips the true block.
  33509. this.operators[conditionLocation] = this.operators.length;
  33510. this.operators[conditionLocation + 1] = 'jz';
  33511. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33512. var jumpLocation = this.operators.length;
  33513. this.operators.push(null, null);
  33514. var endOfTrue = this.operators.length;
  33515. this.parseBlock();
  33516. this.expect(PostScriptTokenTypes.RBRACE);
  33517. this.expect(PostScriptTokenTypes.IFELSE);
  33518. // The jump is added at the end of the true block to skip the false
  33519. // block.
  33520. this.operators[jumpLocation] = this.operators.length;
  33521. this.operators[jumpLocation + 1] = 'j';
  33522. this.operators[conditionLocation] = endOfTrue;
  33523. this.operators[conditionLocation + 1] = 'jz';
  33524. } else {
  33525. error('PS Function: error parsing conditional.');
  33526. }
  33527. }
  33528. };
  33529. return PostScriptParser;
  33530. })();
  33531. var PostScriptTokenTypes = {
  33532. LBRACE: 0,
  33533. RBRACE: 1,
  33534. NUMBER: 2,
  33535. OPERATOR: 3,
  33536. IF: 4,
  33537. IFELSE: 5
  33538. };
  33539. var PostScriptToken = (function PostScriptTokenClosure() {
  33540. function PostScriptToken(type, value) {
  33541. this.type = type;
  33542. this.value = value;
  33543. }
  33544. var opCache = Object.create(null);
  33545. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  33546. var opValue = opCache[op];
  33547. if (opValue) {
  33548. return opValue;
  33549. }
  33550. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  33551. };
  33552. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  33553. '{');
  33554. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  33555. '}');
  33556. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  33557. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  33558. 'IFELSE');
  33559. return PostScriptToken;
  33560. })();
  33561. var PostScriptLexer = (function PostScriptLexerClosure() {
  33562. function PostScriptLexer(stream) {
  33563. this.stream = stream;
  33564. this.nextChar();
  33565. this.strBuf = [];
  33566. }
  33567. PostScriptLexer.prototype = {
  33568. nextChar: function PostScriptLexer_nextChar() {
  33569. return (this.currentChar = this.stream.getByte());
  33570. },
  33571. getToken: function PostScriptLexer_getToken() {
  33572. var comment = false;
  33573. var ch = this.currentChar;
  33574. // skip comments
  33575. while (true) {
  33576. if (ch < 0) {
  33577. return EOF;
  33578. }
  33579. if (comment) {
  33580. if (ch === 0x0A || ch === 0x0D) {
  33581. comment = false;
  33582. }
  33583. } else if (ch === 0x25) { // '%'
  33584. comment = true;
  33585. } else if (!isSpace(ch)) {
  33586. break;
  33587. }
  33588. ch = this.nextChar();
  33589. }
  33590. switch (ch | 0) {
  33591. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  33592. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  33593. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  33594. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  33595. this.getNumber());
  33596. case 0x7B: // '{'
  33597. this.nextChar();
  33598. return PostScriptToken.LBRACE;
  33599. case 0x7D: // '}'
  33600. this.nextChar();
  33601. return PostScriptToken.RBRACE;
  33602. }
  33603. // operator
  33604. var strBuf = this.strBuf;
  33605. strBuf.length = 0;
  33606. strBuf[0] = String.fromCharCode(ch);
  33607. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  33608. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  33609. strBuf.push(String.fromCharCode(ch));
  33610. }
  33611. var str = strBuf.join('');
  33612. switch (str.toLowerCase()) {
  33613. case 'if':
  33614. return PostScriptToken.IF;
  33615. case 'ifelse':
  33616. return PostScriptToken.IFELSE;
  33617. default:
  33618. return PostScriptToken.getOperator(str);
  33619. }
  33620. },
  33621. getNumber: function PostScriptLexer_getNumber() {
  33622. var ch = this.currentChar;
  33623. var strBuf = this.strBuf;
  33624. strBuf.length = 0;
  33625. strBuf[0] = String.fromCharCode(ch);
  33626. while ((ch = this.nextChar()) >= 0) {
  33627. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  33628. ch === 0x2D || ch === 0x2E) { // '-', '.'
  33629. strBuf.push(String.fromCharCode(ch));
  33630. } else {
  33631. break;
  33632. }
  33633. }
  33634. var value = parseFloat(strBuf.join(''));
  33635. if (isNaN(value)) {
  33636. error('Invalid floating point number: ' + value);
  33637. }
  33638. return value;
  33639. }
  33640. };
  33641. return PostScriptLexer;
  33642. })();
  33643. exports.PostScriptLexer = PostScriptLexer;
  33644. exports.PostScriptParser = PostScriptParser;
  33645. }));
  33646. (function (root, factory) {
  33647. {
  33648. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  33649. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper,
  33650. root.pdfjsDisplayWebGL);
  33651. }
  33652. }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper,
  33653. displayWebGL) {
  33654. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33655. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  33656. var ImageKind = sharedUtil.ImageKind;
  33657. var OPS = sharedUtil.OPS;
  33658. var TextRenderingMode = sharedUtil.TextRenderingMode;
  33659. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  33660. var Util = sharedUtil.Util;
  33661. var assert = sharedUtil.assert;
  33662. var info = sharedUtil.info;
  33663. var isNum = sharedUtil.isNum;
  33664. var isArray = sharedUtil.isArray;
  33665. var isLittleEndian = sharedUtil.isLittleEndian;
  33666. var error = sharedUtil.error;
  33667. var shadow = sharedUtil.shadow;
  33668. var warn = sharedUtil.warn;
  33669. var TilingPattern = displayPatternHelper.TilingPattern;
  33670. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  33671. var WebGLUtils = displayWebGL.WebGLUtils;
  33672. var hasCanvasTypedArrays = displayDOMUtils.hasCanvasTypedArrays;
  33673. // <canvas> contexts store most of the state we need natively.
  33674. // However, PDF needs a bit more state, which we store here.
  33675. // Minimal font size that would be used during canvas fillText operations.
  33676. var MIN_FONT_SIZE = 16;
  33677. // Maximum font size that would be used during canvas fillText operations.
  33678. var MAX_FONT_SIZE = 100;
  33679. var MAX_GROUP_SIZE = 4096;
  33680. // Heuristic value used when enforcing minimum line widths.
  33681. var MIN_WIDTH_FACTOR = 0.65;
  33682. var COMPILE_TYPE3_GLYPHS = true;
  33683. var MAX_SIZE_TO_COMPILE = 1000;
  33684. var FULL_CHUNK_HEIGHT = 16;
  33685. var HasCanvasTypedArraysCached = {
  33686. get value() {
  33687. return shadow(HasCanvasTypedArraysCached, 'value', hasCanvasTypedArrays());
  33688. }
  33689. };
  33690. var IsLittleEndianCached = {
  33691. get value() {
  33692. return shadow(IsLittleEndianCached, 'value', isLittleEndian());
  33693. }
  33694. };
  33695. function createScratchCanvas(width, height) {
  33696. var canvas = document.createElement('canvas');
  33697. canvas.width = width;
  33698. canvas.height = height;
  33699. return canvas;
  33700. }
  33701. function addContextCurrentTransform(ctx) {
  33702. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  33703. if (!ctx.mozCurrentTransform) {
  33704. ctx._originalSave = ctx.save;
  33705. ctx._originalRestore = ctx.restore;
  33706. ctx._originalRotate = ctx.rotate;
  33707. ctx._originalScale = ctx.scale;
  33708. ctx._originalTranslate = ctx.translate;
  33709. ctx._originalTransform = ctx.transform;
  33710. ctx._originalSetTransform = ctx.setTransform;
  33711. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  33712. ctx._transformStack = [];
  33713. Object.defineProperty(ctx, 'mozCurrentTransform', {
  33714. get: function getCurrentTransform() {
  33715. return this._transformMatrix;
  33716. }
  33717. });
  33718. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  33719. get: function getCurrentTransformInverse() {
  33720. // Calculation done using WolframAlpha:
  33721. // http://www.wolframalpha.com/input/?
  33722. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  33723. var m = this._transformMatrix;
  33724. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  33725. var ad_bc = a * d - b * c;
  33726. var bc_ad = b * c - a * d;
  33727. return [
  33728. d / ad_bc,
  33729. b / bc_ad,
  33730. c / bc_ad,
  33731. a / ad_bc,
  33732. (d * e - c * f) / bc_ad,
  33733. (b * e - a * f) / ad_bc
  33734. ];
  33735. }
  33736. });
  33737. ctx.save = function ctxSave() {
  33738. var old = this._transformMatrix;
  33739. this._transformStack.push(old);
  33740. this._transformMatrix = old.slice(0, 6);
  33741. this._originalSave();
  33742. };
  33743. ctx.restore = function ctxRestore() {
  33744. var prev = this._transformStack.pop();
  33745. if (prev) {
  33746. this._transformMatrix = prev;
  33747. this._originalRestore();
  33748. }
  33749. };
  33750. ctx.translate = function ctxTranslate(x, y) {
  33751. var m = this._transformMatrix;
  33752. m[4] = m[0] * x + m[2] * y + m[4];
  33753. m[5] = m[1] * x + m[3] * y + m[5];
  33754. this._originalTranslate(x, y);
  33755. };
  33756. ctx.scale = function ctxScale(x, y) {
  33757. var m = this._transformMatrix;
  33758. m[0] = m[0] * x;
  33759. m[1] = m[1] * x;
  33760. m[2] = m[2] * y;
  33761. m[3] = m[3] * y;
  33762. this._originalScale(x, y);
  33763. };
  33764. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  33765. var m = this._transformMatrix;
  33766. this._transformMatrix = [
  33767. m[0] * a + m[2] * b,
  33768. m[1] * a + m[3] * b,
  33769. m[0] * c + m[2] * d,
  33770. m[1] * c + m[3] * d,
  33771. m[0] * e + m[2] * f + m[4],
  33772. m[1] * e + m[3] * f + m[5]
  33773. ];
  33774. ctx._originalTransform(a, b, c, d, e, f);
  33775. };
  33776. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  33777. this._transformMatrix = [a, b, c, d, e, f];
  33778. ctx._originalSetTransform(a, b, c, d, e, f);
  33779. };
  33780. ctx.rotate = function ctxRotate(angle) {
  33781. var cosValue = Math.cos(angle);
  33782. var sinValue = Math.sin(angle);
  33783. var m = this._transformMatrix;
  33784. this._transformMatrix = [
  33785. m[0] * cosValue + m[2] * sinValue,
  33786. m[1] * cosValue + m[3] * sinValue,
  33787. m[0] * (-sinValue) + m[2] * cosValue,
  33788. m[1] * (-sinValue) + m[3] * cosValue,
  33789. m[4],
  33790. m[5]
  33791. ];
  33792. this._originalRotate(angle);
  33793. };
  33794. }
  33795. }
  33796. var CachedCanvases = (function CachedCanvasesClosure() {
  33797. function CachedCanvases() {
  33798. this.cache = Object.create(null);
  33799. }
  33800. CachedCanvases.prototype = {
  33801. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  33802. trackTransform) {
  33803. var canvasEntry;
  33804. if (this.cache[id] !== undefined) {
  33805. canvasEntry = this.cache[id];
  33806. canvasEntry.canvas.width = width;
  33807. canvasEntry.canvas.height = height;
  33808. // reset canvas transform for emulated mozCurrentTransform, if needed
  33809. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  33810. } else {
  33811. var canvas = createScratchCanvas(width, height);
  33812. var ctx = canvas.getContext('2d');
  33813. if (trackTransform) {
  33814. addContextCurrentTransform(ctx);
  33815. }
  33816. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  33817. }
  33818. return canvasEntry;
  33819. },
  33820. clear: function () {
  33821. for (var id in this.cache) {
  33822. var canvasEntry = this.cache[id];
  33823. // Zeroing the width and height causes Firefox to release graphics
  33824. // resources immediately, which can greatly reduce memory consumption.
  33825. canvasEntry.canvas.width = 0;
  33826. canvasEntry.canvas.height = 0;
  33827. delete this.cache[id];
  33828. }
  33829. }
  33830. };
  33831. return CachedCanvases;
  33832. })();
  33833. function compileType3Glyph(imgData) {
  33834. var POINT_TO_PROCESS_LIMIT = 1000;
  33835. var width = imgData.width, height = imgData.height;
  33836. var i, j, j0, width1 = width + 1;
  33837. var points = new Uint8Array(width1 * (height + 1));
  33838. var POINT_TYPES =
  33839. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  33840. // decodes bit-packed mask data
  33841. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  33842. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  33843. for (i = 0, ii = data0.length; i < ii; i++) {
  33844. var mask = 128, elem = data0[i];
  33845. while (mask > 0) {
  33846. data[pos++] = (elem & mask) ? 0 : 255;
  33847. mask >>= 1;
  33848. }
  33849. }
  33850. // finding iteresting points: every point is located between mask pixels,
  33851. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  33852. // will have flags assigned based on neighboring mask pixels:
  33853. // 4 | 8
  33854. // --P--
  33855. // 2 | 1
  33856. // We are interested only in points with the flags:
  33857. // - outside corners: 1, 2, 4, 8;
  33858. // - inside corners: 7, 11, 13, 14;
  33859. // - and, intersections: 5, 10.
  33860. var count = 0;
  33861. pos = 0;
  33862. if (data[pos] !== 0) {
  33863. points[0] = 1;
  33864. ++count;
  33865. }
  33866. for (j = 1; j < width; j++) {
  33867. if (data[pos] !== data[pos + 1]) {
  33868. points[j] = data[pos] ? 2 : 1;
  33869. ++count;
  33870. }
  33871. pos++;
  33872. }
  33873. if (data[pos] !== 0) {
  33874. points[j] = 2;
  33875. ++count;
  33876. }
  33877. for (i = 1; i < height; i++) {
  33878. pos = i * lineSize;
  33879. j0 = i * width1;
  33880. if (data[pos - lineSize] !== data[pos]) {
  33881. points[j0] = data[pos] ? 1 : 8;
  33882. ++count;
  33883. }
  33884. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  33885. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  33886. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  33887. for (j = 1; j < width; j++) {
  33888. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  33889. (data[pos - lineSize + 1] ? 8 : 0);
  33890. if (POINT_TYPES[sum]) {
  33891. points[j0 + j] = POINT_TYPES[sum];
  33892. ++count;
  33893. }
  33894. pos++;
  33895. }
  33896. if (data[pos - lineSize] !== data[pos]) {
  33897. points[j0 + j] = data[pos] ? 2 : 4;
  33898. ++count;
  33899. }
  33900. if (count > POINT_TO_PROCESS_LIMIT) {
  33901. return null;
  33902. }
  33903. }
  33904. pos = lineSize * (height - 1);
  33905. j0 = i * width1;
  33906. if (data[pos] !== 0) {
  33907. points[j0] = 8;
  33908. ++count;
  33909. }
  33910. for (j = 1; j < width; j++) {
  33911. if (data[pos] !== data[pos + 1]) {
  33912. points[j0 + j] = data[pos] ? 4 : 8;
  33913. ++count;
  33914. }
  33915. pos++;
  33916. }
  33917. if (data[pos] !== 0) {
  33918. points[j0 + j] = 4;
  33919. ++count;
  33920. }
  33921. if (count > POINT_TO_PROCESS_LIMIT) {
  33922. return null;
  33923. }
  33924. // building outlines
  33925. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  33926. var outlines = [];
  33927. for (i = 0; count && i <= height; i++) {
  33928. var p = i * width1;
  33929. var end = p + width;
  33930. while (p < end && !points[p]) {
  33931. p++;
  33932. }
  33933. if (p === end) {
  33934. continue;
  33935. }
  33936. var coords = [p % width1, i];
  33937. var type = points[p], p0 = p, pp;
  33938. do {
  33939. var step = steps[type];
  33940. do {
  33941. p += step;
  33942. } while (!points[p]);
  33943. pp = points[p];
  33944. if (pp !== 5 && pp !== 10) {
  33945. // set new direction
  33946. type = pp;
  33947. // delete mark
  33948. points[p] = 0;
  33949. } else { // type is 5 or 10, ie, a crossing
  33950. // set new direction
  33951. type = pp & ((0x33 * type) >> 4);
  33952. // set new type for "future hit"
  33953. points[p] &= (type >> 2 | type << 2);
  33954. }
  33955. coords.push(p % width1);
  33956. coords.push((p / width1) | 0);
  33957. --count;
  33958. } while (p0 !== p);
  33959. outlines.push(coords);
  33960. --i;
  33961. }
  33962. var drawOutline = function(c) {
  33963. c.save();
  33964. // the path shall be painted in [0..1]x[0..1] space
  33965. c.scale(1 / width, -1 / height);
  33966. c.translate(0, -height);
  33967. c.beginPath();
  33968. for (var i = 0, ii = outlines.length; i < ii; i++) {
  33969. var o = outlines[i];
  33970. c.moveTo(o[0], o[1]);
  33971. for (var j = 2, jj = o.length; j < jj; j += 2) {
  33972. c.lineTo(o[j], o[j+1]);
  33973. }
  33974. }
  33975. c.fill();
  33976. c.beginPath();
  33977. c.restore();
  33978. };
  33979. return drawOutline;
  33980. }
  33981. var CanvasExtraState = (function CanvasExtraStateClosure() {
  33982. function CanvasExtraState(old) {
  33983. // Are soft masks and alpha values shapes or opacities?
  33984. this.alphaIsShape = false;
  33985. this.fontSize = 0;
  33986. this.fontSizeScale = 1;
  33987. this.textMatrix = IDENTITY_MATRIX;
  33988. this.textMatrixScale = 1;
  33989. this.fontMatrix = FONT_IDENTITY_MATRIX;
  33990. this.leading = 0;
  33991. // Current point (in user coordinates)
  33992. this.x = 0;
  33993. this.y = 0;
  33994. // Start of text line (in text coordinates)
  33995. this.lineX = 0;
  33996. this.lineY = 0;
  33997. // Character and word spacing
  33998. this.charSpacing = 0;
  33999. this.wordSpacing = 0;
  34000. this.textHScale = 1;
  34001. this.textRenderingMode = TextRenderingMode.FILL;
  34002. this.textRise = 0;
  34003. // Default fore and background colors
  34004. this.fillColor = '#000000';
  34005. this.strokeColor = '#000000';
  34006. this.patternFill = false;
  34007. // Note: fill alpha applies to all non-stroking operations
  34008. this.fillAlpha = 1;
  34009. this.strokeAlpha = 1;
  34010. this.lineWidth = 1;
  34011. this.activeSMask = null;
  34012. this.resumeSMaskCtx = null; // nonclonable field (see the save method below)
  34013. this.old = old;
  34014. }
  34015. CanvasExtraState.prototype = {
  34016. clone: function CanvasExtraState_clone() {
  34017. return Object.create(this);
  34018. },
  34019. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  34020. this.x = x;
  34021. this.y = y;
  34022. }
  34023. };
  34024. return CanvasExtraState;
  34025. })();
  34026. var CanvasGraphics = (function CanvasGraphicsClosure() {
  34027. // Defines the time the executeOperatorList is going to be executing
  34028. // before it stops and shedules a continue of execution.
  34029. var EXECUTION_TIME = 15;
  34030. // Defines the number of steps before checking the execution time
  34031. var EXECUTION_STEPS = 10;
  34032. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  34033. this.ctx = canvasCtx;
  34034. this.current = new CanvasExtraState();
  34035. this.stateStack = [];
  34036. this.pendingClip = null;
  34037. this.pendingEOFill = false;
  34038. this.res = null;
  34039. this.xobjs = null;
  34040. this.commonObjs = commonObjs;
  34041. this.objs = objs;
  34042. this.imageLayer = imageLayer;
  34043. this.groupStack = [];
  34044. this.processingType3 = null;
  34045. // Patterns are painted relative to the initial page/form transform, see pdf
  34046. // spec 8.7.2 NOTE 1.
  34047. this.baseTransform = null;
  34048. this.baseTransformStack = [];
  34049. this.groupLevel = 0;
  34050. this.smaskStack = [];
  34051. this.smaskCounter = 0;
  34052. this.tempSMask = null;
  34053. this.cachedCanvases = new CachedCanvases();
  34054. if (canvasCtx) {
  34055. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  34056. // the transformation must already be set in canvasCtx._transformMatrix.
  34057. addContextCurrentTransform(canvasCtx);
  34058. }
  34059. this.cachedGetSinglePixelWidth = null;
  34060. }
  34061. function putBinaryImageData(ctx, imgData) {
  34062. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  34063. ctx.putImageData(imgData, 0, 0);
  34064. return;
  34065. }
  34066. // Put the image data to the canvas in chunks, rather than putting the
  34067. // whole image at once. This saves JS memory, because the ImageData object
  34068. // is smaller. It also possibly saves C++ memory within the implementation
  34069. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  34070. // the data passed to putImageData()). |n| shouldn't be too small, however,
  34071. // because too many putImageData() calls will slow things down.
  34072. //
  34073. // Note: as written, if the last chunk is partial, the putImageData() call
  34074. // will (conceptually) put pixels past the bounds of the canvas. But
  34075. // that's ok; any such pixels are ignored.
  34076. var height = imgData.height, width = imgData.width;
  34077. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  34078. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  34079. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  34080. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  34081. var srcPos = 0, destPos;
  34082. var src = imgData.data;
  34083. var dest = chunkImgData.data;
  34084. var i, j, thisChunkHeight, elemsInThisChunk;
  34085. // There are multiple forms in which the pixel data can be passed, and
  34086. // imgData.kind tells us which one this is.
  34087. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  34088. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  34089. var srcLength = src.byteLength;
  34090. var dest32 = HasCanvasTypedArraysCached.value ?
  34091. new Uint32Array(dest.buffer) : new Uint32ArrayView(dest);
  34092. var dest32DataLength = dest32.length;
  34093. var fullSrcDiff = (width + 7) >> 3;
  34094. var white = 0xFFFFFFFF;
  34095. var black = (IsLittleEndianCached.value ||
  34096. !HasCanvasTypedArraysCached.value) ? 0xFF000000 : 0x000000FF;
  34097. for (i = 0; i < totalChunks; i++) {
  34098. thisChunkHeight =
  34099. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  34100. destPos = 0;
  34101. for (j = 0; j < thisChunkHeight; j++) {
  34102. var srcDiff = srcLength - srcPos;
  34103. var k = 0;
  34104. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  34105. var kEndUnrolled = kEnd & ~7;
  34106. var mask = 0;
  34107. var srcByte = 0;
  34108. for (; k < kEndUnrolled; k += 8) {
  34109. srcByte = src[srcPos++];
  34110. dest32[destPos++] = (srcByte & 128) ? white : black;
  34111. dest32[destPos++] = (srcByte & 64) ? white : black;
  34112. dest32[destPos++] = (srcByte & 32) ? white : black;
  34113. dest32[destPos++] = (srcByte & 16) ? white : black;
  34114. dest32[destPos++] = (srcByte & 8) ? white : black;
  34115. dest32[destPos++] = (srcByte & 4) ? white : black;
  34116. dest32[destPos++] = (srcByte & 2) ? white : black;
  34117. dest32[destPos++] = (srcByte & 1) ? white : black;
  34118. }
  34119. for (; k < kEnd; k++) {
  34120. if (mask === 0) {
  34121. srcByte = src[srcPos++];
  34122. mask = 128;
  34123. }
  34124. dest32[destPos++] = (srcByte & mask) ? white : black;
  34125. mask >>= 1;
  34126. }
  34127. }
  34128. // We ran out of input. Make all remaining pixels transparent.
  34129. while (destPos < dest32DataLength) {
  34130. dest32[destPos++] = 0;
  34131. }
  34132. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  34133. }
  34134. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  34135. // RGBA, 32-bits per pixel.
  34136. j = 0;
  34137. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  34138. for (i = 0; i < fullChunks; i++) {
  34139. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  34140. srcPos += elemsInThisChunk;
  34141. ctx.putImageData(chunkImgData, 0, j);
  34142. j += FULL_CHUNK_HEIGHT;
  34143. }
  34144. if (i < totalChunks) {
  34145. elemsInThisChunk = width * partialChunkHeight * 4;
  34146. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  34147. ctx.putImageData(chunkImgData, 0, j);
  34148. }
  34149. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  34150. // RGB, 24-bits per pixel.
  34151. thisChunkHeight = FULL_CHUNK_HEIGHT;
  34152. elemsInThisChunk = width * thisChunkHeight;
  34153. for (i = 0; i < totalChunks; i++) {
  34154. if (i >= fullChunks) {
  34155. thisChunkHeight = partialChunkHeight;
  34156. elemsInThisChunk = width * thisChunkHeight;
  34157. }
  34158. destPos = 0;
  34159. for (j = elemsInThisChunk; j--;) {
  34160. dest[destPos++] = src[srcPos++];
  34161. dest[destPos++] = src[srcPos++];
  34162. dest[destPos++] = src[srcPos++];
  34163. dest[destPos++] = 255;
  34164. }
  34165. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  34166. }
  34167. } else {
  34168. error('bad image kind: ' + imgData.kind);
  34169. }
  34170. }
  34171. function putBinaryImageMask(ctx, imgData) {
  34172. var height = imgData.height, width = imgData.width;
  34173. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  34174. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  34175. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  34176. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  34177. var srcPos = 0;
  34178. var src = imgData.data;
  34179. var dest = chunkImgData.data;
  34180. for (var i = 0; i < totalChunks; i++) {
  34181. var thisChunkHeight =
  34182. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  34183. // Expand the mask so it can be used by the canvas. Any required
  34184. // inversion has already been handled.
  34185. var destPos = 3; // alpha component offset
  34186. for (var j = 0; j < thisChunkHeight; j++) {
  34187. var mask = 0;
  34188. for (var k = 0; k < width; k++) {
  34189. if (!mask) {
  34190. var elem = src[srcPos++];
  34191. mask = 128;
  34192. }
  34193. dest[destPos] = (elem & mask) ? 0 : 255;
  34194. destPos += 4;
  34195. mask >>= 1;
  34196. }
  34197. }
  34198. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  34199. }
  34200. }
  34201. function copyCtxState(sourceCtx, destCtx) {
  34202. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  34203. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  34204. 'globalCompositeOperation', 'font'];
  34205. for (var i = 0, ii = properties.length; i < ii; i++) {
  34206. var property = properties[i];
  34207. if (sourceCtx[property] !== undefined) {
  34208. destCtx[property] = sourceCtx[property];
  34209. }
  34210. }
  34211. if (sourceCtx.setLineDash !== undefined) {
  34212. destCtx.setLineDash(sourceCtx.getLineDash());
  34213. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  34214. }
  34215. }
  34216. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  34217. var length = bytes.length;
  34218. for (var i = 3; i < length; i += 4) {
  34219. var alpha = bytes[i];
  34220. if (alpha === 0) {
  34221. bytes[i - 3] = r0;
  34222. bytes[i - 2] = g0;
  34223. bytes[i - 1] = b0;
  34224. } else if (alpha < 255) {
  34225. var alpha_ = 255 - alpha;
  34226. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  34227. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  34228. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  34229. }
  34230. }
  34231. }
  34232. function composeSMaskAlpha(maskData, layerData, transferMap) {
  34233. var length = maskData.length;
  34234. var scale = 1 / 255;
  34235. for (var i = 3; i < length; i += 4) {
  34236. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  34237. layerData[i] = (layerData[i] * alpha * scale) | 0;
  34238. }
  34239. }
  34240. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  34241. var length = maskData.length;
  34242. for (var i = 3; i < length; i += 4) {
  34243. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  34244. (maskData[i - 2] * 152) + // * 0.59 ....
  34245. (maskData[i - 1] * 28); // * 0.11 ....
  34246. layerData[i] = transferMap ?
  34247. (layerData[i] * transferMap[y >> 8]) >> 8 :
  34248. (layerData[i] * y) >> 16;
  34249. }
  34250. }
  34251. function genericComposeSMask(maskCtx, layerCtx, width, height,
  34252. subtype, backdrop, transferMap) {
  34253. var hasBackdrop = !!backdrop;
  34254. var r0 = hasBackdrop ? backdrop[0] : 0;
  34255. var g0 = hasBackdrop ? backdrop[1] : 0;
  34256. var b0 = hasBackdrop ? backdrop[2] : 0;
  34257. var composeFn;
  34258. if (subtype === 'Luminosity') {
  34259. composeFn = composeSMaskLuminosity;
  34260. } else {
  34261. composeFn = composeSMaskAlpha;
  34262. }
  34263. // processing image in chunks to save memory
  34264. var PIXELS_TO_PROCESS = 1048576;
  34265. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  34266. for (var row = 0; row < height; row += chunkSize) {
  34267. var chunkHeight = Math.min(chunkSize, height - row);
  34268. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  34269. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  34270. if (hasBackdrop) {
  34271. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  34272. }
  34273. composeFn(maskData.data, layerData.data, transferMap);
  34274. maskCtx.putImageData(layerData, 0, row);
  34275. }
  34276. }
  34277. function composeSMask(ctx, smask, layerCtx) {
  34278. var mask = smask.canvas;
  34279. var maskCtx = smask.context;
  34280. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  34281. smask.offsetX, smask.offsetY);
  34282. var backdrop = smask.backdrop || null;
  34283. if (!smask.transferMap && WebGLUtils.isEnabled) {
  34284. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  34285. {subtype: smask.subtype, backdrop: backdrop});
  34286. ctx.setTransform(1, 0, 0, 1, 0, 0);
  34287. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  34288. return;
  34289. }
  34290. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  34291. smask.subtype, backdrop, smask.transferMap);
  34292. ctx.drawImage(mask, 0, 0);
  34293. }
  34294. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  34295. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  34296. var NORMAL_CLIP = {};
  34297. var EO_CLIP = {};
  34298. CanvasGraphics.prototype = {
  34299. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  34300. transparency) {
  34301. // For pdfs that use blend modes we have to clear the canvas else certain
  34302. // blend modes can look wrong since we'd be blending with a white
  34303. // backdrop. The problem with a transparent backdrop though is we then
  34304. // don't get sub pixel anti aliasing on text, creating temporary
  34305. // transparent canvas when we have blend modes.
  34306. var width = this.ctx.canvas.width;
  34307. var height = this.ctx.canvas.height;
  34308. this.ctx.save();
  34309. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  34310. this.ctx.fillRect(0, 0, width, height);
  34311. this.ctx.restore();
  34312. if (transparency) {
  34313. var transparentCanvas = this.cachedCanvases.getCanvas(
  34314. 'transparent', width, height, true);
  34315. this.compositeCtx = this.ctx;
  34316. this.transparentCanvas = transparentCanvas.canvas;
  34317. this.ctx = transparentCanvas.context;
  34318. this.ctx.save();
  34319. // The transform can be applied before rendering, transferring it to
  34320. // the new canvas.
  34321. this.ctx.transform.apply(this.ctx,
  34322. this.compositeCtx.mozCurrentTransform);
  34323. }
  34324. this.ctx.save();
  34325. if (transform) {
  34326. this.ctx.transform.apply(this.ctx, transform);
  34327. }
  34328. this.ctx.transform.apply(this.ctx, viewport.transform);
  34329. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  34330. if (this.imageLayer) {
  34331. this.imageLayer.beginLayout();
  34332. }
  34333. },
  34334. executeOperatorList: function CanvasGraphics_executeOperatorList(
  34335. operatorList,
  34336. executionStartIdx, continueCallback,
  34337. stepper) {
  34338. var argsArray = operatorList.argsArray;
  34339. var fnArray = operatorList.fnArray;
  34340. var i = executionStartIdx || 0;
  34341. var argsArrayLen = argsArray.length;
  34342. // Sometimes the OperatorList to execute is empty.
  34343. if (argsArrayLen === i) {
  34344. return i;
  34345. }
  34346. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  34347. typeof continueCallback === 'function');
  34348. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  34349. var steps = 0;
  34350. var commonObjs = this.commonObjs;
  34351. var objs = this.objs;
  34352. var fnId;
  34353. while (true) {
  34354. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  34355. stepper.breakIt(i, continueCallback);
  34356. return i;
  34357. }
  34358. fnId = fnArray[i];
  34359. if (fnId !== OPS.dependency) {
  34360. this[fnId].apply(this, argsArray[i]);
  34361. } else {
  34362. var deps = argsArray[i];
  34363. for (var n = 0, nn = deps.length; n < nn; n++) {
  34364. var depObjId = deps[n];
  34365. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  34366. var objsPool = common ? commonObjs : objs;
  34367. // If the promise isn't resolved yet, add the continueCallback
  34368. // to the promise and bail out.
  34369. if (!objsPool.isResolved(depObjId)) {
  34370. objsPool.get(depObjId, continueCallback);
  34371. return i;
  34372. }
  34373. }
  34374. }
  34375. i++;
  34376. // If the entire operatorList was executed, stop as were done.
  34377. if (i === argsArrayLen) {
  34378. return i;
  34379. }
  34380. // If the execution took longer then a certain amount of time and
  34381. // `continueCallback` is specified, interrupt the execution.
  34382. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  34383. if (Date.now() > endTime) {
  34384. continueCallback();
  34385. return i;
  34386. }
  34387. steps = 0;
  34388. }
  34389. // If the operatorList isn't executed completely yet OR the execution
  34390. // time was short enough, do another execution round.
  34391. }
  34392. },
  34393. endDrawing: function CanvasGraphics_endDrawing() {
  34394. // Finishing all opened operations such as SMask group painting.
  34395. if (this.current.activeSMask !== null) {
  34396. this.endSMaskGroup();
  34397. }
  34398. this.ctx.restore();
  34399. if (this.transparentCanvas) {
  34400. this.ctx = this.compositeCtx;
  34401. this.ctx.save();
  34402. this.ctx.setTransform(1, 0, 0, 1, 0, 0); // Avoid apply transform twice
  34403. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  34404. this.ctx.restore();
  34405. this.transparentCanvas = null;
  34406. }
  34407. this.cachedCanvases.clear();
  34408. WebGLUtils.clear();
  34409. if (this.imageLayer) {
  34410. this.imageLayer.endLayout();
  34411. }
  34412. },
  34413. // Graphics state
  34414. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  34415. this.current.lineWidth = width;
  34416. this.ctx.lineWidth = width;
  34417. },
  34418. setLineCap: function CanvasGraphics_setLineCap(style) {
  34419. this.ctx.lineCap = LINE_CAP_STYLES[style];
  34420. },
  34421. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  34422. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  34423. },
  34424. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  34425. this.ctx.miterLimit = limit;
  34426. },
  34427. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  34428. var ctx = this.ctx;
  34429. if (ctx.setLineDash !== undefined) {
  34430. ctx.setLineDash(dashArray);
  34431. ctx.lineDashOffset = dashPhase;
  34432. }
  34433. },
  34434. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  34435. // Maybe if we one day fully support color spaces this will be important
  34436. // for now we can ignore.
  34437. // TODO set rendering intent?
  34438. },
  34439. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  34440. // There's no way to control this with canvas, but we can safely ignore.
  34441. // TODO set flatness?
  34442. },
  34443. setGState: function CanvasGraphics_setGState(states) {
  34444. for (var i = 0, ii = states.length; i < ii; i++) {
  34445. var state = states[i];
  34446. var key = state[0];
  34447. var value = state[1];
  34448. switch (key) {
  34449. case 'LW':
  34450. this.setLineWidth(value);
  34451. break;
  34452. case 'LC':
  34453. this.setLineCap(value);
  34454. break;
  34455. case 'LJ':
  34456. this.setLineJoin(value);
  34457. break;
  34458. case 'ML':
  34459. this.setMiterLimit(value);
  34460. break;
  34461. case 'D':
  34462. this.setDash(value[0], value[1]);
  34463. break;
  34464. case 'RI':
  34465. this.setRenderingIntent(value);
  34466. break;
  34467. case 'FL':
  34468. this.setFlatness(value);
  34469. break;
  34470. case 'Font':
  34471. this.setFont(value[0], value[1]);
  34472. break;
  34473. case 'CA':
  34474. this.current.strokeAlpha = state[1];
  34475. break;
  34476. case 'ca':
  34477. this.current.fillAlpha = state[1];
  34478. this.ctx.globalAlpha = state[1];
  34479. break;
  34480. case 'BM':
  34481. if (value && value.name && (value.name !== 'Normal')) {
  34482. var mode = value.name.replace(/([A-Z])/g,
  34483. function(c) {
  34484. return '-' + c.toLowerCase();
  34485. }
  34486. ).substring(1);
  34487. this.ctx.globalCompositeOperation = mode;
  34488. if (this.ctx.globalCompositeOperation !== mode) {
  34489. warn('globalCompositeOperation "' + mode +
  34490. '" is not supported');
  34491. }
  34492. } else {
  34493. this.ctx.globalCompositeOperation = 'source-over';
  34494. }
  34495. break;
  34496. case 'SMask':
  34497. if (this.current.activeSMask) {
  34498. // If SMask is currrenly used, it needs to be suspended or
  34499. // finished. Suspend only makes sense when at least one save()
  34500. // was performed and state needs to be reverted on restore().
  34501. if (this.stateStack.length > 0 &&
  34502. (this.stateStack[this.stateStack.length - 1].activeSMask ===
  34503. this.current.activeSMask)) {
  34504. this.suspendSMaskGroup();
  34505. } else {
  34506. this.endSMaskGroup();
  34507. }
  34508. }
  34509. this.current.activeSMask = value ? this.tempSMask : null;
  34510. if (this.current.activeSMask) {
  34511. this.beginSMaskGroup();
  34512. }
  34513. this.tempSMask = null;
  34514. break;
  34515. }
  34516. }
  34517. },
  34518. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  34519. var activeSMask = this.current.activeSMask;
  34520. var drawnWidth = activeSMask.canvas.width;
  34521. var drawnHeight = activeSMask.canvas.height;
  34522. var cacheId = 'smaskGroupAt' + this.groupLevel;
  34523. var scratchCanvas = this.cachedCanvases.getCanvas(
  34524. cacheId, drawnWidth, drawnHeight, true);
  34525. var currentCtx = this.ctx;
  34526. var currentTransform = currentCtx.mozCurrentTransform;
  34527. this.ctx.save();
  34528. var groupCtx = scratchCanvas.context;
  34529. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  34530. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  34531. groupCtx.transform.apply(groupCtx, currentTransform);
  34532. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  34533. copyCtxState(currentCtx, groupCtx);
  34534. this.ctx = groupCtx;
  34535. this.setGState([
  34536. ['BM', 'Normal'],
  34537. ['ca', 1],
  34538. ['CA', 1]
  34539. ]);
  34540. this.groupStack.push(currentCtx);
  34541. this.groupLevel++;
  34542. },
  34543. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34544. // Similar to endSMaskGroup, the intermediate canvas has to be composed
  34545. // and future ctx state restored.
  34546. var groupCtx = this.ctx;
  34547. this.groupLevel--;
  34548. this.ctx = this.groupStack.pop();
  34549. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  34550. this.ctx.restore();
  34551. this.ctx.save(); // save is needed since SMask will be resumed.
  34552. copyCtxState(groupCtx, this.ctx);
  34553. // Saving state for resuming.
  34554. this.current.resumeSMaskCtx = groupCtx;
  34555. // Transform was changed in the SMask canvas, reflecting this change on
  34556. // this.ctx.
  34557. var deltaTransform = Util.transform(
  34558. this.current.activeSMask.startTransformInverse,
  34559. groupCtx.mozCurrentTransform);
  34560. this.ctx.transform.apply(this.ctx, deltaTransform);
  34561. // SMask was composed, the results at the groupCtx can be cleared.
  34562. groupCtx.save();
  34563. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  34564. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  34565. groupCtx.restore();
  34566. },
  34567. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34568. // Resuming state saved by suspendSMaskGroup. We don't need to restore
  34569. // any groupCtx state since restore() command (the only caller) will do
  34570. // that for us. See also beginSMaskGroup.
  34571. var groupCtx = this.current.resumeSMaskCtx;
  34572. var currentCtx = this.ctx;
  34573. this.ctx = groupCtx;
  34574. this.groupStack.push(currentCtx);
  34575. this.groupLevel++;
  34576. },
  34577. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  34578. var groupCtx = this.ctx;
  34579. this.groupLevel--;
  34580. this.ctx = this.groupStack.pop();
  34581. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  34582. this.ctx.restore();
  34583. copyCtxState(groupCtx, this.ctx);
  34584. // Transform was changed in the SMask canvas, reflecting this change on
  34585. // this.ctx.
  34586. var deltaTransform = Util.transform(
  34587. this.current.activeSMask.startTransformInverse,
  34588. groupCtx.mozCurrentTransform);
  34589. this.ctx.transform.apply(this.ctx, deltaTransform);
  34590. },
  34591. save: function CanvasGraphics_save() {
  34592. this.ctx.save();
  34593. var old = this.current;
  34594. this.stateStack.push(old);
  34595. this.current = old.clone();
  34596. this.current.resumeSMaskCtx = null;
  34597. },
  34598. restore: function CanvasGraphics_restore() {
  34599. // SMask was suspended, we just need to resume it.
  34600. if (this.current.resumeSMaskCtx) {
  34601. this.resumeSMaskGroup();
  34602. }
  34603. // SMask has to be finished once there is no states that are using the
  34604. // same SMask.
  34605. if (this.current.activeSMask !== null && (this.stateStack.length === 0 ||
  34606. this.stateStack[this.stateStack.length - 1].activeSMask !==
  34607. this.current.activeSMask)) {
  34608. this.endSMaskGroup();
  34609. }
  34610. if (this.stateStack.length !== 0) {
  34611. this.current = this.stateStack.pop();
  34612. this.ctx.restore();
  34613. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  34614. this.pendingClip = null;
  34615. this.cachedGetSinglePixelWidth = null;
  34616. }
  34617. },
  34618. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  34619. this.ctx.transform(a, b, c, d, e, f);
  34620. this.cachedGetSinglePixelWidth = null;
  34621. },
  34622. // Path
  34623. constructPath: function CanvasGraphics_constructPath(ops, args) {
  34624. var ctx = this.ctx;
  34625. var current = this.current;
  34626. var x = current.x, y = current.y;
  34627. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  34628. switch (ops[i] | 0) {
  34629. case OPS.rectangle:
  34630. x = args[j++];
  34631. y = args[j++];
  34632. var width = args[j++];
  34633. var height = args[j++];
  34634. if (width === 0) {
  34635. width = this.getSinglePixelWidth();
  34636. }
  34637. if (height === 0) {
  34638. height = this.getSinglePixelWidth();
  34639. }
  34640. var xw = x + width;
  34641. var yh = y + height;
  34642. this.ctx.moveTo(x, y);
  34643. this.ctx.lineTo(xw, y);
  34644. this.ctx.lineTo(xw, yh);
  34645. this.ctx.lineTo(x, yh);
  34646. this.ctx.lineTo(x, y);
  34647. this.ctx.closePath();
  34648. break;
  34649. case OPS.moveTo:
  34650. x = args[j++];
  34651. y = args[j++];
  34652. ctx.moveTo(x, y);
  34653. break;
  34654. case OPS.lineTo:
  34655. x = args[j++];
  34656. y = args[j++];
  34657. ctx.lineTo(x, y);
  34658. break;
  34659. case OPS.curveTo:
  34660. x = args[j + 4];
  34661. y = args[j + 5];
  34662. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  34663. x, y);
  34664. j += 6;
  34665. break;
  34666. case OPS.curveTo2:
  34667. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  34668. args[j + 2], args[j + 3]);
  34669. x = args[j + 2];
  34670. y = args[j + 3];
  34671. j += 4;
  34672. break;
  34673. case OPS.curveTo3:
  34674. x = args[j + 2];
  34675. y = args[j + 3];
  34676. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  34677. j += 4;
  34678. break;
  34679. case OPS.closePath:
  34680. ctx.closePath();
  34681. break;
  34682. }
  34683. }
  34684. current.setCurrentPoint(x, y);
  34685. },
  34686. closePath: function CanvasGraphics_closePath() {
  34687. this.ctx.closePath();
  34688. },
  34689. stroke: function CanvasGraphics_stroke(consumePath) {
  34690. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  34691. var ctx = this.ctx;
  34692. var strokeColor = this.current.strokeColor;
  34693. // Prevent drawing too thin lines by enforcing a minimum line width.
  34694. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  34695. this.current.lineWidth);
  34696. // For stroke we want to temporarily change the global alpha to the
  34697. // stroking alpha.
  34698. ctx.globalAlpha = this.current.strokeAlpha;
  34699. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  34700. strokeColor.type === 'Pattern') {
  34701. // for patterns, we transform to pattern space, calculate
  34702. // the pattern, call stroke, and restore to user space
  34703. ctx.save();
  34704. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  34705. ctx.stroke();
  34706. ctx.restore();
  34707. } else {
  34708. ctx.stroke();
  34709. }
  34710. if (consumePath) {
  34711. this.consumePath();
  34712. }
  34713. // Restore the global alpha to the fill alpha
  34714. ctx.globalAlpha = this.current.fillAlpha;
  34715. },
  34716. closeStroke: function CanvasGraphics_closeStroke() {
  34717. this.closePath();
  34718. this.stroke();
  34719. },
  34720. fill: function CanvasGraphics_fill(consumePath) {
  34721. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  34722. var ctx = this.ctx;
  34723. var fillColor = this.current.fillColor;
  34724. var isPatternFill = this.current.patternFill;
  34725. var needRestore = false;
  34726. if (isPatternFill) {
  34727. ctx.save();
  34728. if (this.baseTransform) {
  34729. ctx.setTransform.apply(ctx, this.baseTransform);
  34730. }
  34731. ctx.fillStyle = fillColor.getPattern(ctx, this);
  34732. needRestore = true;
  34733. }
  34734. if (this.pendingEOFill) {
  34735. if (ctx.mozFillRule !== undefined) {
  34736. ctx.mozFillRule = 'evenodd';
  34737. ctx.fill();
  34738. ctx.mozFillRule = 'nonzero';
  34739. } else {
  34740. ctx.fill('evenodd');
  34741. }
  34742. this.pendingEOFill = false;
  34743. } else {
  34744. ctx.fill();
  34745. }
  34746. if (needRestore) {
  34747. ctx.restore();
  34748. }
  34749. if (consumePath) {
  34750. this.consumePath();
  34751. }
  34752. },
  34753. eoFill: function CanvasGraphics_eoFill() {
  34754. this.pendingEOFill = true;
  34755. this.fill();
  34756. },
  34757. fillStroke: function CanvasGraphics_fillStroke() {
  34758. this.fill(false);
  34759. this.stroke(false);
  34760. this.consumePath();
  34761. },
  34762. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  34763. this.pendingEOFill = true;
  34764. this.fillStroke();
  34765. },
  34766. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  34767. this.closePath();
  34768. this.fillStroke();
  34769. },
  34770. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  34771. this.pendingEOFill = true;
  34772. this.closePath();
  34773. this.fillStroke();
  34774. },
  34775. endPath: function CanvasGraphics_endPath() {
  34776. this.consumePath();
  34777. },
  34778. // Clipping
  34779. clip: function CanvasGraphics_clip() {
  34780. this.pendingClip = NORMAL_CLIP;
  34781. },
  34782. eoClip: function CanvasGraphics_eoClip() {
  34783. this.pendingClip = EO_CLIP;
  34784. },
  34785. // Text
  34786. beginText: function CanvasGraphics_beginText() {
  34787. this.current.textMatrix = IDENTITY_MATRIX;
  34788. this.current.textMatrixScale = 1;
  34789. this.current.x = this.current.lineX = 0;
  34790. this.current.y = this.current.lineY = 0;
  34791. },
  34792. endText: function CanvasGraphics_endText() {
  34793. var paths = this.pendingTextPaths;
  34794. var ctx = this.ctx;
  34795. if (paths === undefined) {
  34796. ctx.beginPath();
  34797. return;
  34798. }
  34799. ctx.save();
  34800. ctx.beginPath();
  34801. for (var i = 0; i < paths.length; i++) {
  34802. var path = paths[i];
  34803. ctx.setTransform.apply(ctx, path.transform);
  34804. ctx.translate(path.x, path.y);
  34805. path.addToPath(ctx, path.fontSize);
  34806. }
  34807. ctx.restore();
  34808. ctx.clip();
  34809. ctx.beginPath();
  34810. delete this.pendingTextPaths;
  34811. },
  34812. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  34813. this.current.charSpacing = spacing;
  34814. },
  34815. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  34816. this.current.wordSpacing = spacing;
  34817. },
  34818. setHScale: function CanvasGraphics_setHScale(scale) {
  34819. this.current.textHScale = scale / 100;
  34820. },
  34821. setLeading: function CanvasGraphics_setLeading(leading) {
  34822. this.current.leading = -leading;
  34823. },
  34824. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  34825. var fontObj = this.commonObjs.get(fontRefName);
  34826. var current = this.current;
  34827. if (!fontObj) {
  34828. error('Can\'t find font for ' + fontRefName);
  34829. }
  34830. current.fontMatrix = (fontObj.fontMatrix ?
  34831. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  34832. // A valid matrix needs all main diagonal elements to be non-zero
  34833. // This also ensures we bypass FF bugzilla bug #719844.
  34834. if (current.fontMatrix[0] === 0 ||
  34835. current.fontMatrix[3] === 0) {
  34836. warn('Invalid font matrix for font ' + fontRefName);
  34837. }
  34838. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  34839. // and in some docs this can be negative (inverted x-y axes).
  34840. if (size < 0) {
  34841. size = -size;
  34842. current.fontDirection = -1;
  34843. } else {
  34844. current.fontDirection = 1;
  34845. }
  34846. this.current.font = fontObj;
  34847. this.current.fontSize = size;
  34848. if (fontObj.isType3Font) {
  34849. return; // we don't need ctx.font for Type3 fonts
  34850. }
  34851. var name = fontObj.loadedName || 'sans-serif';
  34852. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  34853. (fontObj.bold ? 'bold' : 'normal');
  34854. var italic = fontObj.italic ? 'italic' : 'normal';
  34855. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  34856. // Some font backends cannot handle fonts below certain size.
  34857. // Keeping the font at minimal size and using the fontSizeScale to change
  34858. // the current transformation matrix before the fillText/strokeText.
  34859. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  34860. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  34861. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  34862. this.current.fontSizeScale = size / browserFontSize;
  34863. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  34864. this.ctx.font = rule;
  34865. },
  34866. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  34867. this.current.textRenderingMode = mode;
  34868. },
  34869. setTextRise: function CanvasGraphics_setTextRise(rise) {
  34870. this.current.textRise = rise;
  34871. },
  34872. moveText: function CanvasGraphics_moveText(x, y) {
  34873. this.current.x = this.current.lineX += x;
  34874. this.current.y = this.current.lineY += y;
  34875. },
  34876. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  34877. this.setLeading(-y);
  34878. this.moveText(x, y);
  34879. },
  34880. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  34881. this.current.textMatrix = [a, b, c, d, e, f];
  34882. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  34883. this.current.x = this.current.lineX = 0;
  34884. this.current.y = this.current.lineY = 0;
  34885. },
  34886. nextLine: function CanvasGraphics_nextLine() {
  34887. this.moveText(0, this.current.leading);
  34888. },
  34889. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  34890. var ctx = this.ctx;
  34891. var current = this.current;
  34892. var font = current.font;
  34893. var textRenderingMode = current.textRenderingMode;
  34894. var fontSize = current.fontSize / current.fontSizeScale;
  34895. var fillStrokeMode = textRenderingMode &
  34896. TextRenderingMode.FILL_STROKE_MASK;
  34897. var isAddToPathSet = !!(textRenderingMode &
  34898. TextRenderingMode.ADD_TO_PATH_FLAG);
  34899. var addToPath;
  34900. if (font.disableFontFace || isAddToPathSet) {
  34901. addToPath = font.getPathGenerator(this.commonObjs, character);
  34902. }
  34903. if (font.disableFontFace) {
  34904. ctx.save();
  34905. ctx.translate(x, y);
  34906. ctx.beginPath();
  34907. addToPath(ctx, fontSize);
  34908. if (fillStrokeMode === TextRenderingMode.FILL ||
  34909. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34910. ctx.fill();
  34911. }
  34912. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34913. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34914. ctx.stroke();
  34915. }
  34916. ctx.restore();
  34917. } else {
  34918. if (fillStrokeMode === TextRenderingMode.FILL ||
  34919. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34920. ctx.fillText(character, x, y);
  34921. }
  34922. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34923. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34924. ctx.strokeText(character, x, y);
  34925. }
  34926. }
  34927. if (isAddToPathSet) {
  34928. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  34929. paths.push({
  34930. transform: ctx.mozCurrentTransform,
  34931. x: x,
  34932. y: y,
  34933. fontSize: fontSize,
  34934. addToPath: addToPath
  34935. });
  34936. }
  34937. },
  34938. get isFontSubpixelAAEnabled() {
  34939. // Checks if anti-aliasing is enabled when scaled text is painted.
  34940. // On Windows GDI scaled fonts looks bad.
  34941. var ctx = document.createElement('canvas').getContext('2d');
  34942. ctx.scale(1.5, 1);
  34943. ctx.fillText('I', 0, 10);
  34944. var data = ctx.getImageData(0, 0, 10, 10).data;
  34945. var enabled = false;
  34946. for (var i = 3; i < data.length; i += 4) {
  34947. if (data[i] > 0 && data[i] < 255) {
  34948. enabled = true;
  34949. break;
  34950. }
  34951. }
  34952. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  34953. },
  34954. showText: function CanvasGraphics_showText(glyphs) {
  34955. var current = this.current;
  34956. var font = current.font;
  34957. if (font.isType3Font) {
  34958. return this.showType3Text(glyphs);
  34959. }
  34960. var fontSize = current.fontSize;
  34961. if (fontSize === 0) {
  34962. return;
  34963. }
  34964. var ctx = this.ctx;
  34965. var fontSizeScale = current.fontSizeScale;
  34966. var charSpacing = current.charSpacing;
  34967. var wordSpacing = current.wordSpacing;
  34968. var fontDirection = current.fontDirection;
  34969. var textHScale = current.textHScale * fontDirection;
  34970. var glyphsLength = glyphs.length;
  34971. var vertical = font.vertical;
  34972. var spacingDir = vertical ? 1 : -1;
  34973. var defaultVMetrics = font.defaultVMetrics;
  34974. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  34975. var simpleFillText =
  34976. current.textRenderingMode === TextRenderingMode.FILL &&
  34977. !font.disableFontFace;
  34978. ctx.save();
  34979. ctx.transform.apply(ctx, current.textMatrix);
  34980. ctx.translate(current.x, current.y + current.textRise);
  34981. if (current.patternFill) {
  34982. // TODO: Some shading patterns are not applied correctly to text,
  34983. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  34984. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  34985. }
  34986. if (fontDirection > 0) {
  34987. ctx.scale(textHScale, -1);
  34988. } else {
  34989. ctx.scale(textHScale, 1);
  34990. }
  34991. var lineWidth = current.lineWidth;
  34992. var scale = current.textMatrixScale;
  34993. if (scale === 0 || lineWidth === 0) {
  34994. var fillStrokeMode = current.textRenderingMode &
  34995. TextRenderingMode.FILL_STROKE_MASK;
  34996. if (fillStrokeMode === TextRenderingMode.STROKE ||
  34997. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  34998. this.cachedGetSinglePixelWidth = null;
  34999. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  35000. }
  35001. } else {
  35002. lineWidth /= scale;
  35003. }
  35004. if (fontSizeScale !== 1.0) {
  35005. ctx.scale(fontSizeScale, fontSizeScale);
  35006. lineWidth /= fontSizeScale;
  35007. }
  35008. ctx.lineWidth = lineWidth;
  35009. var x = 0, i;
  35010. for (i = 0; i < glyphsLength; ++i) {
  35011. var glyph = glyphs[i];
  35012. if (isNum(glyph)) {
  35013. x += spacingDir * glyph * fontSize / 1000;
  35014. continue;
  35015. }
  35016. var restoreNeeded = false;
  35017. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  35018. var character = glyph.fontChar;
  35019. var accent = glyph.accent;
  35020. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  35021. var width = glyph.width;
  35022. if (vertical) {
  35023. var vmetric, vx, vy;
  35024. vmetric = glyph.vmetric || defaultVMetrics;
  35025. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  35026. vx = -vx * widthAdvanceScale;
  35027. vy = vmetric[2] * widthAdvanceScale;
  35028. width = vmetric ? -vmetric[0] : width;
  35029. scaledX = vx / fontSizeScale;
  35030. scaledY = (x + vy) / fontSizeScale;
  35031. } else {
  35032. scaledX = x / fontSizeScale;
  35033. scaledY = 0;
  35034. }
  35035. if (font.remeasure && width > 0) {
  35036. // Some standard fonts may not have the exact width: rescale per
  35037. // character if measured width is greater than expected glyph width
  35038. // and subpixel-aa is enabled, otherwise just center the glyph.
  35039. var measuredWidth = ctx.measureText(character).width * 1000 /
  35040. fontSize * fontSizeScale;
  35041. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  35042. var characterScaleX = width / measuredWidth;
  35043. restoreNeeded = true;
  35044. ctx.save();
  35045. ctx.scale(characterScaleX, 1);
  35046. scaledX /= characterScaleX;
  35047. } else if (width !== measuredWidth) {
  35048. scaledX += (width - measuredWidth) / 2000 *
  35049. fontSize / fontSizeScale;
  35050. }
  35051. }
  35052. // Only attempt to draw the glyph if it is actually in the embedded font
  35053. // file or if there isn't a font file so the fallback font is shown.
  35054. if (glyph.isInFont || font.missingFile) {
  35055. if (simpleFillText && !accent) {
  35056. // common case
  35057. ctx.fillText(character, scaledX, scaledY);
  35058. } else {
  35059. this.paintChar(character, scaledX, scaledY);
  35060. if (accent) {
  35061. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  35062. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  35063. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  35064. }
  35065. }
  35066. }
  35067. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  35068. x += charWidth;
  35069. if (restoreNeeded) {
  35070. ctx.restore();
  35071. }
  35072. }
  35073. if (vertical) {
  35074. current.y -= x * textHScale;
  35075. } else {
  35076. current.x += x * textHScale;
  35077. }
  35078. ctx.restore();
  35079. },
  35080. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  35081. // Type3 fonts - each glyph is a "mini-PDF"
  35082. var ctx = this.ctx;
  35083. var current = this.current;
  35084. var font = current.font;
  35085. var fontSize = current.fontSize;
  35086. var fontDirection = current.fontDirection;
  35087. var spacingDir = font.vertical ? 1 : -1;
  35088. var charSpacing = current.charSpacing;
  35089. var wordSpacing = current.wordSpacing;
  35090. var textHScale = current.textHScale * fontDirection;
  35091. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  35092. var glyphsLength = glyphs.length;
  35093. var isTextInvisible =
  35094. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  35095. var i, glyph, width, spacingLength;
  35096. if (isTextInvisible || fontSize === 0) {
  35097. return;
  35098. }
  35099. this.cachedGetSinglePixelWidth = null;
  35100. ctx.save();
  35101. ctx.transform.apply(ctx, current.textMatrix);
  35102. ctx.translate(current.x, current.y);
  35103. ctx.scale(textHScale, fontDirection);
  35104. for (i = 0; i < glyphsLength; ++i) {
  35105. glyph = glyphs[i];
  35106. if (isNum(glyph)) {
  35107. spacingLength = spacingDir * glyph * fontSize / 1000;
  35108. this.ctx.translate(spacingLength, 0);
  35109. current.x += spacingLength * textHScale;
  35110. continue;
  35111. }
  35112. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  35113. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  35114. if (!operatorList) {
  35115. warn('Type3 character \"' + glyph.operatorListId +
  35116. '\" is not available');
  35117. continue;
  35118. }
  35119. this.processingType3 = glyph;
  35120. this.save();
  35121. ctx.scale(fontSize, fontSize);
  35122. ctx.transform.apply(ctx, fontMatrix);
  35123. this.executeOperatorList(operatorList);
  35124. this.restore();
  35125. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  35126. width = transformed[0] * fontSize + spacing;
  35127. ctx.translate(width, 0);
  35128. current.x += width * textHScale;
  35129. }
  35130. ctx.restore();
  35131. this.processingType3 = null;
  35132. },
  35133. // Type3 fonts
  35134. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  35135. // We can safely ignore this since the width should be the same
  35136. // as the width in the Widths array.
  35137. },
  35138. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  35139. yWidth,
  35140. llx,
  35141. lly,
  35142. urx,
  35143. ury) {
  35144. // TODO According to the spec we're also suppose to ignore any operators
  35145. // that set color or include images while processing this type3 font.
  35146. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  35147. this.clip();
  35148. this.endPath();
  35149. },
  35150. // Color
  35151. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  35152. var pattern;
  35153. if (IR[0] === 'TilingPattern') {
  35154. var color = IR[1];
  35155. var baseTransform = this.baseTransform ||
  35156. this.ctx.mozCurrentTransform.slice();
  35157. var self = this;
  35158. var canvasGraphicsFactory = {
  35159. createCanvasGraphics: function (ctx) {
  35160. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  35161. }
  35162. };
  35163. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  35164. baseTransform);
  35165. } else {
  35166. pattern = getShadingPatternFromIR(IR);
  35167. }
  35168. return pattern;
  35169. },
  35170. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  35171. this.current.strokeColor = this.getColorN_Pattern(arguments);
  35172. },
  35173. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  35174. this.current.fillColor = this.getColorN_Pattern(arguments);
  35175. this.current.patternFill = true;
  35176. },
  35177. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  35178. var color = Util.makeCssRgb(r, g, b);
  35179. this.ctx.strokeStyle = color;
  35180. this.current.strokeColor = color;
  35181. },
  35182. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  35183. var color = Util.makeCssRgb(r, g, b);
  35184. this.ctx.fillStyle = color;
  35185. this.current.fillColor = color;
  35186. this.current.patternFill = false;
  35187. },
  35188. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  35189. var ctx = this.ctx;
  35190. this.save();
  35191. var pattern = getShadingPatternFromIR(patternIR);
  35192. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  35193. var inv = ctx.mozCurrentTransformInverse;
  35194. if (inv) {
  35195. var canvas = ctx.canvas;
  35196. var width = canvas.width;
  35197. var height = canvas.height;
  35198. var bl = Util.applyTransform([0, 0], inv);
  35199. var br = Util.applyTransform([0, height], inv);
  35200. var ul = Util.applyTransform([width, 0], inv);
  35201. var ur = Util.applyTransform([width, height], inv);
  35202. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  35203. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  35204. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  35205. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  35206. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  35207. } else {
  35208. // HACK to draw the gradient onto an infinite rectangle.
  35209. // PDF gradients are drawn across the entire image while
  35210. // Canvas only allows gradients to be drawn in a rectangle
  35211. // The following bug should allow us to remove this.
  35212. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  35213. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  35214. }
  35215. this.restore();
  35216. },
  35217. // Images
  35218. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  35219. error('Should not call beginInlineImage');
  35220. },
  35221. beginImageData: function CanvasGraphics_beginImageData() {
  35222. error('Should not call beginImageData');
  35223. },
  35224. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  35225. bbox) {
  35226. this.save();
  35227. this.baseTransformStack.push(this.baseTransform);
  35228. if (isArray(matrix) && 6 === matrix.length) {
  35229. this.transform.apply(this, matrix);
  35230. }
  35231. this.baseTransform = this.ctx.mozCurrentTransform;
  35232. if (isArray(bbox) && 4 === bbox.length) {
  35233. var width = bbox[2] - bbox[0];
  35234. var height = bbox[3] - bbox[1];
  35235. this.ctx.rect(bbox[0], bbox[1], width, height);
  35236. this.clip();
  35237. this.endPath();
  35238. }
  35239. },
  35240. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  35241. this.restore();
  35242. this.baseTransform = this.baseTransformStack.pop();
  35243. },
  35244. beginGroup: function CanvasGraphics_beginGroup(group) {
  35245. this.save();
  35246. var currentCtx = this.ctx;
  35247. // TODO non-isolated groups - according to Rik at adobe non-isolated
  35248. // group results aren't usually that different and they even have tools
  35249. // that ignore this setting. Notes from Rik on implementing:
  35250. // - When you encounter an transparency group, create a new canvas with
  35251. // the dimensions of the bbox
  35252. // - copy the content from the previous canvas to the new canvas
  35253. // - draw as usual
  35254. // - remove the backdrop alpha:
  35255. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  35256. // value of your transparency group and 'alphaBackdrop' the alpha of the
  35257. // backdrop
  35258. // - remove background color:
  35259. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  35260. if (!group.isolated) {
  35261. info('TODO: Support non-isolated groups.');
  35262. }
  35263. // TODO knockout - supposedly possible with the clever use of compositing
  35264. // modes.
  35265. if (group.knockout) {
  35266. warn('Knockout groups not supported.');
  35267. }
  35268. var currentTransform = currentCtx.mozCurrentTransform;
  35269. if (group.matrix) {
  35270. currentCtx.transform.apply(currentCtx, group.matrix);
  35271. }
  35272. assert(group.bbox, 'Bounding box is required.');
  35273. // Based on the current transform figure out how big the bounding box
  35274. // will actually be.
  35275. var bounds = Util.getAxialAlignedBoundingBox(
  35276. group.bbox,
  35277. currentCtx.mozCurrentTransform);
  35278. // Clip the bounding box to the current canvas.
  35279. var canvasBounds = [0,
  35280. 0,
  35281. currentCtx.canvas.width,
  35282. currentCtx.canvas.height];
  35283. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  35284. // Use ceil in case we're between sizes so we don't create canvas that is
  35285. // too small and make the canvas at least 1x1 pixels.
  35286. var offsetX = Math.floor(bounds[0]);
  35287. var offsetY = Math.floor(bounds[1]);
  35288. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  35289. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  35290. var scaleX = 1, scaleY = 1;
  35291. if (drawnWidth > MAX_GROUP_SIZE) {
  35292. scaleX = drawnWidth / MAX_GROUP_SIZE;
  35293. drawnWidth = MAX_GROUP_SIZE;
  35294. }
  35295. if (drawnHeight > MAX_GROUP_SIZE) {
  35296. scaleY = drawnHeight / MAX_GROUP_SIZE;
  35297. drawnHeight = MAX_GROUP_SIZE;
  35298. }
  35299. var cacheId = 'groupAt' + this.groupLevel;
  35300. if (group.smask) {
  35301. // Using two cache entries is case if masks are used one after another.
  35302. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  35303. }
  35304. var scratchCanvas = this.cachedCanvases.getCanvas(
  35305. cacheId, drawnWidth, drawnHeight, true);
  35306. var groupCtx = scratchCanvas.context;
  35307. // Since we created a new canvas that is just the size of the bounding box
  35308. // we have to translate the group ctx.
  35309. groupCtx.scale(1 / scaleX, 1 / scaleY);
  35310. groupCtx.translate(-offsetX, -offsetY);
  35311. groupCtx.transform.apply(groupCtx, currentTransform);
  35312. if (group.smask) {
  35313. // Saving state and cached mask to be used in setGState.
  35314. this.smaskStack.push({
  35315. canvas: scratchCanvas.canvas,
  35316. context: groupCtx,
  35317. offsetX: offsetX,
  35318. offsetY: offsetY,
  35319. scaleX: scaleX,
  35320. scaleY: scaleY,
  35321. subtype: group.smask.subtype,
  35322. backdrop: group.smask.backdrop,
  35323. transferMap: group.smask.transferMap || null,
  35324. startTransformInverse: null, // used during suspend operation
  35325. });
  35326. } else {
  35327. // Setup the current ctx so when the group is popped we draw it at the
  35328. // right location.
  35329. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  35330. currentCtx.translate(offsetX, offsetY);
  35331. currentCtx.scale(scaleX, scaleY);
  35332. }
  35333. // The transparency group inherits all off the current graphics state
  35334. // except the blend mode, soft mask, and alpha constants.
  35335. copyCtxState(currentCtx, groupCtx);
  35336. this.ctx = groupCtx;
  35337. this.setGState([
  35338. ['BM', 'Normal'],
  35339. ['ca', 1],
  35340. ['CA', 1]
  35341. ]);
  35342. this.groupStack.push(currentCtx);
  35343. this.groupLevel++;
  35344. // Reseting mask state, masks will be applied on restore of the group.
  35345. this.current.activeSMask = null;
  35346. },
  35347. endGroup: function CanvasGraphics_endGroup(group) {
  35348. this.groupLevel--;
  35349. var groupCtx = this.ctx;
  35350. this.ctx = this.groupStack.pop();
  35351. // Turn off image smoothing to avoid sub pixel interpolation which can
  35352. // look kind of blurry for some pdfs.
  35353. if (this.ctx.imageSmoothingEnabled !== undefined) {
  35354. this.ctx.imageSmoothingEnabled = false;
  35355. } else {
  35356. this.ctx.mozImageSmoothingEnabled = false;
  35357. }
  35358. if (group.smask) {
  35359. this.tempSMask = this.smaskStack.pop();
  35360. } else {
  35361. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  35362. }
  35363. this.restore();
  35364. },
  35365. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  35366. this.save();
  35367. this.current = new CanvasExtraState();
  35368. if (this.baseTransform) {
  35369. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  35370. }
  35371. },
  35372. endAnnotations: function CanvasGraphics_endAnnotations() {
  35373. this.restore();
  35374. },
  35375. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  35376. matrix) {
  35377. this.save();
  35378. if (isArray(rect) && 4 === rect.length) {
  35379. var width = rect[2] - rect[0];
  35380. var height = rect[3] - rect[1];
  35381. this.ctx.rect(rect[0], rect[1], width, height);
  35382. this.clip();
  35383. this.endPath();
  35384. }
  35385. this.transform.apply(this, transform);
  35386. this.transform.apply(this, matrix);
  35387. },
  35388. endAnnotation: function CanvasGraphics_endAnnotation() {
  35389. this.restore();
  35390. },
  35391. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  35392. var domImage = this.objs.get(objId);
  35393. if (!domImage) {
  35394. warn('Dependent image isn\'t ready yet');
  35395. return;
  35396. }
  35397. this.save();
  35398. var ctx = this.ctx;
  35399. // scale the image to the unit square
  35400. ctx.scale(1 / w, -1 / h);
  35401. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  35402. 0, -h, w, h);
  35403. if (this.imageLayer) {
  35404. var currentTransform = ctx.mozCurrentTransformInverse;
  35405. var position = this.getCanvasPosition(0, 0);
  35406. this.imageLayer.appendImage({
  35407. objId: objId,
  35408. left: position[0],
  35409. top: position[1],
  35410. width: w / currentTransform[0],
  35411. height: h / currentTransform[3]
  35412. });
  35413. }
  35414. this.restore();
  35415. },
  35416. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  35417. var ctx = this.ctx;
  35418. var width = img.width, height = img.height;
  35419. var fillColor = this.current.fillColor;
  35420. var isPatternFill = this.current.patternFill;
  35421. var glyph = this.processingType3;
  35422. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  35423. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  35424. glyph.compiled =
  35425. compileType3Glyph({data: img.data, width: width, height: height});
  35426. } else {
  35427. glyph.compiled = null;
  35428. }
  35429. }
  35430. if (glyph && glyph.compiled) {
  35431. glyph.compiled(ctx);
  35432. return;
  35433. }
  35434. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35435. width, height);
  35436. var maskCtx = maskCanvas.context;
  35437. maskCtx.save();
  35438. putBinaryImageMask(maskCtx, img);
  35439. maskCtx.globalCompositeOperation = 'source-in';
  35440. maskCtx.fillStyle = isPatternFill ?
  35441. fillColor.getPattern(maskCtx, this) : fillColor;
  35442. maskCtx.fillRect(0, 0, width, height);
  35443. maskCtx.restore();
  35444. this.paintInlineImageXObject(maskCanvas.canvas);
  35445. },
  35446. paintImageMaskXObjectRepeat:
  35447. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  35448. scaleY, positions) {
  35449. var width = imgData.width;
  35450. var height = imgData.height;
  35451. var fillColor = this.current.fillColor;
  35452. var isPatternFill = this.current.patternFill;
  35453. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35454. width, height);
  35455. var maskCtx = maskCanvas.context;
  35456. maskCtx.save();
  35457. putBinaryImageMask(maskCtx, imgData);
  35458. maskCtx.globalCompositeOperation = 'source-in';
  35459. maskCtx.fillStyle = isPatternFill ?
  35460. fillColor.getPattern(maskCtx, this) : fillColor;
  35461. maskCtx.fillRect(0, 0, width, height);
  35462. maskCtx.restore();
  35463. var ctx = this.ctx;
  35464. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  35465. ctx.save();
  35466. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  35467. ctx.scale(1, -1);
  35468. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  35469. 0, -1, 1, 1);
  35470. ctx.restore();
  35471. }
  35472. },
  35473. paintImageMaskXObjectGroup:
  35474. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  35475. var ctx = this.ctx;
  35476. var fillColor = this.current.fillColor;
  35477. var isPatternFill = this.current.patternFill;
  35478. for (var i = 0, ii = images.length; i < ii; i++) {
  35479. var image = images[i];
  35480. var width = image.width, height = image.height;
  35481. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  35482. width, height);
  35483. var maskCtx = maskCanvas.context;
  35484. maskCtx.save();
  35485. putBinaryImageMask(maskCtx, image);
  35486. maskCtx.globalCompositeOperation = 'source-in';
  35487. maskCtx.fillStyle = isPatternFill ?
  35488. fillColor.getPattern(maskCtx, this) : fillColor;
  35489. maskCtx.fillRect(0, 0, width, height);
  35490. maskCtx.restore();
  35491. ctx.save();
  35492. ctx.transform.apply(ctx, image.transform);
  35493. ctx.scale(1, -1);
  35494. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  35495. 0, -1, 1, 1);
  35496. ctx.restore();
  35497. }
  35498. },
  35499. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  35500. var imgData = this.objs.get(objId);
  35501. if (!imgData) {
  35502. warn('Dependent image isn\'t ready yet');
  35503. return;
  35504. }
  35505. this.paintInlineImageXObject(imgData);
  35506. },
  35507. paintImageXObjectRepeat:
  35508. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  35509. positions) {
  35510. var imgData = this.objs.get(objId);
  35511. if (!imgData) {
  35512. warn('Dependent image isn\'t ready yet');
  35513. return;
  35514. }
  35515. var width = imgData.width;
  35516. var height = imgData.height;
  35517. var map = [];
  35518. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  35519. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  35520. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  35521. }
  35522. this.paintInlineImageXObjectGroup(imgData, map);
  35523. },
  35524. paintInlineImageXObject:
  35525. function CanvasGraphics_paintInlineImageXObject(imgData) {
  35526. var width = imgData.width;
  35527. var height = imgData.height;
  35528. var ctx = this.ctx;
  35529. this.save();
  35530. // scale the image to the unit square
  35531. ctx.scale(1 / width, -1 / height);
  35532. var currentTransform = ctx.mozCurrentTransformInverse;
  35533. var a = currentTransform[0], b = currentTransform[1];
  35534. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  35535. var c = currentTransform[2], d = currentTransform[3];
  35536. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  35537. var imgToPaint, tmpCanvas;
  35538. // instanceof HTMLElement does not work in jsdom node.js module
  35539. if (imgData instanceof HTMLElement || !imgData.data) {
  35540. imgToPaint = imgData;
  35541. } else {
  35542. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  35543. width, height);
  35544. var tmpCtx = tmpCanvas.context;
  35545. putBinaryImageData(tmpCtx, imgData);
  35546. imgToPaint = tmpCanvas.canvas;
  35547. }
  35548. var paintWidth = width, paintHeight = height;
  35549. var tmpCanvasId = 'prescale1';
  35550. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  35551. // pixels during drawImage operation, painting on the temporary canvas(es)
  35552. // that are twice smaller in size
  35553. while ((widthScale > 2 && paintWidth > 1) ||
  35554. (heightScale > 2 && paintHeight > 1)) {
  35555. var newWidth = paintWidth, newHeight = paintHeight;
  35556. if (widthScale > 2 && paintWidth > 1) {
  35557. newWidth = Math.ceil(paintWidth / 2);
  35558. widthScale /= paintWidth / newWidth;
  35559. }
  35560. if (heightScale > 2 && paintHeight > 1) {
  35561. newHeight = Math.ceil(paintHeight / 2);
  35562. heightScale /= paintHeight / newHeight;
  35563. }
  35564. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  35565. newWidth, newHeight);
  35566. tmpCtx = tmpCanvas.context;
  35567. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  35568. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  35569. 0, 0, newWidth, newHeight);
  35570. imgToPaint = tmpCanvas.canvas;
  35571. paintWidth = newWidth;
  35572. paintHeight = newHeight;
  35573. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  35574. }
  35575. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  35576. 0, -height, width, height);
  35577. if (this.imageLayer) {
  35578. var position = this.getCanvasPosition(0, -height);
  35579. this.imageLayer.appendImage({
  35580. imgData: imgData,
  35581. left: position[0],
  35582. top: position[1],
  35583. width: width / currentTransform[0],
  35584. height: height / currentTransform[3]
  35585. });
  35586. }
  35587. this.restore();
  35588. },
  35589. paintInlineImageXObjectGroup:
  35590. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  35591. var ctx = this.ctx;
  35592. var w = imgData.width;
  35593. var h = imgData.height;
  35594. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  35595. var tmpCtx = tmpCanvas.context;
  35596. putBinaryImageData(tmpCtx, imgData);
  35597. for (var i = 0, ii = map.length; i < ii; i++) {
  35598. var entry = map[i];
  35599. ctx.save();
  35600. ctx.transform.apply(ctx, entry.transform);
  35601. ctx.scale(1, -1);
  35602. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  35603. 0, -1, 1, 1);
  35604. if (this.imageLayer) {
  35605. var position = this.getCanvasPosition(entry.x, entry.y);
  35606. this.imageLayer.appendImage({
  35607. imgData: imgData,
  35608. left: position[0],
  35609. top: position[1],
  35610. width: w,
  35611. height: h
  35612. });
  35613. }
  35614. ctx.restore();
  35615. }
  35616. },
  35617. paintSolidColorImageMask:
  35618. function CanvasGraphics_paintSolidColorImageMask() {
  35619. this.ctx.fillRect(0, 0, 1, 1);
  35620. },
  35621. paintXObject: function CanvasGraphics_paintXObject() {
  35622. warn('Unsupported \'paintXObject\' command.');
  35623. },
  35624. // Marked content
  35625. markPoint: function CanvasGraphics_markPoint(tag) {
  35626. // TODO Marked content.
  35627. },
  35628. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  35629. // TODO Marked content.
  35630. },
  35631. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  35632. // TODO Marked content.
  35633. },
  35634. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  35635. tag, properties) {
  35636. // TODO Marked content.
  35637. },
  35638. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  35639. // TODO Marked content.
  35640. },
  35641. // Compatibility
  35642. beginCompat: function CanvasGraphics_beginCompat() {
  35643. // TODO ignore undefined operators (should we do that anyway?)
  35644. },
  35645. endCompat: function CanvasGraphics_endCompat() {
  35646. // TODO stop ignoring undefined operators
  35647. },
  35648. // Helper functions
  35649. consumePath: function CanvasGraphics_consumePath() {
  35650. var ctx = this.ctx;
  35651. if (this.pendingClip) {
  35652. if (this.pendingClip === EO_CLIP) {
  35653. if (ctx.mozFillRule !== undefined) {
  35654. ctx.mozFillRule = 'evenodd';
  35655. ctx.clip();
  35656. ctx.mozFillRule = 'nonzero';
  35657. } else {
  35658. ctx.clip('evenodd');
  35659. }
  35660. } else {
  35661. ctx.clip();
  35662. }
  35663. this.pendingClip = null;
  35664. }
  35665. ctx.beginPath();
  35666. },
  35667. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  35668. if (this.cachedGetSinglePixelWidth === null) {
  35669. // NOTE: The `save` and `restore` commands used below is a workaround
  35670. // that is necessary in order to prevent `mozCurrentTransformInverse`
  35671. // from intermittently returning incorrect values in Firefox, see:
  35672. // https://github.com/mozilla/pdf.js/issues/7188.
  35673. this.ctx.save();
  35674. var inverse = this.ctx.mozCurrentTransformInverse;
  35675. this.ctx.restore();
  35676. // max of the current horizontal and vertical scale
  35677. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  35678. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  35679. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  35680. }
  35681. return this.cachedGetSinglePixelWidth;
  35682. },
  35683. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  35684. var transform = this.ctx.mozCurrentTransform;
  35685. return [
  35686. transform[0] * x + transform[2] * y + transform[4],
  35687. transform[1] * x + transform[3] * y + transform[5]
  35688. ];
  35689. }
  35690. };
  35691. for (var op in OPS) {
  35692. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  35693. }
  35694. return CanvasGraphics;
  35695. })();
  35696. exports.CanvasGraphics = CanvasGraphics;
  35697. exports.createScratchCanvas = createScratchCanvas;
  35698. }));
  35699. (function (root, factory) {
  35700. {
  35701. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  35702. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  35703. }
  35704. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  35705. var error = sharedUtil.error;
  35706. var info = sharedUtil.info;
  35707. var isArray = sharedUtil.isArray;
  35708. var isBool = sharedUtil.isBool;
  35709. var isDict = corePrimitives.isDict;
  35710. var isStream = corePrimitives.isStream;
  35711. var PostScriptLexer = corePsParser.PostScriptLexer;
  35712. var PostScriptParser = corePsParser.PostScriptParser;
  35713. var PDFFunction = (function PDFFunctionClosure() {
  35714. var CONSTRUCT_SAMPLED = 0;
  35715. var CONSTRUCT_INTERPOLATED = 2;
  35716. var CONSTRUCT_STICHED = 3;
  35717. var CONSTRUCT_POSTSCRIPT = 4;
  35718. return {
  35719. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  35720. str) {
  35721. var i, ii;
  35722. var length = 1;
  35723. for (i = 0, ii = size.length; i < ii; i++) {
  35724. length *= size[i];
  35725. }
  35726. length *= outputSize;
  35727. var array = new Array(length);
  35728. var codeSize = 0;
  35729. var codeBuf = 0;
  35730. // 32 is a valid bps so shifting won't work
  35731. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  35732. var strBytes = str.getBytes((length * bps + 7) / 8);
  35733. var strIdx = 0;
  35734. for (i = 0; i < length; i++) {
  35735. while (codeSize < bps) {
  35736. codeBuf <<= 8;
  35737. codeBuf |= strBytes[strIdx++];
  35738. codeSize += 8;
  35739. }
  35740. codeSize -= bps;
  35741. array[i] = (codeBuf >> codeSize) * sampleMul;
  35742. codeBuf &= (1 << codeSize) - 1;
  35743. }
  35744. return array;
  35745. },
  35746. getIR: function PDFFunction_getIR(xref, fn) {
  35747. var dict = fn.dict;
  35748. if (!dict) {
  35749. dict = fn;
  35750. }
  35751. var types = [this.constructSampled,
  35752. null,
  35753. this.constructInterpolated,
  35754. this.constructStiched,
  35755. this.constructPostScript];
  35756. var typeNum = dict.get('FunctionType');
  35757. var typeFn = types[typeNum];
  35758. if (!typeFn) {
  35759. error('Unknown type of function');
  35760. }
  35761. return typeFn.call(this, fn, dict, xref);
  35762. },
  35763. fromIR: function PDFFunction_fromIR(IR) {
  35764. var type = IR[0];
  35765. switch (type) {
  35766. case CONSTRUCT_SAMPLED:
  35767. return this.constructSampledFromIR(IR);
  35768. case CONSTRUCT_INTERPOLATED:
  35769. return this.constructInterpolatedFromIR(IR);
  35770. case CONSTRUCT_STICHED:
  35771. return this.constructStichedFromIR(IR);
  35772. //case CONSTRUCT_POSTSCRIPT:
  35773. default:
  35774. return this.constructPostScriptFromIR(IR);
  35775. }
  35776. },
  35777. parse: function PDFFunction_parse(xref, fn) {
  35778. var IR = this.getIR(xref, fn);
  35779. return this.fromIR(IR);
  35780. },
  35781. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  35782. if (!isArray(fnObj)) {
  35783. // not an array -- parsing as regular function
  35784. return this.parse(xref, fnObj);
  35785. }
  35786. var fnArray = [];
  35787. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  35788. var obj = xref.fetchIfRef(fnObj[j]);
  35789. fnArray.push(PDFFunction.parse(xref, obj));
  35790. }
  35791. return function (src, srcOffset, dest, destOffset) {
  35792. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  35793. fnArray[i](src, srcOffset, dest, destOffset + i);
  35794. }
  35795. };
  35796. },
  35797. constructSampled: function PDFFunction_constructSampled(str, dict) {
  35798. function toMultiArray(arr) {
  35799. var inputLength = arr.length;
  35800. var out = [];
  35801. var index = 0;
  35802. for (var i = 0; i < inputLength; i += 2) {
  35803. out[index] = [arr[i], arr[i + 1]];
  35804. ++index;
  35805. }
  35806. return out;
  35807. }
  35808. var domain = dict.getArray('Domain');
  35809. var range = dict.getArray('Range');
  35810. if (!domain || !range) {
  35811. error('No domain or range');
  35812. }
  35813. var inputSize = domain.length / 2;
  35814. var outputSize = range.length / 2;
  35815. domain = toMultiArray(domain);
  35816. range = toMultiArray(range);
  35817. var size = dict.get('Size');
  35818. var bps = dict.get('BitsPerSample');
  35819. var order = dict.get('Order') || 1;
  35820. if (order !== 1) {
  35821. // No description how cubic spline interpolation works in PDF32000:2008
  35822. // As in poppler, ignoring order, linear interpolation may work as good
  35823. info('No support for cubic spline interpolation: ' + order);
  35824. }
  35825. var encode = dict.getArray('Encode');
  35826. if (!encode) {
  35827. encode = [];
  35828. for (var i = 0; i < inputSize; ++i) {
  35829. encode.push(0);
  35830. encode.push(size[i] - 1);
  35831. }
  35832. }
  35833. encode = toMultiArray(encode);
  35834. var decode = dict.getArray('Decode');
  35835. if (!decode) {
  35836. decode = range;
  35837. } else {
  35838. decode = toMultiArray(decode);
  35839. }
  35840. var samples = this.getSampleArray(size, outputSize, bps, str);
  35841. return [
  35842. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  35843. outputSize, Math.pow(2, bps) - 1, range
  35844. ];
  35845. },
  35846. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  35847. // See chapter 3, page 109 of the PDF reference
  35848. function interpolate(x, xmin, xmax, ymin, ymax) {
  35849. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  35850. }
  35851. return function constructSampledFromIRResult(src, srcOffset,
  35852. dest, destOffset) {
  35853. // See chapter 3, page 110 of the PDF reference.
  35854. var m = IR[1];
  35855. var domain = IR[2];
  35856. var encode = IR[3];
  35857. var decode = IR[4];
  35858. var samples = IR[5];
  35859. var size = IR[6];
  35860. var n = IR[7];
  35861. //var mask = IR[8];
  35862. var range = IR[9];
  35863. // Building the cube vertices: its part and sample index
  35864. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  35865. var cubeVertices = 1 << m;
  35866. var cubeN = new Float64Array(cubeVertices);
  35867. var cubeVertex = new Uint32Array(cubeVertices);
  35868. var i, j;
  35869. for (j = 0; j < cubeVertices; j++) {
  35870. cubeN[j] = 1;
  35871. }
  35872. var k = n, pos = 1;
  35873. // Map x_i to y_j for 0 <= i < m using the sampled function.
  35874. for (i = 0; i < m; ++i) {
  35875. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  35876. var domain_2i = domain[i][0];
  35877. var domain_2i_1 = domain[i][1];
  35878. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  35879. domain_2i_1);
  35880. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  35881. // Encode_2i, Encode_2i+1)
  35882. var e = interpolate(xi, domain_2i, domain_2i_1,
  35883. encode[i][0], encode[i][1]);
  35884. // e_i' = min(max(e_i, 0), Size_i - 1)
  35885. var size_i = size[i];
  35886. e = Math.min(Math.max(e, 0), size_i - 1);
  35887. // Adjusting the cube: N and vertex sample index
  35888. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  35889. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  35890. var n1 = e - e0; // (e - e0) / (e1 - e0);
  35891. var offset0 = e0 * k;
  35892. var offset1 = offset0 + k; // e1 * k
  35893. for (j = 0; j < cubeVertices; j++) {
  35894. if (j & pos) {
  35895. cubeN[j] *= n1;
  35896. cubeVertex[j] += offset1;
  35897. } else {
  35898. cubeN[j] *= n0;
  35899. cubeVertex[j] += offset0;
  35900. }
  35901. }
  35902. k *= size_i;
  35903. pos <<= 1;
  35904. }
  35905. for (j = 0; j < n; ++j) {
  35906. // Sum all cube vertices' samples portions
  35907. var rj = 0;
  35908. for (i = 0; i < cubeVertices; i++) {
  35909. rj += samples[cubeVertex[i] + j] * cubeN[i];
  35910. }
  35911. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  35912. // Decode_2j, Decode_2j+1)
  35913. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  35914. // y_j = min(max(r_j, range_2j), range_2j+1)
  35915. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  35916. range[j][1]);
  35917. }
  35918. };
  35919. },
  35920. constructInterpolated: function PDFFunction_constructInterpolated(str,
  35921. dict) {
  35922. var c0 = dict.getArray('C0') || [0];
  35923. var c1 = dict.getArray('C1') || [1];
  35924. var n = dict.get('N');
  35925. if (!isArray(c0) || !isArray(c1)) {
  35926. error('Illegal dictionary for interpolated function');
  35927. }
  35928. var length = c0.length;
  35929. var diff = [];
  35930. for (var i = 0; i < length; ++i) {
  35931. diff.push(c1[i] - c0[i]);
  35932. }
  35933. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  35934. },
  35935. constructInterpolatedFromIR:
  35936. function PDFFunction_constructInterpolatedFromIR(IR) {
  35937. var c0 = IR[1];
  35938. var diff = IR[2];
  35939. var n = IR[3];
  35940. var length = diff.length;
  35941. return function constructInterpolatedFromIRResult(src, srcOffset,
  35942. dest, destOffset) {
  35943. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  35944. for (var j = 0; j < length; ++j) {
  35945. dest[destOffset + j] = c0[j] + (x * diff[j]);
  35946. }
  35947. };
  35948. },
  35949. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  35950. var domain = dict.getArray('Domain');
  35951. if (!domain) {
  35952. error('No domain');
  35953. }
  35954. var inputSize = domain.length / 2;
  35955. if (inputSize !== 1) {
  35956. error('Bad domain for stiched function');
  35957. }
  35958. var fnRefs = dict.get('Functions');
  35959. var fns = [];
  35960. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  35961. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  35962. }
  35963. var bounds = dict.getArray('Bounds');
  35964. var encode = dict.getArray('Encode');
  35965. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  35966. },
  35967. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  35968. var domain = IR[1];
  35969. var bounds = IR[2];
  35970. var encode = IR[3];
  35971. var fnsIR = IR[4];
  35972. var fns = [];
  35973. var tmpBuf = new Float32Array(1);
  35974. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  35975. fns.push(PDFFunction.fromIR(fnsIR[i]));
  35976. }
  35977. return function constructStichedFromIRResult(src, srcOffset,
  35978. dest, destOffset) {
  35979. var clip = function constructStichedFromIRClip(v, min, max) {
  35980. if (v > max) {
  35981. v = max;
  35982. } else if (v < min) {
  35983. v = min;
  35984. }
  35985. return v;
  35986. };
  35987. // clip to domain
  35988. var v = clip(src[srcOffset], domain[0], domain[1]);
  35989. // calculate which bound the value is in
  35990. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  35991. if (v < bounds[i]) {
  35992. break;
  35993. }
  35994. }
  35995. // encode value into domain of function
  35996. var dmin = domain[0];
  35997. if (i > 0) {
  35998. dmin = bounds[i - 1];
  35999. }
  36000. var dmax = domain[1];
  36001. if (i < bounds.length) {
  36002. dmax = bounds[i];
  36003. }
  36004. var rmin = encode[2 * i];
  36005. var rmax = encode[2 * i + 1];
  36006. // Prevent the value from becoming NaN as a result
  36007. // of division by zero (fixes issue6113.pdf).
  36008. tmpBuf[0] = dmin === dmax ? rmin :
  36009. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  36010. // call the appropriate function
  36011. fns[i](tmpBuf, 0, dest, destOffset);
  36012. };
  36013. },
  36014. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  36015. xref) {
  36016. var domain = dict.getArray('Domain');
  36017. var range = dict.getArray('Range');
  36018. if (!domain) {
  36019. error('No domain.');
  36020. }
  36021. if (!range) {
  36022. error('No range.');
  36023. }
  36024. var lexer = new PostScriptLexer(fn);
  36025. var parser = new PostScriptParser(lexer);
  36026. var code = parser.parse();
  36027. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  36028. },
  36029. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  36030. IR) {
  36031. var domain = IR[1];
  36032. var range = IR[2];
  36033. var code = IR[3];
  36034. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  36035. if (compiled) {
  36036. // Compiled function consists of simple expressions such as addition,
  36037. // subtraction, Math.max, and also contains 'var' and 'return'
  36038. // statements. See the generation in the PostScriptCompiler below.
  36039. /*jshint -W054 */
  36040. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  36041. }
  36042. info('Unable to compile PS function');
  36043. var numOutputs = range.length >> 1;
  36044. var numInputs = domain.length >> 1;
  36045. var evaluator = new PostScriptEvaluator(code);
  36046. // Cache the values for a big speed up, the cache size is limited though
  36047. // since the number of possible values can be huge from a PS function.
  36048. var cache = Object.create(null);
  36049. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  36050. // seen in our tests.
  36051. var MAX_CACHE_SIZE = 2048 * 4;
  36052. var cache_available = MAX_CACHE_SIZE;
  36053. var tmpBuf = new Float32Array(numInputs);
  36054. return function constructPostScriptFromIRResult(src, srcOffset,
  36055. dest, destOffset) {
  36056. var i, value;
  36057. var key = '';
  36058. var input = tmpBuf;
  36059. for (i = 0; i < numInputs; i++) {
  36060. value = src[srcOffset + i];
  36061. input[i] = value;
  36062. key += value + '_';
  36063. }
  36064. var cachedValue = cache[key];
  36065. if (cachedValue !== undefined) {
  36066. dest.set(cachedValue, destOffset);
  36067. return;
  36068. }
  36069. var output = new Float32Array(numOutputs);
  36070. var stack = evaluator.execute(input);
  36071. var stackIndex = stack.length - numOutputs;
  36072. for (i = 0; i < numOutputs; i++) {
  36073. value = stack[stackIndex + i];
  36074. var bound = range[i * 2];
  36075. if (value < bound) {
  36076. value = bound;
  36077. } else {
  36078. bound = range[i * 2 +1];
  36079. if (value > bound) {
  36080. value = bound;
  36081. }
  36082. }
  36083. output[i] = value;
  36084. }
  36085. if (cache_available > 0) {
  36086. cache_available--;
  36087. cache[key] = output;
  36088. }
  36089. dest.set(output, destOffset);
  36090. };
  36091. }
  36092. };
  36093. })();
  36094. function isPDFFunction(v) {
  36095. var fnDict;
  36096. if (typeof v !== 'object') {
  36097. return false;
  36098. } else if (isDict(v)) {
  36099. fnDict = v;
  36100. } else if (isStream(v)) {
  36101. fnDict = v.dict;
  36102. } else {
  36103. return false;
  36104. }
  36105. return fnDict.has('FunctionType');
  36106. }
  36107. var PostScriptStack = (function PostScriptStackClosure() {
  36108. var MAX_STACK_SIZE = 100;
  36109. function PostScriptStack(initialStack) {
  36110. this.stack = !initialStack ? [] :
  36111. Array.prototype.slice.call(initialStack, 0);
  36112. }
  36113. PostScriptStack.prototype = {
  36114. push: function PostScriptStack_push(value) {
  36115. if (this.stack.length >= MAX_STACK_SIZE) {
  36116. error('PostScript function stack overflow.');
  36117. }
  36118. this.stack.push(value);
  36119. },
  36120. pop: function PostScriptStack_pop() {
  36121. if (this.stack.length <= 0) {
  36122. error('PostScript function stack underflow.');
  36123. }
  36124. return this.stack.pop();
  36125. },
  36126. copy: function PostScriptStack_copy(n) {
  36127. if (this.stack.length + n >= MAX_STACK_SIZE) {
  36128. error('PostScript function stack overflow.');
  36129. }
  36130. var stack = this.stack;
  36131. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  36132. stack.push(stack[i]);
  36133. }
  36134. },
  36135. index: function PostScriptStack_index(n) {
  36136. this.push(this.stack[this.stack.length - n - 1]);
  36137. },
  36138. // rotate the last n stack elements p times
  36139. roll: function PostScriptStack_roll(n, p) {
  36140. var stack = this.stack;
  36141. var l = stack.length - n;
  36142. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  36143. for (i = l, j = r; i < j; i++, j--) {
  36144. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  36145. }
  36146. for (i = l, j = c - 1; i < j; i++, j--) {
  36147. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  36148. }
  36149. for (i = c, j = r; i < j; i++, j--) {
  36150. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  36151. }
  36152. }
  36153. };
  36154. return PostScriptStack;
  36155. })();
  36156. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  36157. function PostScriptEvaluator(operators) {
  36158. this.operators = operators;
  36159. }
  36160. PostScriptEvaluator.prototype = {
  36161. execute: function PostScriptEvaluator_execute(initialStack) {
  36162. var stack = new PostScriptStack(initialStack);
  36163. var counter = 0;
  36164. var operators = this.operators;
  36165. var length = operators.length;
  36166. var operator, a, b;
  36167. while (counter < length) {
  36168. operator = operators[counter++];
  36169. if (typeof operator === 'number') {
  36170. // Operator is really an operand and should be pushed to the stack.
  36171. stack.push(operator);
  36172. continue;
  36173. }
  36174. switch (operator) {
  36175. // non standard ps operators
  36176. case 'jz': // jump if false
  36177. b = stack.pop();
  36178. a = stack.pop();
  36179. if (!a) {
  36180. counter = b;
  36181. }
  36182. break;
  36183. case 'j': // jump
  36184. a = stack.pop();
  36185. counter = a;
  36186. break;
  36187. // all ps operators in alphabetical order (excluding if/ifelse)
  36188. case 'abs':
  36189. a = stack.pop();
  36190. stack.push(Math.abs(a));
  36191. break;
  36192. case 'add':
  36193. b = stack.pop();
  36194. a = stack.pop();
  36195. stack.push(a + b);
  36196. break;
  36197. case 'and':
  36198. b = stack.pop();
  36199. a = stack.pop();
  36200. if (isBool(a) && isBool(b)) {
  36201. stack.push(a && b);
  36202. } else {
  36203. stack.push(a & b);
  36204. }
  36205. break;
  36206. case 'atan':
  36207. a = stack.pop();
  36208. stack.push(Math.atan(a));
  36209. break;
  36210. case 'bitshift':
  36211. b = stack.pop();
  36212. a = stack.pop();
  36213. if (a > 0) {
  36214. stack.push(a << b);
  36215. } else {
  36216. stack.push(a >> b);
  36217. }
  36218. break;
  36219. case 'ceiling':
  36220. a = stack.pop();
  36221. stack.push(Math.ceil(a));
  36222. break;
  36223. case 'copy':
  36224. a = stack.pop();
  36225. stack.copy(a);
  36226. break;
  36227. case 'cos':
  36228. a = stack.pop();
  36229. stack.push(Math.cos(a));
  36230. break;
  36231. case 'cvi':
  36232. a = stack.pop() | 0;
  36233. stack.push(a);
  36234. break;
  36235. case 'cvr':
  36236. // noop
  36237. break;
  36238. case 'div':
  36239. b = stack.pop();
  36240. a = stack.pop();
  36241. stack.push(a / b);
  36242. break;
  36243. case 'dup':
  36244. stack.copy(1);
  36245. break;
  36246. case 'eq':
  36247. b = stack.pop();
  36248. a = stack.pop();
  36249. stack.push(a === b);
  36250. break;
  36251. case 'exch':
  36252. stack.roll(2, 1);
  36253. break;
  36254. case 'exp':
  36255. b = stack.pop();
  36256. a = stack.pop();
  36257. stack.push(Math.pow(a, b));
  36258. break;
  36259. case 'false':
  36260. stack.push(false);
  36261. break;
  36262. case 'floor':
  36263. a = stack.pop();
  36264. stack.push(Math.floor(a));
  36265. break;
  36266. case 'ge':
  36267. b = stack.pop();
  36268. a = stack.pop();
  36269. stack.push(a >= b);
  36270. break;
  36271. case 'gt':
  36272. b = stack.pop();
  36273. a = stack.pop();
  36274. stack.push(a > b);
  36275. break;
  36276. case 'idiv':
  36277. b = stack.pop();
  36278. a = stack.pop();
  36279. stack.push((a / b) | 0);
  36280. break;
  36281. case 'index':
  36282. a = stack.pop();
  36283. stack.index(a);
  36284. break;
  36285. case 'le':
  36286. b = stack.pop();
  36287. a = stack.pop();
  36288. stack.push(a <= b);
  36289. break;
  36290. case 'ln':
  36291. a = stack.pop();
  36292. stack.push(Math.log(a));
  36293. break;
  36294. case 'log':
  36295. a = stack.pop();
  36296. stack.push(Math.log(a) / Math.LN10);
  36297. break;
  36298. case 'lt':
  36299. b = stack.pop();
  36300. a = stack.pop();
  36301. stack.push(a < b);
  36302. break;
  36303. case 'mod':
  36304. b = stack.pop();
  36305. a = stack.pop();
  36306. stack.push(a % b);
  36307. break;
  36308. case 'mul':
  36309. b = stack.pop();
  36310. a = stack.pop();
  36311. stack.push(a * b);
  36312. break;
  36313. case 'ne':
  36314. b = stack.pop();
  36315. a = stack.pop();
  36316. stack.push(a !== b);
  36317. break;
  36318. case 'neg':
  36319. a = stack.pop();
  36320. stack.push(-a);
  36321. break;
  36322. case 'not':
  36323. a = stack.pop();
  36324. if (isBool(a)) {
  36325. stack.push(!a);
  36326. } else {
  36327. stack.push(~a);
  36328. }
  36329. break;
  36330. case 'or':
  36331. b = stack.pop();
  36332. a = stack.pop();
  36333. if (isBool(a) && isBool(b)) {
  36334. stack.push(a || b);
  36335. } else {
  36336. stack.push(a | b);
  36337. }
  36338. break;
  36339. case 'pop':
  36340. stack.pop();
  36341. break;
  36342. case 'roll':
  36343. b = stack.pop();
  36344. a = stack.pop();
  36345. stack.roll(a, b);
  36346. break;
  36347. case 'round':
  36348. a = stack.pop();
  36349. stack.push(Math.round(a));
  36350. break;
  36351. case 'sin':
  36352. a = stack.pop();
  36353. stack.push(Math.sin(a));
  36354. break;
  36355. case 'sqrt':
  36356. a = stack.pop();
  36357. stack.push(Math.sqrt(a));
  36358. break;
  36359. case 'sub':
  36360. b = stack.pop();
  36361. a = stack.pop();
  36362. stack.push(a - b);
  36363. break;
  36364. case 'true':
  36365. stack.push(true);
  36366. break;
  36367. case 'truncate':
  36368. a = stack.pop();
  36369. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  36370. stack.push(a);
  36371. break;
  36372. case 'xor':
  36373. b = stack.pop();
  36374. a = stack.pop();
  36375. if (isBool(a) && isBool(b)) {
  36376. stack.push(a !== b);
  36377. } else {
  36378. stack.push(a ^ b);
  36379. }
  36380. break;
  36381. default:
  36382. error('Unknown operator ' + operator);
  36383. break;
  36384. }
  36385. }
  36386. return stack.stack;
  36387. }
  36388. };
  36389. return PostScriptEvaluator;
  36390. })();
  36391. // Most of the PDFs functions consist of simple operations such as:
  36392. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  36393. //
  36394. // We can compile most of such programs, and at the same moment, we can
  36395. // optimize some expressions using basic math properties. Keeping track of
  36396. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  36397. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  36398. function AstNode(type) {
  36399. this.type = type;
  36400. }
  36401. AstNode.prototype.visit = function (visitor) {
  36402. throw new Error('abstract method');
  36403. };
  36404. function AstArgument(index, min, max) {
  36405. AstNode.call(this, 'args');
  36406. this.index = index;
  36407. this.min = min;
  36408. this.max = max;
  36409. }
  36410. AstArgument.prototype = Object.create(AstNode.prototype);
  36411. AstArgument.prototype.visit = function (visitor) {
  36412. visitor.visitArgument(this);
  36413. };
  36414. function AstLiteral(number) {
  36415. AstNode.call(this, 'literal');
  36416. this.number = number;
  36417. this.min = number;
  36418. this.max = number;
  36419. }
  36420. AstLiteral.prototype = Object.create(AstNode.prototype);
  36421. AstLiteral.prototype.visit = function (visitor) {
  36422. visitor.visitLiteral(this);
  36423. };
  36424. function AstBinaryOperation(op, arg1, arg2, min, max) {
  36425. AstNode.call(this, 'binary');
  36426. this.op = op;
  36427. this.arg1 = arg1;
  36428. this.arg2 = arg2;
  36429. this.min = min;
  36430. this.max = max;
  36431. }
  36432. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  36433. AstBinaryOperation.prototype.visit = function (visitor) {
  36434. visitor.visitBinaryOperation(this);
  36435. };
  36436. function AstMin(arg, max) {
  36437. AstNode.call(this, 'max');
  36438. this.arg = arg;
  36439. this.min = arg.min;
  36440. this.max = max;
  36441. }
  36442. AstMin.prototype = Object.create(AstNode.prototype);
  36443. AstMin.prototype.visit = function (visitor) {
  36444. visitor.visitMin(this);
  36445. };
  36446. function AstVariable(index, min, max) {
  36447. AstNode.call(this, 'var');
  36448. this.index = index;
  36449. this.min = min;
  36450. this.max = max;
  36451. }
  36452. AstVariable.prototype = Object.create(AstNode.prototype);
  36453. AstVariable.prototype.visit = function (visitor) {
  36454. visitor.visitVariable(this);
  36455. };
  36456. function AstVariableDefinition(variable, arg) {
  36457. AstNode.call(this, 'definition');
  36458. this.variable = variable;
  36459. this.arg = arg;
  36460. }
  36461. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  36462. AstVariableDefinition.prototype.visit = function (visitor) {
  36463. visitor.visitVariableDefinition(this);
  36464. };
  36465. function ExpressionBuilderVisitor() {
  36466. this.parts = [];
  36467. }
  36468. ExpressionBuilderVisitor.prototype = {
  36469. visitArgument: function (arg) {
  36470. this.parts.push('Math.max(', arg.min, ', Math.min(',
  36471. arg.max, ', src[srcOffset + ', arg.index, ']))');
  36472. },
  36473. visitVariable: function (variable) {
  36474. this.parts.push('v', variable.index);
  36475. },
  36476. visitLiteral: function (literal) {
  36477. this.parts.push(literal.number);
  36478. },
  36479. visitBinaryOperation: function (operation) {
  36480. this.parts.push('(');
  36481. operation.arg1.visit(this);
  36482. this.parts.push(' ', operation.op, ' ');
  36483. operation.arg2.visit(this);
  36484. this.parts.push(')');
  36485. },
  36486. visitVariableDefinition: function (definition) {
  36487. this.parts.push('var ');
  36488. definition.variable.visit(this);
  36489. this.parts.push(' = ');
  36490. definition.arg.visit(this);
  36491. this.parts.push(';');
  36492. },
  36493. visitMin: function (max) {
  36494. this.parts.push('Math.min(');
  36495. max.arg.visit(this);
  36496. this.parts.push(', ', max.max, ')');
  36497. },
  36498. toString: function () {
  36499. return this.parts.join('');
  36500. }
  36501. };
  36502. function buildAddOperation(num1, num2) {
  36503. if (num2.type === 'literal' && num2.number === 0) {
  36504. // optimization: second operand is 0
  36505. return num1;
  36506. }
  36507. if (num1.type === 'literal' && num1.number === 0) {
  36508. // optimization: first operand is 0
  36509. return num2;
  36510. }
  36511. if (num2.type === 'literal' && num1.type === 'literal') {
  36512. // optimization: operands operand are literals
  36513. return new AstLiteral(num1.number + num2.number);
  36514. }
  36515. return new AstBinaryOperation('+', num1, num2,
  36516. num1.min + num2.min, num1.max + num2.max);
  36517. }
  36518. function buildMulOperation(num1, num2) {
  36519. if (num2.type === 'literal') {
  36520. // optimization: second operands is a literal...
  36521. if (num2.number === 0) {
  36522. return new AstLiteral(0); // and it's 0
  36523. } else if (num2.number === 1) {
  36524. return num1; // and it's 1
  36525. } else if (num1.type === 'literal') {
  36526. // ... and first operands is a literal too
  36527. return new AstLiteral(num1.number * num2.number);
  36528. }
  36529. }
  36530. if (num1.type === 'literal') {
  36531. // optimization: first operands is a literal...
  36532. if (num1.number === 0) {
  36533. return new AstLiteral(0); // and it's 0
  36534. } else if (num1.number === 1) {
  36535. return num2; // and it's 1
  36536. }
  36537. }
  36538. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  36539. num1.max * num2.min, num1.max * num2.max);
  36540. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  36541. num1.max * num2.min, num1.max * num2.max);
  36542. return new AstBinaryOperation('*', num1, num2, min, max);
  36543. }
  36544. function buildSubOperation(num1, num2) {
  36545. if (num2.type === 'literal') {
  36546. // optimization: second operands is a literal...
  36547. if (num2.number === 0) {
  36548. return num1; // ... and it's 0
  36549. } else if (num1.type === 'literal') {
  36550. // ... and first operands is a literal too
  36551. return new AstLiteral(num1.number - num2.number);
  36552. }
  36553. }
  36554. if (num2.type === 'binary' && num2.op === '-' &&
  36555. num1.type === 'literal' && num1.number === 1 &&
  36556. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  36557. // optimization for case: 1 - (1 - x)
  36558. return num2.arg2;
  36559. }
  36560. return new AstBinaryOperation('-', num1, num2,
  36561. num1.min - num2.max, num1.max - num2.min);
  36562. }
  36563. function buildMinOperation(num1, max) {
  36564. if (num1.min >= max) {
  36565. // optimization: num1 min value is not less than required max
  36566. return new AstLiteral(max); // just returning max
  36567. } else if (num1.max <= max) {
  36568. // optimization: num1 max value is not greater than required max
  36569. return num1; // just returning an argument
  36570. }
  36571. return new AstMin(num1, max);
  36572. }
  36573. function PostScriptCompiler() {}
  36574. PostScriptCompiler.prototype = {
  36575. compile: function PostScriptCompiler_compile(code, domain, range) {
  36576. var stack = [];
  36577. var i, ii;
  36578. var instructions = [];
  36579. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  36580. var lastRegister = 0;
  36581. var n, j;
  36582. var num1, num2, ast1, ast2, tmpVar, item;
  36583. for (i = 0; i < inputSize; i++) {
  36584. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  36585. }
  36586. for (i = 0, ii = code.length; i < ii; i++) {
  36587. item = code[i];
  36588. if (typeof item === 'number') {
  36589. stack.push(new AstLiteral(item));
  36590. continue;
  36591. }
  36592. switch (item) {
  36593. case 'add':
  36594. if (stack.length < 2) {
  36595. return null;
  36596. }
  36597. num2 = stack.pop();
  36598. num1 = stack.pop();
  36599. stack.push(buildAddOperation(num1, num2));
  36600. break;
  36601. case 'cvr':
  36602. if (stack.length < 1) {
  36603. return null;
  36604. }
  36605. break;
  36606. case 'mul':
  36607. if (stack.length < 2) {
  36608. return null;
  36609. }
  36610. num2 = stack.pop();
  36611. num1 = stack.pop();
  36612. stack.push(buildMulOperation(num1, num2));
  36613. break;
  36614. case 'sub':
  36615. if (stack.length < 2) {
  36616. return null;
  36617. }
  36618. num2 = stack.pop();
  36619. num1 = stack.pop();
  36620. stack.push(buildSubOperation(num1, num2));
  36621. break;
  36622. case 'exch':
  36623. if (stack.length < 2) {
  36624. return null;
  36625. }
  36626. ast1 = stack.pop(); ast2 = stack.pop();
  36627. stack.push(ast1, ast2);
  36628. break;
  36629. case 'pop':
  36630. if (stack.length < 1) {
  36631. return null;
  36632. }
  36633. stack.pop();
  36634. break;
  36635. case 'index':
  36636. if (stack.length < 1) {
  36637. return null;
  36638. }
  36639. num1 = stack.pop();
  36640. if (num1.type !== 'literal') {
  36641. return null;
  36642. }
  36643. n = num1.number;
  36644. if (n < 0 || (n|0) !== n || stack.length < n) {
  36645. return null;
  36646. }
  36647. ast1 = stack[stack.length - n - 1];
  36648. if (ast1.type === 'literal' || ast1.type === 'var') {
  36649. stack.push(ast1);
  36650. break;
  36651. }
  36652. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  36653. stack[stack.length - n - 1] = tmpVar;
  36654. stack.push(tmpVar);
  36655. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  36656. break;
  36657. case 'dup':
  36658. if (stack.length < 1) {
  36659. return null;
  36660. }
  36661. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  36662. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  36663. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  36664. // special case of the commands sequence for the min operation
  36665. num1 = stack.pop();
  36666. stack.push(buildMinOperation(num1, code[i + 1]));
  36667. i += 6;
  36668. break;
  36669. }
  36670. ast1 = stack[stack.length - 1];
  36671. if (ast1.type === 'literal' || ast1.type === 'var') {
  36672. // we don't have to save into intermediate variable a literal or
  36673. // variable.
  36674. stack.push(ast1);
  36675. break;
  36676. }
  36677. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  36678. stack[stack.length - 1] = tmpVar;
  36679. stack.push(tmpVar);
  36680. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  36681. break;
  36682. case 'roll':
  36683. if (stack.length < 2) {
  36684. return null;
  36685. }
  36686. num2 = stack.pop();
  36687. num1 = stack.pop();
  36688. if (num2.type !== 'literal' || num1.type !== 'literal') {
  36689. // both roll operands must be numbers
  36690. return null;
  36691. }
  36692. j = num2.number;
  36693. n = num1.number;
  36694. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  36695. // ... and integers
  36696. return null;
  36697. }
  36698. j = ((j % n) + n) % n;
  36699. if (j === 0) {
  36700. break; // just skipping -- there are nothing to rotate
  36701. }
  36702. Array.prototype.push.apply(stack,
  36703. stack.splice(stack.length - n, n - j));
  36704. break;
  36705. default:
  36706. return null; // unsupported operator
  36707. }
  36708. }
  36709. if (stack.length !== outputSize) {
  36710. return null;
  36711. }
  36712. var result = [];
  36713. instructions.forEach(function (instruction) {
  36714. var statementBuilder = new ExpressionBuilderVisitor();
  36715. instruction.visit(statementBuilder);
  36716. result.push(statementBuilder.toString());
  36717. });
  36718. stack.forEach(function (expr, i) {
  36719. var statementBuilder = new ExpressionBuilderVisitor();
  36720. expr.visit(statementBuilder);
  36721. var min = range[i * 2], max = range[i * 2 + 1];
  36722. var out = [statementBuilder.toString()];
  36723. if (min > expr.min) {
  36724. out.unshift('Math.max(', min, ', ');
  36725. out.push(')');
  36726. }
  36727. if (max < expr.max) {
  36728. out.unshift('Math.min(', max, ', ');
  36729. out.push(')');
  36730. }
  36731. out.unshift('dest[destOffset + ', i, '] = ');
  36732. out.push(';');
  36733. result.push(out.join(''));
  36734. });
  36735. return result.join('\n');
  36736. }
  36737. };
  36738. return PostScriptCompiler;
  36739. })();
  36740. exports.isPDFFunction = isPDFFunction;
  36741. exports.PDFFunction = PDFFunction;
  36742. exports.PostScriptEvaluator = PostScriptEvaluator;
  36743. exports.PostScriptCompiler = PostScriptCompiler;
  36744. }));
  36745. (function (root, factory) {
  36746. {
  36747. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  36748. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  36749. root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils);
  36750. }
  36751. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  36752. displayMetadata, displayDOMUtils, amdRequire) {
  36753. var InvalidPDFException = sharedUtil.InvalidPDFException;
  36754. var MessageHandler = sharedUtil.MessageHandler;
  36755. var MissingPDFException = sharedUtil.MissingPDFException;
  36756. var PageViewport = sharedUtil.PageViewport;
  36757. var PasswordResponses = sharedUtil.PasswordResponses;
  36758. var PasswordException = sharedUtil.PasswordException;
  36759. var StatTimer = sharedUtil.StatTimer;
  36760. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  36761. var UnknownErrorException = sharedUtil.UnknownErrorException;
  36762. var Util = sharedUtil.Util;
  36763. var createPromiseCapability = sharedUtil.createPromiseCapability;
  36764. var error = sharedUtil.error;
  36765. var deprecated = sharedUtil.deprecated;
  36766. var getVerbosityLevel = sharedUtil.getVerbosityLevel;
  36767. var info = sharedUtil.info;
  36768. var isInt = sharedUtil.isInt;
  36769. var isArray = sharedUtil.isArray;
  36770. var isArrayBuffer = sharedUtil.isArrayBuffer;
  36771. var isSameOrigin = sharedUtil.isSameOrigin;
  36772. var loadJpegStream = sharedUtil.loadJpegStream;
  36773. var stringToBytes = sharedUtil.stringToBytes;
  36774. var globalScope = sharedUtil.globalScope;
  36775. var warn = sharedUtil.warn;
  36776. var FontFaceObject = displayFontLoader.FontFaceObject;
  36777. var FontLoader = displayFontLoader.FontLoader;
  36778. var CanvasGraphics = displayCanvas.CanvasGraphics;
  36779. var createScratchCanvas = displayCanvas.createScratchCanvas;
  36780. var Metadata = displayMetadata.Metadata;
  36781. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  36782. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  36783. var isWorkerDisabled = false;
  36784. var workerSrc;
  36785. var isPostMessageTransfersDisabled = false;
  36786. /**
  36787. * Document initialization / loading parameters object.
  36788. *
  36789. * @typedef {Object} DocumentInitParameters
  36790. * @property {string} url - The URL of the PDF.
  36791. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  36792. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  36793. * use atob() to convert it to a binary string first.
  36794. * @property {Object} httpHeaders - Basic authentication headers.
  36795. * @property {boolean} withCredentials - Indicates whether or not cross-site
  36796. * Access-Control requests should be made using credentials such as cookies
  36797. * or authorization headers. The default is false.
  36798. * @property {string} password - For decrypting password-protected PDFs.
  36799. * @property {TypedArray} initialData - A typed array with the first portion or
  36800. * all of the pdf data. Used by the extension since some data is already
  36801. * loaded before the switch to range requests.
  36802. * @property {number} length - The PDF file length. It's used for progress
  36803. * reports and range requests operations.
  36804. * @property {PDFDataRangeTransport} range
  36805. * @property {number} rangeChunkSize - Optional parameter to specify
  36806. * maximum number of bytes fetched per range request. The default value is
  36807. * 2^16 = 65536.
  36808. * @property {PDFWorker} worker - The worker that will be used for the loading
  36809. * and parsing of the PDF data.
  36810. */
  36811. /**
  36812. * @typedef {Object} PDFDocumentStats
  36813. * @property {Array} streamTypes - Used stream types in the document (an item
  36814. * is set to true if specific stream ID was used in the document).
  36815. * @property {Array} fontTypes - Used font type in the document (an item is set
  36816. * to true if specific font ID was used in the document).
  36817. */
  36818. /**
  36819. * This is the main entry point for loading a PDF and interacting with it.
  36820. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  36821. * is used, which means it must follow the same origin rules that any XHR does
  36822. * e.g. No cross domain requests without CORS.
  36823. *
  36824. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  36825. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  36826. * already populated with data or parameter object.
  36827. *
  36828. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  36829. * if you want to manually serve range requests for data in the PDF.
  36830. *
  36831. * @param {function} passwordCallback (deprecated) It is used to request a
  36832. * password if wrong or no password was provided. The callback receives two
  36833. * parameters: function that needs to be called with new password and reason
  36834. * (see {PasswordResponses}).
  36835. *
  36836. * @param {function} progressCallback (deprecated) It is used to be able to
  36837. * monitor the loading progress of the PDF file (necessary to implement e.g.
  36838. * a loading bar). The callback receives an {Object} with the properties:
  36839. * {number} loaded and {number} total.
  36840. *
  36841. * @return {PDFDocumentLoadingTask}
  36842. */
  36843. function getDocument(src, pdfDataRangeTransport,
  36844. passwordCallback, progressCallback) {
  36845. var task = new PDFDocumentLoadingTask();
  36846. // Support of the obsolete arguments (for compatibility with API v1.0)
  36847. if (arguments.length > 1) {
  36848. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  36849. 'passwordCallback or progressCallback argument');
  36850. }
  36851. if (pdfDataRangeTransport) {
  36852. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  36853. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  36854. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  36855. pdfDataRangeTransport.length = src.length;
  36856. pdfDataRangeTransport.initialData = src.initialData;
  36857. if (!pdfDataRangeTransport.abort) {
  36858. pdfDataRangeTransport.abort = function () {};
  36859. }
  36860. }
  36861. src = Object.create(src);
  36862. src.range = pdfDataRangeTransport;
  36863. }
  36864. task.onPassword = passwordCallback || null;
  36865. task.onProgress = progressCallback || null;
  36866. var source;
  36867. if (typeof src === 'string') {
  36868. source = { url: src };
  36869. } else if (isArrayBuffer(src)) {
  36870. source = { data: src };
  36871. } else if (src instanceof PDFDataRangeTransport) {
  36872. source = { range: src };
  36873. } else {
  36874. if (typeof src !== 'object') {
  36875. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  36876. 'string or a parameter object');
  36877. }
  36878. if (!src.url && !src.data && !src.range) {
  36879. error('Invalid parameter object: need either .data, .range or .url');
  36880. }
  36881. source = src;
  36882. }
  36883. var params = {};
  36884. var rangeTransport = null;
  36885. var worker = null;
  36886. for (var key in source) {
  36887. if (key === 'url' && typeof window !== 'undefined') {
  36888. // The full path is required in the 'url' field.
  36889. params[key] = new URL(source[key], window.location).href;
  36890. continue;
  36891. } else if (key === 'range') {
  36892. rangeTransport = source[key];
  36893. continue;
  36894. } else if (key === 'worker') {
  36895. worker = source[key];
  36896. continue;
  36897. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  36898. // Converting string or array-like data to Uint8Array.
  36899. var pdfBytes = source[key];
  36900. if (typeof pdfBytes === 'string') {
  36901. params[key] = stringToBytes(pdfBytes);
  36902. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  36903. !isNaN(pdfBytes.length)) {
  36904. params[key] = new Uint8Array(pdfBytes);
  36905. } else if (isArrayBuffer(pdfBytes)) {
  36906. params[key] = new Uint8Array(pdfBytes);
  36907. } else {
  36908. error('Invalid PDF binary data: either typed array, string or ' +
  36909. 'array-like object is expected in the data property.');
  36910. }
  36911. continue;
  36912. }
  36913. params[key] = source[key];
  36914. }
  36915. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  36916. if (!worker) {
  36917. // Worker was not provided -- creating and owning our own.
  36918. worker = new PDFWorker();
  36919. task._worker = worker;
  36920. }
  36921. var docId = task.docId;
  36922. worker.promise.then(function () {
  36923. if (task.destroyed) {
  36924. throw new Error('Loading aborted');
  36925. }
  36926. return _fetchDocument(worker, params, rangeTransport, docId).then(
  36927. function (workerId) {
  36928. if (task.destroyed) {
  36929. throw new Error('Loading aborted');
  36930. }
  36931. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  36932. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  36933. task._transport = transport;
  36934. messageHandler.send('Ready', null);
  36935. });
  36936. }).catch(task._capability.reject);
  36937. return task;
  36938. }
  36939. /**
  36940. * Starts fetching of specified PDF document/data.
  36941. * @param {PDFWorker} worker
  36942. * @param {Object} source
  36943. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  36944. * @param {string} docId Unique document id, used as MessageHandler id.
  36945. * @returns {Promise} The promise, which is resolved when worker id of
  36946. * MessageHandler is known.
  36947. * @private
  36948. */
  36949. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  36950. if (worker.destroyed) {
  36951. return Promise.reject(new Error('Worker was destroyed'));
  36952. }
  36953. source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
  36954. source.disableStream = getDefaultSetting('disableStream');
  36955. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  36956. if (pdfDataRangeTransport) {
  36957. source.length = pdfDataRangeTransport.length;
  36958. source.initialData = pdfDataRangeTransport.initialData;
  36959. }
  36960. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  36961. docId: docId,
  36962. source: source,
  36963. disableRange: getDefaultSetting('disableRange'),
  36964. maxImageSize: getDefaultSetting('maxImageSize'),
  36965. cMapUrl: getDefaultSetting('cMapUrl'),
  36966. cMapPacked: getDefaultSetting('cMapPacked'),
  36967. disableFontFace: getDefaultSetting('disableFontFace'),
  36968. disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
  36969. postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
  36970. !isPostMessageTransfersDisabled,
  36971. }).then(function (workerId) {
  36972. if (worker.destroyed) {
  36973. throw new Error('Worker was destroyed');
  36974. }
  36975. return workerId;
  36976. });
  36977. }
  36978. /**
  36979. * PDF document loading operation.
  36980. * @class
  36981. * @alias PDFDocumentLoadingTask
  36982. */
  36983. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  36984. var nextDocumentId = 0;
  36985. /** @constructs PDFDocumentLoadingTask */
  36986. function PDFDocumentLoadingTask() {
  36987. this._capability = createPromiseCapability();
  36988. this._transport = null;
  36989. this._worker = null;
  36990. /**
  36991. * Unique document loading task id -- used in MessageHandlers.
  36992. * @type {string}
  36993. */
  36994. this.docId = 'd' + (nextDocumentId++);
  36995. /**
  36996. * Shows if loading task is destroyed.
  36997. * @type {boolean}
  36998. */
  36999. this.destroyed = false;
  37000. /**
  37001. * Callback to request a password if wrong or no password was provided.
  37002. * The callback receives two parameters: function that needs to be called
  37003. * with new password and reason (see {PasswordResponses}).
  37004. */
  37005. this.onPassword = null;
  37006. /**
  37007. * Callback to be able to monitor the loading progress of the PDF file
  37008. * (necessary to implement e.g. a loading bar). The callback receives
  37009. * an {Object} with the properties: {number} loaded and {number} total.
  37010. */
  37011. this.onProgress = null;
  37012. /**
  37013. * Callback to when unsupported feature is used. The callback receives
  37014. * an {UNSUPPORTED_FEATURES} argument.
  37015. */
  37016. this.onUnsupportedFeature = null;
  37017. }
  37018. PDFDocumentLoadingTask.prototype =
  37019. /** @lends PDFDocumentLoadingTask.prototype */ {
  37020. /**
  37021. * @return {Promise}
  37022. */
  37023. get promise() {
  37024. return this._capability.promise;
  37025. },
  37026. /**
  37027. * Aborts all network requests and destroys worker.
  37028. * @return {Promise} A promise that is resolved after destruction activity
  37029. * is completed.
  37030. */
  37031. destroy: function () {
  37032. this.destroyed = true;
  37033. var transportDestroyed = !this._transport ? Promise.resolve() :
  37034. this._transport.destroy();
  37035. return transportDestroyed.then(function () {
  37036. this._transport = null;
  37037. if (this._worker) {
  37038. this._worker.destroy();
  37039. this._worker = null;
  37040. }
  37041. }.bind(this));
  37042. },
  37043. /**
  37044. * Registers callbacks to indicate the document loading completion.
  37045. *
  37046. * @param {function} onFulfilled The callback for the loading completion.
  37047. * @param {function} onRejected The callback for the loading failure.
  37048. * @return {Promise} A promise that is resolved after the onFulfilled or
  37049. * onRejected callback.
  37050. */
  37051. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  37052. return this.promise.then.apply(this.promise, arguments);
  37053. }
  37054. };
  37055. return PDFDocumentLoadingTask;
  37056. })();
  37057. /**
  37058. * Abstract class to support range requests file loading.
  37059. * @class
  37060. * @alias PDFDataRangeTransport
  37061. * @param {number} length
  37062. * @param {Uint8Array} initialData
  37063. */
  37064. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  37065. function PDFDataRangeTransport(length, initialData) {
  37066. this.length = length;
  37067. this.initialData = initialData;
  37068. this._rangeListeners = [];
  37069. this._progressListeners = [];
  37070. this._progressiveReadListeners = [];
  37071. this._readyCapability = createPromiseCapability();
  37072. }
  37073. PDFDataRangeTransport.prototype =
  37074. /** @lends PDFDataRangeTransport.prototype */ {
  37075. addRangeListener:
  37076. function PDFDataRangeTransport_addRangeListener(listener) {
  37077. this._rangeListeners.push(listener);
  37078. },
  37079. addProgressListener:
  37080. function PDFDataRangeTransport_addProgressListener(listener) {
  37081. this._progressListeners.push(listener);
  37082. },
  37083. addProgressiveReadListener:
  37084. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  37085. this._progressiveReadListeners.push(listener);
  37086. },
  37087. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  37088. var listeners = this._rangeListeners;
  37089. for (var i = 0, n = listeners.length; i < n; ++i) {
  37090. listeners[i](begin, chunk);
  37091. }
  37092. },
  37093. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  37094. this._readyCapability.promise.then(function () {
  37095. var listeners = this._progressListeners;
  37096. for (var i = 0, n = listeners.length; i < n; ++i) {
  37097. listeners[i](loaded);
  37098. }
  37099. }.bind(this));
  37100. },
  37101. onDataProgressiveRead:
  37102. function PDFDataRangeTransport_onDataProgress(chunk) {
  37103. this._readyCapability.promise.then(function () {
  37104. var listeners = this._progressiveReadListeners;
  37105. for (var i = 0, n = listeners.length; i < n; ++i) {
  37106. listeners[i](chunk);
  37107. }
  37108. }.bind(this));
  37109. },
  37110. transportReady: function PDFDataRangeTransport_transportReady() {
  37111. this._readyCapability.resolve();
  37112. },
  37113. requestDataRange:
  37114. function PDFDataRangeTransport_requestDataRange(begin, end) {
  37115. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  37116. },
  37117. abort: function PDFDataRangeTransport_abort() {
  37118. }
  37119. };
  37120. return PDFDataRangeTransport;
  37121. })();
  37122. /**
  37123. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  37124. * properties that can be read synchronously.
  37125. * @class
  37126. * @alias PDFDocumentProxy
  37127. */
  37128. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  37129. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  37130. this.pdfInfo = pdfInfo;
  37131. this.transport = transport;
  37132. this.loadingTask = loadingTask;
  37133. }
  37134. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  37135. /**
  37136. * @return {number} Total number of pages the PDF contains.
  37137. */
  37138. get numPages() {
  37139. return this.pdfInfo.numPages;
  37140. },
  37141. /**
  37142. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  37143. * unique.
  37144. */
  37145. get fingerprint() {
  37146. return this.pdfInfo.fingerprint;
  37147. },
  37148. /**
  37149. * @param {number} pageNumber The page number to get. The first page is 1.
  37150. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  37151. * object.
  37152. */
  37153. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  37154. return this.transport.getPage(pageNumber);
  37155. },
  37156. /**
  37157. * @param {{num: number, gen: number}} ref The page reference. Must have
  37158. * the 'num' and 'gen' properties.
  37159. * @return {Promise} A promise that is resolved with the page index that is
  37160. * associated with the reference.
  37161. */
  37162. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  37163. return this.transport.getPageIndex(ref);
  37164. },
  37165. /**
  37166. * @return {Promise} A promise that is resolved with a lookup table for
  37167. * mapping named destinations to reference numbers.
  37168. *
  37169. * This can be slow for large documents: use getDestination instead
  37170. */
  37171. getDestinations: function PDFDocumentProxy_getDestinations() {
  37172. return this.transport.getDestinations();
  37173. },
  37174. /**
  37175. * @param {string} id The named destination to get.
  37176. * @return {Promise} A promise that is resolved with all information
  37177. * of the given named destination.
  37178. */
  37179. getDestination: function PDFDocumentProxy_getDestination(id) {
  37180. return this.transport.getDestination(id);
  37181. },
  37182. /**
  37183. * @return {Promise} A promise that is resolved with:
  37184. * an Array containing the pageLabels that correspond to the pageIndexes,
  37185. * or `null` when no pageLabels are present in the PDF file.
  37186. */
  37187. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  37188. return this.transport.getPageLabels();
  37189. },
  37190. /**
  37191. * @return {Promise} A promise that is resolved with a lookup table for
  37192. * mapping named attachments to their content.
  37193. */
  37194. getAttachments: function PDFDocumentProxy_getAttachments() {
  37195. return this.transport.getAttachments();
  37196. },
  37197. /**
  37198. * @return {Promise} A promise that is resolved with an array of all the
  37199. * JavaScript strings in the name tree.
  37200. */
  37201. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  37202. return this.transport.getJavaScript();
  37203. },
  37204. /**
  37205. * @return {Promise} A promise that is resolved with an {Array} that is a
  37206. * tree outline (if it has one) of the PDF. The tree is in the format of:
  37207. * [
  37208. * {
  37209. * title: string,
  37210. * bold: boolean,
  37211. * italic: boolean,
  37212. * color: rgb Uint8Array,
  37213. * dest: dest obj,
  37214. * url: string,
  37215. * items: array of more items like this
  37216. * },
  37217. * ...
  37218. * ].
  37219. */
  37220. getOutline: function PDFDocumentProxy_getOutline() {
  37221. return this.transport.getOutline();
  37222. },
  37223. /**
  37224. * @return {Promise} A promise that is resolved with an {Object} that has
  37225. * info and metadata properties. Info is an {Object} filled with anything
  37226. * available in the information dictionary and similarly metadata is a
  37227. * {Metadata} object with information from the metadata section of the PDF.
  37228. */
  37229. getMetadata: function PDFDocumentProxy_getMetadata() {
  37230. return this.transport.getMetadata();
  37231. },
  37232. /**
  37233. * @return {Promise} A promise that is resolved with a TypedArray that has
  37234. * the raw data from the PDF.
  37235. */
  37236. getData: function PDFDocumentProxy_getData() {
  37237. return this.transport.getData();
  37238. },
  37239. /**
  37240. * @return {Promise} A promise that is resolved when the document's data
  37241. * is loaded. It is resolved with an {Object} that contains the length
  37242. * property that indicates size of the PDF data in bytes.
  37243. */
  37244. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  37245. return this.transport.downloadInfoCapability.promise;
  37246. },
  37247. /**
  37248. * @return {Promise} A promise this is resolved with current stats about
  37249. * document structures (see {@link PDFDocumentStats}).
  37250. */
  37251. getStats: function PDFDocumentProxy_getStats() {
  37252. return this.transport.getStats();
  37253. },
  37254. /**
  37255. * Cleans up resources allocated by the document, e.g. created @font-face.
  37256. */
  37257. cleanup: function PDFDocumentProxy_cleanup() {
  37258. this.transport.startCleanup();
  37259. },
  37260. /**
  37261. * Destroys current document instance and terminates worker.
  37262. */
  37263. destroy: function PDFDocumentProxy_destroy() {
  37264. return this.loadingTask.destroy();
  37265. }
  37266. };
  37267. return PDFDocumentProxy;
  37268. })();
  37269. /**
  37270. * Page getTextContent parameters.
  37271. *
  37272. * @typedef {Object} getTextContentParameters
  37273. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  37274. * whitespace with standard spaces (0x20). The default value is `false`.
  37275. * @param {boolean} disableCombineTextItems - do not attempt to combine
  37276. * same line {@link TextItem}'s. The default value is `false`.
  37277. */
  37278. /**
  37279. * Page text content.
  37280. *
  37281. * @typedef {Object} TextContent
  37282. * @property {array} items - array of {@link TextItem}
  37283. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  37284. * name.
  37285. */
  37286. /**
  37287. * Page text content part.
  37288. *
  37289. * @typedef {Object} TextItem
  37290. * @property {string} str - text content.
  37291. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  37292. * @property {array} transform - transformation matrix.
  37293. * @property {number} width - width in device space.
  37294. * @property {number} height - height in device space.
  37295. * @property {string} fontName - font name used by pdf.js for converted font.
  37296. */
  37297. /**
  37298. * Text style.
  37299. *
  37300. * @typedef {Object} TextStyle
  37301. * @property {number} ascent - font ascent.
  37302. * @property {number} descent - font descent.
  37303. * @property {boolean} vertical - text is in vertical mode.
  37304. * @property {string} fontFamily - possible font family
  37305. */
  37306. /**
  37307. * Page annotation parameters.
  37308. *
  37309. * @typedef {Object} GetAnnotationsParameters
  37310. * @param {string} intent - Determines the annotations that will be fetched,
  37311. * can be either 'display' (viewable annotations) or 'print'
  37312. * (printable annotations).
  37313. * If the parameter is omitted, all annotations are fetched.
  37314. */
  37315. /**
  37316. * Page render parameters.
  37317. *
  37318. * @typedef {Object} RenderParameters
  37319. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  37320. * @property {PageViewport} viewport - Rendering viewport obtained by
  37321. * calling of PDFPage.getViewport method.
  37322. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  37323. * (default value is 'display').
  37324. * @property {boolean} renderInteractiveForms - (optional) Whether or not
  37325. * interactive form elements are rendered in the display
  37326. * layer. If so, we do not render them on canvas as well.
  37327. * @property {Array} transform - (optional) Additional transform, applied
  37328. * just before viewport transform.
  37329. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  37330. * endLayout and appendImage functions.
  37331. * @property {function} continueCallback - (deprecated) A function that will be
  37332. * called each time the rendering is paused. To continue
  37333. * rendering call the function that is the first argument
  37334. * to the callback.
  37335. */
  37336. /**
  37337. * PDF page operator list.
  37338. *
  37339. * @typedef {Object} PDFOperatorList
  37340. * @property {Array} fnArray - Array containing the operator functions.
  37341. * @property {Array} argsArray - Array containing the arguments of the
  37342. * functions.
  37343. */
  37344. /**
  37345. * Proxy to a PDFPage in the worker thread.
  37346. * @class
  37347. * @alias PDFPageProxy
  37348. */
  37349. var PDFPageProxy = (function PDFPageProxyClosure() {
  37350. function PDFPageProxy(pageIndex, pageInfo, transport) {
  37351. this.pageIndex = pageIndex;
  37352. this.pageInfo = pageInfo;
  37353. this.transport = transport;
  37354. this.stats = new StatTimer();
  37355. this.stats.enabled = getDefaultSetting('enableStats');
  37356. this.commonObjs = transport.commonObjs;
  37357. this.objs = new PDFObjects();
  37358. this.cleanupAfterRender = false;
  37359. this.pendingCleanup = false;
  37360. this.intentStates = Object.create(null);
  37361. this.destroyed = false;
  37362. }
  37363. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  37364. /**
  37365. * @return {number} Page number of the page. First page is 1.
  37366. */
  37367. get pageNumber() {
  37368. return this.pageIndex + 1;
  37369. },
  37370. /**
  37371. * @return {number} The number of degrees the page is rotated clockwise.
  37372. */
  37373. get rotate() {
  37374. return this.pageInfo.rotate;
  37375. },
  37376. /**
  37377. * @return {Object} The reference that points to this page. It has 'num' and
  37378. * 'gen' properties.
  37379. */
  37380. get ref() {
  37381. return this.pageInfo.ref;
  37382. },
  37383. /**
  37384. * @return {Array} An array of the visible portion of the PDF page in the
  37385. * user space units - [x1, y1, x2, y2].
  37386. */
  37387. get view() {
  37388. return this.pageInfo.view;
  37389. },
  37390. /**
  37391. * @param {number} scale The desired scale of the viewport.
  37392. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  37393. * defaults to the page rotation.
  37394. * @return {PageViewport} Contains 'width' and 'height' properties
  37395. * along with transforms required for rendering.
  37396. */
  37397. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  37398. if (arguments.length < 2) {
  37399. rotate = this.rotate;
  37400. }
  37401. return new PageViewport(this.view, scale, rotate, 0, 0);
  37402. },
  37403. /**
  37404. * @param {GetAnnotationsParameters} params - Annotation parameters.
  37405. * @return {Promise} A promise that is resolved with an {Array} of the
  37406. * annotation objects.
  37407. */
  37408. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  37409. var intent = (params && params.intent) || null;
  37410. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  37411. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  37412. intent);
  37413. this.annotationsIntent = intent;
  37414. }
  37415. return this.annotationsPromise;
  37416. },
  37417. /**
  37418. * Begins the process of rendering a page to the desired context.
  37419. * @param {RenderParameters} params Page render parameters.
  37420. * @return {RenderTask} An object that contains the promise, which
  37421. * is resolved when the page finishes rendering.
  37422. */
  37423. render: function PDFPageProxy_render(params) {
  37424. var stats = this.stats;
  37425. stats.time('Overall');
  37426. // If there was a pending destroy cancel it so no cleanup happens during
  37427. // this call to render.
  37428. this.pendingCleanup = false;
  37429. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  37430. var renderInteractiveForms = (params.renderInteractiveForms === true ?
  37431. true : /* Default */ false);
  37432. if (!this.intentStates[renderingIntent]) {
  37433. this.intentStates[renderingIntent] = Object.create(null);
  37434. }
  37435. var intentState = this.intentStates[renderingIntent];
  37436. // If there's no displayReadyCapability yet, then the operatorList
  37437. // was never requested before. Make the request and create the promise.
  37438. if (!intentState.displayReadyCapability) {
  37439. intentState.receivingOperatorList = true;
  37440. intentState.displayReadyCapability = createPromiseCapability();
  37441. intentState.operatorList = {
  37442. fnArray: [],
  37443. argsArray: [],
  37444. lastChunk: false
  37445. };
  37446. this.stats.time('Page Request');
  37447. this.transport.messageHandler.send('RenderPageRequest', {
  37448. pageIndex: this.pageNumber - 1,
  37449. intent: renderingIntent,
  37450. renderInteractiveForms: renderInteractiveForms,
  37451. });
  37452. }
  37453. var internalRenderTask = new InternalRenderTask(complete, params,
  37454. this.objs,
  37455. this.commonObjs,
  37456. intentState.operatorList,
  37457. this.pageNumber);
  37458. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  37459. if (!intentState.renderTasks) {
  37460. intentState.renderTasks = [];
  37461. }
  37462. intentState.renderTasks.push(internalRenderTask);
  37463. var renderTask = internalRenderTask.task;
  37464. // Obsolete parameter support
  37465. if (params.continueCallback) {
  37466. deprecated('render is used with continueCallback parameter');
  37467. renderTask.onContinue = params.continueCallback;
  37468. }
  37469. var self = this;
  37470. intentState.displayReadyCapability.promise.then(
  37471. function pageDisplayReadyPromise(transparency) {
  37472. if (self.pendingCleanup) {
  37473. complete();
  37474. return;
  37475. }
  37476. stats.time('Rendering');
  37477. internalRenderTask.initializeGraphics(transparency);
  37478. internalRenderTask.operatorListChanged();
  37479. },
  37480. function pageDisplayReadPromiseError(reason) {
  37481. complete(reason);
  37482. }
  37483. );
  37484. function complete(error) {
  37485. var i = intentState.renderTasks.indexOf(internalRenderTask);
  37486. if (i >= 0) {
  37487. intentState.renderTasks.splice(i, 1);
  37488. }
  37489. if (self.cleanupAfterRender) {
  37490. self.pendingCleanup = true;
  37491. }
  37492. self._tryCleanup();
  37493. if (error) {
  37494. internalRenderTask.capability.reject(error);
  37495. } else {
  37496. internalRenderTask.capability.resolve();
  37497. }
  37498. stats.timeEnd('Rendering');
  37499. stats.timeEnd('Overall');
  37500. }
  37501. return renderTask;
  37502. },
  37503. /**
  37504. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  37505. * object that represents page's operator list.
  37506. */
  37507. getOperatorList: function PDFPageProxy_getOperatorList() {
  37508. function operatorListChanged() {
  37509. if (intentState.operatorList.lastChunk) {
  37510. intentState.opListReadCapability.resolve(intentState.operatorList);
  37511. var i = intentState.renderTasks.indexOf(opListTask);
  37512. if (i >= 0) {
  37513. intentState.renderTasks.splice(i, 1);
  37514. }
  37515. }
  37516. }
  37517. var renderingIntent = 'oplist';
  37518. if (!this.intentStates[renderingIntent]) {
  37519. this.intentStates[renderingIntent] = Object.create(null);
  37520. }
  37521. var intentState = this.intentStates[renderingIntent];
  37522. var opListTask;
  37523. if (!intentState.opListReadCapability) {
  37524. opListTask = {};
  37525. opListTask.operatorListChanged = operatorListChanged;
  37526. intentState.receivingOperatorList = true;
  37527. intentState.opListReadCapability = createPromiseCapability();
  37528. intentState.renderTasks = [];
  37529. intentState.renderTasks.push(opListTask);
  37530. intentState.operatorList = {
  37531. fnArray: [],
  37532. argsArray: [],
  37533. lastChunk: false
  37534. };
  37535. this.transport.messageHandler.send('RenderPageRequest', {
  37536. pageIndex: this.pageIndex,
  37537. intent: renderingIntent
  37538. });
  37539. }
  37540. return intentState.opListReadCapability.promise;
  37541. },
  37542. /**
  37543. * @param {getTextContentParameters} params - getTextContent parameters.
  37544. * @return {Promise} That is resolved a {@link TextContent}
  37545. * object that represent the page text content.
  37546. */
  37547. getTextContent: function PDFPageProxy_getTextContent(params) {
  37548. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  37549. pageIndex: this.pageNumber - 1,
  37550. normalizeWhitespace: (params && params.normalizeWhitespace === true ?
  37551. true : /* Default */ false),
  37552. combineTextItems: (params && params.disableCombineTextItems === true ?
  37553. false : /* Default */ true),
  37554. });
  37555. },
  37556. /**
  37557. * Destroys page object.
  37558. */
  37559. _destroy: function PDFPageProxy_destroy() {
  37560. this.destroyed = true;
  37561. this.transport.pageCache[this.pageIndex] = null;
  37562. var waitOn = [];
  37563. Object.keys(this.intentStates).forEach(function(intent) {
  37564. if (intent === 'oplist') {
  37565. // Avoid errors below, since the renderTasks are just stubs.
  37566. return;
  37567. }
  37568. var intentState = this.intentStates[intent];
  37569. intentState.renderTasks.forEach(function(renderTask) {
  37570. var renderCompleted = renderTask.capability.promise.
  37571. catch(function () {}); // ignoring failures
  37572. waitOn.push(renderCompleted);
  37573. renderTask.cancel();
  37574. });
  37575. }, this);
  37576. this.objs.clear();
  37577. this.annotationsPromise = null;
  37578. this.pendingCleanup = false;
  37579. return Promise.all(waitOn);
  37580. },
  37581. /**
  37582. * Cleans up resources allocated by the page. (deprecated)
  37583. */
  37584. destroy: function() {
  37585. deprecated('page destroy method, use cleanup() instead');
  37586. this.cleanup();
  37587. },
  37588. /**
  37589. * Cleans up resources allocated by the page.
  37590. */
  37591. cleanup: function PDFPageProxy_cleanup() {
  37592. this.pendingCleanup = true;
  37593. this._tryCleanup();
  37594. },
  37595. /**
  37596. * For internal use only. Attempts to clean up if rendering is in a state
  37597. * where that's possible.
  37598. * @ignore
  37599. */
  37600. _tryCleanup: function PDFPageProxy_tryCleanup() {
  37601. if (!this.pendingCleanup ||
  37602. Object.keys(this.intentStates).some(function(intent) {
  37603. var intentState = this.intentStates[intent];
  37604. return (intentState.renderTasks.length !== 0 ||
  37605. intentState.receivingOperatorList);
  37606. }, this)) {
  37607. return;
  37608. }
  37609. Object.keys(this.intentStates).forEach(function(intent) {
  37610. delete this.intentStates[intent];
  37611. }, this);
  37612. this.objs.clear();
  37613. this.annotationsPromise = null;
  37614. this.pendingCleanup = false;
  37615. },
  37616. /**
  37617. * For internal use only.
  37618. * @ignore
  37619. */
  37620. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  37621. intent) {
  37622. var intentState = this.intentStates[intent];
  37623. // TODO Refactor RenderPageRequest to separate rendering
  37624. // and operator list logic
  37625. if (intentState.displayReadyCapability) {
  37626. intentState.displayReadyCapability.resolve(transparency);
  37627. }
  37628. },
  37629. /**
  37630. * For internal use only.
  37631. * @ignore
  37632. */
  37633. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  37634. intent) {
  37635. var intentState = this.intentStates[intent];
  37636. var i, ii;
  37637. // Add the new chunk to the current operator list.
  37638. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  37639. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  37640. intentState.operatorList.argsArray.push(
  37641. operatorListChunk.argsArray[i]);
  37642. }
  37643. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  37644. // Notify all the rendering tasks there are more operators to be consumed.
  37645. for (i = 0; i < intentState.renderTasks.length; i++) {
  37646. intentState.renderTasks[i].operatorListChanged();
  37647. }
  37648. if (operatorListChunk.lastChunk) {
  37649. intentState.receivingOperatorList = false;
  37650. this._tryCleanup();
  37651. }
  37652. }
  37653. };
  37654. return PDFPageProxy;
  37655. })();
  37656. /**
  37657. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  37658. * WorkerTransport for them. If creation of a web worker is not possible,
  37659. * a "fake" worker will be used instead.
  37660. * @class
  37661. */
  37662. var PDFWorker = (function PDFWorkerClosure() {
  37663. var nextFakeWorkerId = 0;
  37664. function getWorkerSrc() {
  37665. if (typeof workerSrc !== 'undefined') {
  37666. return workerSrc;
  37667. }
  37668. if (getDefaultSetting('workerSrc')) {
  37669. return getDefaultSetting('workerSrc');
  37670. }
  37671. if (pdfjsFilePath) {
  37672. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  37673. }
  37674. error('No PDFJS.workerSrc specified');
  37675. }
  37676. var fakeWorkerFilesLoadedCapability;
  37677. // Loads worker code into main thread.
  37678. function setupFakeWorkerGlobal() {
  37679. var WorkerMessageHandler;
  37680. if (!fakeWorkerFilesLoadedCapability) {
  37681. fakeWorkerFilesLoadedCapability = createPromiseCapability();
  37682. // In the developer build load worker_loader which in turn loads all the
  37683. // other files and resolves the promise. In production only the
  37684. // pdf.worker.js file is needed.
  37685. WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  37686. fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
  37687. }
  37688. return fakeWorkerFilesLoadedCapability.promise;
  37689. }
  37690. function FakeWorkerPort(defer) {
  37691. this._listeners = [];
  37692. this._defer = defer;
  37693. this._deferred = Promise.resolve(undefined);
  37694. }
  37695. FakeWorkerPort.prototype = {
  37696. postMessage: function (obj, transfers) {
  37697. function cloneValue(value) {
  37698. // Trying to perform a structured clone close to the spec, including
  37699. // transfers.
  37700. if (typeof value !== 'object' || value === null) {
  37701. return value;
  37702. }
  37703. if (cloned.has(value)) { // already cloned the object
  37704. return cloned.get(value);
  37705. }
  37706. var result;
  37707. var buffer;
  37708. if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
  37709. // We found object with ArrayBuffer (typed array).
  37710. var transferable = transfers && transfers.indexOf(buffer) >= 0;
  37711. if (value === buffer) {
  37712. // Special case when we are faking typed arrays in compatibility.js.
  37713. result = value;
  37714. } else if (transferable) {
  37715. result = new value.constructor(buffer, value.byteOffset,
  37716. value.byteLength);
  37717. } else {
  37718. result = new value.constructor(value);
  37719. }
  37720. cloned.set(value, result);
  37721. return result;
  37722. }
  37723. result = isArray(value) ? [] : {};
  37724. cloned.set(value, result); // adding to cache now for cyclic references
  37725. // Cloning all value and object properties, however ignoring properties
  37726. // defined via getter.
  37727. for (var i in value) {
  37728. var desc, p = value;
  37729. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  37730. p = Object.getPrototypeOf(p);
  37731. }
  37732. if (typeof desc.value === 'undefined' ||
  37733. typeof desc.value === 'function') {
  37734. continue;
  37735. }
  37736. result[i] = cloneValue(desc.value);
  37737. }
  37738. return result;
  37739. }
  37740. if (!this._defer) {
  37741. this._listeners.forEach(function (listener) {
  37742. listener.call(this, {data: obj});
  37743. }, this);
  37744. return;
  37745. }
  37746. var cloned = new WeakMap();
  37747. var e = {data: cloneValue(obj)};
  37748. this._deferred.then(function () {
  37749. this._listeners.forEach(function (listener) {
  37750. listener.call(this, e);
  37751. }, this);
  37752. }.bind(this));
  37753. },
  37754. addEventListener: function (name, listener) {
  37755. this._listeners.push(listener);
  37756. },
  37757. removeEventListener: function (name, listener) {
  37758. var i = this._listeners.indexOf(listener);
  37759. this._listeners.splice(i, 1);
  37760. },
  37761. terminate: function () {
  37762. this._listeners = [];
  37763. }
  37764. };
  37765. function createCDNWrapper(url) {
  37766. // We will rely on blob URL's property to specify origin.
  37767. // We want this function to fail in case if createObjectURL or Blob do not
  37768. // exist or fail for some reason -- our Worker creation will fail anyway.
  37769. var wrapper = 'importScripts(\'' + url + '\');';
  37770. return URL.createObjectURL(new Blob([wrapper]));
  37771. }
  37772. function PDFWorker(name) {
  37773. this.name = name;
  37774. this.destroyed = false;
  37775. this._readyCapability = createPromiseCapability();
  37776. this._port = null;
  37777. this._webWorker = null;
  37778. this._messageHandler = null;
  37779. this._initialize();
  37780. }
  37781. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  37782. get promise() {
  37783. return this._readyCapability.promise;
  37784. },
  37785. get port() {
  37786. return this._port;
  37787. },
  37788. get messageHandler() {
  37789. return this._messageHandler;
  37790. },
  37791. _initialize: function PDFWorker_initialize() {
  37792. // If worker support isn't disabled explicit and the browser has worker
  37793. // support, create a new web worker and test if it/the browser fulfills
  37794. // all requirements to run parts of pdf.js in a web worker.
  37795. // Right now, the requirement is, that an Uint8Array is still an
  37796. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  37797. // Either workers are disabled, not supported or have thrown an exception.
  37798. // Thus, we fallback to a faked worker.
  37799. this._setupFakeWorker();
  37800. },
  37801. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  37802. if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
  37803. warn('Setting up fake worker.');
  37804. isWorkerDisabled = true;
  37805. }
  37806. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  37807. if (this.destroyed) {
  37808. this._readyCapability.reject(new Error('Worker was destroyed'));
  37809. return;
  37810. }
  37811. // We cannot turn on proper fake port simulation (this includes
  37812. // structured cloning) when typed arrays are not supported. Relying
  37813. // on a chance that messages will be sent in proper order.
  37814. var isTypedArraysPresent = Uint8Array !== Float32Array;
  37815. var port = new FakeWorkerPort(isTypedArraysPresent);
  37816. this._port = port;
  37817. // All fake workers use the same port, making id unique.
  37818. var id = 'fake' + (nextFakeWorkerId++);
  37819. // If the main thread is our worker, setup the handling for the
  37820. // messages -- the main thread sends to it self.
  37821. var workerHandler = new MessageHandler(id + '_worker', id, port);
  37822. WorkerMessageHandler.setup(workerHandler, port);
  37823. var messageHandler = new MessageHandler(id, id + '_worker', port);
  37824. this._messageHandler = messageHandler;
  37825. this._readyCapability.resolve();
  37826. }.bind(this));
  37827. },
  37828. /**
  37829. * Destroys the worker instance.
  37830. */
  37831. destroy: function PDFWorker_destroy() {
  37832. this.destroyed = true;
  37833. if (this._webWorker) {
  37834. // We need to terminate only web worker created resource.
  37835. this._webWorker.terminate();
  37836. this._webWorker = null;
  37837. }
  37838. this._port = null;
  37839. if (this._messageHandler) {
  37840. this._messageHandler.destroy();
  37841. this._messageHandler = null;
  37842. }
  37843. }
  37844. };
  37845. return PDFWorker;
  37846. })();
  37847. /**
  37848. * For internal use only.
  37849. * @ignore
  37850. */
  37851. var WorkerTransport = (function WorkerTransportClosure() {
  37852. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  37853. this.messageHandler = messageHandler;
  37854. this.loadingTask = loadingTask;
  37855. this.pdfDataRangeTransport = pdfDataRangeTransport;
  37856. this.commonObjs = new PDFObjects();
  37857. this.fontLoader = new FontLoader(loadingTask.docId);
  37858. this.destroyed = false;
  37859. this.destroyCapability = null;
  37860. this.pageCache = [];
  37861. this.pagePromises = [];
  37862. this.downloadInfoCapability = createPromiseCapability();
  37863. this.setupMessageHandler();
  37864. }
  37865. WorkerTransport.prototype = {
  37866. destroy: function WorkerTransport_destroy() {
  37867. if (this.destroyCapability) {
  37868. return this.destroyCapability.promise;
  37869. }
  37870. this.destroyed = true;
  37871. this.destroyCapability = createPromiseCapability();
  37872. var waitOn = [];
  37873. // We need to wait for all renderings to be completed, e.g.
  37874. // timeout/rAF can take a long time.
  37875. this.pageCache.forEach(function (page) {
  37876. if (page) {
  37877. waitOn.push(page._destroy());
  37878. }
  37879. });
  37880. this.pageCache = [];
  37881. this.pagePromises = [];
  37882. var self = this;
  37883. // We also need to wait for the worker to finish its long running tasks.
  37884. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  37885. waitOn.push(terminated);
  37886. Promise.all(waitOn).then(function () {
  37887. self.fontLoader.clear();
  37888. if (self.pdfDataRangeTransport) {
  37889. self.pdfDataRangeTransport.abort();
  37890. self.pdfDataRangeTransport = null;
  37891. }
  37892. if (self.messageHandler) {
  37893. self.messageHandler.destroy();
  37894. self.messageHandler = null;
  37895. }
  37896. self.destroyCapability.resolve();
  37897. }, this.destroyCapability.reject);
  37898. return this.destroyCapability.promise;
  37899. },
  37900. setupMessageHandler:
  37901. function WorkerTransport_setupMessageHandler() {
  37902. var messageHandler = this.messageHandler;
  37903. function updatePassword(password) {
  37904. messageHandler.send('UpdatePassword', password);
  37905. }
  37906. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  37907. if (pdfDataRangeTransport) {
  37908. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  37909. messageHandler.send('OnDataRange', {
  37910. begin: begin,
  37911. chunk: chunk
  37912. });
  37913. });
  37914. pdfDataRangeTransport.addProgressListener(function(loaded) {
  37915. messageHandler.send('OnDataProgress', {
  37916. loaded: loaded
  37917. });
  37918. });
  37919. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  37920. messageHandler.send('OnDataRange', {
  37921. chunk: chunk
  37922. });
  37923. });
  37924. messageHandler.on('RequestDataRange',
  37925. function transportDataRange(data) {
  37926. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  37927. }, this);
  37928. }
  37929. messageHandler.on('GetDoc', function transportDoc(data) {
  37930. var pdfInfo = data.pdfInfo;
  37931. this.numPages = data.pdfInfo.numPages;
  37932. var loadingTask = this.loadingTask;
  37933. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  37934. this.pdfDocument = pdfDocument;
  37935. loadingTask._capability.resolve(pdfDocument);
  37936. }, this);
  37937. messageHandler.on('NeedPassword',
  37938. function transportNeedPassword(exception) {
  37939. var loadingTask = this.loadingTask;
  37940. if (loadingTask.onPassword) {
  37941. return loadingTask.onPassword(updatePassword,
  37942. PasswordResponses.NEED_PASSWORD);
  37943. }
  37944. loadingTask._capability.reject(
  37945. new PasswordException(exception.message, exception.code));
  37946. }, this);
  37947. messageHandler.on('IncorrectPassword',
  37948. function transportIncorrectPassword(exception) {
  37949. var loadingTask = this.loadingTask;
  37950. if (loadingTask.onPassword) {
  37951. return loadingTask.onPassword(updatePassword,
  37952. PasswordResponses.INCORRECT_PASSWORD);
  37953. }
  37954. loadingTask._capability.reject(
  37955. new PasswordException(exception.message, exception.code));
  37956. }, this);
  37957. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  37958. this.loadingTask._capability.reject(
  37959. new InvalidPDFException(exception.message));
  37960. }, this);
  37961. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  37962. this.loadingTask._capability.reject(
  37963. new MissingPDFException(exception.message));
  37964. }, this);
  37965. messageHandler.on('UnexpectedResponse',
  37966. function transportUnexpectedResponse(exception) {
  37967. this.loadingTask._capability.reject(
  37968. new UnexpectedResponseException(exception.message, exception.status));
  37969. }, this);
  37970. messageHandler.on('UnknownError',
  37971. function transportUnknownError(exception) {
  37972. this.loadingTask._capability.reject(
  37973. new UnknownErrorException(exception.message, exception.details));
  37974. }, this);
  37975. messageHandler.on('DataLoaded', function transportPage(data) {
  37976. this.downloadInfoCapability.resolve(data);
  37977. }, this);
  37978. messageHandler.on('PDFManagerReady', function transportPage(data) {
  37979. if (this.pdfDataRangeTransport) {
  37980. this.pdfDataRangeTransport.transportReady();
  37981. }
  37982. }, this);
  37983. messageHandler.on('StartRenderPage', function transportRender(data) {
  37984. if (this.destroyed) {
  37985. return; // Ignore any pending requests if the worker was terminated.
  37986. }
  37987. var page = this.pageCache[data.pageIndex];
  37988. page.stats.timeEnd('Page Request');
  37989. page._startRenderPage(data.transparency, data.intent);
  37990. }, this);
  37991. messageHandler.on('RenderPageChunk', function transportRender(data) {
  37992. if (this.destroyed) {
  37993. return; // Ignore any pending requests if the worker was terminated.
  37994. }
  37995. var page = this.pageCache[data.pageIndex];
  37996. page._renderPageChunk(data.operatorList, data.intent);
  37997. }, this);
  37998. messageHandler.on('commonobj', function transportObj(data) {
  37999. if (this.destroyed) {
  38000. return; // Ignore any pending requests if the worker was terminated.
  38001. }
  38002. var id = data[0];
  38003. var type = data[1];
  38004. if (this.commonObjs.hasData(id)) {
  38005. return;
  38006. }
  38007. switch (type) {
  38008. case 'Font':
  38009. var exportedData = data[2];
  38010. if ('error' in exportedData) {
  38011. var exportedError = exportedData.error;
  38012. warn('Error during font loading: ' + exportedError);
  38013. this.commonObjs.resolve(id, exportedError);
  38014. break;
  38015. }
  38016. var fontRegistry = null;
  38017. if (getDefaultSetting('pdfBug') && globalScope.FontInspector &&
  38018. globalScope['FontInspector'].enabled) {
  38019. fontRegistry = {
  38020. registerFont: function (font, url) {
  38021. globalScope['FontInspector'].fontAdded(font, url);
  38022. }
  38023. };
  38024. }
  38025. var font = new FontFaceObject(exportedData, {
  38026. isEvalSuported: getDefaultSetting('isEvalSupported'),
  38027. disableFontFace: getDefaultSetting('disableFontFace'),
  38028. fontRegistry: fontRegistry
  38029. });
  38030. this.fontLoader.bind(
  38031. [font],
  38032. function fontReady(fontObjs) {
  38033. this.commonObjs.resolve(id, font);
  38034. }.bind(this)
  38035. );
  38036. break;
  38037. case 'FontPath':
  38038. this.commonObjs.resolve(id, data[2]);
  38039. break;
  38040. default:
  38041. error('Got unknown common object type ' + type);
  38042. }
  38043. }, this);
  38044. messageHandler.on('obj', function transportObj(data) {
  38045. if (this.destroyed) {
  38046. return; // Ignore any pending requests if the worker was terminated.
  38047. }
  38048. var id = data[0];
  38049. var pageIndex = data[1];
  38050. var type = data[2];
  38051. var pageProxy = this.pageCache[pageIndex];
  38052. var imageData;
  38053. if (pageProxy.objs.hasData(id)) {
  38054. return;
  38055. }
  38056. switch (type) {
  38057. case 'JpegStream':
  38058. imageData = data[3];
  38059. loadJpegStream(id, imageData, pageProxy.objs);
  38060. break;
  38061. case 'Image':
  38062. imageData = data[3];
  38063. pageProxy.objs.resolve(id, imageData);
  38064. // heuristics that will allow not to store large data
  38065. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  38066. if (imageData && 'data' in imageData &&
  38067. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  38068. pageProxy.cleanupAfterRender = true;
  38069. }
  38070. break;
  38071. default:
  38072. error('Got unknown object type ' + type);
  38073. }
  38074. }, this);
  38075. messageHandler.on('DocProgress', function transportDocProgress(data) {
  38076. if (this.destroyed) {
  38077. return; // Ignore any pending requests if the worker was terminated.
  38078. }
  38079. var loadingTask = this.loadingTask;
  38080. if (loadingTask.onProgress) {
  38081. loadingTask.onProgress({
  38082. loaded: data.loaded,
  38083. total: data.total
  38084. });
  38085. }
  38086. }, this);
  38087. messageHandler.on('PageError', function transportError(data) {
  38088. if (this.destroyed) {
  38089. return; // Ignore any pending requests if the worker was terminated.
  38090. }
  38091. var page = this.pageCache[data.pageNum - 1];
  38092. var intentState = page.intentStates[data.intent];
  38093. if (intentState.displayReadyCapability) {
  38094. intentState.displayReadyCapability.reject(data.error);
  38095. } else {
  38096. error(data.error);
  38097. }
  38098. if (intentState.operatorList) {
  38099. // Mark operator list as complete.
  38100. intentState.operatorList.lastChunk = true;
  38101. for (var i = 0; i < intentState.renderTasks.length; i++) {
  38102. intentState.renderTasks[i].operatorListChanged();
  38103. }
  38104. }
  38105. }, this);
  38106. messageHandler.on('UnsupportedFeature',
  38107. function transportUnsupportedFeature(data) {
  38108. if (this.destroyed) {
  38109. return; // Ignore any pending requests if the worker was terminated.
  38110. }
  38111. var featureId = data.featureId;
  38112. var loadingTask = this.loadingTask;
  38113. if (loadingTask.onUnsupportedFeature) {
  38114. loadingTask.onUnsupportedFeature(featureId);
  38115. }
  38116. _UnsupportedManager.notify(featureId);
  38117. }, this);
  38118. messageHandler.on('JpegDecode', function(data) {
  38119. if (this.destroyed) {
  38120. return Promise.reject(new Error('Worker was destroyed'));
  38121. }
  38122. var imageUrl = data[0];
  38123. var components = data[1];
  38124. if (components !== 3 && components !== 1) {
  38125. return Promise.reject(
  38126. new Error('Only 3 components or 1 component can be returned'));
  38127. }
  38128. return new Promise(function (resolve, reject) {
  38129. var img = new Image();
  38130. img.onload = function () {
  38131. var width = img.width;
  38132. var height = img.height;
  38133. var size = width * height;
  38134. var rgbaLength = size * 4;
  38135. var buf = new Uint8Array(size * components);
  38136. var tmpCanvas = createScratchCanvas(width, height);
  38137. var tmpCtx = tmpCanvas.getContext('2d');
  38138. tmpCtx.drawImage(img, 0, 0);
  38139. var data = tmpCtx.getImageData(0, 0, width, height).data;
  38140. var i, j;
  38141. if (components === 3) {
  38142. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  38143. buf[j] = data[i];
  38144. buf[j + 1] = data[i + 1];
  38145. buf[j + 2] = data[i + 2];
  38146. }
  38147. } else if (components === 1) {
  38148. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  38149. buf[j] = data[i];
  38150. }
  38151. }
  38152. resolve({ data: buf, width: width, height: height});
  38153. };
  38154. img.onerror = function () {
  38155. reject(new Error('JpegDecode failed to load image'));
  38156. };
  38157. img.src = imageUrl;
  38158. });
  38159. }, this);
  38160. },
  38161. getData: function WorkerTransport_getData() {
  38162. return this.messageHandler.sendWithPromise('GetData', null);
  38163. },
  38164. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  38165. if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
  38166. return Promise.reject(new Error('Invalid page request'));
  38167. }
  38168. var pageIndex = pageNumber - 1;
  38169. if (pageIndex in this.pagePromises) {
  38170. return this.pagePromises[pageIndex];
  38171. }
  38172. var promise = this.messageHandler.sendWithPromise('GetPage', {
  38173. pageIndex: pageIndex
  38174. }).then(function (pageInfo) {
  38175. if (this.destroyed) {
  38176. throw new Error('Transport destroyed');
  38177. }
  38178. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  38179. this.pageCache[pageIndex] = page;
  38180. return page;
  38181. }.bind(this));
  38182. this.pagePromises[pageIndex] = promise;
  38183. return promise;
  38184. },
  38185. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  38186. return this.messageHandler.sendWithPromise('GetPageIndex', {
  38187. ref: ref,
  38188. }).catch(function (reason) {
  38189. return Promise.reject(new Error(reason));
  38190. });
  38191. },
  38192. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  38193. return this.messageHandler.sendWithPromise('GetAnnotations', {
  38194. pageIndex: pageIndex,
  38195. intent: intent,
  38196. });
  38197. },
  38198. getDestinations: function WorkerTransport_getDestinations() {
  38199. return this.messageHandler.sendWithPromise('GetDestinations', null);
  38200. },
  38201. getDestination: function WorkerTransport_getDestination(id) {
  38202. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  38203. },
  38204. getPageLabels: function WorkerTransport_getPageLabels() {
  38205. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  38206. },
  38207. getAttachments: function WorkerTransport_getAttachments() {
  38208. return this.messageHandler.sendWithPromise('GetAttachments', null);
  38209. },
  38210. getJavaScript: function WorkerTransport_getJavaScript() {
  38211. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  38212. },
  38213. getOutline: function WorkerTransport_getOutline() {
  38214. return this.messageHandler.sendWithPromise('GetOutline', null);
  38215. },
  38216. getMetadata: function WorkerTransport_getMetadata() {
  38217. return this.messageHandler.sendWithPromise('GetMetadata', null).
  38218. then(function transportMetadata(results) {
  38219. return {
  38220. info: results[0],
  38221. metadata: (results[1] ? new Metadata(results[1]) : null)
  38222. };
  38223. });
  38224. },
  38225. getStats: function WorkerTransport_getStats() {
  38226. return this.messageHandler.sendWithPromise('GetStats', null);
  38227. },
  38228. startCleanup: function WorkerTransport_startCleanup() {
  38229. this.messageHandler.sendWithPromise('Cleanup', null).
  38230. then(function endCleanup() {
  38231. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  38232. var page = this.pageCache[i];
  38233. if (page) {
  38234. page.cleanup();
  38235. }
  38236. }
  38237. this.commonObjs.clear();
  38238. this.fontLoader.clear();
  38239. }.bind(this));
  38240. }
  38241. };
  38242. return WorkerTransport;
  38243. })();
  38244. /**
  38245. * A PDF document and page is built of many objects. E.g. there are objects
  38246. * for fonts, images, rendering code and such. These objects might get processed
  38247. * inside of a worker. The `PDFObjects` implements some basic functions to
  38248. * manage these objects.
  38249. * @ignore
  38250. */
  38251. var PDFObjects = (function PDFObjectsClosure() {
  38252. function PDFObjects() {
  38253. this.objs = Object.create(null);
  38254. }
  38255. PDFObjects.prototype = {
  38256. /**
  38257. * Internal function.
  38258. * Ensures there is an object defined for `objId`.
  38259. */
  38260. ensureObj: function PDFObjects_ensureObj(objId) {
  38261. if (this.objs[objId]) {
  38262. return this.objs[objId];
  38263. }
  38264. var obj = {
  38265. capability: createPromiseCapability(),
  38266. data: null,
  38267. resolved: false
  38268. };
  38269. this.objs[objId] = obj;
  38270. return obj;
  38271. },
  38272. /**
  38273. * If called *without* callback, this returns the data of `objId` but the
  38274. * object needs to be resolved. If it isn't, this function throws.
  38275. *
  38276. * If called *with* a callback, the callback is called with the data of the
  38277. * object once the object is resolved. That means, if you call this
  38278. * function and the object is already resolved, the callback gets called
  38279. * right away.
  38280. */
  38281. get: function PDFObjects_get(objId, callback) {
  38282. // If there is a callback, then the get can be async and the object is
  38283. // not required to be resolved right now
  38284. if (callback) {
  38285. this.ensureObj(objId).capability.promise.then(callback);
  38286. return null;
  38287. }
  38288. // If there isn't a callback, the user expects to get the resolved data
  38289. // directly.
  38290. var obj = this.objs[objId];
  38291. // If there isn't an object yet or the object isn't resolved, then the
  38292. // data isn't ready yet!
  38293. if (!obj || !obj.resolved) {
  38294. error('Requesting object that isn\'t resolved yet ' + objId);
  38295. }
  38296. return obj.data;
  38297. },
  38298. /**
  38299. * Resolves the object `objId` with optional `data`.
  38300. */
  38301. resolve: function PDFObjects_resolve(objId, data) {
  38302. var obj = this.ensureObj(objId);
  38303. obj.resolved = true;
  38304. obj.data = data;
  38305. obj.capability.resolve(data);
  38306. },
  38307. isResolved: function PDFObjects_isResolved(objId) {
  38308. var objs = this.objs;
  38309. if (!objs[objId]) {
  38310. return false;
  38311. } else {
  38312. return objs[objId].resolved;
  38313. }
  38314. },
  38315. hasData: function PDFObjects_hasData(objId) {
  38316. return this.isResolved(objId);
  38317. },
  38318. /**
  38319. * Returns the data of `objId` if object exists, null otherwise.
  38320. */
  38321. getData: function PDFObjects_getData(objId) {
  38322. var objs = this.objs;
  38323. if (!objs[objId] || !objs[objId].resolved) {
  38324. return null;
  38325. } else {
  38326. return objs[objId].data;
  38327. }
  38328. },
  38329. clear: function PDFObjects_clear() {
  38330. this.objs = Object.create(null);
  38331. }
  38332. };
  38333. return PDFObjects;
  38334. })();
  38335. /**
  38336. * Allows controlling of the rendering tasks.
  38337. * @class
  38338. * @alias RenderTask
  38339. */
  38340. var RenderTask = (function RenderTaskClosure() {
  38341. function RenderTask(internalRenderTask) {
  38342. this._internalRenderTask = internalRenderTask;
  38343. /**
  38344. * Callback for incremental rendering -- a function that will be called
  38345. * each time the rendering is paused. To continue rendering call the
  38346. * function that is the first argument to the callback.
  38347. * @type {function}
  38348. */
  38349. this.onContinue = null;
  38350. }
  38351. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  38352. /**
  38353. * Promise for rendering task completion.
  38354. * @return {Promise}
  38355. */
  38356. get promise() {
  38357. return this._internalRenderTask.capability.promise;
  38358. },
  38359. /**
  38360. * Cancels the rendering task. If the task is currently rendering it will
  38361. * not be cancelled until graphics pauses with a timeout. The promise that
  38362. * this object extends will resolved when cancelled.
  38363. */
  38364. cancel: function RenderTask_cancel() {
  38365. this._internalRenderTask.cancel();
  38366. },
  38367. /**
  38368. * Registers callbacks to indicate the rendering task completion.
  38369. *
  38370. * @param {function} onFulfilled The callback for the rendering completion.
  38371. * @param {function} onRejected The callback for the rendering failure.
  38372. * @return {Promise} A promise that is resolved after the onFulfilled or
  38373. * onRejected callback.
  38374. */
  38375. then: function RenderTask_then(onFulfilled, onRejected) {
  38376. return this.promise.then.apply(this.promise, arguments);
  38377. }
  38378. };
  38379. return RenderTask;
  38380. })();
  38381. /**
  38382. * For internal use only.
  38383. * @ignore
  38384. */
  38385. var InternalRenderTask = (function InternalRenderTaskClosure() {
  38386. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  38387. pageNumber) {
  38388. this.callback = callback;
  38389. this.params = params;
  38390. this.objs = objs;
  38391. this.commonObjs = commonObjs;
  38392. this.operatorListIdx = null;
  38393. this.operatorList = operatorList;
  38394. this.pageNumber = pageNumber;
  38395. this.running = false;
  38396. this.graphicsReadyCallback = null;
  38397. this.graphicsReady = false;
  38398. this.useRequestAnimationFrame = false;
  38399. this.cancelled = false;
  38400. this.capability = createPromiseCapability();
  38401. this.task = new RenderTask(this);
  38402. // caching this-bound methods
  38403. this._continueBound = this._continue.bind(this);
  38404. this._scheduleNextBound = this._scheduleNext.bind(this);
  38405. this._nextBound = this._next.bind(this);
  38406. }
  38407. InternalRenderTask.prototype = {
  38408. initializeGraphics:
  38409. function InternalRenderTask_initializeGraphics(transparency) {
  38410. if (this.cancelled) {
  38411. return;
  38412. }
  38413. if (getDefaultSetting('pdfBug') && globalScope.StepperManager &&
  38414. globalScope.StepperManager.enabled) {
  38415. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  38416. this.stepper.init(this.operatorList);
  38417. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  38418. }
  38419. var params = this.params;
  38420. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  38421. this.objs, params.imageLayer);
  38422. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  38423. this.operatorListIdx = 0;
  38424. this.graphicsReady = true;
  38425. if (this.graphicsReadyCallback) {
  38426. this.graphicsReadyCallback();
  38427. }
  38428. },
  38429. cancel: function InternalRenderTask_cancel() {
  38430. this.running = false;
  38431. this.cancelled = true;
  38432. this.callback('cancelled');
  38433. },
  38434. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  38435. if (!this.graphicsReady) {
  38436. if (!this.graphicsReadyCallback) {
  38437. this.graphicsReadyCallback = this._continueBound;
  38438. }
  38439. return;
  38440. }
  38441. if (this.stepper) {
  38442. this.stepper.updateOperatorList(this.operatorList);
  38443. }
  38444. if (this.running) {
  38445. return;
  38446. }
  38447. this._continue();
  38448. },
  38449. _continue: function InternalRenderTask__continue() {
  38450. this.running = true;
  38451. if (this.cancelled) {
  38452. return;
  38453. }
  38454. if (this.task.onContinue) {
  38455. this.task.onContinue.call(this.task, this._scheduleNextBound);
  38456. } else {
  38457. this._scheduleNext();
  38458. }
  38459. },
  38460. _scheduleNext: function InternalRenderTask__scheduleNext() {
  38461. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  38462. window.requestAnimationFrame(this._nextBound);
  38463. } else {
  38464. Promise.resolve(undefined).then(this._nextBound);
  38465. }
  38466. },
  38467. _next: function InternalRenderTask__next() {
  38468. if (this.cancelled) {
  38469. return;
  38470. }
  38471. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  38472. this.operatorListIdx,
  38473. this._continueBound,
  38474. this.stepper);
  38475. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  38476. this.running = false;
  38477. if (this.operatorList.lastChunk) {
  38478. this.gfx.endDrawing();
  38479. this.callback();
  38480. }
  38481. }
  38482. }
  38483. };
  38484. return InternalRenderTask;
  38485. })();
  38486. /**
  38487. * (Deprecated) Global observer of unsupported feature usages. Use
  38488. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  38489. */
  38490. var _UnsupportedManager = (function UnsupportedManagerClosure() {
  38491. var listeners = [];
  38492. return {
  38493. listen: function (cb) {
  38494. deprecated('Global UnsupportedManager.listen is used: ' +
  38495. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  38496. listeners.push(cb);
  38497. },
  38498. notify: function (featureId) {
  38499. for (var i = 0, ii = listeners.length; i < ii; i++) {
  38500. listeners[i](featureId);
  38501. }
  38502. }
  38503. };
  38504. })();
  38505. if (typeof pdfjsVersion !== 'undefined') {
  38506. exports.version = pdfjsVersion;
  38507. }
  38508. if (typeof pdfjsBuild !== 'undefined') {
  38509. exports.build = pdfjsBuild;
  38510. }
  38511. exports.getDocument = getDocument;
  38512. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  38513. exports.PDFWorker = PDFWorker;
  38514. exports.PDFDocumentProxy = PDFDocumentProxy;
  38515. exports.PDFPageProxy = PDFPageProxy;
  38516. exports._UnsupportedManager = _UnsupportedManager;
  38517. }));
  38518. (function (root, factory) {
  38519. {
  38520. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  38521. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  38522. }
  38523. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  38524. var error = sharedUtil.error;
  38525. var info = sharedUtil.info;
  38526. var isArray = sharedUtil.isArray;
  38527. var isString = sharedUtil.isString;
  38528. var shadow = sharedUtil.shadow;
  38529. var warn = sharedUtil.warn;
  38530. var isDict = corePrimitives.isDict;
  38531. var isName = corePrimitives.isName;
  38532. var isStream = corePrimitives.isStream;
  38533. var PDFFunction = coreFunction.PDFFunction;
  38534. var ColorSpace = (function ColorSpaceClosure() {
  38535. /**
  38536. * Resizes an RGB image with 3 components.
  38537. * @param {TypedArray} src - The source buffer.
  38538. * @param {Number} bpc - Number of bits per component.
  38539. * @param {Number} w1 - Original width.
  38540. * @param {Number} h1 - Original height.
  38541. * @param {Number} w2 - New width.
  38542. * @param {Number} h2 - New height.
  38543. * @param {Number} alpha01 - Size reserved for the alpha channel.
  38544. * @param {TypedArray} dest - The destination buffer.
  38545. */
  38546. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  38547. var COMPONENTS = 3;
  38548. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  38549. var xRatio = w1 / w2;
  38550. var yRatio = h1 / h2;
  38551. var i, j, py, newIndex = 0, oldIndex;
  38552. var xScaled = new Uint16Array(w2);
  38553. var w1Scanline = w1 * COMPONENTS;
  38554. for (i = 0; i < w2; i++) {
  38555. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  38556. }
  38557. for (i = 0; i < h2; i++) {
  38558. py = Math.floor(i * yRatio) * w1Scanline;
  38559. for (j = 0; j < w2; j++) {
  38560. oldIndex = py + xScaled[j];
  38561. dest[newIndex++] = src[oldIndex++];
  38562. dest[newIndex++] = src[oldIndex++];
  38563. dest[newIndex++] = src[oldIndex++];
  38564. newIndex += alpha01;
  38565. }
  38566. }
  38567. }
  38568. // Constructor should define this.numComps, this.defaultColor, this.name
  38569. function ColorSpace() {
  38570. error('should not call ColorSpace constructor');
  38571. }
  38572. ColorSpace.prototype = {
  38573. /**
  38574. * Converts the color value to the RGB color. The color components are
  38575. * located in the src array starting from the srcOffset. Returns the array
  38576. * of the rgb components, each value ranging from [0,255].
  38577. */
  38578. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  38579. var rgb = new Uint8Array(3);
  38580. this.getRgbItem(src, srcOffset, rgb, 0);
  38581. return rgb;
  38582. },
  38583. /**
  38584. * Converts the color value to the RGB color, similar to the getRgb method.
  38585. * The result placed into the dest array starting from the destOffset.
  38586. */
  38587. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  38588. dest, destOffset) {
  38589. error('Should not call ColorSpace.getRgbItem');
  38590. },
  38591. /**
  38592. * Converts the specified number of the color values to the RGB colors.
  38593. * The colors are located in the src array starting from the srcOffset.
  38594. * The result is placed into the dest array starting from the destOffset.
  38595. * The src array items shall be in [0,2^bits) range, the dest array items
  38596. * will be in [0,255] range. alpha01 indicates how many alpha components
  38597. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  38598. * array).
  38599. */
  38600. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  38601. dest, destOffset, bits,
  38602. alpha01) {
  38603. error('Should not call ColorSpace.getRgbBuffer');
  38604. },
  38605. /**
  38606. * Determines the number of bytes required to store the result of the
  38607. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  38608. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  38609. */
  38610. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  38611. alpha01) {
  38612. error('Should not call ColorSpace.getOutputLength');
  38613. },
  38614. /**
  38615. * Returns true if source data will be equal the result/output data.
  38616. */
  38617. isPassthrough: function ColorSpace_isPassthrough(bits) {
  38618. return false;
  38619. },
  38620. /**
  38621. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  38622. * how many alpha components there are in the dest array; it will be either
  38623. * 0 (RGB array) or 1 (RGBA array).
  38624. */
  38625. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  38626. originalHeight, width, height,
  38627. actualHeight, bpc, comps, alpha01) {
  38628. var count = originalWidth * originalHeight;
  38629. var rgbBuf = null;
  38630. var numComponentColors = 1 << bpc;
  38631. var needsResizing = originalHeight !== height || originalWidth !== width;
  38632. var i, ii;
  38633. if (this.isPassthrough(bpc)) {
  38634. rgbBuf = comps;
  38635. } else if (this.numComps === 1 && count > numComponentColors &&
  38636. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  38637. // Optimization: create a color map when there is just one component and
  38638. // we are converting more colors than the size of the color map. We
  38639. // don't build the map if the colorspace is gray or rgb since those
  38640. // methods are faster than building a map. This mainly offers big speed
  38641. // ups for indexed and alternate colorspaces.
  38642. //
  38643. // TODO it may be worth while to cache the color map. While running
  38644. // testing I never hit a cache so I will leave that out for now (perhaps
  38645. // we are reparsing colorspaces too much?).
  38646. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  38647. new Uint16Array(numComponentColors);
  38648. var key;
  38649. for (i = 0; i < numComponentColors; i++) {
  38650. allColors[i] = i;
  38651. }
  38652. var colorMap = new Uint8Array(numComponentColors * 3);
  38653. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  38654. /* alpha01 = */ 0);
  38655. var destPos, rgbPos;
  38656. if (!needsResizing) {
  38657. // Fill in the RGB values directly into |dest|.
  38658. destPos = 0;
  38659. for (i = 0; i < count; ++i) {
  38660. key = comps[i] * 3;
  38661. dest[destPos++] = colorMap[key];
  38662. dest[destPos++] = colorMap[key + 1];
  38663. dest[destPos++] = colorMap[key + 2];
  38664. destPos += alpha01;
  38665. }
  38666. } else {
  38667. rgbBuf = new Uint8Array(count * 3);
  38668. rgbPos = 0;
  38669. for (i = 0; i < count; ++i) {
  38670. key = comps[i] * 3;
  38671. rgbBuf[rgbPos++] = colorMap[key];
  38672. rgbBuf[rgbPos++] = colorMap[key + 1];
  38673. rgbBuf[rgbPos++] = colorMap[key + 2];
  38674. }
  38675. }
  38676. } else {
  38677. if (!needsResizing) {
  38678. // Fill in the RGB values directly into |dest|.
  38679. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  38680. alpha01);
  38681. } else {
  38682. rgbBuf = new Uint8Array(count * 3);
  38683. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  38684. /* alpha01 = */ 0);
  38685. }
  38686. }
  38687. if (rgbBuf) {
  38688. if (needsResizing) {
  38689. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight,
  38690. width, height, alpha01, dest);
  38691. } else {
  38692. rgbPos = 0;
  38693. destPos = 0;
  38694. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  38695. dest[destPos++] = rgbBuf[rgbPos++];
  38696. dest[destPos++] = rgbBuf[rgbPos++];
  38697. dest[destPos++] = rgbBuf[rgbPos++];
  38698. destPos += alpha01;
  38699. }
  38700. }
  38701. }
  38702. },
  38703. /**
  38704. * True if the colorspace has components in the default range of [0, 1].
  38705. * This should be true for all colorspaces except for lab color spaces
  38706. * which are [0,100], [-128, 127], [-128, 127].
  38707. */
  38708. usesZeroToOneRange: true
  38709. };
  38710. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  38711. var IR = ColorSpace.parseToIR(cs, xref, res);
  38712. if (IR instanceof AlternateCS) {
  38713. return IR;
  38714. }
  38715. return ColorSpace.fromIR(IR);
  38716. };
  38717. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  38718. var name = isArray(IR) ? IR[0] : IR;
  38719. var whitePoint, blackPoint, gamma;
  38720. switch (name) {
  38721. case 'DeviceGrayCS':
  38722. return this.singletons.gray;
  38723. case 'DeviceRgbCS':
  38724. return this.singletons.rgb;
  38725. case 'DeviceCmykCS':
  38726. return this.singletons.cmyk;
  38727. case 'CalGrayCS':
  38728. whitePoint = IR[1];
  38729. blackPoint = IR[2];
  38730. gamma = IR[3];
  38731. return new CalGrayCS(whitePoint, blackPoint, gamma);
  38732. case 'CalRGBCS':
  38733. whitePoint = IR[1];
  38734. blackPoint = IR[2];
  38735. gamma = IR[3];
  38736. var matrix = IR[4];
  38737. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  38738. case 'PatternCS':
  38739. var basePatternCS = IR[1];
  38740. if (basePatternCS) {
  38741. basePatternCS = ColorSpace.fromIR(basePatternCS);
  38742. }
  38743. return new PatternCS(basePatternCS);
  38744. case 'IndexedCS':
  38745. var baseIndexedCS = IR[1];
  38746. var hiVal = IR[2];
  38747. var lookup = IR[3];
  38748. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  38749. case 'AlternateCS':
  38750. var numComps = IR[1];
  38751. var alt = IR[2];
  38752. var tintFnIR = IR[3];
  38753. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  38754. PDFFunction.fromIR(tintFnIR));
  38755. case 'LabCS':
  38756. whitePoint = IR[1];
  38757. blackPoint = IR[2];
  38758. var range = IR[3];
  38759. return new LabCS(whitePoint, blackPoint, range);
  38760. default:
  38761. error('Unknown name ' + name);
  38762. }
  38763. return null;
  38764. };
  38765. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38766. if (isName(cs)) {
  38767. var colorSpaces = res.get('ColorSpace');
  38768. if (isDict(colorSpaces)) {
  38769. var refcs = colorSpaces.get(cs.name);
  38770. if (refcs) {
  38771. cs = refcs;
  38772. }
  38773. }
  38774. }
  38775. cs = xref.fetchIfRef(cs);
  38776. var mode;
  38777. if (isName(cs)) {
  38778. mode = cs.name;
  38779. this.mode = mode;
  38780. switch (mode) {
  38781. case 'DeviceGray':
  38782. case 'G':
  38783. return 'DeviceGrayCS';
  38784. case 'DeviceRGB':
  38785. case 'RGB':
  38786. return 'DeviceRgbCS';
  38787. case 'DeviceCMYK':
  38788. case 'CMYK':
  38789. return 'DeviceCmykCS';
  38790. case 'Pattern':
  38791. return ['PatternCS', null];
  38792. default:
  38793. error('unrecognized colorspace ' + mode);
  38794. }
  38795. } else if (isArray(cs)) {
  38796. mode = xref.fetchIfRef(cs[0]).name;
  38797. this.mode = mode;
  38798. var numComps, params, alt, whitePoint, blackPoint, gamma;
  38799. switch (mode) {
  38800. case 'DeviceGray':
  38801. case 'G':
  38802. return 'DeviceGrayCS';
  38803. case 'DeviceRGB':
  38804. case 'RGB':
  38805. return 'DeviceRgbCS';
  38806. case 'DeviceCMYK':
  38807. case 'CMYK':
  38808. return 'DeviceCmykCS';
  38809. case 'CalGray':
  38810. params = xref.fetchIfRef(cs[1]);
  38811. whitePoint = params.getArray('WhitePoint');
  38812. blackPoint = params.getArray('BlackPoint');
  38813. gamma = params.get('Gamma');
  38814. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  38815. case 'CalRGB':
  38816. params = xref.fetchIfRef(cs[1]);
  38817. whitePoint = params.getArray('WhitePoint');
  38818. blackPoint = params.getArray('BlackPoint');
  38819. gamma = params.getArray('Gamma');
  38820. var matrix = params.getArray('Matrix');
  38821. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  38822. case 'ICCBased':
  38823. var stream = xref.fetchIfRef(cs[1]);
  38824. var dict = stream.dict;
  38825. numComps = dict.get('N');
  38826. alt = dict.get('Alternate');
  38827. if (alt) {
  38828. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38829. // Parse the /Alternate CS to ensure that the number of components
  38830. // are correct, and also (indirectly) that it is not a PatternCS.
  38831. var altCS = ColorSpace.fromIR(altIR);
  38832. if (altCS.numComps === numComps) {
  38833. return altIR;
  38834. }
  38835. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38836. }
  38837. if (numComps === 1) {
  38838. return 'DeviceGrayCS';
  38839. } else if (numComps === 3) {
  38840. return 'DeviceRgbCS';
  38841. } else if (numComps === 4) {
  38842. return 'DeviceCmykCS';
  38843. }
  38844. break;
  38845. case 'Pattern':
  38846. var basePatternCS = cs[1] || null;
  38847. if (basePatternCS) {
  38848. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38849. }
  38850. return ['PatternCS', basePatternCS];
  38851. case 'Indexed':
  38852. case 'I':
  38853. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38854. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38855. var lookup = xref.fetchIfRef(cs[3]);
  38856. if (isStream(lookup)) {
  38857. lookup = lookup.getBytes();
  38858. }
  38859. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38860. case 'Separation':
  38861. case 'DeviceN':
  38862. var name = xref.fetchIfRef(cs[1]);
  38863. numComps = 1;
  38864. if (isName(name)) {
  38865. numComps = 1;
  38866. } else if (isArray(name)) {
  38867. numComps = name.length;
  38868. }
  38869. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38870. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38871. return ['AlternateCS', numComps, alt, tintFnIR];
  38872. case 'Lab':
  38873. params = xref.fetchIfRef(cs[1]);
  38874. whitePoint = params.getArray('WhitePoint');
  38875. blackPoint = params.getArray('BlackPoint');
  38876. var range = params.getArray('Range');
  38877. return ['LabCS', whitePoint, blackPoint, range];
  38878. default:
  38879. error('unimplemented color space object "' + mode + '"');
  38880. }
  38881. } else {
  38882. error('unrecognized color space object: "' + cs + '"');
  38883. }
  38884. return null;
  38885. };
  38886. /**
  38887. * Checks if a decode map matches the default decode map for a color space.
  38888. * This handles the general decode maps where there are two values per
  38889. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38890. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38891. * slightly different.
  38892. * @param {Array} decode Decode map (usually from an image).
  38893. * @param {Number} n Number of components the color space has.
  38894. */
  38895. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38896. if (!isArray(decode)) {
  38897. return true;
  38898. }
  38899. if (n * 2 !== decode.length) {
  38900. warn('The decode map is not the correct length');
  38901. return true;
  38902. }
  38903. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38904. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38905. return false;
  38906. }
  38907. }
  38908. return true;
  38909. };
  38910. ColorSpace.singletons = {
  38911. get gray() {
  38912. return shadow(this, 'gray', new DeviceGrayCS());
  38913. },
  38914. get rgb() {
  38915. return shadow(this, 'rgb', new DeviceRgbCS());
  38916. },
  38917. get cmyk() {
  38918. return shadow(this, 'cmyk', new DeviceCmykCS());
  38919. }
  38920. };
  38921. return ColorSpace;
  38922. })();
  38923. /**
  38924. * Alternate color space handles both Separation and DeviceN color spaces. A
  38925. * Separation color space is actually just a DeviceN with one color component.
  38926. * Both color spaces use a tinting function to convert colors to a base color
  38927. * space.
  38928. */
  38929. var AlternateCS = (function AlternateCSClosure() {
  38930. function AlternateCS(numComps, base, tintFn) {
  38931. this.name = 'Alternate';
  38932. this.numComps = numComps;
  38933. this.defaultColor = new Float32Array(numComps);
  38934. for (var i = 0; i < numComps; ++i) {
  38935. this.defaultColor[i] = 1;
  38936. }
  38937. this.base = base;
  38938. this.tintFn = tintFn;
  38939. this.tmpBuf = new Float32Array(base.numComps);
  38940. }
  38941. AlternateCS.prototype = {
  38942. getRgb: ColorSpace.prototype.getRgb,
  38943. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38944. dest, destOffset) {
  38945. var tmpBuf = this.tmpBuf;
  38946. this.tintFn(src, srcOffset, tmpBuf, 0);
  38947. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38948. },
  38949. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38950. dest, destOffset, bits,
  38951. alpha01) {
  38952. var tintFn = this.tintFn;
  38953. var base = this.base;
  38954. var scale = 1 / ((1 << bits) - 1);
  38955. var baseNumComps = base.numComps;
  38956. var usesZeroToOneRange = base.usesZeroToOneRange;
  38957. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38958. alpha01 === 0;
  38959. var pos = isPassthrough ? destOffset : 0;
  38960. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38961. var numComps = this.numComps;
  38962. var scaled = new Float32Array(numComps);
  38963. var tinted = new Float32Array(baseNumComps);
  38964. var i, j;
  38965. if (usesZeroToOneRange) {
  38966. for (i = 0; i < count; i++) {
  38967. for (j = 0; j < numComps; j++) {
  38968. scaled[j] = src[srcOffset++] * scale;
  38969. }
  38970. tintFn(scaled, 0, tinted, 0);
  38971. for (j = 0; j < baseNumComps; j++) {
  38972. baseBuf[pos++] = tinted[j] * 255;
  38973. }
  38974. }
  38975. } else {
  38976. for (i = 0; i < count; i++) {
  38977. for (j = 0; j < numComps; j++) {
  38978. scaled[j] = src[srcOffset++] * scale;
  38979. }
  38980. tintFn(scaled, 0, tinted, 0);
  38981. base.getRgbItem(tinted, 0, baseBuf, pos);
  38982. pos += baseNumComps;
  38983. }
  38984. }
  38985. if (!isPassthrough) {
  38986. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38987. }
  38988. },
  38989. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38990. alpha01) {
  38991. return this.base.getOutputLength(inputLength *
  38992. this.base.numComps / this.numComps,
  38993. alpha01);
  38994. },
  38995. isPassthrough: ColorSpace.prototype.isPassthrough,
  38996. fillRgb: ColorSpace.prototype.fillRgb,
  38997. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38998. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38999. },
  39000. usesZeroToOneRange: true
  39001. };
  39002. return AlternateCS;
  39003. })();
  39004. var PatternCS = (function PatternCSClosure() {
  39005. function PatternCS(baseCS) {
  39006. this.name = 'Pattern';
  39007. this.base = baseCS;
  39008. }
  39009. PatternCS.prototype = {};
  39010. return PatternCS;
  39011. })();
  39012. var IndexedCS = (function IndexedCSClosure() {
  39013. function IndexedCS(base, highVal, lookup) {
  39014. this.name = 'Indexed';
  39015. this.numComps = 1;
  39016. this.defaultColor = new Uint8Array([0]);
  39017. this.base = base;
  39018. this.highVal = highVal;
  39019. var baseNumComps = base.numComps;
  39020. var length = baseNumComps * highVal;
  39021. var lookupArray;
  39022. if (isStream(lookup)) {
  39023. lookupArray = new Uint8Array(length);
  39024. var bytes = lookup.getBytes(length);
  39025. lookupArray.set(bytes);
  39026. } else if (isString(lookup)) {
  39027. lookupArray = new Uint8Array(length);
  39028. for (var i = 0; i < length; ++i) {
  39029. lookupArray[i] = lookup.charCodeAt(i);
  39030. }
  39031. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  39032. lookupArray = lookup;
  39033. } else {
  39034. error('Unrecognized lookup table: ' + lookup);
  39035. }
  39036. this.lookup = lookupArray;
  39037. }
  39038. IndexedCS.prototype = {
  39039. getRgb: ColorSpace.prototype.getRgb,
  39040. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  39041. dest, destOffset) {
  39042. var numComps = this.base.numComps;
  39043. var start = src[srcOffset] * numComps;
  39044. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  39045. },
  39046. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  39047. dest, destOffset, bits,
  39048. alpha01) {
  39049. var base = this.base;
  39050. var numComps = base.numComps;
  39051. var outputDelta = base.getOutputLength(numComps, alpha01);
  39052. var lookup = this.lookup;
  39053. for (var i = 0; i < count; ++i) {
  39054. var lookupPos = src[srcOffset++] * numComps;
  39055. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  39056. destOffset += outputDelta;
  39057. }
  39058. },
  39059. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  39060. return this.base.getOutputLength(inputLength * this.base.numComps,
  39061. alpha01);
  39062. },
  39063. isPassthrough: ColorSpace.prototype.isPassthrough,
  39064. fillRgb: ColorSpace.prototype.fillRgb,
  39065. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  39066. // indexed color maps shouldn't be changed
  39067. return true;
  39068. },
  39069. usesZeroToOneRange: true
  39070. };
  39071. return IndexedCS;
  39072. })();
  39073. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  39074. function DeviceGrayCS() {
  39075. this.name = 'DeviceGray';
  39076. this.numComps = 1;
  39077. this.defaultColor = new Float32Array([0]);
  39078. }
  39079. DeviceGrayCS.prototype = {
  39080. getRgb: ColorSpace.prototype.getRgb,
  39081. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  39082. dest, destOffset) {
  39083. var c = (src[srcOffset] * 255) | 0;
  39084. c = c < 0 ? 0 : c > 255 ? 255 : c;
  39085. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  39086. },
  39087. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  39088. dest, destOffset, bits,
  39089. alpha01) {
  39090. var scale = 255 / ((1 << bits) - 1);
  39091. var j = srcOffset, q = destOffset;
  39092. for (var i = 0; i < count; ++i) {
  39093. var c = (scale * src[j++]) | 0;
  39094. dest[q++] = c;
  39095. dest[q++] = c;
  39096. dest[q++] = c;
  39097. q += alpha01;
  39098. }
  39099. },
  39100. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  39101. alpha01) {
  39102. return inputLength * (3 + alpha01);
  39103. },
  39104. isPassthrough: ColorSpace.prototype.isPassthrough,
  39105. fillRgb: ColorSpace.prototype.fillRgb,
  39106. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  39107. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39108. },
  39109. usesZeroToOneRange: true
  39110. };
  39111. return DeviceGrayCS;
  39112. })();
  39113. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  39114. function DeviceRgbCS() {
  39115. this.name = 'DeviceRGB';
  39116. this.numComps = 3;
  39117. this.defaultColor = new Float32Array([0, 0, 0]);
  39118. }
  39119. DeviceRgbCS.prototype = {
  39120. getRgb: ColorSpace.prototype.getRgb,
  39121. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  39122. dest, destOffset) {
  39123. var r = (src[srcOffset] * 255) | 0;
  39124. var g = (src[srcOffset + 1] * 255) | 0;
  39125. var b = (src[srcOffset + 2] * 255) | 0;
  39126. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  39127. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  39128. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  39129. },
  39130. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  39131. dest, destOffset, bits,
  39132. alpha01) {
  39133. if (bits === 8 && alpha01 === 0) {
  39134. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  39135. return;
  39136. }
  39137. var scale = 255 / ((1 << bits) - 1);
  39138. var j = srcOffset, q = destOffset;
  39139. for (var i = 0; i < count; ++i) {
  39140. dest[q++] = (scale * src[j++]) | 0;
  39141. dest[q++] = (scale * src[j++]) | 0;
  39142. dest[q++] = (scale * src[j++]) | 0;
  39143. q += alpha01;
  39144. }
  39145. },
  39146. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  39147. alpha01) {
  39148. return (inputLength * (3 + alpha01) / 3) | 0;
  39149. },
  39150. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  39151. return bits === 8;
  39152. },
  39153. fillRgb: ColorSpace.prototype.fillRgb,
  39154. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  39155. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39156. },
  39157. usesZeroToOneRange: true
  39158. };
  39159. return DeviceRgbCS;
  39160. })();
  39161. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  39162. // The coefficients below was found using numerical analysis: the method of
  39163. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  39164. // where color_value is the tabular value from the table of sampled RGB colors
  39165. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  39166. // CMYK color conversion using the estimation below:
  39167. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  39168. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  39169. var c = src[srcOffset + 0] * srcScale;
  39170. var m = src[srcOffset + 1] * srcScale;
  39171. var y = src[srcOffset + 2] * srcScale;
  39172. var k = src[srcOffset + 3] * srcScale;
  39173. var r =
  39174. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  39175. 18.82290502165302 * y + 212.25662451639585 * k +
  39176. -285.2331026137004) +
  39177. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  39178. -17.873870861415444 * k - 5.497006427196366) +
  39179. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  39180. 17.5119270841813) +
  39181. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  39182. var g =
  39183. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  39184. 6.871425592049007 * y + 31.159100130055922 * k +
  39185. -79.2970844816548) +
  39186. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  39187. 131.35250912493976 * k - 190.9453302588951) +
  39188. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  39189. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  39190. var b =
  39191. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  39192. 30.89978309703729 * y - 0.23883238689178934 * k +
  39193. -14.183576799673286) +
  39194. m * (10.49593273432072 * m + 63.02378494754052 * y +
  39195. 50.606957656360734 * k - 112.23884253719248) +
  39196. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  39197. -193.58209356861505) +
  39198. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  39199. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  39200. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  39201. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  39202. }
  39203. function DeviceCmykCS() {
  39204. this.name = 'DeviceCMYK';
  39205. this.numComps = 4;
  39206. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  39207. }
  39208. DeviceCmykCS.prototype = {
  39209. getRgb: ColorSpace.prototype.getRgb,
  39210. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  39211. dest, destOffset) {
  39212. convertToRgb(src, srcOffset, 1, dest, destOffset);
  39213. },
  39214. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  39215. dest, destOffset, bits,
  39216. alpha01) {
  39217. var scale = 1 / ((1 << bits) - 1);
  39218. for (var i = 0; i < count; i++) {
  39219. convertToRgb(src, srcOffset, scale, dest, destOffset);
  39220. srcOffset += 4;
  39221. destOffset += 3 + alpha01;
  39222. }
  39223. },
  39224. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  39225. alpha01) {
  39226. return (inputLength / 4 * (3 + alpha01)) | 0;
  39227. },
  39228. isPassthrough: ColorSpace.prototype.isPassthrough,
  39229. fillRgb: ColorSpace.prototype.fillRgb,
  39230. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  39231. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39232. },
  39233. usesZeroToOneRange: true
  39234. };
  39235. return DeviceCmykCS;
  39236. })();
  39237. //
  39238. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  39239. //
  39240. var CalGrayCS = (function CalGrayCSClosure() {
  39241. function CalGrayCS(whitePoint, blackPoint, gamma) {
  39242. this.name = 'CalGray';
  39243. this.numComps = 1;
  39244. this.defaultColor = new Float32Array([0]);
  39245. if (!whitePoint) {
  39246. error('WhitePoint missing - required for color space CalGray');
  39247. }
  39248. blackPoint = blackPoint || [0, 0, 0];
  39249. gamma = gamma || 1;
  39250. // Translate arguments to spec variables.
  39251. this.XW = whitePoint[0];
  39252. this.YW = whitePoint[1];
  39253. this.ZW = whitePoint[2];
  39254. this.XB = blackPoint[0];
  39255. this.YB = blackPoint[1];
  39256. this.ZB = blackPoint[2];
  39257. this.G = gamma;
  39258. // Validate variables as per spec.
  39259. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39260. error('Invalid WhitePoint components for ' + this.name +
  39261. ', no fallback available');
  39262. }
  39263. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39264. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  39265. this.XB = this.YB = this.ZB = 0;
  39266. }
  39267. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  39268. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  39269. ', ZB: ' + this.ZB + ', only default values are supported.');
  39270. }
  39271. if (this.G < 1) {
  39272. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  39273. ', falling back to default');
  39274. this.G = 1;
  39275. }
  39276. }
  39277. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39278. // A represents a gray component of a calibrated gray space.
  39279. // A <---> AG in the spec
  39280. var A = src[srcOffset] * scale;
  39281. var AG = Math.pow(A, cs.G);
  39282. // Computes L as per spec. ( = cs.YW * AG )
  39283. // Except if other than default BlackPoint values are used.
  39284. var L = cs.YW * AG;
  39285. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  39286. // Convert values to rgb range [0, 255].
  39287. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  39288. dest[destOffset] = val;
  39289. dest[destOffset + 1] = val;
  39290. dest[destOffset + 2] = val;
  39291. }
  39292. CalGrayCS.prototype = {
  39293. getRgb: ColorSpace.prototype.getRgb,
  39294. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  39295. dest, destOffset) {
  39296. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39297. },
  39298. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  39299. dest, destOffset, bits,
  39300. alpha01) {
  39301. var scale = 1 / ((1 << bits) - 1);
  39302. for (var i = 0; i < count; ++i) {
  39303. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39304. srcOffset += 1;
  39305. destOffset += 3 + alpha01;
  39306. }
  39307. },
  39308. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  39309. return inputLength * (3 + alpha01);
  39310. },
  39311. isPassthrough: ColorSpace.prototype.isPassthrough,
  39312. fillRgb: ColorSpace.prototype.fillRgb,
  39313. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  39314. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39315. },
  39316. usesZeroToOneRange: true
  39317. };
  39318. return CalGrayCS;
  39319. })();
  39320. //
  39321. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  39322. //
  39323. var CalRGBCS = (function CalRGBCSClosure() {
  39324. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  39325. // matrices.
  39326. var BRADFORD_SCALE_MATRIX = new Float32Array([
  39327. 0.8951, 0.2664, -0.1614,
  39328. -0.7502, 1.7135, 0.0367,
  39329. 0.0389, -0.0685, 1.0296]);
  39330. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  39331. 0.9869929, -0.1470543, 0.1599627,
  39332. 0.4323053, 0.5183603, 0.0492912,
  39333. -0.0085287, 0.0400428, 0.9684867]);
  39334. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  39335. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  39336. 3.2404542, -1.5371385, -0.4985314,
  39337. -0.9692660, 1.8760108, 0.0415560,
  39338. 0.0556434, -0.2040259, 1.0572252]);
  39339. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  39340. var tempNormalizeMatrix = new Float32Array(3);
  39341. var tempConvertMatrix1 = new Float32Array(3);
  39342. var tempConvertMatrix2 = new Float32Array(3);
  39343. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  39344. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  39345. this.name = 'CalRGB';
  39346. this.numComps = 3;
  39347. this.defaultColor = new Float32Array(3);
  39348. if (!whitePoint) {
  39349. error('WhitePoint missing - required for color space CalRGB');
  39350. }
  39351. blackPoint = blackPoint || new Float32Array(3);
  39352. gamma = gamma || new Float32Array([1, 1, 1]);
  39353. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  39354. // Translate arguments to spec variables.
  39355. var XW = whitePoint[0];
  39356. var YW = whitePoint[1];
  39357. var ZW = whitePoint[2];
  39358. this.whitePoint = whitePoint;
  39359. var XB = blackPoint[0];
  39360. var YB = blackPoint[1];
  39361. var ZB = blackPoint[2];
  39362. this.blackPoint = blackPoint;
  39363. this.GR = gamma[0];
  39364. this.GG = gamma[1];
  39365. this.GB = gamma[2];
  39366. this.MXA = matrix[0];
  39367. this.MYA = matrix[1];
  39368. this.MZA = matrix[2];
  39369. this.MXB = matrix[3];
  39370. this.MYB = matrix[4];
  39371. this.MZB = matrix[5];
  39372. this.MXC = matrix[6];
  39373. this.MYC = matrix[7];
  39374. this.MZC = matrix[8];
  39375. // Validate variables as per spec.
  39376. if (XW < 0 || ZW < 0 || YW !== 1) {
  39377. error('Invalid WhitePoint components for ' + this.name +
  39378. ', no fallback available');
  39379. }
  39380. if (XB < 0 || YB < 0 || ZB < 0) {
  39381. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  39382. ', ' + ZB + '], falling back to default');
  39383. this.blackPoint = new Float32Array(3);
  39384. }
  39385. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  39386. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  39387. '] for ' + this.name + ', falling back to default');
  39388. this.GR = this.GG = this.GB = 1;
  39389. }
  39390. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  39391. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  39392. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  39393. info('Invalid Matrix for ' + this.name + ' [' +
  39394. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  39395. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  39396. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  39397. '], falling back to default');
  39398. this.MXA = this.MYB = this.MZC = 1;
  39399. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  39400. }
  39401. }
  39402. function matrixProduct(a, b, result) {
  39403. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  39404. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  39405. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  39406. }
  39407. function convertToFlat(sourceWhitePoint, LMS, result) {
  39408. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  39409. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  39410. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  39411. }
  39412. function convertToD65(sourceWhitePoint, LMS, result) {
  39413. var D65X = 0.95047;
  39414. var D65Y = 1;
  39415. var D65Z = 1.08883;
  39416. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  39417. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  39418. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  39419. }
  39420. function sRGBTransferFunction(color) {
  39421. // See http://en.wikipedia.org/wiki/SRGB.
  39422. if (color <= 0.0031308){
  39423. return adjustToRange(0, 1, 12.92 * color);
  39424. }
  39425. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  39426. }
  39427. function adjustToRange(min, max, value) {
  39428. return Math.max(min, Math.min(max, value));
  39429. }
  39430. function decodeL(L) {
  39431. if (L < 0) {
  39432. return -decodeL(-L);
  39433. }
  39434. if (L > 8.0) {
  39435. return Math.pow(((L + 16) / 116), 3);
  39436. }
  39437. return L * DECODE_L_CONSTANT;
  39438. }
  39439. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  39440. // In case the blackPoint is already the default blackPoint then there is
  39441. // no need to do compensation.
  39442. if (sourceBlackPoint[0] === 0 &&
  39443. sourceBlackPoint[1] === 0 &&
  39444. sourceBlackPoint[2] === 0) {
  39445. result[0] = XYZ_Flat[0];
  39446. result[1] = XYZ_Flat[1];
  39447. result[2] = XYZ_Flat[2];
  39448. return;
  39449. }
  39450. // For the blackPoint calculation details, please see
  39451. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39452. // AdobeBPC.pdf.
  39453. // The destination blackPoint is the default blackPoint [0, 0, 0].
  39454. var zeroDecodeL = decodeL(0);
  39455. var X_DST = zeroDecodeL;
  39456. var X_SRC = decodeL(sourceBlackPoint[0]);
  39457. var Y_DST = zeroDecodeL;
  39458. var Y_SRC = decodeL(sourceBlackPoint[1]);
  39459. var Z_DST = zeroDecodeL;
  39460. var Z_SRC = decodeL(sourceBlackPoint[2]);
  39461. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  39462. var X_Offset = 1 - X_Scale;
  39463. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  39464. var Y_Offset = 1 - Y_Scale;
  39465. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  39466. var Z_Offset = 1 - Z_Scale;
  39467. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  39468. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  39469. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  39470. }
  39471. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  39472. // In case the whitePoint is already flat then there is no need to do
  39473. // normalization.
  39474. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  39475. result[0] = XYZ_In[0];
  39476. result[1] = XYZ_In[1];
  39477. result[2] = XYZ_In[2];
  39478. return;
  39479. }
  39480. var LMS = result;
  39481. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39482. var LMS_Flat = tempNormalizeMatrix;
  39483. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  39484. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  39485. }
  39486. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  39487. var LMS = result;
  39488. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39489. var LMS_D65 = tempNormalizeMatrix;
  39490. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  39491. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  39492. }
  39493. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39494. // A, B and C represent a red, green and blue components of a calibrated
  39495. // rgb space.
  39496. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  39497. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  39498. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  39499. // A <---> AGR in the spec
  39500. // B <---> BGG in the spec
  39501. // C <---> CGB in the spec
  39502. var AGR = Math.pow(A, cs.GR);
  39503. var BGG = Math.pow(B, cs.GG);
  39504. var CGB = Math.pow(C, cs.GB);
  39505. // Computes intermediate variables L, M, N as per spec.
  39506. // To decode X, Y, Z values map L, M, N directly to them.
  39507. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  39508. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  39509. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  39510. // The following calculations are based on this document:
  39511. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39512. // AdobeBPC.pdf.
  39513. var XYZ = tempConvertMatrix1;
  39514. XYZ[0] = X;
  39515. XYZ[1] = Y;
  39516. XYZ[2] = Z;
  39517. var XYZ_Flat = tempConvertMatrix2;
  39518. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  39519. var XYZ_Black = tempConvertMatrix1;
  39520. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  39521. var XYZ_D65 = tempConvertMatrix2;
  39522. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  39523. var SRGB = tempConvertMatrix1;
  39524. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  39525. var sR = sRGBTransferFunction(SRGB[0]);
  39526. var sG = sRGBTransferFunction(SRGB[1]);
  39527. var sB = sRGBTransferFunction(SRGB[2]);
  39528. // Convert the values to rgb range [0, 255].
  39529. dest[destOffset] = Math.round(sR * 255);
  39530. dest[destOffset + 1] = Math.round(sG * 255);
  39531. dest[destOffset + 2] = Math.round(sB * 255);
  39532. }
  39533. CalRGBCS.prototype = {
  39534. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  39535. var rgb = new Uint8Array(3);
  39536. this.getRgbItem(src, srcOffset, rgb, 0);
  39537. return rgb;
  39538. },
  39539. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  39540. dest, destOffset) {
  39541. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39542. },
  39543. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  39544. dest, destOffset, bits,
  39545. alpha01) {
  39546. var scale = 1 / ((1 << bits) - 1);
  39547. for (var i = 0; i < count; ++i) {
  39548. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39549. srcOffset += 3;
  39550. destOffset += 3 + alpha01;
  39551. }
  39552. },
  39553. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  39554. return (inputLength * (3 + alpha01) / 3) | 0;
  39555. },
  39556. isPassthrough: ColorSpace.prototype.isPassthrough,
  39557. fillRgb: ColorSpace.prototype.fillRgb,
  39558. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  39559. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39560. },
  39561. usesZeroToOneRange: true
  39562. };
  39563. return CalRGBCS;
  39564. })();
  39565. //
  39566. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  39567. //
  39568. var LabCS = (function LabCSClosure() {
  39569. function LabCS(whitePoint, blackPoint, range) {
  39570. this.name = 'Lab';
  39571. this.numComps = 3;
  39572. this.defaultColor = new Float32Array([0, 0, 0]);
  39573. if (!whitePoint) {
  39574. error('WhitePoint missing - required for color space Lab');
  39575. }
  39576. blackPoint = blackPoint || [0, 0, 0];
  39577. range = range || [-100, 100, -100, 100];
  39578. // Translate args to spec variables
  39579. this.XW = whitePoint[0];
  39580. this.YW = whitePoint[1];
  39581. this.ZW = whitePoint[2];
  39582. this.amin = range[0];
  39583. this.amax = range[1];
  39584. this.bmin = range[2];
  39585. this.bmax = range[3];
  39586. // These are here just for completeness - the spec doesn't offer any
  39587. // formulas that use BlackPoint in Lab
  39588. this.XB = blackPoint[0];
  39589. this.YB = blackPoint[1];
  39590. this.ZB = blackPoint[2];
  39591. // Validate vars as per spec
  39592. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39593. error('Invalid WhitePoint components, no fallback available');
  39594. }
  39595. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39596. info('Invalid BlackPoint, falling back to default');
  39597. this.XB = this.YB = this.ZB = 0;
  39598. }
  39599. if (this.amin > this.amax || this.bmin > this.bmax) {
  39600. info('Invalid Range, falling back to defaults');
  39601. this.amin = -100;
  39602. this.amax = 100;
  39603. this.bmin = -100;
  39604. this.bmax = 100;
  39605. }
  39606. }
  39607. // Function g(x) from spec
  39608. function fn_g(x) {
  39609. if (x >= 6 / 29) {
  39610. return x * x * x;
  39611. } else {
  39612. return (108 / 841) * (x - 4 / 29);
  39613. }
  39614. }
  39615. function decode(value, high1, low2, high2) {
  39616. return low2 + (value) * (high2 - low2) / (high1);
  39617. }
  39618. // If decoding is needed maxVal should be 2^bits per component - 1.
  39619. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  39620. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  39621. // not the usual [0, 1]. If a command like setFillColor is used the src
  39622. // values will already be within the correct range. However, if we are
  39623. // converting an image we have to map the values to the correct range given
  39624. // above.
  39625. // Ls,as,bs <---> L*,a*,b* in the spec
  39626. var Ls = src[srcOffset];
  39627. var as = src[srcOffset + 1];
  39628. var bs = src[srcOffset + 2];
  39629. if (maxVal !== false) {
  39630. Ls = decode(Ls, maxVal, 0, 100);
  39631. as = decode(as, maxVal, cs.amin, cs.amax);
  39632. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  39633. }
  39634. // Adjust limits of 'as' and 'bs'
  39635. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  39636. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  39637. // Computes intermediate variables X,Y,Z as per spec
  39638. var M = (Ls + 16) / 116;
  39639. var L = M + (as / 500);
  39640. var N = M - (bs / 200);
  39641. var X = cs.XW * fn_g(L);
  39642. var Y = cs.YW * fn_g(M);
  39643. var Z = cs.ZW * fn_g(N);
  39644. var r, g, b;
  39645. // Using different conversions for D50 and D65 white points,
  39646. // per http://www.color.org/srgb.pdf
  39647. if (cs.ZW < 1) {
  39648. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  39649. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  39650. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  39651. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  39652. } else {
  39653. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  39654. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  39655. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  39656. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  39657. }
  39658. // clamp color values to [0,1] range then convert to [0,255] range.
  39659. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  39660. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  39661. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  39662. }
  39663. LabCS.prototype = {
  39664. getRgb: ColorSpace.prototype.getRgb,
  39665. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  39666. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  39667. },
  39668. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  39669. dest, destOffset, bits,
  39670. alpha01) {
  39671. var maxVal = (1 << bits) - 1;
  39672. for (var i = 0; i < count; i++) {
  39673. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  39674. srcOffset += 3;
  39675. destOffset += 3 + alpha01;
  39676. }
  39677. },
  39678. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  39679. return (inputLength * (3 + alpha01) / 3) | 0;
  39680. },
  39681. isPassthrough: ColorSpace.prototype.isPassthrough,
  39682. fillRgb: ColorSpace.prototype.fillRgb,
  39683. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  39684. // XXX: Decoding is handled with the lab conversion because of the strange
  39685. // ranges that are used.
  39686. return true;
  39687. },
  39688. usesZeroToOneRange: false
  39689. };
  39690. return LabCS;
  39691. })();
  39692. exports.ColorSpace = ColorSpace;
  39693. }));
  39694. (function (root, factory) {
  39695. {
  39696. factory((root.pdfjsDisplayGlobal = {}), root.pdfjsSharedUtil,
  39697. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayAPI,
  39698. root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer,
  39699. root.pdfjsDisplayMetadata, root.pdfjsDisplaySVG);
  39700. }
  39701. }(this, function (exports, sharedUtil, displayDOMUtils, displayAPI,
  39702. displayAnnotationLayer, displayTextLayer, displayMetadata,
  39703. displaySVG) {
  39704. var globalScope = sharedUtil.globalScope;
  39705. var deprecated = sharedUtil.deprecated;
  39706. var warn = sharedUtil.warn;
  39707. var LinkTarget = displayDOMUtils.LinkTarget;
  39708. var isWorker = (typeof window === 'undefined');
  39709. // The global PDFJS object is now deprecated and will not be supported in
  39710. // the future. The members below are maintained for backward compatibility
  39711. // and shall not be extended or modified. If the global.js is included as
  39712. // a module, we will create a global PDFJS object instance or use existing.
  39713. if (!globalScope.PDFJS) {
  39714. globalScope.PDFJS = {};
  39715. }
  39716. var PDFJS = globalScope.PDFJS;
  39717. if (typeof pdfjsVersion !== 'undefined') {
  39718. PDFJS.version = pdfjsVersion;
  39719. }
  39720. if (typeof pdfjsBuild !== 'undefined') {
  39721. PDFJS.build = pdfjsBuild;
  39722. }
  39723. PDFJS.pdfBug = false;
  39724. if (PDFJS.verbosity !== undefined) {
  39725. sharedUtil.setVerbosityLevel(PDFJS.verbosity);
  39726. }
  39727. delete PDFJS.verbosity;
  39728. Object.defineProperty(PDFJS, 'verbosity', {
  39729. get: function () { return sharedUtil.getVerbosityLevel(); },
  39730. set: function (level) { sharedUtil.setVerbosityLevel(level); },
  39731. enumerable: true,
  39732. configurable: true
  39733. });
  39734. PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
  39735. PDFJS.OPS = sharedUtil.OPS;
  39736. PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39737. PDFJS.isValidUrl = sharedUtil.isValidUrl;
  39738. PDFJS.shadow = sharedUtil.shadow;
  39739. PDFJS.createBlob = sharedUtil.createBlob;
  39740. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  39741. return sharedUtil.createObjectURL(data, contentType,
  39742. PDFJS.disableCreateObjectURL);
  39743. };
  39744. Object.defineProperty(PDFJS, 'isLittleEndian', {
  39745. configurable: true,
  39746. get: function PDFJS_isLittleEndian() {
  39747. var value = sharedUtil.isLittleEndian();
  39748. return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
  39749. }
  39750. });
  39751. PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
  39752. PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
  39753. PDFJS.PasswordException = sharedUtil.PasswordException;
  39754. PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
  39755. PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
  39756. PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
  39757. PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39758. PDFJS.Util = sharedUtil.Util;
  39759. PDFJS.PageViewport = sharedUtil.PageViewport;
  39760. PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
  39761. /**
  39762. * The maximum allowed image size in total pixels e.g. width * height. Images
  39763. * above this value will not be drawn. Use -1 for no limit.
  39764. * @var {number}
  39765. */
  39766. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  39767. -1 : PDFJS.maxImageSize);
  39768. /**
  39769. * The url of where the predefined Adobe CMaps are located. Include trailing
  39770. * slash.
  39771. * @var {string}
  39772. */
  39773. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  39774. /**
  39775. * Specifies if CMaps are binary packed.
  39776. * @var {boolean}
  39777. */
  39778. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  39779. /**
  39780. * By default fonts are converted to OpenType fonts and loaded via font face
  39781. * rules. If disabled, the font will be rendered using a built in font
  39782. * renderer that constructs the glyphs with primitive path commands.
  39783. * @var {boolean}
  39784. */
  39785. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  39786. false : PDFJS.disableFontFace);
  39787. /**
  39788. * Path for image resources, mainly for annotation icons. Include trailing
  39789. * slash.
  39790. * @var {string}
  39791. */
  39792. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  39793. '' : PDFJS.imageResourcesPath);
  39794. /**
  39795. * Disable the web worker and run all code on the main thread. This will
  39796. * happen automatically if the browser doesn't support workers or sending
  39797. * typed arrays to workers.
  39798. * @var {boolean}
  39799. */
  39800. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  39801. false : PDFJS.disableWorker);
  39802. /**
  39803. * Path and filename of the worker file. Required when the worker is enabled
  39804. * in development mode. If unspecified in the production build, the worker
  39805. * will be loaded based on the location of the pdf.js file. It is recommended
  39806. * that the workerSrc is set in a custom application to prevent issues caused
  39807. * by third-party frameworks and libraries.
  39808. * @var {string}
  39809. */
  39810. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  39811. /**
  39812. * Disable range request loading of PDF files. When enabled and if the server
  39813. * supports partial content requests then the PDF will be fetched in chunks.
  39814. * Enabled (false) by default.
  39815. * @var {boolean}
  39816. */
  39817. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  39818. false : PDFJS.disableRange);
  39819. /**
  39820. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  39821. * in chunks. This default behavior can be disabled.
  39822. * @var {boolean}
  39823. */
  39824. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  39825. false : PDFJS.disableStream);
  39826. /**
  39827. * Disable pre-fetching of PDF file data. When range requests are enabled
  39828. * PDF.js will automatically keep fetching more data even if it isn't needed
  39829. * to display the current page. This default behavior can be disabled.
  39830. *
  39831. * NOTE: It is also necessary to disable streaming, see above,
  39832. * in order for disabling of pre-fetching to work correctly.
  39833. * @var {boolean}
  39834. */
  39835. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  39836. false : PDFJS.disableAutoFetch);
  39837. /**
  39838. * Enables special hooks for debugging PDF.js.
  39839. * @var {boolean}
  39840. */
  39841. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  39842. /**
  39843. * Enables transfer usage in postMessage for ArrayBuffers.
  39844. * @var {boolean}
  39845. */
  39846. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  39847. true : PDFJS.postMessageTransfers);
  39848. /**
  39849. * Disables URL.createObjectURL usage.
  39850. * @var {boolean}
  39851. */
  39852. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  39853. false : PDFJS.disableCreateObjectURL);
  39854. /**
  39855. * Disables WebGL usage.
  39856. * @var {boolean}
  39857. */
  39858. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  39859. true : PDFJS.disableWebGL);
  39860. /**
  39861. * Specifies the |target| attribute for external links.
  39862. * The constants from PDFJS.LinkTarget should be used:
  39863. * - NONE [default]
  39864. * - SELF
  39865. * - BLANK
  39866. * - PARENT
  39867. * - TOP
  39868. * @var {number}
  39869. */
  39870. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  39871. LinkTarget.NONE : PDFJS.externalLinkTarget);
  39872. /**
  39873. * Specifies the |rel| attribute for external links. Defaults to stripping
  39874. * the referrer.
  39875. * @var {string}
  39876. */
  39877. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  39878. 'noreferrer' : PDFJS.externalLinkRel);
  39879. /**
  39880. * Determines if we can eval strings as JS. Primarily used to improve
  39881. * performance for font rendering.
  39882. * @var {boolean}
  39883. */
  39884. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  39885. true : PDFJS.isEvalSupported);
  39886. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  39887. delete PDFJS.openExternalLinksInNewWindow;
  39888. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  39889. get: function () {
  39890. return PDFJS.externalLinkTarget === LinkTarget.BLANK;
  39891. },
  39892. set: function (value) {
  39893. if (value) {
  39894. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  39895. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  39896. }
  39897. if (PDFJS.externalLinkTarget !== LinkTarget.NONE) {
  39898. warn('PDFJS.externalLinkTarget is already initialized');
  39899. return;
  39900. }
  39901. PDFJS.externalLinkTarget = value ? LinkTarget.BLANK : LinkTarget.NONE;
  39902. },
  39903. enumerable: true,
  39904. configurable: true
  39905. });
  39906. if (savedOpenExternalLinksInNewWindow) {
  39907. /**
  39908. * (Deprecated) Opens external links in a new window if enabled.
  39909. * The default behavior opens external links in the PDF.js window.
  39910. *
  39911. * NOTE: This property has been deprecated, please use
  39912. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  39913. * @var {boolean}
  39914. */
  39915. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  39916. }
  39917. PDFJS.getDocument = displayAPI.getDocument;
  39918. PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
  39919. PDFJS.PDFWorker = displayAPI.PDFWorker;
  39920. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  39921. configurable: true,
  39922. get: function PDFJS_hasCanvasTypedArrays() {
  39923. var value = displayDOMUtils.hasCanvasTypedArrays();
  39924. return sharedUtil.shadow(PDFJS, 'hasCanvasTypedArrays', value);
  39925. }
  39926. });
  39927. PDFJS.CustomStyle = displayDOMUtils.CustomStyle;
  39928. PDFJS.LinkTarget = LinkTarget;
  39929. PDFJS.addLinkAttributes = displayDOMUtils.addLinkAttributes;
  39930. PDFJS.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  39931. PDFJS.isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet;
  39932. PDFJS.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
  39933. PDFJS.renderTextLayer = displayTextLayer.renderTextLayer;
  39934. PDFJS.Metadata = displayMetadata.Metadata;
  39935. PDFJS.SVGGraphics = displaySVG.SVGGraphics;
  39936. PDFJS.UnsupportedManager = displayAPI._UnsupportedManager;
  39937. exports.globalScope = globalScope;
  39938. exports.isWorker = isWorker;
  39939. exports.PDFJS = globalScope.PDFJS;
  39940. }));
  39941. (function (root, factory) {
  39942. {
  39943. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  39944. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  39945. root.pdfjsCoreJpx);
  39946. }
  39947. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  39948. coreStream, coreJpx) {
  39949. var ImageKind = sharedUtil.ImageKind;
  39950. var assert = sharedUtil.assert;
  39951. var error = sharedUtil.error;
  39952. var info = sharedUtil.info;
  39953. var isArray = sharedUtil.isArray;
  39954. var warn = sharedUtil.warn;
  39955. var Name = corePrimitives.Name;
  39956. var isStream = corePrimitives.isStream;
  39957. var ColorSpace = coreColorSpace.ColorSpace;
  39958. var DecodeStream = coreStream.DecodeStream;
  39959. var JpegStream = coreStream.JpegStream;
  39960. var JpxImage = coreJpx.JpxImage;
  39961. var PDFImage = (function PDFImageClosure() {
  39962. /**
  39963. * Decodes the image using native decoder if possible. Resolves the promise
  39964. * when the image data is ready.
  39965. */
  39966. function handleImageData(image, nativeDecoder) {
  39967. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  39968. return nativeDecoder.decode(image);
  39969. } else {
  39970. return Promise.resolve(image);
  39971. }
  39972. }
  39973. /**
  39974. * Decode and clamp a value. The formula is different from the spec because we
  39975. * don't decode to float range [0,1], we decode it in the [0,max] range.
  39976. */
  39977. function decodeAndClamp(value, addend, coefficient, max) {
  39978. value = addend + value * coefficient;
  39979. // Clamp the value to the range
  39980. return (value < 0 ? 0 : (value > max ? max : value));
  39981. }
  39982. /**
  39983. * Resizes an image mask with 1 component.
  39984. * @param {TypedArray} src - The source buffer.
  39985. * @param {Number} bpc - Number of bits per component.
  39986. * @param {Number} w1 - Original width.
  39987. * @param {Number} h1 - Original height.
  39988. * @param {Number} w2 - New width.
  39989. * @param {Number} h2 - New height.
  39990. * @returns {TypedArray} The resized image mask buffer.
  39991. */
  39992. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  39993. var length = w2 * h2;
  39994. var dest = (bpc <= 8 ? new Uint8Array(length) :
  39995. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39996. var xRatio = w1 / w2;
  39997. var yRatio = h1 / h2;
  39998. var i, j, py, newIndex = 0, oldIndex;
  39999. var xScaled = new Uint16Array(w2);
  40000. var w1Scanline = w1;
  40001. for (i = 0; i < w2; i++) {
  40002. xScaled[i] = Math.floor(i * xRatio);
  40003. }
  40004. for (i = 0; i < h2; i++) {
  40005. py = Math.floor(i * yRatio) * w1Scanline;
  40006. for (j = 0; j < w2; j++) {
  40007. oldIndex = py + xScaled[j];
  40008. dest[newIndex++] = src[oldIndex];
  40009. }
  40010. }
  40011. return dest;
  40012. }
  40013. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  40014. this.image = image;
  40015. var dict = image.dict;
  40016. if (dict.has('Filter')) {
  40017. var filter = dict.get('Filter').name;
  40018. if (filter === 'JPXDecode') {
  40019. var jpxImage = new JpxImage();
  40020. jpxImage.parseImageProperties(image.stream);
  40021. image.stream.reset();
  40022. image.bitsPerComponent = jpxImage.bitsPerComponent;
  40023. image.numComps = jpxImage.componentsCount;
  40024. } else if (filter === 'JBIG2Decode') {
  40025. image.bitsPerComponent = 1;
  40026. image.numComps = 1;
  40027. }
  40028. }
  40029. // TODO cache rendered images?
  40030. this.width = dict.get('Width', 'W');
  40031. this.height = dict.get('Height', 'H');
  40032. if (this.width < 1 || this.height < 1) {
  40033. error('Invalid image width: ' + this.width + ' or height: ' +
  40034. this.height);
  40035. }
  40036. this.interpolate = dict.get('Interpolate', 'I') || false;
  40037. this.imageMask = dict.get('ImageMask', 'IM') || false;
  40038. this.matte = dict.get('Matte') || false;
  40039. var bitsPerComponent = image.bitsPerComponent;
  40040. if (!bitsPerComponent) {
  40041. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  40042. if (!bitsPerComponent) {
  40043. if (this.imageMask) {
  40044. bitsPerComponent = 1;
  40045. } else {
  40046. error('Bits per component missing in image: ' + this.imageMask);
  40047. }
  40048. }
  40049. }
  40050. this.bpc = bitsPerComponent;
  40051. if (!this.imageMask) {
  40052. var colorSpace = dict.get('ColorSpace', 'CS');
  40053. if (!colorSpace) {
  40054. info('JPX images (which do not require color spaces)');
  40055. switch (image.numComps) {
  40056. case 1:
  40057. colorSpace = Name.get('DeviceGray');
  40058. break;
  40059. case 3:
  40060. colorSpace = Name.get('DeviceRGB');
  40061. break;
  40062. case 4:
  40063. colorSpace = Name.get('DeviceCMYK');
  40064. break;
  40065. default:
  40066. error('JPX images with ' + this.numComps +
  40067. ' color components not supported.');
  40068. }
  40069. }
  40070. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  40071. this.numComps = this.colorSpace.numComps;
  40072. }
  40073. this.decode = dict.getArray('Decode', 'D');
  40074. this.needsDecode = false;
  40075. if (this.decode &&
  40076. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  40077. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  40078. this.needsDecode = true;
  40079. // Do some preprocessing to avoid more math.
  40080. var max = (1 << bitsPerComponent) - 1;
  40081. this.decodeCoefficients = [];
  40082. this.decodeAddends = [];
  40083. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  40084. var dmin = this.decode[i];
  40085. var dmax = this.decode[i + 1];
  40086. this.decodeCoefficients[j] = dmax - dmin;
  40087. this.decodeAddends[j] = max * dmin;
  40088. }
  40089. }
  40090. if (smask) {
  40091. this.smask = new PDFImage(xref, res, smask, false);
  40092. } else if (mask) {
  40093. if (isStream(mask)) {
  40094. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  40095. if (!imageMask) {
  40096. warn('Ignoring /Mask in image without /ImageMask.');
  40097. } else {
  40098. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  40099. }
  40100. } else {
  40101. // Color key mask (just an array).
  40102. this.mask = mask;
  40103. }
  40104. }
  40105. }
  40106. /**
  40107. * Handles processing of image data and returns the Promise that is resolved
  40108. * with a PDFImage when the image is ready to be used.
  40109. */
  40110. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  40111. res, image, inline,
  40112. nativeDecoder) {
  40113. var imagePromise = handleImageData(image, nativeDecoder);
  40114. var smaskPromise;
  40115. var maskPromise;
  40116. var smask = image.dict.get('SMask');
  40117. var mask = image.dict.get('Mask');
  40118. if (smask) {
  40119. smaskPromise = handleImageData(smask, nativeDecoder);
  40120. maskPromise = Promise.resolve(null);
  40121. } else {
  40122. smaskPromise = Promise.resolve(null);
  40123. if (mask) {
  40124. if (isStream(mask)) {
  40125. maskPromise = handleImageData(mask, nativeDecoder);
  40126. } else if (isArray(mask)) {
  40127. maskPromise = Promise.resolve(mask);
  40128. } else {
  40129. warn('Unsupported mask format.');
  40130. maskPromise = Promise.resolve(null);
  40131. }
  40132. } else {
  40133. maskPromise = Promise.resolve(null);
  40134. }
  40135. }
  40136. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  40137. function(results) {
  40138. var imageData = results[0];
  40139. var smaskData = results[1];
  40140. var maskData = results[2];
  40141. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  40142. });
  40143. };
  40144. PDFImage.createMask =
  40145. function PDFImage_createMask(imgArray, width, height,
  40146. imageIsFromDecodeStream, inverseDecode) {
  40147. // |imgArray| might not contain full data for every pixel of the mask, so
  40148. // we need to distinguish between |computedLength| and |actualLength|.
  40149. // In particular, if inverseDecode is true, then the array we return must
  40150. // have a length of |computedLength|.
  40151. var computedLength = ((width + 7) >> 3) * height;
  40152. var actualLength = imgArray.byteLength;
  40153. var haveFullData = computedLength === actualLength;
  40154. var data, i;
  40155. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  40156. // imgArray came from a DecodeStream and its data is in an appropriate
  40157. // form, so we can just transfer it.
  40158. data = imgArray;
  40159. } else if (!inverseDecode) {
  40160. data = new Uint8Array(actualLength);
  40161. data.set(imgArray);
  40162. } else {
  40163. data = new Uint8Array(computedLength);
  40164. data.set(imgArray);
  40165. for (i = actualLength; i < computedLength; i++) {
  40166. data[i] = 0xff;
  40167. }
  40168. }
  40169. // If necessary, invert the original mask data (but not any extra we might
  40170. // have added above). It's safe to modify the array -- whether it's the
  40171. // original or a copy, we're about to transfer it anyway, so nothing else
  40172. // in this thread can be relying on its contents.
  40173. if (inverseDecode) {
  40174. for (i = 0; i < actualLength; i++) {
  40175. data[i] = ~data[i];
  40176. }
  40177. }
  40178. return {data: data, width: width, height: height};
  40179. };
  40180. PDFImage.prototype = {
  40181. get drawWidth() {
  40182. return Math.max(this.width,
  40183. this.smask && this.smask.width || 0,
  40184. this.mask && this.mask.width || 0);
  40185. },
  40186. get drawHeight() {
  40187. return Math.max(this.height,
  40188. this.smask && this.smask.height || 0,
  40189. this.mask && this.mask.height || 0);
  40190. },
  40191. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  40192. var bpc = this.bpc;
  40193. var numComps = this.numComps;
  40194. var decodeAddends = this.decodeAddends;
  40195. var decodeCoefficients = this.decodeCoefficients;
  40196. var max = (1 << bpc) - 1;
  40197. var i, ii;
  40198. if (bpc === 1) {
  40199. // If the buffer needed decode that means it just needs to be inverted.
  40200. for (i = 0, ii = buffer.length; i < ii; i++) {
  40201. buffer[i] = +!(buffer[i]);
  40202. }
  40203. return;
  40204. }
  40205. var index = 0;
  40206. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  40207. for (var j = 0; j < numComps; j++) {
  40208. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  40209. decodeCoefficients[j], max);
  40210. index++;
  40211. }
  40212. }
  40213. },
  40214. getComponents: function PDFImage_getComponents(buffer) {
  40215. var bpc = this.bpc;
  40216. // This image doesn't require any extra work.
  40217. if (bpc === 8) {
  40218. return buffer;
  40219. }
  40220. var width = this.width;
  40221. var height = this.height;
  40222. var numComps = this.numComps;
  40223. var length = width * height * numComps;
  40224. var bufferPos = 0;
  40225. var output = (bpc <= 8 ? new Uint8Array(length) :
  40226. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  40227. var rowComps = width * numComps;
  40228. var max = (1 << bpc) - 1;
  40229. var i = 0, ii, buf;
  40230. if (bpc === 1) {
  40231. // Optimization for reading 1 bpc images.
  40232. var mask, loop1End, loop2End;
  40233. for (var j = 0; j < height; j++) {
  40234. loop1End = i + (rowComps & ~7);
  40235. loop2End = i + rowComps;
  40236. // unroll loop for all full bytes
  40237. while (i < loop1End) {
  40238. buf = buffer[bufferPos++];
  40239. output[i] = (buf >> 7) & 1;
  40240. output[i + 1] = (buf >> 6) & 1;
  40241. output[i + 2] = (buf >> 5) & 1;
  40242. output[i + 3] = (buf >> 4) & 1;
  40243. output[i + 4] = (buf >> 3) & 1;
  40244. output[i + 5] = (buf >> 2) & 1;
  40245. output[i + 6] = (buf >> 1) & 1;
  40246. output[i + 7] = buf & 1;
  40247. i += 8;
  40248. }
  40249. // handle remaining bits
  40250. if (i < loop2End) {
  40251. buf = buffer[bufferPos++];
  40252. mask = 128;
  40253. while (i < loop2End) {
  40254. output[i++] = +!!(buf & mask);
  40255. mask >>= 1;
  40256. }
  40257. }
  40258. }
  40259. } else {
  40260. // The general case that handles all other bpc values.
  40261. var bits = 0;
  40262. buf = 0;
  40263. for (i = 0, ii = length; i < ii; ++i) {
  40264. if (i % rowComps === 0) {
  40265. buf = 0;
  40266. bits = 0;
  40267. }
  40268. while (bits < bpc) {
  40269. buf = (buf << 8) | buffer[bufferPos++];
  40270. bits += 8;
  40271. }
  40272. var remainingBits = bits - bpc;
  40273. var value = buf >> remainingBits;
  40274. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  40275. buf = buf & ((1 << remainingBits) - 1);
  40276. bits = remainingBits;
  40277. }
  40278. }
  40279. return output;
  40280. },
  40281. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  40282. actualHeight, image) {
  40283. var smask = this.smask;
  40284. var mask = this.mask;
  40285. var alphaBuf, sw, sh, i, ii, j;
  40286. if (smask) {
  40287. sw = smask.width;
  40288. sh = smask.height;
  40289. alphaBuf = new Uint8Array(sw * sh);
  40290. smask.fillGrayBuffer(alphaBuf);
  40291. if (sw !== width || sh !== height) {
  40292. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh,
  40293. width, height);
  40294. }
  40295. } else if (mask) {
  40296. if (mask instanceof PDFImage) {
  40297. sw = mask.width;
  40298. sh = mask.height;
  40299. alphaBuf = new Uint8Array(sw * sh);
  40300. mask.numComps = 1;
  40301. mask.fillGrayBuffer(alphaBuf);
  40302. // Need to invert values in rgbaBuf
  40303. for (i = 0, ii = sw * sh; i < ii; ++i) {
  40304. alphaBuf[i] = 255 - alphaBuf[i];
  40305. }
  40306. if (sw !== width || sh !== height) {
  40307. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
  40308. width, height);
  40309. }
  40310. } else if (isArray(mask)) {
  40311. // Color key mask: if any of the components are outside the range
  40312. // then they should be painted.
  40313. alphaBuf = new Uint8Array(width * height);
  40314. var numComps = this.numComps;
  40315. for (i = 0, ii = width * height; i < ii; ++i) {
  40316. var opacity = 0;
  40317. var imageOffset = i * numComps;
  40318. for (j = 0; j < numComps; ++j) {
  40319. var color = image[imageOffset + j];
  40320. var maskOffset = j * 2;
  40321. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  40322. opacity = 255;
  40323. break;
  40324. }
  40325. }
  40326. alphaBuf[i] = opacity;
  40327. }
  40328. } else {
  40329. error('Unknown mask format.');
  40330. }
  40331. }
  40332. if (alphaBuf) {
  40333. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40334. rgbaBuf[j] = alphaBuf[i];
  40335. }
  40336. } else {
  40337. // No mask.
  40338. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40339. rgbaBuf[j] = 255;
  40340. }
  40341. }
  40342. },
  40343. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  40344. var matte = this.smask && this.smask.matte;
  40345. if (!matte) {
  40346. return;
  40347. }
  40348. var matteRgb = this.colorSpace.getRgb(matte, 0);
  40349. var matteR = matteRgb[0];
  40350. var matteG = matteRgb[1];
  40351. var matteB = matteRgb[2];
  40352. var length = width * height * 4;
  40353. var r, g, b;
  40354. for (var i = 0; i < length; i += 4) {
  40355. var alpha = buffer[i + 3];
  40356. if (alpha === 0) {
  40357. // according formula we have to get Infinity in all components
  40358. // making it white (typical paper color) should be okay
  40359. buffer[i] = 255;
  40360. buffer[i + 1] = 255;
  40361. buffer[i + 2] = 255;
  40362. continue;
  40363. }
  40364. var k = 255 / alpha;
  40365. r = (buffer[i] - matteR) * k + matteR;
  40366. g = (buffer[i + 1] - matteG) * k + matteG;
  40367. b = (buffer[i + 2] - matteB) * k + matteB;
  40368. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  40369. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  40370. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  40371. }
  40372. },
  40373. createImageData: function PDFImage_createImageData(forceRGBA) {
  40374. var drawWidth = this.drawWidth;
  40375. var drawHeight = this.drawHeight;
  40376. var imgData = { // other fields are filled in below
  40377. width: drawWidth,
  40378. height: drawHeight
  40379. };
  40380. var numComps = this.numComps;
  40381. var originalWidth = this.width;
  40382. var originalHeight = this.height;
  40383. var bpc = this.bpc;
  40384. // Rows start at byte boundary.
  40385. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  40386. var imgArray;
  40387. if (!forceRGBA) {
  40388. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  40389. // without any complications, we pass a same-sized copy to the main
  40390. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  40391. // of memory for many scanned documents. It's also much faster.
  40392. //
  40393. // Similarly, if it is a 24-bit-per pixel RGB image without any
  40394. // complications, we avoid expanding by 1.333x to RGBA form.
  40395. var kind;
  40396. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  40397. kind = ImageKind.GRAYSCALE_1BPP;
  40398. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  40399. !this.needsDecode) {
  40400. kind = ImageKind.RGB_24BPP;
  40401. }
  40402. if (kind && !this.smask && !this.mask &&
  40403. drawWidth === originalWidth && drawHeight === originalHeight) {
  40404. imgData.kind = kind;
  40405. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40406. // If imgArray came from a DecodeStream, we're safe to transfer it
  40407. // (and thus detach its underlying buffer) because it will constitute
  40408. // the entire DecodeStream's data. But if it came from a Stream, we
  40409. // need to copy it because it'll only be a portion of the Stream's
  40410. // data, and the rest will be read later on.
  40411. if (this.image instanceof DecodeStream) {
  40412. imgData.data = imgArray;
  40413. } else {
  40414. var newArray = new Uint8Array(imgArray.length);
  40415. newArray.set(imgArray);
  40416. imgData.data = newArray;
  40417. }
  40418. if (this.needsDecode) {
  40419. // Invert the buffer (which must be grayscale if we reached here).
  40420. assert(kind === ImageKind.GRAYSCALE_1BPP);
  40421. var buffer = imgData.data;
  40422. for (var i = 0, ii = buffer.length; i < ii; i++) {
  40423. buffer[i] ^= 0xff;
  40424. }
  40425. }
  40426. return imgData;
  40427. }
  40428. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  40429. (this.colorSpace.name === 'DeviceGray' ||
  40430. this.colorSpace.name === 'DeviceRGB' ||
  40431. this.colorSpace.name === 'DeviceCMYK')) {
  40432. imgData.kind = ImageKind.RGB_24BPP;
  40433. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  40434. drawWidth, drawHeight, true);
  40435. return imgData;
  40436. }
  40437. }
  40438. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40439. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  40440. var actualHeight = 0 | (imgArray.length / rowBytes *
  40441. drawHeight / originalHeight);
  40442. var comps = this.getComponents(imgArray);
  40443. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  40444. // more compact RGB_24BPP form if allowable.
  40445. var alpha01, maybeUndoPreblend;
  40446. if (!forceRGBA && !this.smask && !this.mask) {
  40447. imgData.kind = ImageKind.RGB_24BPP;
  40448. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  40449. alpha01 = 0;
  40450. maybeUndoPreblend = false;
  40451. } else {
  40452. imgData.kind = ImageKind.RGBA_32BPP;
  40453. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  40454. alpha01 = 1;
  40455. maybeUndoPreblend = true;
  40456. // Color key masking (opacity) must be performed before decoding.
  40457. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  40458. comps);
  40459. }
  40460. if (this.needsDecode) {
  40461. this.decodeBuffer(comps);
  40462. }
  40463. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  40464. drawWidth, drawHeight, actualHeight, bpc, comps,
  40465. alpha01);
  40466. if (maybeUndoPreblend) {
  40467. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  40468. }
  40469. return imgData;
  40470. },
  40471. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  40472. var numComps = this.numComps;
  40473. if (numComps !== 1) {
  40474. error('Reading gray scale from a color image: ' + numComps);
  40475. }
  40476. var width = this.width;
  40477. var height = this.height;
  40478. var bpc = this.bpc;
  40479. // rows start at byte boundary
  40480. var rowBytes = (width * numComps * bpc + 7) >> 3;
  40481. var imgArray = this.getImageBytes(height * rowBytes);
  40482. var comps = this.getComponents(imgArray);
  40483. var i, length;
  40484. if (bpc === 1) {
  40485. // inline decoding (= inversion) for 1 bpc images
  40486. length = width * height;
  40487. if (this.needsDecode) {
  40488. // invert and scale to {0, 255}
  40489. for (i = 0; i < length; ++i) {
  40490. buffer[i] = (comps[i] - 1) & 255;
  40491. }
  40492. } else {
  40493. // scale to {0, 255}
  40494. for (i = 0; i < length; ++i) {
  40495. buffer[i] = (-comps[i]) & 255;
  40496. }
  40497. }
  40498. return;
  40499. }
  40500. if (this.needsDecode) {
  40501. this.decodeBuffer(comps);
  40502. }
  40503. length = width * height;
  40504. // we aren't using a colorspace so we need to scale the value
  40505. var scale = 255 / ((1 << bpc) - 1);
  40506. for (i = 0; i < length; ++i) {
  40507. buffer[i] = (scale * comps[i]) | 0;
  40508. }
  40509. },
  40510. getImageBytes: function PDFImage_getImageBytes(length,
  40511. drawWidth, drawHeight,
  40512. forceRGB) {
  40513. this.image.reset();
  40514. this.image.drawWidth = drawWidth || this.width;
  40515. this.image.drawHeight = drawHeight || this.height;
  40516. this.image.forceRGB = !!forceRGB;
  40517. return this.image.getBytes(length);
  40518. }
  40519. };
  40520. return PDFImage;
  40521. })();
  40522. exports.PDFImage = PDFImage;
  40523. }));
  40524. (function (root, factory) {
  40525. {
  40526. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  40527. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  40528. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  40529. }
  40530. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  40531. coreChunkedStream, coreColorSpace) {
  40532. var InvalidPDFException = sharedUtil.InvalidPDFException;
  40533. var MissingDataException = sharedUtil.MissingDataException;
  40534. var XRefParseException = sharedUtil.XRefParseException;
  40535. var assert = sharedUtil.assert;
  40536. var bytesToString = sharedUtil.bytesToString;
  40537. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40538. var error = sharedUtil.error;
  40539. var info = sharedUtil.info;
  40540. var isArray = sharedUtil.isArray;
  40541. var isInt = sharedUtil.isInt;
  40542. var isString = sharedUtil.isString;
  40543. var shadow = sharedUtil.shadow;
  40544. var stringToPDFString = sharedUtil.stringToPDFString;
  40545. var stringToUTF8String = sharedUtil.stringToUTF8String;
  40546. var warn = sharedUtil.warn;
  40547. var isValidUrl = sharedUtil.isValidUrl;
  40548. var Util = sharedUtil.Util;
  40549. var Ref = corePrimitives.Ref;
  40550. var RefSet = corePrimitives.RefSet;
  40551. var RefSetCache = corePrimitives.RefSetCache;
  40552. var isName = corePrimitives.isName;
  40553. var isCmd = corePrimitives.isCmd;
  40554. var isDict = corePrimitives.isDict;
  40555. var isRef = corePrimitives.isRef;
  40556. var isRefsEqual = corePrimitives.isRefsEqual;
  40557. var isStream = corePrimitives.isStream;
  40558. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  40559. var Lexer = coreParser.Lexer;
  40560. var Parser = coreParser.Parser;
  40561. var ChunkedStream = coreChunkedStream.ChunkedStream;
  40562. var ColorSpace = coreColorSpace.ColorSpace;
  40563. var Catalog = (function CatalogClosure() {
  40564. function Catalog(pdfManager, xref, pageFactory) {
  40565. this.pdfManager = pdfManager;
  40566. this.xref = xref;
  40567. this.catDict = xref.getCatalogObj();
  40568. this.fontCache = new RefSetCache();
  40569. assert(isDict(this.catDict),
  40570. 'catalog object is not a dictionary');
  40571. // TODO refactor to move getPage() to the PDFDocument.
  40572. this.pageFactory = pageFactory;
  40573. this.pagePromises = [];
  40574. }
  40575. Catalog.prototype = {
  40576. get metadata() {
  40577. var streamRef = this.catDict.getRaw('Metadata');
  40578. if (!isRef(streamRef)) {
  40579. return shadow(this, 'metadata', null);
  40580. }
  40581. var encryptMetadata = (!this.xref.encrypt ? false :
  40582. this.xref.encrypt.encryptMetadata);
  40583. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  40584. var metadata;
  40585. if (stream && isDict(stream.dict)) {
  40586. var type = stream.dict.get('Type');
  40587. var subtype = stream.dict.get('Subtype');
  40588. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  40589. // XXX: This should examine the charset the XML document defines,
  40590. // however since there are currently no real means to decode
  40591. // arbitrary charsets, let's just hope that the author of the PDF
  40592. // was reasonable enough to stick with the XML default charset,
  40593. // which is UTF-8.
  40594. try {
  40595. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  40596. } catch (e) {
  40597. info('Skipping invalid metadata.');
  40598. }
  40599. }
  40600. }
  40601. return shadow(this, 'metadata', metadata);
  40602. },
  40603. get toplevelPagesDict() {
  40604. var pagesObj = this.catDict.get('Pages');
  40605. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  40606. // shadow the prototype getter
  40607. return shadow(this, 'toplevelPagesDict', pagesObj);
  40608. },
  40609. get documentOutline() {
  40610. var obj = null;
  40611. try {
  40612. obj = this.readDocumentOutline();
  40613. } catch (ex) {
  40614. if (ex instanceof MissingDataException) {
  40615. throw ex;
  40616. }
  40617. warn('Unable to read document outline');
  40618. }
  40619. return shadow(this, 'documentOutline', obj);
  40620. },
  40621. readDocumentOutline: function Catalog_readDocumentOutline() {
  40622. var obj = this.catDict.get('Outlines');
  40623. if (!isDict(obj)) {
  40624. return null;
  40625. }
  40626. obj = obj.getRaw('First');
  40627. if (!isRef(obj)) {
  40628. return null;
  40629. }
  40630. var root = { items: [] };
  40631. var queue = [{obj: obj, parent: root}];
  40632. // To avoid recursion, keep track of the already processed items.
  40633. var processed = new RefSet();
  40634. processed.put(obj);
  40635. var xref = this.xref, blackColor = new Uint8Array(3);
  40636. while (queue.length > 0) {
  40637. var i = queue.shift();
  40638. var outlineDict = xref.fetchIfRef(i.obj);
  40639. if (outlineDict === null) {
  40640. continue;
  40641. }
  40642. assert(outlineDict.has('Title'), 'Invalid outline item');
  40643. var actionDict = outlineDict.get('A'), dest = null, url = null;
  40644. if (actionDict) {
  40645. var destEntry = actionDict.get('D');
  40646. if (destEntry) {
  40647. dest = destEntry;
  40648. } else {
  40649. var uriEntry = actionDict.get('URI');
  40650. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  40651. url = uriEntry;
  40652. }
  40653. }
  40654. } else if (outlineDict.has('Dest')) {
  40655. dest = outlineDict.getRaw('Dest');
  40656. if (isName(dest)) {
  40657. dest = dest.name;
  40658. }
  40659. }
  40660. var title = outlineDict.get('Title');
  40661. var flags = outlineDict.get('F') || 0;
  40662. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  40663. // We only need to parse the color when it's valid, and non-default.
  40664. if (isArray(color) && color.length === 3 &&
  40665. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  40666. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  40667. }
  40668. var outlineItem = {
  40669. dest: dest,
  40670. url: url,
  40671. title: stringToPDFString(title),
  40672. color: rgbColor,
  40673. count: outlineDict.get('Count'),
  40674. bold: !!(flags & 2),
  40675. italic: !!(flags & 1),
  40676. items: []
  40677. };
  40678. i.parent.items.push(outlineItem);
  40679. obj = outlineDict.getRaw('First');
  40680. if (isRef(obj) && !processed.has(obj)) {
  40681. queue.push({obj: obj, parent: outlineItem});
  40682. processed.put(obj);
  40683. }
  40684. obj = outlineDict.getRaw('Next');
  40685. if (isRef(obj) && !processed.has(obj)) {
  40686. queue.push({obj: obj, parent: i.parent});
  40687. processed.put(obj);
  40688. }
  40689. }
  40690. return (root.items.length > 0 ? root.items : null);
  40691. },
  40692. get numPages() {
  40693. var obj = this.toplevelPagesDict.get('Count');
  40694. assert(
  40695. isInt(obj),
  40696. 'page count in top level pages object is not an integer'
  40697. );
  40698. // shadow the prototype getter
  40699. return shadow(this, 'num', obj);
  40700. },
  40701. get destinations() {
  40702. function fetchDestination(dest) {
  40703. return isDict(dest) ? dest.get('D') : dest;
  40704. }
  40705. var xref = this.xref;
  40706. var dests = {}, nameTreeRef, nameDictionaryRef;
  40707. var obj = this.catDict.get('Names');
  40708. if (obj && obj.has('Dests')) {
  40709. nameTreeRef = obj.getRaw('Dests');
  40710. } else if (this.catDict.has('Dests')) {
  40711. nameDictionaryRef = this.catDict.get('Dests');
  40712. }
  40713. if (nameDictionaryRef) {
  40714. // reading simple destination dictionary
  40715. obj = nameDictionaryRef;
  40716. obj.forEach(function catalogForEach(key, value) {
  40717. if (!value) {
  40718. return;
  40719. }
  40720. dests[key] = fetchDestination(value);
  40721. });
  40722. }
  40723. if (nameTreeRef) {
  40724. var nameTree = new NameTree(nameTreeRef, xref);
  40725. var names = nameTree.getAll();
  40726. for (var name in names) {
  40727. dests[name] = fetchDestination(names[name]);
  40728. }
  40729. }
  40730. return shadow(this, 'destinations', dests);
  40731. },
  40732. getDestination: function Catalog_getDestination(destinationId) {
  40733. function fetchDestination(dest) {
  40734. return isDict(dest) ? dest.get('D') : dest;
  40735. }
  40736. var xref = this.xref;
  40737. var dest = null, nameTreeRef, nameDictionaryRef;
  40738. var obj = this.catDict.get('Names');
  40739. if (obj && obj.has('Dests')) {
  40740. nameTreeRef = obj.getRaw('Dests');
  40741. } else if (this.catDict.has('Dests')) {
  40742. nameDictionaryRef = this.catDict.get('Dests');
  40743. }
  40744. if (nameDictionaryRef) { // Simple destination dictionary.
  40745. var value = nameDictionaryRef.get(destinationId);
  40746. if (value) {
  40747. dest = fetchDestination(value);
  40748. }
  40749. }
  40750. if (nameTreeRef) {
  40751. var nameTree = new NameTree(nameTreeRef, xref);
  40752. dest = fetchDestination(nameTree.get(destinationId));
  40753. }
  40754. return dest;
  40755. },
  40756. get pageLabels() {
  40757. var obj = null;
  40758. try {
  40759. obj = this.readPageLabels();
  40760. } catch (ex) {
  40761. if (ex instanceof MissingDataException) {
  40762. throw ex;
  40763. }
  40764. warn('Unable to read page labels.');
  40765. }
  40766. return shadow(this, 'pageLabels', obj);
  40767. },
  40768. readPageLabels: function Catalog_readPageLabels() {
  40769. var obj = this.catDict.getRaw('PageLabels');
  40770. if (!obj) {
  40771. return null;
  40772. }
  40773. var pageLabels = new Array(this.numPages);
  40774. var style = null;
  40775. var prefix = '';
  40776. var start = 1;
  40777. var numberTree = new NumberTree(obj, this.xref);
  40778. var nums = numberTree.getAll();
  40779. var currentLabel = '', currentIndex = 1;
  40780. for (var i = 0, ii = this.numPages; i < ii; i++) {
  40781. if (i in nums) {
  40782. var labelDict = nums[i];
  40783. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  40784. var type = labelDict.get('Type');
  40785. assert(!type || isName(type, 'PageLabel'),
  40786. 'Invalid type in PageLabel dictionary.');
  40787. var s = labelDict.get('S');
  40788. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  40789. style = (s ? s.name : null);
  40790. prefix = labelDict.get('P') || '';
  40791. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  40792. start = labelDict.get('St') || 1;
  40793. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  40794. currentIndex = start;
  40795. }
  40796. switch (style) {
  40797. case 'D':
  40798. currentLabel = currentIndex;
  40799. break;
  40800. case 'R':
  40801. case 'r':
  40802. currentLabel = Util.toRoman(currentIndex, style === 'r');
  40803. break;
  40804. case 'A':
  40805. case 'a':
  40806. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  40807. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  40808. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  40809. var letterIndex = currentIndex - 1;
  40810. var character = String.fromCharCode(baseCharCode +
  40811. (letterIndex % LIMIT));
  40812. var charBuf = [];
  40813. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  40814. charBuf.push(character);
  40815. }
  40816. currentLabel = charBuf.join('');
  40817. break;
  40818. default:
  40819. assert(!style,
  40820. 'Invalid style "' + style + '" in PageLabel dictionary.');
  40821. }
  40822. pageLabels[i] = prefix + currentLabel;
  40823. currentLabel = '';
  40824. currentIndex++;
  40825. }
  40826. return pageLabels;
  40827. },
  40828. get attachments() {
  40829. var xref = this.xref;
  40830. var attachments = null, nameTreeRef;
  40831. var obj = this.catDict.get('Names');
  40832. if (obj) {
  40833. nameTreeRef = obj.getRaw('EmbeddedFiles');
  40834. }
  40835. if (nameTreeRef) {
  40836. var nameTree = new NameTree(nameTreeRef, xref);
  40837. var names = nameTree.getAll();
  40838. for (var name in names) {
  40839. var fs = new FileSpec(names[name], xref);
  40840. if (!attachments) {
  40841. attachments = Object.create(null);
  40842. }
  40843. attachments[stringToPDFString(name)] = fs.serializable;
  40844. }
  40845. }
  40846. return shadow(this, 'attachments', attachments);
  40847. },
  40848. get javaScript() {
  40849. var xref = this.xref;
  40850. var obj = this.catDict.get('Names');
  40851. var javaScript = [];
  40852. function appendIfJavaScriptDict(jsDict) {
  40853. var type = jsDict.get('S');
  40854. if (!isName(type, 'JavaScript')) {
  40855. return;
  40856. }
  40857. var js = jsDict.get('JS');
  40858. if (isStream(js)) {
  40859. js = bytesToString(js.getBytes());
  40860. } else if (!isString(js)) {
  40861. return;
  40862. }
  40863. javaScript.push(stringToPDFString(js));
  40864. }
  40865. if (obj && obj.has('JavaScript')) {
  40866. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  40867. var names = nameTree.getAll();
  40868. for (var name in names) {
  40869. // We don't really use the JavaScript right now. This code is
  40870. // defensive so we don't cause errors on document load.
  40871. var jsDict = names[name];
  40872. if (isDict(jsDict)) {
  40873. appendIfJavaScriptDict(jsDict);
  40874. }
  40875. }
  40876. }
  40877. // Append OpenAction actions to javaScript array
  40878. var openactionDict = this.catDict.get('OpenAction');
  40879. if (isDict(openactionDict, 'Action')) {
  40880. var actionType = openactionDict.get('S');
  40881. if (isName(actionType, 'Named')) {
  40882. // The named Print action is not a part of the PDF 1.7 specification,
  40883. // but is supported by many PDF readers/writers (including Adobe's).
  40884. var action = openactionDict.get('N');
  40885. if (isName(action, 'Print')) {
  40886. javaScript.push('print({});');
  40887. }
  40888. } else {
  40889. appendIfJavaScriptDict(openactionDict);
  40890. }
  40891. }
  40892. return shadow(this, 'javaScript', javaScript);
  40893. },
  40894. cleanup: function Catalog_cleanup() {
  40895. var promises = [];
  40896. this.fontCache.forEach(function (promise) {
  40897. promises.push(promise);
  40898. });
  40899. return Promise.all(promises).then(function (translatedFonts) {
  40900. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  40901. var font = translatedFonts[i].dict;
  40902. delete font.translated;
  40903. }
  40904. this.fontCache.clear();
  40905. }.bind(this));
  40906. },
  40907. getPage: function Catalog_getPage(pageIndex) {
  40908. if (!(pageIndex in this.pagePromises)) {
  40909. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  40910. function (a) {
  40911. var dict = a[0];
  40912. var ref = a[1];
  40913. return this.pageFactory.createPage(pageIndex, dict, ref,
  40914. this.fontCache);
  40915. }.bind(this)
  40916. );
  40917. }
  40918. return this.pagePromises[pageIndex];
  40919. },
  40920. getPageDict: function Catalog_getPageDict(pageIndex) {
  40921. var capability = createPromiseCapability();
  40922. var nodesToVisit = [this.catDict.getRaw('Pages')];
  40923. var currentPageIndex = 0;
  40924. var xref = this.xref;
  40925. var checkAllKids = false;
  40926. function next() {
  40927. while (nodesToVisit.length) {
  40928. var currentNode = nodesToVisit.pop();
  40929. if (isRef(currentNode)) {
  40930. xref.fetchAsync(currentNode).then(function (obj) {
  40931. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  40932. if (pageIndex === currentPageIndex) {
  40933. capability.resolve([obj, currentNode]);
  40934. } else {
  40935. currentPageIndex++;
  40936. next();
  40937. }
  40938. return;
  40939. }
  40940. nodesToVisit.push(obj);
  40941. next();
  40942. }, capability.reject);
  40943. return;
  40944. }
  40945. // Must be a child page dictionary.
  40946. assert(
  40947. isDict(currentNode),
  40948. 'page dictionary kid reference points to wrong type of object'
  40949. );
  40950. var count = currentNode.get('Count');
  40951. // If the current node doesn't have any children, avoid getting stuck
  40952. // in an empty node further down in the tree (see issue5644.pdf).
  40953. if (count === 0) {
  40954. checkAllKids = true;
  40955. }
  40956. // Skip nodes where the page can't be.
  40957. if (currentPageIndex + count <= pageIndex) {
  40958. currentPageIndex += count;
  40959. continue;
  40960. }
  40961. var kids = currentNode.get('Kids');
  40962. assert(isArray(kids), 'page dictionary kids object is not an array');
  40963. if (!checkAllKids && count === kids.length) {
  40964. // Nodes that don't have the page have been skipped and this is the
  40965. // bottom of the tree which means the page requested must be a
  40966. // descendant of this pages node. Ideally we would just resolve the
  40967. // promise with the page ref here, but there is the case where more
  40968. // pages nodes could link to single a page (see issue 3666 pdf). To
  40969. // handle this push it back on the queue so if it is a pages node it
  40970. // will be descended into.
  40971. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  40972. currentPageIndex = pageIndex;
  40973. continue;
  40974. } else {
  40975. for (var last = kids.length - 1; last >= 0; last--) {
  40976. nodesToVisit.push(kids[last]);
  40977. }
  40978. }
  40979. }
  40980. capability.reject('Page index ' + pageIndex + ' not found.');
  40981. }
  40982. next();
  40983. return capability.promise;
  40984. },
  40985. getPageIndex: function Catalog_getPageIndex(pageRef) {
  40986. // The page tree nodes have the count of all the leaves below them. To get
  40987. // how many pages are before we just have to walk up the tree and keep
  40988. // adding the count of siblings to the left of the node.
  40989. var xref = this.xref;
  40990. function pagesBeforeRef(kidRef) {
  40991. var total = 0;
  40992. var parentRef;
  40993. return xref.fetchAsync(kidRef).then(function (node) {
  40994. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
  40995. !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  40996. throw new Error('The reference does not point to a /Page Dict.');
  40997. }
  40998. if (!node) {
  40999. return null;
  41000. }
  41001. assert(isDict(node), 'node must be a Dict.');
  41002. parentRef = node.getRaw('Parent');
  41003. return node.getAsync('Parent');
  41004. }).then(function (parent) {
  41005. if (!parent) {
  41006. return null;
  41007. }
  41008. assert(isDict(parent), 'parent must be a Dict.');
  41009. return parent.getAsync('Kids');
  41010. }).then(function (kids) {
  41011. if (!kids) {
  41012. return null;
  41013. }
  41014. var kidPromises = [];
  41015. var found = false;
  41016. for (var i = 0; i < kids.length; i++) {
  41017. var kid = kids[i];
  41018. assert(isRef(kid), 'kid must be a Ref.');
  41019. if (kid.num === kidRef.num) {
  41020. found = true;
  41021. break;
  41022. }
  41023. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  41024. if (kid.has('Count')) {
  41025. var count = kid.get('Count');
  41026. total += count;
  41027. } else { // page leaf node
  41028. total++;
  41029. }
  41030. }));
  41031. }
  41032. if (!found) {
  41033. error('kid ref not found in parents kids');
  41034. }
  41035. return Promise.all(kidPromises).then(function () {
  41036. return [total, parentRef];
  41037. });
  41038. });
  41039. }
  41040. var total = 0;
  41041. function next(ref) {
  41042. return pagesBeforeRef(ref).then(function (args) {
  41043. if (!args) {
  41044. return total;
  41045. }
  41046. var count = args[0];
  41047. var parentRef = args[1];
  41048. total += count;
  41049. return next(parentRef);
  41050. });
  41051. }
  41052. return next(pageRef);
  41053. }
  41054. };
  41055. return Catalog;
  41056. })();
  41057. var XRef = (function XRefClosure() {
  41058. function XRef(stream, password) {
  41059. this.stream = stream;
  41060. this.entries = [];
  41061. this.xrefstms = Object.create(null);
  41062. // prepare the XRef cache
  41063. this.cache = [];
  41064. this.password = password;
  41065. this.stats = {
  41066. streamTypes: [],
  41067. fontTypes: []
  41068. };
  41069. }
  41070. XRef.prototype = {
  41071. setStartXRef: function XRef_setStartXRef(startXRef) {
  41072. // Store the starting positions of xref tables as we process them
  41073. // so we can recover from missing data errors
  41074. this.startXRefQueue = [startXRef];
  41075. },
  41076. parse: function XRef_parse(recoveryMode) {
  41077. var trailerDict;
  41078. if (!recoveryMode) {
  41079. trailerDict = this.readXRef();
  41080. } else {
  41081. warn('Indexing all PDF objects');
  41082. trailerDict = this.indexObjects();
  41083. }
  41084. trailerDict.assignXref(this);
  41085. this.trailer = trailerDict;
  41086. var encrypt = trailerDict.get('Encrypt');
  41087. if (encrypt) {
  41088. var ids = trailerDict.get('ID');
  41089. var fileId = (ids && ids.length) ? ids[0] : '';
  41090. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  41091. this.password);
  41092. }
  41093. // get the root dictionary (catalog) object
  41094. if (!(this.root = trailerDict.get('Root'))) {
  41095. error('Invalid root reference');
  41096. }
  41097. },
  41098. processXRefTable: function XRef_processXRefTable(parser) {
  41099. if (!('tableState' in this)) {
  41100. // Stores state of the table as we process it so we can resume
  41101. // from middle of table in case of missing data error
  41102. this.tableState = {
  41103. entryNum: 0,
  41104. streamPos: parser.lexer.stream.pos,
  41105. parserBuf1: parser.buf1,
  41106. parserBuf2: parser.buf2
  41107. };
  41108. }
  41109. var obj = this.readXRefTable(parser);
  41110. // Sanity check
  41111. if (!isCmd(obj, 'trailer')) {
  41112. error('Invalid XRef table: could not find trailer dictionary');
  41113. }
  41114. // Read trailer dictionary, e.g.
  41115. // trailer
  41116. // << /Size 22
  41117. // /Root 20R
  41118. // /Info 10R
  41119. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  41120. // >>
  41121. // The parser goes through the entire stream << ... >> and provides
  41122. // a getter interface for the key-value table
  41123. var dict = parser.getObj();
  41124. // The pdflib PDF generator can generate a nested trailer dictionary
  41125. if (!isDict(dict) && dict.dict) {
  41126. dict = dict.dict;
  41127. }
  41128. if (!isDict(dict)) {
  41129. error('Invalid XRef table: could not parse trailer dictionary');
  41130. }
  41131. delete this.tableState;
  41132. return dict;
  41133. },
  41134. readXRefTable: function XRef_readXRefTable(parser) {
  41135. // Example of cross-reference table:
  41136. // xref
  41137. // 0 1 <-- subsection header (first obj #, obj count)
  41138. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  41139. // 23 2 <-- subsection header ... and so on ...
  41140. // 0000025518 00002 n
  41141. // 0000025635 00000 n
  41142. // trailer
  41143. // ...
  41144. var stream = parser.lexer.stream;
  41145. var tableState = this.tableState;
  41146. stream.pos = tableState.streamPos;
  41147. parser.buf1 = tableState.parserBuf1;
  41148. parser.buf2 = tableState.parserBuf2;
  41149. // Outer loop is over subsection headers
  41150. var obj;
  41151. while (true) {
  41152. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  41153. if (isCmd(obj = parser.getObj(), 'trailer')) {
  41154. break;
  41155. }
  41156. tableState.firstEntryNum = obj;
  41157. tableState.entryCount = parser.getObj();
  41158. }
  41159. var first = tableState.firstEntryNum;
  41160. var count = tableState.entryCount;
  41161. if (!isInt(first) || !isInt(count)) {
  41162. error('Invalid XRef table: wrong types in subsection header');
  41163. }
  41164. // Inner loop is over objects themselves
  41165. for (var i = tableState.entryNum; i < count; i++) {
  41166. tableState.streamPos = stream.pos;
  41167. tableState.entryNum = i;
  41168. tableState.parserBuf1 = parser.buf1;
  41169. tableState.parserBuf2 = parser.buf2;
  41170. var entry = {};
  41171. entry.offset = parser.getObj();
  41172. entry.gen = parser.getObj();
  41173. var type = parser.getObj();
  41174. if (isCmd(type, 'f')) {
  41175. entry.free = true;
  41176. } else if (isCmd(type, 'n')) {
  41177. entry.uncompressed = true;
  41178. }
  41179. // Validate entry obj
  41180. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  41181. !(entry.free || entry.uncompressed)) {
  41182. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  41183. }
  41184. // The first xref table entry, i.e. obj 0, should be free. Attempting
  41185. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  41186. if (i === 0 && entry.free && first === 1) {
  41187. first = 0;
  41188. }
  41189. if (!this.entries[i + first]) {
  41190. this.entries[i + first] = entry;
  41191. }
  41192. }
  41193. tableState.entryNum = 0;
  41194. tableState.streamPos = stream.pos;
  41195. tableState.parserBuf1 = parser.buf1;
  41196. tableState.parserBuf2 = parser.buf2;
  41197. delete tableState.firstEntryNum;
  41198. delete tableState.entryCount;
  41199. }
  41200. // Sanity check: as per spec, first object must be free
  41201. if (this.entries[0] && !this.entries[0].free) {
  41202. error('Invalid XRef table: unexpected first object');
  41203. }
  41204. return obj;
  41205. },
  41206. processXRefStream: function XRef_processXRefStream(stream) {
  41207. if (!('streamState' in this)) {
  41208. // Stores state of the stream as we process it so we can resume
  41209. // from middle of stream in case of missing data error
  41210. var streamParameters = stream.dict;
  41211. var byteWidths = streamParameters.get('W');
  41212. var range = streamParameters.get('Index');
  41213. if (!range) {
  41214. range = [0, streamParameters.get('Size')];
  41215. }
  41216. this.streamState = {
  41217. entryRanges: range,
  41218. byteWidths: byteWidths,
  41219. entryNum: 0,
  41220. streamPos: stream.pos
  41221. };
  41222. }
  41223. this.readXRefStream(stream);
  41224. delete this.streamState;
  41225. return stream.dict;
  41226. },
  41227. readXRefStream: function XRef_readXRefStream(stream) {
  41228. var i, j;
  41229. var streamState = this.streamState;
  41230. stream.pos = streamState.streamPos;
  41231. var byteWidths = streamState.byteWidths;
  41232. var typeFieldWidth = byteWidths[0];
  41233. var offsetFieldWidth = byteWidths[1];
  41234. var generationFieldWidth = byteWidths[2];
  41235. var entryRanges = streamState.entryRanges;
  41236. while (entryRanges.length > 0) {
  41237. var first = entryRanges[0];
  41238. var n = entryRanges[1];
  41239. if (!isInt(first) || !isInt(n)) {
  41240. error('Invalid XRef range fields: ' + first + ', ' + n);
  41241. }
  41242. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  41243. !isInt(generationFieldWidth)) {
  41244. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  41245. }
  41246. for (i = streamState.entryNum; i < n; ++i) {
  41247. streamState.entryNum = i;
  41248. streamState.streamPos = stream.pos;
  41249. var type = 0, offset = 0, generation = 0;
  41250. for (j = 0; j < typeFieldWidth; ++j) {
  41251. type = (type << 8) | stream.getByte();
  41252. }
  41253. // if type field is absent, its default value is 1
  41254. if (typeFieldWidth === 0) {
  41255. type = 1;
  41256. }
  41257. for (j = 0; j < offsetFieldWidth; ++j) {
  41258. offset = (offset << 8) | stream.getByte();
  41259. }
  41260. for (j = 0; j < generationFieldWidth; ++j) {
  41261. generation = (generation << 8) | stream.getByte();
  41262. }
  41263. var entry = {};
  41264. entry.offset = offset;
  41265. entry.gen = generation;
  41266. switch (type) {
  41267. case 0:
  41268. entry.free = true;
  41269. break;
  41270. case 1:
  41271. entry.uncompressed = true;
  41272. break;
  41273. case 2:
  41274. break;
  41275. default:
  41276. error('Invalid XRef entry type: ' + type);
  41277. }
  41278. if (!this.entries[first + i]) {
  41279. this.entries[first + i] = entry;
  41280. }
  41281. }
  41282. streamState.entryNum = 0;
  41283. streamState.streamPos = stream.pos;
  41284. entryRanges.splice(0, 2);
  41285. }
  41286. },
  41287. indexObjects: function XRef_indexObjects() {
  41288. // Simple scan through the PDF content to find objects,
  41289. // trailers and XRef streams.
  41290. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  41291. var PERCENT = 0x25, LT = 0x3C;
  41292. function readToken(data, offset) {
  41293. var token = '', ch = data[offset];
  41294. while (ch !== LF && ch !== CR && ch !== LT) {
  41295. if (++offset >= data.length) {
  41296. break;
  41297. }
  41298. token += String.fromCharCode(ch);
  41299. ch = data[offset];
  41300. }
  41301. return token;
  41302. }
  41303. function skipUntil(data, offset, what) {
  41304. var length = what.length, dataLength = data.length;
  41305. var skipped = 0;
  41306. // finding byte sequence
  41307. while (offset < dataLength) {
  41308. var i = 0;
  41309. while (i < length && data[offset + i] === what[i]) {
  41310. ++i;
  41311. }
  41312. if (i >= length) {
  41313. break; // sequence found
  41314. }
  41315. offset++;
  41316. skipped++;
  41317. }
  41318. return skipped;
  41319. }
  41320. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  41321. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  41322. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  41323. 101, 102]);
  41324. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  41325. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  41326. // Clear out any existing entries, since they may be bogus.
  41327. this.entries.length = 0;
  41328. var stream = this.stream;
  41329. stream.pos = 0;
  41330. var buffer = stream.getBytes();
  41331. var position = stream.start, length = buffer.length;
  41332. var trailers = [], xrefStms = [];
  41333. while (position < length) {
  41334. var ch = buffer[position];
  41335. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  41336. ++position;
  41337. continue;
  41338. }
  41339. if (ch === PERCENT) { // %-comment
  41340. do {
  41341. ++position;
  41342. if (position >= length) {
  41343. break;
  41344. }
  41345. ch = buffer[position];
  41346. } while (ch !== LF && ch !== CR);
  41347. continue;
  41348. }
  41349. var token = readToken(buffer, position);
  41350. var m;
  41351. if (token.indexOf('xref') === 0 &&
  41352. (token.length === 4 || /\s/.test(token[4]))) {
  41353. position += skipUntil(buffer, position, trailerBytes);
  41354. trailers.push(position);
  41355. position += skipUntil(buffer, position, startxrefBytes);
  41356. } else if ((m = objRegExp.exec(token))) {
  41357. if (typeof this.entries[m[1]] === 'undefined') {
  41358. this.entries[m[1]] = {
  41359. offset: position - stream.start,
  41360. gen: m[2] | 0,
  41361. uncompressed: true
  41362. };
  41363. }
  41364. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  41365. var content = buffer.subarray(position, position + contentLength);
  41366. // checking XRef stream suspect
  41367. // (it shall have '/XRef' and next char is not a letter)
  41368. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  41369. if (xrefTagOffset < contentLength &&
  41370. content[xrefTagOffset + 5] < 64) {
  41371. xrefStms.push(position - stream.start);
  41372. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  41373. }
  41374. position += contentLength;
  41375. } else if (token.indexOf('trailer') === 0 &&
  41376. (token.length === 7 || /\s/.test(token[7]))) {
  41377. trailers.push(position);
  41378. position += skipUntil(buffer, position, startxrefBytes);
  41379. } else {
  41380. position += token.length + 1;
  41381. }
  41382. }
  41383. // reading XRef streams
  41384. var i, ii;
  41385. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  41386. this.startXRefQueue.push(xrefStms[i]);
  41387. this.readXRef(/* recoveryMode */ true);
  41388. }
  41389. // finding main trailer
  41390. var dict;
  41391. for (i = 0, ii = trailers.length; i < ii; ++i) {
  41392. stream.pos = trailers[i];
  41393. var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
  41394. /* xref = */ this, /* recoveryMode = */ true);
  41395. var obj = parser.getObj();
  41396. if (!isCmd(obj, 'trailer')) {
  41397. continue;
  41398. }
  41399. // read the trailer dictionary
  41400. dict = parser.getObj();
  41401. if (!isDict(dict)) {
  41402. continue;
  41403. }
  41404. // taking the first one with 'ID'
  41405. if (dict.has('ID')) {
  41406. return dict;
  41407. }
  41408. }
  41409. // no tailer with 'ID', taking last one (if exists)
  41410. if (dict) {
  41411. return dict;
  41412. }
  41413. // nothing helps
  41414. // calling error() would reject worker with an UnknownErrorException.
  41415. throw new InvalidPDFException('Invalid PDF structure');
  41416. },
  41417. readXRef: function XRef_readXRef(recoveryMode) {
  41418. var stream = this.stream;
  41419. try {
  41420. while (this.startXRefQueue.length) {
  41421. var startXRef = this.startXRefQueue[0];
  41422. stream.pos = startXRef + stream.start;
  41423. var parser = new Parser(new Lexer(stream), true, this);
  41424. var obj = parser.getObj();
  41425. var dict;
  41426. // Get dictionary
  41427. if (isCmd(obj, 'xref')) {
  41428. // Parse end-of-file XRef
  41429. dict = this.processXRefTable(parser);
  41430. if (!this.topDict) {
  41431. this.topDict = dict;
  41432. }
  41433. // Recursively get other XRefs 'XRefStm', if any
  41434. obj = dict.get('XRefStm');
  41435. if (isInt(obj)) {
  41436. var pos = obj;
  41437. // ignore previously loaded xref streams
  41438. // (possible infinite recursion)
  41439. if (!(pos in this.xrefstms)) {
  41440. this.xrefstms[pos] = 1;
  41441. this.startXRefQueue.push(pos);
  41442. }
  41443. }
  41444. } else if (isInt(obj)) {
  41445. // Parse in-stream XRef
  41446. if (!isInt(parser.getObj()) ||
  41447. !isCmd(parser.getObj(), 'obj') ||
  41448. !isStream(obj = parser.getObj())) {
  41449. error('Invalid XRef stream');
  41450. }
  41451. dict = this.processXRefStream(obj);
  41452. if (!this.topDict) {
  41453. this.topDict = dict;
  41454. }
  41455. if (!dict) {
  41456. error('Failed to read XRef stream');
  41457. }
  41458. } else {
  41459. error('Invalid XRef stream header');
  41460. }
  41461. // Recursively get previous dictionary, if any
  41462. obj = dict.get('Prev');
  41463. if (isInt(obj)) {
  41464. this.startXRefQueue.push(obj);
  41465. } else if (isRef(obj)) {
  41466. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  41467. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  41468. this.startXRefQueue.push(obj.num);
  41469. }
  41470. this.startXRefQueue.shift();
  41471. }
  41472. return this.topDict;
  41473. } catch (e) {
  41474. if (e instanceof MissingDataException) {
  41475. throw e;
  41476. }
  41477. info('(while reading XRef): ' + e);
  41478. }
  41479. if (recoveryMode) {
  41480. return;
  41481. }
  41482. throw new XRefParseException();
  41483. },
  41484. getEntry: function XRef_getEntry(i) {
  41485. var xrefEntry = this.entries[i];
  41486. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  41487. return xrefEntry;
  41488. }
  41489. return null;
  41490. },
  41491. fetchIfRef: function XRef_fetchIfRef(obj) {
  41492. if (!isRef(obj)) {
  41493. return obj;
  41494. }
  41495. return this.fetch(obj);
  41496. },
  41497. fetch: function XRef_fetch(ref, suppressEncryption) {
  41498. assert(isRef(ref), 'ref object is not a reference');
  41499. var num = ref.num;
  41500. if (num in this.cache) {
  41501. var cacheEntry = this.cache[num];
  41502. return cacheEntry;
  41503. }
  41504. var xrefEntry = this.getEntry(num);
  41505. // the referenced entry can be free
  41506. if (xrefEntry === null) {
  41507. return (this.cache[num] = null);
  41508. }
  41509. if (xrefEntry.uncompressed) {
  41510. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  41511. } else {
  41512. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  41513. }
  41514. if (isDict(xrefEntry)){
  41515. xrefEntry.objId = ref.toString();
  41516. } else if (isStream(xrefEntry)) {
  41517. xrefEntry.dict.objId = ref.toString();
  41518. }
  41519. return xrefEntry;
  41520. },
  41521. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  41522. suppressEncryption) {
  41523. var gen = ref.gen;
  41524. var num = ref.num;
  41525. if (xrefEntry.gen !== gen) {
  41526. error('inconsistent generation in XRef');
  41527. }
  41528. var stream = this.stream.makeSubStream(xrefEntry.offset +
  41529. this.stream.start);
  41530. var parser = new Parser(new Lexer(stream), true, this);
  41531. var obj1 = parser.getObj();
  41532. var obj2 = parser.getObj();
  41533. var obj3 = parser.getObj();
  41534. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  41535. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  41536. !isCmd(obj3)) {
  41537. error('bad XRef entry');
  41538. }
  41539. if (!isCmd(obj3, 'obj')) {
  41540. // some bad PDFs use "obj1234" and really mean 1234
  41541. if (obj3.cmd.indexOf('obj') === 0) {
  41542. num = parseInt(obj3.cmd.substring(3), 10);
  41543. if (!isNaN(num)) {
  41544. return num;
  41545. }
  41546. }
  41547. error('bad XRef entry');
  41548. }
  41549. if (this.encrypt && !suppressEncryption) {
  41550. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  41551. } else {
  41552. xrefEntry = parser.getObj();
  41553. }
  41554. if (!isStream(xrefEntry)) {
  41555. this.cache[num] = xrefEntry;
  41556. }
  41557. return xrefEntry;
  41558. },
  41559. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  41560. suppressEncryption) {
  41561. var tableOffset = xrefEntry.offset;
  41562. var stream = this.fetch(new Ref(tableOffset, 0));
  41563. if (!isStream(stream)) {
  41564. error('bad ObjStm stream');
  41565. }
  41566. var first = stream.dict.get('First');
  41567. var n = stream.dict.get('N');
  41568. if (!isInt(first) || !isInt(n)) {
  41569. error('invalid first and n parameters for ObjStm stream');
  41570. }
  41571. var parser = new Parser(new Lexer(stream), false, this);
  41572. parser.allowStreams = true;
  41573. var i, entries = [], num, nums = [];
  41574. // read the object numbers to populate cache
  41575. for (i = 0; i < n; ++i) {
  41576. num = parser.getObj();
  41577. if (!isInt(num)) {
  41578. error('invalid object number in the ObjStm stream: ' + num);
  41579. }
  41580. nums.push(num);
  41581. var offset = parser.getObj();
  41582. if (!isInt(offset)) {
  41583. error('invalid object offset in the ObjStm stream: ' + offset);
  41584. }
  41585. }
  41586. // read stream objects for cache
  41587. for (i = 0; i < n; ++i) {
  41588. entries.push(parser.getObj());
  41589. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  41590. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  41591. if (isCmd(parser.buf1, 'endobj')) {
  41592. parser.shift();
  41593. }
  41594. num = nums[i];
  41595. var entry = this.entries[num];
  41596. if (entry && entry.offset === tableOffset && entry.gen === i) {
  41597. this.cache[num] = entries[i];
  41598. }
  41599. }
  41600. xrefEntry = entries[xrefEntry.gen];
  41601. if (xrefEntry === undefined) {
  41602. error('bad XRef entry for compressed object');
  41603. }
  41604. return xrefEntry;
  41605. },
  41606. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  41607. if (!isRef(obj)) {
  41608. return Promise.resolve(obj);
  41609. }
  41610. return this.fetchAsync(obj);
  41611. },
  41612. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  41613. var streamManager = this.stream.manager;
  41614. var xref = this;
  41615. return new Promise(function tryFetch(resolve, reject) {
  41616. try {
  41617. resolve(xref.fetch(ref, suppressEncryption));
  41618. } catch (e) {
  41619. if (e instanceof MissingDataException) {
  41620. streamManager.requestRange(e.begin, e.end).then(function () {
  41621. tryFetch(resolve, reject);
  41622. }, reject);
  41623. return;
  41624. }
  41625. reject(e);
  41626. }
  41627. });
  41628. },
  41629. getCatalogObj: function XRef_getCatalogObj() {
  41630. return this.root;
  41631. }
  41632. };
  41633. return XRef;
  41634. })();
  41635. /**
  41636. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  41637. * see the specification (7.9.6 and 7.9.7) for additional details.
  41638. * TODO: implement all the Dict functions and make this more efficient.
  41639. */
  41640. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  41641. function NameOrNumberTree(root, xref) {
  41642. throw new Error('Cannot initialize NameOrNumberTree.');
  41643. }
  41644. NameOrNumberTree.prototype = {
  41645. getAll: function NameOrNumberTree_getAll() {
  41646. var dict = Object.create(null);
  41647. if (!this.root) {
  41648. return dict;
  41649. }
  41650. var xref = this.xref;
  41651. // Reading Name/Number tree.
  41652. var processed = new RefSet();
  41653. processed.put(this.root);
  41654. var queue = [this.root];
  41655. while (queue.length > 0) {
  41656. var i, n;
  41657. var obj = xref.fetchIfRef(queue.shift());
  41658. if (!isDict(obj)) {
  41659. continue;
  41660. }
  41661. if (obj.has('Kids')) {
  41662. var kids = obj.get('Kids');
  41663. for (i = 0, n = kids.length; i < n; i++) {
  41664. var kid = kids[i];
  41665. assert(!processed.has(kid),
  41666. 'Duplicate entry in "' + this._type + '" tree.');
  41667. queue.push(kid);
  41668. processed.put(kid);
  41669. }
  41670. continue;
  41671. }
  41672. var entries = obj.get(this._type);
  41673. if (isArray(entries)) {
  41674. for (i = 0, n = entries.length; i < n; i += 2) {
  41675. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  41676. }
  41677. }
  41678. }
  41679. return dict;
  41680. },
  41681. get: function NameOrNumberTree_get(key) {
  41682. if (!this.root) {
  41683. return null;
  41684. }
  41685. var xref = this.xref;
  41686. var kidsOrEntries = xref.fetchIfRef(this.root);
  41687. var loopCount = 0;
  41688. var MAX_LEVELS = 10;
  41689. var l, r, m;
  41690. // Perform a binary search to quickly find the entry that
  41691. // contains the key we are looking for.
  41692. while (kidsOrEntries.has('Kids')) {
  41693. if (++loopCount > MAX_LEVELS) {
  41694. warn('Search depth limit reached for "' + this._type + '" tree.');
  41695. return null;
  41696. }
  41697. var kids = kidsOrEntries.get('Kids');
  41698. if (!isArray(kids)) {
  41699. return null;
  41700. }
  41701. l = 0;
  41702. r = kids.length - 1;
  41703. while (l <= r) {
  41704. m = (l + r) >> 1;
  41705. var kid = xref.fetchIfRef(kids[m]);
  41706. var limits = kid.get('Limits');
  41707. if (key < xref.fetchIfRef(limits[0])) {
  41708. r = m - 1;
  41709. } else if (key > xref.fetchIfRef(limits[1])) {
  41710. l = m + 1;
  41711. } else {
  41712. kidsOrEntries = xref.fetchIfRef(kids[m]);
  41713. break;
  41714. }
  41715. }
  41716. if (l > r) {
  41717. return null;
  41718. }
  41719. }
  41720. // If we get here, then we have found the right entry. Now go through the
  41721. // entries in the dictionary until we find the key we're looking for.
  41722. var entries = kidsOrEntries.get(this._type);
  41723. if (isArray(entries)) {
  41724. // Perform a binary search to reduce the lookup time.
  41725. l = 0;
  41726. r = entries.length - 2;
  41727. while (l <= r) {
  41728. // Check only even indices (0, 2, 4, ...) because the
  41729. // odd indices contain the actual data.
  41730. m = (l + r) & ~1;
  41731. var currentKey = xref.fetchIfRef(entries[m]);
  41732. if (key < currentKey) {
  41733. r = m - 2;
  41734. } else if (key > currentKey) {
  41735. l = m + 2;
  41736. } else {
  41737. return xref.fetchIfRef(entries[m + 1]);
  41738. }
  41739. }
  41740. }
  41741. return null;
  41742. }
  41743. };
  41744. return NameOrNumberTree;
  41745. })();
  41746. var NameTree = (function NameTreeClosure() {
  41747. function NameTree(root, xref) {
  41748. this.root = root;
  41749. this.xref = xref;
  41750. this._type = 'Names';
  41751. }
  41752. Util.inherit(NameTree, NameOrNumberTree, {});
  41753. return NameTree;
  41754. })();
  41755. var NumberTree = (function NumberTreeClosure() {
  41756. function NumberTree(root, xref) {
  41757. this.root = root;
  41758. this.xref = xref;
  41759. this._type = 'Nums';
  41760. }
  41761. Util.inherit(NumberTree, NameOrNumberTree, {});
  41762. return NumberTree;
  41763. })();
  41764. /**
  41765. * "A PDF file can refer to the contents of another file by using a File
  41766. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  41767. * NOTE: Only embedded files are supported (as part of the attachments support)
  41768. * TODO: support the 'URL' file system (with caching if !/V), portable
  41769. * collections attributes and related files (/RF)
  41770. */
  41771. var FileSpec = (function FileSpecClosure() {
  41772. function FileSpec(root, xref) {
  41773. if (!root || !isDict(root)) {
  41774. return;
  41775. }
  41776. this.xref = xref;
  41777. this.root = root;
  41778. if (root.has('FS')) {
  41779. this.fs = root.get('FS');
  41780. }
  41781. this.description = root.has('Desc') ?
  41782. stringToPDFString(root.get('Desc')) :
  41783. '';
  41784. if (root.has('RF')) {
  41785. warn('Related file specifications are not supported');
  41786. }
  41787. this.contentAvailable = true;
  41788. if (!root.has('EF')) {
  41789. this.contentAvailable = false;
  41790. warn('Non-embedded file specifications are not supported');
  41791. }
  41792. }
  41793. function pickPlatformItem(dict) {
  41794. // Look for the filename in this order:
  41795. // UF, F, Unix, Mac, DOS
  41796. if (dict.has('UF')) {
  41797. return dict.get('UF');
  41798. } else if (dict.has('F')) {
  41799. return dict.get('F');
  41800. } else if (dict.has('Unix')) {
  41801. return dict.get('Unix');
  41802. } else if (dict.has('Mac')) {
  41803. return dict.get('Mac');
  41804. } else if (dict.has('DOS')) {
  41805. return dict.get('DOS');
  41806. } else {
  41807. return null;
  41808. }
  41809. }
  41810. FileSpec.prototype = {
  41811. get filename() {
  41812. if (!this._filename && this.root) {
  41813. var filename = pickPlatformItem(this.root) || 'unnamed';
  41814. this._filename = stringToPDFString(filename).
  41815. replace(/\\\\/g, '\\').
  41816. replace(/\\\//g, '/').
  41817. replace(/\\/g, '/');
  41818. }
  41819. return this._filename;
  41820. },
  41821. get content() {
  41822. if (!this.contentAvailable) {
  41823. return null;
  41824. }
  41825. if (!this.contentRef && this.root) {
  41826. this.contentRef = pickPlatformItem(this.root.get('EF'));
  41827. }
  41828. var content = null;
  41829. if (this.contentRef) {
  41830. var xref = this.xref;
  41831. var fileObj = xref.fetchIfRef(this.contentRef);
  41832. if (fileObj && isStream(fileObj)) {
  41833. content = fileObj.getBytes();
  41834. } else {
  41835. warn('Embedded file specification points to non-existing/invalid ' +
  41836. 'content');
  41837. }
  41838. } else {
  41839. warn('Embedded file specification does not have a content');
  41840. }
  41841. return content;
  41842. },
  41843. get serializable() {
  41844. return {
  41845. filename: this.filename,
  41846. content: this.content
  41847. };
  41848. }
  41849. };
  41850. return FileSpec;
  41851. })();
  41852. /**
  41853. * A helper for loading missing data in object graphs. It traverses the graph
  41854. * depth first and queues up any objects that have missing data. Once it has
  41855. * has traversed as many objects that are available it attempts to bundle the
  41856. * missing data requests and then resume from the nodes that weren't ready.
  41857. *
  41858. * NOTE: It provides protection from circular references by keeping track of
  41859. * of loaded references. However, you must be careful not to load any graphs
  41860. * that have references to the catalog or other pages since that will cause the
  41861. * entire PDF document object graph to be traversed.
  41862. */
  41863. var ObjectLoader = (function() {
  41864. function mayHaveChildren(value) {
  41865. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  41866. }
  41867. function addChildren(node, nodesToVisit) {
  41868. var value;
  41869. if (isDict(node) || isStream(node)) {
  41870. var map;
  41871. if (isDict(node)) {
  41872. map = node.map;
  41873. } else {
  41874. map = node.dict.map;
  41875. }
  41876. for (var key in map) {
  41877. value = map[key];
  41878. if (mayHaveChildren(value)) {
  41879. nodesToVisit.push(value);
  41880. }
  41881. }
  41882. } else if (isArray(node)) {
  41883. for (var i = 0, ii = node.length; i < ii; i++) {
  41884. value = node[i];
  41885. if (mayHaveChildren(value)) {
  41886. nodesToVisit.push(value);
  41887. }
  41888. }
  41889. }
  41890. }
  41891. function ObjectLoader(obj, keys, xref) {
  41892. this.obj = obj;
  41893. this.keys = keys;
  41894. this.xref = xref;
  41895. this.refSet = null;
  41896. this.capability = null;
  41897. }
  41898. ObjectLoader.prototype = {
  41899. load: function ObjectLoader_load() {
  41900. var keys = this.keys;
  41901. this.capability = createPromiseCapability();
  41902. // Don't walk the graph if all the data is already loaded.
  41903. if (!(this.xref.stream instanceof ChunkedStream) ||
  41904. this.xref.stream.getMissingChunks().length === 0) {
  41905. this.capability.resolve();
  41906. return this.capability.promise;
  41907. }
  41908. this.refSet = new RefSet();
  41909. // Setup the initial nodes to visit.
  41910. var nodesToVisit = [];
  41911. for (var i = 0; i < keys.length; i++) {
  41912. nodesToVisit.push(this.obj[keys[i]]);
  41913. }
  41914. this._walk(nodesToVisit);
  41915. return this.capability.promise;
  41916. },
  41917. _walk: function ObjectLoader_walk(nodesToVisit) {
  41918. var nodesToRevisit = [];
  41919. var pendingRequests = [];
  41920. // DFS walk of the object graph.
  41921. while (nodesToVisit.length) {
  41922. var currentNode = nodesToVisit.pop();
  41923. // Only references or chunked streams can cause missing data exceptions.
  41924. if (isRef(currentNode)) {
  41925. // Skip nodes that have already been visited.
  41926. if (this.refSet.has(currentNode)) {
  41927. continue;
  41928. }
  41929. try {
  41930. var ref = currentNode;
  41931. this.refSet.put(ref);
  41932. currentNode = this.xref.fetch(currentNode);
  41933. } catch (e) {
  41934. if (!(e instanceof MissingDataException)) {
  41935. throw e;
  41936. }
  41937. nodesToRevisit.push(currentNode);
  41938. pendingRequests.push({ begin: e.begin, end: e.end });
  41939. }
  41940. }
  41941. if (currentNode && currentNode.getBaseStreams) {
  41942. var baseStreams = currentNode.getBaseStreams();
  41943. var foundMissingData = false;
  41944. for (var i = 0; i < baseStreams.length; i++) {
  41945. var stream = baseStreams[i];
  41946. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  41947. foundMissingData = true;
  41948. pendingRequests.push({
  41949. begin: stream.start,
  41950. end: stream.end
  41951. });
  41952. }
  41953. }
  41954. if (foundMissingData) {
  41955. nodesToRevisit.push(currentNode);
  41956. }
  41957. }
  41958. addChildren(currentNode, nodesToVisit);
  41959. }
  41960. if (pendingRequests.length) {
  41961. this.xref.stream.manager.requestRanges(pendingRequests).then(
  41962. function pendingRequestCallback() {
  41963. nodesToVisit = nodesToRevisit;
  41964. for (var i = 0; i < nodesToRevisit.length; i++) {
  41965. var node = nodesToRevisit[i];
  41966. // Remove any reference nodes from the currrent refset so they
  41967. // aren't skipped when we revist them.
  41968. if (isRef(node)) {
  41969. this.refSet.remove(node);
  41970. }
  41971. }
  41972. this._walk(nodesToVisit);
  41973. }.bind(this), this.capability.reject);
  41974. return;
  41975. }
  41976. // Everything is loaded.
  41977. this.refSet = null;
  41978. this.capability.resolve();
  41979. }
  41980. };
  41981. return ObjectLoader;
  41982. })();
  41983. exports.Catalog = Catalog;
  41984. exports.ObjectLoader = ObjectLoader;
  41985. exports.XRef = XRef;
  41986. exports.FileSpec = FileSpec;
  41987. }));
  41988. (function (root, factory) {
  41989. {
  41990. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  41991. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  41992. root.pdfjsCoreColorSpace);
  41993. }
  41994. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  41995. coreColorSpace) {
  41996. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41997. var MissingDataException = sharedUtil.MissingDataException;
  41998. var Util = sharedUtil.Util;
  41999. var assert = sharedUtil.assert;
  42000. var error = sharedUtil.error;
  42001. var info = sharedUtil.info;
  42002. var warn = sharedUtil.warn;
  42003. var isStream = corePrimitives.isStream;
  42004. var PDFFunction = coreFunction.PDFFunction;
  42005. var ColorSpace = coreColorSpace.ColorSpace;
  42006. var ShadingType = {
  42007. FUNCTION_BASED: 1,
  42008. AXIAL: 2,
  42009. RADIAL: 3,
  42010. FREE_FORM_MESH: 4,
  42011. LATTICE_FORM_MESH: 5,
  42012. COONS_PATCH_MESH: 6,
  42013. TENSOR_PATCH_MESH: 7
  42014. };
  42015. var Pattern = (function PatternClosure() {
  42016. // Constructor should define this.getPattern
  42017. function Pattern() {
  42018. error('should not call Pattern constructor');
  42019. }
  42020. Pattern.prototype = {
  42021. // Input: current Canvas context
  42022. // Output: the appropriate fillStyle or strokeStyle
  42023. getPattern: function Pattern_getPattern(ctx) {
  42024. error('Should not call Pattern.getStyle: ' + ctx);
  42025. }
  42026. };
  42027. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  42028. res, handler) {
  42029. var dict = isStream(shading) ? shading.dict : shading;
  42030. var type = dict.get('ShadingType');
  42031. try {
  42032. switch (type) {
  42033. case ShadingType.AXIAL:
  42034. case ShadingType.RADIAL:
  42035. // Both radial and axial shadings are handled by RadialAxial shading.
  42036. return new Shadings.RadialAxial(dict, matrix, xref, res);
  42037. case ShadingType.FREE_FORM_MESH:
  42038. case ShadingType.LATTICE_FORM_MESH:
  42039. case ShadingType.COONS_PATCH_MESH:
  42040. case ShadingType.TENSOR_PATCH_MESH:
  42041. return new Shadings.Mesh(shading, matrix, xref, res);
  42042. default:
  42043. throw new Error('Unsupported ShadingType: ' + type);
  42044. }
  42045. } catch (ex) {
  42046. if (ex instanceof MissingDataException) {
  42047. throw ex;
  42048. }
  42049. handler.send('UnsupportedFeature',
  42050. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  42051. warn(ex);
  42052. return new Shadings.Dummy();
  42053. }
  42054. };
  42055. return Pattern;
  42056. })();
  42057. var Shadings = {};
  42058. // A small number to offset the first/last color stops so we can insert ones to
  42059. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  42060. Shadings.SMALL_NUMBER = 1e-6;
  42061. // Radial and axial shading have very similar implementations
  42062. // If needed, the implementations can be broken into two classes
  42063. Shadings.RadialAxial = (function RadialAxialClosure() {
  42064. function RadialAxial(dict, matrix, xref, res) {
  42065. this.matrix = matrix;
  42066. this.coordsArr = dict.getArray('Coords');
  42067. this.shadingType = dict.get('ShadingType');
  42068. this.type = 'Pattern';
  42069. var cs = dict.get('ColorSpace', 'CS');
  42070. cs = ColorSpace.parse(cs, xref, res);
  42071. this.cs = cs;
  42072. var t0 = 0.0, t1 = 1.0;
  42073. if (dict.has('Domain')) {
  42074. var domainArr = dict.getArray('Domain');
  42075. t0 = domainArr[0];
  42076. t1 = domainArr[1];
  42077. }
  42078. var extendStart = false, extendEnd = false;
  42079. if (dict.has('Extend')) {
  42080. var extendArr = dict.getArray('Extend');
  42081. extendStart = extendArr[0];
  42082. extendEnd = extendArr[1];
  42083. }
  42084. if (this.shadingType === ShadingType.RADIAL &&
  42085. (!extendStart || !extendEnd)) {
  42086. // Radial gradient only currently works if either circle is fully within
  42087. // the other circle.
  42088. var x1 = this.coordsArr[0];
  42089. var y1 = this.coordsArr[1];
  42090. var r1 = this.coordsArr[2];
  42091. var x2 = this.coordsArr[3];
  42092. var y2 = this.coordsArr[4];
  42093. var r2 = this.coordsArr[5];
  42094. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  42095. if (r1 <= r2 + distance &&
  42096. r2 <= r1 + distance) {
  42097. warn('Unsupported radial gradient.');
  42098. }
  42099. }
  42100. this.extendStart = extendStart;
  42101. this.extendEnd = extendEnd;
  42102. var fnObj = dict.get('Function');
  42103. var fn = PDFFunction.parseArray(xref, fnObj);
  42104. // 10 samples seems good enough for now, but probably won't work
  42105. // if there are sharp color changes. Ideally, we would implement
  42106. // the spec faithfully and add lossless optimizations.
  42107. var diff = t1 - t0;
  42108. var step = diff / 10;
  42109. var colorStops = this.colorStops = [];
  42110. // Protect against bad domains so we don't end up in an infinte loop below.
  42111. if (t0 >= t1 || step <= 0) {
  42112. // Acrobat doesn't seem to handle these cases so we'll ignore for
  42113. // now.
  42114. info('Bad shading domain.');
  42115. return;
  42116. }
  42117. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  42118. var rgbColor;
  42119. for (var i = t0; i <= t1; i += step) {
  42120. ratio[0] = i;
  42121. fn(ratio, 0, color, 0);
  42122. rgbColor = cs.getRgb(color, 0);
  42123. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  42124. colorStops.push([(i - t0) / diff, cssColor]);
  42125. }
  42126. var background = 'transparent';
  42127. if (dict.has('Background')) {
  42128. rgbColor = cs.getRgb(dict.get('Background'), 0);
  42129. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  42130. }
  42131. if (!extendStart) {
  42132. // Insert a color stop at the front and offset the first real color stop
  42133. // so it doesn't conflict with the one we insert.
  42134. colorStops.unshift([0, background]);
  42135. colorStops[1][0] += Shadings.SMALL_NUMBER;
  42136. }
  42137. if (!extendEnd) {
  42138. // Same idea as above in extendStart but for the end.
  42139. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  42140. colorStops.push([1, background]);
  42141. }
  42142. this.colorStops = colorStops;
  42143. }
  42144. RadialAxial.prototype = {
  42145. getIR: function RadialAxial_getIR() {
  42146. var coordsArr = this.coordsArr;
  42147. var shadingType = this.shadingType;
  42148. var type, p0, p1, r0, r1;
  42149. if (shadingType === ShadingType.AXIAL) {
  42150. p0 = [coordsArr[0], coordsArr[1]];
  42151. p1 = [coordsArr[2], coordsArr[3]];
  42152. r0 = null;
  42153. r1 = null;
  42154. type = 'axial';
  42155. } else if (shadingType === ShadingType.RADIAL) {
  42156. p0 = [coordsArr[0], coordsArr[1]];
  42157. p1 = [coordsArr[3], coordsArr[4]];
  42158. r0 = coordsArr[2];
  42159. r1 = coordsArr[5];
  42160. type = 'radial';
  42161. } else {
  42162. error('getPattern type unknown: ' + shadingType);
  42163. }
  42164. var matrix = this.matrix;
  42165. if (matrix) {
  42166. p0 = Util.applyTransform(p0, matrix);
  42167. p1 = Util.applyTransform(p1, matrix);
  42168. if (shadingType === ShadingType.RADIAL) {
  42169. var scale = Util.singularValueDecompose2dScale(matrix);
  42170. r0 *= scale[0];
  42171. r1 *= scale[1];
  42172. }
  42173. }
  42174. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  42175. }
  42176. };
  42177. return RadialAxial;
  42178. })();
  42179. // All mesh shading. For now, they will be presented as set of the triangles
  42180. // to be drawn on the canvas and rgb color for each vertex.
  42181. Shadings.Mesh = (function MeshClosure() {
  42182. function MeshStreamReader(stream, context) {
  42183. this.stream = stream;
  42184. this.context = context;
  42185. this.buffer = 0;
  42186. this.bufferLength = 0;
  42187. var numComps = context.numComps;
  42188. this.tmpCompsBuf = new Float32Array(numComps);
  42189. var csNumComps = context.colorSpace.numComps;
  42190. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  42191. this.tmpCompsBuf;
  42192. }
  42193. MeshStreamReader.prototype = {
  42194. get hasData() {
  42195. if (this.stream.end) {
  42196. return this.stream.pos < this.stream.end;
  42197. }
  42198. if (this.bufferLength > 0) {
  42199. return true;
  42200. }
  42201. var nextByte = this.stream.getByte();
  42202. if (nextByte < 0) {
  42203. return false;
  42204. }
  42205. this.buffer = nextByte;
  42206. this.bufferLength = 8;
  42207. return true;
  42208. },
  42209. readBits: function MeshStreamReader_readBits(n) {
  42210. var buffer = this.buffer;
  42211. var bufferLength = this.bufferLength;
  42212. if (n === 32) {
  42213. if (bufferLength === 0) {
  42214. return ((this.stream.getByte() << 24) |
  42215. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  42216. this.stream.getByte()) >>> 0;
  42217. }
  42218. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  42219. (this.stream.getByte() << 8) | this.stream.getByte();
  42220. var nextByte = this.stream.getByte();
  42221. this.buffer = nextByte & ((1 << bufferLength) - 1);
  42222. return ((buffer << (8 - bufferLength)) |
  42223. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  42224. }
  42225. if (n === 8 && bufferLength === 0) {
  42226. return this.stream.getByte();
  42227. }
  42228. while (bufferLength < n) {
  42229. buffer = (buffer << 8) | this.stream.getByte();
  42230. bufferLength += 8;
  42231. }
  42232. bufferLength -= n;
  42233. this.bufferLength = bufferLength;
  42234. this.buffer = buffer & ((1 << bufferLength) - 1);
  42235. return buffer >> bufferLength;
  42236. },
  42237. align: function MeshStreamReader_align() {
  42238. this.buffer = 0;
  42239. this.bufferLength = 0;
  42240. },
  42241. readFlag: function MeshStreamReader_readFlag() {
  42242. return this.readBits(this.context.bitsPerFlag);
  42243. },
  42244. readCoordinate: function MeshStreamReader_readCoordinate() {
  42245. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  42246. var xi = this.readBits(bitsPerCoordinate);
  42247. var yi = this.readBits(bitsPerCoordinate);
  42248. var decode = this.context.decode;
  42249. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  42250. 2.3283064365386963e-10; // 2 ^ -32
  42251. return [
  42252. xi * scale * (decode[1] - decode[0]) + decode[0],
  42253. yi * scale * (decode[3] - decode[2]) + decode[2]
  42254. ];
  42255. },
  42256. readComponents: function MeshStreamReader_readComponents() {
  42257. var numComps = this.context.numComps;
  42258. var bitsPerComponent = this.context.bitsPerComponent;
  42259. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  42260. 2.3283064365386963e-10; // 2 ^ -32
  42261. var decode = this.context.decode;
  42262. var components = this.tmpCompsBuf;
  42263. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  42264. var ci = this.readBits(bitsPerComponent);
  42265. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  42266. }
  42267. var color = this.tmpCsCompsBuf;
  42268. if (this.context.colorFn) {
  42269. this.context.colorFn(components, 0, color, 0);
  42270. }
  42271. return this.context.colorSpace.getRgb(color, 0);
  42272. }
  42273. };
  42274. function decodeType4Shading(mesh, reader) {
  42275. var coords = mesh.coords;
  42276. var colors = mesh.colors;
  42277. var operators = [];
  42278. var ps = []; // not maintaining cs since that will match ps
  42279. var verticesLeft = 0; // assuming we have all data to start a new triangle
  42280. while (reader.hasData) {
  42281. var f = reader.readFlag();
  42282. var coord = reader.readCoordinate();
  42283. var color = reader.readComponents();
  42284. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  42285. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  42286. switch (f) {
  42287. case 0:
  42288. verticesLeft = 3;
  42289. break;
  42290. case 1:
  42291. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  42292. verticesLeft = 1;
  42293. break;
  42294. case 2:
  42295. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  42296. verticesLeft = 1;
  42297. break;
  42298. }
  42299. operators.push(f);
  42300. }
  42301. ps.push(coords.length);
  42302. coords.push(coord);
  42303. colors.push(color);
  42304. verticesLeft--;
  42305. reader.align();
  42306. }
  42307. mesh.figures.push({
  42308. type: 'triangles',
  42309. coords: new Int32Array(ps),
  42310. colors: new Int32Array(ps),
  42311. });
  42312. }
  42313. function decodeType5Shading(mesh, reader, verticesPerRow) {
  42314. var coords = mesh.coords;
  42315. var colors = mesh.colors;
  42316. var ps = []; // not maintaining cs since that will match ps
  42317. while (reader.hasData) {
  42318. var coord = reader.readCoordinate();
  42319. var color = reader.readComponents();
  42320. ps.push(coords.length);
  42321. coords.push(coord);
  42322. colors.push(color);
  42323. }
  42324. mesh.figures.push({
  42325. type: 'lattice',
  42326. coords: new Int32Array(ps),
  42327. colors: new Int32Array(ps),
  42328. verticesPerRow: verticesPerRow
  42329. });
  42330. }
  42331. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  42332. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  42333. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  42334. var getB = (function getBClosure() {
  42335. function buildB(count) {
  42336. var lut = [];
  42337. for (var i = 0; i <= count; i++) {
  42338. var t = i / count, t_ = 1 - t;
  42339. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  42340. 3 * t * t * t_, t * t * t]));
  42341. }
  42342. return lut;
  42343. }
  42344. var cache = [];
  42345. return function getB(count) {
  42346. if (!cache[count]) {
  42347. cache[count] = buildB(count);
  42348. }
  42349. return cache[count];
  42350. };
  42351. })();
  42352. function buildFigureFromPatch(mesh, index) {
  42353. var figure = mesh.figures[index];
  42354. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  42355. var coords = mesh.coords, colors = mesh.colors;
  42356. var pi = figure.coords;
  42357. var ci = figure.colors;
  42358. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  42359. coords[pi[12]][0], coords[pi[15]][0]);
  42360. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  42361. coords[pi[12]][1], coords[pi[15]][1]);
  42362. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  42363. coords[pi[12]][0], coords[pi[15]][0]);
  42364. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  42365. coords[pi[12]][1], coords[pi[15]][1]);
  42366. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  42367. (mesh.bounds[2] - mesh.bounds[0]));
  42368. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  42369. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  42370. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  42371. (mesh.bounds[3] - mesh.bounds[1]));
  42372. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  42373. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  42374. var verticesPerRow = splitXBy + 1;
  42375. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  42376. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  42377. var k = 0;
  42378. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  42379. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  42380. c2 = colors[ci[2]], c3 = colors[ci[3]];
  42381. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  42382. for (var row = 0; row <= splitYBy; row++) {
  42383. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  42384. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  42385. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  42386. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  42387. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  42388. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  42389. for (var col = 0; col <= splitXBy; col++, k++) {
  42390. if ((row === 0 || row === splitYBy) &&
  42391. (col === 0 || col === splitXBy)) {
  42392. continue;
  42393. }
  42394. var x = 0, y = 0;
  42395. var q = 0;
  42396. for (var i = 0; i <= 3; i++) {
  42397. for (var j = 0; j <= 3; j++, q++) {
  42398. var m = bRow[row][i] * bCol[col][j];
  42399. x += coords[pi[q]][0] * m;
  42400. y += coords[pi[q]][1] * m;
  42401. }
  42402. }
  42403. figureCoords[k] = coords.length;
  42404. coords.push([x, y]);
  42405. figureColors[k] = colors.length;
  42406. var newColor = new Uint8Array(3);
  42407. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  42408. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  42409. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  42410. colors.push(newColor);
  42411. }
  42412. }
  42413. figureCoords[0] = pi[0];
  42414. figureColors[0] = ci[0];
  42415. figureCoords[splitXBy] = pi[3];
  42416. figureColors[splitXBy] = ci[1];
  42417. figureCoords[verticesPerRow * splitYBy] = pi[12];
  42418. figureColors[verticesPerRow * splitYBy] = ci[2];
  42419. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  42420. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  42421. mesh.figures[index] = {
  42422. type: 'lattice',
  42423. coords: figureCoords,
  42424. colors: figureColors,
  42425. verticesPerRow: verticesPerRow
  42426. };
  42427. }
  42428. function decodeType6Shading(mesh, reader) {
  42429. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  42430. var coords = mesh.coords;
  42431. var colors = mesh.colors;
  42432. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  42433. var cs = new Int32Array(4); // c00, c30, c03, c33
  42434. while (reader.hasData) {
  42435. var f = reader.readFlag();
  42436. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  42437. var i, ii;
  42438. var pi = coords.length;
  42439. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  42440. coords.push(reader.readCoordinate());
  42441. }
  42442. var ci = colors.length;
  42443. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  42444. colors.push(reader.readComponents());
  42445. }
  42446. var tmp1, tmp2, tmp3, tmp4;
  42447. switch (f) {
  42448. case 0:
  42449. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  42450. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  42451. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  42452. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  42453. cs[2] = ci + 1; cs[3] = ci + 2;
  42454. cs[0] = ci; cs[1] = ci + 3;
  42455. break;
  42456. case 1:
  42457. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  42458. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42459. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42460. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  42461. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42462. tmp1 = cs[2]; tmp2 = cs[3];
  42463. cs[2] = tmp2; cs[3] = ci;
  42464. cs[0] = tmp1; cs[1] = ci + 1;
  42465. break;
  42466. case 2:
  42467. tmp1 = ps[15];
  42468. tmp2 = ps[11];
  42469. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42470. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42471. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  42472. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42473. tmp1 = cs[3];
  42474. cs[2] = cs[1]; cs[3] = ci;
  42475. cs[0] = tmp1; cs[1] = ci + 1;
  42476. break;
  42477. case 3:
  42478. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42479. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  42480. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  42481. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42482. cs[2] = cs[0]; cs[3] = ci;
  42483. cs[0] = cs[1]; cs[1] = ci + 1;
  42484. break;
  42485. }
  42486. // set p11, p12, p21, p22
  42487. ps[5] = coords.length;
  42488. coords.push([
  42489. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  42490. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  42491. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  42492. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  42493. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  42494. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  42495. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  42496. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  42497. ]);
  42498. ps[6] = coords.length;
  42499. coords.push([
  42500. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  42501. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  42502. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  42503. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  42504. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  42505. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  42506. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  42507. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  42508. ]);
  42509. ps[9] = coords.length;
  42510. coords.push([
  42511. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  42512. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  42513. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  42514. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  42515. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  42516. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  42517. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  42518. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  42519. ]);
  42520. ps[10] = coords.length;
  42521. coords.push([
  42522. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  42523. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  42524. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  42525. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  42526. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  42527. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  42528. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  42529. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  42530. ]);
  42531. mesh.figures.push({
  42532. type: 'patch',
  42533. coords: new Int32Array(ps), // making copies of ps and cs
  42534. colors: new Int32Array(cs)
  42535. });
  42536. }
  42537. }
  42538. function decodeType7Shading(mesh, reader) {
  42539. var coords = mesh.coords;
  42540. var colors = mesh.colors;
  42541. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  42542. var cs = new Int32Array(4); // c00, c30, c03, c33
  42543. while (reader.hasData) {
  42544. var f = reader.readFlag();
  42545. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  42546. var i, ii;
  42547. var pi = coords.length;
  42548. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  42549. coords.push(reader.readCoordinate());
  42550. }
  42551. var ci = colors.length;
  42552. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  42553. colors.push(reader.readComponents());
  42554. }
  42555. var tmp1, tmp2, tmp3, tmp4;
  42556. switch (f) {
  42557. case 0:
  42558. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  42559. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  42560. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  42561. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  42562. cs[2] = ci + 1; cs[3] = ci + 2;
  42563. cs[0] = ci; cs[1] = ci + 3;
  42564. break;
  42565. case 1:
  42566. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  42567. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42568. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42569. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42570. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42571. tmp1 = cs[2]; tmp2 = cs[3];
  42572. cs[2] = tmp2; cs[3] = ci;
  42573. cs[0] = tmp1; cs[1] = ci + 1;
  42574. break;
  42575. case 2:
  42576. tmp1 = ps[15];
  42577. tmp2 = ps[11];
  42578. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42579. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42580. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42581. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42582. tmp1 = cs[3];
  42583. cs[2] = cs[1]; cs[3] = ci;
  42584. cs[0] = tmp1; cs[1] = ci + 1;
  42585. break;
  42586. case 3:
  42587. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  42588. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  42589. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  42590. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  42591. cs[2] = cs[0]; cs[3] = ci;
  42592. cs[0] = cs[1]; cs[1] = ci + 1;
  42593. break;
  42594. }
  42595. mesh.figures.push({
  42596. type: 'patch',
  42597. coords: new Int32Array(ps), // making copies of ps and cs
  42598. colors: new Int32Array(cs)
  42599. });
  42600. }
  42601. }
  42602. function updateBounds(mesh) {
  42603. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  42604. maxX = minX, maxY = minY;
  42605. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  42606. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  42607. minX = minX > x ? x : minX;
  42608. minY = minY > y ? y : minY;
  42609. maxX = maxX < x ? x : maxX;
  42610. maxY = maxY < y ? y : maxY;
  42611. }
  42612. mesh.bounds = [minX, minY, maxX, maxY];
  42613. }
  42614. function packData(mesh) {
  42615. var i, ii, j, jj;
  42616. var coords = mesh.coords;
  42617. var coordsPacked = new Float32Array(coords.length * 2);
  42618. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  42619. var xy = coords[i];
  42620. coordsPacked[j++] = xy[0];
  42621. coordsPacked[j++] = xy[1];
  42622. }
  42623. mesh.coords = coordsPacked;
  42624. var colors = mesh.colors;
  42625. var colorsPacked = new Uint8Array(colors.length * 3);
  42626. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  42627. var c = colors[i];
  42628. colorsPacked[j++] = c[0];
  42629. colorsPacked[j++] = c[1];
  42630. colorsPacked[j++] = c[2];
  42631. }
  42632. mesh.colors = colorsPacked;
  42633. var figures = mesh.figures;
  42634. for (i = 0, ii = figures.length; i < ii; i++) {
  42635. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  42636. for (j = 0, jj = ps.length; j < jj; j++) {
  42637. ps[j] *= 2;
  42638. cs[j] *= 3;
  42639. }
  42640. }
  42641. }
  42642. function Mesh(stream, matrix, xref, res) {
  42643. assert(isStream(stream), 'Mesh data is not a stream');
  42644. var dict = stream.dict;
  42645. this.matrix = matrix;
  42646. this.shadingType = dict.get('ShadingType');
  42647. this.type = 'Pattern';
  42648. this.bbox = dict.getArray('BBox');
  42649. var cs = dict.get('ColorSpace', 'CS');
  42650. cs = ColorSpace.parse(cs, xref, res);
  42651. this.cs = cs;
  42652. this.background = dict.has('Background') ?
  42653. cs.getRgb(dict.get('Background'), 0) : null;
  42654. var fnObj = dict.get('Function');
  42655. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  42656. this.coords = [];
  42657. this.colors = [];
  42658. this.figures = [];
  42659. var decodeContext = {
  42660. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  42661. bitsPerComponent: dict.get('BitsPerComponent'),
  42662. bitsPerFlag: dict.get('BitsPerFlag'),
  42663. decode: dict.getArray('Decode'),
  42664. colorFn: fn,
  42665. colorSpace: cs,
  42666. numComps: fn ? 1 : cs.numComps
  42667. };
  42668. var reader = new MeshStreamReader(stream, decodeContext);
  42669. var patchMesh = false;
  42670. switch (this.shadingType) {
  42671. case ShadingType.FREE_FORM_MESH:
  42672. decodeType4Shading(this, reader);
  42673. break;
  42674. case ShadingType.LATTICE_FORM_MESH:
  42675. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  42676. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  42677. decodeType5Shading(this, reader, verticesPerRow);
  42678. break;
  42679. case ShadingType.COONS_PATCH_MESH:
  42680. decodeType6Shading(this, reader);
  42681. patchMesh = true;
  42682. break;
  42683. case ShadingType.TENSOR_PATCH_MESH:
  42684. decodeType7Shading(this, reader);
  42685. patchMesh = true;
  42686. break;
  42687. default:
  42688. error('Unsupported mesh type.');
  42689. break;
  42690. }
  42691. if (patchMesh) {
  42692. // dirty bounds calculation for determining, how dense shall be triangles
  42693. updateBounds(this);
  42694. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  42695. buildFigureFromPatch(this, i);
  42696. }
  42697. }
  42698. // calculate bounds
  42699. updateBounds(this);
  42700. packData(this);
  42701. }
  42702. Mesh.prototype = {
  42703. getIR: function Mesh_getIR() {
  42704. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  42705. this.bounds, this.matrix, this.bbox, this.background];
  42706. }
  42707. };
  42708. return Mesh;
  42709. })();
  42710. Shadings.Dummy = (function DummyClosure() {
  42711. function Dummy() {
  42712. this.type = 'Pattern';
  42713. }
  42714. Dummy.prototype = {
  42715. getIR: function Dummy_getIR() {
  42716. return ['Dummy'];
  42717. }
  42718. };
  42719. return Dummy;
  42720. })();
  42721. function getTilingPatternIR(operatorList, dict, args) {
  42722. var matrix = dict.getArray('Matrix');
  42723. var bbox = dict.getArray('BBox');
  42724. var xstep = dict.get('XStep');
  42725. var ystep = dict.get('YStep');
  42726. var paintType = dict.get('PaintType');
  42727. var tilingType = dict.get('TilingType');
  42728. return [
  42729. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  42730. paintType, tilingType
  42731. ];
  42732. }
  42733. exports.Pattern = Pattern;
  42734. exports.getTilingPatternIR = getTilingPatternIR;
  42735. }));
  42736. (function (root, factory) {
  42737. {
  42738. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  42739. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  42740. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  42741. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  42742. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  42743. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  42744. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  42745. }
  42746. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  42747. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  42748. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  42749. coreEncodings, coreStandardFonts, coreUnicode,
  42750. coreGlyphList) {
  42751. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  42752. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  42753. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  42754. var ImageKind = sharedUtil.ImageKind;
  42755. var OPS = sharedUtil.OPS;
  42756. var TextRenderingMode = sharedUtil.TextRenderingMode;
  42757. var Util = sharedUtil.Util;
  42758. var assert = sharedUtil.assert;
  42759. var createPromiseCapability = sharedUtil.createPromiseCapability;
  42760. var error = sharedUtil.error;
  42761. var info = sharedUtil.info;
  42762. var isArray = sharedUtil.isArray;
  42763. var isNum = sharedUtil.isNum;
  42764. var isString = sharedUtil.isString;
  42765. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  42766. var warn = sharedUtil.warn;
  42767. var Dict = corePrimitives.Dict;
  42768. var Name = corePrimitives.Name;
  42769. var isCmd = corePrimitives.isCmd;
  42770. var isDict = corePrimitives.isDict;
  42771. var isName = corePrimitives.isName;
  42772. var isRef = corePrimitives.isRef;
  42773. var isStream = corePrimitives.isStream;
  42774. var DecodeStream = coreStream.DecodeStream;
  42775. var JpegStream = coreStream.JpegStream;
  42776. var Stream = coreStream.Stream;
  42777. var Lexer = coreParser.Lexer;
  42778. var Parser = coreParser.Parser;
  42779. var isEOF = coreParser.isEOF;
  42780. var PDFImage = coreImage.PDFImage;
  42781. var ColorSpace = coreColorSpace.ColorSpace;
  42782. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  42783. var ErrorFont = coreFonts.ErrorFont;
  42784. var FontFlags = coreFonts.FontFlags;
  42785. var Font = coreFonts.Font;
  42786. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  42787. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  42788. var getFontType = coreFonts.getFontType;
  42789. var isPDFFunction = coreFunction.isPDFFunction;
  42790. var PDFFunction = coreFunction.PDFFunction;
  42791. var Pattern = corePattern.Pattern;
  42792. var getTilingPatternIR = corePattern.getTilingPatternIR;
  42793. var CMapFactory = coreCMap.CMapFactory;
  42794. var IdentityCMap = coreCMap.IdentityCMap;
  42795. var getMetrics = coreMetrics.getMetrics;
  42796. var bidi = coreBidi.bidi;
  42797. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  42798. var StandardEncoding = coreEncodings.StandardEncoding;
  42799. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  42800. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  42801. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  42802. var getEncoding = coreEncodings.getEncoding;
  42803. var getStdFontMap = coreStandardFonts.getStdFontMap;
  42804. var getSerifFonts = coreStandardFonts.getSerifFonts;
  42805. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  42806. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  42807. var reverseIfRtl = coreUnicode.reverseIfRtl;
  42808. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  42809. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  42810. var PartialEvaluator = (function PartialEvaluatorClosure() {
  42811. var DefaultPartialEvaluatorOptions = {
  42812. forceDataSchema: false,
  42813. maxImageSize: -1,
  42814. disableFontFace: false,
  42815. cMapOptions: { url: null, packed: false }
  42816. };
  42817. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  42818. this.xref = xref;
  42819. this.resources = resources;
  42820. this.handler = handler;
  42821. this.forceDataSchema = forceDataSchema;
  42822. }
  42823. NativeImageDecoder.prototype = {
  42824. canDecode: function (image) {
  42825. return image instanceof JpegStream &&
  42826. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  42827. },
  42828. decode: function (image) {
  42829. // For natively supported JPEGs send them to the main thread for decoding.
  42830. var dict = image.dict;
  42831. var colorSpace = dict.get('ColorSpace', 'CS');
  42832. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  42833. var numComps = colorSpace.numComps;
  42834. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  42835. [image.getIR(this.forceDataSchema), numComps]);
  42836. return decodePromise.then(function (message) {
  42837. var data = message.data;
  42838. return new Stream(data, 0, data.length, image.dict);
  42839. });
  42840. }
  42841. };
  42842. /**
  42843. * Checks if the image can be decoded and displayed by the browser without any
  42844. * further processing such as color space conversions.
  42845. */
  42846. NativeImageDecoder.isSupported =
  42847. function NativeImageDecoder_isSupported(image, xref, res) {
  42848. var dict = image.dict;
  42849. if (dict.has('DecodeParms') || dict.has('DP')) {
  42850. return false;
  42851. }
  42852. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  42853. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  42854. cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  42855. };
  42856. /**
  42857. * Checks if the image can be decoded by the browser.
  42858. */
  42859. NativeImageDecoder.isDecodable =
  42860. function NativeImageDecoder_isDecodable(image, xref, res) {
  42861. var dict = image.dict;
  42862. if (dict.has('DecodeParms') || dict.has('DP')) {
  42863. return false;
  42864. }
  42865. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  42866. return (cs.numComps === 1 || cs.numComps === 3) &&
  42867. cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  42868. };
  42869. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  42870. uniquePrefix, idCounters, fontCache, options) {
  42871. this.pdfManager = pdfManager;
  42872. this.xref = xref;
  42873. this.handler = handler;
  42874. this.pageIndex = pageIndex;
  42875. this.uniquePrefix = uniquePrefix;
  42876. this.idCounters = idCounters;
  42877. this.fontCache = fontCache;
  42878. this.options = options || DefaultPartialEvaluatorOptions;
  42879. }
  42880. // Trying to minimize Date.now() usage and check every 100 time
  42881. var TIME_SLOT_DURATION_MS = 20;
  42882. var CHECK_TIME_EVERY = 100;
  42883. function TimeSlotManager() {
  42884. this.reset();
  42885. }
  42886. TimeSlotManager.prototype = {
  42887. check: function TimeSlotManager_check() {
  42888. if (++this.checked < CHECK_TIME_EVERY) {
  42889. return false;
  42890. }
  42891. this.checked = 0;
  42892. return this.endTime <= Date.now();
  42893. },
  42894. reset: function TimeSlotManager_reset() {
  42895. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  42896. this.checked = 0;
  42897. }
  42898. };
  42899. var deferred = Promise.resolve();
  42900. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  42901. PartialEvaluator.prototype = {
  42902. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  42903. if (!isDict(resources)) {
  42904. return false;
  42905. }
  42906. var processed = Object.create(null);
  42907. if (resources.objId) {
  42908. processed[resources.objId] = true;
  42909. }
  42910. var nodes = [resources], xref = this.xref;
  42911. while (nodes.length) {
  42912. var key, i, ii;
  42913. var node = nodes.shift();
  42914. // First check the current resources for blend modes.
  42915. var graphicStates = node.get('ExtGState');
  42916. if (isDict(graphicStates)) {
  42917. var graphicStatesKeys = graphicStates.getKeys();
  42918. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  42919. key = graphicStatesKeys[i];
  42920. var graphicState = graphicStates.get(key);
  42921. var bm = graphicState.get('BM');
  42922. if (isName(bm) && bm.name !== 'Normal') {
  42923. return true;
  42924. }
  42925. }
  42926. }
  42927. // Descend into the XObjects to look for more resources and blend modes.
  42928. var xObjects = node.get('XObject');
  42929. if (!isDict(xObjects)) {
  42930. continue;
  42931. }
  42932. var xObjectsKeys = xObjects.getKeys();
  42933. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  42934. key = xObjectsKeys[i];
  42935. var xObject = xObjects.getRaw(key);
  42936. if (isRef(xObject)) {
  42937. if (processed[xObject.toString()]) {
  42938. // The XObject has already been processed, and by avoiding a
  42939. // redundant `xref.fetch` we can *significantly* reduce the load
  42940. // time for badly generated PDF files (fixes issue6961.pdf).
  42941. continue;
  42942. }
  42943. xObject = xref.fetch(xObject);
  42944. }
  42945. if (!isStream(xObject)) {
  42946. continue;
  42947. }
  42948. if (xObject.dict.objId) {
  42949. if (processed[xObject.dict.objId]) {
  42950. // stream has objId and is processed already
  42951. continue;
  42952. }
  42953. processed[xObject.dict.objId] = true;
  42954. }
  42955. var xResources = xObject.dict.get('Resources');
  42956. // Checking objId to detect an infinite loop.
  42957. if (isDict(xResources) &&
  42958. (!xResources.objId || !processed[xResources.objId])) {
  42959. nodes.push(xResources);
  42960. if (xResources.objId) {
  42961. processed[xResources.objId] = true;
  42962. }
  42963. }
  42964. }
  42965. }
  42966. return false;
  42967. },
  42968. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  42969. xobj, smask,
  42970. operatorList,
  42971. task,
  42972. initialState) {
  42973. var matrix = xobj.dict.getArray('Matrix');
  42974. var bbox = xobj.dict.getArray('BBox');
  42975. var group = xobj.dict.get('Group');
  42976. if (group) {
  42977. var groupOptions = {
  42978. matrix: matrix,
  42979. bbox: bbox,
  42980. smask: smask,
  42981. isolated: false,
  42982. knockout: false
  42983. };
  42984. var groupSubtype = group.get('S');
  42985. var colorSpace;
  42986. if (isName(groupSubtype, 'Transparency')) {
  42987. groupOptions.isolated = (group.get('I') || false);
  42988. groupOptions.knockout = (group.get('K') || false);
  42989. colorSpace = (group.has('CS') ?
  42990. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  42991. }
  42992. if (smask && smask.backdrop) {
  42993. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  42994. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  42995. }
  42996. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  42997. }
  42998. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  42999. return this.getOperatorList(xobj, task,
  43000. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  43001. then(function () {
  43002. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  43003. if (group) {
  43004. operatorList.addOp(OPS.endGroup, [groupOptions]);
  43005. }
  43006. });
  43007. },
  43008. buildPaintImageXObject:
  43009. function PartialEvaluator_buildPaintImageXObject(resources, image,
  43010. inline, operatorList,
  43011. cacheKey, imageCache) {
  43012. var self = this;
  43013. var dict = image.dict;
  43014. var w = dict.get('Width', 'W');
  43015. var h = dict.get('Height', 'H');
  43016. if (!(w && isNum(w)) || !(h && isNum(h))) {
  43017. warn('Image dimensions are missing, or not numbers.');
  43018. return;
  43019. }
  43020. var maxImageSize = this.options.maxImageSize;
  43021. if (maxImageSize !== -1 && w * h > maxImageSize) {
  43022. warn('Image exceeded maximum allowed size and was removed.');
  43023. return;
  43024. }
  43025. var imageMask = (dict.get('ImageMask', 'IM') || false);
  43026. var imgData, args;
  43027. if (imageMask) {
  43028. // This depends on a tmpCanvas being filled with the
  43029. // current fillStyle, such that processing the pixel
  43030. // data can't be done here. Instead of creating a
  43031. // complete PDFImage, only read the information needed
  43032. // for later.
  43033. var width = dict.get('Width', 'W');
  43034. var height = dict.get('Height', 'H');
  43035. var bitStrideLength = (width + 7) >> 3;
  43036. var imgArray = image.getBytes(bitStrideLength * height);
  43037. var decode = dict.getArray('Decode', 'D');
  43038. var inverseDecode = (!!decode && decode[0] > 0);
  43039. imgData = PDFImage.createMask(imgArray, width, height,
  43040. image instanceof DecodeStream,
  43041. inverseDecode);
  43042. imgData.cached = true;
  43043. args = [imgData];
  43044. operatorList.addOp(OPS.paintImageMaskXObject, args);
  43045. if (cacheKey) {
  43046. imageCache[cacheKey] = {
  43047. fn: OPS.paintImageMaskXObject,
  43048. args: args
  43049. };
  43050. }
  43051. return;
  43052. }
  43053. var softMask = (dict.get('SMask', 'SM') || false);
  43054. var mask = (dict.get('Mask') || false);
  43055. var SMALL_IMAGE_DIMENSIONS = 200;
  43056. // Inlining small images into the queue as RGB data
  43057. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  43058. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  43059. var imageObj = new PDFImage(this.xref, resources, image,
  43060. inline, null, null);
  43061. // We force the use of RGBA_32BPP images here, because we can't handle
  43062. // any other kind.
  43063. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  43064. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  43065. return;
  43066. }
  43067. // If there is no imageMask, create the PDFImage and a lot
  43068. // of image processing can be done here.
  43069. var uniquePrefix = (this.uniquePrefix || '');
  43070. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  43071. operatorList.addDependency(objId);
  43072. args = [objId, w, h];
  43073. if (!softMask && !mask && image instanceof JpegStream &&
  43074. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  43075. // These JPEGs don't need any more processing so we can just send it.
  43076. operatorList.addOp(OPS.paintJpegXObject, args);
  43077. this.handler.send('obj',
  43078. [objId, this.pageIndex, 'JpegStream',
  43079. image.getIR(this.options.forceDataSchema)]);
  43080. return;
  43081. }
  43082. // Creates native image decoder only if a JPEG image or mask is present.
  43083. var nativeImageDecoder = null;
  43084. if (image instanceof JpegStream || mask instanceof JpegStream ||
  43085. softMask instanceof JpegStream) {
  43086. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  43087. self.handler, self.options.forceDataSchema);
  43088. }
  43089. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  43090. nativeImageDecoder).
  43091. then(function(imageObj) {
  43092. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  43093. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  43094. [imgData.data.buffer]);
  43095. }).then(undefined, function (reason) {
  43096. warn('Unable to decode image: ' + reason);
  43097. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  43098. });
  43099. operatorList.addOp(OPS.paintImageXObject, args);
  43100. if (cacheKey) {
  43101. imageCache[cacheKey] = {
  43102. fn: OPS.paintImageXObject,
  43103. args: args
  43104. };
  43105. }
  43106. },
  43107. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  43108. operatorList, task,
  43109. stateManager) {
  43110. var smaskContent = smask.get('G');
  43111. var smaskOptions = {
  43112. subtype: smask.get('S').name,
  43113. backdrop: smask.get('BC')
  43114. };
  43115. // The SMask might have a alpha/luminosity value transfer function --
  43116. // we will build a map of integer values in range 0..255 to be fast.
  43117. var transferObj = smask.get('TR');
  43118. if (isPDFFunction(transferObj)) {
  43119. var transferFn = PDFFunction.parse(this.xref, transferObj);
  43120. var transferMap = new Uint8Array(256);
  43121. var tmp = new Float32Array(1);
  43122. for (var i = 0; i < 256; i++) {
  43123. tmp[0] = i / 255;
  43124. transferFn(tmp, 0, tmp, 0);
  43125. transferMap[i] = (tmp[0] * 255) | 0;
  43126. }
  43127. smaskOptions.transferMap = transferMap;
  43128. }
  43129. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  43130. operatorList, task, stateManager.state.clone());
  43131. },
  43132. handleTilingType:
  43133. function PartialEvaluator_handleTilingType(fn, args, resources,
  43134. pattern, patternDict,
  43135. operatorList, task) {
  43136. // Create an IR of the pattern code.
  43137. var tilingOpList = new OperatorList();
  43138. // Merge the available resources, to prevent issues when the patternDict
  43139. // is missing some /Resources entries (fixes issue6541.pdf).
  43140. var resourcesArray = [patternDict.get('Resources'), resources];
  43141. var patternResources = Dict.merge(this.xref, resourcesArray);
  43142. return this.getOperatorList(pattern, task, patternResources,
  43143. tilingOpList).then(function () {
  43144. // Add the dependencies to the parent operator list so they are
  43145. // resolved before sub operator list is executed synchronously.
  43146. operatorList.addDependencies(tilingOpList.dependencies);
  43147. operatorList.addOp(fn, getTilingPatternIR({
  43148. fnArray: tilingOpList.fnArray,
  43149. argsArray: tilingOpList.argsArray
  43150. }, patternDict, args));
  43151. });
  43152. },
  43153. handleSetFont:
  43154. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  43155. operatorList, task, state) {
  43156. // TODO(mack): Not needed?
  43157. var fontName;
  43158. if (fontArgs) {
  43159. fontArgs = fontArgs.slice();
  43160. fontName = fontArgs[0].name;
  43161. }
  43162. var self = this;
  43163. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  43164. function (translated) {
  43165. if (!translated.font.isType3Font) {
  43166. return translated;
  43167. }
  43168. return translated.loadType3Data(self, resources, operatorList, task).
  43169. then(function () {
  43170. return translated;
  43171. }, function (reason) {
  43172. // Error in the font data -- sending unsupported feature notification.
  43173. self.handler.send('UnsupportedFeature',
  43174. {featureId: UNSUPPORTED_FEATURES.font});
  43175. return new TranslatedFont('g_font_error',
  43176. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  43177. });
  43178. }).then(function (translated) {
  43179. state.font = translated.font;
  43180. translated.send(self.handler);
  43181. return translated.loadedName;
  43182. });
  43183. },
  43184. handleText: function PartialEvaluator_handleText(chars, state) {
  43185. var font = state.font;
  43186. var glyphs = font.charsToGlyphs(chars);
  43187. var isAddToPathSet = !!(state.textRenderingMode &
  43188. TextRenderingMode.ADD_TO_PATH_FLAG);
  43189. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  43190. var buildPath = function (fontChar) {
  43191. if (!font.renderer.hasBuiltPath(fontChar)) {
  43192. var path = font.renderer.getPathJs(fontChar);
  43193. this.handler.send('commonobj', [
  43194. font.loadedName + '_path_' + fontChar,
  43195. 'FontPath',
  43196. path
  43197. ]);
  43198. }
  43199. }.bind(this);
  43200. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  43201. var glyph = glyphs[i];
  43202. buildPath(glyph.fontChar);
  43203. // If the glyph has an accent we need to build a path for its
  43204. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  43205. var accent = glyph.accent;
  43206. if (accent && accent.fontChar) {
  43207. buildPath(accent.fontChar);
  43208. }
  43209. }
  43210. }
  43211. return glyphs;
  43212. },
  43213. setGState: function PartialEvaluator_setGState(resources, gState,
  43214. operatorList, task,
  43215. xref, stateManager) {
  43216. // This array holds the converted/processed state data.
  43217. var gStateObj = [];
  43218. var gStateKeys = gState.getKeys();
  43219. var self = this;
  43220. var promise = Promise.resolve();
  43221. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  43222. var key = gStateKeys[i];
  43223. var value = gState.get(key);
  43224. switch (key) {
  43225. case 'Type':
  43226. break;
  43227. case 'LW':
  43228. case 'LC':
  43229. case 'LJ':
  43230. case 'ML':
  43231. case 'D':
  43232. case 'RI':
  43233. case 'FL':
  43234. case 'CA':
  43235. case 'ca':
  43236. gStateObj.push([key, value]);
  43237. break;
  43238. case 'Font':
  43239. promise = promise.then(function () {
  43240. return self.handleSetFont(resources, null, value[0], operatorList,
  43241. task, stateManager.state).
  43242. then(function (loadedName) {
  43243. operatorList.addDependency(loadedName);
  43244. gStateObj.push([key, [loadedName, value[1]]]);
  43245. });
  43246. });
  43247. break;
  43248. case 'BM':
  43249. gStateObj.push([key, value]);
  43250. break;
  43251. case 'SMask':
  43252. if (isName(value, 'None')) {
  43253. gStateObj.push([key, false]);
  43254. break;
  43255. }
  43256. if (isDict(value)) {
  43257. promise = promise.then(function (dict) {
  43258. return self.handleSMask(dict, resources, operatorList,
  43259. task, stateManager);
  43260. }.bind(this, value));
  43261. gStateObj.push([key, true]);
  43262. } else {
  43263. warn('Unsupported SMask type');
  43264. }
  43265. break;
  43266. // Only generate info log messages for the following since
  43267. // they are unlikely to have a big impact on the rendering.
  43268. case 'OP':
  43269. case 'op':
  43270. case 'OPM':
  43271. case 'BG':
  43272. case 'BG2':
  43273. case 'UCR':
  43274. case 'UCR2':
  43275. case 'TR':
  43276. case 'TR2':
  43277. case 'HT':
  43278. case 'SM':
  43279. case 'SA':
  43280. case 'AIS':
  43281. case 'TK':
  43282. // TODO implement these operators.
  43283. info('graphic state operator ' + key);
  43284. break;
  43285. default:
  43286. info('Unknown graphic state operator ' + key);
  43287. break;
  43288. }
  43289. }
  43290. return promise.then(function () {
  43291. if (gStateObj.length > 0) {
  43292. operatorList.addOp(OPS.setGState, [gStateObj]);
  43293. }
  43294. });
  43295. },
  43296. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  43297. resources) {
  43298. function errorFont() {
  43299. return Promise.resolve(new TranslatedFont('g_font_error',
  43300. new ErrorFont('Font ' + fontName + ' is not available'), font));
  43301. }
  43302. var fontRef;
  43303. if (font) { // Loading by ref.
  43304. assert(isRef(font));
  43305. fontRef = font;
  43306. } else { // Loading by name.
  43307. var fontRes = resources.get('Font');
  43308. if (fontRes) {
  43309. fontRef = fontRes.getRaw(fontName);
  43310. } else {
  43311. warn('fontRes not available');
  43312. return errorFont();
  43313. }
  43314. }
  43315. if (!fontRef) {
  43316. warn('fontRef not available');
  43317. return errorFont();
  43318. }
  43319. if (this.fontCache.has(fontRef)) {
  43320. return this.fontCache.get(fontRef);
  43321. }
  43322. font = xref.fetchIfRef(fontRef);
  43323. if (!isDict(font)) {
  43324. return errorFont();
  43325. }
  43326. // We are holding `font.translated` references just for `fontRef`s that
  43327. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  43328. if (font.translated) {
  43329. return font.translated;
  43330. }
  43331. var fontCapability = createPromiseCapability();
  43332. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  43333. var descriptor = preEvaluatedFont.descriptor;
  43334. var fontRefIsRef = isRef(fontRef), fontID;
  43335. if (fontRefIsRef) {
  43336. fontID = fontRef.toString();
  43337. }
  43338. if (isDict(descriptor)) {
  43339. if (!descriptor.fontAliases) {
  43340. descriptor.fontAliases = Object.create(null);
  43341. }
  43342. var fontAliases = descriptor.fontAliases;
  43343. var hash = preEvaluatedFont.hash;
  43344. if (fontAliases[hash]) {
  43345. var aliasFontRef = fontAliases[hash].aliasRef;
  43346. if (fontRefIsRef && aliasFontRef &&
  43347. this.fontCache.has(aliasFontRef)) {
  43348. this.fontCache.putAlias(fontRef, aliasFontRef);
  43349. return this.fontCache.get(fontRef);
  43350. }
  43351. } else {
  43352. fontAliases[hash] = {
  43353. fontID: Font.getFontID()
  43354. };
  43355. }
  43356. if (fontRefIsRef) {
  43357. fontAliases[hash].aliasRef = fontRef;
  43358. }
  43359. fontID = fontAliases[hash].fontID;
  43360. }
  43361. // Workaround for bad PDF generators that reference fonts incorrectly,
  43362. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  43363. // In this case we should not put the font into `this.fontCache` (which is
  43364. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  43365. //
  43366. // However, if we don't cache the font it's not possible to remove it
  43367. // when `cleanup` is triggered from the API, which causes issues on
  43368. // subsequent rendering operations (see issue7403.pdf).
  43369. // A simple workaround would be to just not hold `font.translated`
  43370. // references in this case, but this would force us to unnecessarily load
  43371. // the same fonts over and over.
  43372. //
  43373. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  43374. // key in `this.fontCache`, to allow the font to be cached.
  43375. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  43376. // keys. Also, since `fontRef` is used when getting cached fonts,
  43377. // we'll not accidentally match fonts cached with the `fontID`.
  43378. if (fontRefIsRef) {
  43379. this.fontCache.put(fontRef, fontCapability.promise);
  43380. } else {
  43381. if (!fontID) {
  43382. fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
  43383. }
  43384. this.fontCache.put('id_' + fontID, fontCapability.promise);
  43385. }
  43386. assert(fontID, 'The "fontID" must be defined.');
  43387. // Keep track of each font we translated so the caller can
  43388. // load them asynchronously before calling display on a page.
  43389. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  43390. font.translated = fontCapability.promise;
  43391. // TODO move promises into translate font
  43392. var translatedPromise;
  43393. try {
  43394. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  43395. } catch (e) {
  43396. translatedPromise = Promise.reject(e);
  43397. }
  43398. var self = this;
  43399. translatedPromise.then(function (translatedFont) {
  43400. if (translatedFont.fontType !== undefined) {
  43401. var xrefFontStats = xref.stats.fontTypes;
  43402. xrefFontStats[translatedFont.fontType] = true;
  43403. }
  43404. fontCapability.resolve(new TranslatedFont(font.loadedName,
  43405. translatedFont, font));
  43406. }, function (reason) {
  43407. // TODO fontCapability.reject?
  43408. // Error in the font data -- sending unsupported feature notification.
  43409. self.handler.send('UnsupportedFeature',
  43410. {featureId: UNSUPPORTED_FEATURES.font});
  43411. try {
  43412. // error, but it's still nice to have font type reported
  43413. var descriptor = preEvaluatedFont.descriptor;
  43414. var fontFile3 = descriptor && descriptor.get('FontFile3');
  43415. var subtype = fontFile3 && fontFile3.get('Subtype');
  43416. var fontType = getFontType(preEvaluatedFont.type,
  43417. subtype && subtype.name);
  43418. var xrefFontStats = xref.stats.fontTypes;
  43419. xrefFontStats[fontType] = true;
  43420. } catch (ex) { }
  43421. fontCapability.resolve(new TranslatedFont(font.loadedName,
  43422. new ErrorFont(reason instanceof Error ? reason.message : reason),
  43423. font));
  43424. });
  43425. return fontCapability.promise;
  43426. },
  43427. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  43428. var lastIndex = operatorList.length - 1;
  43429. if (!args) {
  43430. args = [];
  43431. }
  43432. if (lastIndex < 0 ||
  43433. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  43434. operatorList.addOp(OPS.constructPath, [[fn], args]);
  43435. } else {
  43436. var opArgs = operatorList.argsArray[lastIndex];
  43437. opArgs[0].push(fn);
  43438. Array.prototype.push.apply(opArgs[1], args);
  43439. }
  43440. },
  43441. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  43442. cs, patterns, resources, task, xref) {
  43443. // compile tiling patterns
  43444. var patternName = args[args.length - 1];
  43445. // SCN/scn applies patterns along with normal colors
  43446. var pattern;
  43447. if (isName(patternName) &&
  43448. (pattern = patterns.get(patternName.name))) {
  43449. var dict = (isStream(pattern) ? pattern.dict : pattern);
  43450. var typeNum = dict.get('PatternType');
  43451. if (typeNum === TILING_PATTERN) {
  43452. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  43453. return this.handleTilingType(fn, color, resources, pattern,
  43454. dict, operatorList, task);
  43455. } else if (typeNum === SHADING_PATTERN) {
  43456. var shading = dict.get('Shading');
  43457. var matrix = dict.getArray('Matrix');
  43458. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  43459. this.handler);
  43460. operatorList.addOp(fn, pattern.getIR());
  43461. return Promise.resolve();
  43462. } else {
  43463. return Promise.reject('Unknown PatternType: ' + typeNum);
  43464. }
  43465. }
  43466. // TODO shall we fail here?
  43467. operatorList.addOp(fn, args);
  43468. return Promise.resolve();
  43469. },
  43470. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  43471. task,
  43472. resources,
  43473. operatorList,
  43474. initialState) {
  43475. var self = this;
  43476. var xref = this.xref;
  43477. var imageCache = Object.create(null);
  43478. assert(operatorList);
  43479. resources = (resources || Dict.empty);
  43480. var xobjs = (resources.get('XObject') || Dict.empty);
  43481. var patterns = (resources.get('Pattern') || Dict.empty);
  43482. var stateManager = new StateManager(initialState || new EvalState());
  43483. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  43484. var timeSlotManager = new TimeSlotManager();
  43485. return new Promise(function promiseBody(resolve, reject) {
  43486. var next = function (promise) {
  43487. promise.then(function () {
  43488. try {
  43489. promiseBody(resolve, reject);
  43490. } catch (ex) {
  43491. reject(ex);
  43492. }
  43493. }, reject);
  43494. };
  43495. task.ensureNotTerminated();
  43496. timeSlotManager.reset();
  43497. var stop, operation = {}, i, ii, cs;
  43498. while (!(stop = timeSlotManager.check())) {
  43499. // The arguments parsed by read() are used beyond this loop, so we
  43500. // cannot reuse the same array on each iteration. Therefore we pass
  43501. // in |null| as the initial value (see the comment on
  43502. // EvaluatorPreprocessor_read() for why).
  43503. operation.args = null;
  43504. if (!(preprocessor.read(operation))) {
  43505. break;
  43506. }
  43507. var args = operation.args;
  43508. var fn = operation.fn;
  43509. switch (fn | 0) {
  43510. case OPS.paintXObject:
  43511. if (args[0].code) {
  43512. break;
  43513. }
  43514. // eagerly compile XForm objects
  43515. var name = args[0].name;
  43516. if (!name) {
  43517. warn('XObject must be referred to by name.');
  43518. continue;
  43519. }
  43520. if (imageCache[name] !== undefined) {
  43521. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  43522. args = null;
  43523. continue;
  43524. }
  43525. var xobj = xobjs.get(name);
  43526. if (xobj) {
  43527. assert(isStream(xobj), 'XObject should be a stream');
  43528. var type = xobj.dict.get('Subtype');
  43529. assert(isName(type), 'XObject should have a Name subtype');
  43530. if (type.name === 'Form') {
  43531. stateManager.save();
  43532. next(self.buildFormXObject(resources, xobj, null,
  43533. operatorList, task,
  43534. stateManager.state.clone()).
  43535. then(function () {
  43536. stateManager.restore();
  43537. }));
  43538. return;
  43539. } else if (type.name === 'Image') {
  43540. self.buildPaintImageXObject(resources, xobj, false,
  43541. operatorList, name, imageCache);
  43542. args = null;
  43543. continue;
  43544. } else if (type.name === 'PS') {
  43545. // PostScript XObjects are unused when viewing documents.
  43546. // See section 4.7.1 of Adobe's PDF reference.
  43547. info('Ignored XObject subtype PS');
  43548. continue;
  43549. } else {
  43550. error('Unhandled XObject subtype ' + type.name);
  43551. }
  43552. }
  43553. break;
  43554. case OPS.setFont:
  43555. var fontSize = args[1];
  43556. // eagerly collect all fonts
  43557. next(self.handleSetFont(resources, args, null, operatorList,
  43558. task, stateManager.state).
  43559. then(function (loadedName) {
  43560. operatorList.addDependency(loadedName);
  43561. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  43562. }));
  43563. return;
  43564. case OPS.endInlineImage:
  43565. var cacheKey = args[0].cacheKey;
  43566. if (cacheKey) {
  43567. var cacheEntry = imageCache[cacheKey];
  43568. if (cacheEntry !== undefined) {
  43569. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  43570. args = null;
  43571. continue;
  43572. }
  43573. }
  43574. self.buildPaintImageXObject(resources, args[0], true,
  43575. operatorList, cacheKey, imageCache);
  43576. args = null;
  43577. continue;
  43578. case OPS.showText:
  43579. args[0] = self.handleText(args[0], stateManager.state);
  43580. break;
  43581. case OPS.showSpacedText:
  43582. var arr = args[0];
  43583. var combinedGlyphs = [];
  43584. var arrLength = arr.length;
  43585. var state = stateManager.state;
  43586. for (i = 0; i < arrLength; ++i) {
  43587. var arrItem = arr[i];
  43588. if (isString(arrItem)) {
  43589. Array.prototype.push.apply(combinedGlyphs,
  43590. self.handleText(arrItem, state));
  43591. } else if (isNum(arrItem)) {
  43592. combinedGlyphs.push(arrItem);
  43593. }
  43594. }
  43595. args[0] = combinedGlyphs;
  43596. fn = OPS.showText;
  43597. break;
  43598. case OPS.nextLineShowText:
  43599. operatorList.addOp(OPS.nextLine);
  43600. args[0] = self.handleText(args[0], stateManager.state);
  43601. fn = OPS.showText;
  43602. break;
  43603. case OPS.nextLineSetSpacingShowText:
  43604. operatorList.addOp(OPS.nextLine);
  43605. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  43606. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  43607. args[0] = self.handleText(args[0], stateManager.state);
  43608. fn = OPS.showText;
  43609. break;
  43610. case OPS.setTextRenderingMode:
  43611. stateManager.state.textRenderingMode = args[0];
  43612. break;
  43613. case OPS.setFillColorSpace:
  43614. stateManager.state.fillColorSpace =
  43615. ColorSpace.parse(args[0], xref, resources);
  43616. continue;
  43617. case OPS.setStrokeColorSpace:
  43618. stateManager.state.strokeColorSpace =
  43619. ColorSpace.parse(args[0], xref, resources);
  43620. continue;
  43621. case OPS.setFillColor:
  43622. cs = stateManager.state.fillColorSpace;
  43623. args = cs.getRgb(args, 0);
  43624. fn = OPS.setFillRGBColor;
  43625. break;
  43626. case OPS.setStrokeColor:
  43627. cs = stateManager.state.strokeColorSpace;
  43628. args = cs.getRgb(args, 0);
  43629. fn = OPS.setStrokeRGBColor;
  43630. break;
  43631. case OPS.setFillGray:
  43632. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  43633. args = ColorSpace.singletons.gray.getRgb(args, 0);
  43634. fn = OPS.setFillRGBColor;
  43635. break;
  43636. case OPS.setStrokeGray:
  43637. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  43638. args = ColorSpace.singletons.gray.getRgb(args, 0);
  43639. fn = OPS.setStrokeRGBColor;
  43640. break;
  43641. case OPS.setFillCMYKColor:
  43642. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  43643. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  43644. fn = OPS.setFillRGBColor;
  43645. break;
  43646. case OPS.setStrokeCMYKColor:
  43647. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  43648. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  43649. fn = OPS.setStrokeRGBColor;
  43650. break;
  43651. case OPS.setFillRGBColor:
  43652. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  43653. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  43654. break;
  43655. case OPS.setStrokeRGBColor:
  43656. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  43657. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  43658. break;
  43659. case OPS.setFillColorN:
  43660. cs = stateManager.state.fillColorSpace;
  43661. if (cs.name === 'Pattern') {
  43662. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  43663. cs, patterns, resources, task, xref));
  43664. return;
  43665. }
  43666. args = cs.getRgb(args, 0);
  43667. fn = OPS.setFillRGBColor;
  43668. break;
  43669. case OPS.setStrokeColorN:
  43670. cs = stateManager.state.strokeColorSpace;
  43671. if (cs.name === 'Pattern') {
  43672. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  43673. cs, patterns, resources, task, xref));
  43674. return;
  43675. }
  43676. args = cs.getRgb(args, 0);
  43677. fn = OPS.setStrokeRGBColor;
  43678. break;
  43679. case OPS.shadingFill:
  43680. var shadingRes = resources.get('Shading');
  43681. if (!shadingRes) {
  43682. error('No shading resource found');
  43683. }
  43684. var shading = shadingRes.get(args[0].name);
  43685. if (!shading) {
  43686. error('No shading object found');
  43687. }
  43688. var shadingFill = Pattern.parseShading(shading, null, xref,
  43689. resources, self.handler);
  43690. var patternIR = shadingFill.getIR();
  43691. args = [patternIR];
  43692. fn = OPS.shadingFill;
  43693. break;
  43694. case OPS.setGState:
  43695. var dictName = args[0];
  43696. var extGState = resources.get('ExtGState');
  43697. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  43698. break;
  43699. }
  43700. var gState = extGState.get(dictName.name);
  43701. next(self.setGState(resources, gState, operatorList, task, xref,
  43702. stateManager));
  43703. return;
  43704. case OPS.moveTo:
  43705. case OPS.lineTo:
  43706. case OPS.curveTo:
  43707. case OPS.curveTo2:
  43708. case OPS.curveTo3:
  43709. case OPS.closePath:
  43710. self.buildPath(operatorList, fn, args);
  43711. continue;
  43712. case OPS.rectangle:
  43713. self.buildPath(operatorList, fn, args);
  43714. continue;
  43715. case OPS.markPoint:
  43716. case OPS.markPointProps:
  43717. case OPS.beginMarkedContent:
  43718. case OPS.beginMarkedContentProps:
  43719. case OPS.endMarkedContent:
  43720. case OPS.beginCompat:
  43721. case OPS.endCompat:
  43722. // Ignore operators where the corresponding handlers are known to
  43723. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  43724. // serialization errors and is also a bit more efficient.
  43725. // We could also try to serialize all objects in a general way,
  43726. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  43727. // but doing so is meaningless without knowing the semantics.
  43728. continue;
  43729. default:
  43730. // Note: Ignore the operator if it has `Dict` arguments, since
  43731. // those are non-serializable, otherwise postMessage will throw
  43732. // "An object could not be cloned.".
  43733. if (args !== null) {
  43734. for (i = 0, ii = args.length; i < ii; i++) {
  43735. if (args[i] instanceof Dict) {
  43736. break;
  43737. }
  43738. }
  43739. if (i < ii) {
  43740. warn('getOperatorList - ignoring operator: ' + fn);
  43741. continue;
  43742. }
  43743. }
  43744. }
  43745. operatorList.addOp(fn, args);
  43746. }
  43747. if (stop) {
  43748. next(deferred);
  43749. return;
  43750. }
  43751. // Some PDFs don't close all restores inside object/form.
  43752. // Closing those for them.
  43753. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  43754. operatorList.addOp(OPS.restore, []);
  43755. }
  43756. resolve();
  43757. });
  43758. },
  43759. getTextContent:
  43760. function PartialEvaluator_getTextContent(stream, task, resources,
  43761. stateManager,
  43762. normalizeWhitespace,
  43763. combineTextItems) {
  43764. stateManager = (stateManager || new StateManager(new TextState()));
  43765. var WhitespaceRegexp = /\s/g;
  43766. var textContent = {
  43767. items: [],
  43768. styles: Object.create(null)
  43769. };
  43770. var textContentItem = {
  43771. initialized: false,
  43772. str: [],
  43773. width: 0,
  43774. height: 0,
  43775. vertical: false,
  43776. lastAdvanceWidth: 0,
  43777. lastAdvanceHeight: 0,
  43778. textAdvanceScale: 0,
  43779. spaceWidth: 0,
  43780. fakeSpaceMin: Infinity,
  43781. fakeMultiSpaceMin: Infinity,
  43782. fakeMultiSpaceMax: -0,
  43783. textRunBreakAllowed: false,
  43784. transform: null,
  43785. fontName: null
  43786. };
  43787. var SPACE_FACTOR = 0.3;
  43788. var MULTI_SPACE_FACTOR = 1.5;
  43789. var MULTI_SPACE_FACTOR_MAX = 4;
  43790. var self = this;
  43791. var xref = this.xref;
  43792. resources = (xref.fetchIfRef(resources) || Dict.empty);
  43793. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  43794. var xobjs = null;
  43795. var xobjsCache = Object.create(null);
  43796. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  43797. var textState;
  43798. function ensureTextContentItem() {
  43799. if (textContentItem.initialized) {
  43800. return textContentItem;
  43801. }
  43802. var font = textState.font;
  43803. if (!(font.loadedName in textContent.styles)) {
  43804. textContent.styles[font.loadedName] = {
  43805. fontFamily: font.fallbackName,
  43806. ascent: font.ascent,
  43807. descent: font.descent,
  43808. vertical: font.vertical
  43809. };
  43810. }
  43811. textContentItem.fontName = font.loadedName;
  43812. // 9.4.4 Text Space Details
  43813. var tsm = [textState.fontSize * textState.textHScale, 0,
  43814. 0, textState.fontSize,
  43815. 0, textState.textRise];
  43816. if (font.isType3Font &&
  43817. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  43818. textState.fontSize === 1) {
  43819. var glyphHeight = font.bbox[3] - font.bbox[1];
  43820. if (glyphHeight > 0) {
  43821. glyphHeight = glyphHeight * textState.fontMatrix[3];
  43822. tsm[3] *= glyphHeight;
  43823. }
  43824. }
  43825. var trm = Util.transform(textState.ctm,
  43826. Util.transform(textState.textMatrix, tsm));
  43827. textContentItem.transform = trm;
  43828. if (!font.vertical) {
  43829. textContentItem.width = 0;
  43830. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  43831. textContentItem.vertical = false;
  43832. } else {
  43833. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  43834. textContentItem.height = 0;
  43835. textContentItem.vertical = true;
  43836. }
  43837. var a = textState.textLineMatrix[0];
  43838. var b = textState.textLineMatrix[1];
  43839. var scaleLineX = Math.sqrt(a * a + b * b);
  43840. a = textState.ctm[0];
  43841. b = textState.ctm[1];
  43842. var scaleCtmX = Math.sqrt(a * a + b * b);
  43843. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  43844. textContentItem.lastAdvanceWidth = 0;
  43845. textContentItem.lastAdvanceHeight = 0;
  43846. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  43847. if (spaceWidth) {
  43848. textContentItem.spaceWidth = spaceWidth;
  43849. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  43850. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  43851. textContentItem.fakeMultiSpaceMax =
  43852. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  43853. // It's okay for monospace fonts to fake as much space as needed.
  43854. textContentItem.textRunBreakAllowed = !font.isMonospace;
  43855. } else {
  43856. textContentItem.spaceWidth = 0;
  43857. textContentItem.fakeSpaceMin = Infinity;
  43858. textContentItem.fakeMultiSpaceMin = Infinity;
  43859. textContentItem.fakeMultiSpaceMax = 0;
  43860. textContentItem.textRunBreakAllowed = false;
  43861. }
  43862. textContentItem.initialized = true;
  43863. return textContentItem;
  43864. }
  43865. function replaceWhitespace(str) {
  43866. // Replaces all whitespaces with standard spaces (0x20), to avoid
  43867. // alignment issues between the textLayer and the canvas if the text
  43868. // contains e.g. tabs (fixes issue6612.pdf).
  43869. var i = 0, ii = str.length, code;
  43870. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  43871. i++;
  43872. }
  43873. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  43874. }
  43875. function runBidiTransform(textChunk) {
  43876. var str = textChunk.str.join('');
  43877. var bidiResult = bidi(str, -1, textChunk.vertical);
  43878. return {
  43879. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  43880. bidiResult.str),
  43881. dir: bidiResult.dir,
  43882. width: textChunk.width,
  43883. height: textChunk.height,
  43884. transform: textChunk.transform,
  43885. fontName: textChunk.fontName
  43886. };
  43887. }
  43888. function handleSetFont(fontName, fontRef) {
  43889. return self.loadFont(fontName, fontRef, xref, resources).
  43890. then(function (translated) {
  43891. textState.font = translated.font;
  43892. textState.fontMatrix = translated.font.fontMatrix ||
  43893. FONT_IDENTITY_MATRIX;
  43894. });
  43895. }
  43896. function buildTextContentItem(chars) {
  43897. var font = textState.font;
  43898. var textChunk = ensureTextContentItem();
  43899. var width = 0;
  43900. var height = 0;
  43901. var glyphs = font.charsToGlyphs(chars);
  43902. var defaultVMetrics = font.defaultVMetrics;
  43903. for (var i = 0; i < glyphs.length; i++) {
  43904. var glyph = glyphs[i];
  43905. var vMetricX = null;
  43906. var vMetricY = null;
  43907. var glyphWidth = null;
  43908. if (font.vertical) {
  43909. if (glyph.vmetric) {
  43910. glyphWidth = glyph.vmetric[0];
  43911. vMetricX = glyph.vmetric[1];
  43912. vMetricY = glyph.vmetric[2];
  43913. } else {
  43914. glyphWidth = glyph.width;
  43915. vMetricX = glyph.width * 0.5;
  43916. vMetricY = defaultVMetrics[2];
  43917. }
  43918. } else {
  43919. glyphWidth = glyph.width;
  43920. }
  43921. var glyphUnicode = glyph.unicode;
  43922. var NormalizedUnicodes = getNormalizedUnicodes();
  43923. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  43924. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  43925. }
  43926. glyphUnicode = reverseIfRtl(glyphUnicode);
  43927. // The following will calculate the x and y of the individual glyphs.
  43928. // if (font.vertical) {
  43929. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  43930. // textState.fontMatrix[0];
  43931. // tsm[5] -= vMetricY * textState.fontSize *
  43932. // textState.fontMatrix[0];
  43933. // }
  43934. // var trm = Util.transform(textState.textMatrix, tsm);
  43935. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  43936. // var x = pt[0];
  43937. // var y = pt[1];
  43938. var charSpacing = textState.charSpacing;
  43939. if (glyph.isSpace) {
  43940. var wordSpacing = textState.wordSpacing;
  43941. charSpacing += wordSpacing;
  43942. if (wordSpacing > 0) {
  43943. addFakeSpaces(wordSpacing, textChunk.str);
  43944. }
  43945. }
  43946. var tx = 0;
  43947. var ty = 0;
  43948. if (!font.vertical) {
  43949. var w0 = glyphWidth * textState.fontMatrix[0];
  43950. tx = (w0 * textState.fontSize + charSpacing) *
  43951. textState.textHScale;
  43952. width += tx;
  43953. } else {
  43954. var w1 = glyphWidth * textState.fontMatrix[0];
  43955. ty = w1 * textState.fontSize + charSpacing;
  43956. height += ty;
  43957. }
  43958. textState.translateTextMatrix(tx, ty);
  43959. textChunk.str.push(glyphUnicode);
  43960. }
  43961. if (!font.vertical) {
  43962. textChunk.lastAdvanceWidth = width;
  43963. textChunk.width += width * textChunk.textAdvanceScale;
  43964. } else {
  43965. textChunk.lastAdvanceHeight = height;
  43966. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  43967. }
  43968. return textChunk;
  43969. }
  43970. function addFakeSpaces(width, strBuf) {
  43971. if (width < textContentItem.fakeSpaceMin) {
  43972. return;
  43973. }
  43974. if (width < textContentItem.fakeMultiSpaceMin) {
  43975. strBuf.push(' ');
  43976. return;
  43977. }
  43978. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  43979. while (fakeSpaces-- > 0) {
  43980. strBuf.push(' ');
  43981. }
  43982. }
  43983. function flushTextContentItem() {
  43984. if (!textContentItem.initialized) {
  43985. return;
  43986. }
  43987. textContent.items.push(runBidiTransform(textContentItem));
  43988. textContentItem.initialized = false;
  43989. textContentItem.str.length = 0;
  43990. }
  43991. var timeSlotManager = new TimeSlotManager();
  43992. return new Promise(function promiseBody(resolve, reject) {
  43993. var next = function (promise) {
  43994. promise.then(function () {
  43995. try {
  43996. promiseBody(resolve, reject);
  43997. } catch (ex) {
  43998. reject(ex);
  43999. }
  44000. }, reject);
  44001. };
  44002. task.ensureNotTerminated();
  44003. timeSlotManager.reset();
  44004. var stop, operation = {}, args = [];
  44005. while (!(stop = timeSlotManager.check())) {
  44006. // The arguments parsed by read() are not used beyond this loop, so
  44007. // we can reuse the same array on every iteration, thus avoiding
  44008. // unnecessary allocations.
  44009. args.length = 0;
  44010. operation.args = args;
  44011. if (!(preprocessor.read(operation))) {
  44012. break;
  44013. }
  44014. textState = stateManager.state;
  44015. var fn = operation.fn;
  44016. args = operation.args;
  44017. var advance, diff;
  44018. switch (fn | 0) {
  44019. case OPS.setFont:
  44020. // Optimization to ignore multiple identical Tf commands.
  44021. var fontNameArg = args[0].name, fontSizeArg = args[1];
  44022. if (textState.font && fontNameArg === textState.fontName &&
  44023. fontSizeArg === textState.fontSize) {
  44024. break;
  44025. }
  44026. flushTextContentItem();
  44027. textState.fontName = fontNameArg;
  44028. textState.fontSize = fontSizeArg;
  44029. next(handleSetFont(fontNameArg, null));
  44030. return;
  44031. case OPS.setTextRise:
  44032. flushTextContentItem();
  44033. textState.textRise = args[0];
  44034. break;
  44035. case OPS.setHScale:
  44036. flushTextContentItem();
  44037. textState.textHScale = args[0] / 100;
  44038. break;
  44039. case OPS.setLeading:
  44040. flushTextContentItem();
  44041. textState.leading = args[0];
  44042. break;
  44043. case OPS.moveText:
  44044. // Optimization to treat same line movement as advance
  44045. var isSameTextLine = !textState.font ? false :
  44046. ((textState.font.vertical ? args[0] : args[1]) === 0);
  44047. advance = args[0] - args[1];
  44048. if (combineTextItems &&
  44049. isSameTextLine && textContentItem.initialized &&
  44050. advance > 0 &&
  44051. advance <= textContentItem.fakeMultiSpaceMax) {
  44052. textState.translateTextLineMatrix(args[0], args[1]);
  44053. textContentItem.width +=
  44054. (args[0] - textContentItem.lastAdvanceWidth);
  44055. textContentItem.height +=
  44056. (args[1] - textContentItem.lastAdvanceHeight);
  44057. diff = (args[0] - textContentItem.lastAdvanceWidth) -
  44058. (args[1] - textContentItem.lastAdvanceHeight);
  44059. addFakeSpaces(diff, textContentItem.str);
  44060. break;
  44061. }
  44062. flushTextContentItem();
  44063. textState.translateTextLineMatrix(args[0], args[1]);
  44064. textState.textMatrix = textState.textLineMatrix.slice();
  44065. break;
  44066. case OPS.setLeadingMoveText:
  44067. flushTextContentItem();
  44068. textState.leading = -args[1];
  44069. textState.translateTextLineMatrix(args[0], args[1]);
  44070. textState.textMatrix = textState.textLineMatrix.slice();
  44071. break;
  44072. case OPS.nextLine:
  44073. flushTextContentItem();
  44074. textState.carriageReturn();
  44075. break;
  44076. case OPS.setTextMatrix:
  44077. // Optimization to treat same line movement as advance.
  44078. advance = textState.calcTextLineMatrixAdvance(
  44079. args[0], args[1], args[2], args[3], args[4], args[5]);
  44080. if (combineTextItems &&
  44081. advance !== null && textContentItem.initialized &&
  44082. advance.value > 0 &&
  44083. advance.value <= textContentItem.fakeMultiSpaceMax) {
  44084. textState.translateTextLineMatrix(advance.width,
  44085. advance.height);
  44086. textContentItem.width +=
  44087. (advance.width - textContentItem.lastAdvanceWidth);
  44088. textContentItem.height +=
  44089. (advance.height - textContentItem.lastAdvanceHeight);
  44090. diff = (advance.width - textContentItem.lastAdvanceWidth) -
  44091. (advance.height - textContentItem.lastAdvanceHeight);
  44092. addFakeSpaces(diff, textContentItem.str);
  44093. break;
  44094. }
  44095. flushTextContentItem();
  44096. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  44097. args[4], args[5]);
  44098. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  44099. args[4], args[5]);
  44100. break;
  44101. case OPS.setCharSpacing:
  44102. textState.charSpacing = args[0];
  44103. break;
  44104. case OPS.setWordSpacing:
  44105. textState.wordSpacing = args[0];
  44106. break;
  44107. case OPS.beginText:
  44108. flushTextContentItem();
  44109. textState.textMatrix = IDENTITY_MATRIX.slice();
  44110. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  44111. break;
  44112. case OPS.showSpacedText:
  44113. var items = args[0];
  44114. var offset;
  44115. for (var j = 0, jj = items.length; j < jj; j++) {
  44116. if (typeof items[j] === 'string') {
  44117. buildTextContentItem(items[j]);
  44118. } else {
  44119. ensureTextContentItem();
  44120. // PDF Specification 5.3.2 states:
  44121. // The number is expressed in thousandths of a unit of text
  44122. // space.
  44123. // This amount is subtracted from the current horizontal or
  44124. // vertical coordinate, depending on the writing mode.
  44125. // In the default coordinate system, a positive adjustment
  44126. // has the effect of moving the next glyph painted either to
  44127. // the left or down by the given amount.
  44128. advance = items[j] * textState.fontSize / 1000;
  44129. var breakTextRun = false;
  44130. if (textState.font.vertical) {
  44131. offset = advance *
  44132. (textState.textHScale * textState.textMatrix[2] +
  44133. textState.textMatrix[3]);
  44134. textState.translateTextMatrix(0, advance);
  44135. breakTextRun = textContentItem.textRunBreakAllowed &&
  44136. advance > textContentItem.fakeMultiSpaceMax;
  44137. if (!breakTextRun) {
  44138. // Value needs to be added to height to paint down.
  44139. textContentItem.height += offset;
  44140. }
  44141. } else {
  44142. advance = -advance;
  44143. offset = advance * (
  44144. textState.textHScale * textState.textMatrix[0] +
  44145. textState.textMatrix[1]);
  44146. textState.translateTextMatrix(advance, 0);
  44147. breakTextRun = textContentItem.textRunBreakAllowed &&
  44148. advance > textContentItem.fakeMultiSpaceMax;
  44149. if (!breakTextRun) {
  44150. // Value needs to be subtracted from width to paint left.
  44151. textContentItem.width += offset;
  44152. }
  44153. }
  44154. if (breakTextRun) {
  44155. flushTextContentItem();
  44156. } else if (advance > 0) {
  44157. addFakeSpaces(advance, textContentItem.str);
  44158. }
  44159. }
  44160. }
  44161. break;
  44162. case OPS.showText:
  44163. buildTextContentItem(args[0]);
  44164. break;
  44165. case OPS.nextLineShowText:
  44166. flushTextContentItem();
  44167. textState.carriageReturn();
  44168. buildTextContentItem(args[0]);
  44169. break;
  44170. case OPS.nextLineSetSpacingShowText:
  44171. flushTextContentItem();
  44172. textState.wordSpacing = args[0];
  44173. textState.charSpacing = args[1];
  44174. textState.carriageReturn();
  44175. buildTextContentItem(args[2]);
  44176. break;
  44177. case OPS.paintXObject:
  44178. flushTextContentItem();
  44179. if (args[0].code) {
  44180. break;
  44181. }
  44182. if (!xobjs) {
  44183. xobjs = (resources.get('XObject') || Dict.empty);
  44184. }
  44185. var name = args[0].name;
  44186. if (xobjsCache.key === name) {
  44187. if (xobjsCache.texts) {
  44188. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  44189. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  44190. }
  44191. break;
  44192. }
  44193. var xobj = xobjs.get(name);
  44194. if (!xobj) {
  44195. break;
  44196. }
  44197. assert(isStream(xobj), 'XObject should be a stream');
  44198. var type = xobj.dict.get('Subtype');
  44199. assert(isName(type), 'XObject should have a Name subtype');
  44200. if ('Form' !== type.name) {
  44201. xobjsCache.key = name;
  44202. xobjsCache.texts = null;
  44203. break;
  44204. }
  44205. stateManager.save();
  44206. var matrix = xobj.dict.getArray('Matrix');
  44207. if (isArray(matrix) && matrix.length === 6) {
  44208. stateManager.transform(matrix);
  44209. }
  44210. next(self.getTextContent(xobj, task,
  44211. xobj.dict.get('Resources') || resources, stateManager,
  44212. normalizeWhitespace, combineTextItems).then(
  44213. function (formTextContent) {
  44214. Util.appendToArray(textContent.items, formTextContent.items);
  44215. Util.extendObj(textContent.styles, formTextContent.styles);
  44216. stateManager.restore();
  44217. xobjsCache.key = name;
  44218. xobjsCache.texts = formTextContent;
  44219. }));
  44220. return;
  44221. case OPS.setGState:
  44222. flushTextContentItem();
  44223. var dictName = args[0];
  44224. var extGState = resources.get('ExtGState');
  44225. if (!isDict(extGState) || !isName(dictName)) {
  44226. break;
  44227. }
  44228. var gState = extGState.get(dictName.name);
  44229. if (!isDict(gState)) {
  44230. break;
  44231. }
  44232. var gStateFont = gState.get('Font');
  44233. if (gStateFont) {
  44234. textState.fontName = null;
  44235. textState.fontSize = gStateFont[1];
  44236. next(handleSetFont(null, gStateFont[0]));
  44237. return;
  44238. }
  44239. break;
  44240. } // switch
  44241. } // while
  44242. if (stop) {
  44243. next(deferred);
  44244. return;
  44245. }
  44246. flushTextContentItem();
  44247. resolve(textContent);
  44248. });
  44249. },
  44250. extractDataStructures:
  44251. function PartialEvaluator_extractDataStructures(dict, baseDict,
  44252. xref, properties) {
  44253. // 9.10.2
  44254. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  44255. var toUnicodePromise = toUnicode ?
  44256. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  44257. if (properties.composite) {
  44258. // CIDSystemInfo helps to match CID to glyphs
  44259. var cidSystemInfo = dict.get('CIDSystemInfo');
  44260. if (isDict(cidSystemInfo)) {
  44261. properties.cidSystemInfo = {
  44262. registry: cidSystemInfo.get('Registry'),
  44263. ordering: cidSystemInfo.get('Ordering'),
  44264. supplement: cidSystemInfo.get('Supplement')
  44265. };
  44266. }
  44267. var cidToGidMap = dict.get('CIDToGIDMap');
  44268. if (isStream(cidToGidMap)) {
  44269. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  44270. }
  44271. }
  44272. // Based on 9.6.6 of the spec the encoding can come from multiple places
  44273. // and depends on the font type. The base encoding and differences are
  44274. // read here, but the encoding that is actually used is chosen during
  44275. // glyph mapping in the font.
  44276. // TODO: Loading the built in encoding in the font would allow the
  44277. // differences to be merged in here not require us to hold on to it.
  44278. var differences = [];
  44279. var baseEncodingName = null;
  44280. var encoding;
  44281. if (dict.has('Encoding')) {
  44282. encoding = dict.get('Encoding');
  44283. if (isDict(encoding)) {
  44284. baseEncodingName = encoding.get('BaseEncoding');
  44285. baseEncodingName = (isName(baseEncodingName) ?
  44286. baseEncodingName.name : null);
  44287. // Load the differences between the base and original
  44288. if (encoding.has('Differences')) {
  44289. var diffEncoding = encoding.get('Differences');
  44290. var index = 0;
  44291. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  44292. var data = xref.fetchIfRef(diffEncoding[j]);
  44293. if (isNum(data)) {
  44294. index = data;
  44295. } else if (isName(data)) {
  44296. differences[index++] = data.name;
  44297. } else {
  44298. error('Invalid entry in \'Differences\' array: ' + data);
  44299. }
  44300. }
  44301. }
  44302. } else if (isName(encoding)) {
  44303. baseEncodingName = encoding.name;
  44304. } else {
  44305. error('Encoding is not a Name nor a Dict');
  44306. }
  44307. // According to table 114 if the encoding is a named encoding it must be
  44308. // one of these predefined encodings.
  44309. if ((baseEncodingName !== 'MacRomanEncoding' &&
  44310. baseEncodingName !== 'MacExpertEncoding' &&
  44311. baseEncodingName !== 'WinAnsiEncoding')) {
  44312. baseEncodingName = null;
  44313. }
  44314. }
  44315. if (baseEncodingName) {
  44316. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  44317. } else {
  44318. encoding = (properties.type === 'TrueType' ?
  44319. WinAnsiEncoding : StandardEncoding);
  44320. // The Symbolic attribute can be misused for regular fonts
  44321. // Heuristic: we have to check if the font is a standard one also
  44322. if (!!(properties.flags & FontFlags.Symbolic)) {
  44323. encoding = MacRomanEncoding;
  44324. if (!properties.file) {
  44325. if (/Symbol/i.test(properties.name)) {
  44326. encoding = SymbolSetEncoding;
  44327. } else if (/Dingbats/i.test(properties.name)) {
  44328. encoding = ZapfDingbatsEncoding;
  44329. }
  44330. }
  44331. }
  44332. properties.defaultEncoding = encoding;
  44333. }
  44334. properties.differences = differences;
  44335. properties.baseEncodingName = baseEncodingName;
  44336. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  44337. properties.dict = dict;
  44338. return toUnicodePromise.then(function(toUnicode) {
  44339. properties.toUnicode = toUnicode;
  44340. return this.buildToUnicode(properties);
  44341. }.bind(this)).then(function (toUnicode) {
  44342. properties.toUnicode = toUnicode;
  44343. return properties;
  44344. });
  44345. },
  44346. /**
  44347. * Builds a char code to unicode map based on section 9.10 of the spec.
  44348. * @param {Object} properties Font properties object.
  44349. * @return {Promise} A Promise that is resolved with a
  44350. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  44351. */
  44352. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  44353. properties.hasIncludedToUnicodeMap =
  44354. !!properties.toUnicode && properties.toUnicode.length > 0;
  44355. // Section 9.10.2 Mapping Character Codes to Unicode Values
  44356. if (properties.hasIncludedToUnicodeMap) {
  44357. return Promise.resolve(properties.toUnicode);
  44358. }
  44359. // According to the spec if the font is a simple font we should only map
  44360. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  44361. // the differences array only contains adobe standard or symbol set names,
  44362. // in pratice it seems better to always try to create a toUnicode
  44363. // map based of the default encoding.
  44364. var toUnicode, charcode, glyphName;
  44365. if (!properties.composite /* is simple font */) {
  44366. toUnicode = [];
  44367. var encoding = properties.defaultEncoding.slice();
  44368. var baseEncodingName = properties.baseEncodingName;
  44369. // Merge in the differences array.
  44370. var differences = properties.differences;
  44371. for (charcode in differences) {
  44372. glyphName = differences[charcode];
  44373. if (glyphName === '.notdef') {
  44374. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  44375. // where there should be spaces (fixes issue5256.pdf).
  44376. continue;
  44377. }
  44378. encoding[charcode] = glyphName;
  44379. }
  44380. var glyphsUnicodeMap = getGlyphsUnicode();
  44381. for (charcode in encoding) {
  44382. // a) Map the character code to a character name.
  44383. glyphName = encoding[charcode];
  44384. // b) Look up the character name in the Adobe Glyph List (see the
  44385. // Bibliography) to obtain the corresponding Unicode value.
  44386. if (glyphName === '') {
  44387. continue;
  44388. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  44389. // (undocumented) c) Few heuristics to recognize unknown glyphs
  44390. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  44391. var code = 0;
  44392. switch (glyphName[0]) {
  44393. case 'G': // Gxx glyph
  44394. if (glyphName.length === 3) {
  44395. code = parseInt(glyphName.substr(1), 16);
  44396. }
  44397. break;
  44398. case 'g': // g00xx glyph
  44399. if (glyphName.length === 5) {
  44400. code = parseInt(glyphName.substr(1), 16);
  44401. }
  44402. break;
  44403. case 'C': // Cddd glyph
  44404. case 'c': // cddd glyph
  44405. if (glyphName.length >= 3) {
  44406. code = +glyphName.substr(1);
  44407. }
  44408. break;
  44409. default:
  44410. // 'uniXXXX'/'uXXXX{XX}' glyphs
  44411. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  44412. if (unicode !== -1) {
  44413. code = unicode;
  44414. }
  44415. }
  44416. if (code) {
  44417. // If |baseEncodingName| is one the predefined encodings,
  44418. // and |code| equals |charcode|, using the glyph defined in the
  44419. // baseEncoding seems to yield a better |toUnicode| mapping
  44420. // (fixes issue 5070).
  44421. if (baseEncodingName && code === +charcode) {
  44422. var baseEncoding = getEncoding(baseEncodingName);
  44423. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  44424. toUnicode[charcode] =
  44425. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  44426. continue;
  44427. }
  44428. }
  44429. toUnicode[charcode] = String.fromCharCode(code);
  44430. }
  44431. continue;
  44432. }
  44433. toUnicode[charcode] =
  44434. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  44435. }
  44436. return Promise.resolve(new ToUnicodeMap(toUnicode));
  44437. }
  44438. // If the font is a composite font that uses one of the predefined CMaps
  44439. // listed in Table 118 (except Identity–H and Identity–V) or whose
  44440. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  44441. // Adobe-Korea1 character collection:
  44442. if (properties.composite && (
  44443. (properties.cMap.builtInCMap &&
  44444. !(properties.cMap instanceof IdentityCMap)) ||
  44445. (properties.cidSystemInfo.registry === 'Adobe' &&
  44446. (properties.cidSystemInfo.ordering === 'GB1' ||
  44447. properties.cidSystemInfo.ordering === 'CNS1' ||
  44448. properties.cidSystemInfo.ordering === 'Japan1' ||
  44449. properties.cidSystemInfo.ordering === 'Korea1')))) {
  44450. // Then:
  44451. // a) Map the character code to a character identifier (CID) according
  44452. // to the font’s CMap.
  44453. // b) Obtain the registry and ordering of the character collection used
  44454. // by the font’s CMap (for example, Adobe and Japan1) from its
  44455. // CIDSystemInfo dictionary.
  44456. var registry = properties.cidSystemInfo.registry;
  44457. var ordering = properties.cidSystemInfo.ordering;
  44458. // c) Construct a second CMap name by concatenating the registry and
  44459. // ordering obtained in step (b) in the format registry–ordering–UCS2
  44460. // (for example, Adobe–Japan1–UCS2).
  44461. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  44462. // d) Obtain the CMap with the name constructed in step (c) (available
  44463. // from the ASN Web site; see the Bibliography).
  44464. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  44465. null).then(
  44466. function (ucs2CMap) {
  44467. var cMap = properties.cMap;
  44468. toUnicode = [];
  44469. cMap.forEach(function(charcode, cid) {
  44470. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  44471. // e) Map the CID obtained in step (a) according to the CMap
  44472. // obtained in step (d), producing a Unicode value.
  44473. var ucs2 = ucs2CMap.lookup(cid);
  44474. if (ucs2) {
  44475. toUnicode[charcode] =
  44476. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  44477. ucs2.charCodeAt(1));
  44478. }
  44479. });
  44480. return new ToUnicodeMap(toUnicode);
  44481. });
  44482. }
  44483. // The viewer's choice, just use an identity map.
  44484. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  44485. properties.lastChar));
  44486. },
  44487. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  44488. var cmapObj = toUnicode;
  44489. if (isName(cmapObj)) {
  44490. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  44491. function (cmap) {
  44492. if (cmap instanceof IdentityCMap) {
  44493. return new IdentityToUnicodeMap(0, 0xFFFF);
  44494. }
  44495. return new ToUnicodeMap(cmap.getMap());
  44496. });
  44497. } else if (isStream(cmapObj)) {
  44498. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  44499. function (cmap) {
  44500. if (cmap instanceof IdentityCMap) {
  44501. return new IdentityToUnicodeMap(0, 0xFFFF);
  44502. }
  44503. var map = new Array(cmap.length);
  44504. // Convert UTF-16BE
  44505. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  44506. // to iterate over all keys.
  44507. cmap.forEach(function(charCode, token) {
  44508. var str = [];
  44509. for (var k = 0; k < token.length; k += 2) {
  44510. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  44511. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  44512. str.push(w1);
  44513. continue;
  44514. }
  44515. k += 2;
  44516. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  44517. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  44518. }
  44519. map[charCode] = String.fromCharCode.apply(String, str);
  44520. });
  44521. return new ToUnicodeMap(map);
  44522. });
  44523. }
  44524. return Promise.resolve(null);
  44525. },
  44526. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  44527. // Extract the encoding from the CIDToGIDMap
  44528. var glyphsData = cidToGidStream.getBytes();
  44529. // Set encoding 0 to later verify the font has an encoding
  44530. var result = [];
  44531. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  44532. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  44533. if (glyphID === 0) {
  44534. continue;
  44535. }
  44536. var code = j >> 1;
  44537. result[code] = glyphID;
  44538. }
  44539. return result;
  44540. },
  44541. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  44542. descriptor,
  44543. properties) {
  44544. var glyphsWidths = [];
  44545. var defaultWidth = 0;
  44546. var glyphsVMetrics = [];
  44547. var defaultVMetrics;
  44548. var i, ii, j, jj, start, code, widths;
  44549. if (properties.composite) {
  44550. defaultWidth = dict.get('DW') || 1000;
  44551. widths = dict.get('W');
  44552. if (widths) {
  44553. for (i = 0, ii = widths.length; i < ii; i++) {
  44554. start = widths[i++];
  44555. code = xref.fetchIfRef(widths[i]);
  44556. if (isArray(code)) {
  44557. for (j = 0, jj = code.length; j < jj; j++) {
  44558. glyphsWidths[start++] = code[j];
  44559. }
  44560. } else {
  44561. var width = widths[++i];
  44562. for (j = start; j <= code; j++) {
  44563. glyphsWidths[j] = width;
  44564. }
  44565. }
  44566. }
  44567. }
  44568. if (properties.vertical) {
  44569. var vmetrics = (dict.get('DW2') || [880, -1000]);
  44570. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  44571. vmetrics = dict.get('W2');
  44572. if (vmetrics) {
  44573. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  44574. start = vmetrics[i++];
  44575. code = xref.fetchIfRef(vmetrics[i]);
  44576. if (isArray(code)) {
  44577. for (j = 0, jj = code.length; j < jj; j++) {
  44578. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  44579. }
  44580. } else {
  44581. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  44582. for (j = start; j <= code; j++) {
  44583. glyphsVMetrics[j] = vmetric;
  44584. }
  44585. }
  44586. }
  44587. }
  44588. }
  44589. } else {
  44590. var firstChar = properties.firstChar;
  44591. widths = dict.get('Widths');
  44592. if (widths) {
  44593. j = firstChar;
  44594. for (i = 0, ii = widths.length; i < ii; i++) {
  44595. glyphsWidths[j++] = widths[i];
  44596. }
  44597. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  44598. } else {
  44599. // Trying get the BaseFont metrics (see comment above).
  44600. var baseFontName = dict.get('BaseFont');
  44601. if (isName(baseFontName)) {
  44602. var metrics = this.getBaseFontMetrics(baseFontName.name);
  44603. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  44604. properties);
  44605. defaultWidth = metrics.defaultWidth;
  44606. }
  44607. }
  44608. }
  44609. // Heuristic: detection of monospace font by checking all non-zero widths
  44610. var isMonospace = true;
  44611. var firstWidth = defaultWidth;
  44612. for (var glyph in glyphsWidths) {
  44613. var glyphWidth = glyphsWidths[glyph];
  44614. if (!glyphWidth) {
  44615. continue;
  44616. }
  44617. if (!firstWidth) {
  44618. firstWidth = glyphWidth;
  44619. continue;
  44620. }
  44621. if (firstWidth !== glyphWidth) {
  44622. isMonospace = false;
  44623. break;
  44624. }
  44625. }
  44626. if (isMonospace) {
  44627. properties.flags |= FontFlags.FixedPitch;
  44628. }
  44629. properties.defaultWidth = defaultWidth;
  44630. properties.widths = glyphsWidths;
  44631. properties.defaultVMetrics = defaultVMetrics;
  44632. properties.vmetrics = glyphsVMetrics;
  44633. },
  44634. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  44635. // Simulating descriptor flags attribute
  44636. var fontNameWoStyle = baseFontName.split('-')[0];
  44637. return (fontNameWoStyle in getSerifFonts()) ||
  44638. (fontNameWoStyle.search(/serif/gi) !== -1);
  44639. },
  44640. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  44641. var defaultWidth = 0;
  44642. var widths = [];
  44643. var monospace = false;
  44644. var stdFontMap = getStdFontMap();
  44645. var lookupName = (stdFontMap[name] || name);
  44646. var Metrics = getMetrics();
  44647. if (!(lookupName in Metrics)) {
  44648. // Use default fonts for looking up font metrics if the passed
  44649. // font is not a base font
  44650. if (this.isSerifFont(name)) {
  44651. lookupName = 'Times-Roman';
  44652. } else {
  44653. lookupName = 'Helvetica';
  44654. }
  44655. }
  44656. var glyphWidths = Metrics[lookupName];
  44657. if (isNum(glyphWidths)) {
  44658. defaultWidth = glyphWidths;
  44659. monospace = true;
  44660. } else {
  44661. widths = glyphWidths(); // expand lazy widths array
  44662. }
  44663. return {
  44664. defaultWidth: defaultWidth,
  44665. monospace: monospace,
  44666. widths: widths
  44667. };
  44668. },
  44669. buildCharCodeToWidth:
  44670. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  44671. properties) {
  44672. var widths = Object.create(null);
  44673. var differences = properties.differences;
  44674. var encoding = properties.defaultEncoding;
  44675. for (var charCode = 0; charCode < 256; charCode++) {
  44676. if (charCode in differences &&
  44677. widthsByGlyphName[differences[charCode]]) {
  44678. widths[charCode] = widthsByGlyphName[differences[charCode]];
  44679. continue;
  44680. }
  44681. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  44682. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  44683. continue;
  44684. }
  44685. }
  44686. return widths;
  44687. },
  44688. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  44689. var baseDict = dict;
  44690. var type = dict.get('Subtype');
  44691. assert(isName(type), 'invalid font Subtype');
  44692. var composite = false;
  44693. var uint8array;
  44694. if (type.name === 'Type0') {
  44695. // If font is a composite
  44696. // - get the descendant font
  44697. // - set the type according to the descendant font
  44698. // - get the FontDescriptor from the descendant font
  44699. var df = dict.get('DescendantFonts');
  44700. if (!df) {
  44701. error('Descendant fonts are not specified');
  44702. }
  44703. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  44704. type = dict.get('Subtype');
  44705. assert(isName(type), 'invalid font Subtype');
  44706. composite = true;
  44707. }
  44708. var descriptor = dict.get('FontDescriptor');
  44709. if (descriptor) {
  44710. var hash = new MurmurHash3_64();
  44711. var encoding = baseDict.getRaw('Encoding');
  44712. if (isName(encoding)) {
  44713. hash.update(encoding.name);
  44714. } else if (isRef(encoding)) {
  44715. hash.update(encoding.toString());
  44716. } else if (isDict(encoding)) {
  44717. var keys = encoding.getKeys();
  44718. for (var i = 0, ii = keys.length; i < ii; i++) {
  44719. var entry = encoding.getRaw(keys[i]);
  44720. if (isName(entry)) {
  44721. hash.update(entry.name);
  44722. } else if (isRef(entry)) {
  44723. hash.update(entry.toString());
  44724. } else if (isArray(entry)) { // 'Differences' entry.
  44725. // Ideally we should check the contents of the array, but to avoid
  44726. // parsing it here and then again in |extractDataStructures|,
  44727. // we only use the array length for now (fixes bug1157493.pdf).
  44728. hash.update(entry.length.toString());
  44729. }
  44730. }
  44731. }
  44732. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  44733. if (isStream(toUnicode)) {
  44734. var stream = toUnicode.str || toUnicode;
  44735. uint8array = stream.buffer ?
  44736. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  44737. new Uint8Array(stream.bytes.buffer,
  44738. stream.start, stream.end - stream.start);
  44739. hash.update(uint8array);
  44740. } else if (isName(toUnicode)) {
  44741. hash.update(toUnicode.name);
  44742. }
  44743. var widths = dict.get('Widths') || baseDict.get('Widths');
  44744. if (widths) {
  44745. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  44746. hash.update(uint8array);
  44747. }
  44748. }
  44749. return {
  44750. descriptor: descriptor,
  44751. dict: dict,
  44752. baseDict: baseDict,
  44753. composite: composite,
  44754. type: type.name,
  44755. hash: hash ? hash.hexdigest() : ''
  44756. };
  44757. },
  44758. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  44759. xref) {
  44760. var baseDict = preEvaluatedFont.baseDict;
  44761. var dict = preEvaluatedFont.dict;
  44762. var composite = preEvaluatedFont.composite;
  44763. var descriptor = preEvaluatedFont.descriptor;
  44764. var type = preEvaluatedFont.type;
  44765. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  44766. var cMapOptions = this.options.cMapOptions;
  44767. var properties;
  44768. if (!descriptor) {
  44769. if (type === 'Type3') {
  44770. // FontDescriptor is only required for Type3 fonts when the document
  44771. // is a tagged pdf. Create a barbebones one to get by.
  44772. descriptor = new Dict(null);
  44773. descriptor.set('FontName', Name.get(type));
  44774. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  44775. } else {
  44776. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  44777. // FontDescriptor was not required.
  44778. // This case is here for compatibility.
  44779. var baseFontName = dict.get('BaseFont');
  44780. if (!isName(baseFontName)) {
  44781. error('Base font is not specified');
  44782. }
  44783. // Using base font name as a font name.
  44784. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  44785. var metrics = this.getBaseFontMetrics(baseFontName);
  44786. // Simulating descriptor flags attribute
  44787. var fontNameWoStyle = baseFontName.split('-')[0];
  44788. var flags =
  44789. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  44790. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  44791. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  44792. FontFlags.Nonsymbolic);
  44793. properties = {
  44794. type: type,
  44795. name: baseFontName,
  44796. widths: metrics.widths,
  44797. defaultWidth: metrics.defaultWidth,
  44798. flags: flags,
  44799. firstChar: 0,
  44800. lastChar: maxCharIndex
  44801. };
  44802. return this.extractDataStructures(dict, dict, xref, properties).then(
  44803. function (properties) {
  44804. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  44805. properties);
  44806. return new Font(baseFontName, null, properties);
  44807. }.bind(this));
  44808. }
  44809. }
  44810. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  44811. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  44812. // to ignore this rule when a variant of a standard font is used.
  44813. // TODO Fill the width array depending on which of the base font this is
  44814. // a variant.
  44815. var firstChar = (dict.get('FirstChar') || 0);
  44816. var lastChar = (dict.get('LastChar') || maxCharIndex);
  44817. var fontName = descriptor.get('FontName');
  44818. var baseFont = dict.get('BaseFont');
  44819. // Some bad PDFs have a string as the font name.
  44820. if (isString(fontName)) {
  44821. fontName = Name.get(fontName);
  44822. }
  44823. if (isString(baseFont)) {
  44824. baseFont = Name.get(baseFont);
  44825. }
  44826. if (type !== 'Type3') {
  44827. var fontNameStr = fontName && fontName.name;
  44828. var baseFontStr = baseFont && baseFont.name;
  44829. if (fontNameStr !== baseFontStr) {
  44830. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  44831. '" but should be the same as the Font\'s BaseFont "' +
  44832. baseFontStr + '"');
  44833. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  44834. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  44835. if (fontNameStr && baseFontStr &&
  44836. baseFontStr.indexOf(fontNameStr) === 0) {
  44837. fontName = baseFont;
  44838. }
  44839. }
  44840. }
  44841. fontName = (fontName || baseFont);
  44842. assert(isName(fontName), 'invalid font name');
  44843. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  44844. if (fontFile) {
  44845. if (fontFile.dict) {
  44846. var subtype = fontFile.dict.get('Subtype');
  44847. if (subtype) {
  44848. subtype = subtype.name;
  44849. }
  44850. var length1 = fontFile.dict.get('Length1');
  44851. var length2 = fontFile.dict.get('Length2');
  44852. var length3 = fontFile.dict.get('Length3');
  44853. }
  44854. }
  44855. properties = {
  44856. type: type,
  44857. name: fontName.name,
  44858. subtype: subtype,
  44859. file: fontFile,
  44860. length1: length1,
  44861. length2: length2,
  44862. length3: length3,
  44863. loadedName: baseDict.loadedName,
  44864. composite: composite,
  44865. wideChars: composite,
  44866. fixedPitch: false,
  44867. fontMatrix: (dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX),
  44868. firstChar: firstChar || 0,
  44869. lastChar: (lastChar || maxCharIndex),
  44870. bbox: descriptor.getArray('FontBBox'),
  44871. ascent: descriptor.get('Ascent'),
  44872. descent: descriptor.get('Descent'),
  44873. xHeight: descriptor.get('XHeight'),
  44874. capHeight: descriptor.get('CapHeight'),
  44875. flags: descriptor.get('Flags'),
  44876. italicAngle: descriptor.get('ItalicAngle'),
  44877. coded: false
  44878. };
  44879. var cMapPromise;
  44880. if (composite) {
  44881. var cidEncoding = baseDict.get('Encoding');
  44882. if (isName(cidEncoding)) {
  44883. properties.cidEncoding = cidEncoding.name;
  44884. }
  44885. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  44886. function (cMap) {
  44887. properties.cMap = cMap;
  44888. properties.vertical = properties.cMap.vertical;
  44889. });
  44890. } else {
  44891. cMapPromise = Promise.resolve(undefined);
  44892. }
  44893. return cMapPromise.then(function () {
  44894. return this.extractDataStructures(dict, baseDict, xref, properties);
  44895. }.bind(this)).then(function (properties) {
  44896. this.extractWidths(dict, xref, descriptor, properties);
  44897. if (type === 'Type3') {
  44898. properties.isType3Font = true;
  44899. }
  44900. return new Font(fontName.name, fontFile, properties);
  44901. }.bind(this));
  44902. }
  44903. };
  44904. return PartialEvaluator;
  44905. })();
  44906. var TranslatedFont = (function TranslatedFontClosure() {
  44907. function TranslatedFont(loadedName, font, dict) {
  44908. this.loadedName = loadedName;
  44909. this.font = font;
  44910. this.dict = dict;
  44911. this.type3Loaded = null;
  44912. this.sent = false;
  44913. }
  44914. TranslatedFont.prototype = {
  44915. send: function (handler) {
  44916. if (this.sent) {
  44917. return;
  44918. }
  44919. var fontData = this.font.exportData();
  44920. handler.send('commonobj', [
  44921. this.loadedName,
  44922. 'Font',
  44923. fontData
  44924. ]);
  44925. this.sent = true;
  44926. },
  44927. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  44928. assert(this.font.isType3Font);
  44929. if (this.type3Loaded) {
  44930. return this.type3Loaded;
  44931. }
  44932. var translatedFont = this.font;
  44933. var loadCharProcsPromise = Promise.resolve();
  44934. var charProcs = this.dict.get('CharProcs');
  44935. var fontResources = this.dict.get('Resources') || resources;
  44936. var charProcKeys = charProcs.getKeys();
  44937. var charProcOperatorList = Object.create(null);
  44938. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  44939. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  44940. var glyphStream = charProcs.get(key);
  44941. var operatorList = new OperatorList();
  44942. return evaluator.getOperatorList(glyphStream, task, fontResources,
  44943. operatorList).then(function () {
  44944. charProcOperatorList[key] = operatorList.getIR();
  44945. // Add the dependencies to the parent operator list so they are
  44946. // resolved before sub operator list is executed synchronously.
  44947. parentOperatorList.addDependencies(operatorList.dependencies);
  44948. }, function (reason) {
  44949. warn('Type3 font resource \"' + key + '\" is not available');
  44950. var operatorList = new OperatorList();
  44951. charProcOperatorList[key] = operatorList.getIR();
  44952. });
  44953. }.bind(this, charProcKeys[i]));
  44954. }
  44955. this.type3Loaded = loadCharProcsPromise.then(function () {
  44956. translatedFont.charProcOperatorList = charProcOperatorList;
  44957. });
  44958. return this.type3Loaded;
  44959. }
  44960. };
  44961. return TranslatedFont;
  44962. })();
  44963. var OperatorList = (function OperatorListClosure() {
  44964. var CHUNK_SIZE = 1000;
  44965. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  44966. function getTransfers(queue) {
  44967. var transfers = [];
  44968. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44969. for (var i = 0, ii = queue.length; i < ii; i++) {
  44970. switch (fnArray[i]) {
  44971. case OPS.paintInlineImageXObject:
  44972. case OPS.paintInlineImageXObjectGroup:
  44973. case OPS.paintImageMaskXObject:
  44974. var arg = argsArray[i][0]; // first param in imgData
  44975. if (!arg.cached) {
  44976. transfers.push(arg.data.buffer);
  44977. }
  44978. break;
  44979. }
  44980. }
  44981. return transfers;
  44982. }
  44983. function OperatorList(intent, messageHandler, pageIndex) {
  44984. this.messageHandler = messageHandler;
  44985. this.fnArray = [];
  44986. this.argsArray = [];
  44987. this.dependencies = Object.create(null);
  44988. this._totalLength = 0;
  44989. this.pageIndex = pageIndex;
  44990. this.intent = intent;
  44991. }
  44992. OperatorList.prototype = {
  44993. get length() {
  44994. return this.argsArray.length;
  44995. },
  44996. /**
  44997. * @returns {number} The total length of the entire operator list,
  44998. * since `this.length === 0` after flushing.
  44999. */
  45000. get totalLength() {
  45001. return (this._totalLength + this.length);
  45002. },
  45003. addOp: function(fn, args) {
  45004. this.fnArray.push(fn);
  45005. this.argsArray.push(args);
  45006. if (this.messageHandler) {
  45007. if (this.fnArray.length >= CHUNK_SIZE) {
  45008. this.flush();
  45009. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  45010. (fn === OPS.restore || fn === OPS.endText)) {
  45011. // heuristic to flush on boundary of restore or endText
  45012. this.flush();
  45013. }
  45014. }
  45015. },
  45016. addDependency: function(dependency) {
  45017. if (dependency in this.dependencies) {
  45018. return;
  45019. }
  45020. this.dependencies[dependency] = true;
  45021. this.addOp(OPS.dependency, [dependency]);
  45022. },
  45023. addDependencies: function(dependencies) {
  45024. for (var key in dependencies) {
  45025. this.addDependency(key);
  45026. }
  45027. },
  45028. addOpList: function(opList) {
  45029. Util.extendObj(this.dependencies, opList.dependencies);
  45030. for (var i = 0, ii = opList.length; i < ii; i++) {
  45031. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  45032. }
  45033. },
  45034. getIR: function() {
  45035. return {
  45036. fnArray: this.fnArray,
  45037. argsArray: this.argsArray,
  45038. length: this.length
  45039. };
  45040. },
  45041. flush: function(lastChunk) {
  45042. if (this.intent !== 'oplist') {
  45043. new QueueOptimizer().optimize(this);
  45044. }
  45045. var transfers = getTransfers(this);
  45046. var length = this.length;
  45047. this._totalLength += length;
  45048. this.messageHandler.send('RenderPageChunk', {
  45049. operatorList: {
  45050. fnArray: this.fnArray,
  45051. argsArray: this.argsArray,
  45052. lastChunk: lastChunk,
  45053. length: length
  45054. },
  45055. pageIndex: this.pageIndex,
  45056. intent: this.intent
  45057. }, transfers);
  45058. this.dependencies = Object.create(null);
  45059. this.fnArray.length = 0;
  45060. this.argsArray.length = 0;
  45061. }
  45062. };
  45063. return OperatorList;
  45064. })();
  45065. var StateManager = (function StateManagerClosure() {
  45066. function StateManager(initialState) {
  45067. this.state = initialState;
  45068. this.stateStack = [];
  45069. }
  45070. StateManager.prototype = {
  45071. save: function () {
  45072. var old = this.state;
  45073. this.stateStack.push(this.state);
  45074. this.state = old.clone();
  45075. },
  45076. restore: function () {
  45077. var prev = this.stateStack.pop();
  45078. if (prev) {
  45079. this.state = prev;
  45080. }
  45081. },
  45082. transform: function (args) {
  45083. this.state.ctm = Util.transform(this.state.ctm, args);
  45084. }
  45085. };
  45086. return StateManager;
  45087. })();
  45088. var TextState = (function TextStateClosure() {
  45089. function TextState() {
  45090. this.ctm = new Float32Array(IDENTITY_MATRIX);
  45091. this.fontName = null;
  45092. this.fontSize = 0;
  45093. this.font = null;
  45094. this.fontMatrix = FONT_IDENTITY_MATRIX;
  45095. this.textMatrix = IDENTITY_MATRIX.slice();
  45096. this.textLineMatrix = IDENTITY_MATRIX.slice();
  45097. this.charSpacing = 0;
  45098. this.wordSpacing = 0;
  45099. this.leading = 0;
  45100. this.textHScale = 1;
  45101. this.textRise = 0;
  45102. }
  45103. TextState.prototype = {
  45104. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  45105. var m = this.textMatrix;
  45106. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  45107. },
  45108. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  45109. var m = this.textLineMatrix;
  45110. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  45111. },
  45112. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  45113. var m = this.textMatrix;
  45114. m[4] = m[0] * x + m[2] * y + m[4];
  45115. m[5] = m[1] * x + m[3] * y + m[5];
  45116. },
  45117. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  45118. var m = this.textLineMatrix;
  45119. m[4] = m[0] * x + m[2] * y + m[4];
  45120. m[5] = m[1] * x + m[3] * y + m[5];
  45121. },
  45122. calcTextLineMatrixAdvance:
  45123. function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  45124. var font = this.font;
  45125. if (!font) {
  45126. return null;
  45127. }
  45128. var m = this.textLineMatrix;
  45129. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  45130. return null;
  45131. }
  45132. var txDiff = e - m[4], tyDiff = f - m[5];
  45133. if ((font.vertical && txDiff !== 0) || (!font.vertical && tyDiff !== 0)) {
  45134. return null;
  45135. }
  45136. var tx, ty, denominator = a * d - b * c;
  45137. if (font.vertical) {
  45138. tx = -tyDiff * c / denominator;
  45139. ty = tyDiff * a / denominator;
  45140. } else {
  45141. tx = txDiff * d / denominator;
  45142. ty = -txDiff * b / denominator;
  45143. }
  45144. return { width: tx, height: ty, value: (font.vertical ? ty : tx), };
  45145. },
  45146. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  45147. // 9.4.4 Text Space Details
  45148. var tsm = [this.fontSize * this.textHScale, 0,
  45149. 0, this.fontSize,
  45150. 0, this.textRise];
  45151. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  45152. },
  45153. carriageReturn: function TextState_carriageReturn() {
  45154. this.translateTextLineMatrix(0, -this.leading);
  45155. this.textMatrix = this.textLineMatrix.slice();
  45156. },
  45157. clone: function TextState_clone() {
  45158. var clone = Object.create(this);
  45159. clone.textMatrix = this.textMatrix.slice();
  45160. clone.textLineMatrix = this.textLineMatrix.slice();
  45161. clone.fontMatrix = this.fontMatrix.slice();
  45162. return clone;
  45163. }
  45164. };
  45165. return TextState;
  45166. })();
  45167. var EvalState = (function EvalStateClosure() {
  45168. function EvalState() {
  45169. this.ctm = new Float32Array(IDENTITY_MATRIX);
  45170. this.font = null;
  45171. this.textRenderingMode = TextRenderingMode.FILL;
  45172. this.fillColorSpace = ColorSpace.singletons.gray;
  45173. this.strokeColorSpace = ColorSpace.singletons.gray;
  45174. }
  45175. EvalState.prototype = {
  45176. clone: function CanvasExtraState_clone() {
  45177. return Object.create(this);
  45178. },
  45179. };
  45180. return EvalState;
  45181. })();
  45182. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  45183. // Specifies properties for each command
  45184. //
  45185. // If variableArgs === true: [0, `numArgs`] expected
  45186. // If variableArgs === false: exactly `numArgs` expected
  45187. var getOPMap = getLookupTableFactory(function (t) {
  45188. // Graphic state
  45189. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  45190. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  45191. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  45192. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  45193. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  45194. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  45195. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  45196. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  45197. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  45198. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  45199. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  45200. // Path
  45201. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  45202. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  45203. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  45204. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  45205. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  45206. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  45207. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  45208. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  45209. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  45210. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  45211. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  45212. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  45213. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  45214. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  45215. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  45216. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  45217. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  45218. // Clipping
  45219. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  45220. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  45221. // Text
  45222. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  45223. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  45224. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  45225. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  45226. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  45227. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  45228. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  45229. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  45230. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  45231. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  45232. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  45233. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  45234. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  45235. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  45236. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  45237. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  45238. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  45239. variableArgs: false };
  45240. // Type3 fonts
  45241. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  45242. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  45243. variableArgs: false };
  45244. // Color
  45245. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  45246. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  45247. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  45248. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  45249. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  45250. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  45251. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  45252. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  45253. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  45254. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  45255. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  45256. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  45257. // Shading
  45258. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  45259. // Images
  45260. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  45261. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  45262. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  45263. // XObjects
  45264. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  45265. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  45266. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  45267. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  45268. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  45269. variableArgs: false };
  45270. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  45271. // Compatibility
  45272. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  45273. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  45274. // (reserved partial commands for the lexer)
  45275. t['BM'] = null;
  45276. t['BD'] = null;
  45277. t['true'] = null;
  45278. t['fa'] = null;
  45279. t['fal'] = null;
  45280. t['fals'] = null;
  45281. t['false'] = null;
  45282. t['nu'] = null;
  45283. t['nul'] = null;
  45284. t['null'] = null;
  45285. });
  45286. function EvaluatorPreprocessor(stream, xref, stateManager) {
  45287. this.opMap = getOPMap();
  45288. // TODO(mduan): pass array of knownCommands rather than this.opMap
  45289. // dictionary
  45290. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  45291. this.stateManager = stateManager;
  45292. this.nonProcessedArgs = [];
  45293. }
  45294. EvaluatorPreprocessor.prototype = {
  45295. get savedStatesDepth() {
  45296. return this.stateManager.stateStack.length;
  45297. },
  45298. // |operation| is an object with two fields:
  45299. //
  45300. // - |fn| is an out param.
  45301. //
  45302. // - |args| is an inout param. On entry, it should have one of two values.
  45303. //
  45304. // - An empty array. This indicates that the caller is providing the
  45305. // array in which the args will be stored in. The caller should use
  45306. // this value if it can reuse a single array for each call to read().
  45307. //
  45308. // - |null|. This indicates that the caller needs this function to create
  45309. // the array in which any args are stored in. If there are zero args,
  45310. // this function will leave |operation.args| as |null| (thus avoiding
  45311. // allocations that would occur if we used an empty array to represent
  45312. // zero arguments). Otherwise, it will replace |null| with a new array
  45313. // containing the arguments. The caller should use this value if it
  45314. // cannot reuse an array for each call to read().
  45315. //
  45316. // These two modes are present because this function is very hot and so
  45317. // avoiding allocations where possible is worthwhile.
  45318. //
  45319. read: function EvaluatorPreprocessor_read(operation) {
  45320. var args = operation.args;
  45321. while (true) {
  45322. var obj = this.parser.getObj();
  45323. if (isCmd(obj)) {
  45324. var cmd = obj.cmd;
  45325. // Check that the command is valid
  45326. var opSpec = this.opMap[cmd];
  45327. if (!opSpec) {
  45328. warn('Unknown command "' + cmd + '"');
  45329. continue;
  45330. }
  45331. var fn = opSpec.id;
  45332. var numArgs = opSpec.numArgs;
  45333. var argsLength = args !== null ? args.length : 0;
  45334. if (!opSpec.variableArgs) {
  45335. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  45336. if (argsLength !== numArgs) {
  45337. var nonProcessedArgs = this.nonProcessedArgs;
  45338. while (argsLength > numArgs) {
  45339. nonProcessedArgs.push(args.shift());
  45340. argsLength--;
  45341. }
  45342. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  45343. if (!args) {
  45344. args = [];
  45345. }
  45346. args.unshift(nonProcessedArgs.pop());
  45347. argsLength++;
  45348. }
  45349. }
  45350. if (argsLength < numArgs) {
  45351. // If we receive too few args, it's not possible to possible
  45352. // to execute the command, so skip the command
  45353. info('Command ' + fn + ': because expected ' +
  45354. numArgs + ' args, but received ' + argsLength +
  45355. ' args; skipping');
  45356. args = null;
  45357. continue;
  45358. }
  45359. } else if (argsLength > numArgs) {
  45360. info('Command ' + fn + ': expected [0,' + numArgs +
  45361. '] args, but received ' + argsLength + ' args');
  45362. }
  45363. // TODO figure out how to type-check vararg functions
  45364. this.preprocessCommand(fn, args);
  45365. operation.fn = fn;
  45366. operation.args = args;
  45367. return true;
  45368. } else {
  45369. if (isEOF(obj)) {
  45370. return false; // no more commands
  45371. }
  45372. // argument
  45373. if (obj !== null) {
  45374. if (!args) {
  45375. args = [];
  45376. }
  45377. args.push(obj);
  45378. assert(args.length <= 33, 'Too many arguments');
  45379. }
  45380. }
  45381. }
  45382. },
  45383. preprocessCommand:
  45384. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  45385. switch (fn | 0) {
  45386. case OPS.save:
  45387. this.stateManager.save();
  45388. break;
  45389. case OPS.restore:
  45390. this.stateManager.restore();
  45391. break;
  45392. case OPS.transform:
  45393. this.stateManager.transform(args);
  45394. break;
  45395. }
  45396. }
  45397. };
  45398. return EvaluatorPreprocessor;
  45399. })();
  45400. var QueueOptimizer = (function QueueOptimizerClosure() {
  45401. function addState(parentState, pattern, fn) {
  45402. var state = parentState;
  45403. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  45404. var item = pattern[i];
  45405. state = (state[item] || (state[item] = []));
  45406. }
  45407. state[pattern[pattern.length - 1]] = fn;
  45408. }
  45409. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  45410. argsArray) {
  45411. // Handles special case of mainly LaTeX documents which use image masks to
  45412. // draw lines with the current fill style.
  45413. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  45414. // have been found at iFirstSave.
  45415. var iFirstPIMXO = iFirstSave + 2;
  45416. for (var i = 0; i < count; i++) {
  45417. var arg = argsArray[iFirstPIMXO + 4 * i];
  45418. var imageMask = arg.length === 1 && arg[0];
  45419. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  45420. (!imageMask.data.length ||
  45421. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  45422. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  45423. continue;
  45424. }
  45425. break;
  45426. }
  45427. return count - i;
  45428. }
  45429. var InitialState = [];
  45430. // This replaces (save, transform, paintInlineImageXObject, restore)+
  45431. // sequences with one |paintInlineImageXObjectGroup| operation.
  45432. addState(InitialState,
  45433. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  45434. function foundInlineImageGroup(context) {
  45435. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  45436. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  45437. var MAX_WIDTH = 1000;
  45438. var IMAGE_PADDING = 1;
  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 iFirstPIIXO = 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.paintInlineImageXObject ||
  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 = Math.min((i - iFirstSave) / 4,
  45459. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  45460. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  45461. return i;
  45462. }
  45463. // assuming that heights of those image is too small (~1 pixel)
  45464. // packing as much as possible by lines
  45465. var maxX = 0;
  45466. var map = [], maxLineHeight = 0;
  45467. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  45468. var q;
  45469. for (q = 0; q < count; q++) {
  45470. var transform = argsArray[iFirstTransform + (q << 2)];
  45471. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  45472. if (currentX + img.width > MAX_WIDTH) {
  45473. // starting new line
  45474. maxX = Math.max(maxX, currentX);
  45475. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  45476. currentX = 0;
  45477. maxLineHeight = 0;
  45478. }
  45479. map.push({
  45480. transform: transform,
  45481. x: currentX, y: currentY,
  45482. w: img.width, h: img.height
  45483. });
  45484. currentX += img.width + 2 * IMAGE_PADDING;
  45485. maxLineHeight = Math.max(maxLineHeight, img.height);
  45486. }
  45487. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  45488. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  45489. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  45490. var imgRowSize = imgWidth << 2;
  45491. for (q = 0; q < count; q++) {
  45492. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  45493. // Copy image by lines and extends pixels into padding.
  45494. var rowSize = map[q].w << 2;
  45495. var dataOffset = 0;
  45496. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  45497. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  45498. for (var k = 0, kk = map[q].h; k < kk; k++) {
  45499. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  45500. dataOffset += rowSize;
  45501. offset += imgRowSize;
  45502. }
  45503. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  45504. while (offset >= 0) {
  45505. data[offset - 4] = data[offset];
  45506. data[offset - 3] = data[offset + 1];
  45507. data[offset - 2] = data[offset + 2];
  45508. data[offset - 1] = data[offset + 3];
  45509. data[offset + rowSize] = data[offset + rowSize - 4];
  45510. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  45511. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  45512. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  45513. offset -= imgRowSize;
  45514. }
  45515. }
  45516. // Replace queue items.
  45517. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  45518. argsArray.splice(iFirstSave, count * 4,
  45519. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  45520. data: imgData }, map]);
  45521. return iFirstSave + 1;
  45522. });
  45523. // This replaces (save, transform, paintImageMaskXObject, restore)+
  45524. // sequences with one |paintImageMaskXObjectGroup| or one
  45525. // |paintImageMaskXObjectRepeat| operation.
  45526. addState(InitialState,
  45527. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  45528. function foundImageMaskGroup(context) {
  45529. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  45530. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  45531. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  45532. var fnArray = context.fnArray, argsArray = context.argsArray;
  45533. var curr = context.iCurr;
  45534. var iFirstSave = curr - 3;
  45535. var iFirstTransform = curr - 2;
  45536. var iFirstPIMXO = curr - 1;
  45537. // Look for the quartets.
  45538. var i = iFirstSave + 4;
  45539. var ii = fnArray.length;
  45540. while (i + 3 < ii) {
  45541. if (fnArray[i] !== OPS.save ||
  45542. fnArray[i + 1] !== OPS.transform ||
  45543. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  45544. fnArray[i + 3] !== OPS.restore) {
  45545. break; // ops don't match
  45546. }
  45547. i += 4;
  45548. }
  45549. // At this point, i is the index of the first op past the last valid
  45550. // quartet.
  45551. var count = (i - iFirstSave) / 4;
  45552. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  45553. argsArray);
  45554. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  45555. return i;
  45556. }
  45557. var q;
  45558. var isSameImage = false;
  45559. var iTransform, transformArgs;
  45560. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  45561. if (argsArray[iFirstTransform][1] === 0 &&
  45562. argsArray[iFirstTransform][2] === 0) {
  45563. isSameImage = true;
  45564. var firstTransformArg0 = argsArray[iFirstTransform][0];
  45565. var firstTransformArg3 = argsArray[iFirstTransform][3];
  45566. iTransform = iFirstTransform + 4;
  45567. var iPIMXO = iFirstPIMXO + 4;
  45568. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  45569. transformArgs = argsArray[iTransform];
  45570. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  45571. transformArgs[0] !== firstTransformArg0 ||
  45572. transformArgs[1] !== 0 ||
  45573. transformArgs[2] !== 0 ||
  45574. transformArgs[3] !== firstTransformArg3) {
  45575. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  45576. isSameImage = false;
  45577. } else {
  45578. count = q;
  45579. }
  45580. break; // different image or transform
  45581. }
  45582. }
  45583. }
  45584. if (isSameImage) {
  45585. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  45586. var positions = new Float32Array(count * 2);
  45587. iTransform = iFirstTransform;
  45588. for (q = 0; q < count; q++, iTransform += 4) {
  45589. transformArgs = argsArray[iTransform];
  45590. positions[(q << 1)] = transformArgs[4];
  45591. positions[(q << 1) + 1] = transformArgs[5];
  45592. }
  45593. // Replace queue items.
  45594. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  45595. argsArray.splice(iFirstSave, count * 4,
  45596. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  45597. } else {
  45598. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  45599. var images = [];
  45600. for (q = 0; q < count; q++) {
  45601. transformArgs = argsArray[iFirstTransform + (q << 2)];
  45602. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  45603. images.push({ data: maskParams.data, width: maskParams.width,
  45604. height: maskParams.height,
  45605. transform: transformArgs });
  45606. }
  45607. // Replace queue items.
  45608. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  45609. argsArray.splice(iFirstSave, count * 4, [images]);
  45610. }
  45611. return iFirstSave + 1;
  45612. });
  45613. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  45614. // with one paintImageXObjectRepeat operation, if the |transform| and
  45615. // |paintImageXObjectRepeat| ops are appropriate.
  45616. addState(InitialState,
  45617. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  45618. function (context) {
  45619. var MIN_IMAGES_IN_BLOCK = 3;
  45620. var MAX_IMAGES_IN_BLOCK = 1000;
  45621. var fnArray = context.fnArray, argsArray = context.argsArray;
  45622. var curr = context.iCurr;
  45623. var iFirstSave = curr - 3;
  45624. var iFirstTransform = curr - 2;
  45625. var iFirstPIXO = curr - 1;
  45626. var iFirstRestore = curr;
  45627. if (argsArray[iFirstTransform][1] !== 0 ||
  45628. argsArray[iFirstTransform][2] !== 0) {
  45629. return iFirstRestore + 1; // transform has the wrong form
  45630. }
  45631. // Look for the quartets.
  45632. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  45633. var firstTransformArg0 = argsArray[iFirstTransform][0];
  45634. var firstTransformArg3 = argsArray[iFirstTransform][3];
  45635. var i = iFirstSave + 4;
  45636. var ii = fnArray.length;
  45637. while (i + 3 < ii) {
  45638. if (fnArray[i] !== OPS.save ||
  45639. fnArray[i + 1] !== OPS.transform ||
  45640. fnArray[i + 2] !== OPS.paintImageXObject ||
  45641. fnArray[i + 3] !== OPS.restore) {
  45642. break; // ops don't match
  45643. }
  45644. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  45645. argsArray[i + 1][1] !== 0 ||
  45646. argsArray[i + 1][2] !== 0 ||
  45647. argsArray[i + 1][3] !== firstTransformArg3) {
  45648. break; // transforms don't match
  45649. }
  45650. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  45651. break; // images don't match
  45652. }
  45653. i += 4;
  45654. }
  45655. // At this point, i is the index of the first op past the last valid
  45656. // quartet.
  45657. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  45658. if (count < MIN_IMAGES_IN_BLOCK) {
  45659. return i;
  45660. }
  45661. // Extract the (x,y) positions from all of the matching transforms.
  45662. var positions = new Float32Array(count * 2);
  45663. var iTransform = iFirstTransform;
  45664. for (var q = 0; q < count; q++, iTransform += 4) {
  45665. var transformArgs = argsArray[iTransform];
  45666. positions[(q << 1)] = transformArgs[4];
  45667. positions[(q << 1) + 1] = transformArgs[5];
  45668. }
  45669. // Replace queue items.
  45670. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  45671. positions];
  45672. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  45673. argsArray.splice(iFirstSave, count * 4, args);
  45674. return iFirstSave + 1;
  45675. });
  45676. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  45677. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  45678. // sequences, if the font for each one is the same.
  45679. addState(InitialState,
  45680. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  45681. function (context) {
  45682. var MIN_CHARS_IN_BLOCK = 3;
  45683. var MAX_CHARS_IN_BLOCK = 1000;
  45684. var fnArray = context.fnArray, argsArray = context.argsArray;
  45685. var curr = context.iCurr;
  45686. var iFirstBeginText = curr - 4;
  45687. var iFirstSetFont = curr - 3;
  45688. var iFirstSetTextMatrix = curr - 2;
  45689. var iFirstShowText = curr - 1;
  45690. var iFirstEndText = curr;
  45691. // Look for the quintets.
  45692. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  45693. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  45694. var i = iFirstBeginText + 5;
  45695. var ii = fnArray.length;
  45696. while (i + 4 < ii) {
  45697. if (fnArray[i] !== OPS.beginText ||
  45698. fnArray[i + 1] !== OPS.setFont ||
  45699. fnArray[i + 2] !== OPS.setTextMatrix ||
  45700. fnArray[i + 3] !== OPS.showText ||
  45701. fnArray[i + 4] !== OPS.endText) {
  45702. break; // ops don't match
  45703. }
  45704. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  45705. argsArray[i + 1][1] !== firstSetFontArg1) {
  45706. break; // fonts don't match
  45707. }
  45708. i += 5;
  45709. }
  45710. // At this point, i is the index of the first op past the last valid
  45711. // quintet.
  45712. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  45713. if (count < MIN_CHARS_IN_BLOCK) {
  45714. return i;
  45715. }
  45716. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  45717. // showText, endText), include that as well. (E.g. <something> might be
  45718. // |dependency|.)
  45719. var iFirst = iFirstBeginText;
  45720. if (iFirstBeginText >= 4 &&
  45721. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  45722. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  45723. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  45724. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  45725. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  45726. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  45727. count++;
  45728. iFirst -= 5;
  45729. }
  45730. // Remove (endText, beginText, setFont) trios.
  45731. var iEndText = iFirst + 4;
  45732. for (var q = 1; q < count; q++) {
  45733. fnArray.splice(iEndText, 3);
  45734. argsArray.splice(iEndText, 3);
  45735. iEndText += 2;
  45736. }
  45737. return iEndText + 1;
  45738. });
  45739. function QueueOptimizer() {}
  45740. QueueOptimizer.prototype = {
  45741. optimize: function QueueOptimizer_optimize(queue) {
  45742. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  45743. var context = {
  45744. iCurr: 0,
  45745. fnArray: fnArray,
  45746. argsArray: argsArray
  45747. };
  45748. var state;
  45749. var i = 0, ii = fnArray.length;
  45750. while (i < ii) {
  45751. state = (state || InitialState)[fnArray[i]];
  45752. if (typeof state === 'function') { // we found some handler
  45753. context.iCurr = i;
  45754. // state() returns the index of the first non-matching op (if we
  45755. // didn't match) or the first op past the modified ops (if we did
  45756. // match and replace).
  45757. i = state(context);
  45758. state = undefined; // reset the state machine
  45759. ii = context.fnArray.length;
  45760. } else {
  45761. i++;
  45762. }
  45763. }
  45764. }
  45765. };
  45766. return QueueOptimizer;
  45767. })();
  45768. exports.OperatorList = OperatorList;
  45769. exports.PartialEvaluator = PartialEvaluator;
  45770. }));
  45771. (function (root, factory) {
  45772. {
  45773. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  45774. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  45775. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  45776. }
  45777. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  45778. coreColorSpace, coreObj, coreEvaluator) {
  45779. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  45780. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  45781. var AnnotationFlag = sharedUtil.AnnotationFlag;
  45782. var AnnotationType = sharedUtil.AnnotationType;
  45783. var OPS = sharedUtil.OPS;
  45784. var Util = sharedUtil.Util;
  45785. var isBool = sharedUtil.isBool;
  45786. var isString = sharedUtil.isString;
  45787. var isArray = sharedUtil.isArray;
  45788. var isInt = sharedUtil.isInt;
  45789. var isValidUrl = sharedUtil.isValidUrl;
  45790. var stringToBytes = sharedUtil.stringToBytes;
  45791. var stringToPDFString = sharedUtil.stringToPDFString;
  45792. var stringToUTF8String = sharedUtil.stringToUTF8String;
  45793. var warn = sharedUtil.warn;
  45794. var Dict = corePrimitives.Dict;
  45795. var isDict = corePrimitives.isDict;
  45796. var isName = corePrimitives.isName;
  45797. var isRef = corePrimitives.isRef;
  45798. var Stream = coreStream.Stream;
  45799. var ColorSpace = coreColorSpace.ColorSpace;
  45800. var ObjectLoader = coreObj.ObjectLoader;
  45801. var FileSpec = coreObj.FileSpec;
  45802. var OperatorList = coreEvaluator.OperatorList;
  45803. /**
  45804. * @class
  45805. * @alias AnnotationFactory
  45806. */
  45807. function AnnotationFactory() {}
  45808. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  45809. /**
  45810. * @param {XRef} xref
  45811. * @param {Object} ref
  45812. * @param {string} uniquePrefix
  45813. * @param {Object} idCounters
  45814. * @returns {Annotation}
  45815. */
  45816. create: function AnnotationFactory_create(xref, ref,
  45817. uniquePrefix, idCounters) {
  45818. var dict = xref.fetchIfRef(ref);
  45819. if (!isDict(dict)) {
  45820. return;
  45821. }
  45822. var id = isRef(ref) ? ref.toString() :
  45823. 'annot_' + (uniquePrefix || '') + (++idCounters.obj);
  45824. // Determine the annotation's subtype.
  45825. var subtype = dict.get('Subtype');
  45826. subtype = isName(subtype) ? subtype.name : null;
  45827. // Return the right annotation object based on the subtype and field type.
  45828. var parameters = {
  45829. xref: xref,
  45830. dict: dict,
  45831. ref: isRef(ref) ? ref : null,
  45832. subtype: subtype,
  45833. id: id,
  45834. };
  45835. switch (subtype) {
  45836. case 'Link':
  45837. return new LinkAnnotation(parameters);
  45838. case 'Text':
  45839. return new TextAnnotation(parameters);
  45840. case 'Widget':
  45841. var fieldType = Util.getInheritableProperty(dict, 'FT');
  45842. fieldType = isName(fieldType) ? fieldType.name : null;
  45843. switch (fieldType) {
  45844. case 'Tx':
  45845. return new TextWidgetAnnotation(parameters);
  45846. case 'Ch':
  45847. return new ChoiceWidgetAnnotation(parameters);
  45848. }
  45849. warn('Unimplemented widget field type "' + fieldType + '", ' +
  45850. 'falling back to base field type.');
  45851. return new WidgetAnnotation(parameters);
  45852. case 'Popup':
  45853. return new PopupAnnotation(parameters);
  45854. case 'Highlight':
  45855. return new HighlightAnnotation(parameters);
  45856. case 'Underline':
  45857. return new UnderlineAnnotation(parameters);
  45858. case 'Squiggly':
  45859. return new SquigglyAnnotation(parameters);
  45860. case 'StrikeOut':
  45861. return new StrikeOutAnnotation(parameters);
  45862. case 'FileAttachment':
  45863. return new FileAttachmentAnnotation(parameters);
  45864. default:
  45865. if (!subtype) {
  45866. warn('Annotation is missing the required /Subtype.');
  45867. } else {
  45868. warn('Unimplemented annotation type "' + subtype + '", ' +
  45869. 'falling back to base annotation.');
  45870. }
  45871. return new Annotation(parameters);
  45872. }
  45873. }
  45874. };
  45875. var Annotation = (function AnnotationClosure() {
  45876. // 12.5.5: Algorithm: Appearance streams
  45877. function getTransformMatrix(rect, bbox, matrix) {
  45878. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  45879. var minX = bounds[0];
  45880. var minY = bounds[1];
  45881. var maxX = bounds[2];
  45882. var maxY = bounds[3];
  45883. if (minX === maxX || minY === maxY) {
  45884. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  45885. // just apply the transform for rect
  45886. return [1, 0, 0, 1, rect[0], rect[1]];
  45887. }
  45888. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  45889. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  45890. return [
  45891. xRatio,
  45892. 0,
  45893. 0,
  45894. yRatio,
  45895. rect[0] - minX * xRatio,
  45896. rect[1] - minY * yRatio
  45897. ];
  45898. }
  45899. function getDefaultAppearance(dict) {
  45900. var appearanceState = dict.get('AP');
  45901. if (!isDict(appearanceState)) {
  45902. return;
  45903. }
  45904. var appearance;
  45905. var appearances = appearanceState.get('N');
  45906. if (isDict(appearances)) {
  45907. var as = dict.get('AS');
  45908. if (as && appearances.has(as.name)) {
  45909. appearance = appearances.get(as.name);
  45910. }
  45911. } else {
  45912. appearance = appearances;
  45913. }
  45914. return appearance;
  45915. }
  45916. function Annotation(params) {
  45917. var dict = params.dict;
  45918. this.setFlags(dict.get('F'));
  45919. this.setRectangle(dict.getArray('Rect'));
  45920. this.setColor(dict.getArray('C'));
  45921. this.setBorderStyle(dict);
  45922. this.appearance = getDefaultAppearance(dict);
  45923. // Expose public properties using a data object.
  45924. this.data = {};
  45925. this.data.id = params.id;
  45926. this.data.subtype = params.subtype;
  45927. this.data.annotationFlags = this.flags;
  45928. this.data.rect = this.rectangle;
  45929. this.data.color = this.color;
  45930. this.data.borderStyle = this.borderStyle;
  45931. this.data.hasAppearance = !!this.appearance;
  45932. }
  45933. Annotation.prototype = {
  45934. /**
  45935. * @private
  45936. */
  45937. _hasFlag: function Annotation_hasFlag(flags, flag) {
  45938. return !!(flags & flag);
  45939. },
  45940. /**
  45941. * @private
  45942. */
  45943. _isViewable: function Annotation_isViewable(flags) {
  45944. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  45945. !this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
  45946. !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  45947. },
  45948. /**
  45949. * @private
  45950. */
  45951. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  45952. return this._hasFlag(flags, AnnotationFlag.PRINT) &&
  45953. !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  45954. !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  45955. },
  45956. /**
  45957. * @return {boolean}
  45958. */
  45959. get viewable() {
  45960. if (this.flags === 0) {
  45961. return true;
  45962. }
  45963. return this._isViewable(this.flags);
  45964. },
  45965. /**
  45966. * @return {boolean}
  45967. */
  45968. get printable() {
  45969. if (this.flags === 0) {
  45970. return false;
  45971. }
  45972. return this._isPrintable(this.flags);
  45973. },
  45974. /**
  45975. * Set the flags.
  45976. *
  45977. * @public
  45978. * @memberof Annotation
  45979. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  45980. * characteristics
  45981. * @see {@link shared/util.js}
  45982. */
  45983. setFlags: function Annotation_setFlags(flags) {
  45984. this.flags = (isInt(flags) && flags > 0) ? flags : 0;
  45985. },
  45986. /**
  45987. * Check if a provided flag is set.
  45988. *
  45989. * @public
  45990. * @memberof Annotation
  45991. * @param {number} flag - Hexadecimal representation for an annotation
  45992. * characteristic
  45993. * @return {boolean}
  45994. * @see {@link shared/util.js}
  45995. */
  45996. hasFlag: function Annotation_hasFlag(flag) {
  45997. return this._hasFlag(this.flags, flag);
  45998. },
  45999. /**
  46000. * Set the rectangle.
  46001. *
  46002. * @public
  46003. * @memberof Annotation
  46004. * @param {Array} rectangle - The rectangle array with exactly four entries
  46005. */
  46006. setRectangle: function Annotation_setRectangle(rectangle) {
  46007. if (isArray(rectangle) && rectangle.length === 4) {
  46008. this.rectangle = Util.normalizeRect(rectangle);
  46009. } else {
  46010. this.rectangle = [0, 0, 0, 0];
  46011. }
  46012. },
  46013. /**
  46014. * Set the color and take care of color space conversion.
  46015. *
  46016. * @public
  46017. * @memberof Annotation
  46018. * @param {Array} color - The color array containing either 0
  46019. * (transparent), 1 (grayscale), 3 (RGB) or
  46020. * 4 (CMYK) elements
  46021. */
  46022. setColor: function Annotation_setColor(color) {
  46023. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  46024. if (!isArray(color)) {
  46025. this.color = rgbColor;
  46026. return;
  46027. }
  46028. switch (color.length) {
  46029. case 0: // Transparent, which we indicate with a null value
  46030. this.color = null;
  46031. break;
  46032. case 1: // Convert grayscale to RGB
  46033. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  46034. this.color = rgbColor;
  46035. break;
  46036. case 3: // Convert RGB percentages to RGB
  46037. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  46038. this.color = rgbColor;
  46039. break;
  46040. case 4: // Convert CMYK to RGB
  46041. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  46042. this.color = rgbColor;
  46043. break;
  46044. default:
  46045. this.color = rgbColor;
  46046. break;
  46047. }
  46048. },
  46049. /**
  46050. * Set the border style (as AnnotationBorderStyle object).
  46051. *
  46052. * @public
  46053. * @memberof Annotation
  46054. * @param {Dict} borderStyle - The border style dictionary
  46055. */
  46056. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  46057. this.borderStyle = new AnnotationBorderStyle();
  46058. if (!isDict(borderStyle)) {
  46059. return;
  46060. }
  46061. if (borderStyle.has('BS')) {
  46062. var dict = borderStyle.get('BS');
  46063. var dictType = dict.get('Type');
  46064. if (!dictType || isName(dictType, 'Border')) {
  46065. this.borderStyle.setWidth(dict.get('W'));
  46066. this.borderStyle.setStyle(dict.get('S'));
  46067. this.borderStyle.setDashArray(dict.getArray('D'));
  46068. }
  46069. } else if (borderStyle.has('Border')) {
  46070. var array = borderStyle.getArray('Border');
  46071. if (isArray(array) && array.length >= 3) {
  46072. this.borderStyle.setHorizontalCornerRadius(array[0]);
  46073. this.borderStyle.setVerticalCornerRadius(array[1]);
  46074. this.borderStyle.setWidth(array[2]);
  46075. if (array.length === 4) { // Dash array available
  46076. this.borderStyle.setDashArray(array[3]);
  46077. }
  46078. }
  46079. } else {
  46080. // There are no border entries in the dictionary. According to the
  46081. // specification, we should draw a solid border of width 1 in that
  46082. // case, but Adobe Reader did not implement that part of the
  46083. // specification and instead draws no border at all, so we do the same.
  46084. // See also https://github.com/mozilla/pdf.js/issues/6179.
  46085. this.borderStyle.setWidth(0);
  46086. }
  46087. },
  46088. /**
  46089. * Prepare the annotation for working with a popup in the display layer.
  46090. *
  46091. * @private
  46092. * @memberof Annotation
  46093. * @param {Dict} dict - The annotation's data dictionary
  46094. */
  46095. _preparePopup: function Annotation_preparePopup(dict) {
  46096. if (!dict.has('C')) {
  46097. // Fall back to the default background color.
  46098. this.data.color = null;
  46099. }
  46100. this.data.hasPopup = dict.has('Popup');
  46101. this.data.title = stringToPDFString(dict.get('T') || '');
  46102. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  46103. },
  46104. loadResources: function Annotation_loadResources(keys) {
  46105. return new Promise(function (resolve, reject) {
  46106. this.appearance.dict.getAsync('Resources').then(function (resources) {
  46107. if (!resources) {
  46108. resolve();
  46109. return;
  46110. }
  46111. var objectLoader = new ObjectLoader(resources.map,
  46112. keys,
  46113. resources.xref);
  46114. objectLoader.load().then(function() {
  46115. resolve(resources);
  46116. }, reject);
  46117. }, reject);
  46118. }.bind(this));
  46119. },
  46120. getOperatorList: function Annotation_getOperatorList(evaluator, task,
  46121. renderForms) {
  46122. if (!this.appearance) {
  46123. return Promise.resolve(new OperatorList());
  46124. }
  46125. var data = this.data;
  46126. var appearanceDict = this.appearance.dict;
  46127. var resourcesPromise = this.loadResources([
  46128. 'ExtGState',
  46129. 'ColorSpace',
  46130. 'Pattern',
  46131. 'Shading',
  46132. 'XObject',
  46133. 'Font'
  46134. // ProcSet
  46135. // Properties
  46136. ]);
  46137. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  46138. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0 ,0];
  46139. var transform = getTransformMatrix(data.rect, bbox, matrix);
  46140. var self = this;
  46141. return resourcesPromise.then(function(resources) {
  46142. var opList = new OperatorList();
  46143. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  46144. return evaluator.getOperatorList(self.appearance, task,
  46145. resources, opList).
  46146. then(function () {
  46147. opList.addOp(OPS.endAnnotation, []);
  46148. self.appearance.reset();
  46149. return opList;
  46150. });
  46151. });
  46152. }
  46153. };
  46154. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  46155. annotations, opList, partialEvaluator, task, intent, renderForms) {
  46156. var annotationPromises = [];
  46157. for (var i = 0, n = annotations.length; i < n; ++i) {
  46158. if ((intent === 'display' && annotations[i].viewable) ||
  46159. (intent === 'print' && annotations[i].printable)) {
  46160. annotationPromises.push(
  46161. annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  46162. }
  46163. }
  46164. return Promise.all(annotationPromises).then(function(operatorLists) {
  46165. opList.addOp(OPS.beginAnnotations, []);
  46166. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  46167. opList.addOpList(operatorLists[i]);
  46168. }
  46169. opList.addOp(OPS.endAnnotations, []);
  46170. });
  46171. };
  46172. return Annotation;
  46173. })();
  46174. /**
  46175. * Contains all data regarding an annotation's border style.
  46176. *
  46177. * @class
  46178. */
  46179. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  46180. /**
  46181. * @constructor
  46182. * @private
  46183. */
  46184. function AnnotationBorderStyle() {
  46185. this.width = 1;
  46186. this.style = AnnotationBorderStyleType.SOLID;
  46187. this.dashArray = [3];
  46188. this.horizontalCornerRadius = 0;
  46189. this.verticalCornerRadius = 0;
  46190. }
  46191. AnnotationBorderStyle.prototype = {
  46192. /**
  46193. * Set the width.
  46194. *
  46195. * @public
  46196. * @memberof AnnotationBorderStyle
  46197. * @param {integer} width - The width
  46198. */
  46199. setWidth: function AnnotationBorderStyle_setWidth(width) {
  46200. if (width === (width | 0)) {
  46201. this.width = width;
  46202. }
  46203. },
  46204. /**
  46205. * Set the style.
  46206. *
  46207. * @public
  46208. * @memberof AnnotationBorderStyle
  46209. * @param {Object} style - The style object
  46210. * @see {@link shared/util.js}
  46211. */
  46212. setStyle: function AnnotationBorderStyle_setStyle(style) {
  46213. if (!style) {
  46214. return;
  46215. }
  46216. switch (style.name) {
  46217. case 'S':
  46218. this.style = AnnotationBorderStyleType.SOLID;
  46219. break;
  46220. case 'D':
  46221. this.style = AnnotationBorderStyleType.DASHED;
  46222. break;
  46223. case 'B':
  46224. this.style = AnnotationBorderStyleType.BEVELED;
  46225. break;
  46226. case 'I':
  46227. this.style = AnnotationBorderStyleType.INSET;
  46228. break;
  46229. case 'U':
  46230. this.style = AnnotationBorderStyleType.UNDERLINE;
  46231. break;
  46232. default:
  46233. break;
  46234. }
  46235. },
  46236. /**
  46237. * Set the dash array.
  46238. *
  46239. * @public
  46240. * @memberof AnnotationBorderStyle
  46241. * @param {Array} dashArray - The dash array with at least one element
  46242. */
  46243. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  46244. // We validate the dash array, but we do not use it because CSS does not
  46245. // allow us to change spacing of dashes. For more information, visit
  46246. // http://www.w3.org/TR/css3-background/#the-border-style.
  46247. if (isArray(dashArray) && dashArray.length > 0) {
  46248. // According to the PDF specification: the elements in a dashArray
  46249. // shall be numbers that are nonnegative and not all equal to zero.
  46250. var isValid = true;
  46251. var allZeros = true;
  46252. for (var i = 0, len = dashArray.length; i < len; i++) {
  46253. var element = dashArray[i];
  46254. var validNumber = (+element >= 0);
  46255. if (!validNumber) {
  46256. isValid = false;
  46257. break;
  46258. } else if (element > 0) {
  46259. allZeros = false;
  46260. }
  46261. }
  46262. if (isValid && !allZeros) {
  46263. this.dashArray = dashArray;
  46264. } else {
  46265. this.width = 0; // Adobe behavior when the array is invalid.
  46266. }
  46267. } else if (dashArray) {
  46268. this.width = 0; // Adobe behavior when the array is invalid.
  46269. }
  46270. },
  46271. /**
  46272. * Set the horizontal corner radius (from a Border dictionary).
  46273. *
  46274. * @public
  46275. * @memberof AnnotationBorderStyle
  46276. * @param {integer} radius - The horizontal corner radius
  46277. */
  46278. setHorizontalCornerRadius:
  46279. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  46280. if (radius === (radius | 0)) {
  46281. this.horizontalCornerRadius = radius;
  46282. }
  46283. },
  46284. /**
  46285. * Set the vertical corner radius (from a Border dictionary).
  46286. *
  46287. * @public
  46288. * @memberof AnnotationBorderStyle
  46289. * @param {integer} radius - The vertical corner radius
  46290. */
  46291. setVerticalCornerRadius:
  46292. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  46293. if (radius === (radius | 0)) {
  46294. this.verticalCornerRadius = radius;
  46295. }
  46296. }
  46297. };
  46298. return AnnotationBorderStyle;
  46299. })();
  46300. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  46301. function WidgetAnnotation(params) {
  46302. Annotation.call(this, params);
  46303. var dict = params.dict;
  46304. var data = this.data;
  46305. data.annotationType = AnnotationType.WIDGET;
  46306. data.fieldValue = Util.getInheritableProperty(dict, 'V',
  46307. /* getArray = */ true);
  46308. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  46309. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  46310. var fieldType = Util.getInheritableProperty(dict, 'FT');
  46311. data.fieldType = isName(fieldType) ? fieldType.name : null;
  46312. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  46313. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  46314. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  46315. data.fieldFlags = 0;
  46316. }
  46317. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  46318. // Hide signatures because we cannot validate them.
  46319. if (data.fieldType === 'Sig') {
  46320. this.setFlags(AnnotationFlag.HIDDEN);
  46321. }
  46322. // Building the full field name by collecting the field and
  46323. // its ancestors 'T' data and joining them using '.'.
  46324. var fieldName = [];
  46325. var namedItem = dict;
  46326. var ref = params.ref;
  46327. while (namedItem) {
  46328. var parent = namedItem.get('Parent');
  46329. var parentRef = namedItem.getRaw('Parent');
  46330. var name = namedItem.get('T');
  46331. if (name) {
  46332. fieldName.unshift(stringToPDFString(name));
  46333. } else if (parent && ref) {
  46334. // The field name is absent, that means more than one field
  46335. // with the same name may exist. Replacing the empty name
  46336. // with the '`' plus index in the parent's 'Kids' array.
  46337. // This is not in the PDF spec but necessary to id the
  46338. // the input controls.
  46339. var kids = parent.get('Kids');
  46340. var j, jj;
  46341. for (j = 0, jj = kids.length; j < jj; j++) {
  46342. var kidRef = kids[j];
  46343. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  46344. break;
  46345. }
  46346. }
  46347. fieldName.unshift('`' + j);
  46348. }
  46349. namedItem = parent;
  46350. ref = parentRef;
  46351. }
  46352. data.fullName = fieldName.join('.');
  46353. }
  46354. Util.inherit(WidgetAnnotation, Annotation, {
  46355. /**
  46356. * Check if a provided field flag is set.
  46357. *
  46358. * @public
  46359. * @memberof WidgetAnnotation
  46360. * @param {number} flag - Hexadecimal representation for an annotation
  46361. * field characteristic
  46362. * @return {boolean}
  46363. * @see {@link shared/util.js}
  46364. */
  46365. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  46366. return !!(this.data.fieldFlags & flag);
  46367. },
  46368. });
  46369. return WidgetAnnotation;
  46370. })();
  46371. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  46372. function TextWidgetAnnotation(params) {
  46373. WidgetAnnotation.call(this, params);
  46374. // The field value is always a string.
  46375. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  46376. // Determine the alignment of text in the field.
  46377. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  46378. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  46379. alignment = null;
  46380. }
  46381. this.data.textAlignment = alignment;
  46382. // Determine the maximum length of text in the field.
  46383. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  46384. if (!isInt(maximumLength) || maximumLength < 0) {
  46385. maximumLength = null;
  46386. }
  46387. this.data.maxLen = maximumLength;
  46388. // Process field flags for the display layer.
  46389. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  46390. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
  46391. !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) &&
  46392. !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) &&
  46393. !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) &&
  46394. this.data.maxLen !== null;
  46395. }
  46396. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  46397. getOperatorList:
  46398. function TextWidgetAnnotation_getOperatorList(evaluator, task,
  46399. renderForms) {
  46400. var operatorList = new OperatorList();
  46401. // Do not render form elements on the canvas when interactive forms are
  46402. // enabled. The display layer is responsible for rendering them instead.
  46403. if (renderForms) {
  46404. return Promise.resolve(operatorList);
  46405. }
  46406. if (this.appearance) {
  46407. return Annotation.prototype.getOperatorList.call(this, evaluator, task,
  46408. renderForms);
  46409. }
  46410. // Even if there is an appearance stream, ignore it. This is the
  46411. // behaviour used by Adobe Reader.
  46412. if (!this.data.defaultAppearance) {
  46413. return Promise.resolve(operatorList);
  46414. }
  46415. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  46416. return evaluator.getOperatorList(stream, task, this.fieldResources,
  46417. operatorList).
  46418. then(function () {
  46419. return operatorList;
  46420. });
  46421. }
  46422. });
  46423. return TextWidgetAnnotation;
  46424. })();
  46425. var ChoiceWidgetAnnotation = (function ChoiceWidgetAnnotationClosure() {
  46426. function ChoiceWidgetAnnotation(params) {
  46427. WidgetAnnotation.call(this, params);
  46428. // Determine the options. The options array may consist of strings or
  46429. // arrays. If the array consists of arrays, then the first element of
  46430. // each array is the export value and the second element of each array is
  46431. // the display value. If the array consists of strings, then these
  46432. // represent both the export and display value. In this case, we convert
  46433. // it to an array of arrays as well for convenience in the display layer.
  46434. this.data.options = [];
  46435. var options = params.dict.getArray('Opt');
  46436. if (isArray(options)) {
  46437. for (var i = 0, ii = options.length; i < ii; i++) {
  46438. var option = options[i];
  46439. this.data.options[i] = {
  46440. exportValue: isArray(option) ? option[0] : option,
  46441. displayValue: isArray(option) ? option[1] : option,
  46442. };
  46443. }
  46444. }
  46445. // Determine the field value. In this case, it may be a string or an
  46446. // array of strings. For convenience in the display layer, convert the
  46447. // string to an array of one string as well.
  46448. if (!isArray(this.data.fieldValue)) {
  46449. this.data.fieldValue = [this.data.fieldValue];
  46450. }
  46451. // Process field flags for the display layer.
  46452. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  46453. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  46454. }
  46455. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  46456. getOperatorList:
  46457. function ChoiceWidgetAnnotation_getOperatorList(evaluator, task,
  46458. renderForms) {
  46459. var operatorList = new OperatorList();
  46460. // Do not render form elements on the canvas when interactive forms are
  46461. // enabled. The display layer is responsible for rendering them instead.
  46462. if (renderForms) {
  46463. return Promise.resolve(operatorList);
  46464. }
  46465. return Annotation.prototype.getOperatorList.call(this, evaluator, task,
  46466. renderForms);
  46467. }
  46468. });
  46469. return ChoiceWidgetAnnotation;
  46470. })();
  46471. var TextAnnotation = (function TextAnnotationClosure() {
  46472. var DEFAULT_ICON_SIZE = 22; // px
  46473. function TextAnnotation(parameters) {
  46474. Annotation.call(this, parameters);
  46475. this.data.annotationType = AnnotationType.TEXT;
  46476. if (this.data.hasAppearance) {
  46477. this.data.name = 'NoIcon';
  46478. } else {
  46479. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  46480. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  46481. this.data.name = parameters.dict.has('Name') ?
  46482. parameters.dict.get('Name').name : 'Note';
  46483. }
  46484. this._preparePopup(parameters.dict);
  46485. }
  46486. Util.inherit(TextAnnotation, Annotation, {});
  46487. return TextAnnotation;
  46488. })();
  46489. var LinkAnnotation = (function LinkAnnotationClosure() {
  46490. function LinkAnnotation(params) {
  46491. Annotation.call(this, params);
  46492. var dict = params.dict;
  46493. var data = this.data;
  46494. data.annotationType = AnnotationType.LINK;
  46495. var action = dict.get('A'), url, dest;
  46496. if (action && isDict(action)) {
  46497. var linkType = action.get('S').name;
  46498. switch (linkType) {
  46499. case 'URI':
  46500. url = action.get('URI');
  46501. if (isName(url)) {
  46502. // Some bad PDFs do not put parentheses around relative URLs.
  46503. url = '/' + url.name;
  46504. } else if (url) {
  46505. url = addDefaultProtocolToUrl(url);
  46506. }
  46507. // TODO: pdf spec mentions urls can be relative to a Base
  46508. // entry in the dictionary.
  46509. break;
  46510. case 'GoTo':
  46511. dest = action.get('D');
  46512. break;
  46513. case 'GoToR':
  46514. var urlDict = action.get('F');
  46515. if (isDict(urlDict)) {
  46516. // We assume that we found a FileSpec dictionary
  46517. // and fetch the URL without checking any further.
  46518. url = urlDict.get('F') || null;
  46519. } else if (isString(urlDict)) {
  46520. url = urlDict;
  46521. }
  46522. // NOTE: the destination is relative to the *remote* document.
  46523. var remoteDest = action.get('D');
  46524. if (remoteDest) {
  46525. if (isName(remoteDest)) {
  46526. remoteDest = remoteDest.name;
  46527. }
  46528. if (isString(url)) {
  46529. var baseUrl = url.split('#')[0];
  46530. if (isString(remoteDest)) {
  46531. // In practice, a named destination may contain only a number.
  46532. // If that happens, use the '#nameddest=' form to avoid the link
  46533. // redirecting to a page, instead of the correct destination.
  46534. url = baseUrl + '#' +
  46535. (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  46536. } else if (isArray(remoteDest)) {
  46537. url = baseUrl + '#' + JSON.stringify(remoteDest);
  46538. }
  46539. }
  46540. }
  46541. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  46542. var newWindow = action.get('NewWindow');
  46543. if (isBool(newWindow)) {
  46544. data.newWindow = newWindow;
  46545. }
  46546. break;
  46547. case 'Named':
  46548. data.action = action.get('N').name;
  46549. break;
  46550. default:
  46551. warn('unrecognized link type: ' + linkType);
  46552. }
  46553. } else if (dict.has('Dest')) { // Simple destination link.
  46554. dest = dict.get('Dest');
  46555. }
  46556. if (url) {
  46557. if (isValidUrl(url, /* allowRelative = */ false)) {
  46558. data.url = tryConvertUrlEncoding(url);
  46559. }
  46560. }
  46561. if (dest) {
  46562. data.dest = isName(dest) ? dest.name : dest;
  46563. }
  46564. }
  46565. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  46566. function addDefaultProtocolToUrl(url) {
  46567. if (isString(url) && url.indexOf('www.') === 0) {
  46568. return ('http://' + url);
  46569. }
  46570. return url;
  46571. }
  46572. function tryConvertUrlEncoding(url) {
  46573. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  46574. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  46575. try {
  46576. return stringToUTF8String(url);
  46577. } catch (e) {
  46578. return url;
  46579. }
  46580. }
  46581. Util.inherit(LinkAnnotation, Annotation, {});
  46582. return LinkAnnotation;
  46583. })();
  46584. var PopupAnnotation = (function PopupAnnotationClosure() {
  46585. function PopupAnnotation(parameters) {
  46586. Annotation.call(this, parameters);
  46587. this.data.annotationType = AnnotationType.POPUP;
  46588. var dict = parameters.dict;
  46589. var parentItem = dict.get('Parent');
  46590. if (!parentItem) {
  46591. warn('Popup annotation has a missing or invalid parent annotation.');
  46592. return;
  46593. }
  46594. this.data.parentId = dict.getRaw('Parent').toString();
  46595. this.data.title = stringToPDFString(parentItem.get('T') || '');
  46596. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  46597. if (!parentItem.has('C')) {
  46598. // Fall back to the default background color.
  46599. this.data.color = null;
  46600. } else {
  46601. this.setColor(parentItem.getArray('C'));
  46602. this.data.color = this.color;
  46603. }
  46604. // If the Popup annotation is not viewable, but the parent annotation is,
  46605. // that is most likely a bug. Fallback to inherit the flags from the parent
  46606. // annotation (this is consistent with the behaviour in Adobe Reader).
  46607. if (!this.viewable) {
  46608. var parentFlags = parentItem.get('F');
  46609. if (this._isViewable(parentFlags)) {
  46610. this.setFlags(parentFlags);
  46611. }
  46612. }
  46613. }
  46614. Util.inherit(PopupAnnotation, Annotation, {});
  46615. return PopupAnnotation;
  46616. })();
  46617. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  46618. function HighlightAnnotation(parameters) {
  46619. Annotation.call(this, parameters);
  46620. this.data.annotationType = AnnotationType.HIGHLIGHT;
  46621. this._preparePopup(parameters.dict);
  46622. // PDF viewers completely ignore any border styles.
  46623. this.data.borderStyle.setWidth(0);
  46624. }
  46625. Util.inherit(HighlightAnnotation, Annotation, {});
  46626. return HighlightAnnotation;
  46627. })();
  46628. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  46629. function UnderlineAnnotation(parameters) {
  46630. Annotation.call(this, parameters);
  46631. this.data.annotationType = AnnotationType.UNDERLINE;
  46632. this._preparePopup(parameters.dict);
  46633. // PDF viewers completely ignore any border styles.
  46634. this.data.borderStyle.setWidth(0);
  46635. }
  46636. Util.inherit(UnderlineAnnotation, Annotation, {});
  46637. return UnderlineAnnotation;
  46638. })();
  46639. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  46640. function SquigglyAnnotation(parameters) {
  46641. Annotation.call(this, parameters);
  46642. this.data.annotationType = AnnotationType.SQUIGGLY;
  46643. this._preparePopup(parameters.dict);
  46644. // PDF viewers completely ignore any border styles.
  46645. this.data.borderStyle.setWidth(0);
  46646. }
  46647. Util.inherit(SquigglyAnnotation, Annotation, {});
  46648. return SquigglyAnnotation;
  46649. })();
  46650. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  46651. function StrikeOutAnnotation(parameters) {
  46652. Annotation.call(this, parameters);
  46653. this.data.annotationType = AnnotationType.STRIKEOUT;
  46654. this._preparePopup(parameters.dict);
  46655. // PDF viewers completely ignore any border styles.
  46656. this.data.borderStyle.setWidth(0);
  46657. }
  46658. Util.inherit(StrikeOutAnnotation, Annotation, {});
  46659. return StrikeOutAnnotation;
  46660. })();
  46661. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  46662. function FileAttachmentAnnotation(parameters) {
  46663. Annotation.call(this, parameters);
  46664. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  46665. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  46666. this.data.file = file.serializable;
  46667. this._preparePopup(parameters.dict);
  46668. }
  46669. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  46670. return FileAttachmentAnnotation;
  46671. })();
  46672. exports.Annotation = Annotation;
  46673. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  46674. exports.AnnotationFactory = AnnotationFactory;
  46675. }));
  46676. (function (root, factory) {
  46677. {
  46678. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  46679. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  46680. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  46681. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  46682. }
  46683. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  46684. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  46685. var MissingDataException = sharedUtil.MissingDataException;
  46686. var Util = sharedUtil.Util;
  46687. var assert = sharedUtil.assert;
  46688. var error = sharedUtil.error;
  46689. var info = sharedUtil.info;
  46690. var isArray = sharedUtil.isArray;
  46691. var isArrayBuffer = sharedUtil.isArrayBuffer;
  46692. var isString = sharedUtil.isString;
  46693. var shadow = sharedUtil.shadow;
  46694. var stringToBytes = sharedUtil.stringToBytes;
  46695. var stringToPDFString = sharedUtil.stringToPDFString;
  46696. var warn = sharedUtil.warn;
  46697. var isSpace = sharedUtil.isSpace;
  46698. var Dict = corePrimitives.Dict;
  46699. var isDict = corePrimitives.isDict;
  46700. var isName = corePrimitives.isName;
  46701. var isStream = corePrimitives.isStream;
  46702. var NullStream = coreStream.NullStream;
  46703. var Stream = coreStream.Stream;
  46704. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  46705. var Catalog = coreObj.Catalog;
  46706. var ObjectLoader = coreObj.ObjectLoader;
  46707. var XRef = coreObj.XRef;
  46708. var Linearization = coreParser.Linearization;
  46709. var calculateMD5 = coreCrypto.calculateMD5;
  46710. var OperatorList = coreEvaluator.OperatorList;
  46711. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  46712. var Annotation = coreAnnotation.Annotation;
  46713. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  46714. var Page = (function PageClosure() {
  46715. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  46716. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  46717. this.pdfManager = pdfManager;
  46718. this.pageIndex = pageIndex;
  46719. this.pageDict = pageDict;
  46720. this.xref = xref;
  46721. this.ref = ref;
  46722. this.fontCache = fontCache;
  46723. this.uniquePrefix = 'p' + this.pageIndex + '_';
  46724. this.idCounters = {
  46725. obj: 0
  46726. };
  46727. this.evaluatorOptions = pdfManager.evaluatorOptions;
  46728. this.resourcesPromise = null;
  46729. }
  46730. Page.prototype = {
  46731. getPageProp: function Page_getPageProp(key) {
  46732. return this.pageDict.get(key);
  46733. },
  46734. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  46735. var dict = this.pageDict, valueArray = null, loopCount = 0;
  46736. var MAX_LOOP_COUNT = 100;
  46737. // Always walk up the entire parent chain, to be able to find
  46738. // e.g. \Resources placed on multiple levels of the tree.
  46739. while (dict) {
  46740. var value = dict.get(key);
  46741. if (value) {
  46742. if (!valueArray) {
  46743. valueArray = [];
  46744. }
  46745. valueArray.push(value);
  46746. }
  46747. if (++loopCount > MAX_LOOP_COUNT) {
  46748. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  46749. break;
  46750. }
  46751. dict = dict.get('Parent');
  46752. }
  46753. if (!valueArray) {
  46754. return Dict.empty;
  46755. }
  46756. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  46757. loopCount > MAX_LOOP_COUNT) {
  46758. return valueArray[0];
  46759. }
  46760. return Dict.merge(this.xref, valueArray);
  46761. },
  46762. get content() {
  46763. return this.getPageProp('Contents');
  46764. },
  46765. get resources() {
  46766. // For robustness: The spec states that a \Resources entry has to be
  46767. // present, but can be empty. Some document omit it still, in this case
  46768. // we return an empty dictionary.
  46769. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  46770. },
  46771. get mediaBox() {
  46772. var obj = this.getInheritedPageProp('MediaBox');
  46773. // Reset invalid media box to letter size.
  46774. if (!isArray(obj) || obj.length !== 4) {
  46775. obj = LETTER_SIZE_MEDIABOX;
  46776. }
  46777. return shadow(this, 'mediaBox', obj);
  46778. },
  46779. get view() {
  46780. var mediaBox = this.mediaBox;
  46781. var cropBox = this.getInheritedPageProp('CropBox');
  46782. if (!isArray(cropBox) || cropBox.length !== 4) {
  46783. return shadow(this, 'view', mediaBox);
  46784. }
  46785. // From the spec, 6th ed., p.963:
  46786. // "The crop, bleed, trim, and art boxes should not ordinarily
  46787. // extend beyond the boundaries of the media box. If they do, they are
  46788. // effectively reduced to their intersection with the media box."
  46789. cropBox = Util.intersect(cropBox, mediaBox);
  46790. if (!cropBox) {
  46791. return shadow(this, 'view', mediaBox);
  46792. }
  46793. return shadow(this, 'view', cropBox);
  46794. },
  46795. get rotate() {
  46796. var rotate = this.getInheritedPageProp('Rotate') || 0;
  46797. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  46798. if (rotate % 90 !== 0) {
  46799. rotate = 0;
  46800. } else if (rotate >= 360) {
  46801. rotate = rotate % 360;
  46802. } else if (rotate < 0) {
  46803. // The spec doesn't cover negatives, assume its counterclockwise
  46804. // rotation. The following is the other implementation of modulo.
  46805. rotate = ((rotate % 360) + 360) % 360;
  46806. }
  46807. return shadow(this, 'rotate', rotate);
  46808. },
  46809. getContentStream: function Page_getContentStream() {
  46810. var content = this.content;
  46811. var stream;
  46812. if (isArray(content)) {
  46813. // fetching items
  46814. var xref = this.xref;
  46815. var i, n = content.length;
  46816. var streams = [];
  46817. for (i = 0; i < n; ++i) {
  46818. streams.push(xref.fetchIfRef(content[i]));
  46819. }
  46820. stream = new StreamsSequenceStream(streams);
  46821. } else if (isStream(content)) {
  46822. stream = content;
  46823. } else {
  46824. // replacing non-existent page content with empty one
  46825. stream = new NullStream();
  46826. }
  46827. return stream;
  46828. },
  46829. loadResources: function Page_loadResources(keys) {
  46830. if (!this.resourcesPromise) {
  46831. // TODO: add async getInheritedPageProp and remove this.
  46832. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  46833. }
  46834. return this.resourcesPromise.then(function resourceSuccess() {
  46835. var objectLoader = new ObjectLoader(this.resources.map,
  46836. keys,
  46837. this.xref);
  46838. return objectLoader.load();
  46839. }.bind(this));
  46840. },
  46841. getOperatorList: function Page_getOperatorList(handler, task, intent,
  46842. renderInteractiveForms) {
  46843. var self = this;
  46844. var pdfManager = this.pdfManager;
  46845. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  46846. []);
  46847. var resourcesPromise = this.loadResources([
  46848. 'ExtGState',
  46849. 'ColorSpace',
  46850. 'Pattern',
  46851. 'Shading',
  46852. 'XObject',
  46853. 'Font'
  46854. // ProcSet
  46855. // Properties
  46856. ]);
  46857. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  46858. handler, this.pageIndex,
  46859. this.uniquePrefix,
  46860. this.idCounters,
  46861. this.fontCache,
  46862. this.evaluatorOptions);
  46863. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  46864. var pageListPromise = dataPromises.then(function(data) {
  46865. var contentStream = data[0];
  46866. var opList = new OperatorList(intent, handler, self.pageIndex);
  46867. handler.send('StartRenderPage', {
  46868. transparency: partialEvaluator.hasBlendModes(self.resources),
  46869. pageIndex: self.pageIndex,
  46870. intent: intent
  46871. });
  46872. return partialEvaluator.getOperatorList(contentStream, task,
  46873. self.resources, opList).then(function () {
  46874. return opList;
  46875. });
  46876. });
  46877. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  46878. return Promise.all([pageListPromise, annotationsPromise]).then(
  46879. function(datas) {
  46880. var pageOpList = datas[0];
  46881. var annotations = datas[1];
  46882. if (annotations.length === 0) {
  46883. pageOpList.flush(true);
  46884. return pageOpList;
  46885. }
  46886. var annotationsReadyPromise = Annotation.appendToOperatorList(
  46887. annotations, pageOpList, partialEvaluator, task, intent,
  46888. renderInteractiveForms);
  46889. return annotationsReadyPromise.then(function () {
  46890. pageOpList.flush(true);
  46891. return pageOpList;
  46892. });
  46893. });
  46894. },
  46895. extractTextContent: function Page_extractTextContent(task,
  46896. normalizeWhitespace,
  46897. combineTextItems) {
  46898. var handler = {
  46899. on: function nullHandlerOn() {},
  46900. send: function nullHandlerSend() {}
  46901. };
  46902. var self = this;
  46903. var pdfManager = this.pdfManager;
  46904. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  46905. []);
  46906. var resourcesPromise = this.loadResources([
  46907. 'ExtGState',
  46908. 'XObject',
  46909. 'Font'
  46910. ]);
  46911. var dataPromises = Promise.all([contentStreamPromise,
  46912. resourcesPromise]);
  46913. return dataPromises.then(function(data) {
  46914. var contentStream = data[0];
  46915. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  46916. handler, self.pageIndex,
  46917. self.uniquePrefix,
  46918. self.idCounters,
  46919. self.fontCache,
  46920. self.evaluatorOptions);
  46921. return partialEvaluator.getTextContent(contentStream,
  46922. task,
  46923. self.resources,
  46924. /* stateManager = */ null,
  46925. normalizeWhitespace,
  46926. combineTextItems);
  46927. });
  46928. },
  46929. getAnnotationsData: function Page_getAnnotationsData(intent) {
  46930. var annotations = this.annotations;
  46931. var annotationsData = [];
  46932. for (var i = 0, n = annotations.length; i < n; ++i) {
  46933. if (intent) {
  46934. if (!(intent === 'display' && annotations[i].viewable) &&
  46935. !(intent === 'print' && annotations[i].printable)) {
  46936. continue;
  46937. }
  46938. }
  46939. annotationsData.push(annotations[i].data);
  46940. }
  46941. return annotationsData;
  46942. },
  46943. get annotations() {
  46944. var annotations = [];
  46945. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  46946. var annotationFactory = new AnnotationFactory();
  46947. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  46948. var annotationRef = annotationRefs[i];
  46949. var annotation = annotationFactory.create(this.xref, annotationRef,
  46950. this.uniquePrefix,
  46951. this.idCounters);
  46952. if (annotation) {
  46953. annotations.push(annotation);
  46954. }
  46955. }
  46956. return shadow(this, 'annotations', annotations);
  46957. }
  46958. };
  46959. return Page;
  46960. })();
  46961. /**
  46962. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  46963. * `PDFDoc`, this one doesn't have any job management code.
  46964. * Right now there exists one PDFDocument on the main thread + one object
  46965. * for each worker. If there is no worker support enabled, there are two
  46966. * `PDFDocument` objects on the main thread created.
  46967. */
  46968. var PDFDocument = (function PDFDocumentClosure() {
  46969. var FINGERPRINT_FIRST_BYTES = 1024;
  46970. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  46971. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  46972. function PDFDocument(pdfManager, arg, password) {
  46973. if (isStream(arg)) {
  46974. init.call(this, pdfManager, arg, password);
  46975. } else if (isArrayBuffer(arg)) {
  46976. init.call(this, pdfManager, new Stream(arg), password);
  46977. } else {
  46978. error('PDFDocument: Unknown argument type');
  46979. }
  46980. }
  46981. function init(pdfManager, stream, password) {
  46982. assert(stream.length > 0, 'stream must have data');
  46983. this.pdfManager = pdfManager;
  46984. this.stream = stream;
  46985. var xref = new XRef(this.stream, password, pdfManager);
  46986. this.xref = xref;
  46987. }
  46988. function find(stream, needle, limit, backwards) {
  46989. var pos = stream.pos;
  46990. var end = stream.end;
  46991. var strBuf = [];
  46992. if (pos + limit > end) {
  46993. limit = end - pos;
  46994. }
  46995. for (var n = 0; n < limit; ++n) {
  46996. strBuf.push(String.fromCharCode(stream.getByte()));
  46997. }
  46998. var str = strBuf.join('');
  46999. stream.pos = pos;
  47000. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  47001. if (index === -1) {
  47002. return false; /* not found */
  47003. }
  47004. stream.pos += index;
  47005. return true; /* found */
  47006. }
  47007. var DocumentInfoValidators = {
  47008. get entries() {
  47009. // Lazily build this since all the validation functions below are not
  47010. // defined until after this file loads.
  47011. return shadow(this, 'entries', {
  47012. Title: isString,
  47013. Author: isString,
  47014. Subject: isString,
  47015. Keywords: isString,
  47016. Creator: isString,
  47017. Producer: isString,
  47018. CreationDate: isString,
  47019. ModDate: isString,
  47020. Trapped: isName
  47021. });
  47022. }
  47023. };
  47024. PDFDocument.prototype = {
  47025. parse: function PDFDocument_parse(recoveryMode) {
  47026. this.setup(recoveryMode);
  47027. var version = this.catalog.catDict.get('Version');
  47028. if (isName(version)) {
  47029. this.pdfFormatVersion = version.name;
  47030. }
  47031. try {
  47032. // checking if AcroForm is present
  47033. this.acroForm = this.catalog.catDict.get('AcroForm');
  47034. if (this.acroForm) {
  47035. this.xfa = this.acroForm.get('XFA');
  47036. var fields = this.acroForm.get('Fields');
  47037. if ((!fields || !isArray(fields) || fields.length === 0) &&
  47038. !this.xfa) {
  47039. // no fields and no XFA -- not a form (?)
  47040. this.acroForm = null;
  47041. }
  47042. }
  47043. } catch (ex) {
  47044. info('Something wrong with AcroForm entry');
  47045. this.acroForm = null;
  47046. }
  47047. },
  47048. get linearization() {
  47049. var linearization = null;
  47050. if (this.stream.length) {
  47051. try {
  47052. linearization = Linearization.create(this.stream);
  47053. } catch (err) {
  47054. if (err instanceof MissingDataException) {
  47055. throw err;
  47056. }
  47057. info(err);
  47058. }
  47059. }
  47060. // shadow the prototype getter with a data property
  47061. return shadow(this, 'linearization', linearization);
  47062. },
  47063. get startXRef() {
  47064. var stream = this.stream;
  47065. var startXRef = 0;
  47066. var linearization = this.linearization;
  47067. if (linearization) {
  47068. // Find end of first obj.
  47069. stream.reset();
  47070. if (find(stream, 'endobj', 1024)) {
  47071. startXRef = stream.pos + 6;
  47072. }
  47073. } else {
  47074. // Find startxref by jumping backward from the end of the file.
  47075. var step = 1024;
  47076. var found = false, pos = stream.end;
  47077. while (!found && pos > 0) {
  47078. pos -= step - 'startxref'.length;
  47079. if (pos < 0) {
  47080. pos = 0;
  47081. }
  47082. stream.pos = pos;
  47083. found = find(stream, 'startxref', step, true);
  47084. }
  47085. if (found) {
  47086. stream.skip(9);
  47087. var ch;
  47088. do {
  47089. ch = stream.getByte();
  47090. } while (isSpace(ch));
  47091. var str = '';
  47092. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  47093. str += String.fromCharCode(ch);
  47094. ch = stream.getByte();
  47095. }
  47096. startXRef = parseInt(str, 10);
  47097. if (isNaN(startXRef)) {
  47098. startXRef = 0;
  47099. }
  47100. }
  47101. }
  47102. // shadow the prototype getter with a data property
  47103. return shadow(this, 'startXRef', startXRef);
  47104. },
  47105. get mainXRefEntriesOffset() {
  47106. var mainXRefEntriesOffset = 0;
  47107. var linearization = this.linearization;
  47108. if (linearization) {
  47109. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  47110. }
  47111. // shadow the prototype getter with a data property
  47112. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  47113. },
  47114. // Find the header, remove leading garbage and setup the stream
  47115. // starting from the header.
  47116. checkHeader: function PDFDocument_checkHeader() {
  47117. var stream = this.stream;
  47118. stream.reset();
  47119. if (find(stream, '%PDF-', 1024)) {
  47120. // Found the header, trim off any garbage before it.
  47121. stream.moveStart();
  47122. // Reading file format version
  47123. var MAX_VERSION_LENGTH = 12;
  47124. var version = '', ch;
  47125. while ((ch = stream.getByte()) > 0x20) { // SPACE
  47126. if (version.length >= MAX_VERSION_LENGTH) {
  47127. break;
  47128. }
  47129. version += String.fromCharCode(ch);
  47130. }
  47131. if (!this.pdfFormatVersion) {
  47132. // removing "%PDF-"-prefix
  47133. this.pdfFormatVersion = version.substring(5);
  47134. }
  47135. return;
  47136. }
  47137. // May not be a PDF file, continue anyway.
  47138. },
  47139. parseStartXRef: function PDFDocument_parseStartXRef() {
  47140. var startXRef = this.startXRef;
  47141. this.xref.setStartXRef(startXRef);
  47142. },
  47143. setup: function PDFDocument_setup(recoveryMode) {
  47144. this.xref.parse(recoveryMode);
  47145. var self = this;
  47146. var pageFactory = {
  47147. createPage: function (pageIndex, dict, ref, fontCache) {
  47148. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  47149. fontCache);
  47150. }
  47151. };
  47152. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  47153. },
  47154. get numPages() {
  47155. var linearization = this.linearization;
  47156. var num = linearization ? linearization.numPages : this.catalog.numPages;
  47157. // shadow the prototype getter
  47158. return shadow(this, 'numPages', num);
  47159. },
  47160. get documentInfo() {
  47161. var docInfo = {
  47162. PDFFormatVersion: this.pdfFormatVersion,
  47163. IsAcroFormPresent: !!this.acroForm,
  47164. IsXFAPresent: !!this.xfa
  47165. };
  47166. var infoDict;
  47167. try {
  47168. infoDict = this.xref.trailer.get('Info');
  47169. } catch (err) {
  47170. info('The document information dictionary is invalid.');
  47171. }
  47172. if (infoDict) {
  47173. var validEntries = DocumentInfoValidators.entries;
  47174. // Only fill the document info with valid entries from the spec.
  47175. for (var key in validEntries) {
  47176. if (infoDict.has(key)) {
  47177. var value = infoDict.get(key);
  47178. // Make sure the value conforms to the spec.
  47179. if (validEntries[key](value)) {
  47180. docInfo[key] = (typeof value !== 'string' ?
  47181. value : stringToPDFString(value));
  47182. } else {
  47183. info('Bad value in document info for "' + key + '"');
  47184. }
  47185. }
  47186. }
  47187. }
  47188. return shadow(this, 'documentInfo', docInfo);
  47189. },
  47190. get fingerprint() {
  47191. var xref = this.xref, hash, fileID = '';
  47192. var idArray = xref.trailer.get('ID');
  47193. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  47194. idArray[0] !== EMPTY_FINGERPRINT) {
  47195. hash = stringToBytes(idArray[0]);
  47196. } else {
  47197. if (this.stream.ensureRange) {
  47198. this.stream.ensureRange(0,
  47199. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  47200. }
  47201. hash = calculateMD5(this.stream.bytes.subarray(0,
  47202. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  47203. }
  47204. for (var i = 0, n = hash.length; i < n; i++) {
  47205. var hex = hash[i].toString(16);
  47206. fileID += hex.length === 1 ? '0' + hex : hex;
  47207. }
  47208. return shadow(this, 'fingerprint', fileID);
  47209. },
  47210. getPage: function PDFDocument_getPage(pageIndex) {
  47211. return this.catalog.getPage(pageIndex);
  47212. },
  47213. cleanup: function PDFDocument_cleanup() {
  47214. return this.catalog.cleanup();
  47215. }
  47216. };
  47217. return PDFDocument;
  47218. })();
  47219. exports.Page = Page;
  47220. exports.PDFDocument = PDFDocument;
  47221. }));
  47222. (function (root, factory) {
  47223. {
  47224. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  47225. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  47226. root.pdfjsCoreDocument);
  47227. }
  47228. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  47229. coreDocument) {
  47230. var NotImplementedException = sharedUtil.NotImplementedException;
  47231. var MissingDataException = sharedUtil.MissingDataException;
  47232. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47233. var Util = sharedUtil.Util;
  47234. var Stream = coreStream.Stream;
  47235. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  47236. var PDFDocument = coreDocument.PDFDocument;
  47237. var BasePdfManager = (function BasePdfManagerClosure() {
  47238. function BasePdfManager() {
  47239. throw new Error('Cannot initialize BaseManagerManager');
  47240. }
  47241. BasePdfManager.prototype = {
  47242. get docId() {
  47243. return this._docId;
  47244. },
  47245. onLoadedStream: function BasePdfManager_onLoadedStream() {
  47246. throw new NotImplementedException();
  47247. },
  47248. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  47249. return this.ensure(this.pdfDocument, prop, args);
  47250. },
  47251. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  47252. return this.ensure(this.pdfDocument.xref, prop, args);
  47253. },
  47254. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  47255. return this.ensure(this.pdfDocument.catalog, prop, args);
  47256. },
  47257. getPage: function BasePdfManager_getPage(pageIndex) {
  47258. return this.pdfDocument.getPage(pageIndex);
  47259. },
  47260. cleanup: function BasePdfManager_cleanup() {
  47261. return this.pdfDocument.cleanup();
  47262. },
  47263. ensure: function BasePdfManager_ensure(obj, prop, args) {
  47264. return new NotImplementedException();
  47265. },
  47266. requestRange: function BasePdfManager_requestRange(begin, end) {
  47267. return new NotImplementedException();
  47268. },
  47269. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  47270. return new NotImplementedException();
  47271. },
  47272. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  47273. return new NotImplementedException();
  47274. },
  47275. updatePassword: function BasePdfManager_updatePassword(password) {
  47276. this.pdfDocument.xref.password = this.password = password;
  47277. if (this._passwordChangedCapability) {
  47278. this._passwordChangedCapability.resolve();
  47279. }
  47280. },
  47281. passwordChanged: function BasePdfManager_passwordChanged() {
  47282. this._passwordChangedCapability = createPromiseCapability();
  47283. return this._passwordChangedCapability.promise;
  47284. },
  47285. terminate: function BasePdfManager_terminate() {
  47286. return new NotImplementedException();
  47287. }
  47288. };
  47289. return BasePdfManager;
  47290. })();
  47291. var LocalPdfManager = (function LocalPdfManagerClosure() {
  47292. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  47293. this._docId = docId;
  47294. this.evaluatorOptions = evaluatorOptions;
  47295. var stream = new Stream(data);
  47296. this.pdfDocument = new PDFDocument(this, stream, password);
  47297. this._loadedStreamCapability = createPromiseCapability();
  47298. this._loadedStreamCapability.resolve(stream);
  47299. }
  47300. Util.inherit(LocalPdfManager, BasePdfManager, {
  47301. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  47302. return new Promise(function (resolve, reject) {
  47303. try {
  47304. var value = obj[prop];
  47305. var result;
  47306. if (typeof value === 'function') {
  47307. result = value.apply(obj, args);
  47308. } else {
  47309. result = value;
  47310. }
  47311. resolve(result);
  47312. } catch (e) {
  47313. reject(e);
  47314. }
  47315. });
  47316. },
  47317. requestRange: function LocalPdfManager_requestRange(begin, end) {
  47318. return Promise.resolve();
  47319. },
  47320. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  47321. return;
  47322. },
  47323. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  47324. return this._loadedStreamCapability.promise;
  47325. },
  47326. terminate: function LocalPdfManager_terminate() {
  47327. return;
  47328. }
  47329. });
  47330. return LocalPdfManager;
  47331. })();
  47332. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  47333. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  47334. this._docId = docId;
  47335. this.msgHandler = args.msgHandler;
  47336. this.evaluatorOptions = evaluatorOptions;
  47337. var params = {
  47338. msgHandler: args.msgHandler,
  47339. url: args.url,
  47340. length: args.length,
  47341. disableAutoFetch: args.disableAutoFetch,
  47342. rangeChunkSize: args.rangeChunkSize
  47343. };
  47344. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  47345. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  47346. args.password);
  47347. }
  47348. Util.inherit(NetworkPdfManager, BasePdfManager, {
  47349. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  47350. var pdfManager = this;
  47351. return new Promise(function (resolve, reject) {
  47352. function ensureHelper() {
  47353. try {
  47354. var result;
  47355. var value = obj[prop];
  47356. if (typeof value === 'function') {
  47357. result = value.apply(obj, args);
  47358. } else {
  47359. result = value;
  47360. }
  47361. resolve(result);
  47362. } catch(e) {
  47363. if (!(e instanceof MissingDataException)) {
  47364. reject(e);
  47365. return;
  47366. }
  47367. pdfManager.streamManager.requestRange(e.begin, e.end).
  47368. then(ensureHelper, reject);
  47369. }
  47370. }
  47371. ensureHelper();
  47372. });
  47373. },
  47374. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  47375. return this.streamManager.requestRange(begin, end);
  47376. },
  47377. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  47378. this.streamManager.requestAllChunks();
  47379. },
  47380. sendProgressiveData:
  47381. function NetworkPdfManager_sendProgressiveData(chunk) {
  47382. this.streamManager.onReceiveData({ chunk: chunk });
  47383. },
  47384. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  47385. return this.streamManager.onLoadedStream();
  47386. },
  47387. terminate: function NetworkPdfManager_terminate() {
  47388. this.streamManager.abort();
  47389. }
  47390. });
  47391. return NetworkPdfManager;
  47392. })();
  47393. exports.LocalPdfManager = LocalPdfManager;
  47394. exports.NetworkPdfManager = NetworkPdfManager;
  47395. }));
  47396. (function (root, factory) {
  47397. {
  47398. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  47399. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  47400. }
  47401. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  47402. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  47403. var InvalidPDFException = sharedUtil.InvalidPDFException;
  47404. var MessageHandler = sharedUtil.MessageHandler;
  47405. var MissingPDFException = sharedUtil.MissingPDFException;
  47406. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  47407. var PasswordException = sharedUtil.PasswordException;
  47408. var PasswordResponses = sharedUtil.PasswordResponses;
  47409. var UnknownErrorException = sharedUtil.UnknownErrorException;
  47410. var XRefParseException = sharedUtil.XRefParseException;
  47411. var arrayByteLength = sharedUtil.arrayByteLength;
  47412. var arraysToBytes = sharedUtil.arraysToBytes;
  47413. var assert = sharedUtil.assert;
  47414. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47415. var error = sharedUtil.error;
  47416. var info = sharedUtil.info;
  47417. var warn = sharedUtil.warn;
  47418. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  47419. var Ref = corePrimitives.Ref;
  47420. var LocalPdfManager = corePdfManager.LocalPdfManager;
  47421. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  47422. var globalScope = sharedUtil.globalScope;
  47423. var WorkerTask = (function WorkerTaskClosure() {
  47424. function WorkerTask(name) {
  47425. this.name = name;
  47426. this.terminated = false;
  47427. this._capability = createPromiseCapability();
  47428. }
  47429. WorkerTask.prototype = {
  47430. get finished() {
  47431. return this._capability.promise;
  47432. },
  47433. finish: function () {
  47434. this._capability.resolve();
  47435. },
  47436. terminate: function () {
  47437. this.terminated = true;
  47438. },
  47439. ensureNotTerminated: function () {
  47440. if (this.terminated) {
  47441. throw new Error('Worker task was terminated');
  47442. }
  47443. }
  47444. };
  47445. return WorkerTask;
  47446. })();
  47447. /** @implements {IPDFStream} */
  47448. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  47449. function PDFWorkerStream(params, msgHandler) {
  47450. this._queuedChunks = [];
  47451. var initialData = params.initialData;
  47452. if (initialData && initialData.length > 0) {
  47453. this._queuedChunks.push(initialData);
  47454. }
  47455. this._msgHandler = msgHandler;
  47456. this._isRangeSupported = !(params.disableRange);
  47457. this._isStreamingSupported = !(params.disableStream);
  47458. this._contentLength = params.length;
  47459. this._fullRequestReader = null;
  47460. this._rangeReaders = [];
  47461. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  47462. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  47463. }
  47464. PDFWorkerStream.prototype = {
  47465. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  47466. if (args.begin === undefined) {
  47467. if (this._fullRequestReader) {
  47468. this._fullRequestReader._enqueue(args.chunk);
  47469. } else {
  47470. this._queuedChunks.push(args.chunk);
  47471. }
  47472. } else {
  47473. var found = this._rangeReaders.some(function (rangeReader) {
  47474. if (rangeReader._begin !== args.begin) {
  47475. return false;
  47476. }
  47477. rangeReader._enqueue(args.chunk);
  47478. return true;
  47479. });
  47480. assert(found);
  47481. }
  47482. },
  47483. _onProgress: function PDFWorkerStream_onProgress(evt) {
  47484. if (this._rangeReaders.length > 0) {
  47485. // Reporting to first range reader.
  47486. var firstReader = this._rangeReaders[0];
  47487. if (firstReader.onProgress) {
  47488. firstReader.onProgress({loaded: evt.loaded});
  47489. }
  47490. }
  47491. },
  47492. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  47493. var i = this._rangeReaders.indexOf(reader);
  47494. if (i >= 0) {
  47495. this._rangeReaders.splice(i, 1);
  47496. }
  47497. },
  47498. getFullReader: function PDFWorkerStream_getFullReader() {
  47499. assert(!this._fullRequestReader);
  47500. var queuedChunks = this._queuedChunks;
  47501. this._queuedChunks = null;
  47502. return new PDFWorkerStreamReader(this, queuedChunks);
  47503. },
  47504. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  47505. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  47506. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  47507. this._rangeReaders.push(reader);
  47508. return reader;
  47509. },
  47510. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  47511. if (this._fullRequestReader) {
  47512. this._fullRequestReader.cancel(reason);
  47513. }
  47514. var readers = this._rangeReaders.slice(0);
  47515. readers.forEach(function (rangeReader) {
  47516. rangeReader.cancel(reason);
  47517. });
  47518. }
  47519. };
  47520. /** @implements {IPDFStreamReader} */
  47521. function PDFWorkerStreamReader(stream, queuedChunks) {
  47522. this._stream = stream;
  47523. this._done = false;
  47524. this._queuedChunks = queuedChunks || [];
  47525. this._requests = [];
  47526. this._headersReady = Promise.resolve();
  47527. stream._fullRequestReader = this;
  47528. this.onProgress = null; // not used
  47529. }
  47530. PDFWorkerStreamReader.prototype = {
  47531. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  47532. if (this._done) {
  47533. return; // ignore new data
  47534. }
  47535. if (this._requests.length > 0) {
  47536. var requestCapability = this._requests.shift();
  47537. requestCapability.resolve({value: chunk, done: false});
  47538. return;
  47539. }
  47540. this._queuedChunks.push(chunk);
  47541. },
  47542. get headersReady() {
  47543. return this._headersReady;
  47544. },
  47545. get isRangeSupported() {
  47546. return this._stream._isRangeSupported;
  47547. },
  47548. get isStreamingSupported() {
  47549. return this._stream._isStreamingSupported;
  47550. },
  47551. get contentLength() {
  47552. return this._stream._contentLength;
  47553. },
  47554. read: function PDFWorkerStreamReader_read() {
  47555. if (this._queuedChunks.length > 0) {
  47556. var chunk = this._queuedChunks.shift();
  47557. return Promise.resolve({value: chunk, done: false});
  47558. }
  47559. if (this._done) {
  47560. return Promise.resolve({value: undefined, done: true});
  47561. }
  47562. var requestCapability = createPromiseCapability();
  47563. this._requests.push(requestCapability);
  47564. return requestCapability.promise;
  47565. },
  47566. cancel: function PDFWorkerStreamReader_cancel(reason) {
  47567. this._done = true;
  47568. this._requests.forEach(function (requestCapability) {
  47569. requestCapability.resolve({value: undefined, done: true});
  47570. });
  47571. this._requests = [];
  47572. }
  47573. };
  47574. /** @implements {IPDFStreamRangeReader} */
  47575. function PDFWorkerStreamRangeReader(stream, begin, end) {
  47576. this._stream = stream;
  47577. this._begin = begin;
  47578. this._end = end;
  47579. this._queuedChunk = null;
  47580. this._requests = [];
  47581. this._done = false;
  47582. this.onProgress = null;
  47583. }
  47584. PDFWorkerStreamRangeReader.prototype = {
  47585. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  47586. if (this._done) {
  47587. return; // ignore new data
  47588. }
  47589. if (this._requests.length === 0) {
  47590. this._queuedChunk = chunk;
  47591. } else {
  47592. var requestsCapability = this._requests.shift();
  47593. requestsCapability.resolve({value: chunk, done: false});
  47594. this._requests.forEach(function (requestCapability) {
  47595. requestCapability.resolve({value: undefined, done: true});
  47596. });
  47597. this._requests = [];
  47598. }
  47599. this._done = true;
  47600. this._stream._removeRangeReader(this);
  47601. },
  47602. get isStreamingSupported() {
  47603. return false;
  47604. },
  47605. read: function PDFWorkerStreamRangeReader_read() {
  47606. if (this._queuedChunk) {
  47607. return Promise.resolve({value: this._queuedChunk, done: false});
  47608. }
  47609. if (this._done) {
  47610. return Promise.resolve({value: undefined, done: true});
  47611. }
  47612. var requestCapability = createPromiseCapability();
  47613. this._requests.push(requestCapability);
  47614. return requestCapability.promise;
  47615. },
  47616. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  47617. this._done = true;
  47618. this._requests.forEach(function (requestCapability) {
  47619. requestCapability.resolve({value: undefined, done: true});
  47620. });
  47621. this._requests = [];
  47622. this._stream._removeRangeReader(this);
  47623. }
  47624. };
  47625. return PDFWorkerStream;
  47626. })();
  47627. /** @type IPDFStream */
  47628. var PDFNetworkStream;
  47629. /**
  47630. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  47631. * @param {IPDFStream} cls - the PDF data transport.
  47632. */
  47633. function setPDFNetworkStreamClass(cls) {
  47634. PDFNetworkStream = cls;
  47635. }
  47636. var WorkerMessageHandler = {
  47637. setup: function wphSetup(handler, port) {
  47638. var testMessageProcessed = false;
  47639. handler.on('test', function wphSetupTest(data) {
  47640. if (testMessageProcessed) {
  47641. return; // we already processed 'test' message once
  47642. }
  47643. testMessageProcessed = true;
  47644. // check if Uint8Array can be sent to worker
  47645. if (!(data instanceof Uint8Array)) {
  47646. handler.send('test', 'main', false);
  47647. return;
  47648. }
  47649. // making sure postMessage transfers are working
  47650. var supportTransfers = data[0] === 255;
  47651. handler.postMessageTransfers = supportTransfers;
  47652. // check if the response property is supported by xhr
  47653. var xhr = new XMLHttpRequest();
  47654. var responseExists = 'response' in xhr;
  47655. // check if the property is actually implemented
  47656. try {
  47657. var dummy = xhr.responseType;
  47658. } catch (e) {
  47659. responseExists = false;
  47660. }
  47661. if (!responseExists) {
  47662. handler.send('test', false);
  47663. return;
  47664. }
  47665. handler.send('test', {
  47666. supportTypedArray: true,
  47667. supportTransfers: supportTransfers
  47668. });
  47669. });
  47670. handler.on('configure', function wphConfigure(data) {
  47671. setVerbosityLevel(data.verbosity);
  47672. });
  47673. handler.on('GetDocRequest', function wphSetupDoc(data) {
  47674. return WorkerMessageHandler.createDocumentHandler(data, port);
  47675. });
  47676. },
  47677. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  47678. // This context is actually holds references on pdfManager and handler,
  47679. // until the latter is destroyed.
  47680. var pdfManager;
  47681. var terminated = false;
  47682. var cancelXHRs = null;
  47683. var WorkerTasks = [];
  47684. var docId = docParams.docId;
  47685. var workerHandlerName = docParams.docId + '_worker';
  47686. var handler = new MessageHandler(workerHandlerName, docId, port);
  47687. // Ensure that postMessage transfers are correctly enabled/disabled,
  47688. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  47689. handler.postMessageTransfers = docParams.postMessageTransfers;
  47690. function ensureNotTerminated() {
  47691. if (terminated) {
  47692. throw new Error('Worker was terminated');
  47693. }
  47694. }
  47695. function startWorkerTask(task) {
  47696. WorkerTasks.push(task);
  47697. }
  47698. function finishWorkerTask(task) {
  47699. task.finish();
  47700. var i = WorkerTasks.indexOf(task);
  47701. WorkerTasks.splice(i, 1);
  47702. }
  47703. function loadDocument(recoveryMode) {
  47704. var loadDocumentCapability = createPromiseCapability();
  47705. var parseSuccess = function parseSuccess() {
  47706. var numPagesPromise = pdfManager.ensureDoc('numPages');
  47707. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  47708. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  47709. Promise.all([numPagesPromise, fingerprintPromise,
  47710. encryptedPromise]).then(function onDocReady(results) {
  47711. var doc = {
  47712. numPages: results[0],
  47713. fingerprint: results[1],
  47714. encrypted: !!results[2],
  47715. };
  47716. loadDocumentCapability.resolve(doc);
  47717. },
  47718. parseFailure);
  47719. };
  47720. var parseFailure = function parseFailure(e) {
  47721. loadDocumentCapability.reject(e);
  47722. };
  47723. pdfManager.ensureDoc('checkHeader', []).then(function() {
  47724. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  47725. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  47726. parseSuccess, parseFailure);
  47727. }, parseFailure);
  47728. }, parseFailure);
  47729. return loadDocumentCapability.promise;
  47730. }
  47731. function getPdfManager(data, evaluatorOptions) {
  47732. var pdfManagerCapability = createPromiseCapability();
  47733. var pdfManager;
  47734. var source = data.source;
  47735. if (source.data) {
  47736. try {
  47737. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  47738. evaluatorOptions);
  47739. pdfManagerCapability.resolve(pdfManager);
  47740. } catch (ex) {
  47741. pdfManagerCapability.reject(ex);
  47742. }
  47743. return pdfManagerCapability.promise;
  47744. }
  47745. var pdfStream;
  47746. try {
  47747. if (source.chunkedViewerLoading) {
  47748. pdfStream = new PDFWorkerStream(source, handler);
  47749. } else {
  47750. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  47751. pdfStream = new PDFNetworkStream(data);
  47752. }
  47753. } catch (ex) {
  47754. pdfManagerCapability.reject(ex);
  47755. return pdfManagerCapability.promise;
  47756. }
  47757. var fullRequest = pdfStream.getFullReader();
  47758. fullRequest.headersReady.then(function () {
  47759. if (!fullRequest.isStreamingSupported ||
  47760. !fullRequest.isRangeSupported) {
  47761. // If stream or range are disabled, it's our only way to report
  47762. // loading progress.
  47763. fullRequest.onProgress = function (evt) {
  47764. handler.send('DocProgress', {
  47765. loaded: evt.loaded,
  47766. total: evt.total
  47767. });
  47768. };
  47769. }
  47770. if (!fullRequest.isRangeSupported) {
  47771. return;
  47772. }
  47773. // We don't need auto-fetch when streaming is enabled.
  47774. var disableAutoFetch = source.disableAutoFetch ||
  47775. fullRequest.isStreamingSupported;
  47776. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  47777. msgHandler: handler,
  47778. url: source.url,
  47779. password: source.password,
  47780. length: fullRequest.contentLength,
  47781. disableAutoFetch: disableAutoFetch,
  47782. rangeChunkSize: source.rangeChunkSize
  47783. }, evaluatorOptions);
  47784. pdfManagerCapability.resolve(pdfManager);
  47785. cancelXHRs = null;
  47786. }).catch(function (reason) {
  47787. pdfManagerCapability.reject(reason);
  47788. cancelXHRs = null;
  47789. });
  47790. var cachedChunks = [], loaded = 0;
  47791. var flushChunks = function () {
  47792. var pdfFile = arraysToBytes(cachedChunks);
  47793. if (source.length && pdfFile.length !== source.length) {
  47794. warn('reported HTTP length is different from actual');
  47795. }
  47796. // the data is array, instantiating directly from it
  47797. try {
  47798. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  47799. evaluatorOptions);
  47800. pdfManagerCapability.resolve(pdfManager);
  47801. } catch (ex) {
  47802. pdfManagerCapability.reject(ex);
  47803. }
  47804. cachedChunks = [];
  47805. };
  47806. var readPromise = new Promise(function (resolve, reject) {
  47807. var readChunk = function (chunk) {
  47808. try {
  47809. ensureNotTerminated();
  47810. if (chunk.done) {
  47811. if (!pdfManager) {
  47812. flushChunks();
  47813. }
  47814. cancelXHRs = null;
  47815. return;
  47816. }
  47817. var data = chunk.value;
  47818. loaded += arrayByteLength(data);
  47819. if (!fullRequest.isStreamingSupported) {
  47820. handler.send('DocProgress', {
  47821. loaded: loaded,
  47822. total: Math.max(loaded, fullRequest.contentLength || 0)
  47823. });
  47824. }
  47825. if (pdfManager) {
  47826. pdfManager.sendProgressiveData(data);
  47827. } else {
  47828. cachedChunks.push(data);
  47829. }
  47830. fullRequest.read().then(readChunk, reject);
  47831. } catch (e) {
  47832. reject(e);
  47833. }
  47834. };
  47835. fullRequest.read().then(readChunk, reject);
  47836. });
  47837. readPromise.catch(function (e) {
  47838. pdfManagerCapability.reject(e);
  47839. cancelXHRs = null;
  47840. });
  47841. cancelXHRs = function () {
  47842. pdfStream.cancelAllRequests('abort');
  47843. };
  47844. return pdfManagerCapability.promise;
  47845. }
  47846. var setupDoc = function(data) {
  47847. var onSuccess = function(doc) {
  47848. ensureNotTerminated();
  47849. handler.send('GetDoc', { pdfInfo: doc });
  47850. };
  47851. var onFailure = function(e) {
  47852. if (e instanceof PasswordException) {
  47853. if (e.code === PasswordResponses.NEED_PASSWORD) {
  47854. handler.send('NeedPassword', e);
  47855. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  47856. handler.send('IncorrectPassword', e);
  47857. }
  47858. } else if (e instanceof InvalidPDFException) {
  47859. handler.send('InvalidPDF', e);
  47860. } else if (e instanceof MissingPDFException) {
  47861. handler.send('MissingPDF', e);
  47862. } else if (e instanceof UnexpectedResponseException) {
  47863. handler.send('UnexpectedResponse', e);
  47864. } else {
  47865. handler.send('UnknownError',
  47866. new UnknownErrorException(e.message, e.toString()));
  47867. }
  47868. };
  47869. ensureNotTerminated();
  47870. var cMapOptions = {
  47871. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  47872. packed: data.cMapPacked === true
  47873. };
  47874. var evaluatorOptions = {
  47875. forceDataSchema: data.disableCreateObjectURL,
  47876. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  47877. disableFontFace: data.disableFontFace,
  47878. cMapOptions: cMapOptions
  47879. };
  47880. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  47881. if (terminated) {
  47882. // We were in a process of setting up the manager, but it got
  47883. // terminated in the middle.
  47884. newPdfManager.terminate();
  47885. throw new Error('Worker was terminated');
  47886. }
  47887. pdfManager = newPdfManager;
  47888. handler.send('PDFManagerReady', null);
  47889. pdfManager.onLoadedStream().then(function(stream) {
  47890. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  47891. });
  47892. }).then(function pdfManagerReady() {
  47893. ensureNotTerminated();
  47894. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  47895. ensureNotTerminated();
  47896. // Try again with recoveryMode == true
  47897. if (!(ex instanceof XRefParseException)) {
  47898. if (ex instanceof PasswordException) {
  47899. // after password exception prepare to receive a new password
  47900. // to repeat loading
  47901. pdfManager.passwordChanged().then(pdfManagerReady);
  47902. }
  47903. onFailure(ex);
  47904. return;
  47905. }
  47906. pdfManager.requestLoadedStream();
  47907. pdfManager.onLoadedStream().then(function() {
  47908. ensureNotTerminated();
  47909. loadDocument(true).then(onSuccess, onFailure);
  47910. });
  47911. }, onFailure);
  47912. }, onFailure);
  47913. };
  47914. handler.on('GetPage', function wphSetupGetPage(data) {
  47915. return pdfManager.getPage(data.pageIndex).then(function(page) {
  47916. var rotatePromise = pdfManager.ensure(page, 'rotate');
  47917. var refPromise = pdfManager.ensure(page, 'ref');
  47918. var viewPromise = pdfManager.ensure(page, 'view');
  47919. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  47920. function(results) {
  47921. return {
  47922. rotate: results[0],
  47923. ref: results[1],
  47924. view: results[2]
  47925. };
  47926. });
  47927. });
  47928. });
  47929. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  47930. var ref = new Ref(data.ref.num, data.ref.gen);
  47931. var catalog = pdfManager.pdfDocument.catalog;
  47932. return catalog.getPageIndex(ref);
  47933. });
  47934. handler.on('GetDestinations',
  47935. function wphSetupGetDestinations(data) {
  47936. return pdfManager.ensureCatalog('destinations');
  47937. }
  47938. );
  47939. handler.on('GetDestination',
  47940. function wphSetupGetDestination(data) {
  47941. return pdfManager.ensureCatalog('getDestination', [data.id]);
  47942. }
  47943. );
  47944. handler.on('GetPageLabels',
  47945. function wphSetupGetPageLabels(data) {
  47946. return pdfManager.ensureCatalog('pageLabels');
  47947. }
  47948. );
  47949. handler.on('GetAttachments',
  47950. function wphSetupGetAttachments(data) {
  47951. return pdfManager.ensureCatalog('attachments');
  47952. }
  47953. );
  47954. handler.on('GetJavaScript',
  47955. function wphSetupGetJavaScript(data) {
  47956. return pdfManager.ensureCatalog('javaScript');
  47957. }
  47958. );
  47959. handler.on('GetOutline',
  47960. function wphSetupGetOutline(data) {
  47961. return pdfManager.ensureCatalog('documentOutline');
  47962. }
  47963. );
  47964. handler.on('GetMetadata',
  47965. function wphSetupGetMetadata(data) {
  47966. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  47967. pdfManager.ensureCatalog('metadata')]);
  47968. }
  47969. );
  47970. handler.on('GetData', function wphSetupGetData(data) {
  47971. pdfManager.requestLoadedStream();
  47972. return pdfManager.onLoadedStream().then(function(stream) {
  47973. return stream.bytes;
  47974. });
  47975. });
  47976. handler.on('GetStats',
  47977. function wphSetupGetStats(data) {
  47978. return pdfManager.pdfDocument.xref.stats;
  47979. }
  47980. );
  47981. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  47982. pdfManager.updatePassword(data);
  47983. });
  47984. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  47985. return pdfManager.getPage(data.pageIndex).then(function(page) {
  47986. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  47987. });
  47988. });
  47989. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  47990. var pageIndex = data.pageIndex;
  47991. pdfManager.getPage(pageIndex).then(function(page) {
  47992. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  47993. startWorkerTask(task);
  47994. var pageNum = pageIndex + 1;
  47995. var start = Date.now();
  47996. // Pre compile the pdf page and fetch the fonts/images.
  47997. page.getOperatorList(handler, task, data.intent,
  47998. data.renderInteractiveForms).then(
  47999. function(operatorList) {
  48000. finishWorkerTask(task);
  48001. info('page=' + pageNum + ' - getOperatorList: time=' +
  48002. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  48003. }, function(e) {
  48004. finishWorkerTask(task);
  48005. if (task.terminated) {
  48006. return; // ignoring errors from the terminated thread
  48007. }
  48008. // For compatibility with older behavior, generating unknown
  48009. // unsupported feature notification on errors.
  48010. handler.send('UnsupportedFeature',
  48011. {featureId: UNSUPPORTED_FEATURES.unknown});
  48012. var minimumStackMessage =
  48013. 'worker.js: while trying to getPage() and getOperatorList()';
  48014. var wrappedException;
  48015. // Turn the error into an obj that can be serialized
  48016. if (typeof e === 'string') {
  48017. wrappedException = {
  48018. message: e,
  48019. stack: minimumStackMessage
  48020. };
  48021. } else if (typeof e === 'object') {
  48022. wrappedException = {
  48023. message: e.message || e.toString(),
  48024. stack: e.stack || minimumStackMessage
  48025. };
  48026. } else {
  48027. wrappedException = {
  48028. message: 'Unknown exception type: ' + (typeof e),
  48029. stack: minimumStackMessage
  48030. };
  48031. }
  48032. handler.send('PageError', {
  48033. pageNum: pageNum,
  48034. error: wrappedException,
  48035. intent: data.intent
  48036. });
  48037. });
  48038. });
  48039. }, this);
  48040. handler.on('GetTextContent', function wphExtractText(data) {
  48041. var pageIndex = data.pageIndex;
  48042. var normalizeWhitespace = data.normalizeWhitespace;
  48043. var combineTextItems = data.combineTextItems;
  48044. return pdfManager.getPage(pageIndex).then(function(page) {
  48045. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  48046. startWorkerTask(task);
  48047. var pageNum = pageIndex + 1;
  48048. var start = Date.now();
  48049. return page.extractTextContent(task, normalizeWhitespace,
  48050. combineTextItems).then(
  48051. function(textContent) {
  48052. finishWorkerTask(task);
  48053. info('text indexing: page=' + pageNum + ' - time=' +
  48054. (Date.now() - start) + 'ms');
  48055. return textContent;
  48056. }, function (reason) {
  48057. finishWorkerTask(task);
  48058. if (task.terminated) {
  48059. return; // ignoring errors from the terminated thread
  48060. }
  48061. throw reason;
  48062. });
  48063. });
  48064. });
  48065. handler.on('Cleanup', function wphCleanup(data) {
  48066. return pdfManager.cleanup();
  48067. });
  48068. handler.on('Terminate', function wphTerminate(data) {
  48069. terminated = true;
  48070. if (pdfManager) {
  48071. pdfManager.terminate();
  48072. pdfManager = null;
  48073. }
  48074. if (cancelXHRs) {
  48075. cancelXHRs();
  48076. }
  48077. var waitOn = [];
  48078. WorkerTasks.forEach(function (task) {
  48079. waitOn.push(task.finished);
  48080. task.terminate();
  48081. });
  48082. return Promise.all(waitOn).then(function () {
  48083. // Notice that even if we destroying handler, resolved response promise
  48084. // must be sent back.
  48085. handler.destroy();
  48086. handler = null;
  48087. });
  48088. });
  48089. handler.on('Ready', function wphReady(data) {
  48090. setupDoc(docParams);
  48091. docParams = null; // we don't need docParams anymore -- saving memory.
  48092. });
  48093. return workerHandlerName;
  48094. }
  48095. };
  48096. function initializeWorker() {
  48097. if (!('console' in globalScope)) {
  48098. var consoleTimer = {};
  48099. var workerConsole = {
  48100. log: function log() {
  48101. var args = Array.prototype.slice.call(arguments);
  48102. globalScope.postMessage({
  48103. targetName: 'main',
  48104. action: 'console_log',
  48105. data: args
  48106. });
  48107. },
  48108. error: function error() {
  48109. var args = Array.prototype.slice.call(arguments);
  48110. globalScope.postMessage({
  48111. targetName: 'main',
  48112. action: 'console_error',
  48113. data: args
  48114. });
  48115. throw 'pdf.js execution error';
  48116. },
  48117. time: function time(name) {
  48118. consoleTimer[name] = Date.now();
  48119. },
  48120. timeEnd: function timeEnd(name) {
  48121. var time = consoleTimer[name];
  48122. if (!time) {
  48123. error('Unknown timer name ' + name);
  48124. }
  48125. this.log('Timer:', name, Date.now() - time);
  48126. }
  48127. };
  48128. globalScope.console = workerConsole;
  48129. }
  48130. var handler = new MessageHandler('worker', 'main', self);
  48131. WorkerMessageHandler.setup(handler, self);
  48132. handler.send('ready', null);
  48133. }
  48134. // Worker thread (and not node.js)?
  48135. if (typeof window === 'undefined' &&
  48136. !(typeof module !== 'undefined' && module.require)) {
  48137. initializeWorker();
  48138. }
  48139. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  48140. exports.WorkerTask = WorkerTask;
  48141. exports.WorkerMessageHandler = WorkerMessageHandler;
  48142. }));
  48143. var NetworkManager = (function NetworkManagerClosure() {
  48144. var OK_RESPONSE = 200;
  48145. var PARTIAL_CONTENT_RESPONSE = 206;
  48146. function NetworkManager(url, args) {
  48147. this.url = url;
  48148. args = args || {};
  48149. this.isHttp = /^https?:/i.test(url);
  48150. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  48151. this.withCredentials = args.withCredentials || false;
  48152. this.getXhr = args.getXhr ||
  48153. function NetworkManager_getXhr() {
  48154. return new XMLHttpRequest();
  48155. };
  48156. this.currXhrId = 0;
  48157. this.pendingRequests = Object.create(null);
  48158. this.loadedRequests = Object.create(null);
  48159. }
  48160. function getArrayBuffer(xhr) {
  48161. var data = xhr.response;
  48162. if (typeof data !== 'string') {
  48163. return data;
  48164. }
  48165. var length = data.length;
  48166. var array = new Uint8Array(length);
  48167. for (var i = 0; i < length; i++) {
  48168. array[i] = data.charCodeAt(i) & 0xFF;
  48169. }
  48170. return array.buffer;
  48171. }
  48172. var supportsMozChunked = (function supportsMozChunkedClosure() {
  48173. try {
  48174. var x = new XMLHttpRequest();
  48175. // Firefox 37- required .open() to be called before setting responseType.
  48176. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  48177. // Even though the URL is not visited, .open() could fail if the URL is
  48178. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  48179. // When this error occurs, this feature detection method will mistakenly
  48180. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  48181. x.open('GET', 'https://example.com');
  48182. x.responseType = 'moz-chunked-arraybuffer';
  48183. return x.responseType === 'moz-chunked-arraybuffer';
  48184. } catch (e) {
  48185. return false;
  48186. }
  48187. })();
  48188. NetworkManager.prototype = {
  48189. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  48190. var args = {
  48191. begin: begin,
  48192. end: end
  48193. };
  48194. for (var prop in listeners) {
  48195. args[prop] = listeners[prop];
  48196. }
  48197. return this.request(args);
  48198. },
  48199. requestFull: function NetworkManager_requestFull(listeners) {
  48200. return this.request(listeners);
  48201. },
  48202. request: function NetworkManager_request(args) {
  48203. var xhr = this.getXhr();
  48204. var xhrId = this.currXhrId++;
  48205. var pendingRequest = this.pendingRequests[xhrId] = {
  48206. xhr: xhr
  48207. };
  48208. xhr.open('GET', this.url);
  48209. xhr.withCredentials = this.withCredentials;
  48210. for (var property in this.httpHeaders) {
  48211. var value = this.httpHeaders[property];
  48212. if (typeof value === 'undefined') {
  48213. continue;
  48214. }
  48215. xhr.setRequestHeader(property, value);
  48216. }
  48217. if (this.isHttp && 'begin' in args && 'end' in args) {
  48218. var rangeStr = args.begin + '-' + (args.end - 1);
  48219. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  48220. pendingRequest.expectedStatus = 206;
  48221. } else {
  48222. pendingRequest.expectedStatus = 200;
  48223. }
  48224. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  48225. if (useMozChunkedLoading) {
  48226. xhr.responseType = 'moz-chunked-arraybuffer';
  48227. pendingRequest.onProgressiveData = args.onProgressiveData;
  48228. pendingRequest.mozChunked = true;
  48229. } else {
  48230. xhr.responseType = 'arraybuffer';
  48231. }
  48232. if (args.onError) {
  48233. xhr.onerror = function(evt) {
  48234. args.onError(xhr.status);
  48235. };
  48236. }
  48237. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  48238. xhr.onprogress = this.onProgress.bind(this, xhrId);
  48239. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  48240. pendingRequest.onDone = args.onDone;
  48241. pendingRequest.onError = args.onError;
  48242. pendingRequest.onProgress = args.onProgress;
  48243. xhr.send(null);
  48244. return xhrId;
  48245. },
  48246. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  48247. var pendingRequest = this.pendingRequests[xhrId];
  48248. if (!pendingRequest) {
  48249. // Maybe abortRequest was called...
  48250. return;
  48251. }
  48252. if (pendingRequest.mozChunked) {
  48253. var chunk = getArrayBuffer(pendingRequest.xhr);
  48254. pendingRequest.onProgressiveData(chunk);
  48255. }
  48256. var onProgress = pendingRequest.onProgress;
  48257. if (onProgress) {
  48258. onProgress(evt);
  48259. }
  48260. },
  48261. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  48262. var pendingRequest = this.pendingRequests[xhrId];
  48263. if (!pendingRequest) {
  48264. // Maybe abortRequest was called...
  48265. return;
  48266. }
  48267. var xhr = pendingRequest.xhr;
  48268. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  48269. pendingRequest.onHeadersReceived();
  48270. delete pendingRequest.onHeadersReceived;
  48271. }
  48272. if (xhr.readyState !== 4) {
  48273. return;
  48274. }
  48275. if (!(xhrId in this.pendingRequests)) {
  48276. // The XHR request might have been aborted in onHeadersReceived()
  48277. // callback, in which case we should abort request
  48278. return;
  48279. }
  48280. delete this.pendingRequests[xhrId];
  48281. // success status == 0 can be on ftp, file and other protocols
  48282. if (xhr.status === 0 && this.isHttp) {
  48283. if (pendingRequest.onError) {
  48284. pendingRequest.onError(xhr.status);
  48285. }
  48286. return;
  48287. }
  48288. var xhrStatus = xhr.status || OK_RESPONSE;
  48289. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  48290. // "A server MAY ignore the Range header". This means it's possible to
  48291. // get a 200 rather than a 206 response from a range request.
  48292. var ok_response_on_range_request =
  48293. xhrStatus === OK_RESPONSE &&
  48294. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  48295. if (!ok_response_on_range_request &&
  48296. xhrStatus !== pendingRequest.expectedStatus) {
  48297. if (pendingRequest.onError) {
  48298. pendingRequest.onError(xhr.status);
  48299. }
  48300. return;
  48301. }
  48302. this.loadedRequests[xhrId] = true;
  48303. var chunk = getArrayBuffer(xhr);
  48304. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  48305. var rangeHeader = xhr.getResponseHeader('Content-Range');
  48306. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  48307. var begin = parseInt(matches[1], 10);
  48308. pendingRequest.onDone({
  48309. begin: begin,
  48310. chunk: chunk
  48311. });
  48312. } else if (pendingRequest.onProgressiveData) {
  48313. pendingRequest.onDone(null);
  48314. } else if (chunk) {
  48315. pendingRequest.onDone({
  48316. begin: 0,
  48317. chunk: chunk
  48318. });
  48319. } else if (pendingRequest.onError) {
  48320. pendingRequest.onError(xhr.status);
  48321. }
  48322. },
  48323. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  48324. for (var xhrId in this.pendingRequests) {
  48325. return true;
  48326. }
  48327. return false;
  48328. },
  48329. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  48330. return this.pendingRequests[xhrId].xhr;
  48331. },
  48332. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  48333. return !!(this.pendingRequests[xhrId].onProgressiveData);
  48334. },
  48335. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  48336. return xhrId in this.pendingRequests;
  48337. },
  48338. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  48339. return xhrId in this.loadedRequests;
  48340. },
  48341. abortAllRequests: function NetworkManager_abortAllRequests() {
  48342. for (var xhrId in this.pendingRequests) {
  48343. this.abortRequest(xhrId | 0);
  48344. }
  48345. },
  48346. abortRequest: function NetworkManager_abortRequest(xhrId) {
  48347. var xhr = this.pendingRequests[xhrId].xhr;
  48348. delete this.pendingRequests[xhrId];
  48349. xhr.abort();
  48350. }
  48351. };
  48352. return NetworkManager;
  48353. })();
  48354. (function (root, factory) {
  48355. {
  48356. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  48357. root.pdfjsCoreWorker);
  48358. }
  48359. }(this, function (exports, sharedUtil, coreWorker) {
  48360. var assert = sharedUtil.assert;
  48361. var createPromiseCapability = sharedUtil.createPromiseCapability;
  48362. var isInt = sharedUtil.isInt;
  48363. var MissingPDFException = sharedUtil.MissingPDFException;
  48364. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  48365. /** @implements {IPDFStream} */
  48366. function PDFNetworkStream(options) {
  48367. this._options = options;
  48368. var source = options.source;
  48369. this._manager = new NetworkManager(source.url, {
  48370. httpHeaders: source.httpHeaders,
  48371. withCredentials: source.withCredentials
  48372. });
  48373. this._rangeChunkSize = source.rangeChunkSize;
  48374. this._fullRequestReader = null;
  48375. this._rangeRequestReaders = [];
  48376. }
  48377. PDFNetworkStream.prototype = {
  48378. _onRangeRequestReaderClosed:
  48379. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  48380. var i = this._rangeRequestReaders.indexOf(reader);
  48381. if (i >= 0) {
  48382. this._rangeRequestReaders.splice(i, 1);
  48383. }
  48384. },
  48385. getFullReader: function PDFNetworkStream_getFullReader() {
  48386. assert(!this._fullRequestReader);
  48387. this._fullRequestReader =
  48388. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  48389. return this._fullRequestReader;
  48390. },
  48391. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  48392. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  48393. begin, end);
  48394. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  48395. this._rangeRequestReaders.push(reader);
  48396. return reader;
  48397. },
  48398. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  48399. if (this._fullRequestReader) {
  48400. this._fullRequestReader.cancel(reason);
  48401. }
  48402. var readers = this._rangeRequestReaders.slice(0);
  48403. readers.forEach(function (reader) {
  48404. reader.cancel(reason);
  48405. });
  48406. }
  48407. };
  48408. /** @implements {IPDFStreamReader} */
  48409. function PDFNetworkStreamFullRequestReader(manager, options) {
  48410. this._manager = manager;
  48411. var source = options.source;
  48412. var args = {
  48413. onHeadersReceived: this._onHeadersReceived.bind(this),
  48414. onProgressiveData: source.disableStream ? null :
  48415. this._onProgressiveData.bind(this),
  48416. onDone: this._onDone.bind(this),
  48417. onError: this._onError.bind(this),
  48418. onProgress: this._onProgress.bind(this)
  48419. };
  48420. this._url = source.url;
  48421. this._fullRequestId = manager.requestFull(args);
  48422. this._headersReceivedCapability = createPromiseCapability();
  48423. this._disableRange = options.disableRange || false;
  48424. this._contentLength = source.length; // optional
  48425. this._rangeChunkSize = source.rangeChunkSize;
  48426. if (!this._rangeChunkSize && !this._disableRange) {
  48427. this._disableRange = true;
  48428. }
  48429. this._isStreamingSupported = false;
  48430. this._isRangeSupported = false;
  48431. this._cachedChunks = [];
  48432. this._requests = [];
  48433. this._done = false;
  48434. this._storedError = undefined;
  48435. this.onProgress = null;
  48436. }
  48437. PDFNetworkStreamFullRequestReader.prototype = {
  48438. _validateRangeRequestCapabilities: function
  48439. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  48440. if (this._disableRange) {
  48441. return false;
  48442. }
  48443. var networkManager = this._manager;
  48444. var fullRequestXhrId = this._fullRequestId;
  48445. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  48446. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  48447. return false;
  48448. }
  48449. var contentEncoding =
  48450. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  48451. if (contentEncoding !== 'identity') {
  48452. return false;
  48453. }
  48454. var length = fullRequestXhr.getResponseHeader('Content-Length');
  48455. length = parseInt(length, 10);
  48456. if (!isInt(length)) {
  48457. return false;
  48458. }
  48459. this._contentLength = length; // setting right content length
  48460. if (length <= 2 * this._rangeChunkSize) {
  48461. // The file size is smaller than the size of two chunks, so it does
  48462. // not make any sense to abort the request and retry with a range
  48463. // request.
  48464. return false;
  48465. }
  48466. return true;
  48467. },
  48468. _onHeadersReceived:
  48469. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  48470. if (this._validateRangeRequestCapabilities()) {
  48471. this._isRangeSupported = true;
  48472. }
  48473. var networkManager = this._manager;
  48474. var fullRequestXhrId = this._fullRequestId;
  48475. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  48476. // We can continue fetching when progressive loading is enabled,
  48477. // and we don't need the autoFetch feature.
  48478. this._isStreamingSupported = true;
  48479. } else if (this._isRangeSupported) {
  48480. // NOTE: by cancelling the full request, and then issuing range
  48481. // requests, there will be an issue for sites where you can only
  48482. // request the pdf once. However, if this is the case, then the
  48483. // server should not be returning that it can support range
  48484. // requests.
  48485. networkManager.abortRequest(fullRequestXhrId);
  48486. }
  48487. this._headersReceivedCapability.resolve();
  48488. },
  48489. _onProgressiveData:
  48490. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  48491. if (this._requests.length > 0) {
  48492. var requestCapability = this._requests.shift();
  48493. requestCapability.resolve({value: chunk, done: false});
  48494. } else {
  48495. this._cachedChunks.push(chunk);
  48496. }
  48497. },
  48498. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  48499. if (args) {
  48500. this._onProgressiveData(args.chunk);
  48501. }
  48502. this._done = true;
  48503. if (this._cachedChunks.length > 0) {
  48504. return;
  48505. }
  48506. this._requests.forEach(function (requestCapability) {
  48507. requestCapability.resolve({value: undefined, done: true});
  48508. });
  48509. this._requests = [];
  48510. },
  48511. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  48512. var url = this._url;
  48513. var exception;
  48514. if (status === 404 || status === 0 && /^file:/.test(url)) {
  48515. exception = new MissingPDFException('Missing PDF "' + url + '".');
  48516. } else {
  48517. exception = new UnexpectedResponseException(
  48518. 'Unexpected server response (' + status +
  48519. ') while retrieving PDF "' + url + '".', status);
  48520. }
  48521. this._storedError = exception;
  48522. this._headersReceivedCapability.reject(exception);
  48523. this._requests.forEach(function (requestCapability) {
  48524. requestCapability.reject(exception);
  48525. });
  48526. this._requests = [];
  48527. this._cachedChunks = [];
  48528. },
  48529. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  48530. if (this.onProgress) {
  48531. this.onProgress({
  48532. loaded: data.loaded,
  48533. total: data.lengthComputable ? data.total : this._contentLength
  48534. });
  48535. }
  48536. },
  48537. get isRangeSupported() {
  48538. return this._isRangeSupported;
  48539. },
  48540. get isStreamingSupported() {
  48541. return this._isStreamingSupported;
  48542. },
  48543. get contentLength() {
  48544. return this._contentLength;
  48545. },
  48546. get headersReady() {
  48547. return this._headersReceivedCapability.promise;
  48548. },
  48549. read: function PDFNetworkStreamFullRequestReader_read() {
  48550. if (this._storedError) {
  48551. return Promise.reject(this._storedError);
  48552. }
  48553. if (this._cachedChunks.length > 0) {
  48554. var chunk = this._cachedChunks.shift();
  48555. return Promise.resolve(chunk);
  48556. }
  48557. if (this._done) {
  48558. return Promise.resolve({value: undefined, done: true});
  48559. }
  48560. var requestCapability = createPromiseCapability();
  48561. this._requests.push(requestCapability);
  48562. return requestCapability.promise;
  48563. },
  48564. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  48565. this._done = true;
  48566. this._headersReceivedCapability.reject(reason);
  48567. this._requests.forEach(function (requestCapability) {
  48568. requestCapability.resolve({value: undefined, done: true});
  48569. });
  48570. this._requests = [];
  48571. if (this._manager.isPendingRequest(this._fullRequestId)) {
  48572. this._manager.abortRequest(this._fullRequestId);
  48573. }
  48574. this._fullRequestReader = null;
  48575. }
  48576. };
  48577. /** @implements {IPDFStreamRangeReader} */
  48578. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  48579. this._manager = manager;
  48580. var args = {
  48581. onDone: this._onDone.bind(this),
  48582. onProgress: this._onProgress.bind(this)
  48583. };
  48584. this._requestId = manager.requestRange(begin, end, args);
  48585. this._requests = [];
  48586. this._queuedChunk = null;
  48587. this._done = false;
  48588. this.onProgress = null;
  48589. this.onClosed = null;
  48590. }
  48591. PDFNetworkStreamRangeRequestReader.prototype = {
  48592. _close: function PDFNetworkStreamRangeRequestReader_close() {
  48593. if (this.onClosed) {
  48594. this.onClosed(this);
  48595. }
  48596. },
  48597. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  48598. var chunk = data.chunk;
  48599. if (this._requests.length > 0) {
  48600. var requestCapability = this._requests.shift();
  48601. requestCapability.resolve({value: chunk, done: false});
  48602. } else {
  48603. this._queuedChunk = chunk;
  48604. }
  48605. this._done = true;
  48606. this._requests.forEach(function (requestCapability) {
  48607. requestCapability.resolve({value: undefined, done: true});
  48608. });
  48609. this._requests = [];
  48610. this._close();
  48611. },
  48612. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  48613. if (!this.isStreamingSupported && this.onProgress) {
  48614. this.onProgress({
  48615. loaded: evt.loaded
  48616. });
  48617. }
  48618. },
  48619. get isStreamingSupported() {
  48620. return false; // TODO allow progressive range bytes loading
  48621. },
  48622. read: function PDFNetworkStreamRangeRequestReader_read() {
  48623. if (this._queuedChunk !== null) {
  48624. var chunk = this._queuedChunk;
  48625. this._queuedChunk = null;
  48626. return Promise.resolve({value: chunk, done: false});
  48627. }
  48628. if (this._done) {
  48629. return Promise.resolve({value: undefined, done: true});
  48630. }
  48631. var requestCapability = createPromiseCapability();
  48632. this._requests.push(requestCapability);
  48633. return requestCapability.promise;
  48634. },
  48635. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  48636. this._done = true;
  48637. this._requests.forEach(function (requestCapability) {
  48638. requestCapability.resolve({value: undefined, done: true});
  48639. });
  48640. this._requests = [];
  48641. if (this._manager.isPendingRequest(this._requestId)) {
  48642. this._manager.abortRequest(this._requestId);
  48643. }
  48644. this._close();
  48645. }
  48646. };
  48647. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  48648. exports.PDFNetworkStream = PDFNetworkStream;
  48649. exports.NetworkManager = NetworkManager;
  48650. }));
  48651. }).call(pdfjsLibs);
  48652. exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
  48653. exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
  48654. exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
  48655. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  48656. exports.PDFDataRangeTransport =
  48657. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  48658. exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
  48659. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  48660. exports.AnnotationLayer =
  48661. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  48662. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  48663. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  48664. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  48665. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  48666. exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
  48667. exports.UnexpectedResponseException =
  48668. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  48669. exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
  48670. exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  48671. exports.isValidUrl = pdfjsLibs.pdfjsSharedUtil.isValidUrl;
  48672. exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
  48673. exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
  48674. exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
  48675. exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
  48676. exports.getFilenameFromUrl =
  48677. pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
  48678. exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
  48679. }));