12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747 |
- <?php
- require_once(dirname(__FILE__).'/config/tcpdf_config.php');
- class TCPDF {
-
-
- private $tcpdf_version = '5.9.134';
-
-
- protected $page;
-
- protected $n;
-
- protected $offsets;
-
- protected $buffer;
-
- protected $pages = array();
-
- protected $state;
-
- protected $compress;
-
- protected $CurOrientation;
-
- protected $pagedim = array();
-
- protected $k;
-
- protected $fwPt;
-
- protected $fhPt;
-
- protected $wPt;
-
- protected $hPt;
-
- protected $w;
-
- protected $h;
-
- protected $lMargin;
-
- protected $tMargin;
-
- protected $rMargin;
-
- protected $bMargin;
-
- protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
-
- protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
-
- protected $x;
-
- protected $y;
-
- protected $lasth;
-
- protected $LineWidth;
-
- protected $CoreFonts;
-
- protected $fonts = array();
-
- protected $FontFiles = array();
-
- protected $diffs = array();
-
- protected $images = array();
-
- protected $PageAnnots = array();
-
- protected $links = array();
-
- protected $FontFamily;
-
- protected $FontStyle;
-
- protected $FontAscent;
-
- protected $FontDescent;
-
- protected $underline;
-
- protected $overline;
-
- protected $CurrentFont;
-
- protected $FontSizePt;
-
- protected $FontSize;
-
- protected $DrawColor;
-
- protected $FillColor;
-
- protected $TextColor;
-
- protected $ColorFlag;
-
- protected $AutoPageBreak;
-
- protected $PageBreakTrigger;
-
- protected $InHeader = false;
-
- protected $InFooter = false;
-
- protected $ZoomMode;
-
- protected $LayoutMode;
-
- protected $docinfounicode = true;
-
- protected $title = '';
-
- protected $subject = '';
-
- protected $author = '';
-
- protected $keywords = '';
-
- protected $creator = '';
-
- protected $starting_page_number = 1;
-
- protected $alias_tot_pages = '{:ptp:}';
-
- protected $alias_num_page = '{:pnp:}';
-
- protected $alias_group_tot_pages = '{:ptg:}';
-
- protected $alias_group_num_page = '{:png:}';
-
- protected $alias_right_shift = '{rsc:';
-
- protected $img_rb_x;
-
- protected $img_rb_y;
-
- protected $imgscale = 1;
-
- protected $isunicode = false;
-
- protected $unicode;
-
- protected $encmaps;
-
- protected $PDFVersion = '1.7';
-
- protected $header_xobjid = -1;
-
- protected $header_xobj_autoreset = false;
-
- protected $header_margin;
-
- protected $footer_margin;
-
- protected $original_lMargin;
-
- protected $original_rMargin;
-
- protected $header_font;
-
- protected $footer_font;
-
- protected $l;
-
- protected $barcode = false;
-
- protected $print_header = true;
-
- protected $print_footer = true;
-
- protected $header_logo = '';
-
- protected $header_logo_width = 30;
-
- protected $header_title = '';
-
- protected $header_string = '';
-
- protected $default_table_columns = 4;
-
-
- protected $HREF = array();
-
- protected $fontlist = array();
-
- protected $fgcolor;
-
- protected $listordered = array();
-
- protected $listcount = array();
-
- protected $listnum = 0;
-
- protected $listindent = 0;
-
- protected $listindentlevel = 0;
-
- protected $bgcolor;
-
- protected $tempfontsize = 10;
-
- protected $lispacer = '';
-
- protected $encoding = 'UTF-8';
-
- protected $internal_encoding;
-
- protected $rtl = false;
-
- protected $tmprtl = false;
-
-
- protected $encrypted;
-
- protected $encryptdata = array();
-
- protected $last_enc_key;
-
- protected $last_enc_key_c;
-
- protected $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
-
- protected $file_id;
-
-
- protected $outlines = array();
-
- protected $OutlineRoot;
-
-
- protected $javascript = '';
-
- protected $n_js;
-
- protected $linethrough;
-
- protected $ur = array();
-
- protected $dpi = 72;
-
- protected $newpagegroup = array();
-
- protected $pagegroups = array();
-
- protected $currpagegroup = 0;
-
- protected $extgstates;
-
- protected $jpeg_quality;
-
- protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
-
- protected $viewer_preferences;
-
- protected $PageMode;
-
- protected $gradients = array();
-
- protected $intmrk = array();
-
- protected $bordermrk = array();
-
- protected $emptypagemrk = array();
-
- protected $cntmrk = array();
-
- protected $footerpos = array();
-
- protected $footerlen = array();
-
- protected $newline = true;
-
- protected $endlinex = 0;
-
- protected $linestyleWidth = '';
-
- protected $linestyleCap = '0 J';
-
- protected $linestyleJoin = '0 j';
-
- protected $linestyleDash = '[] 0 d';
-
- protected $openMarkedContent = false;
-
- protected $htmlvspace = 0;
-
- protected $spot_colors = array();
-
- protected $lisymbol = '';
-
- protected $epsmarker = 'x#!#EPS#!#x';
-
- protected $transfmatrix = array();
-
- protected $transfmatrix_key = 0;
-
- protected $booklet = false;
-
- protected $feps = 0.005;
-
- protected $tagvspaces = array();
-
- protected $customlistindent = -1;
-
- protected $opencell = true;
-
- protected $embeddedfiles = array();
-
- protected $premode = false;
-
- protected $transfmrk = array();
-
- protected $htmlLinkColorArray = array(0, 0, 255);
-
- protected $htmlLinkFontStyle = 'U';
-
- protected $numpages = 0;
-
- protected $pagelen = array();
-
- protected $numimages = 0;
-
- protected $imagekeys = array();
-
- protected $bufferlen = 0;
-
- protected $diskcache = false;
-
- protected $numfonts = 0;
-
- protected $fontkeys = array();
-
- protected $font_obj_ids = array();
-
- protected $pageopen = array();
-
- protected $default_monospaced_font = 'courier';
-
- protected $objcopy;
-
- protected $cache_file_length = array();
-
- protected $thead = '';
-
- protected $theadMargins = array();
-
- protected $cache_UTF8StringToArray = array();
-
- protected $cache_maxsize_UTF8StringToArray = 8;
-
- protected $cache_size_UTF8StringToArray = 0;
-
- protected $sign = false;
-
- protected $signature_data = array();
-
- protected $signature_max_length = 11742;
-
- protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
-
- protected $empty_signature_appearance = array();
-
- protected $re_spaces = '/[^\S\xa0]/';
-
- protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
-
- protected $sig_obj_id = 0;
-
- protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
-
- protected $sig_annot_ref = '***SIGANNREF*** 0 R';
-
- protected $page_obj_id = array();
-
- protected $form_obj_id = array();
-
- protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
-
- protected $js_objects = array();
-
- protected $form_action = '';
-
- protected $form_enctype = 'application/x-www-form-urlencoded';
-
- protected $form_mode = 'post';
-
- protected $annotation_fonts = array();
-
- protected $radiobutton_groups = array();
-
- protected $radio_groups = array();
-
- protected $textindent = 0;
-
- protected $start_transaction_page = 0;
-
- protected $start_transaction_y = 0;
-
- protected $inthead = false;
-
- protected $columns = array();
-
- protected $num_columns = 1;
-
- protected $current_column = 0;
-
- protected $column_start_page = 0;
-
- protected $maxselcol = array('page' => 0, 'column' => 0);
-
- protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
-
- protected $textrendermode = 0;
-
- protected $textstrokewidth = 0;
-
- protected $strokecolor;
-
- protected $pdfunit = 'mm';
-
- protected $tocpage = false;
-
- protected $rasterize_vector_images = false;
-
- protected $font_subsetting = true;
-
- protected $default_graphic_vars = array();
-
- protected $xobjects = array();
-
- protected $inxobj = false;
-
- protected $xobjid = '';
-
- protected $font_stretching = 100;
-
- protected $font_spacing = 0;
-
- protected $page_regions = array();
-
- protected $webcolor = array();
-
- protected $spotcolor = array();
-
- protected $pdflayers = array();
-
- protected $dests = array();
-
- protected $n_dests;
-
- protected $svgdir = '';
-
- protected $svgunit = 'px';
-
- protected $svggradients = array();
-
- protected $svggradientid = 0;
-
- protected $svgdefsmode = false;
-
- protected $svgdefs = array();
-
- protected $svgclipmode = false;
-
- protected $svgclippaths = array();
-
- protected $svgcliptm = array();
-
- protected $svgclipid = 0;
-
- protected $svgtext = '';
-
- protected $svgtextmode = array();
-
- protected $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode');
-
- protected $svgstyles = array(array(
- 'alignment-baseline' => 'auto',
- 'baseline-shift' => 'baseline',
- 'clip' => 'auto',
- 'clip-path' => 'none',
- 'clip-rule' => 'nonzero',
- 'color' => 'black',
- 'color-interpolation' => 'sRGB',
- 'color-interpolation-filters' => 'linearRGB',
- 'color-profile' => 'auto',
- 'color-rendering' => 'auto',
- 'cursor' => 'auto',
- 'direction' => 'ltr',
- 'display' => 'inline',
- 'dominant-baseline' => 'auto',
- 'enable-background' => 'accumulate',
- 'fill' => 'black',
- 'fill-opacity' => 1,
- 'fill-rule' => 'nonzero',
- 'filter' => 'none',
- 'flood-color' => 'black',
- 'flood-opacity' => 1,
- 'font' => '',
- 'font-family' => 'helvetica',
- 'font-size' => 'medium',
- 'font-size-adjust' => 'none',
- 'font-stretch' => 'normal',
- 'font-style' => 'normal',
- 'font-variant' => 'normal',
- 'font-weight' => 'normal',
- 'glyph-orientation-horizontal' => '0deg',
- 'glyph-orientation-vertical' => 'auto',
- 'image-rendering' => 'auto',
- 'kerning' => 'auto',
- 'letter-spacing' => 'normal',
- 'lighting-color' => 'white',
- 'marker' => '',
- 'marker-end' => 'none',
- 'marker-mid' => 'none',
- 'marker-start' => 'none',
- 'mask' => 'none',
- 'opacity' => 1,
- 'overflow' => 'auto',
- 'pointer-events' => 'visiblePainted',
- 'shape-rendering' => 'auto',
- 'stop-color' => 'black',
- 'stop-opacity' => 1,
- 'stroke' => 'none',
- 'stroke-dasharray' => 'none',
- 'stroke-dashoffset' => 0,
- 'stroke-linecap' => 'butt',
- 'stroke-linejoin' => 'miter',
- 'stroke-miterlimit' => 4,
- 'stroke-opacity' => 1,
- 'stroke-width' => 1,
- 'text-anchor' => 'start',
- 'text-decoration' => 'none',
- 'text-rendering' => 'auto',
- 'unicode-bidi' => 'normal',
- 'visibility' => 'visible',
- 'word-spacing' => 'normal',
- 'writing-mode' => 'lr-tb',
- 'text-color' => 'black',
- 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
- ));
-
- protected $force_srgb = false;
-
- protected $pdfa_mode = false;
-
- protected $doc_date;
-
- protected $custom_xmp = '';
-
-
-
-
- public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
-
- if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
- $this->internal_encoding = mb_internal_encoding();
- mb_internal_encoding('ASCII');
- }
-
- require(dirname(__FILE__).'/htmlcolors.php');
- $this->webcolor = $webcolor;
-
- if (file_exists(dirname(__FILE__).'/spotcolors.php')) {
- require(dirname(__FILE__).'/spotcolors.php');
- $this->spotcolor = $spotcolor;
- } else {
- $this->spotcolor = array();
- }
- require_once(dirname(__FILE__).'/unicode_data.php');
- $this->unicode = new TCPDF_UNICODE_DATA();
- require_once(dirname(__FILE__).'/encodings_maps.php');
- $this->encmaps = new TCPDF_ENCODING_MAPS();
- $this->font_obj_ids = array();
- $this->page_obj_id = array();
- $this->form_obj_id = array();
-
- $this->pdfa_mode = $pdfa;
- $this->force_srgb = false;
-
- $this->diskcache = $diskcache ? true : false;
-
- $this->rtl = false;
- $this->tmprtl = false;
-
- $this->_dochecks();
-
- $this->isunicode = $unicode;
- $this->page = 0;
- $this->transfmrk[0] = array();
- $this->pagedim = array();
- $this->n = 2;
- $this->buffer = '';
- $this->pages = array();
- $this->state = 0;
- $this->fonts = array();
- $this->FontFiles = array();
- $this->diffs = array();
- $this->images = array();
- $this->links = array();
- $this->gradients = array();
- $this->InFooter = false;
- $this->lasth = 0;
- $this->FontFamily = 'helvetica';
- $this->FontStyle = '';
- $this->FontSizePt = 12;
- $this->underline = false;
- $this->overline = false;
- $this->linethrough = false;
- $this->DrawColor = '0 G';
- $this->FillColor = '0 g';
- $this->TextColor = '0 g';
- $this->ColorFlag = false;
- $this->pdflayers = array();
-
- $this->encrypted = false;
- $this->last_enc_key = '';
-
- $this->CoreFonts = array(
- 'courier'=>'Courier',
- 'courierB'=>'Courier-Bold',
- 'courierI'=>'Courier-Oblique',
- 'courierBI'=>'Courier-BoldOblique',
- 'helvetica'=>'Helvetica',
- 'helveticaB'=>'Helvetica-Bold',
- 'helveticaI'=>'Helvetica-Oblique',
- 'helveticaBI'=>'Helvetica-BoldOblique',
- 'times'=>'Times-Roman',
- 'timesB'=>'Times-Bold',
- 'timesI'=>'Times-Italic',
- 'timesBI'=>'Times-BoldItalic',
- 'symbol'=>'Symbol',
- 'zapfdingbats'=>'ZapfDingbats'
- );
-
- $this->setPageUnit($unit);
-
- $this->setPageFormat($format, $orientation);
-
- $margin = 28.35 / $this->k;
- $this->SetMargins($margin, $margin);
-
- $cpadding = $margin / 10;
- $this->setCellPaddings($cpadding, 0, $cpadding, 0);
-
- $this->setCellMargins(0, 0, 0, 0);
-
- $this->LineWidth = 0.57 / $this->k;
- $this->linestyleWidth = sprintf('%.2F w', ($this->LineWidth * $this->k));
- $this->linestyleCap = '0 J';
- $this->linestyleJoin = '0 j';
- $this->linestyleDash = '[] 0 d';
-
- $this->SetAutoPageBreak(true, (2 * $margin));
-
- $this->SetDisplayMode('fullwidth');
-
- $this->SetCompression();
-
- $this->setPDFVersion();
- $this->encoding = $encoding;
- $this->HREF = array();
- $this->getFontsList();
- $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
- $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
- $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
- $this->extgstates = array();
-
- $this->sign = false;
- $this->ur['enabled'] = false;
- $this->ur['document'] = '/FullSave';
- $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
- $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
- $this->ur['signature'] = '/Modify';
- $this->ur['ef'] = '/Create/Delete/Modify/Import';
- $this->ur['formex'] = '';
- $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
- $this->empty_signature_appearance = array();
-
- $this->jpeg_quality = 75;
-
- $this->utf8Bidi(array(''), '');
-
- $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
-
- if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
-
-
-
-
-
- $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
- } else {
-
- $this->setSpacesRE('/[^\S\xa0]/');
- }
- $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
-
- $this->file_id = md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$format.$encoding));
-
- $this->doc_date = substr_replace(date('YmdHisO'), '\'', (0 - 2), 0).'\'';
-
- $this->default_graphic_vars = $this->getGraphicVars();
- $this->header_xobj_autoreset = false;
- $this->custom_xmp = '';
- }
-
- public function __destruct() {
-
- if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
- mb_internal_encoding($this->internal_encoding);
- }
-
- $this->_destroy(true);
- }
-
- public function getTCPDFVersion() {
- return $this->tcpdf_version;
- }
-
- public function setPageUnit($unit) {
- $unit = strtolower($unit);
-
- switch ($unit) {
-
- case 'px':
- case 'pt': {
- $this->k = 1;
- break;
- }
-
- case 'mm': {
- $this->k = $this->dpi / 25.4;
- break;
- }
-
- case 'cm': {
- $this->k = $this->dpi / 2.54;
- break;
- }
-
- case 'in': {
- $this->k = $this->dpi;
- break;
- }
-
- default : {
- $this->Error('Incorrect unit: '.$unit);
- break;
- }
- }
- $this->pdfunit = $unit;
- if (isset($this->CurOrientation)) {
- $this->setPageOrientation($this->CurOrientation);
- }
- }
-
- public function getPageSizeFromFormat($format) {
-
- switch (strtoupper($format)) {
-
- case 'A0' : {$pf = array( 2383.937, 3370.394); break;}
- case 'A1' : {$pf = array( 1683.780, 2383.937); break;}
- case 'A2' : {$pf = array( 1190.551, 1683.780); break;}
- case 'A3' : {$pf = array( 841.890, 1190.551); break;}
- case 'A4' : {$pf = array( 595.276, 841.890); break;}
- case 'A5' : {$pf = array( 419.528, 595.276); break;}
- case 'A6' : {$pf = array( 297.638, 419.528); break;}
- case 'A7' : {$pf = array( 209.764, 297.638); break;}
- case 'A8' : {$pf = array( 147.402, 209.764); break;}
- case 'A9' : {$pf = array( 104.882, 147.402); break;}
- case 'A10': {$pf = array( 73.701, 104.882); break;}
- case 'A11': {$pf = array( 51.024, 73.701); break;}
- case 'A12': {$pf = array( 36.850, 51.024); break;}
-
- case 'B0' : {$pf = array( 2834.646, 4008.189); break;}
- case 'B1' : {$pf = array( 2004.094, 2834.646); break;}
- case 'B2' : {$pf = array( 1417.323, 2004.094); break;}
- case 'B3' : {$pf = array( 1000.630, 1417.323); break;}
- case 'B4' : {$pf = array( 708.661, 1000.630); break;}
- case 'B5' : {$pf = array( 498.898, 708.661); break;}
- case 'B6' : {$pf = array( 354.331, 498.898); break;}
- case 'B7' : {$pf = array( 249.449, 354.331); break;}
- case 'B8' : {$pf = array( 175.748, 249.449); break;}
- case 'B9' : {$pf = array( 124.724, 175.748); break;}
- case 'B10': {$pf = array( 87.874, 124.724); break;}
- case 'B11': {$pf = array( 62.362, 87.874); break;}
- case 'B12': {$pf = array( 42.520, 62.362); break;}
-
- case 'C0' : {$pf = array( 2599.370, 3676.535); break;}
- case 'C1' : {$pf = array( 1836.850, 2599.370); break;}
- case 'C2' : {$pf = array( 1298.268, 1836.850); break;}
- case 'C3' : {$pf = array( 918.425, 1298.268); break;}
- case 'C4' : {$pf = array( 649.134, 918.425); break;}
- case 'C5' : {$pf = array( 459.213, 649.134); break;}
- case 'C6' : {$pf = array( 323.150, 459.213); break;}
- case 'C7' : {$pf = array( 229.606, 323.150); break;}
- case 'C8' : {$pf = array( 161.575, 229.606); break;}
- case 'C9' : {$pf = array( 113.386, 161.575); break;}
- case 'C10': {$pf = array( 79.370, 113.386); break;}
- case 'C11': {$pf = array( 56.693, 79.370); break;}
- case 'C12': {$pf = array( 39.685, 56.693); break;}
- case 'C76': {$pf = array( 229.606, 459.213); break;}
- case 'DL' : {$pf = array( 311.811, 623.622); break;}
-
- case 'E0' : {$pf = array( 2491.654, 3517.795); break;}
- case 'E1' : {$pf = array( 1757.480, 2491.654); break;}
- case 'E2' : {$pf = array( 1247.244, 1757.480); break;}
- case 'E3' : {$pf = array( 878.740, 1247.244); break;}
- case 'E4' : {$pf = array( 623.622, 878.740); break;}
- case 'E5' : {$pf = array( 439.370, 623.622); break;}
- case 'E6' : {$pf = array( 311.811, 439.370); break;}
- case 'E7' : {$pf = array( 221.102, 311.811); break;}
- case 'E8' : {$pf = array( 155.906, 221.102); break;}
- case 'E9' : {$pf = array( 110.551, 155.906); break;}
- case 'E10': {$pf = array( 76.535, 110.551); break;}
- case 'E11': {$pf = array( 53.858, 76.535); break;}
- case 'E12': {$pf = array( 36.850, 53.858); break;}
-
- case 'G0' : {$pf = array( 2715.591, 3838.110); break;}
- case 'G1' : {$pf = array( 1919.055, 2715.591); break;}
- case 'G2' : {$pf = array( 1357.795, 1919.055); break;}
- case 'G3' : {$pf = array( 958.110, 1357.795); break;}
- case 'G4' : {$pf = array( 677.480, 958.110); break;}
- case 'G5' : {$pf = array( 479.055, 677.480); break;}
- case 'G6' : {$pf = array( 337.323, 479.055); break;}
- case 'G7' : {$pf = array( 238.110, 337.323); break;}
- case 'G8' : {$pf = array( 167.244, 238.110); break;}
- case 'G9' : {$pf = array( 119.055, 167.244); break;}
- case 'G10': {$pf = array( 82.205, 119.055); break;}
- case 'G11': {$pf = array( 59.528, 82.205); break;}
- case 'G12': {$pf = array( 39.685, 59.528); break;}
-
- case 'RA0': {$pf = array( 2437.795, 3458.268); break;}
- case 'RA1': {$pf = array( 1729.134, 2437.795); break;}
- case 'RA2': {$pf = array( 1218.898, 1729.134); break;}
- case 'RA3': {$pf = array( 864.567, 1218.898); break;}
- case 'RA4': {$pf = array( 609.449, 864.567); break;}
- case 'SRA0': {$pf = array( 2551.181, 3628.346); break;}
- case 'SRA1': {$pf = array( 1814.173, 2551.181); break;}
- case 'SRA2': {$pf = array( 1275.591, 1814.173); break;}
- case 'SRA3': {$pf = array( 907.087, 1275.591); break;}
- case 'SRA4': {$pf = array( 637.795, 907.087); break;}
-
- case '4A0': {$pf = array( 4767.874, 6740.787); break;}
- case '2A0': {$pf = array( 3370.394, 4767.874); break;}
-
- case 'A2_EXTRA' : {$pf = array( 1261.417, 1754.646); break;}
- case 'A3+' : {$pf = array( 932.598, 1369.134); break;}
- case 'A3_EXTRA' : {$pf = array( 912.756, 1261.417); break;}
- case 'A3_SUPER' : {$pf = array( 864.567, 1440.000); break;}
- case 'SUPER_A3' : {$pf = array( 864.567, 1380.472); break;}
- case 'A4_EXTRA' : {$pf = array( 666.142, 912.756); break;}
- case 'A4_SUPER' : {$pf = array( 649.134, 912.756); break;}
- case 'SUPER_A4' : {$pf = array( 643.465, 1009.134); break;}
- case 'A4_LONG' : {$pf = array( 595.276, 986.457); break;}
- case 'F4' : {$pf = array( 595.276, 935.433); break;}
- case 'SO_B5_EXTRA': {$pf = array( 572.598, 782.362); break;}
- case 'A5_EXTRA' : {$pf = array( 490.394, 666.142); break;}
-
- case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;}
- case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;}
- case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;}
- case 'ANSI_B': {$pf = array( 792.000, 1224.000); break;}
- case 'ANSI_A': {$pf = array( 612.000, 792.000); break;}
-
- case 'USLEDGER':
- case 'LEDGER' : {$pf = array( 1224.000, 792.000); break;}
- case 'ORGANIZERK':
- case 'BIBLE':
- case 'USTABLOID':
- case 'TABLOID': {$pf = array( 792.000, 1224.000); break;}
- case 'ORGANIZERM':
- case 'USLETTER':
- case 'LETTER' : {$pf = array( 612.000, 792.000); break;}
- case 'USLEGAL':
- case 'LEGAL' : {$pf = array( 612.000, 1008.000); break;}
- case 'GOVERNMENTLETTER':
- case 'GLETTER': {$pf = array( 576.000, 756.000); break;}
- case 'JUNIORLEGAL':
- case 'JLEGAL' : {$pf = array( 576.000, 360.000); break;}
-
- case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;}
- case 'SUPER_B': {$pf = array( 936.000, 1368.000); break;}
- case 'QUARTO': {$pf = array( 648.000, 792.000); break;}
- case 'GOVERNMENTLEGAL':
- case 'FOLIO': {$pf = array( 612.000, 936.000); break;}
- case 'MONARCH':
- case 'EXECUTIVE': {$pf = array( 522.000, 756.000); break;}
- case 'ORGANIZERL':
- case 'STATEMENT':
- case 'MEMO': {$pf = array( 396.000, 612.000); break;}
- case 'FOOLSCAP': {$pf = array( 595.440, 936.000); break;}
- case 'COMPACT': {$pf = array( 306.000, 486.000); break;}
- case 'ORGANIZERJ': {$pf = array( 198.000, 360.000); break;}
-
- case 'P1': {$pf = array( 1587.402, 2437.795); break;}
- case 'P2': {$pf = array( 1218.898, 1587.402); break;}
- case 'P3': {$pf = array( 793.701, 1218.898); break;}
- case 'P4': {$pf = array( 609.449, 793.701); break;}
- case 'P5': {$pf = array( 396.850, 609.449); break;}
- case 'P6': {$pf = array( 303.307, 396.850); break;}
-
- case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;}
- case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;}
- case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;}
- case 'BROADSHEET':
- case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;}
- case 'ARCH_B' : {$pf = array( 864.000, 1296.000); break;}
- case 'ARCH_A' : {$pf = array( 648.000, 864.000); break;}
-
-
- case 'ANNENV_A2' : {$pf = array( 314.640, 414.000); break;}
- case 'ANNENV_A6' : {$pf = array( 342.000, 468.000); break;}
- case 'ANNENV_A7' : {$pf = array( 378.000, 522.000); break;}
- case 'ANNENV_A8' : {$pf = array( 396.000, 584.640); break;}
- case 'ANNENV_A10' : {$pf = array( 450.000, 692.640); break;}
- case 'ANNENV_SLIM': {$pf = array( 278.640, 638.640); break;}
-
- case 'COMMENV_N6_1/4': {$pf = array( 252.000, 432.000); break;}
- case 'COMMENV_N6_3/4': {$pf = array( 260.640, 468.000); break;}
- case 'COMMENV_N8' : {$pf = array( 278.640, 540.000); break;}
- case 'COMMENV_N9' : {$pf = array( 278.640, 638.640); break;}
- case 'COMMENV_N10' : {$pf = array( 296.640, 684.000); break;}
- case 'COMMENV_N11' : {$pf = array( 324.000, 746.640); break;}
- case 'COMMENV_N12' : {$pf = array( 342.000, 792.000); break;}
- case 'COMMENV_N14' : {$pf = array( 360.000, 828.000); break;}
-
- case 'CATENV_N1' : {$pf = array( 432.000, 648.000); break;}
- case 'CATENV_N1_3/4' : {$pf = array( 468.000, 684.000); break;}
- case 'CATENV_N2' : {$pf = array( 468.000, 720.000); break;}
- case 'CATENV_N3' : {$pf = array( 504.000, 720.000); break;}
- case 'CATENV_N6' : {$pf = array( 540.000, 756.000); break;}
- case 'CATENV_N7' : {$pf = array( 576.000, 792.000); break;}
- case 'CATENV_N8' : {$pf = array( 594.000, 810.000); break;}
- case 'CATENV_N9_1/2' : {$pf = array( 612.000, 756.000); break;}
- case 'CATENV_N9_3/4' : {$pf = array( 630.000, 810.000); break;}
- case 'CATENV_N10_1/2': {$pf = array( 648.000, 864.000); break;}
- case 'CATENV_N12_1/2': {$pf = array( 684.000, 900.000); break;}
- case 'CATENV_N13_1/2': {$pf = array( 720.000, 936.000); break;}
- case 'CATENV_N14_1/4': {$pf = array( 810.000, 882.000); break;}
- case 'CATENV_N14_1/2': {$pf = array( 828.000, 1044.000); break;}
-
- case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;}
- case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;}
- case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;}
- case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;}
- case 'JIS_B4' : {$pf = array( 728.504, 1031.811); break;}
- case 'JIS_B5' : {$pf = array( 515.906, 728.504); break;}
- case 'JIS_B6' : {$pf = array( 362.835, 515.906); break;}
- case 'JIS_B7' : {$pf = array( 257.953, 362.835); break;}
- case 'JIS_B8' : {$pf = array( 181.417, 257.953); break;}
- case 'JIS_B9' : {$pf = array( 127.559, 181.417); break;}
- case 'JIS_B10': {$pf = array( 90.709, 127.559); break;}
- case 'JIS_B11': {$pf = array( 62.362, 90.709); break;}
- case 'JIS_B12': {$pf = array( 45.354, 62.362); break;}
-
- case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;}
- case 'PA1' : {$pf = array( 1587.402, 2381.102); break;}
- case 'PA2' : {$pf = array( 1190.551, 1587.402); break;}
- case 'PA3' : {$pf = array( 793.701, 1190.551); break;}
- case 'PA4' : {$pf = array( 595.276, 793.701); break;}
- case 'PA5' : {$pf = array( 396.850, 595.276); break;}
- case 'PA6' : {$pf = array( 297.638, 396.850); break;}
- case 'PA7' : {$pf = array( 198.425, 297.638); break;}
- case 'PA8' : {$pf = array( 147.402, 198.425); break;}
- case 'PA9' : {$pf = array( 99.213, 147.402); break;}
- case 'PA10': {$pf = array( 73.701, 99.213); break;}
-
- case 'PASSPORT_PHOTO': {$pf = array( 99.213, 127.559); break;}
- case 'E' : {$pf = array( 233.858, 340.157); break;}
- case 'L':
- case '3R' : {$pf = array( 252.283, 360.000); break;}
- case 'KG':
- case '4R' : {$pf = array( 289.134, 430.866); break;}
- case '4D' : {$pf = array( 340.157, 430.866); break;}
- case '2L':
- case '5R' : {$pf = array( 360.000, 504.567); break;}
- case '8P':
- case '6R' : {$pf = array( 430.866, 575.433); break;}
- case '6P':
- case '8R' : {$pf = array( 575.433, 720.000); break;}
- case '6PW':
- case 'S8R' : {$pf = array( 575.433, 864.567); break;}
- case '4P':
- case '10R' : {$pf = array( 720.000, 864.567); break;}
- case '4PW':
- case 'S10R': {$pf = array( 720.000, 1080.000); break;}
- case '11R' : {$pf = array( 790.866, 1009.134); break;}
- case 'S11R': {$pf = array( 790.866, 1224.567); break;}
- case '12R' : {$pf = array( 864.567, 1080.000); break;}
- case 'S12R': {$pf = array( 864.567, 1292.598); break;}
-
- case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;}
- case 'NEWSPAPER_BERLINER' : {$pf = array( 1332.283, 892.913); break;}
- case 'NEWSPAPER_TABLOID':
- case 'NEWSPAPER_COMPACT' : {$pf = array( 1218.898, 793.701); break;}
-
- case 'CREDIT_CARD':
- case 'BUSINESS_CARD':
- case 'BUSINESS_CARD_ISO7810': {$pf = array( 153.014, 242.646); break;}
- case 'BUSINESS_CARD_ISO216' : {$pf = array( 147.402, 209.764); break;}
- case 'BUSINESS_CARD_IT':
- case 'BUSINESS_CARD_UK':
- case 'BUSINESS_CARD_FR':
- case 'BUSINESS_CARD_DE':
- case 'BUSINESS_CARD_ES' : {$pf = array( 155.906, 240.945); break;}
- case 'BUSINESS_CARD_CA':
- case 'BUSINESS_CARD_US' : {$pf = array( 144.567, 252.283); break;}
- case 'BUSINESS_CARD_JP' : {$pf = array( 155.906, 257.953); break;}
- case 'BUSINESS_CARD_HK' : {$pf = array( 153.071, 255.118); break;}
- case 'BUSINESS_CARD_AU':
- case 'BUSINESS_CARD_DK':
- case 'BUSINESS_CARD_SE' : {$pf = array( 155.906, 255.118); break;}
- case 'BUSINESS_CARD_RU':
- case 'BUSINESS_CARD_CZ':
- case 'BUSINESS_CARD_FI':
- case 'BUSINESS_CARD_HU':
- case 'BUSINESS_CARD_IL' : {$pf = array( 141.732, 255.118); break;}
-
- case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;}
- case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;}
- case '12SHEET': {$pf = array( 8640.000, 4320.000); break;}
- case '16SHEET': {$pf = array( 5760.000, 8640.000); break;}
- case '32SHEET': {$pf = array(11520.000, 8640.000); break;}
- case '48SHEET': {$pf = array(17280.000, 8640.000); break;}
- case '64SHEET': {$pf = array(23040.000, 8640.000); break;}
- case '96SHEET': {$pf = array(34560.000, 8640.000); break;}
-
-
- case 'EN_EMPEROR' : {$pf = array( 3456.000, 5184.000); break;}
- case 'EN_ANTIQUARIAN' : {$pf = array( 2232.000, 3816.000); break;}
- case 'EN_GRAND_EAGLE' : {$pf = array( 2070.000, 3024.000); break;}
- case 'EN_DOUBLE_ELEPHANT' : {$pf = array( 1926.000, 2880.000); break;}
- case 'EN_ATLAS' : {$pf = array( 1872.000, 2448.000); break;}
- case 'EN_COLOMBIER' : {$pf = array( 1692.000, 2484.000); break;}
- case 'EN_ELEPHANT' : {$pf = array( 1656.000, 2016.000); break;}
- case 'EN_DOUBLE_DEMY' : {$pf = array( 1620.000, 2556.000); break;}
- case 'EN_IMPERIAL' : {$pf = array( 1584.000, 2160.000); break;}
- case 'EN_PRINCESS' : {$pf = array( 1548.000, 2016.000); break;}
- case 'EN_CARTRIDGE' : {$pf = array( 1512.000, 1872.000); break;}
- case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;}
- case 'EN_ROYAL' : {$pf = array( 1440.000, 1800.000); break;}
- case 'EN_SHEET':
- case 'EN_HALF_POST' : {$pf = array( 1404.000, 1692.000); break;}
- case 'EN_SUPER_ROYAL' : {$pf = array( 1368.000, 1944.000); break;}
- case 'EN_DOUBLE_POST' : {$pf = array( 1368.000, 2196.000); break;}
- case 'EN_MEDIUM' : {$pf = array( 1260.000, 1656.000); break;}
- case 'EN_DEMY' : {$pf = array( 1260.000, 1620.000); break;}
- case 'EN_LARGE_POST' : {$pf = array( 1188.000, 1512.000); break;}
- case 'EN_COPY_DRAUGHT' : {$pf = array( 1152.000, 1440.000); break;}
- case 'EN_POST' : {$pf = array( 1116.000, 1386.000); break;}
- case 'EN_CROWN' : {$pf = array( 1080.000, 1440.000); break;}
- case 'EN_PINCHED_POST' : {$pf = array( 1062.000, 1332.000); break;}
- case 'EN_BRIEF' : {$pf = array( 972.000, 1152.000); break;}
- case 'EN_FOOLSCAP' : {$pf = array( 972.000, 1224.000); break;}
- case 'EN_SMALL_FOOLSCAP' : {$pf = array( 954.000, 1188.000); break;}
- case 'EN_POTT' : {$pf = array( 900.000, 1080.000); break;}
-
- case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;}
- case 'BE_COLOMBIER' : {$pf = array( 1757.480, 2409.449); break;}
- case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;}
- case 'BE_ELEPHANT' : {$pf = array( 1746.142, 2182.677); break;}
- case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;}
- case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;}
- case 'BE_JESUS' : {$pf = array( 1530.709, 2069.291); break;}
- case 'BE_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
- case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;}
- case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;}
- case 'BE_COQUILLE' : {$pf = array( 1218.898, 1587.402); break;}
- case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;}
- case 'BE_RUCHE' : {$pf = array( 1020.472, 1303.937); break;}
- case 'BE_PROPATRIA' : {$pf = array( 977.953, 1218.898); break;}
- case 'BE_LYS' : {$pf = array( 898.583, 1125.354); break;}
- case 'BE_POT' : {$pf = array( 870.236, 1088.504); break;}
- case 'BE_ROSETTE' : {$pf = array( 765.354, 983.622); break;}
-
- case 'FR_UNIVERS' : {$pf = array( 2834.646, 3685.039); break;}
- case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;}
- case 'FR_GRANDE_MONDE' : {$pf = array( 2551.181, 3571.654); break;}
- case 'FR_DOUBLE_SOLEIL' : {$pf = array( 2267.717, 3401.575); break;}
- case 'FR_DOUBLE_JESUS' : {$pf = array( 2154.331, 3174.803); break;}
- case 'FR_GRAND_AIGLE' : {$pf = array( 2125.984, 3004.724); break;}
- case 'FR_PETIT_AIGLE' : {$pf = array( 1984.252, 2664.567); break;}
- case 'FR_DOUBLE_RAISIN' : {$pf = array( 1842.520, 2834.646); break;}
- case 'FR_JOURNAL' : {$pf = array( 1842.520, 2664.567); break;}
- case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;}
- case 'FR_DOUBLE_CAVALIER' : {$pf = array( 1757.480, 2607.874); break;}
- case 'FR_CLOCHE' : {$pf = array( 1700.787, 2267.717); break;}
- case 'FR_SOLEIL' : {$pf = array( 1700.787, 2267.717); break;}
- case 'FR_DOUBLE_CARRE' : {$pf = array( 1587.402, 2551.181); break;}
- case 'FR_DOUBLE_COQUILLE' : {$pf = array( 1587.402, 2494.488); break;}
- case 'FR_JESUS' : {$pf = array( 1587.402, 2154.331); break;}
- case 'FR_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
- case 'FR_CAVALIER' : {$pf = array( 1303.937, 1757.480); break;}
- case 'FR_DOUBLE_COURONNE' : {$pf = array( 1303.937, 2040.945); break;}
- case 'FR_CARRE' : {$pf = array( 1275.591, 1587.402); break;}
- case 'FR_COQUILLE' : {$pf = array( 1247.244, 1587.402); break;}
- case 'FR_DOUBLE_TELLIERE' : {$pf = array( 1247.244, 1927.559); break;}
- case 'FR_DOUBLE_CLOCHE' : {$pf = array( 1133.858, 1700.787); break;}
- case 'FR_DOUBLE_POT' : {$pf = array( 1133.858, 1757.480); break;}
- case 'FR_ECU' : {$pf = array( 1133.858, 1474.016); break;}
- case 'FR_COURONNE' : {$pf = array( 1020.472, 1303.937); break;}
- case 'FR_TELLIERE' : {$pf = array( 963.780, 1247.244); break;}
- case 'FR_POT' : {$pf = array( 878.740, 1133.858); break;}
-
- default: {$pf = array( 595.276, 841.890); break;}
- }
- return $pf;
- }
-
- protected function setPageFormat($format, $orientation='P') {
- if (!empty($format) AND isset($this->pagedim[$this->page])) {
-
- unset($this->pagedim[$this->page]);
- }
- if (is_string($format)) {
-
- $pf = $this->getPageSizeFromFormat($format);
- $this->fwPt = $pf[0];
- $this->fhPt = $pf[1];
- } else {
-
- if (isset($format['MediaBox'])) {
- $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false);
- $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
- $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
- } else {
- if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
- $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
- } else {
- if (!isset($format['format'])) {
-
- $format['format'] = 'A4';
- }
- $pf = $this->getPageSizeFromFormat($format['format']);
- }
- $this->fwPt = $pf[0];
- $this->fhPt = $pf[1];
- $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
- }
-
- if (isset($format['CropBox'])) {
- $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false);
- }
-
- if (isset($format['BleedBox'])) {
- $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false);
- }
-
- if (isset($format['TrimBox'])) {
- $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false);
- }
-
- if (isset($format['ArtBox'])) {
- $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false);
- }
-
- if (isset($format['BoxColorInfo'])) {
- $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
- }
- if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
-
- $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
- }
- if (isset($format['PZ'])) {
-
- $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
- }
- if (isset($format['trans'])) {
-
- if (isset($format['trans']['Dur'])) {
-
- $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
- }
- $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
- if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
-
- $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
- $valid_effect = array('Split', 'Blinds');
- $valid_vals = array('H', 'V');
- if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
- $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
- }
- $valid_effect = array('Split', 'Box', 'Fly');
- $valid_vals = array('I', 'O');
- if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
- $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
- }
- $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
- if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
- if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
- OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
- OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
- $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
- }
- }
- if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
- $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
- }
- if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
- $this->pagedim[$this->page]['trans']['B'] = 'true';
- }
- } else {
- $this->pagedim[$this->page]['trans']['S'] = 'R';
- }
- if (isset($format['trans']['D'])) {
-
- $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
- } else {
- $this->pagedim[$this->page]['trans']['D'] = 1;
- }
- }
- }
- $this->setPageOrientation($orientation);
- }
-
- public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false) {
- if (!isset($this->pagedim[$page])) {
-
- $this->pagedim[$page] = array();
- }
- $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
- if (!in_array($type, $pageboxes)) {
- return;
- }
- if ($points) {
- $k = 1;
- } else {
- $k = $this->k;
- }
- $this->pagedim[$page][$type]['llx'] = ($llx * $k);
- $this->pagedim[$page][$type]['lly'] = ($lly * $k);
- $this->pagedim[$page][$type]['urx'] = ($urx * $k);
- $this->pagedim[$page][$type]['ury'] = ($ury * $k);
- }
-
- protected function swapPageBoxCoordinates($page) {
- $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
- foreach ($pageboxes as $type) {
-
- if (isset($this->pagedim[$page][$type])) {
- $tmp = $this->pagedim[$page][$type]['llx'];
- $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly'];
- $this->pagedim[$page][$type]['lly'] = $tmp;
- $tmp = $this->pagedim[$page][$type]['urx'];
- $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury'];
- $this->pagedim[$page][$type]['ury'] = $tmp;
- }
- }
- }
-
- public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
- if (!isset($this->pagedim[$this->page]['MediaBox'])) {
-
- $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
- }
- if (!isset($this->pagedim[$this->page]['CropBox'])) {
-
- $this->setPageBoxes($this->page, 'CropBox', $this->pagedim[$this->page]['MediaBox']['llx'], $this->pagedim[$this->page]['MediaBox']['lly'], $this->pagedim[$this->page]['MediaBox']['urx'], $this->pagedim[$this->page]['MediaBox']['ury'], true);
- }
- if (!isset($this->pagedim[$this->page]['BleedBox'])) {
-
- $this->setPageBoxes($this->page, 'BleedBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
- }
- if (!isset($this->pagedim[$this->page]['TrimBox'])) {
-
- $this->setPageBoxes($this->page, 'TrimBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
- }
- if (!isset($this->pagedim[$this->page]['ArtBox'])) {
-
- $this->setPageBoxes($this->page, 'ArtBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
- }
- if (!isset($this->pagedim[$this->page]['Rotate'])) {
-
- $this->pagedim[$this->page]['Rotate'] = 0;
- }
- if (!isset($this->pagedim[$this->page]['PZ'])) {
-
- $this->pagedim[$this->page]['PZ'] = 1;
- }
- if ($this->fwPt > $this->fhPt) {
-
- $default_orientation = 'L';
- } else {
-
- $default_orientation = 'P';
- }
- $valid_orientations = array('P', 'L');
- if (empty($orientation)) {
- $orientation = $default_orientation;
- } else {
- $orientation = strtoupper($orientation{0});
- }
- if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
- $this->CurOrientation = $orientation;
- $this->wPt = $this->fhPt;
- $this->hPt = $this->fwPt;
- } else {
- $this->CurOrientation = $default_orientation;
- $this->wPt = $this->fwPt;
- $this->hPt = $this->fhPt;
- }
- if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
-
- $this->swapPageBoxCoordinates($this->page);
- }
- $this->w = $this->wPt / $this->k;
- $this->h = $this->hPt / $this->k;
- if ($this->empty_string($autopagebreak)) {
- if (isset($this->AutoPageBreak)) {
- $autopagebreak = $this->AutoPageBreak;
- } else {
- $autopagebreak = true;
- }
- }
- if ($this->empty_string($bottommargin)) {
- if (isset($this->bMargin)) {
- $bottommargin = $this->bMargin;
- } else {
-
- $bottommargin = 2 * 28.35 / $this->k;
- }
- }
- $this->SetAutoPageBreak($autopagebreak, $bottommargin);
-
- $this->pagedim[$this->page]['w'] = $this->wPt;
- $this->pagedim[$this->page]['h'] = $this->hPt;
- $this->pagedim[$this->page]['wk'] = $this->w;
- $this->pagedim[$this->page]['hk'] = $this->h;
- $this->pagedim[$this->page]['tm'] = $this->tMargin;
- $this->pagedim[$this->page]['bm'] = $bottommargin;
- $this->pagedim[$this->page]['lm'] = $this->lMargin;
- $this->pagedim[$this->page]['rm'] = $this->rMargin;
- $this->pagedim[$this->page]['pb'] = $autopagebreak;
- $this->pagedim[$this->page]['or'] = $this->CurOrientation;
- $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
- $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
- }
-
- public function setSpacesRE($re='/[^\S\xa0]/') {
- $this->re_spaces = $re;
- $re_parts = explode('/', $re);
-
- $this->re_space = array();
- if (isset($re_parts[1]) AND !empty($re_parts[1])) {
- $this->re_space['p'] = $re_parts[1];
- } else {
- $this->re_space['p'] = '[\s]';
- }
-
- if (isset($re_parts[2]) AND !empty($re_parts[2])) {
- $this->re_space['m'] = $re_parts[2];
- } else {
- $this->re_space['m'] = '';
- }
- }
-
- public function setRTL($enable, $resetx=true) {
- $enable = $enable ? true : false;
- $resetx = ($resetx AND ($enable != $this->rtl));
- $this->rtl = $enable;
- $this->tmprtl = false;
- if ($resetx) {
- $this->Ln(0);
- }
- }
-
- public function getRTL() {
- return $this->rtl;
- }
-
- public function setTempRTL($mode) {
- $newmode = false;
- switch (strtoupper($mode)) {
- case 'LTR':
- case 'L': {
- if ($this->rtl) {
- $newmode = 'L';
- }
- break;
- }
- case 'RTL':
- case 'R': {
- if (!$this->rtl) {
- $newmode = 'R';
- }
- break;
- }
- case false:
- default: {
- $newmode = false;
- break;
- }
- }
- $this->tmprtl = $newmode;
- }
-
- public function isRTLTextDir() {
- return ($this->rtl OR ($this->tmprtl == 'R'));
- }
-
- public function setLastH($h) {
- $this->lasth = $h;
- }
-
- public function resetLastH() {
- $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
- }
-
- public function getLastH() {
- return $this->lasth;
- }
-
- public function setImageScale($scale) {
- $this->imgscale = $scale;
- }
-
- public function getImageScale() {
- return $this->imgscale;
- }
-
- public function getPageDimensions($pagenum='') {
- if (empty($pagenum)) {
- $pagenum = $this->page;
- }
- return $this->pagedim[$pagenum];
- }
-
- public function getPageWidth($pagenum='') {
- if (empty($pagenum)) {
- return $this->w;
- }
- return $this->pagedim[$pagenum]['w'];
- }
-
- public function getPageHeight($pagenum='') {
- if (empty($pagenum)) {
- return $this->h;
- }
- return $this->pagedim[$pagenum]['h'];
- }
-
- public function getBreakMargin($pagenum='') {
- if (empty($pagenum)) {
- return $this->bMargin;
- }
- return $this->pagedim[$pagenum]['bm'];
- }
-
- public function getScaleFactor() {
- return $this->k;
- }
-
- public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
-
- $this->lMargin = $left;
- $this->tMargin = $top;
- if ($right == -1) {
- $right = $left;
- }
- $this->rMargin = $right;
- if ($keepmargins) {
-
- $this->original_lMargin = $this->lMargin;
- $this->original_rMargin = $this->rMargin;
- }
- }
-
- public function SetLeftMargin($margin) {
-
- $this->lMargin = $margin;
- if (($this->page > 0) AND ($this->x < $margin)) {
- $this->x = $margin;
- }
- }
-
- public function SetTopMargin($margin) {
-
- $this->tMargin = $margin;
- if (($this->page > 0) AND ($this->y < $margin)) {
- $this->y = $margin;
- }
- }
-
- public function SetRightMargin($margin) {
- $this->rMargin = $margin;
- if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
- $this->x = $this->w - $margin;
- }
- }
-
- public function SetCellPadding($pad) {
- if ($pad >= 0) {
- $this->cell_padding['L'] = $pad;
- $this->cell_padding['T'] = $pad;
- $this->cell_padding['R'] = $pad;
- $this->cell_padding['B'] = $pad;
- }
- }
-
- public function setCellPaddings($left='', $top='', $right='', $bottom='') {
- if (($left !== '') AND ($left >= 0)) {
- $this->cell_padding['L'] = $left;
- }
- if (($top !== '') AND ($top >= 0)) {
- $this->cell_padding['T'] = $top;
- }
- if (($right !== '') AND ($right >= 0)) {
- $this->cell_padding['R'] = $right;
- }
- if (($bottom !== '') AND ($bottom >= 0)) {
- $this->cell_padding['B'] = $bottom;
- }
- }
-
- public function getCellPaddings() {
- return $this->cell_padding;
- }
-
- public function setCellMargins($left='', $top='', $right='', $bottom='') {
- if (($left !== '') AND ($left >= 0)) {
- $this->cell_margin['L'] = $left;
- }
- if (($top !== '') AND ($top >= 0)) {
- $this->cell_margin['T'] = $top;
- }
- if (($right !== '') AND ($right >= 0)) {
- $this->cell_margin['R'] = $right;
- }
- if (($bottom !== '') AND ($bottom >= 0)) {
- $this->cell_margin['B'] = $bottom;
- }
- }
-
- public function getCellMargins() {
- return $this->cell_margin;
- }
-
- protected function adjustCellPadding($brd=0) {
- if (empty($brd)) {
- return;
- }
- if (is_string($brd)) {
-
- $slen = strlen($brd);
- $newbrd = array();
- for ($i = 0; $i < $slen; ++$i) {
- $newbrd[$brd[$i]] = true;
- }
- $brd = $newbrd;
- } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
- $brd = array('LRTB' => true);
- }
- if (!is_array($brd)) {
- return;
- }
-
- $cp = $this->cell_padding;
-
- if (isset($brd['mode'])) {
- $mode = $brd['mode'];
- unset($brd['mode']);
- } else {
- $mode = 'normal';
- }
-
- foreach ($brd as $border => $style) {
- $line_width = $this->LineWidth;
- if (is_array($style) AND isset($style['width'])) {
-
- $line_width = $style['width'];
- }
- $adj = 0;
- switch ($mode) {
- case 'ext': {
- $adj = 0;
- break;
- }
- case 'int': {
- $adj = $line_width;
- break;
- }
- case 'normal':
- default: {
- $adj = ($line_width / 2);
- break;
- }
- }
-
- if ((strpos($border,'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
- $this->cell_padding['T'] = $adj;
- }
- if ((strpos($border,'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
- $this->cell_padding['R'] = $adj;
- }
- if ((strpos($border,'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
- $this->cell_padding['B'] = $adj;
- }
- if ((strpos($border,'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
- $this->cell_padding['L'] = $adj;
- }
- }
- return array('T' => ($this->cell_padding['T'] - $cp['T']), 'R' => ($this->cell_padding['R'] - $cp['R']), 'B' => ($this->cell_padding['B'] - $cp['B']), 'L' => ($this->cell_padding['L'] - $cp['L']));
- }
-
- public function SetAutoPageBreak($auto, $margin=0) {
- $this->AutoPageBreak = $auto ? true : false;
- $this->bMargin = $margin;
- $this->PageBreakTrigger = $this->h - $margin;
- }
-
- public function getAutoPageBreak() {
- return $this->AutoPageBreak;
- }
-
- public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
- if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
- $this->ZoomMode = $zoom;
- } else {
- $this->Error('Incorrect zoom display mode: '.$zoom);
- }
- switch ($layout) {
- case 'default':
- case 'single':
- case 'SinglePage': {
- $this->LayoutMode = 'SinglePage';
- break;
- }
- case 'continuous':
- case 'OneColumn': {
- $this->LayoutMode = 'OneColumn';
- break;
- }
- case 'two':
- case 'TwoColumnLeft': {
- $this->LayoutMode = 'TwoColumnLeft';
- break;
- }
- case 'TwoColumnRight': {
- $this->LayoutMode = 'TwoColumnRight';
- break;
- }
- case 'TwoPageLeft': {
- $this->LayoutMode = 'TwoPageLeft';
- break;
- }
- case 'TwoPageRight': {
- $this->LayoutMode = 'TwoPageRight';
- break;
- }
- default: {
- $this->LayoutMode = 'SinglePage';
- }
- }
- switch ($mode) {
- case 'UseNone': {
- $this->PageMode = 'UseNone';
- break;
- }
- case 'UseOutlines': {
- $this->PageMode = 'UseOutlines';
- break;
- }
- case 'UseThumbs': {
- $this->PageMode = 'UseThumbs';
- break;
- }
- case 'FullScreen': {
- $this->PageMode = 'FullScreen';
- break;
- }
- case 'UseOC': {
- $this->PageMode = 'UseOC';
- break;
- }
- case '': {
- $this->PageMode = 'UseAttachments';
- break;
- }
- default: {
- $this->PageMode = 'UseNone';
- }
- }
- }
-
- public function SetCompression($compress=true) {
- if (function_exists('gzcompress')) {
- $this->compress = $compress ? true : false;
- } else {
- $this->compress = false;
- }
- }
-
- public function setSRGBmode($mode=false) {
- $this->force_srgb = $mode ? true : false;
- }
-
- public function SetDocInfoUnicode($unicode=true) {
- $this->docinfounicode = $unicode ? true : false;
- }
-
- public function SetTitle($title) {
- $this->title = $title;
- }
-
- public function SetSubject($subject) {
- $this->subject = $subject;
- }
-
- public function SetAuthor($author) {
- $this->author = $author;
- }
-
- public function SetKeywords($keywords) {
- $this->keywords = $keywords;
- }
-
- public function SetCreator($creator) {
- $this->creator = $creator;
- }
-
- public function Error($msg) {
-
- $this->_destroy(true);
-
- die('<strong>TCPDF ERROR: </strong>'.$msg);
- }
-
- public function Open() {
- $this->state = 1;
- }
-
- public function Close() {
- if ($this->state == 3) {
- return;
- }
- if ($this->page == 0) {
- $this->AddPage();
- }
- $this->endLayer();
-
- $gvars = $this->getGraphicVars();
- $this->setEqualColumns();
- $this->lastpage(true);
- $this->SetAutoPageBreak(false);
- $this->x = 0;
- $this->y = $this->h - (1 / $this->k);
- $this->lMargin = 0;
- $this->_out('q');
- $this->SetFont('helvetica', '', 1);
- $this->setTextRenderingMode(0, false, false);
- $msg = "\x50\x6f\x77\x65\x72\x65\x64\x20\x62\x79\x20\x54\x43\x50\x44\x46\x20\x28\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
- $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
- $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
- $this->_out('Q');
-
- $this->setGraphicVars($gvars);
-
- $this->endPage();
-
- $this->_enddoc();
-
- $this->_destroy(false);
- }
-
- public function setPage($pnum, $resetmargins=false) {
- if (($pnum == $this->page) AND ($this->state == 2)) {
- return;
- }
- if (($pnum > 0) AND ($pnum <= $this->numpages)) {
- $this->state = 2;
-
-
- $oldpage = $this->page;
- $this->page = $pnum;
- $this->wPt = $this->pagedim[$this->page]['w'];
- $this->hPt = $this->pagedim[$this->page]['h'];
- $this->w = $this->pagedim[$this->page]['wk'];
- $this->h = $this->pagedim[$this->page]['hk'];
- $this->tMargin = $this->pagedim[$this->page]['tm'];
- $this->bMargin = $this->pagedim[$this->page]['bm'];
- $this->original_lMargin = $this->pagedim[$this->page]['olm'];
- $this->original_rMargin = $this->pagedim[$this->page]['orm'];
- $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
- $this->CurOrientation = $this->pagedim[$this->page]['or'];
- $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
-
-
- if ($resetmargins) {
- $this->lMargin = $this->pagedim[$this->page]['olm'];
- $this->rMargin = $this->pagedim[$this->page]['orm'];
- $this->SetY($this->tMargin);
- } else {
-
- if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
- $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
- $this->lMargin += $deltam;
- $this->rMargin -= $deltam;
- }
- }
- } else {
- $this->Error('Wrong page number on setPage() function: '.$pnum);
- }
- }
-
- public function lastPage($resetmargins=false) {
- $this->setPage($this->getNumPages(), $resetmargins);
- }
-
- public function getPage() {
- return $this->page;
- }
-
- public function getNumPages() {
- return $this->numpages;
- }
-
- public function addTOCPage($orientation='', $format='', $keepmargins=false) {
- $this->AddPage($orientation, $format, $keepmargins, true);
- }
-
- public function endTOCPage() {
- $this->endPage(true);
- }
-
- public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
- if ($this->inxobj) {
-
- return;
- }
- if (!isset($this->original_lMargin) OR $keepmargins) {
- $this->original_lMargin = $this->lMargin;
- }
- if (!isset($this->original_rMargin) OR $keepmargins) {
- $this->original_rMargin = $this->rMargin;
- }
-
- $this->endPage();
-
- $this->startPage($orientation, $format, $tocpage);
- }
-
- public function endPage($tocpage=false) {
-
- if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
- return;
- }
-
- $this->setFooter();
-
- $this->_endpage();
-
- $this->pageopen[$this->page] = false;
- if ($tocpage) {
- $this->tocpage = false;
- }
- }
-
- public function startPage($orientation='', $format='', $tocpage=false) {
- if ($tocpage) {
- $this->tocpage = true;
- }
-
- if ($this->tocpage) {
-
-
- $tmpoutlines = $this->outlines;
- foreach ($tmpoutlines as $key => $outline) {
- if ($outline['p'] > $this->numpages) {
- $this->outlines[$key]['p'] = ($outline['p'] + 1);
- }
- }
-
- $tmpdests = $this->dests;
- foreach ($tmpdests as $key => $dest) {
- if ($dest['p'] > $this->numpages) {
- $this->dests[$key]['p'] = ($dest['p'] + 1);
- }
- }
-
- $tmplinks = $this->links;
- foreach ($tmplinks as $key => $link) {
- if ($link[0] > $this->numpages) {
- $this->links[$key][0] = ($link[0] + 1);
- }
- }
- }
- if ($this->numpages > $this->page) {
-
- $this->setPage($this->page + 1);
- $this->SetY($this->tMargin);
- return;
- }
-
- if ($this->state == 0) {
- $this->Open();
- }
- ++$this->numpages;
- $this->swapMargins($this->booklet);
-
- $gvars = $this->getGraphicVars();
-
- $this->_beginpage($orientation, $format);
-
- $this->pageopen[$this->page] = true;
-
- $this->setGraphicVars($gvars);
-
- $this->setPageMark();
-
- $this->setHeader();
-
- $this->setGraphicVars($gvars);
-
- $this->setPageMark();
-
- $this->setTableHeader();
-
- $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
- }
-
- public function setPageMark() {
- $this->intmrk[$this->page] = $this->pagelen[$this->page];
- $this->bordermrk[$this->page] = $this->intmrk[$this->page];
- $this->setContentMark();
- }
-
- protected function setContentMark($page=0) {
- if ($page <= 0) {
- $page = $this->page;
- }
- if (isset($this->footerlen[$page])) {
- $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
- } else {
- $this->cntmrk[$page] = $this->pagelen[$page];
- }
- }
-
- public function setHeaderData($ln='', $lw=0, $ht='', $hs='') {
- $this->header_logo = $ln;
- $this->header_logo_width = $lw;
- $this->header_title = $ht;
- $this->header_string = $hs;
- }
-
- public function getHeaderData() {
- $ret = array();
- $ret['logo'] = $this->header_logo;
- $ret['logo_width'] = $this->header_logo_width;
- $ret['title'] = $this->header_title;
- $ret['string'] = $this->header_string;
- return $ret;
- }
-
- public function setHeaderMargin($hm=10) {
- $this->header_margin = $hm;
- }
-
- public function getHeaderMargin() {
- return $this->header_margin;
- }
-
- public function setFooterMargin($fm=10) {
- $this->footer_margin = $fm;
- }
-
- public function getFooterMargin() {
- return $this->footer_margin;
- }
-
- public function setPrintHeader($val=true) {
- $this->print_header = $val ? true : false;
- }
-
- public function setPrintFooter($val=true) {
- $this->print_footer = $val ? true : false;
- }
-
- public function getImageRBX() {
- return $this->img_rb_x;
- }
-
- public function getImageRBY() {
- return $this->img_rb_y;
- }
-
- public function resetHeaderTemplate() {
- $this->header_xobjid = -1;
- }
-
- public function setHeaderTemplateAutoreset($val=true) {
- $this->header_xobj_autoreset = $val ? true : false;
- }
-
- public function Header() {
- if ($this->header_xobjid < 0) {
-
- $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
- $headerfont = $this->getHeaderFont();
- $headerdata = $this->getHeaderData();
- $this->y = $this->header_margin;
- if ($this->rtl) {
- $this->x = $this->w - $this->original_rMargin;
- } else {
- $this->x = $this->original_lMargin;
- }
- if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
- $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
- if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
- $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
- } elseif ($imgtype == 'svg') {
- $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
- } else {
- $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
- }
- $imgy = $this->getImageRBY();
- } else {
- $imgy = $this->y;
- }
- $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2);
-
- if ($this->getRTL()) {
- $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
- } else {
- $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
- }
- $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
- $this->SetTextColor(0, 0, 0);
-
- $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
- $this->SetX($header_x);
- $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
-
- $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
- $this->SetX($header_x);
- $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
-
- $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
- $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
- if ($this->rtl) {
- $this->SetX($this->original_rMargin);
- } else {
- $this->SetX($this->original_lMargin);
- }
- $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
- $this->endTemplate();
- }
-
- $x = 0;
- $dx = 0;
- if ($this->booklet AND (($this->page % 2) == 0)) {
-
- $dx = ($this->original_lMargin - $this->original_rMargin);
- }
- if ($this->rtl) {
- $x = $this->w + $dx;
- } else {
- $x = 0 + $dx;
- }
- $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
- if ($this->header_xobj_autoreset) {
-
- $this->header_xobjid = -1;
- }
- }
-
- public function Footer() {
- $cur_y = $this->y;
- $this->SetTextColor(0, 0, 0);
-
- $line_width = 0.85 / $this->k;
- $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
-
- $barcode = $this->getBarcode();
- if (!empty($barcode)) {
- $this->Ln($line_width);
- $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
- $style = array(
- 'position' => $this->rtl?'R':'L',
- 'align' => $this->rtl?'R':'L',
- 'stretch' => false,
- 'fitwidth' => true,
- 'cellfitalign' => '',
- 'border' => false,
- 'padding' => 0,
- 'fgcolor' => array(0,0,0),
- 'bgcolor' => false,
- 'text' => false
- );
- $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
- }
- if (empty($this->pagegroups)) {
- $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
- } else {
- $pagenumtxt = $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
- }
- $this->SetY($cur_y);
-
- if ($this->getRTL()) {
- $this->SetX($this->original_rMargin);
- $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
- } else {
- $this->SetX($this->original_lMargin);
- $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
- }
- }
-
- protected function setHeader() {
- if (!$this->print_header) {
- return;
- }
- $this->InHeader = true;
- $this->setGraphicVars($this->default_graphic_vars);
- $temp_thead = $this->thead;
- $temp_theadMargins = $this->theadMargins;
- $lasth = $this->lasth;
- $this->_out('q');
- $this->rMargin = $this->original_rMargin;
- $this->lMargin = $this->original_lMargin;
- $this->SetCellPadding(0);
-
- if ($this->rtl) {
- $this->SetXY($this->original_rMargin, $this->header_margin);
- } else {
- $this->SetXY($this->original_lMargin, $this->header_margin);
- }
- $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
- $this->Header();
-
- if ($this->rtl) {
- $this->SetXY($this->original_rMargin, $this->tMargin);
- } else {
- $this->SetXY($this->original_lMargin, $this->tMargin);
- }
- $this->_out('Q');
- $this->lasth = $lasth;
- $this->thead = $temp_thead;
- $this->theadMargins = $temp_theadMargins;
- $this->newline = false;
- $this->InHeader = false;
- }
-
- protected function setFooter() {
-
- $this->InFooter = true;
-
- $gvars = $this->getGraphicVars();
-
- $this->footerpos[$this->page] = $this->pagelen[$this->page];
- $this->_out("\n");
- if ($this->print_footer) {
- $this->setGraphicVars($this->default_graphic_vars);
- $this->current_column = 0;
- $this->num_columns = 1;
- $temp_thead = $this->thead;
- $temp_theadMargins = $this->theadMargins;
- $lasth = $this->lasth;
- $this->_out('q');
- $this->rMargin = $this->original_rMargin;
- $this->lMargin = $this->original_lMargin;
- $this->SetCellPadding(0);
-
- $footer_y = $this->h - $this->footer_margin;
- if ($this->rtl) {
- $this->SetXY($this->original_rMargin, $footer_y);
- } else {
- $this->SetXY($this->original_lMargin, $footer_y);
- }
- $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
- $this->Footer();
-
- if ($this->rtl) {
- $this->SetXY($this->original_rMargin, $this->tMargin);
- } else {
- $this->SetXY($this->original_lMargin, $this->tMargin);
- }
- $this->_out('Q');
- $this->lasth = $lasth;
- $this->thead = $temp_thead;
- $this->theadMargins = $temp_theadMargins;
- }
-
- $this->setGraphicVars($gvars);
- $this->current_column = $gvars['current_column'];
- $this->num_columns = $gvars['num_columns'];
-
- $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
- $this->InFooter = false;
- }
-
- protected function inPageBody() {
- return (($this->InHeader === false) AND ($this->InFooter === false));
- }
-
- protected function setTableHeader() {
- if ($this->num_columns > 1) {
-
- return;
- }
- if (isset($this->theadMargins['top'])) {
-
- $this->tMargin = $this->theadMargins['top'];
- $this->pagedim[$this->page]['tm'] = $this->tMargin;
- $this->y = $this->tMargin;
- }
- if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
-
- $prev_lMargin = $this->lMargin;
- $prev_rMargin = $this->rMargin;
- $prev_cell_padding = $this->cell_padding;
- $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
- $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
- $this->cell_padding = $this->theadMargins['cell_padding'];
- if ($this->rtl) {
- $this->x = $this->w - $this->rMargin;
- } else {
- $this->x = $this->lMargin;
- }
-
- if ($this->theadMargins['cell']) {
- if ($this->rtl) {
- $this->x -= $this->cell_padding['R'];
- } else {
- $this->x += $this->cell_padding['L'];
- }
- }
-
- $this->writeHTML($this->thead, false, false, false, false, '');
-
- if (!isset($this->theadMargins['top'])) {
- $this->theadMargins['top'] = $this->tMargin;
- }
-
- if (!isset($this->columns[0]['th'])) {
- $this->columns[0]['th'] = array();
- }
- $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
- $this->tMargin = $this->y;
- $this->pagedim[$this->page]['tm'] = $this->tMargin;
- $this->lasth = 0;
- $this->lMargin = $prev_lMargin;
- $this->rMargin = $prev_rMargin;
- $this->cell_padding = $prev_cell_padding;
- }
- }
-
- public function PageNo() {
- return $this->page;
- }
-
- public function AddSpotColor($name, $c, $m, $y, $k) {
- if (!isset($this->spot_colors[$name])) {
- $i = (1 + count($this->spot_colors));
- $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k);
- }
- }
-
- public function getSpotColor($name) {
- if (isset($this->spot_colors[$name])) {
- return $this->spot_colors[$name];
- }
- $color = preg_replace('/[\s]*/', '', $name);
- $color = strtolower($color);
- if (isset($this->spotcolor[$color])) {
- $this->AddSpotColor($this->spotcolor[$color][4], $this->spotcolor[$color][0], $this->spotcolor[$color][1], $this->spotcolor[$color][2], $this->spotcolor[$color][3]);
- return $this->spot_colors[$name];
- }
- return false;
- }
-
- public function setSpotColor($type, $name, $tint=100) {
- $spotcolor = $this->getSpotColor($name);
- if ($spotcolor === false) {
- $this->Error('Undefined spot color: '.$name.', you must add it on the spotcolors.php file.');
- }
- $tint = (max(0, min(100, $tint)) / 100);
- $intcolor = array('C' => $spotcolor['c'], 'M' => $spotcolor['m'], 'Y' => $spotcolor['y'], 'K' => $spotcolor['k'], 'name' => $spotcolor['i']);
- $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
- switch ($type) {
- case 'draw': {
- $pdfcolor .= sprintf('CS %.3F SCN', $tint);
- $this->DrawColor = $pdfcolor;
- $this->strokecolor = $intcolor;
- break;
- }
- case 'fill': {
- $pdfcolor .= sprintf('cs %.3F scn', $tint);
- $this->FillColor = $pdfcolor;
- $this->bgcolor = $intcolor;
- break;
- }
- case 'text': {
- $pdfcolor .= sprintf('cs %.3F scn', $tint);
- $this->TextColor = $pdfcolor;
- $this->fgcolor = $intcolor;
- break;
- }
- }
- $this->ColorFlag = ($this->FillColor != $this->TextColor);
- if ($this->page > 0) {
- $this->_out($pdfcolor);
- }
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
- }
- return $pdfcolor;
- }
-
- public function SetDrawSpotColor($name, $tint=100) {
- $this->setSpotColor('draw', $name, $tint);
- }
-
- public function SetFillSpotColor($name, $tint=100) {
- $this->setSpotColor('fill', $name, $tint);
- }
-
- public function SetTextSpotColor($name, $tint=100) {
- $this->setSpotColor('text', $name, $tint);
- }
-
- public function setColorArray($type, $color, $ret=false) {
- if (is_array($color)) {
- $color = array_values($color);
-
- $r = isset($color[0]) ? $color[0] : -1;
-
- $g = isset($color[1]) ? $color[1] : -1;
-
- $b = isset($color[2]) ? $color[2] : -1;
-
- $k = isset($color[3]) ? $color[3] : -1;
-
- $name = isset($color[4]) ? $color[4] : '';
- if ($r >= 0) {
- return $this->setColor($type, $r, $g, $b, $k, $ret, $name);
- }
- }
- return '';
- }
-
- public function SetDrawColorArray($color, $ret=false) {
- return $this->setColorArray('draw', $color, $ret);
- }
-
- public function SetFillColorArray($color, $ret=false) {
- return $this->setColorArray('fill', $color, $ret);
- }
-
- public function SetTextColorArray($color, $ret=false) {
- return $this->setColorArray('text', $color, $ret);
- }
-
- public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
-
- if (!is_numeric($col1)) {
- $col1 = 0;
- }
- if (!is_numeric($col2)) {
- $col2 = -1;
- }
- if (!is_numeric($col3)) {
- $col3 = -1;
- }
- if (!is_numeric($col4)) {
- $col4 = -1;
- }
-
- $suffix = '';
- if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
-
- $col1 = max(0, min(255, $col1));
- $intcolor = array('G' => $col1);
- $pdfcolor = sprintf('%.3F ', ($col1 / 255));
- $suffix = 'g';
- } elseif ($col4 == -1) {
-
- $col1 = max(0, min(255, $col1));
- $col2 = max(0, min(255, $col2));
- $col3 = max(0, min(255, $col3));
- $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
- $pdfcolor = sprintf('%.3F %.3F %.3F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
- $suffix = 'rg';
- } else {
- $col1 = max(0, min(100, $col1));
- $col2 = max(0, min(100, $col2));
- $col3 = max(0, min(100, $col3));
- $col4 = max(0, min(100, $col4));
- if (empty($name)) {
-
- $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
- $pdfcolor = sprintf('%.3F %.3F %.3F %.3F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
- $suffix = 'k';
- } else {
-
- $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
- $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
- $pdfcolor = $this->setSpotColor($type, $name, 100);
- }
- }
- switch ($type) {
- case 'draw': {
- $pdfcolor .= strtoupper($suffix);
- $this->DrawColor = $pdfcolor;
- $this->strokecolor = $intcolor;
- break;
- }
- case 'fill': {
- $pdfcolor .= $suffix;
- $this->FillColor = $pdfcolor;
- $this->bgcolor = $intcolor;
- break;
- }
- case 'text': {
- $pdfcolor .= $suffix;
- $this->TextColor = $pdfcolor;
- $this->fgcolor = $intcolor;
- break;
- }
- }
- $this->ColorFlag = ($this->FillColor != $this->TextColor);
- if (($type != 'text') AND ($this->page > 0)) {
- if (!$ret) {
- $this->_out($pdfcolor);
- }
- return $pdfcolor;
- }
- return '';
- }
-
- public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
- return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
- }
-
- public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
- return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
- }
-
- public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
- return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
- }
-
- public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
- return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
- }
-
- public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
-
- if (!$this->empty_string($fontname)) {
- $prev_FontFamily = $this->FontFamily;
- $prev_FontStyle = $this->FontStyle;
- $prev_FontSizePt = $this->FontSizePt;
- $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
- }
-
- $sa = $this->UTF8ArrToLatin1($sa);
- $w = 0;
- $wa = array();
- foreach ($sa as $ck => $char) {
-
- $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
- $wa[] = $cw;
- $w += $cw;
- }
-
- if (!$this->empty_string($fontname)) {
- $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
- }
- if ($getarray) {
- return $wa;
- }
- return $w;
- }
-
- public function GetCharWidth($char, $notlast=true) {
-
- $chw = $this->getRawCharWidth($char);
- if (($this->font_spacing != 0) AND $notlast) {
-
- $chw += $this->font_spacing;
- }
- if ($this->font_stretching != 100) {
-
- $chw *= ($this->font_stretching / 100);
- }
- return $chw;
- }
-
- public function getRawCharWidth($char) {
- if ($char == 173) {
-
- return (0);
- }
- if (isset($this->CurrentFont['cw'][$char])) {
- $w = $this->CurrentFont['cw'][$char];
- } elseif (isset($this->CurrentFont['dw'])) {
-
- $w = $this->CurrentFont['dw'];
- } elseif (isset($this->CurrentFont['cw'][32])) {
-
- $w = $this->CurrentFont['cw'][32];
- } else {
- $w = 600;
- }
- return ($w * $this->FontSize / 1000);
- }
-
- public function GetNumChars($s) {
- if ($this->isUnicodeFont()) {
- return count($this->UTF8StringToArray($s));
- }
- return strlen($s);
- }
-
- protected function getFontsList() {
- $fontsdir = opendir($this->_getfontpath());
- while (($file = readdir($fontsdir)) !== false) {
- if (substr($file, -4) == '.php') {
- array_push($this->fontlist, strtolower(basename($file, '.php')));
- }
- }
- closedir($fontsdir);
- }
-
- public function AddFont($family, $style='', $fontfile='', $subset='default') {
- if ($subset === 'default') {
- $subset = $this->font_subsetting;
- }
- if ($this->pdfa_mode) {
- $subset = false;
- }
- if ($this->empty_string($family)) {
- if (!$this->empty_string($this->FontFamily)) {
- $family = $this->FontFamily;
- } else {
- $this->Error('Empty font family');
- }
- }
-
- if (substr($family, -1) == 'I') {
- $style .= 'I';
- $family = substr($family, 0, -1);
- }
- if (substr($family, -1) == 'B') {
- $style .= 'B';
- $family = substr($family, 0, -1);
- }
-
- $family = strtolower($family);
- if ((!$this->isunicode) AND ($family == 'arial')) {
- $family = 'helvetica';
- }
- if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
- $style = '';
- }
- if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
-
- $family = 'pdfa'.$family;
- }
- $tempstyle = strtoupper($style);
- $style = '';
-
- if (strpos($tempstyle, 'U') !== false) {
- $this->underline = true;
- } else {
- $this->underline = false;
- }
-
- if (strpos($tempstyle, 'D') !== false) {
- $this->linethrough = true;
- } else {
- $this->linethrough = false;
- }
-
- if (strpos($tempstyle, 'O') !== false) {
- $this->overline = true;
- } else {
- $this->overline = false;
- }
-
- if (strpos($tempstyle, 'B') !== false) {
- $style .= 'B';
- }
-
- if (strpos($tempstyle, 'I') !== false) {
- $style .= 'I';
- }
- $bistyle = $style;
- $fontkey = $family.$style;
- $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
- $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
-
- $fb = $this->getFontBuffer($fontkey);
- if ($fb !== false) {
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
- }
- return $fontdata;
- }
- if (isset($type)) {
- unset($type);
- }
- if (isset($cw)) {
- unset($cw);
- }
-
- $fontdir = false;
- if (!$this->empty_string($fontfile)) {
- $fontdir = dirname($fontfile);
- if ($this->empty_string($fontdir) OR ($fontdir == '.')) {
- $fontdir = '';
- } else {
- $fontdir .= '/';
- }
- }
- $missing_style = false;
-
- if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) {
-
- $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
-
- if (($fontdir !== false) AND file_exists($fontdir.$tmp_fontfile)) {
- $fontfile = $fontdir.$tmp_fontfile;
- } elseif (file_exists($this->_getfontpath().$tmp_fontfile)) {
- $fontfile = $this->_getfontpath().$tmp_fontfile;
- } elseif (file_exists($tmp_fontfile)) {
- $fontfile = $tmp_fontfile;
- } elseif (!$this->empty_string($style)) {
- $missing_style = true;
-
- $tmp_fontfile = str_replace(' ', '', $family).'.php';
- if (($fontdir !== false) AND file_exists($fontdir.$tmp_fontfile)) {
- $fontfile = $fontdir.$tmp_fontfile;
- } elseif (file_exists($this->_getfontpath().$tmp_fontfile)) {
- $fontfile = $this->_getfontpath().$tmp_fontfile;
- } else {
- $fontfile = $tmp_fontfile;
- }
- }
- }
-
- if (file_exists($fontfile)) {
- include($fontfile);
- } else {
- $this->Error('Could not include font definition file: '.$family.'');
- }
-
- if ((!isset($type)) OR (!isset($cw))) {
- $this->Error('The font definition file has a bad format: '.$fontfile.'');
- }
-
- if (!isset($file) OR $this->empty_string($file)) {
- $file = '';
- }
- if (!isset($enc) OR $this->empty_string($enc)) {
- $enc = '';
- }
- if (!isset($cidinfo) OR $this->empty_string($cidinfo)) {
- $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
- $cidinfo['uni2cid'] = array();
- }
- if (!isset($ctg) OR $this->empty_string($ctg)) {
- $ctg = '';
- }
- if (!isset($desc) OR $this->empty_string($desc)) {
- $desc = array();
- }
- if (!isset($up) OR $this->empty_string($up)) {
- $up = -100;
- }
- if (!isset($ut) OR $this->empty_string($ut)) {
- $ut = 50;
- }
- if (!isset($cw) OR $this->empty_string($cw)) {
- $cw = array();
- }
- if (!isset($dw) OR $this->empty_string($dw)) {
-
- if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
- $dw = $desc['MissingWidth'];
- } elseif (isset($cw[32])) {
- $dw = $cw[32];
- } else {
- $dw = 600;
- }
- }
- ++$this->numfonts;
- if ($type == 'core') {
- $name = $this->CoreFonts[$fontkey];
- $subset = false;
- } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
- $subset = false;
- } elseif ($type == 'TrueTypeUnicode') {
- $enc = 'Identity-H';
- } elseif ($type == 'cidfont0') {
- if ($this->pdfa_mode) {
- $this->Error('All fonts must be embedded in PDF/A mode!');
- }
- } else {
- $this->Error('Unknow font type: '.$type.'');
- }
-
- if (!isset($name) OR empty($name)) {
- $name = $fontkey;
- }
-
- if (($type != 'core') AND $missing_style) {
-
- $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
- $name .= $styles[$bistyle];
-
- if (strpos($bistyle, 'B') !== false) {
- if (isset($desc['StemV'])) {
-
- $desc['StemV'] = round($desc['StemV'] * 1.75);
- } else {
-
- $desc['StemV'] = 123;
- }
- }
-
- if (strpos($bistyle, 'I') !== false) {
- if (isset($desc['ItalicAngle'])) {
- $desc['ItalicAngle'] -= 11;
- } else {
- $desc['ItalicAngle'] = -11;
- }
- if (isset($desc['Flags'])) {
- $desc['Flags'] |= 64;
- } else {
- $desc['Flags'] = 64;
- }
- }
- }
-
- $subsetchars = array_fill(0, 256, true);
- $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
- }
- if (isset($diff) AND (!empty($diff))) {
-
- $d = 0;
- $nb = count($this->diffs);
- for ($i=1; $i <= $nb; ++$i) {
- if ($this->diffs[$i] == $diff) {
- $d = $i;
- break;
- }
- }
- if ($d == 0) {
- $d = $nb + 1;
- $this->diffs[$d] = $diff;
- }
- $this->setFontSubBuffer($fontkey, 'diff', $d);
- }
- if (!$this->empty_string($file)) {
- if (!isset($this->FontFiles[$file])) {
- if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
- $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
- } elseif ($type != 'core') {
- $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
- }
- } else {
-
- $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
- if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
- $this->FontFiles[$file]['fontkeys'][] = $fontkey;
- }
- }
- }
- return $fontdata;
- }
-
- public function SetFont($family, $style='', $size=0, $fontfile='', $subset='default', $out=true) {
-
- if ($size == 0) {
- $size = $this->FontSizePt;
- }
-
- $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
- $this->FontFamily = $fontdata['family'];
- $this->FontStyle = $fontdata['style'];
- $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
- $this->SetFontSize($size, $out);
- }
-
- public function SetFontSize($size, $out=true) {
-
- $this->FontSizePt = $size;
-
- $this->FontSize = $size / $this->k;
-
- if (isset($this->CurrentFont['desc']['FontBBox'])) {
- $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
- $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
- } else {
- $font_height = $size * 1.219;
- }
- if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
- $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
- }
- if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
- $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
- }
- if (!isset($font_ascent) AND !isset($font_descent)) {
-
- $font_ascent = 0.76 * $font_height;
- $font_descent = $font_height - $font_ascent;
- } elseif (!isset($font_descent)) {
- $font_descent = $font_height - $font_ascent;
- } elseif (!isset($font_ascent)) {
- $font_ascent = $font_height - $font_descent;
- }
- $this->FontAscent = ($font_ascent / $this->k);
- $this->FontDescent = ($font_descent / $this->k);
- if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i']))) {
- $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
- }
- }
-
- public function getFontDescent($font, $style='', $size=0) {
- $fontdata = $this->AddFont($font, $style);
- $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
- if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
- $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
- } else {
- $descent = 1.219 * 0.24 * $size;
- }
- return ($descent / $this->k);
- }
-
- public function getFontAscent($font, $style='', $size=0) {
- $fontdata = $this->AddFont($font, $style);
- $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
- if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
- $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
- } else {
- $ascent = 1.219 * 0.76 * $size;
- }
- return ($ascent / $this->k);
- }
-
- public function SetDefaultMonospacedFont($font) {
- $this->default_monospaced_font = $font;
- }
-
- public function AddLink() {
-
- $n = count($this->links) + 1;
- $this->links[$n] = array(0, 0);
- return $n;
- }
-
- public function SetLink($link, $y=0, $page=-1) {
- if ($y == -1) {
- $y = $this->y;
- }
- if ($page == -1) {
- $page = $this->page;
- }
- $this->links[$link] = array($page, $y);
- }
-
- public function Link($x, $y, $w, $h, $link, $spaces=0) {
- $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
- }
-
- public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
- return;
- }
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
-
- if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
- for ($i=$this->transfmatrix_key; $i > 0; --$i) {
- $maxid = count($this->transfmatrix[$i]) - 1;
- for ($j=$maxid; $j >= 0; --$j) {
- $ctm = $this->transfmatrix[$i][$j];
- if (isset($ctm['a'])) {
- $x = $x * $this->k;
- $y = ($this->h - $y) * $this->k;
- $w = $w * $this->k;
- $h = $h * $this->k;
-
- $xt = $x;
- $yt = $y;
- $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
- $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
-
- $xt = $x + $w;
- $yt = $y;
- $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
- $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
-
- $xt = $x;
- $yt = $y - $h;
- $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
- $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
-
- $xt = $x + $w;
- $yt = $y - $h;
- $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
- $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
-
- $x = min($x1, $x2, $x3, $x4);
- $y = max($y1, $y2, $y3, $y4);
- $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
- $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
- $x = $x / $this->k;
- $y = $this->h - ($y / $this->k);
- }
- }
- }
- }
- if ($this->page <= 0) {
- $page = 1;
- } else {
- $page = $this->page;
- }
- if (!isset($this->PageAnnots[$page])) {
- $this->PageAnnots[$page] = array();
- }
- ++$this->n;
- $this->PageAnnots[$page][] = array('n' => $this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
- if (!$this->pdfa_mode) {
- if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!$this->empty_string($opt['FS'])) AND file_exists($opt['FS']) AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
- ++$this->n;
- $this->embeddedfiles[basename($opt['FS'])] = array('n' => $this->n, 'file' => $opt['FS']);
- }
- }
-
- if (isset($opt['mk']['i']) AND file_exists($opt['mk']['i'])) {
- $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
- }
- if (isset($opt['mk']['ri']) AND file_exists($opt['mk']['ri'])) {
- $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
- }
- if (isset($opt['mk']['ix']) AND file_exists($opt['mk']['ix'])) {
- $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
- }
- }
-
- protected function _putEmbeddedFiles() {
- if ($this->pdfa_mode) {
-
- return;
- }
- reset($this->embeddedfiles);
- foreach ($this->embeddedfiles as $filename => $filedata) {
- $data = file_get_contents($filedata['file']);
- $filter = '';
- if ($this->compress) {
- $data = gzcompress($data);
- $filter = ' /Filter /FlateDecode';
- }
- $stream = $this->_getrawstream($data, $filedata['n']);
- $out = $this->_getobj($filedata['n'])."\n";
- $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' >>';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
-
- public function Text($x, $y, $txt, $fstroke=false, $fclip=false, $ffill=true, $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M', $rtloff=false) {
- $textrendermode = $this->textrendermode;
- $textstrokewidth = $this->textstrokewidth;
- $this->setTextRenderingMode($fstroke, $ffill, $fclip);
- $this->SetXY($x, $y, $rtloff);
- $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
-
- $this->textrendermode = $textrendermode;
- $this->textstrokewidth = $textstrokewidth;
- }
-
- public function AcceptPageBreak() {
- if ($this->num_columns > 1) {
-
- if ($this->current_column < ($this->num_columns - 1)) {
-
- $this->selectColumn($this->current_column + 1);
- } else {
-
- $this->AddPage();
-
- $this->selectColumn(0);
- }
-
- return false;
- }
- return $this->AutoPageBreak;
- }
-
- protected function checkPageBreak($h=0, $y='', $addpage=true) {
- if ($this->empty_string($y)) {
- $y = $this->y;
- }
- $current_page = $this->page;
- if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
- if ($addpage) {
-
- $x = $this->x;
- $this->AddPage($this->CurOrientation);
- $this->y = $this->tMargin;
- $oldpage = $this->page - 1;
- if ($this->rtl) {
- if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
- $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
- } else {
- $this->x = $x;
- }
- } else {
- if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
- $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
- } else {
- $this->x = $x;
- }
- }
- }
- return true;
- }
- if ($current_page != $this->page) {
-
- return true;
- }
- return false;
- }
-
- public function removeSHY($txt='') {
- $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
- if (!$this->isunicode) {
- $txt = preg_replace('/([\\xad]{1})/', '', $txt);
- }
- return $txt;
- }
-
- public function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') {
- $prev_cell_margin = $this->cell_margin;
- $prev_cell_padding = $this->cell_padding;
- $this->adjustCellPadding($border);
- if (!$ignore_min_height) {
- $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
- if ($h < $min_cell_height) {
- $h = $min_cell_height;
- }
- }
- $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
- $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
- $this->cell_padding = $prev_cell_padding;
- $this->cell_margin = $prev_cell_margin;
- }
-
- protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') {
-
- $txt = str_replace($this->unichr(160), ' ', $txt);
- $prev_cell_margin = $this->cell_margin;
- $prev_cell_padding = $this->cell_padding;
- $txt = $this->removeSHY($txt);
- $rs = '';
- $this->adjustCellPadding($border);
- if (!$ignore_min_height) {
- $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
- if ($h < $min_cell_height) {
- $h = $min_cell_height;
- }
- }
- $k = $this->k;
-
- list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
- if ($this->rtl) {
- $x = $this->x - $this->cell_margin['R'];
- } else {
- $x = $this->x + $this->cell_margin['L'];
- }
- $y = $this->y + $this->cell_margin['T'];
- $prev_font_stretching = $this->font_stretching;
- $prev_font_spacing = $this->font_spacing;
-
- switch ($calign) {
- case 'A': {
-
- switch ($valign) {
- case 'T': {
-
- $y -= $this->cell_padding['T'];
- break;
- }
- case 'B': {
-
- $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
- break;
- }
- default:
- case 'C':
- case 'M': {
-
- $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
- break;
- }
- }
- break;
- }
- case 'L': {
-
- switch ($valign) {
- case 'T': {
-
- $y -= ($this->cell_padding['T'] + $this->FontAscent);
- break;
- }
- case 'B': {
-
- $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
- break;
- }
- default:
- case 'C':
- case 'M': {
-
- $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
- break;
- }
- }
- break;
- }
- case 'D': {
-
- switch ($valign) {
- case 'T': {
-
- $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
- break;
- }
- case 'B': {
-
- $y -= ($h - $this->cell_padding['B']);
- break;
- }
- default:
- case 'C':
- case 'M': {
-
- $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
- break;
- }
- }
- break;
- }
- case 'B': {
-
- $y -= $h;
- break;
- }
- case 'C':
- case 'M': {
-
- $y -= ($h / 2);
- break;
- }
- default:
- case 'T': {
-
- break;
- }
- }
-
- switch ($valign) {
- case 'T': {
-
- $yt = $y + $this->cell_padding['T'];
- break;
- }
- case 'B': {
-
- $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
- break;
- }
- default:
- case 'C':
- case 'M': {
-
- $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
- break;
- }
- }
- $basefonty = $yt + $this->FontAscent;
- if ($this->empty_string($w) OR ($w <= 0)) {
- if ($this->rtl) {
- $w = $x - $this->lMargin;
- } else {
- $w = $this->w - $this->rMargin - $x;
- }
- }
- $s = '';
-
- if (is_string($border) AND (strlen($border) == 4)) {
-
- $border = 1;
- }
- if ($fill OR ($border == 1)) {
- if ($fill) {
- $op = ($border == 1) ? 'B' : 'f';
- } else {
- $op = 'S';
- }
- if ($this->rtl) {
- $xk = (($x - $w) * $k);
- } else {
- $xk = ($x * $k);
- }
- $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
- }
-
- $s .= $this->getCellBorder($x, $y, $w, $h, $border);
- if ($txt != '') {
- $txt2 = $txt;
- if ($this->isunicode) {
- if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
- $txt2 = $this->UTF8ToLatin1($txt2);
- } else {
- $unicode = $this->UTF8StringToArray($txt);
- $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl);
- if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
-
-
-
- $topchar = array(3611, 3613, 3615, 3650, 3651, 3652);
- $topsym = array(3633, 3636, 3637, 3638, 3639, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662);
- $numchars = count($unicode);
- $unik = 0;
- $uniblock = array();
- $uniblock[$unik] = array();
- $uniblock[$unik][] = $unicode[0];
-
- for ($i = 1; $i < $numchars; ++$i) {
-
- if (in_array($unicode[$i], $topsym) AND (in_array($unicode[($i - 1)], $topsym) OR in_array($unicode[($i - 1)], $topchar))) {
-
- ++$unik;
- $uniblock[$unik] = array();
- $uniblock[$unik][] = $unicode[$i];
- ++$unik;
- $uniblock[$unik] = array();
- $unicode[$i] = 0x200b;
- } else {
- $uniblock[$unik][] = $unicode[$i];
- }
- }
-
- }
- $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
- }
- }
- $txt2 = $this->_escape($txt2);
-
- $txwidth = $this->GetStringWidth($txt);
- $width = $txwidth;
-
- if ($stretch > 0) {
-
- if ($width <= 0) {
- $ratio = 1;
- } else {
- $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
- }
-
- if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
-
- if ($stretch > 2) {
-
- $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
- } else {
-
- $this->font_stretching *= $ratio;
- }
-
- $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
-
- $align = '';
- }
- }
- if ($this->font_stretching != 100) {
-
- $rs .= sprintf('BT %.2F Tz ET ', $this->font_stretching);
- }
- if ($this->font_spacing != 0) {
-
- $rs .= sprintf('BT %.2F Tc ET ', ($this->font_spacing * $this->k));
- }
- if ($this->ColorFlag AND ($this->textrendermode < 4)) {
- $s .= 'q '.$this->TextColor.' ';
- }
-
- $s .= sprintf('BT %d Tr %.2F w ET ', $this->textrendermode, $this->textstrokewidth);
-
- $ns = substr_count($txt, chr(32));
-
- $spacewidth = 0;
- if (($align == 'J') AND ($ns > 0)) {
- if ($this->isUnicodeFont()) {
-
- $width = $this->GetStringWidth(str_replace(' ', '', $txt));
-
- $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / $this->FontSize;
- if ($this->font_stretching != 100) {
-
- $spacewidth /= ($this->font_stretching / 100);
- }
-
- $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%.3F', $spacewidth).' (', $txt2);
- $unicode_justification = true;
- } else {
-
- $width = $txwidth;
-
- $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
- if ($this->font_stretching != 100) {
-
- $spacewidth /= ($this->font_stretching / 100);
- }
-
- $rs .= sprintf('BT %.3F Tw ET ', $spacewidth);
- }
- $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
- }
-
- $txt2 = str_replace("\r", ' ', $txt2);
- switch ($align) {
- case 'C': {
- $dx = ($w - $width) / 2;
- break;
- }
- case 'R': {
- if ($this->rtl) {
- $dx = $this->cell_padding['R'];
- } else {
- $dx = $w - $width - $this->cell_padding['R'];
- }
- break;
- }
- case 'L': {
- if ($this->rtl) {
- $dx = $w - $width - $this->cell_padding['L'];
- } else {
- $dx = $this->cell_padding['L'];
- }
- break;
- }
- case 'J':
- default: {
- if ($this->rtl) {
- $dx = $this->cell_padding['R'];
- } else {
- $dx = $this->cell_padding['L'];
- }
- break;
- }
- }
- if ($this->rtl) {
- $xdx = $x - $dx - $width;
- } else {
- $xdx = $x + $dx;
- }
- $xdk = $xdx * $k;
-
- $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
- if (isset($uniblock)) {
-
- $xshift = 0;
- $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
- $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
- foreach ($uniblock as $uk => $uniarr) {
- if (($uk % 2) == 0) {
-
- if ($spacewidth != 0) {
-
- $xshift += (count(array_keys($uniarr, 32)) * $spw);
- }
- $xshift += $this->GetArrStringWidth($uniarr);
- } else {
-
- $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
- $topchr = $this->_escape($topchr);
- $s .= sprintf(' BT %.2F %.2F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
- }
- }
- }
- if ($this->underline) {
- $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
- }
- if ($this->linethrough) {
- $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
- }
- if ($this->overline) {
- $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
- }
- if ($this->ColorFlag AND ($this->textrendermode < 4)) {
- $s .= ' Q';
- }
- if ($link) {
- $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
- }
- }
-
- if ($s) {
-
- $rs .= $s;
- if ($this->font_spacing != 0) {
-
- $rs .= ' BT 0 Tc ET';
- }
- if ($this->font_stretching != 100) {
-
- $rs .= ' BT 100 Tz ET';
- }
- }
-
- if (!$this->isUnicodeFont() AND ($align == 'J')) {
- $rs .= ' BT 0 Tw ET';
- }
-
- $this->font_stretching = $prev_font_stretching;
- $this->font_spacing = $prev_font_spacing;
- $this->lasth = $h;
- if ($ln > 0) {
-
- $this->y = $y + $h + $this->cell_margin['B'];
- if ($ln == 1) {
- if ($this->rtl) {
- $this->x = $this->w - $this->rMargin;
- } else {
- $this->x = $this->lMargin;
- }
- }
- } else {
-
- if ($this->rtl) {
- $this->x = $x - $w - $this->cell_margin['L'];
- } else {
- $this->x = $x + $w + $this->cell_margin['R'];
- }
- }
- $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
- $rs = $gstyles.$rs;
- $this->cell_padding = $prev_cell_padding;
- $this->cell_margin = $prev_cell_margin;
- return $rs;
- }
-
- protected function getCellBorder($x, $y, $w, $h, $brd) {
- $s = '';
- if (empty($brd)) {
- return $s;
- }
- if ($brd == 1) {
- $brd = array('LRTB' => true);
- }
-
- $k = $this->k;
- if ($this->rtl) {
- $xeL = ($x - $w) * $k;
- $xeR = $x * $k;
- } else {
- $xeL = $x * $k;
- $xeR = ($x + $w) * $k;
- }
- $yeL = (($this->h - ($y + $h)) * $k);
- $yeT = (($this->h - $y) * $k);
- $xeT = $xeL;
- $xeB = $xeR;
- $yeR = $yeT;
- $yeB = $yeL;
- if (is_string($brd)) {
-
- $slen = strlen($brd);
- $newbrd = array();
- for ($i = 0; $i < $slen; ++$i) {
- $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
- }
- $brd = $newbrd;
- }
- if (isset($brd['mode'])) {
- $mode = $brd['mode'];
- unset($brd['mode']);
- } else {
- $mode = 'normal';
- }
- foreach ($brd as $border => $style) {
- if (is_array($style) AND !empty($style)) {
-
- $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
- $s .= $this->SetLineStyle($style, true)."\n";
- }
- switch ($mode) {
- case 'ext': {
- $off = (($this->LineWidth / 2) * $k);
- $xL = $xeL - $off;
- $xR = $xeR + $off;
- $yT = $yeT + $off;
- $yL = $yeL - $off;
- $xT = $xL;
- $xB = $xR;
- $yR = $yT;
- $yB = $yL;
- $w += $this->LineWidth;
- $h += $this->LineWidth;
- break;
- }
- case 'int': {
- $off = ($this->LineWidth / 2) * $k;
- $xL = $xeL + $off;
- $xR = $xeR - $off;
- $yT = $yeT - $off;
- $yL = $yeL + $off;
- $xT = $xL;
- $xB = $xR;
- $yR = $yT;
- $yB = $yL;
- $w -= $this->LineWidth;
- $h -= $this->LineWidth;
- break;
- }
- case 'normal':
- default: {
- $xL = $xeL;
- $xT = $xeT;
- $xB = $xeB;
- $xR = $xeR;
- $yL = $yeL;
- $yT = $yeT;
- $yB = $yeB;
- $yR = $yeR;
- break;
- }
- }
-
- if (strlen($border) == 4) {
- $s .= sprintf('%.2F %.2F %.2F %.2F re S ', $xT, $yT, ($w * $k), (-$h * $k));
- } elseif (strlen($border) == 3) {
- if (strpos($border,'B') === false) {
- $s .= sprintf('%.2F %.2F m ', $xL, $yL);
- $s .= sprintf('%.2F %.2F l ', $xT, $yT);
- $s .= sprintf('%.2F %.2F l ', $xR, $yR);
- $s .= sprintf('%.2F %.2F l ', $xB, $yB);
- $s .= 'S ';
- } elseif (strpos($border,'L') === false) {
- $s .= sprintf('%.2F %.2F m ', $xT, $yT);
- $s .= sprintf('%.2F %.2F l ', $xR, $yR);
- $s .= sprintf('%.2F %.2F l ', $xB, $yB);
- $s .= sprintf('%.2F %.2F l ', $xL, $yL);
- $s .= 'S ';
- } elseif (strpos($border,'T') === false) {
- $s .= sprintf('%.2F %.2F m ', $xR, $yR);
- $s .= sprintf('%.2F %.2F l ', $xB, $yB);
- $s .= sprintf('%.2F %.2F l ', $xL, $yL);
- $s .= sprintf('%.2F %.2F l ', $xT, $yT);
- $s .= 'S ';
- } elseif (strpos($border,'R') === false) {
- $s .= sprintf('%.2F %.2F m ', $xB, $yB);
- $s .= sprintf('%.2F %.2F l ', $xL, $yL);
- $s .= sprintf('%.2F %.2F l ', $xT, $yT);
- $s .= sprintf('%.2F %.2F l ', $xR, $yR);
- $s .= 'S ';
- }
- } elseif (strlen($border) == 2) {
- if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) {
- $s .= sprintf('%.2F %.2F m ', $xL, $yL);
- $s .= sprintf('%.2F %.2F l ', $xT, $yT);
- $s .= sprintf('%.2F %.2F l ', $xR, $yR);
- $s .= 'S ';
- } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) {
- $s .= sprintf('%.2F %.2F m ', $xT, $yT);
- $s .= sprintf('%.2F %.2F l ', $xR, $yR);
- $s .= sprintf('%.2F %.2F l ', $xB, $yB);
- $s .= 'S ';
- } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) {
- $s .= sprintf('%.2F %.2F m ', $xR, $yR);
- $s .= sprintf('%.2F %.2F l ', $xB, $yB);
- $s .= sprintf('%.2F %.2F l ', $xL, $yL);
- $s .= 'S ';
- } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) {
- $s .= sprintf('%.2F %.2F m ', $xB, $yB);
- $s .= sprintf('%.2F %.2F l ', $xL, $yL);
- $s .= sprintf('%.2F %.2F l ', $xT, $yT);
- $s .= 'S ';
- } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) {
- $s .= sprintf('%.2F %.2F m ', $xL, $yL);
- $s .= sprintf('%.2F %.2F l ', $xT, $yT);
- $s .= 'S ';
- $s .= sprintf('%.2F %.2F m ', $xR, $yR);
- $s .= sprintf('%.2F %.2F l ', $xB, $yB);
- $s .= 'S ';
- } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) {
- $s .= sprintf('%.2F %.2F m ', $xT, $yT);
- $s .= sprintf('%.2F %.2F l ', $xR, $yR);
- $s .= 'S ';
- $s .= sprintf('%.2F %.2F m ', $xB, $yB);
- $s .= sprintf('%.2F %.2F l ', $xL, $yL);
- $s .= 'S ';
- }
- } else {
- if (strpos($border,'L') !== false) {
- $s .= sprintf('%.2F %.2F m ', $xL, $yL);
- $s .= sprintf('%.2F %.2F l ', $xT, $yT);
- $s .= 'S ';
- } elseif (strpos($border,'T') !== false) {
- $s .= sprintf('%.2F %.2F m ', $xT, $yT);
- $s .= sprintf('%.2F %.2F l ', $xR, $yR);
- $s .= 'S ';
- } elseif (strpos($border,'R') !== false) {
- $s .= sprintf('%.2F %.2F m ', $xR, $yR);
- $s .= sprintf('%.2F %.2F l ', $xB, $yB);
- $s .= 'S ';
- } elseif (strpos($border,'B') !== false) {
- $s .= sprintf('%.2F %.2F m ', $xB, $yB);
- $s .= sprintf('%.2F %.2F l ', $xL, $yL);
- $s .= 'S ';
- }
- }
- if (is_array($style) AND !empty($style)) {
-
- $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
- }
- }
- return $s;
- }
-
- public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false) {
- $prev_cell_margin = $this->cell_margin;
- $prev_cell_padding = $this->cell_padding;
-
- $this->adjustCellPadding($border);
- $mc_padding = $this->cell_padding;
- $mc_margin = $this->cell_margin;
- $this->cell_padding['T'] = 0;
- $this->cell_padding['B'] = 0;
- $this->setCellMargins(0, 0, 0, 0);
- if ($this->empty_string($this->lasth) OR $reseth) {
-
- $this->resetLastH();
- }
- if (!$this->empty_string($y)) {
- $this->SetY($y);
- } else {
- $y = $this->GetY();
- }
- $resth = 0;
- if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
-
- $newh = ($this->PageBreakTrigger - $y);
- $resth = ($h - $newh);
- $h = $newh;
- }
-
- $startpage = $this->page;
-
- $startcolumn = $this->current_column;
- if (!$this->empty_string($x)) {
- $this->SetX($x);
- } else {
- $x = $this->GetX();
- }
-
- list($x, $y) = $this->checkPageRegions(0, $x, $y);
-
- $oy = $y + $mc_margin['T'];
- if ($this->rtl) {
- $ox = $this->w - $x - $mc_margin['R'];
- } else {
- $ox = $x + $mc_margin['L'];
- }
- $this->x = $ox;
- $this->y = $oy;
-
- if ($this->empty_string($w) OR ($w <= 0)) {
- if ($this->rtl) {
- $w = $this->x - $this->lMargin - $mc_margin['L'];
- } else {
- $w = $this->w - $this->x - $this->rMargin - $mc_margin['R'];
- }
- }
-
- $lMargin = $this->lMargin;
- $rMargin = $this->rMargin;
- if ($this->rtl) {
- $this->rMargin = $this->w - $this->x;
- $this->lMargin = $this->x - $w;
- } else {
- $this->lMargin = $this->x;
- $this->rMargin = $this->w - $this->x - $w;
- }
- if ($autopadding) {
-
- $this->y += $mc_padding['T'];
- }
- if ($ishtml) {
- $this->writeHTML($txt, true, false, $reseth, true, $align);
- $nl = 1;
- } else {
- $prev_FontSizePt = $this->FontSizePt;
-
- if ($maxh > 0) {
-
- $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
- if ($fitcell) {
-
- $fmin = 1;
- $fmax = $this->FontSizePt;
- $prev_text_height = $text_height;
- $maxit = 100;
- while ($maxit > 0) {
- $fmid = (($fmax + $fmin) / 2);
- $this->SetFontSize($fmid, false);
- $this->resetLastH();
- $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
- if (($text_height == $maxh) OR (($text_height < $maxh) AND ($fmin >= ($fmax - 0.01)))) {
- break;
- } elseif ($text_height < $maxh) {
- $fmin = $fmid;
- } else {
- $fmax = $fmid;
- }
- --$maxit;
- }
- $this->SetFontSize($this->FontSizePt);
- }
- if ($text_height < $maxh) {
- if ($valign == 'M') {
-
- $this->y += (($maxh - $text_height) / 2);
- } elseif ($valign == 'B') {
-
- $this->y += ($maxh - $text_height);
- }
- }
- }
- $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
- if ($fitcell) {
-
- $this->SetFontSize($prev_FontSizePt);
- }
- }
- if ($autopadding) {
-
- $this->y += $mc_padding['B'];
- }
-
- $currentY = $this->y;
-
- $endpage = $this->page;
- if ($resth > 0) {
- $skip = ($endpage - $startpage);
- $tmpresth = $resth;
- while ($tmpresth > 0) {
- if ($skip <= 0) {
-
- $this->checkPageBreak($this->PageBreakTrigger + 1);
- }
- if ($this->num_columns > 1) {
- $tmpresth -= ($this->h - $this->y - $this->bMargin);
- } else {
- $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
- }
- --$skip;
- }
- $currentY = $this->y;
- $endpage = $this->page;
- }
-
- $endcolumn = $this->current_column;
- if ($this->num_columns == 0) {
- $this->num_columns = 1;
- }
-
- $border_start = $this->getBorderMode($border, $position='start');
- $border_end = $this->getBorderMode($border, $position='end');
- $border_middle = $this->getBorderMode($border, $position='middle');
-
- for ($page = $startpage; $page <= $endpage; ++$page) {
- $ccode = '';
- $this->setPage($page);
- if ($this->num_columns < 2) {
-
- $this->SetX($x);
- $this->y = $this->tMargin;
- }
-
- if ($page > $startpage) {
- if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
- $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
- } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
- $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
- }
- }
- if ($startpage == $endpage) {
-
- for ($column = $startcolumn; $column <= $endcolumn; ++$column) {
- $this->selectColumn($column);
- if ($this->rtl) {
- $this->x -= $mc_margin['R'];
- } else {
- $this->x += $mc_margin['L'];
- }
- if ($startcolumn == $endcolumn) {
- $cborder = $border;
- $h = max($h, ($currentY - $oy));
- $this->y = $oy;
- } elseif ($column == $startcolumn) {
- $cborder = $border_start;
- $this->y = $oy;
- $h = $this->h - $this->y - $this->bMargin;
- } elseif ($column == $endcolumn) {
- $cborder = $border_end;
- $h = $currentY - $this->y;
- if ($resth > $h) {
- $h = $resth;
- }
- } else {
- $cborder = $border_middle;
- $h = $this->h - $this->y - $this->bMargin;
- $resth -= $h;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } elseif ($page == $startpage) {
- for ($column = $startcolumn; $column < $this->num_columns; ++$column) {
- $this->selectColumn($column);
- if ($this->rtl) {
- $this->x -= $mc_margin['R'];
- } else {
- $this->x += $mc_margin['L'];
- }
- if ($column == $startcolumn) {
- $cborder = $border_start;
- $this->y = $oy;
- $h = $this->h - $this->y - $this->bMargin;
- } else {
- $cborder = $border_middle;
- $h = $this->h - $this->y - $this->bMargin;
- $resth -= $h;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } elseif ($page == $endpage) {
- for ($column = 0; $column <= $endcolumn; ++$column) {
- $this->selectColumn($column);
- if ($this->rtl) {
- $this->x -= $mc_margin['R'];
- } else {
- $this->x += $mc_margin['L'];
- }
- if ($column == $endcolumn) {
-
- $cborder = $border_end;
- $h = $currentY - $this->y;
- if ($resth > $h) {
- $h = $resth;
- }
- } else {
-
- $cborder = $border_middle;
- $h = $this->h - $this->y - $this->bMargin;
- $resth -= $h;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } else {
- for ($column = 0; $column < $this->num_columns; ++$column) {
- $this->selectColumn($column);
- if ($this->rtl) {
- $this->x -= $mc_margin['R'];
- } else {
- $this->x += $mc_margin['L'];
- }
- $cborder = $border_middle;
- $h = $this->h - $this->y - $this->bMargin;
- $resth -= $h;
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- }
- if ($cborder OR $fill) {
- $offsetlen = strlen($ccode);
-
- if ($this->inxobj) {
-
- if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
- $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
- $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
- $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
- } else {
- $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
- $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
- }
- $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
- $pstart = substr($pagebuff, 0, $pagemark);
- $pend = substr($pagebuff, $pagemark);
- $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
- } else {
- if (end($this->transfmrk[$this->page]) !== false) {
- $pagemarkkey = key($this->transfmrk[$this->page]);
- $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
- $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
- } elseif ($this->InFooter) {
- $pagemark = $this->footerpos[$this->page];
- $this->footerpos[$this->page] += $offsetlen;
- } else {
- $pagemark = $this->intmrk[$this->page];
- $this->intmrk[$this->page] += $offsetlen;
- }
- $pagebuff = $this->getPageBuffer($this->page);
- $pstart = substr($pagebuff, 0, $pagemark);
- $pend = substr($pagebuff, $pagemark);
- $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
- }
- }
- }
-
- $currentY = $this->GetY();
-
- if ($this->num_columns > 1) {
- $this->selectColumn();
- } else {
-
- $this->lMargin = $lMargin;
- $this->rMargin = $rMargin;
- if ($this->page > $startpage) {
-
- $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
- $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
- if (($dl != 0) OR ($dr != 0)) {
- $this->lMargin += $dl;
- $this->rMargin += $dr;
- }
- }
- }
- if ($ln > 0) {
-
- $this->SetY($currentY + $mc_margin['B']);
- if ($ln == 2) {
- $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
- }
- } else {
-
- $this->setPage($startpage);
- $this->y = $y;
- $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
- }
- $this->setContentMark();
- $this->cell_padding = $prev_cell_padding;
- $this->cell_margin = $prev_cell_margin;
- return $nl;
- }
-
- protected function getBorderMode($brd, $position='start') {
- if ((!$this->opencell) OR empty($brd)) {
- return $brd;
- }
- if ($brd == 1) {
- $brd = 'LTRB';
- }
- if (is_string($brd)) {
-
- $slen = strlen($brd);
- $newbrd = array();
- for ($i = 0; $i < $slen; ++$i) {
- $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
- }
- $brd = $newbrd;
- }
- foreach ($brd as $border => $style) {
- switch ($position) {
- case 'start': {
- if (strpos($border, 'B') !== false) {
-
- $newkey = str_replace('B', '', $border);
- if (strlen($newkey) > 0) {
- $brd[$newkey] = $style;
- }
- unset($brd[$border]);
- }
- break;
- }
- case 'middle': {
- if (strpos($border, 'B') !== false) {
-
- $newkey = str_replace('B', '', $border);
- if (strlen($newkey) > 0) {
- $brd[$newkey] = $style;
- }
- unset($brd[$border]);
- $border = $newkey;
- }
- if (strpos($border, 'T') !== false) {
-
- $newkey = str_replace('T', '', $border);
- if (strlen($newkey) > 0) {
- $brd[$newkey] = $style;
- }
- unset($brd[$border]);
- }
- break;
- }
- case 'end': {
- if (strpos($border, 'T') !== false) {
-
- $newkey = str_replace('T', '', $border);
- if (strlen($newkey) > 0) {
- $brd[$newkey] = $style;
- }
- unset($brd[$border]);
- }
- break;
- }
- }
- }
- return $brd;
- }
-
- public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
- if ($txt === '') {
-
- return 1;
- }
-
- $prev_cell_padding = $this->cell_padding;
- $prev_lasth = $this->lasth;
- if (is_array($cellpadding)) {
- $this->cell_padding = $cellpadding;
- }
- $this->adjustCellPadding($border);
- if ($this->empty_string($w) OR ($w <= 0)) {
- if ($this->rtl) {
- $w = $this->x - $this->lMargin;
- } else {
- $w = $this->w - $this->rMargin - $this->x;
- }
- }
- $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
- if ($reseth) {
-
- $this->resetLastH();
- }
- $lines = 1;
- $sum = 0;
- $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
- $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
- $length = count($chars);
- $lastSeparator = -1;
- for ($i = 0; $i < $length; ++$i) {
- $charWidth = $charsWidth[$i];
- if (preg_match($this->re_spaces, $this->unichr($chars[$i]))) {
- $lastSeparator = $i;
- }
- if ((($sum + $charWidth) > $wmax) OR ($chars[$i] == 10)) {
- ++$lines;
- if ($chars[$i] == 10) {
- $lastSeparator = -1;
- $sum = 0;
- } elseif ($lastSeparator != -1) {
- $i = $lastSeparator;
- $lastSeparator = -1;
- $sum = 0;
- } else {
- $sum = $charWidth;
- }
- } else {
- $sum += $charWidth;
- }
- }
- if ($chars[($length - 1)] == 10) {
- --$lines;
- }
- $this->cell_padding = $prev_cell_padding;
- $this->lasth = $prev_lasth;
- return $lines;
- }
-
- public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
-
- $prev_cell_padding = $this->cell_padding;
- $prev_lasth = $this->lasth;
- if (is_array($cellpadding)) {
- $this->cell_padding = $cellpadding;
- }
- $this->adjustCellPadding($border);
- $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
- $height = $lines * ($this->FontSize * $this->cell_height_ratio);
- if ($autopadding) {
-
- $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
- }
- $this->cell_padding = $prev_cell_padding;
- $this->lasth = $prev_lasth;
- return $height;
- }
-
- public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
-
- list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
- if (strlen($txt) == 0) {
-
- $txt = ' ';
- }
- if ($margin === '') {
-
- $margin = $this->cell_margin;
- }
-
- $s = str_replace("\r", '', $txt);
-
- if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $s)) {
- $arabic = true;
- } else {
- $arabic = false;
- }
-
- if ($arabic OR ($this->tmprtl == 'R') OR preg_match($this->unicode->uni_RE_PATTERN_RTL, $s)) {
- $rtlmode = true;
- } else {
- $rtlmode = false;
- }
-
- $chrwidth = $this->GetCharWidth(46);
-
- $chars = $this->UTF8StringToArray($s);
-
- $uchars = $this->UTF8ArrayToUniArray($chars);
-
- $nb = count($chars);
-
- $shy_replacement = 45;
- $shy_replacement_char = $this->unichr($shy_replacement);
-
- $shy_replacement_width = $this->GetCharWidth($shy_replacement);
-
- $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
-
- $pw = $w = $this->w - $this->lMargin - $this->rMargin;
-
- if ($this->rtl) {
- $w = $this->x - $this->lMargin;
- } else {
- $w = $this->w - $this->rMargin - $this->x;
- }
-
- $wmax = $w - $wadj;
- if (!$firstline) {
- $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
- }
- if ((!$firstline) AND (($chrwidth > $wmax) OR ($this->GetCharWidth($chars[0]) > $wmax))) {
-
- return '';
- }
-
- $row_height = max($h, $this->FontSize * $this->cell_height_ratio);
- $start_page = $this->page;
- $i = 0;
- $j = 0;
- $sep = -1;
- $shy = false;
- $l = 0;
- $nl = 0;
- $linebreak = false;
- $pc = 0;
-
- while ($i < $nb) {
- if (($maxh > 0) AND ($this->y >= $maxy) ) {
- break;
- }
-
- $c = $chars[$i];
- if ($c == 10) {
-
- if ($align == 'J') {
- if ($this->rtl) {
- $talign = 'R';
- } else {
- $talign = 'L';
- }
- } else {
- $talign = $align;
- }
- $tmpstr = $this->UniArrSubString($uchars, $j, $i);
- if ($firstline) {
- $startx = $this->x;
- $tmparr = array_slice($chars, $j, ($i - $j));
- if ($rtlmode) {
- $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
- }
- $linew = $this->GetArrStringWidth($tmparr);
- unset($tmparr);
- if ($this->rtl) {
- $this->endlinex = $startx - $linew;
- } else {
- $this->endlinex = $startx + $linew;
- }
- $w = $linew;
- $tmpcellpadding = $this->cell_padding;
- if ($maxh == 0) {
- $this->SetCellPadding(0);
- }
- }
- if ($firstblock AND $this->isRTLTextDir()) {
- $tmpstr = $this->stringRightTrim($tmpstr);
- }
-
- if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
- $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
- }
- unset($tmpstr);
- if ($firstline) {
- $this->cell_padding = $tmpcellpadding;
- return ($this->UniArrSubString($uchars, $i));
- }
- ++$nl;
- $j = $i + 1;
- $l = 0;
- $sep = -1;
- $shy = false;
-
- if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
- $this->AcceptPageBreak();
- if ($this->rtl) {
- $this->x -= $margin['R'];
- } else {
- $this->x += $margin['L'];
- }
- $this->lMargin += $margin['L'];
- $this->rMargin += $margin['R'];
- }
- $w = $this->getRemainingWidth();
- $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
- } else {
-
-
-
-
-
- if (($c != 160) AND (($c == 173) OR preg_match($this->re_spaces, $this->unichr($c)))) {
-
- $sep = $i;
-
- if ($c == 173) {
- $shy = true;
- if ($pc == 45) {
- $tmp_shy_replacement_width = 0;
- $tmp_shy_replacement_char = '';
- } else {
- $tmp_shy_replacement_width = $shy_replacement_width;
- $tmp_shy_replacement_char = $shy_replacement_char;
- }
- } else {
- $shy = false;
- }
- }
-
- if ($this->isUnicodeFont() AND ($arabic)) {
-
-
- $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
- } else {
- $l += $this->GetCharWidth($c);
- }
- if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) ) {
-
- if ($sep == -1) {
-
- if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth)))
- OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $chrwidth)))) {
-
- $this->Cell($w, $h, '', 0, 1);
- $linebreak = true;
- if ($firstline) {
- return ($this->UniArrSubString($uchars, $j));
- }
- } else {
-
- $tmpstr = $this->UniArrSubString($uchars, $j, $i);
- if ($firstline) {
- $startx = $this->x;
- $tmparr = array_slice($chars, $j, ($i - $j));
- if ($rtlmode) {
- $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
- }
- $linew = $this->GetArrStringWidth($tmparr);
- unset($tmparr);
- if ($this->rtl) {
- $this->endlinex = $startx - $linew;
- } else {
- $this->endlinex = $startx + $linew;
- }
- $w = $linew;
- $tmpcellpadding = $this->cell_padding;
- if ($maxh == 0) {
- $this->SetCellPadding(0);
- }
- }
- if ($firstblock AND $this->isRTLTextDir()) {
- $tmpstr = $this->stringRightTrim($tmpstr);
- }
- $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
- unset($tmpstr);
- if ($firstline) {
- $this->cell_padding = $tmpcellpadding;
- return ($this->UniArrSubString($uchars, $i));
- }
- $j = $i;
- --$i;
- }
- } else {
-
- if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
- $endspace = 1;
- } else {
- $endspace = 0;
- }
-
- $strrest = $this->UniArrSubString($uchars, ($sep + $endspace));
- $nextstr = preg_split('/'.$this->re_space['p'].'/'.$this->re_space['m'], $this->stringTrim($strrest));
- if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
-
- $tmpstr = $this->UniArrSubString($uchars, $j, $i);
- if ($firstline) {
- $startx = $this->x;
- $tmparr = array_slice($chars, $j, ($i - $j));
- if ($rtlmode) {
- $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
- }
- $linew = $this->GetArrStringWidth($tmparr);
- unset($tmparr);
- if ($this->rtl) {
- $this->endlinex = $startx - $linew;
- } else {
- $this->endlinex = $startx + $linew;
- }
- $w = $linew;
- $tmpcellpadding = $this->cell_padding;
- if ($maxh == 0) {
- $this->SetCellPadding(0);
- }
- }
- if ($firstblock AND $this->isRTLTextDir()) {
- $tmpstr = $this->stringRightTrim($tmpstr);
- }
- $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
- unset($tmpstr);
- if ($firstline) {
- $this->cell_padding = $tmpcellpadding;
- return ($this->UniArrSubString($uchars, $i));
- }
- $j = $i;
- --$i;
- } else {
-
- if ($shy) {
-
- $shy_width = $tmp_shy_replacement_width;
- if ($this->rtl) {
- $shy_char_left = $tmp_shy_replacement_char;
- $shy_char_right = '';
- } else {
- $shy_char_left = '';
- $shy_char_right = $tmp_shy_replacement_char;
- }
- } else {
- $shy_width = 0;
- $shy_char_left = '';
- $shy_char_right = '';
- }
- $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
- if ($firstline) {
- $startx = $this->x;
- $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
- if ($rtlmode) {
- $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
- }
- $linew = $this->GetArrStringWidth($tmparr);
- unset($tmparr);
- if ($this->rtl) {
- $this->endlinex = $startx - $linew - $shy_width;
- } else {
- $this->endlinex = $startx + $linew + $shy_width;
- }
- $w = $linew;
- $tmpcellpadding = $this->cell_padding;
- if ($maxh == 0) {
- $this->SetCellPadding(0);
- }
- }
-
- if ($firstblock AND $this->isRTLTextDir()) {
- $tmpstr = $this->stringRightTrim($tmpstr);
- }
- $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
- unset($tmpstr);
- if ($firstline) {
-
- $this->cell_padding = $tmpcellpadding;
- return ($this->UniArrSubString($uchars, ($sep + $endspace)));
- }
- $i = $sep;
- $sep = -1;
- $shy = false;
- $j = ($i+1);
- }
- }
-
- if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
- $this->AcceptPageBreak();
- if ($this->rtl) {
- $this->x -= $margin['R'];
- } else {
- $this->x += $margin['L'];
- }
- $this->lMargin += $margin['L'];
- $this->rMargin += $margin['R'];
- }
- $w = $this->getRemainingWidth();
- $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
- if ($linebreak) {
- $linebreak = false;
- } else {
- ++$nl;
- $l = 0;
- }
- }
- }
-
- $pc = $c;
- ++$i;
- }
-
- if ($l > 0) {
- switch ($align) {
- case 'J':
- case 'C': {
- $w = $w;
- break;
- }
- case 'L': {
- if ($this->rtl) {
- $w = $w;
- } else {
- $w = $l;
- }
- break;
- }
- case 'R': {
- if ($this->rtl) {
- $w = $l;
- } else {
- $w = $w;
- }
- break;
- }
- default: {
- $w = $l;
- break;
- }
- }
- $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
- if ($firstline) {
- $startx = $this->x;
- $tmparr = array_slice($chars, $j, ($nb - $j));
- if ($rtlmode) {
- $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
- }
- $linew = $this->GetArrStringWidth($tmparr);
- unset($tmparr);
- if ($this->rtl) {
- $this->endlinex = $startx - $linew;
- } else {
- $this->endlinex = $startx + $linew;
- }
- $w = $linew;
- $tmpcellpadding = $this->cell_padding;
- if ($maxh == 0) {
- $this->SetCellPadding(0);
- }
- }
- if ($firstblock AND $this->isRTLTextDir()) {
- $tmpstr = $this->stringRightTrim($tmpstr);
- }
- $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
- unset($tmpstr);
- if ($firstline) {
- $this->cell_padding = $tmpcellpadding;
- return ($this->UniArrSubString($uchars, $nb));
- }
- ++$nl;
- }
- if ($firstline) {
- return '';
- }
- return $nl;
- }
-
- protected function getRemainingWidth() {
- list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
- if ($this->rtl) {
- return ($this->x - $this->lMargin);
- } else {
- return ($this->w - $this->rMargin - $this->x);
- }
- }
-
- public function UTF8ArrSubString($strarr, $start='', $end='') {
- if (strlen($start) == 0) {
- $start = 0;
- }
- if (strlen($end) == 0) {
- $end = count($strarr);
- }
- $string = '';
- for ($i=$start; $i < $end; ++$i) {
- $string .= $this->unichr($strarr[$i]);
- }
- return $string;
- }
-
- public function UniArrSubString($uniarr, $start='', $end='') {
- if (strlen($start) == 0) {
- $start = 0;
- }
- if (strlen($end) == 0) {
- $end = count($uniarr);
- }
- $string = '';
- for ($i=$start; $i < $end; ++$i) {
- $string .= $uniarr[$i];
- }
- return $string;
- }
-
- public function UTF8ArrayToUniArray($ta) {
- return array_map(array($this, 'unichr'), $ta);
- }
-
- public function unichr($c) {
- if (!$this->isunicode) {
- return chr($c);
- } elseif ($c <= 0x7F) {
-
- return chr($c);
- } elseif ($c <= 0x7FF) {
-
- return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F);
- } elseif ($c <= 0xFFFF) {
-
- return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
- } elseif ($c <= 0x10FFFF) {
-
- return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
- } else {
- return '';
- }
- }
-
- public function getImageFileType($imgfile, $iminfo=array()) {
- $type = '';
- if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
- $mime = explode('/', $iminfo['mime']);
- if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
- $type = strtolower(trim($mime[1]));
- }
- }
- if (empty($type)) {
- $fileinfo = pathinfo($imgfile);
- if (isset($fileinfo['extension']) AND (!$this->empty_string($fileinfo['extension']))) {
- $type = strtolower(trim($fileinfo['extension']));
- }
- }
- if ($type == 'jpg') {
- $type = 'jpeg';
- }
- return $type;
- }
-
- protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
- if ($w <= 0) {
-
- $w = ($this->w - $this->lMargin - $this->rMargin);
- }
- if ($h <= 0) {
-
- $h = ($this->PageBreakTrigger - $this->tMargin);
- }
-
- if ($fitonpage OR $this->AutoPageBreak) {
- $ratio_wh = ($w / $h);
- if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
- $h = $this->PageBreakTrigger - $this->tMargin;
- $w = ($h * $ratio_wh);
- }
-
- if ($fitonpage) {
- $maxw = ($this->w - $this->lMargin - $this->rMargin);
- if ($w > $maxw) {
- $w = $maxw;
- $h = ($w / $ratio_wh);
- }
- }
- }
-
- $prev_x = $this->x;
- $prev_y = $this->y;
- if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
- $y = $this->y;
- if ($this->rtl) {
- $x += ($prev_x - $this->x);
- } else {
- $x += ($this->x - $prev_x);
- }
- $this->newline = true;
- }
-
- if ($fitonpage) {
- $ratio_wh = ($w / $h);
- if (($y + $h) > $this->PageBreakTrigger) {
- $h = $this->PageBreakTrigger - $y;
- $w = ($h * $ratio_wh);
- }
- if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
- $w = $this->w - $this->rMargin - $x;
- $h = ($w / $ratio_wh);
- } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
- $w = $x - $this->lMargin;
- $h = ($w / $ratio_wh);
- }
- }
- return array($w, $h, $x, $y);
- }
-
- public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array()) {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- $cached_file = false;
- $exurl = '';
-
- if ($file{0} === '@') {
-
- $imgdata = substr($file, 1);
- $file = K_PATH_CACHE.'img_'.md5($imgdata);
- $fp = fopen($file, 'w');
- fwrite($fp, $imgdata);
- fclose($fp);
- unset($imgdata);
- $cached_file = true;
- $imsize = @getimagesize($file);
- if ($imsize === FALSE) {
- unlink($file);
- $cached_file = false;
- }
- } else {
- if ($file{0} === '*') {
-
- $file = substr($file, 1);
- $exurl = $file;
- }
-
- if (!@file_exists($file)) {
-
- $file = str_replace(' ', '%20', $file);
- }
- if (@file_exists($file)) {
-
- $imsize = @getimagesize($file);
- } else {
- $imsize = false;
- }
- if ($imsize === FALSE) {
- if (function_exists('curl_init')) {
-
- $cs = curl_init();
- curl_setopt($cs, CURLOPT_URL, $file);
- curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
- curl_setopt($cs, CURLOPT_FAILONERROR, true);
- curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
- curl_setopt($cs, CURLOPT_TIMEOUT, 30);
- curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($cs, CURLOPT_USERAGENT, 'TCPDF');
- $imgdata = curl_exec($cs);
- curl_close($cs);
- if ($imgdata !== FALSE) {
-
- $file = K_PATH_CACHE.'img_'.md5($imgdata);
- $fp = fopen($file, 'w');
- fwrite($fp, $imgdata);
- fclose($fp);
- unset($imgdata);
- $cached_file = true;
- $imsize = @getimagesize($file);
- if ($imsize === FALSE) {
- unlink($file);
- $cached_file = false;
- }
- }
- } elseif (($w > 0) AND ($h > 0)) {
-
- $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
- $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
- $imsize = array($pw, $ph);
- }
- }
- }
- if ($imsize === FALSE) {
- if (substr($file, 0, -34) == K_PATH_CACHE.'msk') {
-
- $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
- $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
- $imsize = array($pw, $ph);
- } else {
- $this->Error('[Image] Unable to get image: '.$file);
- }
- }
-
- list($pixw, $pixh) = $imsize;
-
- if (($w <= 0) AND ($h <= 0)) {
-
- $w = $this->pixelsToUnits($pixw);
- $h = $this->pixelsToUnits($pixh);
- } elseif ($w <= 0) {
- $w = $h * $pixw / $pixh;
- } elseif ($h <= 0) {
- $h = $w * $pixh / $pixw;
- } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
- if (strlen($fitbox) !== 2) {
-
- $fitbox = '--';
- }
-
- if ((($w * $pixh) / ($h * $pixw)) < 1) {
-
- $oldh = $h;
-
- $h = $w * $pixh / $pixw;
-
- $hdiff = ($oldh - $h);
-
- switch (strtoupper($fitbox{1})) {
- case 'T': {
- break;
- }
- case 'M': {
- $y += ($hdiff / 2);
- break;
- }
- case 'B': {
- $y += $hdiff;
- break;
- }
- }
- } else {
-
- $oldw = $w;
-
- $w = $h * $pixw / $pixh;
-
- $wdiff = ($oldw - $w);
-
- switch (strtoupper($fitbox{0})) {
- case 'L': {
- if ($this->rtl) {
- $x -= $wdiff;
- }
- break;
- }
- case 'C': {
- if ($this->rtl) {
- $x -= ($wdiff / 2);
- } else {
- $x += ($wdiff / 2);
- }
- break;
- }
- case 'R': {
- if (!$this->rtl) {
- $x += $wdiff;
- }
- break;
- }
- }
- }
- }
-
- list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
-
- $neww = round($w * $this->k * $dpi / $this->dpi);
- $newh = round($h * $this->k * $dpi / $this->dpi);
-
- $newsize = ($neww * $newh);
- $pixsize = ($pixw * $pixh);
- if (intval($resize) == 2) {
- $resize = true;
- } elseif ($newsize >= $pixsize) {
- $resize = false;
- }
-
- $newimage = true;
- if (in_array($file, $this->imagekeys)) {
- $newimage = false;
-
- $info = $this->getImageBuffer($file);
- if (substr($file, 0, -34) != K_PATH_CACHE.'msk') {
-
- $oldsize = ($info['w'] * $info['h']);
- if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
- $newimage = true;
- }
- }
- } elseif (substr($file, 0, -34) != K_PATH_CACHE.'msk') {
-
- $filehash = md5($file);
- $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash;
- $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash;
- if (in_array($tempfile_plain, $this->imagekeys)) {
-
- $info = $this->getImageBuffer($tempfile_plain);
-
- $oldsize = ($info['w'] * $info['h']);
- if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
- $newimage = true;
- } else {
- $newimage = false;
-
- $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
-
- return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
- }
- }
- }
- if ($newimage) {
-
- $type = strtolower($type);
- if ($type == '') {
- $type = $this->getImageFileType($file, $imsize);
- } elseif ($type == 'jpg') {
- $type = 'jpeg';
- }
- $mqr = $this->get_mqr();
- $this->set_mqr(false);
-
- $mtd = '_parse'.$type;
-
- $gdfunction = 'imagecreatefrom'.$type;
- $info = false;
- if ((method_exists($this, $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
-
- $info = $this->$mtd($file);
- if ($info == 'pngalpha') {
- return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
- }
- }
- if (!$info) {
- if (function_exists($gdfunction)) {
-
- $img = $gdfunction($file);
- if ($resize) {
- $imgr = imagecreatetruecolor($neww, $newh);
- if (($type == 'gif') OR ($type == 'png')) {
- $imgr = $this->_setGDImageTransparency($imgr, $img);
- }
- imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
- if (($type == 'gif') OR ($type == 'png')) {
- $info = $this->_toPNG($imgr);
- } else {
- $info = $this->_toJPEG($imgr);
- }
- } else {
- if (($type == 'gif') OR ($type == 'png')) {
- $info = $this->_toPNG($img);
- } else {
- $info = $this->_toJPEG($img);
- }
- }
- } elseif (extension_loaded('imagick')) {
-
- $img = new Imagick();
- if ($type == 'SVG') {
-
- $svgimg = file_get_contents($file);
-
- $regs = array();
- if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
- $svgtag = $regs[1];
- $tmp = array();
- if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
- $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
- $owu = sprintf('%.3F', ($ow * $dpi / 72)).$this->pdfunit;
- $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
- } else {
- $ow = $w;
- }
- $tmp = array();
- if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
- $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
- $ohu = sprintf('%.3F', ($oh * $dpi / 72)).$this->pdfunit;
- $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
- } else {
- $oh = $h;
- }
- $tmp = array();
- if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
- $vbw = ($ow * $this->imgscale * $this->k);
- $vbh = ($oh * $this->imgscale * $this->k);
- $vbox = sprintf(' viewBox="0 0 %.3F %.3F" ', $vbw, $vbh);
- $svgtag = $vbox.$svgtag;
- }
- $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
- }
- $img->readImageBlob($svgimg);
- } else {
- $img->readImage($file);
- }
- if ($resize) {
- $img->resizeImage($neww, $newh, 10, 1, false);
- }
- $img->setCompressionQuality($this->jpeg_quality);
- $img->setImageFormat('jpeg');
- $tempname = tempnam(K_PATH_CACHE, 'jpg_');
- $img->writeImage($tempname);
- $info = $this->_parsejpeg($tempname);
- unlink($tempname);
- $img->destroy();
- } else {
- return;
- }
- }
- if ($info === false) {
-
- return;
- }
- $this->set_mqr($mqr);
- if ($ismask) {
-
- $info['cs'] = 'DeviceGray';
- }
- $info['i'] = $this->numimages;
- if (!in_array($file, $this->imagekeys)) {
- ++$info['i'];
- }
- if ($imgmask !== false) {
- $info['masked'] = $imgmask;
- }
- if (!empty($exurl)) {
- $info['exurl'] = $exurl;
- }
-
- $info['altimgs'] = $altimgs;
-
- $this->setImageBuffer($file, $info);
- }
- if ($cached_file) {
-
- unlink($file);
- }
-
- $this->img_rb_y = $y + $h;
-
- if ($this->rtl) {
- if ($palign == 'L') {
- $ximg = $this->lMargin;
- } elseif ($palign == 'C') {
- $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($palign == 'R') {
- $ximg = $this->w - $this->rMargin - $w;
- } else {
- $ximg = $x - $w;
- }
- $this->img_rb_x = $ximg;
- } else {
- if ($palign == 'L') {
- $ximg = $this->lMargin;
- } elseif ($palign == 'C') {
- $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($palign == 'R') {
- $ximg = $this->w - $this->rMargin - $w;
- } else {
- $ximg = $x;
- }
- $this->img_rb_x = $ximg + $w;
- }
- if ($ismask OR $hidden) {
-
- return $info['i'];
- }
- $xkimg = $ximg * $this->k;
- if (!$alt) {
-
- $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
- }
- if (!empty($border)) {
- $bx = $this->x;
- $by = $this->y;
- $this->x = $ximg;
- if ($this->rtl) {
- $this->x += $w;
- }
- $this->y = $y;
- $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
- $this->x = $bx;
- $this->y = $by;
- }
- if ($link) {
- $this->Link($ximg, $y, $w, $h, $link, 0);
- }
-
- switch($align) {
- case 'T': {
- $this->y = $y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'M': {
- $this->y = $y + round($h/2);
- $this->x = $this->img_rb_x;
- break;
- }
- case 'B': {
- $this->y = $this->img_rb_y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'N': {
- $this->SetY($this->img_rb_y);
- break;
- }
- default:{
- break;
- }
- }
- $this->endlinex = $this->img_rb_x;
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['images'][] = $info['i'];
- }
- return $info['i'];
- }
-
- public function set_mqr($mqr) {
- if (!defined('PHP_VERSION_ID')) {
- $version = PHP_VERSION;
- define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
- }
- if (PHP_VERSION_ID < 50300) {
- @set_magic_quotes_runtime($mqr);
- }
- }
-
- public function get_mqr() {
- if (!defined('PHP_VERSION_ID')) {
- $version = PHP_VERSION;
- define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
- }
- if (PHP_VERSION_ID < 50300) {
- return @get_magic_quotes_runtime();
- }
- return 0;
- }
-
- protected function _toJPEG($image) {
- $tempname = tempnam(K_PATH_CACHE, 'jpg_');
- imagejpeg($image, $tempname, $this->jpeg_quality);
- imagedestroy($image);
- $retvars = $this->_parsejpeg($tempname);
-
- unlink($tempname);
- return $retvars;
- }
-
- protected function _toPNG($image) {
-
- $tempname = tempnam(K_PATH_CACHE, 'jpg_');
-
- imageinterlace($image, 0);
-
- imagepng($image, $tempname);
-
- imagedestroy($image);
-
- $retvars = $this->_parsepng($tempname);
-
- unlink($tempname);
- return $retvars;
- }
-
- protected function _setGDImageTransparency($new_image, $image) {
-
- $tid = imagecolortransparent($image);
-
- $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
- if ($tid >= 0) {
-
- $tcol = imagecolorsforindex($image, $tid);
- }
- $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
- imagefill($new_image, 0, 0, $tid);
- imagecolortransparent($new_image, $tid);
- return $new_image;
- }
-
- protected function _parsejpeg($file) {
- $a = getimagesize($file);
- if (empty($a)) {
- $this->Error('Missing or incorrect image file: '.$file);
- }
- if ($a[2] != 2) {
- $this->Error('Not a JPEG file: '.$file);
- }
-
- $bpc = isset($a['bits']) ? intval($a['bits']) : 8;
-
- if (!isset($a['channels'])) {
- $channels = 3;
- } else {
- $channels = intval($a['channels']);
- }
-
- switch ($channels) {
- case 1: {
- $colspace = 'DeviceGray';
- break;
- }
- case 3: {
- $colspace = 'DeviceRGB';
- break;
- }
- case 4: {
- $colspace = 'DeviceCMYK';
- break;
- }
- default: {
- $channels = 3;
- $colspace = 'DeviceRGB';
- break;
- }
- }
-
- $data = file_get_contents($file);
-
- $icc = array();
- $offset = 0;
- while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) {
-
- $length = ($this->_getUSHORT($data, ($pos - 2)) - 16);
-
- $msn = max(1, ord($data[($pos + 12)]));
-
- $nom = max(1, ord($data[($pos + 13)]));
-
- $icc[($msn - 1)] = substr($data, ($pos + 14), $length);
-
- $offset = ($pos + 14 + $length);
- }
-
- if (count($icc) > 0) {
- ksort($icc);
- $icc = implode('', $icc);
- if ((ord($icc{36}) != 0x61) OR (ord($icc{37}) != 0x63) OR (ord($icc{38}) != 0x73) OR (ord($icc{39}) != 0x70)) {
-
- $icc = false;
- }
- } else {
- $icc = false;
- }
- return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
- }
-
- protected function _parsepng($file) {
- $f = fopen($file, 'rb');
- if ($f === false) {
- $this->Error('Can\'t open image file: '.$file);
- }
-
- if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
- $this->Error('Not a PNG file: '.$file);
- }
-
- fread($f, 4);
- if (fread($f, 4) != 'IHDR') {
- $this->Error('Incorrect PNG file: '.$file);
- }
- $w = $this->_freadint($f);
- $h = $this->_freadint($f);
- $bpc = ord(fread($f, 1));
- if ($bpc > 8) {
-
- fclose($f);
- return false;
- }
- $ct = ord(fread($f, 1));
- if ($ct == 0) {
- $colspace = 'DeviceGray';
- } elseif ($ct == 2) {
- $colspace = 'DeviceRGB';
- } elseif ($ct == 3) {
- $colspace = 'Indexed';
- } else {
-
- fclose($f);
- return 'pngalpha';
- }
- if (ord(fread($f, 1)) != 0) {
-
- fclose($f);
- return false;
- }
- if (ord(fread($f, 1)) != 0) {
-
- fclose($f);
- return false;
- }
- if (ord(fread($f, 1)) != 0) {
-
- fclose($f);
- return false;
- }
- fread($f, 4);
- $channels = ($ct == 2 ? 3 : 1);
- $parms = '/DecodeParms << /Predictor 15 /Colors '.$channels.' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
-
- $pal = '';
- $trns = '';
- $data = '';
- $icc = false;
- do {
- $n = $this->_freadint($f);
- $type = fread($f, 4);
- if ($type == 'PLTE') {
-
- $pal = $this->rfread($f, $n);
- fread($f, 4);
- } elseif ($type == 'tRNS') {
-
- $t = $this->rfread($f, $n);
- if ($ct == 0) {
- $trns = array(ord($t{1}));
- } elseif ($ct == 2) {
- $trns = array(ord($t{1}), ord($t{3}), ord($t{5}));
- } else {
- $pos = strpos($t, chr(0));
- if ($pos !== false) {
- $trns = array($pos);
- }
- }
- fread($f, 4);
- } elseif ($type == 'IDAT') {
-
- $data .= $this->rfread($f, $n);
- fread($f, 4);
- } elseif ($type == 'iCCP') {
-
- $len = 0;
- while ((ord(fread($f, 1)) > 0) AND ($len < 80)) {
- ++$len;
- }
-
- if (ord(fread($f, 1)) != 0) {
-
- fclose($f);
- return false;
- }
-
- $icc = $this->rfread($f, ($n - $len - 2));
-
- $icc = gzuncompress($icc);
- fread($f, 4);
- } elseif ($type == 'IEND') {
- break;
- } else {
- $this->rfread($f, $n + 4);
- }
- } while ($n);
- if (($colspace == 'Indexed') AND (empty($pal))) {
-
- fclose($f);
- return false;
- }
- fclose($f);
- return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
- }
-
- protected function rfread($handle, $length) {
- $data = fread($handle, $length);
- if ($data === false) {
- return false;
- }
- $rest = $length - strlen($data);
- if ($rest > 0) {
- $data .= $this->rfread($handle, $rest);
- }
- return $data;
- }
-
- protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
- if (empty($filehash)) {
- $filehash = md5($file);
- }
-
- $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash;
-
- $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash;
- if (extension_loaded('imagick')) {
-
- $img = new Imagick();
- $img->readImage($file);
-
- $imga = $img->clone();
-
- $img->separateImageChannel(8);
- $img->negateImage(true);
- $img->setImageFormat('png');
- $img->writeImage($tempfile_alpha);
-
- $imga->separateImageChannel(39);
- $imga->setImageFormat('png');
- $imga->writeImage($tempfile_plain);
- } elseif (function_exists('imagecreatefrompng')) {
-
- $img = imagecreatefrompng($file);
- $imgalpha = imagecreate($wpx, $hpx);
-
- for ($c = 0; $c < 256; ++$c) {
- ImageColorAllocate($imgalpha, $c, $c, $c);
- }
-
- for ($xpx = 0; $xpx < $wpx; ++$xpx) {
- for ($ypx = 0; $ypx < $hpx; ++$ypx) {
- $color = imagecolorat($img, $xpx, $ypx);
- $alpha = ($color >> 24);
- $alpha = (((127 - $alpha) / 127) * 255);
- $alpha = $this->getGDgamma($alpha);
- imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
- }
- }
- imagepng($imgalpha, $tempfile_alpha);
- imagedestroy($imgalpha);
-
- $imgplain = imagecreatetruecolor($wpx, $hpx);
- imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
- imagepng($imgplain, $tempfile_plain);
- imagedestroy($imgplain);
- } else {
- $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
- }
-
- $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
-
- $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
-
- unlink($tempfile_alpha);
- unlink($tempfile_plain);
- }
-
- protected function getGDgamma($v) {
- return (pow(($v / 255), 2.2) * 255);
- }
-
- public function Ln($h='', $cell=false) {
- if (($this->num_columns > 1) AND ($this->y == $this->columns[$this->current_column]['y']) AND isset($this->columns[$this->current_column]['x']) AND ($this->x == $this->columns[$this->current_column]['x'])) {
-
- return;
- }
- if ($cell) {
- if ($this->rtl) {
- $cellpadding = $this->cell_padding['R'];
- } else {
- $cellpadding = $this->cell_padding['L'];
- }
- } else {
- $cellpadding = 0;
- }
- if ($this->rtl) {
- $this->x = $this->w - $this->rMargin - $cellpadding;
- } else {
- $this->x = $this->lMargin + $cellpadding;
- }
- if (is_string($h)) {
- $this->y += $this->lasth;
- } else {
- $this->y += $h;
- }
- $this->newline = true;
- }
-
- public function GetX() {
-
- if ($this->rtl) {
- return ($this->w - $this->x);
- } else {
- return $this->x;
- }
- }
-
- public function GetAbsX() {
- return $this->x;
- }
-
- public function GetY() {
- return $this->y;
- }
-
- public function SetX($x, $rtloff=false) {
- if (!$rtloff AND $this->rtl) {
- if ($x >= 0) {
- $this->x = $this->w - $x;
- } else {
- $this->x = abs($x);
- }
- } else {
- if ($x >= 0) {
- $this->x = $x;
- } else {
- $this->x = $this->w + $x;
- }
- }
- if ($this->x < 0) {
- $this->x = 0;
- }
- if ($this->x > $this->w) {
- $this->x = $this->w;
- }
- }
-
- public function SetY($y, $resetx=true, $rtloff=false) {
- if ($resetx) {
-
- if (!$rtloff AND $this->rtl) {
- $this->x = $this->w - $this->rMargin;
- } else {
- $this->x = $this->lMargin;
- }
- }
- if ($y >= 0) {
- $this->y = $y;
- } else {
- $this->y = $this->h + $y;
- }
- if ($this->y < 0) {
- $this->y = 0;
- }
- if ($this->y > $this->h) {
- $this->y = $this->h;
- }
- }
-
- public function SetXY($x, $y, $rtloff=false) {
- $this->SetY($y, false, $rtloff);
- $this->SetX($x, $rtloff);
- }
-
- protected function sendOutputData($data, $length) {
- if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
-
- header('Content-Length: '.$length);
- }
- echo $data;
- }
-
- public function Output($name='doc.pdf', $dest='I') {
-
-
- if ($this->state < 3) {
- $this->Close();
- }
-
- if (is_bool($dest)) {
- $dest = $dest ? 'D' : 'F';
- }
- $dest = strtoupper($dest);
- if ($dest{0} != 'F') {
- $name = preg_replace('/[\s]+/', '_', $name);
- $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
- }
- if ($this->sign) {
-
-
- $pdfdoc = $this->getBuffer();
-
- $pdfdoc = substr($pdfdoc, 0, -1);
-
- if (isset($this->diskcache) AND $this->diskcache) {
-
- unlink($this->buffer);
- }
- unset($this->buffer);
-
- $byterange_string_len = strlen($this->byterange_string);
-
- $byte_range = array();
- $byte_range[0] = 0;
- $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
- $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
- $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
- $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
-
- $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
- $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
- $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
-
- $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
- $f = fopen($tempdoc, 'wb');
- if (!$f) {
- $this->Error('Unable to create temporary file: '.$tempdoc);
- }
- $pdfdoc_length = strlen($pdfdoc);
- fwrite($f, $pdfdoc, $pdfdoc_length);
- fclose($f);
-
- $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
- if (empty($this->signature_data['extracerts'])) {
- openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
- } else {
- openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']);
- }
- unlink($tempdoc);
-
- $signature = file_get_contents($tempsign);
- unlink($tempsign);
-
- $signature = substr($signature, $pdfdoc_length);
- $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
- $tmparr = explode("\n\n", $signature);
- $signature = $tmparr[1];
- unset($tmparr);
-
- $signature = base64_decode(trim($signature));
-
- $signature = current(unpack('H*', $signature));
- $signature = str_pad($signature, $this->signature_max_length, '0');
-
- $this->diskcache = false;
-
- $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
- $this->bufferlen = strlen($this->buffer);
- }
- switch($dest) {
- case 'I': {
-
- if (ob_get_contents()) {
- $this->Error('Some data has already been output, can\'t send PDF file');
- }
- if (php_sapi_name() != 'cli') {
-
- header('Content-Type: application/pdf');
- if (headers_sent()) {
- $this->Error('Some data has already been output to browser, can\'t send PDF file');
- }
- header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
-
- header('Pragma: public');
- header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
- header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
- header('Content-Disposition: inline; filename="'.basename($name).'";');
- $this->sendOutputData($this->getBuffer(), $this->bufferlen);
- } else {
- echo $this->getBuffer();
- }
- break;
- }
- case 'D': {
-
- if (ob_get_contents()) {
- $this->Error('Some data has already been output, can\'t send PDF file');
- }
- header('Content-Description: File Transfer');
- if (headers_sent()) {
- $this->Error('Some data has already been output to browser, can\'t send PDF file');
- }
- header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
-
- header('Pragma: public');
- header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
- header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
-
- if (strpos(php_sapi_name(), 'cgi') === false) {
- header('Content-Type: application/force-download');
- header('Content-Type: application/octet-stream', false);
- header('Content-Type: application/download', false);
- header('Content-Type: application/pdf', false);
- } else {
- header('Content-Type: application/pdf');
- }
-
- header('Content-Disposition: attachment; filename="'.basename($name).'";');
- header('Content-Transfer-Encoding: binary');
- $this->sendOutputData($this->getBuffer(), $this->bufferlen);
- break;
- }
- case 'F':
- case 'FI':
- case 'FD': {
-
- if ($this->diskcache) {
- copy($this->buffer, $name);
- } else {
- $f = fopen($name, 'wb');
- if (!$f) {
- $this->Error('Unable to create output file: '.$name);
- }
- fwrite($f, $this->getBuffer(), $this->bufferlen);
- fclose($f);
- }
- if ($dest == 'FI') {
-
- header('Content-Type: application/pdf');
- header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
-
- header('Pragma: public');
- header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
- header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
- header('Content-Disposition: inline; filename="'.basename($name).'";');
- $this->sendOutputData(file_get_contents($name), filesize($name));
- } elseif ($dest == 'FD') {
-
- if (ob_get_contents()) {
- $this->Error('Some data has already been output, can\'t send PDF file');
- }
- header('Content-Description: File Transfer');
- if (headers_sent()) {
- $this->Error('Some data has already been output to browser, can\'t send PDF file');
- }
- header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
- header('Pragma: public');
- header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
- header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
-
- if (strpos(php_sapi_name(), 'cgi') === false) {
- header('Content-Type: application/force-download');
- header('Content-Type: application/octet-stream', false);
- header('Content-Type: application/download', false);
- header('Content-Type: application/pdf', false);
- } else {
- header('Content-Type: application/pdf');
- }
-
- header('Content-Disposition: attachment; filename="'.basename($name).'";');
- header('Content-Transfer-Encoding: binary');
- $this->sendOutputData(file_get_contents($name), filesize($name));
- }
- break;
- }
- case 'E': {
-
- $retval = 'Content-Type: application/pdf;'."\r\n";
- $retval .= ' name="'.$name.'"'."\r\n";
- $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
- $retval .= 'Content-Disposition: attachment;'."\r\n";
- $retval .= ' filename="'.$name.'"'."\r\n\r\n";
- $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
- return $retval;
- }
- case 'S': {
-
- return $this->getBuffer();
- }
- default: {
- $this->Error('Incorrect output destination: '.$dest);
- }
- }
- return '';
- }
-
- public function _destroy($destroyall=false, $preserve_objcopy=false) {
- if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) {
-
- unlink($this->buffer);
- }
- foreach (array_keys(get_object_vars($this)) as $val) {
- if ($destroyall OR (
- ($val != 'internal_encoding')
- AND ($val != 'state')
- AND ($val != 'bufferlen')
- AND ($val != 'buffer')
- AND ($val != 'diskcache')
- AND ($val != 'sign')
- AND ($val != 'signature_data')
- AND ($val != 'signature_max_length')
- AND ($val != 'byterange_string')
- )) {
- if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
- unset($this->$val);
- }
- }
- }
- }
-
- protected function _dochecks() {
-
- if (1.1 == 1) {
- $this->Error('Don\'t alter the locale before including class file');
- }
-
- if (sprintf('%.1F', 1.0) != '1.0') {
- setlocale(LC_NUMERIC, 'C');
- }
- }
-
- protected function _getfontpath() {
- if (!defined('K_PATH_FONTS') AND is_dir(dirname(__FILE__).'/fonts')) {
- define('K_PATH_FONTS', dirname(__FILE__).'/fonts/');
- }
- return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
- }
-
- protected function getInternalPageNumberAliases($a= '') {
- $alias = array();
-
- $alias = array('u' => array(), 'a' => array());
- $u = '{'.$a.'}';
- $alias['u'][] = $this->_escape($u);
- if ($this->isunicode) {
- $alias['u'][] = $this->_escape($this->UTF8ToLatin1($u));
- $alias['u'][] = $this->_escape($this->utf8StrRev($u, false, $this->tmprtl));
- $alias['a'][] = $this->_escape($this->UTF8ToLatin1($a));
- $alias['a'][] = $this->_escape($this->utf8StrRev($a, false, $this->tmprtl));
- }
- $alias['a'][] = $this->_escape($a);
- return $alias;
- }
-
- protected function getAllInternalPageNumberAliases() {
- $basic_alias = array($this->alias_tot_pages, $this->alias_num_page, $this->alias_group_tot_pages, $this->alias_group_num_page, $this->alias_right_shift);
- $pnalias = array();
- foreach($basic_alias as $k => $a) {
- $pnalias[$k] = $this->getInternalPageNumberAliases($a);
- }
- return $pnalias;
- }
-
- protected function replacePageNumAliases($page, $replace, $diff=0) {
- foreach ($replace as $rep) {
- foreach ($rep[3] as $a) {
- if (strpos($page, $a) !== false) {
- $page = str_replace($a, $rep[0], $page);
- $diff += ($rep[2] - $rep[1]);
- }
- }
- }
- return array($page, $diff);
- }
-
- protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
- foreach ($aliases as $type => $alias) {
- foreach ($alias as $a) {
-
- $startnum = (strpos($a, ':') + 1);
- $a = substr($a, 0, $startnum);
- if (($pos = strpos($page, $a)) !== false) {
-
- $endnum = strpos($page, '}', $pos);
-
- $aa = substr($page, $pos, ($endnum - $pos + 1));
-
- $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
- $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
- $ratio = floatval($ratio);
- if ($type == 'u') {
- $chrdiff = floor(($diff + 12) * $ratio);
- $shift = str_repeat(' ', $chrdiff);
- $shift = $this->UTF8ToUTF16BE($shift, false);
- } else {
- $chrdiff = floor(($diff + 11) * $ratio);
- $shift = str_repeat(' ', $chrdiff);
- }
- $page = str_replace($aa, $shift, $page);
- }
- }
- }
- return $page;
- }
-
- protected function _putpages() {
- $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
-
- $pnalias = $this->getAllInternalPageNumberAliases();
- $num_pages = $this->numpages;
- $ptpa = $this->formatPageNumber(($this->starting_page_number + $num_pages - 1));
- $ptpu = $this->UTF8ToUTF16BE($ptpa, false);
- $ptp_num_chars = $this->GetNumChars($ptpa);
- $pagegroupnum = 0;
- $groupnum = 0;
- $ptgu = 1;
- $ptga = 1;
- for ($n = 1; $n <= $num_pages; ++$n) {
-
- $temppage = $this->getPageBuffer($n);
- $pagelen = strlen($temppage);
-
- $pnpa = $this->formatPageNumber(($this->starting_page_number + $n - 1));
- $pnpu = $this->UTF8ToUTF16BE($pnpa, false);
- $pnp_num_chars = $this->GetNumChars($pnpa);
- $pdiff = 0;
- $gdiff = 0;
- if (!empty($this->pagegroups)) {
- if (isset($this->newpagegroup[$n])) {
- $pagegroupnum = 0;
- ++$groupnum;
- $ptga = $this->formatPageNumber($this->pagegroups[$groupnum]);
- $ptgu = $this->UTF8ToUTF16BE($ptga, false);
- $ptg_num_chars = $this->GetNumChars($ptga);
- }
- ++$pagegroupnum;
- $pnga = $this->formatPageNumber($pagegroupnum);
- $pngu = $this->UTF8ToUTF16BE($pnga, false);
- $png_num_chars = $this->GetNumChars($pnga);
-
- $replace = array();
- $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
- $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
- $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
- $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
- list($temppage, $gdiff) = $this->replacePageNumAliases($temppage, $replace, $gdiff);
- }
-
- $replace = array();
- $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
- $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
- $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
- $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
- list($temppage, $pdiff) = $this->replacePageNumAliases($temppage, $replace, $pdiff);
-
- $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
-
- $temppage = str_replace($this->epsmarker, '', $temppage);
-
- $this->page_obj_id[$n] = $this->_newobj();
- $out = '<<';
- $out .= ' /Type /Page';
- $out .= ' /Parent 1 0 R';
- $out .= ' /LastModified '.$this->_datestring();
- $out .= ' /Resources 2 0 R';
- $boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
- foreach ($boxes as $box) {
- $out .= ' /'.$box;
- $out .= sprintf(' [%.2F %.2F %.2F %.2F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
- }
- if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
- $out .= ' /BoxColorInfo <<';
- foreach ($boxes as $box) {
- if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
- $out .= ' /'.$box.' <<';
- if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
- $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
- $out .= ' /C [';
- $out .= sprintf(' %.3F %.3F %.3F', $color[0]/255, $color[1]/255, $color[2]/255);
- $out .= ' ]';
- }
- if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
- $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
- }
- if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
- $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
- }
- if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
- $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
- $out .= ' /D [';
- foreach ($dashes as $dash) {
- $out .= sprintf(' %.3F', ($dash * $this->k));
- }
- $out .= ' ]';
- }
- $out .= ' >>';
- }
- }
- $out .= ' >>';
- }
- $out .= ' /Contents '.($this->n + 1).' 0 R';
- $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
- if (!$this->pdfa_mode) {
- $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
- }
- if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
-
- if (isset($this->pagedim[$n]['trans']['Dur'])) {
- $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
- }
- $out .= ' /Trans <<';
- $out .= ' /Type /Trans';
- if (isset($this->pagedim[$n]['trans']['S'])) {
- $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
- }
- if (isset($this->pagedim[$n]['trans']['D'])) {
- $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
- }
- if (isset($this->pagedim[$n]['trans']['Dm'])) {
- $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
- }
- if (isset($this->pagedim[$n]['trans']['M'])) {
- $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
- }
- if (isset($this->pagedim[$n]['trans']['Di'])) {
- $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
- }
- if (isset($this->pagedim[$n]['trans']['SS'])) {
- $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
- }
- if (isset($this->pagedim[$n]['trans']['B'])) {
- $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
- }
- $out .= ' >>';
- }
- $out .= $this->_getannotsrefs($n);
- $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
-
- $p = ($this->compress) ? gzcompress($temppage) : $temppage;
- $this->_newobj();
- $p = $this->_getrawstream($p);
- $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
- if ($this->diskcache) {
-
- unlink($this->pages[$n]);
- }
- }
-
- $out = $this->_getobj(1)."\n";
- $out .= '<< /Type /Pages /Kids [';
- foreach($this->page_obj_id as $page_obj) {
- $out .= ' '.$page_obj.' 0 R';
- }
- $out .= ' ] /Count '.$num_pages.' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- protected function _putannotsrefs($n) {
- $this->_out($this->_getannotsrefs($n));
- }
-
- protected function _getannotsrefs($n) {
- if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
- return '';
- }
- $out = ' /Annots [';
- if (isset($this->PageAnnots[$n])) {
- foreach ($this->PageAnnots[$n] as $key => $val) {
- if (!in_array($val['n'], $this->radio_groups)) {
- $out .= ' '.$val['n'].' 0 R';
- }
- }
-
- if (isset($this->radiobutton_groups[$n])) {
- foreach ($this->radiobutton_groups[$n] as $key => $data) {
- if (isset($data['n'])) {
- $out .= ' '.$data['n'].' 0 R';
- }
- }
- }
- }
- if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
-
- $out .= ' '.$this->sig_obj_id.' 0 R';
- }
- if (!empty($this->empty_signature_appearance)) {
- foreach ($this->empty_signature_appearance as $esa) {
- if ($esa['page'] == $n) {
-
- $out .= ' '.$esa['objid'].' 0 R';
- }
- }
- }
- $out .= ' ]';
- return $out;
- }
-
- protected function _putannotsobjs() {
-
- for ($n=1; $n <= $this->numpages; ++$n) {
- if (isset($this->PageAnnots[$n])) {
-
- foreach ($this->PageAnnots[$n] as $key => $pl) {
- $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
-
- if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
- $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
- $annots = '<<';
- $annots .= ' /Type /Annot';
- $annots .= ' /Subtype /Widget';
- $annots .= ' /Rect [0 0 0 0]';
- if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
-
- $annots .= ' /F 68';
- $annots .= ' /Ff 49153';
- } else {
- $annots .= ' /F 4';
- $annots .= ' /Ff 49152';
- }
- $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
- $annots .= ' /FT /Btn';
- $annots .= ' /Kids [';
- foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
- if (isset($data['kid'])) {
- $annots .= ' '.$data['kid'].' 0 R';
- if ($data['def'] !== 'Off') {
- $defval = $data['def'];
- }
- }
- }
- $annots .= ' ]';
- if (isset($defval)) {
- $annots .= ' /V /'.$defval;
- }
- $annots .= ' >>';
- $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
- $this->form_obj_id[] = $radio_button_obj_id;
-
- $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
- }
- $formfield = false;
- $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
- $a = $pl['x'] * $this->k;
- $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
- $c = $pl['w'] * $this->k;
- $d = $pl['h'] * $this->k;
- $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+$c, $b+$d);
-
- $annots = '<</Type /Annot';
- $annots .= ' /Subtype /'.$pl['opt']['subtype'];
- $annots .= ' /Rect ['.$rect.']';
- $ft = array('Btn', 'Tx', 'Ch', 'Sig');
- if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
- $annots .= ' /FT /'.$pl['opt']['ft'];
- $formfield = true;
- }
- $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
- $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
- $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
- $annots .= ' /M '.$this->_datestring($annot_obj_id);
- if (isset($pl['opt']['f'])) {
- $fval = 0;
- if (is_array($pl['opt']['f'])) {
- foreach ($pl['opt']['f'] as $f) {
- switch (strtolower($f)) {
- case 'invisible': {
- $fval += 1 << 0;
- break;
- }
- case 'hidden': {
- $fval += 1 << 1;
- break;
- }
- case 'print': {
- $fval += 1 << 2;
- break;
- }
- case 'nozoom': {
- $fval += 1 << 3;
- break;
- }
- case 'norotate': {
- $fval += 1 << 4;
- break;
- }
- case 'noview': {
- $fval += 1 << 5;
- break;
- }
- case 'readonly': {
- $fval += 1 << 6;
- break;
- }
- case 'locked': {
- $fval += 1 << 8;
- break;
- }
- case 'togglenoview': {
- $fval += 1 << 9;
- break;
- }
- case 'lockedcontents': {
- $fval += 1 << 10;
- break;
- }
- default: {
- break;
- }
- }
- }
- } else {
- $fval = intval($pl['opt']['f']);
- }
- } else {
- $fval = 4;
- }
- if ($this->pdfa_mode) {
-
- $fval |= 4;
- }
- $annots .= ' /F '.intval($fval);
- if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
- $annots .= ' /AS /'.$pl['opt']['as'];
- }
- if (isset($pl['opt']['ap'])) {
-
- $annots .= ' /AP <<';
- if (is_array($pl['opt']['ap'])) {
- foreach ($pl['opt']['ap'] as $apmode => $apdef) {
-
- $annots .= ' /'.strtoupper($apmode);
- if (is_array($apdef)) {
- $annots .= ' <<';
- foreach ($apdef as $apstate => $stream) {
-
- $apsobjid = $this->_putAPXObject($c, $d, $stream);
- $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
- }
- $annots .= ' >>';
- } else {
-
- $apsobjid = $this->_putAPXObject($c, $d, $apdef);
- $annots .= ' '.$apsobjid.' 0 R';
- }
- }
- } else {
- $annots .= $pl['opt']['ap'];
- }
- $annots .= ' >>';
- }
- if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
- $annots .= ' /BS <<';
- $annots .= ' /Type /Border';
- if (isset($pl['opt']['bs']['w'])) {
- $annots .= ' /W '.intval($pl['opt']['bs']['w']);
- }
- $bstyles = array('S', 'D', 'B', 'I', 'U');
- if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
- $annots .= ' /S /'.$pl['opt']['bs']['s'];
- }
- if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
- $annots .= ' /D [';
- foreach ($pl['opt']['bs']['d'] as $cord) {
- $annots .= ' '.intval($cord);
- }
- $annots .= ']';
- }
- $annots .= ' >>';
- } else {
- $annots .= ' /Border [';
- if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
- $annots .= intval($pl['opt']['border'][0]).' ';
- $annots .= intval($pl['opt']['border'][1]).' ';
- $annots .= intval($pl['opt']['border'][2]);
- if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
- $annots .= ' [';
- foreach ($pl['opt']['border'][3] as $dash) {
- $annots .= intval($dash).' ';
- }
- $annots .= ']';
- }
- } else {
- $annots .= '0 0 0';
- }
- $annots .= ']';
- }
- if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
- $annots .= ' /BE <<';
- $bstyles = array('S', 'C');
- if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $markups)) {
- $annots .= ' /S /'.$pl['opt']['bs']['s'];
- } else {
- $annots .= ' /S /S';
- }
- if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
- $annots .= ' /I '.sprintf(' %.4F', $pl['opt']['be']['i']);
- }
- $annots .= '>>';
- }
- if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
- $annots .= ' /C [';
- foreach ($pl['opt']['c'] as $col) {
- $col = intval($col);
- $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
- $annots .= sprintf(' %.4F', $color);
- }
- $annots .= ']';
- }
-
-
- $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
- if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
-
- if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
- $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
- }
-
- if (isset($pl['opt']['ca'])) {
- $annots .= ' /CA '.sprintf('%.4F', floatval($pl['opt']['ca']));
- }
- if (isset($pl['opt']['rc'])) {
- $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
- }
- $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id);
-
- if (isset($pl['opt']['subj'])) {
- $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
- }
-
-
-
- }
- $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
-
- switch (strtolower($pl['opt']['subtype'])) {
- case 'text': {
- if (isset($pl['opt']['open'])) {
- $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
- }
- $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
- if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
- $annots .= ' /Name /'.$pl['opt']['name'];
- } else {
- $annots .= ' /Name /Note';
- }
- $statemodels = array('Marked', 'Review');
- if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
- $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
- } else {
- $pl['opt']['statemodel'] = 'Marked';
- $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
- }
- if ($pl['opt']['statemodel'] == 'Marked') {
- $states = array('Accepted', 'Unmarked');
- } else {
- $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
- }
- if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
- $annots .= ' /State /'.$pl['opt']['state'];
- } else {
- if ($pl['opt']['statemodel'] == 'Marked') {
- $annots .= ' /State /Unmarked';
- } else {
- $annots .= ' /State /None';
- }
- }
- break;
- }
- case 'link': {
- if (is_string($pl['txt'])) {
-
- $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
- } else {
-
- $l = $this->links[$pl['txt']];
- if (isset($this->page_obj_id[($l[0])])) {
- $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
- }
- }
- $hmodes = array('N', 'I', 'O', 'P');
- if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
- $annots .= ' /H /'.$pl['opt']['h'];
- } else {
- $annots .= ' /H /I';
- }
-
-
- break;
- }
- case 'freetext': {
- if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
- $annots .= ' /DA ('.$pl['opt']['da'].')';
- }
- if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
- $annots .= ' /Q '.intval($pl['opt']['q']);
- }
- if (isset($pl['opt']['rc'])) {
- $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
- }
- if (isset($pl['opt']['ds'])) {
- $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
- }
- if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
- $annots .= ' /CL [';
- foreach ($pl['opt']['cl'] as $cl) {
- $annots .= sprintf('%.4F ', $cl * $this->k);
- }
- $annots .= ']';
- }
- $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
- if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
- $annots .= ' /IT /'.$pl['opt']['it'];
- }
- if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
- $l = $pl['opt']['rd'][0] * $this->k;
- $r = $pl['opt']['rd'][1] * $this->k;
- $t = $pl['opt']['rd'][2] * $this->k;
- $b = $pl['opt']['rd'][3] * $this->k;
- $annots .= ' /RD ['.sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b).']';
- }
- if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
- $annots .= ' /LE /'.$pl['opt']['le'];
- }
- break;
- }
- case 'line': {
- break;
- }
- case 'square': {
- break;
- }
- case 'circle': {
- break;
- }
- case 'polygon': {
- break;
- }
- case 'polyline': {
- break;
- }
- case 'highlight': {
- break;
- }
- case 'underline': {
- break;
- }
- case 'squiggly': {
- break;
- }
- case 'strikeout': {
- break;
- }
- case 'stamp': {
- break;
- }
- case 'caret': {
- break;
- }
- case 'ink': {
- break;
- }
- case 'popup': {
- break;
- }
- case 'fileattachment': {
- if ($this->pdfa_mode) {
-
- break;
- }
- if (!isset($pl['opt']['fs'])) {
- break;
- }
- $filename = basename($pl['opt']['fs']);
- if (isset($this->embeddedfiles[$filename]['n'])) {
- $annots .= ' /FS <</Type /Filespec /F '.$this->_datastring($filename, $annot_obj_id).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
- $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
- if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
- $annots .= ' /Name /'.$pl['opt']['name'];
- } else {
- $annots .= ' /Name /PushPin';
- }
- }
- break;
- }
- case 'sound': {
- if (!isset($pl['opt']['fs'])) {
- break;
- }
- $filename = basename($pl['opt']['fs']);
- if (isset($this->embeddedfiles[$filename]['n'])) {
-
-
- $annots .= ' /Sound <</Type /Filespec /F '.$this->_datastring($filename, $annot_obj_id).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
- $iconsapp = array('Speaker', 'Mic');
- if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
- $annots .= ' /Name /'.$pl['opt']['name'];
- } else {
- $annots .= ' /Name /Speaker';
- }
- }
- break;
- }
- case 'movie': {
- break;
- }
- case 'widget': {
- $hmode = array('N', 'I', 'O', 'P', 'T');
- if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
- $annots .= ' /H /'.$pl['opt']['h'];
- }
- if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
- $annots .= ' /MK <<';
- if (isset($pl['opt']['mk']['r'])) {
- $annots .= ' /R '.$pl['opt']['mk']['r'];
- }
- if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
- $annots .= ' /BC [';
- foreach($pl['opt']['mk']['bc'] AS $col) {
- $col = intval($col);
- $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
- $annots .= sprintf(' %.2F', $color);
- }
- $annots .= ']';
- }
- if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
- $annots .= ' /BG [';
- foreach($pl['opt']['mk']['bg'] AS $col) {
- $col = intval($col);
- $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
- $annots .= sprintf(' %.2F', $color);
- }
- $annots .= ']';
- }
- if (isset($pl['opt']['mk']['ca'])) {
- $annots .= ' /CA '.$pl['opt']['mk']['ca'];
- }
- if (isset($pl['opt']['mk']['rc'])) {
- $annots .= ' /RC '.$pl['opt']['mk']['rc'];
- }
- if (isset($pl['opt']['mk']['ac'])) {
- $annots .= ' /AC '.$pl['opt']['mk']['ac'];
- }
- if (isset($pl['opt']['mk']['i'])) {
- $info = $this->getImageBuffer($pl['opt']['mk']['i']);
- if ($info !== false) {
- $annots .= ' /I '.$info['n'].' 0 R';
- }
- }
- if (isset($pl['opt']['mk']['ri'])) {
- $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
- if ($info !== false) {
- $annots .= ' /RI '.$info['n'].' 0 R';
- }
- }
- if (isset($pl['opt']['mk']['ix'])) {
- $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
- if ($info !== false) {
- $annots .= ' /IX '.$info['n'].' 0 R';
- }
- }
- if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
- $annots .= ' /IF <<';
- $if_sw = array('A', 'B', 'S', 'N');
- if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
- $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
- }
- $if_s = array('A', 'P');
- if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
- $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
- }
- if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
- $annots .= sprintf(' /A [%.2F %.2F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
- }
- if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
- $annots .= ' /FB true';
- }
- $annots .= '>>';
- }
- if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
- $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
- }
- $annots .= '>>';
- }
-
- if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
-
- $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
- }
- if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
- $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
- }
- if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
- $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
- }
- if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
- $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
- }
- if (isset($pl['opt']['ff'])) {
- if (is_array($pl['opt']['ff'])) {
-
- $flag = 0;
- foreach($pl['opt']['ff'] as $val) {
- $flag += 1 << ($val - 1);
- }
- } else {
- $flag = intval($pl['opt']['ff']);
- }
- $annots .= ' /Ff '.$flag;
- }
- if (isset($pl['opt']['maxlen'])) {
- $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
- }
- if (isset($pl['opt']['v'])) {
- $annots .= ' /V';
- if (is_array($pl['opt']['v'])) {
- foreach ($pl['opt']['v'] AS $optval) {
- if (is_float($optval)) {
- $optval = sprintf('%.2F', $optval);
- }
- $annots .= ' '.$optval;
- }
- } else {
- $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
- }
- }
- if (isset($pl['opt']['dv'])) {
- $annots .= ' /DV';
- if (is_array($pl['opt']['dv'])) {
- foreach ($pl['opt']['dv'] AS $optval) {
- if (is_float($optval)) {
- $optval = sprintf('%.2F', $optval);
- }
- $annots .= ' '.$optval;
- }
- } else {
- $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
- }
- }
- if (isset($pl['opt']['rv'])) {
- $annots .= ' /RV';
- if (is_array($pl['opt']['rv'])) {
- foreach ($pl['opt']['rv'] AS $optval) {
- if (is_float($optval)) {
- $optval = sprintf('%.2F', $optval);
- }
- $annots .= ' '.$optval;
- }
- } else {
- $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
- }
- }
- if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
- $annots .= ' /A << '.$pl['opt']['a'].' >>';
- }
- if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
- $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
- }
- if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
- $annots .= ' /DA ('.$pl['opt']['da'].')';
- }
- if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
- $annots .= ' /Q '.intval($pl['opt']['q']);
- }
- if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
- $annots .= ' /Opt [';
- foreach($pl['opt']['opt'] AS $copt) {
- if (is_array($copt)) {
- $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
- } else {
- $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
- }
- }
- $annots .= ']';
- }
- if (isset($pl['opt']['ti'])) {
- $annots .= ' /TI '.intval($pl['opt']['ti']);
- }
- if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
- $annots .= ' /I [';
- foreach($pl['opt']['i'] AS $copt) {
- $annots .= intval($copt).' ';
- }
- $annots .= ']';
- }
- break;
- }
- case 'screen': {
- break;
- }
- case 'printermark': {
- break;
- }
- case 'trapnet': {
- break;
- }
- case 'watermark': {
- break;
- }
- case '3d': {
- break;
- }
- default: {
- break;
- }
- }
- $annots .= '>>';
-
- $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
- if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
-
- $this->form_obj_id[] = $annot_obj_id;
- }
- }
- }
- }
- }
-
- protected function _putAPXObject($w=0, $h=0, $stream='') {
- $stream = trim($stream);
- $out = $this->_getobj()."\n";
- $this->xobjects['AX'.$this->n] = array('n' => $this->n);
- $out .= '<<';
- $out .= ' /Type /XObject';
- $out .= ' /Subtype /Form';
- $out .= ' /FormType 1';
- if ($this->compress) {
- $stream = gzcompress($stream);
- $out .= ' /Filter /FlateDecode';
- }
- $rect = sprintf('%.2F %.2F', $w, $h);
- $out .= ' /BBox [0 0 '.$rect.']';
- $out .= ' /Matrix [1 0 0 1 0 0]';
- $out .= ' /Resources 2 0 R';
- $stream = $this->_getrawstream($stream);
- $out .= ' /Length '.strlen($stream);
- $out .= ' >>';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- $out .= "\n".'endobj';
- $this->_out($out);
- return $this->n;
- }
-
- protected function _getULONG($str, $offset) {
- $v = unpack('Ni', substr($str, $offset, 4));
- return $v['i'];
- }
-
- protected function _getUSHORT($str, $offset) {
- $v = unpack('ni', substr($str, $offset, 2));
- return $v['i'];
- }
-
- protected function _getSHORT($str, $offset) {
- $v = unpack('si', substr($str, $offset, 2));
- return $v['i'];
- }
-
- protected function _getFWORD($str, $offset) {
- $v = $this->_getUSHORT($str, $offset);
- if ($v > 0x7fff) {
- $v -= 0x10000;
- }
- return $v;
- }
-
- protected function _getUFWORD($str, $offset) {
- $v = $this->_getUSHORT($str, $offset);
- return $v;
- }
-
- protected function _getFIXED($str, $offset) {
-
- $m = $this->_getFWORD($str, $offset);
-
- $f = $this->_getUSHORT($str, ($offset + 2));
- $v = floatval(''.$m.'.'.$f.'');
- return $v;
- }
-
- protected function _getBYTE($str, $offset) {
- $v = unpack('Ci', substr($str, $offset, 1));
- return $v['i'];
- }
-
- protected function updateCIDtoGIDmap($map, $cid, $gid) {
- if (($cid >= 0) AND ($cid <= 0xFFFF) AND ($gid >= 0)) {
- if ($gid > 0xFFFF) {
- $gid -= 0x10000;
- }
- $map[($cid * 2)] = chr($gid >> 8);
- $map[(($cid * 2) + 1)] = chr($gid & 0xFF);
- }
- return $map;
- }
-
- public function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='') {
- if (!file_exists($fontfile)) {
- $this->Error('Could not find file: '.$fontfile.'');
- }
-
- $fmetric = array();
-
- $font_path_parts = pathinfo($fontfile);
- if (!isset($font_path_parts['filename'])) {
- $font_path_parts['filename'] = substr($font_path_parts['basename'], 0, -(strlen($font_path_parts['extension']) + 1));
- }
- $font_name = strtolower($font_path_parts['filename']);
- $font_name = preg_replace('/[^a-z0-9_]/', '', $font_name);
- $search = array('bold', 'oblique', 'italic', 'regular');
- $replace = array('b', 'i', 'i', '');
- $font_name = str_replace($search, $replace, $font_name);
- if (empty($font_name)) {
-
- $font_name = 'tcpdffont';
- }
-
- if (empty($outpath)) {
- $outpath = $this->_getfontpath();
- }
-
- if (file_exists($outpath.$font_name.'.php')) {
-
- return $font_name;
- }
- $fmetric['file'] = $font_name.'.z';
- $fmetric['ctg'] = $font_name.'.ctg.z';
-
- $font = file_get_contents($fontfile);
- $fmetric['originalsize'] = strlen($font);
-
- if (empty($fonttype)) {
- if ($this->_getULONG($font, 0) == 0x10000) {
-
- $fonttype = 'TrueTypeUnicode';
- } elseif (substr($font, 0, 4) == 'OTTO') {
-
- $this->Error('Unsupported font format: OpenType with CFF data.');
- } else {
-
- $fonttype = 'Type1';
- }
- }
-
- switch ($fonttype) {
- case 'CID0CT':
- case 'CID0CS':
- case 'CID0KR':
- case 'CID0JP': {
- $fmetric['type'] = 'cidfont0';
- break;
- }
- case 'Type1': {
- $fmetric['type'] = 'Type1';
- if (empty($enc) AND (($flags & 4) == 0)) {
- $enc = 'cp1252';
- }
- break;
- }
- case 'TrueType': {
- $fmetric['type'] = 'TrueType';
- break;
- }
- case 'TrueTypeUnicode':
- default: {
- $fmetric['type'] = 'TrueTypeUnicode';
- break;
- }
- }
-
- $fmetric['enc'] = preg_replace('/[^A-Za-z0-9_\-]/', '', $enc);
- $fmetric['diff'] = '';
- if (($fmetric['type'] == 'TrueType') OR ($fmetric['type'] == 'Type1')) {
- if (!empty($enc) AND ($enc != 'cp1252') AND isset($this->encmaps->encmap[$enc])) {
-
- $enc_ref = $this->encmaps->encmap['cp1252'];
- $enc_target = $this->encmaps->encmap[$enc];
- $last = 0;
- for ($i = 32; $i <= 255; ++$i) {
- if ($enc_target != $enc_ref[$i]) {
- if ($i != ($last + 1)) {
- $fmetric['diff'] .= $i.' ';
- }
- $last = $i;
- $fmetric['diff'] .= '/'.$enc_target[$i].' ';
- }
- }
- }
- }
-
- if ($fmetric['type'] == 'Type1') {
-
-
- $a = unpack('Cmarker/Ctype/Vsize', substr($font, 0, 6));
- if ($a['marker'] != 128) {
- $this->Error('Font file is not a valid binary Type1');
- }
- $fmetric['size1'] = $a['size'];
- $data = substr($font, 6, $fmetric['size1']);
-
- $a = unpack('Cmarker/Ctype/Vsize', substr($font, (6 + $fmetric['size1']), 6));
- if ($a['marker'] != 128) {
- $this->Error('Font file is not a valid binary Type1');
- }
- $fmetric['size2'] = $a['size'];
- $encrypted = substr($font, (12 + $fmetric['size1']), $fmetric['size2']);
- $data .= $encrypted;
-
- $fp = fopen($outpath.$fmetric['file'], 'wb');
- fwrite($fp, gzcompress($data));
- fclose($fp);
-
- $fmetric['Flags'] = $flags;
- preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
- $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
- preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches);
- $fmetric['bbox'] = trim($matches[1]);
- $bv = explode(' ', $fmetric['bbox']);
- $fmetric['Ascent'] = intval($bv[3]);
- $fmetric['Descent'] = intval($bv[1]);
- preg_match('#/ItalicAngle[\s]*([0-9\+\-]*)#', $font, $matches);
- $fmetric['italicAngle'] = intval($matches[1]);
- if ($fmetric['italicAngle'] != 0) {
- $fmetric['Flags'] |= 64;
- }
- preg_match('#/UnderlinePosition[\s]*([0-9\+\-]*)#', $font, $matches);
- $fmetric['underlinePosition'] = intval($matches[1]);
- preg_match('#/UnderlineThickness[\s]*([0-9\+\-]*)#', $font, $matches);
- $fmetric['underlineThickness'] = intval($matches[1]);
- preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches);
- if ($matches[1] == 'true') {
- $fmetric['Flags'] |= 1;
- }
-
- $imap = array();
- if (preg_match_all('#dup[\s]([0-9]+)[\s]*/([^\s]*)[\s]put#sU', $font, $fmap, PREG_SET_ORDER) > 0) {
- foreach ($fmap as $v) {
- $imap[$v[2]] = $v[1];
- }
- }
-
- $r = 55665;
- $c1 = 52845;
- $c2 = 22719;
- $elen = strlen($encrypted);
- $eplain = '';
- for ($i = 0; $i < $elen; ++$i) {
- $chr = ord($encrypted[$i]);
- $eplain .= chr($chr ^ ($r >> 8));
- $r = ((($chr + $r) * $c1 + $c2) % 65536);
- }
- if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) {
- if ($matches[1] == 'true') {
- $fmetric['Flags'] |= 0x40000;
- }
- }
- if (preg_match('#/StdVW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
- $fmetric['StemV'] = intval($matches[1]);
- } else {
- $fmetric['StemV'] = 70;
- }
- if (preg_match('#/StdHW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
- $fmetric['StemH'] = intval($matches[1]);
- } else {
- $fmetric['StemH'] = 30;
- }
- if (preg_match('#/BlueValues[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
- $bv = explode(' ', $matches[1]);
- if (count($bv) >= 6) {
- $v1 = intval($bv[2]);
- $v2 = intval($bv[4]);
- if ($v1 <= $v2) {
- $fmetric['XHeight'] = $v1;
- $fmetric['CapHeight'] = $v2;
- } else {
- $fmetric['XHeight'] = $v2;
- $fmetric['CapHeight'] = $v1;
- }
- } else {
- $fmetric['XHeight'] = 450;
- $fmetric['CapHeight'] = 700;
- }
- } else {
- $fmetric['XHeight'] = 450;
- $fmetric['CapHeight'] = 700;
- }
-
- if (preg_match('#/lenIV[\s]*([0-9]*)#', $eplain, $matches) > 0) {
- $lenIV = intval($matches[1]);
- } else {
- $lenIV = 4;
- }
- $fmetric['Leading'] = 0;
-
- $eplain = substr($eplain, (strpos($eplain, '/CharStrings') + 1));
- preg_match_all('#/([A-Za-z0-9\.]*)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER);
- if (!empty($enc) AND isset($this->encmaps->encmap[$enc])) {
- $enc_map = $this->encmaps->encmap[$enc];
- } else {
- $enc_map = false;
- }
- $fmetric['cw'] = '';
- $fmetric['MaxWidth'] = 0;
- $cwidths = array();
- foreach ($matches as $k => $v) {
- $cid = 0;
- if (isset($imap[$v[1]])) {
- $cid = $imap[$v[1]];
- } elseif ($enc_map !== false) {
- $cid = array_search($v[1], $enc_map);
- if ($cid === false) {
- $cid = 0;
- } elseif ($cid > 1000) {
- $cid -= 1000;
- }
- }
-
- $r = 4330;
- $c1 = 52845;
- $c2 = 22719;
- $cd = $v[2];
- $clen = strlen($cd);
- $ccom = array();
- for ($i = 0; $i < $clen; ++$i) {
- $chr = ord($cd[$i]);
- $ccom[] = ($chr ^ ($r >> 8));
- $r = ((($chr + $r) * $c1 + $c2) % 65536);
- }
-
- $cdec = array();
- $ck = 0;
- $i = $lenIV;
- while ($i < $clen) {
- if ($ccom[$i] < 32) {
- $cdec[$ck] = $ccom[$i];
- if (($ck > 0) AND ($cdec[$ck] == 13)) {
-
- $cwidths[$cid] = $cdec[($ck - 1)];
- }
- ++$i;
- } elseif (($ccom[$i] >= 32) AND ($ccom[$i] <= 246)) {
- $cdec[$ck] = ($ccom[$i] - 139);
- ++$i;
- } elseif (($ccom[$i] >= 247) AND ($ccom[$i] <= 250)) {
- $cdec[$ck] = ((($ccom[$i] - 247) * 256) + $ccom[($i + 1)] + 108);
- $i += 2;
- } elseif (($ccom[$i] >= 251) AND ($ccom[$i] <= 254)) {
- $cdec[$ck] = ((-($ccom[$i] - 251) * 256) - $ccom[($i + 1)] - 108);
- $i += 2;
- } elseif ($ccom[$i] == 255) {
- $sval = chr($ccom[($i + 1)]).chr($ccom[($i + 2)]).chr($ccom[($i + 3)]).chr($ccom[($i + 4)]);
- $vsval = unpack('li', $sval);
- $cdec[$ck] = $vsval['i'];
- $i += 5;
- }
- ++$ck;
- }
- }
- $fmetric['MissingWidth'] = $cwidths[0];
- $fmetric['MaxWidth'] = $fmetric['MissingWidth'];
- $fmetric['AvgWidth'] = 0;
-
- for ($cid = 0; $cid <= 255; ++$cid) {
- if (isset($cwidths[$cid])) {
- if ($cwidths[$cid] > $fmetric['MaxWidth']) {
- $fmetric['MaxWidth'] = $cwidths[$cid];
- }
- $fmetric['AvgWidth'] += $cwidths[$cid];
- $fmetric['cw'] .= ','.$cid.'=>'.$cwidths[$cid];
- } else {
- $fmetric['cw'] .= ','.$cid.'=>'.$fmetric['MissingWidth'];
- }
- }
- $fmetric['AvgWidth'] = round($fmetric['AvgWidth'] / count($cwidths));
- } else {
-
- if ($fmetric['type'] != 'cidfont0') {
-
- $fp = fopen($outpath.$fmetric['file'], 'wb');
- fwrite($fp, gzcompress($font));
- fclose($fp);
- }
- $offset = 0;
- if ($this->_getULONG($font, $offset) != 0x10000) {
-
- return $font;
- }
- $offset += 4;
-
- $numTables = $this->_getUSHORT($font, $offset);
- $offset += 2;
-
- $offset += 6;
-
- $table = array();
-
- for ($i = 0; $i < $numTables; ++$i) {
-
- $tag = substr($font, $offset, 4);
- $offset += 4;
- $table[$tag] = array();
- $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
- $offset += 4;
- $table[$tag]['offset'] = $this->_getULONG($font, $offset);
- $offset += 4;
- $table[$tag]['length'] = $this->_getULONG($font, $offset);
- $offset += 4;
- }
-
- $offset = $table['head']['offset'] + 12;
- if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) {
-
- return $font;
- }
- $offset += 4;
- $offset += 2;
-
- $fmetric['unitsPerEm'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
-
- $urk = (1000 / $fmetric['unitsPerEm']);
- $offset += 16;
- $xMin = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
- $yMin = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
- $xMax = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
- $yMax = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
- $fmetric['bbox'] = ''.$xMin.' '.$yMin.' '.$xMax.' '.$yMax.'';
- $macStyle = $this->_getUSHORT($font, $offset);
- $offset += 2;
-
- $fmetric['Flags'] = $flags;
- if (($macStyle & 2) == 2) {
-
- $fmetric['Flags'] |= 64;
- }
-
- $offset = $table['head']['offset'] + 50;
- $short_offset = ($this->_getSHORT($font, $offset) == 0);
- $offset += 2;
-
- $indexToLoc = array();
- $offset = $table['loca']['offset'];
- if ($short_offset) {
-
- $tot_num_glyphs = ($table['loca']['length'] / 2);
- for ($i = 0; $i < $tot_num_glyphs; ++$i) {
- $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
- $offset += 2;
- }
- } else {
-
- $tot_num_glyphs = ($table['loca']['length'] / 4);
- for ($i = 0; $i < $tot_num_glyphs; ++$i) {
- $indexToLoc[$i] = $this->_getULONG($font, $offset);
- $offset += 4;
- }
- }
-
- $offset = $table['cmap']['offset'] + 2;
- $numEncodingTables = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $encodingTables = array();
- for ($i = 0; $i < $numEncodingTables; ++$i) {
- $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
- $offset += 4;
- }
-
- $offset = $table['OS/2']['offset'];
- $offset += 2;
-
- $fmetric['AvgWidth'] = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
-
- $usWeightClass = round($this->_getUFWORD($font, $offset) * $urk);
-
- $fmetric['StemV'] = round((70 * $usWeightClass) / 400);
- $fmetric['StemH'] = round((30 * $usWeightClass) / 400);
- $offset += 2;
- $offset += 2;
- $fsType = $this->_getSHORT($font, $offset);
- $offset += 2;
- if ($fsType == 2) {
- $this->Error('This Font cannot be modified, embedded or exchanged in any manner without first obtaining permission of the legal owner.');
- }
-
- $fmetric['name'] = '';
- $offset = $table['name']['offset'];
- $offset += 2;
-
- $numNameRecords = $this->_getUSHORT($font, $offset);
- $offset += 2;
-
- $stringStorageOffset = $this->_getUSHORT($font, $offset);
- $offset += 2;
- for ($i = 0; $i < $numNameRecords; ++$i) {
- $offset += 6;
-
- $nameID = $this->_getUSHORT($font, $offset);
- $offset += 2;
- if ($nameID == 6) {
-
- $stringLength = $this->_getUSHORT($font, $offset);
- $offset += 2;
-
- $stringOffset = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $offset = ($table['name']['offset'] + $stringStorageOffset + $stringOffset);
- $fmetric['name'] = substr($font, $offset, $stringLength);
- $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $fmetric['name']);
- break;
- } else {
- $offset += 4;
- }
- }
- if (empty($fmetric['name'])) {
- $fmetric['name'] = $font_name;
- }
-
- $offset = $table['post']['offset'];
- $offset += 4;
- $fmetric['italicAngle'] = $this->_getFIXED($font, $offset);
- $offset += 4;
- $fmetric['underlinePosition'] = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
- $fmetric['underlineThickness'] = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
- $isFixedPitch = ($this->_getULONG($font, $offset) == 0) ? false : true;
- $offset += 2;
- if ($isFixedPitch) {
- $fmetric['Flags'] |= 1;
- }
-
- $offset = $table['hhea']['offset'];
- $offset += 4;
-
- $fmetric['Ascent'] = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
-
- $fmetric['Descent'] = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
-
- $fmetric['Leading'] = round($this->_getFWORD($font, $offset) * $urk);
- $offset += 2;
-
- $fmetric['MaxWidth'] = round($this->_getUFWORD($font, $offset) * $urk);
- $offset += 2;
- $offset += 22;
-
- $numberOfHMetrics = $this->_getUSHORT($font, $offset);
-
- $offset = $table['maxp']['offset'];
- $offset += 4;
-
- $numGlyphs = $this->_getUSHORT($font, $offset);
-
- $ctg = array();
- foreach ($encodingTables as $enctable) {
- if (($enctable['platformID'] == 3) AND ($enctable['encodingID'] == 0)) {
- $modesymbol = true;
- } else {
- $modesymbol = false;
- }
- $offset = $table['cmap']['offset'] + $enctable['offset'];
- $format = $this->_getUSHORT($font, $offset);
- $offset += 2;
- switch ($format) {
- case 0: {
- $offset += 4;
- for ($c = 0; $c < 256; ++$c) {
- $g = $this->_getBYTE($font, $offset);
- $ctg[$c] = $g;
- ++$offset;
- }
- break;
- }
- case 2: {
- $offset += 4;
- $numSubHeaders = 0;
- for ($i = 0; $i < 256; ++$i) {
-
- $subHeaderKeys[$i] = ($this->_getUSHORT($font, $offset) / 8);
- $offset += 2;
- if ($numSubHeaders < $subHeaderKeys[$i]) {
- $numSubHeaders = $subHeaderKeys[$i];
- }
- }
-
- ++$numSubHeaders;
-
- $subHeaders = array();
- $numGlyphIndexArray = 0;
- for ($k = 0; $k < $numSubHeaders; ++$k) {
- $subHeaders[$k]['firstCode'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $subHeaders[$k]['entryCount'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $subHeaders[$k]['idDelta'] = $this->_getSHORT($font, $offset);
- $offset += 2;
- $subHeaders[$k]['idRangeOffset'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
- $subHeaders[$k]['idRangeOffset'] /= 2;
- $numGlyphIndexArray += $subHeaders[$k]['entryCount'];
- }
- for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
- $glyphIndexArray[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- for ($i = 0; $i < 256; ++$i) {
- $k = $subHeaderKeys[$i];
- if ($k == 0) {
-
- $c = $i;
- $g = $glyphIndexArray[0];
- $ctg[$c] = $g;
- } else {
-
- $start_byte = $subHeaders[$k]['firstCode'];
- $end_byte = $start_byte + $subHeaders[$k]['entryCount'];
- for ($j = $start_byte; $j < $end_byte; ++$j) {
-
- $c = (($i << 8) + $j);
- $idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
- $g = $glyphIndexArray[$idRangeOffset];
- $g += ($idDelta[$k] - 65536);
- if ($g < 0) {
- $g = 0;
- }
- $ctg[$c] = $g;
- }
- }
- }
- break;
- }
- case 4: {
- $length = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $offset += 2;
- $segCount = ($this->_getUSHORT($font, $offset) / 2);
- $offset += 2;
- $offset += 6;
- $endCount = array();
- for ($k = 0; $k < $segCount; ++$k) {
- $endCount[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- $offset += 2;
- $startCount = array();
- for ($k = 0; $k < $segCount; ++$k) {
- $startCount[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- $idDelta = array();
- for ($k = 0; $k < $segCount; ++$k) {
- $idDelta[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- $idRangeOffset = array();
- for ($k = 0; $k < $segCount; ++$k) {
- $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- $gidlen = ($length / 2) - 8 - (4 * $segCount);
- $glyphIdArray = array();
- for ($k = 0; $k < $gidlen; ++$k) {
- $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- for ($k = 0; $k < $segCount; ++$k) {
- for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
- if ($idRangeOffset[$k] == 0) {
- $g = $c;
- } else {
- $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
- $g = $glyphIdArray[$gid];
- }
- $g += ($idDelta[$k] - 65536);
- if ($g < 0) {
- $g = 0;
- }
- $ctg[$c] = $g;
- }
- }
- break;
- }
- case 6: {
- $offset += 4;
- $firstCode = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $entryCount = $this->_getUSHORT($font, $offset);
- $offset += 2;
- for ($k = 0; $k < $entryCount; ++$k) {
- $c = ($k + $firstCode);
- $g = $this->_getUSHORT($font, $offset);
- $ctg[$c] = $g;
- $offset += 2;
- }
- break;
- }
- case 8: {
- $offset += 10;
- for ($k = 0; $k < 8192; ++$k) {
- $is32[$k] = $this->_getBYTE($font, $offset);
- ++$offset;
- }
- $nGroups = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($i = 0; $i < $nGroups; ++$i) {
- $startCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $endCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $startGlyphID = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
- $is32idx = floor($c / 8);
- if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
- $c = $k;
- } else {
-
-
-
-
- $c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
- }
- $ctg[$c] = $g;
- ++$startGlyphID;
- }
- }
- break;
- }
- case 10: {
- $offset += 10;
- $startCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $numChars = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($k = 0; $k < $numChars; ++$k) {
- $c = ($k + $startCharCode);
- $g = $this->_getUSHORT($font, $offset);
- $ctg[$c] = $g;
- $offset += 2;
- }
- break;
- }
- case 12: {
- $offset += 10;
- $nGroups = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($k = 0; $k < $nGroups; ++$k) {
- $startCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $endCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $startGlyphCode = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
- $ctg[$c] = $startGlyphCode;
- ++$startGlyphCode;
- }
- }
- break;
- }
- case 13: {
-
- break;
- }
- case 14: {
-
- break;
- }
- }
- }
- if (!isset($ctg[0])) {
- $ctg[0] = 0;
- }
-
- $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[120]] + 4);
- $yMin = $this->_getFWORD($font, $offset);
- $offset += 4;
- $yMax = $this->_getFWORD($font, $offset);
- $offset += 2;
- $fmetric['XHeight'] = round(($yMax - $yMin) * $urk);
-
- $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[72]] + 4);
- $yMin = $this->_getFWORD($font, $offset);
- $offset += 4;
- $yMax = $this->_getFWORD($font, $offset);
- $offset += 2;
- $fmetric['CapHeight'] = round(($yMax - $yMin) * $urk);
-
- $cw = array();
- $offset = $table['hmtx']['offset'];
- for ($i = 0 ; $i < $numberOfHMetrics; ++$i) {
- $cw[$i] = round($this->_getUFWORD($font, $offset) * $urk);
- $offset += 4;
- }
- if ($numberOfHMetrics < $numGlyphs) {
-
- $cw = array_pad($cw, $numGlyphs, $cw[($numberOfHMetrics - 1)]);
- }
- $fmetric['MissingWidth'] = $cw[0];
- $fmetric['cw'] = '';
- for ($cid = 0; $cid <= 65535; ++$cid) {
- if (isset($ctg[$cid]) AND isset($cw[$ctg[$cid]])) {
- $fmetric['cw'] .= ','.$cid.'=>'.$cw[$ctg[$cid]];
- }
- }
- }
- if (($fmetric['type'] == 'TrueTypeUnicode') AND (count($ctg) == 256)) {
- $fmetric['type'] == 'TrueType';
- }
-
- $pfile = '<'.'?'.'php'."\n";
- $pfile .= '// TCPDF FONT FILE DESCRIPTION'."\n";
- $pfile .= '$type=\''.$fmetric['type'].'\';'."\n";
- $pfile .= '$name=\''.$fmetric['name'].'\';'."\n";
- $pfile .= '$up='.$fmetric['underlinePosition'].';'."\n";
- $pfile .= '$ut='.$fmetric['underlineThickness'].';'."\n";
- if ($fmetric['MissingWidth'] > 0) {
- $pfile .= '$dw='.$fmetric['MissingWidth'].';'."\n";
- } else {
- $pfile .= '$dw='.$fmetric['AvgWidth'].';'."\n";
- }
- $pfile .= '$diff=\''.$fmetric['diff'].'\';'."\n";
- if ($fmetric['type'] == 'Type1') {
-
- $pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n";
- $pfile .= '$file=\''.$fmetric['file'].'\';'."\n";
- $pfile .= '$size1='.$fmetric['size1'].';'."\n";
- $pfile .= '$size2='.$fmetric['size2'].';'."\n";
- } else {
- $pfile .= '$originalsize='.$fmetric['originalsize'].';'."\n";
- if ($fmetric['type'] == 'cidfont0') {
-
- switch ($fonttype) {
- case 'CID0JP': {
- $pfile .= '// Japanese'."\n";
- $pfile .= '$enc=\'UniJIS-UTF16-H\';'."\n";
- $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Japan1\',\'Supplement\'=>5);'."\n";
- $pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n";
- break;
- }
- case 'CID0KR': {
- $pfile .= '// Korean'."\n";
- $pfile .= '$enc=\'UniKS-UTF16-H\';'."\n";
- $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Korea1\',\'Supplement\'=>0);'."\n";
- $pfile .= 'include(dirname(__FILE__).\'/uni2cid_ak12.php\');'."\n";
- break;
- }
- case 'CID0CS': {
- $pfile .= '// Chinese Simplified'."\n";
- $pfile .= '$enc=\'UniGB-UTF16-H\';'."\n";
- $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'GB1\',\'Supplement\'=>2);'."\n";
- $pfile .= 'include(dirname(__FILE__).\'/uni2cid_ag15.php\');'."\n";
- break;
- }
- case 'CID0CT':
- default: {
- $pfile .= '// Chinese Traditional'."\n";
- $pfile .= '$enc=\'UniCNS-UTF16-H\';'."\n";
- $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'CNS1\',\'Supplement\'=>0);'."\n";
- $pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n";
- break;
- }
- }
- } else {
-
- $pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n";
- $pfile .= '$file=\''.$fmetric['file'].'\';'."\n";
- $pfile .= '$ctg=\''.$fmetric['ctg'].'\';'."\n";
-
- $cidtogidmap = str_pad('', 131072, "\x00");
- foreach ($ctg as $cid => $gid) {
- $cidtogidmap = $this->updateCIDtoGIDmap($cidtogidmap, $cid, $ctg[$cid]);
- }
-
- $fp = fopen($outpath.$fmetric['ctg'], 'wb');
- fwrite($fp, gzcompress($cidtogidmap));
- fclose($fp);
- }
- }
- $pfile .= '$desc=array(';
- $pfile .= '\'Flags\'=>'.$fmetric['Flags'].',';
- $pfile .= '\'FontBBox\'=>\'['.$fmetric['bbox'].']\',';
- $pfile .= '\'ItalicAngle\'=>'.$fmetric['italicAngle'].',';
- $pfile .= '\'Ascent\'=>'.$fmetric['Ascent'].',';
- $pfile .= '\'Descent\'=>'.$fmetric['Descent'].',';
- $pfile .= '\'Leading\'=>'.$fmetric['Leading'].',';
- $pfile .= '\'CapHeight\'=>'.$fmetric['CapHeight'].',';
- $pfile .= '\'XHeight\'=>'.$fmetric['XHeight'].',';
- $pfile .= '\'StemV\'=>'.$fmetric['StemV'].',';
- $pfile .= '\'StemH\'=>'.$fmetric['StemH'].',';
- $pfile .= '\'AvgWidth\'=>'.$fmetric['AvgWidth'].',';
- $pfile .= '\'MaxWidth\'=>'.$fmetric['MaxWidth'].',';
- $pfile .= '\'MissingWidth\'=>'.$fmetric['MissingWidth'].'';
- $pfile .= ');'."\n";
- $pfile .= '$cw=array('.substr($fmetric['cw'], 1).');'."\n";
- $pfile .= '// --- EOF ---'."\n";
-
- $fp = fopen($outpath.$font_name.'.php', 'w');
- fwrite($fp, $pfile);
- fclose($fp);
-
- return $font_name;
- }
-
- protected function _getTrueTypeFontSubset($font, $subsetchars) {
- ksort($subsetchars);
- $offset = 0;
- if ($this->_getULONG($font, $offset) != 0x10000) {
-
- return $font;
- }
- $offset += 4;
-
- $numTables = $this->_getUSHORT($font, $offset);
- $offset += 2;
-
- $offset += 6;
-
- $table = array();
-
- for ($i = 0; $i < $numTables; ++$i) {
-
- $tag = substr($font, $offset, 4);
- $offset += 4;
- $table[$tag] = array();
- $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
- $offset += 4;
- $table[$tag]['offset'] = $this->_getULONG($font, $offset);
- $offset += 4;
- $table[$tag]['length'] = $this->_getULONG($font, $offset);
- $offset += 4;
- }
-
- $offset = $table['head']['offset'] + 12;
- if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) {
-
- return $font;
- }
- $offset += 4;
-
- $offset = $table['head']['offset'] + 50;
- $short_offset = ($this->_getSHORT($font, $offset) == 0);
- $offset += 2;
-
- $indexToLoc = array();
- $offset = $table['loca']['offset'];
- if ($short_offset) {
-
- $tot_num_glyphs = ($table['loca']['length'] / 2);
- for ($i = 0; $i < $tot_num_glyphs; ++$i) {
- $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
- $offset += 2;
- }
- } else {
-
- $tot_num_glyphs = ($table['loca']['length'] / 4);
- for ($i = 0; $i < $tot_num_glyphs; ++$i) {
- $indexToLoc[$i] = $this->_getULONG($font, $offset);
- $offset += 4;
- }
- }
-
- $subsetglyphs = array();
- $subsetglyphs[0] = true;
- $offset = $table['cmap']['offset'] + 2;
- $numEncodingTables = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $encodingTables = array();
- for ($i = 0; $i < $numEncodingTables; ++$i) {
- $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
- $offset += 4;
- }
- foreach ($encodingTables as $enctable) {
- if (($enctable['platformID'] == 3) AND ($enctable['encodingID'] == 0)) {
- $modesymbol = true;
- } else {
- $modesymbol = false;
- }
- $offset = $table['cmap']['offset'] + $enctable['offset'];
- $format = $this->_getUSHORT($font, $offset);
- $offset += 2;
- switch ($format) {
- case 0: {
- $offset += 4;
- for ($c = 0; $c < 256; ++$c) {
- if (isset($subsetchars[$c])) {
- $g = $this->_getBYTE($font, $offset);
- $subsetglyphs[$g] = true;
- }
- ++$offset;
- }
- break;
- }
- case 2: {
- $offset += 4;
- $numSubHeaders = 0;
- for ($i = 0; $i < 256; ++$i) {
-
- $subHeaderKeys[$i] = ($this->_getUSHORT($font, $offset) / 8);
- $offset += 2;
- if ($numSubHeaders < $subHeaderKeys[$i]) {
- $numSubHeaders = $subHeaderKeys[$i];
- }
- }
-
- ++$numSubHeaders;
-
- $subHeaders = array();
- $numGlyphIndexArray = 0;
- for ($k = 0; $k < $numSubHeaders; ++$k) {
- $subHeaders[$k]['firstCode'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $subHeaders[$k]['entryCount'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $subHeaders[$k]['idDelta'] = $this->_getSHORT($font, $offset);
- $offset += 2;
- $subHeaders[$k]['idRangeOffset'] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
- $subHeaders[$k]['idRangeOffset'] /= 2;
- $numGlyphIndexArray += $subHeaders[$k]['entryCount'];
- }
- for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
- $glyphIndexArray[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- for ($i = 0; $i < 256; ++$i) {
- $k = $subHeaderKeys[$i];
- if ($k == 0) {
-
- $c = $i;
- if (isset($subsetchars[$c])) {
- $g = $glyphIndexArray[0];
- $subsetglyphs[$g] = true;
- }
- } else {
-
- $start_byte = $subHeaders[$k]['firstCode'];
- $end_byte = $start_byte + $subHeaders[$k]['entryCount'];
- for ($j = $start_byte; $j < $end_byte; ++$j) {
-
- $c = (($i << 8) + $j);
- if (isset($subsetchars[$c])) {
- $idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
- $g = $glyphIndexArray[$idRangeOffset];
- $g += ($idDelta[$k] - 65536);
- if ($g < 0) {
- $g = 0;
- }
- $subsetglyphs[$g] = true;
- }
- }
- }
- }
- break;
- }
- case 4: {
- $length = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $offset += 2;
- $segCount = ($this->_getUSHORT($font, $offset) / 2);
- $offset += 2;
- $offset += 6;
- $endCount = array();
- for ($k = 0; $k < $segCount; ++$k) {
- $endCount[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- $offset += 2;
- $startCount = array();
- for ($k = 0; $k < $segCount; ++$k) {
- $startCount[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- $idDelta = array();
- for ($k = 0; $k < $segCount; ++$k) {
- $idDelta[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- $idRangeOffset = array();
- for ($k = 0; $k < $segCount; ++$k) {
- $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- $gidlen = ($length / 2) - 8 - (4 * $segCount);
- $glyphIdArray = array();
- for ($k = 0; $k < $gidlen; ++$k) {
- $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
- $offset += 2;
- }
- for ($k = 0; $k < $segCount; ++$k) {
- for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
- if (isset($subsetchars[$c])) {
- if ($idRangeOffset[$k] == 0) {
- $g = $c;
- } else {
- $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
- $g = $glyphIdArray[$gid];
- }
- $g += ($idDelta[$k] - 65536);
- if ($g < 0) {
- $g = 0;
- }
- $subsetglyphs[$g] = true;
- }
- }
- }
- break;
- }
- case 6: {
- $offset += 4;
- $firstCode = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $entryCount = $this->_getUSHORT($font, $offset);
- $offset += 2;
- for ($k = 0; $k < $entryCount; ++$k) {
- $c = ($k + $firstCode);
- if (isset($subsetchars[$c])) {
- $g = $this->_getUSHORT($font, $offset);
- $subsetglyphs[$g] = true;
- }
- $offset += 2;
- }
- break;
- }
- case 8: {
- $offset += 10;
- for ($k = 0; $k < 8192; ++$k) {
- $is32[$k] = $this->_getBYTE($font, $offset);
- ++$offset;
- }
- $nGroups = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($i = 0; $i < $nGroups; ++$i) {
- $startCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $endCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $startGlyphID = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
- $is32idx = floor($c / 8);
- if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
- $c = $k;
- } else {
-
-
-
-
- $c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
- }
- if (isset($subsetchars[$c])) {
- $subsetglyphs[$startGlyphID] = true;
- }
- ++$startGlyphID;
- }
- }
- break;
- }
- case 10: {
- $offset += 10;
- $startCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $numChars = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($k = 0; $k < $numChars; ++$k) {
- $c = ($k + $startCharCode);
- if (isset($subsetchars[$c])) {
- $g = $this->_getUSHORT($font, $offset);
- $subsetglyphs[$g] = true;
- }
- $offset += 2;
- }
- break;
- }
- case 12: {
- $offset += 10;
- $nGroups = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($k = 0; $k < $nGroups; ++$k) {
- $startCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $endCharCode = $this->_getULONG($font, $offset);
- $offset += 4;
- $startGlyphCode = $this->_getULONG($font, $offset);
- $offset += 4;
- for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
- if (isset($subsetchars[$c])) {
- $subsetglyphs[$startGlyphCode] = true;
- }
- ++$startGlyphCode;
- }
- }
- break;
- }
- case 13: {
-
- break;
- }
- case 14: {
-
- break;
- }
- }
- }
-
- $new_sga = $subsetglyphs;
- while (!empty($new_sga)) {
- $sga = $new_sga;
- $new_sga = array();
- foreach ($sga as $key => $val) {
- if (isset($indexToLoc[$key])) {
- $offset = ($table['glyf']['offset'] + $indexToLoc[$key]);
- $numberOfContours = $this->_getSHORT($font, $offset);
- $offset += 2;
- if ($numberOfContours < 0) {
- $offset += 8;
- do {
- $flags = $this->_getUSHORT($font, $offset);
- $offset += 2;
- $glyphIndex = $this->_getUSHORT($font, $offset);
- $offset += 2;
- if (!isset($subsetglyphs[$glyphIndex])) {
-
- $new_sga[$glyphIndex] = true;
- }
-
- if ($flags & 1) {
- $offset += 4;
- } else {
- $offset += 2;
- }
- if ($flags & 8) {
- $offset += 2;
- } elseif ($flags & 64) {
- $offset += 4;
- } elseif ($flags & 128) {
- $offset += 8;
- }
- } while ($flags & 32);
- }
- }
- }
- $subsetglyphs += $new_sga;
- }
-
- ksort($subsetglyphs);
-
- $glyf = '';
- $loca = '';
- $offset = 0;
- $glyf_offset = $table['glyf']['offset'];
- for ($i = 0; $i < $tot_num_glyphs; ++$i) {
- if (isset($subsetglyphs[$i])) {
- $length = ($indexToLoc[($i + 1)] - $indexToLoc[$i]);
- $glyf .= substr($font, ($glyf_offset + $indexToLoc[$i]), $length);
- } else {
- $length = 0;
- }
- if ($short_offset) {
- $loca .= pack('n', ($offset / 2));
- } else {
- $loca .= pack('N', $offset);
- }
- $offset += $length;
- }
-
-
- $table_names = array ('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep');
-
- $offset = 12;
- foreach ($table as $tag => $val) {
- if (in_array($tag, $table_names)) {
- $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
- if ($tag == 'head') {
-
- $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
- }
- $pad = 4 - ($table[$tag]['length'] % 4);
- if ($pad != 4) {
-
- $table[$tag]['length'] += $pad;
- $table[$tag]['data'] .= str_repeat("\x0", $pad);
- }
- $table[$tag]['offset'] = $offset;
- $offset += $table[$tag]['length'];
-
-
- } else {
- unset($table[$tag]);
- }
- }
-
- $table['loca']['data'] = $loca;
- $table['loca']['length'] = strlen($loca);
- $pad = 4 - ($table['loca']['length'] % 4);
- if ($pad != 4) {
-
- $table['loca']['length'] += $pad;
- $table['loca']['data'] .= str_repeat("\x0", $pad);
- }
- $table['loca']['offset'] = $offset;
- $table['loca']['checkSum'] = $this->_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
- $offset += $table['loca']['length'];
-
- $table['glyf']['data'] = $glyf;
- $table['glyf']['length'] = strlen($glyf);
- $pad = 4 - ($table['glyf']['length'] % 4);
- if ($pad != 4) {
-
- $table['glyf']['length'] += $pad;
- $table['glyf']['data'] .= str_repeat("\x0", $pad);
- }
- $table['glyf']['offset'] = $offset;
- $table['glyf']['checkSum'] = $this->_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
-
- $font = '';
- $font .= pack('N', 0x10000);
- $numTables = count($table);
- $font .= pack('n', $numTables);
- $entrySelector = floor(log($numTables, 2));
- $searchRange = pow(2, $entrySelector) * 16;
- $rangeShift = ($numTables * 16) - $searchRange;
- $font .= pack('n', $searchRange);
- $font .= pack('n', $entrySelector);
- $font .= pack('n', $rangeShift);
- $offset = ($numTables * 16);
- foreach ($table as $tag => $data) {
- $font .= $tag;
- $font .= pack('N', $data['checkSum']);
- $font .= pack('N', ($data['offset'] + $offset));
- $font .= pack('N', $data['length']);
- }
- foreach ($table as $data) {
- $font .= $data['data'];
- }
-
- $checkSumAdjustment = 0xB1B0AFBA - $this->_getTTFtableChecksum($font, strlen($font));
- $font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12);
- return $font;
- }
-
- protected function _getTTFtableChecksum($table, $length) {
- $sum = 0;
- $tlen = ($length / 4);
- $offset = 0;
- for ($i = 0; $i < $tlen; ++$i) {
- $v = unpack('Ni', substr($table, $offset, 4));
- $sum += $v['i'];
- $offset += 4;
- }
- $sum = unpack('Ni', pack('N', $sum));
- return $sum['i'];
- }
-
- protected function _putfontwidths($font, $cidoffset=0) {
- ksort($font['cw']);
- $rangeid = 0;
- $range = array();
- $prevcid = -2;
- $prevwidth = -1;
- $interval = false;
-
- foreach ($font['cw'] as $cid => $width) {
- $cid -= $cidoffset;
- if ($font['subset'] AND ($cid > 255) AND (!isset($font['subsetchars'][$cid]))) {
-
- continue;
- }
- if ($width != $font['dw']) {
- if ($cid == ($prevcid + 1)) {
-
- if ($width == $prevwidth) {
- if ($width == $range[$rangeid][0]) {
- $range[$rangeid][] = $width;
- } else {
- array_pop($range[$rangeid]);
-
- $rangeid = $prevcid;
- $range[$rangeid] = array();
- $range[$rangeid][] = $prevwidth;
- $range[$rangeid][] = $width;
- }
- $interval = true;
- $range[$rangeid]['interval'] = true;
- } else {
- if ($interval) {
-
- $rangeid = $cid;
- $range[$rangeid] = array();
- $range[$rangeid][] = $width;
- } else {
- $range[$rangeid][] = $width;
- }
- $interval = false;
- }
- } else {
-
- $rangeid = $cid;
- $range[$rangeid] = array();
- $range[$rangeid][] = $width;
- $interval = false;
- }
- $prevcid = $cid;
- $prevwidth = $width;
- }
- }
-
- $prevk = -1;
- $nextk = -1;
- $prevint = false;
- foreach ($range as $k => $ws) {
- $cws = count($ws);
- if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
- if (isset($range[$k]['interval'])) {
- unset($range[$k]['interval']);
- }
- $range[$prevk] = array_merge($range[$prevk], $range[$k]);
- unset($range[$k]);
- } else {
- $prevk = $k;
- }
- $nextk = $k + $cws;
- if (isset($ws['interval'])) {
- if ($cws > 3) {
- $prevint = true;
- } else {
- $prevint = false;
- }
- unset($range[$k]['interval']);
- --$nextk;
- } else {
- $prevint = false;
- }
- }
-
- $w = '';
- foreach ($range as $k => $ws) {
- if (count(array_count_values($ws)) == 1) {
-
- $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
- } else {
-
- $w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
- }
- }
- return '/W ['.$w.' ]';
- }
-
- protected function _putfonts() {
- $nf = $this->n;
- foreach ($this->diffs as $diff) {
-
- $this->_newobj();
- $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
- }
- $mqr = $this->get_mqr();
- $this->set_mqr(false);
- foreach ($this->FontFiles as $file => $info) {
-
- $fontdir = $info['fontdir'];
- $file = strtolower($file);
- $fontfile = '';
-
- if (($fontdir !== false) AND file_exists($fontdir.$file)) {
- $fontfile = $fontdir.$file;
- } elseif (file_exists($this->_getfontpath().$file)) {
- $fontfile = $this->_getfontpath().$file;
- } elseif (file_exists($file)) {
- $fontfile = $file;
- }
- if (!$this->empty_string($fontfile)) {
- $font = file_get_contents($fontfile);
- $compressed = (substr($file, -2) == '.z');
- if ((!$compressed) AND (isset($info['length2']))) {
- $header = (ord($font{0}) == 128);
- if ($header) {
-
- $font = substr($font, 6);
- }
- if ($header AND (ord($font[$info['length1']]) == 128)) {
-
- $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
- }
- } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
- if ($compressed) {
-
- $font = gzuncompress($font);
- }
-
- $subsetchars = array();
- foreach ($info['fontkeys'] as $fontkey) {
- $fontinfo = $this->getFontBuffer($fontkey);
- $subsetchars += $fontinfo['subsetchars'];
- }
-
- $font = $this->_getTrueTypeFontSubset($font, $subsetchars);
-
- $info['length1'] = strlen($font);
- if ($compressed) {
-
- $font = gzcompress($font);
- }
- }
- $this->_newobj();
- $this->FontFiles[$file]['n'] = $this->n;
- $stream = $this->_getrawstream($font);
- $out = '<< /Length '.strlen($stream);
- if ($compressed) {
- $out .= ' /Filter /FlateDecode';
- }
- $out .= ' /Length1 '.$info['length1'];
- if (isset($info['length2'])) {
- $out .= ' /Length2 '.$info['length2'].' /Length3 0';
- }
- $out .= ' >>';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
- $this->set_mqr($mqr);
- foreach ($this->fontkeys as $k) {
-
- $font = $this->getFontBuffer($k);
- $type = $font['type'];
- $name = $font['name'];
- if ($type == 'core') {
-
- $out = $this->_getobj($this->font_obj_ids[$k])."\n";
- $out .= '<</Type /Font';
- $out .= ' /Subtype /Type1';
- $out .= ' /BaseFont /'.$name;
- $out .= ' /Name /F'.$font['i'];
- if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
- $out .= ' /Encoding /WinAnsiEncoding';
- }
- if ($k == 'helvetica') {
-
- $this->annotation_fonts[$k] = $font['i'];
- }
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
-
- $out = $this->_getobj($this->font_obj_ids[$k])."\n";
- $out .= '<</Type /Font';
- $out .= ' /Subtype /'.$type;
- $out .= ' /BaseFont /'.$name;
- $out .= ' /Name /F'.$font['i'];
- $out .= ' /FirstChar 32 /LastChar 255';
- $out .= ' /Widths '.($this->n + 1).' 0 R';
- $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
- if ($font['enc']) {
- if (isset($font['diff'])) {
- $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
- } else {
- $out .= ' /Encoding /WinAnsiEncoding';
- }
- }
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
-
- $this->_newobj();
- $s = '[';
- for ($i = 32; $i < 256; ++$i) {
- $s .= $font['cw'][$i].' ';
- }
- $s .= ']';
- $s .= "\n".'endobj';
- $this->_out($s);
-
- $this->_newobj();
- $s = '<</Type /FontDescriptor /FontName /'.$name;
- foreach ($font['desc'] as $fdk => $fdv) {
- if (is_float($fdv)) {
- $fdv = sprintf('%.3F', $fdv);
- }
- $s .= ' /'.$fdk.' '.$fdv.'';
- }
- if (!$this->empty_string($font['file'])) {
- $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
- }
- $s .= '>>';
- $s .= "\n".'endobj';
- $this->_out($s);
- } else {
-
- $mtd = '_put'.strtolower($type);
- if (!method_exists($this, $mtd)) {
- $this->Error('Unsupported font type: '.$type);
- }
- $this->$mtd($font);
- }
- }
- }
-
- protected function _puttruetypeunicode($font) {
- $fontname = '';
- if ($font['subset']) {
-
- $subtag = sprintf('%06u', $font['i']);
- $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
- $fontname .= $subtag.'+';
- }
- $fontname .= $font['name'];
-
-
- $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
- $out .= '<< /Type /Font';
- $out .= ' /Subtype /Type0';
- $out .= ' /BaseFont /'.$fontname;
- $out .= ' /Name /F'.$font['i'];
- $out .= ' /Encoding /'.$font['enc'];
- $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
- $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
-
- $stream = "/CIDInit /ProcSet findresource begin\n";
- $stream .= "12 dict begin\n";
- $stream .= "begincmap\n";
- $stream .= "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n";
- $stream .= "/CMapName /Adobe-Identity-UCS def\n";
- $stream .= "/CMapType 2 def\n";
- $stream .= "/WMode 0 def\n";
- $stream .= "1 begincodespacerange\n";
- $stream .= "<0000> <FFFF>\n";
- $stream .= "endcodespacerange\n";
- $stream .= "100 beginbfrange\n";
- $stream .= "<0000> <00ff> <0000>\n";
- $stream .= "<0100> <01ff> <0100>\n";
- $stream .= "<0200> <02ff> <0200>\n";
- $stream .= "<0300> <03ff> <0300>\n";
- $stream .= "<0400> <04ff> <0400>\n";
- $stream .= "<0500> <05ff> <0500>\n";
- $stream .= "<0600> <06ff> <0600>\n";
- $stream .= "<0700> <07ff> <0700>\n";
- $stream .= "<0800> <08ff> <0800>\n";
- $stream .= "<0900> <09ff> <0900>\n";
- $stream .= "<0a00> <0aff> <0a00>\n";
- $stream .= "<0b00> <0bff> <0b00>\n";
- $stream .= "<0c00> <0cff> <0c00>\n";
- $stream .= "<0d00> <0dff> <0d00>\n";
- $stream .= "<0e00> <0eff> <0e00>\n";
- $stream .= "<0f00> <0fff> <0f00>\n";
- $stream .= "<1000> <10ff> <1000>\n";
- $stream .= "<1100> <11ff> <1100>\n";
- $stream .= "<1200> <12ff> <1200>\n";
- $stream .= "<1300> <13ff> <1300>\n";
- $stream .= "<1400> <14ff> <1400>\n";
- $stream .= "<1500> <15ff> <1500>\n";
- $stream .= "<1600> <16ff> <1600>\n";
- $stream .= "<1700> <17ff> <1700>\n";
- $stream .= "<1800> <18ff> <1800>\n";
- $stream .= "<1900> <19ff> <1900>\n";
- $stream .= "<1a00> <1aff> <1a00>\n";
- $stream .= "<1b00> <1bff> <1b00>\n";
- $stream .= "<1c00> <1cff> <1c00>\n";
- $stream .= "<1d00> <1dff> <1d00>\n";
- $stream .= "<1e00> <1eff> <1e00>\n";
- $stream .= "<1f00> <1fff> <1f00>\n";
- $stream .= "<2000> <20ff> <2000>\n";
- $stream .= "<2100> <21ff> <2100>\n";
- $stream .= "<2200> <22ff> <2200>\n";
- $stream .= "<2300> <23ff> <2300>\n";
- $stream .= "<2400> <24ff> <2400>\n";
- $stream .= "<2500> <25ff> <2500>\n";
- $stream .= "<2600> <26ff> <2600>\n";
- $stream .= "<2700> <27ff> <2700>\n";
- $stream .= "<2800> <28ff> <2800>\n";
- $stream .= "<2900> <29ff> <2900>\n";
- $stream .= "<2a00> <2aff> <2a00>\n";
- $stream .= "<2b00> <2bff> <2b00>\n";
- $stream .= "<2c00> <2cff> <2c00>\n";
- $stream .= "<2d00> <2dff> <2d00>\n";
- $stream .= "<2e00> <2eff> <2e00>\n";
- $stream .= "<2f00> <2fff> <2f00>\n";
- $stream .= "<3000> <30ff> <3000>\n";
- $stream .= "<3100> <31ff> <3100>\n";
- $stream .= "<3200> <32ff> <3200>\n";
- $stream .= "<3300> <33ff> <3300>\n";
- $stream .= "<3400> <34ff> <3400>\n";
- $stream .= "<3500> <35ff> <3500>\n";
- $stream .= "<3600> <36ff> <3600>\n";
- $stream .= "<3700> <37ff> <3700>\n";
- $stream .= "<3800> <38ff> <3800>\n";
- $stream .= "<3900> <39ff> <3900>\n";
- $stream .= "<3a00> <3aff> <3a00>\n";
- $stream .= "<3b00> <3bff> <3b00>\n";
- $stream .= "<3c00> <3cff> <3c00>\n";
- $stream .= "<3d00> <3dff> <3d00>\n";
- $stream .= "<3e00> <3eff> <3e00>\n";
- $stream .= "<3f00> <3fff> <3f00>\n";
- $stream .= "<4000> <40ff> <4000>\n";
- $stream .= "<4100> <41ff> <4100>\n";
- $stream .= "<4200> <42ff> <4200>\n";
- $stream .= "<4300> <43ff> <4300>\n";
- $stream .= "<4400> <44ff> <4400>\n";
- $stream .= "<4500> <45ff> <4500>\n";
- $stream .= "<4600> <46ff> <4600>\n";
- $stream .= "<4700> <47ff> <4700>\n";
- $stream .= "<4800> <48ff> <4800>\n";
- $stream .= "<4900> <49ff> <4900>\n";
- $stream .= "<4a00> <4aff> <4a00>\n";
- $stream .= "<4b00> <4bff> <4b00>\n";
- $stream .= "<4c00> <4cff> <4c00>\n";
- $stream .= "<4d00> <4dff> <4d00>\n";
- $stream .= "<4e00> <4eff> <4e00>\n";
- $stream .= "<4f00> <4fff> <4f00>\n";
- $stream .= "<5000> <50ff> <5000>\n";
- $stream .= "<5100> <51ff> <5100>\n";
- $stream .= "<5200> <52ff> <5200>\n";
- $stream .= "<5300> <53ff> <5300>\n";
- $stream .= "<5400> <54ff> <5400>\n";
- $stream .= "<5500> <55ff> <5500>\n";
- $stream .= "<5600> <56ff> <5600>\n";
- $stream .= "<5700> <57ff> <5700>\n";
- $stream .= "<5800> <58ff> <5800>\n";
- $stream .= "<5900> <59ff> <5900>\n";
- $stream .= "<5a00> <5aff> <5a00>\n";
- $stream .= "<5b00> <5bff> <5b00>\n";
- $stream .= "<5c00> <5cff> <5c00>\n";
- $stream .= "<5d00> <5dff> <5d00>\n";
- $stream .= "<5e00> <5eff> <5e00>\n";
- $stream .= "<5f00> <5fff> <5f00>\n";
- $stream .= "<6000> <60ff> <6000>\n";
- $stream .= "<6100> <61ff> <6100>\n";
- $stream .= "<6200> <62ff> <6200>\n";
- $stream .= "<6300> <63ff> <6300>\n";
- $stream .= "endbfrange\n";
- $stream .= "100 beginbfrange\n";
- $stream .= "<6400> <64ff> <6400>\n";
- $stream .= "<6500> <65ff> <6500>\n";
- $stream .= "<6600> <66ff> <6600>\n";
- $stream .= "<6700> <67ff> <6700>\n";
- $stream .= "<6800> <68ff> <6800>\n";
- $stream .= "<6900> <69ff> <6900>\n";
- $stream .= "<6a00> <6aff> <6a00>\n";
- $stream .= "<6b00> <6bff> <6b00>\n";
- $stream .= "<6c00> <6cff> <6c00>\n";
- $stream .= "<6d00> <6dff> <6d00>\n";
- $stream .= "<6e00> <6eff> <6e00>\n";
- $stream .= "<6f00> <6fff> <6f00>\n";
- $stream .= "<7000> <70ff> <7000>\n";
- $stream .= "<7100> <71ff> <7100>\n";
- $stream .= "<7200> <72ff> <7200>\n";
- $stream .= "<7300> <73ff> <7300>\n";
- $stream .= "<7400> <74ff> <7400>\n";
- $stream .= "<7500> <75ff> <7500>\n";
- $stream .= "<7600> <76ff> <7600>\n";
- $stream .= "<7700> <77ff> <7700>\n";
- $stream .= "<7800> <78ff> <7800>\n";
- $stream .= "<7900> <79ff> <7900>\n";
- $stream .= "<7a00> <7aff> <7a00>\n";
- $stream .= "<7b00> <7bff> <7b00>\n";
- $stream .= "<7c00> <7cff> <7c00>\n";
- $stream .= "<7d00> <7dff> <7d00>\n";
- $stream .= "<7e00> <7eff> <7e00>\n";
- $stream .= "<7f00> <7fff> <7f00>\n";
- $stream .= "<8000> <80ff> <8000>\n";
- $stream .= "<8100> <81ff> <8100>\n";
- $stream .= "<8200> <82ff> <8200>\n";
- $stream .= "<8300> <83ff> <8300>\n";
- $stream .= "<8400> <84ff> <8400>\n";
- $stream .= "<8500> <85ff> <8500>\n";
- $stream .= "<8600> <86ff> <8600>\n";
- $stream .= "<8700> <87ff> <8700>\n";
- $stream .= "<8800> <88ff> <8800>\n";
- $stream .= "<8900> <89ff> <8900>\n";
- $stream .= "<8a00> <8aff> <8a00>\n";
- $stream .= "<8b00> <8bff> <8b00>\n";
- $stream .= "<8c00> <8cff> <8c00>\n";
- $stream .= "<8d00> <8dff> <8d00>\n";
- $stream .= "<8e00> <8eff> <8e00>\n";
- $stream .= "<8f00> <8fff> <8f00>\n";
- $stream .= "<9000> <90ff> <9000>\n";
- $stream .= "<9100> <91ff> <9100>\n";
- $stream .= "<9200> <92ff> <9200>\n";
- $stream .= "<9300> <93ff> <9300>\n";
- $stream .= "<9400> <94ff> <9400>\n";
- $stream .= "<9500> <95ff> <9500>\n";
- $stream .= "<9600> <96ff> <9600>\n";
- $stream .= "<9700> <97ff> <9700>\n";
- $stream .= "<9800> <98ff> <9800>\n";
- $stream .= "<9900> <99ff> <9900>\n";
- $stream .= "<9a00> <9aff> <9a00>\n";
- $stream .= "<9b00> <9bff> <9b00>\n";
- $stream .= "<9c00> <9cff> <9c00>\n";
- $stream .= "<9d00> <9dff> <9d00>\n";
- $stream .= "<9e00> <9eff> <9e00>\n";
- $stream .= "<9f00> <9fff> <9f00>\n";
- $stream .= "<a000> <a0ff> <a000>\n";
- $stream .= "<a100> <a1ff> <a100>\n";
- $stream .= "<a200> <a2ff> <a200>\n";
- $stream .= "<a300> <a3ff> <a300>\n";
- $stream .= "<a400> <a4ff> <a400>\n";
- $stream .= "<a500> <a5ff> <a500>\n";
- $stream .= "<a600> <a6ff> <a600>\n";
- $stream .= "<a700> <a7ff> <a700>\n";
- $stream .= "<a800> <a8ff> <a800>\n";
- $stream .= "<a900> <a9ff> <a900>\n";
- $stream .= "<aa00> <aaff> <aa00>\n";
- $stream .= "<ab00> <abff> <ab00>\n";
- $stream .= "<ac00> <acff> <ac00>\n";
- $stream .= "<ad00> <adff> <ad00>\n";
- $stream .= "<ae00> <aeff> <ae00>\n";
- $stream .= "<af00> <afff> <af00>\n";
- $stream .= "<b000> <b0ff> <b000>\n";
- $stream .= "<b100> <b1ff> <b100>\n";
- $stream .= "<b200> <b2ff> <b200>\n";
- $stream .= "<b300> <b3ff> <b300>\n";
- $stream .= "<b400> <b4ff> <b400>\n";
- $stream .= "<b500> <b5ff> <b500>\n";
- $stream .= "<b600> <b6ff> <b600>\n";
- $stream .= "<b700> <b7ff> <b700>\n";
- $stream .= "<b800> <b8ff> <b800>\n";
- $stream .= "<b900> <b9ff> <b900>\n";
- $stream .= "<ba00> <baff> <ba00>\n";
- $stream .= "<bb00> <bbff> <bb00>\n";
- $stream .= "<bc00> <bcff> <bc00>\n";
- $stream .= "<bd00> <bdff> <bd00>\n";
- $stream .= "<be00> <beff> <be00>\n";
- $stream .= "<bf00> <bfff> <bf00>\n";
- $stream .= "<c000> <c0ff> <c000>\n";
- $stream .= "<c100> <c1ff> <c100>\n";
- $stream .= "<c200> <c2ff> <c200>\n";
- $stream .= "<c300> <c3ff> <c300>\n";
- $stream .= "<c400> <c4ff> <c400>\n";
- $stream .= "<c500> <c5ff> <c500>\n";
- $stream .= "<c600> <c6ff> <c600>\n";
- $stream .= "<c700> <c7ff> <c700>\n";
- $stream .= "endbfrange\n";
- $stream .= "56 beginbfrange\n";
- $stream .= "<c800> <c8ff> <c800>\n";
- $stream .= "<c900> <c9ff> <c900>\n";
- $stream .= "<ca00> <caff> <ca00>\n";
- $stream .= "<cb00> <cbff> <cb00>\n";
- $stream .= "<cc00> <ccff> <cc00>\n";
- $stream .= "<cd00> <cdff> <cd00>\n";
- $stream .= "<ce00> <ceff> <ce00>\n";
- $stream .= "<cf00> <cfff> <cf00>\n";
- $stream .= "<d000> <d0ff> <d000>\n";
- $stream .= "<d100> <d1ff> <d100>\n";
- $stream .= "<d200> <d2ff> <d200>\n";
- $stream .= "<d300> <d3ff> <d300>\n";
- $stream .= "<d400> <d4ff> <d400>\n";
- $stream .= "<d500> <d5ff> <d500>\n";
- $stream .= "<d600> <d6ff> <d600>\n";
- $stream .= "<d700> <d7ff> <d700>\n";
- $stream .= "<d800> <d8ff> <d800>\n";
- $stream .= "<d900> <d9ff> <d900>\n";
- $stream .= "<da00> <daff> <da00>\n";
- $stream .= "<db00> <dbff> <db00>\n";
- $stream .= "<dc00> <dcff> <dc00>\n";
- $stream .= "<dd00> <ddff> <dd00>\n";
- $stream .= "<de00> <deff> <de00>\n";
- $stream .= "<df00> <dfff> <df00>\n";
- $stream .= "<e000> <e0ff> <e000>\n";
- $stream .= "<e100> <e1ff> <e100>\n";
- $stream .= "<e200> <e2ff> <e200>\n";
- $stream .= "<e300> <e3ff> <e300>\n";
- $stream .= "<e400> <e4ff> <e400>\n";
- $stream .= "<e500> <e5ff> <e500>\n";
- $stream .= "<e600> <e6ff> <e600>\n";
- $stream .= "<e700> <e7ff> <e700>\n";
- $stream .= "<e800> <e8ff> <e800>\n";
- $stream .= "<e900> <e9ff> <e900>\n";
- $stream .= "<ea00> <eaff> <ea00>\n";
- $stream .= "<eb00> <ebff> <eb00>\n";
- $stream .= "<ec00> <ecff> <ec00>\n";
- $stream .= "<ed00> <edff> <ed00>\n";
- $stream .= "<ee00> <eeff> <ee00>\n";
- $stream .= "<ef00> <efff> <ef00>\n";
- $stream .= "<f000> <f0ff> <f000>\n";
- $stream .= "<f100> <f1ff> <f100>\n";
- $stream .= "<f200> <f2ff> <f200>\n";
- $stream .= "<f300> <f3ff> <f300>\n";
- $stream .= "<f400> <f4ff> <f400>\n";
- $stream .= "<f500> <f5ff> <f500>\n";
- $stream .= "<f600> <f6ff> <f600>\n";
- $stream .= "<f700> <f7ff> <f700>\n";
- $stream .= "<f800> <f8ff> <f800>\n";
- $stream .= "<f900> <f9ff> <f900>\n";
- $stream .= "<fa00> <faff> <fa00>\n";
- $stream .= "<fb00> <fbff> <fb00>\n";
- $stream .= "<fc00> <fcff> <fc00>\n";
- $stream .= "<fd00> <fdff> <fd00>\n";
- $stream .= "<fe00> <feff> <fe00>\n";
- $stream .= "<ff00> <ffff> <ff00>\n";
- $stream .= "endbfrange\n";
- $stream .= "endcmap\n";
- $stream .= "CMapName currentdict /CMap defineresource pop\n";
- $stream .= "end\n";
- $stream .= "end";
-
- $this->_newobj();
- $stream = ($this->compress) ? gzcompress($stream) : $stream;
- $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
- $stream = $this->_getrawstream($stream);
- $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
-
-
- $oid = $this->_newobj();
- $out = '<< /Type /Font';
- $out .= ' /Subtype /CIDFontType2';
- $out .= ' /BaseFont /'.$fontname;
-
- $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
- $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
- $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
- $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
- $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
- $out .= ' /DW '.$font['dw'];
- $out .= "\n".$this->_putfontwidths($font, 0);
- if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
- $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
- }
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
-
-
- $this->_newobj();
- $out = '<< /Type /FontDescriptor';
- $out .= ' /FontName /'.$fontname;
- foreach ($font['desc'] as $key => $value) {
- if (is_float($value)) {
- $value = sprintf('%.3F', $value);
- }
- $out .= ' /'.$key.' '.$value;
- }
- $fontdir = false;
- if (!$this->empty_string($font['file'])) {
-
- $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
- $fontdir = $this->FontFiles[$font['file']]['fontdir'];
- }
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
- $this->_newobj();
-
-
-
- $ctgfile = strtolower($font['ctg']);
-
- $fontfile = '';
-
- if (($fontdir !== false) AND file_exists($fontdir.$ctgfile)) {
- $fontfile = $fontdir.$ctgfile;
- } elseif (file_exists($this->_getfontpath().$ctgfile)) {
- $fontfile = $this->_getfontpath().$ctgfile;
- } elseif (file_exists($ctgfile)) {
- $fontfile = $ctgfile;
- }
- if ($this->empty_string($fontfile)) {
- $this->Error('Font file not found: '.$ctgfile);
- }
- $stream = $this->_getrawstream(file_get_contents($fontfile));
- $out = '<< /Length '.strlen($stream).'';
- if (substr($fontfile, -2) == '.z') {
-
-
-
- $out .= ' /Filter /FlateDecode';
- }
- $out .= ' >>';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
-
- protected function _putcidfont0($font) {
- $cidoffset = 0;
- if (!isset($font['cw'][1])) {
- $cidoffset = 31;
- }
- if (isset($font['cidinfo']['uni2cid'])) {
-
- $uni2cid = $font['cidinfo']['uni2cid'];
- $cw = array();
- foreach ($font['cw'] as $uni => $width) {
- if (isset($uni2cid[$uni])) {
- $cw[($uni2cid[$uni] + $cidoffset)] = $width;
- } elseif ($uni < 256) {
- $cw[$uni] = $width;
- }
- }
- $font = array_merge($font, array('cw' => $cw));
- }
- $name = $font['name'];
- $enc = $font['enc'];
- if ($enc) {
- $longname = $name.'-'.$enc;
- } else {
- $longname = $name;
- }
- $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
- $out .= '<</Type /Font';
- $out .= ' /Subtype /Type0';
- $out .= ' /BaseFont /'.$longname;
- $out .= ' /Name /F'.$font['i'];
- if ($enc) {
- $out .= ' /Encoding /'.$enc;
- }
- $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- $oid = $this->_newobj();
- $out = '<</Type /Font';
- $out .= ' /Subtype /CIDFontType0';
- $out .= ' /BaseFont /'.$name;
- $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
- $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
- $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
- $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
- $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
- $out .= ' /DW '.$font['dw'];
- $out .= "\n".$this->_putfontwidths($font, $cidoffset);
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- $this->_newobj();
- $s = '<</Type /FontDescriptor /FontName /'.$name;
- foreach ($font['desc'] as $k => $v) {
- if ($k != 'Style') {
- if (is_float($v)) {
- $v = sprintf('%.3F', $v);
- }
- $s .= ' /'.$k.' '.$v.'';
- }
- }
- $s .= '>>';
- $s .= "\n".'endobj';
- $this->_out($s);
- }
-
- protected function _putimages() {
- $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
- foreach ($this->imagekeys as $file) {
- $info = $this->getImageBuffer($file);
-
- if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
- $altoid = $this->_newobj();
- $out = '[';
- foreach ($info['altimgs'] as $altimage) {
- if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
- $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
- $out .= ' /DefaultForPrinting';
- if ($altimage[1] === true) {
- $out .= ' true';
- } else {
- $out .= ' false';
- }
- $out .= ' >>';
- }
- }
- $out .= ' ]';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- $oid = $this->_newobj();
- $this->xobjects['I'.$info['i']] = array('n' => $oid);
- $this->setImageSubBuffer($file, 'n', $this->n);
- $out = '<</Type /XObject';
- $out .= ' /Subtype /Image';
- $out .= ' /Width '.$info['w'];
- $out .= ' /Height '.$info['h'];
- if (array_key_exists('masked', $info)) {
- $out .= ' /SMask '.($this->n - 1).' 0 R';
- }
-
- $icc = false;
- if (isset($info['icc']) AND ($info['icc'] !== false)) {
-
- $icc = true;
- $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
- } elseif ($info['cs'] == 'Indexed') {
-
- $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
- } else {
-
- $out .= ' /ColorSpace /'.$info['cs'];
- }
- if ($info['cs'] == 'DeviceCMYK') {
- $out .= ' /Decode [1 0 1 0 1 0 1 0]';
- }
- $out .= ' /BitsPerComponent '.$info['bpc'];
- if (isset($altoid) AND ($altoid > 0)) {
-
- $out .= ' /Alternates '.$altoid.' 0 R';
- }
- if (isset($info['exurl']) AND !empty($info['exurl'])) {
-
- $out .= ' /Length 0';
- $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
- if (isset($info['f'])) {
- $out .= ' /FFilter /'.$info['f'];
- }
- $out .= ' >>';
- $out .= ' stream'."\n".'endstream';
- } else {
- if (isset($info['f'])) {
- $out .= ' /Filter /'.$info['f'];
- }
- if (isset($info['parms'])) {
- $out .= ' '.$info['parms'];
- }
- if (isset($info['trns']) AND is_array($info['trns'])) {
- $trns = '';
- $count_info = count($info['trns']);
- for ($i=0; $i < $count_info; ++$i) {
- $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
- }
- $out .= ' /Mask ['.$trns.']';
- }
- $stream = $this->_getrawstream($info['data']);
- $out .= ' /Length '.strlen($stream).' >>';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- }
- $out .= "\n".'endobj';
- $this->_out($out);
- if ($icc) {
-
- $this->_newobj();
- $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
- $icc = $this->_getrawstream($icc);
- $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
- } elseif ($info['cs'] == 'Indexed') {
-
- $this->_newobj();
- $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
- $pal = $this->_getrawstream($pal);
- $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
- }
- }
- }
-
- protected function _putxobjects() {
- foreach ($this->xobjects as $key => $data) {
- if (isset($data['outdata'])) {
- $stream = trim($data['outdata']);
- $out = $this->_getobj($data['n'])."\n";
- $out .= '<<';
- $out .= ' /Type /XObject';
- $out .= ' /Subtype /Form';
- $out .= ' /FormType 1';
- if ($this->compress) {
- $stream = gzcompress($stream);
- $out .= ' /Filter /FlateDecode';
- }
- $out .= sprintf(' /BBox [%.2F %.2F %.2F %.2F]', ($data['x'] * $this->k), (-$data['y'] * $this->k), (($data['w'] + $data['x']) * $this->k), (($data['h'] - $data['y']) * $this->k));
- $out .= ' /Matrix [1 0 0 1 0 0]';
- $out .= ' /Resources <<';
- $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
- if (!$this->pdfa_mode) {
-
- if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
- $out .= ' /ExtGState <<';
- foreach ($data['extgstates'] as $k => $extgstate) {
- if (isset($this->extgstates[$k]['name'])) {
- $out .= ' /'.$this->extgstates[$k]['name'];
- } else {
- $out .= ' /GS'.$k;
- }
- $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
- }
- $out .= ' >>';
- }
- if (isset($data['gradients']) AND !empty($data['gradients'])) {
- $gp = '';
- $gs = '';
- foreach ($data['gradients'] as $id => $grad) {
-
- $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
-
- $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
- }
- $out .= ' /Pattern <<'.$gp.' >>';
- $out .= ' /Shading <<'.$gs.' >>';
- }
- }
-
- if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
- $out .= ' /ColorSpace <<';
- foreach ($data['spot_colors'] as $name => $color) {
- $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
- }
- $out .= ' >>';
- }
-
- if (!empty($data['fonts'])) {
- $out .= ' /Font <<';
- foreach ($data['fonts'] as $fontkey => $fontid) {
- $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
- }
- $out .= ' >>';
- }
-
- if (!empty($data['images']) OR !empty($data['xobjects'])) {
- $out .= ' /XObject <<';
- foreach ($data['images'] as $imgid) {
- $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
- }
- foreach ($data['xobjects'] as $sub_id => $sub_objid) {
- $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
- }
- $out .= ' >>';
- }
- $out .= ' >>';
- if (isset($data['group']) AND ($data['group'] !== false)) {
-
- $out .= ' /Group << /Type /Group /S /Transparency';
- if (is_array($data['group'])) {
- if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
- $out .= ' /CS /'.$data['group']['CS'];
- }
- if (isset($data['group']['I'])) {
- $out .= ' /I /'.($data['group']['I']===true?'true':'false');
- }
- if (isset($data['group']['K'])) {
- $out .= ' /K /'.($data['group']['K']===true?'true':'false');
- }
- }
- $out .= ' >>';
- }
- $stream = $this->_getrawstream($stream, $data['n']);
- $out .= ' /Length '.strlen($stream);
- $out .= ' >>';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
- }
-
- protected function _putspotcolors() {
- foreach ($this->spot_colors as $name => $color) {
- $this->_newobj();
- $this->spot_colors[$name]['n'] = $this->n;
- $out = '[/Separation /'.str_replace(' ', '#20', $name);
- $out .= ' /DeviceCMYK <<';
- $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
- $out .= ' '.sprintf('/C1 [%.4F %.4F %.4F %.4F] ', ($color['c'] / 100), ($color['m'] / 100), ($color['y'] / 100), ($color['k'] / 100));
- $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
-
- protected function _getxobjectdict() {
- $out = '';
- foreach ($this->xobjects as $id => $objid) {
- $out .= ' /'.$id.' '.$objid['n'].' 0 R';
- }
- return $out;
- }
-
- protected function _putresourcedict() {
- $out = $this->_getobj(2)."\n";
- $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
- $out .= ' /Font <<';
- foreach ($this->fontkeys as $fontkey) {
- $font = $this->getFontBuffer($fontkey);
- $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
- }
- $out .= ' >>';
- $out .= ' /XObject <<';
- $out .= $this->_getxobjectdict();
- $out .= ' >>';
-
- if (!empty($this->pdflayers)) {
- $out .= ' /Properties <<';
- foreach ($this->pdflayers as $layer) {
- $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
- }
- $out .= ' >>';
- }
- if (!$this->pdfa_mode) {
-
- if (isset($this->extgstates) AND !empty($this->extgstates)) {
- $out .= ' /ExtGState <<';
- foreach ($this->extgstates as $k => $extgstate) {
- if (isset($extgstate['name'])) {
- $out .= ' /'.$extgstate['name'];
- } else {
- $out .= ' /GS'.$k;
- }
- $out .= ' '.$extgstate['n'].' 0 R';
- }
- $out .= ' >>';
- }
- if (isset($this->gradients) AND !empty($this->gradients)) {
- $gp = '';
- $gs = '';
- foreach ($this->gradients as $id => $grad) {
-
- $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
-
- $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
- }
- $out .= ' /Pattern <<'.$gp.' >>';
- $out .= ' /Shading <<'.$gs.' >>';
- }
- }
-
- if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
- $out .= ' /ColorSpace <<';
- foreach ($this->spot_colors as $color) {
- $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
- }
- $out .= ' >>';
- }
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- protected function _putresources() {
- $this->_putextgstates();
- $this->_putocg();
- $this->_putfonts();
- $this->_putimages();
- $this->_putspotcolors();
- $this->_putshaders();
- $this->_putxobjects();
- $this->_putresourcedict();
- $this->_putdests();
- $this->_putbookmarks();
- $this->_putEmbeddedFiles();
- $this->_putannotsobjs();
- $this->_putjavascript();
- $this->_putencryption();
- }
-
- protected function _putinfo() {
- $oid = $this->_newobj();
- $out = '<<';
-
- $prev_isunicode = $this->isunicode;
- if ($this->docinfounicode) {
- $this->isunicode = true;
- }
- if (!$this->empty_string($this->title)) {
-
- $out .= ' /Title '.$this->_textstring($this->title, $oid);
- }
- if (!$this->empty_string($this->author)) {
-
- $out .= ' /Author '.$this->_textstring($this->author, $oid);
- }
- if (!$this->empty_string($this->subject)) {
-
- $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
- }
- if (!$this->empty_string($this->keywords)) {
-
- $out .= ' /Keywords '.$this->_textstring($this->keywords.' TCPDF', $oid);
- }
- if (!$this->empty_string($this->creator)) {
-
- $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
- }
-
- $this->isunicode = $prev_isunicode;
-
- $out .= ' /Producer '.$this->_textstring("\x54\x43\x50\x44\x46\x20".$this->tcpdf_version."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29", $oid);
-
- $out .= ' /CreationDate '.$this->_datestring();
-
- $out .= ' /ModDate '.$this->_datestring();
-
- $out .= ' /Trapped /False';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- return $oid;
- }
-
- public function setExtraXMP($xmp) {
- $this->custom_xmp = $xmp;
- }
-
- protected function _putXMP() {
- $oid = $this->_newobj();
-
- $prev_isunicode = $this->isunicode;
- $this->isunicode = true;
- $prev_encrypted = $this->encrypted;
- $this->encrypted = false;
-
- $xmp = '<?xpacket begin="'.$this->unichr(0xfeff).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
- $xmp .= '<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:08:04">'."\n";
- $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
- $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
- $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
- $xmp .= "\t\t\t".'<dc:title>'."\n";
- $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
- $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.$this->_escapeXML($this->title).'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
- $xmp .= "\t\t\t".'</dc:title>'."\n";
- $xmp .= "\t\t\t".'<dc:creator>'."\n";
- $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
- $xmp .= "\t\t\t\t\t".'<rdf:li>'.$this->_escapeXML($this->author).'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
- $xmp .= "\t\t\t".'</dc:creator>'."\n";
- $xmp .= "\t\t\t".'<dc:description>'."\n";
- $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
- $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.$this->_escapeXML($this->subject).'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
- $xmp .= "\t\t\t".'</dc:description>'."\n";
- $xmp .= "\t\t\t".'<dc:subject>'."\n";
- $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
- $xmp .= "\t\t\t\t\t".'<rdf:li>'.$this->_escapeXML($this->keywords).'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
- $xmp .= "\t\t\t".'</dc:subject>'."\n";
- $xmp .= "\t\t".'</rdf:Description>'."\n";
-
- $docdate = substr($this->doc_date, 0, 4).'-'.substr($this->doc_date, 4, 2).'-'.substr($this->doc_date, 6, 2);
- $docdate .= 'T'.substr($this->doc_date, 8, 2).':'.substr($this->doc_date, 10, 2).':'.substr($this->doc_date, 12, 2);
- $docdate .= '+'.substr($this->doc_date, 15, 2).':'.substr($this->doc_date, 18, 2);
- $docdate = $this->_escapeXML($docdate);
- $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
- $xmp .= "\t\t\t".'<xmp:CreateDate>'.$docdate.'</xmp:CreateDate>'."\n";
- $xmp .= "\t\t\t".'<xmp:CreatorTool>TCPDF</xmp:CreatorTool>'."\n";
- $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docdate.'</xmp:ModifyDate>'."\n";
- $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$docdate.'</xmp:MetadataDate>'."\n";
- $xmp .= "\t\t".'</rdf:Description>'."\n";
- $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
- $xmp .= "\t\t\t".'<pdf:Keywords>'.$this->_escapeXML($this->keywords).' TCPDF</pdf:Keywords>'."\n";
- $xmp .= "\t\t\t".'<pdf:Producer>'.$this->_escapeXML("\x54\x43\x50\x44\x46\x20".$this->tcpdf_version."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29").'</pdf:Producer>'."\n";
- $xmp .= "\t\t".'</rdf:Description>'."\n";
- $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
- $uuid = 'uuid:'.substr($this->file_id, 0, 8).'-'.substr($this->file_id, 8, 4).'-'.substr($this->file_id, 12, 4).'-'.substr($this->file_id, 16, 4).'-'.substr($this->file_id, 20, 12);
- $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
- $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
- $xmp .= "\t\t".'</rdf:Description>'."\n";
- if ($this->pdfa_mode) {
- $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
- $xmp .= "\t\t\t".'<pdfaid:part>1</pdfaid:part>'."\n";
- $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
- $xmp .= "\t\t".'</rdf:Description>'."\n";
- }
-
- $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#">'."\n";
- $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
- $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
- $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
- $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
- $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
- $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
- $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
- $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
- $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
- $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
- $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
- $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
- $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
- $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
- $xmp .= "\t\t".'</rdf:Description>'."\n";
- $xmp .= "\t".'</rdf:RDF>'."\n";
- $xmp .= $this->custom_xmp;
- $xmp .= '</x:xmpmeta>'."\n";
- $xmp .= '<?xpacket end="w"?>';
- $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
-
- $this->isunicode = $prev_isunicode;
- $this->encrypted = $prev_encrypted;
- $this->_out($out);
- return $oid;
- }
-
- protected function _putcatalog() {
-
- $xmpobj = $this->_putXMP();
-
- if ($this->pdfa_mode OR $this->force_srgb) {
- $iccobj = $this->_newobj();
- $icc = file_get_contents(dirname(__FILE__).'/sRGB.icc');
- $filter = '';
- if ($this->compress) {
- $filter = ' /Filter /FlateDecode';
- $icc = gzcompress($icc);
- }
- $icc = $this->_getrawstream($icc);
- $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
- }
-
- $oid = $this->_newobj();
- $out = '<< /Type /Catalog';
- $out .= ' /Version /'.$this->PDFVersion;
-
- $out .= ' /Pages 1 0 R';
-
- $out .= ' /Names <<';
- if ((!$this->pdfa_mode) AND ((!empty($this->javascript)) OR (!empty($this->js_objects)))) {
- $out .= ' /JavaScript '.($this->n_js).' 0 R';
- }
- $out .= ' >>';
- if (!empty($this->dests)) {
- $out .= ' /Dests '.$this->n_dests.' 0 R';
- }
- $out .= $this->_putviewerpreferences();
- if (isset($this->LayoutMode) AND (!$this->empty_string($this->LayoutMode))) {
- $out .= ' /PageLayout /'.$this->LayoutMode;
- }
- if (isset($this->PageMode) AND (!$this->empty_string($this->PageMode))) {
- $out .= ' /PageMode /'.$this->PageMode;
- }
- if (count($this->outlines) > 0) {
- $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
- $out .= ' /PageMode /UseOutlines';
- }
-
- if ($this->ZoomMode == 'fullpage') {
- $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
- } elseif ($this->ZoomMode == 'fullwidth') {
- $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
- } elseif ($this->ZoomMode == 'real') {
- $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
- } elseif (!is_string($this->ZoomMode)) {
- $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %.2F]', ($this->ZoomMode / 100));
- }
-
-
- $out .= ' /Metadata '.$xmpobj.' 0 R';
-
-
- if (isset($this->l['a_meta_language'])) {
- $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
- }
-
-
- if ($this->pdfa_mode OR $this->force_srgb) {
- $out .= ' /OutputIntents [<<';
- $out .= ' /Type /OutputIntent';
- $out .= ' /S /GTS_PDFA1';
- $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
- $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
- $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
- $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
- $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
- $out .= ' >>]';
- }
-
- if (!empty($this->pdflayers)) {
- $lyrobjs = '';
- $lyrobjs_print = '';
- $lyrobjs_view = '';
- foreach ($this->pdflayers as $layer) {
- $lyrobjs .= ' '.$layer['objid'].' 0 R';
- if ($layer['print']) {
- $lyrobjs_print .= ' '.$layer['objid'].' 0 R';
- }
- if ($layer['view']) {
- $lyrobjs_view .= ' '.$layer['objid'].' 0 R';
- }
- }
- $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
- $out .= ' /D <<';
- $out .= ' /Name '.$this->_textstring('Layers', $oid);
- $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
- $out .= ' /BaseState /ON';
- $out .= ' /ON ['.$lyrobjs_print.']';
- $out .= ' /OFF ['.$lyrobjs_view.']';
- $out .= ' /Intent /View';
- $out .= ' /AS [';
- $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
- $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
- $out .= ' ]';
- $out .= ' /Order ['.$lyrobjs.']';
- $out .= ' /ListMode /AllPages';
-
-
- $out .= ' >>';
- $out .= ' >>';
- }
-
- if (!empty($this->form_obj_id) OR ($this->sign AND isset($this->signature_data['cert_type']))) {
- $out .= ' /AcroForm <<';
- $objrefs = '';
- if ($this->sign AND isset($this->signature_data['cert_type'])) {
-
- $objrefs .= $this->sig_obj_id.' 0 R';
- }
- if (!empty($this->empty_signature_appearance)) {
- foreach ($this->empty_signature_appearance as $esa) {
-
- $objrefs .= ' '.$esa['objid'].' 0 R';
- }
- }
- if (!empty($this->form_obj_id)) {
- foreach($this->form_obj_id as $objid) {
- $objrefs .= ' '.$objid.' 0 R';
- }
- }
- $out .= ' /Fields ['.$objrefs.']';
-
- $out .= ' /NeedAppearances false';
- if ($this->sign AND isset($this->signature_data['cert_type'])) {
- if ($this->signature_data['cert_type'] > 0) {
- $out .= ' /SigFlags 3';
- } else {
- $out .= ' /SigFlags 1';
- }
- }
-
- if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
- $out .= ' /DR <<';
- $out .= ' /Font <<';
- foreach ($this->annotation_fonts as $fontkey => $fontid) {
- $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
- }
- $out .= ' >> >>';
- }
- $font = $this->getFontBuffer('helvetica');
- $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
- $out .= ' /Q '.(($this->rtl)?'2':'0');
-
- $out .= ' >>';
-
- if ($this->sign AND isset($this->signature_data['cert_type'])) {
- if ($this->signature_data['cert_type'] > 0) {
- $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
- } else {
- $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
- }
- }
- }
-
-
-
-
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- return $oid;
- }
-
- protected function _putviewerpreferences() {
- $out = ' /ViewerPreferences <<';
- if ($this->rtl) {
- $out .= ' /Direction /R2L';
- } else {
- $out .= ' /Direction /L2R';
- }
- if (isset($this->viewer_preferences['HideToolbar']) AND ($this->viewer_preferences['HideToolbar'])) {
- $out .= ' /HideToolbar true';
- }
- if (isset($this->viewer_preferences['HideMenubar']) AND ($this->viewer_preferences['HideMenubar'])) {
- $out .= ' /HideMenubar true';
- }
- if (isset($this->viewer_preferences['HideWindowUI']) AND ($this->viewer_preferences['HideWindowUI'])) {
- $out .= ' /HideWindowUI true';
- }
- if (isset($this->viewer_preferences['FitWindow']) AND ($this->viewer_preferences['FitWindow'])) {
- $out .= ' /FitWindow true';
- }
- if (isset($this->viewer_preferences['CenterWindow']) AND ($this->viewer_preferences['CenterWindow'])) {
- $out .= ' /CenterWindow true';
- }
- if (isset($this->viewer_preferences['DisplayDocTitle']) AND ($this->viewer_preferences['DisplayDocTitle'])) {
- $out .= ' /DisplayDocTitle true';
- }
- if (isset($this->viewer_preferences['NonFullScreenPageMode'])) {
- $out .= ' /NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode'];
- }
- if (isset($this->viewer_preferences['ViewArea'])) {
- $out .= ' /ViewArea /'.$this->viewer_preferences['ViewArea'];
- }
- if (isset($this->viewer_preferences['ViewClip'])) {
- $out .= ' /ViewClip /'.$this->viewer_preferences['ViewClip'];
- }
- if (isset($this->viewer_preferences['PrintArea'])) {
- $out .= ' /PrintArea /'.$this->viewer_preferences['PrintArea'];
- }
- if (isset($this->viewer_preferences['PrintClip'])) {
- $out .= ' /PrintClip /'.$this->viewer_preferences['PrintClip'];
- }
- if (isset($this->viewer_preferences['PrintScaling'])) {
- $out .= ' /PrintScaling /'.$this->viewer_preferences['PrintScaling'];
- }
- if (isset($this->viewer_preferences['Duplex']) AND (!$this->empty_string($this->viewer_preferences['Duplex']))) {
- $out .= ' /Duplex /'.$this->viewer_preferences['Duplex'];
- }
- if (isset($this->viewer_preferences['PickTrayByPDFSize'])) {
- if ($this->viewer_preferences['PickTrayByPDFSize']) {
- $out .= ' /PickTrayByPDFSize true';
- } else {
- $out .= ' /PickTrayByPDFSize false';
- }
- }
- if (isset($this->viewer_preferences['PrintPageRange'])) {
- $PrintPageRangeNum = '';
- foreach ($this->viewer_preferences['PrintPageRange'] as $k => $v) {
- $PrintPageRangeNum .= ' '.($v - 1).'';
- }
- $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
- }
- if (isset($this->viewer_preferences['NumCopies'])) {
- $out .= ' /NumCopies '.intval($this->viewer_preferences['NumCopies']);
- }
- $out .= ' >>';
- return $out;
- }
-
- protected function _putheader() {
- $this->_out('%PDF-'.$this->PDFVersion);
- $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
- }
-
- protected function _enddoc() {
- $this->state = 1;
- $this->_putheader();
- $this->_putpages();
- $this->_putresources();
-
- if (!empty($this->empty_signature_appearance)) {
- foreach ($this->empty_signature_appearance as $key => $esa) {
-
- $out = $this->_getobj($esa['objid'])."\n";
- $out .= '<< /Type /Annot';
- $out .= ' /Subtype /Widget';
- $out .= ' /Rect ['.$esa['rect'].']';
- $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R';
- $out .= ' /F 4';
- $out .= ' /FT /Sig';
- $signame = sprintf('Signature_%03d', ($key + 1));
- $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
- $out .= ' /Ff 0';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
-
- if ($this->sign AND isset($this->signature_data['cert_type'])) {
-
- $out = $this->_getobj($this->sig_obj_id)."\n";
- $out .= '<< /Type /Annot';
- $out .= ' /Subtype /Widget';
- $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
- $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R';
- $out .= ' /F 4';
- $out .= ' /FT /Sig';
- $out .= ' /T '.$this->_textstring('Signature_000', $this->sig_obj_id);
- $out .= ' /Ff 0';
- $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
-
- $this->_putsignature();
- }
-
- $objid_info = $this->_putinfo();
-
- $objid_catalog = $this->_putcatalog();
-
- $o = $this->bufferlen;
-
- $this->_out('xref');
- $this->_out('0 '.($this->n + 1));
- $this->_out('0000000000 65535 f ');
- for ($i=1; $i <= $this->n; ++$i) {
- if (!isset($this->offsets[$i]) AND ($i > 1)) {
- $this->offsets[$i] = $this->offsets[($i - 1)];
- }
- $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
- }
-
- $out = 'trailer'."\n";
- $out .= '<<';
- $out .= ' /Size '.($this->n + 1);
- $out .= ' /Root '.$objid_catalog.' 0 R';
- $out .= ' /Info '.$objid_info.' 0 R';
- if ($this->encrypted) {
- $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
- }
- $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
- $out .= ' >>';
- $this->_out($out);
- $this->_out('startxref');
- $this->_out($o);
- $this->_out('%%EOF');
- $this->state = 3;
- if ($this->diskcache) {
-
- foreach ($this->imagekeys as $key) {
-
- unlink($this->images[$key]);
- }
- foreach ($this->fontkeys as $key) {
-
- unlink($this->fonts[$key]);
- }
- }
- }
-
- protected function _beginpage($orientation='', $format='') {
- ++$this->page;
- $this->setPageBuffer($this->page, '');
-
- $this->transfmrk[$this->page] = array();
- $this->state = 2;
- if ($this->empty_string($orientation)) {
- if (isset($this->CurOrientation)) {
- $orientation = $this->CurOrientation;
- } elseif ($this->fwPt > $this->fhPt) {
-
- $orientation = 'L';
- } else {
-
- $orientation = 'P';
- }
- }
- if ($this->empty_string($format)) {
- $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
- $this->setPageOrientation($orientation);
- } else {
- $this->setPageFormat($format, $orientation);
- }
- if ($this->rtl) {
- $this->x = $this->w - $this->rMargin;
- } else {
- $this->x = $this->lMargin;
- }
- $this->y = $this->tMargin;
- if (isset($this->newpagegroup[$this->page])) {
-
- $this->currpagegroup = $this->newpagegroup[$this->page];
- $this->pagegroups[$this->currpagegroup] = 1;
- } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
- ++$this->pagegroups[$this->currpagegroup];
- }
- }
-
- protected function _endpage() {
- $this->setVisibility('all');
- $this->state = 1;
- }
-
- protected function _newobj() {
- $this->_out($this->_getobj());
- return $this->n;
- }
-
- protected function _getobj($objid='') {
- if ($objid === '') {
- ++$this->n;
- $objid = $this->n;
- }
- $this->offsets[$objid] = $this->bufferlen;
- return $objid.' 0 obj';
- }
-
- protected function _dounderline($x, $y, $txt) {
- $w = $this->GetStringWidth($txt);
- return $this->_dounderlinew($x, $y, $w);
- }
-
- protected function _dounderlinew($x, $y, $w) {
- $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
- return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
- }
-
- protected function _dolinethrough($x, $y, $txt) {
- $w = $this->GetStringWidth($txt);
- return $this->_dolinethroughw($x, $y, $w);
- }
-
- protected function _dolinethroughw($x, $y, $w) {
- $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
- return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
- }
-
- protected function _dooverline($x, $y, $txt) {
- $w = $this->GetStringWidth($txt);
- return $this->_dooverlinew($x, $y, $w);
- }
-
- protected function _dooverlinew($x, $y, $w) {
- $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
- return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
- }
-
- protected function _freadint($f) {
- $a = unpack('Ni', fread($f, 4));
- return $a['i'];
- }
-
- protected function _escape($s) {
-
- return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
- }
-
- protected function _datastring($s, $n=0) {
- if ($n == 0) {
- $n = $this->n;
- }
- $s = $this->_encrypt_data($n, $s);
- return '('. $this->_escape($s).')';
- }
-
- protected function _datestring($n=0) {
- return $this->_datastring('D:'.$this->doc_date, $n);
- }
-
- protected function _textstring($s, $n=0) {
- if ($this->isunicode) {
-
- $s = $this->UTF8ToUTF16BE($s, true);
- }
- return $this->_datastring($s, $n);
- }
-
- protected function _escapetext($s) {
- if ($this->isunicode) {
- if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
- $s = $this->UTF8ToLatin1($s);
- } else {
-
- $s = $this->utf8StrRev($s, false, $this->tmprtl);
- }
- }
- return $this->_escape($s);
- }
-
- protected function _escapeXML($str) {
- $replaceTable = array("\0" => '', '&' => '&', '<' => '<', '>' => '>');
- $str = strtr($str, $replaceTable);
- return $str;
- }
-
- protected function _getrawstream($s, $n=0) {
- if ($n <= 0) {
-
- $n = $this->n;
- }
- return $this->_encrypt_data($n, $s);
- }
-
- protected function _getstream($s, $n=0) {
- return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream';
- }
-
- protected function _putstream($s, $n=0) {
- $this->_out($this->_getstream($s, $n));
- }
-
- protected function _out($s) {
- if ($this->state == 2) {
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
- } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
-
- $pagebuff = $this->getPageBuffer($this->page);
- $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
- $footer = substr($pagebuff, -$this->footerlen[$this->page]);
- $this->setPageBuffer($this->page, $page.$s."\n".$footer);
-
- $this->footerpos[$this->page] += strlen($s."\n");
- } else {
- $this->setPageBuffer($this->page, $s."\n", true);
- }
- } else {
- $this->setBuffer($s."\n");
- }
- }
-
- protected function UTF8StringToArray($str) {
-
- $strkey = md5($str);
- if (isset($this->cache_UTF8StringToArray[$strkey])) {
-
- $chrarray = $this->cache_UTF8StringToArray[$strkey]['s'];
- if (!isset($this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']])) {
- if ($this->isunicode) {
- foreach ($chrarray as $chr) {
-
- $this->CurrentFont['subsetchars'][$chr] = true;
- }
-
- $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
- }
- $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
- }
- return $chrarray;
- }
-
- if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) {
-
- array_shift($this->cache_UTF8StringToArray);
- }
-
- $this->cache_UTF8StringToArray[$strkey] = array('s' => array(), 'f' => array());
- ++$this->cache_size_UTF8StringToArray;
- if (!$this->isunicode) {
-
- $strarr = array();
- $strlen = strlen($str);
- for ($i=0; $i < $strlen; ++$i) {
- $strarr[] = ord($str[$i]);
- }
-
- $this->cache_UTF8StringToArray[$strkey]['s'] = $strarr;
- $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
- return $strarr;
- }
- $unichar = -1;
- $unicode = array();
- $bytes = array();
- $numbytes = 1;
- $str .= '';
- $length = strlen($str);
- for ($i = 0; $i < $length; ++$i) {
- $char = ord($str[$i]);
- if (count($bytes) == 0) {
- if ($char <= 0x7F) {
- $unichar = $char;
- $numbytes = 1;
- } elseif (($char >> 0x05) == 0x06) {
- $bytes[] = ($char - 0xC0) << 0x06;
- $numbytes = 2;
- } elseif (($char >> 0x04) == 0x0E) {
- $bytes[] = ($char - 0xE0) << 0x0C;
- $numbytes = 3;
- } elseif (($char >> 0x03) == 0x1E) {
- $bytes[] = ($char - 0xF0) << 0x12;
- $numbytes = 4;
- } else {
-
- $unichar = 0xFFFD;
- $bytes = array();
- $numbytes = 1;
- }
- } elseif (($char >> 0x06) == 0x02) {
- $bytes[] = $char - 0x80;
- if (count($bytes) == $numbytes) {
-
- $char = $bytes[0];
- for ($j = 1; $j < $numbytes; ++$j) {
- $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
- }
- if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
-
- $unichar = 0xFFFD;
- } else {
- $unichar = $char;
- }
-
- $bytes = array();
- $numbytes = 1;
- }
- } else {
-
- $unichar = 0xFFFD;
- $bytes = array();
- $numbytes = 1;
- }
- if ($unichar >= 0) {
-
- $unicode[] = $unichar;
-
- $this->CurrentFont['subsetchars'][$unichar] = true;
- $unichar = -1;
- }
- }
-
- $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
-
- $this->cache_UTF8StringToArray[$strkey]['s'] = $unicode;
- $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
- return $unicode;
- }
-
- protected function UTF8ToUTF16BE($str, $setbom=false) {
- if (!$this->isunicode) {
- return $str;
- }
- $unicode = $this->UTF8StringToArray($str);
- return $this->arrUTF8ToUTF16BE($unicode, $setbom);
- }
-
- protected function UTF8ToLatin1($str) {
- if (!$this->isunicode) {
- return $str;
- }
- $outstr = '';
- $unicode = $this->UTF8StringToArray($str);
- foreach ($unicode as $char) {
- if ($char < 256) {
- $outstr .= chr($char);
- } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) {
-
- $outstr .= chr($this->unicode->uni_utf8tolatin[$char]);
- } elseif ($char == 0xFFFD) {
-
- } else {
- $outstr .= '?';
- }
- }
- return $outstr;
- }
-
- protected function UTF8ArrToLatin1($unicode) {
- if ((!$this->isunicode) OR $this->isUnicodeFont()) {
- return $unicode;
- }
- $outarr = array();
- foreach ($unicode as $char) {
- if ($char < 256) {
- $outarr[] = $char;
- } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) {
-
- $outarr[] = $this->unicode->uni_utf8tolatin[$char];
- } elseif ($char == 0xFFFD) {
-
- } else {
- $outarr[] = 63;
- }
- }
- return $outarr;
- }
-
- protected function arrUTF8ToUTF16BE($unicode, $setbom=false) {
- $outstr = '';
- if ($setbom) {
- $outstr .= "\xFE\xFF";
- }
- foreach ($unicode as $char) {
- if ($char == 0x200b) {
-
- } elseif ($char == 0xFFFD) {
- $outstr .= "\xFF\xFD";
- } elseif ($char < 0x10000) {
- $outstr .= chr($char >> 0x08);
- $outstr .= chr($char & 0xFF);
- } else {
- $char -= 0x10000;
- $w1 = 0xD800 | ($char >> 0x0a);
- $w2 = 0xDC00 | ($char & 0x3FF);
- $outstr .= chr($w1 >> 0x08);
- $outstr .= chr($w1 & 0xFF);
- $outstr .= chr($w2 >> 0x08);
- $outstr .= chr($w2 & 0xFF);
- }
- }
- return $outstr;
- }
-
-
- public function setHeaderFont($font) {
- $this->header_font = $font;
- }
-
- public function getHeaderFont() {
- return $this->header_font;
- }
-
- public function setFooterFont($font) {
- $this->footer_font = $font;
- }
-
- public function getFooterFont() {
- return $this->footer_font;
- }
-
- public function setLanguageArray($language) {
- $this->l = $language;
- if (isset($this->l['a_meta_dir'])) {
- $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
- } else {
- $this->rtl = false;
- }
- }
-
- public function getPDFData() {
- if ($this->state < 3) {
- $this->Close();
- }
- return $this->buffer;
- }
-
- public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
- if (!$this->empty_string($url) AND ($url{0} == '#')) {
-
- $lnkdata = explode(',', $url);
- if (isset($lnkdata[0])) {
- $page = intval(substr($lnkdata[0], 1));
- if (empty($page) OR ($page <= 0)) {
- $page = $this->page;
- }
- if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
- $lnky = floatval($lnkdata[1]);
- } else {
- $lnky = 0;
- }
- $url = $this->AddLink();
- $this->SetLink($url, $lnky, $page);
- }
- }
-
- $prevcolor = $this->fgcolor;
- $prevstyle = $this->FontStyle;
- if (empty($color)) {
- $this->SetTextColorArray($this->htmlLinkColorArray);
- } else {
- $this->SetTextColorArray($color);
- }
- if ($style == -1) {
- $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle);
- } else {
- $this->SetFont('', $this->FontStyle.$style);
- }
- $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
-
- $this->SetFont('', $prevstyle);
- $this->SetTextColorArray($prevcolor);
- return $ret;
- }
-
- public function convertHTMLColorToDec($hcolor='#FFFFFF', $defcol=array('R'=>128,'G'=>128,'B'=>128)) {
- $color = preg_replace('/[\s]*/', '', $hcolor);
- $color = strtolower($color);
- if (($dotpos = strpos($color, '.')) !== false) {
-
- $color = substr($color, ($dotpos + 1));
- }
- if (strlen($color) == 0) {
- return $defcol;
- }
-
- if (substr($color, 0, 3) == 'rgb') {
- $codes = substr($color, 4);
- $codes = str_replace(')', '', $codes);
- $returncolor = explode(',', $codes);
- foreach ($returncolor as $key => $val) {
- if (strpos($val, '%') > 0) {
-
- $returncolor[$key] = (255 * intval($val) / 100);
- } else {
- $returncolor[$key] = intval($val);
- }
-
- $returncolor[$key] = max(0, min(255, $returncolor[$key]));
- }
- return $returncolor;
- }
-
- if (substr($color, 0, 4) == 'cmyk') {
- $codes = substr($color, 5);
- $codes = str_replace(')', '', $codes);
- $returncolor = explode(',', $codes);
- foreach ($returncolor as $key => $val) {
- if (strpos($val, '%') !== false) {
-
- $returncolor[$key] = (100 * intval($val) / 100);
- } else {
- $returncolor[$key] = intval($val);
- }
-
- $returncolor[$key] = max(0, min(100, $returncolor[$key]));
- }
- return $returncolor;
- }
- if ($color{0} != '#') {
-
- if (isset($this->webcolor[$color])) {
-
- $color_code = $this->webcolor[$color];
- } else {
-
- $returncolor = $this->getSpotColor($color);
- if ($returncolor === false) {
- $returncolor = $defcol;
- }
- return $returncolor;
- }
- } else {
- $color_code = substr($color, 1);
- }
-
- switch (strlen($color_code)) {
- case 3: {
-
- $r = substr($color_code, 0, 1);
- $g = substr($color_code, 1, 1);
- $b = substr($color_code, 2, 1);
- $returncolor = array();
- $returncolor['R'] = max(0, min(255, hexdec($r.$r)));
- $returncolor['G'] = max(0, min(255, hexdec($g.$g)));
- $returncolor['B'] = max(0, min(255, hexdec($b.$b)));
- break;
- }
- case 6: {
-
- $returncolor = array();
- $returncolor['R'] = max(0, min(255, hexdec(substr($color_code, 0, 2))));
- $returncolor['G'] = max(0, min(255, hexdec(substr($color_code, 2, 2))));
- $returncolor['B'] = max(0, min(255, hexdec(substr($color_code, 4, 2))));
- break;
- }
- case 8: {
-
- $returncolor = array();
- $returncolor['C'] = max(0, min(100, round(hexdec(substr($color_code, 0, 2)) / 2.55)));
- $returncolor['M'] = max(0, min(100, round(hexdec(substr($color_code, 2, 2)) / 2.55)));
- $returncolor['Y'] = max(0, min(100, round(hexdec(substr($color_code, 4, 2)) / 2.55)));
- $returncolor['K'] = max(0, min(100, round(hexdec(substr($color_code, 6, 2)) / 2.55)));
- break;
- }
- default: {
- $returncolor = $defcol;
- break;
- }
- }
- return $returncolor;
- }
-
- public function pixelsToUnits($px) {
- return ($px / ($this->imgscale * $this->k));
- }
-
- public function unhtmlentities($text_to_convert) {
- return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
- }
-
-
- protected function getRandomSeed($seed='') {
- $seed .= microtime();
- if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
-
- $seed .= openssl_random_pseudo_bytes(512);
- } else {
- for ($i = 0; $i < 23; ++$i) {
- $seed .= uniqid('', true);
- }
- }
- $seed .= uniqid('', true);
- $seed .= rand();
- $seed .= getmypid();
- $seed .= __FILE__;
- $seed .= $this->bufferlen;
- if (isset($_SERVER['REMOTE_ADDR'])) {
- $seed .= $_SERVER['REMOTE_ADDR'];
- }
- if (isset($_SERVER['HTTP_USER_AGENT'])) {
- $seed .= $_SERVER['HTTP_USER_AGENT'];
- }
- if (isset($_SERVER['HTTP_ACCEPT'])) {
- $seed .= $_SERVER['HTTP_ACCEPT'];
- }
- if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
- $seed .= $_SERVER['HTTP_ACCEPT_ENCODING'];
- }
- if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- $seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
- }
- if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
- $seed .= $_SERVER['HTTP_ACCEPT_CHARSET'];
- }
- $seed .= rand();
- $seed .= uniqid('', true);
- $seed .= microtime();
- return $seed;
- }
-
- protected function _objectkey($n) {
- $objkey = $this->encryptdata['key'].pack('VXxx', $n);
- if ($this->encryptdata['mode'] == 2) {
-
- $objkey .= "\x73\x41\x6C\x54";
- }
- $objkey = substr($this->_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
- $objkey = substr($objkey, 0, 16);
- return $objkey;
- }
-
- protected function _encrypt_data($n, $s) {
- if (!$this->encrypted) {
- return $s;
- }
- switch ($this->encryptdata['mode']) {
- case 0:
- case 1: {
- $s = $this->_RC4($this->_objectkey($n), $s);
- break;
- }
- case 2: {
- $s = $this->_AES($this->_objectkey($n), $s);
- break;
- }
- case 3: {
- $s = $this->_AES($this->encryptdata['key'], $s);
- break;
- }
- }
- return $s;
- }
-
- protected function _putencryption() {
- if (!$this->encrypted) {
- return;
- }
- $this->encryptdata['objid'] = $this->_newobj();
- $out = '<<';
- if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
- $this->encryptdata['Filter'] = 'Standard';
- }
- $out .= ' /Filter /'.$this->encryptdata['Filter'];
- if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
- $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
- }
- if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
- $this->encryptdata['V'] = 1;
- }
-
- $out .= ' /V '.$this->encryptdata['V'];
- if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
-
- $out .= ' /Length '.$this->encryptdata['Length'];
- } else {
- $out .= ' /Length 40';
- }
- if ($this->encryptdata['V'] >= 4) {
- if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
- $this->encryptdata['StmF'] = 'Identity';
- }
- if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
-
- $this->encryptdata['StrF'] = 'Identity';
- }
-
- if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
- $out .= ' /CF <<';
- $out .= ' /'.$this->encryptdata['StmF'].' <<';
- $out .= ' /Type /CryptFilter';
- if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
-
- $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
- if ($this->encryptdata['pubkey']) {
- $out .= ' /Recipients [';
- foreach ($this->encryptdata['Recipients'] as $rec) {
- $out .= ' <'.$rec.'>';
- }
- $out .= ' ]';
- if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
- $out .= ' /EncryptMetadata false';
- } else {
- $out .= ' /EncryptMetadata true';
- }
- }
- } else {
- $out .= ' /CFM /None';
- }
- if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
-
- $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
- } else {
- $out .= ' /AuthEvent /DocOpen';
- }
- if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
-
- $out .= ' /Length '.$this->encryptdata['CF']['Length'];
- }
- $out .= ' >> >>';
- }
-
- $out .= ' /StmF /'.$this->encryptdata['StmF'];
-
- $out .= ' /StrF /'.$this->encryptdata['StrF'];
- if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
-
- $out .= ' /EFF /'.$this->encryptdata[''];
- }
- }
-
- if ($this->encryptdata['pubkey']) {
- if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
- $out .= ' /Recipients [';
- foreach ($this->encryptdata['Recipients'] as $rec) {
- $out .= ' <'.$rec.'>';
- }
- $out .= ' ]';
- }
- } else {
- $out .= ' /R';
- if ($this->encryptdata['V'] == 5) {
- $out .= ' 5';
- $out .= ' /OE ('.$this->_escape($this->encryptdata['OE']).')';
- $out .= ' /UE ('.$this->_escape($this->encryptdata['UE']).')';
- $out .= ' /Perms ('.$this->_escape($this->encryptdata['perms']).')';
- } elseif ($this->encryptdata['V'] == 4) {
- $out .= ' 4';
- } elseif ($this->encryptdata['V'] < 2) {
- $out .= ' 2';
- } else {
- $out .= ' 3';
- }
- $out .= ' /O ('.$this->_escape($this->encryptdata['O']).')';
- $out .= ' /U ('.$this->_escape($this->encryptdata['U']).')';
- $out .= ' /P '.$this->encryptdata['P'];
- if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
- $out .= ' /EncryptMetadata false';
- } else {
- $out .= ' /EncryptMetadata true';
- }
- }
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- protected function _RC4($key, $text) {
- if (function_exists('mcrypt_decrypt') AND ($out = @mcrypt_decrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
-
- return $out;
- }
- if ($this->last_enc_key != $key) {
- $k = str_repeat($key, ((256 / strlen($key)) + 1));
- $rc4 = range(0, 255);
- $j = 0;
- for ($i = 0; $i < 256; ++$i) {
- $t = $rc4[$i];
- $j = ($j + $t + ord($k[$i])) % 256;
- $rc4[$i] = $rc4[$j];
- $rc4[$j] = $t;
- }
- $this->last_enc_key = $key;
- $this->last_enc_key_c = $rc4;
- } else {
- $rc4 = $this->last_enc_key_c;
- }
- $len = strlen($text);
- $a = 0;
- $b = 0;
- $out = '';
- for ($i = 0; $i < $len; ++$i) {
- $a = ($a + 1) % 256;
- $t = $rc4[$a];
- $b = ($b + $t) % 256;
- $rc4[$a] = $rc4[$b];
- $rc4[$b] = $t;
- $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
- $out .= chr(ord($text[$i]) ^ $k);
- }
- return $out;
- }
-
- protected function _AES($key, $text) {
-
- $padding = 16 - (strlen($text) % 16);
- $text .= str_repeat(chr($padding), $padding);
- $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
- $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
- $text = $iv.$text;
- return $text;
- }
-
- protected function _md5_16($str) {
- return pack('H*', md5($str));
- }
-
- protected function _Uvalue() {
- if ($this->encryptdata['mode'] == 0) {
- return $this->_RC4($this->encryptdata['key'], $this->enc_padding);
- } elseif ($this->encryptdata['mode'] < 3) {
- $tmp = $this->_md5_16($this->enc_padding.$this->encryptdata['fileid']);
- $enc = $this->_RC4($this->encryptdata['key'], $tmp);
- $len = strlen($tmp);
- for ($i = 1; $i <= 19; ++$i) {
- $ek = '';
- for ($j = 0; $j < $len; ++$j) {
- $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
- }
- $enc = $this->_RC4($ek, $enc);
- }
- $enc .= str_repeat("\x00", 16);
- return substr($enc, 0, 32);
- } elseif ($this->encryptdata['mode'] == 3) {
- $seed = $this->_md5_16($this->getRandomSeed());
-
- $this->encryptdata['UVS'] = substr($seed, 0, 8);
-
- $this->encryptdata['UKS'] = substr($seed, 8, 16);
- return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
- }
- }
-
- protected function _UEvalue() {
- $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
- $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
- return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
- }
-
- protected function _Ovalue() {
- if ($this->encryptdata['mode'] < 3) {
- $tmp = $this->_md5_16($this->encryptdata['owner_password']);
- if ($this->encryptdata['mode'] > 0) {
- for ($i = 0; $i < 50; ++$i) {
- $tmp = $this->_md5_16($tmp);
- }
- }
- $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
- $enc = $this->_RC4($owner_key, $this->encryptdata['user_password']);
- if ($this->encryptdata['mode'] > 0) {
- $len = strlen($owner_key);
- for ($i = 1; $i <= 19; ++$i) {
- $ek = '';
- for ($j = 0; $j < $len; ++$j) {
- $ek .= chr(ord($owner_key[$j]) ^ $i);
- }
- $enc = $this->_RC4($ek, $enc);
- }
- }
- return $enc;
- } elseif ($this->encryptdata['mode'] == 3) {
- $seed = $this->_md5_16($this->getRandomSeed());
-
- $this->encryptdata['OVS'] = substr($seed, 0, 8);
-
- $this->encryptdata['OKS'] = substr($seed, 8, 16);
- return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
- }
- }
-
- protected function _OEvalue() {
- $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
- $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
- return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
- }
-
- protected function _fixAES256Password($password) {
- $psw = '';
- $psw_array = $this->utf8Bidi($this->UTF8StringToArray($password), $password, $this->rtl);
- foreach ($psw_array as $c) {
- $psw .= $this->unichr($c);
- }
- return substr($psw, 0, 127);
- }
-
- protected function _generateencryptionkey() {
- $keybytelen = ($this->encryptdata['Length'] / 8);
- if (!$this->encryptdata['pubkey']) {
- if ($this->encryptdata['mode'] == 3) {
-
- $this->encryptdata['key'] = substr(hash('sha256', $this->getRandomSeed(), true), 0, $keybytelen);
-
- $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
- $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
-
- $this->encryptdata['U'] = $this->_Uvalue();
-
- $this->encryptdata['UE'] = $this->_UEvalue();
-
- $this->encryptdata['O'] = $this->_Ovalue();
-
- $this->encryptdata['OE'] = $this->_OEvalue();
-
- $this->encryptdata['P'] = $this->encryptdata['protection'];
-
- $perms = $this->getEncPermissionsString($this->encryptdata['protection']);
- $perms .= chr(255).chr(255).chr(255).chr(255);
- if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
- $perms .= 'F';
- } else {
- $perms .= 'T';
- }
- $perms .= 'adb';
- $perms .= 'nick';
- $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
- $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv);
- } else {
-
- $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].$this->enc_padding, 0, 32);
- $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].$this->enc_padding, 0, 32);
-
- $this->encryptdata['O'] = $this->_Ovalue();
-
- $permissions = $this->getEncPermissionsString($this->encryptdata['protection']);
-
- $tmp = $this->_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
- if ($this->encryptdata['mode'] > 0) {
- for ($i = 0; $i < 50; ++$i) {
- $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen));
- }
- }
- $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
-
- $this->encryptdata['U'] = $this->_Uvalue();
-
- $this->encryptdata['P'] = $this->encryptdata['protection'];
- }
- } else {
-
- $seed = sha1($this->getRandomSeed(), true);
- $recipient_bytes = '';
- foreach ($this->encryptdata['pubkeys'] as $pubkey) {
-
- if (isset($pubkey['p'])) {
- $pkprotection = $this->getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
- } else {
- $pkprotection = $this->encryptdata['protection'];
- }
-
- $pkpermissions = $this->getEncPermissionsString($pkprotection);
-
- $envelope = $seed.$pkpermissions;
-
- $tempkeyfile = tempnam(K_PATH_CACHE, 'tmpkey_');
- $f = fopen($tempkeyfile, 'wb');
- if (!$f) {
- $this->Error('Unable to create temporary key file: '.$tempkeyfile);
- }
- $envelope_length = strlen($envelope);
- fwrite($f, $envelope, $envelope_length);
- fclose($f);
- $tempencfile = tempnam(K_PATH_CACHE, 'tmpenc_');
- if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_DETACHED | PKCS7_BINARY)) {
- $this->Error('Unable to encrypt the file: '.$tempkeyfile);
- }
- unlink($tempkeyfile);
-
- $signature = file_get_contents($tempencfile, false, null, $envelope_length);
- unlink($tempencfile);
-
- $signature = substr($signature, strpos($signature, 'Content-Disposition'));
- $tmparr = explode("\n\n", $signature);
- $signature = trim($tmparr[1]);
- unset($tmparr);
-
- $signature = base64_decode($signature);
-
- $hexsignature = current(unpack('H*', $signature));
-
- $this->encryptdata['Recipients'][] = $hexsignature;
-
- $recipient_bytes .= $signature;
- }
-
- if ($this->encryptdata['mode'] == 3) {
- $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
- } else {
- $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
- }
- }
- }
-
- protected function getUserPermissionCode($permissions, $mode=0) {
- $options = array(
- 'owner' => 2,
- 'print' => 4,
- 'modify' => 8,
- 'copy' => 16,
- 'annot-forms' => 32,
- 'fill-forms' => 256,
- 'extract' => 512,
- 'assemble' => 1024,
- 'print-high' => 2048
- );
- $protection = 2147422012;
- foreach ($permissions as $permission) {
- if (!isset($options[$permission])) {
- $this->Error('Incorrect permission: '.$permission);
- }
- if (($mode > 0) OR ($options[$permission] <= 32)) {
-
- if ($options[$permission] == 2) {
-
- $protection += $options[$permission];
- } else {
- $protection -= $options[$permission];
- }
- }
- }
- return $protection;
- }
-
- public function SetProtection($permissions=array('print', 'modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-high'), $user_pass='', $owner_pass=null, $mode=0, $pubkeys=null) {
- if ($this->pdfa_mode) {
-
- return;
- }
- $this->encryptdata['protection'] = $this->getUserPermissionCode($permissions, $mode);
- if (($pubkeys !== null) AND (is_array($pubkeys))) {
-
- $this->encryptdata['pubkeys'] = $pubkeys;
- if ($mode == 0) {
-
- $mode = 1;
- }
- if (!function_exists('openssl_pkcs7_encrypt')) {
- $this->Error('Public-Key Security requires openssl library.');
- }
-
- $this->encryptdata['pubkey'] = true;
- $this->encryptdata['Filter'] = 'Adobe.PubSec';
- $this->encryptdata['StmF'] = 'DefaultCryptFilter';
- $this->encryptdata['StrF'] = 'DefaultCryptFilter';
- } else {
-
- $this->encryptdata['pubkey'] = false;
- $this->encryptdata['Filter'] = 'Standard';
- $this->encryptdata['StmF'] = 'StdCF';
- $this->encryptdata['StrF'] = 'StdCF';
- }
- if ($mode > 1) {
- if (!extension_loaded('mcrypt')) {
- $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).');
- }
- if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
- $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
- }
- if (($mode == 3) AND !function_exists('hash')) {
-
- $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
- }
- }
- if ($owner_pass === null) {
- $owner_pass = md5($this->getRandomSeed());
- }
- $this->encryptdata['user_password'] = $user_pass;
- $this->encryptdata['owner_password'] = $owner_pass;
- $this->encryptdata['mode'] = $mode;
- switch ($mode) {
- case 0: {
- $this->encryptdata['V'] = 1;
- $this->encryptdata['Length'] = 40;
- $this->encryptdata['CF']['CFM'] = 'V2';
- break;
- }
- case 1: {
- $this->encryptdata['V'] = 2;
- $this->encryptdata['Length'] = 128;
- $this->encryptdata['CF']['CFM'] = 'V2';
- if ($this->encryptdata['pubkey']) {
- $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
- $this->encryptdata['Recipients'] = array();
- }
- break;
- }
- case 2: {
- $this->encryptdata['V'] = 4;
- $this->encryptdata['Length'] = 128;
- $this->encryptdata['CF']['CFM'] = 'AESV2';
- $this->encryptdata['CF']['Length'] = 128;
- if ($this->encryptdata['pubkey']) {
- $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
- $this->encryptdata['Recipients'] = array();
- }
- break;
- }
- case 3: {
- $this->encryptdata['V'] = 5;
- $this->encryptdata['Length'] = 256;
- $this->encryptdata['CF']['CFM'] = 'AESV3';
- $this->encryptdata['CF']['Length'] = 256;
- if ($this->encryptdata['pubkey']) {
- $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
- $this->encryptdata['Recipients'] = array();
- }
- break;
- }
- }
- $this->encrypted = true;
- $this->encryptdata['fileid'] = $this->convertHexStringToString($this->file_id);
- $this->_generateencryptionkey();
- }
-
- protected function convertHexStringToString($bs) {
- $string = '';
- $bslength = strlen($bs);
- if (($bslength % 2) != 0) {
-
- $bs .= '0';
- ++$bslength;
- }
- for ($i = 0; $i < $bslength; $i += 2) {
- $string .= chr(hexdec($bs[$i].$bs[($i + 1)]));
- }
- return $string;
- }
-
- protected function convertStringToHexString($s) {
- $bs = '';
- $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);
- foreach ($chars as $c) {
- $bs .= sprintf('%02s', dechex(ord($c)));
- }
- return $bs;
- }
-
- protected function getEncPermissionsString($protection) {
- $binprot = sprintf('%032b', $protection);
- $str = chr(bindec(substr($binprot, 24, 8)));
- $str .= chr(bindec(substr($binprot, 16, 8)));
- $str .= chr(bindec(substr($binprot, 8, 8)));
- $str .= chr(bindec(substr($binprot, 0, 8)));
- return $str;
- }
-
-
-
- public function StartTransform() {
- $this->_out('q');
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
- } else {
- $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
- }
- ++$this->transfmatrix_key;
- $this->transfmatrix[$this->transfmatrix_key] = array();
- }
-
- public function StopTransform() {
- $this->_out('Q');
- if (isset($this->transfmatrix[$this->transfmatrix_key])) {
- array_pop($this->transfmatrix[$this->transfmatrix_key]);
- --$this->transfmatrix_key;
- }
- if ($this->inxobj) {
-
- array_pop($this->xobjects[$this->xobjid]['transfmrk']);
- } else {
- array_pop($this->transfmrk[$this->page]);
- }
- }
-
- public function ScaleX($s_x, $x='', $y='') {
- $this->Scale($s_x, 100, $x, $y);
- }
-
- public function ScaleY($s_y, $x='', $y='') {
- $this->Scale(100, $s_y, $x, $y);
- }
-
- public function ScaleXY($s, $x='', $y='') {
- $this->Scale($s, $s, $x, $y);
- }
-
- public function Scale($s_x, $s_y, $x='', $y='') {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
- if (($s_x == 0) OR ($s_y == 0)) {
- $this->Error('Please do not use values equal to zero for scaling');
- }
- $y = ($this->h - $y) * $this->k;
- $x *= $this->k;
-
- $s_x /= 100;
- $s_y /= 100;
- $tm = array();
- $tm[0] = $s_x;
- $tm[1] = 0;
- $tm[2] = 0;
- $tm[3] = $s_y;
- $tm[4] = $x * (1 - $s_x);
- $tm[5] = $y * (1 - $s_y);
-
- $this->Transform($tm);
- }
-
- public function MirrorH($x='') {
- $this->Scale(-100, 100, $x);
- }
-
- public function MirrorV($y='') {
- $this->Scale(100, -100, '', $y);
- }
-
- public function MirrorP($x='',$y='') {
- $this->Scale(-100, -100, $x, $y);
- }
-
- public function MirrorL($angle=0, $x='',$y='') {
- $this->Scale(-100, 100, $x, $y);
- $this->Rotate(-2*($angle-90), $x, $y);
- }
-
- public function TranslateX($t_x) {
- $this->Translate($t_x, 0);
- }
-
- public function TranslateY($t_y) {
- $this->Translate(0, $t_y);
- }
-
- public function Translate($t_x, $t_y) {
-
- $tm = array();
- $tm[0] = 1;
- $tm[1] = 0;
- $tm[2] = 0;
- $tm[3] = 1;
- $tm[4] = $t_x * $this->k;
- $tm[5] = -$t_y * $this->k;
-
- $this->Transform($tm);
- }
-
- public function Rotate($angle, $x='', $y='') {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
- $y = ($this->h - $y) * $this->k;
- $x *= $this->k;
-
- $tm = array();
- $tm[0] = cos(deg2rad($angle));
- $tm[1] = sin(deg2rad($angle));
- $tm[2] = -$tm[1];
- $tm[3] = $tm[0];
- $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
- $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
-
- $this->Transform($tm);
- }
-
- public function SkewX($angle_x, $x='', $y='') {
- $this->Skew($angle_x, 0, $x, $y);
- }
-
- public function SkewY($angle_y, $x='', $y='') {
- $this->Skew(0, $angle_y, $x, $y);
- }
-
- public function Skew($angle_x, $angle_y, $x='', $y='') {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
- if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
- $this->Error('Please use values between -90 and +90 degrees for Skewing.');
- }
- $x *= $this->k;
- $y = ($this->h - $y) * $this->k;
-
- $tm = array();
- $tm[0] = 1;
- $tm[1] = tan(deg2rad($angle_y));
- $tm[2] = tan(deg2rad($angle_x));
- $tm[3] = 1;
- $tm[4] = -$tm[2] * $y;
- $tm[5] = -$tm[1] * $x;
-
- $this->Transform($tm);
- }
-
- protected function Transform($tm) {
- $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
-
- $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
-
- if ($this->inxobj) {
-
- if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
- $key = key($this->xobjects[$this->xobjid]['transfmrk']);
- $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
- }
- } elseif (end($this->transfmrk[$this->page]) !== false) {
- $key = key($this->transfmrk[$this->page]);
- $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
- }
- }
-
-
-
-
- public function SetLineWidth($width) {
-
- $this->LineWidth = $width;
- $this->linestyleWidth = sprintf('%.2F w', ($width * $this->k));
- if ($this->page > 0) {
- $this->_out($this->linestyleWidth);
- }
- }
-
- public function GetLineWidth() {
- return $this->LineWidth;
- }
-
- public function SetLineStyle($style, $ret=false) {
- $s = '';
- if (!is_array($style)) {
- return;
- }
- if (isset($style['width'])) {
- $this->LineWidth = $style['width'];
- $this->linestyleWidth = sprintf('%.2F w', ($style['width'] * $this->k));
- $s .= $this->linestyleWidth.' ';
- }
- if (isset($style['cap'])) {
- $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
- if (isset($ca[$style['cap']])) {
- $this->linestyleCap = $ca[$style['cap']].' J';
- $s .= $this->linestyleCap.' ';
- }
- }
- if (isset($style['join'])) {
- $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
- if (isset($ja[$style['join']])) {
- $this->linestyleJoin = $ja[$style['join']].' j';
- $s .= $this->linestyleJoin.' ';
- }
- }
- if (isset($style['dash'])) {
- $dash_string = '';
- if ($style['dash']) {
- if (preg_match('/^.+,/', $style['dash']) > 0) {
- $tab = explode(',', $style['dash']);
- } else {
- $tab = array($style['dash']);
- }
- $dash_string = '';
- foreach ($tab as $i => $v) {
- if ($i) {
- $dash_string .= ' ';
- }
- $dash_string .= sprintf('%.2F', $v);
- }
- }
- if (!isset($style['phase']) OR !$style['dash']) {
- $style['phase'] = 0;
- }
- $this->linestyleDash = sprintf('[%s] %.2F d', $dash_string, $style['phase']);
- $s .= $this->linestyleDash.' ';
- }
- if (isset($style['color'])) {
- $s .= $this->SetDrawColorArray($style['color'], true).' ';
- }
- if (!$ret) {
- $this->_out($s);
- }
- return $s;
- }
-
- protected function _outPoint($x, $y) {
- $this->_out(sprintf('%.2F %.2F m', $x * $this->k, ($this->h - $y) * $this->k));
- }
-
- protected function _outLine($x, $y) {
- $this->_out(sprintf('%.2F %.2F l', $x * $this->k, ($this->h - $y) * $this->k));
- }
-
- protected function _outRect($x, $y, $w, $h, $op) {
- $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op));
- }
-
- protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
- $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
- }
-
- protected function _outCurveV($x2, $y2, $x3, $y3) {
- $this->_out(sprintf('%.2F %.2F %.2F %.2F v', $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
- }
-
- protected function _outCurveY($x1, $y1, $x3, $y3) {
- $this->_out(sprintf('%.2F %.2F %.2F %.2F y', $x1 * $this->k, ($this->h - $y1) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
- }
-
- public function Line($x1, $y1, $x2, $y2, $style=array()) {
- if (is_array($style)) {
- $this->SetLineStyle($style);
- }
- $this->_outPoint($x1, $y1);
- $this->_outLine($x2, $y2);
- $this->_out('S');
- }
-
- public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
- if (!(false === strpos($style, 'F')) AND !empty($fill_color)) {
- $this->SetFillColorArray($fill_color);
- }
- $op = $this->getPathPaintOperator($style);
- if ((!$border_style) OR (isset($border_style['all']))) {
- if (isset($border_style['all']) AND $border_style['all']) {
- $this->SetLineStyle($border_style['all']);
- $border_style = array();
- }
- }
- $this->_outRect($x, $y, $w, $h, $op);
- if ($border_style) {
- $border_style2 = array();
- foreach ($border_style as $line => $value) {
- $length = strlen($line);
- for ($i = 0; $i < $length; ++$i) {
- $border_style2[$line[$i]] = $value;
- }
- }
- $border_style = $border_style2;
- if (isset($border_style['L']) AND $border_style['L']) {
- $this->Line($x, $y, $x, $y + $h, $border_style['L']);
- }
- if (isset($border_style['T']) AND $border_style['T']) {
- $this->Line($x, $y, $x + $w, $y, $border_style['T']);
- }
- if (isset($border_style['R']) AND $border_style['R']) {
- $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
- }
- if (isset($border_style['B']) AND $border_style['B']) {
- $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
- }
- }
- }
-
- public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
- if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
- $this->SetFillColorArray($fill_color);
- }
- $op = $this->getPathPaintOperator($style);
- if ($line_style) {
- $this->SetLineStyle($line_style);
- }
- $this->_outPoint($x0, $y0);
- $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
- $this->_out($op);
- }
-
- public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
- if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
- $this->SetFillColorArray($fill_color);
- }
- $op = $this->getPathPaintOperator($style);
- if ($op == 'f') {
- $line_style = array();
- }
- if ($line_style) {
- $this->SetLineStyle($line_style);
- }
- $this->_outPoint($x0, $y0);
- foreach ($segments as $segment) {
- list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
- $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
- }
- $this->_out($op);
- }
-
- public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
- if ($this->empty_string($ry) OR ($ry == 0)) {
- $ry = $rx;
- }
- if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
- $this->SetFillColorArray($fill_color);
- }
- $op = $this->getPathPaintOperator($style);
- if ($op == 'f') {
- $line_style = array();
- }
- if ($line_style) {
- $this->SetLineStyle($line_style);
- }
- $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
- $this->_out($op);
- }
-
- protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
- $k = $this->k;
- if ($nc < 2) {
- $nc = 2;
- }
- $xmin = 2147483647;
- $ymin = 2147483647;
- $xmax = 0;
- $ymax = 0;
- if ($pie) {
-
- $this->_outPoint($xc, $yc);
- }
- $xang = deg2rad((float) $xang);
- $angs = deg2rad((float) $angs);
- $angf = deg2rad((float) $angf);
- if ($svg) {
- $as = $angs;
- $af = $angf;
- } else {
- $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
- $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
- }
- if ($as < 0) {
- $as += (2 * M_PI);
- }
- if ($af < 0) {
- $af += (2 * M_PI);
- }
- if ($ccw AND ($as > $af)) {
-
- $as -= (2 * M_PI);
- } elseif (!$ccw AND ($as < $af)) {
-
- $af -= (2 * M_PI);
- }
- $total_angle = ($af - $as);
- if ($nc < 2) {
- $nc = 2;
- }
-
- $nc *= (2 * abs($total_angle) / M_PI);
- $nc = round($nc) + 1;
-
- $arcang = ($total_angle / $nc);
-
- $x0 = $xc;
- $y0 = ($this->h - $yc);
-
- $ang = $as;
- $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
- $cos_xang = cos($xang);
- $sin_xang = sin($xang);
- $cos_ang = cos($ang);
- $sin_ang = sin($ang);
-
- $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
- $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
-
- $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
- $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
- if ($pie) {
-
- $this->_outLine($px1, $this->h - $py1);
- } elseif ($startpoint) {
-
- $this->_outPoint($px1, $this->h - $py1);
- }
-
- for ($i = 1; $i <= $nc; ++$i) {
-
- $ang = $as + ($i * $arcang);
- if ($i == $nc) {
- $ang = $af;
- }
- $cos_ang = cos($ang);
- $sin_ang = sin($ang);
-
- $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
- $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
-
- $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
- $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
-
- $cx1 = ($px1 + $qx1);
- $cy1 = ($this->h - ($py1 + $qy1));
- $cx2 = ($px2 - $qx2);
- $cy2 = ($this->h - ($py2 - $qy2));
- $cx3 = $px2;
- $cy3 = ($this->h - $py2);
- $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
-
- $xmin = min($xmin, $cx1, $cx2, $cx3);
- $ymin = min($ymin, $cy1, $cy2, $cy3);
- $xmax = max($xmax, $cx1, $cx2, $cx3);
- $ymax = max($ymax, $cy1, $cy2, $cy3);
-
- $px1 = $px2;
- $py1 = $py2;
- $qx1 = $qx2;
- $qy1 = $qy2;
- }
- if ($pie) {
- $this->_outLine($xc, $yc);
-
- $xmin = min($xmin, $xc);
- $ymin = min($ymin, $yc);
- $xmax = max($xmax, $xc);
- $ymax = max($ymax, $yc);
- }
- return array($xmin, $ymin, $xmax, $ymax);
- }
-
- public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
- $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
- }
-
- public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
- $this->Polygon($p, $style, $line_style, $fill_color, false);
- }
-
- public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
- $nc = count($p);
- $np = $nc / 2;
- if ($closed) {
-
- for ($i = 0; $i < 4; ++$i) {
- $p[$nc + $i] = $p[$i];
- }
-
- if (isset($line_style[0])) {
- $line_style[$np] = $line_style[0];
- }
- $nc += 4;
- }
- if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
- $this->SetFillColorArray($fill_color);
- }
- $op = $this->getPathPaintOperator($style);
- if ($op == 'f') {
- $line_style = array();
- }
- $draw = true;
- if ($line_style) {
- if (isset($line_style['all'])) {
- $this->SetLineStyle($line_style['all']);
- } else {
- $draw = false;
- if ($op == 'B') {
-
- $op = 'f';
- $this->_outPoint($p[0], $p[1]);
- for ($i = 2; $i < $nc; $i = $i + 2) {
- $this->_outLine($p[$i], $p[$i + 1]);
- }
- $this->_out($op);
- }
-
- $this->_outPoint($p[0], $p[1]);
- for ($i = 2; $i < $nc; $i = $i + 2) {
- $line_num = ($i / 2) - 1;
- if (isset($line_style[$line_num])) {
- if ($line_style[$line_num] != 0) {
- if (is_array($line_style[$line_num])) {
- $this->_out('S');
- $this->SetLineStyle($line_style[$line_num]);
- $this->_outPoint($p[$i - 2], $p[$i - 1]);
- $this->_outLine($p[$i], $p[$i + 1]);
- $this->_out('S');
- $this->_outPoint($p[$i], $p[$i + 1]);
- } else {
- $this->_outLine($p[$i], $p[$i + 1]);
- }
- }
- } else {
- $this->_outLine($p[$i], $p[$i + 1]);
- }
- }
- $this->_out($op);
- }
- }
- if ($draw) {
- $this->_outPoint($p[0], $p[1]);
- for ($i = 2; $i < $nc; $i = $i + 2) {
- $this->_outLine($p[$i], $p[$i + 1]);
- }
- $this->_out($op);
- }
- }
-
- public function RegularPolygon($x0, $y0, $r, $ns, $angle=0, $draw_circle=false, $style='', $line_style=array(), $fill_color=array(), $circle_style='', $circle_outLine_style=array(), $circle_fill_color=array()) {
- if (3 > $ns) {
- $ns = 3;
- }
- if ($draw_circle) {
- $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
- }
- $p = array();
- for ($i = 0; $i < $ns; ++$i) {
- $a = $angle + ($i * 360 / $ns);
- $a_rad = deg2rad((float) $a);
- $p[] = $x0 + ($r * sin($a_rad));
- $p[] = $y0 + ($r * cos($a_rad));
- }
- $this->Polygon($p, $style, $line_style, $fill_color);
- }
-
- public function StarPolygon($x0, $y0, $r, $nv, $ng, $angle=0, $draw_circle=false, $style='', $line_style=array(), $fill_color=array(), $circle_style='', $circle_outLine_style=array(), $circle_fill_color=array()) {
- if ($nv < 2) {
- $nv = 2;
- }
- if ($draw_circle) {
- $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
- }
- $p2 = array();
- $visited = array();
- for ($i = 0; $i < $nv; ++$i) {
- $a = $angle + ($i * 360 / $nv);
- $a_rad = deg2rad((float) $a);
- $p2[] = $x0 + ($r * sin($a_rad));
- $p2[] = $y0 + ($r * cos($a_rad));
- $visited[] = false;
- }
- $p = array();
- $i = 0;
- do {
- $p[] = $p2[$i * 2];
- $p[] = $p2[($i * 2) + 1];
- $visited[$i] = true;
- $i += $ng;
- $i %= $nv;
- } while (!$visited[$i]);
- $this->Polygon($p, $style, $line_style, $fill_color);
- }
-
- public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
- $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
- }
-
- public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
- if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
-
- $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
- return;
- }
-
- if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
- $this->SetFillColorArray($fill_color);
- }
- $op = $this->getPathPaintOperator($style);
- if ($op == 'f') {
- $border_style = array();
- }
- if ($border_style) {
- $this->SetLineStyle($border_style);
- }
- $MyArc = 4 / 3 * (sqrt(2) - 1);
- $this->_outPoint($x + $rx, $y);
- $xc = $x + $w - $rx;
- $yc = $y + $ry;
- $this->_outLine($xc, $y);
- if ($round_corner[0]) {
- $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
- } else {
- $this->_outLine($x + $w, $y);
- }
- $xc = $x + $w - $rx;
- $yc = $y + $h - $ry;
- $this->_outLine($x + $w, $yc);
- if ($round_corner[1]) {
- $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
- } else {
- $this->_outLine($x + $w, $y + $h);
- }
- $xc = $x + $rx;
- $yc = $y + $h - $ry;
- $this->_outLine($xc, $y + $h);
- if ($round_corner[2]) {
- $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
- } else {
- $this->_outLine($x, $y + $h);
- }
- $xc = $x + $rx;
- $yc = $y + $ry;
- $this->_outLine($x, $yc);
- if ($round_corner[3]) {
- $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
- } else {
- $this->_outLine($x, $y);
- $this->_outLine($x + $rx, $y);
- }
- $this->_out($op);
- }
-
- public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
-
-
- $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
- if ($dir_angle < 0) {
- $dir_angle += (2 * M_PI);
- }
- $arm_angle = deg2rad($arm_angle);
- $sx1 = $x1;
- $sy1 = $y1;
- if ($head_style > 0) {
-
- $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
- $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
- }
-
- $this->Line($x0, $y0, $sx1, $sy1);
-
- $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
- $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
-
- $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
- $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
- $mode = 'D';
- $style = array();
- switch ($head_style) {
- case 0: {
-
- $mode = 'D';
- $style = array(1, 1, 0);
- break;
- }
- case 1: {
-
- $mode = 'D';
- break;
- }
- case 2: {
-
- $mode = 'DF';
- break;
- }
- case 3: {
-
- $mode = 'F';
- break;
- }
- }
- $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
- }
-
-
-
- protected function utf8StrRev($str, $setbom=false, $forcertl=false) {
- return $this->utf8StrArrRev($this->UTF8StringToArray($str), $str, $setbom, $forcertl);
- }
-
- protected function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false) {
- return $this->arrUTF8ToUTF16BE($this->utf8Bidi($arr, $str, $forcertl), $setbom);
- }
-
- protected function utf8Bidi($ta, $str='', $forcertl=false) {
-
- $pel = 0;
-
- $maxlevel = 0;
- if ($this->empty_string($str)) {
-
- $str = $this->UTF8ArrSubString($ta);
- }
-
- if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $str)) {
- $arabic = true;
- } else {
- $arabic = false;
- }
-
- if (!($forcertl OR $arabic OR preg_match($this->unicode->uni_RE_PATTERN_RTL, $str))) {
- return $ta;
- }
-
- $numchars = count($ta);
- if ($forcertl == 'R') {
- $pel = 1;
- } elseif ($forcertl == 'L') {
- $pel = 0;
- } else {
-
-
- for ($i=0; $i < $numchars; ++$i) {
- $type = $this->unicode->uni_type[$ta[$i]];
- if ($type == 'L') {
- $pel = 0;
- break;
- } elseif (($type == 'AL') OR ($type == 'R')) {
- $pel = 1;
- break;
- }
- }
- }
-
- $cel = $pel;
-
- $dos = 'N';
- $remember = array();
-
- $sor = $pel % 2 ? 'R' : 'L';
- $eor = $sor;
-
- $chardata = Array();
-
-
- for ($i=0; $i < $numchars; ++$i) {
- if ($ta[$i] == $this->unicode->uni_RLE) {
-
-
-
- $next_level = $cel + ($cel % 2) + 1;
- if ($next_level < 62) {
- $remember[] = array('num' => $this->unicode->uni_RLE, 'cel' => $cel, 'dos' => $dos);
- $cel = $next_level;
- $dos = 'N';
- $sor = $eor;
- $eor = $cel % 2 ? 'R' : 'L';
- }
- } elseif ($ta[$i] == $this->unicode->uni_LRE) {
-
-
-
- $next_level = $cel + 2 - ($cel % 2);
- if ( $next_level < 62 ) {
- $remember[] = array('num' => $this->unicode->uni_LRE, 'cel' => $cel, 'dos' => $dos);
- $cel = $next_level;
- $dos = 'N';
- $sor = $eor;
- $eor = $cel % 2 ? 'R' : 'L';
- }
- } elseif ($ta[$i] == $this->unicode->uni_RLO) {
-
-
-
- $next_level = $cel + ($cel % 2) + 1;
- if ($next_level < 62) {
- $remember[] = array('num' => $this->unicode->uni_RLO, 'cel' => $cel, 'dos' => $dos);
- $cel = $next_level;
- $dos = 'R';
- $sor = $eor;
- $eor = $cel % 2 ? 'R' : 'L';
- }
- } elseif ($ta[$i] == $this->unicode->uni_LRO) {
-
-
-
- $next_level = $cel + 2 - ($cel % 2);
- if ( $next_level < 62 ) {
- $remember[] = array('num' => $this->unicode->uni_LRO, 'cel' => $cel, 'dos' => $dos);
- $cel = $next_level;
- $dos = 'L';
- $sor = $eor;
- $eor = $cel % 2 ? 'R' : 'L';
- }
- } elseif ($ta[$i] == $this->unicode->uni_PDF) {
-
- if (count($remember)) {
- $last = count($remember ) - 1;
- if (($remember[$last]['num'] == $this->unicode->uni_RLE) OR
- ($remember[$last]['num'] == $this->unicode->uni_LRE) OR
- ($remember[$last]['num'] == $this->unicode->uni_RLO) OR
- ($remember[$last]['num'] == $this->unicode->uni_LRO)) {
- $match = array_pop($remember);
- $cel = $match['cel'];
- $dos = $match['dos'];
- $sor = $eor;
- $eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
- }
- }
- } elseif (($ta[$i] != $this->unicode->uni_RLE) AND
- ($ta[$i] != $this->unicode->uni_LRE) AND
- ($ta[$i] != $this->unicode->uni_RLO) AND
- ($ta[$i] != $this->unicode->uni_LRO) AND
- ($ta[$i] != $this->unicode->uni_PDF)) {
-
-
-
- if ($dos != 'N') {
- $chardir = $dos;
- } else {
- if (isset($this->unicode->uni_type[$ta[$i]])) {
- $chardir = $this->unicode->uni_type[$ta[$i]];
- } else {
- $chardir = 'L';
- }
- }
-
- $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir, 'sor' => $sor, 'eor' => $eor);
- }
- }
-
-
-
-
-
-
- $numchars = count($chardata);
-
- $prevlevel = -1;
- $levcount = 0;
- for ($i=0; $i < $numchars; ++$i) {
- if ($chardata[$i]['type'] == 'NSM') {
- if ($levcount) {
- $chardata[$i]['type'] = $chardata[$i]['sor'];
- } elseif ($i > 0) {
- $chardata[$i]['type'] = $chardata[($i-1)]['type'];
- }
- }
- if ($chardata[$i]['level'] != $prevlevel) {
- $levcount = 0;
- } else {
- ++$levcount;
- }
- $prevlevel = $chardata[$i]['level'];
- }
-
- $prevlevel = -1;
- $levcount = 0;
- for ($i=0; $i < $numchars; ++$i) {
- if ($chardata[$i]['char'] == 'EN') {
- for ($j=$levcount; $j >= 0; $j--) {
- if ($chardata[$j]['type'] == 'AL') {
- $chardata[$i]['type'] = 'AN';
- } elseif (($chardata[$j]['type'] == 'L') OR ($chardata[$j]['type'] == 'R')) {
- break;
- }
- }
- }
- if ($chardata[$i]['level'] != $prevlevel) {
- $levcount = 0;
- } else {
- ++$levcount;
- }
- $prevlevel = $chardata[$i]['level'];
- }
-
- for ($i=0; $i < $numchars; ++$i) {
- if ($chardata[$i]['type'] == 'AL') {
- $chardata[$i]['type'] = 'R';
- }
- }
-
- $prevlevel = -1;
- $levcount = 0;
- for ($i=0; $i < $numchars; ++$i) {
- if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
- if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
- $chardata[$i]['type'] = 'EN';
- } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
- $chardata[$i]['type'] = 'EN';
- } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'AN') AND ($chardata[($i+1)]['type'] == 'AN')) {
- $chardata[$i]['type'] = 'AN';
- }
- }
- if ($chardata[$i]['level'] != $prevlevel) {
- $levcount = 0;
- } else {
- ++$levcount;
- }
- $prevlevel = $chardata[$i]['level'];
- }
-
- $prevlevel = -1;
- $levcount = 0;
- for ($i=0; $i < $numchars; ++$i) {
- if ($chardata[$i]['type'] == 'ET') {
- if (($levcount > 0) AND ($chardata[($i-1)]['type'] == 'EN')) {
- $chardata[$i]['type'] = 'EN';
- } else {
- $j = $i+1;
- while (($j < $numchars) AND ($chardata[$j]['level'] == $prevlevel)) {
- if ($chardata[$j]['type'] == 'EN') {
- $chardata[$i]['type'] = 'EN';
- break;
- } elseif ($chardata[$j]['type'] != 'ET') {
- break;
- }
- ++$j;
- }
- }
- }
- if ($chardata[$i]['level'] != $prevlevel) {
- $levcount = 0;
- } else {
- ++$levcount;
- }
- $prevlevel = $chardata[$i]['level'];
- }
-
- $prevlevel = -1;
- $levcount = 0;
- for ($i=0; $i < $numchars; ++$i) {
- if (($chardata[$i]['type'] == 'ET') OR ($chardata[$i]['type'] == 'ES') OR ($chardata[$i]['type'] == 'CS')) {
- $chardata[$i]['type'] = 'ON';
- }
- if ($chardata[$i]['level'] != $prevlevel) {
- $levcount = 0;
- } else {
- ++$levcount;
- }
- $prevlevel = $chardata[$i]['level'];
- }
-
- $prevlevel = -1;
- $levcount = 0;
- for ($i=0; $i < $numchars; ++$i) {
- if ($chardata[$i]['char'] == 'EN') {
- for ($j=$levcount; $j >= 0; $j--) {
- if ($chardata[$j]['type'] == 'L') {
- $chardata[$i]['type'] = 'L';
- } elseif ($chardata[$j]['type'] == 'R') {
- break;
- }
- }
- }
- if ($chardata[$i]['level'] != $prevlevel) {
- $levcount = 0;
- } else {
- ++$levcount;
- }
- $prevlevel = $chardata[$i]['level'];
- }
-
- $prevlevel = -1;
- $levcount = 0;
- for ($i=0; $i < $numchars; ++$i) {
- if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
- if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
- $chardata[$i]['type'] = 'L';
- } elseif (($chardata[$i]['type'] == 'N') AND
- (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
- (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
- $chardata[$i]['type'] = 'R';
- } elseif ($chardata[$i]['type'] == 'N') {
-
- $chardata[$i]['type'] = $chardata[$i]['sor'];
- }
- } elseif (($levcount == 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
-
- if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
- $chardata[$i]['type'] = 'L';
- } elseif (($chardata[$i]['type'] == 'N') AND
- (($chardata[$i]['sor'] == 'R') OR ($chardata[$i]['sor'] == 'EN') OR ($chardata[$i]['sor'] == 'AN')) AND
- (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
- $chardata[$i]['type'] = 'R';
- } elseif ($chardata[$i]['type'] == 'N') {
-
- $chardata[$i]['type'] = $chardata[$i]['sor'];
- }
- } elseif (($levcount > 0) AND ((($i+1) == $numchars) OR (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] != $prevlevel))) {
-
- if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
- $chardata[$i]['type'] = 'L';
- } elseif (($chardata[$i]['type'] == 'N') AND
- (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
- (($chardata[$i]['eor'] == 'R') OR ($chardata[$i]['eor'] == 'EN') OR ($chardata[$i]['eor'] == 'AN'))) {
- $chardata[$i]['type'] = 'R';
- } elseif ($chardata[$i]['type'] == 'N') {
-
- $chardata[$i]['type'] = $chardata[$i]['sor'];
- }
- } elseif ($chardata[$i]['type'] == 'N') {
-
- $chardata[$i]['type'] = $chardata[$i]['sor'];
- }
- if ($chardata[$i]['level'] != $prevlevel) {
- $levcount = 0;
- } else {
- ++$levcount;
- }
- $prevlevel = $chardata[$i]['level'];
- }
-
-
- for ($i=0; $i < $numchars; ++$i) {
- $odd = $chardata[$i]['level'] % 2;
- if ($odd) {
- if (($chardata[$i]['type'] == 'L') OR ($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
- $chardata[$i]['level'] += 1;
- }
- } else {
- if ($chardata[$i]['type'] == 'R') {
- $chardata[$i]['level'] += 1;
- } elseif (($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
- $chardata[$i]['level'] += 2;
- }
- }
- $maxlevel = max($chardata[$i]['level'],$maxlevel);
- }
-
-
-
-
-
- for ($i=0; $i < $numchars; ++$i) {
- if (($chardata[$i]['type'] == 'B') OR ($chardata[$i]['type'] == 'S')) {
- $chardata[$i]['level'] = $pel;
- } elseif ($chardata[$i]['type'] == 'WS') {
- $j = $i+1;
- while ($j < $numchars) {
- if ((($chardata[$j]['type'] == 'B') OR ($chardata[$j]['type'] == 'S')) OR
- (($j == ($numchars-1)) AND ($chardata[$j]['type'] == 'WS'))) {
- $chardata[$i]['level'] = $pel;
- break;
- } elseif ($chardata[$j]['type'] != 'WS') {
- break;
- }
- ++$j;
- }
- }
- }
-
-
- if ($arabic) {
- $endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
- $alfletter = array(1570,1571,1573,1575);
- $chardata2 = $chardata;
- $laaletter = false;
- $charAL = array();
- $x = 0;
- for ($i=0; $i < $numchars; ++$i) {
- if (($this->unicode->uni_type[$chardata[$i]['char']] == 'AL') OR ($chardata[$i]['char'] == 32) OR ($chardata[$i]['char'] == 8204)) {
- $charAL[$x] = $chardata[$i];
- $charAL[$x]['i'] = $i;
- $chardata[$i]['x'] = $x;
- ++$x;
- }
- }
- $numAL = $x;
- for ($i=0; $i < $numchars; ++$i) {
- $thischar = $chardata[$i];
- if ($i > 0) {
- $prevchar = $chardata[($i-1)];
- } else {
- $prevchar = false;
- }
- if (($i+1) < $numchars) {
- $nextchar = $chardata[($i+1)];
- } else {
- $nextchar = false;
- }
- if ($this->unicode->uni_type[$thischar['char']] == 'AL') {
- $x = $thischar['x'];
- if ($x > 0) {
- $prevchar = $charAL[($x-1)];
- } else {
- $prevchar = false;
- }
- if (($x+1) < $numAL) {
- $nextchar = $charAL[($x+1)];
- } else {
- $nextchar = false;
- }
-
- if (($prevchar !== false) AND ($prevchar['char'] == 1604) AND (in_array($thischar['char'], $alfletter))) {
- $arabicarr = $this->unicode->uni_laa_array;
- $laaletter = true;
- if ($x > 1) {
- $prevchar = $charAL[($x-2)];
- } else {
- $prevchar = false;
- }
- } else {
- $arabicarr = $this->unicode->uni_arabicsubst;
- $laaletter = false;
- }
- if (($prevchar !== false) AND ($nextchar !== false) AND
- (($this->unicode->uni_type[$prevchar['char']] == 'AL') OR ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) AND
- (($this->unicode->uni_type[$nextchar['char']] == 'AL') OR ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) AND
- ($prevchar['type'] == $thischar['type']) AND
- ($nextchar['type'] == $thischar['type']) AND
- ($nextchar['char'] != 1567)) {
- if (in_array($prevchar['char'], $endedletter)) {
- if (isset($arabicarr[$thischar['char']][2])) {
-
- $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
- }
- } else {
- if (isset($arabicarr[$thischar['char']][3])) {
-
- $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
- }
- }
- } elseif (($nextchar !== false) AND
- (($this->unicode->uni_type[$nextchar['char']] == 'AL') OR ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) AND
- ($nextchar['type'] == $thischar['type']) AND
- ($nextchar['char'] != 1567)) {
- if (isset($arabicarr[$chardata[$i]['char']][2])) {
-
- $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
- }
- } elseif ((($prevchar !== false) AND
- (($this->unicode->uni_type[$prevchar['char']] == 'AL') OR ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) AND
- ($prevchar['type'] == $thischar['type'])) OR
- (($nextchar !== false) AND ($nextchar['char'] == 1567))) {
-
- if (($i > 1) AND ($thischar['char'] == 1607) AND
- ($chardata[$i-1]['char'] == 1604) AND
- ($chardata[$i-2]['char'] == 1604)) {
-
-
- $chardata2[$i-2]['char'] = false;
- $chardata2[$i-1]['char'] = false;
- $chardata2[$i]['char'] = 65010;
- } else {
- if (($prevchar !== false) AND in_array($prevchar['char'], $endedletter)) {
- if (isset($arabicarr[$thischar['char']][0])) {
-
- $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
- }
- } else {
- if (isset($arabicarr[$thischar['char']][1])) {
-
- $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
- }
- }
- }
- } elseif (isset($arabicarr[$thischar['char']][0])) {
-
- $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
- }
-
- if ($laaletter) {
-
- $chardata2[($charAL[($x-1)]['i'])]['char'] = false;
- }
- }
- }
-
- for ($i = 0; $i < ($numchars-1); ++$i) {
- if (($chardata2[$i]['char'] == 1617) AND (isset($this->unicode->uni_diacritics[($chardata2[$i+1]['char'])]))) {
-
- if (isset($this->CurrentFont['cw'][($this->unicode->uni_diacritics[($chardata2[$i+1]['char'])])])) {
- $chardata2[$i]['char'] = false;
- $chardata2[$i+1]['char'] = $this->unicode->uni_diacritics[($chardata2[$i+1]['char'])];
- }
- }
- }
-
- foreach ($chardata2 as $key => $value) {
- if ($value['char'] === false) {
- unset($chardata2[$key]);
- }
- }
- $chardata = array_values($chardata2);
- $numchars = count($chardata);
- unset($chardata2);
- unset($arabicarr);
- unset($laaletter);
- unset($charAL);
- }
-
- for ($j=$maxlevel; $j > 0; $j--) {
- $ordarray = Array();
- $revarr = Array();
- $onlevel = false;
- for ($i=0; $i < $numchars; ++$i) {
- if ($chardata[$i]['level'] >= $j) {
- $onlevel = true;
- if (isset($this->unicode->uni_mirror[$chardata[$i]['char']])) {
-
- $chardata[$i]['char'] = $this->unicode->uni_mirror[$chardata[$i]['char']];
- }
- $revarr[] = $chardata[$i];
- } else {
- if ($onlevel) {
- $revarr = array_reverse($revarr);
- $ordarray = array_merge($ordarray, $revarr);
- $revarr = Array();
- $onlevel = false;
- }
- $ordarray[] = $chardata[$i];
- }
- }
- if ($onlevel) {
- $revarr = array_reverse($revarr);
- $ordarray = array_merge($ordarray, $revarr);
- }
- $chardata = $ordarray;
- }
- $ordarray = array();
- for ($i=0; $i < $numchars; ++$i) {
- $ordarray[] = $chardata[$i]['char'];
-
- $this->CurrentFont['subsetchars'][$chardata[$i]['char']] = true;
- }
-
- $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
- return $ordarray;
- }
-
-
- protected function encodeNameObject($name) {
- $escname = '';
- $length = strlen($name);
- for ($i = 0; $i < $length; ++$i) {
- $chr = $name[$i];
- if (preg_match('/[0-9a-zA-Z]/', $chr) == 1) {
- $escname .= $chr;
- } else {
- $escname .= sprintf('#%02X', ord($chr));
- }
- }
- return $escname;
- }
-
- public function setDestination($name, $y=-1, $page='') {
-
- $name = $this->encodeNameObject($name);
- if ($this->empty_string($name)) {
- return false;
- }
- if ($y == -1) {
- $y = $this->GetY();
- }
- if (empty($page)) {
- $page = $this->PageNo();
- if (empty($page)) {
- return;
- }
- }
- $this->dests[$name] = array('y' => $y, 'p' => $page);
- return $name;
- }
-
- public function getDestination() {
- return $this->dests;
- }
-
- protected function _putdests() {
- if (empty($this->dests)) {
- return;
- }
- $this->n_dests = $this->_newobj();
- $out = ' <<';
- foreach($this->dests as $name => $o) {
- $out .= ' /'.$name.' '.sprintf('[%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($o['p'])], ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
- }
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0)) {
- $this->Bookmark($txt, $level, $y, $page, $style, $color);
- }
-
- public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0)) {
- if ($level < 0) {
- $level = 0;
- }
- if (isset($this->outlines[0])) {
- $lastoutline = end($this->outlines);
- $maxlevel = $lastoutline['l'] + 1;
- } else {
- $maxlevel = 0;
- }
- if ($level > $maxlevel) {
- $level = $maxlevel;
- }
- if ($y == -1) {
- $y = $this->GetY();
- }
- if (empty($page)) {
- $page = $this->PageNo();
- if (empty($page)) {
- return;
- }
- }
- $this->outlines[] = array('t' => $txt, 'l' => $level, 'y' => $y, 'p' => $page, 's' => strtoupper($style), 'c' => $color);
- }
-
- protected function sortBookmarks() {
-
- $outline_p = array();
- $outline_y = array();
- foreach ($this->outlines as $key => $row) {
- $outline_p[$key] = $row['p'];
- $outline_k[$key] = $key;
- }
-
- array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
- }
-
- protected function _putbookmarks() {
- $nb = count($this->outlines);
- if ($nb == 0) {
- return;
- }
-
- $this->sortBookmarks();
- $lru = array();
- $level = 0;
- foreach ($this->outlines as $i => $o) {
- if ($o['l'] > 0) {
- $parent = $lru[($o['l'] - 1)];
-
- $this->outlines[$i]['parent'] = $parent;
- $this->outlines[$parent]['last'] = $i;
- if ($o['l'] > $level) {
-
- $this->outlines[$parent]['first'] = $i;
- }
- } else {
- $this->outlines[$i]['parent'] = $nb;
- }
- if (($o['l'] <= $level) AND ($i > 0)) {
-
- $prev = $lru[$o['l']];
- $this->outlines[$prev]['next'] = $i;
- $this->outlines[$i]['prev'] = $prev;
- }
- $lru[$o['l']] = $i;
- $level = $o['l'];
- }
-
- $n = $this->n + 1;
- $nltags = '/<br[\s]?\/>|<\/(blockquote|dd|dl|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|ul|tcpdf|table|tr|td)>/si';
- foreach ($this->outlines as $i => $o) {
- $oid = $this->_newobj();
-
- $title = preg_replace($nltags, "\n", $o['t']);
- $title = preg_replace("/[\r]+/si", '', $title);
- $title = preg_replace("/[\n]+/si", "\n", $title);
- $title = strip_tags($title);
- $title = $this->stringTrim($title);
- $out = '<</Title '.$this->_textstring($title, $oid);
- $out .= ' /Parent '.($n + $o['parent']).' 0 R';
- if (isset($o['prev'])) {
- $out .= ' /Prev '.($n + $o['prev']).' 0 R';
- }
- if (isset($o['next'])) {
- $out .= ' /Next '.($n + $o['next']).' 0 R';
- }
- if (isset($o['first'])) {
- $out .= ' /First '.($n + $o['first']).' 0 R';
- }
- if (isset($o['last'])) {
- $out .= ' /Last '.($n + $o['last']).' 0 R';
- }
- if (isset($this->page_obj_id[($o['p'])])) {
- $out .= ' '.sprintf('/Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($o['p'])], ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
- }
-
- $style = 0;
- if (!empty($o['s'])) {
-
- if (strpos($o['s'], 'B') !== false) {
- $style |= 2;
- }
-
- if (strpos($o['s'], 'I') !== false) {
- $style |= 1;
- }
- }
- $out .= sprintf(' /F %d', $style);
-
- if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
- $color = array_values($o['c']);
- $out .= sprintf(' /C [%.3F %.3F %.3F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
- } else {
-
- $out .= ' /C [0.0 0.0 0.0]';
- }
- $out .= ' /Count 0';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- $this->OutlineRoot = $this->_newobj();
- $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
- }
-
-
- public function IncludeJS($script) {
- $this->javascript .= $script;
- }
-
- public function addJavascriptObject($script, $onload=false) {
- if ($this->pdfa_mode) {
-
- return false;
- }
- ++$this->n;
- $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
- return $this->n;
- }
-
- protected function _putjavascript() {
- if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
- return;
- }
- if (strpos($this->javascript, 'this.addField') > 0) {
- if (!$this->ur['enabled']) {
-
- }
-
-
- $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
- $jsb = "getField('tcpdfdocsaved').value='saved';";
- $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
- }
- $this->n_js = $this->_newobj();
- $out = ' << /Names [';
- if (!empty($this->javascript)) {
- $out .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
- }
- if (!empty($this->js_objects)) {
- foreach ($this->js_objects as $key => $val) {
- if ($val['onload']) {
- $out .= ' (JS'.$key.') '.$key.' 0 R';
- }
- }
- }
- $out .= ' ] >>';
- $out .= "\n".'endobj';
- $this->_out($out);
-
- if (!empty($this->javascript)) {
- $obj_id = $this->_newobj();
- $out = '<< /S /JavaScript';
- $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- if (!empty($this->js_objects)) {
- foreach ($this->js_objects as $key => $val) {
- $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
- $this->_out($out);
- }
- }
- }
-
- protected function _JScolor($color) {
- static $aColors = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
- if (substr($color,0,1) == '#') {
- return sprintf("['RGB',%.3F,%.3F,%.3F]", hexdec(substr($color,1,2))/255, hexdec(substr($color,3,2))/255, hexdec(substr($color,5,2))/255);
- }
- if (!in_array($color,$aColors)) {
- $this->Error('Invalid color: '.$color);
- }
- return 'color.'.$color;
- }
-
- protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
- if ($this->rtl) {
- $x = $x - $w;
- }
-
- $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
- $k = $this->k;
- $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%.2F,%.2F,%.2F,%.2F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n";
- $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
- while (list($key, $val) = each($prop)) {
- if (strcmp(substr($key, -5), 'Color') == 0) {
- $val = $this->_JScolor($val);
- } else {
- $val = "'".$val."'";
- }
- $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
- }
- if ($this->rtl) {
- $this->x -= $w;
- } else {
- $this->x += $w;
- }
- $this->javascript .= '}';
- }
-
-
- protected function getAnnotOptFromJSProp($prop) {
- if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
-
- return $prop['aopt'];
- }
- $opt = array();
-
- if (isset($prop['alignment'])) {
- switch ($prop['alignment']) {
- case 'left': {
- $opt['q'] = 0;
- break;
- }
- case 'center': {
- $opt['q'] = 1;
- break;
- }
- case 'right': {
- $opt['q'] = 2;
- break;
- }
- default: {
- $opt['q'] = ($this->rtl)?2:0;
- break;
- }
- }
- }
-
- if (isset($prop['lineWidth'])) {
- $linewidth = intval($prop['lineWidth']);
- } else {
- $linewidth = 1;
- }
-
- if (isset($prop['borderStyle'])) {
- switch ($prop['borderStyle']) {
- case 'border.d':
- case 'dashed': {
- $opt['border'] = array(0, 0, $linewidth, array(3, 2));
- $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
- break;
- }
- case 'border.b':
- case 'beveled': {
- $opt['border'] = array(0, 0, $linewidth);
- $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
- break;
- }
- case 'border.i':
- case 'inset': {
- $opt['border'] = array(0, 0, $linewidth);
- $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
- break;
- }
- case 'border.u':
- case 'underline': {
- $opt['border'] = array(0, 0, $linewidth);
- $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
- break;
- }
- case 'border.s':
- case 'solid': {
- $opt['border'] = array(0, 0, $linewidth);
- $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
- break;
- }
- default: {
- break;
- }
- }
- }
- if (isset($prop['border']) AND is_array($prop['border'])) {
- $opt['border'] = $prop['border'];
- }
- if (!isset($opt['mk'])) {
- $opt['mk'] = array();
- }
- if (!isset($opt['mk']['if'])) {
- $opt['mk']['if'] = array();
- }
- $opt['mk']['if']['a'] = array(0.5, 0.5);
-
- if (isset($prop['buttonAlignX'])) {
- $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
- }
-
- if (isset($prop['buttonAlignY'])) {
- $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
- }
-
- if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
- $opt['mk']['if']['fb'] = true;
- }
-
- if (isset($prop['buttonScaleHow'])) {
- switch ($prop['buttonScaleHow']) {
- case 'scaleHow.proportional': {
- $opt['mk']['if']['s'] = 'P';
- break;
- }
- case 'scaleHow.anamorphic': {
- $opt['mk']['if']['s'] = 'A';
- break;
- }
- }
- }
-
- if (isset($prop['buttonScaleWhen'])) {
- switch ($prop['buttonScaleWhen']) {
- case 'scaleWhen.always': {
- $opt['mk']['if']['sw'] = 'A';
- break;
- }
- case 'scaleWhen.never': {
- $opt['mk']['if']['sw'] = 'N';
- break;
- }
- case 'scaleWhen.tooBig': {
- $opt['mk']['if']['sw'] = 'B';
- break;
- }
- case 'scaleWhen.tooSmall': {
- $opt['mk']['if']['sw'] = 'S';
- break;
- }
- }
- }
-
- if (isset($prop['buttonPosition'])) {
- switch ($prop['buttonPosition']) {
- case 0:
- case 'position.textOnly': {
- $opt['mk']['tp'] = 0;
- break;
- }
- case 1:
- case 'position.iconOnly': {
- $opt['mk']['tp'] = 1;
- break;
- }
- case 2:
- case 'position.iconTextV': {
- $opt['mk']['tp'] = 2;
- break;
- }
- case 3:
- case 'position.textIconV': {
- $opt['mk']['tp'] = 3;
- break;
- }
- case 4:
- case 'position.iconTextH': {
- $opt['mk']['tp'] = 4;
- break;
- }
- case 5:
- case 'position.textIconH': {
- $opt['mk']['tp'] = 5;
- break;
- }
- case 6:
- case 'position.overlay': {
- $opt['mk']['tp'] = 6;
- break;
- }
- }
- }
-
- if (isset($prop['fillColor'])) {
- if (is_array($prop['fillColor'])) {
- $opt['mk']['bg'] = $prop['fillColor'];
- } else {
- $opt['mk']['bg'] = $this->convertHTMLColorToDec($prop['fillColor']);
- }
- }
-
- if (isset($prop['strokeColor'])) {
- if (is_array($prop['strokeColor'])) {
- $opt['mk']['bc'] = $prop['strokeColor'];
- } else {
- $opt['mk']['bc'] = $this->convertHTMLColorToDec($prop['strokeColor']);
- }
- }
-
- if (isset($prop['rotation'])) {
- $opt['mk']['r'] = $prop['rotation'];
- }
-
- if (isset($prop['charLimit'])) {
- $opt['maxlen'] = intval($prop['charLimit']);
- }
- if (!isset($ff)) {
- $ff = 0;
- }
-
- if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
- $ff += 1 << 0;
- }
-
- if (isset($prop['required']) AND ($prop['required'] == 'true')) {
- $ff += 1 << 1;
- }
-
- if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
- $ff += 1 << 12;
- }
-
- if (isset($prop['password']) AND ($prop['password'] == 'true')) {
- $ff += 1 << 13;
- }
-
- if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
- $ff += 1 << 14;
- }
-
- if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
- $ff += 1 << 15;
- }
-
- if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
- $ff += 1 << 16;
- }
-
- if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
- $ff += 1 << 17;
- }
-
- if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
- $ff += 1 << 18;
- }
-
- if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
- $ff += 1 << 19;
- }
-
- if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
- $ff += 1 << 20;
- }
-
- if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
- $ff += 1 << 21;
- }
-
- if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
- $ff += 1 << 22;
- }
-
- if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
- $ff += 1 << 23;
- }
-
- if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
- $ff += 1 << 24;
- }
-
- if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
- $ff += 1 << 25;
- }
-
- if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
- $ff += 1 << 25;
- }
-
- if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
- $ff += 1 << 26;
- }
- $opt['ff'] = $ff;
-
- if (isset($prop['defaultValue'])) {
- $opt['dv'] = $prop['defaultValue'];
- }
- $f = 4;
-
- if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
- $f += 1 << 6;
- }
-
- if (isset($prop['display'])) {
- if ($prop['display'] == 'display.visible') {
-
- } elseif ($prop['display'] == 'display.hidden') {
- $f += 1 << 1;
- } elseif ($prop['display'] == 'display.noPrint') {
- $f -= 1 << 2;
- } elseif ($prop['display'] == 'display.noView') {
- $f += 1 << 5;
- }
- }
- $opt['f'] = $f;
-
- if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
- $opt['i'] = $prop['currentValueIndices'];
- }
-
- if (isset($prop['value'])) {
- if (is_array($prop['value'])) {
- $opt['opt'] = array();
- foreach ($prop['value'] AS $key => $optval) {
-
- if (isset($prop['exportValues'][$key])) {
- $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
- } else {
- $opt['opt'][$key] = $prop['value'][$key];
- }
- }
- } else {
- $opt['v'] = $prop['value'];
- }
- }
-
- if (isset($prop['richValue'])) {
- $opt['rv'] = $prop['richValue'];
- }
-
- if (isset($prop['submitName'])) {
- $opt['tm'] = $prop['submitName'];
- }
-
- if (isset($prop['name'])) {
- $opt['t'] = $prop['name'];
- }
-
- if (isset($prop['userName'])) {
- $opt['tu'] = $prop['userName'];
- }
-
- if (isset($prop['highlight'])) {
- switch ($prop['highlight']) {
- case 'none':
- case 'highlight.n': {
- $opt['h'] = 'N';
- break;
- }
- case 'invert':
- case 'highlight.i': {
- $opt['h'] = 'i';
- break;
- }
- case 'push':
- case 'highlight.p': {
- $opt['h'] = 'P';
- break;
- }
- case 'outline':
- case 'highlight.o': {
- $opt['h'] = 'O';
- break;
- }
- }
- }
-
-
-
-
-
-
- return $opt;
- }
-
- public function setFormDefaultProp($prop=array()) {
- $this->default_form_prop = $prop;
- }
-
- public function getFormDefaultProp() {
- return $this->default_form_prop;
- }
-
- public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- if ($js) {
- $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
- return;
- }
-
- $prop = array_merge($this->getFormDefaultProp(), $prop);
-
- $popt = $this->getAnnotOptFromJSProp($prop);
-
- $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
- $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
- $popt['da'] = $fontstyle;
-
- $popt['ap'] = array();
- $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
- $text = '';
- if (isset($prop['value']) AND !empty($prop['value'])) {
- $text = $prop['value'];
- } elseif (isset($opt['v']) AND !empty($opt['v'])) {
- $text = $opt['v'];
- }
- $tmpid = $this->startTemplate($w, $h, false);
- $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
- $this->endTemplate();
- --$this->n;
- $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
- unset($this->xobjects[$tmpid]);
- $popt['ap']['n'] .= 'Q EMC';
-
- $opt = array_merge($popt, $opt);
-
- unset($opt['bs']);
-
- $opt['Subtype'] = 'Widget';
- $opt['ft'] = 'Tx';
- $opt['t'] = $name;
-
-
-
-
-
-
-
-
-
-
-
-
- unset($opt['mk']['ca']);
- unset($opt['mk']['rc']);
- unset($opt['mk']['ac']);
- unset($opt['mk']['i']);
- unset($opt['mk']['ri']);
- unset($opt['mk']['ix']);
- unset($opt['mk']['if']);
-
-
-
-
- unset($opt['mk']['tp']);
-
-
-
-
-
-
-
-
- $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
- if ($this->rtl) {
- $this->x -= $w;
- } else {
- $this->x += $w;
- }
- }
-
- public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($w, $x, $y);
- if ($js) {
- $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
- return;
- }
- if ($this->empty_string($onvalue)) {
- $onvalue = 'On';
- }
- if ($checked) {
- $defval = $onvalue;
- } else {
- $defval = 'Off';
- }
-
- $font = 'zapfdingbats';
- $this->AddFont($font);
- $tmpfont = $this->getFontBuffer($font);
-
- if (!isset($this->radiobutton_groups[$this->page])) {
- $this->radiobutton_groups[$this->page] = array();
- }
- if (!isset($this->radiobutton_groups[$this->page][$name])) {
- $this->radiobutton_groups[$this->page][$name] = array();
- ++$this->n;
- $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
- $this->radio_groups[] = $this->n;
- }
- $kid = ($this->n + 1);
-
- $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
-
- $prop = array_merge($this->getFormDefaultProp(), $prop);
- $prop['NoToggleToOff'] = 'true';
- $prop['Radio'] = 'true';
- $prop['borderStyle'] = 'inset';
-
- $popt = $this->getAnnotOptFromJSProp($prop);
-
- $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
- $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
- $popt['da'] = $fontstyle;
-
- $popt['ap'] = array();
- $popt['ap']['n'] = array();
- $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
- $popt['ap']['n'][$onvalue] = sprintf('q %s BT /F%d %.2F Tf %.2F %.2F Td ('.chr(108).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy);
- $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %.2F Tf %.2F %.2F Td ('.chr(109).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy);
- if (!isset($popt['mk'])) {
- $popt['mk'] = array();
- }
- $popt['mk']['ca'] = '(l)';
-
- $opt = array_merge($popt, $opt);
-
- $opt['Subtype'] = 'Widget';
- $opt['ft'] = 'Btn';
- if ($checked) {
- $opt['v'] = array('/'.$onvalue);
- $opt['as'] = $onvalue;
- } else {
- $opt['as'] = 'Off';
- }
-
- if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
- $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
- }
- $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
- $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
- if ($this->rtl) {
- $this->x -= $w;
- } else {
- $this->x += $w;
- }
- }
-
- public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- if ($js) {
- $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
- $s = '';
- foreach ($values as $value) {
- $s .= '\''.addslashes($value).'\',';
- }
- $this->javascript .= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n";
- return;
- }
-
- $prop = array_merge($this->getFormDefaultProp(), $prop);
-
- $popt = $this->getAnnotOptFromJSProp($prop);
-
- $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
- $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
- $popt['da'] = $fontstyle;
-
- $popt['ap'] = array();
- $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
- $text = '';
- foreach($values as $item) {
- $text .= $item."\n";
- }
- $tmpid = $this->startTemplate($w, $h, false);
- $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
- $this->endTemplate();
- --$this->n;
- $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
- unset($this->xobjects[$tmpid]);
- $popt['ap']['n'] .= 'Q EMC';
-
- $opt = array_merge($popt, $opt);
-
- $opt['Subtype'] = 'Widget';
- $opt['ft'] = 'Ch';
- $opt['t'] = $name;
- $opt['opt'] = $values;
- unset($opt['mk']['ca']);
- unset($opt['mk']['rc']);
- unset($opt['mk']['ac']);
- unset($opt['mk']['i']);
- unset($opt['mk']['ri']);
- unset($opt['mk']['ix']);
- unset($opt['mk']['if']);
- unset($opt['mk']['tp']);
- $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
- if ($this->rtl) {
- $this->x -= $w;
- } else {
- $this->x += $w;
- }
- }
-
- public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- if ($js) {
- $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
- $s = '';
- foreach ($values as $value) {
- $s .= "'".addslashes($value)."',";
- }
- $this->javascript .= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n";
- return;
- }
-
- $prop = array_merge($this->getFormDefaultProp(), $prop);
- $prop['Combo'] = true;
-
- $popt = $this->getAnnotOptFromJSProp($prop);
-
- $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
- $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
- $popt['da'] = $fontstyle;
-
- $popt['ap'] = array();
- $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
- $text = '';
- foreach($values as $item) {
- $text .= $item[1]."\n";
- }
- $tmpid = $this->startTemplate($w, $h, false);
- $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
- $this->endTemplate();
- --$this->n;
- $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
- unset($this->xobjects[$tmpid]);
- $popt['ap']['n'] .= 'Q EMC';
-
- $opt = array_merge($popt, $opt);
-
- $opt['Subtype'] = 'Widget';
- $opt['ft'] = 'Ch';
- $opt['t'] = $name;
- $opt['opt'] = $values;
- unset($opt['mk']['ca']);
- unset($opt['mk']['rc']);
- unset($opt['mk']['ac']);
- unset($opt['mk']['i']);
- unset($opt['mk']['ri']);
- unset($opt['mk']['ix']);
- unset($opt['mk']['if']);
- unset($opt['mk']['tp']);
- $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
- if ($this->rtl) {
- $this->x -= $w;
- } else {
- $this->x += $w;
- }
- }
-
- public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($w, $x, $y);
- if ($js) {
- $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
- return;
- }
- if (!isset($prop['value'])) {
- $prop['value'] = array('Yes');
- }
-
- $prop = array_merge($this->getFormDefaultProp(), $prop);
- $prop['borderStyle'] = 'inset';
-
- $popt = $this->getAnnotOptFromJSProp($prop);
-
- $font = 'zapfdingbats';
- $this->AddFont($font);
- $tmpfont = $this->getFontBuffer($font);
- $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
- $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
- $popt['da'] = $fontstyle;
-
- $popt['ap'] = array();
- $popt['ap']['n'] = array();
- $fy = ((($tmpfont['desc']['Ascent'] + $tmpfont['desc']['Descent']) * $this->FontSizePt) / (1000 * $this->k));
- $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
- $popt['ap']['n']['Yes'] = sprintf('q %s BT /F%d %.2F Tf %.2F %.2F Td ('.chr(110).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy);
- $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %.2F Tf %.2F %.2F Td ('.chr(111).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy);
-
- $opt = array_merge($popt, $opt);
-
- $opt['Subtype'] = 'Widget';
- $opt['ft'] = 'Btn';
- $opt['t'] = $name;
- $opt['opt'] = array($onvalue);
- if ($checked) {
- $opt['v'] = array('/Yes');
- $opt['as'] = 'Yes';
- } else {
- $opt['v'] = array('/Off');
- $opt['as'] = 'Off';
- }
- $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
- if ($this->rtl) {
- $this->x -= $w;
- } else {
- $this->x += $w;
- }
- }
-
- public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- if ($js) {
- $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
- $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
- $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
- $this->javascript .= 'f'.$name.".highlight='push';\n";
- $this->javascript .= 'f'.$name.".print=false;\n";
- return;
- }
-
- $prop = array_merge($this->getFormDefaultProp(), $prop);
- $prop['Pushbutton'] = 'true';
- $prop['highlight'] = 'push';
- $prop['display'] = 'display.noPrint';
-
- $popt = $this->getAnnotOptFromJSProp($prop);
- $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
- $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
- $popt['da'] = $fontstyle;
-
- $popt['ap'] = array();
- $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
- $tmpid = $this->startTemplate($w, $h, false);
- $bw = (2 / $this->k);
- $border = array(
- 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
- 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
- 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
- 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
- $this->SetFillColor(204);
- $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
- $this->endTemplate();
- --$this->n;
- $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
- unset($this->xobjects[$tmpid]);
- $popt['ap']['n'] .= 'Q EMC';
-
- if (!isset($popt['mk'])) {
- $popt['mk'] = array();
- }
- $ann_obj_id = ($this->n + 1);
- if (!empty($action) AND !is_array($action)) {
- $ann_obj_id = ($this->n + 2);
- }
- $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
- $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
- $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
-
- $opt = array_merge($popt, $opt);
-
- $opt['Subtype'] = 'Widget';
- $opt['ft'] = 'Btn';
- $opt['t'] = $caption;
- $opt['v'] = $name;
- if (!empty($action)) {
- if (is_array($action)) {
-
- $opt['aa'] = '/D <<';
- $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
- foreach ($action AS $key => $val) {
- if (($key == 'S') AND in_array($val, $bmode)) {
- $opt['aa'] .= ' /S /'.$val;
- } elseif (($key == 'F') AND (!empty($val))) {
- $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
- } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
- $opt['aa'] .= ' /Fields [';
- foreach ($val AS $field) {
- $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
- }
- $opt['aa'] .= ']';
- } elseif (($key == 'Flags')) {
- $ff = 0;
- if (is_array($val)) {
- foreach ($val AS $flag) {
- switch ($flag) {
- case 'Include/Exclude': {
- $ff += 1 << 0;
- break;
- }
- case 'IncludeNoValueFields': {
- $ff += 1 << 1;
- break;
- }
- case 'ExportFormat': {
- $ff += 1 << 2;
- break;
- }
- case 'GetMethod': {
- $ff += 1 << 3;
- break;
- }
- case 'SubmitCoordinates': {
- $ff += 1 << 4;
- break;
- }
- case 'XFDF': {
- $ff += 1 << 5;
- break;
- }
- case 'IncludeAppendSaves': {
- $ff += 1 << 6;
- break;
- }
- case 'IncludeAnnotations': {
- $ff += 1 << 7;
- break;
- }
- case 'SubmitPDF': {
- $ff += 1 << 8;
- break;
- }
- case 'CanonicalFormat': {
- $ff += 1 << 9;
- break;
- }
- case 'ExclNonUserAnnots': {
- $ff += 1 << 10;
- break;
- }
- case 'ExclFKey': {
- $ff += 1 << 11;
- break;
- }
- case 'EmbedForm': {
- $ff += 1 << 13;
- break;
- }
- }
- }
- } else {
- $ff = intval($val);
- }
- $opt['aa'] .= ' /Flags '.$ff;
- }
- }
- $opt['aa'] .= ' >>';
- } else {
-
- $js_obj_id = $this->addJavascriptObject($action);
- $opt['aa'] = '/D '.$js_obj_id.' 0 R';
- }
- }
- $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
- if ($this->rtl) {
- $this->x -= $w;
- } else {
- $this->x += $w;
- }
- }
-
-
- protected function _putsignature() {
- if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
- return;
- }
- $sigobjid = ($this->sig_obj_id + 1);
- $out = $this->_getobj($sigobjid)."\n";
- $out .= '<< /Type /Sig';
- $out .= ' /Filter /Adobe.PPKLite';
- $out .= ' /SubFilter /adbe.pkcs7.detached';
- $out .= ' '.$this->byterange_string;
- $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
- $out .= ' /Reference [';
- $out .= ' << /Type /SigRef';
- if ($this->signature_data['cert_type'] > 0) {
- $out .= ' /TransformMethod /DocMDP';
- $out .= ' /TransformParams <<';
- $out .= ' /Type /TransformParams';
- $out .= ' /P '.$this->signature_data['cert_type'];
- $out .= ' /V /1.2';
- } else {
- $out .= ' /TransformMethod /UR3';
- $out .= ' /TransformParams <<';
- $out .= ' /Type /TransformParams';
- $out .= ' /V /2.2';
- if (!$this->empty_string($this->ur['document'])) {
- $out .= ' /Document['.$this->ur['document'].']';
- }
- if (!$this->empty_string($this->ur['form'])) {
- $out .= ' /Form['.$this->ur['form'].']';
- }
- if (!$this->empty_string($this->ur['signature'])) {
- $out .= ' /Signature['.$this->ur['signature'].']';
- }
- if (!$this->empty_string($this->ur['annots'])) {
- $out .= ' /Annots['.$this->ur['annots'].']';
- }
- if (!$this->empty_string($this->ur['ef'])) {
- $out .= ' /EF['.$this->ur['ef'].']';
- }
- if (!$this->empty_string($this->ur['formex'])) {
- $out .= ' /FormEX['.$this->ur['formex'].']';
- }
- }
- $out .= ' >>';
-
-
-
-
-
- $out .= ' >>';
- $out .= ' ]';
- if (isset($this->signature_data['info']['Name']) AND !$this->empty_string($this->signature_data['info']['Name'])) {
- $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
- }
- if (isset($this->signature_data['info']['Location']) AND !$this->empty_string($this->signature_data['info']['Location'])) {
- $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
- }
- if (isset($this->signature_data['info']['Reason']) AND !$this->empty_string($this->signature_data['info']['Reason'])) {
- $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
- }
- if (isset($this->signature_data['info']['ContactInfo']) AND !$this->empty_string($this->signature_data['info']['ContactInfo'])) {
- $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
- }
- $out .= ' /M '.$this->_datestring($sigobjid);
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- public function setUserRights(
- $enable=true,
- $document='/FullSave',
- $annots='/Create/Delete/Modify/Copy/Import/Export',
- $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
- $signature='/Modify',
- $ef='/Create/Delete/Modify/Import',
- $formex='') {
- $this->ur['enabled'] = $enable;
- $this->ur['document'] = $document;
- $this->ur['annots'] = $annots;
- $this->ur['form'] = $form;
- $this->ur['signature'] = $signature;
- $this->ur['ef'] = $ef;
- $this->ur['formex'] = $formex;
- if (!$this->sign) {
- $this->setSignature('', '', '', '', 0, array());
- }
- }
-
- public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) {
-
-
-
-
- $this->sign = true;
- ++$this->n;
- $this->sig_obj_id = $this->n;
- ++$this->n;
- $this->signature_data = array();
- if (strlen($signing_cert) == 0) {
- $signing_cert = 'file://'.dirname(__FILE__).'/tcpdf.crt';
- $private_key_password = 'tcpdfdemo';
- }
- if (strlen($private_key) == 0) {
- $private_key = $signing_cert;
- }
- $this->signature_data['signcert'] = $signing_cert;
- $this->signature_data['privkey'] = $private_key;
- $this->signature_data['password'] = $private_key_password;
- $this->signature_data['extracerts'] = $extracerts;
- $this->signature_data['cert_type'] = $cert_type;
- $this->signature_data['info'] = $info;
- }
-
- public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) {
- $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page);
- }
-
- public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) {
- ++$this->n;
- $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page);
- }
-
- protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1) {
- $sigapp = array();
- if (($page < 1) OR ($page > $this->numpages)) {
- $sigapp['page'] = $this->page;
- } else {
- $sigapp['page'] = intval($page);
- }
- $a = $x * $this->k;
- $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
- $c = $w * $this->k;
- $d = $h * $this->k;
- $sigapp['rect'] = sprintf('%.2F %.2F %.2F %.2F', $a, $b, ($a + $c), ($b + $d));
- return $sigapp;
- }
-
- public function startPageGroup($page='') {
- if (empty($page)) {
- $page = $this->page + 1;
- }
- $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
- }
-
- public function AliasNbPages($s='') {}
-
- public function AliasNumPage($s='') {}
-
- public function setStartingPageNumber($num=1) {
- $this->starting_page_number = max(0, intval($num));
- }
-
- public function getAliasRightShift() {
-
- $ref = '{'.$this->alias_right_shift.'}{'.$this->alias_tot_pages.'}{'.$this->alias_num_page.'}';
- $rep = str_repeat(' ', $this->GetNumChars($ref));
- $wdiff = max(1, ($this->GetStringWidth($ref) / $this->GetStringWidth($rep)));
- $sdiff = sprintf('%.3F', $wdiff);
- $alias = $this->alias_right_shift.$sdiff.'}';
- if ($this->isUnicodeFont()) {
- $alias = '{'.$alias;
- }
- return $alias;
- }
-
- public function getAliasNbPages() {
- if ($this->isUnicodeFont()) {
- return '{'.$this->alias_tot_pages.'}';
- }
- return $this->alias_tot_pages;
- }
-
- public function getAliasNumPage() {
- if ($this->isUnicodeFont()) {
- return '{'.$this->alias_num_page.'}';
- }
- return $this->alias_num_page;
- }
-
- public function getPageGroupAlias() {
- if ($this->isUnicodeFont()) {
- return '{'.$this->alias_group_tot_pages.'}';
- }
- return $this->alias_group_tot_pages;
- }
-
- public function getPageNumGroupAlias() {
- if ($this->isUnicodeFont()) {
- return '{'.$this->alias_group_num_page.'}';
- }
- return $this->alias_group_num_page;
- }
-
- public function getGroupPageNo() {
- return $this->pagegroups[$this->currpagegroup];
- }
-
- public function getGroupPageNoFormatted() {
- return $this->formatPageNumber($this->getGroupPageNo());
- }
-
- protected function formatPageNumber($num) {
- return number_format((float)$num, 0, '', '.');
- }
-
- protected function formatTOCPageNumber($num) {
- return number_format((float)$num, 0, '', '.');
- }
-
- public function PageNoFormatted() {
- return $this->formatPageNumber($this->PageNo());
- }
-
- protected function _putocg() {
- if (empty($this->pdflayers)) {
- return;
- }
- foreach ($this->pdflayers as $key => $layer) {
- $this->pdflayers[$key]['objid'] = $this->_newobj();
- $out = '<< /Type /OCG';
- $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
- $out .= ' /Usage <<';
- $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
- $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
- $out .= ' >> >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
-
- public function startLayer($name='', $print=true, $view=true) {
- $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
- if (empty($name)) {
- $name = $layer;
- } else {
- $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
- }
- $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view);
- $this->openMarkedContent = true;
- $this->_out('/OC /'.$layer.' BDC');
- }
-
- public function endLayer() {
- if ($this->openMarkedContent) {
-
- $this->_out('EMC');
- $this->openMarkedContent = false;
- }
- }
-
- public function setVisibility($v) {
- $this->endLayer();
- switch($v) {
- case 'print': {
- $this->startLayer('Print', true, false);
- break;
- }
- case 'view':
- case 'screen': {
- $this->startLayer('View', false, true);
- break;
- }
- case 'all': {
- $this->_out('');
- break;
- }
- default: {
- $this->Error('Incorrect visibility: '.$v);
- break;
- }
- }
- }
-
- protected function addExtGState($parms) {
- if ($this->pdfa_mode) {
-
- return;
- }
-
- foreach ($this->extgstates as $i => $ext) {
- if ($ext['parms'] == $parms) {
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
- }
-
- return $i;
- }
- }
- $n = (count($this->extgstates) + 1);
- $this->extgstates[$n] = array('parms' => $parms);
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
- }
- return $n;
- }
-
- protected function setExtGState($gs) {
- if ($this->pdfa_mode) {
-
- return;
- }
- $this->_out(sprintf('/GS%d gs', $gs));
- }
-
- protected function _putextgstates() {
- if ($this->pdfa_mode) {
-
- return;
- }
- foreach ($this->extgstates as $i => $ext) {
- $this->extgstates[$i]['n'] = $this->_newobj();
- $out = '<< /Type /ExtGState';
- foreach ($ext['parms'] as $k => $v) {
- if (is_float($v)) {
- $v = sprintf('%.2F', $v);
- }
- $out .= ' /'.$k.' '.$v;
- }
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
-
- public function setAlpha($alpha, $bm='Normal') {
- if ($this->pdfa_mode) {
-
- return;
- }
- $gs = $this->addExtGState(array('ca' => $alpha, 'CA' => $alpha, 'BM' => '/'.$bm, 'AIS' => 'false'));
- $this->setExtGState($gs);
- }
-
- public function setJPEGQuality($quality) {
- if (($quality < 1) OR ($quality > 100)) {
- $quality = 75;
- }
- $this->jpeg_quality = intval($quality);
- }
-
- public function setDefaultTableColumns($cols=4) {
- $this->default_table_columns = intval($cols);
- }
-
- public function setCellHeightRatio($h) {
- $this->cell_height_ratio = $h;
- }
-
- public function getCellHeightRatio() {
- return $this->cell_height_ratio;
- }
-
- public function setPDFVersion($version='1.7') {
- if ($this->pdfa_mode) {
-
- $this->PDFVersion = '1.4';
- } else {
- $this->PDFVersion = $version;
- }
- }
-
- public function setViewerPreferences($preferences) {
- $this->viewer_preferences = $preferences;
- }
-
- public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
- $bars = explode(',', $colors);
- $numbars = count($bars);
-
- if ($vertical) {
- $coords = array(0, 0, 0, 1);
- $wb = $w / $numbars;
- $hb = $h;
- $xd = $wb;
- $yd = 0;
- } else {
- $coords = array(1, 0, 0, 0);
- $wb = $w;
- $hb = $h / $numbars;
- $xd = 0;
- $yd = $hb;
- }
- $xb = $x;
- $yb = $y;
- foreach ($bars as $col) {
- switch ($col) {
-
- case 'A': {
- $col_a = array(255);
- $col_b = array(0);
- break;
- }
- case 'W': {
- $col_a = array(0);
- $col_b = array(255);
- break;
- }
- case 'R': {
- $col_a = array(255,255,255);
- $col_b = array(255,0,0);
- break;
- }
- case 'G': {
- $col_a = array(255,255,255);
- $col_b = array(0,255,0);
- break;
- }
- case 'B': {
- $col_a = array(255,255,255);
- $col_b = array(0,0,255);
- break;
- }
- case 'C': {
- $col_a = array(0,0,0,0);
- $col_b = array(100,0,0,0);
- break;
- }
- case 'M': {
- $col_a = array(0,0,0,0);
- $col_b = array(0,100,0,0);
- break;
- }
- case 'Y': {
- $col_a = array(0,0,0,0);
- $col_b = array(0,0,100,0);
- break;
- }
- case 'K': {
- $col_a = array(0,0,0,0);
- $col_b = array(0,0,0,100);
- break;
- }
- default: {
- $col_a = array(255);
- $col_b = array(0);
- break;
- }
- }
- if ($transition) {
-
- $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
- } else {
-
- $this->SetFillColorArray($col_b);
- $this->Rect($xb, $yb, $wb, $hb, 'F', array());
- }
- $xb += $xd;
- $yb += $yd;
- }
- }
-
- public function cropMark($x, $y, $w, $h, $type='A,B,C,D', $color=array(0,0,0)) {
- $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
- $crops = explode(',', $type);
- $numcrops = count($crops);
- $dw = $w / 4;
- $dh = $h / 4;
- foreach ($crops as $crop) {
- switch ($crop) {
- case 'A': {
- $x1 = $x;
- $y1 = $y - $h;
- $x2 = $x;
- $y2 = $y - $dh;
- $x3 = $x - $w;
- $y3 = $y;
- $x4 = $x - $dw;
- $y4 = $y;
- break;
- }
- case 'B': {
- $x1 = $x;
- $y1 = $y - $h;
- $x2 = $x;
- $y2 = $y - $dh;
- $x3 = $x + $dw;
- $y3 = $y;
- $x4 = $x + $w;
- $y4 = $y;
- break;
- }
- case 'C': {
- $x1 = $x - $w;
- $y1 = $y;
- $x2 = $x - $dw;
- $y2 = $y;
- $x3 = $x;
- $y3 = $y + $dh;
- $x4 = $x;
- $y4 = $y + $h;
- break;
- }
- case 'D': {
- $x1 = $x + $dw;
- $y1 = $y;
- $x2 = $x + $w;
- $y2 = $y;
- $x3 = $x;
- $y3 = $y + $dh;
- $x4 = $x;
- $y4 = $y + $h;
- break;
- }
- }
- $this->Line($x1, $y1, $x2, $y2);
- $this->Line($x3, $y3, $x4, $y4);
- }
- }
-
- public function registrationMark($x, $y, $r, $double=false, $cola=array(0,0,0), $colb=array(255,255,255)) {
- $line_style = array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
- $this->SetFillColorArray($cola);
- $this->PieSector($x, $y, $r, 90, 180, 'F');
- $this->PieSector($x, $y, $r, 270, 360, 'F');
- $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
- if ($double) {
- $r2 = $r * 0.5;
- $this->SetFillColorArray($colb);
- $this->PieSector($x, $y, $r2, 90, 180, 'F');
- $this->PieSector($x, $y, $r2, 270, 360, 'F');
- $this->SetFillColorArray($cola);
- $this->PieSector($x, $y, $r2, 0, 90, 'F');
- $this->PieSector($x, $y, $r2, 180, 270, 'F');
- $this->Circle($x, $y, $r2, 0, 360, 'C', $line_style, array(), 8);
- }
- }
-
- public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
- $this->Clip($x, $y, $w, $h);
- $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
- }
-
- public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
- $this->Clip($x, $y, $w, $h);
- $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
- }
-
- public function CoonsPatchMesh($x, $y, $w, $h, $col1=array(), $col2=array(), $col3=array(), $col4=array(), $coords=array(0.00,0.0,0.33,0.00,0.67,0.00,1.00,0.00,1.00,0.33,1.00,0.67,1.00,1.00,0.67,1.00,0.33,1.00,0.00,1.00,0.00,0.67,0.00,0.33), $coords_min=0, $coords_max=1, $antialias=false) {
- if ($this->pdfa_mode) {
- return;
- }
- $this->Clip($x, $y, $w, $h);
- $n = count($this->gradients) + 1;
- $this->gradients[$n] = array();
- $this->gradients[$n]['type'] = 6;
- $this->gradients[$n]['coords'] = array();
- $this->gradients[$n]['antialias'] = $antialias;
- $this->gradients[$n]['colors'] = array();
- $this->gradients[$n]['transparency'] = false;
-
- if (!isset($coords[0]['f'])) {
-
- if (!isset($col1[1])) {
- $col1[1] = $col1[2] = $col1[0];
- }
- if (!isset($col2[1])) {
- $col2[1] = $col2[2] = $col2[0];
- }
- if (!isset($col3[1])) {
- $col3[1] = $col3[2] = $col3[0];
- }
- if (!isset($col4[1])) {
- $col4[1] = $col4[2] = $col4[0];
- }
- $patch_array[0]['f'] = 0;
- $patch_array[0]['points'] = $coords;
- $patch_array[0]['colors'][0]['r'] = $col1[0];
- $patch_array[0]['colors'][0]['g'] = $col1[1];
- $patch_array[0]['colors'][0]['b'] = $col1[2];
- $patch_array[0]['colors'][1]['r'] = $col2[0];
- $patch_array[0]['colors'][1]['g'] = $col2[1];
- $patch_array[0]['colors'][1]['b'] = $col2[2];
- $patch_array[0]['colors'][2]['r'] = $col3[0];
- $patch_array[0]['colors'][2]['g'] = $col3[1];
- $patch_array[0]['colors'][2]['b'] = $col3[2];
- $patch_array[0]['colors'][3]['r'] = $col4[0];
- $patch_array[0]['colors'][3]['g'] = $col4[1];
- $patch_array[0]['colors'][3]['b'] = $col4[2];
- } else {
-
- $patch_array = $coords;
- }
- $bpcd = 65535;
-
- $this->gradients[$n]['stream'] = '';
- $count_patch = count($patch_array);
- for ($i=0; $i < $count_patch; ++$i) {
- $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']);
- $count_points = count($patch_array[$i]['points']);
- for ($j=0; $j < $count_points; ++$j) {
-
- $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
- if ($patch_array[$i]['points'][$j] < 0) {
- $patch_array[$i]['points'][$j] = 0;
- }
- if ($patch_array[$i]['points'][$j] > $bpcd) {
- $patch_array[$i]['points'][$j] = $bpcd;
- }
- $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
- $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
- }
- $count_cols = count($patch_array[$i]['colors']);
- for ($j=0; $j < $count_cols; ++$j) {
-
- $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
- $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
- $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
- }
- }
-
- $this->_out('/Sh'.$n.' sh');
-
- $this->_out('Q');
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
- }
- }
-
- protected function Clip($x, $y, $w, $h) {
- if ($this->rtl) {
- $x = $this->w - $x - $w;
- }
-
- $s = 'q';
-
- $s .= sprintf(' %.2F %.2F %.2F %.2F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
-
- $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
- $this->_out($s);
- }
-
- public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
- if ($this->pdfa_mode) {
- return;
- }
- $n = count($this->gradients) + 1;
- $this->gradients[$n] = array();
- $this->gradients[$n]['type'] = $type;
- $this->gradients[$n]['coords'] = $coords;
- $this->gradients[$n]['antialias'] = $antialias;
- $this->gradients[$n]['colors'] = array();
- $this->gradients[$n]['transparency'] = false;
-
- $numcolspace = count($stops[0]['color']);
- $bcolor = array_values($background);
- switch($numcolspace) {
- case 4: {
- $this->gradients[$n]['colspace'] = 'DeviceCMYK';
- if (!empty($background)) {
- $this->gradients[$n]['background'] = sprintf('%.3F %.3F %.3F %.3F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
- }
- break;
- }
- case 3: {
- $this->gradients[$n]['colspace'] = 'DeviceRGB';
- if (!empty($background)) {
- $this->gradients[$n]['background'] = sprintf('%.3F %.3F %.3F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
- }
- break;
- }
- case 1: {
- $this->gradients[$n]['colspace'] = 'DeviceGray';
- if (!empty($background)) {
- $this->gradients[$n]['background'] = sprintf('%.3F', $bcolor[0]/255);
- }
- break;
- }
- }
- $num_stops = count($stops);
- $last_stop_id = $num_stops - 1;
- foreach ($stops as $key => $stop) {
- $this->gradients[$n]['colors'][$key] = array();
-
- if (isset($stop['offset'])) {
- $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
- } else {
- if ($key == 0) {
- $this->gradients[$n]['colors'][$key]['offset'] = 0;
- } elseif ($key == $last_stop_id) {
- $this->gradients[$n]['colors'][$key]['offset'] = 1;
- } else {
- $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
- $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
- }
- }
- if (isset($stop['opacity'])) {
- $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
- if ((!$this->pdfa_mode) AND ($stop['opacity'] < 1)) {
- $this->gradients[$n]['transparency'] = true;
- }
- } else {
- $this->gradients[$n]['colors'][$key]['opacity'] = 1;
- }
-
- if (isset($stop['exponent'])) {
- $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
- } else {
- $this->gradients[$n]['colors'][$key]['exponent'] = 1;
- }
-
- $color = array_values($stop['color']);
- switch($numcolspace) {
- case 4: {
- $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F %.3F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
- break;
- }
- case 3: {
- $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F', $color[0]/255, $color[1]/255, $color[2]/255);
- break;
- }
- case 1: {
- $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F', $color[0]/255);
- break;
- }
- }
- }
- if ($this->gradients[$n]['transparency']) {
-
- $this->_out('/TGS'.$n.' gs');
- }
-
- $this->_out('/Sh'.$n.' sh');
-
- $this->_out('Q');
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
- }
- }
-
- function _putshaders() {
- if ($this->pdfa_mode) {
- return;
- }
- $idt = count($this->gradients);
- foreach ($this->gradients as $id => $grad) {
- if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
- $fc = $this->_newobj();
- $out = '<<';
- $out .= ' /FunctionType 3';
- $out .= ' /Domain [0 1]';
- $functions = '';
- $bounds = '';
- $encode = '';
- $i = 1;
- $num_cols = count($grad['colors']);
- $lastcols = $num_cols - 1;
- for ($i = 1; $i < $num_cols; ++$i) {
- $functions .= ($fc + $i).' 0 R ';
- if ($i < $lastcols) {
- $bounds .= sprintf('%.3F ', $grad['colors'][$i]['offset']);
- }
- $encode .= '0 1 ';
- }
- $out .= ' /Functions ['.trim($functions).']';
- $out .= ' /Bounds ['.trim($bounds).']';
- $out .= ' /Encode ['.trim($encode).']';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- for ($i = 1; $i < $num_cols; ++$i) {
- $this->_newobj();
- $out = '<<';
- $out .= ' /FunctionType 2';
- $out .= ' /Domain [0 1]';
- $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
- $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
- $out .= ' /N '.$grad['colors'][$i]['exponent'];
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
-
- if ($grad['transparency']) {
- $ft = $this->_newobj();
- $out = '<<';
- $out .= ' /FunctionType 3';
- $out .= ' /Domain [0 1]';
- $functions = '';
- $i = 1;
- $num_cols = count($grad['colors']);
- for ($i = 1; $i < $num_cols; ++$i) {
- $functions .= ($ft + $i).' 0 R ';
- }
- $out .= ' /Functions ['.trim($functions).']';
- $out .= ' /Bounds ['.trim($bounds).']';
- $out .= ' /Encode ['.trim($encode).']';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- for ($i = 1; $i < $num_cols; ++$i) {
- $this->_newobj();
- $out = '<<';
- $out .= ' /FunctionType 2';
- $out .= ' /Domain [0 1]';
- $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
- $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
- $out .= ' /N '.$grad['colors'][$i]['exponent'];
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- }
- }
- }
-
- $this->_newobj();
- $out = '<< /ShadingType '.$grad['type'];
- if (isset($grad['colspace'])) {
- $out .= ' /ColorSpace /'.$grad['colspace'];
- } else {
- $out .= ' /ColorSpace /DeviceRGB';
- }
- if (isset($grad['background']) AND !empty($grad['background'])) {
- $out .= ' /Background ['.$grad['background'].']';
- }
- if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
- $out .= ' /AntiAlias true';
- }
- if ($grad['type'] == 2) {
- $out .= ' '.sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
- $out .= ' /Domain [0 1]';
- $out .= ' /Function '.$fc.' 0 R';
- $out .= ' /Extend [true true]';
- $out .= ' >>';
- } elseif ($grad['type'] == 3) {
-
-
- $out .= ' '.sprintf('/Coords [%.3F %.3F 0 %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
- $out .= ' /Domain [0 1]';
- $out .= ' /Function '.$fc.' 0 R';
- $out .= ' /Extend [true true]';
- $out .= ' >>';
- } elseif ($grad['type'] == 6) {
- $out .= ' /BitsPerCoordinate 16';
- $out .= ' /BitsPerComponent 8';
- $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
- $out .= ' /BitsPerFlag 8';
- $stream = $this->_getrawstream($grad['stream']);
- $out .= ' /Length '.strlen($stream);
- $out .= ' >>';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- }
- $out .= "\n".'endobj';
- $this->_out($out);
- if ($grad['transparency']) {
- $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
- $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
- }
- $this->gradients[$id]['id'] = $this->n;
-
- $this->_newobj();
- $out = '<< /Type /Pattern /PatternType 2';
- $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- $this->gradients[$id]['pattern'] = $this->n;
-
- if ($grad['transparency']) {
-
- $idgs = $id + $idt;
- $this->_newobj();
- $this->_out($shading_transparency);
- $this->gradients[$idgs]['id'] = $this->n;
- $this->_newobj();
- $out = '<< /Type /Pattern /PatternType 2';
- $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
- $out .= ' >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- $this->gradients[$idgs]['pattern'] = $this->n;
-
- $oid = $this->_newobj();
- $this->xobjects['LX'.$oid] = array('n' => $oid);
- $filter = '';
- $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
- if ($this->compress) {
- $filter = ' /Filter /FlateDecode';
- $stream = gzcompress($stream);
- }
- $stream = $this->_getrawstream($stream);
- $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
- $out .= ' /Length '.strlen($stream);
- $rect = sprintf('%.2F %.2F', $this->wPt, $this->hPt);
- $out .= ' /BBox [0 0 '.$rect.']';
- $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
- $out .= ' /Resources <<';
- $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
- $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
- $out .= ' >>';
- $out .= ' >> ';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- $out .= "\n".'endobj';
- $this->_out($out);
-
- $this->_newobj();
- $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
- $this->_out($out);
-
- $this->_newobj();
- $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
- $this->_out($out);
- $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
- }
- }
- }
-
- public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
- $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
- }
-
- public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
- if ($this->rtl) {
- $xc = $this->w - $xc;
- }
- $op = $this->getPathPaintOperator($style);
- if ($op == 'f') {
- $line_style = array();
- }
- if ($cw) {
- $d = $b;
- $b = 360 - $a + $o;
- $a = 360 - $d + $o;
- } else {
- $b += $o;
- $a += $o;
- }
- $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
- $this->_out($op);
- }
-
- public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
- if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
-
- return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
- }
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- $k = $this->k;
- if ($file{0} === '@') {
- $data = substr($file, 1);
- } else {
- $data = file_get_contents($file);
- }
- if ($data === false) {
- $this->Error('EPS file not found: '.$file);
- }
- $regs = array();
-
- preg_match("/%%Creator:([^\r\n]+)/", $data, $regs);
- if (count($regs) > 1) {
- $version_str = trim($regs[1]);
- if (strpos($version_str, 'Adobe Illustrator') !== false) {
- $versexp = explode(' ', $version_str);
- $version = (float)array_pop($versexp);
- if ($version >= 9) {
- $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
- }
- }
- }
-
- $start = strpos($data, '%!PS-Adobe');
- if ($start > 0) {
- $data = substr($data, $start);
- }
-
- preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
- if (count($regs) > 1) {
- list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
- } else {
- $this->Error('No BoundingBox found in EPS/AI file: '.$file);
- }
- $start = strpos($data, '%%EndSetup');
- if ($start === false) {
- $start = strpos($data, '%%EndProlog');
- }
- if ($start === false) {
- $start = strpos($data, '%%BoundingBox');
- }
- $data = substr($data, $start);
- $end = strpos($data, '%%PageTrailer');
- if ($end===false) {
- $end = strpos($data, 'showpage');
- }
- if ($end) {
- $data = substr($data, 0, $end);
- }
-
- if (($w <= 0) AND ($h <= 0)) {
- $w = ($x2 - $x1) / $k;
- $h = ($y2 - $y1) / $k;
- } elseif ($w <= 0) {
- $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
- } elseif ($h <= 0) {
- $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
- }
-
- list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
- if ($this->rasterize_vector_images) {
-
- return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
- }
-
- $scale_x = $w / (($x2 - $x1) / $k);
- $scale_y = $h / (($y2 - $y1) / $k);
-
- $this->img_rb_y = $y + $h;
-
- if ($this->rtl) {
- if ($palign == 'L') {
- $ximg = $this->lMargin;
- } elseif ($palign == 'C') {
- $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($palign == 'R') {
- $ximg = $this->w - $this->rMargin - $w;
- } else {
- $ximg = $x - $w;
- }
- $this->img_rb_x = $ximg;
- } else {
- if ($palign == 'L') {
- $ximg = $this->lMargin;
- } elseif ($palign == 'C') {
- $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($palign == 'R') {
- $ximg = $this->w - $this->rMargin - $w;
- } else {
- $ximg = $x;
- }
- $this->img_rb_x = $ximg + $w;
- }
- if ($useBoundingBox) {
- $dx = $ximg * $k - $x1;
- $dy = $y * $k - $y1;
- } else {
- $dx = $ximg * $k;
- $dy = $y * $k;
- }
-
- $this->_out('q'.$this->epsmarker);
-
- $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
-
- if (isset($scale_x)) {
- $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
- }
-
- $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
- $u=0;
- $cnt = count($lines);
- for ($i=0; $i < $cnt; ++$i) {
- $line = $lines[$i];
- if (($line == '') OR ($line{0} == '%')) {
- continue;
- }
- $len = strlen($line);
-
- $color_name = '';
- if (strcasecmp('x', substr(trim($line), -1)) == 0) {
- if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
-
- $color_name = $matches[0];
-
- $line = str_replace(' '.$color_name, '', $line);
-
- $color_name = substr($color_name, 1, -1);
- }
- }
- $chunks = explode(' ', $line);
- $cmd = trim(array_pop($chunks));
-
- if (($cmd == 'Xa') OR ($cmd == 'XA')) {
- $b = array_pop($chunks);
- $g = array_pop($chunks);
- $r = array_pop($chunks);
- $this->_out(''.$r.' '.$g.' '.$b.' '.($cmd=='Xa'?'rg':'RG'));
- continue;
- }
- $skip = false;
- if ($fixoutvals) {
-
- switch ($cmd) {
- case 'm':
- case 'l':
- case 'L': {
-
- foreach ($chunks as $key => $val) {
- if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
- $skip = true;
- } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
- $skip = true;
- }
- }
- }
- }
- }
- switch ($cmd) {
- case 'm':
- case 'l':
- case 'v':
- case 'y':
- case 'c':
- case 'k':
- case 'K':
- case 'g':
- case 'G':
- case 's':
- case 'S':
- case 'J':
- case 'j':
- case 'w':
- case 'M':
- case 'd':
- case 'n': {
- if ($skip) {
- break;
- }
- $this->_out($line);
- break;
- }
- case 'x': {
- if (empty($color_name)) {
-
- list($col_c, $col_m, $col_y, $col_k) = $chunks;
- $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
- } else {
-
- list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
- $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
- $color_cmd = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
- $this->_out($color_cmd);
- }
- break;
- }
- case 'X': {
- if (empty($color_name)) {
-
- list($col_c, $col_m, $col_y, $col_k) = $chunks;
- $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
- } else {
-
- list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
- $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
- $color_cmd = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
- $this->_out($color_cmd);
- }
- break;
- }
- case 'Y':
- case 'N':
- case 'V':
- case 'L':
- case 'C': {
- if ($skip) {
- break;
- }
- $line[($len - 1)] = strtolower($cmd);
- $this->_out($line);
- break;
- }
- case 'b':
- case 'B': {
- $this->_out($cmd . '*');
- break;
- }
- case 'f':
- case 'F': {
- if ($u > 0) {
- $isU = false;
- $max = min(($i + 5), $cnt);
- for ($j = ($i + 1); $j < $max; ++$j) {
- $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
- }
- if ($isU) {
- $this->_out('f*');
- }
- } else {
- $this->_out('f*');
- }
- break;
- }
- case '*u': {
- ++$u;
- break;
- }
- case '*U': {
- --$u;
- break;
- }
- }
- }
-
- $this->_out($this->epsmarker.'Q');
- if (!empty($border)) {
- $bx = $this->x;
- $by = $this->y;
- $this->x = $ximg;
- if ($this->rtl) {
- $this->x += $w;
- }
- $this->y = $y;
- $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
- $this->x = $bx;
- $this->y = $by;
- }
- if ($link) {
- $this->Link($ximg, $y, $w, $h, $link, 0);
- }
-
- switch($align) {
- case 'T':{
- $this->y = $y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'M':{
- $this->y = $y + round($h/2);
- $this->x = $this->img_rb_x;
- break;
- }
- case 'B':{
- $this->y = $this->img_rb_y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'N':{
- $this->SetY($this->img_rb_y);
- break;
- }
- default:{
- break;
- }
- }
- $this->endlinex = $this->img_rb_x;
- }
-
- public function setBarcode($bc='') {
- $this->barcode = $bc;
- }
-
- public function getBarcode() {
- return $this->barcode;
- }
-
- public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') {
- if ($this->empty_string(trim($code))) {
- return;
- }
- require_once(dirname(__FILE__).'/barcodes.php');
-
- $gvars = $this->getGraphicVars();
-
- $barcodeobj = new TCPDFBarcode($code, $type);
- $arrcode = $barcodeobj->getBarcodeArray();
- if ($arrcode === false) {
- $this->Error('Error in 1D barcode string');
- }
-
- if (!isset($style['position'])) {
- $style['position'] = '';
- } elseif ($style['position'] == 'S') {
-
- $style['position'] = '';
- $style['stretch'] = true;
- }
- if (!isset($style['fitwidth'])) {
- if (!isset($style['stretch'])) {
- $style['fitwidth'] = true;
- } else {
- $style['fitwidth'] = false;
- }
- }
- if ($style['fitwidth']) {
-
- $style['stretch'] = false;
- }
- if (!isset($style['stretch'])) {
- if (($w === '') OR ($w <= 0)) {
- $style['stretch'] = false;
- } else {
- $style['stretch'] = true;
- }
- }
- if (!isset($style['fgcolor'])) {
- $style['fgcolor'] = array(0,0,0);
- }
- if (!isset($style['bgcolor'])) {
- $style['bgcolor'] = false;
- }
- if (!isset($style['border'])) {
- $style['border'] = false;
- }
- $fontsize = 0;
- if (!isset($style['text'])) {
- $style['text'] = false;
- }
- if ($style['text'] AND isset($style['font'])) {
- if (isset($style['fontsize'])) {
- $fontsize = $style['fontsize'];
- }
- $this->SetFont($style['font'], '', $fontsize);
- }
- if (!isset($style['stretchtext'])) {
- $style['stretchtext'] = 4;
- }
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- if (($w === '') OR ($w <= 0)) {
- if ($this->rtl) {
- $w = $x - $this->lMargin;
- } else {
- $w = $this->w - $this->rMargin - $x;
- }
- }
-
- if (!isset($style['padding'])) {
- $padding = 0;
- } elseif ($style['padding'] === 'auto') {
- $padding = 10 * ($w / ($arrcode['maxw'] + 20));
- } else {
- $padding = floatval($style['padding']);
- }
-
- if (!isset($style['hpadding'])) {
- $hpadding = $padding;
- } elseif ($style['hpadding'] === 'auto') {
- $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
- } else {
- $hpadding = floatval($style['hpadding']);
- }
-
- if (!isset($style['vpadding'])) {
- $vpadding = $padding;
- } elseif ($style['vpadding'] === 'auto') {
- $vpadding = ($hpadding / 2);
- } else {
- $vpadding = floatval($style['vpadding']);
- }
-
- $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
- if ($style['stretch']) {
- $xres = $max_xres;
- } else {
- if ($this->empty_string($xres)) {
- $xres = (0.141 * $this->k);
- }
- if ($xres > $max_xres) {
-
- $xres = $max_xres;
- }
- if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
- OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
- $hpadding = 10 * $xres;
- if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
- $vpadding = ($hpadding / 2);
- }
- }
- }
- if ($style['fitwidth']) {
- $wold = $w;
- $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
- if (isset($style['cellfitalign'])) {
- switch ($style['cellfitalign']) {
- case 'L': {
- if ($this->rtl) {
- $x -= ($wold - $w);
- }
- break;
- }
- case 'R': {
- if (!$this->rtl) {
- $x += ($wold - $w);
- }
- break;
- }
- case 'C': {
- if ($this->rtl) {
- $x -= (($wold - $w) / 2);
- } else {
- $x += (($wold - $w) / 2);
- }
- break;
- }
- default : {
- break;
- }
- }
- }
- }
- $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
-
- if (($h === '') OR ($h <= 0)) {
-
- $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
- }
- $barh = $h - $text_height - (2 * $vpadding);
- if ($barh <=0) {
-
- if ($text_height > $h) {
- $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
- $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
- $this->SetFont($style['font'], '', $fontsize);
- }
- if ($vpadding > 0) {
- $vpadding = (($h - $text_height) / 4);
- }
- $barh = $h - $text_height - (2 * $vpadding);
- }
-
- list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
-
- $this->img_rb_y = $y + $h;
-
- if ($this->rtl) {
- if ($style['position'] == 'L') {
- $xpos = $this->lMargin;
- } elseif ($style['position'] == 'C') {
- $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($style['position'] == 'R') {
- $xpos = $this->w - $this->rMargin - $w;
- } else {
- $xpos = $x - $w;
- }
- $this->img_rb_x = $xpos;
- } else {
- if ($style['position'] == 'L') {
- $xpos = $this->lMargin;
- } elseif ($style['position'] == 'C') {
- $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($style['position'] == 'R') {
- $xpos = $this->w - $this->rMargin - $w;
- } else {
- $xpos = $x;
- }
- $this->img_rb_x = $xpos + $w;
- }
- $xpos_rect = $xpos;
- if (!isset($style['align'])) {
- $style['align'] = 'C';
- }
- switch ($style['align']) {
- case 'L': {
- $xpos = $xpos_rect + $hpadding;
- break;
- }
- case 'R': {
- $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
- break;
- }
- case 'C':
- default : {
- $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
- break;
- }
- }
- $xpos_text = $xpos;
-
- $tempRTL = $this->rtl;
- $this->rtl = false;
-
- if ($style['bgcolor']) {
- $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
- } elseif ($style['border']) {
- $this->Rect($xpos_rect, $y, $w, $h, 'D');
- }
-
- $this->SetDrawColorArray($style['fgcolor']);
- $this->SetTextColorArray($style['fgcolor']);
-
- foreach ($arrcode['bcode'] as $k => $v) {
- $bw = ($v['w'] * $xres);
- if ($v['t']) {
-
- $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
- $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
- }
- $xpos += $bw;
- }
-
- if ($style['text']) {
- if (isset($style['label']) AND !$this->empty_string($style['label'])) {
- $label = $style['label'];
- } else {
- $label = $code;
- }
- $txtwidth = ($arrcode['maxw'] * $xres);
- if ($this->GetStringWidth($label) > $txtwidth) {
- $style['stretchtext'] = 2;
- }
-
- $this->x = $xpos_text;
- $this->y = $y + $vpadding + $barh;
- $cellpadding = $this->cell_padding;
- $this->SetCellPadding(0);
- $this->Cell($txtwidth, '', $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
- $this->cell_padding = $cellpadding;
- }
-
- $this->rtl = $tempRTL;
-
- $this->setGraphicVars($gvars);
-
- switch($align) {
- case 'T':{
- $this->y = $y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'M':{
- $this->y = $y + round($h / 2);
- $this->x = $this->img_rb_x;
- break;
- }
- case 'B':{
- $this->y = $this->img_rb_y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'N':{
- $this->SetY($this->img_rb_y);
- break;
- }
- default:{
- break;
- }
- }
- $this->endlinex = $this->img_rb_x;
- }
-
- public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) {
-
- $xres = 1 / $xres;
- $newstyle = array(
- 'position' => '',
- 'align' => '',
- 'stretch' => false,
- 'fitwidth' => false,
- 'cellfitalign' => '',
- 'border' => false,
- 'padding' => 0,
- 'fgcolor' => array(0,0,0),
- 'bgcolor' => false,
- 'text' => true,
- 'font' => $font,
- 'fontsize' => 8,
- 'stretchtext' => 4
- );
- if ($style & 1) {
- $newstyle['border'] = true;
- }
- if ($style & 2) {
- $newstyle['bgcolor'] = false;
- }
- if ($style & 4) {
- $newstyle['position'] = 'C';
- } elseif ($style & 8) {
- $newstyle['position'] = 'L';
- } elseif ($style & 16) {
- $newstyle['position'] = 'R';
- }
- if ($style & 128) {
- $newstyle['text'] = true;
- }
- if ($style & 256) {
- $newstyle['stretchtext'] = 4;
- }
- $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, '');
- }
-
- public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='', $distort=false) {
- if ($this->empty_string(trim($code))) {
- return;
- }
- require_once(dirname(__FILE__).'/2dbarcodes.php');
-
- $gvars = $this->getGraphicVars();
-
- $barcodeobj = new TCPDF2DBarcode($code, $type);
- $arrcode = $barcodeobj->getBarcodeArray();
- if (($arrcode === false) OR empty($arrcode)) {
- $this->Error('Error in 2D barcode string');
- }
-
- if (!isset($style['position'])) {
- $style['position'] = '';
- }
- if (!isset($style['fgcolor'])) {
- $style['fgcolor'] = array(0,0,0);
- }
- if (!isset($style['bgcolor'])) {
- $style['bgcolor'] = false;
- }
- if (!isset($style['border'])) {
- $style['border'] = false;
- }
-
- if (!isset($style['padding'])) {
- $style['padding'] = 0;
- } elseif ($style['padding'] === 'auto') {
- $style['padding'] = 4;
- }
- if (!isset($style['hpadding'])) {
- $style['hpadding'] = $style['padding'];
- } elseif ($style['hpadding'] === 'auto') {
- $style['hpadding'] = 4;
- }
- if (!isset($style['vpadding'])) {
- $style['vpadding'] = $style['padding'];
- } elseif ($style['vpadding'] === 'auto') {
- $style['vpadding'] = 4;
- }
- $hpad = (2 * $style['hpadding']);
- $vpad = (2 * $style['vpadding']);
-
- if (!isset($style['module_width'])) {
- $style['module_width'] = 1;
- }
- if (!isset($style['module_height'])) {
- $style['module_height'] = 1;
- }
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
-
- $rows = $arrcode['num_rows'];
- $cols = $arrcode['num_cols'];
-
- $mw = $style['module_width'];
- $mh = $style['module_height'];
-
- if ($this->rtl) {
- $maxw = $x - $this->lMargin;
- } else {
- $maxw = $this->w - $this->rMargin - $x;
- }
- $maxh = ($this->h - $this->tMargin - $this->bMargin);
- $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
- $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
- if (!$distort) {
- if (($maxw * $ratioHW) > $maxh) {
- $maxw = $maxh * $ratioWH;
- }
- if (($maxh * $ratioWH) > $maxw) {
- $maxh = $maxw * $ratioHW;
- }
- }
-
- if ($w > $maxw) {
- $w = $maxw;
- }
- if ($h > $maxh) {
- $h = $maxh;
- }
-
- if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
- $w = ($cols + $hpad) * ($mw / $this->k);
- $h = ($rows + $vpad) * ($mh / $this->k);
- } elseif (($w === '') OR ($w <= 0)) {
- $w = $h * $ratioWH;
- } elseif (($h === '') OR ($h <= 0)) {
- $h = $w * $ratioHW;
- }
-
- $bw = ($w * $cols) / ($cols + $hpad);
- $bh = ($h * $rows) / ($rows + $vpad);
-
- $cw = $bw / $cols;
- $ch = $bh / $rows;
- if (!$distort) {
- if (($cw / $ch) > ($mw / $mh)) {
-
- $cw = $ch * $mw / $mh;
- $bw = $cw * $cols;
- $style['hpadding'] = ($w - $bw) / (2 * $cw);
- } else {
-
- $ch = $cw * $mh / $mw;
- $bh = $ch * $rows;
- $style['vpadding'] = ($h - $bh) / (2 * $ch);
- }
- }
-
- list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
-
- $this->img_rb_y = $y + $h;
-
- if ($this->rtl) {
- if ($style['position'] == 'L') {
- $xpos = $this->lMargin;
- } elseif ($style['position'] == 'C') {
- $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($style['position'] == 'R') {
- $xpos = $this->w - $this->rMargin - $w;
- } else {
- $xpos = $x - $w;
- }
- $this->img_rb_x = $xpos;
- } else {
- if ($style['position'] == 'L') {
- $xpos = $this->lMargin;
- } elseif ($style['position'] == 'C') {
- $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($style['position'] == 'R') {
- $xpos = $this->w - $this->rMargin - $w;
- } else {
- $xpos = $x;
- }
- $this->img_rb_x = $xpos + $w;
- }
- $xstart = $xpos + ($style['hpadding'] * $cw);
- $ystart = $y + ($style['vpadding'] * $ch);
-
- $tempRTL = $this->rtl;
- $this->rtl = false;
-
- if ($style['bgcolor']) {
- $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
- } elseif ($style['border']) {
- $this->Rect($xpos, $y, $w, $h, 'D');
- }
-
- $this->SetDrawColorArray($style['fgcolor']);
-
-
- for ($r = 0; $r < $rows; ++$r) {
- $xr = $xstart;
-
- for ($c = 0; $c < $cols; ++$c) {
- if ($arrcode['bcode'][$r][$c] == 1) {
-
- $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
- }
- $xr += $cw;
- }
- $ystart += $ch;
- }
-
- $this->rtl = $tempRTL;
-
- $this->setGraphicVars($gvars);
-
- switch($align) {
- case 'T':{
- $this->y = $y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'M':{
- $this->y = $y + round($h/2);
- $this->x = $this->img_rb_x;
- break;
- }
- case 'B':{
- $this->y = $this->img_rb_y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'N':{
- $this->SetY($this->img_rb_y);
- break;
- }
- default:{
- break;
- }
- }
- $this->endlinex = $this->img_rb_x;
- }
-
- public function getMargins() {
- $ret = array(
- 'left' => $this->lMargin,
- 'right' => $this->rMargin,
- 'top' => $this->tMargin,
- 'bottom' => $this->bMargin,
- 'header' => $this->header_margin,
- 'footer' => $this->footer_margin,
- 'cell' => $this->cell_padding,
- 'padding_left' => $this->cell_padding['L'],
- 'padding_top' => $this->cell_padding['T'],
- 'padding_right' => $this->cell_padding['R'],
- 'padding_bottom' => $this->cell_padding['B']
- );
- return $ret;
- }
-
- public function getOriginalMargins() {
- $ret = array(
- 'left' => $this->original_lMargin,
- 'right' => $this->original_rMargin
- );
- return $ret;
- }
-
- public function getFontSize() {
- return $this->FontSize;
- }
-
- public function getFontSizePt() {
- return $this->FontSizePt;
- }
-
- public function getFontFamily() {
- return $this->FontFamily;
- }
-
- public function getFontStyle() {
- return $this->FontStyle;
- }
-
- public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') {
-
- if ($tidy_options === '') {
- $tidy_options = array (
- 'clean' => 1,
- 'drop-empty-paras' => 0,
- 'drop-proprietary-attributes' => 1,
- 'fix-backslash' => 1,
- 'hide-comments' => 1,
- 'join-styles' => 1,
- 'lower-literals' => 1,
- 'merge-divs' => 1,
- 'merge-spans' => 1,
- 'output-xhtml' => 1,
- 'word-2000' => 1,
- 'wrap' => 0,
- 'output-bom' => 0,
-
-
-
- );
- }
-
- $tidy = tidy_parse_string($html, $tidy_options);
-
- $tidy->cleanRepair();
-
- $tidy_head = tidy_get_head($tidy);
- $css = $tidy_head->value;
- $css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
- $css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
- $css = str_replace('/*<![CDATA[*/', '', $css);
- $css = str_replace('/*]]>*/', '', $css);
- preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
- if (isset($matches[1])) {
- $css = strtolower($matches[1]);
- } else {
- $css = '';
- }
-
- $css = '<style>'.$default_css.$css.'</style>';
-
- $tidy_body = tidy_get_body($tidy);
- $html = $tidy_body->value;
-
- $html = str_replace('<br>', '<br />', $html);
-
- $html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
- $html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
- if ($tagvs !== '') {
-
- $this->setHtmlVSpace($tagvs);
- }
-
- return $css.$html;
- }
-
- protected function extractCSSproperties($cssdata) {
- if (empty($cssdata)) {
- return array();
- }
-
- $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
-
- $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
-
- $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
-
- $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
-
- $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
- $cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
-
- $cssdata = trim($cssdata);
-
- $cssblocks = array();
- $matches = array();
- if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
- foreach ($matches[1] as $key => $type) {
- $cssblocks[$type] = $matches[2][$key];
- }
-
- $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
- }
-
- if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
- $cssdata .= $cssblocks['all'];
- }
- if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
- $cssdata .= $cssblocks['print'];
- }
-
- $cssblocks = array();
- $matches = array();
-
- if (substr($cssdata, -1) == '}') {
-
- $cssdata = substr($cssdata, 0, -1);
- }
- $matches = explode('}', $cssdata);
- foreach ($matches as $key => $block) {
-
- $cssblocks[$key] = explode('{', $block);
- if (!isset($cssblocks[$key][1])) {
-
- unset($cssblocks[$key]);
- }
- }
-
- foreach ($cssblocks as $key => $block) {
- if (strpos($block[0], ',') > 0) {
- $selectors = explode(',', $block[0]);
- foreach ($selectors as $sel) {
- $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
- }
- unset($cssblocks[$key]);
- }
- }
-
- $cssdata = array();
- foreach ($cssblocks as $block) {
- $selector = $block[0];
-
- $matches = array();
- $a = 0;
- $b = intval(preg_match_all('/[\#]/', $selector, $matches));
- $c = intval(preg_match_all('/[\[\.]/', $selector, $matches));
- $c += intval(preg_match_all('/[\:]link|visited|hover|active|focus|target|lang|enabled|disabled|checked|indeterminate|root|nth|first|last|only|empty|contains|not/i', $selector, $matches));
- $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches));
- $d += intval(preg_match_all('/[\:][\:]/', $selector, $matches));
- $specificity = $a.$b.$c.$d;
-
- $cssdata[$specificity.' '.$selector] = $block[1];
- }
-
- ksort($cssdata, SORT_STRING);
-
- return $cssdata;
- }
-
- protected function isValidCSSSelectorForTag($dom, $key, $selector) {
- $valid = false;
- $tag = $dom[$key]['value'];
- $class = array();
- if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
- $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
- }
- $id = '';
- if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
- $id = strtolower($dom[$key]['attribute']['id']);
- }
- $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
- $matches = array();
- if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
- $parentop = array_pop($matches[1]);
- $operator = $parentop[0];
- $offset = $parentop[1];
- $lasttag = array_pop($matches[2]);
- $lasttag = strtolower(trim($lasttag[0]));
- if (($lasttag == '*') OR ($lasttag == $tag)) {
-
- $attrib = array_pop($matches[3]);
- $attrib = strtolower(trim($attrib[0]));
- if (!empty($attrib)) {
-
- switch ($attrib{0}) {
- case '.': {
- if (in_array(substr($attrib, 1), $class)) {
- $valid = true;
- }
- break;
- }
- case '#': {
- if (substr($attrib, 1) == $id) {
- $valid = true;
- }
- break;
- }
- case '[': {
- $attrmatch = array();
- if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
- $att = strtolower($attrmatch[1]);
- $val = $attrmatch[3];
- if (isset($dom[$key]['attribute'][$att])) {
- switch ($attrmatch[2]) {
- case '=': {
- if ($dom[$key]['attribute'][$att] == $val) {
- $valid = true;
- }
- break;
- }
- case '~=': {
- if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
- $valid = true;
- }
- break;
- }
- case '^=': {
- if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
- $valid = true;
- }
- break;
- }
- case '$=': {
- if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
- $valid = true;
- }
- break;
- }
- case '*=': {
- if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
- $valid = true;
- }
- break;
- }
- case '|=': {
- if ($dom[$key]['attribute'][$att] == $val) {
- $valid = true;
- } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
- $valid = true;
- }
- break;
- }
- default: {
- $valid = true;
- }
- }
- }
- }
- break;
- }
- case ':': {
- if ($attrib{1} == ':') {
-
-
- } else {
-
-
- }
- break;
- }
- }
- } else {
- $valid = true;
- }
- if ($valid AND ($offset > 0)) {
- $valid = false;
-
- $selector = substr($selector, 0, $offset);
- switch ($operator) {
- case ' ': {
- while ($dom[$key]['parent'] > 0) {
- if ($this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
- $valid = true;
- break;
- } else {
- $key = $dom[$key]['parent'];
- }
- }
- break;
- }
- case '>': {
- $valid = $this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
- break;
- }
- case '+': {
- for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
- if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
- $valid = $this->isValidCSSSelectorForTag($dom, $i, $selector);
- break;
- }
- }
- break;
- }
- case '~': {
- for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
- if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
- if ($this->isValidCSSSelectorForTag($dom, $i, $selector)) {
- break;
- }
- }
- }
- break;
- }
- }
- }
- }
- }
- return $valid;
- }
-
- protected function getCSSdataArray($dom, $key, $css) {
- $cssarray = array();
-
- $selectors = array();
- if (isset($dom[($dom[$key]['parent'])]['csssel'])) {
- $selectors = $dom[($dom[$key]['parent'])]['csssel'];
- }
-
- foreach($css as $selector => $style) {
- $pos = strpos($selector, ' ');
-
- $specificity = substr($selector, 0, $pos);
-
- $selector = substr($selector, $pos);
-
- if ($this->isValidCSSSelectorForTag($dom, $key, $selector)) {
- if (!in_array($selector, $selectors)) {
-
- $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style);
- $selectors[] = $selector;
- }
- }
- }
- if (isset($dom[$key]['attribute']['style'])) {
-
- $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']);
- }
-
- $cssordered = array();
- foreach ($cssarray as $key => $val) {
- $skey = sprintf('%04d', $key);
- $cssordered[$val['s'].'_'.$skey] = $val;
- }
-
- ksort($cssordered, SORT_STRING);
- return array($selectors, $cssordered);
- }
-
- protected function getTagStyleFromCSSarray($css) {
- $tagstyle = '';
- foreach ($css as $style) {
-
- $csscmds = explode(';', $style['c']);
- foreach ($csscmds as $cmd) {
- if (!empty($cmd)) {
- $pos = strpos($cmd, ':');
- if ($pos !== false) {
- $cmd = substr($cmd, 0, ($pos + 1));
- if (strpos($tagstyle, $cmd) !== false) {
-
- $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle);
- }
- }
- }
- }
- $tagstyle .= ';'.$style['c'];
- }
-
- $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
- return $tagstyle;
- }
-
- protected function getCSSBorderWidth($width) {
- if ($width == 'thin') {
- $width = (2 / $this->k);
- } elseif ($width == 'medium') {
- $width = (4 / $this->k);
- } elseif ($width == 'thick') {
- $width = (6 / $this->k);
- } else {
- $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
- }
- return $width;
- }
-
- protected function getCSSBorderDashStyle($style) {
- switch (strtolower($style)) {
- case 'none':
- case 'hidden': {
- $dash = -1;
- break;
- }
- case 'dotted': {
- $dash = 1;
- break;
- }
- case 'dashed': {
- $dash = 3;
- break;
- }
- case 'double':
- case 'groove':
- case 'ridge':
- case 'inset':
- case 'outset':
- case 'solid':
- default: {
- $dash = 0;
- break;
- }
- }
- return $dash;
- }
-
- protected function getCSSBorderStyle($cssborder) {
- $bprop = preg_split('/[\s]+/', trim($cssborder));
- $border = array();
- switch (count($bprop)) {
- case 3: {
- $width = $bprop[0];
- $style = $bprop[1];
- $color = $bprop[2];
- break;
- }
- case 2: {
- $width = 'medium';
- $style = $bprop[0];
- $color = $bprop[1];
- break;
- }
- case 1: {
- $width = 'medium';
- $style = $bprop[0];
- $color = 'black';
- break;
- }
- default: {
- $width = 'medium';
- $style = 'solid';
- $color = 'black';
- break;
- }
- }
- if ($style == 'none') {
- return array();
- }
- $border['cap'] = 'square';
- $border['join'] = 'miter';
- $border['dash'] = $this->getCSSBorderDashStyle($style);
- if ($border['dash'] < 0) {
- return array();
- }
- $border['width'] = $this->getCSSBorderWidth($width);
- $border['color'] = $this->convertHTMLColorToDec($color);
- return $border;
- }
-
- public function getCSSPadding($csspadding, $width=0) {
- $padding = preg_split('/[\s]+/', trim($csspadding));
- $cell_padding = array();
- switch (count($padding)) {
- case 4: {
- $cell_padding['T'] = $padding[0];
- $cell_padding['R'] = $padding[1];
- $cell_padding['B'] = $padding[2];
- $cell_padding['L'] = $padding[3];
- break;
- }
- case 3: {
- $cell_padding['T'] = $padding[0];
- $cell_padding['R'] = $padding[1];
- $cell_padding['B'] = $padding[2];
- $cell_padding['L'] = $padding[1];
- break;
- }
- case 2: {
- $cell_padding['T'] = $padding[0];
- $cell_padding['R'] = $padding[1];
- $cell_padding['B'] = $padding[0];
- $cell_padding['L'] = $padding[1];
- break;
- }
- case 1: {
- $cell_padding['T'] = $padding[0];
- $cell_padding['R'] = $padding[0];
- $cell_padding['B'] = $padding[0];
- $cell_padding['L'] = $padding[0];
- break;
- }
- default: {
- return $this->cell_padding;
- }
- }
- if ($width == 0) {
- $width = $this->w - $this->lMargin - $this->rMargin;
- }
- $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
- $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
- $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
- $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
- return $cell_padding;
- }
-
- public function getCSSMargin($cssmargin, $width=0) {
- $margin = preg_split('/[\s]+/', trim($cssmargin));
- $cell_margin = array();
- switch (count($margin)) {
- case 4: {
- $cell_margin['T'] = $margin[0];
- $cell_margin['R'] = $margin[1];
- $cell_margin['B'] = $margin[2];
- $cell_margin['L'] = $margin[3];
- break;
- }
- case 3: {
- $cell_margin['T'] = $margin[0];
- $cell_margin['R'] = $margin[1];
- $cell_margin['B'] = $margin[2];
- $cell_margin['L'] = $margin[1];
- break;
- }
- case 2: {
- $cell_margin['T'] = $margin[0];
- $cell_margin['R'] = $margin[1];
- $cell_margin['B'] = $margin[0];
- $cell_margin['L'] = $margin[1];
- break;
- }
- case 1: {
- $cell_margin['T'] = $margin[0];
- $cell_margin['R'] = $margin[0];
- $cell_margin['B'] = $margin[0];
- $cell_margin['L'] = $margin[0];
- break;
- }
- default: {
- return $this->cell_margin;
- }
- }
- if ($width == 0) {
- $width = $this->w - $this->lMargin - $this->rMargin;
- }
- $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
- $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
- $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
- $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
- return $cell_margin;
- }
-
- public function getCSSBorderMargin($cssbspace, $width=0) {
- $space = preg_split('/[\s]+/', trim($cssbspace));
- $border_spacing = array();
- switch (count($space)) {
- case 2: {
- $border_spacing['H'] = $space[0];
- $border_spacing['V'] = $space[1];
- break;
- }
- case 1: {
- $border_spacing['H'] = $space[0];
- $border_spacing['V'] = $space[0];
- break;
- }
- default: {
- return array('H' => 0, 'V' => 0);
- }
- }
- if ($width == 0) {
- $width = $this->w - $this->lMargin - $this->rMargin;
- }
- $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
- $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
- return $border_spacing;
- }
-
- protected function getCSSFontSpacing($spacing, $parent=0) {
- $val = 0;
- $spacing = trim($spacing);
- switch ($spacing) {
- case 'normal': {
- $val = 0;
- break;
- }
- case 'inherit': {
- if ($parent == 'normal') {
- $val = 0;
- } else {
- $val = $parent;
- }
- break;
- }
- default: {
- $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
- }
- }
- return $val;
- }
-
- protected function getCSSFontStretching($stretch, $parent=100) {
- $val = 100;
- $stretch = trim($stretch);
- switch ($stretch) {
- case 'ultra-condensed': {
- $val = 40;
- break;
- }
- case 'extra-condensed': {
- $val = 55;
- break;
- }
- case 'condensed': {
- $val = 70;
- break;
- }
- case 'semi-condensed': {
- $val = 85;
- break;
- }
- case 'normal': {
- $val = 100;
- break;
- }
- case 'semi-expanded': {
- $val = 115;
- break;
- }
- case 'expanded': {
- $val = 130;
- break;
- }
- case 'extra-expanded': {
- $val = 145;
- break;
- }
- case 'ultra-expanded': {
- $val = 160;
- break;
- }
- case 'wider': {
- $val = $parent + 10;
- break;
- }
- case 'narrower': {
- $val = $parent - 10;
- break;
- }
- case 'inherit': {
- if ($parent == 'normal') {
- $val = 100;
- } else {
- $val = $parent;
- }
- break;
- }
- default: {
- $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
- }
- }
- return $val;
- }
-
- protected function getHtmlDomArray($html) {
-
- $css = array();
-
- $matches = array();
- if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
- if (isset($matches[1][0])) {
- $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
- }
- $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
- }
-
- $matches = array();
- if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
- foreach ($matches[1] as $key => $link) {
- $type = array();
- if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
- $type = array();
- preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
-
-
- if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
- $type = array();
- if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
-
- $cssdata = file_get_contents(trim($type[1]));
- $css = array_merge($css, $this->extractCSSproperties($cssdata));
- }
- }
- }
- }
- }
-
- $matches = array();
- if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
- foreach ($matches[1] as $key => $media) {
- $type = array();
- preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
-
-
- if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
- $cssdata = $matches[2][$key];
- $css = array_merge($css, $this->extractCSSproperties($cssdata));
- }
- }
- }
-
- $csstagarray = '<cssarray>'.htmlentities(serialize($css)).'</cssarray>';
-
- $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
- $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
-
- $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
-
- $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
-
- $html = strip_tags($html, '<marker/><a><b><blockquote><body><br><br/><dd><del><div><dl><dt><em><font><form><h1><h2><h3><h4><h5><h6><hr><hr/><i><img><input><label><li><ol><option><p><pre><s><select><small><span><strike><strong><sub><sup><table><tablehead><tcpdf><td><textarea><th><thead><tr><tt><u><ul>');
-
- $html = preg_replace('/<pre/', '<xre', $html);
- $html = preg_replace('/<(table|tr|td|th|tcpdf|blockquote|dd|div|dl|dt|form|h1|h2|h3|h4|h5|h6|br|hr|li|ol|ul|p)([^\>]*)>[\n\r\t]+/', '<\\1\\2>', $html);
- $html = preg_replace('@(\r\n|\r)@', "\n", $html);
- $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
- $html = strtr($html, $repTable);
- $offset = 0;
- while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
- $html_a = substr($html, 0, $offset);
- $html_b = substr($html, $offset, ($pos - $offset + 6));
- while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
-
- $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
- }
- while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
-
- $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2 \\3</pre>", $html_b);
- }
- $html = $html_a.$html_b.substr($html, $pos + 6);
- $offset = strlen($html_a.$html_b);
- }
- $offset = 0;
- while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
- $html_a = substr($html, 0, $offset);
- $html_b = substr($html, $offset, ($pos - $offset + 11));
- while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
-
- $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
- $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
- }
- $html = $html_a.$html_b.substr($html, $pos + 11);
- $offset = strlen($html_a.$html_b);
- }
- $html = preg_replace('/([\s]*)<option/si', '<option', $html);
- $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
- $offset = 0;
- while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
- $html_a = substr($html, 0, $offset);
- $html_b = substr($html, $offset, ($pos - $offset + 9));
- while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
- $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
- $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
- }
- $html = $html_a.$html_b.substr($html, $pos + 9);
- $offset = strlen($html_a.$html_b);
- }
- if (preg_match("'</select'si", $html)) {
- $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
- $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
- }
- $html = str_replace("\n", ' ', $html);
-
- $html = str_replace('<TBR>', "\n", $html);
-
- $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
- $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
- $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
- $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
- $html = preg_replace('/<\/(table|tr|td|th|blockquote|dd|dt|dl|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|ul|p)>[\s]+</', '</\\1><', $html);
- $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
- $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
- $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
- $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1> \\2', $html);
- $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
- $html = preg_replace('/<xre/', '<pre', $html);
- $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
- $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1> </li>', $html);
- $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1"> </font><img', $html);
- $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1> ', $html);
- $html = preg_replace('/[\s]<\/([^\>]*)>/', ' </\\1>', $html);
- $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html);
-
- $html = $this->stringTrim($html);
-
- $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
-
- $tagpattern = '/(<[^>]+>)/';
-
- $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
-
- $maxel = count($a);
- $elkey = 0;
- $key = 0;
-
- $dom = array();
- $dom[$key] = array();
-
-
- $dom[$key]['tag'] = false;
- $dom[$key]['block'] = false;
- $dom[$key]['value'] = '';
- $dom[$key]['parent'] = 0;
- $dom[$key]['hide'] = false;
- $dom[$key]['fontname'] = $this->FontFamily;
- $dom[$key]['fontstyle'] = $this->FontStyle;
- $dom[$key]['fontsize'] = $this->FontSizePt;
- $dom[$key]['font-stretch'] = $this->font_stretching;
- $dom[$key]['letter-spacing'] = $this->font_spacing;
- $dom[$key]['stroke'] = $this->textstrokewidth;
- $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
- $dom[$key]['clip'] = ($this->textrendermode > 3);
- $dom[$key]['line-height'] = $this->cell_height_ratio;
- $dom[$key]['bgcolor'] = false;
- $dom[$key]['fgcolor'] = $this->fgcolor;
- $dom[$key]['strokecolor'] = $this->strokecolor;
- $dom[$key]['align'] = '';
- $dom[$key]['listtype'] = '';
- $dom[$key]['text-indent'] = 0;
- $dom[$key]['border'] = array();
- $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
- $thead = false;
- ++$key;
- $level = array();
- array_push($level, 0);
- while ($elkey < $maxel) {
- $dom[$key] = array();
- $element = $a[$elkey];
- $dom[$key]['elkey'] = $elkey;
- if (preg_match($tagpattern, $element)) {
-
- $element = substr($element, 1, -1);
-
- preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
- $tagname = strtolower($tag[1]);
-
- if ($tagname == 'thead') {
- if ($element{0} == '/') {
- $thead = false;
- } else {
- $thead = true;
- }
- ++$elkey;
- continue;
- }
- $dom[$key]['tag'] = true;
- $dom[$key]['value'] = $tagname;
- if (in_array($dom[$key]['value'], $blocktags)) {
- $dom[$key]['block'] = true;
- } else {
- $dom[$key]['block'] = false;
- }
- if ($element{0} == '/') {
-
- $dom[$key]['opening'] = false;
- $dom[$key]['parent'] = end($level);
- array_pop($level);
- $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
- $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
- $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
- $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
- $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
- $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
- $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
- $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
- $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
- $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
- $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
- $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
- $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
- $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
- $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
- if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
- $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
- }
-
- if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
- $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
- }
- if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
- $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
- for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
- $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
- }
- $key = $i;
-
- $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
-
- $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
- $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
- }
-
- if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
- if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
- $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
- }
- for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
- $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
- }
- if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
- $dom[($dom[$key]['parent'])]['attribute'] = array();
- }
-
- $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
- }
- if (($dom[$key]['value'] == 'table') AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) {
-
- $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
- $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
- }
- } else {
-
- $dom[$key]['opening'] = true;
- $dom[$key]['parent'] = end($level);
- if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
-
- $dom[$key]['self'] = true;
- } else {
-
- array_push($level, $key);
- $dom[$key]['self'] = false;
- }
-
- $parentkey = 0;
- if ($key > 0) {
- $parentkey = $dom[$key]['parent'];
- $dom[$key]['hide'] = $dom[$parentkey]['hide'];
- $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
- $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
- $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
- $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
- $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
- $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
- $dom[$key]['fill'] = $dom[$parentkey]['fill'];
- $dom[$key]['clip'] = $dom[$parentkey]['clip'];
- $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
- $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
- $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
- $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
- $dom[$key]['align'] = $dom[$parentkey]['align'];
- $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
- $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
- $dom[$key]['border'] = array();
- $dom[$key]['dir'] = $dom[$parentkey]['dir'];
- }
-
- preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
- $dom[$key]['attribute'] = array();
- while (list($id, $name) = each($attr_array[1])) {
- $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
- }
- if (!empty($css)) {
-
- list($dom[$key]['csssel'], $dom[$key]['cssdata']) = $this->getCSSdataArray($dom, $key, $css);
- $dom[$key]['attribute']['style'] = $this->getTagStyleFromCSSarray($dom[$key]['cssdata']);
- }
-
- if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
-
- preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
- $dom[$key]['style'] = array();
- while (list($id, $name) = each($style_array[1])) {
-
- $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
- }
-
-
- if (isset($dom[$key]['style']['direction'])) {
- $dom[$key]['dir'] = $dom[$key]['style']['direction'];
- }
-
- if (isset($dom[$key]['style']['display'])) {
- $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
- }
-
- if (isset($dom[$key]['style']['font-family'])) {
- $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
- }
-
- if (isset($dom[$key]['style']['list-style-type'])) {
- $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
- if ($dom[$key]['listtype'] == 'inherit') {
- $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
- }
- }
-
- if (isset($dom[$key]['style']['text-indent'])) {
- $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
- if ($dom[$key]['text-indent'] == 'inherit') {
- $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
- }
- }
-
- if (isset($dom[$key]['style']['font-size'])) {
- $fsize = trim($dom[$key]['style']['font-size']);
- switch ($fsize) {
-
- case 'xx-small': {
- $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4;
- break;
- }
- case 'x-small': {
- $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3;
- break;
- }
- case 'small': {
- $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2;
- break;
- }
- case 'medium': {
- $dom[$key]['fontsize'] = $dom[0]['fontsize'];
- break;
- }
- case 'large': {
- $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 2;
- break;
- }
- case 'x-large': {
- $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 4;
- break;
- }
- case 'xx-large': {
- $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 6;
- break;
- }
-
- case 'smaller': {
- $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3;
- break;
- }
- case 'larger': {
- $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] + 3;
- break;
- }
- default: {
- $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true);
- }
- }
- }
-
- if (isset($dom[$key]['style']['font-stretch'])) {
- $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
- }
-
- if (isset($dom[$key]['style']['letter-spacing'])) {
- $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
- }
-
- if (isset($dom[$key]['style']['line-height'])) {
- $lineheight = trim($dom[$key]['style']['line-height']);
- switch ($lineheight) {
-
- case 'normal': {
- $dom[$key]['line-height'] = $dom[0]['line-height'];
- break;
- }
- default: {
- if (is_numeric($lineheight)) {
- $lineheight = $lineheight * 100;
- }
- $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
- }
- }
- }
-
- if (isset($dom[$key]['style']['font-weight'])) {
- if (strtolower($dom[$key]['style']['font-weight']{0}) == 'n') {
- if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
- $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
- }
- } elseif (strtolower($dom[$key]['style']['font-weight']{0}) == 'b') {
- $dom[$key]['fontstyle'] .= 'B';
- }
- }
- if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) {
- $dom[$key]['fontstyle'] .= 'I';
- }
-
- if (isset($dom[$key]['style']['color']) AND (!$this->empty_string($dom[$key]['style']['color']))) {
- $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']);
- } elseif ($dom[$key]['value'] == 'a') {
- $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
- }
-
- if (isset($dom[$key]['style']['background-color']) AND (!$this->empty_string($dom[$key]['style']['background-color']))) {
- $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
- }
-
- if (isset($dom[$key]['style']['text-decoration'])) {
- $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
- foreach ($decors as $dec) {
- $dec = trim($dec);
- if (!$this->empty_string($dec)) {
- if ($dec{0} == 'u') {
-
- $dom[$key]['fontstyle'] .= 'U';
- } elseif ($dec{0} == 'l') {
-
- $dom[$key]['fontstyle'] .= 'D';
- } elseif ($dec{0} == 'o') {
-
- $dom[$key]['fontstyle'] .= 'O';
- }
- }
- }
- } elseif ($dom[$key]['value'] == 'a') {
- $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
- }
-
- if (isset($dom[$key]['style']['width'])) {
- $dom[$key]['width'] = $dom[$key]['style']['width'];
- }
-
- if (isset($dom[$key]['style']['height'])) {
- $dom[$key]['height'] = $dom[$key]['style']['height'];
- }
-
- if (isset($dom[$key]['style']['text-align'])) {
- $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0});
- }
-
- if (isset($dom[$key]['style']['border'])) {
- $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
- if (!empty($borderstyle)) {
- $dom[$key]['border']['LTRB'] = $borderstyle;
- }
- }
- if (isset($dom[$key]['style']['border-color'])) {
- $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
- if (isset($brd_colors[3])) {
- $dom[$key]['border']['L']['color'] = $this->convertHTMLColorToDec($brd_colors[3]);
- }
- if (isset($brd_colors[1])) {
- $dom[$key]['border']['R']['color'] = $this->convertHTMLColorToDec($brd_colors[1]);
- }
- if (isset($brd_colors[0])) {
- $dom[$key]['border']['T']['color'] = $this->convertHTMLColorToDec($brd_colors[0]);
- }
- if (isset($brd_colors[2])) {
- $dom[$key]['border']['B']['color'] = $this->convertHTMLColorToDec($brd_colors[2]);
- }
- }
- if (isset($dom[$key]['style']['border-width'])) {
- $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
- if (isset($brd_widths[3])) {
- $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
- }
- if (isset($brd_widths[1])) {
- $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
- }
- if (isset($brd_widths[0])) {
- $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
- }
- if (isset($brd_widths[2])) {
- $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
- }
- }
- if (isset($dom[$key]['style']['border-style'])) {
- $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
- if (isset($brd_styles[3])) {
- $dom[$key]['border']['L']['cap'] = 'square';
- $dom[$key]['border']['L']['join'] = 'miter';
- $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
- if ($dom[$key]['border']['L']['dash'] < 0) {
- $dom[$key]['border']['L'] = array();
- }
- }
- if (isset($brd_styles[1])) {
- $dom[$key]['border']['R']['cap'] = 'square';
- $dom[$key]['border']['R']['join'] = 'miter';
- $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
- if ($dom[$key]['border']['R']['dash'] < 0) {
- $dom[$key]['border']['R'] = array();
- }
- }
- if (isset($brd_styles[0])) {
- $dom[$key]['border']['T']['cap'] = 'square';
- $dom[$key]['border']['T']['join'] = 'miter';
- $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
- if ($dom[$key]['border']['T']['dash'] < 0) {
- $dom[$key]['border']['T'] = array();
- }
- }
- if (isset($brd_styles[2])) {
- $dom[$key]['border']['B']['cap'] = 'square';
- $dom[$key]['border']['B']['join'] = 'miter';
- $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
- if ($dom[$key]['border']['B']['dash'] < 0) {
- $dom[$key]['border']['B'] = array();
- }
- }
- }
- $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
- foreach ($cellside as $bsk => $bsv) {
- if (isset($dom[$key]['style']['border-'.$bsv])) {
- $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
- if (!empty($borderstyle)) {
- $dom[$key]['border'][$bsk] = $borderstyle;
- }
- }
- if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
- $dom[$key]['border'][$bsk]['color'] = $this->convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color']);
- }
- if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
- $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
- }
- if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
- $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
- if ($dom[$key]['border'][$bsk]['dash'] < 0) {
- $dom[$key]['border'][$bsk] = array();
- }
- }
- }
-
- if (isset($dom[$key]['style']['padding'])) {
- $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
- } else {
- $dom[$key]['padding'] = $this->cell_padding;
- }
- foreach ($cellside as $psk => $psv) {
- if (isset($dom[$key]['style']['padding-'.$psv])) {
- $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
- }
- }
-
- if (isset($dom[$key]['style']['margin'])) {
- $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
- } else {
- $dom[$key]['margin'] = $this->cell_margin;
- }
- foreach ($cellside as $psk => $psv) {
- if (isset($dom[$key]['style']['margin-'.$psv])) {
- $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
- }
- }
-
- if (isset($dom[$key]['style']['border-spacing'])) {
- $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
- }
-
- if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
- $dom[$key]['attribute']['nobr'] = 'true';
- }
-
- if (isset($dom[$key]['style']['page-break-before'])) {
- if ($dom[$key]['style']['page-break-before'] == 'always') {
- $dom[$key]['attribute']['pagebreak'] = 'true';
- } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
- $dom[$key]['attribute']['pagebreak'] = 'left';
- } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
- $dom[$key]['attribute']['pagebreak'] = 'right';
- }
- }
-
- if (isset($dom[$key]['style']['page-break-after'])) {
- if ($dom[$key]['style']['page-break-after'] == 'always') {
- $dom[$key]['attribute']['pagebreakafter'] = 'true';
- } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
- $dom[$key]['attribute']['pagebreakafter'] = 'left';
- } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
- $dom[$key]['attribute']['pagebreakafter'] = 'right';
- }
- }
- }
- if (isset($dom[$key]['attribute']['display'])) {
- $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
- }
- if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
- $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
- if (!empty($borderstyle)) {
- $dom[$key]['border']['LTRB'] = $borderstyle;
- }
- }
-
- if ($dom[$key]['value'] == 'font') {
-
- if (isset($dom[$key]['attribute']['face'])) {
- $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
- }
-
- if (isset($dom[$key]['attribute']['size'])) {
- if ($key > 0) {
- if ($dom[$key]['attribute']['size']{0} == '+') {
- $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
- } elseif ($dom[$key]['attribute']['size']{0} == '-') {
- $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
- } else {
- $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
- }
- } else {
- $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
- }
- }
- }
-
- if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
- AND (!isset($dom[$key]['align']) OR $this->empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
- if ($this->rtl) {
- $dom[$key]['align'] = 'R';
- } else {
- $dom[$key]['align'] = 'L';
- }
- }
- if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
- if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
- $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
- }
- }
- if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
- $dom[$key]['fontstyle'] .= 'B';
- }
- if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
- $dom[$key]['fontstyle'] .= 'I';
- }
- if ($dom[$key]['value'] == 'u') {
- $dom[$key]['fontstyle'] .= 'U';
- }
- if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
- $dom[$key]['fontstyle'] .= 'D';
- }
- if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
- $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
- }
- if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
- $dom[$key]['fontname'] = $this->default_monospaced_font;
- }
- if (($dom[$key]['value']{0} == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
-
- if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
- $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
- $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
- }
- if (!isset($dom[$key]['style']['font-weight'])) {
- $dom[$key]['fontstyle'] .= 'B';
- }
- }
- if (($dom[$key]['value'] == 'table')) {
- $dom[$key]['rows'] = 0;
- $dom[$key]['trids'] = array();
- $dom[$key]['thead'] = '';
- }
- if (($dom[$key]['value'] == 'tr')) {
- $dom[$key]['cols'] = 0;
- if ($thead) {
- $dom[$key]['thead'] = true;
-
- } else {
- $dom[$key]['thead'] = false;
-
- ++$dom[($dom[$key]['parent'])]['rows'];
-
- array_push($dom[($dom[$key]['parent'])]['trids'], $key);
- }
- }
- if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
- if (isset($dom[$key]['attribute']['colspan'])) {
- $colspan = intval($dom[$key]['attribute']['colspan']);
- } else {
- $colspan = 1;
- }
- $dom[$key]['attribute']['colspan'] = $colspan;
- $dom[($dom[$key]['parent'])]['cols'] += $colspan;
- }
-
- if (isset($dom[$key]['attribute']['dir'])) {
- $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
- }
-
- if (isset($dom[$key]['attribute']['color']) AND (!$this->empty_string($dom[$key]['attribute']['color']))) {
- $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
- } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
- $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
- }
-
- if (isset($dom[$key]['attribute']['bgcolor']) AND (!$this->empty_string($dom[$key]['attribute']['bgcolor']))) {
- $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
- }
-
- if (isset($dom[$key]['attribute']['strokecolor']) AND (!$this->empty_string($dom[$key]['attribute']['strokecolor']))) {
- $dom[$key]['strokecolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['strokecolor']);
- }
-
- if (isset($dom[$key]['attribute']['width'])) {
- $dom[$key]['width'] = $dom[$key]['attribute']['width'];
- }
-
- if (isset($dom[$key]['attribute']['height'])) {
- $dom[$key]['height'] = $dom[$key]['attribute']['height'];
- }
-
- if (isset($dom[$key]['attribute']['align']) AND (!$this->empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
- $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0});
- }
-
- if (isset($dom[$key]['attribute']['stroke'])) {
-
- $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
- }
- if (isset($dom[$key]['attribute']['fill'])) {
-
- if ($dom[$key]['attribute']['fill'] == 'true') {
- $dom[$key]['fill'] = true;
- } else {
- $dom[$key]['fill'] = false;
- }
- }
- if (isset($dom[$key]['attribute']['clip'])) {
-
- if ($dom[$key]['attribute']['clip'] == 'true') {
- $dom[$key]['clip'] = true;
- } else {
- $dom[$key]['clip'] = false;
- }
- }
- }
- } else {
-
- $dom[$key]['tag'] = false;
- $dom[$key]['block'] = false;
-
- $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
- $dom[$key]['parent'] = end($level);
- $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
- }
- ++$elkey;
- ++$key;
- }
- return $dom;
- }
-
- protected function getSpaceString() {
- $spacestr = chr(32);
- if ($this->isUnicodeFont()) {
- $spacestr = chr(0).chr(32);
- }
- return $spacestr;
- }
-
- public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
- return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
- }
-
- public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
- $gvars = $this->getGraphicVars();
-
- $prev_cell_margin = $this->cell_margin;
- $prev_cell_padding = $this->cell_padding;
- $prevPage = $this->page;
- $prevlMargin = $this->lMargin;
- $prevrMargin = $this->rMargin;
- $curfontname = $this->FontFamily;
- $curfontstyle = $this->FontStyle;
- $curfontsize = $this->FontSizePt;
- $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
- $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
- $curfontstretcing = $this->font_stretching;
- $curfontkerning = $this->font_spacing;
- $this->newline = true;
- $newline = true;
- $startlinepage = $this->page;
- $minstartliney = $this->y;
- $maxbottomliney = 0;
- $startlinex = $this->x;
- $startliney = $this->y;
- $yshift = 0;
- $loop = 0;
- $curpos = 0;
- $this_method_vars = array();
- $undo = false;
- $fontaligned = false;
- $reverse_dir = false;
- $this->premode = false;
- if ($this->inxobj) {
-
- $pask = count($this->xobjects[$this->xobjid]['annotations']);
- } elseif (isset($this->PageAnnots[$this->page])) {
- $pask = count($this->PageAnnots[$this->page]);
- } else {
- $pask = 0;
- }
- if ($this->inxobj) {
-
- $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
- } elseif (!$this->InFooter) {
- if (isset($this->footerlen[$this->page])) {
- $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
- } else {
- $this->footerpos[$this->page] = $this->pagelen[$this->page];
- }
- $startlinepos = $this->footerpos[$this->page];
- } else {
-
- $startlinepos = $this->pagelen[$this->page];
- }
- $lalign = $align;
- $plalign = $align;
- if ($this->rtl) {
- $w = $this->x - $this->lMargin;
- } else {
- $w = $this->w - $this->rMargin - $this->x;
- }
- $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
- if ($cell) {
- if ($this->rtl) {
- $this->x -= $this->cell_padding['R'];
- $this->lMargin += $this->cell_padding['R'];
- } else {
- $this->x += $this->cell_padding['L'];
- $this->rMargin += $this->cell_padding['L'];
- }
- }
- if ($this->customlistindent >= 0) {
- $this->listindent = $this->customlistindent;
- } else {
- $this->listindent = $this->GetStringWidth('000000');
- }
- $this->listindentlevel = 0;
-
- $prev_cell_height_ratio = $this->cell_height_ratio;
- $prev_listnum = $this->listnum;
- $prev_listordered = $this->listordered;
- $prev_listcount = $this->listcount;
- $prev_lispacer = $this->lispacer;
- $this->listnum = 0;
- $this->listordered = array();
- $this->listcount = array();
- $this->lispacer = '';
- if (($this->empty_string($this->lasth)) OR ($reseth)) {
-
- $this->resetLastH();
- }
- $dom = $this->getHtmlDomArray($html);
- $maxel = count($dom);
- $key = 0;
- $hidden_node_key = -1;
- while ($key < $maxel) {
- if ($dom[$key]['tag']) {
- if ($dom[$key]['opening']) {
- if (($hidden_node_key <= 0) AND $dom[$key]['hide']) {
-
- $hidden_node_key = $key;
- }
- } elseif (($hidden_node_key > 0) AND ($dom[$key]['parent'] == $hidden_node_key)) {
-
- $hidden_node_key = 0;
- }
- }
- if ($hidden_node_key >= 0) {
-
- ++$key;
- if ($hidden_node_key == 0) {
-
- $hidden_node_key = -1;
- }
- continue;
- }
- if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
-
- if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
-
- $this->checkPageBreak($this->PageBreakTrigger + 1);
- }
- if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
- OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
-
- $this->checkPageBreak($this->PageBreakTrigger + 1);
- }
- }
- if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
- if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
- $dom[$key]['attribute']['nobr'] = false;
- } else {
-
- $this->startTransaction();
-
- $this_method_vars['html'] = $html;
- $this_method_vars['ln'] = $ln;
- $this_method_vars['fill'] = $fill;
- $this_method_vars['reseth'] = $reseth;
- $this_method_vars['cell'] = $cell;
- $this_method_vars['align'] = $align;
- $this_method_vars['gvars'] = $gvars;
- $this_method_vars['prevPage'] = $prevPage;
- $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
- $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
- $this_method_vars['prevlMargin'] = $prevlMargin;
- $this_method_vars['prevrMargin'] = $prevrMargin;
- $this_method_vars['curfontname'] = $curfontname;
- $this_method_vars['curfontstyle'] = $curfontstyle;
- $this_method_vars['curfontsize'] = $curfontsize;
- $this_method_vars['curfontascent'] = $curfontascent;
- $this_method_vars['curfontdescent'] = $curfontdescent;
- $this_method_vars['curfontstretcing'] = $curfontstretcing;
- $this_method_vars['curfontkerning'] = $curfontkerning;
- $this_method_vars['minstartliney'] = $minstartliney;
- $this_method_vars['maxbottomliney'] = $maxbottomliney;
- $this_method_vars['yshift'] = $yshift;
- $this_method_vars['startlinepage'] = $startlinepage;
- $this_method_vars['startlinepos'] = $startlinepos;
- $this_method_vars['startlinex'] = $startlinex;
- $this_method_vars['startliney'] = $startliney;
- $this_method_vars['newline'] = $newline;
- $this_method_vars['loop'] = $loop;
- $this_method_vars['curpos'] = $curpos;
- $this_method_vars['pask'] = $pask;
- $this_method_vars['lalign'] = $lalign;
- $this_method_vars['plalign'] = $plalign;
- $this_method_vars['w'] = $w;
- $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
- $this_method_vars['prev_listnum'] = $prev_listnum;
- $this_method_vars['prev_listordered'] = $prev_listordered;
- $this_method_vars['prev_listcount'] = $prev_listcount;
- $this_method_vars['prev_lispacer'] = $prev_lispacer;
- $this_method_vars['fontaligned'] = $fontaligned;
- $this_method_vars['key'] = $key;
- $this_method_vars['dom'] = $dom;
- }
- }
-
- if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
- if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !$this->empty_string($dom[$dom[$key]['parent']]['thead'])) {
- $this->inthead = true;
-
- $this->writeHTML($this->thead, false, false, false, false, '');
-
- if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
-
-
- $this->rollbackTransaction(true);
-
- foreach ($this_method_vars as $vkey => $vval) {
- $$vkey = $vval;
- }
-
- $tmp_thead = $this->thead;
- $this->thead = '';
-
- $pre_y = $this->y;
- if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
-
- $startliney = $this->y;
- }
- $this->start_transaction_page = $this->page;
- $this->start_transaction_y = $this->y;
-
- $this->thead = $tmp_thead;
-
- if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
- $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
- } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
- $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
- } else {
- $tmp_cellspacing = 0;
- }
- $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
- $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
- $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
- $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
- $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
- $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
-
- $this->writeHTML($this->thead, false, false, false, false, '');
- }
- }
-
- while ( ($key < $maxel) AND (!(
- ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
- OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
- ++$key;
- }
- }
- if ($dom[$key]['tag'] OR ($key == 0)) {
- if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
- $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
- }
-
- if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
-
- $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], $this->lasth, 'px');
- $autolinebreak = false;
- if (isset($dom[$key]['width']) AND ($dom[$key]['width'] > 0)) {
- $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], 1, 'px', false);
- if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
- AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
- OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
-
- $autolinebreak = true;
- $this->Ln('', $cell);
- if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
-
- --$key;
- }
- }
- }
- if (!$autolinebreak) {
- if ($this->inPageBody()) {
- $pre_y = $this->y;
-
- if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
-
- $startliney = $this->y;
- }
- }
- if ($this->page > $startlinepage) {
-
- if (isset($this->footerlen[$startlinepage])) {
- $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
- }
-
- $pagebuff = $this->getPageBuffer($startlinepage);
- $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
- $tstart = substr($pagebuff, 0, $startlinepos);
- $tend = substr($this->getPageBuffer($startlinepage), $curpos);
-
- $this->setPageBuffer($startlinepage, $tstart.''.$tend);
- $pagebuff = $this->getPageBuffer($this->page);
- $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
- $tend = substr($pagebuff, $this->cntmrk[$this->page]);
-
- $yshift = ($minstartliney - $this->y);
- if ($fontaligned) {
- $yshift += ($curfontsize / $this->k);
- }
- $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k));
- $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
-
- if (isset($this->PageAnnots[$this->page])) {
- $next_pask = count($this->PageAnnots[$this->page]);
- } else {
- $next_pask = 0;
- }
- if (isset($this->PageAnnots[$startlinepage])) {
- foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
- if ($pak >= $pask) {
- $this->PageAnnots[$this->page][] = $pac;
- unset($this->PageAnnots[$startlinepage][$pak]);
- $npak = count($this->PageAnnots[$this->page]) - 1;
- $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
- }
- }
- }
- $pask = $next_pask;
- $startlinepos = $this->cntmrk[$this->page];
- $startlinepage = $this->page;
- $startliney = $this->y;
- $this->newline = false;
- }
- $this->y += ((($curfontsize * $this->cell_height_ratio / $this->k) + $curfontascent - $curfontdescent) / 2) - $imgh;
- $minstartliney = min($this->y, $minstartliney);
- $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
- }
- } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
-
- $pfontname = $curfontname;
- $pfontstyle = $curfontstyle;
- $pfontsize = $curfontsize;
- $fontname = isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname;
- $fontstyle = isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle;
- $fontsize = isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize;
- $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
- $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
- if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
- OR ($this->cell_height_ratio != $dom[$key]['line-height'])
- OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
- if (($key < ($maxel - 1)) AND (
- ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
- OR ($this->cell_height_ratio != $dom[$key]['line-height'])
- OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize) AND ($fontsize >= 0) AND ($curfontsize >= 0) AND ($fontsize != $curfontsize))
- )) {
- if ($this->page > $startlinepage) {
-
- if (isset($this->footerlen[$startlinepage])) {
- $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
- }
-
- $pagebuff = $this->getPageBuffer($startlinepage);
- $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
- $tstart = substr($pagebuff, 0, $startlinepos);
- $tend = substr($this->getPageBuffer($startlinepage), $curpos);
-
- $this->setPageBuffer($startlinepage, $tstart.''.$tend);
- $pagebuff = $this->getPageBuffer($this->page);
- $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
- $tend = substr($pagebuff, $this->cntmrk[$this->page]);
-
- $yshift = ($minstartliney - $this->y);
- $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k));
- $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
-
- if (isset($this->PageAnnots[$this->page])) {
- $next_pask = count($this->PageAnnots[$this->page]);
- } else {
- $next_pask = 0;
- }
- if (isset($this->PageAnnots[$startlinepage])) {
- foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
- if ($pak >= $pask) {
- $this->PageAnnots[$this->page][] = $pac;
- unset($this->PageAnnots[$startlinepage][$pak]);
- $npak = count($this->PageAnnots[$this->page]) - 1;
- $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
- }
- }
- }
- $pask = $next_pask;
- $startlinepos = $this->cntmrk[$this->page];
- $startlinepage = $this->page;
- $startliney = $this->y;
- }
- if (!isset($dom[$key]['line-height'])) {
- $dom[$key]['line-height'] = $this->cell_height_ratio;
- }
- if (!$dom[$key]['block']) {
- if (!(isset($dom[($key + 1)]) AND $dom[($key + 1)]['tag'] AND (!$dom[($key + 1)]['opening']) AND ($dom[($key + 1)]['value'] != 'li') AND $dom[$key]['tag'] AND (!$dom[$key]['opening']))) {
- $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
- }
- if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
- $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
- if (isset($line_align_data) AND (($line_align_data[0] == ($key - 1)) OR (($line_align_data[0] == ($key - 2)) AND (isset($dom[($key - 1)])) AND (preg_match('/^([\s]+)$/', $dom[($key - 1)]['value']) > 0)))) {
- $minstartliney = min($this->y, $line_align_data[1]);
- $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $line_align_data[2]);
- } else {
- $minstartliney = min($this->y, $minstartliney);
- $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
- }
- $line_align_data = $current_line_align_data;
- }
- }
- $this->cell_height_ratio = $dom[$key]['line-height'];
- $fontaligned = true;
- }
- $this->SetFont($fontname, $fontstyle, $fontsize);
-
- $this->resetLastH();
- $curfontname = $fontname;
- $curfontstyle = $fontstyle;
- $curfontsize = $fontsize;
- $curfontascent = $fontascent;
- $curfontdescent = $fontdescent;
- }
- }
-
- $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
- $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
- $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
- $this->setTextRenderingMode($textstroke, $textfill, $textclip);
- if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
- $this->setFontStretching($dom[$key]['font-stretch']);
- }
- if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
- $this->setFontSpacing($dom[$key]['letter-spacing']);
- }
- if (($plalign == 'J') AND $dom[$key]['block']) {
- $plalign = '';
- }
-
- $curpos = $this->pagelen[$startlinepage];
- if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
- $this->SetFillColorArray($dom[$key]['bgcolor']);
- $wfill = true;
- } else {
- $wfill = $fill | false;
- }
- if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
- $this->SetTextColorArray($dom[$key]['fgcolor']);
- }
- if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
- $this->SetDrawColorArray($dom[$key]['strokecolor']);
- }
- if (isset($dom[$key]['align'])) {
- $lalign = $dom[$key]['align'];
- }
- if ($this->empty_string($lalign)) {
- $lalign = $align;
- }
- }
-
- if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
- $newline = true;
- $fontaligned = false;
-
- if (isset($startlinex)) {
- $yshift = ($minstartliney - $startliney);
- if (($yshift > 0) OR ($this->page > $startlinepage)) {
- $yshift = 0;
- }
- $t_x = 0;
-
- $linew = abs($this->endlinex - $startlinex);
- if ($this->inxobj) {
-
- $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
- if (isset($opentagpos)) {
- $midpos = $opentagpos;
- } else {
- $midpos = 0;
- }
- if ($midpos > 0) {
- $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
- $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
- } else {
- $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
- $pend = '';
- }
- } else {
- $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
- if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
- $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
- $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
- } elseif (isset($opentagpos)) {
- $midpos = $opentagpos;
- } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
- $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
- $midpos = $this->footerpos[$startlinepage];
- } else {
- $midpos = 0;
- }
- if ($midpos > 0) {
- $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
- $pend = substr($this->getPageBuffer($startlinepage), $midpos);
- } else {
- $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
- $pend = '';
- }
- }
- if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
-
- $tw = $w;
- if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
- $tw += $this->cell_padding['R'];
- }
- if ($this->lMargin != $prevlMargin) {
- $tw += ($prevlMargin - $this->lMargin);
- }
- if ($this->rMargin != $prevrMargin) {
- $tw += ($prevrMargin - $this->rMargin);
- }
- $one_space_width = $this->GetStringWidth(chr(32));
- $no = 0;
- if ($this->isRTLTextDir()) {
-
- $pos1 = $this->revstrpos($pmid, '[(');
- if ($pos1 > 0) {
- $pos1 = intval($pos1);
- if ($this->isUnicodeFont()) {
- $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32)));
- $spacelen = 2;
- } else {
- $pos2 = intval($this->revstrpos($pmid, '[('.chr(32)));
- $spacelen = 1;
- }
- if ($pos1 == $pos2) {
- $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
- if (substr($pmid, $pos1, 4) == '[()]') {
- $linew -= $one_space_width;
- } elseif ($pos1 == strpos($pmid, '[(')) {
- $no = 1;
- }
- }
- }
- } else {
-
- $pos1 = $this->revstrpos($pmid, ')]');
- if ($pos1 > 0) {
- $pos1 = intval($pos1);
- if ($this->isUnicodeFont()) {
- $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) + 2;
- $spacelen = 2;
- } else {
- $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) + 1;
- $spacelen = 1;
- }
- if ($pos1 == $pos2) {
- $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
- $linew -= $one_space_width;
- }
- }
- }
- $mdiff = ($tw - $linew);
- if ($plalign == 'C') {
- if ($this->rtl) {
- $t_x = -($mdiff / 2);
- } else {
- $t_x = ($mdiff / 2);
- }
- } elseif ($plalign == 'R') {
-
- $t_x = $mdiff;
- } elseif ($plalign == 'L') {
-
- $t_x = -$mdiff;
- } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
-
- if ($this->isRTLTextDir()) {
-
- $t_x = -$mdiff;
- }
- $ns = 0;
- $pmidtemp = $pmid;
-
- $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
- $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
-
- if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
- $spacestr = $this->getSpaceString();
- $maxkk = count($lnstring[1]) - 1;
- for ($kk=0; $kk <= $maxkk; ++$kk) {
-
- $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
- $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
-
- $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
-
- $ns += $lnstring[2][$kk];
- $lnstring[3][$kk] = $ns;
- }
- if ($ns == 0) {
- $ns = 1;
- }
-
- $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
- $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
- if ($this->font_spacing != 0) {
-
- $osw = -1000 * $this->font_spacing / $this->FontSize;
- $spacewidthu += $osw;
- }
- $nsmax = $ns;
- $ns = 0;
- reset($lnstring);
- $offset = 0;
- $strcount = 0;
- $prev_epsposbeg = 0;
- $textpos = 0;
- if ($this->isRTLTextDir()) {
- $textpos = $this->wPt;
- }
- global $spacew;
- while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
-
- $stroffset = strpos($pmid, '[(', $offset);
- if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
-
- $offset = strpos($pmid, ')]', $stroffset);
- while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
- $offset = strpos($pmid, ')]', ($offset + 1));
- }
- if ($offset === false) {
- $this->Error('HTML Justification: malformed PDF code.');
- }
- continue;
- }
- if ($this->isRTLTextDir()) {
- $spacew = ($spacewidth * ($nsmax - $ns));
- } else {
- $spacew = ($spacewidth * $ns);
- }
- $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
- $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
- $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q');
- if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend))
- OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) {
-
- $trx = sprintf('1 0 0 1 %.3F 0 cm', $spacew);
- $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
- $pmid_b = substr($pmid, 0, $epsposbeg);
- $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
- $pmid_e = substr($pmid, $epsposend);
- $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
- $offset = $epsposend;
- continue;
- }
- $prev_epsposbeg = $epsposbeg;
- $currentxpos = 0;
-
- switch ($strpiece[2][0]) {
- case 'Td':
- case 'cm':
- case 'm':
- case 'l': {
-
- preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
- $currentxpos = $xmatches[1];
- $textpos = $currentxpos;
- if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
- $ns = $lnstring[3][$strcount];
- if ($this->isRTLTextDir()) {
- $spacew = ($spacewidth * ($nsmax - $ns));
- }
- ++$strcount;
- }
-
- $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
- create_function('$matches', 'global $spacew;
- $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
- return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1);
- break;
- }
- case 're': {
-
- if (!$this->empty_string($this->lispacer)) {
- $this->lispacer = '';
- continue;
- }
- preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
- $currentxpos = $xmatches[1];
- global $x_diff, $w_diff;
- $x_diff = 0;
- $w_diff = 0;
- if ($this->isRTLTextDir()) {
- if ($currentxpos < $textpos) {
- $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
- $w_diff = ($spacewidth * $lnstring[2][$strcount]);
- } else {
- if ($strcount > 0) {
- $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
- $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
- }
- }
- } else {
- if ($currentxpos > $textpos) {
- if ($strcount > 0) {
- $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
- }
- $w_diff = ($spacewidth * $lnstring[2][$strcount]);
- } else {
- if ($strcount > 1) {
- $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
- }
- if ($strcount > 0) {
- $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
- }
- }
- }
- $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x',
- create_function('$matches', 'global $x_diff, $w_diff;
- $newx = sprintf("%.2F",(floatval($matches[1]) + $x_diff));
- $neww = sprintf("%.2F",(floatval($matches[3]) + $w_diff));
- return "".$newx." ".$matches[2]." ".$neww." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1);
- break;
- }
- case 'c': {
-
- preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x', $pmid, $xmatches);
- $currentxpos = $xmatches[1];
-
- $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x',
- create_function('$matches', 'global $spacew;
- $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew));
- $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew));
- $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew));
- return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1);
- break;
- }
- }
-
- $cxpos = ($currentxpos / $this->k);
- $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
- if ($this->inxobj) {
-
- foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
- if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
- if ($cxpos > $lmpos) {
- $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
- $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
- } else {
- $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
- }
- break;
- }
- }
- } elseif (isset($this->PageAnnots[$this->page])) {
- foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
- if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
- if ($cxpos > $lmpos) {
- $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
- $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
- } else {
- $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
- }
- break;
- }
- }
- }
- }
-
- $pmid = str_replace('x*#!#*x', '', $pmid);
- if ($this->isUnicodeFont()) {
-
- $spacew = $spacewidthu;
- if ($this->font_stretching != 100) {
-
- $spacew /= ($this->font_stretching / 100);
- }
- $pmidtemp = $pmid;
-
- $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
- $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
- $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x",
- create_function('$matches', 'global $spacew;
- $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
- $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
- return "[(".str_replace(chr(0).chr(32), ") ".sprintf("%.3F", $spacew)." (", $matches[1]).")]";'), $pmidtemp);
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
- } else {
- $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
- }
- $endlinepos = strlen($pstart."\n".$pmid."\n");
- } else {
-
- if ($this->font_stretching != 100) {
-
- $spacewidth /= ($this->font_stretching / 100);
- }
- $rs = sprintf('%.3F Tw', $spacewidth);
- $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
- } else {
- $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
- }
- $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
- }
- }
- }
- }
- if (($t_x != 0) OR ($yshift < 0)) {
-
- $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k));
- $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
- $endlinepos = strlen($pstart);
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
- foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
- if ($pak >= $pask) {
- $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
- $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
- }
- }
- } else {
- $this->setPageBuffer($startlinepage, $pstart.$pend);
-
- if (isset($this->PageAnnots[$this->page])) {
- foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
- if ($pak >= $pask) {
- $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
- $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
- }
- }
- }
- }
- $this->y -= $yshift;
- }
- }
- $pbrk = $this->checkPageBreak($this->lasth);
- $this->newline = false;
- $startlinex = $this->x;
- $startliney = $this->y;
- if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
- $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
- } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
- $startliney -= (($this->FontSizePt / 0.7) / $this->k);
- } else {
- $minstartliney = $startliney;
- $maxbottomliney = ($this->y + (($fontsize * $this->cell_height_ratio) / $this->k));
- }
- $startlinepage = $this->page;
- if (isset($endlinepos) AND (!$pbrk)) {
- $startlinepos = $endlinepos;
- } else {
- if ($this->inxobj) {
-
- $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
- } elseif (!$this->InFooter) {
- if (isset($this->footerlen[$this->page])) {
- $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
- } else {
- $this->footerpos[$this->page] = $this->pagelen[$this->page];
- }
- $startlinepos = $this->footerpos[$this->page];
- } else {
- $startlinepos = $this->pagelen[$this->page];
- }
- }
- unset($endlinepos);
- $plalign = $lalign;
- if (isset($this->PageAnnots[$this->page])) {
- $pask = count($this->PageAnnots[$this->page]);
- } else {
- $pask = 0;
- }
- if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
- AND (isset($this->emptypagemrk[$this->page]))
- AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
- $this->SetFont($fontname, $fontstyle, $fontsize);
- if ($wfill) {
- $this->SetFillColorArray($this->bgcolor);
- }
- }
- }
- if (isset($opentagpos)) {
- unset($opentagpos);
- }
- if ($dom[$key]['tag']) {
- if ($dom[$key]['opening']) {
-
- if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
- $this->textindent = $dom[$key]['text-indent'];
- $this->newline = true;
- }
-
- if ($dom[$key]['value'] == 'table') {
-
- if ($this->rtl) {
- $wtmp = $this->x - $this->lMargin;
- } else {
- $wtmp = $this->w - $this->rMargin - $this->x;
- }
-
- if (isset($dom[$key]['attribute']['cellspacing'])) {
- $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
- $cellspacing = array('H' => $clsp, 'V' => $clsp);
- } elseif (isset($dom[$key]['border-spacing'])) {
- $cellspacing = $dom[$key]['border-spacing'];
- } else {
- $cellspacing = array('H' => 0, 'V' => 0);
- }
-
- if (isset($dom[$key]['width'])) {
- $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
- } else {
- $table_width = $wtmp;
- }
- $table_width -= (2 * $cellspacing['H']);
- if (!$this->inthead) {
- $this->y += $cellspacing['V'];
- }
- if ($this->rtl) {
- $cellspacingx = -$cellspacing['H'];
- } else {
- $cellspacingx = $cellspacing['H'];
- }
-
- $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
-
- $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
-
- $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
- }
-
- if ($dom[$key]['value'] == 'tr') {
-
- $colid = 0;
- }
-
- if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
- $trid = $dom[$key]['parent'];
- $table_el = $dom[$trid]['parent'];
- if (!isset($dom[$table_el]['cols'])) {
- $dom[$table_el]['cols'] = $dom[$trid]['cols'];
- }
-
- $tdborder = 0;
- if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
- $tdborder = $dom[$key]['border'];
- }
- $colspan = $dom[$key]['attribute']['colspan'];
- $old_cell_padding = $this->cell_padding;
- if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
- $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
- $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
- } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
- $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
- } else {
- $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
- }
- $this->cell_padding = $current_cell_padding;
- if (isset($dom[$key]['height'])) {
-
- $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
- } else {
- $cellh = 0;
- }
- if (isset($dom[$key]['content'])) {
- $cell_content = stripslashes($dom[$key]['content']);
- } else {
- $cell_content = ' ';
- }
- $tagtype = $dom[$key]['value'];
- $parentid = $key;
- while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
-
- ++$key;
- }
- if (!isset($dom[$trid]['startpage'])) {
- $dom[$trid]['startpage'] = $this->page;
- } else {
- $this->setPage($dom[$trid]['startpage']);
- }
- if (!isset($dom[$trid]['startcolumn'])) {
- $dom[$trid]['startcolumn'] = $this->current_column;
- } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
- $tmpx = $this->x;
- $this->selectColumn($dom[$trid]['startcolumn']);
- $this->x = $tmpx;
- }
- if (!isset($dom[$trid]['starty'])) {
- $dom[$trid]['starty'] = $this->y;
- } else {
- $this->y = $dom[$trid]['starty'];
- }
- if (!isset($dom[$trid]['startx'])) {
- $dom[$trid]['startx'] = $this->x;
- $this->x += $cellspacingx;
- } else {
- $this->x += ($cellspacingx / 2);
- }
- if (isset($dom[$parentid]['attribute']['rowspan'])) {
- $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
- } else {
- $rowspan = 1;
- }
-
- if (isset($dom[$table_el]['rowspans'])) {
- $rsk = 0;
- $rskmax = count($dom[$table_el]['rowspans']);
- while ($rsk < $rskmax) {
- $trwsp = $dom[$table_el]['rowspans'][$rsk];
- $rsstartx = $trwsp['startx'];
- $rsendx = $trwsp['endx'];
-
- if ($trwsp['startpage'] < $this->page) {
- if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
- $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
- $rsstartx -= $dl;
- $rsendx -= $dl;
- } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
- $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
- $rsstartx += $dl;
- $rsendx += $dl;
- }
- }
- if (($trwsp['rowspan'] > 0)
- AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
- AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
- AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
-
- $this->x = $rsendx + $cellspacingx;
-
- $colid += $trwsp['colspan'];
- if (($trwsp['rowspan'] == 1)
- AND (isset($dom[$trid]['endy']))
- AND (isset($dom[$trid]['endpage']))
- AND (isset($dom[$trid]['endcolumn']))
- AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
- AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
-
- $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
- $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
- }
- $rsk = 0;
- } else {
- ++$rsk;
- }
- }
- }
- if (isset($dom[$parentid]['width'])) {
-
- $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
- $tmpcw = ($cellw / $colspan);
- for ($i = 0; $i < $colspan; ++$i) {
- $table_colwidths[($colid + $i)] = $tmpcw;
- }
- } else {
-
- $cellw = 0;
- for ($i = 0; $i < $colspan; ++$i) {
- $cellw += $table_colwidths[($colid + $i)];
- }
- }
- $cellw += (($colspan - 1) * $cellspacing['H']);
-
- $colid += $colspan;
-
- if ($rowspan > 1) {
- $trsid = array_push($dom[$table_el]['rowspans'], array('trid' => $trid, 'rowspan' => $rowspan, 'mrowspan' => $rowspan, 'colspan' => $colspan, 'startpage' => $this->page, 'startcolumn' => $this->current_column, 'startx' => $this->x, 'starty' => $this->y));
- }
- $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
- if ($rowspan > 1) {
- $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
- }
-
- if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
- $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
- }
-
- if (isset($tdborder) AND !empty($tdborder)) {
- $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
- }
- $prevLastH = $this->lasth;
-
- if ($this->rtl) {
- $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
- } else {
- $this->colxshift['x'] = $this->x - $this->lMargin;
- }
- $this->colxshift['s'] = $cellspacing;
- $this->colxshift['p'] = $current_cell_padding;
-
- $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
-
- $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
- $this->lasth = $prevLastH;
- $this->cell_padding = $old_cell_padding;
- $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
-
- if ($rowspan <= 1) {
- if (isset($dom[$trid]['endy'])) {
- if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
- $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
- } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
- $dom[$trid]['endy'] = $this->y;
- }
- } else {
- $dom[$trid]['endy'] = $this->y;
- }
- if (isset($dom[$trid]['endpage'])) {
- $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
- } else {
- $dom[$trid]['endpage'] = $this->page;
- }
- if (isset($dom[$trid]['endcolumn'])) {
- $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
- } else {
- $dom[$trid]['endcolumn'] = $this->current_column;
- }
- } else {
-
- $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
- $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
- $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
- $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
- }
- if (isset($dom[$table_el]['rowspans'])) {
-
- foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
- if ($trwsp['rowspan'] > 0) {
- if (isset($dom[$trid]['endpage'])) {
- if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
- $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
- } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
- $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
- $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
- $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
- } else {
- $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
- }
- }
- }
- }
- }
- $this->x += ($cellspacingx / 2);
- } else {
-
- if (!isset($opentagpos)) {
- if ($this->inxobj) {
-
- $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
- } elseif (!$this->InFooter) {
- if (isset($this->footerlen[$this->page])) {
- $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
- } else {
- $this->footerpos[$this->page] = $this->pagelen[$this->page];
- }
- $opentagpos = $this->footerpos[$this->page];
- }
- }
- $dom = $this->openHTMLTagHandler($dom, $key, $cell);
- }
- } else {
- $prev_numpages = $this->numpages;
- $old_bordermrk = $this->bordermrk[$this->page];
- $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
- if ($this->bordermrk[$this->page] > $old_bordermrk) {
- $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
- }
- if ($prev_numpages > $this->numpages) {
- $startlinepage = $this->page;
- }
- }
- } elseif (strlen($dom[$key]['value']) > 0) {
-
- if (!$this->empty_string($this->lispacer) AND ($this->lispacer != '^')) {
- $this->SetFont($pfontname, $pfontstyle, $pfontsize);
- $this->resetLastH();
- $minstartliney = $this->y;
- $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
- $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
- $this->SetFont($curfontname, $curfontstyle, $curfontsize);
- $this->resetLastH();
- if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
- $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
- $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
- $this->y += ((($pfontsize - $curfontsize) * $this->cell_height_ratio / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
- $minstartliney = min($this->y, $minstartliney);
- $maxbottomliney = max(($this->y + (($pfontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
- }
- }
-
- $this->htmlvspace = 0;
- if ((!$this->premode) AND $this->isRTLTextDir()) {
-
- $lsp = '';
- $rsp = '';
- if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
- $lsp = $matches[1];
- }
- if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
- $rsp = $matches[1];
- }
- $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
- }
- if ($newline) {
- if (!$this->premode) {
- $prelen = strlen($dom[$key]['value']);
- if ($this->isRTLTextDir()) {
-
- $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
- } else {
-
- $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
- }
- $postlen = strlen($dom[$key]['value']);
- if (($postlen == 0) AND ($prelen > 0)) {
- $dom[$key]['trimmed_space'] = true;
- }
- }
- $newline = false;
- $firstblock = true;
- } else {
- $firstblock = false;
-
- $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
- }
- $strrest = '';
- if ($this->rtl) {
- $this->x -= $this->textindent;
- } else {
- $this->x += $this->textindent;
- }
- if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
- $strlinelen = $this->GetStringWidth($dom[$key]['value']);
- if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
-
- $hrefcolor = '';
- if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
- $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
- }
- $hrefstyle = -1;
- if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
- $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
- }
- $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
- } else {
- $wadj = 0;
- if ($this->rtl) {
- $cwa = $this->x - $this->lMargin;
- } else {
- $cwa = $this->w - $this->rMargin - $this->x;
- }
- if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
-
- $nkey = ($key + 1);
- $write_block = true;
- $same_textdir = true;
- $tmp_fontname = $this->FontFamily;
- $tmp_fontstyle = $this->FontStyle;
- $tmp_fontsize = $this->FontSizePt;
- while ($write_block AND isset($dom[$nkey])) {
- if ($dom[$nkey]['tag']) {
- if ($dom[$nkey]['block']) {
-
- $write_block = false;
- }
- $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
- $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
- $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
- $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
- } else {
- $nextstr = preg_split('/'.$this->re_space['p'].'+/'.$this->re_space['m'], $dom[$nkey]['value']);
- if (isset($nextstr[0]) AND $same_textdir) {
- $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
- }
- if (isset($nextstr[1])) {
- $write_block = false;
- }
- }
- ++$nkey;
- }
- }
- if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
- $wadj = 0;
- $nextstr = preg_split('/'.$this->re_space['p'].'/'.$this->re_space['m'], $dom[$key]['value']);
- $numblks = count($nextstr);
- if ($numblks > 1) {
-
- $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
- }
- }
-
- if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
-
- $reverse_dir = true;
- $this->rtl = !$this->rtl;
- $revshift = ($strlinelen + $wadj + 0.000001);
- if ($this->rtl) {
- $this->x += $revshift;
- } else {
- $this->x -= $revshift;
- }
- $xws = $this->x;
- }
-
- $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
-
- if ($reverse_dir AND ($wadj == 0)) {
- $this->x = $xws;
- $this->rtl = !$this->rtl;
- $reverse_dir = false;
- }
- }
- }
- $this->textindent = 0;
- if (strlen($strrest) > 0) {
-
- $this->newline = true;
- if ($strrest == $dom[$key]['value']) {
-
- ++$loop;
- } else {
- $loop = 0;
- }
- $dom[$key]['value'] = $strrest;
- if ($cell) {
- if ($this->rtl) {
- $this->x -= $this->cell_padding['R'];
- } else {
- $this->x += $this->cell_padding['L'];
- }
- }
- if ($loop < 3) {
- --$key;
- }
- } else {
- $loop = 0;
- }
- }
- ++$key;
- if (isset($dom[$key]['tag']) AND $dom[$key]['tag'] AND (!isset($dom[$key]['opening']) OR !$dom[$key]['opening']) AND isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
-
- if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
-
-
- $this->rollbackTransaction(true);
-
- foreach ($this_method_vars as $vkey => $vval) {
- $$vkey = $vval;
- }
-
- $pre_y = $this->y;
- if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
- $startliney = $this->y;
- }
- $undo = true;
- } else {
- $undo = false;
- }
- }
- }
-
- if (isset($startlinex)) {
- $yshift = ($minstartliney - $startliney);
- if (($yshift > 0) OR ($this->page > $startlinepage)) {
- $yshift = 0;
- }
- $t_x = 0;
-
- $linew = abs($this->endlinex - $startlinex);
- if ($this->inxobj) {
-
- $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
- if (isset($opentagpos)) {
- $midpos = $opentagpos;
- } else {
- $midpos = 0;
- }
- if ($midpos > 0) {
- $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
- $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
- } else {
- $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
- $pend = '';
- }
- } else {
- $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
- if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
- $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
- $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
- } elseif (isset($opentagpos)) {
- $midpos = $opentagpos;
- } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
- $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
- $midpos = $this->footerpos[$startlinepage];
- } else {
- $midpos = 0;
- }
- if ($midpos > 0) {
- $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
- $pend = substr($this->getPageBuffer($startlinepage), $midpos);
- } else {
- $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
- $pend = '';
- }
- }
- if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
-
- $tw = $w;
- if ($this->lMargin != $prevlMargin) {
- $tw += ($prevlMargin - $this->lMargin);
- }
- if ($this->rMargin != $prevrMargin) {
- $tw += ($prevrMargin - $this->rMargin);
- }
- $one_space_width = $this->GetStringWidth(chr(32));
- $no = 0;
- if ($this->isRTLTextDir()) {
-
- $pos1 = $this->revstrpos($pmid, '[(');
- if ($pos1 > 0) {
- $pos1 = intval($pos1);
- if ($this->isUnicodeFont()) {
- $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32)));
- $spacelen = 2;
- } else {
- $pos2 = intval($this->revstrpos($pmid, '[('.chr(32)));
- $spacelen = 1;
- }
- if ($pos1 == $pos2) {
- $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
- if (substr($pmid, $pos1, 4) == '[()]') {
- $linew -= $one_space_width;
- } elseif ($pos1 == strpos($pmid, '[(')) {
- $no = 1;
- }
- }
- }
- } else {
-
- $pos1 = $this->revstrpos($pmid, ')]');
- if ($pos1 > 0) {
- $pos1 = intval($pos1);
- if ($this->isUnicodeFont()) {
- $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) + 2;
- $spacelen = 2;
- } else {
- $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) + 1;
- $spacelen = 1;
- }
- if ($pos1 == $pos2) {
- $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
- $linew -= $one_space_width;
- }
- }
- }
- $mdiff = ($tw - $linew);
- if ($plalign == 'C') {
- if ($this->rtl) {
- $t_x = -($mdiff / 2);
- } else {
- $t_x = ($mdiff / 2);
- }
- } elseif ($plalign == 'R') {
-
- $t_x = $mdiff;
- } elseif ($plalign == 'L') {
-
- $t_x = -$mdiff;
- }
- }
- if (($t_x != 0) OR ($yshift < 0)) {
-
- $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k));
- $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
- $endlinepos = strlen($pstart);
- if ($this->inxobj) {
-
- $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
- foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
- if ($pak >= $pask) {
- $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
- $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
- }
- }
- } else {
- $this->setPageBuffer($startlinepage, $pstart.$pend);
-
- if (isset($this->PageAnnots[$this->page])) {
- foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
- if ($pak >= $pask) {
- $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
- $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
- }
- }
- }
- }
- $this->y -= $yshift;
- $yshift = 0;
- }
- }
-
- $this->setGraphicVars($gvars);
- if ($this->num_columns > 1) {
- $this->selectColumn();
- } elseif ($this->page > $prevPage) {
- $this->lMargin = $this->pagedim[$this->page]['olm'];
- $this->rMargin = $this->pagedim[$this->page]['orm'];
- }
-
- $this->cell_height_ratio = $prev_cell_height_ratio;
- $this->listnum = $prev_listnum;
- $this->listordered = $prev_listordered;
- $this->listcount = $prev_listcount;
- $this->lispacer = $prev_lispacer;
- if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
- $this->Ln($this->lasth);
- if ($this->y < $maxbottomliney) {
- $this->y = $maxbottomliney;
- }
- }
- unset($dom);
- }
-
- protected function openHTMLTagHandler($dom, $key, $cell) {
- $tag = $dom[$key];
- $parent = $dom[($dom[$key]['parent'])];
- $firsttag = ($key == 1);
-
- if (isset($tag['dir'])) {
- $this->setTempRTL($tag['dir']);
- } else {
- $this->tmprtl = false;
- }
- if ($tag['block']) {
- $hbz = 0;
- $hb = 0;
-
- if (isset($this->tagvspaces[$tag['value']][0]['h']) AND ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
- $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
- } elseif (isset($tag['fontsize'])) {
- $cur_h = ($tag['fontsize'] / $this->k) * $this->cell_height_ratio;
- } else {
- $cur_h = $this->FontSize * $this->cell_height_ratio;
- }
- if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
- $n = $this->tagvspaces[$tag['value']][0]['n'];
- } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
- $n = 0.6;
- } else {
- $n = 1;
- }
- if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br')))) {
- $hb = 0;
- } else {
- $hb = ($n * $cur_h);
- }
- if (($this->htmlvspace <= 0) AND ($n > 0)) {
- if (isset($parent['fontsize'])) {
- $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
- } else {
- $hbz = $this->FontSize * $this->cell_height_ratio;
- }
- }
- }
-
- switch($tag['value']) {
- case 'table': {
- $cp = 0;
- $cs = 0;
- $dom[$key]['rowspans'] = array();
- if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
-
- if (!$this->empty_string($dom[$key]['thead'])) {
-
- $this->thead = $dom[$key]['thead'];
- if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
- $this->theadMargins = array();
- $this->theadMargins['cell_padding'] = $this->cell_padding;
- $this->theadMargins['lmargin'] = $this->lMargin;
- $this->theadMargins['rmargin'] = $this->rMargin;
- $this->theadMargins['page'] = $this->page;
- $this->theadMargins['cell'] = $cell;
- }
- }
- }
-
- $dom[$key]['old_cell_padding'] = $this->cell_padding;
- if (isset($tag['attribute']['cellpadding'])) {
- $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
- $this->SetCellPadding($pad);
- } elseif (isset($tag['padding'])) {
- $this->cell_padding = $tag['padding'];
- }
- if (isset($tag['attribute']['cellspacing'])) {
- $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
- } elseif (isset($tag['border-spacing'])) {
- $cs = $tag['border-spacing']['V'];
- }
- $prev_y = $this->y;
- if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
- $this->inthead = true;
-
- $this->checkPageBreak($this->PageBreakTrigger + 1);
- }
- break;
- }
- case 'tr': {
-
- $dom[$key]['cellpos'] = array();
- break;
- }
- case 'hr': {
- if ((isset($tag['height'])) AND ($tag['height'] != '')) {
- $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
- } else {
- $hrHeight = $this->GetLineWidth();
- }
- $this->addHTMLVertSpace($hbz, ($hrHeight / 2), $cell, $firsttag);
- $x = $this->GetX();
- $y = $this->GetY();
- $wtmp = $this->w - $this->lMargin - $this->rMargin;
- if ($cell) {
- $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
- }
- if ((isset($tag['width'])) AND ($tag['width'] != '')) {
- $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
- } else {
- $hrWidth = $wtmp;
- }
- $prevlinewidth = $this->GetLineWidth();
- $this->SetLineWidth($hrHeight);
- $this->Line($x, $y, $x + $hrWidth, $y);
- $this->SetLineWidth($prevlinewidth);
- $this->addHTMLVertSpace(($hrHeight / 2), 0, $cell, !isset($dom[($key + 1)]));
- break;
- }
- case 'a': {
- if (array_key_exists('href', $tag['attribute'])) {
- $this->HREF['url'] = $tag['attribute']['href'];
- }
- break;
- }
- case 'img': {
- if (isset($tag['attribute']['src'])) {
- if ($tag['attribute']['src']{0} === '@') {
-
- $tag['attribute']['src'] = '@'.base64_decode(substr($tag['attribute']['src'], 1));
- $type = '';
- } else {
-
- if (preg_match('%^/{2}%', $tag['attribute']['src'])) {
- $tag['attribute']['src'] = 'http:'.$tag['attribute']['src'];
- }
-
- if (($tag['attribute']['src'][0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
- $findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']);
- if (($findroot === false) OR ($findroot > 1)) {
- if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
- $tag['attribute']['src'] = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$tag['attribute']['src'];
- } else {
- $tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
- }
- }
- }
- $tag['attribute']['src'] = htmlspecialchars_decode(urldecode($tag['attribute']['src']));
- $type = $this->getImageFileType($tag['attribute']['src']);
- $testscrtype = @parse_url($tag['attribute']['src']);
- if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
-
- $tag['attribute']['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag['attribute']['src']);
- }
- }
- if (!isset($tag['width'])) {
- $tag['width'] = 0;
- }
- if (!isset($tag['height'])) {
- $tag['height'] = 0;
- }
-
-
-
- $tag['attribute']['align'] = 'bottom';
-
- switch($tag['attribute']['align']) {
- case 'top': {
- $align = 'T';
- break;
- }
- case 'middle': {
- $align = 'M';
- break;
- }
- case 'bottom': {
- $align = 'B';
- break;
- }
- default: {
- $align = 'B';
- break;
- }
- }
- $prevy = $this->y;
- $xpos = $this->x;
- $imglink = '';
- if (isset($this->HREF['url']) AND !$this->empty_string($this->HREF['url'])) {
- $imglink = $this->HREF['url'];
- if ($imglink{0} == '#') {
-
- $lnkdata = explode(',', $imglink);
- if (isset($lnkdata[0])) {
- $page = intval(substr($lnkdata[0], 1));
- if (empty($page) OR ($page <= 0)) {
- $page = $this->page;
- }
- if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
- $lnky = floatval($lnkdata[1]);
- } else {
- $lnky = 0;
- }
- $imglink = $this->AddLink();
- $this->SetLink($imglink, $lnky, $page);
- }
- }
- }
- $border = 0;
- if (isset($tag['border']) AND !empty($tag['border'])) {
-
- $border = $tag['border'];
- }
- $iw = '';
- if (isset($tag['width'])) {
- $iw = $this->getHTMLUnitToUnits($tag['width'], 1, 'px', false);
- }
- $ih = '';
- if (isset($tag['height'])) {
- $ih = $this->getHTMLUnitToUnits($tag['height'], 1, 'px', false);
- }
- if (($type == 'eps') OR ($type == 'ai')) {
- $this->ImageEps($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
- } elseif ($type == 'svg') {
- $this->ImageSVG($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
- } else {
- $this->Image($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
- }
- switch($align) {
- case 'T': {
- $this->y = $prevy;
- break;
- }
- case 'M': {
- $this->y = (($this->img_rb_y + $prevy - ($tag['fontsize'] / $this->k)) / 2) ;
- break;
- }
- case 'B': {
- $this->y = $this->img_rb_y - ($tag['fontsize'] / $this->k);
- break;
- }
- }
- }
- break;
- }
- case 'dl': {
- ++$this->listnum;
- if ($this->listnum == 1) {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- } else {
- $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
- }
- break;
- }
- case 'dt': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- break;
- }
- case 'dd': {
- if ($this->rtl) {
- $this->rMargin += $this->listindent;
- } else {
- $this->lMargin += $this->listindent;
- }
- ++$this->listindentlevel;
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- break;
- }
- case 'ul':
- case 'ol': {
- ++$this->listnum;
- if ($tag['value'] == 'ol') {
- $this->listordered[$this->listnum] = true;
- } else {
- $this->listordered[$this->listnum] = false;
- }
- if (isset($tag['attribute']['start'])) {
- $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
- } else {
- $this->listcount[$this->listnum] = 0;
- }
- if ($this->rtl) {
- $this->rMargin += $this->listindent;
- $this->x -= $this->listindent;
- } else {
- $this->lMargin += $this->listindent;
- $this->x += $this->listindent;
- }
- ++$this->listindentlevel;
- if ($this->listnum == 1) {
- if ($key > 1) {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- }
- } else {
- $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
- }
- break;
- }
- case 'li': {
- if ($key > 2) {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- }
- if ($this->listordered[$this->listnum]) {
-
- if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) {
- $this->lispacer = $parent['attribute']['type'];
- } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) {
- $this->lispacer = $parent['listtype'];
- } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) {
- $this->lispacer = $this->lisymbol;
- } else {
- $this->lispacer = '#';
- }
- ++$this->listcount[$this->listnum];
- if (isset($tag['attribute']['value'])) {
- $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
- }
- } else {
-
- if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) {
- $this->lispacer = $parent['attribute']['type'];
- } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) {
- $this->lispacer = $parent['listtype'];
- } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) {
- $this->lispacer = $this->lisymbol;
- } else {
- $this->lispacer = '!';
- }
- }
- break;
- }
- case 'blockquote': {
- if ($this->rtl) {
- $this->rMargin += $this->listindent;
- } else {
- $this->lMargin += $this->listindent;
- }
- ++$this->listindentlevel;
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- break;
- }
- case 'br': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- break;
- }
- case 'div': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- break;
- }
- case 'p': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- break;
- }
- case 'pre': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- $this->premode = true;
- break;
- }
- case 'sup': {
- $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
- break;
- }
- case 'sub': {
- $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
- break;
- }
- case 'h1':
- case 'h2':
- case 'h3':
- case 'h4':
- case 'h5':
- case 'h6': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
- break;
- }
-
- case 'form': {
- if (isset($tag['attribute']['action'])) {
- $this->form_action = $tag['attribute']['action'];
- } else {
- $this->form_action = K_PATH_URL.$_SERVER['SCRIPT_NAME'];
- }
- if (isset($tag['attribute']['enctype'])) {
- $this->form_enctype = $tag['attribute']['enctype'];
- } else {
- $this->form_enctype = 'application/x-www-form-urlencoded';
- }
- if (isset($tag['attribute']['method'])) {
- $this->form_mode = $tag['attribute']['method'];
- } else {
- $this->form_mode = 'post';
- }
- break;
- }
- case 'input': {
- if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
- $name = $tag['attribute']['name'];
- } else {
- break;
- }
- $prop = array();
- $opt = array();
- if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) {
- $prop['readonly'] = true;
- }
- if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) {
- $value = $tag['attribute']['value'];
- }
- if (isset($tag['attribute']['maxlength']) AND !$this->empty_string($tag['attribute']['maxlength'])) {
- $opt['maxlen'] = intval($tag['attribute']['value']);
- }
- $h = $this->FontSize * $this->cell_height_ratio;
- if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) {
- $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
- } else {
- $w = $h;
- }
- if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
- $checked = true;
- } else {
- $checked = false;
- }
- if (isset($tag['align'])) {
- switch ($tag['align']) {
- case 'C': {
- $opt['q'] = 1;
- break;
- }
- case 'R': {
- $opt['q'] = 2;
- break;
- }
- case 'L':
- default: {
- break;
- }
- }
- }
- switch ($tag['attribute']['type']) {
- case 'text': {
- if (isset($value)) {
- $opt['v'] = $value;
- }
- $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
- break;
- }
- case 'password': {
- if (isset($value)) {
- $opt['v'] = $value;
- }
- $prop['password'] = 'true';
- $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
- break;
- }
- case 'checkbox': {
- $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
- break;
- }
- case 'radio': {
- $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
- break;
- }
- case 'submit': {
- $w = $this->GetStringWidth($value) * 1.5;
- $h *= 1.6;
- $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
- $action = array();
- $action['S'] = 'SubmitForm';
- $action['F'] = $this->form_action;
- if ($this->form_enctype != 'FDF') {
- $action['Flags'] = array('ExportFormat');
- }
- if ($this->form_mode == 'get') {
- $action['Flags'] = array('GetMethod');
- }
- $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
- break;
- }
- case 'reset': {
- $w = $this->GetStringWidth($value) * 1.5;
- $h *= 1.6;
- $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
- $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
- break;
- }
- case 'file': {
- $prop['fileSelect'] = 'true';
- $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
- if (!isset($value)) {
- $value = '*';
- }
- $w = $this->GetStringWidth($value) * 2;
- $h *= 1.2;
- $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
- $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
- $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
- break;
- }
- case 'hidden': {
- if (isset($value)) {
- $opt['v'] = $value;
- }
- $opt['f'] = array('invisible', 'hidden');
- $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
- break;
- }
- case 'image': {
-
- if (isset($tag['attribute']['src']) AND !$this->empty_string($tag['attribute']['src'])) {
- $img = $tag['attribute']['src'];
- } else {
- break;
- }
- $value = 'img';
-
- if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
- $jsaction = $tag['attribute']['onclick'];
- } else {
- $jsaction = '';
- }
- $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
- break;
- }
- case 'button': {
- $w = $this->GetStringWidth($value) * 1.5;
- $h *= 1.6;
- $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
- if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
- $jsaction = $tag['attribute']['onclick'];
- } else {
- $jsaction = '';
- }
- $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
- break;
- }
- }
- break;
- }
- case 'textarea': {
- $prop = array();
- $opt = array();
- if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) {
- $prop['readonly'] = true;
- }
- if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
- $name = $tag['attribute']['name'];
- } else {
- break;
- }
- if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) {
- $opt['v'] = $tag['attribute']['value'];
- }
- if (isset($tag['attribute']['cols']) AND !$this->empty_string($tag['attribute']['cols'])) {
- $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
- } else {
- $w = 40;
- }
- if (isset($tag['attribute']['rows']) AND !$this->empty_string($tag['attribute']['rows'])) {
- $h = intval($tag['attribute']['rows']) * $this->FontSize * $this->cell_height_ratio;
- } else {
- $h = 10;
- }
- $prop['multiline'] = 'true';
- $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
- break;
- }
- case 'select': {
- $h = $this->FontSize * $this->cell_height_ratio;
- if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) {
- $h *= ($tag['attribute']['size'] + 1);
- }
- $prop = array();
- $opt = array();
- if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
- $name = $tag['attribute']['name'];
- } else {
- break;
- }
- $w = 0;
- if (isset($tag['attribute']['opt']) AND !$this->empty_string($tag['attribute']['opt'])) {
- $options = explode('#!NwL!#', $tag['attribute']['opt']);
- $values = array();
- foreach ($options as $val) {
- if (strpos($val, '#!TaB!#') !== false) {
- $opts = explode('#!TaB!#', $val);
- $values[] = $opts;
- $w = max($w, $this->GetStringWidth($opts[1]));
- } else {
- $values[] = $val;
- $w = max($w, $this->GetStringWidth($val));
- }
- }
- } else {
- break;
- }
- $w *= 2;
- if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
- $prop['multipleSelection'] = 'true';
- $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
- } else {
- $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
- }
- break;
- }
- case 'tcpdf': {
- if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
-
- if (isset($tag['attribute']['method'])) {
- $tcpdf_method = $tag['attribute']['method'];
- if (method_exists($this, $tcpdf_method)) {
- if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
- $params = unserialize(urldecode($tag['attribute']['params']));
- call_user_func_array(array($this, $tcpdf_method), $params);
- } else {
- $this->$tcpdf_method();
- }
- $this->newline = true;
- }
- }
- }
- break;
- }
- default: {
- break;
- }
- }
-
- $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
- if (in_array($tag['value'], $bordertags)) {
-
- $dom[$key]['borderposition'] = $this->getBorderStartPosition();
- }
- if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
- $pba = $dom[$key]['attribute']['pagebreakafter'];
-
- if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
-
- $this->checkPageBreak($this->PageBreakTrigger + 1);
- }
- if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
- OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
-
- $this->checkPageBreak($this->PageBreakTrigger + 1);
- }
- }
- return $dom;
- }
-
- protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
- $tag = $dom[$key];
- $parent = $dom[($dom[$key]['parent'])];
- $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
- $in_table_head = false;
-
- if ($this->rtl) {
- $xmax = $this->w;
- } else {
- $xmax = 0;
- }
- if ($tag['block']) {
- $hbz = 0;
- $hb = 0;
-
- if (isset($this->tagvspaces[$tag['value']][1]['h']) AND ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
- $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
- } elseif (isset($parent['fontsize'])) {
- $pre_h = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
- } else {
- $pre_h = $this->FontSize * $this->cell_height_ratio;
- }
- if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
- $n = $this->tagvspaces[$tag['value']][1]['n'];
- } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
- $n = 0.6;
- } else {
- $n = 1;
- }
- if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
- $hb = 0;
- } else {
- $hb = ($n * $pre_h);
- }
- if ($maxbottomliney > $this->PageBreakTrigger) {
- $hbz = ($this->FontSize * $this->cell_height_ratio);
- } elseif ($this->y < $maxbottomliney) {
- $hbz = ($maxbottomliney - $this->y);
- }
- }
-
- switch($tag['value']) {
- case 'tr': {
- $table_el = $dom[($dom[$key]['parent'])]['parent'];
- if (!isset($parent['endy'])) {
- $dom[($dom[$key]['parent'])]['endy'] = $this->y;
- $parent['endy'] = $this->y;
- }
- if (!isset($parent['endpage'])) {
- $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
- $parent['endpage'] = $this->page;
- }
- if (!isset($parent['endcolumn'])) {
- $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
- $parent['endcolumn'] = $this->current_column;
- }
-
- if (isset($dom[$table_el]['rowspans'])) {
- foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
- $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
- if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
- if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
- $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
- } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
- $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
- $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
- $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
- }
- }
- }
-
- foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
- if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
- $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
- $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
- $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
- $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
- $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
- $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
- }
- }
-
- foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
- if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
- $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
- $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
- $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
- }
- }
- }
- $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
- if ($this->num_columns > 1) {
- $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
- }
- $this->y = $dom[($dom[$key]['parent'])]['endy'];
- if (isset($dom[$table_el]['attribute']['cellspacing'])) {
- $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
- } elseif (isset($dom[$table_el]['border-spacing'])) {
- $this->y += $dom[$table_el]['border-spacing']['V'];
- }
- $this->Ln(0, $cell);
- if ($this->current_column == $parent['startcolumn']) {
- $this->x = $parent['startx'];
- }
-
- if ($this->page > $parent['startpage']) {
- if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
- $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
- } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
- $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
- }
- }
- break;
- }
- case 'tablehead':
-
- $in_table_head = true;
- $this->inthead = false;
- case 'table': {
- $table_el = $parent;
-
- if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
-
- $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
- } else {
- $border = 0;
- }
- $default_border = $border;
-
- foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
-
- if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
- foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
- if ($trwsp['trid'] == $trkey) {
- $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
- }
- if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0)) {
- $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
- }
- }
- }
- if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
- $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
- $dom[$prevtrkey]['endy'] = $pgendy;
-
- if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
- foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
- if (($trwsp['trid'] == $trkey) AND ($trwsp['mrowspan'] > 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
- $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
- $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
- }
- }
- }
- }
- $prevtrkey = $trkey;
- $table_el = $dom[($dom[$key]['parent'])];
- }
-
- if (count($table_el['trids']) > 0) {
- unset($xmax);
- }
- foreach ($table_el['trids'] as $j => $trkey) {
- $parent = $dom[$trkey];
- if (!isset($xmax)) {
- $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
- }
-
- foreach ($parent['cellpos'] as $k => $cellpos) {
- if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
- $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
- $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
- $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
- $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
- $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
- $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
- $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
- } else {
- $endy = $parent['endy'];
- $startpage = $parent['startpage'];
- $endpage = $parent['endpage'];
- $startcolumn = $parent['startcolumn'];
- $endcolumn = $parent['endcolumn'];
- }
- if ($this->num_columns == 0) {
- $this->num_columns = 1;
- }
- if (isset($cellpos['border'])) {
- $border = $cellpos['border'];
- }
- if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
- $this->SetFillColorArray($cellpos['bgcolor']);
- $fill = true;
- } else {
- $fill = false;
- }
- $x = $cellpos['startx'];
- $y = $parent['starty'];
- $starty = $y;
- $w = abs($cellpos['endx'] - $cellpos['startx']);
-
- $border_start = $this->getBorderMode($border, $position='start');
- $border_end = $this->getBorderMode($border, $position='end');
- $border_middle = $this->getBorderMode($border, $position='middle');
-
- for ($page = $startpage; $page <= $endpage; ++$page) {
- $ccode = '';
- $this->setPage($page);
- if ($this->num_columns < 2) {
-
- $this->x = $x;
- $this->y = $this->tMargin;
- }
-
- if ($page > $startpage) {
- if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
- $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
- } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
- $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
- }
- }
- if ($startpage == $endpage) {
- $deltacol = 0;
- $deltath = 0;
- for ($column = $startcolumn; $column <= $endcolumn; ++$column) {
- $this->selectColumn($column);
- if ($startcolumn == $endcolumn) {
- $cborder = $border;
- $h = $endy - $parent['starty'];
- $this->y = $y;
- $this->x = $x;
- } elseif ($column == $startcolumn) {
- $cborder = $border_start;
- $this->y = $starty;
- $this->x = $x;
- $h = $this->h - $this->y - $this->bMargin;
- if ($this->rtl) {
- $deltacol = $this->x + $this->rMargin - $this->w;
- } else {
- $deltacol = $this->x - $this->lMargin;
- }
- } elseif ($column == $endcolumn) {
- $cborder = $border_end;
- if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
- $this->y = $this->columns[$column]['th']['\''.$page.'\''];
- }
- $this->x += $deltacol;
- $h = $endy - $this->y;
- } else {
- $cborder = $border_middle;
- if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
- $this->y = $this->columns[$column]['th']['\''.$page.'\''];
- }
- $this->x += $deltacol;
- $h = $this->h - $this->y - $this->bMargin;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } elseif ($page == $startpage) {
- $deltacol = 0;
- $deltath = 0;
- for ($column = $startcolumn; $column < $this->num_columns; ++$column) {
- $this->selectColumn($column);
- if ($column == $startcolumn) {
- $cborder = $border_start;
- $this->y = $starty;
- $this->x = $x;
- $h = $this->h - $this->y - $this->bMargin;
- if ($this->rtl) {
- $deltacol = $this->x + $this->rMargin - $this->w;
- } else {
- $deltacol = $this->x - $this->lMargin;
- }
- } else {
- $cborder = $border_middle;
- if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
- $this->y = $this->columns[$column]['th']['\''.$page.'\''];
- }
- $this->x += $deltacol;
- $h = $this->h - $this->y - $this->bMargin;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } elseif ($page == $endpage) {
- $deltacol = 0;
- $deltath = 0;
- for ($column = 0; $column <= $endcolumn; ++$column) {
- $this->selectColumn($column);
- if ($column == $endcolumn) {
- $cborder = $border_end;
- if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
- $this->y = $this->columns[$column]['th']['\''.$page.'\''];
- }
- $this->x += $deltacol;
- $h = $endy - $this->y;
- } else {
- $cborder = $border_middle;
- if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
- $this->y = $this->columns[$column]['th']['\''.$page.'\''];
- }
- $this->x += $deltacol;
- $h = $this->h - $this->y - $this->bMargin;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } else {
- $deltacol = 0;
- $deltath = 0;
- for ($column = 0; $column < $this->num_columns; ++$column) {
- $this->selectColumn($column);
- $cborder = $border_middle;
- if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
- $this->y = $this->columns[$column]['th']['\''.$page.'\''];
- }
- $this->x += $deltacol;
- $h = $this->h - $this->y - $this->bMargin;
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- }
- if ($cborder OR $fill) {
- $offsetlen = strlen($ccode);
-
- if ($this->inxobj) {
-
- if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
- $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
- $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
- $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
- } else {
- $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
- $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
- }
- $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
- $pstart = substr($pagebuff, 0, $pagemark);
- $pend = substr($pagebuff, $pagemark);
- $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
- } else {
-
- if (end($this->transfmrk[$this->page]) !== false) {
- $pagemarkkey = key($this->transfmrk[$this->page]);
- $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
- $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
- } elseif ($this->InFooter) {
- $pagemark = $this->footerpos[$this->page];
- $this->footerpos[$this->page] += $offsetlen;
- } else {
- $pagemark = $this->intmrk[$this->page];
- $this->intmrk[$this->page] += $offsetlen;
- }
- $pagebuff = $this->getPageBuffer($this->page);
- $pstart = substr($pagebuff, 0, $pagemark);
- $pend = substr($pagebuff, $pagemark);
- $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
- }
- }
- }
-
- $border = $default_border;
- }
- if (isset($table_el['attribute']['cellspacing'])) {
- $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
- } elseif (isset($table_el['border-spacing'])) {
- $this->y += $table_el['border-spacing']['V'];
- }
- $this->Ln(0, $cell);
- $this->x = $parent['startx'];
- if ($endpage > $startpage) {
- if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
- $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
- } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
- $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
- }
- }
- }
- if (!$in_table_head) {
- $this->cell_padding = $table_el['old_cell_padding'];
-
- $this->resetLastH();
- if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
- $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
- if (($plendiff > 0) AND ($plendiff < 60)) {
- $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
- if (substr($pagediff, 0, 5) == 'BT /F') {
-
- $plendiff = 0;
- }
- }
- if ($plendiff == 0) {
-
- $this->deletePage($this->numpages);
- }
- }
- if (isset($this->theadMargins['top'])) {
-
- $this->tMargin = $this->theadMargins['top'];
- }
- if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
-
- $this->thead = '';
- $this->theadMargins = array();
- $this->pagedim[$this->page]['tm'] = $this->tMargin;
- }
- }
- $parent = $table_el;
- break;
- }
- case 'a': {
- $this->HREF = '';
- break;
- }
- case 'sup': {
- $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
- break;
- }
- case 'sub': {
- $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize'])/$this->k));
- break;
- }
- case 'div': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
- break;
- }
- case 'blockquote': {
- if ($this->rtl) {
- $this->rMargin -= $this->listindent;
- } else {
- $this->lMargin -= $this->listindent;
- }
- --$this->listindentlevel;
- $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
- break;
- }
- case 'p': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
- break;
- }
- case 'pre': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
- $this->premode = false;
- break;
- }
- case 'dl': {
- --$this->listnum;
- if ($this->listnum <= 0) {
- $this->listnum = 0;
- $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
- } else {
- $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
- }
- $this->resetLastH();
- break;
- }
- case 'dt': {
- $this->lispacer = '';
- $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
- break;
- }
- case 'dd': {
- $this->lispacer = '';
- if ($this->rtl) {
- $this->rMargin -= $this->listindent;
- } else {
- $this->lMargin -= $this->listindent;
- }
- --$this->listindentlevel;
- $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
- break;
- }
- case 'ul':
- case 'ol': {
- --$this->listnum;
- $this->lispacer = '';
- if ($this->rtl) {
- $this->rMargin -= $this->listindent;
- } else {
- $this->lMargin -= $this->listindent;
- }
- --$this->listindentlevel;
- if ($this->listnum <= 0) {
- $this->listnum = 0;
- $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
- } else {
- $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
- }
- $this->resetLastH();
- break;
- }
- case 'li': {
- $this->lispacer = '';
- $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
- break;
- }
- case 'h1':
- case 'h2':
- case 'h3':
- case 'h4':
- case 'h5':
- case 'h6': {
- $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
- break;
- }
-
- case 'form': {
- $this->form_action = '';
- $this->form_enctype = 'application/x-www-form-urlencoded';
- break;
- }
- default : {
- break;
- }
- }
-
- $this->drawHTMLTagBorder($parent, $xmax);
- if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
- $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
-
- if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
-
- $this->checkPageBreak($this->PageBreakTrigger + 1);
- }
- if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
- OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
-
- $this->checkPageBreak($this->PageBreakTrigger + 1);
- }
- }
- $this->tmprtl = false;
- return $dom;
- }
-
- protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
- if ($firsttag) {
- $this->Ln(0, $cell);
- $this->htmlvspace = 0;
- return;
- }
- if ($lasttag) {
- $this->Ln($hbz, $cell);
- $this->htmlvspace = 0;
- return;
- }
- if ($hb < $this->htmlvspace) {
- $hd = 0;
- } else {
- $hd = $hb - $this->htmlvspace;
- $this->htmlvspace = $hb;
- }
- $this->Ln(($hbz + $hd), $cell);
- }
-
- protected function getBorderStartPosition() {
- if ($this->rtl) {
- $xmax = $this->lMargin;
- } else {
- $xmax = $this->w - $this->rMargin;
- }
- return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
- }
-
- protected function drawHTMLTagBorder($tag, $xmax) {
- if (!isset($tag['borderposition'])) {
-
- return;
- }
- $prev_x = $this->x;
- $prev_y = $this->y;
- $prev_lasth = $this->lasth;
- $border = 0;
- $fill = false;
- $this->lasth = 0;
- if (isset($tag['border']) AND !empty($tag['border'])) {
-
- $border = $tag['border'];
- if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
-
- $border = $this->getBorderMode($border, $position='middle');
- }
- }
- if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
-
- $old_bgcolor = $this->bgcolor;
- $this->SetFillColorArray($tag['bgcolor']);
- $fill = true;
- }
- if (!$border AND !$fill) {
-
- return;
- }
- if (isset($tag['attribute']['cellspacing'])) {
- $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
- $cellspacing = array('H' => $clsp, 'V' => $clsp);
- } elseif (isset($tag['border-spacing'])) {
- $cellspacing = $tag['border-spacing'];
- } else {
- $cellspacing = array('H' => 0, 'V' => 0);
- }
- if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
-
- $border['mode'] = 'ext';
- }
- if ($this->rtl) {
- if ($xmax >= $tag['borderposition']['x']) {
- $xmax = $tag['borderposition']['xmax'];
- }
- $w = ($tag['borderposition']['x'] - $xmax);
- } else {
- if ($xmax <= $tag['borderposition']['x']) {
- $xmax = $tag['borderposition']['xmax'];
- }
- $w = ($xmax - $tag['borderposition']['x']);
- }
- if ($w <= 0) {
- return;
- }
- $w += $cellspacing['H'];
- $startpage = $tag['borderposition']['page'];
- $startcolumn = $tag['borderposition']['column'];
- $x = $tag['borderposition']['x'];
- $y = $tag['borderposition']['y'];
- $endpage = $this->page;
- $starty = $tag['borderposition']['y'] - $cellspacing['V'];
- $currentY = $this->y;
- $this->x = $x;
-
- $endcolumn = $this->current_column;
- if ($this->num_columns == 0) {
- $this->num_columns = 1;
- }
-
- $border_start = $this->getBorderMode($border, $position='start');
- $border_end = $this->getBorderMode($border, $position='end');
- $border_middle = $this->getBorderMode($border, $position='middle');
-
- $temp_page_regions = $this->page_regions;
- $this->page_regions = array();
-
- for ($page = $startpage; $page <= $endpage; ++$page) {
- $ccode = '';
- $this->setPage($page);
- if ($this->num_columns < 2) {
-
- $this->x = $x;
- $this->y = $this->tMargin;
- }
-
- if ($page > $startpage) {
- if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
- $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
- } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
- $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
- }
- }
- if ($startpage == $endpage) {
-
- for ($column = $startcolumn; $column <= $endcolumn; ++$column) {
- $this->selectColumn($column);
- if ($startcolumn == $endcolumn) {
- $cborder = $border;
- $h = ($currentY - $y) + $cellspacing['V'];
- $this->y = $starty;
- } elseif ($column == $startcolumn) {
- $cborder = $border_start;
- $this->y = $starty;
- $h = $this->h - $this->y - $this->bMargin;
- } elseif ($column == $endcolumn) {
- $cborder = $border_end;
- $h = $currentY - $this->y;
- } else {
- $cborder = $border_middle;
- $h = $this->h - $this->y - $this->bMargin;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } elseif ($page == $startpage) {
- for ($column = $startcolumn; $column < $this->num_columns; ++$column) {
- $this->selectColumn($column);
- if ($column == $startcolumn) {
- $cborder = $border_start;
- $this->y = $starty;
- $h = $this->h - $this->y - $this->bMargin;
- } else {
- $cborder = $border_middle;
- $h = $this->h - $this->y - $this->bMargin;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } elseif ($page == $endpage) {
- for ($column = 0; $column <= $endcolumn; ++$column) {
- $this->selectColumn($column);
- if ($column == $endcolumn) {
-
- $cborder = $border_end;
- $h = $currentY - $this->y;
- } else {
-
- $cborder = $border_middle;
- $h = $this->h - $this->y - $this->bMargin;
- }
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- } else {
- for ($column = 0; $column < $this->num_columns; ++$column) {
- $this->selectColumn($column);
- $cborder = $border_middle;
- $h = $this->h - $this->y - $this->bMargin;
- $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
- }
- }
- if ($cborder OR $fill) {
- $offsetlen = strlen($ccode);
-
- if ($this->inxobj) {
-
- if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
- $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
- $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
- $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
- } else {
- $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
- $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
- }
- $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
- $pstart = substr($pagebuff, 0, $pagemark);
- $pend = substr($pagebuff, $pagemark);
- $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
- } else {
- if (end($this->transfmrk[$this->page]) !== false) {
- $pagemarkkey = key($this->transfmrk[$this->page]);
- $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
- $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
- } elseif ($this->InFooter) {
- $pagemark = $this->footerpos[$this->page];
- $this->footerpos[$this->page] += $offsetlen;
- } else {
- $pagemark = $this->intmrk[$this->page];
- $this->intmrk[$this->page] += $offsetlen;
- }
- $pagebuff = $this->getPageBuffer($this->page);
- $pstart = substr($pagebuff, 0, $this->bordermrk[$this->page]);
- $pend = substr($pagebuff, $this->bordermrk[$this->page]);
- $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
- $this->bordermrk[$this->page] += $offsetlen;
- $this->cntmrk[$this->page] += $offsetlen;
- }
- }
- }
-
- $this->page_regions = $temp_page_regions;
- if (isset($old_bgcolor)) {
-
- $this->SetFillColorArray($old_bgcolor);
- }
-
- $this->x = $prev_x;
- $this->y = $prev_y;
- $this->lasth = $prev_lasth;
- }
-
- public function setLIsymbol($symbol='!') {
-
- if (substr($symbol, 0, 4) == 'img|') {
- $this->lisymbol = $symbol;
- return;
- }
- $symbol = strtolower($symbol);
- switch ($symbol) {
- case '!' :
- case '#' :
- case 'disc' :
- case 'circle' :
- case 'square' :
- case '1':
- case 'decimal':
- case 'decimal-leading-zero':
- case 'i':
- case 'lower-roman':
- case 'I':
- case 'upper-roman':
- case 'a':
- case 'lower-alpha':
- case 'lower-latin':
- case 'A':
- case 'upper-alpha':
- case 'upper-latin':
- case 'lower-greek': {
- $this->lisymbol = $symbol;
- break;
- }
- default : {
- $this->lisymbol = '';
- }
- }
- }
-
- public function SetBooklet($booklet=true, $inner=-1, $outer=-1) {
- $this->booklet = $booklet;
- if ($inner >= 0) {
- $this->lMargin = $inner;
- }
- if ($outer >= 0) {
- $this->rMargin = $outer;
- }
- }
-
- protected function swapMargins($reverse=true) {
- if ($reverse) {
-
- $mtemp = $this->original_lMargin;
- $this->original_lMargin = $this->original_rMargin;
- $this->original_rMargin = $mtemp;
- $deltam = $this->original_lMargin - $this->original_rMargin;
- $this->lMargin += $deltam;
- $this->rMargin -= $deltam;
- }
- }
-
- public function setHtmlVSpace($tagvs) {
- $this->tagvspaces = $tagvs;
- }
-
- public function setListIndentWidth($width) {
- return $this->customlistindent = floatval($width);
- }
-
- public function setOpenCell($isopen) {
- $this->opencell = $isopen;
- }
-
- public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
- $this->htmlLinkColorArray = $color;
- $this->htmlLinkFontStyle = $fontstyle;
- }
-
- public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
- $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
- $retval = 0;
- $value = 0;
- $unit = 'px';
- $k = $this->k;
- if ($points) {
- $k = 1;
- }
- if (in_array($defaultunit, $supportedunits)) {
- $unit = $defaultunit;
- }
- if (is_numeric($htmlval)) {
- $value = floatval($htmlval);
- } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
- $value = floatval($mnum[1]);
- if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
- if (in_array($munit[1], $supportedunits)) {
- $unit = $munit[1];
- }
- }
- }
- switch ($unit) {
-
- case '%': {
- $retval = (($value * $refsize) / 100);
- break;
- }
-
- case 'em': {
- $retval = ($value * $refsize);
- break;
- }
-
- case 'ex': {
- $retval = $value * ($refsize / 2);
- break;
- }
-
- case 'in': {
- $retval = ($value * $this->dpi) / $k;
- break;
- }
-
- case 'cm': {
- $retval = ($value / 2.54 * $this->dpi) / $k;
- break;
- }
-
- case 'mm': {
- $retval = ($value / 25.4 * $this->dpi) / $k;
- break;
- }
-
- case 'pc': {
- $retval = ($value * 12) / $k;
- break;
- }
-
- case 'pt': {
- $retval = $value / $k;
- break;
- }
-
- case 'px': {
- $retval = $this->pixelsToUnits($value);
- break;
- }
- }
- return $retval;
- }
-
- public function intToRoman($number) {
- $roman = '';
- while ($number >= 1000) {
- $roman .= 'M';
- $number -= 1000;
- }
- while ($number >= 900) {
- $roman .= 'CM';
- $number -= 900;
- }
- while ($number >= 500) {
- $roman .= 'D';
- $number -= 500;
- }
- while ($number >= 400) {
- $roman .= 'CD';
- $number -= 400;
- }
- while ($number >= 100) {
- $roman .= 'C';
- $number -= 100;
- }
- while ($number >= 90) {
- $roman .= 'XC';
- $number -= 90;
- }
- while ($number >= 50) {
- $roman .= 'L';
- $number -= 50;
- }
- while ($number >= 40) {
- $roman .= 'XL';
- $number -= 40;
- }
- while ($number >= 10) {
- $roman .= 'X';
- $number -= 10;
- }
- while ($number >= 9) {
- $roman .= 'IX';
- $number -= 9;
- }
- while ($number >= 5) {
- $roman .= 'V';
- $number -= 5;
- }
- while ($number >= 4) {
- $roman .= 'IV';
- $number -= 4;
- }
- while ($number >= 1) {
- $roman .= 'I';
- --$number;
- }
- return $roman;
- }
-
- protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
- $size /= $this->k;
- $fill = '';
- $bgcolor = $this->bgcolor;
- $color = $this->fgcolor;
- $strokecolor = $this->strokecolor;
- $width = 0;
- $textitem = '';
- $tmpx = $this->x;
- $lspace = $this->GetStringWidth(' ');
- if ($listtype == '^') {
-
- $this->lispacer = '';
- return;
- } elseif ($listtype == '!') {
-
- $deftypes = array('disc', 'circle', 'square');
- $listtype = $deftypes[($listdepth - 1) % 3];
- } elseif ($listtype == '#') {
-
- $listtype = 'decimal';
- } elseif (substr($listtype, 0, 4) == 'img|') {
-
- $img = explode('|', $listtype);
- $listtype = 'img';
- }
- switch ($listtype) {
-
- case 'none': {
- break;
- }
- case 'disc': {
- $r = $size / 6;
- $lspace += (2 * $r);
- if ($this->rtl) {
- $this->x += $lspace;
- } else {
- $this->x -= $lspace;
- }
- $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
- break;
- }
- case 'circle': {
- $r = $size / 6;
- $lspace += (2 * $r);
- if ($this->rtl) {
- $this->x += $lspace;
- } else {
- $this->x -= $lspace;
- }
- $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
- $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
- $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
- $this->_out($prev_line_style);
- break;
- }
- case 'square': {
- $l = $size / 3;
- $lspace += $l;
- if ($this->rtl) {;
- $this->x += $lspace;
- } else {
- $this->x -= $lspace;
- }
- $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
- break;
- }
- case 'img': {
-
- $lspace += $img[2];
- if ($this->rtl) {;
- $this->x += $lspace;
- } else {
- $this->x -= $lspace;
- }
- $imgtype = strtolower($img[1]);
- $prev_y = $this->y;
- switch ($imgtype) {
- case 'svg': {
- $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
- break;
- }
- case 'ai':
- case 'eps': {
- $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
- break;
- }
- default: {
- $this->Image($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], $img[1], '', 'T', false, 300, '', false, false, 0, false, false, false);
- break;
- }
- }
- $this->y = $prev_y;
- break;
- }
-
-
-
- case '1':
- case 'decimal': {
- $textitem = $this->listcount[$this->listnum];
- break;
- }
- case 'decimal-leading-zero': {
- $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
- break;
- }
- case 'i':
- case 'lower-roman': {
- $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum]));
- break;
- }
- case 'I':
- case 'upper-roman': {
- $textitem = $this->intToRoman($this->listcount[$this->listnum]);
- break;
- }
- case 'a':
- case 'lower-alpha':
- case 'lower-latin': {
- $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
- break;
- }
- case 'A':
- case 'upper-alpha':
- case 'upper-latin': {
- $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
- break;
- }
- case 'lower-greek': {
- $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1);
- break;
- }
-
- default: {
- $textitem = $this->listcount[$this->listnum];
- }
- }
- if (!$this->empty_string($textitem)) {
-
- $prev_y = $this->y;
- $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
- if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
- $tmpx = $this->x;
- }
-
- if ($this->rtl) {
- $textitem = '.'.$textitem;
- } else {
- $textitem = $textitem.'.';
- }
- $lspace += $this->GetStringWidth($textitem);
- if ($this->rtl) {
- $this->x += $lspace;
- } else {
- $this->x -= $lspace;
- }
- $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
- }
- $this->x = $tmpx;
- $this->lispacer = '^';
-
- $this->SetFillColorArray($bgcolor);
- $this->SetDrawColorArray($strokecolor);
- $this->SettextColorArray($color);
- }
-
- protected function getGraphicVars() {
- $grapvars = array(
- 'FontFamily' => $this->FontFamily,
- 'FontStyle' => $this->FontStyle,
- 'FontSizePt' => $this->FontSizePt,
- 'rMargin' => $this->rMargin,
- 'lMargin' => $this->lMargin,
- 'cell_padding' => $this->cell_padding,
- 'cell_margin' => $this->cell_margin,
- 'LineWidth' => $this->LineWidth,
- 'linestyleWidth' => $this->linestyleWidth,
- 'linestyleCap' => $this->linestyleCap,
- 'linestyleJoin' => $this->linestyleJoin,
- 'linestyleDash' => $this->linestyleDash,
- 'textrendermode' => $this->textrendermode,
- 'textstrokewidth' => $this->textstrokewidth,
- 'DrawColor' => $this->DrawColor,
- 'FillColor' => $this->FillColor,
- 'TextColor' => $this->TextColor,
- 'ColorFlag' => $this->ColorFlag,
- 'bgcolor' => $this->bgcolor,
- 'fgcolor' => $this->fgcolor,
- 'htmlvspace' => $this->htmlvspace,
- 'listindent' => $this->listindent,
- 'listindentlevel' => $this->listindentlevel,
- 'listnum' => $this->listnum,
- 'listordered' => $this->listordered,
- 'listcount' => $this->listcount,
- 'lispacer' => $this->lispacer,
- 'cell_height_ratio' => $this->cell_height_ratio,
- 'font_stretching' => $this->font_stretching,
- 'font_spacing' => $this->font_spacing,
-
- 'lasth' => $this->lasth,
- 'tMargin' => $this->tMargin,
- 'bMargin' => $this->bMargin,
- 'AutoPageBreak' => $this->AutoPageBreak,
- 'PageBreakTrigger' => $this->PageBreakTrigger,
- 'x' => $this->x,
- 'y' => $this->y,
- 'w' => $this->w,
- 'h' => $this->h,
- 'wPt' => $this->wPt,
- 'hPt' => $this->hPt,
- 'fwPt' => $this->fwPt,
- 'fhPt' => $this->fhPt,
- 'page' => $this->page,
- 'current_column' => $this->current_column,
- 'num_columns' => $this->num_columns
- );
- return $grapvars;
- }
-
- protected function setGraphicVars($gvars, $extended=false) {
- $this->FontFamily = $gvars['FontFamily'];
- $this->FontStyle = $gvars['FontStyle'];
- $this->FontSizePt = $gvars['FontSizePt'];
- $this->rMargin = $gvars['rMargin'];
- $this->lMargin = $gvars['lMargin'];
- $this->cell_padding = $gvars['cell_padding'];
- $this->cell_margin = $gvars['cell_margin'];
- $this->LineWidth = $gvars['LineWidth'];
- $this->linestyleWidth = $gvars['linestyleWidth'];
- $this->linestyleCap = $gvars['linestyleCap'];
- $this->linestyleJoin = $gvars['linestyleJoin'];
- $this->linestyleDash = $gvars['linestyleDash'];
- $this->textrendermode = $gvars['textrendermode'];
- $this->textstrokewidth = $gvars['textstrokewidth'];
- $this->DrawColor = $gvars['DrawColor'];
- $this->FillColor = $gvars['FillColor'];
- $this->TextColor = $gvars['TextColor'];
- $this->ColorFlag = $gvars['ColorFlag'];
- $this->bgcolor = $gvars['bgcolor'];
- $this->fgcolor = $gvars['fgcolor'];
- $this->htmlvspace = $gvars['htmlvspace'];
- $this->listindent = $gvars['listindent'];
- $this->listindentlevel = $gvars['listindentlevel'];
- $this->listnum = $gvars['listnum'];
- $this->listordered = $gvars['listordered'];
- $this->listcount = $gvars['listcount'];
- $this->lispacer = $gvars['lispacer'];
- $this->cell_height_ratio = $gvars['cell_height_ratio'];
- $this->font_stretching = $gvars['font_stretching'];
- $this->font_spacing = $gvars['font_spacing'];
- if ($extended) {
-
- $this->lasth = $gvars['lasth'];
- $this->tMargin = $gvars['tMargin'];
- $this->bMargin = $gvars['bMargin'];
- $this->AutoPageBreak = $gvars['AutoPageBreak'];
- $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
- $this->x = $gvars['x'];
- $this->y = $gvars['y'];
- $this->w = $gvars['w'];
- $this->h = $gvars['h'];
- $this->wPt = $gvars['wPt'];
- $this->hPt = $gvars['hPt'];
- $this->fwPt = $gvars['fwPt'];
- $this->fhPt = $gvars['fhPt'];
- $this->page = $gvars['page'];
- $this->current_column = $gvars['current_column'];
- $this->num_columns = $gvars['num_columns'];
- }
- $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
- if (!$this->empty_string($this->FontFamily)) {
- $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
- }
- }
-
- protected function getObjFilename($name) {
- return tempnam(K_PATH_CACHE, $name.'_');
- }
-
- protected function writeDiskCache($filename, $data, $append=false) {
- if ($append) {
- $fmode = 'ab+';
- } else {
- $fmode = 'wb+';
- }
- $f = @fopen($filename, $fmode);
- if (!$f) {
- $this->Error('Unable to write cache file: '.$filename);
- } else {
- fwrite($f, $data);
- fclose($f);
- }
-
- if (!isset($this->cache_file_length['_'.$filename])) {
- $this->cache_file_length['_'.$filename] = strlen($data);
- } else {
- $this->cache_file_length['_'.$filename] += strlen($data);
- }
- }
-
- protected function readDiskCache($filename) {
- return file_get_contents($filename);
- }
-
- protected function setBuffer($data) {
- $this->bufferlen += strlen($data);
- if ($this->diskcache) {
- if (!isset($this->buffer) OR $this->empty_string($this->buffer)) {
- $this->buffer = $this->getObjFilename('buffer');
- }
- $this->writeDiskCache($this->buffer, $data, true);
- } else {
- $this->buffer .= $data;
- }
- }
-
- protected function replaceBuffer($data) {
- $this->bufferlen = strlen($data);
- if ($this->diskcache) {
- if (!isset($this->buffer) OR $this->empty_string($this->buffer)) {
- $this->buffer = $this->getObjFilename('buffer');
- }
- $this->writeDiskCache($this->buffer, $data, false);
- } else {
- $this->buffer = $data;
- }
- }
-
- protected function getBuffer() {
- if ($this->diskcache) {
- return $this->readDiskCache($this->buffer);
- } else {
- return $this->buffer;
- }
- }
-
- protected function setPageBuffer($page, $data, $append=false) {
- if ($this->diskcache) {
- if (!isset($this->pages[$page])) {
- $this->pages[$page] = $this->getObjFilename('page'.$page);
- }
- $this->writeDiskCache($this->pages[$page], $data, $append);
- } else {
- if ($append) {
- $this->pages[$page] .= $data;
- } else {
- $this->pages[$page] = $data;
- }
- }
- if ($append AND isset($this->pagelen[$page])) {
- $this->pagelen[$page] += strlen($data);
- } else {
- $this->pagelen[$page] = strlen($data);
- }
- }
-
- protected function getPageBuffer($page) {
- if ($this->diskcache) {
- return $this->readDiskCache($this->pages[$page]);
- } elseif (isset($this->pages[$page])) {
- return $this->pages[$page];
- }
- return false;
- }
-
- protected function setImageBuffer($image, $data) {
- if ($this->diskcache) {
- if (!isset($this->images[$image])) {
- $this->images[$image] = $this->getObjFilename('image'.$image);
- }
- $this->writeDiskCache($this->images[$image], serialize($data));
- } else {
- $this->images[$image] = $data;
- }
- if (!in_array($image, $this->imagekeys)) {
- $this->imagekeys[] = $image;
- ++$this->numimages;
- }
- }
-
- protected function setImageSubBuffer($image, $key, $data) {
- if (!isset($this->images[$image])) {
- $this->setImageBuffer($image, array());
- }
- if ($this->diskcache) {
- $tmpimg = $this->getImageBuffer($image);
- $tmpimg[$key] = $data;
- $this->writeDiskCache($this->images[$image], serialize($tmpimg));
- } else {
- $this->images[$image][$key] = $data;
- }
- }
-
- protected function getImageBuffer($image) {
- if ($this->diskcache AND isset($this->images[$image])) {
- return unserialize($this->readDiskCache($this->images[$image]));
- } elseif (isset($this->images[$image])) {
- return $this->images[$image];
- }
- return false;
- }
-
- protected function setFontBuffer($font, $data) {
- if ($this->diskcache) {
- if (!isset($this->fonts[$font])) {
- $this->fonts[$font] = $this->getObjFilename('font');
- }
- $this->writeDiskCache($this->fonts[$font], serialize($data));
- } else {
- $this->fonts[$font] = $data;
- }
- if (!in_array($font, $this->fontkeys)) {
- $this->fontkeys[] = $font;
-
- ++$this->n;
- $this->font_obj_ids[$font] = $this->n;
- $this->setFontSubBuffer($font, 'n', $this->n);
- }
- }
-
- protected function setFontSubBuffer($font, $key, $data) {
- if (!isset($this->fonts[$font])) {
- $this->setFontBuffer($font, array());
- }
- if ($this->diskcache) {
- $tmpfont = $this->getFontBuffer($font);
- $tmpfont[$key] = $data;
- $this->writeDiskCache($this->fonts[$font], serialize($tmpfont));
- } else {
- $this->fonts[$font][$key] = $data;
- }
- }
-
- protected function getFontBuffer($font) {
- if ($this->diskcache AND isset($this->fonts[$font])) {
- return unserialize($this->readDiskCache($this->fonts[$font]));
- } elseif (isset($this->fonts[$font])) {
- return $this->fonts[$font];
- }
- return false;
- }
-
- public function movePage($frompage, $topage) {
- if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
- return false;
- }
- if ($frompage == $this->page) {
-
- $this->endPage();
- }
-
- $tmppage = $this->getPageBuffer($frompage);
- $tmppagedim = $this->pagedim[$frompage];
- $tmppagelen = $this->pagelen[$frompage];
- $tmpintmrk = $this->intmrk[$frompage];
- $tmpbordermrk = $this->bordermrk[$frompage];
- $tmpcntmrk = $this->cntmrk[$frompage];
- if (isset($this->footerpos[$frompage])) {
- $tmpfooterpos = $this->footerpos[$frompage];
- }
- if (isset($this->footerlen[$frompage])) {
- $tmpfooterlen = $this->footerlen[$frompage];
- }
- if (isset($this->transfmrk[$frompage])) {
- $tmptransfmrk = $this->transfmrk[$frompage];
- }
- if (isset($this->PageAnnots[$frompage])) {
- $tmpannots = $this->PageAnnots[$frompage];
- }
- if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
- for ($i = $frompage; $i > $topage; --$i) {
- if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
- --$this->pagegroups[$this->newpagegroup[$i]];
- break;
- }
- }
- for ($i = $topage; $i > 0; --$i) {
- if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
- ++$this->pagegroups[$this->newpagegroup[$i]];
- break;
- }
- }
- }
- for ($i = $frompage; $i > $topage; --$i) {
- $j = $i - 1;
-
- $this->setPageBuffer($i, $this->getPageBuffer($j));
- $this->pagedim[$i] = $this->pagedim[$j];
- $this->pagelen[$i] = $this->pagelen[$j];
- $this->intmrk[$i] = $this->intmrk[$j];
- $this->bordermrk[$i] = $this->bordermrk[$j];
- $this->cntmrk[$i] = $this->cntmrk[$j];
- if (isset($this->footerpos[$j])) {
- $this->footerpos[$i] = $this->footerpos[$j];
- } elseif (isset($this->footerpos[$i])) {
- unset($this->footerpos[$i]);
- }
- if (isset($this->footerlen[$j])) {
- $this->footerlen[$i] = $this->footerlen[$j];
- } elseif (isset($this->footerlen[$i])) {
- unset($this->footerlen[$i]);
- }
- if (isset($this->transfmrk[$j])) {
- $this->transfmrk[$i] = $this->transfmrk[$j];
- } elseif (isset($this->transfmrk[$i])) {
- unset($this->transfmrk[$i]);
- }
- if (isset($this->PageAnnots[$j])) {
- $this->PageAnnots[$i] = $this->PageAnnots[$j];
- } elseif (isset($this->PageAnnots[$i])) {
- unset($this->PageAnnots[$i]);
- }
- if (isset($this->newpagegroup[$j])) {
- $this->newpagegroup[$i] = $this->newpagegroup[$j];
- unset($this->newpagegroup[$j]);
- }
- if ($this->currpagegroup == $j) {
- $this->currpagegroup = $i;
- }
- }
- $this->setPageBuffer($topage, $tmppage);
- $this->pagedim[$topage] = $tmppagedim;
- $this->pagelen[$topage] = $tmppagelen;
- $this->intmrk[$topage] = $tmpintmrk;
- $this->bordermrk[$topage] = $tmpbordermrk;
- $this->cntmrk[$topage] = $tmpcntmrk;
- if (isset($tmpfooterpos)) {
- $this->footerpos[$topage] = $tmpfooterpos;
- } elseif (isset($this->footerpos[$topage])) {
- unset($this->footerpos[$topage]);
- }
- if (isset($tmpfooterlen)) {
- $this->footerlen[$topage] = $tmpfooterlen;
- } elseif (isset($this->footerlen[$topage])) {
- unset($this->footerlen[$topage]);
- }
- if (isset($tmptransfmrk)) {
- $this->transfmrk[$topage] = $tmptransfmrk;
- } elseif (isset($this->transfmrk[$topage])) {
- unset($this->transfmrk[$topage]);
- }
- if (isset($tmpannots)) {
- $this->PageAnnots[$topage] = $tmpannots;
- } elseif (isset($this->PageAnnots[$topage])) {
- unset($this->PageAnnots[$topage]);
- }
-
- $tmpoutlines = $this->outlines;
- foreach ($tmpoutlines as $key => $outline) {
- if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
- $this->outlines[$key]['p'] = ($outline['p'] + 1);
- } elseif ($outline['p'] == $frompage) {
- $this->outlines[$key]['p'] = $topage;
- }
- }
-
- $tmpdests = $this->dests;
- foreach ($tmpdests as $key => $dest) {
- if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
- $this->dests[$key]['p'] = ($dest['p'] + 1);
- } elseif ($dest['p'] == $frompage) {
- $this->dests[$key]['p'] = $topage;
- }
- }
-
- $tmplinks = $this->links;
- foreach ($tmplinks as $key => $link) {
- if (($link[0] >= $topage) AND ($link[0] < $frompage)) {
- $this->links[$key][0] = ($link[0] + 1);
- } elseif ($link[0] == $frompage) {
- $this->links[$key][0] = $topage;
- }
- }
-
- $tmpjavascript = $this->javascript;
- global $jfrompage, $jtopage;
- $jfrompage = $frompage;
- $jtopage = $topage;
- $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
- create_function('$matches', 'global $jfrompage, $jtopage;
- $pagenum = intval($matches[3]) + 1;
- if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
- $newpage = ($pagenum + 1);
- } elseif ($pagenum == $jfrompage) {
- $newpage = $jtopage;
- } else {
- $newpage = $pagenum;
- }
- --$newpage;
- return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
-
- $this->lastPage(true);
- return true;
- }
-
- public function deletePage($page) {
- if (($page < 1) OR ($page > $this->numpages)) {
- return false;
- }
-
- unset($this->pages[$page]);
- unset($this->pagedim[$page]);
- unset($this->pagelen[$page]);
- unset($this->intmrk[$page]);
- unset($this->bordermrk[$page]);
- unset($this->cntmrk[$page]);
- if (isset($this->footerpos[$page])) {
- unset($this->footerpos[$page]);
- }
- if (isset($this->footerlen[$page])) {
- unset($this->footerlen[$page]);
- }
- if (isset($this->transfmrk[$page])) {
- unset($this->transfmrk[$page]);
- }
- if (isset($this->PageAnnots[$page])) {
- unset($this->PageAnnots[$page]);
- }
- if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
- for ($i = $page; $i > 0; --$i) {
- if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
- --$this->pagegroups[$this->newpagegroup[$i]];
- break;
- }
- }
- }
- if (isset($this->pageopen[$page])) {
- unset($this->pageopen[$page]);
- }
- if ($page < $this->numpages) {
-
- for ($i = $page; $i < $this->numpages; ++$i) {
- $j = $i + 1;
-
- $this->setPageBuffer($i, $this->getPageBuffer($j));
- $this->pagedim[$i] = $this->pagedim[$j];
- $this->pagelen[$i] = $this->pagelen[$j];
- $this->intmrk[$i] = $this->intmrk[$j];
- $this->bordermrk[$i] = $this->bordermrk[$j];
- $this->cntmrk[$i] = $this->cntmrk[$j];
- if (isset($this->footerpos[$j])) {
- $this->footerpos[$i] = $this->footerpos[$j];
- } elseif (isset($this->footerpos[$i])) {
- unset($this->footerpos[$i]);
- }
- if (isset($this->footerlen[$j])) {
- $this->footerlen[$i] = $this->footerlen[$j];
- } elseif (isset($this->footerlen[$i])) {
- unset($this->footerlen[$i]);
- }
- if (isset($this->transfmrk[$j])) {
- $this->transfmrk[$i] = $this->transfmrk[$j];
- } elseif (isset($this->transfmrk[$i])) {
- unset($this->transfmrk[$i]);
- }
- if (isset($this->PageAnnots[$j])) {
- $this->PageAnnots[$i] = $this->PageAnnots[$j];
- } elseif (isset($this->PageAnnots[$i])) {
- unset($this->PageAnnots[$i]);
- }
- if (isset($this->newpagegroup[$j])) {
- $this->newpagegroup[$i] = $this->newpagegroup[$j];
- unset($this->newpagegroup[$j]);
- }
- if ($this->currpagegroup == $j) {
- $this->currpagegroup = $i;
- }
- if (isset($this->pageopen[$j])) {
- $this->pageopen[$i] = $this->pageopen[$j];
- } elseif (isset($this->pageopen[$i])) {
- unset($this->pageopen[$i]);
- }
- }
-
- unset($this->pages[$this->numpages]);
- unset($this->pagedim[$this->numpages]);
- unset($this->pagelen[$this->numpages]);
- unset($this->intmrk[$this->numpages]);
- unset($this->bordermrk[$this->numpages]);
- unset($this->cntmrk[$this->numpages]);
- if (isset($this->footerpos[$this->numpages])) {
- unset($this->footerpos[$this->numpages]);
- }
- if (isset($this->footerlen[$this->numpages])) {
- unset($this->footerlen[$this->numpages]);
- }
- if (isset($this->transfmrk[$this->numpages])) {
- unset($this->transfmrk[$this->numpages]);
- }
- if (isset($this->PageAnnots[$this->numpages])) {
- unset($this->PageAnnots[$this->numpages]);
- }
- if (isset($this->newpagegroup[$this->numpages])) {
- unset($this->newpagegroup[$this->numpages]);
- }
- if ($this->currpagegroup == $this->numpages) {
- $this->currpagegroup = ($this->numpages - 1);
- }
- if (isset($this->pagegroups[$this->numpages])) {
- unset($this->pagegroups[$this->numpages]);
- }
- if (isset($this->pageopen[$this->numpages])) {
- unset($this->pageopen[$this->numpages]);
- }
- }
- --$this->numpages;
- $this->page = $this->numpages;
-
- $tmpoutlines = $this->outlines;
- foreach ($tmpoutlines as $key => $outline) {
- if ($outline['p'] > $page) {
- $this->outlines[$key]['p'] = $outline['p'] - 1;
- } elseif ($outline['p'] == $page) {
- unset($this->outlines[$key]);
- }
- }
-
- $tmpdests = $this->dests;
- foreach ($tmpdests as $key => $dest) {
- if ($dest['p'] > $page) {
- $this->dests[$key]['p'] = $dest['p'] - 1;
- } elseif ($dest['p'] == $page) {
- unset($this->dests[$key]);
- }
- }
-
- $tmplinks = $this->links;
- foreach ($tmplinks as $key => $link) {
- if ($link[0] > $page) {
- $this->links[$key][0] = $link[0] - 1;
- } elseif ($link[0] == $page) {
- unset($this->links[$key]);
- }
- }
-
- $tmpjavascript = $this->javascript;
- global $jpage;
- $jpage = $page;
- $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
- create_function('$matches', 'global $jpage;
- $pagenum = intval($matches[3]) + 1;
- if ($pagenum >= $jpage) {
- $newpage = ($pagenum - 1);
- } elseif ($pagenum == $jpage) {
- $newpage = 1;
- } else {
- $newpage = $pagenum;
- }
- --$newpage;
- return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
-
- $this->lastPage(true);
- return true;
- }
-
- public function copyPage($page=0) {
- if ($page == 0) {
-
- $page = $this->page;
- }
- if (($page < 1) OR ($page > $this->numpages)) {
- return false;
- }
-
- $this->endPage();
-
- ++$this->numpages;
- $this->page = $this->numpages;
- $this->setPageBuffer($this->page, $this->getPageBuffer($page));
- $this->pagedim[$this->page] = $this->pagedim[$page];
- $this->pagelen[$this->page] = $this->pagelen[$page];
- $this->intmrk[$this->page] = $this->intmrk[$page];
- $this->bordermrk[$this->page] = $this->bordermrk[$page];
- $this->cntmrk[$this->page] = $this->cntmrk[$page];
- $this->pageopen[$this->page] = false;
- if (isset($this->footerpos[$page])) {
- $this->footerpos[$this->page] = $this->footerpos[$page];
- }
- if (isset($this->footerlen[$page])) {
- $this->footerlen[$this->page] = $this->footerlen[$page];
- }
- if (isset($this->transfmrk[$page])) {
- $this->transfmrk[$this->page] = $this->transfmrk[$page];
- }
- if (isset($this->PageAnnots[$page])) {
- $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
- }
- if (isset($this->newpagegroup[$page])) {
-
- $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
- $this->currpagegroup = $this->newpagegroup[$this->page];
- $this->pagegroups[$this->currpagegroup] = 1;
- } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
- ++$this->pagegroups[$this->currpagegroup];
- }
-
- $tmpoutlines = $this->outlines;
- foreach ($tmpoutlines as $key => $outline) {
- if ($outline['p'] == $page) {
- $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'y' => $outline['y'], 'p' => $this->page, 's' => $outline['s'], 'c' => $outline['c']);
- }
- }
-
- $tmplinks = $this->links;
- foreach ($tmplinks as $key => $link) {
- if ($link[0] == $page) {
- $this->links[] = array($this->page, $link[1]);
- }
- }
-
- $this->lastPage(true);
- return true;
- }
-
- public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
- $fontsize = $this->FontSizePt;
- $fontfamily = $this->FontFamily;
- $fontstyle = $this->FontStyle;
- $w = $this->w - $this->lMargin - $this->rMargin;
- $spacer = $this->GetStringWidth(chr(32)) * 4;
- $page_first = $this->getPage();
- $lmargin = $this->lMargin;
- $rmargin = $this->rMargin;
- $x_start = $this->GetX();
- $current_page = $this->page;
- $current_column = $this->current_column;
- if ($this->empty_string($numbersfont)) {
- $numbersfont = $this->default_monospaced_font;
- }
- if ($this->empty_string($filler)) {
- $filler = ' ';
- }
- if ($this->empty_string($page)) {
- $gap = ' ';
- } else {
- $gap = '';
- if ($page < 1) {
- $page = 1;
- }
- }
- $this->SetFont($numbersfont, $fontstyle, $fontsize);
- $numwidth = $this->GetStringWidth('00000');
- $maxpage = 0;
- foreach ($this->outlines as $key => $outline) {
-
- if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
- $outline['p'] += ($this->page - $page_first);
- }
- if ($this->rtl) {
- $aligntext = 'R';
- $alignnum = 'L';
- } else {
- $aligntext = 'L';
- $alignnum = 'R';
- }
- if ($outline['l'] == 0) {
- $this->SetFont($fontfamily, $fontstyle.'B', $fontsize);
- } else {
- $this->SetFont($fontfamily, $fontstyle, $fontsize - $outline['l']);
- }
-
- $this->checkPageBreak((2 * $this->FontSize * $this->cell_height_ratio));
-
- if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
- $this->lMargin = $lmargin;
- $this->rMargin = $rmargin;
- } else {
- if ($this->current_column != $current_column) {
- if ($this->rtl) {
- $x_start = $this->w - $this->columns[$this->current_column]['x'];
- } else {
- $x_start = $this->columns[$this->current_column]['x'];
- }
- }
- $lmargin = $this->lMargin;
- $rmargin = $this->rMargin;
- $current_page = $this->page;
- $current_column = $this->current_column;
- }
- $this->SetX($x_start);
- $indent = ($spacer * $outline['l']);
- if ($this->rtl) {
- $this->x -= $indent;
- $this->rMargin = $this->w - $this->x;
- } else {
- $this->x += $indent;
- $this->lMargin = $this->x;
- }
- $link = $this->AddLink();
- $this->SetLink($link, $outline['y'], $outline['p']);
-
- if ($this->rtl) {
- $txt = ' '.$outline['t'];
- } else {
- $txt = $outline['t'].' ';
- }
- $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
- if ($this->rtl) {
- $tw = $this->x - $this->lMargin;
- } else {
- $tw = $this->w - $this->rMargin - $this->x;
- }
- $this->SetFont($numbersfont, $fontstyle, $fontsize);
- if ($this->empty_string($page)) {
- $pagenum = $outline['p'];
- } else {
-
- $pagenum = '{#'.($outline['p']).'}';
- if ($this->isUnicodeFont()) {
- $pagenum = '{'.$pagenum.'}';
- }
- $maxpage = max($maxpage, $outline['p']);
- }
- $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
- $numfills = floor($fw / $this->GetStringWidth($filler));
- if ($numfills > 0) {
- $rowfill = str_repeat($filler, $numfills);
- } else {
- $rowfill = '';
- }
- if ($this->rtl) {
- $pagenum = $pagenum.$gap.$rowfill;
- } else {
- $pagenum = $rowfill.$gap.$pagenum;
- }
-
- $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
- }
- $page_last = $this->getPage();
- $maxpage = max($maxpage, $page_last);
- $numpages = $page_last - $page_first + 1;
- if (!$this->empty_string($page)) {
- for ($p = $page_first; $p <= $page_last; ++$p) {
-
- $temppage = $this->getPageBuffer($p);
- for ($n = 1; $n <= $maxpage; ++$n) {
-
- $a = '{#'.$n.'}';
-
- $pnalias = $this->getInternalPageNumberAliases($a);
-
- if (($n >= $page) AND ($n <= $this->numpages)) {
- $np = $n + $numpages;
- } else {
- $np = $n;
- }
- $na = $this->formatTOCPageNumber(($this->starting_page_number + $np - 1));
- $nu = $this->UTF8ToUTF16BE($na, false);
-
- foreach ($pnalias['u'] as $u) {
- $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
- if ($this->rtl) {
- $nr = $nu.$this->UTF8ToUTF16BE(' '.$sfill);
- } else {
- $nr = $this->UTF8ToUTF16BE($sfill.' ').$nu;
- }
- $temppage = str_replace($u, $nr, $temppage);
- }
- foreach ($pnalias['a'] as $a) {
- $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
- if ($this->rtl) {
- $nr = $na.' '.$sfill;
- } else {
- $nr = $sfill.' '.$na;
- }
- $temppage = str_replace($a, $nr, $temppage);
- }
- }
-
- $this->setPageBuffer($p, $temppage);
- }
-
- $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
- for ($i = 0; $i < $numpages; ++$i) {
- $this->movePage($page_last, $page);
- }
- }
- }
-
- public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
- $filler = ' ';
- $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
- $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
-
- $this->htmlLinkColorArray = array();
- $this->htmlLinkFontStyle = '';
- $page_first = $this->getPage();
-
- $current_font = $this->FontFamily;
- foreach ($templates as $level => $html) {
- $dom = $this->getHtmlDomArray($html);
- foreach ($dom as $key => $value) {
- if ($value['value'] == '#TOC_PAGE_NUMBER#') {
- $this->SetFont($dom[($key - 1)]['fontname']);
- $templates['F'.$level] = $this->isUnicodeFont();
- }
- }
- }
- $this->SetFont($current_font);
- $maxpage = 0;
- foreach ($this->outlines as $key => $outline) {
-
- $row = $templates[$outline['l']];
- if ($this->empty_string($page)) {
- $pagenum = $outline['p'];
- } else {
-
- $pagenum = '{#'.($outline['p']).'}';
- if ($templates['F'.$outline['l']]) {
- $pagenum = '{'.$pagenum.'}';
- }
- $maxpage = max($maxpage, $outline['p']);
- }
-
- $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
- $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
-
- $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
-
- $this->writeHTML($row, false, false, true, false, '');
- }
-
- $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
- $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
-
- $page_last = $this->getPage();
- $maxpage = max($maxpage, $page_last);
- $numpages = $page_last - $page_first + 1;
- if (!$this->empty_string($page)) {
- for ($p = $page_first; $p <= $page_last; ++$p) {
-
- $temppage = $this->getPageBuffer($p);
- for ($n = 1; $n <= $maxpage; ++$n) {
-
- $a = '{#'.$n.'}';
-
- $pnalias = $this->getInternalPageNumberAliases($a);
-
- if ($n >= $page) {
- $np = $n + $numpages;
- } else {
- $np = $n;
- }
- $na = $this->formatTOCPageNumber(($this->starting_page_number + $np - 1));
- $nu = $this->UTF8ToUTF16BE($na, false);
-
- foreach ($pnalias['u'] as $u) {
- if ($correct_align) {
- $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
- if ($this->rtl) {
- $nr = $nu.$this->UTF8ToUTF16BE(' '.$sfill);
- } else {
- $nr = $this->UTF8ToUTF16BE($sfill.' ').$nu;
- }
- } else {
- $nr = $nu;
- }
- $temppage = str_replace($u, $nr, $temppage);
- }
- foreach ($pnalias['a'] as $a) {
- if ($correct_align) {
- $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
- if ($this->rtl) {
- $nr = $na.' '.$sfill;
- } else {
- $nr = $sfill.' '.$na;
- }
- } else {
- $nr = $na;
- }
- $temppage = str_replace($a, $nr, $temppage);
- }
- }
-
- $this->setPageBuffer($p, $temppage);
- }
-
- $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
- for ($i = 0; $i < $numpages; ++$i) {
- $this->movePage($page_last, $page);
- }
- }
- }
-
- public function startTransaction() {
- if (isset($this->objcopy)) {
-
- $this->commitTransaction();
- }
-
- $this->start_transaction_page = $this->page;
- $this->start_transaction_y = $this->y;
-
- $this->objcopy = $this->objclone($this);
- }
-
- public function commitTransaction() {
- if (isset($this->objcopy)) {
- $this->objcopy->_destroy(true, true);
- unset($this->objcopy);
- }
- }
-
- public function rollbackTransaction($self=false) {
- if (isset($this->objcopy)) {
- if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) {
-
- foreach ($this->objcopy->cache_file_length as $file => $length) {
- $file = substr($file, 1);
- $handle = fopen($file, 'r+');
- ftruncate($handle, $length);
- }
- }
- $this->_destroy(true, true);
- if ($self) {
- $objvars = get_object_vars($this->objcopy);
- foreach ($objvars as $key => $value) {
- $this->$key = $value;
- }
- }
- return $this->objcopy;
- }
- return $this;
- }
-
- public function objclone($object) {
- return @clone($object);
- }
-
- public function empty_string($str) {
- return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
- }
-
- public function revstrpos($haystack, $needle, $offset = 0) {
- $length = strlen($haystack);
- $offset = ($offset > 0)?($length - $offset):abs($offset);
- $pos = strpos(strrev($haystack), strrev($needle), $offset);
- return ($pos === false)?false:($length - $pos - strlen($needle));
- }
-
-
- public function setEqualColumns($numcols=0, $width=0, $y='') {
- $this->columns = array();
- if ($numcols < 2) {
- $numcols = 0;
- $this->columns = array();
- } else {
-
- $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
- if (($width == 0) OR ($width > $maxwidth)) {
- $width = $maxwidth;
- }
- if ($this->empty_string($y)) {
- $y = $this->y;
- }
-
- $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
-
- for ($i = 0; $i < $numcols; ++$i) {
- $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
- }
- }
- $this->num_columns = $numcols;
- $this->current_column = 0;
- $this->column_start_page = $this->page;
- $this->selectColumn(0);
- }
-
- public function resetColumns() {
- $this->lMargin = $this->original_lMargin;
- $this->rMargin = $this->original_rMargin;
- $this->setEqualColumns();
- }
-
- public function setColumnsArray($columns) {
- $this->columns = $columns;
- $this->num_columns = count($columns);
- $this->current_column = 0;
- $this->column_start_page = $this->page;
- $this->selectColumn(0);
- }
-
- public function selectColumn($col='') {
- if (is_string($col)) {
- $col = $this->current_column;
- } elseif ($col >= $this->num_columns) {
- $col = 0;
- }
- $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
- $enable_thead = false;
- if ($this->num_columns > 1) {
- if ($col != $this->current_column) {
-
- if ($this->column_start_page == $this->page) {
- $this->y = $this->columns[$col]['y'];
- } else {
- $this->y = $this->tMargin;
- }
-
- if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
- $enable_thead = true;
- $this->maxselcol['page'] = $this->page;
- $this->maxselcol['column'] = $col;
- }
- }
- $xshift = $this->colxshift;
-
- $listindent = ($this->listindentlevel * $this->listindent);
-
- $colpos = 0;
- for ($i = 0; $i < $col; ++$i) {
- $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
- }
- if ($this->rtl) {
- $x = $this->w - $this->original_rMargin - $colpos;
- $this->rMargin = ($this->w - $x + $listindent);
- $this->lMargin = ($x - $this->columns[$col]['w']);
- $this->x = $x - $listindent;
- } else {
- $x = $this->original_lMargin + $colpos;
- $this->lMargin = ($x + $listindent);
- $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
- $this->x = $x + $listindent;
- }
- $this->columns[$col]['x'] = $x;
- }
- $this->current_column = $col;
-
- $this->newline = true;
-
- if ((!$this->empty_string($this->thead)) AND (!$this->inthead)) {
- if ($enable_thead) {
-
- $this->writeHTML($this->thead, false, false, false, false, '');
- $this->y += $xshift['s']['V'];
-
- if (!isset($this->columns[$col]['th'])) {
- $this->columns[$col]['th'] = array();
- }
- $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
- $this->lasth = 0;
- } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
- $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
- }
- }
-
- if ($this->rtl) {
- $this->rMargin += $xshift['x'];
- $this->x -= ($xshift['x'] + $xshift['p']['R']);
- } else {
- $this->lMargin += $xshift['x'];
- $this->x += $xshift['x'] + $xshift['p']['L'];
- }
- }
-
- public function getColumn() {
- return $this->current_column;
- }
-
- public function getNumberOfColumns() {
- return $this->num_columns;
- }
-
- public function serializeTCPDFtagParameters($pararray) {
- return urlencode(serialize($pararray));
- }
-
- public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
-
-
- if ($stroke < 0) {
- $stroke = 0;
- }
- if ($fill === true) {
- if ($stroke > 0) {
- if ($clip === true) {
-
- $textrendermode = 6;
- } else {
-
- $textrendermode = 2;
- }
- $textstrokewidth = $stroke;
- } else {
- if ($clip === true) {
-
- $textrendermode = 4;
- } else {
-
- $textrendermode = 0;
- }
- }
- } else {
- if ($stroke > 0) {
- if ($clip === true) {
-
- $textrendermode = 5;
- } else {
-
- $textrendermode = 1;
- }
- $textstrokewidth = $stroke;
- } else {
- if ($clip === true) {
-
- $textrendermode = 7;
- } else {
-
- $textrendermode = 3;
- }
- }
- }
- $this->textrendermode = $textrendermode;
- $this->textstrokewidth = $stroke * $this->k;
- }
-
- protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
- $hyphenword = array();
- $numchars = count($word);
- if ($numchars <= $charmin) {
- return $word;
- }
- $word_string = $this->UTF8ArrSubString($word);
-
- $pattern = '/^([a-zA-Z0-9_\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/';
- if (preg_match($pattern, $word_string) > 0) {
-
- return $word;
- }
- $pattern = '/(([a-zA-Z0-9\-]+\.)?)((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/';
- if (preg_match($pattern, $word_string) > 0) {
-
- return $word;
- }
- if (isset($dictionary[$word_string])) {
- return $this->UTF8StringToArray($dictionary[$word_string]);
- }
-
- $tmpword = array_merge(array(95), $word, array(95));
- $tmpnumchars = $numchars + 2;
- $maxpos = $tmpnumchars - $charmin;
- for ($pos = 0; $pos < $maxpos; ++$pos) {
- $imax = min(($tmpnumchars - $pos), $charmax);
- for ($i = $charmin; $i <= $imax; ++$i) {
- $subword = strtolower($this->UTF8ArrSubString($tmpword, $pos, $pos + $i));
- if (isset($patterns[$subword])) {
- $pattern = $this->UTF8StringToArray($patterns[$subword]);
- $pattern_length = count($pattern);
- $digits = 1;
- for ($j = 0; $j < $pattern_length; ++$j) {
-
- if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
- if ($j == 0) {
- $zero = $pos - 1;
- } else {
- $zero = $pos + $j - $digits;
- }
- if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] != $pattern[$j])) {
- $hyphenword[$zero] = $this->unichr($pattern[$j]);
- }
- ++$digits;
- }
- }
- }
- }
- }
- $inserted = 0;
- $maxpos = $numchars - $rightmin;
- for ($i = $leftmin; $i <= $maxpos; ++$i) {
- if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
-
- array_splice($word, $i + $inserted, 0, 173);
- ++$inserted;
- }
- }
- return $word;
- }
-
- public function getHyphenPatternsFromTEX($file) {
-
-
- $data = file_get_contents($file);
- $patterns = array();
-
- $data = preg_replace('/\%[^\n]*/', '', $data);
-
- preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
- $data = trim(substr($matches[0], 10, -1));
-
- $patterns_array = preg_split('/[\s]+/', $data);
-
- $patterns = array();
- foreach($patterns_array as $val) {
- if (!$this->empty_string($val)) {
- $val = trim($val);
- $val = str_replace('\'', '\\\'', $val);
- $key = preg_replace('/[0-9]+/', '', $val);
- $patterns[$key] = $val;
- }
- }
- return $patterns;
- }
-
- public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
- $text = $this->unhtmlentities($text);
- $word = array();
- $txtarr = array();
- $intag = false;
- if (!is_array($patterns)) {
- $patterns = $this->getHyphenPatternsFromTEX($patterns);
- }
-
- $unichars = $this->UTF8StringToArray($text);
-
- foreach ($unichars as $char) {
- if ((!$intag) AND $this->unicode->uni_type[$char] == 'L') {
-
- $word[] = $char;
- } else {
-
- if (!$this->empty_string($word)) {
-
- $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
- $word = array();
- }
- $txtarr[] = $char;
- if (chr($char) == '<') {
-
- $intag = true;
- } elseif ($intag AND (chr($char) == '>')) {
-
- $intag = false;
- }
- }
- }
- if (!$this->empty_string($word)) {
-
- $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
- }
-
- return $this->UTF8ArrSubString($txtarr);
- }
-
- public function setRasterizeVectorImages($mode) {
- $this->rasterize_vector_images = $mode;
- }
-
- protected function getPathPaintOperator($style, $default='S') {
- $op = '';
- switch($style) {
- case 'S':
- case 'D': {
- $op = 'S';
- break;
- }
- case 's':
- case 'd': {
- $op = 's';
- break;
- }
- case 'f':
- case 'F': {
- $op = 'f';
- break;
- }
- case 'f*':
- case 'F*': {
- $op = 'f*';
- break;
- }
- case 'B':
- case 'FD':
- case 'DF': {
- $op = 'B';
- break;
- }
- case 'B*':
- case 'F*D':
- case 'DF*': {
- $op = 'B*';
- break;
- }
- case 'b':
- case 'fd':
- case 'df': {
- $op = 'b';
- break;
- }
- case 'b*':
- case 'f*d':
- case 'df*': {
- $op = 'b*';
- break;
- }
- case 'CNZ': {
- $op = 'W n';
- break;
- }
- case 'CEO': {
- $op = 'W* n';
- break;
- }
- case 'n': {
- $op = 'n';
- break;
- }
- default: {
- if (!empty($default)) {
- $op = $this->getPathPaintOperator($default, '');
- } else {
- $op = '';
- }
- }
- }
- return $op;
- }
-
- public function setFontSubsetting($enable=true) {
- if ($this->pdfa_mode) {
- $this->font_subsetting = false;
- } else {
- $this->font_subsetting = $enable ? true : false;
- }
- }
-
- public function getFontSubsetting() {
- return $this->font_subsetting;
- }
-
- public function stringLeftTrim($str, $replace='') {
- return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
- }
-
- public function stringRightTrim($str, $replace='') {
- return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
- }
-
- public function stringTrim($str, $replace='') {
- $str = $this->stringLeftTrim($str, $replace);
- $str = $this->stringRightTrim($str, $replace);
- return $str;
- }
-
- public function isUnicodeFont() {
- return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
- }
-
- public function getFontFamilyName($fontfamily) {
-
- $fontfamily = preg_replace('/[^a-z0-9\,]/', '', strtolower($fontfamily));
-
- $fontslist = preg_split('/[,]/', $fontfamily);
-
- foreach ($fontslist as $font) {
-
- $font = preg_replace('/italic$/', 'I', $font);
- $font = preg_replace('/oblique$/', 'I', $font);
- $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
-
- $pattern = array();
- $replacement = array();
- $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
- $replacement[] = 'times';
- $pattern[] = '/^sansserif/';
- $replacement[] = 'helvetica';
- $pattern[] = '/^monospace/';
- $replacement[] = 'courier';
- $font = preg_replace($pattern, $replacement, $font);
- if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
- return $font;
- }
- }
-
- return $this->CurrentFont['fontkey'];
- }
-
- public function startTemplate($w=0, $h=0, $group=false) {
- if ($this->inxobj) {
-
- return false;
- }
- $this->inxobj = true;
- ++$this->n;
-
- $this->xobjid = 'XT'.$this->n;
-
- $this->xobjects[$this->xobjid] = array('n' => $this->n);
-
- $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
-
- $this->xobjects[$this->xobjid]['intmrk'] = 0;
- $this->xobjects[$this->xobjid]['transfmrk'] = array();
- $this->xobjects[$this->xobjid]['outdata'] = '';
- $this->xobjects[$this->xobjid]['xobjects'] = array();
- $this->xobjects[$this->xobjid]['images'] = array();
- $this->xobjects[$this->xobjid]['fonts'] = array();
- $this->xobjects[$this->xobjid]['annotations'] = array();
- $this->xobjects[$this->xobjid]['extgstates'] = array();
- $this->xobjects[$this->xobjid]['gradients'] = array();
- $this->xobjects[$this->xobjid]['spot_colors'] = array();
-
- $this->num_columns = 1;
- $this->current_column = 0;
- $this->SetAutoPageBreak(false);
- if (($w === '') OR ($w <= 0)) {
- $w = $this->w - $this->lMargin - $this->rMargin;
- }
- if (($h === '') OR ($h <= 0)) {
- $h = $this->h - $this->tMargin - $this->bMargin;
- }
- $this->xobjects[$this->xobjid]['x'] = 0;
- $this->xobjects[$this->xobjid]['y'] = 0;
- $this->xobjects[$this->xobjid]['w'] = $w;
- $this->xobjects[$this->xobjid]['h'] = $h;
- $this->w = $w;
- $this->h = $h;
- $this->wPt = $this->w * $this->k;
- $this->hPt = $this->h * $this->k;
- $this->fwPt = $this->wPt;
- $this->fhPt = $this->hPt;
- $this->x = 0;
- $this->y = 0;
- $this->lMargin = 0;
- $this->rMargin = 0;
- $this->tMargin = 0;
- $this->bMargin = 0;
-
- $this->xobjects[$this->xobjid]['group'] = $group;
- return $this->xobjid;
- }
-
- public function endTemplate() {
- if (!$this->inxobj) {
-
- return false;
- }
- $this->inxobj = false;
-
- $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
- return $this->xobjid;
- }
-
- public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
- if (!isset($this->xobjects[$id])) {
- $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
- }
- if ($this->inxobj) {
- if ($id == $this->xobjid) {
-
- $this->endTemplate();
- } else {
-
- $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
- }
- }
-
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- $ow = $this->xobjects[$id]['w'];
- $oh = $this->xobjects[$id]['h'];
-
- if (($w <= 0) AND ($h <= 0)) {
- $w = $ow;
- $h = $oh;
- } elseif ($w <= 0) {
- $w = $h * $ow / $oh;
- } elseif ($h <= 0) {
- $h = $w * $oh / $ow;
- }
-
- list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
-
- $rb_y = $y + $h;
-
- if ($this->rtl) {
- if ($palign == 'L') {
- $xt = $this->lMargin;
- } elseif ($palign == 'C') {
- $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($palign == 'R') {
- $xt = $this->w - $this->rMargin - $w;
- } else {
- $xt = $x - $w;
- }
- $rb_x = $xt;
- } else {
- if ($palign == 'L') {
- $xt = $this->lMargin;
- } elseif ($palign == 'C') {
- $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($palign == 'R') {
- $xt = $this->w - $this->rMargin - $w;
- } else {
- $xt = $x;
- }
- $rb_x = $xt + $w;
- }
-
- $this->StartTransform();
-
- $sx = ($w / $this->xobjects[$id]['w']);
- $sy = ($h / $this->xobjects[$id]['h']);
- $tm = array();
- $tm[0] = $sx;
- $tm[1] = 0;
- $tm[2] = 0;
- $tm[3] = $sy;
- $tm[4] = $xt * $this->k;
- $tm[5] = ($this->h - $h - $y) * $this->k;
- $this->Transform($tm);
-
- $this->_out('/'.$id.' Do');
- $this->StopTransform();
-
- if (!empty($this->xobjects[$id]['annotations'])) {
- foreach ($this->xobjects[$id]['annotations'] as $annot) {
-
- $coordlt = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
- $ax = ($coordlt[4] / $this->k);
- $ay = ($this->h - $h - ($coordlt[5] / $this->k));
- $coordrb = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
- $aw = ($coordrb[4] / $this->k) - $ax;
- $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
- $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
- }
- }
-
- switch($align) {
- case 'T': {
- $this->y = $y;
- $this->x = $rb_x;
- break;
- }
- case 'M': {
- $this->y = $y + round($h/2);
- $this->x = $rb_x;
- break;
- }
- case 'B': {
- $this->y = $rb_y;
- $this->x = $rb_x;
- break;
- }
- case 'N': {
- $this->SetY($rb_y);
- break;
- }
- default:{
- break;
- }
- }
- }
-
- public function setFontStretching($perc=100) {
- $this->font_stretching = $perc;
- }
-
- public function getFontStretching() {
- return $this->font_stretching;
- }
-
- public function setFontSpacing($spacing=0) {
- $this->font_spacing = $spacing;
- }
-
- public function getFontSpacing() {
- return $this->font_spacing;
- }
-
- public function getPageRegions() {
- return $this->page_regions;
- }
-
- public function setPageRegions($regions=array()) {
-
- $this->page_regions = array();
-
- foreach ($regions as $data) {
- $this->addPageRegion($data);
- }
- }
-
- public function addPageRegion($region) {
- if (!isset($region['page']) OR empty($region['page'])) {
- $region['page'] = $this->page;
- }
- if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
- AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
- AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
- $this->page_regions[] = $region;
- }
- }
-
- public function removePageRegion($key) {
- if (isset($this->page_regions[$key])) {
- unset($this->page_regions[$key]);
- }
- }
-
- protected function checkPageRegions($h, $x, $y) {
-
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
- if (empty($this->page_regions)) {
-
- return array($x, $y);
- }
- if (empty($h)) {
- $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
- }
-
- if ($this->checkPageBreak($h, $y)) {
-
- $x = $this->x;
- $y = $this->y;
- }
- if ($this->num_columns > 1) {
- if ($this->rtl) {
- $this->lMargin = $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w'];
- } else {
- $this->rMargin = $this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w'];
- }
- } else {
- if ($this->rtl) {
- $this->lMargin = $this->original_lMargin;
- } else {
- $this->rMargin = $this->original_rMargin;
- }
- }
-
- foreach ($this->page_regions as $regid => $regdata) {
- if ($regdata['page'] == $this->page) {
-
- if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
-
- $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']);
- $yt = max($y, $regdata['yt']);
- $yb = min(($yt + $h), $regdata['yb']);
- $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
- $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
- if ($regdata['side'] == 'L') {
- $new_margin = max($xt, $xb);
- if ($this->lMargin < $new_margin) {
- if ($this->rtl) {
-
- $this->lMargin = $new_margin;
- }
- if ($x < $new_margin) {
-
- $x = $new_margin;
- if ($new_margin > ($this->w - $this->rMargin)) {
-
- $y = $regdata['yb'] - $h;
- }
- }
- }
- } elseif ($regdata['side'] == 'R') {
- $new_margin = min($xt, $xb);
- if (($this->w - $this->rMargin) > $new_margin) {
- if (!$this->rtl) {
-
- $this->rMargin = ($this->w - $new_margin);
- }
- if ($x > $new_margin) {
-
- $x = $new_margin;
- if ($new_margin > $this->lMargin) {
-
- $y = $regdata['yb'] - $h;
- }
- }
- }
- }
- }
- }
- }
- return array($x, $y);
- }
-
-
- public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
- if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
-
- return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
- }
- if ($file{0} === '@') {
- $this->svgdir = '';
- $svgdata = substr($file, 1);
- } else {
- $this->svgdir = dirname($file);
- $svgdata = file_get_contents($file);
- }
- if ($svgdata === false) {
- $this->Error('SVG file not found: '.$file);
- }
- if ($x === '') {
- $x = $this->x;
- }
- if ($y === '') {
- $y = $this->y;
- }
-
- list($x, $y) = $this->checkPageRegions($h, $x, $y);
- $k = $this->k;
- $ox = 0;
- $oy = 0;
- $ow = $w;
- $oh = $h;
- $aspect_ratio_align = 'xMidYMid';
- $aspect_ratio_ms = 'meet';
- $regs = array();
-
- preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
- if (isset($regs[1]) AND !empty($regs[1])) {
- $tmp = array();
- if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
- $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
- }
- $tmp = array();
- if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
- $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
- }
- $tmp = array();
- if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
- $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
- }
- $tmp = array();
- if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
- $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
- }
- $tmp = array();
- $view_box = array();
- if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
- if (count($tmp) == 5) {
- array_shift($tmp);
- foreach ($tmp as $key => $val) {
- $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
- }
- $ox = $view_box[0];
- $oy = $view_box[1];
- }
-
- $tmp = array();
- if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
- $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
- switch (count($aspect_ratio)) {
- case 3: {
- $aspect_ratio_align = $aspect_ratio[1];
- $aspect_ratio_ms = $aspect_ratio[2];
- break;
- }
- case 2: {
- $aspect_ratio_align = $aspect_ratio[0];
- $aspect_ratio_ms = $aspect_ratio[1];
- break;
- }
- case 1: {
- $aspect_ratio_align = $aspect_ratio[0];
- $aspect_ratio_ms = 'meet';
- break;
- }
- }
- }
- }
- }
-
- if (($w <= 0) AND ($h <= 0)) {
-
- $w = $ow;
- $h = $oh;
- } elseif ($w <= 0) {
- $w = $h * $ow / $oh;
- } elseif ($h <= 0) {
- $h = $w * $oh / $ow;
- }
-
- list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
- if ($this->rasterize_vector_images) {
-
- return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
- }
-
- $this->img_rb_y = $y + $h;
-
- if ($this->rtl) {
- if ($palign == 'L') {
- $ximg = $this->lMargin;
- } elseif ($palign == 'C') {
- $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($palign == 'R') {
- $ximg = $this->w - $this->rMargin - $w;
- } else {
- $ximg = $x - $w;
- }
- $this->img_rb_x = $ximg;
- } else {
- if ($palign == 'L') {
- $ximg = $this->lMargin;
- } elseif ($palign == 'C') {
- $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
- } elseif ($palign == 'R') {
- $ximg = $this->w - $this->rMargin - $w;
- } else {
- $ximg = $x;
- }
- $this->img_rb_x = $ximg + $w;
- }
-
- $gvars = $this->getGraphicVars();
-
- $svgoffset_x = ($ximg - $ox) * $this->k;
- $svgoffset_y = -($y - $oy) * $this->k;
- if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
- $ow = $view_box[2];
- $oh = $view_box[3];
- } else {
- if ($ow <= 0) {
- $ow = $w;
- }
- if ($oh <= 0) {
- $oh = $h;
- }
- }
- $svgscale_x = $w / $ow;
- $svgscale_y = $h / $oh;
-
- if ($aspect_ratio_align != 'none') {
-
- $svgscale_old_x = $svgscale_x;
- $svgscale_old_y = $svgscale_y;
-
- if ($aspect_ratio_ms == 'slice') {
-
- if ($svgscale_x > $svgscale_y) {
- $svgscale_y = $svgscale_x;
- } elseif ($svgscale_x < $svgscale_y) {
- $svgscale_x = $svgscale_y;
- }
- } else {
-
- if ($svgscale_x < $svgscale_y) {
- $svgscale_y = $svgscale_x;
- } elseif ($svgscale_x > $svgscale_y) {
- $svgscale_x = $svgscale_y;
- }
- }
-
- switch (substr($aspect_ratio_align, 1, 3)) {
- case 'Min': {
-
- break;
- }
- case 'Max': {
- $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
- break;
- }
- default:
- case 'Mid': {
- $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
- break;
- }
- }
-
- switch (substr($aspect_ratio_align, 5)) {
- case 'Min': {
-
- break;
- }
- case 'Max': {
- $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
- break;
- }
- default:
- case 'Mid': {
- $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
- break;
- }
- }
- }
-
- $page_break_mode = $this->AutoPageBreak;
- $page_break_margin = $this->getBreakMargin();
- $cell_padding = $this->cell_padding;
- $this->SetCellPadding(0);
- $this->SetAutoPageBreak(false);
-
- $this->_out('q'.$this->epsmarker);
-
- $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
-
- $e = $ox * $this->k * (1 - $svgscale_x);
- $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
- $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $svgscale_x, 0, 0, $svgscale_y, $e + $svgoffset_x, $f + $svgoffset_y));
-
- $this->parser = xml_parser_create('UTF-8');
-
- xml_set_object($this->parser, $this);
-
- xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
-
- xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler');
-
- xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
-
- if (!xml_parse($this->parser, $svgdata)) {
- $error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser));
- $this->Error($error_message);
- }
-
- xml_parser_free($this->parser);
-
- $this->_out($this->epsmarker.'Q');
-
- $this->setGraphicVars($gvars);
- $this->lasth = $gvars['lasth'];
- if (!empty($border)) {
- $bx = $this->x;
- $by = $this->y;
- $this->x = $ximg;
- if ($this->rtl) {
- $this->x += $w;
- }
- $this->y = $y;
- $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
- $this->x = $bx;
- $this->y = $by;
- }
- if ($link) {
- $this->Link($ximg, $y, $w, $h, $link, 0);
- }
-
- switch($align) {
- case 'T':{
- $this->y = $y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'M':{
- $this->y = $y + round($h/2);
- $this->x = $this->img_rb_x;
- break;
- }
- case 'B':{
- $this->y = $this->img_rb_y;
- $this->x = $this->img_rb_x;
- break;
- }
- case 'N':{
- $this->SetY($this->img_rb_y);
- break;
- }
- default:{
-
- $this->x = $gvars['x'];
- $this->y = $gvars['y'];
- $this->page = $gvars['page'];
- $this->current_column = $gvars['current_column'];
- $this->tMargin = $gvars['tMargin'];
- $this->bMargin = $gvars['bMargin'];
- $this->w = $gvars['w'];
- $this->h = $gvars['h'];
- $this->wPt = $gvars['wPt'];
- $this->hPt = $gvars['hPt'];
- $this->fwPt = $gvars['fwPt'];
- $this->fhPt = $gvars['fhPt'];
- break;
- }
- }
- $this->endlinex = $this->img_rb_x;
-
- $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
- $this->cell_padding = $cell_padding;
- }
-
- protected function getSVGTransformMatrix($attribute) {
-
- $tm = array(1, 0, 0, 1, 0, 0);
- $transform = array();
- if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) {
- foreach ($transform as $key => $data) {
- if (!empty($data[2])) {
- $a = 1;
- $b = 0;
- $c = 0;
- $d = 1;
- $e = 0;
- $f = 0;
- $regs = array();
- switch ($data[1]) {
- case 'matrix': {
- if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
- $a = $regs[1];
- $b = $regs[2];
- $c = $regs[3];
- $d = $regs[4];
- $e = $regs[5];
- $f = $regs[6];
- }
- break;
- }
- case 'translate': {
- if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
- $e = $regs[1];
- $f = $regs[2];
- } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
- $e = $regs[1];
- }
- break;
- }
- case 'scale': {
- if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
- $a = $regs[1];
- $d = $regs[2];
- } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
- $a = $regs[1];
- $d = $a;
- }
- break;
- }
- case 'rotate': {
- if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
- $ang = deg2rad($regs[1]);
- $x = $regs[2];
- $y = $regs[3];
- $a = cos($ang);
- $b = sin($ang);
- $c = -$b;
- $d = $a;
- $e = ($x * (1 - $a)) - ($y * $c);
- $f = ($y * (1 - $d)) - ($x * $b);
- } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
- $ang = deg2rad($regs[1]);
- $a = cos($ang);
- $b = sin($ang);
- $c = -$b;
- $d = $a;
- $e = 0;
- $f = 0;
- }
- break;
- }
- case 'skewX': {
- if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
- $c = tan(deg2rad($regs[1]));
- }
- break;
- }
- case 'skewY': {
- if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
- $b = tan(deg2rad($regs[1]));
- }
- break;
- }
- }
- $tm = $this->getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
- }
- }
- }
- return $tm;
- }
-
- protected function getTransformationMatrixProduct($ta, $tb) {
- $tm = array();
- $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
- $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
- $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
- $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
- $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
- $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
- return $tm;
- }
-
- protected function convertSVGtMatrix($tm) {
- $a = $tm[0];
- $b = -$tm[1];
- $c = -$tm[2];
- $d = $tm[3];
- $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
- $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
- $x = 0;
- $y = $this->h * $this->k;
- $e = ($x * (1 - $a)) - ($y * $c) + $e;
- $f = ($y * (1 - $d)) - ($x * $b) + $f;
- return array($a, $b, $c, $d, $e, $f);
- }
-
- protected function SVGTransform($tm) {
- $this->Transform($this->convertSVGtMatrix($tm));
- }
-
- protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
- $objstyle = '';
- $minlen = (0.01 / $this->k);
- if (!isset($svgstyle['opacity'])) {
- return $objstyle;
- }
-
- $regs = array();
- if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
- $clip_path = $this->svgclippaths[$regs[1]];
- foreach ($clip_path as $cp) {
- $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
- }
- }
-
- if ($svgstyle['opacity'] != 1) {
- $this->SetAlpha($svgstyle['opacity']);
- }
-
- $fill_color = $this->convertHTMLColorToDec($svgstyle['color']);
- $this->SetFillColorArray($fill_color);
-
- $text_color = $this->convertHTMLColorToDec($svgstyle['text-color']);
- $this->SetTextColorArray($text_color);
-
- if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
- $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
- $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
- $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
- $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
- $cx = $x + $left;
- $cy = $y + $top;
- $cw = $w - $left - $right;
- $ch = $h - $top - $bottom;
- if ($svgstyle['clip-rule'] == 'evenodd') {
- $clip_rule = 'CNZ';
- } else {
- $clip_rule = 'CEO';
- }
- $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
- }
-
- $regs = array();
- if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
-
- $gradient = $this->svggradients[$regs[1]];
- if (isset($gradient['xref'])) {
-
- $newgradient = $this->svggradients[$gradient['xref']];
- $newgradient['coords'] = $gradient['coords'];
- $newgradient['mode'] = $gradient['mode'];
- $newgradient['gradientUnits'] = $gradient['gradientUnits'];
- if (isset($gradient['gradientTransform'])) {
- $newgradient['gradientTransform'] = $gradient['gradientTransform'];
- }
- $gradient = $newgradient;
- }
-
- $this->_out('q');
-
- if (!empty($clip_function) AND method_exists($this, $clip_function)) {
- $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
- if (is_array($bbox) AND (count($bbox) == 4)) {
- list($x, $y, $w, $h) = $bbox;
- }
- }
- if ($gradient['mode'] == 'measure') {
- if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
- $gtm = $gradient['gradientTransform'];
-
- $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
- $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
- $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
- $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
- if (isset($gradient['coords'][4])) {
- $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
- }
- $gradient['coords'][0] = $xa;
- $gradient['coords'][1] = $ya;
- $gradient['coords'][2] = $xb;
- $gradient['coords'][3] = $yb;
- }
-
- $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
- $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
- $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
- $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
- if (isset($gradient['coords'][4])) {
- $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
- }
-
- if ($gradient['gradientUnits'] == 'objectBoundingBox') {
-
- $gradient['coords'][0] += $x;
- $gradient['coords'][1] += $y;
- $gradient['coords'][2] += $x;
- $gradient['coords'][3] += $y;
- }
- if ($w <= $minlen) {
- $w = $minlen;
- }
- if ($h <= $minlen) {
- $h = $minlen;
- }
-
- $gradient['coords'][0] = ($gradient['coords'][0] - $x) / $w;
- $gradient['coords'][1] = ($gradient['coords'][1] - $y) / $h;
- $gradient['coords'][2] = ($gradient['coords'][2] - $x) / $w;
- $gradient['coords'][3] = ($gradient['coords'][3] - $y) / $h;
- if (isset($gradient['coords'][4])) {
- $gradient['coords'][4] /= $w;
- }
- } elseif ($gradient['mode'] == 'percentage') {
- foreach($gradient['coords'] as $key => $val) {
- $gradient['coords'][$key] = (intval($val) / 100);
- }
- }
-
- foreach($gradient['coords'] as $key => $val) {
- if ($val < 0) {
- $gradient['coords'][$key] = 0;
- } elseif ($val > 1) {
- $gradient['coords'][$key] = 1;
- }
- }
- if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
-
- $gradient['coords'][0] = 1;
- $gradient['coords'][1] = 0;
- $gradient['coords'][2] = 0.999;
- $gradient['coords'][3] = 0;
- }
-
- $tmp = $gradient['coords'][1];
- $gradient['coords'][1] = $gradient['coords'][3];
- $gradient['coords'][3] = $tmp;
-
- if ($gradient['type'] == 3) {
-
- $cy = $this->h - $y - ($gradient['coords'][1] * ($w + $h));
- $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $w*$this->k, $x*$this->k, $cy*$this->k));
- } else {
- $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k));
- }
- if (count($gradient['stops']) > 1) {
- $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
- }
- } elseif ($svgstyle['fill'] != 'none') {
- $fill_color = $this->convertHTMLColorToDec($svgstyle['fill']);
- if ($svgstyle['fill-opacity'] != 1) {
- $this->SetAlpha($svgstyle['fill-opacity']);
- }
- $this->SetFillColorArray($fill_color);
- if ($svgstyle['fill-rule'] == 'evenodd') {
- $objstyle .= 'F*';
- } else {
- $objstyle .= 'F';
- }
- }
-
- if ($svgstyle['stroke'] != 'none') {
- $stroke_style = array(
- 'color' => $this->convertHTMLColorToDec($svgstyle['stroke']),
- 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
- 'cap' => $svgstyle['stroke-linecap'],
- 'join' => $svgstyle['stroke-linejoin']
- );
- if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
- $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
- }
- $this->SetLineStyle($stroke_style);
- $objstyle .= 'D';
- }
-
- $regs = array();
- if (!empty($svgstyle['font'])) {
- if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
- $font_family = $this->getFontFamilyName($regs[1]);
- } else {
- $font_family = $svgstyle['font-family'];
- }
- if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
- $font_size = trim($regs[1]);
- } else {
- $font_size = $svgstyle['font-size'];
- }
- if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
- $font_style = trim($regs[1]);
- } else {
- $font_style = $svgstyle['font-style'];
- }
- if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
- $font_weight = trim($regs[1]);
- } else {
- $font_weight = $svgstyle['font-weight'];
- }
- if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
- $font_stretch = trim($regs[1]);
- } else {
- $font_stretch = $svgstyle['font-stretch'];
- }
- if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
- $font_spacing = trim($regs[1]);
- } else {
- $font_spacing = $svgstyle['letter-spacing'];
- }
- } else {
- $font_family = $this->getFontFamilyName($svgstyle['font-family']);
- $font_size = $svgstyle['font-size'];
- $font_style = $svgstyle['font-style'];
- $font_weight = $svgstyle['font-weight'];
- $font_stretch = $svgstyle['font-stretch'];
- $font_spacing = $svgstyle['letter-spacing'];
- }
- $font_size = $this->getHTMLUnitToUnits($font_size, $prevsvgstyle['font-size'], $this->svgunit, false) * $this->k;
- $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
- $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
- switch ($font_style) {
- case 'italic': {
- $font_style = 'I';
- break;
- }
- case 'oblique': {
- $font_style = 'I';
- break;
- }
- default:
- case 'normal': {
- $font_style = '';
- break;
- }
- }
- switch ($font_weight) {
- case 'bold':
- case 'bolder': {
- $font_style .= 'B';
- break;
- }
- }
- switch ($svgstyle['text-decoration']) {
- case 'underline': {
- $font_style .= 'U';
- break;
- }
- case 'overline': {
- $font_style .= 'O';
- break;
- }
- case 'line-through': {
- $font_style .= 'D';
- break;
- }
- default:
- case 'none': {
- break;
- }
- }
- $this->SetFont($font_family, $font_style, $font_size);
- $this->setFontStretching($font_stretch);
- $this->setFontSpacing($font_spacing);
- return $objstyle;
- }
-
- protected function SVGPath($d, $style='') {
-
- $op = $this->getPathPaintOperator($style, '');
- if (empty($op)) {
- return;
- }
- $paths = array();
- $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
- preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
- $x = 0;
- $y = 0;
- $x1 = 0;
- $y1 = 0;
- $x2 = 0;
- $y2 = 0;
- $xmin = 2147483647;
- $xmax = 0;
- $ymin = 2147483647;
- $ymax = 0;
- $relcoord = false;
- $minlen = (0.01 / $this->k);
- $firstcmd = true;
-
- foreach ($paths as $key => $val) {
-
- $cmd = trim($val[1]);
- if (strtolower($cmd) == $cmd) {
-
- $relcoord = true;
- $xoffset = $x;
- $yoffset = $y;
- } else {
- $relcoord = false;
- $xoffset = 0;
- $yoffset = 0;
- }
- $params = array();
- if (isset($val[2])) {
-
- $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
- $params = array();
- foreach ($rawparams as $ck => $cp) {
- $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
- if (abs($params[$ck]) < $minlen) {
-
- $params[$ck] = 0;
- }
- }
- }
-
- $x0 = $x;
- $y0 = $y;
- switch (strtoupper($cmd)) {
- case 'M': {
- foreach ($params as $ck => $cp) {
- if (($ck % 2) == 0) {
- $x = $cp + $xoffset;
- } else {
- $y = $cp + $yoffset;
- if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
- if ($ck == 1) {
- $this->_outPoint($x, $y);
- $firstcmd = false;
- } else {
- $this->_outLine($x, $y);
- }
- }
- $xmin = min($xmin, $x);
- $ymin = min($ymin, $y);
- $xmax = max($xmax, $x);
- $ymax = max($ymax, $y);
- if ($relcoord) {
- $xoffset = $x;
- $yoffset = $y;
- }
- }
- }
- break;
- }
- case 'L': {
- foreach ($params as $ck => $cp) {
- if (($ck % 2) == 0) {
- $x = $cp + $xoffset;
- } else {
- $y = $cp + $yoffset;
- if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
- $this->_outLine($x, $y);
- }
- $xmin = min($xmin, $x);
- $ymin = min($ymin, $y);
- $xmax = max($xmax, $x);
- $ymax = max($ymax, $y);
- if ($relcoord) {
- $xoffset = $x;
- $yoffset = $y;
- }
- }
- }
- break;
- }
- case 'H': {
- foreach ($params as $ck => $cp) {
- $x = $cp + $xoffset;
- if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
- $this->_outLine($x, $y);
- }
- $xmin = min($xmin, $x);
- $xmax = max($xmax, $x);
- if ($relcoord) {
- $xoffset = $x;
- }
- }
- break;
- }
- case 'V': {
- foreach ($params as $ck => $cp) {
- $y = $cp + $yoffset;
- if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
- $this->_outLine($x, $y);
- }
- $ymin = min($ymin, $y);
- $ymax = max($ymax, $y);
- if ($relcoord) {
- $yoffset = $y;
- }
- }
- break;
- }
- case 'C': {
- foreach ($params as $ck => $cp) {
- $params[$ck] = $cp;
- if ((($ck + 1) % 6) == 0) {
- $x1 = $params[($ck - 5)] + $xoffset;
- $y1 = $params[($ck - 4)] + $yoffset;
- $x2 = $params[($ck - 3)] + $xoffset;
- $y2 = $params[($ck - 2)] + $yoffset;
- $x = $params[($ck - 1)] + $xoffset;
- $y = $params[($ck)] + $yoffset;
- $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
- $xmin = min($xmin, $x, $x1, $x2);
- $ymin = min($ymin, $y, $y1, $y2);
- $xmax = max($xmax, $x, $x1, $x2);
- $ymax = max($ymax, $y, $y1, $y2);
- if ($relcoord) {
- $xoffset = $x;
- $yoffset = $y;
- }
- }
- }
- break;
- }
- case 'S': {
- foreach ($params as $ck => $cp) {
- $params[$ck] = $cp;
- if ((($ck + 1) % 4) == 0) {
- if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
- $x1 = (2 * $x) - $x2;
- $y1 = (2 * $y) - $y2;
- } else {
- $x1 = $x;
- $y1 = $y;
- }
- $x2 = $params[($ck - 3)] + $xoffset;
- $y2 = $params[($ck - 2)] + $yoffset;
- $x = $params[($ck - 1)] + $xoffset;
- $y = $params[($ck)] + $yoffset;
- $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
- $xmin = min($xmin, $x, $x1, $x2);
- $ymin = min($ymin, $y, $y1, $y2);
- $xmax = max($xmax, $x, $x1, $x2);
- $ymax = max($ymax, $y, $y1, $y2);
- if ($relcoord) {
- $xoffset = $x;
- $yoffset = $y;
- }
- }
- }
- break;
- }
- case 'Q': {
- foreach ($params as $ck => $cp) {
- $params[$ck] = $cp;
- if ((($ck + 1) % 4) == 0) {
-
- $x1 = $params[($ck - 3)] + $xoffset;
- $y1 = $params[($ck - 2)] + $yoffset;
- $xa = ($x + (2 * $x1)) / 3;
- $ya = ($y + (2 * $y1)) / 3;
- $x = $params[($ck - 1)] + $xoffset;
- $y = $params[($ck)] + $yoffset;
- $xb = ($x + (2 * $x1)) / 3;
- $yb = ($y + (2 * $y1)) / 3;
- $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
- $xmin = min($xmin, $x, $xa, $xb);
- $ymin = min($ymin, $y, $ya, $yb);
- $xmax = max($xmax, $x, $xa, $xb);
- $ymax = max($ymax, $y, $ya, $yb);
- if ($relcoord) {
- $xoffset = $x;
- $yoffset = $y;
- }
- }
- }
- break;
- }
- case 'T': {
- foreach ($params as $ck => $cp) {
- $params[$ck] = $cp;
- if (($ck % 2) != 0) {
- if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
- $x1 = (2 * $x) - $x1;
- $y1 = (2 * $y) - $y1;
- } else {
- $x1 = $x;
- $y1 = $y;
- }
-
- $xa = ($x + (2 * $x1)) / 3;
- $ya = ($y + (2 * $y1)) / 3;
- $x = $params[($ck - 1)] + $xoffset;
- $y = $params[($ck)] + $yoffset;
- $xb = ($x + (2 * $x1)) / 3;
- $yb = ($y + (2 * $y1)) / 3;
- $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
- $xmin = min($xmin, $x, $xa, $xb);
- $ymin = min($ymin, $y, $ya, $yb);
- $xmax = max($xmax, $x, $xa, $xb);
- $ymax = max($ymax, $y, $ya, $yb);
- if ($relcoord) {
- $xoffset = $x;
- $yoffset = $y;
- }
- }
- }
- break;
- }
- case 'A': {
- foreach ($params as $ck => $cp) {
- $params[$ck] = $cp;
- if ((($ck + 1) % 7) == 0) {
- $x0 = $x;
- $y0 = $y;
- $rx = abs($params[($ck - 6)]);
- $ry = abs($params[($ck - 5)]);
- $ang = -$rawparams[($ck - 4)];
- $angle = deg2rad($ang);
- $fa = $rawparams[($ck - 3)];
- $fs = $rawparams[($ck - 2)];
- $x = $params[($ck - 1)] + $xoffset;
- $y = $params[$ck] + $yoffset;
- if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
-
- $xmin = min($xmin, $x);
- $ymin = min($ymin, $y);
- $xmax = max($xmax, $x);
- $ymax = max($ymax, $y);
- } else {
- $cos_ang = cos($angle);
- $sin_ang = sin($angle);
- $a = (($x0 - $x) / 2);
- $b = (($y0 - $y) / 2);
- $xa = ($a * $cos_ang) - ($b * $sin_ang);
- $ya = ($a * $sin_ang) + ($b * $cos_ang);
- $rx2 = $rx * $rx;
- $ry2 = $ry * $ry;
- $xa2 = $xa * $xa;
- $ya2 = $ya * $ya;
- $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
- if ($delta > 1) {
- $rx *= sqrt($delta);
- $ry *= sqrt($delta);
- $rx2 = $rx * $rx;
- $ry2 = $ry * $ry;
- }
- $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
- if ($numerator < 0) {
- $root = 0;
- } else {
- $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
- }
- if ($fa == $fs){
- $root *= -1;
- }
- $cax = $root * (($rx * $ya) / $ry);
- $cay = -$root * (($ry * $xa) / $rx);
-
- $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
- $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
-
- $angs = $this->getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
- $dang = $this->getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
- if (($fs == 0) AND ($dang > 0)) {
- $dang -= (2 * M_PI);
- } elseif (($fs == 1) AND ($dang < 0)) {
- $dang += (2 * M_PI);
- }
- $angf = $angs - $dang;
- if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
-
- $tmp = $angs;
- $angs = $angf;
- $angf = $tmp;
- }
- $angs = round(rad2deg($angs), 6);
- $angf = round(rad2deg($angf), 6);
-
- if (($angs < 0) AND ($angf < 0)) {
- $angs += 360;
- $angf += 360;
- }
- $pie = false;
- if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
- $pie = true;
- }
- list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
- $xmin = min($xmin, $x, $axmin);
- $ymin = min($ymin, $y, $aymin);
- $xmax = max($xmax, $x, $axmax);
- $ymax = max($ymax, $y, $aymax);
- }
- if ($relcoord) {
- $xoffset = $x;
- $yoffset = $y;
- }
- }
- }
- break;
- }
- case 'Z': {
- $this->_out('h');
- break;
- }
- }
- $firstcmd = false;
- }
- if (!empty($op)) {
- $this->_out($op);
- }
- return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
- }
-
- protected function getVectorsAngle($x1, $y1, $x2, $y2) {
- $dprod = ($x1 * $x2) + ($y1 * $y2);
- $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
- $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
- $angle = acos($dprod / ($dist1 * $dist2));
- if (is_nan($angle)) {
- $angle = M_PI;
- }
- if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
- $angle *= -1;
- }
- return $angle;
- }
-
- protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
-
- if ($this->svgclipmode) {
- $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
- return;
- }
- if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
- if (!isset($attribs['id'])) {
- $attribs['id'] = 'DF_'.(count($this->svgdefs) + 1);
- }
- $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
- return;
- }
- $clipping = false;
- if ($parser == 'clip-path') {
-
- $clipping = true;
- }
-
- $prev_svgstyle = $this->svgstyles[(count($this->svgstyles) - 1)];
- $svgstyle = $this->svgstyles[0];
- if (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) {
-
- $attribs['style'] = ';'.$attribs['style'];
- }
- foreach ($prev_svgstyle as $key => $val) {
- if (in_array($key, $this->svginheritprop)) {
-
- $svgstyle[$key] = $val;
- }
- if (isset($attribs[$key]) AND !$this->empty_string($attribs[$key])) {
-
- if ($attribs[$key] == 'inherit') {
- $svgstyle[$key] = $val;
- } else {
- $svgstyle[$key] = $attribs[$key];
- }
- } elseif (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) {
-
- $attrval = array();
- if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
- if ($attrval[1] == 'inherit') {
- $svgstyle[$key] = $val;
- } else {
- $svgstyle[$key] = $attrval[1];
- }
- }
- }
- }
-
- if (!empty($ctm)) {
- $tm = $ctm;
- } else {
- $tm = $this->svgstyles[(count($this->svgstyles) - 1)]['transfmatrix'];
- }
- if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
- $tm = $this->getTransformationMatrixProduct($tm, $this->getSVGTransformMatrix($attribs['transform']));
- }
- $svgstyle['transfmatrix'] = $tm;
- $invisible = false;
- if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
-
- $invisible = true;
- }
-
- switch($name) {
- case 'defs': {
- $this->svgdefsmode = true;
- break;
- }
-
- case 'clipPath': {
- if ($invisible) {
- break;
- }
- $this->svgclipmode = true;
- if (!isset($attribs['id'])) {
- $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
- }
- $this->svgclipid = $attribs['id'];
- $this->svgclippaths[$this->svgclipid] = array();
- $this->svgcliptm[$this->svgclipid] = $tm;
- break;
- }
- case 'svg': {
-
- break;
- }
- case 'g': {
-
- array_push($this->svgstyles, $svgstyle);
- $this->StartTransform();
- $this->setSVGStyles($svgstyle, $prev_svgstyle);
- break;
- }
- case 'linearGradient': {
- if ($this->pdfa_mode) {
- break;
- }
- if (!isset($attribs['id'])) {
- $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
- }
- $this->svggradientid = $attribs['id'];
- $this->svggradients[$this->svggradientid] = array();
- $this->svggradients[$this->svggradientid]['type'] = 2;
- $this->svggradients[$this->svggradientid]['stops'] = array();
- if (isset($attribs['gradientUnits'])) {
- $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
- } else {
- $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
- }
-
- $x1 = (isset($attribs['x1'])?$attribs['x1']:'0%');
- $y1 = (isset($attribs['y1'])?$attribs['y1']:'0%');
- $x2 = (isset($attribs['x2'])?$attribs['x2']:'100%');
- $y2 = (isset($attribs['y2'])?$attribs['y2']:'0%');
- if (substr($x1, -1) != '%') {
- $this->svggradients[$this->svggradientid]['mode'] = 'measure';
- } else {
- $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
- }
- if (isset($attribs['gradientTransform'])) {
- $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
- }
- $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
- if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
-
- $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
- }
- break;
- }
- case 'radialGradient': {
- if ($this->pdfa_mode) {
- break;
- }
- if (!isset($attribs['id'])) {
- $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
- }
- $this->svggradientid = $attribs['id'];
- $this->svggradients[$this->svggradientid] = array();
- $this->svggradients[$this->svggradientid]['type'] = 3;
- $this->svggradients[$this->svggradientid]['stops'] = array();
- if (isset($attribs['gradientUnits'])) {
- $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
- } else {
- $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
- }
-
- $cx = (isset($attribs['cx'])?$attribs['cx']:0.5);
- $cy = (isset($attribs['cy'])?$attribs['cy']:0.5);
- $fx = (isset($attribs['fx'])?$attribs['fx']:$cx);
- $fy = (isset($attribs['fy'])?$attribs['fy']:$cy);
- $r = (isset($attribs['r'])?$attribs['r']:0.5);
- if (isset($attribs['cx']) AND (substr($attribs['cx'], -1) != '%')) {
- $this->svggradients[$this->svggradientid]['mode'] = 'measure';
- } else {
- $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
- }
- if (isset($attribs['gradientTransform'])) {
- $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
- }
- $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
- if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
-
- $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
- }
- break;
- }
- case 'stop': {
-
- if (substr($attribs['offset'], -1) == '%') {
- $offset = floatval(substr($attribs['offset'], -1)) / 100;
- } else {
- $offset = floatval($attribs['offset']);
- if ($offset > 1) {
- $offset /= 100;
- }
- }
- $stop_color = isset($svgstyle['stop-color'])?$this->convertHTMLColorToDec($svgstyle['stop-color']):'black';
- $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
- $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
- break;
- }
-
- case 'path': {
- if ($invisible) {
- break;
- }
- if (isset($attribs['d'])) {
- $d = trim($attribs['d']);
- if (!empty($d)) {
- if ($clipping) {
- $this->SVGTransform($tm);
- $this->SVGPath($d, 'CNZ');
- } else {
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, 0, 0, 1, 1, 'SVGPath', array($d, 'CNZ'));
- if (!empty($obstyle)) {
- $this->SVGPath($d, $obstyle);
- }
- $this->StopTransform();
- }
- }
- }
- break;
- }
-
- case 'rect': {
- if ($invisible) {
- break;
- }
- $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
- $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
- $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
- $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
- $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
- $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
- if ($clipping) {
- $this->SVGTransform($tm);
- $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
- } else {
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
- if (!empty($obstyle)) {
- $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
- }
- $this->StopTransform();
- }
- break;
- }
- case 'circle': {
- if ($invisible) {
- break;
- }
- $cx = (isset($attribs['cx'])?$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false):0);
- $cy = (isset($attribs['cy'])?$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false):0);
- $r = (isset($attribs['r'])?$this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false):0);
- $x = $cx - $r;
- $y = $cy - $r;
- $w = 2 * $r;
- $h = $w;
- if ($clipping) {
- $this->SVGTransform($tm);
- $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
- } else {
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
- if (!empty($obstyle)) {
- $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
- }
- $this->StopTransform();
- }
- break;
- }
- case 'ellipse': {
- if ($invisible) {
- break;
- }
- $cx = (isset($attribs['cx'])?$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false):0);
- $cy = (isset($attribs['cy'])?$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false):0);
- $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
- $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):0);
- $x = $cx - $rx;
- $y = $cy - $ry;
- $w = 2 * $rx;
- $h = 2 * $ry;
- if ($clipping) {
- $this->SVGTransform($tm);
- $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
- } else {
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
- if (!empty($obstyle)) {
- $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
- }
- $this->StopTransform();
- }
- break;
- }
- case 'line': {
- if ($invisible) {
- break;
- }
- $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
- $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
- $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
- $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
- $x = $x1;
- $y = $y1;
- $w = abs($x2 - $x1);
- $h = abs($y2 - $y1);
- if (!$clipping) {
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
- $this->Line($x1, $y1, $x2, $y2);
- $this->StopTransform();
- }
- break;
- }
- case 'polyline':
- case 'polygon': {
- if ($invisible) {
- break;
- }
- $points = (isset($attribs['points'])?$attribs['points']:'0 0');
- $points = trim($points);
-
- $points = preg_split('/[\,\s]+/si', $points);
- if (count($points) < 4) {
- break;
- }
- $p = array();
- $xmin = 2147483647;
- $xmax = 0;
- $ymin = 2147483647;
- $ymax = 0;
- foreach ($points as $key => $val) {
- $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
- if (($key % 2) == 0) {
-
- $xmin = min($xmin, $p[$key]);
- $xmax = max($xmax, $p[$key]);
- } else {
-
- $ymin = min($ymin, $p[$key]);
- $ymax = max($ymax, $p[$key]);
- }
- }
- $x = $xmin;
- $y = $ymin;
- $w = ($xmax - $xmin);
- $h = ($ymax - $ymin);
- if ($name == 'polyline') {
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
- $this->PolyLine($p, 'D', array(), array());
- $this->StopTransform();
- } else {
- if ($clipping) {
- $this->SVGTransform($tm);
- $this->Polygon($p, 'CNZ', array(), array(), true);
- } else {
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
- if (!empty($obstyle)) {
- $this->Polygon($p, $obstyle, array(), array(), true);
- }
- $this->StopTransform();
- }
- }
- break;
- }
-
- case 'image': {
- if ($invisible) {
- break;
- }
- if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
- break;
- }
- $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
- $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
- $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
- $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
- $img = $attribs['xlink:href'];
- if (!$clipping) {
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
-
- if (!$this->empty_string($this->svgdir) AND (($img{0} == '.') OR (basename($img) == $img))) {
-
- $img = $this->svgdir.'/'.$img;
- }
- if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
- $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
- if (($findroot === false) OR ($findroot > 1)) {
- if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
- $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
- } else {
- $img = $_SERVER['DOCUMENT_ROOT'].$img;
- }
- }
- }
- $img = urldecode($img);
- $testscrtype = @parse_url($img);
- if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
-
- $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
- }
- $this->Image($img, $x, $y, $w, $h);
- $this->StopTransform();
- }
- break;
- }
-
- case 'text':
- case 'tspan': {
- $this->svgtextmode['invisible'] = $invisible;
- if ($invisible) {
- break;
- }
- array_push($this->svgstyles, $svgstyle);
-
- $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):$this->x);
- $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):$this->y);
- $svgstyle['text-color'] = $svgstyle['fill'];
- $this->svgtext = '';
- if (isset($svgstyle['text-anchor'])) {
- $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
- } else {
- $this->svgtextmode['text-anchor'] = 'start';
- }
- if (isset($svgstyle['direction'])) {
- if ($svgstyle['direction'] == 'rtl') {
- $this->svgtextmode['rtl'] = true;
- } else {
- $this->svgtextmode['rtl'] = false;
- }
- } else {
- $this->svgtextmode['rtl'] = false;
- }
- if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
- $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
- } else {
- $this->svgtextmode['stroke'] = false;
- }
- $this->StartTransform();
- $this->SVGTransform($tm);
- $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
- $this->x = $x;
- $this->y = $y;
- break;
- }
-
- case 'use': {
- if (isset($attribs['xlink:href'])) {
- $use = $this->svgdefs[substr($attribs['xlink:href'], 1)];
- if (isset($attribs['xlink:href'])) {
- unset($attribs['xlink:href']);
- }
- if (isset($attribs['id'])) {
- unset($attribs['id']);
- }
- $attribs = array_merge($use['attribs'], $attribs);
- $this->startSVGElementHandler($parser, $use['name'], $use['attribs']);
- }
- break;
- }
- default: {
- break;
- }
- }
- }
-
- protected function endSVGElementHandler($parser, $name) {
- switch($name) {
- case 'defs': {
- $this->svgdefsmode = false;
- break;
- }
-
- case 'clipPath': {
- $this->svgclipmode = false;
- break;
- }
- case 'g': {
-
- array_pop($this->svgstyles);
- $this->StopTransform();
- break;
- }
- case 'text':
- case 'tspan': {
- if ($this->svgtextmode['invisible']) {
-
-
- break;
- }
-
- $text = $this->stringTrim($this->svgtext);
- if ($this->svgtextmode['text-anchor'] != 'start') {
- $textlen = $this->GetStringWidth($text);
-
- if ($this->svgtextmode['text-anchor'] == 'end') {
- if ($this->svgtextmode['rtl']) {
- $this->x += $textlen;
- } else {
- $this->x -= $textlen;
- }
- } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
- if ($this->svgtextmode['rtl']) {
- $this->x += ($textlen / 2);
- } else {
- $this->x -= ($textlen / 2);
- }
- }
- }
- $textrendermode = $this->textrendermode;
- $textstrokewidth = $this->textstrokewidth;
- $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
- $this->Cell(0, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
-
- $this->textrendermode = $textrendermode;
- $this->textstrokewidth = $textstrokewidth;
- $this->svgtext = '';
- $this->StopTransform();
- array_pop($this->svgstyles);
- break;
- }
- default: {
- break;
- }
- }
- }
-
- protected function segSVGContentHandler($parser, $data) {
- $this->svgtext .= $data;
- }
-
- }
|