tcpdf.php 878 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 6.2.26
  5. // Begin : 2002-08-03
  6. // Last Update : 2018-09-14
  7. // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
  8. // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2018 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the License
  25. // along with TCPDF. If not, see
  26. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  27. //
  28. // See LICENSE.TXT file for more information.
  29. // -------------------------------------------------------------------
  30. //
  31. // Description :
  32. // This is a PHP class for generating PDF documents without requiring external extensions.
  33. //
  34. // NOTE:
  35. // This class was originally derived in 2002 from the Public
  36. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  37. // but now is almost entirely rewritten and contains thousands of
  38. // new lines of code and hundreds new features.
  39. //
  40. // Main features:
  41. // * no external libraries are required for the basic functions;
  42. // * all standard page formats, custom page formats, custom margins and units of measure;
  43. // * UTF-8 Unicode and Right-To-Left languages;
  44. // * TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
  45. // * font subsetting;
  46. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  47. // * images, graphic (geometric figures) and transformation methods;
  48. // * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)
  49. // * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  50. // * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  51. // * automatic page header and footer management;
  52. // * document encryption up to 256 bit and digital signature certifications;
  53. // * transactions to UNDO commands;
  54. // * PDF annotations, including links, text and file attachments;
  55. // * text rendering modes (fill, stroke and clipping);
  56. // * multiple columns mode;
  57. // * no-write page regions;
  58. // * bookmarks, named destinations and table of content;
  59. // * text hyphenation;
  60. // * text stretching and spacing (tracking);
  61. // * automatic page break, line break and text alignments including justification;
  62. // * automatic page numbering and page groups;
  63. // * move and delete pages;
  64. // * page compression (requires php-zlib extension);
  65. // * XOBject Templates;
  66. // * Layers and object visibility.
  67. // * PDF/A-1b support
  68. //============================================================+
  69. /**
  70. * @file
  71. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  72. * TCPDF project (http://www.tcpdf.org) was originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  73. * <h3>TCPDF main features are:</h3>
  74. * <ul>
  75. * <li>no external libraries are required for the basic functions;</li>
  76. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  77. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  78. * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  79. * <li>font subsetting;</li>
  80. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  81. * <li>images, graphic (geometric figures) and transformation methods;
  82. * <li>supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)</li>
  83. * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;</li>
  84. * <li>JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  85. * <li>automatic page header and footer management;</li>
  86. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  87. * <li>transactions to UNDO commands;</li>
  88. * <li>PDF annotations, including links, text and file attachments;</li>
  89. * <li>text rendering modes (fill, stroke and clipping);</li>
  90. * <li>multiple columns mode;</li>
  91. * <li>no-write page regions;</li>
  92. * <li>bookmarks, named destinations and table of content;</li>
  93. * <li>text hyphenation;</li>
  94. * <li>text stretching and spacing (tracking);</li>
  95. * <li>automatic page break, line break and text alignments including justification;</li>
  96. * <li>automatic page numbering and page groups;</li>
  97. * <li>move and delete pages;</li>
  98. * <li>page compression (requires php-zlib extension);</li>
  99. * <li>XOBject Templates;</li>
  100. * <li>Layers and object visibility;</li>
  101. * <li>PDF/A-1b support.</li>
  102. * </ul>
  103. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  104. * @package com.tecnick.tcpdf
  105. * @author Nicola Asuni
  106. * @version 6.2.26
  107. */
  108. // TCPDF configuration
  109. require_once(dirname(__FILE__).'/tcpdf_autoconfig.php');
  110. // TCPDF static font methods and data
  111. require_once(dirname(__FILE__).'/include/tcpdf_font_data.php');
  112. // TCPDF static font methods and data
  113. require_once(dirname(__FILE__).'/include/tcpdf_fonts.php');
  114. // TCPDF static color methods and data
  115. require_once(dirname(__FILE__).'/include/tcpdf_colors.php');
  116. // TCPDF static image methods and data
  117. require_once(dirname(__FILE__).'/include/tcpdf_images.php');
  118. // TCPDF static methods and data
  119. require_once(dirname(__FILE__).'/include/tcpdf_static.php');
  120. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  121. /**
  122. * @class TCPDF
  123. * PHP class for generating PDF documents without requiring external extensions.
  124. * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  125. * @package com.tecnick.tcpdf
  126. * @brief PHP class for generating PDF documents without requiring external extensions.
  127. * @version 6.2.26
  128. * @author Nicola Asuni - info@tecnick.com
  129. * @IgnoreAnnotation("protected")
  130. * @IgnoreAnnotation("public")
  131. * @IgnoreAnnotation("pre")
  132. */
  133. class TCPDF {
  134. // Protected properties
  135. /**
  136. * Current page number.
  137. * @protected
  138. */
  139. protected $page;
  140. /**
  141. * Current object number.
  142. * @protected
  143. */
  144. protected $n;
  145. /**
  146. * Array of object offsets.
  147. * @protected
  148. */
  149. protected $offsets = array();
  150. /**
  151. * Array of object IDs for each page.
  152. * @protected
  153. */
  154. protected $pageobjects = array();
  155. /**
  156. * Buffer holding in-memory PDF.
  157. * @protected
  158. */
  159. protected $buffer;
  160. /**
  161. * Array containing pages.
  162. * @protected
  163. */
  164. protected $pages = array();
  165. /**
  166. * Current document state.
  167. * @protected
  168. */
  169. protected $state;
  170. /**
  171. * Compression flag.
  172. * @protected
  173. */
  174. protected $compress;
  175. /**
  176. * Current page orientation (P = Portrait, L = Landscape).
  177. * @protected
  178. */
  179. protected $CurOrientation;
  180. /**
  181. * Page dimensions.
  182. * @protected
  183. */
  184. protected $pagedim = array();
  185. /**
  186. * Scale factor (number of points in user unit).
  187. * @protected
  188. */
  189. protected $k;
  190. /**
  191. * Width of page format in points.
  192. * @protected
  193. */
  194. protected $fwPt;
  195. /**
  196. * Height of page format in points.
  197. * @protected
  198. */
  199. protected $fhPt;
  200. /**
  201. * Current width of page in points.
  202. * @protected
  203. */
  204. protected $wPt;
  205. /**
  206. * Current height of page in points.
  207. * @protected
  208. */
  209. protected $hPt;
  210. /**
  211. * Current width of page in user unit.
  212. * @protected
  213. */
  214. protected $w;
  215. /**
  216. * Current height of page in user unit.
  217. * @protected
  218. */
  219. protected $h;
  220. /**
  221. * Left margin.
  222. * @protected
  223. */
  224. protected $lMargin;
  225. /**
  226. * Right margin.
  227. * @protected
  228. */
  229. protected $rMargin;
  230. /**
  231. * Cell left margin (used by regions).
  232. * @protected
  233. */
  234. protected $clMargin;
  235. /**
  236. * Cell right margin (used by regions).
  237. * @protected
  238. */
  239. protected $crMargin;
  240. /**
  241. * Top margin.
  242. * @protected
  243. */
  244. protected $tMargin;
  245. /**
  246. * Page break margin.
  247. * @protected
  248. */
  249. protected $bMargin;
  250. /**
  251. * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  252. * @since 5.9.000 (2010-10-03)
  253. * @protected
  254. */
  255. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  256. /**
  257. * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  258. * @since 5.9.000 (2010-10-04)
  259. * @protected
  260. */
  261. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  262. /**
  263. * Current horizontal position in user unit for cell positioning.
  264. * @protected
  265. */
  266. protected $x;
  267. /**
  268. * Current vertical position in user unit for cell positioning.
  269. * @protected
  270. */
  271. protected $y;
  272. /**
  273. * Height of last cell printed.
  274. * @protected
  275. */
  276. protected $lasth;
  277. /**
  278. * Line width in user unit.
  279. * @protected
  280. */
  281. protected $LineWidth;
  282. /**
  283. * Array of standard font names.
  284. * @protected
  285. */
  286. protected $CoreFonts;
  287. /**
  288. * Array of used fonts.
  289. * @protected
  290. */
  291. protected $fonts = array();
  292. /**
  293. * Array of font files.
  294. * @protected
  295. */
  296. protected $FontFiles = array();
  297. /**
  298. * Array of encoding differences.
  299. * @protected
  300. */
  301. protected $diffs = array();
  302. /**
  303. * Array of used images.
  304. * @protected
  305. */
  306. protected $images = array();
  307. /**
  308. * Depth of the svg tag, to keep track if the svg tag is a subtag or the root tag.
  309. * @protected
  310. */
  311. protected $svg_tag_depth = 0;
  312. /**
  313. * Array of Annotations in pages.
  314. * @protected
  315. */
  316. protected $PageAnnots = array();
  317. /**
  318. * Array of internal links.
  319. * @protected
  320. */
  321. protected $links = array();
  322. /**
  323. * Current font family.
  324. * @protected
  325. */
  326. protected $FontFamily;
  327. /**
  328. * Current font style.
  329. * @protected
  330. */
  331. protected $FontStyle;
  332. /**
  333. * Current font ascent (distance between font top and baseline).
  334. * @protected
  335. * @since 2.8.000 (2007-03-29)
  336. */
  337. protected $FontAscent;
  338. /**
  339. * Current font descent (distance between font bottom and baseline).
  340. * @protected
  341. * @since 2.8.000 (2007-03-29)
  342. */
  343. protected $FontDescent;
  344. /**
  345. * Underlining flag.
  346. * @protected
  347. */
  348. protected $underline;
  349. /**
  350. * Overlining flag.
  351. * @protected
  352. */
  353. protected $overline;
  354. /**
  355. * Current font info.
  356. * @protected
  357. */
  358. protected $CurrentFont;
  359. /**
  360. * Current font size in points.
  361. * @protected
  362. */
  363. protected $FontSizePt;
  364. /**
  365. * Current font size in user unit.
  366. * @protected
  367. */
  368. protected $FontSize;
  369. /**
  370. * Commands for drawing color.
  371. * @protected
  372. */
  373. protected $DrawColor;
  374. /**
  375. * Commands for filling color.
  376. * @protected
  377. */
  378. protected $FillColor;
  379. /**
  380. * Commands for text color.
  381. * @protected
  382. */
  383. protected $TextColor;
  384. /**
  385. * Indicates whether fill and text colors are different.
  386. * @protected
  387. */
  388. protected $ColorFlag;
  389. /**
  390. * Automatic page breaking.
  391. * @protected
  392. */
  393. protected $AutoPageBreak;
  394. /**
  395. * Threshold used to trigger page breaks.
  396. * @protected
  397. */
  398. protected $PageBreakTrigger;
  399. /**
  400. * Flag set when processing page header.
  401. * @protected
  402. */
  403. protected $InHeader = false;
  404. /**
  405. * Flag set when processing page footer.
  406. * @protected
  407. */
  408. protected $InFooter = false;
  409. /**
  410. * Zoom display mode.
  411. * @protected
  412. */
  413. protected $ZoomMode;
  414. /**
  415. * Layout display mode.
  416. * @protected
  417. */
  418. protected $LayoutMode;
  419. /**
  420. * If true set the document information dictionary in Unicode.
  421. * @protected
  422. */
  423. protected $docinfounicode = true;
  424. /**
  425. * Document title.
  426. * @protected
  427. */
  428. protected $title = '';
  429. /**
  430. * Document subject.
  431. * @protected
  432. */
  433. protected $subject = '';
  434. /**
  435. * Document author.
  436. * @protected
  437. */
  438. protected $author = '';
  439. /**
  440. * Document keywords.
  441. * @protected
  442. */
  443. protected $keywords = '';
  444. /**
  445. * Document creator.
  446. * @protected
  447. */
  448. protected $creator = '';
  449. /**
  450. * Starting page number.
  451. * @protected
  452. */
  453. protected $starting_page_number = 1;
  454. /**
  455. * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  456. * @since 2002-07-31
  457. * @author Nicola Asuni
  458. * @protected
  459. */
  460. protected $img_rb_x;
  461. /**
  462. * The right-bottom corner Y coordinate of last inserted image.
  463. * @since 2002-07-31
  464. * @author Nicola Asuni
  465. * @protected
  466. */
  467. protected $img_rb_y;
  468. /**
  469. * Adjusting factor to convert pixels to user units.
  470. * @since 2004-06-14
  471. * @author Nicola Asuni
  472. * @protected
  473. */
  474. protected $imgscale = 1;
  475. /**
  476. * Boolean flag set to true when the input text is unicode (require unicode fonts).
  477. * @since 2005-01-02
  478. * @author Nicola Asuni
  479. * @protected
  480. */
  481. protected $isunicode = false;
  482. /**
  483. * PDF version.
  484. * @since 1.5.3
  485. * @protected
  486. */
  487. protected $PDFVersion = '1.7';
  488. /**
  489. * ID of the stored default header template (-1 = not set).
  490. * @protected
  491. */
  492. protected $header_xobjid = false;
  493. /**
  494. * If true reset the Header Xobject template at each page
  495. * @protected
  496. */
  497. protected $header_xobj_autoreset = false;
  498. /**
  499. * Minimum distance between header and top page margin.
  500. * @protected
  501. */
  502. protected $header_margin;
  503. /**
  504. * Minimum distance between footer and bottom page margin.
  505. * @protected
  506. */
  507. protected $footer_margin;
  508. /**
  509. * Original left margin value.
  510. * @protected
  511. * @since 1.53.0.TC013
  512. */
  513. protected $original_lMargin;
  514. /**
  515. * Original right margin value.
  516. * @protected
  517. * @since 1.53.0.TC013
  518. */
  519. protected $original_rMargin;
  520. /**
  521. * Default font used on page header.
  522. * @protected
  523. */
  524. protected $header_font;
  525. /**
  526. * Default font used on page footer.
  527. * @protected
  528. */
  529. protected $footer_font;
  530. /**
  531. * Language templates.
  532. * @protected
  533. */
  534. protected $l;
  535. /**
  536. * Barcode to print on page footer (only if set).
  537. * @protected
  538. */
  539. protected $barcode = false;
  540. /**
  541. * Boolean flag to print/hide page header.
  542. * @protected
  543. */
  544. protected $print_header = true;
  545. /**
  546. * Boolean flag to print/hide page footer.
  547. * @protected
  548. */
  549. protected $print_footer = true;
  550. /**
  551. * Header image logo.
  552. * @protected
  553. */
  554. protected $header_logo = '';
  555. /**
  556. * Width of header image logo in user units.
  557. * @protected
  558. */
  559. protected $header_logo_width = 30;
  560. /**
  561. * Title to be printed on default page header.
  562. * @protected
  563. */
  564. protected $header_title = '';
  565. /**
  566. * String to pring on page header after title.
  567. * @protected
  568. */
  569. protected $header_string = '';
  570. /**
  571. * Color for header text (RGB array).
  572. * @since 5.9.174 (2012-07-25)
  573. * @protected
  574. */
  575. protected $header_text_color = array(0,0,0);
  576. /**
  577. * Color for header line (RGB array).
  578. * @since 5.9.174 (2012-07-25)
  579. * @protected
  580. */
  581. protected $header_line_color = array(0,0,0);
  582. /**
  583. * Color for footer text (RGB array).
  584. * @since 5.9.174 (2012-07-25)
  585. * @protected
  586. */
  587. protected $footer_text_color = array(0,0,0);
  588. /**
  589. * Color for footer line (RGB array).
  590. * @since 5.9.174 (2012-07-25)
  591. * @protected
  592. */
  593. protected $footer_line_color = array(0,0,0);
  594. /**
  595. * Text shadow data array.
  596. * @since 5.9.174 (2012-07-25)
  597. * @protected
  598. */
  599. protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
  600. /**
  601. * Default number of columns for html table.
  602. * @protected
  603. */
  604. protected $default_table_columns = 4;
  605. // variables for html parser
  606. /**
  607. * HTML PARSER: array to store current link and rendering styles.
  608. * @protected
  609. */
  610. protected $HREF = array();
  611. /**
  612. * List of available fonts on filesystem.
  613. * @protected
  614. */
  615. protected $fontlist = array();
  616. /**
  617. * Current foreground color.
  618. * @protected
  619. */
  620. protected $fgcolor;
  621. /**
  622. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  623. * @protected
  624. */
  625. protected $listordered = array();
  626. /**
  627. * HTML PARSER: array count list items on nested lists.
  628. * @protected
  629. */
  630. protected $listcount = array();
  631. /**
  632. * HTML PARSER: current list nesting level.
  633. * @protected
  634. */
  635. protected $listnum = 0;
  636. /**
  637. * HTML PARSER: indent amount for lists.
  638. * @protected
  639. */
  640. protected $listindent = 0;
  641. /**
  642. * HTML PARSER: current list indententation level.
  643. * @protected
  644. */
  645. protected $listindentlevel = 0;
  646. /**
  647. * Current background color.
  648. * @protected
  649. */
  650. protected $bgcolor;
  651. /**
  652. * Temporary font size in points.
  653. * @protected
  654. */
  655. protected $tempfontsize = 10;
  656. /**
  657. * Spacer string for LI tags.
  658. * @protected
  659. */
  660. protected $lispacer = '';
  661. /**
  662. * Default encoding.
  663. * @protected
  664. * @since 1.53.0.TC010
  665. */
  666. protected $encoding = 'UTF-8';
  667. /**
  668. * PHP internal encoding.
  669. * @protected
  670. * @since 1.53.0.TC016
  671. */
  672. protected $internal_encoding;
  673. /**
  674. * Boolean flag to indicate if the document language is Right-To-Left.
  675. * @protected
  676. * @since 2.0.000
  677. */
  678. protected $rtl = false;
  679. /**
  680. * Boolean flag used to force RTL or LTR string direction.
  681. * @protected
  682. * @since 2.0.000
  683. */
  684. protected $tmprtl = false;
  685. // --- Variables used for document encryption:
  686. /**
  687. * IBoolean flag indicating whether document is protected.
  688. * @protected
  689. * @since 2.0.000 (2008-01-02)
  690. */
  691. protected $encrypted;
  692. /**
  693. * Array containing encryption settings.
  694. * @protected
  695. * @since 5.0.005 (2010-05-11)
  696. */
  697. protected $encryptdata = array();
  698. /**
  699. * Last RC4 key encrypted (cached for optimisation).
  700. * @protected
  701. * @since 2.0.000 (2008-01-02)
  702. */
  703. protected $last_enc_key;
  704. /**
  705. * Last RC4 computed key.
  706. * @protected
  707. * @since 2.0.000 (2008-01-02)
  708. */
  709. protected $last_enc_key_c;
  710. /**
  711. * File ID (used on document trailer).
  712. * @protected
  713. * @since 5.0.005 (2010-05-12)
  714. */
  715. protected $file_id;
  716. // --- bookmark ---
  717. /**
  718. * Outlines for bookmark.
  719. * @protected
  720. * @since 2.1.002 (2008-02-12)
  721. */
  722. protected $outlines = array();
  723. /**
  724. * Outline root for bookmark.
  725. * @protected
  726. * @since 2.1.002 (2008-02-12)
  727. */
  728. protected $OutlineRoot;
  729. // --- javascript and form ---
  730. /**
  731. * Javascript code.
  732. * @protected
  733. * @since 2.1.002 (2008-02-12)
  734. */
  735. protected $javascript = '';
  736. /**
  737. * Javascript counter.
  738. * @protected
  739. * @since 2.1.002 (2008-02-12)
  740. */
  741. protected $n_js;
  742. /**
  743. * line through state
  744. * @protected
  745. * @since 2.8.000 (2008-03-19)
  746. */
  747. protected $linethrough;
  748. /**
  749. * Array with additional document-wide usage rights for the document.
  750. * @protected
  751. * @since 5.8.014 (2010-08-23)
  752. */
  753. protected $ur = array();
  754. /**
  755. * DPI (Dot Per Inch) Document Resolution (do not change).
  756. * @protected
  757. * @since 3.0.000 (2008-03-27)
  758. */
  759. protected $dpi = 72;
  760. /**
  761. * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  762. * @protected
  763. * @since 3.0.000 (2008-03-27)
  764. */
  765. protected $newpagegroup = array();
  766. /**
  767. * Array that contains the number of pages in each page group.
  768. * @protected
  769. * @since 3.0.000 (2008-03-27)
  770. */
  771. protected $pagegroups = array();
  772. /**
  773. * Current page group number.
  774. * @protected
  775. * @since 3.0.000 (2008-03-27)
  776. */
  777. protected $currpagegroup = 0;
  778. /**
  779. * Array of transparency objects and parameters.
  780. * @protected
  781. * @since 3.0.000 (2008-03-27)
  782. */
  783. protected $extgstates;
  784. /**
  785. * Set the default JPEG compression quality (1-100).
  786. * @protected
  787. * @since 3.0.000 (2008-03-27)
  788. */
  789. protected $jpeg_quality;
  790. /**
  791. * Default cell height ratio.
  792. * @protected
  793. * @since 3.0.014 (2008-05-23)
  794. */
  795. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  796. /**
  797. * PDF viewer preferences.
  798. * @protected
  799. * @since 3.1.000 (2008-06-09)
  800. */
  801. protected $viewer_preferences;
  802. /**
  803. * A name object specifying how the document should be displayed when opened.
  804. * @protected
  805. * @since 3.1.000 (2008-06-09)
  806. */
  807. protected $PageMode;
  808. /**
  809. * Array for storing gradient information.
  810. * @protected
  811. * @since 3.1.000 (2008-06-09)
  812. */
  813. protected $gradients = array();
  814. /**
  815. * Array used to store positions inside the pages buffer (keys are the page numbers).
  816. * @protected
  817. * @since 3.2.000 (2008-06-26)
  818. */
  819. protected $intmrk = array();
  820. /**
  821. * Array used to store positions inside the pages buffer (keys are the page numbers).
  822. * @protected
  823. * @since 5.7.000 (2010-08-03)
  824. */
  825. protected $bordermrk = array();
  826. /**
  827. * Array used to store page positions to track empty pages (keys are the page numbers).
  828. * @protected
  829. * @since 5.8.007 (2010-08-18)
  830. */
  831. protected $emptypagemrk = array();
  832. /**
  833. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  834. * @protected
  835. * @since 4.6.021 (2009-07-20)
  836. */
  837. protected $cntmrk = array();
  838. /**
  839. * Array used to store footer positions of each page.
  840. * @protected
  841. * @since 3.2.000 (2008-07-01)
  842. */
  843. protected $footerpos = array();
  844. /**
  845. * Array used to store footer length of each page.
  846. * @protected
  847. * @since 4.0.014 (2008-07-29)
  848. */
  849. protected $footerlen = array();
  850. /**
  851. * Boolean flag to indicate if a new line is created.
  852. * @protected
  853. * @since 3.2.000 (2008-07-01)
  854. */
  855. protected $newline = true;
  856. /**
  857. * End position of the latest inserted line.
  858. * @protected
  859. * @since 3.2.000 (2008-07-01)
  860. */
  861. protected $endlinex = 0;
  862. /**
  863. * PDF string for width value of the last line.
  864. * @protected
  865. * @since 4.0.006 (2008-07-16)
  866. */
  867. protected $linestyleWidth = '';
  868. /**
  869. * PDF string for CAP value of the last line.
  870. * @protected
  871. * @since 4.0.006 (2008-07-16)
  872. */
  873. protected $linestyleCap = '0 J';
  874. /**
  875. * PDF string for join value of the last line.
  876. * @protected
  877. * @since 4.0.006 (2008-07-16)
  878. */
  879. protected $linestyleJoin = '0 j';
  880. /**
  881. * PDF string for dash value of the last line.
  882. * @protected
  883. * @since 4.0.006 (2008-07-16)
  884. */
  885. protected $linestyleDash = '[] 0 d';
  886. /**
  887. * Boolean flag to indicate if marked-content sequence is open.
  888. * @protected
  889. * @since 4.0.013 (2008-07-28)
  890. */
  891. protected $openMarkedContent = false;
  892. /**
  893. * Count the latest inserted vertical spaces on HTML.
  894. * @protected
  895. * @since 4.0.021 (2008-08-24)
  896. */
  897. protected $htmlvspace = 0;
  898. /**
  899. * Array of Spot colors.
  900. * @protected
  901. * @since 4.0.024 (2008-09-12)
  902. */
  903. protected $spot_colors = array();
  904. /**
  905. * Symbol used for HTML unordered list items.
  906. * @protected
  907. * @since 4.0.028 (2008-09-26)
  908. */
  909. protected $lisymbol = '';
  910. /**
  911. * String used to mark the beginning and end of EPS image blocks.
  912. * @protected
  913. * @since 4.1.000 (2008-10-18)
  914. */
  915. protected $epsmarker = 'x#!#EPS#!#x';
  916. /**
  917. * Array of transformation matrix.
  918. * @protected
  919. * @since 4.2.000 (2008-10-29)
  920. */
  921. protected $transfmatrix = array();
  922. /**
  923. * Current key for transformation matrix.
  924. * @protected
  925. * @since 4.8.005 (2009-09-17)
  926. */
  927. protected $transfmatrix_key = 0;
  928. /**
  929. * Booklet mode for double-sided pages.
  930. * @protected
  931. * @since 4.2.000 (2008-10-29)
  932. */
  933. protected $booklet = false;
  934. /**
  935. * Epsilon value used for float calculations.
  936. * @protected
  937. * @since 4.2.000 (2008-10-29)
  938. */
  939. protected $feps = 0.005;
  940. /**
  941. * Array used for custom vertical spaces for HTML tags.
  942. * @protected
  943. * @since 4.2.001 (2008-10-30)
  944. */
  945. protected $tagvspaces = array();
  946. /**
  947. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  948. * @protected
  949. * @since 4.2.007 (2008-11-12)
  950. */
  951. protected $customlistindent = -1;
  952. /**
  953. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  954. * @protected
  955. * @since 4.2.010 (2008-11-14)
  956. */
  957. protected $opencell = true;
  958. /**
  959. * Array of files to embedd.
  960. * @protected
  961. * @since 4.4.000 (2008-12-07)
  962. */
  963. protected $embeddedfiles = array();
  964. /**
  965. * Boolean flag to indicate if we are inside a PRE tag.
  966. * @protected
  967. * @since 4.4.001 (2008-12-08)
  968. */
  969. protected $premode = false;
  970. /**
  971. * Array used to store positions of graphics transformation blocks inside the page buffer.
  972. * keys are the page numbers
  973. * @protected
  974. * @since 4.4.002 (2008-12-09)
  975. */
  976. protected $transfmrk = array();
  977. /**
  978. * Default color for html links.
  979. * @protected
  980. * @since 4.4.003 (2008-12-09)
  981. */
  982. protected $htmlLinkColorArray = array(0, 0, 255);
  983. /**
  984. * Default font style to add to html links.
  985. * @protected
  986. * @since 4.4.003 (2008-12-09)
  987. */
  988. protected $htmlLinkFontStyle = 'U';
  989. /**
  990. * Counts the number of pages.
  991. * @protected
  992. * @since 4.5.000 (2008-12-31)
  993. */
  994. protected $numpages = 0;
  995. /**
  996. * Array containing page lengths in bytes.
  997. * @protected
  998. * @since 4.5.000 (2008-12-31)
  999. */
  1000. protected $pagelen = array();
  1001. /**
  1002. * Counts the number of pages.
  1003. * @protected
  1004. * @since 4.5.000 (2008-12-31)
  1005. */
  1006. protected $numimages = 0;
  1007. /**
  1008. * Store the image keys.
  1009. * @protected
  1010. * @since 4.5.000 (2008-12-31)
  1011. */
  1012. protected $imagekeys = array();
  1013. /**
  1014. * Length of the buffer in bytes.
  1015. * @protected
  1016. * @since 4.5.000 (2008-12-31)
  1017. */
  1018. protected $bufferlen = 0;
  1019. /**
  1020. * Counts the number of fonts.
  1021. * @protected
  1022. * @since 4.5.000 (2009-01-02)
  1023. */
  1024. protected $numfonts = 0;
  1025. /**
  1026. * Store the font keys.
  1027. * @protected
  1028. * @since 4.5.000 (2009-01-02)
  1029. */
  1030. protected $fontkeys = array();
  1031. /**
  1032. * Store the font object IDs.
  1033. * @protected
  1034. * @since 4.8.001 (2009-09-09)
  1035. */
  1036. protected $font_obj_ids = array();
  1037. /**
  1038. * Store the fage status (true when opened, false when closed).
  1039. * @protected
  1040. * @since 4.5.000 (2009-01-02)
  1041. */
  1042. protected $pageopen = array();
  1043. /**
  1044. * Default monospace font.
  1045. * @protected
  1046. * @since 4.5.025 (2009-03-10)
  1047. */
  1048. protected $default_monospaced_font = 'courier';
  1049. /**
  1050. * Cloned copy of the current class object.
  1051. * @protected
  1052. * @since 4.5.029 (2009-03-19)
  1053. */
  1054. protected $objcopy;
  1055. /**
  1056. * Array used to store the lengths of cache files.
  1057. * @protected
  1058. * @since 4.5.029 (2009-03-19)
  1059. */
  1060. protected $cache_file_length = array();
  1061. /**
  1062. * Table header content to be repeated on each new page.
  1063. * @protected
  1064. * @since 4.5.030 (2009-03-20)
  1065. */
  1066. protected $thead = '';
  1067. /**
  1068. * Margins used for table header.
  1069. * @protected
  1070. * @since 4.5.030 (2009-03-20)
  1071. */
  1072. protected $theadMargins = array();
  1073. /**
  1074. * Boolean flag to enable document digital signature.
  1075. * @protected
  1076. * @since 4.6.005 (2009-04-24)
  1077. */
  1078. protected $sign = false;
  1079. /**
  1080. * Digital signature data.
  1081. * @protected
  1082. * @since 4.6.005 (2009-04-24)
  1083. */
  1084. protected $signature_data = array();
  1085. /**
  1086. * Digital signature max length.
  1087. * @protected
  1088. * @since 4.6.005 (2009-04-24)
  1089. */
  1090. protected $signature_max_length = 11742;
  1091. /**
  1092. * Data for digital signature appearance.
  1093. * @protected
  1094. * @since 5.3.011 (2010-06-16)
  1095. */
  1096. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1097. /**
  1098. * Array of empty digital signature appearances.
  1099. * @protected
  1100. * @since 5.9.101 (2011-07-06)
  1101. */
  1102. protected $empty_signature_appearance = array();
  1103. /**
  1104. * Boolean flag to enable document timestamping with TSA.
  1105. * @protected
  1106. * @since 6.0.085 (2014-06-19)
  1107. */
  1108. protected $tsa_timestamp = false;
  1109. /**
  1110. * Timestamping data.
  1111. * @protected
  1112. * @since 6.0.085 (2014-06-19)
  1113. */
  1114. protected $tsa_data = array();
  1115. /**
  1116. * Regular expression used to find blank characters (required for word-wrapping).
  1117. * @protected
  1118. * @since 4.6.006 (2009-04-28)
  1119. */
  1120. protected $re_spaces = '/[^\S\xa0]/';
  1121. /**
  1122. * Array of $re_spaces parts.
  1123. * @protected
  1124. * @since 5.5.011 (2010-07-09)
  1125. */
  1126. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1127. /**
  1128. * Digital signature object ID.
  1129. * @protected
  1130. * @since 4.6.022 (2009-06-23)
  1131. */
  1132. protected $sig_obj_id = 0;
  1133. /**
  1134. * ID of page objects.
  1135. * @protected
  1136. * @since 4.7.000 (2009-08-29)
  1137. */
  1138. protected $page_obj_id = array();
  1139. /**
  1140. * List of form annotations IDs.
  1141. * @protected
  1142. * @since 4.8.000 (2009-09-07)
  1143. */
  1144. protected $form_obj_id = array();
  1145. /**
  1146. * Deafult Javascript field properties. Possible values are described on official Javascript for Acrobat API reference. Annotation options can be directly specified using the 'aopt' entry.
  1147. * @protected
  1148. * @since 4.8.000 (2009-09-07)
  1149. */
  1150. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1151. /**
  1152. * Javascript objects array.
  1153. * @protected
  1154. * @since 4.8.000 (2009-09-07)
  1155. */
  1156. protected $js_objects = array();
  1157. /**
  1158. * Current form action (used during XHTML rendering).
  1159. * @protected
  1160. * @since 4.8.000 (2009-09-07)
  1161. */
  1162. protected $form_action = '';
  1163. /**
  1164. * Current form encryption type (used during XHTML rendering).
  1165. * @protected
  1166. * @since 4.8.000 (2009-09-07)
  1167. */
  1168. protected $form_enctype = 'application/x-www-form-urlencoded';
  1169. /**
  1170. * Current method to submit forms.
  1171. * @protected
  1172. * @since 4.8.000 (2009-09-07)
  1173. */
  1174. protected $form_mode = 'post';
  1175. /**
  1176. * List of fonts used on form fields (fontname => fontkey).
  1177. * @protected
  1178. * @since 4.8.001 (2009-09-09)
  1179. */
  1180. protected $annotation_fonts = array();
  1181. /**
  1182. * List of radio buttons parent objects.
  1183. * @protected
  1184. * @since 4.8.001 (2009-09-09)
  1185. */
  1186. protected $radiobutton_groups = array();
  1187. /**
  1188. * List of radio group objects IDs.
  1189. * @protected
  1190. * @since 4.8.001 (2009-09-09)
  1191. */
  1192. protected $radio_groups = array();
  1193. /**
  1194. * Text indentation value (used for text-indent CSS attribute).
  1195. * @protected
  1196. * @since 4.8.006 (2009-09-23)
  1197. */
  1198. protected $textindent = 0;
  1199. /**
  1200. * Store page number when startTransaction() is called.
  1201. * @protected
  1202. * @since 4.8.006 (2009-09-23)
  1203. */
  1204. protected $start_transaction_page = 0;
  1205. /**
  1206. * Store Y position when startTransaction() is called.
  1207. * @protected
  1208. * @since 4.9.001 (2010-03-28)
  1209. */
  1210. protected $start_transaction_y = 0;
  1211. /**
  1212. * True when we are printing the thead section on a new page.
  1213. * @protected
  1214. * @since 4.8.027 (2010-01-25)
  1215. */
  1216. protected $inthead = false;
  1217. /**
  1218. * Array of column measures (width, space, starting Y position).
  1219. * @protected
  1220. * @since 4.9.001 (2010-03-28)
  1221. */
  1222. protected $columns = array();
  1223. /**
  1224. * Number of colums.
  1225. * @protected
  1226. * @since 4.9.001 (2010-03-28)
  1227. */
  1228. protected $num_columns = 1;
  1229. /**
  1230. * Current column number.
  1231. * @protected
  1232. * @since 4.9.001 (2010-03-28)
  1233. */
  1234. protected $current_column = 0;
  1235. /**
  1236. * Starting page for columns.
  1237. * @protected
  1238. * @since 4.9.001 (2010-03-28)
  1239. */
  1240. protected $column_start_page = 0;
  1241. /**
  1242. * Maximum page and column selected.
  1243. * @protected
  1244. * @since 5.8.000 (2010-08-11)
  1245. */
  1246. protected $maxselcol = array('page' => 0, 'column' => 0);
  1247. /**
  1248. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1249. * @protected
  1250. * @since 5.8.000 (2010-08-11)
  1251. */
  1252. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1253. /**
  1254. * Text rendering mode: 0 = Fill text; 1 = Stroke text; 2 = Fill, then stroke text; 3 = Neither fill nor stroke text (invisible); 4 = Fill text and add to path for clipping; 5 = Stroke text and add to path for clipping; 6 = Fill, then stroke text and add to path for clipping; 7 = Add text to path for clipping.
  1255. * @protected
  1256. * @since 4.9.008 (2010-04-03)
  1257. */
  1258. protected $textrendermode = 0;
  1259. /**
  1260. * Text stroke width in doc units.
  1261. * @protected
  1262. * @since 4.9.008 (2010-04-03)
  1263. */
  1264. protected $textstrokewidth = 0;
  1265. /**
  1266. * Current stroke color.
  1267. * @protected
  1268. * @since 4.9.008 (2010-04-03)
  1269. */
  1270. protected $strokecolor;
  1271. /**
  1272. * Default unit of measure for document.
  1273. * @protected
  1274. * @since 5.0.000 (2010-04-22)
  1275. */
  1276. protected $pdfunit = 'mm';
  1277. /**
  1278. * Boolean flag true when we are on TOC (Table Of Content) page.
  1279. * @protected
  1280. */
  1281. protected $tocpage = false;
  1282. /**
  1283. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1284. * @protected
  1285. * @since 5.0.000 (2010-04-26)
  1286. */
  1287. protected $rasterize_vector_images = false;
  1288. /**
  1289. * Boolean flag: if true enables font subsetting by default.
  1290. * @protected
  1291. * @since 5.3.002 (2010-06-07)
  1292. */
  1293. protected $font_subsetting = true;
  1294. /**
  1295. * Array of default graphic settings.
  1296. * @protected
  1297. * @since 5.5.008 (2010-07-02)
  1298. */
  1299. protected $default_graphic_vars = array();
  1300. /**
  1301. * Array of XObjects.
  1302. * @protected
  1303. * @since 5.8.014 (2010-08-23)
  1304. */
  1305. protected $xobjects = array();
  1306. /**
  1307. * Boolean value true when we are inside an XObject.
  1308. * @protected
  1309. * @since 5.8.017 (2010-08-24)
  1310. */
  1311. protected $inxobj = false;
  1312. /**
  1313. * Current XObject ID.
  1314. * @protected
  1315. * @since 5.8.017 (2010-08-24)
  1316. */
  1317. protected $xobjid = '';
  1318. /**
  1319. * Percentage of character stretching.
  1320. * @protected
  1321. * @since 5.9.000 (2010-09-29)
  1322. */
  1323. protected $font_stretching = 100;
  1324. /**
  1325. * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1326. * @protected
  1327. * @since 5.9.000 (2010-09-29)
  1328. */
  1329. protected $font_spacing = 0;
  1330. /**
  1331. * Array of no-write regions.
  1332. * ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right)
  1333. * @protected
  1334. * @since 5.9.003 (2010-10-14)
  1335. */
  1336. protected $page_regions = array();
  1337. /**
  1338. * Boolean value true when page region check is active.
  1339. * @protected
  1340. */
  1341. protected $check_page_regions = true;
  1342. /**
  1343. * Array of PDF layers data.
  1344. * @protected
  1345. * @since 5.9.102 (2011-07-13)
  1346. */
  1347. protected $pdflayers = array();
  1348. /**
  1349. * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1350. * @protected
  1351. * @since 5.9.097 (2011-06-23)
  1352. */
  1353. protected $dests = array();
  1354. /**
  1355. * Object ID for Named Destinations
  1356. * @protected
  1357. * @since 5.9.097 (2011-06-23)
  1358. */
  1359. protected $n_dests;
  1360. /**
  1361. * Embedded Files Names
  1362. * @protected
  1363. * @since 5.9.204 (2013-01-23)
  1364. */
  1365. protected $efnames = array();
  1366. /**
  1367. * Directory used for the last SVG image.
  1368. * @protected
  1369. * @since 5.0.000 (2010-05-05)
  1370. */
  1371. protected $svgdir = '';
  1372. /**
  1373. * Deafult unit of measure for SVG.
  1374. * @protected
  1375. * @since 5.0.000 (2010-05-02)
  1376. */
  1377. protected $svgunit = 'px';
  1378. /**
  1379. * Array of SVG gradients.
  1380. * @protected
  1381. * @since 5.0.000 (2010-05-02)
  1382. */
  1383. protected $svggradients = array();
  1384. /**
  1385. * ID of last SVG gradient.
  1386. * @protected
  1387. * @since 5.0.000 (2010-05-02)
  1388. */
  1389. protected $svggradientid = 0;
  1390. /**
  1391. * Boolean value true when in SVG defs group.
  1392. * @protected
  1393. * @since 5.0.000 (2010-05-02)
  1394. */
  1395. protected $svgdefsmode = false;
  1396. /**
  1397. * Array of SVG defs.
  1398. * @protected
  1399. * @since 5.0.000 (2010-05-02)
  1400. */
  1401. protected $svgdefs = array();
  1402. /**
  1403. * Boolean value true when in SVG clipPath tag.
  1404. * @protected
  1405. * @since 5.0.000 (2010-04-26)
  1406. */
  1407. protected $svgclipmode = false;
  1408. /**
  1409. * Array of SVG clipPath commands.
  1410. * @protected
  1411. * @since 5.0.000 (2010-05-02)
  1412. */
  1413. protected $svgclippaths = array();
  1414. /**
  1415. * Array of SVG clipPath tranformation matrix.
  1416. * @protected
  1417. * @since 5.8.022 (2010-08-31)
  1418. */
  1419. protected $svgcliptm = array();
  1420. /**
  1421. * ID of last SVG clipPath.
  1422. * @protected
  1423. * @since 5.0.000 (2010-05-02)
  1424. */
  1425. protected $svgclipid = 0;
  1426. /**
  1427. * SVG text.
  1428. * @protected
  1429. * @since 5.0.000 (2010-05-02)
  1430. */
  1431. protected $svgtext = '';
  1432. /**
  1433. * SVG text properties.
  1434. * @protected
  1435. * @since 5.8.013 (2010-08-23)
  1436. */
  1437. protected $svgtextmode = array();
  1438. /**
  1439. * Array of SVG properties.
  1440. * @protected
  1441. * @since 5.0.000 (2010-05-02)
  1442. */
  1443. protected $svgstyles = array(array(
  1444. 'alignment-baseline' => 'auto',
  1445. 'baseline-shift' => 'baseline',
  1446. 'clip' => 'auto',
  1447. 'clip-path' => 'none',
  1448. 'clip-rule' => 'nonzero',
  1449. 'color' => 'black',
  1450. 'color-interpolation' => 'sRGB',
  1451. 'color-interpolation-filters' => 'linearRGB',
  1452. 'color-profile' => 'auto',
  1453. 'color-rendering' => 'auto',
  1454. 'cursor' => 'auto',
  1455. 'direction' => 'ltr',
  1456. 'display' => 'inline',
  1457. 'dominant-baseline' => 'auto',
  1458. 'enable-background' => 'accumulate',
  1459. 'fill' => 'black',
  1460. 'fill-opacity' => 1,
  1461. 'fill-rule' => 'nonzero',
  1462. 'filter' => 'none',
  1463. 'flood-color' => 'black',
  1464. 'flood-opacity' => 1,
  1465. 'font' => '',
  1466. 'font-family' => 'helvetica',
  1467. 'font-size' => 'medium',
  1468. 'font-size-adjust' => 'none',
  1469. 'font-stretch' => 'normal',
  1470. 'font-style' => 'normal',
  1471. 'font-variant' => 'normal',
  1472. 'font-weight' => 'normal',
  1473. 'glyph-orientation-horizontal' => '0deg',
  1474. 'glyph-orientation-vertical' => 'auto',
  1475. 'image-rendering' => 'auto',
  1476. 'kerning' => 'auto',
  1477. 'letter-spacing' => 'normal',
  1478. 'lighting-color' => 'white',
  1479. 'marker' => '',
  1480. 'marker-end' => 'none',
  1481. 'marker-mid' => 'none',
  1482. 'marker-start' => 'none',
  1483. 'mask' => 'none',
  1484. 'opacity' => 1,
  1485. 'overflow' => 'auto',
  1486. 'pointer-events' => 'visiblePainted',
  1487. 'shape-rendering' => 'auto',
  1488. 'stop-color' => 'black',
  1489. 'stop-opacity' => 1,
  1490. 'stroke' => 'none',
  1491. 'stroke-dasharray' => 'none',
  1492. 'stroke-dashoffset' => 0,
  1493. 'stroke-linecap' => 'butt',
  1494. 'stroke-linejoin' => 'miter',
  1495. 'stroke-miterlimit' => 4,
  1496. 'stroke-opacity' => 1,
  1497. 'stroke-width' => 1,
  1498. 'text-anchor' => 'start',
  1499. 'text-decoration' => 'none',
  1500. 'text-rendering' => 'auto',
  1501. 'unicode-bidi' => 'normal',
  1502. 'visibility' => 'visible',
  1503. 'word-spacing' => 'normal',
  1504. 'writing-mode' => 'lr-tb',
  1505. 'text-color' => 'black',
  1506. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1507. ));
  1508. /**
  1509. * If true force sRGB color profile for all document.
  1510. * @protected
  1511. * @since 5.9.121 (2011-09-28)
  1512. */
  1513. protected $force_srgb = false;
  1514. /**
  1515. * If true set the document to PDF/A mode.
  1516. * @protected
  1517. * @since 5.9.121 (2011-09-27)
  1518. */
  1519. protected $pdfa_mode = false;
  1520. /**
  1521. * Document creation date-time
  1522. * @protected
  1523. * @since 5.9.152 (2012-03-22)
  1524. */
  1525. protected $doc_creation_timestamp;
  1526. /**
  1527. * Document modification date-time
  1528. * @protected
  1529. * @since 5.9.152 (2012-03-22)
  1530. */
  1531. protected $doc_modification_timestamp;
  1532. /**
  1533. * Custom XMP data.
  1534. * @protected
  1535. * @since 5.9.128 (2011-10-06)
  1536. */
  1537. protected $custom_xmp = '';
  1538. /**
  1539. * Overprint mode array.
  1540. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1541. * @protected
  1542. * @since 5.9.152 (2012-03-23)
  1543. */
  1544. protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
  1545. /**
  1546. * Alpha mode array.
  1547. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1548. * @protected
  1549. * @since 5.9.152 (2012-03-23)
  1550. */
  1551. protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
  1552. /**
  1553. * Define the page boundaries boxes to be set on document.
  1554. * @protected
  1555. * @since 5.9.152 (2012-03-23)
  1556. */
  1557. protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  1558. /**
  1559. * If true print TCPDF meta link.
  1560. * @protected
  1561. * @since 5.9.152 (2012-03-23)
  1562. */
  1563. protected $tcpdflink = true;
  1564. /**
  1565. * Cache array for computed GD gamma values.
  1566. * @protected
  1567. * @since 5.9.1632 (2012-06-05)
  1568. */
  1569. protected $gdgammacache = array();
  1570. //------------------------------------------------------------
  1571. // METHODS
  1572. //------------------------------------------------------------
  1573. /**
  1574. * This is the class constructor.
  1575. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1576. *
  1577. * IMPORTANT: Please note that this method sets the mb_internal_encoding to ASCII, so if you are using the mbstring module functions with TCPDF you need to correctly set/unset the mb_internal_encoding when needed.
  1578. *
  1579. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1580. * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1581. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  1582. * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
  1583. * @param $encoding (string) Charset encoding (used only when converting back html entities); default is UTF-8.
  1584. * @param $diskcache (boolean) DEPRECATED FEATURE
  1585. * @param $pdfa (boolean) If TRUE set the document to PDF/A mode.
  1586. * @public
  1587. * @see getPageSizeFromFormat(), setPageFormat()
  1588. */
  1589. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
  1590. /* Set internal character encoding to ASCII */
  1591. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1592. $this->internal_encoding = mb_internal_encoding();
  1593. mb_internal_encoding('ASCII');
  1594. }
  1595. // set file ID for trailer
  1596. $serformat = (is_array($format) ? json_encode($format) : $format);
  1597. $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
  1598. $this->font_obj_ids = array();
  1599. $this->page_obj_id = array();
  1600. $this->form_obj_id = array();
  1601. // set pdf/a mode
  1602. $this->pdfa_mode = $pdfa;
  1603. $this->force_srgb = false;
  1604. // set language direction
  1605. $this->rtl = false;
  1606. $this->tmprtl = false;
  1607. // some checks
  1608. $this->_dochecks();
  1609. // initialization of properties
  1610. $this->isunicode = $unicode;
  1611. $this->page = 0;
  1612. $this->transfmrk[0] = array();
  1613. $this->pagedim = array();
  1614. $this->n = 2;
  1615. $this->buffer = '';
  1616. $this->pages = array();
  1617. $this->state = 0;
  1618. $this->fonts = array();
  1619. $this->FontFiles = array();
  1620. $this->diffs = array();
  1621. $this->images = array();
  1622. $this->links = array();
  1623. $this->gradients = array();
  1624. $this->InFooter = false;
  1625. $this->lasth = 0;
  1626. $this->FontFamily = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  1627. $this->FontStyle = '';
  1628. $this->FontSizePt = 12;
  1629. $this->underline = false;
  1630. $this->overline = false;
  1631. $this->linethrough = false;
  1632. $this->DrawColor = '0 G';
  1633. $this->FillColor = '0 g';
  1634. $this->TextColor = '0 g';
  1635. $this->ColorFlag = false;
  1636. $this->pdflayers = array();
  1637. // encryption values
  1638. $this->encrypted = false;
  1639. $this->last_enc_key = '';
  1640. // standard Unicode fonts
  1641. $this->CoreFonts = array(
  1642. 'courier'=>'Courier',
  1643. 'courierB'=>'Courier-Bold',
  1644. 'courierI'=>'Courier-Oblique',
  1645. 'courierBI'=>'Courier-BoldOblique',
  1646. 'helvetica'=>'Helvetica',
  1647. 'helveticaB'=>'Helvetica-Bold',
  1648. 'helveticaI'=>'Helvetica-Oblique',
  1649. 'helveticaBI'=>'Helvetica-BoldOblique',
  1650. 'times'=>'Times-Roman',
  1651. 'timesB'=>'Times-Bold',
  1652. 'timesI'=>'Times-Italic',
  1653. 'timesBI'=>'Times-BoldItalic',
  1654. 'symbol'=>'Symbol',
  1655. 'zapfdingbats'=>'ZapfDingbats'
  1656. );
  1657. // set scale factor
  1658. $this->setPageUnit($unit);
  1659. // set page format and orientation
  1660. $this->setPageFormat($format, $orientation);
  1661. // page margins (1 cm)
  1662. $margin = 28.35 / $this->k;
  1663. $this->SetMargins($margin, $margin);
  1664. $this->clMargin = $this->lMargin;
  1665. $this->crMargin = $this->rMargin;
  1666. // internal cell padding
  1667. $cpadding = $margin / 10;
  1668. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1669. // cell margins
  1670. $this->setCellMargins(0, 0, 0, 0);
  1671. // line width (0.2 mm)
  1672. $this->LineWidth = 0.57 / $this->k;
  1673. $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
  1674. $this->linestyleCap = '0 J';
  1675. $this->linestyleJoin = '0 j';
  1676. $this->linestyleDash = '[] 0 d';
  1677. // automatic page break
  1678. $this->SetAutoPageBreak(true, (2 * $margin));
  1679. // full width display mode
  1680. $this->SetDisplayMode('fullwidth');
  1681. // compression
  1682. $this->SetCompression();
  1683. // set default PDF version number
  1684. $this->setPDFVersion();
  1685. $this->tcpdflink = true;
  1686. $this->encoding = $encoding;
  1687. $this->HREF = array();
  1688. $this->getFontsList();
  1689. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1690. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1691. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1692. $this->extgstates = array();
  1693. $this->setTextShadow();
  1694. // signature
  1695. $this->sign = false;
  1696. $this->tsa_timestamp = false;
  1697. $this->tsa_data = array();
  1698. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
  1699. $this->empty_signature_appearance = array();
  1700. // user's rights
  1701. $this->ur['enabled'] = false;
  1702. $this->ur['document'] = '/FullSave';
  1703. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1704. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1705. $this->ur['signature'] = '/Modify';
  1706. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1707. $this->ur['formex'] = '';
  1708. // set default JPEG quality
  1709. $this->jpeg_quality = 75;
  1710. // initialize some settings
  1711. TCPDF_FONTS::utf8Bidi(array(''), '', false, $this->isunicode, $this->CurrentFont);
  1712. // set default font
  1713. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1714. $this->setHeaderFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
  1715. $this->setFooterFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
  1716. // check if PCRE Unicode support is enabled
  1717. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1718. // PCRE unicode support is turned ON
  1719. // \s : any whitespace character
  1720. // \p{Z} : any separator
  1721. // \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  1722. // \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  1723. //$this->setSpacesRE('/(?!\xa0)[\s\p{Z}\p{Lo}]/u');
  1724. $this->setSpacesRE('/(?!\xa0)[\s\p{Z}]/u');
  1725. } else {
  1726. // PCRE unicode support is turned OFF
  1727. $this->setSpacesRE('/[^\S\xa0]/');
  1728. }
  1729. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1730. // set document creation and modification timestamp
  1731. $this->doc_creation_timestamp = time();
  1732. $this->doc_modification_timestamp = $this->doc_creation_timestamp;
  1733. // get default graphic vars
  1734. $this->default_graphic_vars = $this->getGraphicVars();
  1735. $this->header_xobj_autoreset = false;
  1736. $this->custom_xmp = '';
  1737. // Call cleanup method after script execution finishes or exit() is called.
  1738. // NOTE: This will not be executed if the process is killed with a SIGTERM or SIGKILL signal.
  1739. register_shutdown_function(array($this, '_destroy'), true);
  1740. }
  1741. /**
  1742. * Default destructor.
  1743. * @public
  1744. * @since 1.53.0.TC016
  1745. */
  1746. public function __destruct() {
  1747. // cleanup
  1748. $this->_destroy(true);
  1749. }
  1750. /**
  1751. * Set the units of measure for the document.
  1752. * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1753. * @public
  1754. * @since 3.0.015 (2008-06-06)
  1755. */
  1756. public function setPageUnit($unit) {
  1757. $unit = strtolower($unit);
  1758. //Set scale factor
  1759. switch ($unit) {
  1760. // points
  1761. case 'px':
  1762. case 'pt': {
  1763. $this->k = 1;
  1764. break;
  1765. }
  1766. // millimeters
  1767. case 'mm': {
  1768. $this->k = $this->dpi / 25.4;
  1769. break;
  1770. }
  1771. // centimeters
  1772. case 'cm': {
  1773. $this->k = $this->dpi / 2.54;
  1774. break;
  1775. }
  1776. // inches
  1777. case 'in': {
  1778. $this->k = $this->dpi;
  1779. break;
  1780. }
  1781. // unsupported unit
  1782. default : {
  1783. $this->Error('Incorrect unit: '.$unit);
  1784. break;
  1785. }
  1786. }
  1787. $this->pdfunit = $unit;
  1788. if (isset($this->CurOrientation)) {
  1789. $this->setPageOrientation($this->CurOrientation);
  1790. }
  1791. }
  1792. /**
  1793. * Change the format of the current page
  1794. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numbers (width, height) or an array containing the following measures and options:<ul>
  1795. * <li>['format'] = page format name (one of the above);</li>
  1796. * <li>['Rotate'] : The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li>
  1797. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  1798. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  1799. * <li>['MediaBox']['llx'] : lower-left x coordinate</li>
  1800. * <li>['MediaBox']['lly'] : lower-left y coordinate</li>
  1801. * <li>['MediaBox']['urx'] : upper-right x coordinate</li>
  1802. * <li>['MediaBox']['ury'] : upper-right y coordinate</li>
  1803. * <li>['CropBox'] : the visible region of default user space:</li>
  1804. * <li>['CropBox']['llx'] : lower-left x coordinate</li>
  1805. * <li>['CropBox']['lly'] : lower-left y coordinate</li>
  1806. * <li>['CropBox']['urx'] : upper-right x coordinate</li>
  1807. * <li>['CropBox']['ury'] : upper-right y coordinate</li>
  1808. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  1809. * <li>['BleedBox']['llx'] : lower-left x coordinate</li>
  1810. * <li>['BleedBox']['lly'] : lower-left y coordinate</li>
  1811. * <li>['BleedBox']['urx'] : upper-right x coordinate</li>
  1812. * <li>['BleedBox']['ury'] : upper-right y coordinate</li>
  1813. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  1814. * <li>['TrimBox']['llx'] : lower-left x coordinate</li>
  1815. * <li>['TrimBox']['lly'] : lower-left y coordinate</li>
  1816. * <li>['TrimBox']['urx'] : upper-right x coordinate</li>
  1817. * <li>['TrimBox']['ury'] : upper-right y coordinate</li>
  1818. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  1819. * <li>['ArtBox']['llx'] : lower-left x coordinate</li>
  1820. * <li>['ArtBox']['lly'] : lower-left y coordinate</li>
  1821. * <li>['ArtBox']['urx'] : upper-right x coordinate</li>
  1822. * <li>['ArtBox']['ury'] : upper-right y coordinate</li>
  1823. * <li>['BoxColorInfo'] :specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for each of the possible page boundaries other than the MediaBox:</li>
  1824. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  1825. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  1826. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  1827. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  1828. * <li>['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation</li>
  1829. * <li>['trans']['Dur'] : The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li>
  1830. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  1831. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  1832. * <li>['trans']['Dm'] : (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li>
  1833. * <li>['trans']['M'] : (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li>
  1834. * <li>['trans']['Di'] : (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li>
  1835. * <li>['trans']['SS'] : (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0.</li>
  1836. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  1837. * </ul>
  1838. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
  1839. * <li>P or Portrait (default)</li>
  1840. * <li>L or Landscape</li>
  1841. * <li>'' (empty string) for automatic orientation</li>
  1842. * </ul>
  1843. * @protected
  1844. * @since 3.0.015 (2008-06-06)
  1845. * @see getPageSizeFromFormat()
  1846. */
  1847. protected function setPageFormat($format, $orientation='P') {
  1848. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  1849. // remove inherited values
  1850. unset($this->pagedim[$this->page]);
  1851. }
  1852. if (is_string($format)) {
  1853. // get page measures from format name
  1854. $pf = TCPDF_STATIC::getPageSizeFromFormat($format);
  1855. $this->fwPt = $pf[0];
  1856. $this->fhPt = $pf[1];
  1857. } else {
  1858. // the boundaries of the physical medium on which the page shall be displayed or printed
  1859. if (isset($format['MediaBox'])) {
  1860. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false, $this->k, $this->pagedim);
  1861. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  1862. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  1863. } else {
  1864. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  1865. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  1866. } else {
  1867. if (!isset($format['format'])) {
  1868. // default value
  1869. $format['format'] = 'A4';
  1870. }
  1871. $pf = TCPDF_STATIC::getPageSizeFromFormat($format['format']);
  1872. }
  1873. $this->fwPt = $pf[0];
  1874. $this->fhPt = $pf[1];
  1875. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1876. }
  1877. // the visible region of default user space
  1878. if (isset($format['CropBox'])) {
  1879. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false, $this->k, $this->pagedim);
  1880. }
  1881. // the region to which the contents of the page shall be clipped when output in a production environment
  1882. if (isset($format['BleedBox'])) {
  1883. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false, $this->k, $this->pagedim);
  1884. }
  1885. // the intended dimensions of the finished page after trimming
  1886. if (isset($format['TrimBox'])) {
  1887. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false, $this->k, $this->pagedim);
  1888. }
  1889. // the page's meaningful content (including potential white space)
  1890. if (isset($format['ArtBox'])) {
  1891. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false, $this->k, $this->pagedim);
  1892. }
  1893. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  1894. if (isset($format['BoxColorInfo'])) {
  1895. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  1896. }
  1897. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  1898. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1899. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  1900. }
  1901. if (isset($format['PZ'])) {
  1902. // The page's preferred zoom (magnification) factor
  1903. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  1904. }
  1905. if (isset($format['trans'])) {
  1906. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  1907. if (isset($format['trans']['Dur'])) {
  1908. // The page's display duration
  1909. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  1910. }
  1911. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  1912. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  1913. // The transition style that shall be used when moving to this page from another during a presentation
  1914. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  1915. $valid_effect = array('Split', 'Blinds');
  1916. $valid_vals = array('H', 'V');
  1917. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  1918. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  1919. }
  1920. $valid_effect = array('Split', 'Box', 'Fly');
  1921. $valid_vals = array('I', 'O');
  1922. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  1923. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  1924. }
  1925. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  1926. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  1927. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  1928. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  1929. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  1930. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  1931. }
  1932. }
  1933. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  1934. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  1935. }
  1936. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  1937. $this->pagedim[$this->page]['trans']['B'] = 'true';
  1938. }
  1939. } else {
  1940. $this->pagedim[$this->page]['trans']['S'] = 'R';
  1941. }
  1942. if (isset($format['trans']['D'])) {
  1943. // The duration of the transition effect, in seconds
  1944. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  1945. } else {
  1946. $this->pagedim[$this->page]['trans']['D'] = 1;
  1947. }
  1948. }
  1949. }
  1950. $this->setPageOrientation($orientation);
  1951. }
  1952. /**
  1953. * Set page orientation.
  1954. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1955. * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
  1956. * @param $bottommargin (float) bottom margin of the page.
  1957. * @public
  1958. * @since 3.0.015 (2008-06-06)
  1959. */
  1960. public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
  1961. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  1962. // the boundaries of the physical medium on which the page shall be displayed or printed
  1963. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1964. }
  1965. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  1966. // the visible region of default user space
  1967. $this->pagedim = TCPDF_STATIC::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, $this->k, $this->pagedim);
  1968. }
  1969. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  1970. // the region to which the contents of the page shall be clipped when output in a production environment
  1971. $this->pagedim = TCPDF_STATIC::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, $this->k, $this->pagedim);
  1972. }
  1973. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  1974. // the intended dimensions of the finished page after trimming
  1975. $this->pagedim = TCPDF_STATIC::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, $this->k, $this->pagedim);
  1976. }
  1977. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  1978. // the page's meaningful content (including potential white space)
  1979. $this->pagedim = TCPDF_STATIC::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, $this->k, $this->pagedim);
  1980. }
  1981. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  1982. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1983. $this->pagedim[$this->page]['Rotate'] = 0;
  1984. }
  1985. if (!isset($this->pagedim[$this->page]['PZ'])) {
  1986. // The page's preferred zoom (magnification) factor
  1987. $this->pagedim[$this->page]['PZ'] = 1;
  1988. }
  1989. if ($this->fwPt > $this->fhPt) {
  1990. // landscape
  1991. $default_orientation = 'L';
  1992. } else {
  1993. // portrait
  1994. $default_orientation = 'P';
  1995. }
  1996. $valid_orientations = array('P', 'L');
  1997. if (empty($orientation)) {
  1998. $orientation = $default_orientation;
  1999. } else {
  2000. $orientation = strtoupper($orientation[0]);
  2001. }
  2002. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  2003. $this->CurOrientation = $orientation;
  2004. $this->wPt = $this->fhPt;
  2005. $this->hPt = $this->fwPt;
  2006. } else {
  2007. $this->CurOrientation = $default_orientation;
  2008. $this->wPt = $this->fwPt;
  2009. $this->hPt = $this->fhPt;
  2010. }
  2011. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2012. // swap X and Y coordinates (change page orientation)
  2013. $this->pagedim = TCPDF_STATIC::swapPageBoxCoordinates($this->page, $this->pagedim);
  2014. }
  2015. $this->w = ($this->wPt / $this->k);
  2016. $this->h = ($this->hPt / $this->k);
  2017. if (TCPDF_STATIC::empty_string($autopagebreak)) {
  2018. if (isset($this->AutoPageBreak)) {
  2019. $autopagebreak = $this->AutoPageBreak;
  2020. } else {
  2021. $autopagebreak = true;
  2022. }
  2023. }
  2024. if (TCPDF_STATIC::empty_string($bottommargin)) {
  2025. if (isset($this->bMargin)) {
  2026. $bottommargin = $this->bMargin;
  2027. } else {
  2028. // default value = 2 cm
  2029. $bottommargin = 2 * 28.35 / $this->k;
  2030. }
  2031. }
  2032. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  2033. // store page dimensions
  2034. $this->pagedim[$this->page]['w'] = $this->wPt;
  2035. $this->pagedim[$this->page]['h'] = $this->hPt;
  2036. $this->pagedim[$this->page]['wk'] = $this->w;
  2037. $this->pagedim[$this->page]['hk'] = $this->h;
  2038. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2039. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2040. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2041. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2042. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2043. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2044. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2045. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2046. }
  2047. /**
  2048. * Set regular expression to detect withespaces or word separators.
  2049. * The pattern delimiter must be the forward-slash character "/".
  2050. * Some example patterns are:
  2051. * <pre>
  2052. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2053. * Unicode and PCRE unicode support: "/(?!\xa0)[\s\p{Z}]/u"
  2054. * Unicode and PCRE unicode support in Chinese mode: "/(?!\xa0)[\s\p{Z}\p{Lo}]/u"
  2055. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2056. * \s : any whitespace character
  2057. * \p{Z} : any separator
  2058. * \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  2059. * \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  2060. * </pre>
  2061. * @param $re (string) regular expression (leave empty for default).
  2062. * @public
  2063. * @since 4.6.016 (2009-06-15)
  2064. */
  2065. public function setSpacesRE($re='/[^\S\xa0]/') {
  2066. $this->re_spaces = $re;
  2067. $re_parts = explode('/', $re);
  2068. // get pattern parts
  2069. $this->re_space = array();
  2070. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2071. $this->re_space['p'] = $re_parts[1];
  2072. } else {
  2073. $this->re_space['p'] = '[\s]';
  2074. }
  2075. // set pattern modifiers
  2076. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2077. $this->re_space['m'] = $re_parts[2];
  2078. } else {
  2079. $this->re_space['m'] = '';
  2080. }
  2081. }
  2082. /**
  2083. * Enable or disable Right-To-Left language mode
  2084. * @param $enable (Boolean) if true enable Right-To-Left language mode.
  2085. * @param $resetx (Boolean) if true reset the X position on direction change.
  2086. * @public
  2087. * @since 2.0.000 (2008-01-03)
  2088. */
  2089. public function setRTL($enable, $resetx=true) {
  2090. $enable = $enable ? true : false;
  2091. $resetx = ($resetx AND ($enable != $this->rtl));
  2092. $this->rtl = $enable;
  2093. $this->tmprtl = false;
  2094. if ($resetx) {
  2095. $this->Ln(0);
  2096. }
  2097. }
  2098. /**
  2099. * Return the RTL status
  2100. * @return boolean
  2101. * @public
  2102. * @since 4.0.012 (2008-07-24)
  2103. */
  2104. public function getRTL() {
  2105. return $this->rtl;
  2106. }
  2107. /**
  2108. * Force temporary RTL language direction
  2109. * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
  2110. * @public
  2111. * @since 2.1.000 (2008-01-09)
  2112. */
  2113. public function setTempRTL($mode) {
  2114. $newmode = false;
  2115. switch (strtoupper($mode)) {
  2116. case 'LTR':
  2117. case 'L': {
  2118. if ($this->rtl) {
  2119. $newmode = 'L';
  2120. }
  2121. break;
  2122. }
  2123. case 'RTL':
  2124. case 'R': {
  2125. if (!$this->rtl) {
  2126. $newmode = 'R';
  2127. }
  2128. break;
  2129. }
  2130. case false:
  2131. default: {
  2132. $newmode = false;
  2133. break;
  2134. }
  2135. }
  2136. $this->tmprtl = $newmode;
  2137. }
  2138. /**
  2139. * Return the current temporary RTL status
  2140. * @return boolean
  2141. * @public
  2142. * @since 4.8.014 (2009-11-04)
  2143. */
  2144. public function isRTLTextDir() {
  2145. return ($this->rtl OR ($this->tmprtl == 'R'));
  2146. }
  2147. /**
  2148. * Set the last cell height.
  2149. * @param $h (float) cell height.
  2150. * @author Nicola Asuni
  2151. * @public
  2152. * @since 1.53.0.TC034
  2153. */
  2154. public function setLastH($h) {
  2155. $this->lasth = $h;
  2156. }
  2157. /**
  2158. * Return the cell height
  2159. * @param $fontsize (int) Font size in internal units
  2160. * @param $padding (boolean) If true add cell padding
  2161. * @public
  2162. */
  2163. public function getCellHeight($fontsize, $padding=TRUE) {
  2164. $height = ($fontsize * $this->cell_height_ratio);
  2165. if ($padding) {
  2166. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  2167. }
  2168. return round($height, 6);
  2169. }
  2170. /**
  2171. * Reset the last cell height.
  2172. * @public
  2173. * @since 5.9.000 (2010-10-03)
  2174. */
  2175. public function resetLastH() {
  2176. $this->lasth = $this->getCellHeight($this->FontSize);
  2177. }
  2178. /**
  2179. * Get the last cell height.
  2180. * @return last cell height
  2181. * @public
  2182. * @since 4.0.017 (2008-08-05)
  2183. */
  2184. public function getLastH() {
  2185. return $this->lasth;
  2186. }
  2187. /**
  2188. * Set the adjusting factor to convert pixels to user units.
  2189. * @param $scale (float) adjusting factor to convert pixels to user units.
  2190. * @author Nicola Asuni
  2191. * @public
  2192. * @since 1.5.2
  2193. */
  2194. public function setImageScale($scale) {
  2195. $this->imgscale = $scale;
  2196. }
  2197. /**
  2198. * Returns the adjusting factor to convert pixels to user units.
  2199. * @return float adjusting factor to convert pixels to user units.
  2200. * @author Nicola Asuni
  2201. * @public
  2202. * @since 1.5.2
  2203. */
  2204. public function getImageScale() {
  2205. return $this->imgscale;
  2206. }
  2207. /**
  2208. * Returns an array of page dimensions:
  2209. * <ul><li>$this->pagedim[$this->page]['w'] = page width in points</li><li>$this->pagedim[$this->page]['h'] = height in points</li><li>$this->pagedim[$this->page]['wk'] = page width in user units</li><li>$this->pagedim[$this->page]['hk'] = page height in user units</li><li>$this->pagedim[$this->page]['tm'] = top margin</li><li>$this->pagedim[$this->page]['bm'] = bottom margin</li><li>$this->pagedim[$this->page]['lm'] = left margin</li><li>$this->pagedim[$this->page]['rm'] = right margin</li><li>$this->pagedim[$this->page]['pb'] = auto page break</li><li>$this->pagedim[$this->page]['or'] = page orientation</li><li>$this->pagedim[$this->page]['olm'] = original left margin</li><li>$this->pagedim[$this->page]['orm'] = original right margin</li><li>$this->pagedim[$this->page]['Rotate'] = The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li><li>$this->pagedim[$this->page]['PZ'] = The page's preferred zoom (magnification) factor.</li><li>$this->pagedim[$this->page]['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation<ul><li>$this->pagedim[$this->page]['trans']['Dur'] = The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li><li>$this->pagedim[$this->page]['trans']['S'] = transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li><li>$this->pagedim[$this->page]['trans']['D'] = The duration of the transition effect, in seconds.</li><li>$this->pagedim[$this->page]['trans']['Dm'] = (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li><li>$this->pagedim[$this->page]['trans']['M'] = (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li><li>$this->pagedim[$this->page]['trans']['Di'] = (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li><li>$this->pagedim[$this->page]['trans']['SS'] = (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0. </li><li>$this->pagedim[$this->page]['trans']['B'] = (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li></ul></li><li>$this->pagedim[$this->page]['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed<ul><li>$this->pagedim[$this->page]['MediaBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['CropBox'] : the visible region of default user space<ul><li>$this->pagedim[$this->page]['CropBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment<ul><li>$this->pagedim[$this->page]['BleedBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['TrimBox'] : the intended dimensions of the finished page after trimming<ul><li>$this->pagedim[$this->page]['TrimBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['ArtBox'] : the extent of the page's meaningful content<ul><li>$this->pagedim[$this->page]['ArtBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['ury'] = upper-right y coordinate in points</li></ul></li></ul>
  2210. * @param $pagenum (int) page number (empty = current page)
  2211. * @return array of page dimensions.
  2212. * @author Nicola Asuni
  2213. * @public
  2214. * @since 4.5.027 (2009-03-16)
  2215. */
  2216. public function getPageDimensions($pagenum='') {
  2217. if (empty($pagenum)) {
  2218. $pagenum = $this->page;
  2219. }
  2220. return $this->pagedim[$pagenum];
  2221. }
  2222. /**
  2223. * Returns the page width in units.
  2224. * @param $pagenum (int) page number (empty = current page)
  2225. * @return int page width.
  2226. * @author Nicola Asuni
  2227. * @public
  2228. * @since 1.5.2
  2229. * @see getPageDimensions()
  2230. */
  2231. public function getPageWidth($pagenum='') {
  2232. if (empty($pagenum)) {
  2233. return $this->w;
  2234. }
  2235. return $this->pagedim[$pagenum]['w'];
  2236. }
  2237. /**
  2238. * Returns the page height in units.
  2239. * @param $pagenum (int) page number (empty = current page)
  2240. * @return int page height.
  2241. * @author Nicola Asuni
  2242. * @public
  2243. * @since 1.5.2
  2244. * @see getPageDimensions()
  2245. */
  2246. public function getPageHeight($pagenum='') {
  2247. if (empty($pagenum)) {
  2248. return $this->h;
  2249. }
  2250. return $this->pagedim[$pagenum]['h'];
  2251. }
  2252. /**
  2253. * Returns the page break margin.
  2254. * @param $pagenum (int) page number (empty = current page)
  2255. * @return int page break margin.
  2256. * @author Nicola Asuni
  2257. * @public
  2258. * @since 1.5.2
  2259. * @see getPageDimensions()
  2260. */
  2261. public function getBreakMargin($pagenum='') {
  2262. if (empty($pagenum)) {
  2263. return $this->bMargin;
  2264. }
  2265. return $this->pagedim[$pagenum]['bm'];
  2266. }
  2267. /**
  2268. * Returns the scale factor (number of points in user unit).
  2269. * @return int scale factor.
  2270. * @author Nicola Asuni
  2271. * @public
  2272. * @since 1.5.2
  2273. */
  2274. public function getScaleFactor() {
  2275. return $this->k;
  2276. }
  2277. /**
  2278. * Defines the left, top and right margins.
  2279. * @param $left (float) Left margin.
  2280. * @param $top (float) Top margin.
  2281. * @param $right (float) Right margin. Default value is the left one.
  2282. * @param $keepmargins (boolean) if true overwrites the default page margins
  2283. * @public
  2284. * @since 1.0
  2285. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2286. */
  2287. public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
  2288. //Set left, top and right margins
  2289. $this->lMargin = $left;
  2290. $this->tMargin = $top;
  2291. if ($right == -1) {
  2292. $right = $left;
  2293. }
  2294. $this->rMargin = $right;
  2295. if ($keepmargins) {
  2296. // overwrite original values
  2297. $this->original_lMargin = $this->lMargin;
  2298. $this->original_rMargin = $this->rMargin;
  2299. }
  2300. }
  2301. /**
  2302. * Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
  2303. * @param $margin (float) The margin.
  2304. * @public
  2305. * @since 1.4
  2306. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2307. */
  2308. public function SetLeftMargin($margin) {
  2309. //Set left margin
  2310. $this->lMargin = $margin;
  2311. if (($this->page > 0) AND ($this->x < $margin)) {
  2312. $this->x = $margin;
  2313. }
  2314. }
  2315. /**
  2316. * Defines the top margin. The method can be called before creating the first page.
  2317. * @param $margin (float) The margin.
  2318. * @public
  2319. * @since 1.5
  2320. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2321. */
  2322. public function SetTopMargin($margin) {
  2323. //Set top margin
  2324. $this->tMargin = $margin;
  2325. if (($this->page > 0) AND ($this->y < $margin)) {
  2326. $this->y = $margin;
  2327. }
  2328. }
  2329. /**
  2330. * Defines the right margin. The method can be called before creating the first page.
  2331. * @param $margin (float) The margin.
  2332. * @public
  2333. * @since 1.5
  2334. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2335. */
  2336. public function SetRightMargin($margin) {
  2337. $this->rMargin = $margin;
  2338. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  2339. $this->x = $this->w - $margin;
  2340. }
  2341. }
  2342. /**
  2343. * Set the same internal Cell padding for top, right, bottom, left-
  2344. * @param $pad (float) internal padding.
  2345. * @public
  2346. * @since 2.1.000 (2008-01-09)
  2347. * @see getCellPaddings(), setCellPaddings()
  2348. */
  2349. public function SetCellPadding($pad) {
  2350. if ($pad >= 0) {
  2351. $this->cell_padding['L'] = $pad;
  2352. $this->cell_padding['T'] = $pad;
  2353. $this->cell_padding['R'] = $pad;
  2354. $this->cell_padding['B'] = $pad;
  2355. }
  2356. }
  2357. /**
  2358. * Set the internal Cell paddings.
  2359. * @param $left (float) left padding
  2360. * @param $top (float) top padding
  2361. * @param $right (float) right padding
  2362. * @param $bottom (float) bottom padding
  2363. * @public
  2364. * @since 5.9.000 (2010-10-03)
  2365. * @see getCellPaddings(), SetCellPadding()
  2366. */
  2367. public function setCellPaddings($left='', $top='', $right='', $bottom='') {
  2368. if (($left !== '') AND ($left >= 0)) {
  2369. $this->cell_padding['L'] = $left;
  2370. }
  2371. if (($top !== '') AND ($top >= 0)) {
  2372. $this->cell_padding['T'] = $top;
  2373. }
  2374. if (($right !== '') AND ($right >= 0)) {
  2375. $this->cell_padding['R'] = $right;
  2376. }
  2377. if (($bottom !== '') AND ($bottom >= 0)) {
  2378. $this->cell_padding['B'] = $bottom;
  2379. }
  2380. }
  2381. /**
  2382. * Get the internal Cell padding array.
  2383. * @return array of padding values
  2384. * @public
  2385. * @since 5.9.000 (2010-10-03)
  2386. * @see setCellPaddings(), SetCellPadding()
  2387. */
  2388. public function getCellPaddings() {
  2389. return $this->cell_padding;
  2390. }
  2391. /**
  2392. * Set the internal Cell margins.
  2393. * @param $left (float) left margin
  2394. * @param $top (float) top margin
  2395. * @param $right (float) right margin
  2396. * @param $bottom (float) bottom margin
  2397. * @public
  2398. * @since 5.9.000 (2010-10-03)
  2399. * @see getCellMargins()
  2400. */
  2401. public function setCellMargins($left='', $top='', $right='', $bottom='') {
  2402. if (($left !== '') AND ($left >= 0)) {
  2403. $this->cell_margin['L'] = $left;
  2404. }
  2405. if (($top !== '') AND ($top >= 0)) {
  2406. $this->cell_margin['T'] = $top;
  2407. }
  2408. if (($right !== '') AND ($right >= 0)) {
  2409. $this->cell_margin['R'] = $right;
  2410. }
  2411. if (($bottom !== '') AND ($bottom >= 0)) {
  2412. $this->cell_margin['B'] = $bottom;
  2413. }
  2414. }
  2415. /**
  2416. * Get the internal Cell margin array.
  2417. * @return array of margin values
  2418. * @public
  2419. * @since 5.9.000 (2010-10-03)
  2420. * @see setCellMargins()
  2421. */
  2422. public function getCellMargins() {
  2423. return $this->cell_margin;
  2424. }
  2425. /**
  2426. * Adjust the internal Cell padding array to take account of the line width.
  2427. * @param $brd (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  2428. * @return array of adjustments
  2429. * @public
  2430. * @since 5.9.000 (2010-10-03)
  2431. */
  2432. protected function adjustCellPadding($brd=0) {
  2433. if (empty($brd)) {
  2434. return;
  2435. }
  2436. if (is_string($brd)) {
  2437. // convert string to array
  2438. $slen = strlen($brd);
  2439. $newbrd = array();
  2440. for ($i = 0; $i < $slen; ++$i) {
  2441. $newbrd[$brd[$i]] = true;
  2442. }
  2443. $brd = $newbrd;
  2444. } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
  2445. $brd = array('LRTB' => true);
  2446. }
  2447. if (!is_array($brd)) {
  2448. return;
  2449. }
  2450. // store current cell padding
  2451. $cp = $this->cell_padding;
  2452. // select border mode
  2453. if (isset($brd['mode'])) {
  2454. $mode = $brd['mode'];
  2455. unset($brd['mode']);
  2456. } else {
  2457. $mode = 'normal';
  2458. }
  2459. // process borders
  2460. foreach ($brd as $border => $style) {
  2461. $line_width = $this->LineWidth;
  2462. if (is_array($style) AND isset($style['width'])) {
  2463. // get border width
  2464. $line_width = $style['width'];
  2465. }
  2466. $adj = 0; // line width inside the cell
  2467. switch ($mode) {
  2468. case 'ext': {
  2469. $adj = 0;
  2470. break;
  2471. }
  2472. case 'int': {
  2473. $adj = $line_width;
  2474. break;
  2475. }
  2476. case 'normal':
  2477. default: {
  2478. $adj = ($line_width / 2);
  2479. break;
  2480. }
  2481. }
  2482. // correct internal cell padding if required to avoid overlap between text and lines
  2483. if ((strpos($border,'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
  2484. $this->cell_padding['T'] = $adj;
  2485. }
  2486. if ((strpos($border,'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
  2487. $this->cell_padding['R'] = $adj;
  2488. }
  2489. if ((strpos($border,'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
  2490. $this->cell_padding['B'] = $adj;
  2491. }
  2492. if ((strpos($border,'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
  2493. $this->cell_padding['L'] = $adj;
  2494. }
  2495. }
  2496. 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']));
  2497. }
  2498. /**
  2499. * Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
  2500. * @param $auto (boolean) Boolean indicating if mode should be on or off.
  2501. * @param $margin (float) Distance from the bottom of the page.
  2502. * @public
  2503. * @since 1.0
  2504. * @see Cell(), MultiCell(), AcceptPageBreak()
  2505. */
  2506. public function SetAutoPageBreak($auto, $margin=0) {
  2507. $this->AutoPageBreak = $auto ? true : false;
  2508. $this->bMargin = $margin;
  2509. $this->PageBreakTrigger = $this->h - $margin;
  2510. }
  2511. /**
  2512. * Return the auto-page-break mode (true or false).
  2513. * @return boolean auto-page-break mode
  2514. * @public
  2515. * @since 5.9.088
  2516. */
  2517. public function getAutoPageBreak() {
  2518. return $this->AutoPageBreak;
  2519. }
  2520. /**
  2521. * Defines the way the document is to be displayed by the viewer.
  2522. * @param $zoom (mixed) The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
  2523. * @param $layout (string) The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  2524. * @param $mode (string) A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  2525. * @public
  2526. * @since 1.2
  2527. */
  2528. public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  2529. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  2530. $this->ZoomMode = $zoom;
  2531. } else {
  2532. $this->Error('Incorrect zoom display mode: '.$zoom);
  2533. }
  2534. $this->LayoutMode = TCPDF_STATIC::getPageLayoutMode($layout);
  2535. $this->PageMode = TCPDF_STATIC::getPageMode($mode);
  2536. }
  2537. /**
  2538. * Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
  2539. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2540. * @param $compress (boolean) Boolean indicating if compression must be enabled.
  2541. * @public
  2542. * @since 1.4
  2543. */
  2544. public function SetCompression($compress=true) {
  2545. if (function_exists('gzcompress')) {
  2546. $this->compress = $compress ? true : false;
  2547. } else {
  2548. $this->compress = false;
  2549. }
  2550. }
  2551. /**
  2552. * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  2553. * @param $mode (boolean) If true force sRGB output intent.
  2554. * @public
  2555. * @since 5.9.121 (2011-09-28)
  2556. */
  2557. public function setSRGBmode($mode=false) {
  2558. $this->force_srgb = $mode ? true : false;
  2559. }
  2560. /**
  2561. * Turn on/off Unicode mode for document information dictionary (meta tags).
  2562. * This has effect only when unicode mode is set to false.
  2563. * @param $unicode (boolean) if true set the meta information in Unicode
  2564. * @since 5.9.027 (2010-12-01)
  2565. * @public
  2566. */
  2567. public function SetDocInfoUnicode($unicode=true) {
  2568. $this->docinfounicode = $unicode ? true : false;
  2569. }
  2570. /**
  2571. * Defines the title of the document.
  2572. * @param $title (string) The title.
  2573. * @public
  2574. * @since 1.2
  2575. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2576. */
  2577. public function SetTitle($title) {
  2578. $this->title = $title;
  2579. }
  2580. /**
  2581. * Defines the subject of the document.
  2582. * @param $subject (string) The subject.
  2583. * @public
  2584. * @since 1.2
  2585. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2586. */
  2587. public function SetSubject($subject) {
  2588. $this->subject = $subject;
  2589. }
  2590. /**
  2591. * Defines the author of the document.
  2592. * @param $author (string) The name of the author.
  2593. * @public
  2594. * @since 1.2
  2595. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2596. */
  2597. public function SetAuthor($author) {
  2598. $this->author = $author;
  2599. }
  2600. /**
  2601. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2602. * @param $keywords (string) The list of keywords.
  2603. * @public
  2604. * @since 1.2
  2605. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2606. */
  2607. public function SetKeywords($keywords) {
  2608. $this->keywords = $keywords;
  2609. }
  2610. /**
  2611. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2612. * @param $creator (string) The name of the creator.
  2613. * @public
  2614. * @since 1.2
  2615. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2616. */
  2617. public function SetCreator($creator) {
  2618. $this->creator = $creator;
  2619. }
  2620. /**
  2621. * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
  2622. * @param $msg (string) The error message
  2623. * @public
  2624. * @since 1.0
  2625. */
  2626. public function Error($msg) {
  2627. // unset all class variables
  2628. $this->_destroy(true);
  2629. if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
  2630. die('<strong>TCPDF ERROR: </strong>'.$msg);
  2631. } else {
  2632. throw new Exception('TCPDF ERROR: '.$msg);
  2633. }
  2634. }
  2635. /**
  2636. * This method begins the generation of the PDF document.
  2637. * It is not necessary to call it explicitly because AddPage() does it automatically.
  2638. * Note: no page is created by this method
  2639. * @public
  2640. * @since 1.0
  2641. * @see AddPage(), Close()
  2642. */
  2643. public function Open() {
  2644. $this->state = 1;
  2645. }
  2646. /**
  2647. * Terminates the PDF document.
  2648. * It is not necessary to call this method explicitly because Output() does it automatically.
  2649. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2650. * @public
  2651. * @since 1.0
  2652. * @see Open(), Output()
  2653. */
  2654. public function Close() {
  2655. if ($this->state == 3) {
  2656. return;
  2657. }
  2658. if ($this->page == 0) {
  2659. $this->AddPage();
  2660. }
  2661. $this->endLayer();
  2662. if ($this->tcpdflink) {
  2663. // save current graphic settings
  2664. $gvars = $this->getGraphicVars();
  2665. $this->setEqualColumns();
  2666. $this->lastpage(true);
  2667. $this->SetAutoPageBreak(false);
  2668. $this->x = 0;
  2669. $this->y = $this->h - (1 / $this->k);
  2670. $this->lMargin = 0;
  2671. $this->_outSaveGraphicsState();
  2672. $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  2673. $this->SetFont($font, '', 1);
  2674. $this->setTextRenderingMode(0, false, false);
  2675. $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";
  2676. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  2677. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  2678. $this->_outRestoreGraphicsState();
  2679. // restore graphic settings
  2680. $this->setGraphicVars($gvars);
  2681. }
  2682. // close page
  2683. $this->endPage();
  2684. // close document
  2685. $this->_enddoc();
  2686. // unset all class variables (except critical ones)
  2687. $this->_destroy(false);
  2688. }
  2689. /**
  2690. * Move pointer at the specified document page and update page dimensions.
  2691. * @param $pnum (int) page number (1 ... numpages)
  2692. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  2693. * @public
  2694. * @since 2.1.000 (2008-01-07)
  2695. * @see getPage(), lastpage(), getNumPages()
  2696. */
  2697. public function setPage($pnum, $resetmargins=false) {
  2698. if (($pnum == $this->page) AND ($this->state == 2)) {
  2699. return;
  2700. }
  2701. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  2702. $this->state = 2;
  2703. // save current graphic settings
  2704. //$gvars = $this->getGraphicVars();
  2705. $oldpage = $this->page;
  2706. $this->page = $pnum;
  2707. $this->wPt = $this->pagedim[$this->page]['w'];
  2708. $this->hPt = $this->pagedim[$this->page]['h'];
  2709. $this->w = $this->pagedim[$this->page]['wk'];
  2710. $this->h = $this->pagedim[$this->page]['hk'];
  2711. $this->tMargin = $this->pagedim[$this->page]['tm'];
  2712. $this->bMargin = $this->pagedim[$this->page]['bm'];
  2713. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2714. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2715. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2716. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2717. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  2718. // restore graphic settings
  2719. //$this->setGraphicVars($gvars);
  2720. if ($resetmargins) {
  2721. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2722. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2723. $this->SetY($this->tMargin);
  2724. } else {
  2725. // account for booklet mode
  2726. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  2727. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2728. $this->lMargin += $deltam;
  2729. $this->rMargin -= $deltam;
  2730. }
  2731. }
  2732. } else {
  2733. $this->Error('Wrong page number on setPage() function: '.$pnum);
  2734. }
  2735. }
  2736. /**
  2737. * Reset pointer to the last document page.
  2738. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  2739. * @public
  2740. * @since 2.0.000 (2008-01-04)
  2741. * @see setPage(), getPage(), getNumPages()
  2742. */
  2743. public function lastPage($resetmargins=false) {
  2744. $this->setPage($this->getNumPages(), $resetmargins);
  2745. }
  2746. /**
  2747. * Get current document page number.
  2748. * @return int page number
  2749. * @public
  2750. * @since 2.1.000 (2008-01-07)
  2751. * @see setPage(), lastpage(), getNumPages()
  2752. */
  2753. public function getPage() {
  2754. return $this->page;
  2755. }
  2756. /**
  2757. * Get the total number of insered pages.
  2758. * @return int number of pages
  2759. * @public
  2760. * @since 2.1.000 (2008-01-07)
  2761. * @see setPage(), getPage(), lastpage()
  2762. */
  2763. public function getNumPages() {
  2764. return $this->numpages;
  2765. }
  2766. /**
  2767. * Adds a new TOC (Table Of Content) page to the document.
  2768. * @param $orientation (string) page orientation.
  2769. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2770. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  2771. * @public
  2772. * @since 5.0.001 (2010-05-06)
  2773. * @see AddPage(), startPage(), endPage(), endTOCPage()
  2774. */
  2775. public function addTOCPage($orientation='', $format='', $keepmargins=false) {
  2776. $this->AddPage($orientation, $format, $keepmargins, true);
  2777. }
  2778. /**
  2779. * Terminate the current TOC (Table Of Content) page
  2780. * @public
  2781. * @since 5.0.001 (2010-05-06)
  2782. * @see AddPage(), startPage(), endPage(), addTOCPage()
  2783. */
  2784. public function endTOCPage() {
  2785. $this->endPage(true);
  2786. }
  2787. /**
  2788. * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer (if enabled). Then the page is added, the current position set to the top-left corner according to the left and top margins (or top-right if in RTL mode), and Header() is called to display the header (if enabled).
  2789. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2790. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2791. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2792. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  2793. * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
  2794. * @public
  2795. * @since 1.0
  2796. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2797. */
  2798. public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
  2799. if ($this->inxobj) {
  2800. // we are inside an XObject template
  2801. return;
  2802. }
  2803. if (!isset($this->original_lMargin) OR $keepmargins) {
  2804. $this->original_lMargin = $this->lMargin;
  2805. }
  2806. if (!isset($this->original_rMargin) OR $keepmargins) {
  2807. $this->original_rMargin = $this->rMargin;
  2808. }
  2809. // terminate previous page
  2810. $this->endPage();
  2811. // start new page
  2812. $this->startPage($orientation, $format, $tocpage);
  2813. }
  2814. /**
  2815. * Terminate the current page
  2816. * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
  2817. * @public
  2818. * @since 4.2.010 (2008-11-14)
  2819. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  2820. */
  2821. public function endPage($tocpage=false) {
  2822. // check if page is already closed
  2823. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  2824. return;
  2825. }
  2826. // print page footer
  2827. $this->setFooter();
  2828. // close page
  2829. $this->_endpage();
  2830. // mark page as closed
  2831. $this->pageopen[$this->page] = false;
  2832. if ($tocpage) {
  2833. $this->tocpage = false;
  2834. }
  2835. }
  2836. /**
  2837. * Starts a new page to the document. The page must be closed using the endPage() function.
  2838. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2839. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2840. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2841. * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
  2842. * @since 4.2.010 (2008-11-14)
  2843. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2844. * @public
  2845. */
  2846. public function startPage($orientation='', $format='', $tocpage=false) {
  2847. if ($tocpage) {
  2848. $this->tocpage = true;
  2849. }
  2850. // move page numbers of documents to be attached
  2851. if ($this->tocpage) {
  2852. // move reference to unexistent pages (used for page attachments)
  2853. // adjust outlines
  2854. $tmpoutlines = $this->outlines;
  2855. foreach ($tmpoutlines as $key => $outline) {
  2856. if (!$outline['f'] AND ($outline['p'] > $this->numpages)) {
  2857. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  2858. }
  2859. }
  2860. // adjust dests
  2861. $tmpdests = $this->dests;
  2862. foreach ($tmpdests as $key => $dest) {
  2863. if (!$dest['f'] AND ($dest['p'] > $this->numpages)) {
  2864. $this->dests[$key]['p'] = ($dest['p'] + 1);
  2865. }
  2866. }
  2867. // adjust links
  2868. $tmplinks = $this->links;
  2869. foreach ($tmplinks as $key => $link) {
  2870. if (!$link['f'] AND ($link['p'] > $this->numpages)) {
  2871. $this->links[$key]['p'] = ($link['p'] + 1);
  2872. }
  2873. }
  2874. }
  2875. if ($this->numpages > $this->page) {
  2876. // this page has been already added
  2877. $this->setPage($this->page + 1);
  2878. $this->SetY($this->tMargin);
  2879. return;
  2880. }
  2881. // start a new page
  2882. if ($this->state == 0) {
  2883. $this->Open();
  2884. }
  2885. ++$this->numpages;
  2886. $this->swapMargins($this->booklet);
  2887. // save current graphic settings
  2888. $gvars = $this->getGraphicVars();
  2889. // start new page
  2890. $this->_beginpage($orientation, $format);
  2891. // mark page as open
  2892. $this->pageopen[$this->page] = true;
  2893. // restore graphic settings
  2894. $this->setGraphicVars($gvars);
  2895. // mark this point
  2896. $this->setPageMark();
  2897. // print page header
  2898. $this->setHeader();
  2899. // restore graphic settings
  2900. $this->setGraphicVars($gvars);
  2901. // mark this point
  2902. $this->setPageMark();
  2903. // print table header (if any)
  2904. $this->setTableHeader();
  2905. // set mark for empty page check
  2906. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  2907. }
  2908. /**
  2909. * Set start-writing mark on current page stream used to put borders and fills.
  2910. * Borders and fills are always created after content and inserted on the position marked by this method.
  2911. * This function must be called after calling Image() function for a background image.
  2912. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2913. * @public
  2914. * @since 4.0.016 (2008-07-30)
  2915. */
  2916. public function setPageMark() {
  2917. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2918. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  2919. $this->setContentMark();
  2920. }
  2921. /**
  2922. * Set start-writing mark on selected page.
  2923. * Borders and fills are always created after content and inserted on the position marked by this method.
  2924. * @param $page (int) page number (default is the current page)
  2925. * @protected
  2926. * @since 4.6.021 (2009-07-20)
  2927. */
  2928. protected function setContentMark($page=0) {
  2929. if ($page <= 0) {
  2930. $page = $this->page;
  2931. }
  2932. if (isset($this->footerlen[$page])) {
  2933. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  2934. } else {
  2935. $this->cntmrk[$page] = $this->pagelen[$page];
  2936. }
  2937. }
  2938. /**
  2939. * Set header data.
  2940. * @param $ln (string) header image logo
  2941. * @param $lw (string) header image logo width in mm
  2942. * @param $ht (string) string to print as title on document header
  2943. * @param $hs (string) string to print on document header
  2944. * @param $tc (array) RGB array color for text.
  2945. * @param $lc (array) RGB array color for line.
  2946. * @public
  2947. */
  2948. public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
  2949. $this->header_logo = $ln;
  2950. $this->header_logo_width = $lw;
  2951. $this->header_title = $ht;
  2952. $this->header_string = $hs;
  2953. $this->header_text_color = $tc;
  2954. $this->header_line_color = $lc;
  2955. }
  2956. /**
  2957. * Set footer data.
  2958. * @param $tc (array) RGB array color for text.
  2959. * @param $lc (array) RGB array color for line.
  2960. * @public
  2961. */
  2962. public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
  2963. $this->footer_text_color = $tc;
  2964. $this->footer_line_color = $lc;
  2965. }
  2966. /**
  2967. * Returns header data:
  2968. * <ul><li>$ret['logo'] = logo image</li><li>$ret['logo_width'] = width of the image logo in user units</li><li>$ret['title'] = header title</li><li>$ret['string'] = header description string</li></ul>
  2969. * @return array()
  2970. * @public
  2971. * @since 4.0.012 (2008-07-24)
  2972. */
  2973. public function getHeaderData() {
  2974. $ret = array();
  2975. $ret['logo'] = $this->header_logo;
  2976. $ret['logo_width'] = $this->header_logo_width;
  2977. $ret['title'] = $this->header_title;
  2978. $ret['string'] = $this->header_string;
  2979. $ret['text_color'] = $this->header_text_color;
  2980. $ret['line_color'] = $this->header_line_color;
  2981. return $ret;
  2982. }
  2983. /**
  2984. * Set header margin.
  2985. * (minimum distance between header and top page margin)
  2986. * @param $hm (int) distance in user units
  2987. * @public
  2988. */
  2989. public function setHeaderMargin($hm=10) {
  2990. $this->header_margin = $hm;
  2991. }
  2992. /**
  2993. * Returns header margin in user units.
  2994. * @return float
  2995. * @since 4.0.012 (2008-07-24)
  2996. * @public
  2997. */
  2998. public function getHeaderMargin() {
  2999. return $this->header_margin;
  3000. }
  3001. /**
  3002. * Set footer margin.
  3003. * (minimum distance between footer and bottom page margin)
  3004. * @param $fm (int) distance in user units
  3005. * @public
  3006. */
  3007. public function setFooterMargin($fm=10) {
  3008. $this->footer_margin = $fm;
  3009. }
  3010. /**
  3011. * Returns footer margin in user units.
  3012. * @return float
  3013. * @since 4.0.012 (2008-07-24)
  3014. * @public
  3015. */
  3016. public function getFooterMargin() {
  3017. return $this->footer_margin;
  3018. }
  3019. /**
  3020. * Set a flag to print page header.
  3021. * @param $val (boolean) set to true to print the page header (default), false otherwise.
  3022. * @public
  3023. */
  3024. public function setPrintHeader($val=true) {
  3025. $this->print_header = $val ? true : false;
  3026. }
  3027. /**
  3028. * Set a flag to print page footer.
  3029. * @param $val (boolean) set to true to print the page footer (default), false otherwise.
  3030. * @public
  3031. */
  3032. public function setPrintFooter($val=true) {
  3033. $this->print_footer = $val ? true : false;
  3034. }
  3035. /**
  3036. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3037. * @return float
  3038. * @public
  3039. */
  3040. public function getImageRBX() {
  3041. return $this->img_rb_x;
  3042. }
  3043. /**
  3044. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3045. * @return float
  3046. * @public
  3047. */
  3048. public function getImageRBY() {
  3049. return $this->img_rb_y;
  3050. }
  3051. /**
  3052. * Reset the xobject template used by Header() method.
  3053. * @public
  3054. */
  3055. public function resetHeaderTemplate() {
  3056. $this->header_xobjid = false;
  3057. }
  3058. /**
  3059. * Set a flag to automatically reset the xobject template used by Header() method at each page.
  3060. * @param $val (boolean) set to true to reset Header xobject template at each page, false otherwise.
  3061. * @public
  3062. */
  3063. public function setHeaderTemplateAutoreset($val=true) {
  3064. $this->header_xobj_autoreset = $val ? true : false;
  3065. }
  3066. /**
  3067. * This method is used to render the page header.
  3068. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3069. * @public
  3070. */
  3071. public function Header() {
  3072. if ($this->header_xobjid === false) {
  3073. // start a new XObject Template
  3074. $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
  3075. $headerfont = $this->getHeaderFont();
  3076. $headerdata = $this->getHeaderData();
  3077. $this->y = $this->header_margin;
  3078. if ($this->rtl) {
  3079. $this->x = $this->w - $this->original_rMargin;
  3080. } else {
  3081. $this->x = $this->original_lMargin;
  3082. }
  3083. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3084. $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3085. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3086. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3087. } elseif ($imgtype == 'svg') {
  3088. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3089. } else {
  3090. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3091. }
  3092. $imgy = $this->getImageRBY();
  3093. } else {
  3094. $imgy = $this->y;
  3095. }
  3096. $cell_height = $this->getCellHeight($headerfont[2] / $this->k);
  3097. // set starting margin for text data cell
  3098. if ($this->getRTL()) {
  3099. $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  3100. } else {
  3101. $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  3102. }
  3103. $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  3104. $this->SetTextColorArray($this->header_text_color);
  3105. // header title
  3106. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  3107. $this->SetX($header_x);
  3108. $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  3109. // header string
  3110. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3111. $this->SetX($header_x);
  3112. $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
  3113. // print an ending header line
  3114. $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
  3115. $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
  3116. if ($this->rtl) {
  3117. $this->SetX($this->original_rMargin);
  3118. } else {
  3119. $this->SetX($this->original_lMargin);
  3120. }
  3121. $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
  3122. $this->endTemplate();
  3123. }
  3124. // print header template
  3125. $x = 0;
  3126. $dx = 0;
  3127. if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
  3128. // adjust margins for booklet mode
  3129. $dx = ($this->original_lMargin - $this->original_rMargin);
  3130. }
  3131. if ($this->rtl) {
  3132. $x = $this->w + $dx;
  3133. } else {
  3134. $x = 0 + $dx;
  3135. }
  3136. $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
  3137. if ($this->header_xobj_autoreset) {
  3138. // reset header xobject template at each page
  3139. $this->header_xobjid = false;
  3140. }
  3141. }
  3142. /**
  3143. * This method is used to render the page footer.
  3144. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3145. * @public
  3146. */
  3147. public function Footer() {
  3148. $cur_y = $this->y;
  3149. $this->SetTextColorArray($this->footer_text_color);
  3150. //set style for cell border
  3151. $line_width = (0.85 / $this->k);
  3152. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
  3153. //print document barcode
  3154. $barcode = $this->getBarcode();
  3155. if (!empty($barcode)) {
  3156. $this->Ln($line_width);
  3157. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
  3158. $style = array(
  3159. 'position' => $this->rtl?'R':'L',
  3160. 'align' => $this->rtl?'R':'L',
  3161. 'stretch' => false,
  3162. 'fitwidth' => true,
  3163. 'cellfitalign' => '',
  3164. 'border' => false,
  3165. 'padding' => 0,
  3166. 'fgcolor' => array(0,0,0),
  3167. 'bgcolor' => false,
  3168. 'text' => false
  3169. );
  3170. $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
  3171. }
  3172. $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
  3173. if (empty($this->pagegroups)) {
  3174. $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3175. } else {
  3176. $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3177. }
  3178. $this->SetY($cur_y);
  3179. //Print page number
  3180. if ($this->getRTL()) {
  3181. $this->SetX($this->original_rMargin);
  3182. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  3183. } else {
  3184. $this->SetX($this->original_lMargin);
  3185. $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
  3186. }
  3187. }
  3188. /**
  3189. * This method is used to render the page header.
  3190. * @protected
  3191. * @since 4.0.012 (2008-07-24)
  3192. */
  3193. protected function setHeader() {
  3194. if (!$this->print_header OR ($this->state != 2)) {
  3195. return;
  3196. }
  3197. $this->InHeader = true;
  3198. $this->setGraphicVars($this->default_graphic_vars);
  3199. $temp_thead = $this->thead;
  3200. $temp_theadMargins = $this->theadMargins;
  3201. $lasth = $this->lasth;
  3202. $newline = $this->newline;
  3203. $this->_outSaveGraphicsState();
  3204. $this->rMargin = $this->original_rMargin;
  3205. $this->lMargin = $this->original_lMargin;
  3206. $this->SetCellPadding(0);
  3207. //set current position
  3208. if ($this->rtl) {
  3209. $this->SetXY($this->original_rMargin, $this->header_margin);
  3210. } else {
  3211. $this->SetXY($this->original_lMargin, $this->header_margin);
  3212. }
  3213. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3214. $this->Header();
  3215. //restore position
  3216. if ($this->rtl) {
  3217. $this->SetXY($this->original_rMargin, $this->tMargin);
  3218. } else {
  3219. $this->SetXY($this->original_lMargin, $this->tMargin);
  3220. }
  3221. $this->_outRestoreGraphicsState();
  3222. $this->lasth = $lasth;
  3223. $this->thead = $temp_thead;
  3224. $this->theadMargins = $temp_theadMargins;
  3225. $this->newline = $newline;
  3226. $this->InHeader = false;
  3227. }
  3228. /**
  3229. * This method is used to render the page footer.
  3230. * @protected
  3231. * @since 4.0.012 (2008-07-24)
  3232. */
  3233. protected function setFooter() {
  3234. if ($this->state != 2) {
  3235. return;
  3236. }
  3237. $this->InFooter = true;
  3238. // save current graphic settings
  3239. $gvars = $this->getGraphicVars();
  3240. // mark this point
  3241. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3242. $this->_out("\n");
  3243. if ($this->print_footer) {
  3244. $this->setGraphicVars($this->default_graphic_vars);
  3245. $this->current_column = 0;
  3246. $this->num_columns = 1;
  3247. $temp_thead = $this->thead;
  3248. $temp_theadMargins = $this->theadMargins;
  3249. $lasth = $this->lasth;
  3250. $this->_outSaveGraphicsState();
  3251. $this->rMargin = $this->original_rMargin;
  3252. $this->lMargin = $this->original_lMargin;
  3253. $this->SetCellPadding(0);
  3254. //set current position
  3255. $footer_y = $this->h - $this->footer_margin;
  3256. if ($this->rtl) {
  3257. $this->SetXY($this->original_rMargin, $footer_y);
  3258. } else {
  3259. $this->SetXY($this->original_lMargin, $footer_y);
  3260. }
  3261. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3262. $this->Footer();
  3263. //restore position
  3264. if ($this->rtl) {
  3265. $this->SetXY($this->original_rMargin, $this->tMargin);
  3266. } else {
  3267. $this->SetXY($this->original_lMargin, $this->tMargin);
  3268. }
  3269. $this->_outRestoreGraphicsState();
  3270. $this->lasth = $lasth;
  3271. $this->thead = $temp_thead;
  3272. $this->theadMargins = $temp_theadMargins;
  3273. }
  3274. // restore graphic settings
  3275. $this->setGraphicVars($gvars);
  3276. $this->current_column = $gvars['current_column'];
  3277. $this->num_columns = $gvars['num_columns'];
  3278. // calculate footer length
  3279. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3280. $this->InFooter = false;
  3281. }
  3282. /**
  3283. * Check if we are on the page body (excluding page header and footer).
  3284. * @return true if we are not in page header nor in page footer, false otherwise.
  3285. * @protected
  3286. * @since 5.9.091 (2011-06-15)
  3287. */
  3288. protected function inPageBody() {
  3289. return (($this->InHeader === false) AND ($this->InFooter === false));
  3290. }
  3291. /**
  3292. * This method is used to render the table header on new page (if any).
  3293. * @protected
  3294. * @since 4.5.030 (2009-03-25)
  3295. */
  3296. protected function setTableHeader() {
  3297. if ($this->num_columns > 1) {
  3298. // multi column mode
  3299. return;
  3300. }
  3301. if (isset($this->theadMargins['top'])) {
  3302. // restore the original top-margin
  3303. $this->tMargin = $this->theadMargins['top'];
  3304. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3305. $this->y = $this->tMargin;
  3306. }
  3307. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  3308. // set margins
  3309. $prev_lMargin = $this->lMargin;
  3310. $prev_rMargin = $this->rMargin;
  3311. $prev_cell_padding = $this->cell_padding;
  3312. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3313. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3314. $this->cell_padding = $this->theadMargins['cell_padding'];
  3315. if ($this->rtl) {
  3316. $this->x = $this->w - $this->rMargin;
  3317. } else {
  3318. $this->x = $this->lMargin;
  3319. }
  3320. // account for special "cell" mode
  3321. if ($this->theadMargins['cell']) {
  3322. if ($this->rtl) {
  3323. $this->x -= $this->cell_padding['R'];
  3324. } else {
  3325. $this->x += $this->cell_padding['L'];
  3326. }
  3327. }
  3328. $gvars = $this->getGraphicVars();
  3329. if (!empty($this->theadMargins['gvars'])) {
  3330. // set the correct graphic style
  3331. $this->setGraphicVars($this->theadMargins['gvars']);
  3332. $this->rMargin = $gvars['rMargin'];
  3333. $this->lMargin = $gvars['lMargin'];
  3334. }
  3335. // print table header
  3336. $this->writeHTML($this->thead, false, false, false, false, '');
  3337. $this->setGraphicVars($gvars);
  3338. // set new top margin to skip the table headers
  3339. if (!isset($this->theadMargins['top'])) {
  3340. $this->theadMargins['top'] = $this->tMargin;
  3341. }
  3342. // store end of header position
  3343. if (!isset($this->columns[0]['th'])) {
  3344. $this->columns[0]['th'] = array();
  3345. }
  3346. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3347. $this->tMargin = $this->y;
  3348. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3349. $this->lasth = 0;
  3350. $this->lMargin = $prev_lMargin;
  3351. $this->rMargin = $prev_rMargin;
  3352. $this->cell_padding = $prev_cell_padding;
  3353. }
  3354. }
  3355. /**
  3356. * Returns the current page number.
  3357. * @return int page number
  3358. * @public
  3359. * @since 1.0
  3360. * @see getAliasNbPages()
  3361. */
  3362. public function PageNo() {
  3363. return $this->page;
  3364. }
  3365. /**
  3366. * Returns the array of spot colors.
  3367. * @return (array) Spot colors array.
  3368. * @public
  3369. * @since 6.0.038 (2013-09-30)
  3370. */
  3371. public function getAllSpotColors() {
  3372. return $this->spot_colors;
  3373. }
  3374. /**
  3375. * Defines a new spot color.
  3376. * It can be expressed in RGB components or gray scale.
  3377. * The method can be called before the first page is created and the value is retained from page to page.
  3378. * @param $name (string) Full name of the spot color.
  3379. * @param $c (float) Cyan color for CMYK. Value between 0 and 100.
  3380. * @param $m (float) Magenta color for CMYK. Value between 0 and 100.
  3381. * @param $y (float) Yellow color for CMYK. Value between 0 and 100.
  3382. * @param $k (float) Key (Black) color for CMYK. Value between 0 and 100.
  3383. * @public
  3384. * @since 4.0.024 (2008-09-12)
  3385. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3386. */
  3387. public function AddSpotColor($name, $c, $m, $y, $k) {
  3388. if (!isset($this->spot_colors[$name])) {
  3389. $i = (1 + count($this->spot_colors));
  3390. $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
  3391. }
  3392. }
  3393. /**
  3394. * Set the spot color for the specified type ('draw', 'fill', 'text').
  3395. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3396. * @param $name (string) Name of the spot color.
  3397. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3398. * @return (string) PDF color command.
  3399. * @public
  3400. * @since 5.9.125 (2011-10-03)
  3401. */
  3402. public function setSpotColor($type, $name, $tint=100) {
  3403. $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
  3404. if ($spotcolor === false) {
  3405. $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
  3406. }
  3407. $tint = (max(0, min(100, $tint)) / 100);
  3408. $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
  3409. switch ($type) {
  3410. case 'draw': {
  3411. $pdfcolor .= sprintf('CS %F SCN', $tint);
  3412. $this->DrawColor = $pdfcolor;
  3413. $this->strokecolor = $spotcolor;
  3414. break;
  3415. }
  3416. case 'fill': {
  3417. $pdfcolor .= sprintf('cs %F scn', $tint);
  3418. $this->FillColor = $pdfcolor;
  3419. $this->bgcolor = $spotcolor;
  3420. break;
  3421. }
  3422. case 'text': {
  3423. $pdfcolor .= sprintf('cs %F scn', $tint);
  3424. $this->TextColor = $pdfcolor;
  3425. $this->fgcolor = $spotcolor;
  3426. break;
  3427. }
  3428. }
  3429. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3430. if ($this->state == 2) {
  3431. $this->_out($pdfcolor);
  3432. }
  3433. if ($this->inxobj) {
  3434. // we are inside an XObject template
  3435. $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  3436. }
  3437. return $pdfcolor;
  3438. }
  3439. /**
  3440. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  3441. * @param $name (string) Name of the spot color.
  3442. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3443. * @public
  3444. * @since 4.0.024 (2008-09-12)
  3445. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3446. */
  3447. public function SetDrawSpotColor($name, $tint=100) {
  3448. $this->setSpotColor('draw', $name, $tint);
  3449. }
  3450. /**
  3451. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  3452. * @param $name (string) Name of the spot color.
  3453. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3454. * @public
  3455. * @since 4.0.024 (2008-09-12)
  3456. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  3457. */
  3458. public function SetFillSpotColor($name, $tint=100) {
  3459. $this->setSpotColor('fill', $name, $tint);
  3460. }
  3461. /**
  3462. * Defines the spot color used for text.
  3463. * @param $name (string) Name of the spot color.
  3464. * @param $tint (int) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3465. * @public
  3466. * @since 4.0.024 (2008-09-12)
  3467. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3468. */
  3469. public function SetTextSpotColor($name, $tint=100) {
  3470. $this->setSpotColor('text', $name, $tint);
  3471. }
  3472. /**
  3473. * Set the color array for the specified type ('draw', 'fill', 'text').
  3474. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3475. * The method can be called before the first page is created and the value is retained from page to page.
  3476. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3477. * @param $color (array) Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  3478. * @param $ret (boolean) If true do not send the PDF command.
  3479. * @return (string) The PDF command or empty string.
  3480. * @public
  3481. * @since 3.1.000 (2008-06-11)
  3482. */
  3483. public function setColorArray($type, $color, $ret=false) {
  3484. if (is_array($color)) {
  3485. $color = array_values($color);
  3486. // component: grey, RGB red or CMYK cyan
  3487. $c = isset($color[0]) ? $color[0] : -1;
  3488. // component: RGB green or CMYK magenta
  3489. $m = isset($color[1]) ? $color[1] : -1;
  3490. // component: RGB blue or CMYK yellow
  3491. $y = isset($color[2]) ? $color[2] : -1;
  3492. // component: CMYK black
  3493. $k = isset($color[3]) ? $color[3] : -1;
  3494. // color name
  3495. $name = isset($color[4]) ? $color[4] : '';
  3496. if ($c >= 0) {
  3497. return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
  3498. }
  3499. }
  3500. return '';
  3501. }
  3502. /**
  3503. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3504. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3505. * The method can be called before the first page is created and the value is retained from page to page.
  3506. * @param $color (array) Array of colors (1, 3 or 4 values).
  3507. * @param $ret (boolean) If true do not send the PDF command.
  3508. * @return string the PDF command
  3509. * @public
  3510. * @since 3.1.000 (2008-06-11)
  3511. * @see SetDrawColor()
  3512. */
  3513. public function SetDrawColorArray($color, $ret=false) {
  3514. return $this->setColorArray('draw', $color, $ret);
  3515. }
  3516. /**
  3517. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  3518. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3519. * The method can be called before the first page is created and the value is retained from page to page.
  3520. * @param $color (array) Array of colors (1, 3 or 4 values).
  3521. * @param $ret (boolean) If true do not send the PDF command.
  3522. * @public
  3523. * @since 3.1.000 (2008-6-11)
  3524. * @see SetFillColor()
  3525. */
  3526. public function SetFillColorArray($color, $ret=false) {
  3527. return $this->setColorArray('fill', $color, $ret);
  3528. }
  3529. /**
  3530. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  3531. * The method can be called before the first page is created and the value is retained from page to page.
  3532. * @param $color (array) Array of colors (1, 3 or 4 values).
  3533. * @param $ret (boolean) If true do not send the PDF command.
  3534. * @public
  3535. * @since 3.1.000 (2008-6-11)
  3536. * @see SetFillColor()
  3537. */
  3538. public function SetTextColorArray($color, $ret=false) {
  3539. return $this->setColorArray('text', $color, $ret);
  3540. }
  3541. /**
  3542. * Defines the color used by the specified type ('draw', 'fill', 'text').
  3543. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3544. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3545. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3546. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3547. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3548. * @param $ret (boolean) If true do not send the command.
  3549. * @param $name (string) spot color name (if any)
  3550. * @return (string) The PDF command or empty string.
  3551. * @public
  3552. * @since 5.9.125 (2011-10-03)
  3553. */
  3554. public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3555. // set default values
  3556. if (!is_numeric($col1)) {
  3557. $col1 = 0;
  3558. }
  3559. if (!is_numeric($col2)) {
  3560. $col2 = -1;
  3561. }
  3562. if (!is_numeric($col3)) {
  3563. $col3 = -1;
  3564. }
  3565. if (!is_numeric($col4)) {
  3566. $col4 = -1;
  3567. }
  3568. // set color by case
  3569. $suffix = '';
  3570. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  3571. // Grey scale
  3572. $col1 = max(0, min(255, $col1));
  3573. $intcolor = array('G' => $col1);
  3574. $pdfcolor = sprintf('%F ', ($col1 / 255));
  3575. $suffix = 'g';
  3576. } elseif ($col4 == -1) {
  3577. // RGB
  3578. $col1 = max(0, min(255, $col1));
  3579. $col2 = max(0, min(255, $col2));
  3580. $col3 = max(0, min(255, $col3));
  3581. $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  3582. $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  3583. $suffix = 'rg';
  3584. } else {
  3585. $col1 = max(0, min(100, $col1));
  3586. $col2 = max(0, min(100, $col2));
  3587. $col3 = max(0, min(100, $col3));
  3588. $col4 = max(0, min(100, $col4));
  3589. if (empty($name)) {
  3590. // CMYK
  3591. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  3592. $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  3593. $suffix = 'k';
  3594. } else {
  3595. // SPOT COLOR
  3596. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  3597. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  3598. $pdfcolor = $this->setSpotColor($type, $name, 100);
  3599. }
  3600. }
  3601. switch ($type) {
  3602. case 'draw': {
  3603. $pdfcolor .= strtoupper($suffix);
  3604. $this->DrawColor = $pdfcolor;
  3605. $this->strokecolor = $intcolor;
  3606. break;
  3607. }
  3608. case 'fill': {
  3609. $pdfcolor .= $suffix;
  3610. $this->FillColor = $pdfcolor;
  3611. $this->bgcolor = $intcolor;
  3612. break;
  3613. }
  3614. case 'text': {
  3615. $pdfcolor .= $suffix;
  3616. $this->TextColor = $pdfcolor;
  3617. $this->fgcolor = $intcolor;
  3618. break;
  3619. }
  3620. }
  3621. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3622. if (($type != 'text') AND ($this->state == 2)) {
  3623. if (!$ret) {
  3624. $this->_out($pdfcolor);
  3625. }
  3626. return $pdfcolor;
  3627. }
  3628. return '';
  3629. }
  3630. /**
  3631. * Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  3632. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3633. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3634. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3635. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3636. * @param $ret (boolean) If true do not send the command.
  3637. * @param $name (string) spot color name (if any)
  3638. * @return string the PDF command
  3639. * @public
  3640. * @since 1.3
  3641. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3642. */
  3643. public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3644. return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
  3645. }
  3646. /**
  3647. * Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  3648. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3649. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3650. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3651. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3652. * @param $ret (boolean) If true do not send the command.
  3653. * @param $name (string) Spot color name (if any).
  3654. * @return (string) The PDF command.
  3655. * @public
  3656. * @since 1.3
  3657. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  3658. */
  3659. public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3660. return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
  3661. }
  3662. /**
  3663. * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  3664. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3665. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3666. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3667. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3668. * @param $ret (boolean) If true do not send the command.
  3669. * @param $name (string) Spot color name (if any).
  3670. * @return (string) Empty string.
  3671. * @public
  3672. * @since 1.3
  3673. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  3674. */
  3675. public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3676. return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
  3677. }
  3678. /**
  3679. * Returns the length of a string in user unit. A font must be selected.<br>
  3680. * @param $s (string) The string whose length is to be computed
  3681. * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  3682. * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line-through</li><li>O: overline</li></ul> or any combination. The default value is regular.
  3683. * @param $fontsize (float) Font size in points. The default value is the current size.
  3684. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  3685. * @return mixed int total string length or array of characted widths
  3686. * @author Nicola Asuni
  3687. * @public
  3688. * @since 1.2
  3689. */
  3690. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3691. return $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont), $s, $this->tmprtl, $this->isunicode, $this->CurrentFont), $fontname, $fontstyle, $fontsize, $getarray);
  3692. }
  3693. /**
  3694. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  3695. * @param $sa (string) The array of chars whose total length is to be computed
  3696. * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  3697. * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line through</li><li>O: overline</li></ul> or any combination. The default value is regular.
  3698. * @param $fontsize (float) Font size in points. The default value is the current size.
  3699. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  3700. * @return mixed int total string length or array of characted widths
  3701. * @author Nicola Asuni
  3702. * @public
  3703. * @since 2.4.000 (2008-03-06)
  3704. */
  3705. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3706. // store current values
  3707. if (!TCPDF_STATIC::empty_string($fontname)) {
  3708. $prev_FontFamily = $this->FontFamily;
  3709. $prev_FontStyle = $this->FontStyle;
  3710. $prev_FontSizePt = $this->FontSizePt;
  3711. $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
  3712. }
  3713. // convert UTF-8 array to Latin1 if required
  3714. if ($this->isunicode AND (!$this->isUnicodeFont())) {
  3715. $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
  3716. }
  3717. $w = 0; // total width
  3718. $wa = array(); // array of characters widths
  3719. foreach ($sa as $ck => $char) {
  3720. // character width
  3721. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  3722. $wa[] = $cw;
  3723. $w += $cw;
  3724. }
  3725. // restore previous values
  3726. if (!TCPDF_STATIC::empty_string($fontname)) {
  3727. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
  3728. }
  3729. if ($getarray) {
  3730. return $wa;
  3731. }
  3732. return $w;
  3733. }
  3734. /**
  3735. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  3736. * @param $char (int) The char code whose length is to be returned
  3737. * @param $notlast (boolean) If false ignore the font-spacing.
  3738. * @return float char width
  3739. * @author Nicola Asuni
  3740. * @public
  3741. * @since 2.4.000 (2008-03-06)
  3742. */
  3743. public function GetCharWidth($char, $notlast=true) {
  3744. // get raw width
  3745. $chw = $this->getRawCharWidth($char);
  3746. if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
  3747. // increase/decrease font spacing
  3748. $chw += $this->font_spacing;
  3749. }
  3750. if ($this->font_stretching != 100) {
  3751. // fixed stretching mode
  3752. $chw *= ($this->font_stretching / 100);
  3753. }
  3754. return $chw;
  3755. }
  3756. /**
  3757. * Returns the length of the char in user unit for the current font.
  3758. * @param $char (int) The char code whose length is to be returned
  3759. * @return float char width
  3760. * @author Nicola Asuni
  3761. * @public
  3762. * @since 5.9.000 (2010-09-28)
  3763. */
  3764. public function getRawCharWidth($char) {
  3765. if ($char == 173) {
  3766. // SHY character will not be printed
  3767. return (0);
  3768. }
  3769. if (isset($this->CurrentFont['cw'][$char])) {
  3770. $w = $this->CurrentFont['cw'][$char];
  3771. } elseif (isset($this->CurrentFont['dw'])) {
  3772. // default width
  3773. $w = $this->CurrentFont['dw'];
  3774. } elseif (isset($this->CurrentFont['cw'][32])) {
  3775. // default width
  3776. $w = $this->CurrentFont['cw'][32];
  3777. } else {
  3778. $w = 600;
  3779. }
  3780. return $this->getAbsFontMeasure($w);
  3781. }
  3782. /**
  3783. * Returns the numbero of characters in a string.
  3784. * @param $s (string) The input string.
  3785. * @return int number of characters
  3786. * @public
  3787. * @since 2.0.0001 (2008-01-07)
  3788. */
  3789. public function GetNumChars($s) {
  3790. if ($this->isUnicodeFont()) {
  3791. return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
  3792. }
  3793. return strlen($s);
  3794. }
  3795. /**
  3796. * Fill the list of available fonts ($this->fontlist).
  3797. * @protected
  3798. * @since 4.0.013 (2008-07-28)
  3799. */
  3800. protected function getFontsList() {
  3801. if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) {
  3802. while (($file = readdir($fontsdir)) !== false) {
  3803. if (substr($file, -4) == '.php') {
  3804. array_push($this->fontlist, strtolower(basename($file, '.php')));
  3805. }
  3806. }
  3807. closedir($fontsdir);
  3808. }
  3809. }
  3810. /**
  3811. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3812. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3813. * The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
  3814. * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3815. * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
  3816. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3817. * @return array containing the font data, or false in case of error.
  3818. * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  3819. * @public
  3820. * @since 1.5
  3821. * @see SetFont(), setFontSubsetting()
  3822. */
  3823. public function AddFont($family, $style='', $fontfile='', $subset='default') {
  3824. if ($subset === 'default') {
  3825. $subset = $this->font_subsetting;
  3826. }
  3827. if ($this->pdfa_mode) {
  3828. $subset = false;
  3829. }
  3830. if (TCPDF_STATIC::empty_string($family)) {
  3831. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  3832. $family = $this->FontFamily;
  3833. } else {
  3834. $this->Error('Empty font family');
  3835. }
  3836. }
  3837. // move embedded styles on $style
  3838. if (substr($family, -1) == 'I') {
  3839. $style .= 'I';
  3840. $family = substr($family, 0, -1);
  3841. }
  3842. if (substr($family, -1) == 'B') {
  3843. $style .= 'B';
  3844. $family = substr($family, 0, -1);
  3845. }
  3846. // normalize family name
  3847. $family = strtolower($family);
  3848. if ((!$this->isunicode) AND ($family == 'arial')) {
  3849. $family = 'helvetica';
  3850. }
  3851. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  3852. $style = '';
  3853. }
  3854. if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  3855. // all fonts must be embedded
  3856. $family = 'pdfa'.$family;
  3857. }
  3858. $tempstyle = strtoupper($style);
  3859. $style = '';
  3860. // underline
  3861. if (strpos($tempstyle, 'U') !== false) {
  3862. $this->underline = true;
  3863. } else {
  3864. $this->underline = false;
  3865. }
  3866. // line-through (deleted)
  3867. if (strpos($tempstyle, 'D') !== false) {
  3868. $this->linethrough = true;
  3869. } else {
  3870. $this->linethrough = false;
  3871. }
  3872. // overline
  3873. if (strpos($tempstyle, 'O') !== false) {
  3874. $this->overline = true;
  3875. } else {
  3876. $this->overline = false;
  3877. }
  3878. // bold
  3879. if (strpos($tempstyle, 'B') !== false) {
  3880. $style .= 'B';
  3881. }
  3882. // oblique
  3883. if (strpos($tempstyle, 'I') !== false) {
  3884. $style .= 'I';
  3885. }
  3886. $bistyle = $style;
  3887. $fontkey = $family.$style;
  3888. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  3889. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  3890. // check if the font has been already added
  3891. $fb = $this->getFontBuffer($fontkey);
  3892. if ($fb !== false) {
  3893. if ($this->inxobj) {
  3894. // we are inside an XObject template
  3895. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  3896. }
  3897. return $fontdata;
  3898. }
  3899. // get specified font directory (if any)
  3900. $fontdir = false;
  3901. if (!TCPDF_STATIC::empty_string($fontfile)) {
  3902. $fontdir = dirname($fontfile);
  3903. if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) {
  3904. $fontdir = '';
  3905. } else {
  3906. $fontdir .= '/';
  3907. }
  3908. }
  3909. // true when the font style variation is missing
  3910. $missing_style = false;
  3911. // search and include font file
  3912. if (TCPDF_STATIC::empty_string($fontfile) OR (!@TCPDF_STATIC::file_exists($fontfile))) {
  3913. // build a standard filenames for specified font
  3914. $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
  3915. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3916. if (TCPDF_STATIC::empty_string($fontfile)) {
  3917. $missing_style = true;
  3918. // try to remove the style part
  3919. $tmp_fontfile = str_replace(' ', '', $family).'.php';
  3920. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3921. }
  3922. }
  3923. // include font file
  3924. if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) {
  3925. include($fontfile);
  3926. } else {
  3927. $this->Error('Could not include font definition file: '.$family.'');
  3928. }
  3929. // check font parameters
  3930. if ((!isset($type)) OR (!isset($cw))) {
  3931. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  3932. }
  3933. // SET default parameters
  3934. if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
  3935. $file = '';
  3936. }
  3937. if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
  3938. $enc = '';
  3939. }
  3940. if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
  3941. $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
  3942. $cidinfo['uni2cid'] = array();
  3943. }
  3944. if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
  3945. $ctg = '';
  3946. }
  3947. if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
  3948. $desc = array();
  3949. }
  3950. if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
  3951. $up = -100;
  3952. }
  3953. if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
  3954. $ut = 50;
  3955. }
  3956. if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
  3957. $cw = array();
  3958. }
  3959. if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
  3960. // set default width
  3961. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  3962. $dw = $desc['MissingWidth'];
  3963. } elseif (isset($cw[32])) {
  3964. $dw = $cw[32];
  3965. } else {
  3966. $dw = 600;
  3967. }
  3968. }
  3969. ++$this->numfonts;
  3970. if ($type == 'core') {
  3971. $name = $this->CoreFonts[$fontkey];
  3972. $subset = false;
  3973. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  3974. $subset = false;
  3975. } elseif ($type == 'TrueTypeUnicode') {
  3976. $enc = 'Identity-H';
  3977. } elseif ($type == 'cidfont0') {
  3978. if ($this->pdfa_mode) {
  3979. $this->Error('All fonts must be embedded in PDF/A mode!');
  3980. }
  3981. } else {
  3982. $this->Error('Unknow font type: '.$type.'');
  3983. }
  3984. // set name if unset
  3985. if (!isset($name) OR empty($name)) {
  3986. $name = $fontkey;
  3987. }
  3988. // create artificial font style variations if missing (only works with non-embedded fonts)
  3989. if (($type != 'core') AND $missing_style) {
  3990. // style variations
  3991. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  3992. $name .= $styles[$bistyle];
  3993. // artificial bold
  3994. if (strpos($bistyle, 'B') !== false) {
  3995. if (isset($desc['StemV'])) {
  3996. // from normal to bold
  3997. $desc['StemV'] = round($desc['StemV'] * 1.75);
  3998. } else {
  3999. // bold
  4000. $desc['StemV'] = 123;
  4001. }
  4002. }
  4003. // artificial italic
  4004. if (strpos($bistyle, 'I') !== false) {
  4005. if (isset($desc['ItalicAngle'])) {
  4006. $desc['ItalicAngle'] -= 11;
  4007. } else {
  4008. $desc['ItalicAngle'] = -11;
  4009. }
  4010. if (isset($desc['Flags'])) {
  4011. $desc['Flags'] |= 64; //bit 7
  4012. } else {
  4013. $desc['Flags'] = 64;
  4014. }
  4015. }
  4016. }
  4017. // check if the array of characters bounding boxes is defined
  4018. if (!isset($cbbox)) {
  4019. $cbbox = array();
  4020. }
  4021. // initialize subsetchars
  4022. $subsetchars = array_fill(0, 255, true);
  4023. $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'cbbox' => $cbbox, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
  4024. if ($this->inxobj) {
  4025. // we are inside an XObject template
  4026. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4027. }
  4028. if (isset($diff) AND (!empty($diff))) {
  4029. //Search existing encodings
  4030. $d = 0;
  4031. $nb = count($this->diffs);
  4032. for ($i=1; $i <= $nb; ++$i) {
  4033. if ($this->diffs[$i] == $diff) {
  4034. $d = $i;
  4035. break;
  4036. }
  4037. }
  4038. if ($d == 0) {
  4039. $d = $nb + 1;
  4040. $this->diffs[$d] = $diff;
  4041. }
  4042. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4043. }
  4044. if (!TCPDF_STATIC::empty_string($file)) {
  4045. if (!isset($this->FontFiles[$file])) {
  4046. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4047. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4048. } elseif ($type != 'core') {
  4049. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4050. }
  4051. } else {
  4052. // update fontkeys that are sharing this font file
  4053. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4054. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  4055. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4056. }
  4057. }
  4058. }
  4059. return $fontdata;
  4060. }
  4061. /**
  4062. * Sets the font used to print character strings.
  4063. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4064. * The method can be called before the first page is created and the font is retained from page to page.
  4065. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4066. * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the K_PATH_FONTS constant</li></ul><br />
  4067. * @param $family (string) Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
  4068. * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line through</li><li>O: overline</li></ul> or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined.
  4069. * @param $size (float) Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
  4070. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4071. * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  4072. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4073. * @author Nicola Asuni
  4074. * @public
  4075. * @since 1.0
  4076. * @see AddFont(), SetFontSize()
  4077. */
  4078. public function SetFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true) {
  4079. //Select a font; size given in points
  4080. if ($size === null) {
  4081. $size = $this->FontSizePt;
  4082. }
  4083. if ($size < 0) {
  4084. $size = 0;
  4085. }
  4086. // try to add font (if not already added)
  4087. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  4088. $this->FontFamily = $fontdata['family'];
  4089. $this->FontStyle = $fontdata['style'];
  4090. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  4091. // save subset chars of the previous font
  4092. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4093. }
  4094. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  4095. $this->SetFontSize($size, $out);
  4096. }
  4097. /**
  4098. * Defines the size of the current font.
  4099. * @param $size (float) The font size in points.
  4100. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4101. * @public
  4102. * @since 1.0
  4103. * @see SetFont()
  4104. */
  4105. public function SetFontSize($size, $out=true) {
  4106. $size = (float)$size;
  4107. // font size in points
  4108. $this->FontSizePt = $size;
  4109. // font size in user units
  4110. $this->FontSize = $size / $this->k;
  4111. // calculate some font metrics
  4112. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4113. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4114. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  4115. } else {
  4116. $font_height = $size * 1.219;
  4117. }
  4118. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4119. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  4120. }
  4121. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4122. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  4123. }
  4124. if (!isset($font_ascent) AND !isset($font_descent)) {
  4125. // core font
  4126. $font_ascent = 0.76 * $font_height;
  4127. $font_descent = $font_height - $font_ascent;
  4128. } elseif (!isset($font_descent)) {
  4129. $font_descent = $font_height - $font_ascent;
  4130. } elseif (!isset($font_ascent)) {
  4131. $font_ascent = $font_height - $font_descent;
  4132. }
  4133. $this->FontAscent = ($font_ascent / $this->k);
  4134. $this->FontDescent = ($font_descent / $this->k);
  4135. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  4136. $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4137. }
  4138. }
  4139. /**
  4140. * Returns the bounding box of the current font in user units.
  4141. * @return array
  4142. * @public
  4143. * @since 5.9.152 (2012-03-23)
  4144. */
  4145. public function getFontBBox() {
  4146. $fbbox = array();
  4147. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4148. $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4149. $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
  4150. } else {
  4151. // Find max width
  4152. if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  4153. $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  4154. } else {
  4155. $maxw = 0;
  4156. if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  4157. $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
  4158. }
  4159. if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  4160. $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
  4161. }
  4162. if (isset($this->CurrentFont['dw'])) {
  4163. $maxw = max($maxw, $this->CurrentFont['dw']);
  4164. }
  4165. foreach ($this->CurrentFont['cw'] as $char => $w) {
  4166. $maxw = max($maxw, $w);
  4167. }
  4168. if ($maxw == 0) {
  4169. $maxw = 600;
  4170. }
  4171. $maxw = $this->getAbsFontMeasure($maxw);
  4172. }
  4173. $fbbox = array(0, (0 - $this->FontDescent), $maxw, $this->FontAscent);
  4174. }
  4175. return $fbbox;
  4176. }
  4177. /**
  4178. * Convert a relative font measure into absolute value.
  4179. * @param $s (int) Font measure.
  4180. * @return float Absolute measure.
  4181. * @since 5.9.186 (2012-09-13)
  4182. */
  4183. public function getAbsFontMeasure($s) {
  4184. return ($s * $this->FontSize / 1000);
  4185. }
  4186. /**
  4187. * Returns the glyph bounding box of the specified character in the current font in user units.
  4188. * @param $char (int) Input character code.
  4189. * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  4190. * @since 5.9.186 (2012-09-13)
  4191. */
  4192. public function getCharBBox($char) {
  4193. $c = intval($char);
  4194. if (isset($this->CurrentFont['cw'][$c])) {
  4195. // glyph is defined ... use zero width & height for glyphs without outlines
  4196. $result = array(0,0,0,0);
  4197. if (isset($this->CurrentFont['cbbox'][$c])) {
  4198. $result = $this->CurrentFont['cbbox'][$c];
  4199. }
  4200. return array_map(array($this,'getAbsFontMeasure'), $result);
  4201. }
  4202. return false;
  4203. }
  4204. /**
  4205. * Return the font descent value
  4206. * @param $font (string) font name
  4207. * @param $style (string) font style
  4208. * @param $size (float) The size (in points)
  4209. * @return int font descent
  4210. * @public
  4211. * @author Nicola Asuni
  4212. * @since 4.9.003 (2010-03-30)
  4213. */
  4214. public function getFontDescent($font, $style='', $size=0) {
  4215. $fontdata = $this->AddFont($font, $style);
  4216. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4217. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4218. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  4219. } else {
  4220. $descent = (1.219 * 0.24 * $size);
  4221. }
  4222. return ($descent / $this->k);
  4223. }
  4224. /**
  4225. * Return the font ascent value.
  4226. * @param $font (string) font name
  4227. * @param $style (string) font style
  4228. * @param $size (float) The size (in points)
  4229. * @return int font ascent
  4230. * @public
  4231. * @author Nicola Asuni
  4232. * @since 4.9.003 (2010-03-30)
  4233. */
  4234. public function getFontAscent($font, $style='', $size=0) {
  4235. $fontdata = $this->AddFont($font, $style);
  4236. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4237. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4238. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  4239. } else {
  4240. $ascent = 1.219 * 0.76 * $size;
  4241. }
  4242. return ($ascent / $this->k);
  4243. }
  4244. /**
  4245. * Return true in the character is present in the specified font.
  4246. * @param $char (mixed) Character to check (integer value or string)
  4247. * @param $font (string) Font name (family name).
  4248. * @param $style (string) Font style.
  4249. * @return (boolean) true if the char is defined, false otherwise.
  4250. * @public
  4251. * @since 5.9.153 (2012-03-28)
  4252. */
  4253. public function isCharDefined($char, $font='', $style='') {
  4254. if (is_string($char)) {
  4255. // get character code
  4256. $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont);
  4257. $char = $char[0];
  4258. }
  4259. if (TCPDF_STATIC::empty_string($font)) {
  4260. if (TCPDF_STATIC::empty_string($style)) {
  4261. return (isset($this->CurrentFont['cw'][intval($char)]));
  4262. }
  4263. $font = $this->FontFamily;
  4264. }
  4265. $fontdata = $this->AddFont($font, $style);
  4266. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4267. return (isset($fontinfo['cw'][intval($char)]));
  4268. }
  4269. /**
  4270. * Replace missing font characters on selected font with specified substitutions.
  4271. * @param $text (string) Text to process.
  4272. * @param $font (string) Font name (family name).
  4273. * @param $style (string) Font style.
  4274. * @param $subs (array) Array of possible character substitutions. The key is the character to check (integer value) and the value is a single intege value or an array of possible substitutes.
  4275. * @return (string) Processed text.
  4276. * @public
  4277. * @since 5.9.153 (2012-03-28)
  4278. */
  4279. public function replaceMissingChars($text, $font='', $style='', $subs=array()) {
  4280. if (empty($subs)) {
  4281. return $text;
  4282. }
  4283. if (TCPDF_STATIC::empty_string($font)) {
  4284. $font = $this->FontFamily;
  4285. }
  4286. $fontdata = $this->AddFont($font, $style);
  4287. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4288. $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  4289. foreach ($uniarr as $k => $chr) {
  4290. if (!isset($fontinfo['cw'][$chr])) {
  4291. // this character is missing on the selected font
  4292. if (isset($subs[$chr])) {
  4293. // we have available substitutions
  4294. if (is_array($subs[$chr])) {
  4295. foreach($subs[$chr] as $s) {
  4296. if (isset($fontinfo['cw'][$s])) {
  4297. $uniarr[$k] = $s;
  4298. break;
  4299. }
  4300. }
  4301. } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  4302. $uniarr[$k] = $subs[$chr];
  4303. }
  4304. }
  4305. }
  4306. }
  4307. return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr, $this->isunicode));
  4308. }
  4309. /**
  4310. * Defines the default monospaced font.
  4311. * @param $font (string) Font name.
  4312. * @public
  4313. * @since 4.5.025
  4314. */
  4315. public function SetDefaultMonospacedFont($font) {
  4316. $this->default_monospaced_font = $font;
  4317. }
  4318. /**
  4319. * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
  4320. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4321. * @public
  4322. * @since 1.5
  4323. * @see Cell(), Write(), Image(), Link(), SetLink()
  4324. */
  4325. public function AddLink() {
  4326. // create a new internal link
  4327. $n = count($this->links) + 1;
  4328. $this->links[$n] = array('p' => 0, 'y' => 0, 'f' => false);
  4329. return $n;
  4330. }
  4331. /**
  4332. * Defines the page and position a link points to.
  4333. * @param $link (int) The link identifier returned by AddLink()
  4334. * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4335. * @param $page (int) Number of target page; -1 indicates the current page (default value). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  4336. * @public
  4337. * @since 1.5
  4338. * @see AddLink()
  4339. */
  4340. public function SetLink($link, $y=0, $page=-1) {
  4341. $fixed = false;
  4342. if (!empty($page) AND ($page[0] == '*')) {
  4343. $page = intval(substr($page, 1));
  4344. // this page number will not be changed when moving/add/deleting pages
  4345. $fixed = true;
  4346. }
  4347. if ($page < 0) {
  4348. $page = $this->page;
  4349. }
  4350. if ($y == -1) {
  4351. $y = $this->y;
  4352. }
  4353. $this->links[$link] = array('p' => $page, 'y' => $y, 'f' => $fixed);
  4354. }
  4355. /**
  4356. * Puts a link on a rectangular area of the page.
  4357. * Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.
  4358. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4359. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4360. * @param $w (float) Width of the rectangle
  4361. * @param $h (float) Height of the rectangle
  4362. * @param $link (mixed) URL or identifier returned by AddLink()
  4363. * @param $spaces (int) number of spaces on the text to link
  4364. * @public
  4365. * @since 1.5
  4366. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4367. */
  4368. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  4369. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  4370. }
  4371. /**
  4372. * Puts a markup annotation on a rectangular area of the page.
  4373. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4374. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4375. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4376. * @param $w (float) Width of the rectangle
  4377. * @param $h (float) Height of the rectangle
  4378. * @param $text (string) annotation text or alternate content
  4379. * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
  4380. * @param $spaces (int) number of spaces on the text to link
  4381. * @public
  4382. * @since 4.0.018 (2008-08-06)
  4383. */
  4384. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  4385. if ($this->inxobj) {
  4386. // store parameters for later use on template
  4387. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  4388. return;
  4389. }
  4390. if ($x === '') {
  4391. $x = $this->x;
  4392. }
  4393. if ($y === '') {
  4394. $y = $this->y;
  4395. }
  4396. // check page for no-write regions and adapt page margins if necessary
  4397. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  4398. // recalculate coordinates to account for graphic transformations
  4399. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4400. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  4401. $maxid = count($this->transfmatrix[$i]) - 1;
  4402. for ($j=$maxid; $j >= 0; --$j) {
  4403. $ctm = $this->transfmatrix[$i][$j];
  4404. if (isset($ctm['a'])) {
  4405. $x = $x * $this->k;
  4406. $y = ($this->h - $y) * $this->k;
  4407. $w = $w * $this->k;
  4408. $h = $h * $this->k;
  4409. // top left
  4410. $xt = $x;
  4411. $yt = $y;
  4412. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4413. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4414. // top right
  4415. $xt = $x + $w;
  4416. $yt = $y;
  4417. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4418. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4419. // bottom left
  4420. $xt = $x;
  4421. $yt = $y - $h;
  4422. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4423. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4424. // bottom right
  4425. $xt = $x + $w;
  4426. $yt = $y - $h;
  4427. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4428. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4429. // new coordinates (rectangle area)
  4430. $x = min($x1, $x2, $x3, $x4);
  4431. $y = max($y1, $y2, $y3, $y4);
  4432. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  4433. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  4434. $x = $x / $this->k;
  4435. $y = $this->h - ($y / $this->k);
  4436. }
  4437. }
  4438. }
  4439. }
  4440. if ($this->page <= 0) {
  4441. $page = 1;
  4442. } else {
  4443. $page = $this->page;
  4444. }
  4445. if (!isset($this->PageAnnots[$page])) {
  4446. $this->PageAnnots[$page] = array();
  4447. }
  4448. $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  4449. if (!$this->pdfa_mode) {
  4450. if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
  4451. AND (@TCPDF_STATIC::file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
  4452. AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  4453. $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
  4454. }
  4455. }
  4456. // Add widgets annotation's icons
  4457. if (isset($opt['mk']['i']) AND @TCPDF_STATIC::file_exists($opt['mk']['i'])) {
  4458. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  4459. }
  4460. if (isset($opt['mk']['ri']) AND @TCPDF_STATIC::file_exists($opt['mk']['ri'])) {
  4461. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4462. }
  4463. if (isset($opt['mk']['ix']) AND @TCPDF_STATIC::file_exists($opt['mk']['ix'])) {
  4464. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4465. }
  4466. }
  4467. /**
  4468. * Embedd the attached files.
  4469. * @since 4.4.000 (2008-12-07)
  4470. * @protected
  4471. * @see Annotation()
  4472. */
  4473. protected function _putEmbeddedFiles() {
  4474. if ($this->pdfa_mode) {
  4475. // embedded files are not allowed in PDF/A mode
  4476. return;
  4477. }
  4478. reset($this->embeddedfiles);
  4479. foreach ($this->embeddedfiles as $filename => $filedata) {
  4480. $data = TCPDF_STATIC::fileGetContents($filedata['file']);
  4481. if ($data !== FALSE) {
  4482. $rawsize = strlen($data);
  4483. if ($rawsize > 0) {
  4484. // update name tree
  4485. $this->efnames[$filename] = $filedata['f'].' 0 R';
  4486. // embedded file specification object
  4487. $out = $this->_getobj($filedata['f'])."\n";
  4488. $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']).' /EF <</F '.$filedata['n'].' 0 R>> >>';
  4489. $out .= "\n".'endobj';
  4490. $this->_out($out);
  4491. // embedded file object
  4492. $filter = '';
  4493. if ($this->compress) {
  4494. $data = gzcompress($data);
  4495. $filter = ' /Filter /FlateDecode';
  4496. }
  4497. $stream = $this->_getrawstream($data, $filedata['n']);
  4498. $out = $this->_getobj($filedata['n'])."\n";
  4499. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
  4500. $out .= ' stream'."\n".$stream."\n".'endstream';
  4501. $out .= "\n".'endobj';
  4502. $this->_out($out);
  4503. }
  4504. }
  4505. }
  4506. }
  4507. /**
  4508. * Prints a text cell at the specified position.
  4509. * This method allows to place a string precisely on the page.
  4510. * @param $x (float) Abscissa of the cell origin
  4511. * @param $y (float) Ordinate of the cell origin
  4512. * @param $txt (string) String to print
  4513. * @param $fstroke (int) outline size in user units (false = disable)
  4514. * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4515. * @param $ffill (boolean) if true fills the text
  4516. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4517. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  4518. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  4519. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4520. * @param $link (mixed) URL or identifier returned by AddLink().
  4521. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4522. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4523. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li><li>B : cell bottom</li></ul>
  4524. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4525. * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4526. * @public
  4527. * @since 1.0
  4528. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4529. */
  4530. 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) {
  4531. $textrendermode = $this->textrendermode;
  4532. $textstrokewidth = $this->textstrokewidth;
  4533. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  4534. $this->SetXY($x, $y, $rtloff);
  4535. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  4536. // restore previous rendering mode
  4537. $this->textrendermode = $textrendermode;
  4538. $this->textstrokewidth = $textstrokewidth;
  4539. }
  4540. /**
  4541. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4542. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4543. * This method is called automatically and should not be called directly by the application.
  4544. * @return boolean
  4545. * @public
  4546. * @since 1.4
  4547. * @see SetAutoPageBreak()
  4548. */
  4549. public function AcceptPageBreak() {
  4550. if ($this->num_columns > 1) {
  4551. // multi column mode
  4552. if ($this->current_column < ($this->num_columns - 1)) {
  4553. // go to next column
  4554. $this->selectColumn($this->current_column + 1);
  4555. } elseif ($this->AutoPageBreak) {
  4556. // add a new page
  4557. $this->AddPage();
  4558. // set first column
  4559. $this->selectColumn(0);
  4560. }
  4561. // avoid page breaking from checkPageBreak()
  4562. return false;
  4563. }
  4564. return $this->AutoPageBreak;
  4565. }
  4566. /**
  4567. * Add page if needed.
  4568. * @param $h (float) Cell height. Default value: 0.
  4569. * @param $y (mixed) starting y position, leave empty for current position.
  4570. * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
  4571. * @return boolean true in case of page break, false otherwise.
  4572. * @since 3.2.000 (2008-07-01)
  4573. * @protected
  4574. */
  4575. protected function checkPageBreak($h=0, $y='', $addpage=true) {
  4576. if (TCPDF_STATIC::empty_string($y)) {
  4577. $y = $this->y;
  4578. }
  4579. $current_page = $this->page;
  4580. if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  4581. if ($addpage) {
  4582. //Automatic page break
  4583. $x = $this->x;
  4584. $this->AddPage($this->CurOrientation);
  4585. $this->y = $this->tMargin;
  4586. $oldpage = $this->page - 1;
  4587. if ($this->rtl) {
  4588. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4589. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4590. } else {
  4591. $this->x = $x;
  4592. }
  4593. } else {
  4594. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4595. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4596. } else {
  4597. $this->x = $x;
  4598. }
  4599. }
  4600. }
  4601. return true;
  4602. }
  4603. if ($current_page != $this->page) {
  4604. // account for columns mode
  4605. return true;
  4606. }
  4607. return false;
  4608. }
  4609. /**
  4610. * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
  4611. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4612. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  4613. * @param $h (float) Cell height. Default value: 0.
  4614. * @param $txt (string) String to print. Default value: empty string.
  4615. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4616. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  4617. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  4618. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4619. * @param $link (mixed) URL or identifier returned by AddLink().
  4620. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4621. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4622. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  4623. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4624. * @public
  4625. * @since 1.0
  4626. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  4627. */
  4628. 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') {
  4629. $prev_cell_margin = $this->cell_margin;
  4630. $prev_cell_padding = $this->cell_padding;
  4631. $this->adjustCellPadding($border);
  4632. if (!$ignore_min_height) {
  4633. $min_cell_height = $this->getCellHeight($this->FontSize);
  4634. if ($h < $min_cell_height) {
  4635. $h = $min_cell_height;
  4636. }
  4637. }
  4638. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  4639. // apply text shadow if enabled
  4640. if ($this->txtshadow['enabled']) {
  4641. // save data
  4642. $x = $this->x;
  4643. $y = $this->y;
  4644. $bc = $this->bgcolor;
  4645. $fc = $this->fgcolor;
  4646. $sc = $this->strokecolor;
  4647. $alpha = $this->alpha;
  4648. // print shadow
  4649. $this->x += $this->txtshadow['depth_w'];
  4650. $this->y += $this->txtshadow['depth_h'];
  4651. $this->SetFillColorArray($this->txtshadow['color']);
  4652. $this->SetTextColorArray($this->txtshadow['color']);
  4653. $this->SetDrawColorArray($this->txtshadow['color']);
  4654. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4655. $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  4656. }
  4657. if ($this->state == 2) {
  4658. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4659. }
  4660. //restore data
  4661. $this->x = $x;
  4662. $this->y = $y;
  4663. $this->SetFillColorArray($bc);
  4664. $this->SetTextColorArray($fc);
  4665. $this->SetDrawColorArray($sc);
  4666. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4667. $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  4668. }
  4669. }
  4670. if ($this->state == 2) {
  4671. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4672. }
  4673. $this->cell_padding = $prev_cell_padding;
  4674. $this->cell_margin = $prev_cell_margin;
  4675. }
  4676. /**
  4677. * Returns the PDF string code to print a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
  4678. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4679. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  4680. * @param $h (float) Cell height. Default value: 0.
  4681. * @param $txt (string) String to print. Default value: empty string.
  4682. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4683. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  4684. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  4685. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4686. * @param $link (mixed) URL or identifier returned by AddLink().
  4687. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4688. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4689. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  4690. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
  4691. * @return string containing cell code
  4692. * @protected
  4693. * @since 1.0
  4694. * @see Cell()
  4695. */
  4696. 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') {
  4697. // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  4698. $txt = str_replace(TCPDF_FONTS::unichr(160, $this->isunicode), ' ', $txt);
  4699. $prev_cell_margin = $this->cell_margin;
  4700. $prev_cell_padding = $this->cell_padding;
  4701. $txt = TCPDF_STATIC::removeSHY($txt, $this->isunicode);
  4702. $rs = ''; //string to be returned
  4703. $this->adjustCellPadding($border);
  4704. if (!$ignore_min_height) {
  4705. $min_cell_height = $this->getCellHeight($this->FontSize);
  4706. if ($h < $min_cell_height) {
  4707. $h = $min_cell_height;
  4708. }
  4709. }
  4710. $k = $this->k;
  4711. // check page for no-write regions and adapt page margins if necessary
  4712. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  4713. if ($this->rtl) {
  4714. $x = $this->x - $this->cell_margin['R'];
  4715. } else {
  4716. $x = $this->x + $this->cell_margin['L'];
  4717. }
  4718. $y = $this->y + $this->cell_margin['T'];
  4719. $prev_font_stretching = $this->font_stretching;
  4720. $prev_font_spacing = $this->font_spacing;
  4721. // cell vertical alignment
  4722. switch ($calign) {
  4723. case 'A': {
  4724. // font top
  4725. switch ($valign) {
  4726. case 'T': {
  4727. // top
  4728. $y -= $this->cell_padding['T'];
  4729. break;
  4730. }
  4731. case 'B': {
  4732. // bottom
  4733. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  4734. break;
  4735. }
  4736. default:
  4737. case 'C':
  4738. case 'M': {
  4739. // center
  4740. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  4741. break;
  4742. }
  4743. }
  4744. break;
  4745. }
  4746. case 'L': {
  4747. // font baseline
  4748. switch ($valign) {
  4749. case 'T': {
  4750. // top
  4751. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  4752. break;
  4753. }
  4754. case 'B': {
  4755. // bottom
  4756. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  4757. break;
  4758. }
  4759. default:
  4760. case 'C':
  4761. case 'M': {
  4762. // center
  4763. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  4764. break;
  4765. }
  4766. }
  4767. break;
  4768. }
  4769. case 'D': {
  4770. // font bottom
  4771. switch ($valign) {
  4772. case 'T': {
  4773. // top
  4774. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  4775. break;
  4776. }
  4777. case 'B': {
  4778. // bottom
  4779. $y -= ($h - $this->cell_padding['B']);
  4780. break;
  4781. }
  4782. default:
  4783. case 'C':
  4784. case 'M': {
  4785. // center
  4786. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  4787. break;
  4788. }
  4789. }
  4790. break;
  4791. }
  4792. case 'B': {
  4793. // cell bottom
  4794. $y -= $h;
  4795. break;
  4796. }
  4797. case 'C':
  4798. case 'M': {
  4799. // cell center
  4800. $y -= ($h / 2);
  4801. break;
  4802. }
  4803. default:
  4804. case 'T': {
  4805. // cell top
  4806. break;
  4807. }
  4808. }
  4809. // text vertical alignment
  4810. switch ($valign) {
  4811. case 'T': {
  4812. // top
  4813. $yt = $y + $this->cell_padding['T'];
  4814. break;
  4815. }
  4816. case 'B': {
  4817. // bottom
  4818. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  4819. break;
  4820. }
  4821. default:
  4822. case 'C':
  4823. case 'M': {
  4824. // center
  4825. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  4826. break;
  4827. }
  4828. }
  4829. $basefonty = $yt + $this->FontAscent;
  4830. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  4831. if ($this->rtl) {
  4832. $w = $x - $this->lMargin;
  4833. } else {
  4834. $w = $this->w - $this->rMargin - $x;
  4835. }
  4836. }
  4837. $s = '';
  4838. // fill and borders
  4839. if (is_string($border) AND (strlen($border) == 4)) {
  4840. // full border
  4841. $border = 1;
  4842. }
  4843. if ($fill OR ($border == 1)) {
  4844. if ($fill) {
  4845. $op = ($border == 1) ? 'B' : 'f';
  4846. } else {
  4847. $op = 'S';
  4848. }
  4849. if ($this->rtl) {
  4850. $xk = (($x - $w) * $k);
  4851. } else {
  4852. $xk = ($x * $k);
  4853. }
  4854. $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  4855. }
  4856. // draw borders
  4857. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  4858. if ($txt != '') {
  4859. $txt2 = $txt;
  4860. if ($this->isunicode) {
  4861. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  4862. $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont);
  4863. } else {
  4864. $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values
  4865. $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont);
  4866. // replace thai chars (if any)
  4867. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  4868. // number of chars
  4869. $numchars = count($unicode);
  4870. // po pla, for far, for fan
  4871. $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
  4872. // do chada, to patak
  4873. $lowtail = array(0x0e0e, 0x0e0f);
  4874. // mai hun arkad, sara i, sara ii, sara ue, sara uee
  4875. $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
  4876. // mai ek, mai tho, mai tri, mai chattawa, karan
  4877. $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
  4878. // sara u, sara uu, pinthu
  4879. $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
  4880. $output = array();
  4881. for ($i = 0; $i < $numchars; $i++) {
  4882. if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  4883. $ch0 = $unicode[$i];
  4884. $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
  4885. $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
  4886. $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
  4887. if (in_array($ch0, $tonemark)) {
  4888. if ($chn == 0x0e33) {
  4889. // sara um
  4890. if (in_array($ch1, $longtail)) {
  4891. // tonemark at upper left
  4892. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4893. } else {
  4894. // tonemark at upper right (normal position)
  4895. $output[] = $ch0;
  4896. }
  4897. } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
  4898. // tonemark at lower left
  4899. $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
  4900. } elseif (in_array($ch1, $upvowel)) {
  4901. if (in_array($ch2, $longtail)) {
  4902. // tonemark at upper left
  4903. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4904. } else {
  4905. // tonemark at upper right (normal position)
  4906. $output[] = $ch0;
  4907. }
  4908. } else {
  4909. // tonemark at lower right
  4910. $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
  4911. }
  4912. } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
  4913. // add lower left nikhahit and sara aa
  4914. if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  4915. $output[] = 0xf711;
  4916. $this->CurrentFont['subsetchars'][0xf711] = true;
  4917. $output[] = 0x0e32;
  4918. $this->CurrentFont['subsetchars'][0x0e32] = true;
  4919. } else {
  4920. $output[] = $ch0;
  4921. }
  4922. } elseif (in_array($ch1, $longtail)) {
  4923. if ($ch0 == 0x0e31) {
  4924. // lower left mai hun arkad
  4925. $output[] = $this->replaceChar($ch0, 0xf710);
  4926. } elseif (in_array($ch0, $upvowel)) {
  4927. // lower left
  4928. $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
  4929. } elseif ($ch0 == 0x0e47) {
  4930. // lower left mai tai koo
  4931. $output[] = $this->replaceChar($ch0, 0xf712);
  4932. } else {
  4933. // normal character
  4934. $output[] = $ch0;
  4935. }
  4936. } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
  4937. // lower vowel
  4938. $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
  4939. } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
  4940. // yo ying without lower part
  4941. $output[] = $this->replaceChar($ch0, 0xf70f);
  4942. } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
  4943. // tho santan without lower part
  4944. $output[] = $this->replaceChar($ch0, 0xf700);
  4945. } else {
  4946. $output[] = $ch0;
  4947. }
  4948. } else {
  4949. // non-thai character
  4950. $output[] = $unicode[$i];
  4951. }
  4952. }
  4953. $unicode = $output;
  4954. // update font subsetchars
  4955. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4956. } // end of K_THAI_TOPCHARS
  4957. $txt2 = TCPDF_FONTS::arrUTF8ToUTF16BE($unicode, false);
  4958. }
  4959. }
  4960. $txt2 = TCPDF_STATIC::_escape($txt2);
  4961. // get current text width (considering general font stretching and spacing)
  4962. $txwidth = $this->GetStringWidth($txt);
  4963. $width = $txwidth;
  4964. // check for stretch mode
  4965. if ($stretch > 0) {
  4966. // calculate ratio between cell width and text width
  4967. if ($width <= 0) {
  4968. $ratio = 1;
  4969. } else {
  4970. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  4971. }
  4972. // check if stretching is required
  4973. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  4974. // the text will be stretched to fit cell width
  4975. if ($stretch > 2) {
  4976. // set new character spacing
  4977. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  4978. } else {
  4979. // set new horizontal stretching
  4980. $this->font_stretching *= $ratio;
  4981. }
  4982. // recalculate text width (the text fills the entire cell)
  4983. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  4984. // reset alignment
  4985. $align = '';
  4986. }
  4987. }
  4988. if ($this->font_stretching != 100) {
  4989. // apply font stretching
  4990. $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
  4991. }
  4992. if ($this->font_spacing != 0) {
  4993. // increase/decrease font spacing
  4994. $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
  4995. }
  4996. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  4997. $s .= 'q '.$this->TextColor.' ';
  4998. }
  4999. // rendering mode
  5000. $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
  5001. // count number of spaces
  5002. $ns = substr_count($txt, chr(32));
  5003. // Justification
  5004. $spacewidth = 0;
  5005. if (($align == 'J') AND ($ns > 0)) {
  5006. if ($this->isUnicodeFont()) {
  5007. // get string width without spaces
  5008. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  5009. // calculate average space width
  5010. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
  5011. if ($this->font_stretching != 100) {
  5012. // word spacing is affected by stretching
  5013. $spacewidth /= ($this->font_stretching / 100);
  5014. }
  5015. // set word position to be used with TJ operator
  5016. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
  5017. $unicode_justification = true;
  5018. } else {
  5019. // get string width
  5020. $width = $txwidth;
  5021. // new space width
  5022. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5023. if ($this->font_stretching != 100) {
  5024. // word spacing (Tw) is affected by stretching
  5025. $spacewidth /= ($this->font_stretching / 100);
  5026. }
  5027. // set word spacing
  5028. $rs .= sprintf('BT %F Tw ET ', $spacewidth);
  5029. }
  5030. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5031. }
  5032. // replace carriage return characters
  5033. $txt2 = str_replace("\r", ' ', $txt2);
  5034. switch ($align) {
  5035. case 'C': {
  5036. $dx = ($w - $width) / 2;
  5037. break;
  5038. }
  5039. case 'R': {
  5040. if ($this->rtl) {
  5041. $dx = $this->cell_padding['R'];
  5042. } else {
  5043. $dx = $w - $width - $this->cell_padding['R'];
  5044. }
  5045. break;
  5046. }
  5047. case 'L': {
  5048. if ($this->rtl) {
  5049. $dx = $w - $width - $this->cell_padding['L'];
  5050. } else {
  5051. $dx = $this->cell_padding['L'];
  5052. }
  5053. break;
  5054. }
  5055. case 'J':
  5056. default: {
  5057. if ($this->rtl) {
  5058. $dx = $this->cell_padding['R'];
  5059. } else {
  5060. $dx = $this->cell_padding['L'];
  5061. }
  5062. break;
  5063. }
  5064. }
  5065. if ($this->rtl) {
  5066. $xdx = $x - $dx - $width;
  5067. } else {
  5068. $xdx = $x + $dx;
  5069. }
  5070. $xdk = $xdx * $k;
  5071. // print text
  5072. $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  5073. if (isset($uniblock)) {
  5074. // print overlapping characters as separate string
  5075. $xshift = 0; // horizontal shift
  5076. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  5077. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5078. foreach ($uniblock as $uk => $uniarr) {
  5079. if (($uk % 2) == 0) {
  5080. // x space to skip
  5081. if ($spacewidth != 0) {
  5082. // justification shift
  5083. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  5084. }
  5085. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5086. } else {
  5087. // character to print
  5088. $topchr = TCPDF_FONTS::arrUTF8ToUTF16BE($uniarr, false);
  5089. $topchr = TCPDF_STATIC::_escape($topchr);
  5090. $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  5091. }
  5092. }
  5093. }
  5094. if ($this->underline) {
  5095. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  5096. }
  5097. if ($this->linethrough) {
  5098. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  5099. }
  5100. if ($this->overline) {
  5101. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  5102. }
  5103. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5104. $s .= ' Q';
  5105. }
  5106. if ($link) {
  5107. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  5108. }
  5109. }
  5110. // output cell
  5111. if ($s) {
  5112. // output cell
  5113. $rs .= $s;
  5114. if ($this->font_spacing != 0) {
  5115. // reset font spacing mode
  5116. $rs .= ' BT 0 Tc ET';
  5117. }
  5118. if ($this->font_stretching != 100) {
  5119. // reset font stretching mode
  5120. $rs .= ' BT 100 Tz ET';
  5121. }
  5122. }
  5123. // reset word spacing
  5124. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5125. $rs .= ' BT 0 Tw ET';
  5126. }
  5127. // reset stretching and spacing
  5128. $this->font_stretching = $prev_font_stretching;
  5129. $this->font_spacing = $prev_font_spacing;
  5130. $this->lasth = $h;
  5131. if ($ln > 0) {
  5132. //Go to the beginning of the next line
  5133. $this->y = $y + $h + $this->cell_margin['B'];
  5134. if ($ln == 1) {
  5135. if ($this->rtl) {
  5136. $this->x = $this->w - $this->rMargin;
  5137. } else {
  5138. $this->x = $this->lMargin;
  5139. }
  5140. }
  5141. } else {
  5142. // go left or right by case
  5143. if ($this->rtl) {
  5144. $this->x = $x - $w - $this->cell_margin['L'];
  5145. } else {
  5146. $this->x = $x + $w + $this->cell_margin['R'];
  5147. }
  5148. }
  5149. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5150. $rs = $gstyles.$rs;
  5151. $this->cell_padding = $prev_cell_padding;
  5152. $this->cell_margin = $prev_cell_margin;
  5153. return $rs;
  5154. }
  5155. /**
  5156. * Replace a char if is defined on the current font.
  5157. * @param $oldchar (int) Integer code (unicode) of the character to replace.
  5158. * @param $newchar (int) Integer code (unicode) of the new character.
  5159. * @return int the replaced char or the old char in case the new char i not defined
  5160. * @protected
  5161. * @since 5.9.167 (2012-06-22)
  5162. */
  5163. protected function replaceChar($oldchar, $newchar) {
  5164. if ($this->isCharDefined($newchar)) {
  5165. // add the new char on the subset list
  5166. $this->CurrentFont['subsetchars'][$newchar] = true;
  5167. // return the new character
  5168. return $newchar;
  5169. }
  5170. // return the old char
  5171. return $oldchar;
  5172. }
  5173. /**
  5174. * Returns the code to draw the cell border
  5175. * @param $x (float) X coordinate.
  5176. * @param $y (float) Y coordinate.
  5177. * @param $w (float) Cell width.
  5178. * @param $h (float) Cell height.
  5179. * @param $brd (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5180. * @return string containing cell border code
  5181. * @protected
  5182. * @see SetLineStyle()
  5183. * @since 5.7.000 (2010-08-02)
  5184. */
  5185. protected function getCellBorder($x, $y, $w, $h, $brd) {
  5186. $s = ''; // string to be returned
  5187. if (empty($brd)) {
  5188. return $s;
  5189. }
  5190. if ($brd == 1) {
  5191. $brd = array('LRTB' => true);
  5192. }
  5193. // calculate coordinates for border
  5194. $k = $this->k;
  5195. if ($this->rtl) {
  5196. $xeL = ($x - $w) * $k;
  5197. $xeR = $x * $k;
  5198. } else {
  5199. $xeL = $x * $k;
  5200. $xeR = ($x + $w) * $k;
  5201. }
  5202. $yeL = (($this->h - ($y + $h)) * $k);
  5203. $yeT = (($this->h - $y) * $k);
  5204. $xeT = $xeL;
  5205. $xeB = $xeR;
  5206. $yeR = $yeT;
  5207. $yeB = $yeL;
  5208. if (is_string($brd)) {
  5209. // convert string to array
  5210. $slen = strlen($brd);
  5211. $newbrd = array();
  5212. for ($i = 0; $i < $slen; ++$i) {
  5213. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  5214. }
  5215. $brd = $newbrd;
  5216. }
  5217. if (isset($brd['mode'])) {
  5218. $mode = $brd['mode'];
  5219. unset($brd['mode']);
  5220. } else {
  5221. $mode = 'normal';
  5222. }
  5223. foreach ($brd as $border => $style) {
  5224. if (is_array($style) AND !empty($style)) {
  5225. // apply border style
  5226. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5227. $s .= $this->SetLineStyle($style, true)."\n";
  5228. }
  5229. switch ($mode) {
  5230. case 'ext': {
  5231. $off = (($this->LineWidth / 2) * $k);
  5232. $xL = $xeL - $off;
  5233. $xR = $xeR + $off;
  5234. $yT = $yeT + $off;
  5235. $yL = $yeL - $off;
  5236. $xT = $xL;
  5237. $xB = $xR;
  5238. $yR = $yT;
  5239. $yB = $yL;
  5240. $w += $this->LineWidth;
  5241. $h += $this->LineWidth;
  5242. break;
  5243. }
  5244. case 'int': {
  5245. $off = ($this->LineWidth / 2) * $k;
  5246. $xL = $xeL + $off;
  5247. $xR = $xeR - $off;
  5248. $yT = $yeT - $off;
  5249. $yL = $yeL + $off;
  5250. $xT = $xL;
  5251. $xB = $xR;
  5252. $yR = $yT;
  5253. $yB = $yL;
  5254. $w -= $this->LineWidth;
  5255. $h -= $this->LineWidth;
  5256. break;
  5257. }
  5258. case 'normal':
  5259. default: {
  5260. $xL = $xeL;
  5261. $xT = $xeT;
  5262. $xB = $xeB;
  5263. $xR = $xeR;
  5264. $yL = $yeL;
  5265. $yT = $yeT;
  5266. $yB = $yeB;
  5267. $yR = $yeR;
  5268. break;
  5269. }
  5270. }
  5271. // draw borders by case
  5272. if (strlen($border) == 4) {
  5273. $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  5274. } elseif (strlen($border) == 3) {
  5275. if (strpos($border,'B') === false) { // LTR
  5276. $s .= sprintf('%F %F m ', $xL, $yL);
  5277. $s .= sprintf('%F %F l ', $xT, $yT);
  5278. $s .= sprintf('%F %F l ', $xR, $yR);
  5279. $s .= sprintf('%F %F l ', $xB, $yB);
  5280. $s .= 'S ';
  5281. } elseif (strpos($border,'L') === false) { // TRB
  5282. $s .= sprintf('%F %F m ', $xT, $yT);
  5283. $s .= sprintf('%F %F l ', $xR, $yR);
  5284. $s .= sprintf('%F %F l ', $xB, $yB);
  5285. $s .= sprintf('%F %F l ', $xL, $yL);
  5286. $s .= 'S ';
  5287. } elseif (strpos($border,'T') === false) { // RBL
  5288. $s .= sprintf('%F %F m ', $xR, $yR);
  5289. $s .= sprintf('%F %F l ', $xB, $yB);
  5290. $s .= sprintf('%F %F l ', $xL, $yL);
  5291. $s .= sprintf('%F %F l ', $xT, $yT);
  5292. $s .= 'S ';
  5293. } elseif (strpos($border,'R') === false) { // BLT
  5294. $s .= sprintf('%F %F m ', $xB, $yB);
  5295. $s .= sprintf('%F %F l ', $xL, $yL);
  5296. $s .= sprintf('%F %F l ', $xT, $yT);
  5297. $s .= sprintf('%F %F l ', $xR, $yR);
  5298. $s .= 'S ';
  5299. }
  5300. } elseif (strlen($border) == 2) {
  5301. if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  5302. $s .= sprintf('%F %F m ', $xL, $yL);
  5303. $s .= sprintf('%F %F l ', $xT, $yT);
  5304. $s .= sprintf('%F %F l ', $xR, $yR);
  5305. $s .= 'S ';
  5306. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  5307. $s .= sprintf('%F %F m ', $xT, $yT);
  5308. $s .= sprintf('%F %F l ', $xR, $yR);
  5309. $s .= sprintf('%F %F l ', $xB, $yB);
  5310. $s .= 'S ';
  5311. } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  5312. $s .= sprintf('%F %F m ', $xR, $yR);
  5313. $s .= sprintf('%F %F l ', $xB, $yB);
  5314. $s .= sprintf('%F %F l ', $xL, $yL);
  5315. $s .= 'S ';
  5316. } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  5317. $s .= sprintf('%F %F m ', $xB, $yB);
  5318. $s .= sprintf('%F %F l ', $xL, $yL);
  5319. $s .= sprintf('%F %F l ', $xT, $yT);
  5320. $s .= 'S ';
  5321. } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  5322. $s .= sprintf('%F %F m ', $xL, $yL);
  5323. $s .= sprintf('%F %F l ', $xT, $yT);
  5324. $s .= 'S ';
  5325. $s .= sprintf('%F %F m ', $xR, $yR);
  5326. $s .= sprintf('%F %F l ', $xB, $yB);
  5327. $s .= 'S ';
  5328. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  5329. $s .= sprintf('%F %F m ', $xT, $yT);
  5330. $s .= sprintf('%F %F l ', $xR, $yR);
  5331. $s .= 'S ';
  5332. $s .= sprintf('%F %F m ', $xB, $yB);
  5333. $s .= sprintf('%F %F l ', $xL, $yL);
  5334. $s .= 'S ';
  5335. }
  5336. } else { // strlen($border) == 1
  5337. if (strpos($border,'L') !== false) { // L
  5338. $s .= sprintf('%F %F m ', $xL, $yL);
  5339. $s .= sprintf('%F %F l ', $xT, $yT);
  5340. $s .= 'S ';
  5341. } elseif (strpos($border,'T') !== false) { // T
  5342. $s .= sprintf('%F %F m ', $xT, $yT);
  5343. $s .= sprintf('%F %F l ', $xR, $yR);
  5344. $s .= 'S ';
  5345. } elseif (strpos($border,'R') !== false) { // R
  5346. $s .= sprintf('%F %F m ', $xR, $yR);
  5347. $s .= sprintf('%F %F l ', $xB, $yB);
  5348. $s .= 'S ';
  5349. } elseif (strpos($border,'B') !== false) { // B
  5350. $s .= sprintf('%F %F m ', $xB, $yB);
  5351. $s .= sprintf('%F %F l ', $xL, $yL);
  5352. $s .= 'S ';
  5353. }
  5354. }
  5355. if (is_array($style) AND !empty($style)) {
  5356. // reset border style to previous value
  5357. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5358. }
  5359. }
  5360. return $s;
  5361. }
  5362. /**
  5363. * This method allows printing text with line breaks.
  5364. * They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br />
  5365. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5366. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5367. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  5368. * @param $txt (string) String to print
  5369. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5370. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value when $ishtml=false)</li></ul>
  5371. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5372. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
  5373. * @param $x (float) x position in user units
  5374. * @param $y (float) y position in user units
  5375. * @param $reseth (boolean) if true reset the last cell height (default true).
  5376. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  5377. * @param $ishtml (boolean) INTERNAL USE ONLY -- set to true if $txt is HTML content (default = false). Never set this parameter to true, use instead writeHTMLCell() or writeHTML() methods.
  5378. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  5379. * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false.
  5380. * @param $valign (string) Vertical alignment of text (requires $maxh = $h > 0). Possible values are:<ul><li>T: TOP</li><li>M: middle</li><li>B: bottom</li></ul>. This feature works only when $ishtml=false and the cell must fit in a single page.
  5381. * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode). $maxh must be greater than 0 and equal to $h.
  5382. * @return int Return the number of cells or 1 for html mode.
  5383. * @public
  5384. * @since 1.3
  5385. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5386. */
  5387. 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) {
  5388. $prev_cell_margin = $this->cell_margin;
  5389. $prev_cell_padding = $this->cell_padding;
  5390. // adjust internal padding
  5391. $this->adjustCellPadding($border);
  5392. $mc_padding = $this->cell_padding;
  5393. $mc_margin = $this->cell_margin;
  5394. $this->cell_padding['T'] = 0;
  5395. $this->cell_padding['B'] = 0;
  5396. $this->setCellMargins(0, 0, 0, 0);
  5397. if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) {
  5398. // reset row height
  5399. $this->resetLastH();
  5400. }
  5401. if (!TCPDF_STATIC::empty_string($y)) {
  5402. $this->SetY($y); // set y in order to convert negative y values to positive ones
  5403. }
  5404. $y = $this->GetY();
  5405. $resth = 0;
  5406. if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5407. // spit cell in more pages/columns
  5408. $newh = ($this->PageBreakTrigger - $y);
  5409. $resth = ($h - $newh); // cell to be printed on the next page/column
  5410. $h = $newh;
  5411. }
  5412. // get current page number
  5413. $startpage = $this->page;
  5414. // get current column
  5415. $startcolumn = $this->current_column;
  5416. if (!TCPDF_STATIC::empty_string($x)) {
  5417. $this->SetX($x);
  5418. } else {
  5419. $x = $this->GetX();
  5420. }
  5421. // check page for no-write regions and adapt page margins if necessary
  5422. list($x, $y) = $this->checkPageRegions(0, $x, $y);
  5423. // apply margins
  5424. $oy = $y + $mc_margin['T'];
  5425. if ($this->rtl) {
  5426. $ox = ($this->w - $x - $mc_margin['R']);
  5427. } else {
  5428. $ox = ($x + $mc_margin['L']);
  5429. }
  5430. $this->x = $ox;
  5431. $this->y = $oy;
  5432. // set width
  5433. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5434. if ($this->rtl) {
  5435. $w = ($this->x - $this->lMargin - $mc_margin['L']);
  5436. } else {
  5437. $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
  5438. }
  5439. }
  5440. // store original margin values
  5441. $lMargin = $this->lMargin;
  5442. $rMargin = $this->rMargin;
  5443. if ($this->rtl) {
  5444. $this->rMargin = ($this->w - $this->x);
  5445. $this->lMargin = ($this->x - $w);
  5446. } else {
  5447. $this->lMargin = ($this->x);
  5448. $this->rMargin = ($this->w - $this->x - $w);
  5449. }
  5450. $this->clMargin = $this->lMargin;
  5451. $this->crMargin = $this->rMargin;
  5452. if ($autopadding) {
  5453. // add top padding
  5454. $this->y += $mc_padding['T'];
  5455. }
  5456. if ($ishtml) { // ******* Write HTML text
  5457. $this->writeHTML($txt, true, false, $reseth, true, $align);
  5458. $nl = 1;
  5459. } else { // ******* Write simple text
  5460. $prev_FontSizePt = $this->FontSizePt;
  5461. if ($fitcell) {
  5462. // ajust height values
  5463. $tobottom = ($this->h - $this->y - $this->bMargin - $this->cell_padding['T'] - $this->cell_padding['B']);
  5464. $h = $maxh = max(min($h, $tobottom), min($maxh, $tobottom));
  5465. }
  5466. // vertical alignment
  5467. if ($maxh > 0) {
  5468. // get text height
  5469. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5470. if ($fitcell AND ($text_height > $maxh) AND ($this->FontSizePt > 1)) {
  5471. // try to reduce font size to fit text on cell (use a quick search algorithm)
  5472. $fmin = 1;
  5473. $fmax = $this->FontSizePt;
  5474. $diff_epsilon = (1 / $this->k); // one point (min resolution)
  5475. $maxit = (2 * min(100, max(10, intval($fmax)))); // max number of iterations
  5476. while ($maxit >= 0) {
  5477. $fmid = (($fmax + $fmin) / 2);
  5478. $this->SetFontSize($fmid, false);
  5479. $this->resetLastH();
  5480. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5481. $diff = ($maxh - $text_height);
  5482. if ($diff >= 0) {
  5483. if ($diff <= $diff_epsilon) {
  5484. break;
  5485. }
  5486. $fmin = $fmid;
  5487. } else {
  5488. $fmax = $fmid;
  5489. }
  5490. --$maxit;
  5491. }
  5492. if ($maxit < 0) {
  5493. // premature exit, we get the minimum font value to fit the cell
  5494. $this->SetFontSize($fmin);
  5495. $this->resetLastH();
  5496. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5497. } else {
  5498. $this->SetFontSize($fmid);
  5499. $this->resetLastH();
  5500. }
  5501. }
  5502. if ($text_height < $maxh) {
  5503. if ($valign == 'M') {
  5504. // text vertically centered
  5505. $this->y += (($maxh - $text_height) / 2);
  5506. } elseif ($valign == 'B') {
  5507. // text vertically aligned on bottom
  5508. $this->y += ($maxh - $text_height);
  5509. }
  5510. }
  5511. }
  5512. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  5513. if ($fitcell) {
  5514. // restore font size
  5515. $this->SetFontSize($prev_FontSizePt);
  5516. }
  5517. }
  5518. if ($autopadding) {
  5519. // add bottom padding
  5520. $this->y += $mc_padding['B'];
  5521. }
  5522. // Get end-of-text Y position
  5523. $currentY = $this->y;
  5524. // get latest page number
  5525. $endpage = $this->page;
  5526. if ($resth > 0) {
  5527. $skip = ($endpage - $startpage);
  5528. $tmpresth = $resth;
  5529. while ($tmpresth > 0) {
  5530. if ($skip <= 0) {
  5531. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5532. $this->checkPageBreak($this->PageBreakTrigger + 1);
  5533. }
  5534. if ($this->num_columns > 1) {
  5535. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  5536. } else {
  5537. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  5538. }
  5539. --$skip;
  5540. }
  5541. $currentY = $this->y;
  5542. $endpage = $this->page;
  5543. }
  5544. // get latest column
  5545. $endcolumn = $this->current_column;
  5546. if ($this->num_columns == 0) {
  5547. $this->num_columns = 1;
  5548. }
  5549. // disable page regions check
  5550. $check_page_regions = $this->check_page_regions;
  5551. $this->check_page_regions = false;
  5552. // get border modes
  5553. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  5554. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  5555. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  5556. // design borders around HTML cells.
  5557. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  5558. $ccode = '';
  5559. $this->setPage($page);
  5560. if ($this->num_columns < 2) {
  5561. // single-column mode
  5562. $this->SetX($x);
  5563. $this->y = $this->tMargin;
  5564. }
  5565. // account for margin changes
  5566. if ($page > $startpage) {
  5567. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5568. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5569. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5570. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5571. }
  5572. }
  5573. if ($startpage == $endpage) {
  5574. // single page
  5575. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  5576. if ($column != $this->current_column) {
  5577. $this->selectColumn($column);
  5578. }
  5579. if ($this->rtl) {
  5580. $this->x -= $mc_margin['R'];
  5581. } else {
  5582. $this->x += $mc_margin['L'];
  5583. }
  5584. if ($startcolumn == $endcolumn) { // single column
  5585. $cborder = $border;
  5586. $h = max($h, ($currentY - $oy));
  5587. $this->y = $oy;
  5588. } elseif ($column == $startcolumn) { // first column
  5589. $cborder = $border_start;
  5590. $this->y = $oy;
  5591. $h = $this->h - $this->y - $this->bMargin;
  5592. } elseif ($column == $endcolumn) { // end column
  5593. $cborder = $border_end;
  5594. $h = $currentY - $this->y;
  5595. if ($resth > $h) {
  5596. $h = $resth;
  5597. }
  5598. } else { // middle column
  5599. $cborder = $border_middle;
  5600. $h = $this->h - $this->y - $this->bMargin;
  5601. $resth -= $h;
  5602. }
  5603. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5604. } // end for each column
  5605. } elseif ($page == $startpage) { // first page
  5606. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  5607. if ($column != $this->current_column) {
  5608. $this->selectColumn($column);
  5609. }
  5610. if ($this->rtl) {
  5611. $this->x -= $mc_margin['R'];
  5612. } else {
  5613. $this->x += $mc_margin['L'];
  5614. }
  5615. if ($column == $startcolumn) { // first column
  5616. $cborder = $border_start;
  5617. $this->y = $oy;
  5618. $h = $this->h - $this->y - $this->bMargin;
  5619. } else { // middle column
  5620. $cborder = $border_middle;
  5621. $h = $this->h - $this->y - $this->bMargin;
  5622. $resth -= $h;
  5623. }
  5624. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5625. } // end for each column
  5626. } elseif ($page == $endpage) { // last page
  5627. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  5628. if ($column != $this->current_column) {
  5629. $this->selectColumn($column);
  5630. }
  5631. if ($this->rtl) {
  5632. $this->x -= $mc_margin['R'];
  5633. } else {
  5634. $this->x += $mc_margin['L'];
  5635. }
  5636. if ($column == $endcolumn) {
  5637. // end column
  5638. $cborder = $border_end;
  5639. $h = $currentY - $this->y;
  5640. if ($resth > $h) {
  5641. $h = $resth;
  5642. }
  5643. } else {
  5644. // middle column
  5645. $cborder = $border_middle;
  5646. $h = $this->h - $this->y - $this->bMargin;
  5647. $resth -= $h;
  5648. }
  5649. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5650. } // end for each column
  5651. } else { // middle page
  5652. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  5653. $this->selectColumn($column);
  5654. if ($this->rtl) {
  5655. $this->x -= $mc_margin['R'];
  5656. } else {
  5657. $this->x += $mc_margin['L'];
  5658. }
  5659. $cborder = $border_middle;
  5660. $h = $this->h - $this->y - $this->bMargin;
  5661. $resth -= $h;
  5662. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5663. } // end for each column
  5664. }
  5665. if ($cborder OR $fill) {
  5666. $offsetlen = strlen($ccode);
  5667. // draw border and fill
  5668. if ($this->inxobj) {
  5669. // we are inside an XObject template
  5670. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5671. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  5672. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5673. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  5674. } else {
  5675. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  5676. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  5677. }
  5678. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  5679. $pstart = substr($pagebuff, 0, $pagemark);
  5680. $pend = substr($pagebuff, $pagemark);
  5681. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5682. } else {
  5683. if (end($this->transfmrk[$this->page]) !== false) {
  5684. $pagemarkkey = key($this->transfmrk[$this->page]);
  5685. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  5686. $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  5687. } elseif ($this->InFooter) {
  5688. $pagemark = $this->footerpos[$this->page];
  5689. $this->footerpos[$this->page] += $offsetlen;
  5690. } else {
  5691. $pagemark = $this->intmrk[$this->page];
  5692. $this->intmrk[$this->page] += $offsetlen;
  5693. }
  5694. $pagebuff = $this->getPageBuffer($this->page);
  5695. $pstart = substr($pagebuff, 0, $pagemark);
  5696. $pend = substr($pagebuff, $pagemark);
  5697. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  5698. }
  5699. }
  5700. } // end for each page
  5701. // restore page regions check
  5702. $this->check_page_regions = $check_page_regions;
  5703. // Get end-of-cell Y position
  5704. $currentY = $this->GetY();
  5705. // restore previous values
  5706. if ($this->num_columns > 1) {
  5707. $this->selectColumn();
  5708. } else {
  5709. // restore original margins
  5710. $this->lMargin = $lMargin;
  5711. $this->rMargin = $rMargin;
  5712. if ($this->page > $startpage) {
  5713. // check for margin variations between pages (i.e. booklet mode)
  5714. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  5715. $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  5716. if (($dl != 0) OR ($dr != 0)) {
  5717. $this->lMargin += $dl;
  5718. $this->rMargin += $dr;
  5719. }
  5720. }
  5721. }
  5722. if ($ln > 0) {
  5723. //Go to the beginning of the next line
  5724. $this->SetY($currentY + $mc_margin['B']);
  5725. if ($ln == 2) {
  5726. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5727. }
  5728. } else {
  5729. // go left or right by case
  5730. $this->setPage($startpage);
  5731. $this->y = $y;
  5732. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5733. }
  5734. $this->setContentMark();
  5735. $this->cell_padding = $prev_cell_padding;
  5736. $this->cell_margin = $prev_cell_margin;
  5737. $this->clMargin = $this->lMargin;
  5738. $this->crMargin = $this->rMargin;
  5739. return $nl;
  5740. }
  5741. /**
  5742. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  5743. * @param $txt (string) String for calculating his height
  5744. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5745. * @param $reseth (boolean) if true reset the last cell height (default false).
  5746. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  5747. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  5748. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5749. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5750. * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
  5751. * @public
  5752. * @since 4.5.011
  5753. */
  5754. public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  5755. if ($txt === NULL) {
  5756. return 0;
  5757. }
  5758. if ($txt === '') {
  5759. // empty string
  5760. return 1;
  5761. }
  5762. // adjust internal padding
  5763. $prev_cell_padding = $this->cell_padding;
  5764. $prev_lasth = $this->lasth;
  5765. if (is_array($cellpadding)) {
  5766. $this->cell_padding = $cellpadding;
  5767. }
  5768. $this->adjustCellPadding($border);
  5769. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5770. if ($this->rtl) {
  5771. $w = $this->x - $this->lMargin;
  5772. } else {
  5773. $w = $this->w - $this->rMargin - $this->x;
  5774. }
  5775. }
  5776. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5777. if ($reseth) {
  5778. // reset row height
  5779. $this->resetLastH();
  5780. }
  5781. $lines = 1;
  5782. $sum = 0;
  5783. $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5784. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  5785. $length = count($chars);
  5786. $lastSeparator = -1;
  5787. for ($i = 0; $i < $length; ++$i) {
  5788. $c = $chars[$i];
  5789. $charWidth = $charsWidth[$i];
  5790. if (($c != 160)
  5791. AND (($c == 173)
  5792. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  5793. OR (($c == 45)
  5794. AND ($i > 0) AND ($i < ($length - 1))
  5795. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i - 1)], $this->isunicode))
  5796. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  5797. )
  5798. )
  5799. ) {
  5800. $lastSeparator = $i;
  5801. }
  5802. if ((($sum + $charWidth) > $wmax) OR ($c == 10)) {
  5803. ++$lines;
  5804. if ($c == 10) {
  5805. $lastSeparator = -1;
  5806. $sum = 0;
  5807. } elseif ($lastSeparator != -1) {
  5808. $i = $lastSeparator;
  5809. $lastSeparator = -1;
  5810. $sum = 0;
  5811. } else {
  5812. $sum = $charWidth;
  5813. }
  5814. } else {
  5815. $sum += $charWidth;
  5816. }
  5817. }
  5818. if ($chars[($length - 1)] == 10) {
  5819. --$lines;
  5820. }
  5821. $this->cell_padding = $prev_cell_padding;
  5822. $this->lasth = $prev_lasth;
  5823. return $lines;
  5824. }
  5825. /**
  5826. * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  5827. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  5828. * @pre
  5829. * // store current object
  5830. * $pdf->startTransaction();
  5831. * // store starting values
  5832. * $start_y = $pdf->GetY();
  5833. * $start_page = $pdf->getPage();
  5834. * // call your printing functions with your parameters
  5835. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5836. * $pdf->MultiCell($w=0, $h=0, $txt, $border=1, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
  5837. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5838. * // get the new Y
  5839. * $end_y = $pdf->GetY();
  5840. * $end_page = $pdf->getPage();
  5841. * // calculate height
  5842. * $height = 0;
  5843. * if ($end_page == $start_page) {
  5844. * $height = $end_y - $start_y;
  5845. * } else {
  5846. * for ($page=$start_page; $page <= $end_page; ++$page) {
  5847. * $this->setPage($page);
  5848. * if ($page == $start_page) {
  5849. * // first page
  5850. * $height = $this->h - $start_y - $this->bMargin;
  5851. * } elseif ($page == $end_page) {
  5852. * // last page
  5853. * $height = $end_y - $this->tMargin;
  5854. * } else {
  5855. * $height = $this->h - $this->tMargin - $this->bMargin;
  5856. * }
  5857. * }
  5858. * }
  5859. * // restore previous object
  5860. * $pdf = $pdf->rollbackTransaction();
  5861. *
  5862. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5863. * @param $txt (string) String for calculating his height
  5864. * @param $reseth (boolean) if true reset the last cell height (default false).
  5865. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  5866. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  5867. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5868. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5869. * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
  5870. * @public
  5871. */
  5872. public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  5873. // adjust internal padding
  5874. $prev_cell_padding = $this->cell_padding;
  5875. $prev_lasth = $this->lasth;
  5876. if (is_array($cellpadding)) {
  5877. $this->cell_padding = $cellpadding;
  5878. }
  5879. $this->adjustCellPadding($border);
  5880. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  5881. $height = $this->getCellHeight(($lines * $this->FontSize), $autopadding);
  5882. $this->cell_padding = $prev_cell_padding;
  5883. $this->lasth = $prev_lasth;
  5884. return $height;
  5885. }
  5886. /**
  5887. * This method prints text from the current position.<br />
  5888. * @param $h (float) Line height
  5889. * @param $txt (string) String to print
  5890. * @param $link (mixed) URL or identifier returned by AddLink()
  5891. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5892. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  5893. * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  5894. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  5895. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  5896. * @param $firstblock (boolean) if true the string is the starting of a line.
  5897. * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
  5898. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
  5899. * @param $margin (array) margin array of the parent container
  5900. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  5901. * @public
  5902. * @since 1.5
  5903. */
  5904. public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
  5905. // check page for no-write regions and adapt page margins if necessary
  5906. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  5907. if (strlen($txt) == 0) {
  5908. // fix empty text
  5909. $txt = ' ';
  5910. }
  5911. if ($margin === '') {
  5912. // set default margins
  5913. $margin = $this->cell_margin;
  5914. }
  5915. // remove carriage returns
  5916. $s = str_replace("\r", '', $txt);
  5917. // check if string contains arabic text
  5918. if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $s)) {
  5919. $arabic = true;
  5920. } else {
  5921. $arabic = false;
  5922. }
  5923. // check if string contains RTL text
  5924. if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $s)) {
  5925. $rtlmode = true;
  5926. } else {
  5927. $rtlmode = false;
  5928. }
  5929. // get a char width
  5930. $chrwidth = $this->GetCharWidth(46); // dot character
  5931. // get array of unicode values
  5932. $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont);
  5933. // calculate maximum width for a single character on string
  5934. $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
  5935. array_walk($chrw, array($this, 'getRawCharWidth'));
  5936. $maxchwidth = max($chrw);
  5937. // get array of chars
  5938. $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode);
  5939. // get the number of characters
  5940. $nb = count($chars);
  5941. // replacement for SHY character (minus symbol)
  5942. $shy_replacement = 45;
  5943. $shy_replacement_char = TCPDF_FONTS::unichr($shy_replacement, $this->isunicode);
  5944. // widht for SHY replacement
  5945. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  5946. // page width
  5947. $pw = $w = $this->w - $this->lMargin - $this->rMargin;
  5948. // calculate remaining line width ($w)
  5949. if ($this->rtl) {
  5950. $w = $this->x - $this->lMargin;
  5951. } else {
  5952. $w = $this->w - $this->rMargin - $this->x;
  5953. }
  5954. // max column width
  5955. $wmax = ($w - $wadj);
  5956. if (!$firstline) {
  5957. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  5958. }
  5959. if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
  5960. // the maximum width character do not fit on column
  5961. return '';
  5962. }
  5963. // minimum row height
  5964. $row_height = max($h, $this->getCellHeight($this->FontSize));
  5965. // max Y
  5966. $maxy = $this->y + $maxh - max($row_height, $h);
  5967. $start_page = $this->page;
  5968. $i = 0; // character position
  5969. $j = 0; // current starting position
  5970. $sep = -1; // position of the last blank space
  5971. $prevsep = $sep; // previous separator
  5972. $shy = false; // true if the last blank is a soft hypen (SHY)
  5973. $prevshy = $shy; // previous shy mode
  5974. $l = 0; // current string length
  5975. $nl = 0; //number of lines
  5976. $linebreak = false;
  5977. $pc = 0; // previous character
  5978. // for each character
  5979. while ($i < $nb) {
  5980. if (($maxh > 0) AND ($this->y > $maxy) ) {
  5981. break;
  5982. }
  5983. //Get the current character
  5984. $c = $chars[$i];
  5985. if ($c == 10) { // 10 = "\n" = new line
  5986. //Explicit line break
  5987. if ($align == 'J') {
  5988. if ($this->rtl) {
  5989. $talign = 'R';
  5990. } else {
  5991. $talign = 'L';
  5992. }
  5993. } else {
  5994. $talign = $align;
  5995. }
  5996. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  5997. if ($firstline) {
  5998. $startx = $this->x;
  5999. $tmparr = array_slice($chars, $j, ($i - $j));
  6000. if ($rtlmode) {
  6001. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6002. }
  6003. $linew = $this->GetArrStringWidth($tmparr);
  6004. unset($tmparr);
  6005. if ($this->rtl) {
  6006. $this->endlinex = $startx - $linew;
  6007. } else {
  6008. $this->endlinex = $startx + $linew;
  6009. }
  6010. $w = $linew;
  6011. $tmpcellpadding = $this->cell_padding;
  6012. if ($maxh == 0) {
  6013. $this->SetCellPadding(0);
  6014. }
  6015. }
  6016. if ($firstblock AND $this->isRTLTextDir()) {
  6017. $tmpstr = $this->stringRightTrim($tmpstr);
  6018. }
  6019. // Skip newlines at the beginning of a page or column
  6020. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  6021. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  6022. }
  6023. unset($tmpstr);
  6024. if ($firstline) {
  6025. $this->cell_padding = $tmpcellpadding;
  6026. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6027. }
  6028. ++$nl;
  6029. $j = $i + 1;
  6030. $l = 0;
  6031. $sep = -1;
  6032. $prevsep = $sep;
  6033. $shy = false;
  6034. // account for margin changes
  6035. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6036. $this->AcceptPageBreak();
  6037. if ($this->rtl) {
  6038. $this->x -= $margin['R'];
  6039. } else {
  6040. $this->x += $margin['L'];
  6041. }
  6042. $this->lMargin += $margin['L'];
  6043. $this->rMargin += $margin['R'];
  6044. }
  6045. $w = $this->getRemainingWidth();
  6046. $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
  6047. } else {
  6048. // 160 is the non-breaking space.
  6049. // 173 is SHY (Soft Hypen).
  6050. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6051. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6052. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6053. if (($c != 160)
  6054. AND (($c == 173)
  6055. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  6056. OR (($c == 45)
  6057. AND ($i < ($nb - 1))
  6058. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc, $this->isunicode))
  6059. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  6060. )
  6061. )
  6062. ) {
  6063. // update last blank space position
  6064. $prevsep = $sep;
  6065. $sep = $i;
  6066. // check if is a SHY
  6067. if (($c == 173) OR ($c == 45)) {
  6068. $prevshy = $shy;
  6069. $shy = true;
  6070. if ($pc == 45) {
  6071. $tmp_shy_replacement_width = 0;
  6072. $tmp_shy_replacement_char = '';
  6073. } else {
  6074. $tmp_shy_replacement_width = $shy_replacement_width;
  6075. $tmp_shy_replacement_char = $shy_replacement_char;
  6076. }
  6077. } else {
  6078. $shy = false;
  6079. }
  6080. }
  6081. // update string length
  6082. if ($this->isUnicodeFont() AND ($arabic)) {
  6083. // with bidirectional algorithm some chars may be changed affecting the line length
  6084. // *** very slow ***
  6085. $l = $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl, $this->isunicode, $this->CurrentFont));
  6086. } else {
  6087. $l += $this->GetCharWidth($c);
  6088. }
  6089. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) >= $wmax))) {
  6090. if (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) {
  6091. $sep = $prevsep;
  6092. $shy = $prevshy;
  6093. }
  6094. // we have reached the end of column
  6095. if ($sep == -1) {
  6096. // check if the line was already started
  6097. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  6098. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  6099. // print a void cell and go to next line
  6100. $this->Cell($w, $h, '', 0, 1);
  6101. $linebreak = true;
  6102. if ($firstline) {
  6103. return (TCPDF_FONTS::UniArrSubString($uchars, $j));
  6104. }
  6105. } else {
  6106. // truncate the word because do not fit on column
  6107. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6108. if ($firstline) {
  6109. $startx = $this->x;
  6110. $tmparr = array_slice($chars, $j, ($i - $j));
  6111. if ($rtlmode) {
  6112. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6113. }
  6114. $linew = $this->GetArrStringWidth($tmparr);
  6115. unset($tmparr);
  6116. if ($this->rtl) {
  6117. $this->endlinex = $startx - $linew;
  6118. } else {
  6119. $this->endlinex = $startx + $linew;
  6120. }
  6121. $w = $linew;
  6122. $tmpcellpadding = $this->cell_padding;
  6123. if ($maxh == 0) {
  6124. $this->SetCellPadding(0);
  6125. }
  6126. }
  6127. if ($firstblock AND $this->isRTLTextDir()) {
  6128. $tmpstr = $this->stringRightTrim($tmpstr);
  6129. }
  6130. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6131. unset($tmpstr);
  6132. if ($firstline) {
  6133. $this->cell_padding = $tmpcellpadding;
  6134. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6135. }
  6136. $j = $i;
  6137. --$i;
  6138. }
  6139. } else {
  6140. // word wrapping
  6141. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  6142. $endspace = 1;
  6143. } else {
  6144. $endspace = 0;
  6145. }
  6146. // check the length of the next string
  6147. $strrest = TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace));
  6148. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $this->stringTrim($strrest));
  6149. if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  6150. // truncate the word because do not fit on a full page width
  6151. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6152. if ($firstline) {
  6153. $startx = $this->x;
  6154. $tmparr = array_slice($chars, $j, ($i - $j));
  6155. if ($rtlmode) {
  6156. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6157. }
  6158. $linew = $this->GetArrStringWidth($tmparr);
  6159. unset($tmparr);
  6160. if ($this->rtl) {
  6161. $this->endlinex = ($startx - $linew);
  6162. } else {
  6163. $this->endlinex = ($startx + $linew);
  6164. }
  6165. $w = $linew;
  6166. $tmpcellpadding = $this->cell_padding;
  6167. if ($maxh == 0) {
  6168. $this->SetCellPadding(0);
  6169. }
  6170. }
  6171. if ($firstblock AND $this->isRTLTextDir()) {
  6172. $tmpstr = $this->stringRightTrim($tmpstr);
  6173. }
  6174. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6175. unset($tmpstr);
  6176. if ($firstline) {
  6177. $this->cell_padding = $tmpcellpadding;
  6178. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6179. }
  6180. $j = $i;
  6181. --$i;
  6182. } else {
  6183. // word wrapping
  6184. if ($shy) {
  6185. // add hypen (minus symbol) at the end of the line
  6186. $shy_width = $tmp_shy_replacement_width;
  6187. if ($this->rtl) {
  6188. $shy_char_left = $tmp_shy_replacement_char;
  6189. $shy_char_right = '';
  6190. } else {
  6191. $shy_char_left = '';
  6192. $shy_char_right = $tmp_shy_replacement_char;
  6193. }
  6194. } else {
  6195. $shy_width = 0;
  6196. $shy_char_left = '';
  6197. $shy_char_right = '';
  6198. }
  6199. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, ($sep + $endspace));
  6200. if ($firstline) {
  6201. $startx = $this->x;
  6202. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  6203. if ($rtlmode) {
  6204. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6205. }
  6206. $linew = $this->GetArrStringWidth($tmparr);
  6207. unset($tmparr);
  6208. if ($this->rtl) {
  6209. $this->endlinex = $startx - $linew - $shy_width;
  6210. } else {
  6211. $this->endlinex = $startx + $linew + $shy_width;
  6212. }
  6213. $w = $linew;
  6214. $tmpcellpadding = $this->cell_padding;
  6215. if ($maxh == 0) {
  6216. $this->SetCellPadding(0);
  6217. }
  6218. }
  6219. // print the line
  6220. if ($firstblock AND $this->isRTLTextDir()) {
  6221. $tmpstr = $this->stringRightTrim($tmpstr);
  6222. }
  6223. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  6224. unset($tmpstr);
  6225. if ($firstline) {
  6226. if ($chars[$sep] == 45) {
  6227. $endspace += 1;
  6228. }
  6229. // return the remaining text
  6230. $this->cell_padding = $tmpcellpadding;
  6231. return (TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace)));
  6232. }
  6233. $i = $sep;
  6234. $sep = -1;
  6235. $shy = false;
  6236. $j = ($i + 1);
  6237. }
  6238. }
  6239. // account for margin changes
  6240. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6241. $this->AcceptPageBreak();
  6242. if ($this->rtl) {
  6243. $this->x -= $margin['R'];
  6244. } else {
  6245. $this->x += $margin['L'];
  6246. }
  6247. $this->lMargin += $margin['L'];
  6248. $this->rMargin += $margin['R'];
  6249. }
  6250. $w = $this->getRemainingWidth();
  6251. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6252. if ($linebreak) {
  6253. $linebreak = false;
  6254. } else {
  6255. ++$nl;
  6256. $l = 0;
  6257. }
  6258. }
  6259. }
  6260. // save last character
  6261. $pc = $c;
  6262. ++$i;
  6263. } // end while i < nb
  6264. // print last substring (if any)
  6265. if ($l > 0) {
  6266. switch ($align) {
  6267. case 'J':
  6268. case 'C': {
  6269. $w = $w;
  6270. break;
  6271. }
  6272. case 'L': {
  6273. if ($this->rtl) {
  6274. $w = $w;
  6275. } else {
  6276. $w = $l;
  6277. }
  6278. break;
  6279. }
  6280. case 'R': {
  6281. if ($this->rtl) {
  6282. $w = $l;
  6283. } else {
  6284. $w = $w;
  6285. }
  6286. break;
  6287. }
  6288. default: {
  6289. $w = $l;
  6290. break;
  6291. }
  6292. }
  6293. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $nb);
  6294. if ($firstline) {
  6295. $startx = $this->x;
  6296. $tmparr = array_slice($chars, $j, ($nb - $j));
  6297. if ($rtlmode) {
  6298. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6299. }
  6300. $linew = $this->GetArrStringWidth($tmparr);
  6301. unset($tmparr);
  6302. if ($this->rtl) {
  6303. $this->endlinex = $startx - $linew;
  6304. } else {
  6305. $this->endlinex = $startx + $linew;
  6306. }
  6307. $w = $linew;
  6308. $tmpcellpadding = $this->cell_padding;
  6309. if ($maxh == 0) {
  6310. $this->SetCellPadding(0);
  6311. }
  6312. }
  6313. if ($firstblock AND $this->isRTLTextDir()) {
  6314. $tmpstr = $this->stringRightTrim($tmpstr);
  6315. }
  6316. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  6317. unset($tmpstr);
  6318. if ($firstline) {
  6319. $this->cell_padding = $tmpcellpadding;
  6320. return (TCPDF_FONTS::UniArrSubString($uchars, $nb));
  6321. }
  6322. ++$nl;
  6323. }
  6324. if ($firstline) {
  6325. return '';
  6326. }
  6327. return $nl;
  6328. }
  6329. /**
  6330. * Returns the remaining width between the current position and margins.
  6331. * @return int Return the remaining width
  6332. * @protected
  6333. */
  6334. protected function getRemainingWidth() {
  6335. list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
  6336. if ($this->rtl) {
  6337. return ($this->x - $this->lMargin);
  6338. } else {
  6339. return ($this->w - $this->rMargin - $this->x);
  6340. }
  6341. }
  6342. /**
  6343. * Set the block dimensions accounting for page breaks and page/column fitting
  6344. * @param $w (float) width
  6345. * @param $h (float) height
  6346. * @param $x (float) X coordinate
  6347. * @param $y (float) Y coodiante
  6348. * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
  6349. * @return array($w, $h, $x, $y)
  6350. * @protected
  6351. * @since 5.5.009 (2010-07-05)
  6352. */
  6353. protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
  6354. if ($w <= 0) {
  6355. // set maximum width
  6356. $w = ($this->w - $this->lMargin - $this->rMargin);
  6357. if ($w <= 0) {
  6358. $w = 1;
  6359. }
  6360. }
  6361. if ($h <= 0) {
  6362. // set maximum height
  6363. $h = ($this->PageBreakTrigger - $this->tMargin);
  6364. if ($h <= 0) {
  6365. $h = 1;
  6366. }
  6367. }
  6368. // resize the block to be vertically contained on a single page or single column
  6369. if ($fitonpage OR $this->AutoPageBreak) {
  6370. $ratio_wh = ($w / $h);
  6371. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  6372. $h = $this->PageBreakTrigger - $this->tMargin;
  6373. $w = ($h * $ratio_wh);
  6374. }
  6375. // resize the block to be horizontally contained on a single page or single column
  6376. if ($fitonpage) {
  6377. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  6378. if ($w > $maxw) {
  6379. $w = $maxw;
  6380. $h = ($w / $ratio_wh);
  6381. }
  6382. }
  6383. }
  6384. // Check whether we need a new page or new column first as this does not fit
  6385. $prev_x = $this->x;
  6386. $prev_y = $this->y;
  6387. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  6388. $y = $this->y;
  6389. if ($this->rtl) {
  6390. $x += ($prev_x - $this->x);
  6391. } else {
  6392. $x += ($this->x - $prev_x);
  6393. }
  6394. $this->newline = true;
  6395. }
  6396. // resize the block to be contained on the remaining available page or column space
  6397. if ($fitonpage) {
  6398. $ratio_wh = ($w / $h);
  6399. if (($y + $h) > $this->PageBreakTrigger) {
  6400. $h = $this->PageBreakTrigger - $y;
  6401. $w = ($h * $ratio_wh);
  6402. }
  6403. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  6404. $w = $this->w - $this->rMargin - $x;
  6405. $h = ($w / $ratio_wh);
  6406. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  6407. $w = $x - $this->lMargin;
  6408. $h = ($w / $ratio_wh);
  6409. }
  6410. }
  6411. return array($w, $h, $x, $y);
  6412. }
  6413. /**
  6414. * Puts an image in the page.
  6415. * The upper-left corner must be given.
  6416. * The dimensions can be specified in different ways:<ul>
  6417. * <li>explicit width and height (expressed in user unit)</li>
  6418. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6419. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6420. * Supported formats are JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;
  6421. * The format can be specified explicitly or inferred from the file extension.<br />
  6422. * It is possible to put a link on the image.<br />
  6423. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6424. * @param $file (string) Name of the file containing the image or a '@' character followed by the image data string. To link an image without embedding it on the document, set an asterisk character before the URL (i.e.: '*http://www.example.com/image.jpg').
  6425. * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6426. * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6427. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6428. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6429. * @param $type (string) Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  6430. * @param $link (mixed) URL or identifier returned by AddLink().
  6431. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  6432. * @param $resize (mixed) If true resize (reduce) the image to fit $w and $h (requires GD or ImageMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
  6433. * @param $dpi (int) dot-per-inch resolution used on resize
  6434. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  6435. * @param $ismask (boolean) true if this image is a mask, false otherwise
  6436. * @param $imgmask (mixed) image object returned by this function or false
  6437. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6438. * @param $fitbox (mixed) If not false scale image dimensions proportionally to fit within the ($w, $h) box. $fitbox can be true or a 2 characters string indicating the image alignment inside the box. The first character indicate the horizontal alignment (L = left, C = center, R = right) the second character indicate the vertical algnment (T = top, M = middle, B = bottom).
  6439. * @param $hidden (boolean) If true do not display the image.
  6440. * @param $fitonpage (boolean) If true the image is resized to not exceed page dimensions.
  6441. * @param $alt (boolean) If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  6442. * @param $altimgs (array) Array of alternate images IDs. Each alternative image must be an array with two values: an integer representing the image ID (the value returned by the Image method) and a boolean value to indicate if the image is the default for printing.
  6443. * @return image information
  6444. * @public
  6445. * @since 1.1
  6446. */
  6447. 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()) {
  6448. if ($this->state != 2) {
  6449. return;
  6450. }
  6451. if (strcmp($x, '') === 0) {
  6452. $x = $this->x;
  6453. }
  6454. if (strcmp($y, '') === 0) {
  6455. $y = $this->y;
  6456. }
  6457. // check page for no-write regions and adapt page margins if necessary
  6458. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  6459. $exurl = ''; // external streams
  6460. $imsize = FALSE;
  6461. // check if we are passing an image as file or string
  6462. if ($file[0] === '@') {
  6463. // image from string
  6464. $imgdata = substr($file, 1);
  6465. } else { // image file
  6466. if ($file[0] === '*') {
  6467. // image as external stream
  6468. $file = substr($file, 1);
  6469. $exurl = $file;
  6470. }
  6471. // check if file exist and it is valid
  6472. if (!@TCPDF_STATIC::file_exists($file)) {
  6473. return false;
  6474. }
  6475. if (($imsize = @getimagesize($file)) === FALSE) {
  6476. if (in_array($file, $this->imagekeys)) {
  6477. // get existing image data
  6478. $info = $this->getImageBuffer($file);
  6479. $imsize = array($info['w'], $info['h']);
  6480. } elseif (strpos($file, '__tcpdf_'.$this->file_id.'_img') === FALSE) {
  6481. $imgdata = TCPDF_STATIC::fileGetContents($file);
  6482. }
  6483. }
  6484. }
  6485. if (!empty($imgdata)) {
  6486. // copy image to cache
  6487. $original_file = $file;
  6488. $file = TCPDF_STATIC::getObjFilename('img', $this->file_id);
  6489. $fp = TCPDF_STATIC::fopenLocal($file, 'w');
  6490. if (!$fp) {
  6491. $this->Error('Unable to write file: '.$file);
  6492. }
  6493. fwrite($fp, $imgdata);
  6494. fclose($fp);
  6495. unset($imgdata);
  6496. $imsize = @getimagesize($file);
  6497. if ($imsize === FALSE) {
  6498. unlink($file);
  6499. $file = $original_file;
  6500. }
  6501. }
  6502. if ($imsize === FALSE) {
  6503. if (($w > 0) AND ($h > 0)) {
  6504. // get measures from specified data
  6505. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6506. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6507. $imsize = array($pw, $ph);
  6508. } else {
  6509. $this->Error('[Image] Unable to get the size of the image: '.$file);
  6510. }
  6511. }
  6512. // file hash
  6513. $filehash = md5($file);
  6514. // get original image width and height in pixels
  6515. list($pixw, $pixh) = $imsize;
  6516. // calculate image width and height on document
  6517. if (($w <= 0) AND ($h <= 0)) {
  6518. // convert image size to document unit
  6519. $w = $this->pixelsToUnits($pixw);
  6520. $h = $this->pixelsToUnits($pixh);
  6521. } elseif ($w <= 0) {
  6522. $w = $h * $pixw / $pixh;
  6523. } elseif ($h <= 0) {
  6524. $h = $w * $pixh / $pixw;
  6525. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  6526. if (strlen($fitbox) !== 2) {
  6527. // set default alignment
  6528. $fitbox = '--';
  6529. }
  6530. // scale image dimensions proportionally to fit within the ($w, $h) box
  6531. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  6532. // store current height
  6533. $oldh = $h;
  6534. // calculate new height
  6535. $h = $w * $pixh / $pixw;
  6536. // height difference
  6537. $hdiff = ($oldh - $h);
  6538. // vertical alignment
  6539. switch (strtoupper($fitbox[1])) {
  6540. case 'T': {
  6541. break;
  6542. }
  6543. case 'M': {
  6544. $y += ($hdiff / 2);
  6545. break;
  6546. }
  6547. case 'B': {
  6548. $y += $hdiff;
  6549. break;
  6550. }
  6551. }
  6552. } else {
  6553. // store current width
  6554. $oldw = $w;
  6555. // calculate new width
  6556. $w = $h * $pixw / $pixh;
  6557. // width difference
  6558. $wdiff = ($oldw - $w);
  6559. // horizontal alignment
  6560. switch (strtoupper($fitbox[0])) {
  6561. case 'L': {
  6562. if ($this->rtl) {
  6563. $x -= $wdiff;
  6564. }
  6565. break;
  6566. }
  6567. case 'C': {
  6568. if ($this->rtl) {
  6569. $x -= ($wdiff / 2);
  6570. } else {
  6571. $x += ($wdiff / 2);
  6572. }
  6573. break;
  6574. }
  6575. case 'R': {
  6576. if (!$this->rtl) {
  6577. $x += $wdiff;
  6578. }
  6579. break;
  6580. }
  6581. }
  6582. }
  6583. }
  6584. // fit the image on available space
  6585. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  6586. // calculate new minimum dimensions in pixels
  6587. $neww = round($w * $this->k * $dpi / $this->dpi);
  6588. $newh = round($h * $this->k * $dpi / $this->dpi);
  6589. // check if resize is necessary (resize is used only to reduce the image)
  6590. $newsize = ($neww * $newh);
  6591. $pixsize = ($pixw * $pixh);
  6592. if (intval($resize) == 2) {
  6593. $resize = true;
  6594. } elseif ($newsize >= $pixsize) {
  6595. $resize = false;
  6596. }
  6597. // check if image has been already added on document
  6598. $newimage = true;
  6599. if (in_array($file, $this->imagekeys)) {
  6600. $newimage = false;
  6601. // get existing image data
  6602. $info = $this->getImageBuffer($file);
  6603. if (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE) {
  6604. // check if the newer image is larger
  6605. $oldsize = ($info['w'] * $info['h']);
  6606. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6607. $newimage = true;
  6608. }
  6609. }
  6610. } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)) {
  6611. // create temp image file (without alpha channel)
  6612. $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6613. // create temp alpha file
  6614. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6615. // check for cached images
  6616. if (in_array($tempfile_plain, $this->imagekeys)) {
  6617. // get existing image data
  6618. $info = $this->getImageBuffer($tempfile_plain);
  6619. // check if the newer image is larger
  6620. $oldsize = ($info['w'] * $info['h']);
  6621. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6622. $newimage = true;
  6623. } else {
  6624. $newimage = false;
  6625. // embed mask image
  6626. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6627. // embed image, masked with previously embedded mask
  6628. return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6629. }
  6630. }
  6631. }
  6632. if ($newimage) {
  6633. //First use of image, get info
  6634. $type = strtolower($type);
  6635. if ($type == '') {
  6636. $type = TCPDF_IMAGES::getImageFileType($file, $imsize);
  6637. } elseif ($type == 'jpg') {
  6638. $type = 'jpeg';
  6639. }
  6640. $mqr = TCPDF_STATIC::get_mqr();
  6641. TCPDF_STATIC::set_mqr(false);
  6642. // Specific image handlers (defined on TCPDF_IMAGES CLASS)
  6643. $mtd = '_parse'.$type;
  6644. // GD image handler function
  6645. $gdfunction = 'imagecreatefrom'.$type;
  6646. $info = false;
  6647. if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  6648. // TCPDF image functions
  6649. $info = TCPDF_IMAGES::$mtd($file);
  6650. if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)
  6651. AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
  6652. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
  6653. }
  6654. }
  6655. if (($info === false) AND function_exists($gdfunction)) {
  6656. try {
  6657. // GD library
  6658. $img = $gdfunction($file);
  6659. if ($img !== false) {
  6660. if ($resize) {
  6661. $imgr = imagecreatetruecolor($neww, $newh);
  6662. if (($type == 'gif') OR ($type == 'png')) {
  6663. $imgr = TCPDF_IMAGES::setGDImageTransparency($imgr, $img);
  6664. }
  6665. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  6666. $img = $imgr;
  6667. }
  6668. if (($type == 'gif') OR ($type == 'png')) {
  6669. $info = TCPDF_IMAGES::_toPNG($img, TCPDF_STATIC::getObjFilename('img', $this->file_id));
  6670. } else {
  6671. $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality, TCPDF_STATIC::getObjFilename('img', $this->file_id));
  6672. }
  6673. }
  6674. } catch(Exception $e) {
  6675. $info = false;
  6676. }
  6677. }
  6678. if (($info === false) AND extension_loaded('imagick')) {
  6679. try {
  6680. // ImageMagick library
  6681. $img = new Imagick();
  6682. if ($type == 'svg') {
  6683. if ($file[0] === '@') {
  6684. // image from string
  6685. $svgimg = substr($file, 1);
  6686. } else {
  6687. // get SVG file content
  6688. $svgimg = TCPDF_STATIC::fileGetContents($file);
  6689. }
  6690. if ($svgimg !== FALSE) {
  6691. // get width and height
  6692. $regs = array();
  6693. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  6694. $svgtag = $regs[1];
  6695. $tmp = array();
  6696. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6697. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6698. $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit;
  6699. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  6700. } else {
  6701. $ow = $w;
  6702. }
  6703. $tmp = array();
  6704. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6705. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6706. $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit;
  6707. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  6708. } else {
  6709. $oh = $h;
  6710. }
  6711. $tmp = array();
  6712. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  6713. $vbw = ($ow * $this->imgscale * $this->k);
  6714. $vbh = ($oh * $this->imgscale * $this->k);
  6715. $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
  6716. $svgtag = $vbox.$svgtag;
  6717. }
  6718. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  6719. }
  6720. $img->readImageBlob($svgimg);
  6721. }
  6722. } else {
  6723. $img->readImage($file);
  6724. }
  6725. if ($resize) {
  6726. $img->resizeImage($neww, $newh, 10, 1, false);
  6727. }
  6728. $img->setCompressionQuality($this->jpeg_quality);
  6729. $img->setImageFormat('jpeg');
  6730. $tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id);
  6731. $img->writeImage($tempname);
  6732. $info = TCPDF_IMAGES::_parsejpeg($tempname);
  6733. unlink($tempname);
  6734. $img->destroy();
  6735. } catch(Exception $e) {
  6736. $info = false;
  6737. }
  6738. }
  6739. if ($info === false) {
  6740. // unable to process image
  6741. return;
  6742. }
  6743. TCPDF_STATIC::set_mqr($mqr);
  6744. if ($ismask) {
  6745. // force grayscale
  6746. $info['cs'] = 'DeviceGray';
  6747. }
  6748. if ($imgmask !== false) {
  6749. $info['masked'] = $imgmask;
  6750. }
  6751. if (!empty($exurl)) {
  6752. $info['exurl'] = $exurl;
  6753. }
  6754. // array of alternative images
  6755. $info['altimgs'] = $altimgs;
  6756. // add image to document
  6757. $info['i'] = $this->setImageBuffer($file, $info);
  6758. }
  6759. // set alignment
  6760. $this->img_rb_y = $y + $h;
  6761. // set alignment
  6762. if ($this->rtl) {
  6763. if ($palign == 'L') {
  6764. $ximg = $this->lMargin;
  6765. } elseif ($palign == 'C') {
  6766. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6767. } elseif ($palign == 'R') {
  6768. $ximg = $this->w - $this->rMargin - $w;
  6769. } else {
  6770. $ximg = $x - $w;
  6771. }
  6772. $this->img_rb_x = $ximg;
  6773. } else {
  6774. if ($palign == 'L') {
  6775. $ximg = $this->lMargin;
  6776. } elseif ($palign == 'C') {
  6777. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6778. } elseif ($palign == 'R') {
  6779. $ximg = $this->w - $this->rMargin - $w;
  6780. } else {
  6781. $ximg = $x;
  6782. }
  6783. $this->img_rb_x = $ximg + $w;
  6784. }
  6785. if ($ismask OR $hidden) {
  6786. // image is not displayed
  6787. return $info['i'];
  6788. }
  6789. $xkimg = $ximg * $this->k;
  6790. if (!$alt) {
  6791. // only non-alternative immages will be set
  6792. $this->_out(sprintf('q %F 0 0 %F %F %F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
  6793. }
  6794. if (!empty($border)) {
  6795. $bx = $this->x;
  6796. $by = $this->y;
  6797. $this->x = $ximg;
  6798. if ($this->rtl) {
  6799. $this->x += $w;
  6800. }
  6801. $this->y = $y;
  6802. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  6803. $this->x = $bx;
  6804. $this->y = $by;
  6805. }
  6806. if ($link) {
  6807. $this->Link($ximg, $y, $w, $h, $link, 0);
  6808. }
  6809. // set pointer to align the next text/objects
  6810. switch($align) {
  6811. case 'T': {
  6812. $this->y = $y;
  6813. $this->x = $this->img_rb_x;
  6814. break;
  6815. }
  6816. case 'M': {
  6817. $this->y = $y + round($h/2);
  6818. $this->x = $this->img_rb_x;
  6819. break;
  6820. }
  6821. case 'B': {
  6822. $this->y = $this->img_rb_y;
  6823. $this->x = $this->img_rb_x;
  6824. break;
  6825. }
  6826. case 'N': {
  6827. $this->SetY($this->img_rb_y);
  6828. break;
  6829. }
  6830. default:{
  6831. break;
  6832. }
  6833. }
  6834. $this->endlinex = $this->img_rb_x;
  6835. if ($this->inxobj) {
  6836. // we are inside an XObject template
  6837. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  6838. }
  6839. return $info['i'];
  6840. }
  6841. /**
  6842. * Extract info from a PNG image with alpha channel using the Imagick or GD library.
  6843. * @param $file (string) Name of the file containing the image.
  6844. * @param $x (float) Abscissa of the upper-left corner.
  6845. * @param $y (float) Ordinate of the upper-left corner.
  6846. * @param $wpx (float) Original width of the image in pixels.
  6847. * @param $hpx (float) original height of the image in pixels.
  6848. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6849. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6850. * @param $type (string) Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  6851. * @param $link (mixed) URL or identifier returned by AddLink().
  6852. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  6853. * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
  6854. * @param $dpi (int) dot-per-inch resolution used on resize
  6855. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  6856. * @param $filehash (string) File hash used to build unique file names.
  6857. * @author Nicola Asuni
  6858. * @protected
  6859. * @since 4.3.007 (2008-12-04)
  6860. * @see Image()
  6861. */
  6862. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
  6863. // create temp images
  6864. if (empty($filehash)) {
  6865. $filehash = md5($file);
  6866. }
  6867. // create temp image file (without alpha channel)
  6868. $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6869. // create temp alpha file
  6870. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6871. $parsed = false;
  6872. $parse_error = '';
  6873. // ImageMagick extension
  6874. if (($parsed === false) AND extension_loaded('imagick')) {
  6875. try {
  6876. // ImageMagick library
  6877. $img = new Imagick();
  6878. $img->readImage($file);
  6879. // clone image object
  6880. $imga = TCPDF_STATIC::objclone($img);
  6881. // extract alpha channel
  6882. if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
  6883. $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
  6884. } else {
  6885. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  6886. $img->negateImage(true);
  6887. }
  6888. $img->setImageFormat('png');
  6889. $img->writeImage($tempfile_alpha);
  6890. // remove alpha channel
  6891. if (method_exists($imga, 'setImageMatte')) {
  6892. $imga->setImageMatte(false);
  6893. } else {
  6894. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  6895. }
  6896. $imga->setImageFormat('png');
  6897. $imga->writeImage($tempfile_plain);
  6898. $parsed = true;
  6899. } catch (Exception $e) {
  6900. // Imagemagick fails, try with GD
  6901. $parse_error = 'Imagick library error: '.$e->getMessage();
  6902. }
  6903. }
  6904. // GD extension
  6905. if (($parsed === false) AND function_exists('imagecreatefrompng')) {
  6906. try {
  6907. // generate images
  6908. $img = imagecreatefrompng($file);
  6909. $imgalpha = imagecreate($wpx, $hpx);
  6910. // generate gray scale palette (0 -> 255)
  6911. for ($c = 0; $c < 256; ++$c) {
  6912. ImageColorAllocate($imgalpha, $c, $c, $c);
  6913. }
  6914. // extract alpha channel
  6915. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  6916. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  6917. $color = imagecolorat($img, $xpx, $ypx);
  6918. // get and correct gamma color
  6919. $alpha = $this->getGDgamma($img, $color);
  6920. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  6921. }
  6922. }
  6923. imagepng($imgalpha, $tempfile_alpha);
  6924. imagedestroy($imgalpha);
  6925. // extract image without alpha channel
  6926. $imgplain = imagecreatetruecolor($wpx, $hpx);
  6927. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  6928. imagepng($imgplain, $tempfile_plain);
  6929. imagedestroy($imgplain);
  6930. $parsed = true;
  6931. } catch (Exception $e) {
  6932. // GD fails
  6933. $parse_error = 'GD library error: '.$e->getMessage();
  6934. }
  6935. }
  6936. if ($parsed === false) {
  6937. if (empty($parse_error)) {
  6938. $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  6939. } else {
  6940. $this->Error($parse_error);
  6941. }
  6942. }
  6943. // embed mask image
  6944. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6945. // embed image, masked with previously embedded mask
  6946. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6947. }
  6948. /**
  6949. * Get the GD-corrected PNG gamma value from alpha color
  6950. * @param $img (int) GD image Resource ID.
  6951. * @param $c (int) alpha color
  6952. * @protected
  6953. * @since 4.3.007 (2008-12-04)
  6954. */
  6955. protected function getGDgamma($img, $c) {
  6956. if (!isset($this->gdgammacache['#'.$c])) {
  6957. $colors = imagecolorsforindex($img, $c);
  6958. // GD alpha is only 7 bit (0 -> 127)
  6959. $this->gdgammacache['#'.$c] = (((127 - $colors['alpha']) / 127) * 255);
  6960. // correct gamma
  6961. $this->gdgammacache['#'.$c] = (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255);
  6962. // store the latest values on cache to improve performances
  6963. if (count($this->gdgammacache) > 8) {
  6964. // remove one element from the cache array
  6965. array_shift($this->gdgammacache);
  6966. }
  6967. }
  6968. return $this->gdgammacache['#'.$c];
  6969. }
  6970. /**
  6971. * Performs a line break.
  6972. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  6973. * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
  6974. * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
  6975. * @public
  6976. * @since 1.0
  6977. * @see Cell()
  6978. */
  6979. public function Ln($h='', $cell=false) {
  6980. 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'])) {
  6981. // revove vertical space from the top of the column
  6982. return;
  6983. }
  6984. if ($cell) {
  6985. if ($this->rtl) {
  6986. $cellpadding = $this->cell_padding['R'];
  6987. } else {
  6988. $cellpadding = $this->cell_padding['L'];
  6989. }
  6990. } else {
  6991. $cellpadding = 0;
  6992. }
  6993. if ($this->rtl) {
  6994. $this->x = $this->w - $this->rMargin - $cellpadding;
  6995. } else {
  6996. $this->x = $this->lMargin + $cellpadding;
  6997. }
  6998. if (is_string($h)) {
  6999. $h = $this->lasth;
  7000. }
  7001. $this->y += $h;
  7002. $this->newline = true;
  7003. }
  7004. /**
  7005. * Returns the relative X value of current position.
  7006. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  7007. * @return float
  7008. * @public
  7009. * @since 1.2
  7010. * @see SetX(), GetY(), SetY()
  7011. */
  7012. public function GetX() {
  7013. //Get x position
  7014. if ($this->rtl) {
  7015. return ($this->w - $this->x);
  7016. } else {
  7017. return $this->x;
  7018. }
  7019. }
  7020. /**
  7021. * Returns the absolute X value of current position.
  7022. * @return float
  7023. * @public
  7024. * @since 1.2
  7025. * @see SetX(), GetY(), SetY()
  7026. */
  7027. public function GetAbsX() {
  7028. return $this->x;
  7029. }
  7030. /**
  7031. * Returns the ordinate of the current position.
  7032. * @return float
  7033. * @public
  7034. * @since 1.0
  7035. * @see SetY(), GetX(), SetX()
  7036. */
  7037. public function GetY() {
  7038. return $this->y;
  7039. }
  7040. /**
  7041. * Defines the abscissa of the current position.
  7042. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  7043. * @param $x (float) The value of the abscissa in user units.
  7044. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7045. * @public
  7046. * @since 1.2
  7047. * @see GetX(), GetY(), SetY(), SetXY()
  7048. */
  7049. public function SetX($x, $rtloff=false) {
  7050. $x = floatval($x);
  7051. if (!$rtloff AND $this->rtl) {
  7052. if ($x >= 0) {
  7053. $this->x = $this->w - $x;
  7054. } else {
  7055. $this->x = abs($x);
  7056. }
  7057. } else {
  7058. if ($x >= 0) {
  7059. $this->x = $x;
  7060. } else {
  7061. $this->x = $this->w + $x;
  7062. }
  7063. }
  7064. if ($this->x < 0) {
  7065. $this->x = 0;
  7066. }
  7067. if ($this->x > $this->w) {
  7068. $this->x = $this->w;
  7069. }
  7070. }
  7071. /**
  7072. * Moves the current abscissa back to the left margin and sets the ordinate.
  7073. * If the passed value is negative, it is relative to the bottom of the page.
  7074. * @param $y (float) The value of the ordinate in user units.
  7075. * @param $resetx (bool) if true (default) reset the X position.
  7076. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7077. * @public
  7078. * @since 1.0
  7079. * @see GetX(), GetY(), SetY(), SetXY()
  7080. */
  7081. public function SetY($y, $resetx=true, $rtloff=false) {
  7082. $y = floatval($y);
  7083. if ($resetx) {
  7084. //reset x
  7085. if (!$rtloff AND $this->rtl) {
  7086. $this->x = $this->w - $this->rMargin;
  7087. } else {
  7088. $this->x = $this->lMargin;
  7089. }
  7090. }
  7091. if ($y >= 0) {
  7092. $this->y = $y;
  7093. } else {
  7094. $this->y = $this->h + $y;
  7095. }
  7096. if ($this->y < 0) {
  7097. $this->y = 0;
  7098. }
  7099. if ($this->y > $this->h) {
  7100. $this->y = $this->h;
  7101. }
  7102. }
  7103. /**
  7104. * Defines the abscissa and ordinate of the current position.
  7105. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7106. * @param $x (float) The value of the abscissa.
  7107. * @param $y (float) The value of the ordinate.
  7108. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7109. * @public
  7110. * @since 1.2
  7111. * @see SetX(), SetY()
  7112. */
  7113. public function SetXY($x, $y, $rtloff=false) {
  7114. $this->SetY($y, false, $rtloff);
  7115. $this->SetX($x, $rtloff);
  7116. }
  7117. /**
  7118. * Set the absolute X coordinate of the current pointer.
  7119. * @param $x (float) The value of the abscissa in user units.
  7120. * @public
  7121. * @since 5.9.186 (2012-09-13)
  7122. * @see setAbsX(), setAbsY(), SetAbsXY()
  7123. */
  7124. public function SetAbsX($x) {
  7125. $this->x = floatval($x);
  7126. }
  7127. /**
  7128. * Set the absolute Y coordinate of the current pointer.
  7129. * @param $y (float) (float) The value of the ordinate in user units.
  7130. * @public
  7131. * @since 5.9.186 (2012-09-13)
  7132. * @see setAbsX(), setAbsY(), SetAbsXY()
  7133. */
  7134. public function SetAbsY($y) {
  7135. $this->y = floatval($y);
  7136. }
  7137. /**
  7138. * Set the absolute X and Y coordinates of the current pointer.
  7139. * @param $x (float) The value of the abscissa in user units.
  7140. * @param $y (float) (float) The value of the ordinate in user units.
  7141. * @public
  7142. * @since 5.9.186 (2012-09-13)
  7143. * @see setAbsX(), setAbsY(), SetAbsXY()
  7144. */
  7145. public function SetAbsXY($x, $y) {
  7146. $this->SetAbsX($x);
  7147. $this->SetAbsY($y);
  7148. }
  7149. /**
  7150. * Send the document to a given destination: string, local file or browser.
  7151. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7152. * The method first calls Close() if necessary to terminate the document.
  7153. * @param $name (string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  7154. * @param $dest (string) Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local server file with the name given by name.</li><li>S: return the document as a string (name is ignored).</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li><li>E: return the document as base64 mime multi-part email attachment (RFC 2045)</li></ul>
  7155. * @return string
  7156. * @public
  7157. * @since 1.0
  7158. * @see Close()
  7159. */
  7160. public function Output($name='doc.pdf', $dest='I') {
  7161. //Output PDF to some destination
  7162. //Finish document if necessary
  7163. if ($this->state < 3) {
  7164. $this->Close();
  7165. }
  7166. //Normalize parameters
  7167. if (is_bool($dest)) {
  7168. $dest = $dest ? 'D' : 'F';
  7169. }
  7170. $dest = strtoupper($dest);
  7171. if ($dest[0] != 'F') {
  7172. $name = preg_replace('/[\s]+/', '_', $name);
  7173. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  7174. }
  7175. if ($this->sign) {
  7176. // *** apply digital signature to the document ***
  7177. // get the document content
  7178. $pdfdoc = $this->getBuffer();
  7179. // remove last newline
  7180. $pdfdoc = substr($pdfdoc, 0, -1);
  7181. // remove filler space
  7182. $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string);
  7183. // define the ByteRange
  7184. $byte_range = array();
  7185. $byte_range[0] = 0;
  7186. $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10;
  7187. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  7188. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7189. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  7190. // replace the ByteRange
  7191. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  7192. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  7193. $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc);
  7194. // write the document to a temporary folder
  7195. $tempdoc = TCPDF_STATIC::getObjFilename('doc', $this->file_id);
  7196. $f = TCPDF_STATIC::fopenLocal($tempdoc, 'wb');
  7197. if (!$f) {
  7198. $this->Error('Unable to create temporary file: '.$tempdoc);
  7199. }
  7200. $pdfdoc_length = strlen($pdfdoc);
  7201. fwrite($f, $pdfdoc, $pdfdoc_length);
  7202. fclose($f);
  7203. // get digital signature via openssl library
  7204. $tempsign = TCPDF_STATIC::getObjFilename('sig', $this->file_id);
  7205. if (empty($this->signature_data['extracerts'])) {
  7206. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  7207. } else {
  7208. 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']);
  7209. }
  7210. // read signature
  7211. $signature = file_get_contents($tempsign);
  7212. // extract signature
  7213. $signature = substr($signature, $pdfdoc_length);
  7214. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  7215. $tmparr = explode("\n\n", $signature);
  7216. $signature = $tmparr[1];
  7217. // decode signature
  7218. $signature = base64_decode(trim($signature));
  7219. // add TSA timestamp to signature
  7220. $signature = $this->applyTSA($signature);
  7221. // convert signature to hex
  7222. $signature = current(unpack('H*', $signature));
  7223. $signature = str_pad($signature, $this->signature_max_length, '0');
  7224. // Add signature to the document
  7225. $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  7226. $this->bufferlen = strlen($this->buffer);
  7227. }
  7228. switch($dest) {
  7229. case 'I': {
  7230. // Send PDF to the standard output
  7231. if (ob_get_contents()) {
  7232. $this->Error('Some data has already been output, can\'t send PDF file');
  7233. }
  7234. if (php_sapi_name() != 'cli') {
  7235. // send output to a browser
  7236. header('Content-Type: application/pdf');
  7237. if (headers_sent()) {
  7238. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7239. }
  7240. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7241. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7242. header('Pragma: public');
  7243. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7244. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7245. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7246. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7247. } else {
  7248. echo $this->getBuffer();
  7249. }
  7250. break;
  7251. }
  7252. case 'D': {
  7253. // download PDF as file
  7254. if (ob_get_contents()) {
  7255. $this->Error('Some data has already been output, can\'t send PDF file');
  7256. }
  7257. header('Content-Description: File Transfer');
  7258. if (headers_sent()) {
  7259. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7260. }
  7261. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7262. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7263. header('Pragma: public');
  7264. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7265. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7266. // force download dialog
  7267. if (strpos(php_sapi_name(), 'cgi') === false) {
  7268. header('Content-Type: application/force-download');
  7269. header('Content-Type: application/octet-stream', false);
  7270. header('Content-Type: application/download', false);
  7271. header('Content-Type: application/pdf', false);
  7272. } else {
  7273. header('Content-Type: application/pdf');
  7274. }
  7275. // use the Content-Disposition header to supply a recommended filename
  7276. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7277. header('Content-Transfer-Encoding: binary');
  7278. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7279. break;
  7280. }
  7281. case 'F':
  7282. case 'FI':
  7283. case 'FD': {
  7284. // save PDF to a local file
  7285. $f = TCPDF_STATIC::fopenLocal($name, 'wb');
  7286. if (!$f) {
  7287. $this->Error('Unable to create output file: '.$name);
  7288. }
  7289. fwrite($f, $this->getBuffer(), $this->bufferlen);
  7290. fclose($f);
  7291. if ($dest == 'FI') {
  7292. // send headers to browser
  7293. header('Content-Type: application/pdf');
  7294. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7295. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7296. header('Pragma: public');
  7297. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7298. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7299. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7300. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7301. } elseif ($dest == 'FD') {
  7302. // send headers to browser
  7303. if (ob_get_contents()) {
  7304. $this->Error('Some data has already been output, can\'t send PDF file');
  7305. }
  7306. header('Content-Description: File Transfer');
  7307. if (headers_sent()) {
  7308. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7309. }
  7310. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7311. header('Pragma: public');
  7312. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7313. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7314. // force download dialog
  7315. if (strpos(php_sapi_name(), 'cgi') === false) {
  7316. header('Content-Type: application/force-download');
  7317. header('Content-Type: application/octet-stream', false);
  7318. header('Content-Type: application/download', false);
  7319. header('Content-Type: application/pdf', false);
  7320. } else {
  7321. header('Content-Type: application/pdf');
  7322. }
  7323. // use the Content-Disposition header to supply a recommended filename
  7324. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7325. header('Content-Transfer-Encoding: binary');
  7326. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7327. }
  7328. break;
  7329. }
  7330. case 'E': {
  7331. // return PDF as base64 mime multi-part email attachment (RFC 2045)
  7332. $retval = 'Content-Type: application/pdf;'."\r\n";
  7333. $retval .= ' name="'.$name.'"'."\r\n";
  7334. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7335. $retval .= 'Content-Disposition: attachment;'."\r\n";
  7336. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7337. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  7338. return $retval;
  7339. }
  7340. case 'S': {
  7341. // returns PDF as a string
  7342. return $this->getBuffer();
  7343. }
  7344. default: {
  7345. $this->Error('Incorrect output destination: '.$dest);
  7346. }
  7347. }
  7348. return '';
  7349. }
  7350. /**
  7351. * Unset all class variables except the following critical variables.
  7352. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
  7353. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
  7354. * @public
  7355. * @since 4.5.016 (2009-02-24)
  7356. */
  7357. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  7358. // restore internal encoding
  7359. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  7360. mb_internal_encoding($this->internal_encoding);
  7361. }
  7362. if ($destroyall AND !$preserve_objcopy) {
  7363. // remove all temporary files
  7364. $tmpfiles = glob(K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_*');
  7365. if (!empty($tmpfiles)) {
  7366. array_map('unlink', $tmpfiles);
  7367. }
  7368. }
  7369. $preserve = array(
  7370. 'file_id',
  7371. 'internal_encoding',
  7372. 'state',
  7373. 'bufferlen',
  7374. 'buffer',
  7375. 'cached_files',
  7376. 'sign',
  7377. 'signature_data',
  7378. 'signature_max_length',
  7379. 'byterange_string',
  7380. 'tsa_timestamp',
  7381. 'tsa_data'
  7382. );
  7383. foreach (array_keys(get_object_vars($this)) as $val) {
  7384. if ($destroyall OR !in_array($val, $preserve)) {
  7385. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
  7386. unset($this->$val);
  7387. }
  7388. }
  7389. }
  7390. }
  7391. /**
  7392. * Check for locale-related bug
  7393. * @protected
  7394. */
  7395. protected function _dochecks() {
  7396. //Check for locale-related bug
  7397. if (1.1 == 1) {
  7398. $this->Error('Don\'t alter the locale before including class file');
  7399. }
  7400. //Check for decimal separator
  7401. if (sprintf('%.1F', 1.0) != '1.0') {
  7402. setlocale(LC_NUMERIC, 'C');
  7403. }
  7404. }
  7405. /**
  7406. * Return an array containing variations for the basic page number alias.
  7407. * @param $a (string) Base alias.
  7408. * @return array of page number aliases
  7409. * @protected
  7410. */
  7411. protected function getInternalPageNumberAliases($a= '') {
  7412. $alias = array();
  7413. // build array of Unicode + ASCII variants (the order is important)
  7414. $alias = array('u' => array(), 'a' => array());
  7415. $u = '{'.$a.'}';
  7416. $alias['u'][] = TCPDF_STATIC::_escape($u);
  7417. if ($this->isunicode) {
  7418. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont));
  7419. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7420. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont));
  7421. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7422. }
  7423. $alias['a'][] = TCPDF_STATIC::_escape($a);
  7424. return $alias;
  7425. }
  7426. /**
  7427. * Return an array containing all internal page aliases.
  7428. * @return array of page number aliases
  7429. * @protected
  7430. */
  7431. protected function getAllInternalPageNumberAliases() {
  7432. $basic_alias = array(TCPDF_STATIC::$alias_tot_pages, TCPDF_STATIC::$alias_num_page, TCPDF_STATIC::$alias_group_tot_pages, TCPDF_STATIC::$alias_group_num_page, TCPDF_STATIC::$alias_right_shift);
  7433. $pnalias = array();
  7434. foreach($basic_alias as $k => $a) {
  7435. $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  7436. }
  7437. return $pnalias;
  7438. }
  7439. /**
  7440. * Replace right shift page number aliases with spaces to correct right alignment.
  7441. * This works perfectly only when using monospaced fonts.
  7442. * @param $page (string) Page content.
  7443. * @param $aliases (array) Array of page aliases.
  7444. * @param $diff (int) initial difference to add.
  7445. * @return replaced page content.
  7446. * @protected
  7447. */
  7448. protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
  7449. foreach ($aliases as $type => $alias) {
  7450. foreach ($alias as $a) {
  7451. // find position of compensation factor
  7452. $startnum = (strpos($a, ':') + 1);
  7453. $a = substr($a, 0, $startnum);
  7454. if (($pos = strpos($page, $a)) !== false) {
  7455. // end of alias
  7456. $endnum = strpos($page, '}', $pos);
  7457. // string to be replaced
  7458. $aa = substr($page, $pos, ($endnum - $pos + 1));
  7459. // get compensation factor
  7460. $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
  7461. $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
  7462. $ratio = floatval($ratio);
  7463. if ($type == 'u') {
  7464. $chrdiff = floor(($diff + 12) * $ratio);
  7465. $shift = str_repeat(' ', $chrdiff);
  7466. $shift = TCPDF_FONTS::UTF8ToUTF16BE($shift, false, $this->isunicode, $this->CurrentFont);
  7467. } else {
  7468. $chrdiff = floor(($diff + 11) * $ratio);
  7469. $shift = str_repeat(' ', $chrdiff);
  7470. }
  7471. $page = str_replace($aa, $shift, $page);
  7472. }
  7473. }
  7474. }
  7475. return $page;
  7476. }
  7477. /**
  7478. * Set page boxes to be included on page descriptions.
  7479. * @param $boxes (array) Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  7480. * @protected
  7481. */
  7482. protected function setPageBoxTypes($boxes) {
  7483. $this->page_boxes = array();
  7484. foreach ($boxes as $box) {
  7485. if (in_array($box, TCPDF_STATIC::$pageboxes)) {
  7486. $this->page_boxes[] = $box;
  7487. }
  7488. }
  7489. }
  7490. /**
  7491. * Output pages (and replace page number aliases).
  7492. * @protected
  7493. */
  7494. protected function _putpages() {
  7495. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7496. // get internal aliases for page numbers
  7497. $pnalias = $this->getAllInternalPageNumberAliases();
  7498. $num_pages = $this->numpages;
  7499. $ptpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $num_pages - 1));
  7500. $ptpu = TCPDF_FONTS::UTF8ToUTF16BE($ptpa, false, $this->isunicode, $this->CurrentFont);
  7501. $ptp_num_chars = $this->GetNumChars($ptpa);
  7502. $pagegroupnum = 0;
  7503. $groupnum = 0;
  7504. $ptgu = 1;
  7505. $ptga = 1;
  7506. $ptg_num_chars = 1;
  7507. for ($n = 1; $n <= $num_pages; ++$n) {
  7508. // get current page
  7509. $temppage = $this->getPageBuffer($n);
  7510. $pagelen = strlen($temppage);
  7511. // set replacements for total pages number
  7512. $pnpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $n - 1));
  7513. $pnpu = TCPDF_FONTS::UTF8ToUTF16BE($pnpa, false, $this->isunicode, $this->CurrentFont);
  7514. $pnp_num_chars = $this->GetNumChars($pnpa);
  7515. $pdiff = 0; // difference used for right shift alignment of page numbers
  7516. $gdiff = 0; // difference used for right shift alignment of page group numbers
  7517. if (!empty($this->pagegroups)) {
  7518. if (isset($this->newpagegroup[$n])) {
  7519. $pagegroupnum = 0;
  7520. ++$groupnum;
  7521. $ptga = TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]);
  7522. $ptgu = TCPDF_FONTS::UTF8ToUTF16BE($ptga, false, $this->isunicode, $this->CurrentFont);
  7523. $ptg_num_chars = $this->GetNumChars($ptga);
  7524. }
  7525. ++$pagegroupnum;
  7526. $pnga = TCPDF_STATIC::formatPageNumber($pagegroupnum);
  7527. $pngu = TCPDF_FONTS::UTF8ToUTF16BE($pnga, false, $this->isunicode, $this->CurrentFont);
  7528. $png_num_chars = $this->GetNumChars($pnga);
  7529. // replace page numbers
  7530. $replace = array();
  7531. $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
  7532. $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
  7533. $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
  7534. $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
  7535. list($temppage, $gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $gdiff);
  7536. }
  7537. // replace page numbers
  7538. $replace = array();
  7539. $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
  7540. $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
  7541. $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
  7542. $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
  7543. list($temppage, $pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $pdiff);
  7544. // replace right shift alias
  7545. $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
  7546. // replace EPS marker
  7547. $temppage = str_replace($this->epsmarker, '', $temppage);
  7548. //Page
  7549. $this->page_obj_id[$n] = $this->_newobj();
  7550. $out = '<<';
  7551. $out .= ' /Type /Page';
  7552. $out .= ' /Parent 1 0 R';
  7553. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  7554. $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp);
  7555. }
  7556. $out .= ' /Resources 2 0 R';
  7557. foreach ($this->page_boxes as $box) {
  7558. $out .= ' /'.$box;
  7559. $out .= sprintf(' [%F %F %F %F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
  7560. }
  7561. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7562. $out .= ' /BoxColorInfo <<';
  7563. foreach ($this->page_boxes as $box) {
  7564. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7565. $out .= ' /'.$box.' <<';
  7566. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7567. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7568. $out .= ' /C [';
  7569. $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  7570. $out .= ' ]';
  7571. }
  7572. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  7573. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  7574. }
  7575. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  7576. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  7577. }
  7578. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  7579. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  7580. $out .= ' /D [';
  7581. foreach ($dashes as $dash) {
  7582. $out .= sprintf(' %F', ($dash * $this->k));
  7583. }
  7584. $out .= ' ]';
  7585. }
  7586. $out .= ' >>';
  7587. }
  7588. }
  7589. $out .= ' >>';
  7590. }
  7591. $out .= ' /Contents '.($this->n + 1).' 0 R';
  7592. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  7593. if (!$this->pdfa_mode) {
  7594. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  7595. }
  7596. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  7597. // page transitions
  7598. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  7599. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  7600. }
  7601. $out .= ' /Trans <<';
  7602. $out .= ' /Type /Trans';
  7603. if (isset($this->pagedim[$n]['trans']['S'])) {
  7604. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  7605. }
  7606. if (isset($this->pagedim[$n]['trans']['D'])) {
  7607. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  7608. }
  7609. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  7610. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  7611. }
  7612. if (isset($this->pagedim[$n]['trans']['M'])) {
  7613. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  7614. }
  7615. if (isset($this->pagedim[$n]['trans']['Di'])) {
  7616. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  7617. }
  7618. if (isset($this->pagedim[$n]['trans']['SS'])) {
  7619. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  7620. }
  7621. if (isset($this->pagedim[$n]['trans']['B'])) {
  7622. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  7623. }
  7624. $out .= ' >>';
  7625. }
  7626. $out .= $this->_getannotsrefs($n);
  7627. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  7628. $out .= ' >>';
  7629. $out .= "\n".'endobj';
  7630. $this->_out($out);
  7631. //Page content
  7632. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  7633. $this->_newobj();
  7634. $p = $this->_getrawstream($p);
  7635. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  7636. }
  7637. //Pages root
  7638. $out = $this->_getobj(1)."\n";
  7639. $out .= '<< /Type /Pages /Kids [';
  7640. foreach($this->page_obj_id as $page_obj) {
  7641. $out .= ' '.$page_obj.' 0 R';
  7642. }
  7643. $out .= ' ] /Count '.$num_pages.' >>';
  7644. $out .= "\n".'endobj';
  7645. $this->_out($out);
  7646. }
  7647. /**
  7648. * Get references to page annotations.
  7649. * @param $n (int) page number
  7650. * @return string
  7651. * @protected
  7652. * @author Nicola Asuni
  7653. * @since 5.0.010 (2010-05-17)
  7654. */
  7655. protected function _getannotsrefs($n) {
  7656. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  7657. return '';
  7658. }
  7659. $out = ' /Annots [';
  7660. if (isset($this->PageAnnots[$n])) {
  7661. foreach ($this->PageAnnots[$n] as $key => $val) {
  7662. if (!in_array($val['n'], $this->radio_groups)) {
  7663. $out .= ' '.$val['n'].' 0 R';
  7664. }
  7665. }
  7666. // add radiobutton groups
  7667. if (isset($this->radiobutton_groups[$n])) {
  7668. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  7669. if (isset($data['n'])) {
  7670. $out .= ' '.$data['n'].' 0 R';
  7671. }
  7672. }
  7673. }
  7674. }
  7675. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  7676. // set reference for signature object
  7677. $out .= ' '.$this->sig_obj_id.' 0 R';
  7678. }
  7679. if (!empty($this->empty_signature_appearance)) {
  7680. foreach ($this->empty_signature_appearance as $esa) {
  7681. if ($esa['page'] == $n) {
  7682. // set reference for empty signature objects
  7683. $out .= ' '.$esa['objid'].' 0 R';
  7684. }
  7685. }
  7686. }
  7687. $out .= ' ]';
  7688. return $out;
  7689. }
  7690. /**
  7691. * Output annotations objects for all pages.
  7692. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  7693. * See section 12.5 of PDF 32000_2008 reference.
  7694. * @protected
  7695. * @author Nicola Asuni
  7696. * @since 4.0.018 (2008-08-06)
  7697. */
  7698. protected function _putannotsobjs() {
  7699. // reset object counter
  7700. for ($n=1; $n <= $this->numpages; ++$n) {
  7701. if (isset($this->PageAnnots[$n])) {
  7702. // set page annotations
  7703. foreach ($this->PageAnnots[$n] as $key => $pl) {
  7704. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  7705. // create annotation object for grouping radiobuttons
  7706. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  7707. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  7708. $annots = '<<';
  7709. $annots .= ' /Type /Annot';
  7710. $annots .= ' /Subtype /Widget';
  7711. $annots .= ' /Rect [0 0 0 0]';
  7712. if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  7713. // read only
  7714. $annots .= ' /F 68';
  7715. $annots .= ' /Ff 49153';
  7716. } else {
  7717. $annots .= ' /F 4'; // default print for PDF/A
  7718. $annots .= ' /Ff 49152';
  7719. }
  7720. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  7721. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  7722. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  7723. }
  7724. $annots .= ' /FT /Btn';
  7725. $annots .= ' /Kids [';
  7726. $defval = '';
  7727. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  7728. if (isset($data['kid'])) {
  7729. $annots .= ' '.$data['kid'].' 0 R';
  7730. if ($data['def'] !== 'Off') {
  7731. $defval = $data['def'];
  7732. }
  7733. }
  7734. }
  7735. $annots .= ' ]';
  7736. if (!empty($defval)) {
  7737. $annots .= ' /V /'.$defval;
  7738. }
  7739. $annots .= ' >>';
  7740. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  7741. $this->form_obj_id[] = $radio_button_obj_id;
  7742. // store object id to be used on Parent entry of Kids
  7743. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  7744. }
  7745. $formfield = false;
  7746. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  7747. $a = $pl['x'] * $this->k;
  7748. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  7749. $c = $pl['w'] * $this->k;
  7750. $d = $pl['h'] * $this->k;
  7751. $rect = sprintf('%F %F %F %F', $a, $b, $a+$c, $b+$d);
  7752. // create new annotation object
  7753. $annots = '<</Type /Annot';
  7754. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  7755. $annots .= ' /Rect ['.$rect.']';
  7756. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  7757. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  7758. $annots .= ' /FT /'.$pl['opt']['ft'];
  7759. $formfield = true;
  7760. }
  7761. if ($pl['opt']['subtype'] !== 'Link') {
  7762. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  7763. }
  7764. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  7765. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  7766. $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
  7767. if (isset($pl['opt']['f'])) {
  7768. $fval = 0;
  7769. if (is_array($pl['opt']['f'])) {
  7770. foreach ($pl['opt']['f'] as $f) {
  7771. switch (strtolower($f)) {
  7772. case 'invisible': {
  7773. $fval += 1 << 0;
  7774. break;
  7775. }
  7776. case 'hidden': {
  7777. $fval += 1 << 1;
  7778. break;
  7779. }
  7780. case 'print': {
  7781. $fval += 1 << 2;
  7782. break;
  7783. }
  7784. case 'nozoom': {
  7785. $fval += 1 << 3;
  7786. break;
  7787. }
  7788. case 'norotate': {
  7789. $fval += 1 << 4;
  7790. break;
  7791. }
  7792. case 'noview': {
  7793. $fval += 1 << 5;
  7794. break;
  7795. }
  7796. case 'readonly': {
  7797. $fval += 1 << 6;
  7798. break;
  7799. }
  7800. case 'locked': {
  7801. $fval += 1 << 8;
  7802. break;
  7803. }
  7804. case 'togglenoview': {
  7805. $fval += 1 << 9;
  7806. break;
  7807. }
  7808. case 'lockedcontents': {
  7809. $fval += 1 << 10;
  7810. break;
  7811. }
  7812. default: {
  7813. break;
  7814. }
  7815. }
  7816. }
  7817. } else {
  7818. $fval = intval($pl['opt']['f']);
  7819. }
  7820. } else {
  7821. $fval = 4;
  7822. }
  7823. if ($this->pdfa_mode) {
  7824. // force print flag for PDF/A mode
  7825. $fval |= 4;
  7826. }
  7827. $annots .= ' /F '.intval($fval);
  7828. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  7829. $annots .= ' /AS /'.$pl['opt']['as'];
  7830. }
  7831. if (isset($pl['opt']['ap'])) {
  7832. // appearance stream
  7833. $annots .= ' /AP <<';
  7834. if (is_array($pl['opt']['ap'])) {
  7835. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  7836. // $apmode can be: n = normal; r = rollover; d = down;
  7837. $annots .= ' /'.strtoupper($apmode);
  7838. if (is_array($apdef)) {
  7839. $annots .= ' <<';
  7840. foreach ($apdef as $apstate => $stream) {
  7841. // reference to XObject that define the appearance for this mode-state
  7842. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  7843. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  7844. }
  7845. $annots .= ' >>';
  7846. } else {
  7847. // reference to XObject that define the appearance for this mode
  7848. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  7849. $annots .= ' '.$apsobjid.' 0 R';
  7850. }
  7851. }
  7852. } else {
  7853. $annots .= $pl['opt']['ap'];
  7854. }
  7855. $annots .= ' >>';
  7856. }
  7857. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  7858. $annots .= ' /BS <<';
  7859. $annots .= ' /Type /Border';
  7860. if (isset($pl['opt']['bs']['w'])) {
  7861. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  7862. }
  7863. $bstyles = array('S', 'D', 'B', 'I', 'U');
  7864. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  7865. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7866. }
  7867. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  7868. $annots .= ' /D [';
  7869. foreach ($pl['opt']['bs']['d'] as $cord) {
  7870. $annots .= ' '.intval($cord);
  7871. }
  7872. $annots .= ']';
  7873. }
  7874. $annots .= ' >>';
  7875. } else {
  7876. $annots .= ' /Border [';
  7877. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  7878. $annots .= intval($pl['opt']['border'][0]).' ';
  7879. $annots .= intval($pl['opt']['border'][1]).' ';
  7880. $annots .= intval($pl['opt']['border'][2]);
  7881. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  7882. $annots .= ' [';
  7883. foreach ($pl['opt']['border'][3] as $dash) {
  7884. $annots .= intval($dash).' ';
  7885. }
  7886. $annots .= ']';
  7887. }
  7888. } else {
  7889. $annots .= '0 0 0';
  7890. }
  7891. $annots .= ']';
  7892. }
  7893. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  7894. $annots .= ' /BE <<';
  7895. $bstyles = array('S', 'C');
  7896. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  7897. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7898. } else {
  7899. $annots .= ' /S /S';
  7900. }
  7901. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  7902. $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
  7903. }
  7904. $annots .= '>>';
  7905. }
  7906. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  7907. $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']);
  7908. }
  7909. //$annots .= ' /StructParent ';
  7910. //$annots .= ' /OC ';
  7911. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  7912. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  7913. // this is a markup type
  7914. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  7915. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  7916. }
  7917. //$annots .= ' /Popup ';
  7918. if (isset($pl['opt']['ca'])) {
  7919. $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
  7920. }
  7921. if (isset($pl['opt']['rc'])) {
  7922. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  7923. }
  7924. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
  7925. //$annots .= ' /IRT ';
  7926. if (isset($pl['opt']['subj'])) {
  7927. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  7928. }
  7929. //$annots .= ' /RT ';
  7930. //$annots .= ' /IT ';
  7931. //$annots .= ' /ExData ';
  7932. }
  7933. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  7934. // Annotation types
  7935. switch (strtolower($pl['opt']['subtype'])) {
  7936. case 'text': {
  7937. if (isset($pl['opt']['open'])) {
  7938. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  7939. }
  7940. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  7941. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  7942. $annots .= ' /Name /'.$pl['opt']['name'];
  7943. } else {
  7944. $annots .= ' /Name /Note';
  7945. }
  7946. $statemodels = array('Marked', 'Review');
  7947. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  7948. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  7949. } else {
  7950. $pl['opt']['statemodel'] = 'Marked';
  7951. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  7952. }
  7953. if ($pl['opt']['statemodel'] == 'Marked') {
  7954. $states = array('Accepted', 'Unmarked');
  7955. } else {
  7956. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  7957. }
  7958. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  7959. $annots .= ' /State /'.$pl['opt']['state'];
  7960. } else {
  7961. if ($pl['opt']['statemodel'] == 'Marked') {
  7962. $annots .= ' /State /Unmarked';
  7963. } else {
  7964. $annots .= ' /State /None';
  7965. }
  7966. }
  7967. break;
  7968. }
  7969. case 'link': {
  7970. if (is_string($pl['txt']) && !empty($pl['txt'])) {
  7971. if ($pl['txt'][0] == '#') {
  7972. // internal destination
  7973. $annots .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($pl['txt'], 1));
  7974. } elseif ($pl['txt'][0] == '%') {
  7975. // embedded PDF file
  7976. $filename = basename(substr($pl['txt'], 1));
  7977. $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  7978. } elseif ($pl['txt'][0] == '*') {
  7979. // embedded generic file
  7980. $filename = basename(substr($pl['txt'], 1));
  7981. $jsa = 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});';
  7982. $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
  7983. } else {
  7984. $parsedUrl = parse_url($pl['txt']);
  7985. if (empty($parsedUrl['scheme']) AND (strtolower(substr($parsedUrl['path'], -4)) == '.pdf')) {
  7986. // relative link to a PDF file
  7987. $dest = '[0 /Fit]'; // default page 0
  7988. if (!empty($parsedUrl['fragment'])) {
  7989. // check for named destination
  7990. $tmp = explode('=', $parsedUrl['fragment']);
  7991. $dest = '('.((count($tmp) == 2) ? $tmp[1] : $tmp[0]).')';
  7992. }
  7993. $annots .= ' /A <</S /GoToR /D '.$dest.' /F '.$this->_datastring($this->unhtmlentities($parsedUrl['path']), $annot_obj_id).' /NewWindow true>>';
  7994. } else {
  7995. // external URI link
  7996. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  7997. }
  7998. }
  7999. } elseif (isset($this->links[$pl['txt']])) {
  8000. // internal link ID
  8001. $l = $this->links[$pl['txt']];
  8002. if (isset($this->page_obj_id[($l['p'])])) {
  8003. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l['p'])], ($this->pagedim[$l['p']]['h'] - ($l['y'] * $this->k)));
  8004. }
  8005. }
  8006. $hmodes = array('N', 'I', 'O', 'P');
  8007. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  8008. $annots .= ' /H /'.$pl['opt']['h'];
  8009. } else {
  8010. $annots .= ' /H /I';
  8011. }
  8012. //$annots .= ' /PA ';
  8013. //$annots .= ' /Quadpoints ';
  8014. break;
  8015. }
  8016. case 'freetext': {
  8017. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8018. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8019. }
  8020. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8021. $annots .= ' /Q '.intval($pl['opt']['q']);
  8022. }
  8023. if (isset($pl['opt']['rc'])) {
  8024. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8025. }
  8026. if (isset($pl['opt']['ds'])) {
  8027. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  8028. }
  8029. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  8030. $annots .= ' /CL [';
  8031. foreach ($pl['opt']['cl'] as $cl) {
  8032. $annots .= sprintf('%F ', $cl * $this->k);
  8033. }
  8034. $annots .= ']';
  8035. }
  8036. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  8037. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  8038. $annots .= ' /IT /'.$pl['opt']['it'];
  8039. }
  8040. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  8041. $l = $pl['opt']['rd'][0] * $this->k;
  8042. $r = $pl['opt']['rd'][1] * $this->k;
  8043. $t = $pl['opt']['rd'][2] * $this->k;
  8044. $b = $pl['opt']['rd'][3] * $this->k;
  8045. $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
  8046. }
  8047. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8048. $annots .= ' /LE /'.$pl['opt']['le'];
  8049. }
  8050. break;
  8051. }
  8052. case 'line': {
  8053. break;
  8054. }
  8055. case 'square': {
  8056. break;
  8057. }
  8058. case 'circle': {
  8059. break;
  8060. }
  8061. case 'polygon': {
  8062. break;
  8063. }
  8064. case 'polyline': {
  8065. break;
  8066. }
  8067. case 'highlight': {
  8068. break;
  8069. }
  8070. case 'underline': {
  8071. break;
  8072. }
  8073. case 'squiggly': {
  8074. break;
  8075. }
  8076. case 'strikeout': {
  8077. break;
  8078. }
  8079. case 'stamp': {
  8080. break;
  8081. }
  8082. case 'caret': {
  8083. break;
  8084. }
  8085. case 'ink': {
  8086. break;
  8087. }
  8088. case 'popup': {
  8089. break;
  8090. }
  8091. case 'fileattachment': {
  8092. if ($this->pdfa_mode) {
  8093. // embedded files are not allowed in PDF/A mode
  8094. break;
  8095. }
  8096. if (!isset($pl['opt']['fs'])) {
  8097. break;
  8098. }
  8099. $filename = basename($pl['opt']['fs']);
  8100. if (isset($this->embeddedfiles[$filename]['f'])) {
  8101. $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8102. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  8103. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8104. $annots .= ' /Name /'.$pl['opt']['name'];
  8105. } else {
  8106. $annots .= ' /Name /PushPin';
  8107. }
  8108. // index (zero-based) of the annotation in the Annots array of this page
  8109. $this->embeddedfiles[$filename]['a'] = $key;
  8110. }
  8111. break;
  8112. }
  8113. case 'sound': {
  8114. if (!isset($pl['opt']['fs'])) {
  8115. break;
  8116. }
  8117. $filename = basename($pl['opt']['fs']);
  8118. if (isset($this->embeddedfiles[$filename]['f'])) {
  8119. // ... TO BE COMPLETED ...
  8120. // /R /C /B /E /CO /CP
  8121. $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8122. $iconsapp = array('Speaker', 'Mic');
  8123. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8124. $annots .= ' /Name /'.$pl['opt']['name'];
  8125. } else {
  8126. $annots .= ' /Name /Speaker';
  8127. }
  8128. }
  8129. break;
  8130. }
  8131. case 'movie': {
  8132. break;
  8133. }
  8134. case 'widget': {
  8135. $hmode = array('N', 'I', 'O', 'P', 'T');
  8136. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8137. $annots .= ' /H /'.$pl['opt']['h'];
  8138. }
  8139. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8140. $annots .= ' /MK <<';
  8141. if (isset($pl['opt']['mk']['r'])) {
  8142. $annots .= ' /R '.$pl['opt']['mk']['r'];
  8143. }
  8144. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8145. $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']);
  8146. }
  8147. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8148. $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']);
  8149. }
  8150. if (isset($pl['opt']['mk']['ca'])) {
  8151. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8152. }
  8153. if (isset($pl['opt']['mk']['rc'])) {
  8154. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8155. }
  8156. if (isset($pl['opt']['mk']['ac'])) {
  8157. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8158. }
  8159. if (isset($pl['opt']['mk']['i'])) {
  8160. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  8161. if ($info !== false) {
  8162. $annots .= ' /I '.$info['n'].' 0 R';
  8163. }
  8164. }
  8165. if (isset($pl['opt']['mk']['ri'])) {
  8166. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  8167. if ($info !== false) {
  8168. $annots .= ' /RI '.$info['n'].' 0 R';
  8169. }
  8170. }
  8171. if (isset($pl['opt']['mk']['ix'])) {
  8172. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  8173. if ($info !== false) {
  8174. $annots .= ' /IX '.$info['n'].' 0 R';
  8175. }
  8176. }
  8177. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8178. $annots .= ' /IF <<';
  8179. $if_sw = array('A', 'B', 'S', 'N');
  8180. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8181. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8182. }
  8183. $if_s = array('A', 'P');
  8184. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8185. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8186. }
  8187. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8188. $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8189. }
  8190. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8191. $annots .= ' /FB true';
  8192. }
  8193. $annots .= '>>';
  8194. }
  8195. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8196. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8197. }
  8198. $annots .= '>>';
  8199. } // end MK
  8200. // --- Entries for field dictionaries ---
  8201. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8202. // set parent
  8203. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8204. }
  8205. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8206. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8207. }
  8208. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8209. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8210. }
  8211. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8212. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8213. }
  8214. if (isset($pl['opt']['ff'])) {
  8215. if (is_array($pl['opt']['ff'])) {
  8216. // array of bit settings
  8217. $flag = 0;
  8218. foreach($pl['opt']['ff'] as $val) {
  8219. $flag += 1 << ($val - 1);
  8220. }
  8221. } else {
  8222. $flag = intval($pl['opt']['ff']);
  8223. }
  8224. $annots .= ' /Ff '.$flag;
  8225. }
  8226. if (isset($pl['opt']['maxlen'])) {
  8227. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8228. }
  8229. if (isset($pl['opt']['v'])) {
  8230. $annots .= ' /V';
  8231. if (is_array($pl['opt']['v'])) {
  8232. foreach ($pl['opt']['v'] AS $optval) {
  8233. if (is_float($optval)) {
  8234. $optval = sprintf('%F', $optval);
  8235. }
  8236. $annots .= ' '.$optval;
  8237. }
  8238. } else {
  8239. $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  8240. }
  8241. }
  8242. if (isset($pl['opt']['dv'])) {
  8243. $annots .= ' /DV';
  8244. if (is_array($pl['opt']['dv'])) {
  8245. foreach ($pl['opt']['dv'] AS $optval) {
  8246. if (is_float($optval)) {
  8247. $optval = sprintf('%F', $optval);
  8248. }
  8249. $annots .= ' '.$optval;
  8250. }
  8251. } else {
  8252. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8253. }
  8254. }
  8255. if (isset($pl['opt']['rv'])) {
  8256. $annots .= ' /RV';
  8257. if (is_array($pl['opt']['rv'])) {
  8258. foreach ($pl['opt']['rv'] AS $optval) {
  8259. if (is_float($optval)) {
  8260. $optval = sprintf('%F', $optval);
  8261. }
  8262. $annots .= ' '.$optval;
  8263. }
  8264. } else {
  8265. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8266. }
  8267. }
  8268. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8269. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8270. }
  8271. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8272. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8273. }
  8274. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8275. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8276. }
  8277. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8278. $annots .= ' /Q '.intval($pl['opt']['q']);
  8279. }
  8280. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8281. $annots .= ' /Opt [';
  8282. foreach($pl['opt']['opt'] AS $copt) {
  8283. if (is_array($copt)) {
  8284. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8285. } else {
  8286. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  8287. }
  8288. }
  8289. $annots .= ']';
  8290. }
  8291. if (isset($pl['opt']['ti'])) {
  8292. $annots .= ' /TI '.intval($pl['opt']['ti']);
  8293. }
  8294. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8295. $annots .= ' /I [';
  8296. foreach($pl['opt']['i'] AS $copt) {
  8297. $annots .= intval($copt).' ';
  8298. }
  8299. $annots .= ']';
  8300. }
  8301. break;
  8302. }
  8303. case 'screen': {
  8304. break;
  8305. }
  8306. case 'printermark': {
  8307. break;
  8308. }
  8309. case 'trapnet': {
  8310. break;
  8311. }
  8312. case 'watermark': {
  8313. break;
  8314. }
  8315. case '3d': {
  8316. break;
  8317. }
  8318. default: {
  8319. break;
  8320. }
  8321. }
  8322. $annots .= '>>';
  8323. // create new annotation object
  8324. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8325. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8326. // store reference of form object
  8327. $this->form_obj_id[] = $annot_obj_id;
  8328. }
  8329. }
  8330. }
  8331. } // end for each page
  8332. }
  8333. /**
  8334. * Put appearance streams XObject used to define annotation's appearance states.
  8335. * @param $w (int) annotation width
  8336. * @param $h (int) annotation height
  8337. * @param $stream (string) appearance stream
  8338. * @return int object ID
  8339. * @protected
  8340. * @since 4.8.001 (2009-09-09)
  8341. */
  8342. protected function _putAPXObject($w=0, $h=0, $stream='') {
  8343. $stream = trim($stream);
  8344. $out = $this->_getobj()."\n";
  8345. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8346. $out .= '<<';
  8347. $out .= ' /Type /XObject';
  8348. $out .= ' /Subtype /Form';
  8349. $out .= ' /FormType 1';
  8350. if ($this->compress) {
  8351. $stream = gzcompress($stream);
  8352. $out .= ' /Filter /FlateDecode';
  8353. }
  8354. $rect = sprintf('%F %F', $w, $h);
  8355. $out .= ' /BBox [0 0 '.$rect.']';
  8356. $out .= ' /Matrix [1 0 0 1 0 0]';
  8357. $out .= ' /Resources 2 0 R';
  8358. $stream = $this->_getrawstream($stream);
  8359. $out .= ' /Length '.strlen($stream);
  8360. $out .= ' >>';
  8361. $out .= ' stream'."\n".$stream."\n".'endstream';
  8362. $out .= "\n".'endobj';
  8363. $this->_out($out);
  8364. return $this->n;
  8365. }
  8366. /**
  8367. * Output fonts.
  8368. * @author Nicola Asuni
  8369. * @protected
  8370. */
  8371. protected function _putfonts() {
  8372. $nf = $this->n;
  8373. foreach ($this->diffs as $diff) {
  8374. //Encodings
  8375. $this->_newobj();
  8376. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  8377. }
  8378. $mqr = TCPDF_STATIC::get_mqr();
  8379. TCPDF_STATIC::set_mqr(false);
  8380. foreach ($this->FontFiles as $file => $info) {
  8381. // search and get font file to embedd
  8382. $fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']);
  8383. if (!TCPDF_STATIC::empty_string($fontfile)) {
  8384. $font = file_get_contents($fontfile);
  8385. $compressed = (substr($file, -2) == '.z');
  8386. if ((!$compressed) AND (isset($info['length2']))) {
  8387. $header = (ord($font[0]) == 128);
  8388. if ($header) {
  8389. // strip first binary header
  8390. $font = substr($font, 6);
  8391. }
  8392. if ($header AND (ord($font[$info['length1']]) == 128)) {
  8393. // strip second binary header
  8394. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  8395. }
  8396. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  8397. if ($compressed) {
  8398. // uncompress font
  8399. $font = gzuncompress($font);
  8400. }
  8401. // merge subset characters
  8402. $subsetchars = array(); // used chars
  8403. foreach ($info['fontkeys'] as $fontkey) {
  8404. $fontinfo = $this->getFontBuffer($fontkey);
  8405. $subsetchars += $fontinfo['subsetchars'];
  8406. }
  8407. // rebuild a font subset
  8408. $font = TCPDF_FONTS::_getTrueTypeFontSubset($font, $subsetchars);
  8409. // calculate new font length
  8410. $info['length1'] = strlen($font);
  8411. if ($compressed) {
  8412. // recompress font
  8413. $font = gzcompress($font);
  8414. }
  8415. }
  8416. $this->_newobj();
  8417. $this->FontFiles[$file]['n'] = $this->n;
  8418. $stream = $this->_getrawstream($font);
  8419. $out = '<< /Length '.strlen($stream);
  8420. if ($compressed) {
  8421. $out .= ' /Filter /FlateDecode';
  8422. }
  8423. $out .= ' /Length1 '.$info['length1'];
  8424. if (isset($info['length2'])) {
  8425. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  8426. }
  8427. $out .= ' >>';
  8428. $out .= ' stream'."\n".$stream."\n".'endstream';
  8429. $out .= "\n".'endobj';
  8430. $this->_out($out);
  8431. }
  8432. }
  8433. TCPDF_STATIC::set_mqr($mqr);
  8434. foreach ($this->fontkeys as $k) {
  8435. //Font objects
  8436. $font = $this->getFontBuffer($k);
  8437. $type = $font['type'];
  8438. $name = $font['name'];
  8439. if ($type == 'core') {
  8440. // standard core font
  8441. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8442. $out .= '<</Type /Font';
  8443. $out .= ' /Subtype /Type1';
  8444. $out .= ' /BaseFont /'.$name;
  8445. $out .= ' /Name /F'.$font['i'];
  8446. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  8447. $out .= ' /Encoding /WinAnsiEncoding';
  8448. }
  8449. if ($k == 'helvetica') {
  8450. // add default font for annotations
  8451. $this->annotation_fonts[$k] = $font['i'];
  8452. }
  8453. $out .= ' >>';
  8454. $out .= "\n".'endobj';
  8455. $this->_out($out);
  8456. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  8457. // additional Type1 or TrueType font
  8458. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8459. $out .= '<</Type /Font';
  8460. $out .= ' /Subtype /'.$type;
  8461. $out .= ' /BaseFont /'.$name;
  8462. $out .= ' /Name /F'.$font['i'];
  8463. $out .= ' /FirstChar 32 /LastChar 255';
  8464. $out .= ' /Widths '.($this->n + 1).' 0 R';
  8465. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  8466. if ($font['enc']) {
  8467. if (isset($font['diff'])) {
  8468. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  8469. } else {
  8470. $out .= ' /Encoding /WinAnsiEncoding';
  8471. }
  8472. }
  8473. $out .= ' >>';
  8474. $out .= "\n".'endobj';
  8475. $this->_out($out);
  8476. // Widths
  8477. $this->_newobj();
  8478. $s = '[';
  8479. for ($i = 32; $i < 256; ++$i) {
  8480. if (isset($font['cw'][$i])) {
  8481. $s .= $font['cw'][$i].' ';
  8482. } else {
  8483. $s .= $font['dw'].' ';
  8484. }
  8485. }
  8486. $s .= ']';
  8487. $s .= "\n".'endobj';
  8488. $this->_out($s);
  8489. //Descriptor
  8490. $this->_newobj();
  8491. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8492. foreach ($font['desc'] as $fdk => $fdv) {
  8493. if (is_float($fdv)) {
  8494. $fdv = sprintf('%F', $fdv);
  8495. }
  8496. $s .= ' /'.$fdk.' '.$fdv.'';
  8497. }
  8498. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8499. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8500. }
  8501. $s .= '>>';
  8502. $s .= "\n".'endobj';
  8503. $this->_out($s);
  8504. } else {
  8505. // additional types
  8506. $mtd = '_put'.strtolower($type);
  8507. if (!method_exists($this, $mtd)) {
  8508. $this->Error('Unsupported font type: '.$type);
  8509. }
  8510. $this->$mtd($font);
  8511. }
  8512. }
  8513. }
  8514. /**
  8515. * Adds unicode fonts.<br>
  8516. * Based on PDF Reference 1.3 (section 5)
  8517. * @param $font (array) font data
  8518. * @protected
  8519. * @author Nicola Asuni
  8520. * @since 1.52.0.TC005 (2005-01-05)
  8521. */
  8522. protected function _puttruetypeunicode($font) {
  8523. $fontname = '';
  8524. if ($font['subset']) {
  8525. // change name for font subsetting
  8526. $subtag = sprintf('%06u', $font['i']);
  8527. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  8528. $fontname .= $subtag.'+';
  8529. }
  8530. $fontname .= $font['name'];
  8531. // Type0 Font
  8532. // A composite font composed of other fonts, organized hierarchically
  8533. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8534. $out .= '<< /Type /Font';
  8535. $out .= ' /Subtype /Type0';
  8536. $out .= ' /BaseFont /'.$fontname;
  8537. $out .= ' /Name /F'.$font['i'];
  8538. $out .= ' /Encoding /'.$font['enc'];
  8539. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  8540. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  8541. $out .= ' >>';
  8542. $out .= "\n".'endobj';
  8543. $this->_out($out);
  8544. // ToUnicode map for Identity-H
  8545. $stream = TCPDF_FONT_DATA::$uni_identity_h;
  8546. // ToUnicode Object
  8547. $this->_newobj();
  8548. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  8549. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8550. $stream = $this->_getrawstream($stream);
  8551. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  8552. // CIDFontType2
  8553. // A CIDFont whose glyph descriptions are based on TrueType font technology
  8554. $oid = $this->_newobj();
  8555. $out = '<< /Type /Font';
  8556. $out .= ' /Subtype /CIDFontType2';
  8557. $out .= ' /BaseFont /'.$fontname;
  8558. // A dictionary containing entries that define the character collection of the CIDFont.
  8559. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8560. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8561. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8562. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  8563. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8564. $out .= ' /DW '.$font['dw']; // default width
  8565. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, 0);
  8566. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8567. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  8568. }
  8569. $out .= ' >>';
  8570. $out .= "\n".'endobj';
  8571. $this->_out($out);
  8572. // Font descriptor
  8573. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  8574. $this->_newobj();
  8575. $out = '<< /Type /FontDescriptor';
  8576. $out .= ' /FontName /'.$fontname;
  8577. foreach ($font['desc'] as $key => $value) {
  8578. if (is_float($value)) {
  8579. $value = sprintf('%F', $value);
  8580. }
  8581. $out .= ' /'.$key.' '.$value;
  8582. }
  8583. $fontdir = false;
  8584. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8585. // A stream containing a TrueType font
  8586. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8587. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  8588. }
  8589. $out .= ' >>';
  8590. $out .= "\n".'endobj';
  8591. $this->_out($out);
  8592. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8593. $this->_newobj();
  8594. // Embed CIDToGIDMap
  8595. // A specification of the mapping from CIDs to glyph indices
  8596. // search and get CTG font file to embedd
  8597. $ctgfile = strtolower($font['ctg']);
  8598. // search and get ctg font file to embedd
  8599. $fontfile = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir);
  8600. if (TCPDF_STATIC::empty_string($fontfile)) {
  8601. $this->Error('Font file not found: '.$ctgfile);
  8602. }
  8603. $stream = $this->_getrawstream(file_get_contents($fontfile));
  8604. $out = '<< /Length '.strlen($stream).'';
  8605. if (substr($fontfile, -2) == '.z') { // check file extension
  8606. // Decompresses data encoded using the public-domain
  8607. // zlib/deflate compression method, reproducing the
  8608. // original text or binary data
  8609. $out .= ' /Filter /FlateDecode';
  8610. }
  8611. $out .= ' >>';
  8612. $out .= ' stream'."\n".$stream."\n".'endstream';
  8613. $out .= "\n".'endobj';
  8614. $this->_out($out);
  8615. }
  8616. }
  8617. /**
  8618. * Output CID-0 fonts.
  8619. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  8620. * @param $font (array) font data
  8621. * @protected
  8622. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  8623. * @since 3.2.000 (2008-06-23)
  8624. */
  8625. protected function _putcidfont0($font) {
  8626. $cidoffset = 0;
  8627. if (!isset($font['cw'][1])) {
  8628. $cidoffset = 31;
  8629. }
  8630. if (isset($font['cidinfo']['uni2cid'])) {
  8631. // convert unicode to cid.
  8632. $uni2cid = $font['cidinfo']['uni2cid'];
  8633. $cw = array();
  8634. foreach ($font['cw'] as $uni => $width) {
  8635. if (isset($uni2cid[$uni])) {
  8636. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  8637. } elseif ($uni < 256) {
  8638. $cw[$uni] = $width;
  8639. } // else unknown character
  8640. }
  8641. $font = array_merge($font, array('cw' => $cw));
  8642. }
  8643. $name = $font['name'];
  8644. $enc = $font['enc'];
  8645. if ($enc) {
  8646. $longname = $name.'-'.$enc;
  8647. } else {
  8648. $longname = $name;
  8649. }
  8650. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8651. $out .= '<</Type /Font';
  8652. $out .= ' /Subtype /Type0';
  8653. $out .= ' /BaseFont /'.$longname;
  8654. $out .= ' /Name /F'.$font['i'];
  8655. if ($enc) {
  8656. $out .= ' /Encoding /'.$enc;
  8657. }
  8658. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  8659. $out .= ' >>';
  8660. $out .= "\n".'endobj';
  8661. $this->_out($out);
  8662. $oid = $this->_newobj();
  8663. $out = '<</Type /Font';
  8664. $out .= ' /Subtype /CIDFontType0';
  8665. $out .= ' /BaseFont /'.$name;
  8666. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8667. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8668. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8669. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  8670. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8671. $out .= ' /DW '.$font['dw'];
  8672. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, $cidoffset);
  8673. $out .= ' >>';
  8674. $out .= "\n".'endobj';
  8675. $this->_out($out);
  8676. $this->_newobj();
  8677. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8678. foreach ($font['desc'] as $k => $v) {
  8679. if ($k != 'Style') {
  8680. if (is_float($v)) {
  8681. $v = sprintf('%F', $v);
  8682. }
  8683. $s .= ' /'.$k.' '.$v.'';
  8684. }
  8685. }
  8686. $s .= '>>';
  8687. $s .= "\n".'endobj';
  8688. $this->_out($s);
  8689. }
  8690. /**
  8691. * Output images.
  8692. * @protected
  8693. */
  8694. protected function _putimages() {
  8695. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8696. foreach ($this->imagekeys as $file) {
  8697. $info = $this->getImageBuffer($file);
  8698. // set object for alternate images array
  8699. if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
  8700. $altoid = $this->_newobj();
  8701. $out = '[';
  8702. foreach ($info['altimgs'] as $altimage) {
  8703. if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
  8704. $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
  8705. $out .= ' /DefaultForPrinting';
  8706. if ($altimage[1] === true) {
  8707. $out .= ' true';
  8708. } else {
  8709. $out .= ' false';
  8710. }
  8711. $out .= ' >>';
  8712. }
  8713. }
  8714. $out .= ' ]';
  8715. $out .= "\n".'endobj';
  8716. $this->_out($out);
  8717. }
  8718. // set image object
  8719. $oid = $this->_newobj();
  8720. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  8721. $this->setImageSubBuffer($file, 'n', $this->n);
  8722. $out = '<</Type /XObject';
  8723. $out .= ' /Subtype /Image';
  8724. $out .= ' /Width '.$info['w'];
  8725. $out .= ' /Height '.$info['h'];
  8726. if (array_key_exists('masked', $info)) {
  8727. $out .= ' /SMask '.($this->n - 1).' 0 R';
  8728. }
  8729. // set color space
  8730. $icc = false;
  8731. if (isset($info['icc']) AND ($info['icc'] !== false)) {
  8732. // ICC Colour Space
  8733. $icc = true;
  8734. $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
  8735. } elseif ($info['cs'] == 'Indexed') {
  8736. // Indexed Colour Space
  8737. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  8738. } else {
  8739. // Device Colour Space
  8740. $out .= ' /ColorSpace /'.$info['cs'];
  8741. }
  8742. if ($info['cs'] == 'DeviceCMYK') {
  8743. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  8744. }
  8745. $out .= ' /BitsPerComponent '.$info['bpc'];
  8746. if (isset($altoid) AND ($altoid > 0)) {
  8747. // reference to alternate images dictionary
  8748. $out .= ' /Alternates '.$altoid.' 0 R';
  8749. }
  8750. if (isset($info['exurl']) AND !empty($info['exurl'])) {
  8751. // external stream
  8752. $out .= ' /Length 0';
  8753. $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
  8754. if (isset($info['f'])) {
  8755. $out .= ' /FFilter /'.$info['f'];
  8756. }
  8757. $out .= ' >>';
  8758. $out .= ' stream'."\n".'endstream';
  8759. } else {
  8760. if (isset($info['f'])) {
  8761. $out .= ' /Filter /'.$info['f'];
  8762. }
  8763. if (isset($info['parms'])) {
  8764. $out .= ' '.$info['parms'];
  8765. }
  8766. if (isset($info['trns']) AND is_array($info['trns'])) {
  8767. $trns = '';
  8768. $count_info = count($info['trns']);
  8769. if ($info['cs'] == 'Indexed') {
  8770. $maxval =(pow(2, $info['bpc']) - 1);
  8771. for ($i = 0; $i < $count_info; ++$i) {
  8772. if (($info['trns'][$i] != 0) AND ($info['trns'][$i] != $maxval)) {
  8773. // this is not a binary type mask @TODO: create a SMask
  8774. $trns = '';
  8775. break;
  8776. } elseif (empty($trns) AND ($info['trns'][$i] == 0)) {
  8777. // store the first fully transparent value
  8778. $trns .= $i.' '.$i.' ';
  8779. }
  8780. }
  8781. } else {
  8782. // grayscale or RGB
  8783. for ($i = 0; $i < $count_info; ++$i) {
  8784. if ($info['trns'][$i] == 0) {
  8785. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  8786. }
  8787. }
  8788. }
  8789. // Colour Key Masking
  8790. if (!empty($trns)) {
  8791. $out .= ' /Mask ['.$trns.']';
  8792. }
  8793. }
  8794. $stream = $this->_getrawstream($info['data']);
  8795. $out .= ' /Length '.strlen($stream).' >>';
  8796. $out .= ' stream'."\n".$stream."\n".'endstream';
  8797. }
  8798. $out .= "\n".'endobj';
  8799. $this->_out($out);
  8800. if ($icc) {
  8801. // ICC colour profile
  8802. $this->_newobj();
  8803. $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
  8804. $icc = $this->_getrawstream($icc);
  8805. $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  8806. } elseif ($info['cs'] == 'Indexed') {
  8807. // colour palette
  8808. $this->_newobj();
  8809. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  8810. $pal = $this->_getrawstream($pal);
  8811. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  8812. }
  8813. }
  8814. }
  8815. /**
  8816. * Output Form XObjects Templates.
  8817. * @author Nicola Asuni
  8818. * @since 5.8.017 (2010-08-24)
  8819. * @protected
  8820. * @see startTemplate(), endTemplate(), printTemplate()
  8821. */
  8822. protected function _putxobjects() {
  8823. foreach ($this->xobjects as $key => $data) {
  8824. if (isset($data['outdata'])) {
  8825. $stream = str_replace($this->epsmarker, '', trim($data['outdata']));
  8826. $out = $this->_getobj($data['n'])."\n";
  8827. $out .= '<<';
  8828. $out .= ' /Type /XObject';
  8829. $out .= ' /Subtype /Form';
  8830. $out .= ' /FormType 1';
  8831. if ($this->compress) {
  8832. $stream = gzcompress($stream);
  8833. $out .= ' /Filter /FlateDecode';
  8834. }
  8835. $out .= sprintf(' /BBox [%F %F %F %F]', ($data['x'] * $this->k), (-$data['y'] * $this->k), (($data['w'] + $data['x']) * $this->k), (($data['h'] - $data['y']) * $this->k));
  8836. $out .= ' /Matrix [1 0 0 1 0 0]';
  8837. $out .= ' /Resources <<';
  8838. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8839. if (!$this->pdfa_mode) {
  8840. // transparency
  8841. if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
  8842. $out .= ' /ExtGState <<';
  8843. foreach ($data['extgstates'] as $k => $extgstate) {
  8844. if (isset($this->extgstates[$k]['name'])) {
  8845. $out .= ' /'.$this->extgstates[$k]['name'];
  8846. } else {
  8847. $out .= ' /GS'.$k;
  8848. }
  8849. $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
  8850. }
  8851. $out .= ' >>';
  8852. }
  8853. if (isset($data['gradients']) AND !empty($data['gradients'])) {
  8854. $gp = '';
  8855. $gs = '';
  8856. foreach ($data['gradients'] as $id => $grad) {
  8857. // gradient patterns
  8858. $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
  8859. // gradient shadings
  8860. $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
  8861. }
  8862. $out .= ' /Pattern <<'.$gp.' >>';
  8863. $out .= ' /Shading <<'.$gs.' >>';
  8864. }
  8865. }
  8866. // spot colors
  8867. if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
  8868. $out .= ' /ColorSpace <<';
  8869. foreach ($data['spot_colors'] as $name => $color) {
  8870. $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
  8871. }
  8872. $out .= ' >>';
  8873. }
  8874. // fonts
  8875. if (!empty($data['fonts'])) {
  8876. $out .= ' /Font <<';
  8877. foreach ($data['fonts'] as $fontkey => $fontid) {
  8878. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  8879. }
  8880. $out .= ' >>';
  8881. }
  8882. // images or nested xobjects
  8883. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  8884. $out .= ' /XObject <<';
  8885. foreach ($data['images'] as $imgid) {
  8886. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  8887. }
  8888. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  8889. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  8890. }
  8891. $out .= ' >>';
  8892. }
  8893. $out .= ' >>'; //end resources
  8894. if (isset($data['group']) AND ($data['group'] !== false)) {
  8895. // set transparency group
  8896. $out .= ' /Group << /Type /Group /S /Transparency';
  8897. if (is_array($data['group'])) {
  8898. if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
  8899. $out .= ' /CS /'.$data['group']['CS'];
  8900. }
  8901. if (isset($data['group']['I'])) {
  8902. $out .= ' /I /'.($data['group']['I']===true?'true':'false');
  8903. }
  8904. if (isset($data['group']['K'])) {
  8905. $out .= ' /K /'.($data['group']['K']===true?'true':'false');
  8906. }
  8907. }
  8908. $out .= ' >>';
  8909. }
  8910. $stream = $this->_getrawstream($stream, $data['n']);
  8911. $out .= ' /Length '.strlen($stream);
  8912. $out .= ' >>';
  8913. $out .= ' stream'."\n".$stream."\n".'endstream';
  8914. $out .= "\n".'endobj';
  8915. $this->_out($out);
  8916. }
  8917. }
  8918. }
  8919. /**
  8920. * Output Spot Colors Resources.
  8921. * @protected
  8922. * @since 4.0.024 (2008-09-12)
  8923. */
  8924. protected function _putspotcolors() {
  8925. foreach ($this->spot_colors as $name => $color) {
  8926. $this->_newobj();
  8927. $this->spot_colors[$name]['n'] = $this->n;
  8928. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  8929. $out .= ' /DeviceCMYK <<';
  8930. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  8931. $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
  8932. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  8933. $out .= "\n".'endobj';
  8934. $this->_out($out);
  8935. }
  8936. }
  8937. /**
  8938. * Return XObjects Dictionary.
  8939. * @return string XObjects dictionary
  8940. * @protected
  8941. * @since 5.8.014 (2010-08-23)
  8942. */
  8943. protected function _getxobjectdict() {
  8944. $out = '';
  8945. foreach ($this->xobjects as $id => $objid) {
  8946. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  8947. }
  8948. return $out;
  8949. }
  8950. /**
  8951. * Output Resources Dictionary.
  8952. * @protected
  8953. */
  8954. protected function _putresourcedict() {
  8955. $out = $this->_getobj(2)."\n";
  8956. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8957. $out .= ' /Font <<';
  8958. foreach ($this->fontkeys as $fontkey) {
  8959. $font = $this->getFontBuffer($fontkey);
  8960. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  8961. }
  8962. $out .= ' >>';
  8963. $out .= ' /XObject <<';
  8964. $out .= $this->_getxobjectdict();
  8965. $out .= ' >>';
  8966. // layers
  8967. if (!empty($this->pdflayers)) {
  8968. $out .= ' /Properties <<';
  8969. foreach ($this->pdflayers as $layer) {
  8970. $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
  8971. }
  8972. $out .= ' >>';
  8973. }
  8974. if (!$this->pdfa_mode) {
  8975. // transparency
  8976. if (isset($this->extgstates) AND !empty($this->extgstates)) {
  8977. $out .= ' /ExtGState <<';
  8978. foreach ($this->extgstates as $k => $extgstate) {
  8979. if (isset($extgstate['name'])) {
  8980. $out .= ' /'.$extgstate['name'];
  8981. } else {
  8982. $out .= ' /GS'.$k;
  8983. }
  8984. $out .= ' '.$extgstate['n'].' 0 R';
  8985. }
  8986. $out .= ' >>';
  8987. }
  8988. if (isset($this->gradients) AND !empty($this->gradients)) {
  8989. $gp = '';
  8990. $gs = '';
  8991. foreach ($this->gradients as $id => $grad) {
  8992. // gradient patterns
  8993. $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  8994. // gradient shadings
  8995. $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  8996. }
  8997. $out .= ' /Pattern <<'.$gp.' >>';
  8998. $out .= ' /Shading <<'.$gs.' >>';
  8999. }
  9000. }
  9001. // spot colors
  9002. if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
  9003. $out .= ' /ColorSpace <<';
  9004. foreach ($this->spot_colors as $color) {
  9005. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  9006. }
  9007. $out .= ' >>';
  9008. }
  9009. $out .= ' >>';
  9010. $out .= "\n".'endobj';
  9011. $this->_out($out);
  9012. }
  9013. /**
  9014. * Output Resources.
  9015. * @protected
  9016. */
  9017. protected function _putresources() {
  9018. $this->_putextgstates();
  9019. $this->_putocg();
  9020. $this->_putfonts();
  9021. $this->_putimages();
  9022. $this->_putspotcolors();
  9023. $this->_putshaders();
  9024. $this->_putxobjects();
  9025. $this->_putresourcedict();
  9026. $this->_putdests();
  9027. $this->_putEmbeddedFiles();
  9028. $this->_putannotsobjs();
  9029. $this->_putjavascript();
  9030. $this->_putbookmarks();
  9031. $this->_putencryption();
  9032. }
  9033. /**
  9034. * Adds some Metadata information (Document Information Dictionary)
  9035. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  9036. * @return int object id
  9037. * @protected
  9038. */
  9039. protected function _putinfo() {
  9040. $oid = $this->_newobj();
  9041. $out = '<<';
  9042. // store current isunicode value
  9043. $prev_isunicode = $this->isunicode;
  9044. if ($this->docinfounicode) {
  9045. $this->isunicode = true;
  9046. }
  9047. if (!TCPDF_STATIC::empty_string($this->title)) {
  9048. // The document's title.
  9049. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  9050. }
  9051. if (!TCPDF_STATIC::empty_string($this->author)) {
  9052. // The name of the person who created the document.
  9053. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  9054. }
  9055. if (!TCPDF_STATIC::empty_string($this->subject)) {
  9056. // The subject of the document.
  9057. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  9058. }
  9059. if (!TCPDF_STATIC::empty_string($this->keywords)) {
  9060. // Keywords associated with the document.
  9061. $out .= ' /Keywords '.$this->_textstring($this->keywords, $oid);
  9062. }
  9063. if (!TCPDF_STATIC::empty_string($this->creator)) {
  9064. // If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted.
  9065. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  9066. }
  9067. // restore previous isunicode value
  9068. $this->isunicode = $prev_isunicode;
  9069. // default producer
  9070. $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid);
  9071. // The date and time the document was created, in human-readable form
  9072. $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp);
  9073. // The date and time the document was most recently modified, in human-readable form
  9074. $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp);
  9075. // A name object indicating whether the document has been modified to include trapping information
  9076. $out .= ' /Trapped /False';
  9077. $out .= ' >>';
  9078. $out .= "\n".'endobj';
  9079. $this->_out($out);
  9080. return $oid;
  9081. }
  9082. /**
  9083. * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
  9084. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9085. * @param $xmp (string) Custom XMP data.
  9086. * @since 5.9.128 (2011-10-06)
  9087. * @public
  9088. */
  9089. public function setExtraXMP($xmp) {
  9090. $this->custom_xmp = $xmp;
  9091. }
  9092. /**
  9093. * Put XMP data object and return ID.
  9094. * @return (int) The object ID.
  9095. * @since 5.9.121 (2011-09-28)
  9096. * @protected
  9097. */
  9098. protected function _putXMP() {
  9099. $oid = $this->_newobj();
  9100. // store current isunicode value
  9101. $prev_isunicode = $this->isunicode;
  9102. $this->isunicode = true;
  9103. $prev_encrypted = $this->encrypted;
  9104. $this->encrypted = false;
  9105. // set XMP data
  9106. $xmp = '<?xpacket begin="'.TCPDF_FONTS::unichr(0xfeff, $this->isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
  9107. $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";
  9108. $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  9109. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  9110. $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
  9111. $xmp .= "\t\t\t".'<dc:title>'."\n";
  9112. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9113. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->title).'</rdf:li>'."\n";
  9114. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9115. $xmp .= "\t\t\t".'</dc:title>'."\n";
  9116. $xmp .= "\t\t\t".'<dc:creator>'."\n";
  9117. $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
  9118. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->author).'</rdf:li>'."\n";
  9119. $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
  9120. $xmp .= "\t\t\t".'</dc:creator>'."\n";
  9121. $xmp .= "\t\t\t".'<dc:description>'."\n";
  9122. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9123. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->subject).'</rdf:li>'."\n";
  9124. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9125. $xmp .= "\t\t\t".'</dc:description>'."\n";
  9126. $xmp .= "\t\t\t".'<dc:subject>'."\n";
  9127. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9128. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->keywords).'</rdf:li>'."\n";
  9129. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9130. $xmp .= "\t\t\t".'</dc:subject>'."\n";
  9131. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9132. // convert doc creation date format
  9133. $dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
  9134. $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
  9135. $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
  9136. $doccreationdate .= substr($dcdate, 14, 3).':'.substr($dcdate, 18, 2);
  9137. $doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate);
  9138. // convert doc modification date format
  9139. $dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
  9140. $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
  9141. $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
  9142. $docmoddate .= substr($dmdate, 14, 3).':'.substr($dmdate, 18, 2);
  9143. $docmoddate = TCPDF_STATIC::_escapeXML($docmoddate);
  9144. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  9145. $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
  9146. $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  9147. $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
  9148. $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
  9149. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9150. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  9151. $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC::_escapeXML($this->keywords).'</pdf:Keywords>'."\n";
  9152. $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).'</pdf:Producer>'."\n";
  9153. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9154. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  9155. $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);
  9156. $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
  9157. $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
  9158. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9159. if ($this->pdfa_mode) {
  9160. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
  9161. $xmp .= "\t\t\t".'<pdfaid:part>1</pdfaid:part>'."\n";
  9162. $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
  9163. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9164. }
  9165. // XMP extension schemas
  9166. $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";
  9167. $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
  9168. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9169. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9170. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
  9171. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
  9172. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
  9173. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9174. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9175. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
  9176. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
  9177. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
  9178. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9179. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9180. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9181. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9182. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
  9183. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9184. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9185. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9186. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9187. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9188. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9189. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9190. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
  9191. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
  9192. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
  9193. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9194. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9195. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9196. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9197. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
  9198. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
  9199. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
  9200. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9201. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9202. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9203. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
  9204. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
  9205. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9206. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9207. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9208. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9209. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
  9210. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
  9211. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9212. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9213. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9214. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9215. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9216. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9217. $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
  9218. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9219. $xmp .= "\t".'</rdf:RDF>'."\n";
  9220. $xmp .= $this->custom_xmp;
  9221. $xmp .= '</x:xmpmeta>'."\n";
  9222. $xmp .= '<?xpacket end="w"?>';
  9223. $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
  9224. // restore previous isunicode value
  9225. $this->isunicode = $prev_isunicode;
  9226. $this->encrypted = $prev_encrypted;
  9227. $this->_out($out);
  9228. return $oid;
  9229. }
  9230. /**
  9231. * Output Catalog.
  9232. * @return int object id
  9233. * @protected
  9234. */
  9235. protected function _putcatalog() {
  9236. // put XMP
  9237. $xmpobj = $this->_putXMP();
  9238. // if required, add standard sRGB ICC colour profile
  9239. if ($this->pdfa_mode OR $this->force_srgb) {
  9240. $iccobj = $this->_newobj();
  9241. $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
  9242. $filter = '';
  9243. if ($this->compress) {
  9244. $filter = ' /Filter /FlateDecode';
  9245. $icc = gzcompress($icc);
  9246. }
  9247. $icc = $this->_getrawstream($icc);
  9248. $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  9249. }
  9250. // start catalog
  9251. $oid = $this->_newobj();
  9252. $out = '<< /Type /Catalog';
  9253. $out .= ' /Version /'.$this->PDFVersion;
  9254. //$out .= ' /Extensions <<>>';
  9255. $out .= ' /Pages 1 0 R';
  9256. //$out .= ' /PageLabels ' //...;
  9257. $out .= ' /Names <<';
  9258. if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
  9259. $out .= ' /JavaScript '.$this->n_js;
  9260. }
  9261. if (!empty($this->efnames)) {
  9262. $out .= ' /EmbeddedFiles <</Names [';
  9263. foreach ($this->efnames AS $fn => $fref) {
  9264. $out .= ' '.$this->_datastring($fn).' '.$fref;
  9265. }
  9266. $out .= ' ]>>';
  9267. }
  9268. $out .= ' >>';
  9269. if (!empty($this->dests)) {
  9270. $out .= ' /Dests '.($this->n_dests).' 0 R';
  9271. }
  9272. $out .= $this->_putviewerpreferences();
  9273. if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) {
  9274. $out .= ' /PageLayout /'.$this->LayoutMode;
  9275. }
  9276. if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) {
  9277. $out .= ' /PageMode /'.$this->PageMode;
  9278. }
  9279. if (count($this->outlines) > 0) {
  9280. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  9281. $out .= ' /PageMode /UseOutlines';
  9282. }
  9283. //$out .= ' /Threads []';
  9284. if ($this->ZoomMode == 'fullpage') {
  9285. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  9286. } elseif ($this->ZoomMode == 'fullwidth') {
  9287. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  9288. } elseif ($this->ZoomMode == 'real') {
  9289. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  9290. } elseif (!is_string($this->ZoomMode)) {
  9291. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode / 100));
  9292. }
  9293. //$out .= ' /AA <<>>';
  9294. //$out .= ' /URI <<>>';
  9295. $out .= ' /Metadata '.$xmpobj.' 0 R';
  9296. //$out .= ' /StructTreeRoot <<>>';
  9297. //$out .= ' /MarkInfo <<>>';
  9298. if (isset($this->l['a_meta_language'])) {
  9299. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  9300. }
  9301. //$out .= ' /SpiderInfo <<>>';
  9302. // set OutputIntent to sRGB IEC61966-2.1 if required
  9303. if ($this->pdfa_mode OR $this->force_srgb) {
  9304. $out .= ' /OutputIntents [<<';
  9305. $out .= ' /Type /OutputIntent';
  9306. $out .= ' /S /GTS_PDFA1';
  9307. $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9308. $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9309. $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
  9310. $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9311. $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
  9312. $out .= ' >>]';
  9313. }
  9314. //$out .= ' /PieceInfo <<>>';
  9315. if (!empty($this->pdflayers)) {
  9316. $lyrobjs = '';
  9317. $lyrobjs_off = '';
  9318. $lyrobjs_lock = '';
  9319. foreach ($this->pdflayers as $layer) {
  9320. $layer_obj_ref = ' '.$layer['objid'].' 0 R';
  9321. $lyrobjs .= $layer_obj_ref;
  9322. if ($layer['view'] === false) {
  9323. $lyrobjs_off .= $layer_obj_ref;
  9324. }
  9325. if ($layer['lock']) {
  9326. $lyrobjs_lock .= $layer_obj_ref;
  9327. }
  9328. }
  9329. $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
  9330. $out .= ' /D <<';
  9331. $out .= ' /Name '.$this->_textstring('Layers', $oid);
  9332. $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
  9333. $out .= ' /BaseState /ON';
  9334. $out .= ' /OFF ['.$lyrobjs_off.']';
  9335. $out .= ' /Locked ['.$lyrobjs_lock.']';
  9336. $out .= ' /Intent /View';
  9337. $out .= ' /AS [';
  9338. $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
  9339. $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
  9340. $out .= ' ]';
  9341. $out .= ' /Order ['.$lyrobjs.']';
  9342. $out .= ' /ListMode /AllPages';
  9343. //$out .= ' /RBGroups ['..']';
  9344. //$out .= ' /Locked ['..']';
  9345. $out .= ' >>';
  9346. $out .= ' >>';
  9347. }
  9348. // AcroForm
  9349. if (!empty($this->form_obj_id)
  9350. OR ($this->sign AND isset($this->signature_data['cert_type']))
  9351. OR !empty($this->empty_signature_appearance)) {
  9352. $out .= ' /AcroForm <<';
  9353. $objrefs = '';
  9354. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9355. // set reference for signature object
  9356. $objrefs .= $this->sig_obj_id.' 0 R';
  9357. }
  9358. if (!empty($this->empty_signature_appearance)) {
  9359. foreach ($this->empty_signature_appearance as $esa) {
  9360. // set reference for empty signature objects
  9361. $objrefs .= ' '.$esa['objid'].' 0 R';
  9362. }
  9363. }
  9364. if (!empty($this->form_obj_id)) {
  9365. foreach($this->form_obj_id as $objid) {
  9366. $objrefs .= ' '.$objid.' 0 R';
  9367. }
  9368. }
  9369. $out .= ' /Fields ['.$objrefs.']';
  9370. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  9371. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  9372. $out .= ' /NeedAppearances false';
  9373. }
  9374. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9375. if ($this->signature_data['cert_type'] > 0) {
  9376. $out .= ' /SigFlags 3';
  9377. } else {
  9378. $out .= ' /SigFlags 1';
  9379. }
  9380. }
  9381. //$out .= ' /CO ';
  9382. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  9383. $out .= ' /DR <<';
  9384. $out .= ' /Font <<';
  9385. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  9386. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9387. }
  9388. $out .= ' >> >>';
  9389. }
  9390. $font = $this->getFontBuffer('helvetica');
  9391. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  9392. $out .= ' /Q '.(($this->rtl)?'2':'0');
  9393. //$out .= ' /XFA ';
  9394. $out .= ' >>';
  9395. // signatures
  9396. if ($this->sign AND isset($this->signature_data['cert_type'])
  9397. AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) {
  9398. if ($this->signature_data['cert_type'] > 0) {
  9399. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  9400. } else {
  9401. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  9402. }
  9403. }
  9404. }
  9405. //$out .= ' /Legal <<>>';
  9406. //$out .= ' /Requirements []';
  9407. //$out .= ' /Collection <<>>';
  9408. //$out .= ' /NeedsRendering true';
  9409. $out .= ' >>';
  9410. $out .= "\n".'endobj';
  9411. $this->_out($out);
  9412. return $oid;
  9413. }
  9414. /**
  9415. * Output viewer preferences.
  9416. * @return string for viewer preferences
  9417. * @author Nicola asuni
  9418. * @since 3.1.000 (2008-06-09)
  9419. * @protected
  9420. */
  9421. protected function _putviewerpreferences() {
  9422. $vp = $this->viewer_preferences;
  9423. $out = ' /ViewerPreferences <<';
  9424. if ($this->rtl) {
  9425. $out .= ' /Direction /R2L';
  9426. } else {
  9427. $out .= ' /Direction /L2R';
  9428. }
  9429. if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
  9430. $out .= ' /HideToolbar true';
  9431. }
  9432. if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
  9433. $out .= ' /HideMenubar true';
  9434. }
  9435. if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
  9436. $out .= ' /HideWindowUI true';
  9437. }
  9438. if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
  9439. $out .= ' /FitWindow true';
  9440. }
  9441. if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
  9442. $out .= ' /CenterWindow true';
  9443. }
  9444. if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
  9445. $out .= ' /DisplayDocTitle true';
  9446. }
  9447. if (isset($vp['NonFullScreenPageMode'])) {
  9448. $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
  9449. }
  9450. if (isset($vp['ViewArea'])) {
  9451. $out .= ' /ViewArea /'.$vp['ViewArea'];
  9452. }
  9453. if (isset($vp['ViewClip'])) {
  9454. $out .= ' /ViewClip /'.$vp['ViewClip'];
  9455. }
  9456. if (isset($vp['PrintArea'])) {
  9457. $out .= ' /PrintArea /'.$vp['PrintArea'];
  9458. }
  9459. if (isset($vp['PrintClip'])) {
  9460. $out .= ' /PrintClip /'.$vp['PrintClip'];
  9461. }
  9462. if (isset($vp['PrintScaling'])) {
  9463. $out .= ' /PrintScaling /'.$vp['PrintScaling'];
  9464. }
  9465. if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) {
  9466. $out .= ' /Duplex /'.$vp['Duplex'];
  9467. }
  9468. if (isset($vp['PickTrayByPDFSize'])) {
  9469. if ($vp['PickTrayByPDFSize']) {
  9470. $out .= ' /PickTrayByPDFSize true';
  9471. } else {
  9472. $out .= ' /PickTrayByPDFSize false';
  9473. }
  9474. }
  9475. if (isset($vp['PrintPageRange'])) {
  9476. $PrintPageRangeNum = '';
  9477. foreach ($vp['PrintPageRange'] as $k => $v) {
  9478. $PrintPageRangeNum .= ' '.($v - 1).'';
  9479. }
  9480. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  9481. }
  9482. if (isset($vp['NumCopies'])) {
  9483. $out .= ' /NumCopies '.intval($vp['NumCopies']);
  9484. }
  9485. $out .= ' >>';
  9486. return $out;
  9487. }
  9488. /**
  9489. * Output PDF File Header (7.5.2).
  9490. * @protected
  9491. */
  9492. protected function _putheader() {
  9493. $this->_out('%PDF-'.$this->PDFVersion);
  9494. $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
  9495. }
  9496. /**
  9497. * Output end of document (EOF).
  9498. * @protected
  9499. */
  9500. protected function _enddoc() {
  9501. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  9502. // save subset chars of the previous font
  9503. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  9504. }
  9505. $this->state = 1;
  9506. $this->_putheader();
  9507. $this->_putpages();
  9508. $this->_putresources();
  9509. // empty signature fields
  9510. if (!empty($this->empty_signature_appearance)) {
  9511. foreach ($this->empty_signature_appearance as $key => $esa) {
  9512. // widget annotation for empty signature
  9513. $out = $this->_getobj($esa['objid'])."\n";
  9514. $out .= '<< /Type /Annot';
  9515. $out .= ' /Subtype /Widget';
  9516. $out .= ' /Rect ['.$esa['rect'].']';
  9517. $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
  9518. $out .= ' /F 4';
  9519. $out .= ' /FT /Sig';
  9520. $signame = $esa['name'].sprintf(' [%03d]', ($key + 1));
  9521. $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
  9522. $out .= ' /Ff 0';
  9523. $out .= ' >>';
  9524. $out .= "\n".'endobj';
  9525. $this->_out($out);
  9526. }
  9527. }
  9528. // Signature
  9529. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9530. // widget annotation for signature
  9531. $out = $this->_getobj($this->sig_obj_id)."\n";
  9532. $out .= '<< /Type /Annot';
  9533. $out .= ' /Subtype /Widget';
  9534. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  9535. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  9536. $out .= ' /F 4';
  9537. $out .= ' /FT /Sig';
  9538. $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id);
  9539. $out .= ' /Ff 0';
  9540. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  9541. $out .= ' >>';
  9542. $out .= "\n".'endobj';
  9543. $this->_out($out);
  9544. // signature
  9545. $this->_putsignature();
  9546. }
  9547. // Info
  9548. $objid_info = $this->_putinfo();
  9549. // Catalog
  9550. $objid_catalog = $this->_putcatalog();
  9551. // Cross-ref
  9552. $o = $this->bufferlen;
  9553. // XREF section
  9554. $this->_out('xref');
  9555. $this->_out('0 '.($this->n + 1));
  9556. $this->_out('0000000000 65535 f ');
  9557. $freegen = ($this->n + 2);
  9558. for ($i=1; $i <= $this->n; ++$i) {
  9559. if (!isset($this->offsets[$i]) AND ($i > 1)) {
  9560. $this->_out(sprintf('0000000000 %05d f ', $freegen));
  9561. ++$freegen;
  9562. } else {
  9563. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  9564. }
  9565. }
  9566. // TRAILER
  9567. $out = 'trailer'."\n";
  9568. $out .= '<<';
  9569. $out .= ' /Size '.($this->n + 1);
  9570. $out .= ' /Root '.$objid_catalog.' 0 R';
  9571. $out .= ' /Info '.$objid_info.' 0 R';
  9572. if ($this->encrypted) {
  9573. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  9574. }
  9575. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  9576. $out .= ' >>';
  9577. $this->_out($out);
  9578. $this->_out('startxref');
  9579. $this->_out($o);
  9580. $this->_out('%%EOF');
  9581. $this->state = 3; // end-of-doc
  9582. }
  9583. /**
  9584. * Initialize a new page.
  9585. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  9586. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  9587. * @protected
  9588. * @see getPageSizeFromFormat(), setPageFormat()
  9589. */
  9590. protected function _beginpage($orientation='', $format='') {
  9591. ++$this->page;
  9592. $this->pageobjects[$this->page] = array();
  9593. $this->setPageBuffer($this->page, '');
  9594. // initialize array for graphics tranformation positions inside a page buffer
  9595. $this->transfmrk[$this->page] = array();
  9596. $this->state = 2;
  9597. if (TCPDF_STATIC::empty_string($orientation)) {
  9598. if (isset($this->CurOrientation)) {
  9599. $orientation = $this->CurOrientation;
  9600. } elseif ($this->fwPt > $this->fhPt) {
  9601. // landscape
  9602. $orientation = 'L';
  9603. } else {
  9604. // portrait
  9605. $orientation = 'P';
  9606. }
  9607. }
  9608. if (TCPDF_STATIC::empty_string($format)) {
  9609. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  9610. $this->setPageOrientation($orientation);
  9611. } else {
  9612. $this->setPageFormat($format, $orientation);
  9613. }
  9614. if ($this->rtl) {
  9615. $this->x = $this->w - $this->rMargin;
  9616. } else {
  9617. $this->x = $this->lMargin;
  9618. }
  9619. $this->y = $this->tMargin;
  9620. if (isset($this->newpagegroup[$this->page])) {
  9621. // start a new group
  9622. $this->currpagegroup = $this->newpagegroup[$this->page];
  9623. $this->pagegroups[$this->currpagegroup] = 1;
  9624. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  9625. ++$this->pagegroups[$this->currpagegroup];
  9626. }
  9627. }
  9628. /**
  9629. * Mark end of page.
  9630. * @protected
  9631. */
  9632. protected function _endpage() {
  9633. $this->setVisibility('all');
  9634. $this->state = 1;
  9635. }
  9636. /**
  9637. * Begin a new object and return the object number.
  9638. * @return int object number
  9639. * @protected
  9640. */
  9641. protected function _newobj() {
  9642. $this->_out($this->_getobj());
  9643. return $this->n;
  9644. }
  9645. /**
  9646. * Return the starting object string for the selected object ID.
  9647. * @param $objid (int) Object ID (leave empty to get a new ID).
  9648. * @return string the starting object string
  9649. * @protected
  9650. * @since 5.8.009 (2010-08-20)
  9651. */
  9652. protected function _getobj($objid='') {
  9653. if ($objid === '') {
  9654. ++$this->n;
  9655. $objid = $this->n;
  9656. }
  9657. $this->offsets[$objid] = $this->bufferlen;
  9658. $this->pageobjects[$this->page][] = $objid;
  9659. return $objid.' 0 obj';
  9660. }
  9661. /**
  9662. * Underline text.
  9663. * @param $x (int) X coordinate
  9664. * @param $y (int) Y coordinate
  9665. * @param $txt (string) text to underline
  9666. * @protected
  9667. */
  9668. protected function _dounderline($x, $y, $txt) {
  9669. $w = $this->GetStringWidth($txt);
  9670. return $this->_dounderlinew($x, $y, $w);
  9671. }
  9672. /**
  9673. * Underline for rectangular text area.
  9674. * @param $x (int) X coordinate
  9675. * @param $y (int) Y coordinate
  9676. * @param $w (int) width to underline
  9677. * @protected
  9678. * @since 4.8.008 (2009-09-29)
  9679. */
  9680. protected function _dounderlinew($x, $y, $w) {
  9681. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9682. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  9683. }
  9684. /**
  9685. * Line through text.
  9686. * @param $x (int) X coordinate
  9687. * @param $y (int) Y coordinate
  9688. * @param $txt (string) text to linethrough
  9689. * @protected
  9690. */
  9691. protected function _dolinethrough($x, $y, $txt) {
  9692. $w = $this->GetStringWidth($txt);
  9693. return $this->_dolinethroughw($x, $y, $w);
  9694. }
  9695. /**
  9696. * Line through for rectangular text area.
  9697. * @param $x (int) X coordinate
  9698. * @param $y (int) Y coordinate
  9699. * @param $w (int) line length (width)
  9700. * @protected
  9701. * @since 4.9.008 (2009-09-29)
  9702. */
  9703. protected function _dolinethroughw($x, $y, $w) {
  9704. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9705. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  9706. }
  9707. /**
  9708. * Overline text.
  9709. * @param $x (int) X coordinate
  9710. * @param $y (int) Y coordinate
  9711. * @param $txt (string) text to overline
  9712. * @protected
  9713. * @since 4.9.015 (2010-04-19)
  9714. */
  9715. protected function _dooverline($x, $y, $txt) {
  9716. $w = $this->GetStringWidth($txt);
  9717. return $this->_dooverlinew($x, $y, $w);
  9718. }
  9719. /**
  9720. * Overline for rectangular text area.
  9721. * @param $x (int) X coordinate
  9722. * @param $y (int) Y coordinate
  9723. * @param $w (int) width to overline
  9724. * @protected
  9725. * @since 4.9.015 (2010-04-19)
  9726. */
  9727. protected function _dooverlinew($x, $y, $w) {
  9728. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9729. return sprintf('%F %F %F %F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  9730. }
  9731. /**
  9732. * Format a data string for meta information
  9733. * @param $s (string) data string to escape.
  9734. * @param $n (int) object ID
  9735. * @return string escaped string.
  9736. * @protected
  9737. */
  9738. protected function _datastring($s, $n=0) {
  9739. if ($n == 0) {
  9740. $n = $this->n;
  9741. }
  9742. $s = $this->_encrypt_data($n, $s);
  9743. return '('. TCPDF_STATIC::_escape($s).')';
  9744. }
  9745. /**
  9746. * Set the document creation timestamp
  9747. * @param $time (mixed) Document creation timestamp in seconds or date-time string.
  9748. * @public
  9749. * @since 5.9.152 (2012-03-23)
  9750. */
  9751. public function setDocCreationTimestamp($time) {
  9752. if (is_string($time)) {
  9753. $time = TCPDF_STATIC::getTimestamp($time);
  9754. }
  9755. $this->doc_creation_timestamp = intval($time);
  9756. }
  9757. /**
  9758. * Set the document modification timestamp
  9759. * @param $time (mixed) Document modification timestamp in seconds or date-time string.
  9760. * @public
  9761. * @since 5.9.152 (2012-03-23)
  9762. */
  9763. public function setDocModificationTimestamp($time) {
  9764. if (is_string($time)) {
  9765. $time = TCPDF_STATIC::getTimestamp($time);
  9766. }
  9767. $this->doc_modification_timestamp = intval($time);
  9768. }
  9769. /**
  9770. * Returns document creation timestamp in seconds.
  9771. * @return (int) Creation timestamp in seconds.
  9772. * @public
  9773. * @since 5.9.152 (2012-03-23)
  9774. */
  9775. public function getDocCreationTimestamp() {
  9776. return $this->doc_creation_timestamp;
  9777. }
  9778. /**
  9779. * Returns document modification timestamp in seconds.
  9780. * @return (int) Modfication timestamp in seconds.
  9781. * @public
  9782. * @since 5.9.152 (2012-03-23)
  9783. */
  9784. public function getDocModificationTimestamp() {
  9785. return $this->doc_modification_timestamp;
  9786. }
  9787. /**
  9788. * Returns a formatted date for meta information
  9789. * @param $n (int) Object ID.
  9790. * @param $timestamp (int) Timestamp to convert.
  9791. * @return string escaped date string.
  9792. * @protected
  9793. * @since 4.6.028 (2009-08-25)
  9794. */
  9795. protected function _datestring($n=0, $timestamp=0) {
  9796. if ((empty($timestamp)) OR ($timestamp < 0)) {
  9797. $timestamp = $this->doc_creation_timestamp;
  9798. }
  9799. return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n);
  9800. }
  9801. /**
  9802. * Format a text string for meta information
  9803. * @param $s (string) string to escape.
  9804. * @param $n (int) object ID
  9805. * @return string escaped string.
  9806. * @protected
  9807. */
  9808. protected function _textstring($s, $n=0) {
  9809. if ($this->isunicode) {
  9810. //Convert string to UTF-16BE
  9811. $s = TCPDF_FONTS::UTF8ToUTF16BE($s, true, $this->isunicode, $this->CurrentFont);
  9812. }
  9813. return $this->_datastring($s, $n);
  9814. }
  9815. /**
  9816. * get raw output stream.
  9817. * @param $s (string) string to output.
  9818. * @param $n (int) object reference for encryption mode
  9819. * @protected
  9820. * @author Nicola Asuni
  9821. * @since 5.5.000 (2010-06-22)
  9822. */
  9823. protected function _getrawstream($s, $n=0) {
  9824. if ($n <= 0) {
  9825. // default to current object
  9826. $n = $this->n;
  9827. }
  9828. return $this->_encrypt_data($n, $s);
  9829. }
  9830. /**
  9831. * Output a string to the document.
  9832. * @param $s (string) string to output.
  9833. * @protected
  9834. */
  9835. protected function _out($s) {
  9836. if ($this->state == 2) {
  9837. if ($this->inxobj) {
  9838. // we are inside an XObject template
  9839. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  9840. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  9841. // puts data before page footer
  9842. $pagebuff = $this->getPageBuffer($this->page);
  9843. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  9844. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  9845. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  9846. // update footer position
  9847. $this->footerpos[$this->page] += strlen($s."\n");
  9848. } else {
  9849. // set page data
  9850. $this->setPageBuffer($this->page, $s."\n", true);
  9851. }
  9852. } elseif ($this->state > 0) {
  9853. // set general data
  9854. $this->setBuffer($s."\n");
  9855. }
  9856. }
  9857. /**
  9858. * Set header font.
  9859. * @param $font (array) Array describing the basic font parameters: (family, style, size).
  9860. * @public
  9861. * @since 1.1
  9862. */
  9863. public function setHeaderFont($font) {
  9864. $this->header_font = $font;
  9865. }
  9866. /**
  9867. * Get header font.
  9868. * @return array() Array describing the basic font parameters: (family, style, size).
  9869. * @public
  9870. * @since 4.0.012 (2008-07-24)
  9871. */
  9872. public function getHeaderFont() {
  9873. return $this->header_font;
  9874. }
  9875. /**
  9876. * Set footer font.
  9877. * @param $font (array) Array describing the basic font parameters: (family, style, size).
  9878. * @public
  9879. * @since 1.1
  9880. */
  9881. public function setFooterFont($font) {
  9882. $this->footer_font = $font;
  9883. }
  9884. /**
  9885. * Get Footer font.
  9886. * @return array() Array describing the basic font parameters: (family, style, size).
  9887. * @public
  9888. * @since 4.0.012 (2008-07-24)
  9889. */
  9890. public function getFooterFont() {
  9891. return $this->footer_font;
  9892. }
  9893. /**
  9894. * Set language array.
  9895. * @param $language (array)
  9896. * @public
  9897. * @since 1.1
  9898. */
  9899. public function setLanguageArray($language) {
  9900. $this->l = $language;
  9901. if (isset($this->l['a_meta_dir'])) {
  9902. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  9903. } else {
  9904. $this->rtl = false;
  9905. }
  9906. }
  9907. /**
  9908. * Returns the PDF data.
  9909. * @public
  9910. */
  9911. public function getPDFData() {
  9912. if ($this->state < 3) {
  9913. $this->Close();
  9914. }
  9915. return $this->buffer;
  9916. }
  9917. /**
  9918. * Output anchor link.
  9919. * @param $url (string) link URL or internal link (i.e.: &lt;a href="#23,4.5"&gt;link to page 23 at 4.5 Y position&lt;/a&gt;)
  9920. * @param $name (string) link name
  9921. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  9922. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  9923. * @param $color (array) array of RGB text color
  9924. * @param $style (string) font style (U, D, B, I)
  9925. * @param $firstblock (boolean) if true the string is the starting of a line.
  9926. * @return the number of cells used or the remaining text if $firstline = true;
  9927. * @public
  9928. */
  9929. public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
  9930. if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
  9931. // convert url to internal link
  9932. $lnkdata = explode(',', $url);
  9933. if (isset($lnkdata[0]) ) {
  9934. $page = substr($lnkdata[0], 1);
  9935. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  9936. $lnky = floatval($lnkdata[1]);
  9937. } else {
  9938. $lnky = 0;
  9939. }
  9940. $url = $this->AddLink();
  9941. $this->SetLink($url, $lnky, $page);
  9942. }
  9943. }
  9944. // store current settings
  9945. $prevcolor = $this->fgcolor;
  9946. $prevstyle = $this->FontStyle;
  9947. if (empty($color)) {
  9948. $this->SetTextColorArray($this->htmlLinkColorArray);
  9949. } else {
  9950. $this->SetTextColorArray($color);
  9951. }
  9952. if ($style == -1) {
  9953. $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  9954. } else {
  9955. $this->SetFont('', $this->FontStyle.$style);
  9956. }
  9957. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  9958. // restore settings
  9959. $this->SetFont('', $prevstyle);
  9960. $this->SetTextColorArray($prevcolor);
  9961. return $ret;
  9962. }
  9963. /**
  9964. * Converts pixels to User's Units.
  9965. * @param $px (int) pixels
  9966. * @return float value in user's unit
  9967. * @public
  9968. * @see setImageScale(), getImageScale()
  9969. */
  9970. public function pixelsToUnits($px) {
  9971. return ($px / ($this->imgscale * $this->k));
  9972. }
  9973. /**
  9974. * Reverse function for htmlentities.
  9975. * Convert entities in UTF-8.
  9976. * @param $text_to_convert (string) Text to convert.
  9977. * @return string converted text string
  9978. * @public
  9979. */
  9980. public function unhtmlentities($text_to_convert) {
  9981. return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  9982. }
  9983. // ENCRYPTION METHODS ----------------------------------
  9984. /**
  9985. * Compute encryption key depending on object number where the encrypted data is stored.
  9986. * This is used for all strings and streams without crypt filter specifier.
  9987. * @param $n (int) object number
  9988. * @return int object key
  9989. * @protected
  9990. * @author Nicola Asuni
  9991. * @since 2.0.000 (2008-01-02)
  9992. */
  9993. protected function _objectkey($n) {
  9994. $objkey = $this->encryptdata['key'].pack('VXxx', $n);
  9995. if ($this->encryptdata['mode'] == 2) { // AES-128
  9996. // AES padding
  9997. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  9998. }
  9999. $objkey = substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  10000. $objkey = substr($objkey, 0, 16);
  10001. return $objkey;
  10002. }
  10003. /**
  10004. * Encrypt the input string.
  10005. * @param $n (int) object number
  10006. * @param $s (string) data string to encrypt
  10007. * @return encrypted string
  10008. * @protected
  10009. * @author Nicola Asuni
  10010. * @since 5.0.005 (2010-05-11)
  10011. */
  10012. protected function _encrypt_data($n, $s) {
  10013. if (!$this->encrypted) {
  10014. return $s;
  10015. }
  10016. switch ($this->encryptdata['mode']) {
  10017. case 0: // RC4-40
  10018. case 1: { // RC4-128
  10019. $s = TCPDF_STATIC::_RC4($this->_objectkey($n), $s, $this->last_enc_key, $this->last_enc_key_c);
  10020. break;
  10021. }
  10022. case 2: { // AES-128
  10023. $s = TCPDF_STATIC::_AES($this->_objectkey($n), $s);
  10024. break;
  10025. }
  10026. case 3: { // AES-256
  10027. $s = TCPDF_STATIC::_AES($this->encryptdata['key'], $s);
  10028. break;
  10029. }
  10030. }
  10031. return $s;
  10032. }
  10033. /**
  10034. * Put encryption on PDF document.
  10035. * @protected
  10036. * @author Nicola Asuni
  10037. * @since 2.0.000 (2008-01-02)
  10038. */
  10039. protected function _putencryption() {
  10040. if (!$this->encrypted) {
  10041. return;
  10042. }
  10043. $this->encryptdata['objid'] = $this->_newobj();
  10044. $out = '<<';
  10045. if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  10046. $this->encryptdata['Filter'] = 'Standard';
  10047. }
  10048. $out .= ' /Filter /'.$this->encryptdata['Filter'];
  10049. if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  10050. $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  10051. }
  10052. if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  10053. $this->encryptdata['V'] = 1;
  10054. }
  10055. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  10056. $out .= ' /V '.$this->encryptdata['V'];
  10057. if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  10058. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  10059. $out .= ' /Length '.$this->encryptdata['Length'];
  10060. } else {
  10061. $out .= ' /Length 40';
  10062. }
  10063. if ($this->encryptdata['V'] >= 4) {
  10064. if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  10065. $this->encryptdata['StmF'] = 'Identity';
  10066. }
  10067. if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  10068. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10069. $this->encryptdata['StrF'] = 'Identity';
  10070. }
  10071. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  10072. if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  10073. $out .= ' /CF <<';
  10074. $out .= ' /'.$this->encryptdata['StmF'].' <<';
  10075. $out .= ' /Type /CryptFilter';
  10076. if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  10077. // The method used
  10078. $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  10079. if ($this->encryptdata['pubkey']) {
  10080. $out .= ' /Recipients [';
  10081. foreach ($this->encryptdata['Recipients'] as $rec) {
  10082. $out .= ' <'.$rec.'>';
  10083. }
  10084. $out .= ' ]';
  10085. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  10086. $out .= ' /EncryptMetadata false';
  10087. } else {
  10088. $out .= ' /EncryptMetadata true';
  10089. }
  10090. }
  10091. } else {
  10092. $out .= ' /CFM /None';
  10093. }
  10094. if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  10095. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  10096. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  10097. } else {
  10098. $out .= ' /AuthEvent /DocOpen';
  10099. }
  10100. if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  10101. // The bit length of the encryption key.
  10102. $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  10103. }
  10104. $out .= ' >> >>';
  10105. }
  10106. // The name of the crypt filter that shall be used by default when decrypting streams.
  10107. $out .= ' /StmF /'.$this->encryptdata['StmF'];
  10108. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10109. $out .= ' /StrF /'.$this->encryptdata['StrF'];
  10110. if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  10111. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  10112. $out .= ' /EFF /'.$this->encryptdata[''];
  10113. }
  10114. }
  10115. // Additional encryption dictionary entries for the standard security handler
  10116. if ($this->encryptdata['pubkey']) {
  10117. if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  10118. $out .= ' /Recipients [';
  10119. foreach ($this->encryptdata['Recipients'] as $rec) {
  10120. $out .= ' <'.$rec.'>';
  10121. }
  10122. $out .= ' ]';
  10123. }
  10124. } else {
  10125. $out .= ' /R';
  10126. if ($this->encryptdata['V'] == 5) { // AES-256
  10127. $out .= ' 5';
  10128. $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')';
  10129. $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')';
  10130. $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')';
  10131. } elseif ($this->encryptdata['V'] == 4) { // AES-128
  10132. $out .= ' 4';
  10133. } elseif ($this->encryptdata['V'] < 2) { // RC-40
  10134. $out .= ' 2';
  10135. } else { // RC-128
  10136. $out .= ' 3';
  10137. }
  10138. $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')';
  10139. $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')';
  10140. $out .= ' /P '.$this->encryptdata['P'];
  10141. if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  10142. $out .= ' /EncryptMetadata false';
  10143. } else {
  10144. $out .= ' /EncryptMetadata true';
  10145. }
  10146. }
  10147. $out .= ' >>';
  10148. $out .= "\n".'endobj';
  10149. $this->_out($out);
  10150. }
  10151. /**
  10152. * Compute U value (used for encryption)
  10153. * @return string U value
  10154. * @protected
  10155. * @since 2.0.000 (2008-01-02)
  10156. * @author Nicola Asuni
  10157. */
  10158. protected function _Uvalue() {
  10159. if ($this->encryptdata['mode'] == 0) { // RC4-40
  10160. return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding, $this->last_enc_key, $this->last_enc_key_c);
  10161. } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  10162. $tmp = TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']);
  10163. $enc = TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp, $this->last_enc_key, $this->last_enc_key_c);
  10164. $len = strlen($tmp);
  10165. for ($i = 1; $i <= 19; ++$i) {
  10166. $ek = '';
  10167. for ($j = 0; $j < $len; ++$j) {
  10168. $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
  10169. }
  10170. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10171. }
  10172. $enc .= str_repeat("\x00", 16);
  10173. return substr($enc, 0, 32);
  10174. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10175. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10176. // User Validation Salt
  10177. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  10178. // User Key Salt
  10179. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  10180. return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  10181. }
  10182. }
  10183. /**
  10184. * Compute UE value (used for encryption)
  10185. * @return string UE value
  10186. * @protected
  10187. * @since 5.9.006 (2010-10-19)
  10188. * @author Nicola Asuni
  10189. */
  10190. protected function _UEvalue() {
  10191. $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  10192. return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
  10193. }
  10194. /**
  10195. * Compute O value (used for encryption)
  10196. * @return string O value
  10197. * @protected
  10198. * @since 2.0.000 (2008-01-02)
  10199. * @author Nicola Asuni
  10200. */
  10201. protected function _Ovalue() {
  10202. if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  10203. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']);
  10204. if ($this->encryptdata['mode'] > 0) {
  10205. for ($i = 0; $i < 50; ++$i) {
  10206. $tmp = TCPDF_STATIC::_md5_16($tmp);
  10207. }
  10208. }
  10209. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  10210. $enc = TCPDF_STATIC::_RC4($owner_key, $this->encryptdata['user_password'], $this->last_enc_key, $this->last_enc_key_c);
  10211. if ($this->encryptdata['mode'] > 0) {
  10212. $len = strlen($owner_key);
  10213. for ($i = 1; $i <= 19; ++$i) {
  10214. $ek = '';
  10215. for ($j = 0; $j < $len; ++$j) {
  10216. $ek .= chr(ord($owner_key[$j]) ^ $i);
  10217. }
  10218. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10219. }
  10220. }
  10221. return $enc;
  10222. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10223. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10224. // Owner Validation Salt
  10225. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  10226. // Owner Key Salt
  10227. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  10228. return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  10229. }
  10230. }
  10231. /**
  10232. * Compute OE value (used for encryption)
  10233. * @return string OE value
  10234. * @protected
  10235. * @since 5.9.006 (2010-10-19)
  10236. * @author Nicola Asuni
  10237. */
  10238. protected function _OEvalue() {
  10239. $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  10240. return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
  10241. }
  10242. /**
  10243. * Convert password for AES-256 encryption mode
  10244. * @param $password (string) password
  10245. * @return string password
  10246. * @protected
  10247. * @since 5.9.006 (2010-10-19)
  10248. * @author Nicola Asuni
  10249. */
  10250. protected function _fixAES256Password($password) {
  10251. $psw = ''; // password to be returned
  10252. $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont);
  10253. foreach ($psw_array as $c) {
  10254. $psw .= TCPDF_FONTS::unichr($c, $this->isunicode);
  10255. }
  10256. return substr($psw, 0, 127);
  10257. }
  10258. /**
  10259. * Compute encryption key
  10260. * @protected
  10261. * @since 2.0.000 (2008-01-02)
  10262. * @author Nicola Asuni
  10263. */
  10264. protected function _generateencryptionkey() {
  10265. $keybytelen = ($this->encryptdata['Length'] / 8);
  10266. if (!$this->encryptdata['pubkey']) { // standard mode
  10267. if ($this->encryptdata['mode'] == 3) { // AES-256
  10268. // generate 256 bit random key
  10269. $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen);
  10270. // truncate passwords
  10271. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  10272. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  10273. // Compute U value
  10274. $this->encryptdata['U'] = $this->_Uvalue();
  10275. // Compute UE value
  10276. $this->encryptdata['UE'] = $this->_UEvalue();
  10277. // Compute O value
  10278. $this->encryptdata['O'] = $this->_Ovalue();
  10279. // Compute OE value
  10280. $this->encryptdata['OE'] = $this->_OEvalue();
  10281. // Compute P value
  10282. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10283. // Computing the encryption dictionary's Perms (permissions) value
  10284. $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  10285. $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  10286. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  10287. $perms .= 'F';
  10288. } else {
  10289. $perms .= 'T';
  10290. }
  10291. $perms .= 'adb'; // bytes 9-11
  10292. $perms .= 'nick'; // bytes 12-15
  10293. $this->encryptdata['perms'] = TCPDF_STATIC::_AESnopad($this->encryptdata['key'], $perms);
  10294. } else { // RC4-40, RC4-128, AES-128
  10295. // Pad passwords
  10296. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10297. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10298. // Compute O value
  10299. $this->encryptdata['O'] = $this->_Ovalue();
  10300. // get default permissions (reverse byte order)
  10301. $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
  10302. // Compute encryption key
  10303. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  10304. if ($this->encryptdata['mode'] > 0) {
  10305. for ($i = 0; $i < 50; ++$i) {
  10306. $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen));
  10307. }
  10308. }
  10309. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  10310. // Compute U value
  10311. $this->encryptdata['U'] = $this->_Uvalue();
  10312. // Compute P value
  10313. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10314. }
  10315. } else { // Public-Key mode
  10316. // random 20-byte seed
  10317. $seed = sha1(TCPDF_STATIC::getRandomSeed(), true);
  10318. $recipient_bytes = '';
  10319. foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  10320. // for each public certificate
  10321. if (isset($pubkey['p'])) {
  10322. $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  10323. } else {
  10324. $pkprotection = $this->encryptdata['protection'];
  10325. }
  10326. // get default permissions (reverse byte order)
  10327. $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection);
  10328. // envelope data
  10329. $envelope = $seed.$pkpermissions;
  10330. // write the envelope data to a temporary file
  10331. $tempkeyfile = TCPDF_STATIC::getObjFilename('key', $this->file_id);
  10332. $f = TCPDF_STATIC::fopenLocal($tempkeyfile, 'wb');
  10333. if (!$f) {
  10334. $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  10335. }
  10336. $envelope_length = strlen($envelope);
  10337. fwrite($f, $envelope, $envelope_length);
  10338. fclose($f);
  10339. $tempencfile = TCPDF_STATIC::getObjFilename('enc', $this->file_id);
  10340. if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
  10341. $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  10342. }
  10343. // read encryption signature
  10344. $signature = file_get_contents($tempencfile, false, null, $envelope_length);
  10345. // extract signature
  10346. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  10347. $tmparr = explode("\n\n", $signature);
  10348. $signature = trim($tmparr[1]);
  10349. unset($tmparr);
  10350. // decode signature
  10351. $signature = base64_decode($signature);
  10352. // convert signature to hex
  10353. $hexsignature = current(unpack('H*', $signature));
  10354. // store signature on recipients array
  10355. $this->encryptdata['Recipients'][] = $hexsignature;
  10356. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  10357. $recipient_bytes .= $signature;
  10358. }
  10359. // calculate encryption key
  10360. if ($this->encryptdata['mode'] == 3) { // AES-256
  10361. $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
  10362. } else { // RC4-40, RC4-128, AES-128
  10363. $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
  10364. }
  10365. }
  10366. }
  10367. /**
  10368. * Set document protection
  10369. * Remark: the protection against modification is for people who have the full Acrobat product.
  10370. * If you don't set any password, the document will open as usual. If you set a user password, the PDF viewer will ask for it before displaying the document. The master password, if different from the user one, can be used to get full access.
  10371. * Note: protecting a document requires to encrypt it, which increases the processing time a lot. This can cause a PHP time-out in some cases, especially if the document contains images or fonts.
  10372. * @param $permissions (Array) the set of permissions (specify the ones you want to block):<ul><li>print : Print the document;</li><li>modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';</li><li>copy : Copy or otherwise extract text and graphics from the document;</li><li>annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);</li><li>fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;</li><li>extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);</li><li>assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;</li><li>print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.</li><li>owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.</li></ul>
  10373. * @param $user_pass (String) user password. Empty by default.
  10374. * @param $owner_pass (String) owner password. If not specified, a random value is used.
  10375. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  10376. * @param $pubkeys (String) array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
  10377. * @public
  10378. * @since 2.0.000 (2008-01-02)
  10379. * @author Nicola Asuni
  10380. */
  10381. 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) {
  10382. if ($this->pdfa_mode) {
  10383. // encryption is not allowed in PDF/A mode
  10384. return;
  10385. }
  10386. $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions, $mode);
  10387. if (($pubkeys !== null) AND (is_array($pubkeys))) {
  10388. // public-key mode
  10389. $this->encryptdata['pubkeys'] = $pubkeys;
  10390. if ($mode == 0) {
  10391. // public-Key Security requires at least 128 bit
  10392. $mode = 1;
  10393. }
  10394. if (!function_exists('openssl_pkcs7_encrypt')) {
  10395. $this->Error('Public-Key Security requires openssl library.');
  10396. }
  10397. // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  10398. $this->encryptdata['pubkey'] = true;
  10399. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  10400. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  10401. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  10402. } else {
  10403. // standard mode (password mode)
  10404. $this->encryptdata['pubkey'] = false;
  10405. $this->encryptdata['Filter'] = 'Standard';
  10406. $this->encryptdata['StmF'] = 'StdCF';
  10407. $this->encryptdata['StrF'] = 'StdCF';
  10408. }
  10409. if ($mode > 1) { // AES
  10410. if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) {
  10411. $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).');
  10412. }
  10413. if (extension_loaded('openssl') && !in_array('aes-256-cbc', openssl_get_cipher_methods())) {
  10414. $this->Error('AES encryption requires openssl/aes-256-cbc cypher.');
  10415. }
  10416. if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  10417. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  10418. }
  10419. if (($mode == 3) AND !function_exists('hash')) {
  10420. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  10421. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  10422. }
  10423. }
  10424. if ($owner_pass === null) {
  10425. $owner_pass = md5(TCPDF_STATIC::getRandomSeed());
  10426. }
  10427. $this->encryptdata['user_password'] = $user_pass;
  10428. $this->encryptdata['owner_password'] = $owner_pass;
  10429. $this->encryptdata['mode'] = $mode;
  10430. switch ($mode) {
  10431. case 0: { // RC4 40 bit
  10432. $this->encryptdata['V'] = 1;
  10433. $this->encryptdata['Length'] = 40;
  10434. $this->encryptdata['CF']['CFM'] = 'V2';
  10435. break;
  10436. }
  10437. case 1: { // RC4 128 bit
  10438. $this->encryptdata['V'] = 2;
  10439. $this->encryptdata['Length'] = 128;
  10440. $this->encryptdata['CF']['CFM'] = 'V2';
  10441. if ($this->encryptdata['pubkey']) {
  10442. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  10443. $this->encryptdata['Recipients'] = array();
  10444. }
  10445. break;
  10446. }
  10447. case 2: { // AES 128 bit
  10448. $this->encryptdata['V'] = 4;
  10449. $this->encryptdata['Length'] = 128;
  10450. $this->encryptdata['CF']['CFM'] = 'AESV2';
  10451. $this->encryptdata['CF']['Length'] = 128;
  10452. if ($this->encryptdata['pubkey']) {
  10453. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10454. $this->encryptdata['Recipients'] = array();
  10455. }
  10456. break;
  10457. }
  10458. case 3: { // AES 256 bit
  10459. $this->encryptdata['V'] = 5;
  10460. $this->encryptdata['Length'] = 256;
  10461. $this->encryptdata['CF']['CFM'] = 'AESV3';
  10462. $this->encryptdata['CF']['Length'] = 256;
  10463. if ($this->encryptdata['pubkey']) {
  10464. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10465. $this->encryptdata['Recipients'] = array();
  10466. }
  10467. break;
  10468. }
  10469. }
  10470. $this->encrypted = true;
  10471. $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id);
  10472. $this->_generateencryptionkey();
  10473. }
  10474. // END OF ENCRYPTION FUNCTIONS -------------------------
  10475. // START TRANSFORMATIONS SECTION -----------------------
  10476. /**
  10477. * Starts a 2D tranformation saving current graphic state.
  10478. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  10479. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10480. * @public
  10481. * @since 2.1.000 (2008-01-07)
  10482. * @see StartTransform(), StopTransform()
  10483. */
  10484. public function StartTransform() {
  10485. if ($this->state != 2) {
  10486. return;
  10487. }
  10488. $this->_outSaveGraphicsState();
  10489. if ($this->inxobj) {
  10490. // we are inside an XObject template
  10491. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10492. } else {
  10493. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  10494. }
  10495. ++$this->transfmatrix_key;
  10496. $this->transfmatrix[$this->transfmatrix_key] = array();
  10497. }
  10498. /**
  10499. * Stops a 2D tranformation restoring previous graphic state.
  10500. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  10501. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10502. * @public
  10503. * @since 2.1.000 (2008-01-07)
  10504. * @see StartTransform(), StopTransform()
  10505. */
  10506. public function StopTransform() {
  10507. if ($this->state != 2) {
  10508. return;
  10509. }
  10510. $this->_outRestoreGraphicsState();
  10511. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  10512. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  10513. --$this->transfmatrix_key;
  10514. }
  10515. if ($this->inxobj) {
  10516. // we are inside an XObject template
  10517. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  10518. } else {
  10519. array_pop($this->transfmrk[$this->page]);
  10520. }
  10521. }
  10522. /**
  10523. * Horizontal Scaling.
  10524. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  10525. * @param $x (int) abscissa of the scaling center. Default is current x position
  10526. * @param $y (int) ordinate of the scaling center. Default is current y position
  10527. * @public
  10528. * @since 2.1.000 (2008-01-07)
  10529. * @see StartTransform(), StopTransform()
  10530. */
  10531. public function ScaleX($s_x, $x='', $y='') {
  10532. $this->Scale($s_x, 100, $x, $y);
  10533. }
  10534. /**
  10535. * Vertical Scaling.
  10536. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  10537. * @param $x (int) abscissa of the scaling center. Default is current x position
  10538. * @param $y (int) ordinate of the scaling center. Default is current y position
  10539. * @public
  10540. * @since 2.1.000 (2008-01-07)
  10541. * @see StartTransform(), StopTransform()
  10542. */
  10543. public function ScaleY($s_y, $x='', $y='') {
  10544. $this->Scale(100, $s_y, $x, $y);
  10545. }
  10546. /**
  10547. * Vertical and horizontal proportional Scaling.
  10548. * @param $s (float) scaling factor for width and height as percent. 0 is not allowed.
  10549. * @param $x (int) abscissa of the scaling center. Default is current x position
  10550. * @param $y (int) ordinate of the scaling center. Default is current y position
  10551. * @public
  10552. * @since 2.1.000 (2008-01-07)
  10553. * @see StartTransform(), StopTransform()
  10554. */
  10555. public function ScaleXY($s, $x='', $y='') {
  10556. $this->Scale($s, $s, $x, $y);
  10557. }
  10558. /**
  10559. * Vertical and horizontal non-proportional Scaling.
  10560. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  10561. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  10562. * @param $x (int) abscissa of the scaling center. Default is current x position
  10563. * @param $y (int) ordinate of the scaling center. Default is current y position
  10564. * @public
  10565. * @since 2.1.000 (2008-01-07)
  10566. * @see StartTransform(), StopTransform()
  10567. */
  10568. public function Scale($s_x, $s_y, $x='', $y='') {
  10569. if ($x === '') {
  10570. $x = $this->x;
  10571. }
  10572. if ($y === '') {
  10573. $y = $this->y;
  10574. }
  10575. if (($s_x == 0) OR ($s_y == 0)) {
  10576. $this->Error('Please do not use values equal to zero for scaling');
  10577. }
  10578. $y = ($this->h - $y) * $this->k;
  10579. $x *= $this->k;
  10580. //calculate elements of transformation matrix
  10581. $s_x /= 100;
  10582. $s_y /= 100;
  10583. $tm = array();
  10584. $tm[0] = $s_x;
  10585. $tm[1] = 0;
  10586. $tm[2] = 0;
  10587. $tm[3] = $s_y;
  10588. $tm[4] = $x * (1 - $s_x);
  10589. $tm[5] = $y * (1 - $s_y);
  10590. //scale the coordinate system
  10591. $this->Transform($tm);
  10592. }
  10593. /**
  10594. * Horizontal Mirroring.
  10595. * @param $x (int) abscissa of the point. Default is current x position
  10596. * @public
  10597. * @since 2.1.000 (2008-01-07)
  10598. * @see StartTransform(), StopTransform()
  10599. */
  10600. public function MirrorH($x='') {
  10601. $this->Scale(-100, 100, $x);
  10602. }
  10603. /**
  10604. * Verical Mirroring.
  10605. * @param $y (int) ordinate of the point. Default is current y position
  10606. * @public
  10607. * @since 2.1.000 (2008-01-07)
  10608. * @see StartTransform(), StopTransform()
  10609. */
  10610. public function MirrorV($y='') {
  10611. $this->Scale(100, -100, '', $y);
  10612. }
  10613. /**
  10614. * Point reflection mirroring.
  10615. * @param $x (int) abscissa of the point. Default is current x position
  10616. * @param $y (int) ordinate of the point. Default is current y position
  10617. * @public
  10618. * @since 2.1.000 (2008-01-07)
  10619. * @see StartTransform(), StopTransform()
  10620. */
  10621. public function MirrorP($x='',$y='') {
  10622. $this->Scale(-100, -100, $x, $y);
  10623. }
  10624. /**
  10625. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  10626. * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line).
  10627. * @param $x (int) abscissa of the point. Default is current x position
  10628. * @param $y (int) ordinate of the point. Default is current y position
  10629. * @public
  10630. * @since 2.1.000 (2008-01-07)
  10631. * @see StartTransform(), StopTransform()
  10632. */
  10633. public function MirrorL($angle=0, $x='',$y='') {
  10634. $this->Scale(-100, 100, $x, $y);
  10635. $this->Rotate(-2*($angle-90), $x, $y);
  10636. }
  10637. /**
  10638. * Translate graphic object horizontally.
  10639. * @param $t_x (int) movement to the right (or left for RTL)
  10640. * @public
  10641. * @since 2.1.000 (2008-01-07)
  10642. * @see StartTransform(), StopTransform()
  10643. */
  10644. public function TranslateX($t_x) {
  10645. $this->Translate($t_x, 0);
  10646. }
  10647. /**
  10648. * Translate graphic object vertically.
  10649. * @param $t_y (int) movement to the bottom
  10650. * @public
  10651. * @since 2.1.000 (2008-01-07)
  10652. * @see StartTransform(), StopTransform()
  10653. */
  10654. public function TranslateY($t_y) {
  10655. $this->Translate(0, $t_y);
  10656. }
  10657. /**
  10658. * Translate graphic object horizontally and vertically.
  10659. * @param $t_x (int) movement to the right
  10660. * @param $t_y (int) movement to the bottom
  10661. * @public
  10662. * @since 2.1.000 (2008-01-07)
  10663. * @see StartTransform(), StopTransform()
  10664. */
  10665. public function Translate($t_x, $t_y) {
  10666. //calculate elements of transformation matrix
  10667. $tm = array();
  10668. $tm[0] = 1;
  10669. $tm[1] = 0;
  10670. $tm[2] = 0;
  10671. $tm[3] = 1;
  10672. $tm[4] = $t_x * $this->k;
  10673. $tm[5] = -$t_y * $this->k;
  10674. //translate the coordinate system
  10675. $this->Transform($tm);
  10676. }
  10677. /**
  10678. * Rotate object.
  10679. * @param $angle (float) angle in degrees for counter-clockwise rotation
  10680. * @param $x (int) abscissa of the rotation center. Default is current x position
  10681. * @param $y (int) ordinate of the rotation center. Default is current y position
  10682. * @public
  10683. * @since 2.1.000 (2008-01-07)
  10684. * @see StartTransform(), StopTransform()
  10685. */
  10686. public function Rotate($angle, $x='', $y='') {
  10687. if ($x === '') {
  10688. $x = $this->x;
  10689. }
  10690. if ($y === '') {
  10691. $y = $this->y;
  10692. }
  10693. $y = ($this->h - $y) * $this->k;
  10694. $x *= $this->k;
  10695. //calculate elements of transformation matrix
  10696. $tm = array();
  10697. $tm[0] = cos(deg2rad($angle));
  10698. $tm[1] = sin(deg2rad($angle));
  10699. $tm[2] = -$tm[1];
  10700. $tm[3] = $tm[0];
  10701. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  10702. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  10703. //rotate the coordinate system around ($x,$y)
  10704. $this->Transform($tm);
  10705. }
  10706. /**
  10707. * Skew horizontally.
  10708. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10709. * @param $x (int) abscissa of the skewing center. default is current x position
  10710. * @param $y (int) ordinate of the skewing center. default is current y position
  10711. * @public
  10712. * @since 2.1.000 (2008-01-07)
  10713. * @see StartTransform(), StopTransform()
  10714. */
  10715. public function SkewX($angle_x, $x='', $y='') {
  10716. $this->Skew($angle_x, 0, $x, $y);
  10717. }
  10718. /**
  10719. * Skew vertically.
  10720. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10721. * @param $x (int) abscissa of the skewing center. default is current x position
  10722. * @param $y (int) ordinate of the skewing center. default is current y position
  10723. * @public
  10724. * @since 2.1.000 (2008-01-07)
  10725. * @see StartTransform(), StopTransform()
  10726. */
  10727. public function SkewY($angle_y, $x='', $y='') {
  10728. $this->Skew(0, $angle_y, $x, $y);
  10729. }
  10730. /**
  10731. * Skew.
  10732. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10733. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10734. * @param $x (int) abscissa of the skewing center. default is current x position
  10735. * @param $y (int) ordinate of the skewing center. default is current y position
  10736. * @public
  10737. * @since 2.1.000 (2008-01-07)
  10738. * @see StartTransform(), StopTransform()
  10739. */
  10740. public function Skew($angle_x, $angle_y, $x='', $y='') {
  10741. if ($x === '') {
  10742. $x = $this->x;
  10743. }
  10744. if ($y === '') {
  10745. $y = $this->y;
  10746. }
  10747. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  10748. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  10749. }
  10750. $x *= $this->k;
  10751. $y = ($this->h - $y) * $this->k;
  10752. //calculate elements of transformation matrix
  10753. $tm = array();
  10754. $tm[0] = 1;
  10755. $tm[1] = tan(deg2rad($angle_y));
  10756. $tm[2] = tan(deg2rad($angle_x));
  10757. $tm[3] = 1;
  10758. $tm[4] = -$tm[2] * $y;
  10759. $tm[5] = -$tm[1] * $x;
  10760. //skew the coordinate system
  10761. $this->Transform($tm);
  10762. }
  10763. /**
  10764. * Apply graphic transformations.
  10765. * @param $tm (array) transformation matrix
  10766. * @protected
  10767. * @since 2.1.000 (2008-01-07)
  10768. * @see StartTransform(), StopTransform()
  10769. */
  10770. protected function Transform($tm) {
  10771. if ($this->state != 2) {
  10772. return;
  10773. }
  10774. $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  10775. // add tranformation matrix
  10776. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  10777. // update transformation mark
  10778. if ($this->inxobj) {
  10779. // we are inside an XObject template
  10780. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  10781. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  10782. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10783. }
  10784. } elseif (end($this->transfmrk[$this->page]) !== false) {
  10785. $key = key($this->transfmrk[$this->page]);
  10786. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  10787. }
  10788. }
  10789. // END TRANSFORMATIONS SECTION -------------------------
  10790. // START GRAPHIC FUNCTIONS SECTION ---------------------
  10791. // The following section is based on the code provided by David Hernandez Sanz
  10792. /**
  10793. * Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
  10794. * @param $width (float) The width.
  10795. * @public
  10796. * @since 1.0
  10797. * @see Line(), Rect(), Cell(), MultiCell()
  10798. */
  10799. public function SetLineWidth($width) {
  10800. //Set line width
  10801. $this->LineWidth = $width;
  10802. $this->linestyleWidth = sprintf('%F w', ($width * $this->k));
  10803. if ($this->state == 2) {
  10804. $this->_out($this->linestyleWidth);
  10805. }
  10806. }
  10807. /**
  10808. * Returns the current the line width.
  10809. * @return int Line width
  10810. * @public
  10811. * @since 2.1.000 (2008-01-07)
  10812. * @see Line(), SetLineWidth()
  10813. */
  10814. public function GetLineWidth() {
  10815. return $this->LineWidth;
  10816. }
  10817. /**
  10818. * Set line style.
  10819. * @param $style (array) Line style. Array with keys among the following:
  10820. * <ul>
  10821. * <li>width (float): Width of the line in user units.</li>
  10822. * <li>cap (string): Type of cap to put on the line. Possible values are:
  10823. * butt, round, square. The difference between "square" and "butt" is that
  10824. * "square" projects a flat end past the end of the line.</li>
  10825. * <li>join (string): Type of join. Possible values are: miter, round,
  10826. * bevel.</li>
  10827. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  10828. * series of length values, which are the lengths of the on and off dashes.
  10829. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  10830. * 1 off, 2 on, 1 off, ...</li>
  10831. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  10832. * the point at which the pattern starts.</li>
  10833. * <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName).</li>
  10834. * </ul>
  10835. * @param $ret (boolean) if true do not send the command.
  10836. * @return string the PDF command
  10837. * @public
  10838. * @since 2.1.000 (2008-01-08)
  10839. */
  10840. public function SetLineStyle($style, $ret=false) {
  10841. $s = ''; // string to be returned
  10842. if (!is_array($style)) {
  10843. return;
  10844. }
  10845. if (isset($style['width'])) {
  10846. $this->LineWidth = $style['width'];
  10847. $this->linestyleWidth = sprintf('%F w', ($style['width'] * $this->k));
  10848. $s .= $this->linestyleWidth.' ';
  10849. }
  10850. if (isset($style['cap'])) {
  10851. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  10852. if (isset($ca[$style['cap']])) {
  10853. $this->linestyleCap = $ca[$style['cap']].' J';
  10854. $s .= $this->linestyleCap.' ';
  10855. }
  10856. }
  10857. if (isset($style['join'])) {
  10858. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  10859. if (isset($ja[$style['join']])) {
  10860. $this->linestyleJoin = $ja[$style['join']].' j';
  10861. $s .= $this->linestyleJoin.' ';
  10862. }
  10863. }
  10864. if (isset($style['dash'])) {
  10865. $dash_string = '';
  10866. if ($style['dash']) {
  10867. if (preg_match('/^.+,/', $style['dash']) > 0) {
  10868. $tab = explode(',', $style['dash']);
  10869. } else {
  10870. $tab = array($style['dash']);
  10871. }
  10872. $dash_string = '';
  10873. foreach ($tab as $i => $v) {
  10874. if ($i) {
  10875. $dash_string .= ' ';
  10876. }
  10877. $dash_string .= sprintf('%F', $v);
  10878. }
  10879. }
  10880. if (!isset($style['phase']) OR !$style['dash']) {
  10881. $style['phase'] = 0;
  10882. }
  10883. $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']);
  10884. $s .= $this->linestyleDash.' ';
  10885. }
  10886. if (isset($style['color'])) {
  10887. $s .= $this->SetDrawColorArray($style['color'], true).' ';
  10888. }
  10889. if (!$ret AND ($this->state == 2)) {
  10890. $this->_out($s);
  10891. }
  10892. return $s;
  10893. }
  10894. /**
  10895. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  10896. * @param $x (float) Abscissa of point.
  10897. * @param $y (float) Ordinate of point.
  10898. * @protected
  10899. * @since 2.1.000 (2008-01-08)
  10900. */
  10901. protected function _outPoint($x, $y) {
  10902. if ($this->state == 2) {
  10903. $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k)));
  10904. }
  10905. }
  10906. /**
  10907. * Append a straight line segment from the current point to the point (x, y).
  10908. * The new current point shall be (x, y).
  10909. * @param $x (float) Abscissa of end point.
  10910. * @param $y (float) Ordinate of end point.
  10911. * @protected
  10912. * @since 2.1.000 (2008-01-08)
  10913. */
  10914. protected function _outLine($x, $y) {
  10915. if ($this->state == 2) {
  10916. $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k)));
  10917. }
  10918. }
  10919. /**
  10920. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  10921. * @param $x (float) Abscissa of upper-left corner.
  10922. * @param $y (float) Ordinate of upper-left corner.
  10923. * @param $w (float) Width.
  10924. * @param $h (float) Height.
  10925. * @param $op (string) options
  10926. * @protected
  10927. * @since 2.1.000 (2008-01-08)
  10928. */
  10929. protected function _outRect($x, $y, $w, $h, $op) {
  10930. if ($this->state == 2) {
  10931. $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k), (($this->h - $y) * $this->k), ($w * $this->k), (-$h * $this->k), $op));
  10932. }
  10933. }
  10934. /**
  10935. * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x2, y2) as the Bezier control points.
  10936. * The new current point shall be (x3, y3).
  10937. * @param $x1 (float) Abscissa of control point 1.
  10938. * @param $y1 (float) Ordinate of control point 1.
  10939. * @param $x2 (float) Abscissa of control point 2.
  10940. * @param $y2 (float) Ordinate of control point 2.
  10941. * @param $x3 (float) Abscissa of end point.
  10942. * @param $y3 (float) Ordinate of end point.
  10943. * @protected
  10944. * @since 2.1.000 (2008-01-08)
  10945. */
  10946. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
  10947. if ($this->state == 2) {
  10948. $this->_out(sprintf('%F %F %F %F %F %F 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)));
  10949. }
  10950. }
  10951. /**
  10952. * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using the current point and (x2, y2) as the Bezier control points.
  10953. * The new current point shall be (x3, y3).
  10954. * @param $x2 (float) Abscissa of control point 2.
  10955. * @param $y2 (float) Ordinate of control point 2.
  10956. * @param $x3 (float) Abscissa of end point.
  10957. * @param $y3 (float) Ordinate of end point.
  10958. * @protected
  10959. * @since 4.9.019 (2010-04-26)
  10960. */
  10961. protected function _outCurveV($x2, $y2, $x3, $y3) {
  10962. if ($this->state == 2) {
  10963. $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  10964. }
  10965. }
  10966. /**
  10967. * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x3, y3) as the Bezier control points.
  10968. * The new current point shall be (x3, y3).
  10969. * @param $x1 (float) Abscissa of control point 1.
  10970. * @param $y1 (float) Ordinate of control point 1.
  10971. * @param $x3 (float) Abscissa of end point.
  10972. * @param $y3 (float) Ordinate of end point.
  10973. * @protected
  10974. * @since 2.1.000 (2008-01-08)
  10975. */
  10976. protected function _outCurveY($x1, $y1, $x3, $y3) {
  10977. if ($this->state == 2) {
  10978. $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  10979. }
  10980. }
  10981. /**
  10982. * Draws a line between two points.
  10983. * @param $x1 (float) Abscissa of first point.
  10984. * @param $y1 (float) Ordinate of first point.
  10985. * @param $x2 (float) Abscissa of second point.
  10986. * @param $y2 (float) Ordinate of second point.
  10987. * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  10988. * @public
  10989. * @since 1.0
  10990. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  10991. */
  10992. public function Line($x1, $y1, $x2, $y2, $style=array()) {
  10993. if ($this->state != 2) {
  10994. return;
  10995. }
  10996. if (is_array($style)) {
  10997. $this->SetLineStyle($style);
  10998. }
  10999. $this->_outPoint($x1, $y1);
  11000. $this->_outLine($x2, $y2);
  11001. $this->_out('S');
  11002. }
  11003. /**
  11004. * Draws a rectangle.
  11005. * @param $x (float) Abscissa of upper-left corner.
  11006. * @param $y (float) Ordinate of upper-left corner.
  11007. * @param $w (float) Width.
  11008. * @param $h (float) Height.
  11009. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11010. * @param $border_style (array) Border style of rectangle. Array with keys among the following:
  11011. * <ul>
  11012. * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  11013. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  11014. * </ul>
  11015. * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
  11016. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11017. * @public
  11018. * @since 1.0
  11019. * @see SetLineStyle()
  11020. */
  11021. public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
  11022. if ($this->state != 2) {
  11023. return;
  11024. }
  11025. if (empty($style)) {
  11026. $style = 'S';
  11027. }
  11028. if (!(strpos($style, 'F') === false) AND !empty($fill_color)) {
  11029. // set background color
  11030. $this->SetFillColorArray($fill_color);
  11031. }
  11032. if (!empty($border_style)) {
  11033. if (isset($border_style['all']) AND !empty($border_style['all'])) {
  11034. //set global style for border
  11035. $this->SetLineStyle($border_style['all']);
  11036. $border_style = array();
  11037. } else {
  11038. // remove stroke operator from style
  11039. $opnostroke = array('S' => '', 'D' => '', 's' => '', 'd' => '', 'B' => 'F', 'FD' => 'F', 'DF' => 'F', 'B*' => 'F*', 'F*D' => 'F*', 'DF*' => 'F*', 'b' => 'f', 'fd' => 'f', 'df' => 'f', 'b*' => 'f*', 'f*d' => 'f*', 'df*' => 'f*' );
  11040. if (isset($opnostroke[$style])) {
  11041. $style = $opnostroke[$style];
  11042. }
  11043. }
  11044. }
  11045. if (!empty($style)) {
  11046. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11047. $this->_outRect($x, $y, $w, $h, $op);
  11048. }
  11049. if (!empty($border_style)) {
  11050. $border_style2 = array();
  11051. foreach ($border_style as $line => $value) {
  11052. $length = strlen($line);
  11053. for ($i = 0; $i < $length; ++$i) {
  11054. $border_style2[$line[$i]] = $value;
  11055. }
  11056. }
  11057. $border_style = $border_style2;
  11058. if (isset($border_style['L']) AND $border_style['L']) {
  11059. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  11060. }
  11061. if (isset($border_style['T']) AND $border_style['T']) {
  11062. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  11063. }
  11064. if (isset($border_style['R']) AND $border_style['R']) {
  11065. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  11066. }
  11067. if (isset($border_style['B']) AND $border_style['B']) {
  11068. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  11069. }
  11070. }
  11071. }
  11072. /**
  11073. * Draws a Bezier curve.
  11074. * The Bezier curve is a tangent to the line between the control points at
  11075. * either end of the curve.
  11076. * @param $x0 (float) Abscissa of start point.
  11077. * @param $y0 (float) Ordinate of start point.
  11078. * @param $x1 (float) Abscissa of control point 1.
  11079. * @param $y1 (float) Ordinate of control point 1.
  11080. * @param $x2 (float) Abscissa of control point 2.
  11081. * @param $y2 (float) Ordinate of control point 2.
  11082. * @param $x3 (float) Abscissa of end point.
  11083. * @param $y3 (float) Ordinate of end point.
  11084. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11085. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11086. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11087. * @public
  11088. * @see SetLineStyle()
  11089. * @since 2.1.000 (2008-01-08)
  11090. */
  11091. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
  11092. if ($this->state != 2) {
  11093. return;
  11094. }
  11095. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11096. $this->SetFillColorArray($fill_color);
  11097. }
  11098. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11099. if ($line_style) {
  11100. $this->SetLineStyle($line_style);
  11101. }
  11102. $this->_outPoint($x0, $y0);
  11103. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11104. $this->_out($op);
  11105. }
  11106. /**
  11107. * Draws a poly-Bezier curve.
  11108. * Each Bezier curve segment is a tangent to the line between the control points at
  11109. * either end of the curve.
  11110. * @param $x0 (float) Abscissa of start point.
  11111. * @param $y0 (float) Ordinate of start point.
  11112. * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  11113. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11114. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11115. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11116. * @public
  11117. * @see SetLineStyle()
  11118. * @since 3.0008 (2008-05-12)
  11119. */
  11120. public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
  11121. if ($this->state != 2) {
  11122. return;
  11123. }
  11124. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11125. $this->SetFillColorArray($fill_color);
  11126. }
  11127. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11128. if ($op == 'f') {
  11129. $line_style = array();
  11130. }
  11131. if ($line_style) {
  11132. $this->SetLineStyle($line_style);
  11133. }
  11134. $this->_outPoint($x0, $y0);
  11135. foreach ($segments as $segment) {
  11136. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  11137. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11138. }
  11139. $this->_out($op);
  11140. }
  11141. /**
  11142. * Draws an ellipse.
  11143. * An ellipse is formed from n Bezier curves.
  11144. * @param $x0 (float) Abscissa of center point.
  11145. * @param $y0 (float) Ordinate of center point.
  11146. * @param $rx (float) Horizontal radius.
  11147. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11148. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  11149. * @param $astart: (float) Angle start of draw line. Default value: 0.
  11150. * @param $afinish: (float) Angle finish of draw line. Default value: 360.
  11151. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11152. * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  11153. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11154. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  11155. * @author Nicola Asuni
  11156. * @public
  11157. * @since 2.1.000 (2008-01-08)
  11158. */
  11159. public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11160. if ($this->state != 2) {
  11161. return;
  11162. }
  11163. if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
  11164. $ry = $rx;
  11165. }
  11166. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11167. $this->SetFillColorArray($fill_color);
  11168. }
  11169. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11170. if ($op == 'f') {
  11171. $line_style = array();
  11172. }
  11173. if ($line_style) {
  11174. $this->SetLineStyle($line_style);
  11175. }
  11176. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
  11177. $this->_out($op);
  11178. }
  11179. /**
  11180. * Append an elliptical arc to the current path.
  11181. * An ellipse is formed from n Bezier curves.
  11182. * @param $xc (float) Abscissa of center point.
  11183. * @param $yc (float) Ordinate of center point.
  11184. * @param $rx (float) Horizontal radius.
  11185. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11186. * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  11187. * @param $angs: (float) Angle start of draw line. Default value: 0.
  11188. * @param $angf: (float) Angle finish of draw line. Default value: 360.
  11189. * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors).
  11190. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  11191. * @param $startpoint (boolean) if true output a starting point.
  11192. * @param $ccw (boolean) if true draws in counter-clockwise.
  11193. * @param $svg (boolean) if true the angles are in svg mode (already calculated).
  11194. * @return array bounding box coordinates (x min, y min, x max, y max)
  11195. * @author Nicola Asuni
  11196. * @protected
  11197. * @since 4.9.019 (2010-04-26)
  11198. */
  11199. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
  11200. if (($rx <= 0) OR ($ry < 0)) {
  11201. return;
  11202. }
  11203. $k = $this->k;
  11204. if ($nc < 2) {
  11205. $nc = 2;
  11206. }
  11207. $xmin = 2147483647;
  11208. $ymin = 2147483647;
  11209. $xmax = 0;
  11210. $ymax = 0;
  11211. if ($pie) {
  11212. // center of the arc
  11213. $this->_outPoint($xc, $yc);
  11214. }
  11215. $xang = deg2rad((float) $xang);
  11216. $angs = deg2rad((float) $angs);
  11217. $angf = deg2rad((float) $angf);
  11218. if ($svg) {
  11219. $as = $angs;
  11220. $af = $angf;
  11221. } else {
  11222. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  11223. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  11224. }
  11225. if ($as < 0) {
  11226. $as += (2 * M_PI);
  11227. }
  11228. if ($af < 0) {
  11229. $af += (2 * M_PI);
  11230. }
  11231. if ($ccw AND ($as > $af)) {
  11232. // reverse rotation
  11233. $as -= (2 * M_PI);
  11234. } elseif (!$ccw AND ($as < $af)) {
  11235. // reverse rotation
  11236. $af -= (2 * M_PI);
  11237. }
  11238. $total_angle = ($af - $as);
  11239. if ($nc < 2) {
  11240. $nc = 2;
  11241. }
  11242. // total arcs to draw
  11243. $nc *= (2 * abs($total_angle) / M_PI);
  11244. $nc = round($nc) + 1;
  11245. // angle of each arc
  11246. $arcang = ($total_angle / $nc);
  11247. // center point in PDF coordinates
  11248. $x0 = $xc;
  11249. $y0 = ($this->h - $yc);
  11250. // starting angle
  11251. $ang = $as;
  11252. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  11253. $cos_xang = cos($xang);
  11254. $sin_xang = sin($xang);
  11255. $cos_ang = cos($ang);
  11256. $sin_ang = sin($ang);
  11257. // first arc point
  11258. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11259. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11260. // first Bezier control point
  11261. $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11262. $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11263. if ($pie) {
  11264. // line from center to arc starting point
  11265. $this->_outLine($px1, $this->h - $py1);
  11266. } elseif ($startpoint) {
  11267. // arc starting point
  11268. $this->_outPoint($px1, $this->h - $py1);
  11269. }
  11270. // draw arcs
  11271. for ($i = 1; $i <= $nc; ++$i) {
  11272. // starting angle
  11273. $ang = $as + ($i * $arcang);
  11274. if ($i == $nc) {
  11275. $ang = $af;
  11276. }
  11277. $cos_ang = cos($ang);
  11278. $sin_ang = sin($ang);
  11279. // second arc point
  11280. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11281. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11282. // second Bezier control point
  11283. $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11284. $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11285. // draw arc
  11286. $cx1 = ($px1 + $qx1);
  11287. $cy1 = ($this->h - ($py1 + $qy1));
  11288. $cx2 = ($px2 - $qx2);
  11289. $cy2 = ($this->h - ($py2 - $qy2));
  11290. $cx3 = $px2;
  11291. $cy3 = ($this->h - $py2);
  11292. $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
  11293. // get bounding box coordinates
  11294. $xmin = min($xmin, $cx1, $cx2, $cx3);
  11295. $ymin = min($ymin, $cy1, $cy2, $cy3);
  11296. $xmax = max($xmax, $cx1, $cx2, $cx3);
  11297. $ymax = max($ymax, $cy1, $cy2, $cy3);
  11298. // move to next point
  11299. $px1 = $px2;
  11300. $py1 = $py2;
  11301. $qx1 = $qx2;
  11302. $qy1 = $qy2;
  11303. }
  11304. if ($pie) {
  11305. $this->_outLine($xc, $yc);
  11306. // get bounding box coordinates
  11307. $xmin = min($xmin, $xc);
  11308. $ymin = min($ymin, $yc);
  11309. $xmax = max($xmax, $xc);
  11310. $ymax = max($ymax, $yc);
  11311. }
  11312. return array($xmin, $ymin, $xmax, $ymax);
  11313. }
  11314. /**
  11315. * Draws a circle.
  11316. * A circle is formed from n Bezier curves.
  11317. * @param $x0 (float) Abscissa of center point.
  11318. * @param $y0 (float) Ordinate of center point.
  11319. * @param $r (float) Radius.
  11320. * @param $angstr: (float) Angle start of draw line. Default value: 0.
  11321. * @param $angend: (float) Angle finish of draw line. Default value: 360.
  11322. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11323. * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11324. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11325. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle.
  11326. * @public
  11327. * @since 2.1.000 (2008-01-08)
  11328. */
  11329. public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11330. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  11331. }
  11332. /**
  11333. * Draws a polygonal line
  11334. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11335. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11336. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  11337. * <ul>
  11338. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11339. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11340. * </ul>
  11341. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11342. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11343. * @since 4.8.003 (2009-09-15)
  11344. * @public
  11345. */
  11346. public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
  11347. $this->Polygon($p, $style, $line_style, $fill_color, false);
  11348. }
  11349. /**
  11350. * Draws a polygon.
  11351. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11352. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11353. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  11354. * <ul>
  11355. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11356. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11357. * </ul>
  11358. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11359. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11360. * @param $closed (boolean) if true the polygon is closes, otherwise will remain open
  11361. * @public
  11362. * @since 2.1.000 (2008-01-08)
  11363. */
  11364. public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
  11365. if ($this->state != 2) {
  11366. return;
  11367. }
  11368. $nc = count($p); // number of coordinates
  11369. $np = $nc / 2; // number of points
  11370. if ($closed) {
  11371. // close polygon by adding the first 2 points at the end (one line)
  11372. for ($i = 0; $i < 4; ++$i) {
  11373. $p[$nc + $i] = $p[$i];
  11374. }
  11375. // copy style for the last added line
  11376. if (isset($line_style[0])) {
  11377. $line_style[$np] = $line_style[0];
  11378. }
  11379. $nc += 4;
  11380. }
  11381. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11382. $this->SetFillColorArray($fill_color);
  11383. }
  11384. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11385. if ($op == 'f') {
  11386. $line_style = array();
  11387. }
  11388. $draw = true;
  11389. if ($line_style) {
  11390. if (isset($line_style['all'])) {
  11391. $this->SetLineStyle($line_style['all']);
  11392. } else {
  11393. $draw = false;
  11394. if ($op == 'B') {
  11395. // draw fill
  11396. $op = 'f';
  11397. $this->_outPoint($p[0], $p[1]);
  11398. for ($i = 2; $i < $nc; $i = $i + 2) {
  11399. $this->_outLine($p[$i], $p[$i + 1]);
  11400. }
  11401. $this->_out($op);
  11402. }
  11403. // draw outline
  11404. $this->_outPoint($p[0], $p[1]);
  11405. for ($i = 2; $i < $nc; $i = $i + 2) {
  11406. $line_num = ($i / 2) - 1;
  11407. if (isset($line_style[$line_num])) {
  11408. if ($line_style[$line_num] != 0) {
  11409. if (is_array($line_style[$line_num])) {
  11410. $this->_out('S');
  11411. $this->SetLineStyle($line_style[$line_num]);
  11412. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  11413. $this->_outLine($p[$i], $p[$i + 1]);
  11414. $this->_out('S');
  11415. $this->_outPoint($p[$i], $p[$i + 1]);
  11416. } else {
  11417. $this->_outLine($p[$i], $p[$i + 1]);
  11418. }
  11419. }
  11420. } else {
  11421. $this->_outLine($p[$i], $p[$i + 1]);
  11422. }
  11423. }
  11424. $this->_out($op);
  11425. }
  11426. }
  11427. if ($draw) {
  11428. $this->_outPoint($p[0], $p[1]);
  11429. for ($i = 2; $i < $nc; $i = $i + 2) {
  11430. $this->_outLine($p[$i], $p[$i + 1]);
  11431. }
  11432. $this->_out($op);
  11433. }
  11434. }
  11435. /**
  11436. * Draws a regular polygon.
  11437. * @param $x0 (float) Abscissa of center point.
  11438. * @param $y0 (float) Ordinate of center point.
  11439. * @param $r: (float) Radius of inscribed circle.
  11440. * @param $ns (integer) Number of sides.
  11441. * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0.
  11442. * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false.
  11443. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11444. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  11445. * <ul>
  11446. * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  11447. * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  11448. * </ul>
  11449. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11450. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11451. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  11452. * <ul>
  11453. * <li>D or empty string: Draw (default).</li>
  11454. * <li>F: Fill.</li>
  11455. * <li>DF or FD: Draw and fill.</li>
  11456. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11457. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11458. * </ul>
  11459. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11460. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11461. * @public
  11462. * @since 2.1.000 (2008-01-08)
  11463. */
  11464. 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()) {
  11465. if (3 > $ns) {
  11466. $ns = 3;
  11467. }
  11468. if ($draw_circle) {
  11469. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11470. }
  11471. $p = array();
  11472. for ($i = 0; $i < $ns; ++$i) {
  11473. $a = $angle + ($i * 360 / $ns);
  11474. $a_rad = deg2rad((float) $a);
  11475. $p[] = $x0 + ($r * sin($a_rad));
  11476. $p[] = $y0 + ($r * cos($a_rad));
  11477. }
  11478. $this->Polygon($p, $style, $line_style, $fill_color);
  11479. }
  11480. /**
  11481. * Draws a star polygon
  11482. * @param $x0 (float) Abscissa of center point.
  11483. * @param $y0 (float) Ordinate of center point.
  11484. * @param $r (float) Radius of inscribed circle.
  11485. * @param $nv (integer) Number of vertices.
  11486. * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  11487. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  11488. * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false.
  11489. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11490. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  11491. * <ul>
  11492. * <li>all: Line style of all sides. Array like for
  11493. * SetLineStyle().</li>
  11494. * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  11495. * </ul>
  11496. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11497. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11498. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  11499. * <ul>
  11500. * <li>D or empty string: Draw (default).</li>
  11501. * <li>F: Fill.</li>
  11502. * <li>DF or FD: Draw and fill.</li>
  11503. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11504. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11505. * </ul>
  11506. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11507. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11508. * @public
  11509. * @since 2.1.000 (2008-01-08)
  11510. */
  11511. 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()) {
  11512. if ($nv < 2) {
  11513. $nv = 2;
  11514. }
  11515. if ($draw_circle) {
  11516. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11517. }
  11518. $p2 = array();
  11519. $visited = array();
  11520. for ($i = 0; $i < $nv; ++$i) {
  11521. $a = $angle + ($i * 360 / $nv);
  11522. $a_rad = deg2rad((float) $a);
  11523. $p2[] = $x0 + ($r * sin($a_rad));
  11524. $p2[] = $y0 + ($r * cos($a_rad));
  11525. $visited[] = false;
  11526. }
  11527. $p = array();
  11528. $i = 0;
  11529. do {
  11530. $p[] = $p2[$i * 2];
  11531. $p[] = $p2[($i * 2) + 1];
  11532. $visited[$i] = true;
  11533. $i += $ng;
  11534. $i %= $nv;
  11535. } while (!$visited[$i]);
  11536. $this->Polygon($p, $style, $line_style, $fill_color);
  11537. }
  11538. /**
  11539. * Draws a rounded rectangle.
  11540. * @param $x (float) Abscissa of upper-left corner.
  11541. * @param $y (float) Ordinate of upper-left corner.
  11542. * @param $w (float) Width.
  11543. * @param $h (float) Height.
  11544. * @param $r (float) the radius of the circle used to round off the corners of the rectangle.
  11545. * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
  11546. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11547. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11548. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11549. * @public
  11550. * @since 2.1.000 (2008-01-08)
  11551. */
  11552. public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11553. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  11554. }
  11555. /**
  11556. * Draws a rounded rectangle.
  11557. * @param $x (float) Abscissa of upper-left corner.
  11558. * @param $y (float) Ordinate of upper-left corner.
  11559. * @param $w (float) Width.
  11560. * @param $h (float) Height.
  11561. * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle.
  11562. * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle.
  11563. * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
  11564. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11565. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11566. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11567. * @public
  11568. * @since 4.9.019 (2010-04-22)
  11569. */
  11570. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11571. if ($this->state != 2) {
  11572. return;
  11573. }
  11574. if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  11575. // Not rounded
  11576. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  11577. return;
  11578. }
  11579. // Rounded
  11580. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11581. $this->SetFillColorArray($fill_color);
  11582. }
  11583. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11584. if ($op == 'f') {
  11585. $border_style = array();
  11586. }
  11587. if ($border_style) {
  11588. $this->SetLineStyle($border_style);
  11589. }
  11590. $MyArc = 4 / 3 * (sqrt(2) - 1);
  11591. $this->_outPoint($x + $rx, $y);
  11592. $xc = $x + $w - $rx;
  11593. $yc = $y + $ry;
  11594. $this->_outLine($xc, $y);
  11595. if ($round_corner[0]) {
  11596. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  11597. } else {
  11598. $this->_outLine($x + $w, $y);
  11599. }
  11600. $xc = $x + $w - $rx;
  11601. $yc = $y + $h - $ry;
  11602. $this->_outLine($x + $w, $yc);
  11603. if ($round_corner[1]) {
  11604. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  11605. } else {
  11606. $this->_outLine($x + $w, $y + $h);
  11607. }
  11608. $xc = $x + $rx;
  11609. $yc = $y + $h - $ry;
  11610. $this->_outLine($xc, $y + $h);
  11611. if ($round_corner[2]) {
  11612. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  11613. } else {
  11614. $this->_outLine($x, $y + $h);
  11615. }
  11616. $xc = $x + $rx;
  11617. $yc = $y + $ry;
  11618. $this->_outLine($x, $yc);
  11619. if ($round_corner[3]) {
  11620. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  11621. } else {
  11622. $this->_outLine($x, $y);
  11623. $this->_outLine($x + $rx, $y);
  11624. }
  11625. $this->_out($op);
  11626. }
  11627. /**
  11628. * Draws a grahic arrow.
  11629. * @param $x0 (float) Abscissa of first point.
  11630. * @param $y0 (float) Ordinate of first point.
  11631. * @param $x1 (float) Abscissa of second point.
  11632. * @param $y1 (float) Ordinate of second point.
  11633. * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  11634. * @param $arm_size (float) length of arrowhead arms
  11635. * @param $arm_angle (int) angle between an arm and the shaft
  11636. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  11637. * @since 4.6.018 (2009-07-10)
  11638. */
  11639. public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
  11640. // getting arrow direction angle
  11641. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  11642. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  11643. if ($dir_angle < 0) {
  11644. $dir_angle += (2 * M_PI);
  11645. }
  11646. $arm_angle = deg2rad($arm_angle);
  11647. $sx1 = $x1;
  11648. $sy1 = $y1;
  11649. if ($head_style > 0) {
  11650. // calculate the stopping point for the arrow shaft
  11651. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  11652. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  11653. }
  11654. // main arrow line / shaft
  11655. $this->Line($x0, $y0, $sx1, $sy1);
  11656. // left arrowhead arm tip
  11657. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  11658. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  11659. // right arrowhead arm tip
  11660. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  11661. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  11662. $mode = 'D';
  11663. $style = array();
  11664. switch ($head_style) {
  11665. case 0: {
  11666. // draw only arrowhead arms
  11667. $mode = 'D';
  11668. $style = array(1, 1, 0);
  11669. break;
  11670. }
  11671. case 1: {
  11672. // draw closed arrowhead, but no fill
  11673. $mode = 'D';
  11674. break;
  11675. }
  11676. case 2: {
  11677. // closed and filled arrowhead
  11678. $mode = 'DF';
  11679. break;
  11680. }
  11681. case 3: {
  11682. // filled arrowhead
  11683. $mode = 'F';
  11684. break;
  11685. }
  11686. }
  11687. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  11688. }
  11689. // END GRAPHIC FUNCTIONS SECTION -----------------------
  11690. /**
  11691. * Add a Named Destination.
  11692. * NOTE: destination names are unique, so only last entry will be saved.
  11693. * @param $name (string) Destination name.
  11694. * @param $y (float) Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
  11695. * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  11696. * @param $x (float) X position in user units of the destiantion on the selected page (default = -1 = current position;).
  11697. * @return (string) Stripped named destination identifier or false in case of error.
  11698. * @public
  11699. * @author Christian Deligant, Nicola Asuni
  11700. * @since 5.9.097 (2011-06-23)
  11701. */
  11702. public function setDestination($name, $y=-1, $page='', $x=-1) {
  11703. // remove unsupported characters
  11704. $name = TCPDF_STATIC::encodeNameObject($name);
  11705. if (TCPDF_STATIC::empty_string($name)) {
  11706. return false;
  11707. }
  11708. if ($y == -1) {
  11709. $y = $this->GetY();
  11710. } elseif ($y < 0) {
  11711. $y = 0;
  11712. } elseif ($y > $this->h) {
  11713. $y = $this->h;
  11714. }
  11715. if ($x == -1) {
  11716. $x = $this->GetX();
  11717. } elseif ($x < 0) {
  11718. $x = 0;
  11719. } elseif ($x > $this->w) {
  11720. $x = $this->w;
  11721. }
  11722. $fixed = false;
  11723. if (!empty($page) AND ($page[0] == '*')) {
  11724. $page = intval(substr($page, 1));
  11725. // this page number will not be changed when moving/add/deleting pages
  11726. $fixed = true;
  11727. }
  11728. if (empty($page)) {
  11729. $page = $this->PageNo();
  11730. if (empty($page)) {
  11731. return;
  11732. }
  11733. }
  11734. $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed);
  11735. return $name;
  11736. }
  11737. /**
  11738. * Return the Named Destination array.
  11739. * @return (array) Named Destination array.
  11740. * @public
  11741. * @author Nicola Asuni
  11742. * @since 5.9.097 (2011-06-23)
  11743. */
  11744. public function getDestination() {
  11745. return $this->dests;
  11746. }
  11747. /**
  11748. * Insert Named Destinations.
  11749. * @protected
  11750. * @author Johannes G\FCntert, Nicola Asuni
  11751. * @since 5.9.098 (2011-06-23)
  11752. */
  11753. protected function _putdests() {
  11754. if (empty($this->dests)) {
  11755. return;
  11756. }
  11757. $this->n_dests = $this->_newobj();
  11758. $out = ' <<';
  11759. foreach($this->dests as $name => $o) {
  11760. $out .= ' /'.$name.' '.sprintf('[%u 0 R /XYZ %F %F null]', $this->page_obj_id[($o['p'])], ($o['x'] * $this->k), ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
  11761. }
  11762. $out .= ' >>';
  11763. $out .= "\n".'endobj';
  11764. $this->_out($out);
  11765. }
  11766. /**
  11767. * Adds a bookmark - alias for Bookmark().
  11768. * @param $txt (string) Bookmark description.
  11769. * @param $level (int) Bookmark level (minimum value is 0).
  11770. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11771. * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  11772. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11773. * @param $color (array) RGB color array (values from 0 to 255).
  11774. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11775. * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  11776. * @public
  11777. */
  11778. public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11779. $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
  11780. }
  11781. /**
  11782. * Adds a bookmark.
  11783. * @param $txt (string) Bookmark description.
  11784. * @param $level (int) Bookmark level (minimum value is 0).
  11785. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11786. * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  11787. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11788. * @param $color (array) RGB color array (values from 0 to 255).
  11789. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11790. * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  11791. * @public
  11792. * @since 2.1.002 (2008-02-12)
  11793. */
  11794. public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11795. if ($level < 0) {
  11796. $level = 0;
  11797. }
  11798. if (isset($this->outlines[0])) {
  11799. $lastoutline = end($this->outlines);
  11800. $maxlevel = $lastoutline['l'] + 1;
  11801. } else {
  11802. $maxlevel = 0;
  11803. }
  11804. if ($level > $maxlevel) {
  11805. $level = $maxlevel;
  11806. }
  11807. if ($y == -1) {
  11808. $y = $this->GetY();
  11809. } elseif ($y < 0) {
  11810. $y = 0;
  11811. } elseif ($y > $this->h) {
  11812. $y = $this->h;
  11813. }
  11814. if ($x == -1) {
  11815. $x = $this->GetX();
  11816. } elseif ($x < 0) {
  11817. $x = 0;
  11818. } elseif ($x > $this->w) {
  11819. $x = $this->w;
  11820. }
  11821. $fixed = false;
  11822. if (!empty($page) AND ($page[0] == '*')) {
  11823. $page = intval(substr($page, 1));
  11824. // this page number will not be changed when moving/add/deleting pages
  11825. $fixed = true;
  11826. }
  11827. if (empty($page)) {
  11828. $page = $this->PageNo();
  11829. if (empty($page)) {
  11830. return;
  11831. }
  11832. }
  11833. $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
  11834. }
  11835. /**
  11836. * Sort bookmarks for page and key.
  11837. * @protected
  11838. * @since 5.9.119 (2011-09-19)
  11839. */
  11840. protected function sortBookmarks() {
  11841. // get sorting columns
  11842. $outline_p = array();
  11843. $outline_y = array();
  11844. foreach ($this->outlines as $key => $row) {
  11845. $outline_p[$key] = $row['p'];
  11846. $outline_k[$key] = $key;
  11847. }
  11848. // sort outlines by page and original position
  11849. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  11850. }
  11851. /**
  11852. * Create a bookmark PDF string.
  11853. * @protected
  11854. * @author Olivier Plathey, Nicola Asuni
  11855. * @since 2.1.002 (2008-02-12)
  11856. */
  11857. protected function _putbookmarks() {
  11858. $nb = count($this->outlines);
  11859. if ($nb == 0) {
  11860. return;
  11861. }
  11862. // sort bookmarks
  11863. $this->sortBookmarks();
  11864. $lru = array();
  11865. $level = 0;
  11866. foreach ($this->outlines as $i => $o) {
  11867. if ($o['l'] > 0) {
  11868. $parent = $lru[($o['l'] - 1)];
  11869. //Set parent and last pointers
  11870. $this->outlines[$i]['parent'] = $parent;
  11871. $this->outlines[$parent]['last'] = $i;
  11872. if ($o['l'] > $level) {
  11873. //Level increasing: set first pointer
  11874. $this->outlines[$parent]['first'] = $i;
  11875. }
  11876. } else {
  11877. $this->outlines[$i]['parent'] = $nb;
  11878. }
  11879. if (($o['l'] <= $level) AND ($i > 0)) {
  11880. //Set prev and next pointers
  11881. $prev = $lru[$o['l']];
  11882. $this->outlines[$prev]['next'] = $i;
  11883. $this->outlines[$i]['prev'] = $prev;
  11884. }
  11885. $lru[$o['l']] = $i;
  11886. $level = $o['l'];
  11887. }
  11888. //Outline items
  11889. $n = $this->n + 1;
  11890. $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';
  11891. foreach ($this->outlines as $i => $o) {
  11892. $oid = $this->_newobj();
  11893. // covert HTML title to string
  11894. $title = preg_replace($nltags, "\n", $o['t']);
  11895. $title = preg_replace("/[\r]+/si", '', $title);
  11896. $title = preg_replace("/[\n]+/si", "\n", $title);
  11897. $title = strip_tags($title);
  11898. $title = $this->stringTrim($title);
  11899. $out = '<</Title '.$this->_textstring($title, $oid);
  11900. $out .= ' /Parent '.($n + $o['parent']).' 0 R';
  11901. if (isset($o['prev'])) {
  11902. $out .= ' /Prev '.($n + $o['prev']).' 0 R';
  11903. }
  11904. if (isset($o['next'])) {
  11905. $out .= ' /Next '.($n + $o['next']).' 0 R';
  11906. }
  11907. if (isset($o['first'])) {
  11908. $out .= ' /First '.($n + $o['first']).' 0 R';
  11909. }
  11910. if (isset($o['last'])) {
  11911. $out .= ' /Last '.($n + $o['last']).' 0 R';
  11912. }
  11913. if (isset($o['u']) AND !empty($o['u'])) {
  11914. // link
  11915. if (is_string($o['u'])) {
  11916. if ($o['u'][0] == '#') {
  11917. // internal destination
  11918. $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1));
  11919. } elseif ($o['u'][0] == '%') {
  11920. // embedded PDF file
  11921. $filename = basename(substr($o['u'], 1));
  11922. $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  11923. } elseif ($o['u'][0] == '*') {
  11924. // embedded generic file
  11925. $filename = basename(substr($o['u'], 1));
  11926. $jsa = 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});';
  11927. $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
  11928. } else {
  11929. // external URI link
  11930. $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
  11931. }
  11932. } elseif (isset($this->links[$o['u']])) {
  11933. // internal link ID
  11934. $l = $this->links[$o['u']];
  11935. if (isset($this->page_obj_id[($l['p'])])) {
  11936. $out .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l['p'])], ($this->pagedim[$l['p']]['h'] - ($l['y'] * $this->k)));
  11937. }
  11938. }
  11939. } elseif (isset($this->page_obj_id[($o['p'])])) {
  11940. // link to a page
  11941. $out .= ' '.sprintf('/Dest [%u 0 R /XYZ %F %F null]', $this->page_obj_id[($o['p'])], ($o['x'] * $this->k), ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
  11942. }
  11943. // set font style
  11944. $style = 0;
  11945. if (!empty($o['s'])) {
  11946. // bold
  11947. if (strpos($o['s'], 'B') !== false) {
  11948. $style |= 2;
  11949. }
  11950. // oblique
  11951. if (strpos($o['s'], 'I') !== false) {
  11952. $style |= 1;
  11953. }
  11954. }
  11955. $out .= sprintf(' /F %d', $style);
  11956. // set bookmark color
  11957. if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
  11958. $color = array_values($o['c']);
  11959. $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  11960. } else {
  11961. // black
  11962. $out .= ' /C [0.0 0.0 0.0]';
  11963. }
  11964. $out .= ' /Count 0'; // normally closed item
  11965. $out .= ' >>';
  11966. $out .= "\n".'endobj';
  11967. $this->_out($out);
  11968. }
  11969. //Outline root
  11970. $this->OutlineRoot = $this->_newobj();
  11971. $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
  11972. }
  11973. // --- JAVASCRIPT ------------------------------------------------------
  11974. /**
  11975. * Adds a javascript
  11976. * @param $script (string) Javascript code
  11977. * @public
  11978. * @author Johannes G\FCntert, Nicola Asuni
  11979. * @since 2.1.002 (2008-02-12)
  11980. */
  11981. public function IncludeJS($script) {
  11982. $this->javascript .= $script;
  11983. }
  11984. /**
  11985. * Adds a javascript object and return object ID
  11986. * @param $script (string) Javascript code
  11987. * @param $onload (boolean) if true executes this object when opening the document
  11988. * @return int internal object ID
  11989. * @public
  11990. * @author Nicola Asuni
  11991. * @since 4.8.000 (2009-09-07)
  11992. */
  11993. public function addJavascriptObject($script, $onload=false) {
  11994. if ($this->pdfa_mode) {
  11995. // javascript is not allowed in PDF/A mode
  11996. return false;
  11997. }
  11998. ++$this->n;
  11999. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  12000. return $this->n;
  12001. }
  12002. /**
  12003. * Create a javascript PDF string.
  12004. * @protected
  12005. * @author Johannes G\FCntert, Nicola Asuni
  12006. * @since 2.1.002 (2008-02-12)
  12007. */
  12008. protected function _putjavascript() {
  12009. if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
  12010. return;
  12011. }
  12012. if (strpos($this->javascript, 'this.addField') > 0) {
  12013. if (!$this->ur['enabled']) {
  12014. //$this->setUserRights();
  12015. }
  12016. // the following two lines are used to avoid form fields duplication after saving
  12017. // The addField method only works when releasing user rights (UR3)
  12018. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  12019. $jsb = "getField('tcpdfdocsaved').value='saved';";
  12020. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  12021. }
  12022. // name tree for javascript
  12023. $this->n_js = '<< /Names [';
  12024. if (!empty($this->javascript)) {
  12025. $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
  12026. }
  12027. if (!empty($this->js_objects)) {
  12028. foreach ($this->js_objects as $key => $val) {
  12029. if ($val['onload']) {
  12030. $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
  12031. }
  12032. }
  12033. }
  12034. $this->n_js .= ' ] >>';
  12035. // default Javascript object
  12036. if (!empty($this->javascript)) {
  12037. $obj_id = $this->_newobj();
  12038. $out = '<< /S /JavaScript';
  12039. $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
  12040. $out .= ' >>';
  12041. $out .= "\n".'endobj';
  12042. $this->_out($out);
  12043. }
  12044. // additional Javascript objects
  12045. if (!empty($this->js_objects)) {
  12046. foreach ($this->js_objects as $key => $val) {
  12047. $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  12048. $this->_out($out);
  12049. }
  12050. }
  12051. }
  12052. /**
  12053. * Adds a javascript form field.
  12054. * @param $type (string) field type
  12055. * @param $name (string) field name
  12056. * @param $x (int) horizontal position
  12057. * @param $y (int) vertical position
  12058. * @param $w (int) width
  12059. * @param $h (int) height
  12060. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12061. * @protected
  12062. * @author Denis Van Nuffelen, Nicola Asuni
  12063. * @since 2.1.002 (2008-02-12)
  12064. */
  12065. protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
  12066. if ($this->rtl) {
  12067. $x = $x - $w;
  12068. }
  12069. // the followind avoid fields duplication after saving the document
  12070. $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
  12071. $k = $this->k;
  12072. $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%F,%F,%F,%F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n";
  12073. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  12074. foreach($prop as $key => $val) {
  12075. if (strcmp(substr($key, -5), 'Color') == 0) {
  12076. $val = TCPDF_COLORS::_JScolor($val);
  12077. } else {
  12078. $val = "'".$val."'";
  12079. }
  12080. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  12081. }
  12082. if ($this->rtl) {
  12083. $this->x -= $w;
  12084. } else {
  12085. $this->x += $w;
  12086. }
  12087. $this->javascript .= '}';
  12088. }
  12089. // --- FORM FIELDS -----------------------------------------------------
  12090. /**
  12091. * Set default properties for form fields.
  12092. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12093. * @public
  12094. * @author Nicola Asuni
  12095. * @since 4.8.000 (2009-09-06)
  12096. */
  12097. public function setFormDefaultProp($prop=array()) {
  12098. $this->default_form_prop = $prop;
  12099. }
  12100. /**
  12101. * Return the default properties for form fields.
  12102. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12103. * @public
  12104. * @author Nicola Asuni
  12105. * @since 4.8.000 (2009-09-06)
  12106. */
  12107. public function getFormDefaultProp() {
  12108. return $this->default_form_prop;
  12109. }
  12110. /**
  12111. * Creates a text field
  12112. * @param $name (string) field name
  12113. * @param $w (float) Width of the rectangle
  12114. * @param $h (float) Height of the rectangle
  12115. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12116. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12117. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12118. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12119. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12120. * @public
  12121. * @author Nicola Asuni
  12122. * @since 4.8.000 (2009-09-07)
  12123. */
  12124. public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12125. if ($x === '') {
  12126. $x = $this->x;
  12127. }
  12128. if ($y === '') {
  12129. $y = $this->y;
  12130. }
  12131. // check page for no-write regions and adapt page margins if necessary
  12132. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12133. if ($js) {
  12134. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  12135. return;
  12136. }
  12137. // get default style
  12138. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12139. // get annotation data
  12140. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12141. // set default appearance stream
  12142. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12143. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12144. $popt['da'] = $fontstyle;
  12145. // build appearance stream
  12146. $popt['ap'] = array();
  12147. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12148. $text = '';
  12149. if (isset($prop['value']) AND !empty($prop['value'])) {
  12150. $text = $prop['value'];
  12151. } elseif (isset($opt['v']) AND !empty($opt['v'])) {
  12152. $text = $opt['v'];
  12153. }
  12154. $tmpid = $this->startTemplate($w, $h, false);
  12155. $align = '';
  12156. if (isset($popt['q'])) {
  12157. switch ($popt['q']) {
  12158. case 0: {
  12159. $align = 'L';
  12160. break;
  12161. }
  12162. case 1: {
  12163. $align = 'C';
  12164. break;
  12165. }
  12166. case 2: {
  12167. $align = 'R';
  12168. break;
  12169. }
  12170. default: {
  12171. $align = '';
  12172. break;
  12173. }
  12174. }
  12175. }
  12176. $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12177. $this->endTemplate();
  12178. --$this->n;
  12179. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12180. unset($this->xobjects[$tmpid]);
  12181. $popt['ap']['n'] .= 'Q EMC';
  12182. // merge options
  12183. $opt = array_merge($popt, $opt);
  12184. // remove some conflicting options
  12185. unset($opt['bs']);
  12186. // set remaining annotation data
  12187. $opt['Subtype'] = 'Widget';
  12188. $opt['ft'] = 'Tx';
  12189. $opt['t'] = $name;
  12190. // Additional annotation's parameters (check _putannotsobj() method):
  12191. //$opt['f']
  12192. //$opt['as']
  12193. //$opt['bs']
  12194. //$opt['be']
  12195. //$opt['c']
  12196. //$opt['border']
  12197. //$opt['h']
  12198. //$opt['mk'];
  12199. //$opt['mk']['r']
  12200. //$opt['mk']['bc'];
  12201. //$opt['mk']['bg'];
  12202. unset($opt['mk']['ca']);
  12203. unset($opt['mk']['rc']);
  12204. unset($opt['mk']['ac']);
  12205. unset($opt['mk']['i']);
  12206. unset($opt['mk']['ri']);
  12207. unset($opt['mk']['ix']);
  12208. unset($opt['mk']['if']);
  12209. //$opt['mk']['if']['sw'];
  12210. //$opt['mk']['if']['s'];
  12211. //$opt['mk']['if']['a'];
  12212. //$opt['mk']['if']['fb'];
  12213. unset($opt['mk']['tp']);
  12214. //$opt['tu']
  12215. //$opt['tm']
  12216. //$opt['ff']
  12217. //$opt['v']
  12218. //$opt['dv']
  12219. //$opt['a']
  12220. //$opt['aa']
  12221. //$opt['q']
  12222. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12223. if ($this->rtl) {
  12224. $this->x -= $w;
  12225. } else {
  12226. $this->x += $w;
  12227. }
  12228. }
  12229. /**
  12230. * Creates a RadioButton field.
  12231. * @param $name (string) Field name.
  12232. * @param $w (int) Width of the radio button.
  12233. * @param $prop (array) Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12234. * @param $opt (array) Annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12235. * @param $onvalue (string) Value to be returned if selected.
  12236. * @param $checked (boolean) Define the initial state.
  12237. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12238. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12239. * @param $js (boolean) If true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12240. * @public
  12241. * @author Nicola Asuni
  12242. * @since 4.8.000 (2009-09-07)
  12243. */
  12244. public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
  12245. if ($x === '') {
  12246. $x = $this->x;
  12247. }
  12248. if ($y === '') {
  12249. $y = $this->y;
  12250. }
  12251. // check page for no-write regions and adapt page margins if necessary
  12252. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12253. if ($js) {
  12254. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  12255. return;
  12256. }
  12257. if (TCPDF_STATIC::empty_string($onvalue)) {
  12258. $onvalue = 'On';
  12259. }
  12260. if ($checked) {
  12261. $defval = $onvalue;
  12262. } else {
  12263. $defval = 'Off';
  12264. }
  12265. // set font
  12266. $font = 'zapfdingbats';
  12267. if ($this->pdfa_mode) {
  12268. // all fonts must be embedded
  12269. $font = 'pdfa'.$font;
  12270. }
  12271. $this->AddFont($font);
  12272. $tmpfont = $this->getFontBuffer($font);
  12273. // set data for parent group
  12274. if (!isset($this->radiobutton_groups[$this->page])) {
  12275. $this->radiobutton_groups[$this->page] = array();
  12276. }
  12277. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  12278. $this->radiobutton_groups[$this->page][$name] = array();
  12279. ++$this->n;
  12280. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  12281. $this->radio_groups[] = $this->n;
  12282. }
  12283. $kid = ($this->n + 1);
  12284. // save object ID to be added on Kids entry on parent object
  12285. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  12286. // get default style
  12287. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12288. $prop['NoToggleToOff'] = 'true';
  12289. $prop['Radio'] = 'true';
  12290. $prop['borderStyle'] = 'inset';
  12291. // get annotation data
  12292. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12293. // set additional default options
  12294. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12295. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12296. $popt['da'] = $fontstyle;
  12297. // build appearance stream
  12298. $popt['ap'] = array();
  12299. $popt['ap']['n'] = array();
  12300. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
  12301. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12302. $popt['ap']['n'][$onvalue] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(108).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy);
  12303. $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(109).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy);
  12304. if (!isset($popt['mk'])) {
  12305. $popt['mk'] = array();
  12306. }
  12307. $popt['mk']['ca'] = '(l)';
  12308. // merge options
  12309. $opt = array_merge($popt, $opt);
  12310. // set remaining annotation data
  12311. $opt['Subtype'] = 'Widget';
  12312. $opt['ft'] = 'Btn';
  12313. if ($checked) {
  12314. $opt['v'] = array('/'.$onvalue);
  12315. $opt['as'] = $onvalue;
  12316. } else {
  12317. $opt['as'] = 'Off';
  12318. }
  12319. // store readonly flag
  12320. if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
  12321. $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
  12322. }
  12323. $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
  12324. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12325. if ($this->rtl) {
  12326. $this->x -= $w;
  12327. } else {
  12328. $this->x += $w;
  12329. }
  12330. }
  12331. /**
  12332. * Creates a List-box field
  12333. * @param $name (string) field name
  12334. * @param $w (int) width
  12335. * @param $h (int) height
  12336. * @param $values (array) array containing the list of values.
  12337. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12338. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12339. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12340. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12341. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12342. * @public
  12343. * @author Nicola Asuni
  12344. * @since 4.8.000 (2009-09-07)
  12345. */
  12346. public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12347. if ($x === '') {
  12348. $x = $this->x;
  12349. }
  12350. if ($y === '') {
  12351. $y = $this->y;
  12352. }
  12353. // check page for no-write regions and adapt page margins if necessary
  12354. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12355. if ($js) {
  12356. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  12357. $s = '';
  12358. foreach ($values as $value) {
  12359. if (is_array($value)) {
  12360. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12361. } else {
  12362. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12363. }
  12364. }
  12365. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12366. return;
  12367. }
  12368. // get default style
  12369. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12370. // get annotation data
  12371. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12372. // set additional default values
  12373. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12374. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12375. $popt['da'] = $fontstyle;
  12376. // build appearance stream
  12377. $popt['ap'] = array();
  12378. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12379. $text = '';
  12380. foreach($values as $item) {
  12381. if (is_array($item)) {
  12382. $text .= $item[1]."\n";
  12383. } else {
  12384. $text .= $item."\n";
  12385. }
  12386. }
  12387. $tmpid = $this->startTemplate($w, $h, false);
  12388. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12389. $this->endTemplate();
  12390. --$this->n;
  12391. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12392. unset($this->xobjects[$tmpid]);
  12393. $popt['ap']['n'] .= 'Q EMC';
  12394. // merge options
  12395. $opt = array_merge($popt, $opt);
  12396. // set remaining annotation data
  12397. $opt['Subtype'] = 'Widget';
  12398. $opt['ft'] = 'Ch';
  12399. $opt['t'] = $name;
  12400. $opt['opt'] = $values;
  12401. unset($opt['mk']['ca']);
  12402. unset($opt['mk']['rc']);
  12403. unset($opt['mk']['ac']);
  12404. unset($opt['mk']['i']);
  12405. unset($opt['mk']['ri']);
  12406. unset($opt['mk']['ix']);
  12407. unset($opt['mk']['if']);
  12408. unset($opt['mk']['tp']);
  12409. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12410. if ($this->rtl) {
  12411. $this->x -= $w;
  12412. } else {
  12413. $this->x += $w;
  12414. }
  12415. }
  12416. /**
  12417. * Creates a Combo-box field
  12418. * @param $name (string) field name
  12419. * @param $w (int) width
  12420. * @param $h (int) height
  12421. * @param $values (array) array containing the list of values.
  12422. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12423. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12424. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12425. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12426. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12427. * @public
  12428. * @author Nicola Asuni
  12429. * @since 4.8.000 (2009-09-07)
  12430. */
  12431. public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12432. if ($x === '') {
  12433. $x = $this->x;
  12434. }
  12435. if ($y === '') {
  12436. $y = $this->y;
  12437. }
  12438. // check page for no-write regions and adapt page margins if necessary
  12439. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12440. if ($js) {
  12441. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  12442. $s = '';
  12443. foreach ($values as $value) {
  12444. if (is_array($value)) {
  12445. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12446. } else {
  12447. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12448. }
  12449. }
  12450. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12451. return;
  12452. }
  12453. // get default style
  12454. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12455. $prop['Combo'] = true;
  12456. // get annotation data
  12457. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12458. // set additional default options
  12459. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12460. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12461. $popt['da'] = $fontstyle;
  12462. // build appearance stream
  12463. $popt['ap'] = array();
  12464. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12465. $text = '';
  12466. foreach($values as $item) {
  12467. if (is_array($item)) {
  12468. $text .= $item[1]."\n";
  12469. } else {
  12470. $text .= $item."\n";
  12471. }
  12472. }
  12473. $tmpid = $this->startTemplate($w, $h, false);
  12474. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12475. $this->endTemplate();
  12476. --$this->n;
  12477. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12478. unset($this->xobjects[$tmpid]);
  12479. $popt['ap']['n'] .= 'Q EMC';
  12480. // merge options
  12481. $opt = array_merge($popt, $opt);
  12482. // set remaining annotation data
  12483. $opt['Subtype'] = 'Widget';
  12484. $opt['ft'] = 'Ch';
  12485. $opt['t'] = $name;
  12486. $opt['opt'] = $values;
  12487. unset($opt['mk']['ca']);
  12488. unset($opt['mk']['rc']);
  12489. unset($opt['mk']['ac']);
  12490. unset($opt['mk']['i']);
  12491. unset($opt['mk']['ri']);
  12492. unset($opt['mk']['ix']);
  12493. unset($opt['mk']['if']);
  12494. unset($opt['mk']['tp']);
  12495. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12496. if ($this->rtl) {
  12497. $this->x -= $w;
  12498. } else {
  12499. $this->x += $w;
  12500. }
  12501. }
  12502. /**
  12503. * Creates a CheckBox field
  12504. * @param $name (string) field name
  12505. * @param $w (int) width
  12506. * @param $checked (boolean) define the initial state.
  12507. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12508. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12509. * @param $onvalue (string) value to be returned if selected.
  12510. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12511. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12512. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12513. * @public
  12514. * @author Nicola Asuni
  12515. * @since 4.8.000 (2009-09-07)
  12516. */
  12517. public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
  12518. if ($x === '') {
  12519. $x = $this->x;
  12520. }
  12521. if ($y === '') {
  12522. $y = $this->y;
  12523. }
  12524. // check page for no-write regions and adapt page margins if necessary
  12525. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12526. if ($js) {
  12527. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  12528. return;
  12529. }
  12530. if (!isset($prop['value'])) {
  12531. $prop['value'] = array('Yes');
  12532. }
  12533. // get default style
  12534. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12535. $prop['borderStyle'] = 'inset';
  12536. // get annotation data
  12537. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12538. // set additional default options
  12539. $font = 'zapfdingbats';
  12540. if ($this->pdfa_mode) {
  12541. // all fonts must be embedded
  12542. $font = 'pdfa'.$font;
  12543. }
  12544. $this->AddFont($font);
  12545. $tmpfont = $this->getFontBuffer($font);
  12546. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12547. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12548. $popt['da'] = $fontstyle;
  12549. // build appearance stream
  12550. $popt['ap'] = array();
  12551. $popt['ap']['n'] = array();
  12552. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
  12553. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12554. $popt['ap']['n']['Yes'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(110).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy);
  12555. $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(111).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy);
  12556. // merge options
  12557. $opt = array_merge($popt, $opt);
  12558. // set remaining annotation data
  12559. $opt['Subtype'] = 'Widget';
  12560. $opt['ft'] = 'Btn';
  12561. $opt['t'] = $name;
  12562. if (TCPDF_STATIC::empty_string($onvalue)) {
  12563. $onvalue = 'Yes';
  12564. }
  12565. $opt['opt'] = array($onvalue);
  12566. if ($checked) {
  12567. $opt['v'] = array('/Yes');
  12568. $opt['as'] = 'Yes';
  12569. } else {
  12570. $opt['v'] = array('/Off');
  12571. $opt['as'] = 'Off';
  12572. }
  12573. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12574. if ($this->rtl) {
  12575. $this->x -= $w;
  12576. } else {
  12577. $this->x += $w;
  12578. }
  12579. }
  12580. /**
  12581. * Creates a button field
  12582. * @param $name (string) field name
  12583. * @param $w (int) width
  12584. * @param $h (int) height
  12585. * @param $caption (string) caption.
  12586. * @param $action (mixed) action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as on section 12.7.5 of PDF32000_2008.
  12587. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12588. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12589. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12590. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12591. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12592. * @public
  12593. * @author Nicola Asuni
  12594. * @since 4.8.000 (2009-09-07)
  12595. */
  12596. public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12597. if ($x === '') {
  12598. $x = $this->x;
  12599. }
  12600. if ($y === '') {
  12601. $y = $this->y;
  12602. }
  12603. // check page for no-write regions and adapt page margins if necessary
  12604. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12605. if ($js) {
  12606. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  12607. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  12608. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  12609. $this->javascript .= 'f'.$name.".highlight='push';\n";
  12610. $this->javascript .= 'f'.$name.".print=false;\n";
  12611. return;
  12612. }
  12613. // get default style
  12614. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12615. $prop['Pushbutton'] = 'true';
  12616. $prop['highlight'] = 'push';
  12617. $prop['display'] = 'display.noPrint';
  12618. // get annotation data
  12619. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12620. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12621. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12622. $popt['da'] = $fontstyle;
  12623. // build appearance stream
  12624. $popt['ap'] = array();
  12625. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12626. $tmpid = $this->startTemplate($w, $h, false);
  12627. $bw = (2 / $this->k); // border width
  12628. $border = array(
  12629. 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12630. 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
  12631. 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12632. 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
  12633. $this->SetFillColor(204);
  12634. $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
  12635. $this->endTemplate();
  12636. --$this->n;
  12637. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12638. unset($this->xobjects[$tmpid]);
  12639. $popt['ap']['n'] .= 'Q EMC';
  12640. // set additional default options
  12641. if (!isset($popt['mk'])) {
  12642. $popt['mk'] = array();
  12643. }
  12644. $ann_obj_id = ($this->n + 1);
  12645. if (!empty($action) AND !is_array($action)) {
  12646. $ann_obj_id = ($this->n + 2);
  12647. }
  12648. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  12649. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  12650. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  12651. // merge options
  12652. $opt = array_merge($popt, $opt);
  12653. // set remaining annotation data
  12654. $opt['Subtype'] = 'Widget';
  12655. $opt['ft'] = 'Btn';
  12656. $opt['t'] = $caption;
  12657. $opt['v'] = $name;
  12658. if (!empty($action)) {
  12659. if (is_array($action)) {
  12660. // form action options as on section 12.7.5 of PDF32000_2008.
  12661. $opt['aa'] = '/D <<';
  12662. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  12663. foreach ($action AS $key => $val) {
  12664. if (($key == 'S') AND in_array($val, $bmode)) {
  12665. $opt['aa'] .= ' /S /'.$val;
  12666. } elseif (($key == 'F') AND (!empty($val))) {
  12667. $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
  12668. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  12669. $opt['aa'] .= ' /Fields [';
  12670. foreach ($val AS $field) {
  12671. $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
  12672. }
  12673. $opt['aa'] .= ']';
  12674. } elseif (($key == 'Flags')) {
  12675. $ff = 0;
  12676. if (is_array($val)) {
  12677. foreach ($val AS $flag) {
  12678. switch ($flag) {
  12679. case 'Include/Exclude': {
  12680. $ff += 1 << 0;
  12681. break;
  12682. }
  12683. case 'IncludeNoValueFields': {
  12684. $ff += 1 << 1;
  12685. break;
  12686. }
  12687. case 'ExportFormat': {
  12688. $ff += 1 << 2;
  12689. break;
  12690. }
  12691. case 'GetMethod': {
  12692. $ff += 1 << 3;
  12693. break;
  12694. }
  12695. case 'SubmitCoordinates': {
  12696. $ff += 1 << 4;
  12697. break;
  12698. }
  12699. case 'XFDF': {
  12700. $ff += 1 << 5;
  12701. break;
  12702. }
  12703. case 'IncludeAppendSaves': {
  12704. $ff += 1 << 6;
  12705. break;
  12706. }
  12707. case 'IncludeAnnotations': {
  12708. $ff += 1 << 7;
  12709. break;
  12710. }
  12711. case 'SubmitPDF': {
  12712. $ff += 1 << 8;
  12713. break;
  12714. }
  12715. case 'CanonicalFormat': {
  12716. $ff += 1 << 9;
  12717. break;
  12718. }
  12719. case 'ExclNonUserAnnots': {
  12720. $ff += 1 << 10;
  12721. break;
  12722. }
  12723. case 'ExclFKey': {
  12724. $ff += 1 << 11;
  12725. break;
  12726. }
  12727. case 'EmbedForm': {
  12728. $ff += 1 << 13;
  12729. break;
  12730. }
  12731. }
  12732. }
  12733. } else {
  12734. $ff = intval($val);
  12735. }
  12736. $opt['aa'] .= ' /Flags '.$ff;
  12737. }
  12738. }
  12739. $opt['aa'] .= ' >>';
  12740. } else {
  12741. // Javascript action or raw action command
  12742. $js_obj_id = $this->addJavascriptObject($action);
  12743. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  12744. }
  12745. }
  12746. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12747. if ($this->rtl) {
  12748. $this->x -= $w;
  12749. } else {
  12750. $this->x += $w;
  12751. }
  12752. }
  12753. // --- END FORMS FIELDS ------------------------------------------------
  12754. /**
  12755. * Add certification signature (DocMDP or UR3)
  12756. * You can set only one signature type
  12757. * @protected
  12758. * @author Nicola Asuni
  12759. * @since 4.6.008 (2009-05-07)
  12760. */
  12761. protected function _putsignature() {
  12762. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  12763. return;
  12764. }
  12765. $sigobjid = ($this->sig_obj_id + 1);
  12766. $out = $this->_getobj($sigobjid)."\n";
  12767. $out .= '<< /Type /Sig';
  12768. $out .= ' /Filter /Adobe.PPKLite';
  12769. $out .= ' /SubFilter /adbe.pkcs7.detached';
  12770. $out .= ' '.TCPDF_STATIC::$byterange_string;
  12771. $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
  12772. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  12773. $out .= ' /Reference ['; // array of signature reference dictionaries
  12774. $out .= ' << /Type /SigRef';
  12775. if ($this->signature_data['cert_type'] > 0) {
  12776. $out .= ' /TransformMethod /DocMDP';
  12777. $out .= ' /TransformParams <<';
  12778. $out .= ' /Type /TransformParams';
  12779. $out .= ' /P '.$this->signature_data['cert_type'];
  12780. $out .= ' /V /1.2';
  12781. } else {
  12782. $out .= ' /TransformMethod /UR3';
  12783. $out .= ' /TransformParams <<';
  12784. $out .= ' /Type /TransformParams';
  12785. $out .= ' /V /2.2';
  12786. if (!TCPDF_STATIC::empty_string($this->ur['document'])) {
  12787. $out .= ' /Document['.$this->ur['document'].']';
  12788. }
  12789. if (!TCPDF_STATIC::empty_string($this->ur['form'])) {
  12790. $out .= ' /Form['.$this->ur['form'].']';
  12791. }
  12792. if (!TCPDF_STATIC::empty_string($this->ur['signature'])) {
  12793. $out .= ' /Signature['.$this->ur['signature'].']';
  12794. }
  12795. if (!TCPDF_STATIC::empty_string($this->ur['annots'])) {
  12796. $out .= ' /Annots['.$this->ur['annots'].']';
  12797. }
  12798. if (!TCPDF_STATIC::empty_string($this->ur['ef'])) {
  12799. $out .= ' /EF['.$this->ur['ef'].']';
  12800. }
  12801. if (!TCPDF_STATIC::empty_string($this->ur['formex'])) {
  12802. $out .= ' /FormEX['.$this->ur['formex'].']';
  12803. }
  12804. }
  12805. $out .= ' >>'; // close TransformParams
  12806. // optional digest data (values must be calculated and replaced later)
  12807. //$out .= ' /Data ********** 0 R';
  12808. //$out .= ' /DigestMethod/MD5';
  12809. //$out .= ' /DigestLocation[********** 34]';
  12810. //$out .= ' /DigestValue<********************************>';
  12811. $out .= ' >>';
  12812. $out .= ' ]'; // end of reference
  12813. }
  12814. if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) {
  12815. $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
  12816. }
  12817. if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) {
  12818. $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
  12819. }
  12820. if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) {
  12821. $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
  12822. }
  12823. if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) {
  12824. $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
  12825. }
  12826. $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp);
  12827. $out .= ' >>';
  12828. $out .= "\n".'endobj';
  12829. $this->_out($out);
  12830. }
  12831. /**
  12832. * Set User's Rights for PDF Reader
  12833. * WARNING: This is experimental and currently do not work.
  12834. * Check the PDF Reference 8.7.1 Transform Methods,
  12835. * Table 8.105 Entries in the UR transform parameters dictionary
  12836. * @param $enable (boolean) if true enable user's rights on PDF reader
  12837. * @param $document (string) Names specifying additional document-wide usage rights for the document. The only defined value is "/FullSave", which permits a user to save the document along with modified form and/or annotation data.
  12838. * @param $annots (string) Names specifying additional annotation-related usage rights for the document. Valid names in PDF 1.5 and later are /Create/Delete/Modify/Copy/Import/Export, which permit the user to perform the named operation on annotations.
  12839. * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  12840. * @param $signature (string) Names specifying additional signature-related usage rights for the document. The only defined value is /Modify, which permits a user to apply a digital signature to an existing signature form field or clear a signed signature form field.
  12841. * @param $ef (string) Names specifying additional usage rights for named embedded files in the document. Valid names are /Create/Delete/Modify/Import, which permit the user to perform the named operation on named embedded files
  12842. Names specifying additional embedded-files-related usage rights for the document.
  12843. * @param $formex (string) Names specifying additional form-field-related usage rights. The only valid name is BarcodePlaintext, which permits text form field data to be encoded as a plaintext two-dimensional barcode.
  12844. * @public
  12845. * @author Nicola Asuni
  12846. * @since 2.9.000 (2008-03-26)
  12847. */
  12848. public function setUserRights(
  12849. $enable=true,
  12850. $document='/FullSave',
  12851. $annots='/Create/Delete/Modify/Copy/Import/Export',
  12852. $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  12853. $signature='/Modify',
  12854. $ef='/Create/Delete/Modify/Import',
  12855. $formex='') {
  12856. $this->ur['enabled'] = $enable;
  12857. $this->ur['document'] = $document;
  12858. $this->ur['annots'] = $annots;
  12859. $this->ur['form'] = $form;
  12860. $this->ur['signature'] = $signature;
  12861. $this->ur['ef'] = $ef;
  12862. $this->ur['formex'] = $formex;
  12863. if (!$this->sign) {
  12864. $this->setSignature('', '', '', '', 0, array());
  12865. }
  12866. }
  12867. /**
  12868. * Enable document signature (requires the OpenSSL Library).
  12869. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  12870. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12871. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12872. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  12873. * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://')
  12874. * @param $private_key (mixed) private key (string or filename prefixed with 'file://')
  12875. * @param $private_key_password (string) password
  12876. * @param $extracerts (string) specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.
  12877. * @param $cert_type (int) The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature.
  12878. * @param $info (array) array of option information: Name, Location, Reason, ContactInfo.
  12879. * @param $approval (string) Enable approval signature eg. for PDF incremental update
  12880. * @public
  12881. * @author Nicola Asuni
  12882. * @since 4.6.005 (2009-04-24)
  12883. */
  12884. public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array(), $approval='') {
  12885. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12886. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12887. // to convert pfx certificate to pem: openssl
  12888. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  12889. $this->sign = true;
  12890. ++$this->n;
  12891. $this->sig_obj_id = $this->n; // signature widget
  12892. ++$this->n; // signature object ($this->sig_obj_id + 1)
  12893. $this->signature_data = array();
  12894. if (strlen($signing_cert) == 0) {
  12895. $this->Error('Please provide a certificate file and password!');
  12896. }
  12897. if (strlen($private_key) == 0) {
  12898. $private_key = $signing_cert;
  12899. }
  12900. $this->signature_data['signcert'] = $signing_cert;
  12901. $this->signature_data['privkey'] = $private_key;
  12902. $this->signature_data['password'] = $private_key_password;
  12903. $this->signature_data['extracerts'] = $extracerts;
  12904. $this->signature_data['cert_type'] = $cert_type;
  12905. $this->signature_data['info'] = $info;
  12906. $this->signature_data['approval'] = $approval;
  12907. }
  12908. /**
  12909. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  12910. * @param $x (float) Abscissa of the upper-left corner.
  12911. * @param $y (float) Ordinate of the upper-left corner.
  12912. * @param $w (float) Width of the signature area.
  12913. * @param $h (float) Height of the signature area.
  12914. * @param $page (int) option page number (if < 0 the current page is used).
  12915. * @param $name (string) Name of the signature.
  12916. * @public
  12917. * @author Nicola Asuni
  12918. * @since 5.3.011 (2010-06-17)
  12919. */
  12920. public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12921. $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  12922. }
  12923. /**
  12924. * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
  12925. * @param $x (float) Abscissa of the upper-left corner.
  12926. * @param $y (float) Ordinate of the upper-left corner.
  12927. * @param $w (float) Width of the signature area.
  12928. * @param $h (float) Height of the signature area.
  12929. * @param $page (int) option page number (if < 0 the current page is used).
  12930. * @param $name (string) Name of the signature.
  12931. * @public
  12932. * @author Nicola Asuni
  12933. * @since 5.9.101 (2011-07-06)
  12934. */
  12935. public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12936. ++$this->n;
  12937. $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  12938. }
  12939. /**
  12940. * Get the array that defines the signature appearance (page and rectangle coordinates).
  12941. * @param $x (float) Abscissa of the upper-left corner.
  12942. * @param $y (float) Ordinate of the upper-left corner.
  12943. * @param $w (float) Width of the signature area.
  12944. * @param $h (float) Height of the signature area.
  12945. * @param $page (int) option page number (if < 0 the current page is used).
  12946. * @param $name (string) Name of the signature.
  12947. * @return (array) Array defining page and rectangle coordinates of signature appearance.
  12948. * @protected
  12949. * @author Nicola Asuni
  12950. * @since 5.9.101 (2011-07-06)
  12951. */
  12952. protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12953. $sigapp = array();
  12954. if (($page < 1) OR ($page > $this->numpages)) {
  12955. $sigapp['page'] = $this->page;
  12956. } else {
  12957. $sigapp['page'] = intval($page);
  12958. }
  12959. if (empty($name)) {
  12960. $sigapp['name'] = 'Signature';
  12961. } else {
  12962. $sigapp['name'] = $name;
  12963. }
  12964. $a = $x * $this->k;
  12965. $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
  12966. $c = $w * $this->k;
  12967. $d = $h * $this->k;
  12968. $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a + $c), ($b + $d));
  12969. return $sigapp;
  12970. }
  12971. /**
  12972. * Enable document timestamping (requires the OpenSSL Library).
  12973. * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded.
  12974. * Use with digital signature only!
  12975. * @param $tsa_host (string) Time Stamping Authority (TSA) server (prefixed with 'https://')
  12976. * @param $tsa_username (string) Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional)
  12977. * @param $tsa_password (string) Specifies the password for TSA authorization (optional)
  12978. * @param $tsa_cert (string) Specifies the location of TSA certificate for authorization (optional for cURL)
  12979. * @public
  12980. * @author Richard Stockinger
  12981. * @since 6.0.090 (2014-06-16)
  12982. */
  12983. public function setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='') {
  12984. $this->tsa_data = array();
  12985. if (!function_exists('curl_init')) {
  12986. $this->Error('Please enable cURL PHP extension!');
  12987. }
  12988. if (strlen($tsa_host) == 0) {
  12989. $this->Error('Please specify the host of Time Stamping Authority (TSA)!');
  12990. }
  12991. $this->tsa_data['tsa_host'] = $tsa_host;
  12992. if (is_file($tsa_username)) {
  12993. $this->tsa_data['tsa_auth'] = $tsa_username;
  12994. } else {
  12995. $this->tsa_data['tsa_username'] = $tsa_username;
  12996. }
  12997. $this->tsa_data['tsa_password'] = $tsa_password;
  12998. $this->tsa_data['tsa_cert'] = $tsa_cert;
  12999. $this->tsa_timestamp = true;
  13000. }
  13001. /**
  13002. * NOT YET IMPLEMENTED
  13003. * Request TSA for a timestamp
  13004. * @param $signature (string) Digital signature as binary string
  13005. * @return (string) Timestamped digital signature
  13006. * @protected
  13007. * @author Richard Stockinger
  13008. * @since 6.0.090 (2014-06-16)
  13009. */
  13010. protected function applyTSA($signature) {
  13011. if (!$this->tsa_timestamp) {
  13012. return $signature;
  13013. }
  13014. //@TODO: implement this feature
  13015. return $signature;
  13016. }
  13017. /**
  13018. * Create a new page group.
  13019. * NOTE: call this function before calling AddPage()
  13020. * @param $page (int) starting group page (leave empty for next page).
  13021. * @public
  13022. * @since 3.0.000 (2008-03-27)
  13023. */
  13024. public function startPageGroup($page='') {
  13025. if (empty($page)) {
  13026. $page = $this->page + 1;
  13027. }
  13028. $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
  13029. }
  13030. /**
  13031. * Set the starting page number.
  13032. * @param $num (int) Starting page number.
  13033. * @since 5.9.093 (2011-06-16)
  13034. * @public
  13035. */
  13036. public function setStartingPageNumber($num=1) {
  13037. $this->starting_page_number = max(0, intval($num));
  13038. }
  13039. /**
  13040. * Returns the string alias used right align page numbers.
  13041. * If the current font is unicode type, the returned string wil contain an additional open curly brace.
  13042. * @return string
  13043. * @since 5.9.099 (2011-06-27)
  13044. * @public
  13045. */
  13046. public function getAliasRightShift() {
  13047. // calculate aproximatively the ratio between widths of aliases and replacements.
  13048. $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}';
  13049. $rep = str_repeat(' ', $this->GetNumChars($ref));
  13050. $wrep = $this->GetStringWidth($rep);
  13051. if ($wrep > 0) {
  13052. $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep));
  13053. } else {
  13054. $wdiff = 1;
  13055. }
  13056. $sdiff = sprintf('%F', $wdiff);
  13057. $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}';
  13058. if ($this->isUnicodeFont()) {
  13059. $alias = '{'.$alias;
  13060. }
  13061. return $alias;
  13062. }
  13063. /**
  13064. * Returns the string alias used for the total number of pages.
  13065. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13066. * This alias will be replaced by the total number of pages in the document.
  13067. * @return string
  13068. * @since 4.0.018 (2008-08-08)
  13069. * @public
  13070. */
  13071. public function getAliasNbPages() {
  13072. if ($this->isUnicodeFont()) {
  13073. return '{'.TCPDF_STATIC::$alias_tot_pages.'}';
  13074. }
  13075. return TCPDF_STATIC::$alias_tot_pages;
  13076. }
  13077. /**
  13078. * Returns the string alias used for the page number.
  13079. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13080. * This alias will be replaced by the page number.
  13081. * @return string
  13082. * @since 4.5.000 (2009-01-02)
  13083. * @public
  13084. */
  13085. public function getAliasNumPage() {
  13086. if ($this->isUnicodeFont()) {
  13087. return '{'.TCPDF_STATIC::$alias_num_page.'}';
  13088. }
  13089. return TCPDF_STATIC::$alias_num_page;
  13090. }
  13091. /**
  13092. * Return the alias for the total number of pages in the current page group.
  13093. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13094. * This alias will be replaced by the total number of pages in this group.
  13095. * @return alias of the current page group
  13096. * @public
  13097. * @since 3.0.000 (2008-03-27)
  13098. */
  13099. public function getPageGroupAlias() {
  13100. if ($this->isUnicodeFont()) {
  13101. return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}';
  13102. }
  13103. return TCPDF_STATIC::$alias_group_tot_pages;
  13104. }
  13105. /**
  13106. * Return the alias for the page number on the current page group.
  13107. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13108. * This alias will be replaced by the page number (relative to the belonging group).
  13109. * @return alias of the current page group
  13110. * @public
  13111. * @since 4.5.000 (2009-01-02)
  13112. */
  13113. public function getPageNumGroupAlias() {
  13114. if ($this->isUnicodeFont()) {
  13115. return '{'.TCPDF_STATIC::$alias_group_num_page.'}';
  13116. }
  13117. return TCPDF_STATIC::$alias_group_num_page;
  13118. }
  13119. /**
  13120. * Return the current page in the group.
  13121. * @return current page in the group
  13122. * @public
  13123. * @since 3.0.000 (2008-03-27)
  13124. */
  13125. public function getGroupPageNo() {
  13126. return $this->pagegroups[$this->currpagegroup];
  13127. }
  13128. /**
  13129. * Returns the current group page number formatted as a string.
  13130. * @public
  13131. * @since 4.3.003 (2008-11-18)
  13132. * @see PaneNo(), formatPageNumber()
  13133. */
  13134. public function getGroupPageNoFormatted() {
  13135. return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo());
  13136. }
  13137. /**
  13138. * Returns the current page number formatted as a string.
  13139. * @public
  13140. * @since 4.2.005 (2008-11-06)
  13141. * @see PaneNo(), formatPageNumber()
  13142. */
  13143. public function PageNoFormatted() {
  13144. return TCPDF_STATIC::formatPageNumber($this->PageNo());
  13145. }
  13146. /**
  13147. * Put pdf layers.
  13148. * @protected
  13149. * @since 3.0.000 (2008-03-27)
  13150. */
  13151. protected function _putocg() {
  13152. if (empty($this->pdflayers)) {
  13153. return;
  13154. }
  13155. foreach ($this->pdflayers as $key => $layer) {
  13156. $this->pdflayers[$key]['objid'] = $this->_newobj();
  13157. $out = '<< /Type /OCG';
  13158. $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
  13159. $out .= ' /Usage <<';
  13160. if (isset($layer['print']) AND ($layer['print'] !== NULL)) {
  13161. $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
  13162. }
  13163. $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
  13164. $out .= ' >> >>';
  13165. $out .= "\n".'endobj';
  13166. $this->_out($out);
  13167. }
  13168. }
  13169. /**
  13170. * Start a new pdf layer.
  13171. * @param $name (string) Layer name (only a-z letters and numbers). Leave empty for automatic name.
  13172. * @param $print (boolean|null) Set to TRUE to print this layer, FALSE to not print and NULL to not set this option
  13173. * @param $view (boolean) Set to true to view this layer.
  13174. * @param $lock (boolean) If true lock the layer
  13175. * @public
  13176. * @since 5.9.102 (2011-07-13)
  13177. */
  13178. public function startLayer($name='', $print=true, $view=true, $lock=true) {
  13179. if ($this->state != 2) {
  13180. return;
  13181. }
  13182. $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
  13183. if (empty($name)) {
  13184. $name = $layer;
  13185. } else {
  13186. $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
  13187. }
  13188. $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view, 'lock' => $lock);
  13189. $this->openMarkedContent = true;
  13190. $this->_out('/OC /'.$layer.' BDC');
  13191. }
  13192. /**
  13193. * End the current PDF layer.
  13194. * @public
  13195. * @since 5.9.102 (2011-07-13)
  13196. */
  13197. public function endLayer() {
  13198. if ($this->state != 2) {
  13199. return;
  13200. }
  13201. if ($this->openMarkedContent) {
  13202. // close existing open marked-content layer
  13203. $this->_out('EMC');
  13204. $this->openMarkedContent = false;
  13205. }
  13206. }
  13207. /**
  13208. * Set the visibility of the successive elements.
  13209. * This can be useful, for instance, to put a background
  13210. * image or color that will show on screen but won't print.
  13211. * @param $v (string) visibility mode. Legal values are: all, print, screen or view.
  13212. * @public
  13213. * @since 3.0.000 (2008-03-27)
  13214. */
  13215. public function setVisibility($v) {
  13216. if ($this->state != 2) {
  13217. return;
  13218. }
  13219. $this->endLayer();
  13220. switch($v) {
  13221. case 'print': {
  13222. $this->startLayer('Print', true, false);
  13223. break;
  13224. }
  13225. case 'view':
  13226. case 'screen': {
  13227. $this->startLayer('View', false, true);
  13228. break;
  13229. }
  13230. case 'all': {
  13231. $this->_out('');
  13232. break;
  13233. }
  13234. default: {
  13235. $this->Error('Incorrect visibility: '.$v);
  13236. break;
  13237. }
  13238. }
  13239. }
  13240. /**
  13241. * Add transparency parameters to the current extgstate
  13242. * @param $parms (array) parameters
  13243. * @return the number of extgstates
  13244. * @protected
  13245. * @since 3.0.000 (2008-03-27)
  13246. */
  13247. protected function addExtGState($parms) {
  13248. if ($this->pdfa_mode) {
  13249. // transparencies are not allowed in PDF/A mode
  13250. return;
  13251. }
  13252. // check if this ExtGState already exist
  13253. foreach ($this->extgstates as $i => $ext) {
  13254. if ($ext['parms'] == $parms) {
  13255. if ($this->inxobj) {
  13256. // we are inside an XObject template
  13257. $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
  13258. }
  13259. // return reference to existing ExtGState
  13260. return $i;
  13261. }
  13262. }
  13263. $n = (count($this->extgstates) + 1);
  13264. $this->extgstates[$n] = array('parms' => $parms);
  13265. if ($this->inxobj) {
  13266. // we are inside an XObject template
  13267. $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
  13268. }
  13269. return $n;
  13270. }
  13271. /**
  13272. * Add an extgstate
  13273. * @param $gs (array) extgstate
  13274. * @protected
  13275. * @since 3.0.000 (2008-03-27)
  13276. */
  13277. protected function setExtGState($gs) {
  13278. if ($this->pdfa_mode OR ($this->state != 2)) {
  13279. // transparency is not allowed in PDF/A mode
  13280. return;
  13281. }
  13282. $this->_out(sprintf('/GS%d gs', $gs));
  13283. }
  13284. /**
  13285. * Put extgstates for object transparency
  13286. * @protected
  13287. * @since 3.0.000 (2008-03-27)
  13288. */
  13289. protected function _putextgstates() {
  13290. foreach ($this->extgstates as $i => $ext) {
  13291. $this->extgstates[$i]['n'] = $this->_newobj();
  13292. $out = '<< /Type /ExtGState';
  13293. foreach ($ext['parms'] as $k => $v) {
  13294. if (is_float($v)) {
  13295. $v = sprintf('%F', $v);
  13296. } elseif ($v === true) {
  13297. $v = 'true';
  13298. } elseif ($v === false) {
  13299. $v = 'false';
  13300. }
  13301. $out .= ' /'.$k.' '.$v;
  13302. }
  13303. $out .= ' >>';
  13304. $out .= "\n".'endobj';
  13305. $this->_out($out);
  13306. }
  13307. }
  13308. /**
  13309. * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
  13310. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13311. * @param $stroking (boolean) If true apply overprint for stroking operations.
  13312. * @param $nonstroking (boolean) If true apply overprint for painting operations other than stroking.
  13313. * @param $mode (integer) Overprint mode: (0 = each source colour component value replaces the value previously painted for the corresponding device colorant; 1 = a tint value of 0.0 for a source colour component shall leave the corresponding component of the previously painted colour unchanged).
  13314. * @public
  13315. * @since 5.9.152 (2012-03-23)
  13316. */
  13317. public function setOverprint($stroking=true, $nonstroking='', $mode=0) {
  13318. if ($this->state != 2) {
  13319. return;
  13320. }
  13321. $stroking = $stroking ? true : false;
  13322. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13323. // default value if not set
  13324. $nonstroking = $stroking;
  13325. } else {
  13326. $nonstroking = $nonstroking ? true : false;
  13327. }
  13328. if (($mode != 0) AND ($mode != 1)) {
  13329. $mode = 0;
  13330. }
  13331. $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
  13332. $gs = $this->addExtGState($this->overprint);
  13333. $this->setExtGState($gs);
  13334. }
  13335. /**
  13336. * Get the overprint mode array (OP, op, OPM).
  13337. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13338. * @return array.
  13339. * @public
  13340. * @since 5.9.152 (2012-03-23)
  13341. */
  13342. public function getOverprint() {
  13343. return $this->overprint;
  13344. }
  13345. /**
  13346. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  13347. * @param $stroking (float) Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
  13348. * @param $bm (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  13349. * @param $nonstroking (float) Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
  13350. * @param $ais (boolean)
  13351. * @public
  13352. * @since 3.0.000 (2008-03-27)
  13353. */
  13354. public function setAlpha($stroking=1, $bm='Normal', $nonstroking='', $ais=false) {
  13355. if ($this->pdfa_mode) {
  13356. // transparency is not allowed in PDF/A mode
  13357. return;
  13358. }
  13359. $stroking = floatval($stroking);
  13360. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13361. // default value if not set
  13362. $nonstroking = $stroking;
  13363. } else {
  13364. $nonstroking = floatval($nonstroking);
  13365. }
  13366. if ($bm[0] == '/') {
  13367. // remove trailing slash
  13368. $bm = substr($bm, 1);
  13369. }
  13370. if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  13371. $bm = 'Normal';
  13372. }
  13373. $ais = $ais ? true : false;
  13374. $this->alpha = array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
  13375. $gs = $this->addExtGState($this->alpha);
  13376. $this->setExtGState($gs);
  13377. }
  13378. /**
  13379. * Get the alpha mode array (CA, ca, BM, AIS).
  13380. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13381. * @return array.
  13382. * @public
  13383. * @since 5.9.152 (2012-03-23)
  13384. */
  13385. public function getAlpha() {
  13386. return $this->alpha;
  13387. }
  13388. /**
  13389. * Set the default JPEG compression quality (1-100)
  13390. * @param $quality (int) JPEG quality, integer between 1 and 100
  13391. * @public
  13392. * @since 3.0.000 (2008-03-27)
  13393. */
  13394. public function setJPEGQuality($quality) {
  13395. if (($quality < 1) OR ($quality > 100)) {
  13396. $quality = 75;
  13397. }
  13398. $this->jpeg_quality = intval($quality);
  13399. }
  13400. /**
  13401. * Set the default number of columns in a row for HTML tables.
  13402. * @param $cols (int) number of columns
  13403. * @public
  13404. * @since 3.0.014 (2008-06-04)
  13405. */
  13406. public function setDefaultTableColumns($cols=4) {
  13407. $this->default_table_columns = intval($cols);
  13408. }
  13409. /**
  13410. * Set the height of the cell (line height) respect the font height.
  13411. * @param $h (int) cell proportion respect font height (typical value = 1.25).
  13412. * @public
  13413. * @since 3.0.014 (2008-06-04)
  13414. */
  13415. public function setCellHeightRatio($h) {
  13416. $this->cell_height_ratio = $h;
  13417. }
  13418. /**
  13419. * return the height of cell repect font height.
  13420. * @public
  13421. * @since 4.0.012 (2008-07-24)
  13422. */
  13423. public function getCellHeightRatio() {
  13424. return $this->cell_height_ratio;
  13425. }
  13426. /**
  13427. * Set the PDF version (check PDF reference for valid values).
  13428. * @param $version (string) PDF document version.
  13429. * @public
  13430. * @since 3.1.000 (2008-06-09)
  13431. */
  13432. public function setPDFVersion($version='1.7') {
  13433. if ($this->pdfa_mode) {
  13434. // PDF/A mode
  13435. $this->PDFVersion = '1.4';
  13436. } else {
  13437. $this->PDFVersion = $version;
  13438. }
  13439. }
  13440. /**
  13441. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  13442. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  13443. * <ul><li>HideToolbar boolean (Optional) A flag specifying whether to hide the viewer application's tool bars when the document is active. Default value: false.</li><li>HideMenubar boolean (Optional) A flag specifying whether to hide the viewer application's menu bar when the document is active. Default value: false.</li><li>HideWindowUI boolean (Optional) A flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed. Default value: false.</li><li>FitWindow boolean (Optional) A flag specifying whether to resize the document's window to fit the size of the first displayed page. Default value: false.</li><li>CenterWindow boolean (Optional) A flag specifying whether to position the document's window in the center of the screen. Default value: false.</li><li>DisplayDocTitle boolean (Optional; PDF 1.4) A flag specifying whether the window's title bar should display the document title taken from the Title entry of the document information dictionary (see Section 10.2.1, "Document Information Dictionary"). If false, the title bar should instead display the name of the PDF file containing the document. Default value: false.</li><li>NonFullScreenPageMode name (Optional) The document's page mode, specifying how to display the document on exiting full-screen mode:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>UseOC Optional content group panel visible</li></ul>This entry is meaningful only if the value of the PageMode entry in the catalog dictionary (see Section 3.6.1, "Document Catalog") is FullScreen; it is ignored otherwise. Default value: UseNone.</li><li>ViewArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be displayed when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li><li>ViewClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li><li>PrintArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be rendered when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li><li>PrintClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li><li>PrintScaling name (Optional; PDF 1.6) The page scaling option to be selected when a print dialog is displayed for this document. Valid values are: <ul><li>None, which indicates that the print dialog should reflect no page scaling</li><li>AppDefault (default), which indicates that applications should use the current print scaling</li></ul></li><li>Duplex name (Optional; PDF 1.7) The paper handling option to use when printing the file from the print dialog. The following values are valid:<ul><li>Simplex - Print single-sided</li><li>DuplexFlipShortEdge - Duplex and flip on the short edge of the sheet</li><li>DuplexFlipLongEdge - Duplex and flip on the long edge of the sheet</li></ul>Default value: none</li><li>PickTrayByPDFSize boolean (Optional; PDF 1.7) A flag specifying whether the PDF page size is used to select the input paper tray. This setting influences only the preset values used to populate the print dialog presented by a PDF viewer application. If PickTrayByPDFSize is true, the check box in the print dialog associated with input paper tray is checked. Note: This setting has no effect on Mac OS systems, which do not provide the ability to pick the input tray by size.</li><li>PrintPageRange array (Optional; PDF 1.7) The page numbers used to initialize the print dialog box when the file is printed. The first page of the PDF file is denoted by 1. Each pair consists of the first and last pages in the sub-range. An odd number of integers causes this entry to be ignored. Negative numbers cause the entire array to be ignored. Default value: as defined by PDF viewer application</li><li>NumCopies integer (Optional; PDF 1.7) The number of copies to be printed when the print dialog is opened for this file. Supported values are the integers 2 through 5. Values outside this range are ignored. Default value: as defined by PDF viewer application, but typically 1</li></ul>
  13444. * @param $preferences (array) array of options.
  13445. * @author Nicola Asuni
  13446. * @public
  13447. * @since 3.1.000 (2008-06-09)
  13448. */
  13449. public function setViewerPreferences($preferences) {
  13450. $this->viewer_preferences = $preferences;
  13451. }
  13452. /**
  13453. * Paints color transition registration bars
  13454. * @param $x (float) abscissa of the top left corner of the rectangle.
  13455. * @param $y (float) ordinate of the top left corner of the rectangle.
  13456. * @param $w (float) width of the rectangle.
  13457. * @param $h (float) height of the rectangle.
  13458. * @param $transition (boolean) if true prints tcolor transitions to white.
  13459. * @param $vertical (boolean) if true prints bar vertically.
  13460. * @param $colors (string) colors to print separated by comma. Valid values are: A,W,R,G,B,C,M,Y,K,RGB,CMYK,ALL,ALLSPOT,<SPOT_COLOR_NAME>. Where: A = grayscale black, W = grayscale white, R = RGB red, G RGB green, B RGB blue, C = CMYK cyan, M = CMYK magenta, Y = CMYK yellow, K = CMYK key/black, RGB = RGB registration color, CMYK = CMYK registration color, ALL = Spot registration color, ALLSPOT = print all defined spot colors, <SPOT_COLOR_NAME> = name of the spot color to print.
  13461. * @author Nicola Asuni
  13462. * @since 4.9.000 (2010-03-26)
  13463. * @public
  13464. */
  13465. public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
  13466. if (strpos($colors, 'ALLSPOT') !== false) {
  13467. // expand spot colors
  13468. $spot_colors = '';
  13469. foreach ($this->spot_colors as $spot_color_name => $v) {
  13470. $spot_colors .= ','.$spot_color_name;
  13471. }
  13472. if (!empty($spot_colors)) {
  13473. $spot_colors = substr($spot_colors, 1);
  13474. $colors = str_replace('ALLSPOT', $spot_colors, $colors);
  13475. } else {
  13476. $colors = str_replace('ALLSPOT', 'NONE', $colors);
  13477. }
  13478. }
  13479. $bars = explode(',', $colors);
  13480. $numbars = count($bars); // number of bars to print
  13481. if ($numbars <= 0) {
  13482. return;
  13483. }
  13484. // set bar measures
  13485. if ($vertical) {
  13486. $coords = array(0, 0, 0, 1);
  13487. $wb = $w / $numbars; // bar width
  13488. $hb = $h; // bar height
  13489. $xd = $wb; // delta x
  13490. $yd = 0; // delta y
  13491. } else {
  13492. $coords = array(1, 0, 0, 0);
  13493. $wb = $w; // bar width
  13494. $hb = $h / $numbars; // bar height
  13495. $xd = 0; // delta x
  13496. $yd = $hb; // delta y
  13497. }
  13498. $xb = $x;
  13499. $yb = $y;
  13500. foreach ($bars as $col) {
  13501. switch ($col) {
  13502. // set transition colors
  13503. case 'A': { // BLACK (GRAYSCALE)
  13504. $col_a = array(255);
  13505. $col_b = array(0);
  13506. break;
  13507. }
  13508. case 'W': { // WHITE (GRAYSCALE)
  13509. $col_a = array(0);
  13510. $col_b = array(255);
  13511. break;
  13512. }
  13513. case 'R': { // RED (RGB)
  13514. $col_a = array(255,255,255);
  13515. $col_b = array(255,0,0);
  13516. break;
  13517. }
  13518. case 'G': { // GREEN (RGB)
  13519. $col_a = array(255,255,255);
  13520. $col_b = array(0,255,0);
  13521. break;
  13522. }
  13523. case 'B': { // BLUE (RGB)
  13524. $col_a = array(255,255,255);
  13525. $col_b = array(0,0,255);
  13526. break;
  13527. }
  13528. case 'C': { // CYAN (CMYK)
  13529. $col_a = array(0,0,0,0);
  13530. $col_b = array(100,0,0,0);
  13531. break;
  13532. }
  13533. case 'M': { // MAGENTA (CMYK)
  13534. $col_a = array(0,0,0,0);
  13535. $col_b = array(0,100,0,0);
  13536. break;
  13537. }
  13538. case 'Y': { // YELLOW (CMYK)
  13539. $col_a = array(0,0,0,0);
  13540. $col_b = array(0,0,100,0);
  13541. break;
  13542. }
  13543. case 'K': { // KEY - BLACK (CMYK)
  13544. $col_a = array(0,0,0,0);
  13545. $col_b = array(0,0,0,100);
  13546. break;
  13547. }
  13548. case 'RGB': { // BLACK REGISTRATION (RGB)
  13549. $col_a = array(255,255,255);
  13550. $col_b = array(0,0,0);
  13551. break;
  13552. }
  13553. case 'CMYK': { // BLACK REGISTRATION (CMYK)
  13554. $col_a = array(0,0,0,0);
  13555. $col_b = array(100,100,100,100);
  13556. break;
  13557. }
  13558. case 'ALL': { // SPOT COLOR REGISTRATION
  13559. $col_a = array(0,0,0,0,'None');
  13560. $col_b = array(100,100,100,100,'All');
  13561. break;
  13562. }
  13563. case 'NONE': { // SKIP THIS COLOR
  13564. $col_a = array(0,0,0,0,'None');
  13565. $col_b = array(0,0,0,0,'None');
  13566. break;
  13567. }
  13568. default: { // SPECIFIC SPOT COLOR NAME
  13569. $col_a = array(0,0,0,0,'None');
  13570. $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors);
  13571. if ($col_b === false) {
  13572. // in case of error defaults to the registration color
  13573. $col_b = array(100,100,100,100,'All');
  13574. }
  13575. break;
  13576. }
  13577. }
  13578. if ($col != 'NONE') {
  13579. if ($transition) {
  13580. // color gradient
  13581. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  13582. } else {
  13583. $this->SetFillColorArray($col_b);
  13584. // colored rectangle
  13585. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  13586. }
  13587. $xb += $xd;
  13588. $yb += $yd;
  13589. }
  13590. }
  13591. }
  13592. /**
  13593. * Paints crop marks.
  13594. * @param $x (float) abscissa of the crop mark center.
  13595. * @param $y (float) ordinate of the crop mark center.
  13596. * @param $w (float) width of the crop mark.
  13597. * @param $h (float) height of the crop mark.
  13598. * @param $type (string) type of crop mark, one symbol per type separated by comma: T = TOP, F = BOTTOM, L = LEFT, R = RIGHT, TL = A = TOP-LEFT, TR = B = TOP-RIGHT, BL = C = BOTTOM-LEFT, BR = D = BOTTOM-RIGHT.
  13599. * @param $color (array) crop mark color (default spot registration color).
  13600. * @author Nicola Asuni
  13601. * @since 4.9.000 (2010-03-26)
  13602. * @public
  13603. */
  13604. public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(100,100,100,100,'All')) {
  13605. $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  13606. $type = strtoupper($type);
  13607. $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
  13608. // split type in single components
  13609. $type = str_replace('-', ',', $type);
  13610. $type = str_replace('TL', 'T,L', $type);
  13611. $type = str_replace('TR', 'T,R', $type);
  13612. $type = str_replace('BL', 'F,L', $type);
  13613. $type = str_replace('BR', 'F,R', $type);
  13614. $type = str_replace('A', 'T,L', $type);
  13615. $type = str_replace('B', 'T,R', $type);
  13616. $type = str_replace('T,RO', 'BO', $type);
  13617. $type = str_replace('C', 'F,L', $type);
  13618. $type = str_replace('D', 'F,R', $type);
  13619. $crops = explode(',', strtoupper($type));
  13620. // remove duplicates
  13621. $crops = array_unique($crops);
  13622. $dw = ($w / 4); // horizontal space to leave before the intersection point
  13623. $dh = ($h / 4); // vertical space to leave before the intersection point
  13624. foreach ($crops as $crop) {
  13625. switch ($crop) {
  13626. case 'T':
  13627. case 'TOP': {
  13628. $x1 = $x;
  13629. $y1 = ($y - $h);
  13630. $x2 = $x;
  13631. $y2 = ($y - $dh);
  13632. break;
  13633. }
  13634. case 'F':
  13635. case 'BOTTOM': {
  13636. $x1 = $x;
  13637. $y1 = ($y + $dh);
  13638. $x2 = $x;
  13639. $y2 = ($y + $h);
  13640. break;
  13641. }
  13642. case 'L':
  13643. case 'LEFT': {
  13644. $x1 = ($x - $w);
  13645. $y1 = $y;
  13646. $x2 = ($x - $dw);
  13647. $y2 = $y;
  13648. break;
  13649. }
  13650. case 'R':
  13651. case 'RIGHT': {
  13652. $x1 = ($x + $dw);
  13653. $y1 = $y;
  13654. $x2 = ($x + $w);
  13655. $y2 = $y;
  13656. break;
  13657. }
  13658. }
  13659. $this->Line($x1, $y1, $x2, $y2);
  13660. }
  13661. }
  13662. /**
  13663. * Paints a registration mark
  13664. * @param $x (float) abscissa of the registration mark center.
  13665. * @param $y (float) ordinate of the registration mark center.
  13666. * @param $r (float) radius of the crop mark.
  13667. * @param $double (boolean) if true print two concentric crop marks.
  13668. * @param $cola (array) crop mark color (default spot registration color 'All').
  13669. * @param $colb (array) second crop mark color (default spot registration color 'None').
  13670. * @author Nicola Asuni
  13671. * @since 4.9.000 (2010-03-26)
  13672. * @public
  13673. */
  13674. public function registrationMark($x, $y, $r, $double=false, $cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) {
  13675. $line_style = array('width' => max((0.5 / $this->k),($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  13676. $this->SetFillColorArray($cola);
  13677. $this->PieSector($x, $y, $r, 90, 180, 'F');
  13678. $this->PieSector($x, $y, $r, 270, 360, 'F');
  13679. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13680. if ($double) {
  13681. $ri = $r * 0.5;
  13682. $this->SetFillColorArray($colb);
  13683. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13684. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13685. $this->SetFillColorArray($cola);
  13686. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13687. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13688. $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8);
  13689. }
  13690. }
  13691. /**
  13692. * Paints a CMYK registration mark
  13693. * @param $x (float) abscissa of the registration mark center.
  13694. * @param $y (float) ordinate of the registration mark center.
  13695. * @param $r (float) radius of the crop mark.
  13696. * @author Nicola Asuni
  13697. * @since 6.0.038 (2013-09-30)
  13698. * @public
  13699. */
  13700. public function registrationMarkCMYK($x, $y, $r) {
  13701. // line width
  13702. $lw = max((0.5 / $this->k),($r / 8));
  13703. // internal radius
  13704. $ri = ($r * 0.6);
  13705. // external radius
  13706. $re = ($r * 1.3);
  13707. // Cyan
  13708. $this->SetFillColorArray(array(100,0,0,0));
  13709. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13710. // Magenta
  13711. $this->SetFillColorArray(array(0,100,0,0));
  13712. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13713. // Yellow
  13714. $this->SetFillColorArray(array(0,0,100,0));
  13715. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13716. // Key - black
  13717. $this->SetFillColorArray(array(0,0,0,100));
  13718. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13719. // registration color
  13720. $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All'));
  13721. $this->SetFillColorArray(array(100,100,100,100,'All'));
  13722. // external circle
  13723. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13724. // cross lines
  13725. $this->Line($x, ($y - $re), $x, ($y - $ri));
  13726. $this->Line($x, ($y + $ri), $x, ($y + $re));
  13727. $this->Line(($x - $re), $y, ($x - $ri), $y);
  13728. $this->Line(($x + $ri), $y, ($x + $re), $y);
  13729. }
  13730. /**
  13731. * Paints a linear colour gradient.
  13732. * @param $x (float) abscissa of the top left corner of the rectangle.
  13733. * @param $y (float) ordinate of the top left corner of the rectangle.
  13734. * @param $w (float) width of the rectangle.
  13735. * @param $h (float) height of the rectangle.
  13736. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  13737. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  13738. * @param $coords (array) array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg). The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  13739. * @author Andreas W\FCrmser, Nicola Asuni
  13740. * @since 3.1.000 (2008-06-09)
  13741. * @public
  13742. */
  13743. public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  13744. $this->Clip($x, $y, $w, $h);
  13745. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13746. }
  13747. /**
  13748. * Paints a radial colour gradient.
  13749. * @param $x (float) abscissa of the top left corner of the rectangle.
  13750. * @param $y (float) ordinate of the top left corner of the rectangle.
  13751. * @param $w (float) width of the rectangle.
  13752. * @param $h (float) height of the rectangle.
  13753. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  13754. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  13755. * @param $coords (array) array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1, (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg). (fx, fy) should be inside the circle, otherwise some areas will not be defined.
  13756. * @author Andreas W\FCrmser, Nicola Asuni
  13757. * @since 3.1.000 (2008-06-09)
  13758. * @public
  13759. */
  13760. public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  13761. $this->Clip($x, $y, $w, $h);
  13762. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13763. }
  13764. /**
  13765. * Paints a coons patch mesh.
  13766. * @param $x (float) abscissa of the top left corner of the rectangle.
  13767. * @param $y (float) ordinate of the top left corner of the rectangle.
  13768. * @param $w (float) width of the rectangle.
  13769. * @param $h (float) height of the rectangle.
  13770. * @param $col1 (array) first color (lower left corner) (RGB components).
  13771. * @param $col2 (array) second color (lower right corner) (RGB components).
  13772. * @param $col3 (array) third color (upper right corner) (RGB components).
  13773. * @param $col4 (array) fourth color (upper left corner) (RGB components).
  13774. * @param $coords (array) <ul><li>for one patch mesh: array(float x1, float y1, .... float x12, float y12): 12 pairs of coordinates (normally from 0 to 1) which specify the Bezier control points that define the patch. First pair is the lower left edge point, next is its right control point (control point 2). Then the other points are defined in the order: control point 1, edge point, control point 2 going counter-clockwise around the patch. Last (x12, y12) is the first edge point's left control point (control point 1).</li><li>for two or more patch meshes: array[number of patches]: arrays with the following keys for each patch: f: where to put that patch (0 = first patch, 1, 2, 3 = right, top and left of precedent patch - I didn't figure this out completely - just try and error ;-) points: 12 pairs of coordinates of the Bezier control points as above for the first patch, 8 pairs of coordinates for the following patches, ignoring the coordinates already defined by the precedent patch (I also didn't figure out the order of these - also: try and see what's happening) colors: must be 4 colors for the first patch, 2 colors for the following patches</li></ul>
  13775. * @param $coords_min (array) minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0
  13776. * @param $coords_max (array) maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1
  13777. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13778. * @author Andreas W\FCrmser, Nicola Asuni
  13779. * @since 3.1.000 (2008-06-09)
  13780. * @public
  13781. */
  13782. 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) {
  13783. if ($this->pdfa_mode OR ($this->state != 2)) {
  13784. return;
  13785. }
  13786. $this->Clip($x, $y, $w, $h);
  13787. $n = count($this->gradients) + 1;
  13788. $this->gradients[$n] = array();
  13789. $this->gradients[$n]['type'] = 6; //coons patch mesh
  13790. $this->gradients[$n]['coords'] = array();
  13791. $this->gradients[$n]['antialias'] = $antialias;
  13792. $this->gradients[$n]['colors'] = array();
  13793. $this->gradients[$n]['transparency'] = false;
  13794. //check the coords array if it is the simple array or the multi patch array
  13795. if (!isset($coords[0]['f'])) {
  13796. //simple array -> convert to multi patch array
  13797. if (!isset($col1[1])) {
  13798. $col1[1] = $col1[2] = $col1[0];
  13799. }
  13800. if (!isset($col2[1])) {
  13801. $col2[1] = $col2[2] = $col2[0];
  13802. }
  13803. if (!isset($col3[1])) {
  13804. $col3[1] = $col3[2] = $col3[0];
  13805. }
  13806. if (!isset($col4[1])) {
  13807. $col4[1] = $col4[2] = $col4[0];
  13808. }
  13809. $patch_array[0]['f'] = 0;
  13810. $patch_array[0]['points'] = $coords;
  13811. $patch_array[0]['colors'][0]['r'] = $col1[0];
  13812. $patch_array[0]['colors'][0]['g'] = $col1[1];
  13813. $patch_array[0]['colors'][0]['b'] = $col1[2];
  13814. $patch_array[0]['colors'][1]['r'] = $col2[0];
  13815. $patch_array[0]['colors'][1]['g'] = $col2[1];
  13816. $patch_array[0]['colors'][1]['b'] = $col2[2];
  13817. $patch_array[0]['colors'][2]['r'] = $col3[0];
  13818. $patch_array[0]['colors'][2]['g'] = $col3[1];
  13819. $patch_array[0]['colors'][2]['b'] = $col3[2];
  13820. $patch_array[0]['colors'][3]['r'] = $col4[0];
  13821. $patch_array[0]['colors'][3]['g'] = $col4[1];
  13822. $patch_array[0]['colors'][3]['b'] = $col4[2];
  13823. } else {
  13824. //multi patch array
  13825. $patch_array = $coords;
  13826. }
  13827. $bpcd = 65535; //16 bits per coordinate
  13828. //build the data stream
  13829. $this->gradients[$n]['stream'] = '';
  13830. $count_patch = count($patch_array);
  13831. for ($i=0; $i < $count_patch; ++$i) {
  13832. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  13833. $count_points = count($patch_array[$i]['points']);
  13834. for ($j=0; $j < $count_points; ++$j) {
  13835. //each point as 16 bit
  13836. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  13837. if ($patch_array[$i]['points'][$j] < 0) {
  13838. $patch_array[$i]['points'][$j] = 0;
  13839. }
  13840. if ($patch_array[$i]['points'][$j] > $bpcd) {
  13841. $patch_array[$i]['points'][$j] = $bpcd;
  13842. }
  13843. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
  13844. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
  13845. }
  13846. $count_cols = count($patch_array[$i]['colors']);
  13847. for ($j=0; $j < $count_cols; ++$j) {
  13848. //each color component as 8 bit
  13849. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  13850. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  13851. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  13852. }
  13853. }
  13854. //paint the gradient
  13855. $this->_out('/Sh'.$n.' sh');
  13856. //restore previous Graphic State
  13857. $this->_outRestoreGraphicsState();
  13858. if ($this->inxobj) {
  13859. // we are inside an XObject template
  13860. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13861. }
  13862. }
  13863. /**
  13864. * Set a rectangular clipping area.
  13865. * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  13866. * @param $y (float) ordinate of the top left corner of the rectangle.
  13867. * @param $w (float) width of the rectangle.
  13868. * @param $h (float) height of the rectangle.
  13869. * @author Andreas W\FCrmser, Nicola Asuni
  13870. * @since 3.1.000 (2008-06-09)
  13871. * @protected
  13872. */
  13873. protected function Clip($x, $y, $w, $h) {
  13874. if ($this->state != 2) {
  13875. return;
  13876. }
  13877. if ($this->rtl) {
  13878. $x = $this->w - $x - $w;
  13879. }
  13880. //save current Graphic State
  13881. $s = 'q';
  13882. //set clipping area
  13883. $s .= sprintf(' %F %F %F %F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  13884. //set up transformation matrix for gradient
  13885. $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  13886. $this->_out($s);
  13887. }
  13888. /**
  13889. * Output gradient.
  13890. * @param $type (int) type of gradient (1 Function-based shading; 2 Axial shading; 3 Radial shading; 4 Free-form Gouraud-shaded triangle mesh; 5 Lattice-form Gouraud-shaded triangle mesh; 6 Coons patch mesh; 7 Tensor-product patch mesh). (Not all types are currently supported)
  13891. * @param $coords (array) array of coordinates.
  13892. * @param $stops (array) array gradient color components: color = array of GRAY, RGB or CMYK color components; offset = (0 to 1) represents a location along the gradient vector; exponent = exponent of the exponential interpolation function (default = 1).
  13893. * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value.
  13894. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13895. * @author Nicola Asuni
  13896. * @since 3.1.000 (2008-06-09)
  13897. * @public
  13898. */
  13899. public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
  13900. if ($this->pdfa_mode OR ($this->state != 2)) {
  13901. return;
  13902. }
  13903. $n = count($this->gradients) + 1;
  13904. $this->gradients[$n] = array();
  13905. $this->gradients[$n]['type'] = $type;
  13906. $this->gradients[$n]['coords'] = $coords;
  13907. $this->gradients[$n]['antialias'] = $antialias;
  13908. $this->gradients[$n]['colors'] = array();
  13909. $this->gradients[$n]['transparency'] = false;
  13910. // color space
  13911. $numcolspace = count($stops[0]['color']);
  13912. $bcolor = array_values($background);
  13913. switch($numcolspace) {
  13914. case 5: // SPOT
  13915. case 4: { // CMYK
  13916. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  13917. if (!empty($background)) {
  13918. $this->gradients[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
  13919. }
  13920. break;
  13921. }
  13922. case 3: { // RGB
  13923. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  13924. if (!empty($background)) {
  13925. $this->gradients[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
  13926. }
  13927. break;
  13928. }
  13929. case 1: { // GRAY SCALE
  13930. $this->gradients[$n]['colspace'] = 'DeviceGray';
  13931. if (!empty($background)) {
  13932. $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255);
  13933. }
  13934. break;
  13935. }
  13936. }
  13937. $num_stops = count($stops);
  13938. $last_stop_id = $num_stops - 1;
  13939. foreach ($stops as $key => $stop) {
  13940. $this->gradients[$n]['colors'][$key] = array();
  13941. // offset represents a location along the gradient vector
  13942. if (isset($stop['offset'])) {
  13943. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  13944. } else {
  13945. if ($key == 0) {
  13946. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  13947. } elseif ($key == $last_stop_id) {
  13948. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  13949. } else {
  13950. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  13951. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  13952. }
  13953. }
  13954. if (isset($stop['opacity'])) {
  13955. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  13956. if ((!$this->pdfa_mode) AND ($stop['opacity'] < 1)) {
  13957. $this->gradients[$n]['transparency'] = true;
  13958. }
  13959. } else {
  13960. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  13961. }
  13962. // exponent for the exponential interpolation function
  13963. if (isset($stop['exponent'])) {
  13964. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  13965. } else {
  13966. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  13967. }
  13968. // set colors
  13969. $color = array_values($stop['color']);
  13970. switch($numcolspace) {
  13971. case 5: // SPOT
  13972. case 4: { // CMYK
  13973. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
  13974. break;
  13975. }
  13976. case 3: { // RGB
  13977. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
  13978. break;
  13979. }
  13980. case 1: { // GRAY SCALE
  13981. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
  13982. break;
  13983. }
  13984. }
  13985. }
  13986. if ($this->gradients[$n]['transparency']) {
  13987. // paint luminosity gradient
  13988. $this->_out('/TGS'.$n.' gs');
  13989. }
  13990. //paint the gradient
  13991. $this->_out('/Sh'.$n.' sh');
  13992. //restore previous Graphic State
  13993. $this->_outRestoreGraphicsState();
  13994. if ($this->inxobj) {
  13995. // we are inside an XObject template
  13996. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13997. }
  13998. }
  13999. /**
  14000. * Output gradient shaders.
  14001. * @author Nicola Asuni
  14002. * @since 3.1.000 (2008-06-09)
  14003. * @protected
  14004. */
  14005. function _putshaders() {
  14006. if ($this->pdfa_mode) {
  14007. return;
  14008. }
  14009. $idt = count($this->gradients); //index for transparency gradients
  14010. foreach ($this->gradients as $id => $grad) {
  14011. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  14012. $fc = $this->_newobj();
  14013. $out = '<<';
  14014. $out .= ' /FunctionType 3';
  14015. $out .= ' /Domain [0 1]';
  14016. $functions = '';
  14017. $bounds = '';
  14018. $encode = '';
  14019. $i = 1;
  14020. $num_cols = count($grad['colors']);
  14021. $lastcols = $num_cols - 1;
  14022. for ($i = 1; $i < $num_cols; ++$i) {
  14023. $functions .= ($fc + $i).' 0 R ';
  14024. if ($i < $lastcols) {
  14025. $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
  14026. }
  14027. $encode .= '0 1 ';
  14028. }
  14029. $out .= ' /Functions ['.trim($functions).']';
  14030. $out .= ' /Bounds ['.trim($bounds).']';
  14031. $out .= ' /Encode ['.trim($encode).']';
  14032. $out .= ' >>';
  14033. $out .= "\n".'endobj';
  14034. $this->_out($out);
  14035. for ($i = 1; $i < $num_cols; ++$i) {
  14036. $this->_newobj();
  14037. $out = '<<';
  14038. $out .= ' /FunctionType 2';
  14039. $out .= ' /Domain [0 1]';
  14040. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
  14041. $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  14042. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14043. $out .= ' >>';
  14044. $out .= "\n".'endobj';
  14045. $this->_out($out);
  14046. }
  14047. // set transparency functions
  14048. if ($grad['transparency']) {
  14049. $ft = $this->_newobj();
  14050. $out = '<<';
  14051. $out .= ' /FunctionType 3';
  14052. $out .= ' /Domain [0 1]';
  14053. $functions = '';
  14054. $i = 1;
  14055. $num_cols = count($grad['colors']);
  14056. for ($i = 1; $i < $num_cols; ++$i) {
  14057. $functions .= ($ft + $i).' 0 R ';
  14058. }
  14059. $out .= ' /Functions ['.trim($functions).']';
  14060. $out .= ' /Bounds ['.trim($bounds).']';
  14061. $out .= ' /Encode ['.trim($encode).']';
  14062. $out .= ' >>';
  14063. $out .= "\n".'endobj';
  14064. $this->_out($out);
  14065. for ($i = 1; $i < $num_cols; ++$i) {
  14066. $this->_newobj();
  14067. $out = '<<';
  14068. $out .= ' /FunctionType 2';
  14069. $out .= ' /Domain [0 1]';
  14070. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
  14071. $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  14072. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14073. $out .= ' >>';
  14074. $out .= "\n".'endobj';
  14075. $this->_out($out);
  14076. }
  14077. }
  14078. }
  14079. // set shading object
  14080. $this->_newobj();
  14081. $out = '<< /ShadingType '.$grad['type'];
  14082. if (isset($grad['colspace'])) {
  14083. $out .= ' /ColorSpace /'.$grad['colspace'];
  14084. } else {
  14085. $out .= ' /ColorSpace /DeviceRGB';
  14086. }
  14087. if (isset($grad['background']) AND !empty($grad['background'])) {
  14088. $out .= ' /Background ['.$grad['background'].']';
  14089. }
  14090. if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  14091. $out .= ' /AntiAlias true';
  14092. }
  14093. if ($grad['type'] == 2) {
  14094. $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  14095. $out .= ' /Domain [0 1]';
  14096. $out .= ' /Function '.$fc.' 0 R';
  14097. $out .= ' /Extend [true true]';
  14098. $out .= ' >>';
  14099. } elseif ($grad['type'] == 3) {
  14100. //x0, y0, r0, x1, y1, r1
  14101. //at this this time radius of inner circle is 0
  14102. $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  14103. $out .= ' /Domain [0 1]';
  14104. $out .= ' /Function '.$fc.' 0 R';
  14105. $out .= ' /Extend [true true]';
  14106. $out .= ' >>';
  14107. } elseif ($grad['type'] == 6) {
  14108. $out .= ' /BitsPerCoordinate 16';
  14109. $out .= ' /BitsPerComponent 8';
  14110. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  14111. $out .= ' /BitsPerFlag 8';
  14112. $stream = $this->_getrawstream($grad['stream']);
  14113. $out .= ' /Length '.strlen($stream);
  14114. $out .= ' >>';
  14115. $out .= ' stream'."\n".$stream."\n".'endstream';
  14116. }
  14117. $out .= "\n".'endobj';
  14118. $this->_out($out);
  14119. if ($grad['transparency']) {
  14120. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  14121. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
  14122. }
  14123. $this->gradients[$id]['id'] = $this->n;
  14124. // set pattern object
  14125. $this->_newobj();
  14126. $out = '<< /Type /Pattern /PatternType 2';
  14127. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  14128. $out .= ' >>';
  14129. $out .= "\n".'endobj';
  14130. $this->_out($out);
  14131. $this->gradients[$id]['pattern'] = $this->n;
  14132. // set shading and pattern for transparency mask
  14133. if ($grad['transparency']) {
  14134. // luminosity pattern
  14135. $idgs = $id + $idt;
  14136. $this->_newobj();
  14137. $this->_out($shading_transparency);
  14138. $this->gradients[$idgs]['id'] = $this->n;
  14139. $this->_newobj();
  14140. $out = '<< /Type /Pattern /PatternType 2';
  14141. $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  14142. $out .= ' >>';
  14143. $out .= "\n".'endobj';
  14144. $this->_out($out);
  14145. $this->gradients[$idgs]['pattern'] = $this->n;
  14146. // luminosity XObject
  14147. $oid = $this->_newobj();
  14148. $this->xobjects['LX'.$oid] = array('n' => $oid);
  14149. $filter = '';
  14150. $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  14151. if ($this->compress) {
  14152. $filter = ' /Filter /FlateDecode';
  14153. $stream = gzcompress($stream);
  14154. }
  14155. $stream = $this->_getrawstream($stream);
  14156. $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  14157. $out .= ' /Length '.strlen($stream);
  14158. $rect = sprintf('%F %F', $this->wPt, $this->hPt);
  14159. $out .= ' /BBox [0 0 '.$rect.']';
  14160. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  14161. $out .= ' /Resources <<';
  14162. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  14163. $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  14164. $out .= ' >>';
  14165. $out .= ' >> ';
  14166. $out .= ' stream'."\n".$stream."\n".'endstream';
  14167. $out .= "\n".'endobj';
  14168. $this->_out($out);
  14169. // SMask
  14170. $this->_newobj();
  14171. $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
  14172. $this->_out($out);
  14173. // ExtGState
  14174. $this->_newobj();
  14175. $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
  14176. $this->_out($out);
  14177. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
  14178. }
  14179. }
  14180. }
  14181. /**
  14182. * Draw the sector of a circle.
  14183. * It can be used for instance to render pie charts.
  14184. * @param $xc (float) abscissa of the center.
  14185. * @param $yc (float) ordinate of the center.
  14186. * @param $r (float) radius.
  14187. * @param $a (float) start angle (in degrees).
  14188. * @param $b (float) end angle (in degrees).
  14189. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14190. * @param $cw: (float) indicates whether to go clockwise (default: true).
  14191. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90.
  14192. * @author Maxime Delorme, Nicola Asuni
  14193. * @since 3.1.000 (2008-06-09)
  14194. * @public
  14195. */
  14196. public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
  14197. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  14198. }
  14199. /**
  14200. * Draw the sector of an ellipse.
  14201. * It can be used for instance to render pie charts.
  14202. * @param $xc (float) abscissa of the center.
  14203. * @param $yc (float) ordinate of the center.
  14204. * @param $rx (float) the x-axis radius.
  14205. * @param $ry (float) the y-axis radius.
  14206. * @param $a (float) start angle (in degrees).
  14207. * @param $b (float) end angle (in degrees).
  14208. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14209. * @param $cw: (float) indicates whether to go clockwise.
  14210. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  14211. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc.
  14212. * @author Maxime Delorme, Nicola Asuni
  14213. * @since 3.1.000 (2008-06-09)
  14214. * @public
  14215. */
  14216. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
  14217. if ($this->state != 2) {
  14218. return;
  14219. }
  14220. if ($this->rtl) {
  14221. $xc = ($this->w - $xc);
  14222. }
  14223. $op = TCPDF_STATIC::getPathPaintOperator($style);
  14224. if ($op == 'f') {
  14225. $line_style = array();
  14226. }
  14227. if ($cw) {
  14228. $d = $b;
  14229. $b = (360 - $a + $o);
  14230. $a = (360 - $d + $o);
  14231. } else {
  14232. $b += $o;
  14233. $a += $o;
  14234. }
  14235. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  14236. $this->_out($op);
  14237. }
  14238. /**
  14239. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  14240. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  14241. * Only vector drawing is supported, not text or bitmap.
  14242. * Although the script was successfully tested with various AI format versions, best results are probably achieved with files that were exported in the AI3 format (tested with Illustrator CS2, Freehand MX and Photoshop CS2).
  14243. * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  14244. * @param $x (float) Abscissa of the upper-left corner.
  14245. * @param $y (float) Ordinate of the upper-left corner.
  14246. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14247. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14248. * @param $link (mixed) URL or identifier returned by AddLink().
  14249. * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  14250. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  14251. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  14252. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  14253. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  14254. * @param $fixoutvals (boolean) if true remove values outside the bounding box.
  14255. * @author Valentin Schmidt, Nicola Asuni
  14256. * @since 3.1.000 (2008-06-09)
  14257. * @public
  14258. */
  14259. public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
  14260. if ($this->state != 2) {
  14261. return;
  14262. }
  14263. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  14264. // convert EPS to raster image using GD or ImageMagick libraries
  14265. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14266. }
  14267. if ($x === '') {
  14268. $x = $this->x;
  14269. }
  14270. if ($y === '') {
  14271. $y = $this->y;
  14272. }
  14273. // check page for no-write regions and adapt page margins if necessary
  14274. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14275. $k = $this->k;
  14276. if ($file[0] === '@') { // image from string
  14277. $data = substr($file, 1);
  14278. } else { // EPS/AI file
  14279. $data = TCPDF_STATIC::fileGetContents($file);
  14280. }
  14281. if ($data === FALSE) {
  14282. $this->Error('EPS file not found: '.$file);
  14283. }
  14284. $regs = array();
  14285. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  14286. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  14287. if (count($regs) > 1) {
  14288. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  14289. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  14290. $versexp = explode(' ', $version_str);
  14291. $version = (float)array_pop($versexp);
  14292. if ($version >= 9) {
  14293. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  14294. }
  14295. }
  14296. }
  14297. // strip binary bytes in front of PS-header
  14298. $start = strpos($data, '%!PS-Adobe');
  14299. if ($start > 0) {
  14300. $data = substr($data, $start);
  14301. }
  14302. // find BoundingBox params
  14303. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  14304. if (count($regs) > 1) {
  14305. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  14306. } else {
  14307. $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  14308. }
  14309. $start = strpos($data, '%%EndSetup');
  14310. if ($start === false) {
  14311. $start = strpos($data, '%%EndProlog');
  14312. }
  14313. if ($start === false) {
  14314. $start = strpos($data, '%%BoundingBox');
  14315. }
  14316. $data = substr($data, $start);
  14317. $end = strpos($data, '%%PageTrailer');
  14318. if ($end===false) {
  14319. $end = strpos($data, 'showpage');
  14320. }
  14321. if ($end) {
  14322. $data = substr($data, 0, $end);
  14323. }
  14324. // calculate image width and height on document
  14325. if (($w <= 0) AND ($h <= 0)) {
  14326. $w = ($x2 - $x1) / $k;
  14327. $h = ($y2 - $y1) / $k;
  14328. } elseif ($w <= 0) {
  14329. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  14330. } elseif ($h <= 0) {
  14331. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  14332. }
  14333. // fit the image on available space
  14334. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  14335. if ($this->rasterize_vector_images) {
  14336. // convert EPS to raster image using GD or ImageMagick libraries
  14337. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14338. }
  14339. // set scaling factors
  14340. $scale_x = $w / (($x2 - $x1) / $k);
  14341. $scale_y = $h / (($y2 - $y1) / $k);
  14342. // set alignment
  14343. $this->img_rb_y = $y + $h;
  14344. // set alignment
  14345. if ($this->rtl) {
  14346. if ($palign == 'L') {
  14347. $ximg = $this->lMargin;
  14348. } elseif ($palign == 'C') {
  14349. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14350. } elseif ($palign == 'R') {
  14351. $ximg = $this->w - $this->rMargin - $w;
  14352. } else {
  14353. $ximg = $x - $w;
  14354. }
  14355. $this->img_rb_x = $ximg;
  14356. } else {
  14357. if ($palign == 'L') {
  14358. $ximg = $this->lMargin;
  14359. } elseif ($palign == 'C') {
  14360. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14361. } elseif ($palign == 'R') {
  14362. $ximg = $this->w - $this->rMargin - $w;
  14363. } else {
  14364. $ximg = $x;
  14365. }
  14366. $this->img_rb_x = $ximg + $w;
  14367. }
  14368. if ($useBoundingBox) {
  14369. $dx = $ximg * $k - $x1;
  14370. $dy = $y * $k - $y1;
  14371. } else {
  14372. $dx = $ximg * $k;
  14373. $dy = $y * $k;
  14374. }
  14375. // save the current graphic state
  14376. $this->_out('q'.$this->epsmarker);
  14377. // translate
  14378. $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  14379. // scale
  14380. if (isset($scale_x)) {
  14381. $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  14382. }
  14383. // handle pc/unix/mac line endings
  14384. $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
  14385. $u=0;
  14386. $cnt = count($lines);
  14387. for ($i=0; $i < $cnt; ++$i) {
  14388. $line = $lines[$i];
  14389. if (($line == '') OR ($line[0] == '%')) {
  14390. continue;
  14391. }
  14392. $len = strlen($line);
  14393. // check for spot color names
  14394. $color_name = '';
  14395. if (strcasecmp('x', substr(trim($line), -1)) == 0) {
  14396. if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
  14397. // extract spot color name
  14398. $color_name = $matches[0];
  14399. // remove color name from string
  14400. $line = str_replace(' '.$color_name, '', $line);
  14401. // remove pharentesis from color name
  14402. $color_name = substr($color_name, 1, -1);
  14403. }
  14404. }
  14405. $chunks = explode(' ', $line);
  14406. $cmd = trim(array_pop($chunks));
  14407. // RGB
  14408. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  14409. $b = array_pop($chunks);
  14410. $g = array_pop($chunks);
  14411. $r = array_pop($chunks);
  14412. $this->_out(''.$r.' '.$g.' '.$b.' '.($cmd=='Xa'?'rg':'RG')); //substr($line, 0, -2).'rg' -> in EPS (AI8): c m y k r g b rg!
  14413. continue;
  14414. }
  14415. $skip = false;
  14416. if ($fixoutvals) {
  14417. // check for values outside the bounding box
  14418. switch ($cmd) {
  14419. case 'm':
  14420. case 'l':
  14421. case 'L': {
  14422. // skip values outside bounding box
  14423. foreach ($chunks as $key => $val) {
  14424. if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
  14425. $skip = true;
  14426. } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
  14427. $skip = true;
  14428. }
  14429. }
  14430. }
  14431. }
  14432. }
  14433. switch ($cmd) {
  14434. case 'm':
  14435. case 'l':
  14436. case 'v':
  14437. case 'y':
  14438. case 'c':
  14439. case 'k':
  14440. case 'K':
  14441. case 'g':
  14442. case 'G':
  14443. case 's':
  14444. case 'S':
  14445. case 'J':
  14446. case 'j':
  14447. case 'w':
  14448. case 'M':
  14449. case 'd':
  14450. case 'n': {
  14451. if ($skip) {
  14452. break;
  14453. }
  14454. $this->_out($line);
  14455. break;
  14456. }
  14457. case 'x': {// custom fill color
  14458. if (empty($color_name)) {
  14459. // CMYK color
  14460. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14461. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  14462. } else {
  14463. // Spot Color (CMYK + tint)
  14464. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14465. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14466. $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14467. $this->_out($color_cmd);
  14468. }
  14469. break;
  14470. }
  14471. case 'X': { // custom stroke color
  14472. if (empty($color_name)) {
  14473. // CMYK color
  14474. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14475. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  14476. } else {
  14477. // Spot Color (CMYK + tint)
  14478. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14479. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14480. $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14481. $this->_out($color_cmd);
  14482. }
  14483. break;
  14484. }
  14485. case 'Y':
  14486. case 'N':
  14487. case 'V':
  14488. case 'L':
  14489. case 'C': {
  14490. if ($skip) {
  14491. break;
  14492. }
  14493. $line[($len - 1)] = strtolower($cmd);
  14494. $this->_out($line);
  14495. break;
  14496. }
  14497. case 'b':
  14498. case 'B': {
  14499. $this->_out($cmd . '*');
  14500. break;
  14501. }
  14502. case 'f':
  14503. case 'F': {
  14504. if ($u > 0) {
  14505. $isU = false;
  14506. $max = min(($i + 5), $cnt);
  14507. for ($j = ($i + 1); $j < $max; ++$j) {
  14508. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  14509. }
  14510. if ($isU) {
  14511. $this->_out('f*');
  14512. }
  14513. } else {
  14514. $this->_out('f*');
  14515. }
  14516. break;
  14517. }
  14518. case '*u': {
  14519. ++$u;
  14520. break;
  14521. }
  14522. case '*U': {
  14523. --$u;
  14524. break;
  14525. }
  14526. }
  14527. }
  14528. // restore previous graphic state
  14529. $this->_out($this->epsmarker.'Q');
  14530. if (!empty($border)) {
  14531. $bx = $this->x;
  14532. $by = $this->y;
  14533. $this->x = $ximg;
  14534. if ($this->rtl) {
  14535. $this->x += $w;
  14536. }
  14537. $this->y = $y;
  14538. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  14539. $this->x = $bx;
  14540. $this->y = $by;
  14541. }
  14542. if ($link) {
  14543. $this->Link($ximg, $y, $w, $h, $link, 0);
  14544. }
  14545. // set pointer to align the next text/objects
  14546. switch($align) {
  14547. case 'T':{
  14548. $this->y = $y;
  14549. $this->x = $this->img_rb_x;
  14550. break;
  14551. }
  14552. case 'M':{
  14553. $this->y = $y + round($h/2);
  14554. $this->x = $this->img_rb_x;
  14555. break;
  14556. }
  14557. case 'B':{
  14558. $this->y = $this->img_rb_y;
  14559. $this->x = $this->img_rb_x;
  14560. break;
  14561. }
  14562. case 'N':{
  14563. $this->SetY($this->img_rb_y);
  14564. break;
  14565. }
  14566. default:{
  14567. break;
  14568. }
  14569. }
  14570. $this->endlinex = $this->img_rb_x;
  14571. }
  14572. /**
  14573. * Set document barcode.
  14574. * @param $bc (string) barcode
  14575. * @public
  14576. */
  14577. public function setBarcode($bc='') {
  14578. $this->barcode = $bc;
  14579. }
  14580. /**
  14581. * Get current barcode.
  14582. * @return string
  14583. * @public
  14584. * @since 4.0.012 (2008-07-24)
  14585. */
  14586. public function getBarcode() {
  14587. return $this->barcode;
  14588. }
  14589. /**
  14590. * Print a Linear Barcode.
  14591. * @param $code (string) code to print
  14592. * @param $type (string) type of barcode (see tcpdf_barcodes_1d.php for supported formats).
  14593. * @param $x (int) x position in user units (empty string = current x position)
  14594. * @param $y (int) y position in user units (empty string = current y position)
  14595. * @param $w (int) width in user units (empty string = remaining page width)
  14596. * @param $h (int) height in user units (empty string = remaining page height)
  14597. * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)
  14598. * @param $style (array) array of options:<ul>
  14599. * <li>boolean $style['border'] if true prints a border</li>
  14600. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  14601. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  14602. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  14603. * <li>array $style['fgcolor'] color array for bars and text</li>
  14604. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  14605. * <li>boolean $style['text'] if true prints text below the barcode</li>
  14606. * <li>string $style['label'] override default label</li>
  14607. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  14608. * <li>int $style['stretchtext']: 0 = disabled; 1 = horizontal scaling only if necessary; 2 = forced horizontal scaling; 3 = character spacing only if necessary; 4 = forced character spacing.</li>
  14609. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  14610. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  14611. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  14612. * <li>string $style['fitwidth'] if true reduce the width to fit the barcode width + padding. When this option is enabled the 'stretch' option is automatically disabled.</li>
  14613. * <li>string $style['cellfitalign'] this option works only when 'fitwidth' is true and 'position' is unset or empty. Set the horizontal position of the containing barcode cell inside the specified rectangle: L = left; C = center; R = right.</li></ul>
  14614. * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  14615. * @author Nicola Asuni
  14616. * @since 3.1.000 (2008-06-09)
  14617. * @public
  14618. */
  14619. public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style=array(), $align='') {
  14620. if (TCPDF_STATIC::empty_string(trim($code))) {
  14621. return;
  14622. }
  14623. require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php');
  14624. // save current graphic settings
  14625. $gvars = $this->getGraphicVars();
  14626. // create new barcode object
  14627. $barcodeobj = new TCPDFBarcode($code, $type);
  14628. $arrcode = $barcodeobj->getBarcodeArray();
  14629. if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
  14630. $this->Error('Error in 1D barcode string');
  14631. }
  14632. if ($arrcode['maxh'] <= 0) {
  14633. $arrcode['maxh'] = 1;
  14634. }
  14635. // set default values
  14636. if (!isset($style['position'])) {
  14637. $style['position'] = '';
  14638. } elseif ($style['position'] == 'S') {
  14639. // keep this for backward compatibility
  14640. $style['position'] = '';
  14641. $style['stretch'] = true;
  14642. }
  14643. if (!isset($style['fitwidth'])) {
  14644. if (!isset($style['stretch'])) {
  14645. $style['fitwidth'] = true;
  14646. } else {
  14647. $style['fitwidth'] = false;
  14648. }
  14649. }
  14650. if ($style['fitwidth']) {
  14651. // disable stretch
  14652. $style['stretch'] = false;
  14653. }
  14654. if (!isset($style['stretch'])) {
  14655. if (($w === '') OR ($w <= 0)) {
  14656. $style['stretch'] = false;
  14657. } else {
  14658. $style['stretch'] = true;
  14659. }
  14660. }
  14661. if (!isset($style['fgcolor'])) {
  14662. $style['fgcolor'] = array(0,0,0); // default black
  14663. }
  14664. if (!isset($style['bgcolor'])) {
  14665. $style['bgcolor'] = false; // default transparent
  14666. }
  14667. if (!isset($style['border'])) {
  14668. $style['border'] = false;
  14669. }
  14670. $fontsize = 0;
  14671. if (!isset($style['text'])) {
  14672. $style['text'] = false;
  14673. }
  14674. if ($style['text'] AND isset($style['font'])) {
  14675. if (isset($style['fontsize'])) {
  14676. $fontsize = $style['fontsize'];
  14677. }
  14678. $this->SetFont($style['font'], '', $fontsize);
  14679. }
  14680. if (!isset($style['stretchtext'])) {
  14681. $style['stretchtext'] = 4;
  14682. }
  14683. if ($x === '') {
  14684. $x = $this->x;
  14685. }
  14686. if ($y === '') {
  14687. $y = $this->y;
  14688. }
  14689. // check page for no-write regions and adapt page margins if necessary
  14690. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14691. if (($w === '') OR ($w <= 0)) {
  14692. if ($this->rtl) {
  14693. $w = $x - $this->lMargin;
  14694. } else {
  14695. $w = $this->w - $this->rMargin - $x;
  14696. }
  14697. }
  14698. // padding
  14699. if (!isset($style['padding'])) {
  14700. $padding = 0;
  14701. } elseif ($style['padding'] === 'auto') {
  14702. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  14703. } else {
  14704. $padding = floatval($style['padding']);
  14705. }
  14706. // horizontal padding
  14707. if (!isset($style['hpadding'])) {
  14708. $hpadding = $padding;
  14709. } elseif ($style['hpadding'] === 'auto') {
  14710. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  14711. } else {
  14712. $hpadding = floatval($style['hpadding']);
  14713. }
  14714. // vertical padding
  14715. if (!isset($style['vpadding'])) {
  14716. $vpadding = $padding;
  14717. } elseif ($style['vpadding'] === 'auto') {
  14718. $vpadding = ($hpadding / 2);
  14719. } else {
  14720. $vpadding = floatval($style['vpadding']);
  14721. }
  14722. // calculate xres (single bar width)
  14723. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  14724. if ($style['stretch']) {
  14725. $xres = $max_xres;
  14726. } else {
  14727. if (TCPDF_STATIC::empty_string($xres)) {
  14728. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  14729. }
  14730. if ($xres > $max_xres) {
  14731. // correct xres to fit on $w
  14732. $xres = $max_xres;
  14733. }
  14734. if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  14735. OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  14736. $hpadding = 10 * $xres;
  14737. if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  14738. $vpadding = ($hpadding / 2);
  14739. }
  14740. }
  14741. }
  14742. if ($style['fitwidth']) {
  14743. $wold = $w;
  14744. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  14745. if (isset($style['cellfitalign'])) {
  14746. switch ($style['cellfitalign']) {
  14747. case 'L': {
  14748. if ($this->rtl) {
  14749. $x -= ($wold - $w);
  14750. }
  14751. break;
  14752. }
  14753. case 'R': {
  14754. if (!$this->rtl) {
  14755. $x += ($wold - $w);
  14756. }
  14757. break;
  14758. }
  14759. case 'C': {
  14760. if ($this->rtl) {
  14761. $x -= (($wold - $w) / 2);
  14762. } else {
  14763. $x += (($wold - $w) / 2);
  14764. }
  14765. break;
  14766. }
  14767. default : {
  14768. break;
  14769. }
  14770. }
  14771. }
  14772. }
  14773. $text_height = $this->getCellHeight($fontsize / $this->k);
  14774. // height
  14775. if (($h === '') OR ($h <= 0)) {
  14776. // set default height
  14777. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  14778. }
  14779. $barh = $h - $text_height - (2 * $vpadding);
  14780. if ($barh <=0) {
  14781. // try to reduce font or padding to fit barcode on available height
  14782. if ($text_height > $h) {
  14783. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  14784. $text_height = $this->getCellHeight($fontsize / $this->k);
  14785. $this->SetFont($style['font'], '', $fontsize);
  14786. }
  14787. if ($vpadding > 0) {
  14788. $vpadding = (($h - $text_height) / 4);
  14789. }
  14790. $barh = $h - $text_height - (2 * $vpadding);
  14791. }
  14792. // fit the barcode on available space
  14793. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  14794. // set alignment
  14795. $this->img_rb_y = $y + $h;
  14796. // set alignment
  14797. if ($this->rtl) {
  14798. if ($style['position'] == 'L') {
  14799. $xpos = $this->lMargin;
  14800. } elseif ($style['position'] == 'C') {
  14801. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14802. } elseif ($style['position'] == 'R') {
  14803. $xpos = $this->w - $this->rMargin - $w;
  14804. } else {
  14805. $xpos = $x - $w;
  14806. }
  14807. $this->img_rb_x = $xpos;
  14808. } else {
  14809. if ($style['position'] == 'L') {
  14810. $xpos = $this->lMargin;
  14811. } elseif ($style['position'] == 'C') {
  14812. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14813. } elseif ($style['position'] == 'R') {
  14814. $xpos = $this->w - $this->rMargin - $w;
  14815. } else {
  14816. $xpos = $x;
  14817. }
  14818. $this->img_rb_x = $xpos + $w;
  14819. }
  14820. $xpos_rect = $xpos;
  14821. if (!isset($style['align'])) {
  14822. $style['align'] = 'C';
  14823. }
  14824. switch ($style['align']) {
  14825. case 'L': {
  14826. $xpos = $xpos_rect + $hpadding;
  14827. break;
  14828. }
  14829. case 'R': {
  14830. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  14831. break;
  14832. }
  14833. case 'C':
  14834. default : {
  14835. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  14836. break;
  14837. }
  14838. }
  14839. $xpos_text = $xpos;
  14840. // barcode is always printed in LTR direction
  14841. $tempRTL = $this->rtl;
  14842. $this->rtl = false;
  14843. // print background color
  14844. if ($style['bgcolor']) {
  14845. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  14846. } elseif ($style['border']) {
  14847. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  14848. }
  14849. // set foreground color
  14850. $this->SetDrawColorArray($style['fgcolor']);
  14851. $this->SetTextColorArray($style['fgcolor']);
  14852. // print bars
  14853. foreach ($arrcode['bcode'] as $k => $v) {
  14854. $bw = ($v['w'] * $xres);
  14855. if ($v['t']) {
  14856. // draw a vertical bar
  14857. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  14858. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  14859. }
  14860. $xpos += $bw;
  14861. }
  14862. // print text
  14863. if ($style['text']) {
  14864. if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) {
  14865. $label = $style['label'];
  14866. } else {
  14867. $label = $code;
  14868. }
  14869. $txtwidth = ($arrcode['maxw'] * $xres);
  14870. if ($this->GetStringWidth($label) > $txtwidth) {
  14871. $style['stretchtext'] = 2;
  14872. }
  14873. // print text
  14874. $this->x = $xpos_text;
  14875. $this->y = $y + $vpadding + $barh;
  14876. $cellpadding = $this->cell_padding;
  14877. $this->SetCellPadding(0);
  14878. $this->Cell($txtwidth, '', $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
  14879. $this->cell_padding = $cellpadding;
  14880. }
  14881. // restore original direction
  14882. $this->rtl = $tempRTL;
  14883. // restore previous settings
  14884. $this->setGraphicVars($gvars);
  14885. // set pointer to align the next text/objects
  14886. switch($align) {
  14887. case 'T':{
  14888. $this->y = $y;
  14889. $this->x = $this->img_rb_x;
  14890. break;
  14891. }
  14892. case 'M':{
  14893. $this->y = $y + round($h / 2);
  14894. $this->x = $this->img_rb_x;
  14895. break;
  14896. }
  14897. case 'B':{
  14898. $this->y = $this->img_rb_y;
  14899. $this->x = $this->img_rb_x;
  14900. break;
  14901. }
  14902. case 'N':{
  14903. $this->SetY($this->img_rb_y);
  14904. break;
  14905. }
  14906. default:{
  14907. break;
  14908. }
  14909. }
  14910. $this->endlinex = $this->img_rb_x;
  14911. }
  14912. /**
  14913. * Print 2D Barcode.
  14914. * @param $code (string) code to print
  14915. * @param $type (string) type of barcode (see tcpdf_barcodes_2d.php for supported formats).
  14916. * @param $x (int) x position in user units
  14917. * @param $y (int) y position in user units
  14918. * @param $w (int) width in user units
  14919. * @param $h (int) height in user units
  14920. * @param $style (array) array of options:<ul>
  14921. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  14922. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  14923. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  14924. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  14925. * <li>int $style['module_width'] width of a single module in points</li>
  14926. * <li>int $style['module_height'] height of a single module in points</li>
  14927. * <li>array $style['fgcolor'] color array for bars and text</li>
  14928. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  14929. * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li><li>$style['module_width'] width of a single module in points</li>
  14930. * <li>$style['module_height'] height of a single module in points</li></ul>
  14931. * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  14932. * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  14933. * @author Nicola Asuni
  14934. * @since 4.5.037 (2009-04-07)
  14935. * @public
  14936. */
  14937. public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style=array(), $align='', $distort=false) {
  14938. if (TCPDF_STATIC::empty_string(trim($code))) {
  14939. return;
  14940. }
  14941. require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php');
  14942. // save current graphic settings
  14943. $gvars = $this->getGraphicVars();
  14944. // create new barcode object
  14945. $barcodeobj = new TCPDF2DBarcode($code, $type);
  14946. $arrcode = $barcodeobj->getBarcodeArray();
  14947. if (($arrcode === false) OR empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
  14948. $this->Error('Error in 2D barcode string');
  14949. }
  14950. // set default values
  14951. if (!isset($style['position'])) {
  14952. $style['position'] = '';
  14953. }
  14954. if (!isset($style['fgcolor'])) {
  14955. $style['fgcolor'] = array(0,0,0); // default black
  14956. }
  14957. if (!isset($style['bgcolor'])) {
  14958. $style['bgcolor'] = false; // default transparent
  14959. }
  14960. if (!isset($style['border'])) {
  14961. $style['border'] = false;
  14962. }
  14963. // padding
  14964. if (!isset($style['padding'])) {
  14965. $style['padding'] = 0;
  14966. } elseif ($style['padding'] === 'auto') {
  14967. $style['padding'] = 4;
  14968. }
  14969. if (!isset($style['hpadding'])) {
  14970. $style['hpadding'] = $style['padding'];
  14971. } elseif ($style['hpadding'] === 'auto') {
  14972. $style['hpadding'] = 4;
  14973. }
  14974. if (!isset($style['vpadding'])) {
  14975. $style['vpadding'] = $style['padding'];
  14976. } elseif ($style['vpadding'] === 'auto') {
  14977. $style['vpadding'] = 4;
  14978. }
  14979. $hpad = (2 * $style['hpadding']);
  14980. $vpad = (2 * $style['vpadding']);
  14981. // cell (module) dimension
  14982. if (!isset($style['module_width'])) {
  14983. $style['module_width'] = 1; // width of a single module in points
  14984. }
  14985. if (!isset($style['module_height'])) {
  14986. $style['module_height'] = 1; // height of a single module in points
  14987. }
  14988. if ($x === '') {
  14989. $x = $this->x;
  14990. }
  14991. if ($y === '') {
  14992. $y = $this->y;
  14993. }
  14994. // check page for no-write regions and adapt page margins if necessary
  14995. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14996. // number of barcode columns and rows
  14997. $rows = $arrcode['num_rows'];
  14998. $cols = $arrcode['num_cols'];
  14999. if (($rows <= 0) || ($cols <= 0)){
  15000. $this->Error('Error in 2D barcode string');
  15001. }
  15002. // module width and height
  15003. $mw = $style['module_width'];
  15004. $mh = $style['module_height'];
  15005. if (($mw <= 0) OR ($mh <= 0)) {
  15006. $this->Error('Error in 2D barcode string');
  15007. }
  15008. // get max dimensions
  15009. if ($this->rtl) {
  15010. $maxw = $x - $this->lMargin;
  15011. } else {
  15012. $maxw = $this->w - $this->rMargin - $x;
  15013. }
  15014. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  15015. $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
  15016. $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
  15017. if (!$distort) {
  15018. if (($maxw * $ratioHW) > $maxh) {
  15019. $maxw = $maxh * $ratioWH;
  15020. }
  15021. if (($maxh * $ratioWH) > $maxw) {
  15022. $maxh = $maxw * $ratioHW;
  15023. }
  15024. }
  15025. // set maximum dimensions
  15026. if ($w > $maxw) {
  15027. $w = $maxw;
  15028. }
  15029. if ($h > $maxh) {
  15030. $h = $maxh;
  15031. }
  15032. // set dimensions
  15033. if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
  15034. $w = ($cols + $hpad) * ($mw / $this->k);
  15035. $h = ($rows + $vpad) * ($mh / $this->k);
  15036. } elseif (($w === '') OR ($w <= 0)) {
  15037. $w = $h * $ratioWH;
  15038. } elseif (($h === '') OR ($h <= 0)) {
  15039. $h = $w * $ratioHW;
  15040. }
  15041. // barcode size (excluding padding)
  15042. $bw = ($w * $cols) / ($cols + $hpad);
  15043. $bh = ($h * $rows) / ($rows + $vpad);
  15044. // dimension of single barcode cell unit
  15045. $cw = $bw / $cols;
  15046. $ch = $bh / $rows;
  15047. if (!$distort) {
  15048. if (($cw / $ch) > ($mw / $mh)) {
  15049. // correct horizontal distortion
  15050. $cw = $ch * $mw / $mh;
  15051. $bw = $cw * $cols;
  15052. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  15053. } else {
  15054. // correct vertical distortion
  15055. $ch = $cw * $mh / $mw;
  15056. $bh = $ch * $rows;
  15057. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  15058. }
  15059. }
  15060. // fit the barcode on available space
  15061. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  15062. // set alignment
  15063. $this->img_rb_y = $y + $h;
  15064. // set alignment
  15065. if ($this->rtl) {
  15066. if ($style['position'] == 'L') {
  15067. $xpos = $this->lMargin;
  15068. } elseif ($style['position'] == 'C') {
  15069. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15070. } elseif ($style['position'] == 'R') {
  15071. $xpos = $this->w - $this->rMargin - $w;
  15072. } else {
  15073. $xpos = $x - $w;
  15074. }
  15075. $this->img_rb_x = $xpos;
  15076. } else {
  15077. if ($style['position'] == 'L') {
  15078. $xpos = $this->lMargin;
  15079. } elseif ($style['position'] == 'C') {
  15080. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15081. } elseif ($style['position'] == 'R') {
  15082. $xpos = $this->w - $this->rMargin - $w;
  15083. } else {
  15084. $xpos = $x;
  15085. }
  15086. $this->img_rb_x = $xpos + $w;
  15087. }
  15088. $xstart = $xpos + ($style['hpadding'] * $cw);
  15089. $ystart = $y + ($style['vpadding'] * $ch);
  15090. // barcode is always printed in LTR direction
  15091. $tempRTL = $this->rtl;
  15092. $this->rtl = false;
  15093. // print background color
  15094. if ($style['bgcolor']) {
  15095. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  15096. } elseif ($style['border']) {
  15097. $this->Rect($xpos, $y, $w, $h, 'D');
  15098. }
  15099. // set foreground color
  15100. $this->SetDrawColorArray($style['fgcolor']);
  15101. // print barcode cells
  15102. // for each row
  15103. for ($r = 0; $r < $rows; ++$r) {
  15104. $xr = $xstart;
  15105. // for each column
  15106. for ($c = 0; $c < $cols; ++$c) {
  15107. if ($arrcode['bcode'][$r][$c] == 1) {
  15108. // draw a single barcode cell
  15109. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  15110. }
  15111. $xr += $cw;
  15112. }
  15113. $ystart += $ch;
  15114. }
  15115. // restore original direction
  15116. $this->rtl = $tempRTL;
  15117. // restore previous settings
  15118. $this->setGraphicVars($gvars);
  15119. // set pointer to align the next text/objects
  15120. switch($align) {
  15121. case 'T':{
  15122. $this->y = $y;
  15123. $this->x = $this->img_rb_x;
  15124. break;
  15125. }
  15126. case 'M':{
  15127. $this->y = $y + round($h/2);
  15128. $this->x = $this->img_rb_x;
  15129. break;
  15130. }
  15131. case 'B':{
  15132. $this->y = $this->img_rb_y;
  15133. $this->x = $this->img_rb_x;
  15134. break;
  15135. }
  15136. case 'N':{
  15137. $this->SetY($this->img_rb_y);
  15138. break;
  15139. }
  15140. default:{
  15141. break;
  15142. }
  15143. }
  15144. $this->endlinex = $this->img_rb_x;
  15145. }
  15146. /**
  15147. * Returns an array containing current margins:
  15148. * <ul>
  15149. <li>$ret['left'] = left margin</li>
  15150. <li>$ret['right'] = right margin</li>
  15151. <li>$ret['top'] = top margin</li>
  15152. <li>$ret['bottom'] = bottom margin</li>
  15153. <li>$ret['header'] = header margin</li>
  15154. <li>$ret['footer'] = footer margin</li>
  15155. <li>$ret['cell'] = cell padding array</li>
  15156. <li>$ret['padding_left'] = cell left padding</li>
  15157. <li>$ret['padding_top'] = cell top padding</li>
  15158. <li>$ret['padding_right'] = cell right padding</li>
  15159. <li>$ret['padding_bottom'] = cell bottom padding</li>
  15160. * </ul>
  15161. * @return array containing all margins measures
  15162. * @public
  15163. * @since 3.2.000 (2008-06-23)
  15164. */
  15165. public function getMargins() {
  15166. $ret = array(
  15167. 'left' => $this->lMargin,
  15168. 'right' => $this->rMargin,
  15169. 'top' => $this->tMargin,
  15170. 'bottom' => $this->bMargin,
  15171. 'header' => $this->header_margin,
  15172. 'footer' => $this->footer_margin,
  15173. 'cell' => $this->cell_padding,
  15174. 'padding_left' => $this->cell_padding['L'],
  15175. 'padding_top' => $this->cell_padding['T'],
  15176. 'padding_right' => $this->cell_padding['R'],
  15177. 'padding_bottom' => $this->cell_padding['B']
  15178. );
  15179. return $ret;
  15180. }
  15181. /**
  15182. * Returns an array containing original margins:
  15183. * <ul>
  15184. <li>$ret['left'] = left margin</li>
  15185. <li>$ret['right'] = right margin</li>
  15186. * </ul>
  15187. * @return array containing all margins measures
  15188. * @public
  15189. * @since 4.0.012 (2008-07-24)
  15190. */
  15191. public function getOriginalMargins() {
  15192. $ret = array(
  15193. 'left' => $this->original_lMargin,
  15194. 'right' => $this->original_rMargin
  15195. );
  15196. return $ret;
  15197. }
  15198. /**
  15199. * Returns the current font size.
  15200. * @return current font size
  15201. * @public
  15202. * @since 3.2.000 (2008-06-23)
  15203. */
  15204. public function getFontSize() {
  15205. return $this->FontSize;
  15206. }
  15207. /**
  15208. * Returns the current font size in points unit.
  15209. * @return current font size in points unit
  15210. * @public
  15211. * @since 3.2.000 (2008-06-23)
  15212. */
  15213. public function getFontSizePt() {
  15214. return $this->FontSizePt;
  15215. }
  15216. /**
  15217. * Returns the current font family name.
  15218. * @return string current font family name
  15219. * @public
  15220. * @since 4.3.008 (2008-12-05)
  15221. */
  15222. public function getFontFamily() {
  15223. return $this->FontFamily;
  15224. }
  15225. /**
  15226. * Returns the current font style.
  15227. * @return string current font style
  15228. * @public
  15229. * @since 4.3.008 (2008-12-05)
  15230. */
  15231. public function getFontStyle() {
  15232. return $this->FontStyle;
  15233. }
  15234. /**
  15235. * Cleanup HTML code (requires HTML Tidy library).
  15236. * @param $html (string) htmlcode to fix
  15237. * @param $default_css (string) CSS commands to add
  15238. * @param $tagvs (array) parameters for setHtmlVSpace method
  15239. * @param $tidy_options (array) options for tidy_parse_string function
  15240. * @return string XHTML code cleaned up
  15241. * @author Nicola Asuni
  15242. * @public
  15243. * @since 5.9.017 (2010-11-16)
  15244. * @see setHtmlVSpace()
  15245. */
  15246. public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') {
  15247. return TCPDF_STATIC::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces);
  15248. }
  15249. /**
  15250. * Returns the border width from CSS property
  15251. * @param $width (string) border width
  15252. * @return int with in user units
  15253. * @protected
  15254. * @since 5.7.000 (2010-08-02)
  15255. */
  15256. protected function getCSSBorderWidth($width) {
  15257. if ($width == 'thin') {
  15258. $width = (2 / $this->k);
  15259. } elseif ($width == 'medium') {
  15260. $width = (4 / $this->k);
  15261. } elseif ($width == 'thick') {
  15262. $width = (6 / $this->k);
  15263. } else {
  15264. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  15265. }
  15266. return $width;
  15267. }
  15268. /**
  15269. * Returns the border dash style from CSS property
  15270. * @param $style (string) border style to convert
  15271. * @return int sash style (return -1 in case of none or hidden border)
  15272. * @protected
  15273. * @since 5.7.000 (2010-08-02)
  15274. */
  15275. protected function getCSSBorderDashStyle($style) {
  15276. switch (strtolower($style)) {
  15277. case 'none':
  15278. case 'hidden': {
  15279. $dash = -1;
  15280. break;
  15281. }
  15282. case 'dotted': {
  15283. $dash = 1;
  15284. break;
  15285. }
  15286. case 'dashed': {
  15287. $dash = 3;
  15288. break;
  15289. }
  15290. case 'double':
  15291. case 'groove':
  15292. case 'ridge':
  15293. case 'inset':
  15294. case 'outset':
  15295. case 'solid':
  15296. default: {
  15297. $dash = 0;
  15298. break;
  15299. }
  15300. }
  15301. return $dash;
  15302. }
  15303. /**
  15304. * Returns the border style array from CSS border properties
  15305. * @param $cssborder (string) border properties
  15306. * @return array containing border properties
  15307. * @protected
  15308. * @since 5.7.000 (2010-08-02)
  15309. */
  15310. protected function getCSSBorderStyle($cssborder) {
  15311. $bprop = preg_split('/[\s]+/', trim($cssborder));
  15312. $border = array(); // value to be returned
  15313. switch (count($bprop)) {
  15314. case 3: {
  15315. $width = $bprop[0];
  15316. $style = $bprop[1];
  15317. $color = $bprop[2];
  15318. break;
  15319. }
  15320. case 2: {
  15321. $width = 'medium';
  15322. $style = $bprop[0];
  15323. $color = $bprop[1];
  15324. break;
  15325. }
  15326. case 1: {
  15327. $width = 'medium';
  15328. $style = $bprop[0];
  15329. $color = 'black';
  15330. break;
  15331. }
  15332. default: {
  15333. $width = 'medium';
  15334. $style = 'solid';
  15335. $color = 'black';
  15336. break;
  15337. }
  15338. }
  15339. if ($style == 'none') {
  15340. return array();
  15341. }
  15342. $border['cap'] = 'square';
  15343. $border['join'] = 'miter';
  15344. $border['dash'] = $this->getCSSBorderDashStyle($style);
  15345. if ($border['dash'] < 0) {
  15346. return array();
  15347. }
  15348. $border['width'] = $this->getCSSBorderWidth($width);
  15349. $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color, $this->spot_colors);
  15350. return $border;
  15351. }
  15352. /**
  15353. * Get the internal Cell padding from CSS attribute.
  15354. * @param $csspadding (string) padding properties
  15355. * @param $width (float) width of the containing element
  15356. * @return array of cell paddings
  15357. * @public
  15358. * @since 5.9.000 (2010-10-04)
  15359. */
  15360. public function getCSSPadding($csspadding, $width=0) {
  15361. $padding = preg_split('/[\s]+/', trim($csspadding));
  15362. $cell_padding = array(); // value to be returned
  15363. switch (count($padding)) {
  15364. case 4: {
  15365. $cell_padding['T'] = $padding[0];
  15366. $cell_padding['R'] = $padding[1];
  15367. $cell_padding['B'] = $padding[2];
  15368. $cell_padding['L'] = $padding[3];
  15369. break;
  15370. }
  15371. case 3: {
  15372. $cell_padding['T'] = $padding[0];
  15373. $cell_padding['R'] = $padding[1];
  15374. $cell_padding['B'] = $padding[2];
  15375. $cell_padding['L'] = $padding[1];
  15376. break;
  15377. }
  15378. case 2: {
  15379. $cell_padding['T'] = $padding[0];
  15380. $cell_padding['R'] = $padding[1];
  15381. $cell_padding['B'] = $padding[0];
  15382. $cell_padding['L'] = $padding[1];
  15383. break;
  15384. }
  15385. case 1: {
  15386. $cell_padding['T'] = $padding[0];
  15387. $cell_padding['R'] = $padding[0];
  15388. $cell_padding['B'] = $padding[0];
  15389. $cell_padding['L'] = $padding[0];
  15390. break;
  15391. }
  15392. default: {
  15393. return $this->cell_padding;
  15394. }
  15395. }
  15396. if ($width == 0) {
  15397. $width = $this->w - $this->lMargin - $this->rMargin;
  15398. }
  15399. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  15400. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  15401. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  15402. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  15403. return $cell_padding;
  15404. }
  15405. /**
  15406. * Get the internal Cell margin from CSS attribute.
  15407. * @param $cssmargin (string) margin properties
  15408. * @param $width (float) width of the containing element
  15409. * @return array of cell margins
  15410. * @public
  15411. * @since 5.9.000 (2010-10-04)
  15412. */
  15413. public function getCSSMargin($cssmargin, $width=0) {
  15414. $margin = preg_split('/[\s]+/', trim($cssmargin));
  15415. $cell_margin = array(); // value to be returned
  15416. switch (count($margin)) {
  15417. case 4: {
  15418. $cell_margin['T'] = $margin[0];
  15419. $cell_margin['R'] = $margin[1];
  15420. $cell_margin['B'] = $margin[2];
  15421. $cell_margin['L'] = $margin[3];
  15422. break;
  15423. }
  15424. case 3: {
  15425. $cell_margin['T'] = $margin[0];
  15426. $cell_margin['R'] = $margin[1];
  15427. $cell_margin['B'] = $margin[2];
  15428. $cell_margin['L'] = $margin[1];
  15429. break;
  15430. }
  15431. case 2: {
  15432. $cell_margin['T'] = $margin[0];
  15433. $cell_margin['R'] = $margin[1];
  15434. $cell_margin['B'] = $margin[0];
  15435. $cell_margin['L'] = $margin[1];
  15436. break;
  15437. }
  15438. case 1: {
  15439. $cell_margin['T'] = $margin[0];
  15440. $cell_margin['R'] = $margin[0];
  15441. $cell_margin['B'] = $margin[0];
  15442. $cell_margin['L'] = $margin[0];
  15443. break;
  15444. }
  15445. default: {
  15446. return $this->cell_margin;
  15447. }
  15448. }
  15449. if ($width == 0) {
  15450. $width = $this->w - $this->lMargin - $this->rMargin;
  15451. }
  15452. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  15453. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  15454. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  15455. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  15456. return $cell_margin;
  15457. }
  15458. /**
  15459. * Get the border-spacing from CSS attribute.
  15460. * @param $cssbspace (string) border-spacing CSS properties
  15461. * @param $width (float) width of the containing element
  15462. * @return array of border spacings
  15463. * @public
  15464. * @since 5.9.010 (2010-10-27)
  15465. */
  15466. public function getCSSBorderMargin($cssbspace, $width=0) {
  15467. $space = preg_split('/[\s]+/', trim($cssbspace));
  15468. $border_spacing = array(); // value to be returned
  15469. switch (count($space)) {
  15470. case 2: {
  15471. $border_spacing['H'] = $space[0];
  15472. $border_spacing['V'] = $space[1];
  15473. break;
  15474. }
  15475. case 1: {
  15476. $border_spacing['H'] = $space[0];
  15477. $border_spacing['V'] = $space[0];
  15478. break;
  15479. }
  15480. default: {
  15481. return array('H' => 0, 'V' => 0);
  15482. }
  15483. }
  15484. if ($width == 0) {
  15485. $width = $this->w - $this->lMargin - $this->rMargin;
  15486. }
  15487. $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
  15488. $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
  15489. return $border_spacing;
  15490. }
  15491. /**
  15492. * Returns the letter-spacing value from CSS value
  15493. * @param $spacing (string) letter-spacing value
  15494. * @param $parent (float) font spacing (tracking) value of the parent element
  15495. * @return float quantity to increases or decreases the space between characters in a text.
  15496. * @protected
  15497. * @since 5.9.000 (2010-10-02)
  15498. */
  15499. protected function getCSSFontSpacing($spacing, $parent=0) {
  15500. $val = 0; // value to be returned
  15501. $spacing = trim($spacing);
  15502. switch ($spacing) {
  15503. case 'normal': {
  15504. $val = 0;
  15505. break;
  15506. }
  15507. case 'inherit': {
  15508. if ($parent == 'normal') {
  15509. $val = 0;
  15510. } else {
  15511. $val = $parent;
  15512. }
  15513. break;
  15514. }
  15515. default: {
  15516. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  15517. }
  15518. }
  15519. return $val;
  15520. }
  15521. /**
  15522. * Returns the percentage of font stretching from CSS value
  15523. * @param $stretch (string) stretch mode
  15524. * @param $parent (float) stretch value of the parent element
  15525. * @return float font stretching percentage
  15526. * @protected
  15527. * @since 5.9.000 (2010-10-02)
  15528. */
  15529. protected function getCSSFontStretching($stretch, $parent=100) {
  15530. $val = 100; // value to be returned
  15531. $stretch = trim($stretch);
  15532. switch ($stretch) {
  15533. case 'ultra-condensed': {
  15534. $val = 40;
  15535. break;
  15536. }
  15537. case 'extra-condensed': {
  15538. $val = 55;
  15539. break;
  15540. }
  15541. case 'condensed': {
  15542. $val = 70;
  15543. break;
  15544. }
  15545. case 'semi-condensed': {
  15546. $val = 85;
  15547. break;
  15548. }
  15549. case 'normal': {
  15550. $val = 100;
  15551. break;
  15552. }
  15553. case 'semi-expanded': {
  15554. $val = 115;
  15555. break;
  15556. }
  15557. case 'expanded': {
  15558. $val = 130;
  15559. break;
  15560. }
  15561. case 'extra-expanded': {
  15562. $val = 145;
  15563. break;
  15564. }
  15565. case 'ultra-expanded': {
  15566. $val = 160;
  15567. break;
  15568. }
  15569. case 'wider': {
  15570. $val = ($parent + 10);
  15571. break;
  15572. }
  15573. case 'narrower': {
  15574. $val = ($parent - 10);
  15575. break;
  15576. }
  15577. case 'inherit': {
  15578. if ($parent == 'normal') {
  15579. $val = 100;
  15580. } else {
  15581. $val = $parent;
  15582. }
  15583. break;
  15584. }
  15585. default: {
  15586. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  15587. }
  15588. }
  15589. return $val;
  15590. }
  15591. /**
  15592. * Convert HTML string containing font size value to points
  15593. * @param $val (string) String containing font size value and unit.
  15594. * @param $refsize (float) Reference font size in points.
  15595. * @param $parent_size (float) Parent font size in points.
  15596. * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  15597. * @return float value in points
  15598. * @public
  15599. */
  15600. public function getHTMLFontUnits($val, $refsize=12, $parent_size=12, $defaultunit='pt') {
  15601. $refsize = TCPDF_FONTS::getFontRefSize($refsize);
  15602. $parent_size = TCPDF_FONTS::getFontRefSize($parent_size, $refsize);
  15603. switch ($val) {
  15604. case 'xx-small': {
  15605. $size = ($refsize - 4);
  15606. break;
  15607. }
  15608. case 'x-small': {
  15609. $size = ($refsize - 3);
  15610. break;
  15611. }
  15612. case 'small': {
  15613. $size = ($refsize - 2);
  15614. break;
  15615. }
  15616. case 'medium': {
  15617. $size = $refsize;
  15618. break;
  15619. }
  15620. case 'large': {
  15621. $size = ($refsize + 2);
  15622. break;
  15623. }
  15624. case 'x-large': {
  15625. $size = ($refsize + 4);
  15626. break;
  15627. }
  15628. case 'xx-large': {
  15629. $size = ($refsize + 6);
  15630. break;
  15631. }
  15632. case 'smaller': {
  15633. $size = ($parent_size - 3);
  15634. break;
  15635. }
  15636. case 'larger': {
  15637. $size = ($parent_size + 3);
  15638. break;
  15639. }
  15640. default: {
  15641. $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true);
  15642. }
  15643. }
  15644. return $size;
  15645. }
  15646. /**
  15647. * Returns the HTML DOM array.
  15648. * @param $html (string) html code
  15649. * @return array
  15650. * @protected
  15651. * @since 3.2.000 (2008-06-20)
  15652. */
  15653. protected function getHtmlDomArray($html) {
  15654. // array of CSS styles ( selector => properties).
  15655. $css = array();
  15656. // get CSS array defined at previous call
  15657. $matches = array();
  15658. if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
  15659. if (isset($matches[1][0])) {
  15660. $css = array_merge($css, json_decode($this->unhtmlentities($matches[1][0]), true));
  15661. }
  15662. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
  15663. }
  15664. // extract external CSS files
  15665. $matches = array();
  15666. if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
  15667. foreach ($matches[1] as $key => $link) {
  15668. $type = array();
  15669. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
  15670. $type = array();
  15671. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  15672. // get 'all' and 'print' media, other media types are discarded
  15673. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15674. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15675. $type = array();
  15676. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
  15677. // read CSS data file
  15678. $cssdata = TCPDF_STATIC::fileGetContents(trim($type[1]));
  15679. if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) {
  15680. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15681. }
  15682. }
  15683. }
  15684. }
  15685. }
  15686. }
  15687. // extract style tags
  15688. $matches = array();
  15689. if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
  15690. foreach ($matches[1] as $key => $media) {
  15691. $type = array();
  15692. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  15693. // get 'all' and 'print' media, other media types are discarded
  15694. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15695. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15696. $cssdata = $matches[2][$key];
  15697. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15698. }
  15699. }
  15700. }
  15701. // create a special tag to contain the CSS array (used for table content)
  15702. $csstagarray = '<cssarray>'.htmlentities(json_encode($css)).'</cssarray>';
  15703. // remove head and style blocks
  15704. $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
  15705. $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
  15706. // define block tags
  15707. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  15708. // define self-closing tags
  15709. $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  15710. // remove all unsupported tags (the line below lists all supported tags)
  15711. $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>');
  15712. //replace some blank characters
  15713. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  15714. $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);
  15715. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  15716. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  15717. $html = strtr($html, $repTable);
  15718. $offset = 0;
  15719. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  15720. $html_a = substr($html, 0, $offset);
  15721. $html_b = substr($html, $offset, ($pos - $offset + 6));
  15722. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  15723. // preserve newlines on <pre> tag
  15724. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  15725. }
  15726. while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  15727. // preserve spaces on <pre> tag
  15728. $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  15729. }
  15730. $html = $html_a.$html_b.substr($html, $pos + 6);
  15731. $offset = strlen($html_a.$html_b);
  15732. }
  15733. $offset = 0;
  15734. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  15735. $html_a = substr($html, 0, $offset);
  15736. $html_b = substr($html, $offset, ($pos - $offset + 11));
  15737. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  15738. // preserve newlines on <textarea> tag
  15739. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  15740. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  15741. }
  15742. $html = $html_a.$html_b.substr($html, $pos + 11);
  15743. $offset = strlen($html_a.$html_b);
  15744. }
  15745. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  15746. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  15747. $offset = 0;
  15748. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  15749. $html_a = substr($html, 0, $offset);
  15750. $html_b = substr($html, $offset, ($pos - $offset + 9));
  15751. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  15752. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  15753. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  15754. }
  15755. $html = $html_a.$html_b.substr($html, $pos + 9);
  15756. $offset = strlen($html_a.$html_b);
  15757. }
  15758. if (preg_match("'</select'si", $html)) {
  15759. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  15760. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  15761. }
  15762. $html = str_replace("\n", ' ', $html);
  15763. // restore textarea newlines
  15764. $html = str_replace('<TBR>', "\n", $html);
  15765. // remove extra spaces from code
  15766. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  15767. $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
  15768. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  15769. $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
  15770. $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);
  15771. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  15772. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  15773. $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
  15774. $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
  15775. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  15776. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  15777. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  15778. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  15779. $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  15780. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  15781. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  15782. $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
  15783. $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
  15784. $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  15785. // trim string
  15786. $html = $this->stringTrim($html);
  15787. // fix br tag after li
  15788. $html = preg_replace('/<li><br([^\>]*)>/', '<li> <br\\1>', $html);
  15789. // fix first image tag alignment
  15790. $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
  15791. // pattern for generic tag
  15792. $tagpattern = '/(<[^>]+>)/';
  15793. // explodes the string
  15794. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  15795. // count elements
  15796. $maxel = count($a);
  15797. $elkey = 0;
  15798. $key = 0;
  15799. // create an array of elements
  15800. $dom = array();
  15801. $dom[$key] = array();
  15802. // set inheritable properties fot the first void element
  15803. // possible inheritable properties are: azimuth, border-collapse, border-spacing, caption-side, color, cursor, direction, empty-cells, font, font-family, font-stretch, font-size, font-size-adjust, font-style, font-variant, font-weight, letter-spacing, line-height, list-style, list-style-image, list-style-position, list-style-type, orphans, page, page-break-inside, quotes, speak, speak-header, text-align, text-indent, text-transform, volume, white-space, widows, word-spacing
  15804. $dom[$key]['tag'] = false;
  15805. $dom[$key]['block'] = false;
  15806. $dom[$key]['value'] = '';
  15807. $dom[$key]['parent'] = 0;
  15808. $dom[$key]['hide'] = false;
  15809. $dom[$key]['fontname'] = $this->FontFamily;
  15810. $dom[$key]['fontstyle'] = $this->FontStyle;
  15811. $dom[$key]['fontsize'] = $this->FontSizePt;
  15812. $dom[$key]['font-stretch'] = $this->font_stretching;
  15813. $dom[$key]['letter-spacing'] = $this->font_spacing;
  15814. $dom[$key]['stroke'] = $this->textstrokewidth;
  15815. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  15816. $dom[$key]['clip'] = ($this->textrendermode > 3);
  15817. $dom[$key]['line-height'] = $this->cell_height_ratio;
  15818. $dom[$key]['bgcolor'] = false;
  15819. $dom[$key]['fgcolor'] = $this->fgcolor; // color
  15820. $dom[$key]['strokecolor'] = $this->strokecolor;
  15821. $dom[$key]['align'] = '';
  15822. $dom[$key]['listtype'] = '';
  15823. $dom[$key]['text-indent'] = 0;
  15824. $dom[$key]['text-transform'] = '';
  15825. $dom[$key]['border'] = array();
  15826. $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
  15827. $thead = false; // true when we are inside the THEAD tag
  15828. ++$key;
  15829. $level = array();
  15830. array_push($level, 0); // root
  15831. while ($elkey < $maxel) {
  15832. $dom[$key] = array();
  15833. $element = $a[$elkey];
  15834. $dom[$key]['elkey'] = $elkey;
  15835. if (preg_match($tagpattern, $element)) {
  15836. // html tag
  15837. $element = substr($element, 1, -1);
  15838. // get tag name
  15839. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  15840. $tagname = strtolower($tag[1]);
  15841. // check if we are inside a table header
  15842. if ($tagname == 'thead') {
  15843. if ($element[0] == '/') {
  15844. $thead = false;
  15845. } else {
  15846. $thead = true;
  15847. }
  15848. ++$elkey;
  15849. continue;
  15850. }
  15851. $dom[$key]['tag'] = true;
  15852. $dom[$key]['value'] = $tagname;
  15853. if (in_array($dom[$key]['value'], $blocktags)) {
  15854. $dom[$key]['block'] = true;
  15855. } else {
  15856. $dom[$key]['block'] = false;
  15857. }
  15858. if ($element[0] == '/') {
  15859. // *** closing html tag
  15860. $dom[$key]['opening'] = false;
  15861. $dom[$key]['parent'] = end($level);
  15862. array_pop($level);
  15863. $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
  15864. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  15865. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  15866. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  15867. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  15868. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  15869. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  15870. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  15871. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  15872. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  15873. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  15874. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  15875. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  15876. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  15877. $dom[$key]['text-transform'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['text-transform'];
  15878. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  15879. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  15880. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  15881. }
  15882. // set the number of columns in table tag
  15883. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  15884. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  15885. }
  15886. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  15887. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  15888. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  15889. $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]);
  15890. }
  15891. $key = $i;
  15892. // mark nested tables
  15893. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  15894. // remove thead sections from nested tables
  15895. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  15896. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  15897. }
  15898. // store header rows on a new table
  15899. if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
  15900. if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  15901. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  15902. }
  15903. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  15904. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  15905. }
  15906. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  15907. $dom[($dom[$key]['parent'])]['attribute'] = array();
  15908. }
  15909. // header elements must be always contained in a single page
  15910. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  15911. }
  15912. if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  15913. // remove the nobr attributes from the table header
  15914. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  15915. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  15916. }
  15917. } else {
  15918. // *** opening or self-closing html tag
  15919. $dom[$key]['opening'] = true;
  15920. $dom[$key]['parent'] = end($level);
  15921. if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  15922. // self-closing tag
  15923. $dom[$key]['self'] = true;
  15924. } else {
  15925. // opening tag
  15926. array_push($level, $key);
  15927. $dom[$key]['self'] = false;
  15928. }
  15929. // copy some values from parent
  15930. $parentkey = 0;
  15931. if ($key > 0) {
  15932. $parentkey = $dom[$key]['parent'];
  15933. $dom[$key]['hide'] = $dom[$parentkey]['hide'];
  15934. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  15935. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  15936. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  15937. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  15938. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  15939. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  15940. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  15941. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  15942. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  15943. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  15944. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  15945. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  15946. $dom[$key]['align'] = $dom[$parentkey]['align'];
  15947. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  15948. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  15949. $dom[$key]['text-transform'] = $dom[$parentkey]['text-transform'];
  15950. $dom[$key]['border'] = array();
  15951. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  15952. }
  15953. // get attributes
  15954. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  15955. $dom[$key]['attribute'] = array(); // reset attribute array
  15956. foreach($attr_array[1] as $id => $name) {
  15957. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  15958. }
  15959. if (!empty($css)) {
  15960. // merge CSS style to current style
  15961. list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom, $key, $css);
  15962. $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']);
  15963. }
  15964. // split style attributes
  15965. if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  15966. // get style attributes
  15967. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  15968. $dom[$key]['style'] = array(); // reset style attribute array
  15969. foreach($style_array[1] as $id => $name) {
  15970. // in case of duplicate attribute the last replace the previous
  15971. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  15972. }
  15973. // --- get some style attributes ---
  15974. // text direction
  15975. if (isset($dom[$key]['style']['direction'])) {
  15976. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  15977. }
  15978. // display
  15979. if (isset($dom[$key]['style']['display'])) {
  15980. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
  15981. }
  15982. // font family
  15983. if (isset($dom[$key]['style']['font-family'])) {
  15984. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  15985. }
  15986. // list-style-type
  15987. if (isset($dom[$key]['style']['list-style-type'])) {
  15988. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  15989. if ($dom[$key]['listtype'] == 'inherit') {
  15990. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  15991. }
  15992. }
  15993. // text-indent
  15994. if (isset($dom[$key]['style']['text-indent'])) {
  15995. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  15996. if ($dom[$key]['text-indent'] == 'inherit') {
  15997. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  15998. }
  15999. }
  16000. // text-transform
  16001. if (isset($dom[$key]['style']['text-transform'])) {
  16002. $dom[$key]['text-transform'] = $dom[$key]['style']['text-transform'];
  16003. }
  16004. // font size
  16005. if (isset($dom[$key]['style']['font-size'])) {
  16006. $fsize = trim($dom[$key]['style']['font-size']);
  16007. $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
  16008. }
  16009. // font-stretch
  16010. if (isset($dom[$key]['style']['font-stretch'])) {
  16011. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  16012. }
  16013. // letter-spacing
  16014. if (isset($dom[$key]['style']['letter-spacing'])) {
  16015. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  16016. }
  16017. // line-height (internally is the cell height ratio)
  16018. if (isset($dom[$key]['style']['line-height'])) {
  16019. $lineheight = trim($dom[$key]['style']['line-height']);
  16020. switch ($lineheight) {
  16021. // A normal line height. This is default
  16022. case 'normal': {
  16023. $dom[$key]['line-height'] = $dom[0]['line-height'];
  16024. break;
  16025. }
  16026. case 'inherit': {
  16027. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16028. }
  16029. default: {
  16030. if (is_numeric($lineheight)) {
  16031. // convert to percentage of font height
  16032. $lineheight = ($lineheight * 100).'%';
  16033. }
  16034. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  16035. if (substr($lineheight, -1) !== '%') {
  16036. if ($dom[$key]['fontsize'] <= 0) {
  16037. $dom[$key]['line-height'] = 1;
  16038. } else {
  16039. $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding['T'] - $this->cell_padding['B']) / $dom[$key]['fontsize']);
  16040. }
  16041. }
  16042. }
  16043. }
  16044. }
  16045. // font style
  16046. if (isset($dom[$key]['style']['font-weight'])) {
  16047. if (strtolower($dom[$key]['style']['font-weight'][0]) == 'n') {
  16048. if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
  16049. $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
  16050. }
  16051. } elseif (strtolower($dom[$key]['style']['font-weight'][0]) == 'b') {
  16052. $dom[$key]['fontstyle'] .= 'B';
  16053. }
  16054. }
  16055. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style'][0]) == 'i')) {
  16056. $dom[$key]['fontstyle'] .= 'I';
  16057. }
  16058. // font color
  16059. if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) {
  16060. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors);
  16061. } elseif ($dom[$key]['value'] == 'a') {
  16062. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16063. }
  16064. // background color
  16065. if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) {
  16066. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors);
  16067. }
  16068. // text-decoration
  16069. if (isset($dom[$key]['style']['text-decoration'])) {
  16070. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  16071. foreach ($decors as $dec) {
  16072. $dec = trim($dec);
  16073. if (!TCPDF_STATIC::empty_string($dec)) {
  16074. if ($dec[0] == 'u') {
  16075. // underline
  16076. $dom[$key]['fontstyle'] .= 'U';
  16077. } elseif ($dec[0] == 'l') {
  16078. // line-through
  16079. $dom[$key]['fontstyle'] .= 'D';
  16080. } elseif ($dec[0] == 'o') {
  16081. // overline
  16082. $dom[$key]['fontstyle'] .= 'O';
  16083. }
  16084. }
  16085. }
  16086. } elseif ($dom[$key]['value'] == 'a') {
  16087. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16088. }
  16089. // check for width attribute
  16090. if (isset($dom[$key]['style']['width'])) {
  16091. $dom[$key]['width'] = $dom[$key]['style']['width'];
  16092. }
  16093. // check for height attribute
  16094. if (isset($dom[$key]['style']['height'])) {
  16095. $dom[$key]['height'] = $dom[$key]['style']['height'];
  16096. }
  16097. // check for text alignment
  16098. if (isset($dom[$key]['style']['text-align'])) {
  16099. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align'][0]);
  16100. }
  16101. // check for CSS border properties
  16102. if (isset($dom[$key]['style']['border'])) {
  16103. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  16104. if (!empty($borderstyle)) {
  16105. $dom[$key]['border']['LTRB'] = $borderstyle;
  16106. }
  16107. }
  16108. if (isset($dom[$key]['style']['border-color'])) {
  16109. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  16110. if (isset($brd_colors[3])) {
  16111. $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors);
  16112. }
  16113. if (isset($brd_colors[1])) {
  16114. $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors);
  16115. }
  16116. if (isset($brd_colors[0])) {
  16117. $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors);
  16118. }
  16119. if (isset($brd_colors[2])) {
  16120. $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors);
  16121. }
  16122. }
  16123. if (isset($dom[$key]['style']['border-width'])) {
  16124. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  16125. if (isset($brd_widths[3])) {
  16126. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  16127. }
  16128. if (isset($brd_widths[1])) {
  16129. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  16130. }
  16131. if (isset($brd_widths[0])) {
  16132. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  16133. }
  16134. if (isset($brd_widths[2])) {
  16135. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  16136. }
  16137. }
  16138. if (isset($dom[$key]['style']['border-style'])) {
  16139. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  16140. if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
  16141. $dom[$key]['border']['L']['cap'] = 'square';
  16142. $dom[$key]['border']['L']['join'] = 'miter';
  16143. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  16144. if ($dom[$key]['border']['L']['dash'] < 0) {
  16145. $dom[$key]['border']['L'] = array();
  16146. }
  16147. }
  16148. if (isset($brd_styles[1])) {
  16149. $dom[$key]['border']['R']['cap'] = 'square';
  16150. $dom[$key]['border']['R']['join'] = 'miter';
  16151. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  16152. if ($dom[$key]['border']['R']['dash'] < 0) {
  16153. $dom[$key]['border']['R'] = array();
  16154. }
  16155. }
  16156. if (isset($brd_styles[0])) {
  16157. $dom[$key]['border']['T']['cap'] = 'square';
  16158. $dom[$key]['border']['T']['join'] = 'miter';
  16159. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  16160. if ($dom[$key]['border']['T']['dash'] < 0) {
  16161. $dom[$key]['border']['T'] = array();
  16162. }
  16163. }
  16164. if (isset($brd_styles[2])) {
  16165. $dom[$key]['border']['B']['cap'] = 'square';
  16166. $dom[$key]['border']['B']['join'] = 'miter';
  16167. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  16168. if ($dom[$key]['border']['B']['dash'] < 0) {
  16169. $dom[$key]['border']['B'] = array();
  16170. }
  16171. }
  16172. }
  16173. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  16174. foreach ($cellside as $bsk => $bsv) {
  16175. if (isset($dom[$key]['style']['border-'.$bsv])) {
  16176. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  16177. if (!empty($borderstyle)) {
  16178. $dom[$key]['border'][$bsk] = $borderstyle;
  16179. }
  16180. }
  16181. if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  16182. $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors);
  16183. }
  16184. if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  16185. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  16186. }
  16187. if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  16188. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  16189. if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  16190. $dom[$key]['border'][$bsk] = array();
  16191. }
  16192. }
  16193. }
  16194. // check for CSS padding properties
  16195. if (isset($dom[$key]['style']['padding'])) {
  16196. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  16197. } else {
  16198. $dom[$key]['padding'] = $this->cell_padding;
  16199. }
  16200. foreach ($cellside as $psk => $psv) {
  16201. if (isset($dom[$key]['style']['padding-'.$psv])) {
  16202. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
  16203. }
  16204. }
  16205. // check for CSS margin properties
  16206. if (isset($dom[$key]['style']['margin'])) {
  16207. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  16208. } else {
  16209. $dom[$key]['margin'] = $this->cell_margin;
  16210. }
  16211. foreach ($cellside as $psk => $psv) {
  16212. if (isset($dom[$key]['style']['margin-'.$psv])) {
  16213. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
  16214. }
  16215. }
  16216. // check for CSS border-spacing properties
  16217. if (isset($dom[$key]['style']['border-spacing'])) {
  16218. $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  16219. }
  16220. // page-break-inside
  16221. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  16222. $dom[$key]['attribute']['nobr'] = 'true';
  16223. }
  16224. // page-break-before
  16225. if (isset($dom[$key]['style']['page-break-before'])) {
  16226. if ($dom[$key]['style']['page-break-before'] == 'always') {
  16227. $dom[$key]['attribute']['pagebreak'] = 'true';
  16228. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  16229. $dom[$key]['attribute']['pagebreak'] = 'left';
  16230. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  16231. $dom[$key]['attribute']['pagebreak'] = 'right';
  16232. }
  16233. }
  16234. // page-break-after
  16235. if (isset($dom[$key]['style']['page-break-after'])) {
  16236. if ($dom[$key]['style']['page-break-after'] == 'always') {
  16237. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  16238. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  16239. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  16240. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  16241. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  16242. }
  16243. }
  16244. }
  16245. if (isset($dom[$key]['attribute']['display'])) {
  16246. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
  16247. }
  16248. if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  16249. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  16250. if (!empty($borderstyle)) {
  16251. $dom[$key]['border']['LTRB'] = $borderstyle;
  16252. }
  16253. }
  16254. // check for font tag
  16255. if ($dom[$key]['value'] == 'font') {
  16256. // font family
  16257. if (isset($dom[$key]['attribute']['face'])) {
  16258. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  16259. }
  16260. // font size
  16261. if (isset($dom[$key]['attribute']['size'])) {
  16262. if ($key > 0) {
  16263. if ($dom[$key]['attribute']['size'][0] == '+') {
  16264. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  16265. } elseif ($dom[$key]['attribute']['size'][0] == '-') {
  16266. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  16267. } else {
  16268. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16269. }
  16270. } else {
  16271. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16272. }
  16273. }
  16274. }
  16275. // force natural alignment for lists
  16276. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  16277. AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  16278. if ($this->rtl) {
  16279. $dom[$key]['align'] = 'R';
  16280. } else {
  16281. $dom[$key]['align'] = 'L';
  16282. }
  16283. }
  16284. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  16285. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16286. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  16287. }
  16288. }
  16289. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  16290. $dom[$key]['fontstyle'] .= 'B';
  16291. }
  16292. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  16293. $dom[$key]['fontstyle'] .= 'I';
  16294. }
  16295. if ($dom[$key]['value'] == 'u') {
  16296. $dom[$key]['fontstyle'] .= 'U';
  16297. }
  16298. if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  16299. $dom[$key]['fontstyle'] .= 'D';
  16300. }
  16301. if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  16302. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16303. }
  16304. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  16305. $dom[$key]['fontname'] = $this->default_monospaced_font;
  16306. }
  16307. if (!empty($dom[$key]['value']) AND ($dom[$key]['value'][0] == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
  16308. // headings h1, h2, h3, h4, h5, h6
  16309. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16310. $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
  16311. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  16312. }
  16313. if (!isset($dom[$key]['style']['font-weight'])) {
  16314. $dom[$key]['fontstyle'] .= 'B';
  16315. }
  16316. }
  16317. if (($dom[$key]['value'] == 'table')) {
  16318. $dom[$key]['rows'] = 0; // number of rows
  16319. $dom[$key]['trids'] = array(); // IDs of TR elements
  16320. $dom[$key]['thead'] = ''; // table header rows
  16321. }
  16322. if (($dom[$key]['value'] == 'tr')) {
  16323. $dom[$key]['cols'] = 0;
  16324. if ($thead) {
  16325. $dom[$key]['thead'] = true;
  16326. // rows on thead block are printed as a separate table
  16327. } else {
  16328. $dom[$key]['thead'] = false;
  16329. // store the number of rows on table element
  16330. ++$dom[($dom[$key]['parent'])]['rows'];
  16331. // store the TR elements IDs on table element
  16332. array_push($dom[($dom[$key]['parent'])]['trids'], $key);
  16333. }
  16334. }
  16335. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  16336. if (isset($dom[$key]['attribute']['colspan'])) {
  16337. $colspan = intval($dom[$key]['attribute']['colspan']);
  16338. } else {
  16339. $colspan = 1;
  16340. }
  16341. $dom[$key]['attribute']['colspan'] = $colspan;
  16342. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  16343. }
  16344. // text direction
  16345. if (isset($dom[$key]['attribute']['dir'])) {
  16346. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  16347. }
  16348. // set foreground color attribute
  16349. if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) {
  16350. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors);
  16351. } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  16352. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16353. }
  16354. // set background color attribute
  16355. if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) {
  16356. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors);
  16357. }
  16358. // set stroke color attribute
  16359. if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) {
  16360. $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors);
  16361. }
  16362. // check for width attribute
  16363. if (isset($dom[$key]['attribute']['width'])) {
  16364. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  16365. }
  16366. // check for height attribute
  16367. if (isset($dom[$key]['attribute']['height'])) {
  16368. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  16369. }
  16370. // check for text alignment
  16371. if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  16372. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align'][0]);
  16373. }
  16374. // check for text rendering mode (the following attributes do not exist in HTML)
  16375. if (isset($dom[$key]['attribute']['stroke'])) {
  16376. // font stroke width
  16377. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  16378. }
  16379. if (isset($dom[$key]['attribute']['fill'])) {
  16380. // font fill
  16381. if ($dom[$key]['attribute']['fill'] == 'true') {
  16382. $dom[$key]['fill'] = true;
  16383. } else {
  16384. $dom[$key]['fill'] = false;
  16385. }
  16386. }
  16387. if (isset($dom[$key]['attribute']['clip'])) {
  16388. // clipping mode
  16389. if ($dom[$key]['attribute']['clip'] == 'true') {
  16390. $dom[$key]['clip'] = true;
  16391. } else {
  16392. $dom[$key]['clip'] = false;
  16393. }
  16394. }
  16395. } // end opening tag
  16396. } else {
  16397. // text
  16398. $dom[$key]['tag'] = false;
  16399. $dom[$key]['block'] = false;
  16400. $dom[$key]['parent'] = end($level);
  16401. $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  16402. if (!empty($dom[$dom[$key]['parent']]['text-transform'])) {
  16403. // text-transform for unicode requires mb_convert_case (Multibyte String Functions)
  16404. if (function_exists('mb_convert_case')) {
  16405. $ttm = array('capitalize' => MB_CASE_TITLE, 'uppercase' => MB_CASE_UPPER, 'lowercase' => MB_CASE_LOWER);
  16406. if (isset($ttm[$dom[$dom[$key]['parent']]['text-transform']])) {
  16407. $element = mb_convert_case($element, $ttm[$dom[$dom[$key]['parent']]['text-transform']], $this->encoding);
  16408. }
  16409. } elseif (!$this->isunicode) {
  16410. switch ($dom[$dom[$key]['parent']]['text-transform']) {
  16411. case 'capitalize': {
  16412. $element = ucwords(strtolower($element));
  16413. break;
  16414. }
  16415. case 'uppercase': {
  16416. $element = strtoupper($element);
  16417. break;
  16418. }
  16419. case 'lowercase': {
  16420. $element = strtolower($element);
  16421. break;
  16422. }
  16423. }
  16424. }
  16425. }
  16426. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  16427. }
  16428. ++$elkey;
  16429. ++$key;
  16430. }
  16431. return $dom;
  16432. }
  16433. /**
  16434. * Returns the string used to find spaces
  16435. * @return string
  16436. * @protected
  16437. * @author Nicola Asuni
  16438. * @since 4.8.024 (2010-01-15)
  16439. */
  16440. protected function getSpaceString() {
  16441. $spacestr = chr(32);
  16442. if ($this->isUnicodeFont()) {
  16443. $spacestr = chr(0).chr(32);
  16444. }
  16445. return $spacestr;
  16446. }
  16447. /**
  16448. * Return an hash code used to ensure that the serialized data has been generated by this TCPDF instance.
  16449. * @param $data (string) serialized data
  16450. * @return string
  16451. * @public static
  16452. */
  16453. protected function getHashForTCPDFtagParams($data) {
  16454. return md5(strlen($data).$this->file_id.$data);
  16455. }
  16456. /**
  16457. * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  16458. * @param $data (array) parameters array
  16459. * @return string containing serialized data
  16460. * @public static
  16461. */
  16462. public function serializeTCPDFtagParameters($data) {
  16463. $encoded = urlencode(json_encode($data));
  16464. return $this->getHashForTCPDFtagParams($encoded).$encoded;
  16465. }
  16466. /**
  16467. * Unserialize parameters to be used with TCPDF tag in HTML code.
  16468. * @param $data (string) serialized data
  16469. * @return array containing unserialized data
  16470. * @protected static
  16471. */
  16472. protected function unserializeTCPDFtagParameters($data) {
  16473. $hash = substr($data, 0, 32);
  16474. $encoded = substr($data, 32);
  16475. if ($hash != $this->getHashForTCPDFtagParams($encoded)) {
  16476. $this->Error('Invalid parameters');
  16477. }
  16478. return json_decode(urldecode($encoded), true);
  16479. }
  16480. /**
  16481. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  16482. * The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.<br />
  16483. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  16484. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16485. * Supported tags are: a, b, blockquote, br, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, ol, p, pre, small, span, strong, sub, sup, table, tcpdf, td, th, thead, tr, tt, u, ul
  16486. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16487. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  16488. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  16489. * @param $x (float) upper-left corner X coordinate
  16490. * @param $y (float) upper-left corner Y coordinate
  16491. * @param $html (string) html text to print. Default value: empty string.
  16492. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  16493. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL language)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  16494. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  16495. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  16496. * @param $reseth (boolean) if true reset the last cell height (default true).
  16497. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  16498. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  16499. * @see Multicell(), writeHTML()
  16500. * @public
  16501. */
  16502. public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
  16503. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
  16504. }
  16505. /**
  16506. * Allows to preserve some HTML formatting (limited support).<br />
  16507. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16508. * Supported tags are: a, b, blockquote, br, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, ol, p, pre, small, span, strong, sub, sup, table, tcpdf, td, th, thead, tr, tt, u, ul
  16509. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16510. * @param $html (string) text to display
  16511. * @param $ln (boolean) if true add a new line after text (default = true)
  16512. * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false).
  16513. * @param $reseth (boolean) if true reset the last cell height (default false).
  16514. * @param $cell (boolean) if true add the current left (or right for RTL) padding to each Write (default false).
  16515. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  16516. * @public
  16517. */
  16518. public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
  16519. $gvars = $this->getGraphicVars();
  16520. // store current values
  16521. $prev_cell_margin = $this->cell_margin;
  16522. $prev_cell_padding = $this->cell_padding;
  16523. $prevPage = $this->page;
  16524. $prevlMargin = $this->lMargin;
  16525. $prevrMargin = $this->rMargin;
  16526. $curfontname = $this->FontFamily;
  16527. $curfontstyle = $this->FontStyle;
  16528. $curfontsize = $this->FontSizePt;
  16529. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  16530. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  16531. $curfontstretcing = $this->font_stretching;
  16532. $curfonttracking = $this->font_spacing;
  16533. $this->newline = true;
  16534. $newline = true;
  16535. $startlinepage = $this->page;
  16536. $minstartliney = $this->y;
  16537. $maxbottomliney = 0;
  16538. $startlinex = $this->x;
  16539. $startliney = $this->y;
  16540. $yshift = 0;
  16541. $loop = 0;
  16542. $curpos = 0;
  16543. $this_method_vars = array();
  16544. $undo = false;
  16545. $fontaligned = false;
  16546. $reverse_dir = false; // true when the text direction is reversed
  16547. $this->premode = false;
  16548. if ($this->inxobj) {
  16549. // we are inside an XObject template
  16550. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  16551. } elseif (isset($this->PageAnnots[$this->page])) {
  16552. $pask = count($this->PageAnnots[$this->page]);
  16553. } else {
  16554. $pask = 0;
  16555. }
  16556. if ($this->inxobj) {
  16557. // we are inside an XObject template
  16558. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  16559. } elseif (!$this->InFooter) {
  16560. if (isset($this->footerlen[$this->page])) {
  16561. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  16562. } else {
  16563. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  16564. }
  16565. $startlinepos = $this->footerpos[$this->page];
  16566. } else {
  16567. // we are inside the footer
  16568. $startlinepos = $this->pagelen[$this->page];
  16569. }
  16570. $lalign = $align;
  16571. $plalign = $align;
  16572. if ($this->rtl) {
  16573. $w = $this->x - $this->lMargin;
  16574. } else {
  16575. $w = $this->w - $this->rMargin - $this->x;
  16576. }
  16577. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  16578. if ($cell) {
  16579. if ($this->rtl) {
  16580. $this->x -= $this->cell_padding['R'];
  16581. $this->lMargin += $this->cell_padding['L'];
  16582. } else {
  16583. $this->x += $this->cell_padding['L'];
  16584. $this->rMargin += $this->cell_padding['R'];
  16585. }
  16586. }
  16587. if ($this->customlistindent >= 0) {
  16588. $this->listindent = $this->customlistindent;
  16589. } else {
  16590. $this->listindent = $this->GetStringWidth('000000');
  16591. }
  16592. $this->listindentlevel = 0;
  16593. // save previous states
  16594. $prev_cell_height_ratio = $this->cell_height_ratio;
  16595. $prev_listnum = $this->listnum;
  16596. $prev_listordered = $this->listordered;
  16597. $prev_listcount = $this->listcount;
  16598. $prev_lispacer = $this->lispacer;
  16599. $this->listnum = 0;
  16600. $this->listordered = array();
  16601. $this->listcount = array();
  16602. $this->lispacer = '';
  16603. if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) {
  16604. // reset row height
  16605. $this->resetLastH();
  16606. }
  16607. $dom = $this->getHtmlDomArray($html);
  16608. $maxel = count($dom);
  16609. $key = 0;
  16610. while ($key < $maxel) {
  16611. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
  16612. // store the node key
  16613. $hidden_node_key = $key;
  16614. if ($dom[$key]['self']) {
  16615. // skip just this self-closing tag
  16616. ++$key;
  16617. } else {
  16618. // skip this and all children tags
  16619. while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
  16620. // skip hidden objects
  16621. ++$key;
  16622. }
  16623. ++$key;
  16624. }
  16625. }
  16626. if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  16627. // check for pagebreak
  16628. if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  16629. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16630. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16631. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16632. }
  16633. if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  16634. OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  16635. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16636. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16637. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16638. }
  16639. }
  16640. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  16641. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  16642. $dom[$key]['attribute']['nobr'] = false;
  16643. } else {
  16644. // store current object
  16645. $this->startTransaction();
  16646. // save this method vars
  16647. $this_method_vars['html'] = $html;
  16648. $this_method_vars['ln'] = $ln;
  16649. $this_method_vars['fill'] = $fill;
  16650. $this_method_vars['reseth'] = $reseth;
  16651. $this_method_vars['cell'] = $cell;
  16652. $this_method_vars['align'] = $align;
  16653. $this_method_vars['gvars'] = $gvars;
  16654. $this_method_vars['prevPage'] = $prevPage;
  16655. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  16656. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  16657. $this_method_vars['prevlMargin'] = $prevlMargin;
  16658. $this_method_vars['prevrMargin'] = $prevrMargin;
  16659. $this_method_vars['curfontname'] = $curfontname;
  16660. $this_method_vars['curfontstyle'] = $curfontstyle;
  16661. $this_method_vars['curfontsize'] = $curfontsize;
  16662. $this_method_vars['curfontascent'] = $curfontascent;
  16663. $this_method_vars['curfontdescent'] = $curfontdescent;
  16664. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  16665. $this_method_vars['curfonttracking'] = $curfonttracking;
  16666. $this_method_vars['minstartliney'] = $minstartliney;
  16667. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  16668. $this_method_vars['yshift'] = $yshift;
  16669. $this_method_vars['startlinepage'] = $startlinepage;
  16670. $this_method_vars['startlinepos'] = $startlinepos;
  16671. $this_method_vars['startlinex'] = $startlinex;
  16672. $this_method_vars['startliney'] = $startliney;
  16673. $this_method_vars['newline'] = $newline;
  16674. $this_method_vars['loop'] = $loop;
  16675. $this_method_vars['curpos'] = $curpos;
  16676. $this_method_vars['pask'] = $pask;
  16677. $this_method_vars['lalign'] = $lalign;
  16678. $this_method_vars['plalign'] = $plalign;
  16679. $this_method_vars['w'] = $w;
  16680. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  16681. $this_method_vars['prev_listnum'] = $prev_listnum;
  16682. $this_method_vars['prev_listordered'] = $prev_listordered;
  16683. $this_method_vars['prev_listcount'] = $prev_listcount;
  16684. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  16685. $this_method_vars['fontaligned'] = $fontaligned;
  16686. $this_method_vars['key'] = $key;
  16687. $this_method_vars['dom'] = $dom;
  16688. }
  16689. }
  16690. // print THEAD block
  16691. if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  16692. if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) {
  16693. $this->inthead = true;
  16694. // print table header (thead)
  16695. $this->writeHTML($this->thead, false, false, false, false, '');
  16696. // check if we are on a new page or on a new column
  16697. if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
  16698. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  16699. // restore previous object
  16700. $this->rollbackTransaction(true);
  16701. // restore previous values
  16702. foreach ($this_method_vars as $vkey => $vval) {
  16703. $$vkey = $vval;
  16704. }
  16705. // disable table header
  16706. $tmp_thead = $this->thead;
  16707. $this->thead = '';
  16708. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16709. $pre_y = $this->y;
  16710. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  16711. // fix for multicolumn mode
  16712. $startliney = $this->y;
  16713. }
  16714. $this->start_transaction_page = $this->page;
  16715. $this->start_transaction_y = $this->y;
  16716. // restore table header
  16717. $this->thead = $tmp_thead;
  16718. // fix table border properties
  16719. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  16720. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  16721. } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  16722. $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
  16723. } else {
  16724. $tmp_cellspacing = 0;
  16725. }
  16726. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  16727. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  16728. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  16729. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  16730. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  16731. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  16732. // print table header (thead)
  16733. $this->writeHTML($this->thead, false, false, false, false, '');
  16734. }
  16735. }
  16736. // move $key index forward to skip THEAD block
  16737. while ( ($key < $maxel) AND (!(
  16738. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  16739. OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  16740. ++$key;
  16741. }
  16742. }
  16743. if ($dom[$key]['tag'] OR ($key == 0)) {
  16744. if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  16745. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  16746. }
  16747. // vertically align image in line
  16748. if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  16749. // get image height
  16750. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], ($dom[$key]['fontsize'] / $this->k), 'px');
  16751. $autolinebreak = false;
  16752. if (!empty($dom[$key]['width'])) {
  16753. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], ($dom[$key]['fontsize'] / $this->k), 'px', false);
  16754. if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
  16755. AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
  16756. OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
  16757. // add automatic line break
  16758. $autolinebreak = true;
  16759. $this->Ln('', $cell);
  16760. if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  16761. // go back to evaluate this line break
  16762. --$key;
  16763. }
  16764. }
  16765. }
  16766. if (!$autolinebreak) {
  16767. if ($this->inPageBody()) {
  16768. $pre_y = $this->y;
  16769. // check for page break
  16770. if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
  16771. // fix for multicolumn mode
  16772. $startliney = $this->y;
  16773. }
  16774. }
  16775. if ($this->page > $startlinepage) {
  16776. // fix line splitted over two pages
  16777. if (isset($this->footerlen[$startlinepage])) {
  16778. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16779. }
  16780. // line to be moved one page forward
  16781. $pagebuff = $this->getPageBuffer($startlinepage);
  16782. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16783. $tstart = substr($pagebuff, 0, $startlinepos);
  16784. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16785. // remove line from previous page
  16786. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16787. $pagebuff = $this->getPageBuffer($this->page);
  16788. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16789. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16790. // add line start to current page
  16791. $yshift = ($minstartliney - $this->y);
  16792. if ($fontaligned) {
  16793. $yshift += ($curfontsize / $this->k);
  16794. }
  16795. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16796. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16797. // shift the annotations and links
  16798. if (isset($this->PageAnnots[$this->page])) {
  16799. $next_pask = count($this->PageAnnots[$this->page]);
  16800. } else {
  16801. $next_pask = 0;
  16802. }
  16803. if (isset($this->PageAnnots[$startlinepage])) {
  16804. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16805. if ($pak >= $pask) {
  16806. $this->PageAnnots[$this->page][] = $pac;
  16807. unset($this->PageAnnots[$startlinepage][$pak]);
  16808. $npak = count($this->PageAnnots[$this->page]) - 1;
  16809. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16810. }
  16811. }
  16812. }
  16813. $pask = $next_pask;
  16814. $startlinepos = $this->cntmrk[$this->page];
  16815. $startlinepage = $this->page;
  16816. $startliney = $this->y;
  16817. $this->newline = false;
  16818. }
  16819. $this->y += ($this->getCellHeight($curfontsize / $this->k) - ($curfontdescent * $this->cell_height_ratio) - $imgh);
  16820. $minstartliney = min($this->y, $minstartliney);
  16821. $maxbottomliney = ($startliney + $this->getCellHeight($curfontsize / $this->k));
  16822. }
  16823. } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  16824. // account for different font size
  16825. $pfontname = $curfontname;
  16826. $pfontstyle = $curfontstyle;
  16827. $pfontsize = $curfontsize;
  16828. $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname);
  16829. $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle);
  16830. $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize);
  16831. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  16832. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  16833. if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  16834. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16835. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  16836. if (($key < ($maxel - 1)) AND (
  16837. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
  16838. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16839. OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize)
  16840. AND ($fontsize >= 0) AND ($curfontsize >= 0)
  16841. AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname)))
  16842. )) {
  16843. if ($this->page > $startlinepage) {
  16844. // fix lines splitted over two pages
  16845. if (isset($this->footerlen[$startlinepage])) {
  16846. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16847. }
  16848. // line to be moved one page forward
  16849. $pagebuff = $this->getPageBuffer($startlinepage);
  16850. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16851. $tstart = substr($pagebuff, 0, $startlinepos);
  16852. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16853. // remove line start from previous page
  16854. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16855. $pagebuff = $this->getPageBuffer($this->page);
  16856. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16857. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16858. // add line start to current page
  16859. $yshift = ($minstartliney - $this->y);
  16860. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16861. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16862. // shift the annotations and links
  16863. if (isset($this->PageAnnots[$this->page])) {
  16864. $next_pask = count($this->PageAnnots[$this->page]);
  16865. } else {
  16866. $next_pask = 0;
  16867. }
  16868. if (isset($this->PageAnnots[$startlinepage])) {
  16869. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16870. if ($pak >= $pask) {
  16871. $this->PageAnnots[$this->page][] = $pac;
  16872. unset($this->PageAnnots[$startlinepage][$pak]);
  16873. $npak = count($this->PageAnnots[$this->page]) - 1;
  16874. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16875. }
  16876. }
  16877. }
  16878. $pask = $next_pask;
  16879. $startlinepos = $this->cntmrk[$this->page];
  16880. $startlinepage = $this->page;
  16881. $startliney = $this->y;
  16882. }
  16883. if (!isset($dom[$key]['line-height'])) {
  16884. $dom[$key]['line-height'] = $this->cell_height_ratio;
  16885. }
  16886. if (!$dom[$key]['block']) {
  16887. 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']))) {
  16888. $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  16889. }
  16890. if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  16891. $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
  16892. 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)))) {
  16893. $minstartliney = min($this->y, $line_align_data[1]);
  16894. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $line_align_data[2]);
  16895. } else {
  16896. $minstartliney = min($this->y, $minstartliney);
  16897. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $maxbottomliney);
  16898. }
  16899. $line_align_data = $current_line_align_data;
  16900. }
  16901. }
  16902. $this->cell_height_ratio = $dom[$key]['line-height'];
  16903. $fontaligned = true;
  16904. }
  16905. $this->SetFont($fontname, $fontstyle, $fontsize);
  16906. // reset row height
  16907. $this->resetLastH();
  16908. $curfontname = $fontname;
  16909. $curfontstyle = $fontstyle;
  16910. $curfontsize = $fontsize;
  16911. $curfontascent = $fontascent;
  16912. $curfontdescent = $fontdescent;
  16913. }
  16914. }
  16915. // set text rendering mode
  16916. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  16917. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  16918. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  16919. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  16920. if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  16921. $this->setFontStretching($dom[$key]['font-stretch']);
  16922. }
  16923. if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  16924. $this->setFontSpacing($dom[$key]['letter-spacing']);
  16925. }
  16926. if (($plalign == 'J') AND $dom[$key]['block']) {
  16927. $plalign = '';
  16928. }
  16929. // get current position on page buffer
  16930. $curpos = $this->pagelen[$startlinepage];
  16931. if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  16932. $this->SetFillColorArray($dom[$key]['bgcolor']);
  16933. $wfill = true;
  16934. } else {
  16935. $wfill = $fill | false;
  16936. }
  16937. if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  16938. $this->SetTextColorArray($dom[$key]['fgcolor']);
  16939. }
  16940. if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  16941. $this->SetDrawColorArray($dom[$key]['strokecolor']);
  16942. }
  16943. if (isset($dom[$key]['align'])) {
  16944. $lalign = $dom[$key]['align'];
  16945. }
  16946. if (TCPDF_STATIC::empty_string($lalign)) {
  16947. $lalign = $align;
  16948. }
  16949. }
  16950. // align lines
  16951. if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  16952. $newline = true;
  16953. $fontaligned = false;
  16954. // we are at the beginning of a new line
  16955. if (isset($startlinex)) {
  16956. $yshift = ($minstartliney - $startliney);
  16957. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  16958. $yshift = 0;
  16959. }
  16960. $t_x = 0;
  16961. // the last line must be shifted to be aligned as requested
  16962. $linew = abs($this->endlinex - $startlinex);
  16963. if ($this->inxobj) {
  16964. // we are inside an XObject template
  16965. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  16966. if (isset($opentagpos)) {
  16967. $midpos = $opentagpos;
  16968. } else {
  16969. $midpos = 0;
  16970. }
  16971. if ($midpos > 0) {
  16972. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  16973. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  16974. } else {
  16975. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  16976. $pend = '';
  16977. }
  16978. } else {
  16979. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  16980. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  16981. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16982. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  16983. } elseif (isset($opentagpos)) {
  16984. $midpos = $opentagpos;
  16985. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  16986. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16987. $midpos = $this->footerpos[$startlinepage];
  16988. } else {
  16989. $midpos = 0;
  16990. }
  16991. if ($midpos > 0) {
  16992. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  16993. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  16994. } else {
  16995. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  16996. $pend = '';
  16997. }
  16998. }
  16999. if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  17000. // calculate shifting amount
  17001. $tw = $w;
  17002. if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
  17003. $tw += $this->cell_padding['R'];
  17004. }
  17005. if ($this->lMargin != $prevlMargin) {
  17006. $tw += ($prevlMargin - $this->lMargin);
  17007. }
  17008. if ($this->rMargin != $prevrMargin) {
  17009. $tw += ($prevrMargin - $this->rMargin);
  17010. }
  17011. $one_space_width = $this->GetStringWidth(chr(32));
  17012. $no = 0; // number of spaces on a line contained on a single block
  17013. if ($this->isRTLTextDir()) { // RTL
  17014. // remove left space if exist
  17015. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  17016. if ($pos1 > 0) {
  17017. $pos1 = intval($pos1);
  17018. if ($this->isUnicodeFont()) {
  17019. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  17020. $spacelen = 2;
  17021. } else {
  17022. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  17023. $spacelen = 1;
  17024. }
  17025. if ($pos1 == $pos2) {
  17026. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  17027. if (substr($pmid, $pos1, 4) == '[()]') {
  17028. $linew -= $one_space_width;
  17029. } elseif ($pos1 == strpos($pmid, '[(')) {
  17030. $no = 1;
  17031. }
  17032. }
  17033. }
  17034. } else { // LTR
  17035. // remove right space if exist
  17036. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  17037. if ($pos1 > 0) {
  17038. $pos1 = intval($pos1);
  17039. if ($this->isUnicodeFont()) {
  17040. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  17041. $spacelen = 2;
  17042. } else {
  17043. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  17044. $spacelen = 1;
  17045. }
  17046. if ($pos1 == $pos2) {
  17047. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  17048. $linew -= $one_space_width;
  17049. }
  17050. }
  17051. }
  17052. $mdiff = ($tw - $linew);
  17053. if ($plalign == 'C') {
  17054. if ($this->rtl) {
  17055. $t_x = -($mdiff / 2);
  17056. } else {
  17057. $t_x = ($mdiff / 2);
  17058. }
  17059. } elseif ($plalign == 'R') {
  17060. // right alignment on LTR document
  17061. $t_x = $mdiff;
  17062. } elseif ($plalign == 'L') {
  17063. // left alignment on RTL document
  17064. $t_x = -$mdiff;
  17065. } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  17066. // Justification
  17067. if ($this->isRTLTextDir()) {
  17068. // align text on the left
  17069. $t_x = -$mdiff;
  17070. }
  17071. $ns = 0; // number of spaces
  17072. $pmidtemp = $pmid;
  17073. // escape special characters
  17074. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  17075. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  17076. // search spaces
  17077. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
  17078. $spacestr = $this->getSpaceString();
  17079. $maxkk = count($lnstring[1]) - 1;
  17080. for ($kk=0; $kk <= $maxkk; ++$kk) {
  17081. // restore special characters
  17082. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  17083. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  17084. // store number of spaces on the strings
  17085. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  17086. // count total spaces on line
  17087. $ns += $lnstring[2][$kk];
  17088. $lnstring[3][$kk] = $ns;
  17089. }
  17090. if ($ns == 0) {
  17091. $ns = 1;
  17092. }
  17093. // calculate additional space to add to each existing space
  17094. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  17095. if ($this->FontSize <= 0) {
  17096. $this->FontSize = 1;
  17097. }
  17098. $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  17099. if ($this->font_spacing != 0) {
  17100. // fixed spacing mode
  17101. $osw = -1000 * $this->font_spacing / $this->FontSize;
  17102. $spacewidthu += $osw;
  17103. }
  17104. $nsmax = $ns;
  17105. $ns = 0;
  17106. reset($lnstring);
  17107. $offset = 0;
  17108. $strcount = 0;
  17109. $prev_epsposbeg = 0;
  17110. $textpos = 0;
  17111. if ($this->isRTLTextDir()) {
  17112. $textpos = $this->wPt;
  17113. }
  17114. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
  17115. // check if we are inside a string section '[( ... )]'
  17116. $stroffset = strpos($pmid, '[(', $offset);
  17117. if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  17118. // set offset to the end of string section
  17119. $offset = strpos($pmid, ')]', $stroffset);
  17120. while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
  17121. $offset = strpos($pmid, ')]', ($offset + 1));
  17122. }
  17123. if ($offset === false) {
  17124. $this->Error('HTML Justification: malformed PDF code.');
  17125. }
  17126. continue;
  17127. }
  17128. if ($this->isRTLTextDir()) {
  17129. $spacew = ($spacewidth * ($nsmax - $ns));
  17130. } else {
  17131. $spacew = ($spacewidth * $ns);
  17132. }
  17133. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  17134. $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset);
  17135. if ($epsposend !== null) {
  17136. $epsposend += strlen($this->epsmarker.'Q');
  17137. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
  17138. if ($epsposbeg === null) {
  17139. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
  17140. $prev_epsposbeg = $epsposbeg;
  17141. }
  17142. if (($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) {
  17143. // shift EPS images
  17144. $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
  17145. $pmid_b = substr($pmid, 0, $epsposbeg);
  17146. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  17147. $pmid_e = substr($pmid, $epsposend);
  17148. $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  17149. $offset = $epsposend;
  17150. continue;
  17151. }
  17152. }
  17153. $currentxpos = 0;
  17154. // shift blocks of code
  17155. switch ($strpiece[2][0]) {
  17156. case 'Td':
  17157. case 'cm':
  17158. case 'm':
  17159. case 'l': {
  17160. // get current X position
  17161. preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
  17162. if (!isset($xmatches[1])) {
  17163. break;
  17164. }
  17165. $currentxpos = $xmatches[1];
  17166. $textpos = $currentxpos;
  17167. if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  17168. $ns = $lnstring[3][$strcount];
  17169. if ($this->isRTLTextDir()) {
  17170. $spacew = ($spacewidth * ($nsmax - $ns));
  17171. }
  17172. ++$strcount;
  17173. }
  17174. // justify block
  17175. if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $pmatch) == 1) {
  17176. $newpmid = sprintf('%F',(floatval($pmatch[1]) + $spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4];
  17177. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17178. unset($pmatch, $newpmid);
  17179. }
  17180. break;
  17181. }
  17182. case 're': {
  17183. // justify block
  17184. if (!TCPDF_STATIC::empty_string($this->lispacer)) {
  17185. $this->lispacer = '';
  17186. break;
  17187. }
  17188. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
  17189. if (!isset($xmatches[1])) {
  17190. break;
  17191. }
  17192. $currentxpos = $xmatches[1];
  17193. $x_diff = 0;
  17194. $w_diff = 0;
  17195. if ($this->isRTLTextDir()) { // RTL
  17196. if ($currentxpos < $textpos) {
  17197. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  17198. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17199. } else {
  17200. if ($strcount > 0) {
  17201. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  17202. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17203. }
  17204. }
  17205. } else { // LTR
  17206. if ($currentxpos > $textpos) {
  17207. if ($strcount > 0) {
  17208. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  17209. }
  17210. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17211. } else {
  17212. if ($strcount > 1) {
  17213. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  17214. }
  17215. if ($strcount > 0) {
  17216. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17217. }
  17218. }
  17219. }
  17220. if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $pmatch) == 1) {
  17221. $newx = sprintf('%F',(floatval($pmatch[1]) + $x_diff));
  17222. $neww = sprintf('%F',(floatval($pmatch[3]) + $w_diff));
  17223. $newpmid = $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6];
  17224. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17225. unset($pmatch, $newpmid, $newx, $neww);
  17226. }
  17227. break;
  17228. }
  17229. case 'c': {
  17230. // get current X position
  17231. 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);
  17232. if (!isset($xmatches[1])) {
  17233. break;
  17234. }
  17235. $currentxpos = $xmatches[1];
  17236. // justify block
  17237. if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x', $pmid, $pmatch) == 1) {
  17238. $newx1 = sprintf('%F',(floatval($pmatch[1]) + $spacew));
  17239. $newx2 = sprintf('%F',(floatval($pmatch[3]) + $spacew));
  17240. $newx3 = sprintf('%F',(floatval($pmatch[5]) + $spacew));
  17241. $newpmid = $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8];
  17242. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17243. unset($pmatch, $newpmid, $newx1, $newx2, $newx3);
  17244. }
  17245. break;
  17246. }
  17247. }
  17248. // shift the annotations and links
  17249. $cxpos = ($currentxpos / $this->k);
  17250. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  17251. if ($this->inxobj) {
  17252. // we are inside an XObject template
  17253. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17254. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17255. if ($cxpos > $lmpos) {
  17256. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  17257. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17258. } else {
  17259. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17260. }
  17261. break;
  17262. }
  17263. }
  17264. } elseif (isset($this->PageAnnots[$this->page])) {
  17265. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17266. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17267. if ($cxpos > $lmpos) {
  17268. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  17269. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17270. } else {
  17271. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17272. }
  17273. break;
  17274. }
  17275. }
  17276. }
  17277. } // end of while
  17278. // remove markers
  17279. $pmid = str_replace('x*#!#*x', '', $pmid);
  17280. if ($this->isUnicodeFont()) {
  17281. // multibyte characters
  17282. $spacew = $spacewidthu;
  17283. if ($this->font_stretching != 100) {
  17284. // word spacing is affected by stretching
  17285. $spacew /= ($this->font_stretching / 100);
  17286. }
  17287. // escape special characters
  17288. $pos = 0;
  17289. $pmid = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmid);
  17290. $pmid = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmid);
  17291. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmid, $pamatch) > 0) {
  17292. foreach($pamatch[0] as $pk => $pmatch) {
  17293. $replace = $pamatch[1][$pk];
  17294. $replace = str_replace('#!#OP#!#', '(', $replace);
  17295. $replace = str_replace('#!#CP#!#', ')', $replace);
  17296. $newpmid = '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacew).' (', $replace).')]';
  17297. $pos = strpos($pmid, $pmatch, $pos);
  17298. if ($pos !== FALSE) {
  17299. $pmid = substr_replace($pmid, $newpmid, $pos, strlen($pmatch));
  17300. }
  17301. ++$pos;
  17302. }
  17303. unset($pamatch);
  17304. }
  17305. if ($this->inxobj) {
  17306. // we are inside an XObject template
  17307. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  17308. } else {
  17309. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
  17310. }
  17311. $endlinepos = strlen($pstart."\n".$pmid."\n");
  17312. } else {
  17313. // non-unicode (single-byte characters)
  17314. if ($this->font_stretching != 100) {
  17315. // word spacing (Tw) is affected by stretching
  17316. $spacewidth /= ($this->font_stretching / 100);
  17317. }
  17318. $rs = sprintf('%F Tw', $spacewidth);
  17319. $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
  17320. if ($this->inxobj) {
  17321. // we are inside an XObject template
  17322. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  17323. } else {
  17324. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  17325. }
  17326. $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  17327. }
  17328. }
  17329. } // end of J
  17330. } // end if $startlinex
  17331. if (($t_x != 0) OR ($yshift < 0)) {
  17332. // shift the line
  17333. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  17334. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17335. $endlinepos = strlen($pstart);
  17336. if ($this->inxobj) {
  17337. // we are inside an XObject template
  17338. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17339. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17340. if ($pak >= $pask) {
  17341. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17342. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17343. }
  17344. }
  17345. } else {
  17346. $this->setPageBuffer($startlinepage, $pstart.$pend);
  17347. // shift the annotations and links
  17348. if (isset($this->PageAnnots[$this->page])) {
  17349. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17350. if ($pak >= $pask) {
  17351. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17352. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17353. }
  17354. }
  17355. }
  17356. }
  17357. $this->y -= $yshift;
  17358. }
  17359. }
  17360. $pbrk = $this->checkPageBreak($this->lasth);
  17361. $this->newline = false;
  17362. $startlinex = $this->x;
  17363. $startliney = $this->y;
  17364. if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  17365. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  17366. } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  17367. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  17368. } else {
  17369. $minstartliney = $startliney;
  17370. $maxbottomliney = ($this->y + $this->getCellHeight($fontsize / $this->k));
  17371. }
  17372. $startlinepage = $this->page;
  17373. if (isset($endlinepos) AND (!$pbrk)) {
  17374. $startlinepos = $endlinepos;
  17375. } else {
  17376. if ($this->inxobj) {
  17377. // we are inside an XObject template
  17378. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17379. } elseif (!$this->InFooter) {
  17380. if (isset($this->footerlen[$this->page])) {
  17381. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17382. } else {
  17383. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17384. }
  17385. $startlinepos = $this->footerpos[$this->page];
  17386. } else {
  17387. $startlinepos = $this->pagelen[$this->page];
  17388. }
  17389. }
  17390. unset($endlinepos);
  17391. $plalign = $lalign;
  17392. if (isset($this->PageAnnots[$this->page])) {
  17393. $pask = count($this->PageAnnots[$this->page]);
  17394. } else {
  17395. $pask = 0;
  17396. }
  17397. if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  17398. AND (isset($this->emptypagemrk[$this->page]))
  17399. AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  17400. $this->SetFont($fontname, $fontstyle, $fontsize);
  17401. if ($wfill) {
  17402. $this->SetFillColorArray($this->bgcolor);
  17403. }
  17404. }
  17405. } // end newline
  17406. if (isset($opentagpos)) {
  17407. unset($opentagpos);
  17408. }
  17409. if ($dom[$key]['tag']) {
  17410. if ($dom[$key]['opening']) {
  17411. // get text indentation (if any)
  17412. if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  17413. $this->textindent = $dom[$key]['text-indent'];
  17414. $this->newline = true;
  17415. }
  17416. // table
  17417. if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
  17418. // available page width
  17419. if ($this->rtl) {
  17420. $wtmp = $this->x - $this->lMargin;
  17421. } else {
  17422. $wtmp = $this->w - $this->rMargin - $this->x;
  17423. }
  17424. // get cell spacing
  17425. if (isset($dom[$key]['attribute']['cellspacing'])) {
  17426. $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  17427. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  17428. } elseif (isset($dom[$key]['border-spacing'])) {
  17429. $cellspacing = $dom[$key]['border-spacing'];
  17430. } else {
  17431. $cellspacing = array('H' => 0, 'V' => 0);
  17432. }
  17433. // table width
  17434. if (isset($dom[$key]['width'])) {
  17435. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  17436. } else {
  17437. $table_width = $wtmp;
  17438. }
  17439. $table_width -= (2 * $cellspacing['H']);
  17440. if (!$this->inthead) {
  17441. $this->y += $cellspacing['V'];
  17442. }
  17443. if ($this->rtl) {
  17444. $cellspacingx = -$cellspacing['H'];
  17445. } else {
  17446. $cellspacingx = $cellspacing['H'];
  17447. }
  17448. // total table width without cellspaces
  17449. $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  17450. // minimum column width
  17451. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  17452. // array of custom column widths
  17453. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  17454. }
  17455. // table row
  17456. if ($dom[$key]['value'] == 'tr') {
  17457. // reset column counter
  17458. $colid = 0;
  17459. }
  17460. // table cell
  17461. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  17462. $trid = $dom[$key]['parent'];
  17463. $table_el = $dom[$trid]['parent'];
  17464. if (!isset($dom[$table_el]['cols'])) {
  17465. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  17466. }
  17467. // store border info
  17468. $tdborder = 0;
  17469. if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  17470. $tdborder = $dom[$key]['border'];
  17471. }
  17472. $colspan = intval($dom[$key]['attribute']['colspan']);
  17473. if ($colspan <= 0) {
  17474. $colspan = 1;
  17475. }
  17476. $old_cell_padding = $this->cell_padding;
  17477. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  17478. $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  17479. $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
  17480. } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  17481. $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
  17482. } else {
  17483. $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
  17484. }
  17485. $this->cell_padding = $current_cell_padding;
  17486. if (isset($dom[$key]['height'])) {
  17487. // minimum cell height
  17488. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  17489. } else {
  17490. $cellh = 0;
  17491. }
  17492. if (isset($dom[$key]['content'])) {
  17493. $cell_content = $dom[$key]['content'];
  17494. } else {
  17495. $cell_content = '&nbsp;';
  17496. }
  17497. $tagtype = $dom[$key]['value'];
  17498. $parentid = $key;
  17499. while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  17500. // move $key index forward
  17501. ++$key;
  17502. }
  17503. if (!isset($dom[$trid]['startpage'])) {
  17504. $dom[$trid]['startpage'] = $this->page;
  17505. } else {
  17506. $this->setPage($dom[$trid]['startpage']);
  17507. }
  17508. if (!isset($dom[$trid]['startcolumn'])) {
  17509. $dom[$trid]['startcolumn'] = $this->current_column;
  17510. } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  17511. $tmpx = $this->x;
  17512. $this->selectColumn($dom[$trid]['startcolumn']);
  17513. $this->x = $tmpx;
  17514. }
  17515. if (!isset($dom[$trid]['starty'])) {
  17516. $dom[$trid]['starty'] = $this->y;
  17517. } else {
  17518. $this->y = $dom[$trid]['starty'];
  17519. }
  17520. if (!isset($dom[$trid]['startx'])) {
  17521. $dom[$trid]['startx'] = $this->x;
  17522. $this->x += $cellspacingx;
  17523. } else {
  17524. $this->x += ($cellspacingx / 2);
  17525. }
  17526. if (isset($dom[$parentid]['attribute']['rowspan'])) {
  17527. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  17528. } else {
  17529. $rowspan = 1;
  17530. }
  17531. // skip row-spanned cells started on the previous rows
  17532. if (isset($dom[$table_el]['rowspans'])) {
  17533. $rsk = 0;
  17534. $rskmax = count($dom[$table_el]['rowspans']);
  17535. while ($rsk < $rskmax) {
  17536. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  17537. $rsstartx = $trwsp['startx'];
  17538. $rsendx = $trwsp['endx'];
  17539. // account for margin changes
  17540. if ($trwsp['startpage'] < $this->page) {
  17541. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  17542. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  17543. $rsstartx -= $dl;
  17544. $rsendx -= $dl;
  17545. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  17546. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  17547. $rsstartx += $dl;
  17548. $rsendx += $dl;
  17549. }
  17550. }
  17551. if (($trwsp['rowspan'] > 0)
  17552. AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  17553. AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  17554. AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  17555. // set the starting X position of the current cell
  17556. $this->x = $rsendx + $cellspacingx;
  17557. // increment column indicator
  17558. $colid += $trwsp['colspan'];
  17559. if (($trwsp['rowspan'] == 1)
  17560. AND (isset($dom[$trid]['endy']))
  17561. AND (isset($dom[$trid]['endpage']))
  17562. AND (isset($dom[$trid]['endcolumn']))
  17563. AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  17564. AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17565. // set ending Y position for row
  17566. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17567. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  17568. }
  17569. $rsk = 0;
  17570. } else {
  17571. ++$rsk;
  17572. }
  17573. }
  17574. }
  17575. if (isset($dom[$parentid]['width'])) {
  17576. // user specified width
  17577. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  17578. $tmpcw = ($cellw / $colspan);
  17579. for ($i = 0; $i < $colspan; ++$i) {
  17580. $table_colwidths[($colid + $i)] = $tmpcw;
  17581. }
  17582. } else {
  17583. // inherit column width
  17584. $cellw = 0;
  17585. for ($i = 0; $i < $colspan; ++$i) {
  17586. $cellw += (isset($table_colwidths[($colid + $i)]) ? $table_colwidths[($colid + $i)] : 0);
  17587. }
  17588. }
  17589. $cellw += (($colspan - 1) * $cellspacing['H']);
  17590. // increment column indicator
  17591. $colid += $colspan;
  17592. // add rowspan information to table element
  17593. if ($rowspan > 1) {
  17594. $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));
  17595. }
  17596. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  17597. if ($rowspan > 1) {
  17598. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  17599. }
  17600. // push background colors
  17601. if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  17602. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  17603. }
  17604. // store border info
  17605. if (isset($tdborder) AND !empty($tdborder)) {
  17606. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  17607. }
  17608. $prevLastH = $this->lasth;
  17609. // store some info for multicolumn mode
  17610. if ($this->rtl) {
  17611. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  17612. } else {
  17613. $this->colxshift['x'] = $this->x - $this->lMargin;
  17614. }
  17615. $this->colxshift['s'] = $cellspacing;
  17616. $this->colxshift['p'] = $current_cell_padding;
  17617. // ****** write the cell content ******
  17618. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
  17619. // restore some values
  17620. $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  17621. $this->lasth = $prevLastH;
  17622. $this->cell_padding = $old_cell_padding;
  17623. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  17624. // update the end of row position
  17625. if ($rowspan <= 1) {
  17626. if (isset($dom[$trid]['endy'])) {
  17627. if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  17628. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  17629. } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
  17630. $dom[$trid]['endy'] = $this->y;
  17631. }
  17632. } else {
  17633. $dom[$trid]['endy'] = $this->y;
  17634. }
  17635. if (isset($dom[$trid]['endpage'])) {
  17636. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  17637. } else {
  17638. $dom[$trid]['endpage'] = $this->page;
  17639. }
  17640. if (isset($dom[$trid]['endcolumn'])) {
  17641. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  17642. } else {
  17643. $dom[$trid]['endcolumn'] = $this->current_column;
  17644. }
  17645. } else {
  17646. // account for row-spanned cells
  17647. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  17648. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  17649. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  17650. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  17651. }
  17652. if (isset($dom[$table_el]['rowspans'])) {
  17653. // update endy and endpage on rowspanned cells
  17654. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  17655. if ($trwsp['rowspan'] > 0) {
  17656. if (isset($dom[$trid]['endpage'])) {
  17657. if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17658. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17659. } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  17660. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  17661. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  17662. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  17663. } else {
  17664. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  17665. }
  17666. }
  17667. }
  17668. }
  17669. }
  17670. $this->x += ($cellspacingx / 2);
  17671. } else {
  17672. // opening tag (or self-closing tag)
  17673. if (!isset($opentagpos)) {
  17674. if ($this->inxobj) {
  17675. // we are inside an XObject template
  17676. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17677. } elseif (!$this->InFooter) {
  17678. if (isset($this->footerlen[$this->page])) {
  17679. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17680. } else {
  17681. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17682. }
  17683. $opentagpos = $this->footerpos[$this->page];
  17684. }
  17685. }
  17686. $dom = $this->openHTMLTagHandler($dom, $key, $cell);
  17687. }
  17688. } else { // closing tag
  17689. $prev_numpages = $this->numpages;
  17690. $old_bordermrk = $this->bordermrk[$this->page];
  17691. $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  17692. if ($this->bordermrk[$this->page] > $old_bordermrk) {
  17693. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  17694. }
  17695. if ($prev_numpages > $this->numpages) {
  17696. $startlinepage = $this->page;
  17697. }
  17698. }
  17699. } elseif (strlen($dom[$key]['value']) > 0) {
  17700. // print list-item
  17701. if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  17702. $this->SetFont($pfontname, $pfontstyle, $pfontsize);
  17703. $this->resetLastH();
  17704. $minstartliney = $this->y;
  17705. $maxbottomliney = ($startliney + $this->getCellHeight($this->FontSize));
  17706. if (is_numeric($pfontsize) AND ($pfontsize > 0)) {
  17707. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  17708. }
  17709. $this->SetFont($curfontname, $curfontstyle, $curfontsize);
  17710. $this->resetLastH();
  17711. if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
  17712. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  17713. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  17714. $this->y += ($this->getCellHeight(($pfontsize - $curfontsize) / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  17715. $minstartliney = min($this->y, $minstartliney);
  17716. $maxbottomliney = max(($this->y + $this->getCellHeight($pfontsize / $this->k)), $maxbottomliney);
  17717. }
  17718. }
  17719. // text
  17720. $this->htmlvspace = 0;
  17721. $isRTLString = preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $dom[$key]['value']) || preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $dom[$key]['value']);
  17722. if ((!$this->premode) AND $this->isRTLTextDir() AND !$isRTLString) {
  17723. // reverse spaces order
  17724. $lsp = ''; // left spaces
  17725. $rsp = ''; // right spaces
  17726. if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17727. $lsp = $matches[1];
  17728. }
  17729. if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17730. $rsp = $matches[1];
  17731. }
  17732. $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  17733. }
  17734. if ($newline) {
  17735. if (!$this->premode) {
  17736. $prelen = strlen($dom[$key]['value']);
  17737. if ($this->isRTLTextDir() AND !$isRTLString) {
  17738. // right trim except non-breaking space
  17739. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  17740. } else {
  17741. // left trim except non-breaking space
  17742. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  17743. }
  17744. $postlen = strlen($dom[$key]['value']);
  17745. if (($postlen == 0) AND ($prelen > 0)) {
  17746. $dom[$key]['trimmed_space'] = true;
  17747. }
  17748. }
  17749. $newline = false;
  17750. $firstblock = true;
  17751. } else {
  17752. $firstblock = false;
  17753. // replace empty multiple spaces string with a single space
  17754. $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  17755. }
  17756. $strrest = '';
  17757. if ($this->rtl) {
  17758. $this->x -= $this->textindent;
  17759. } else {
  17760. $this->x += $this->textindent;
  17761. }
  17762. if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  17763. $strlinelen = $this->GetStringWidth($dom[$key]['value']);
  17764. if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  17765. // HTML <a> Link
  17766. $hrefcolor = '';
  17767. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  17768. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  17769. }
  17770. $hrefstyle = -1;
  17771. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  17772. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  17773. }
  17774. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  17775. } else {
  17776. $wadj = 0; // space to leave for block continuity
  17777. if ($this->rtl) {
  17778. $cwa = ($this->x - $this->lMargin);
  17779. } else {
  17780. $cwa = ($this->w - $this->rMargin - $this->x);
  17781. }
  17782. if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
  17783. // check the next text blocks for continuity
  17784. $nkey = ($key + 1);
  17785. $write_block = true;
  17786. $same_textdir = true;
  17787. $tmp_fontname = $this->FontFamily;
  17788. $tmp_fontstyle = $this->FontStyle;
  17789. $tmp_fontsize = $this->FontSizePt;
  17790. while ($write_block AND isset($dom[$nkey])) {
  17791. if ($dom[$nkey]['tag']) {
  17792. if ($dom[$nkey]['block']) {
  17793. // end of block
  17794. $write_block = false;
  17795. }
  17796. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  17797. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  17798. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  17799. $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  17800. } else {
  17801. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/', $this->re_space['m'], $dom[$nkey]['value']);
  17802. if (isset($nextstr[0]) AND $same_textdir) {
  17803. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  17804. if (isset($nextstr[1])) {
  17805. $write_block = false;
  17806. }
  17807. }
  17808. }
  17809. ++$nkey;
  17810. }
  17811. }
  17812. if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
  17813. $wadj = 0;
  17814. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $dom[$key]['value']);
  17815. $numblks = count($nextstr);
  17816. if ($numblks > 1) {
  17817. // try to split on blank spaces
  17818. $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
  17819. } else {
  17820. // set the entire block on new line
  17821. $wadj = $this->GetStringWidth($nextstr[0]);
  17822. }
  17823. }
  17824. // check for reversed text direction
  17825. if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  17826. // LTR text on RTL direction or RTL text on LTR direction
  17827. $reverse_dir = true;
  17828. $this->rtl = !$this->rtl;
  17829. $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
  17830. if ($this->rtl) {
  17831. $this->x += $revshift;
  17832. } else {
  17833. $this->x -= $revshift;
  17834. }
  17835. $xws = $this->x;
  17836. }
  17837. // ****** write only until the end of the line and get the rest ******
  17838. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  17839. // restore default direction
  17840. if ($reverse_dir AND ($wadj == 0)) {
  17841. $this->x = $xws;
  17842. $this->rtl = !$this->rtl;
  17843. $reverse_dir = false;
  17844. }
  17845. }
  17846. }
  17847. $this->textindent = 0;
  17848. if (strlen($strrest) > 0) {
  17849. // store the remaining string on the previous $key position
  17850. $this->newline = true;
  17851. if ($strrest == $dom[$key]['value']) {
  17852. // used to avoid infinite loop
  17853. ++$loop;
  17854. } else {
  17855. $loop = 0;
  17856. }
  17857. $dom[$key]['value'] = $strrest;
  17858. if ($cell) {
  17859. if ($this->rtl) {
  17860. $this->x -= $this->cell_padding['R'];
  17861. } else {
  17862. $this->x += $this->cell_padding['L'];
  17863. }
  17864. }
  17865. if ($loop < 3) {
  17866. --$key;
  17867. }
  17868. } else {
  17869. $loop = 0;
  17870. // add the positive font spacing of the last character (if any)
  17871. if ($this->font_spacing > 0) {
  17872. if ($this->rtl) {
  17873. $this->x -= $this->font_spacing;
  17874. } else {
  17875. $this->x += $this->font_spacing;
  17876. }
  17877. }
  17878. }
  17879. }
  17880. ++$key;
  17881. 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')) {
  17882. // check if we are on a new page or on a new column
  17883. if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
  17884. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  17885. // restore previous object
  17886. $this->rollbackTransaction(true);
  17887. // restore previous values
  17888. foreach ($this_method_vars as $vkey => $vval) {
  17889. $$vkey = $vval;
  17890. }
  17891. if (!empty($dom[$key]['thead'])) {
  17892. $this->inthead = true;
  17893. }
  17894. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  17895. $pre_y = $this->y;
  17896. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  17897. $startliney = $this->y;
  17898. }
  17899. $undo = true; // avoid infinite loop
  17900. } else {
  17901. $undo = false;
  17902. }
  17903. }
  17904. } // end for each $key
  17905. // align the last line
  17906. if (isset($startlinex)) {
  17907. $yshift = ($minstartliney - $startliney);
  17908. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  17909. $yshift = 0;
  17910. }
  17911. $t_x = 0;
  17912. // the last line must be shifted to be aligned as requested
  17913. $linew = abs($this->endlinex - $startlinex);
  17914. if ($this->inxobj) {
  17915. // we are inside an XObject template
  17916. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  17917. if (isset($opentagpos)) {
  17918. $midpos = $opentagpos;
  17919. } else {
  17920. $midpos = 0;
  17921. }
  17922. if ($midpos > 0) {
  17923. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  17924. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  17925. } else {
  17926. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  17927. $pend = '';
  17928. }
  17929. } else {
  17930. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  17931. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17932. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17933. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  17934. } elseif (isset($opentagpos)) {
  17935. $midpos = $opentagpos;
  17936. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17937. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17938. $midpos = $this->footerpos[$startlinepage];
  17939. } else {
  17940. $midpos = 0;
  17941. }
  17942. if ($midpos > 0) {
  17943. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  17944. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  17945. } else {
  17946. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  17947. $pend = '';
  17948. }
  17949. }
  17950. if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  17951. // calculate shifting amount
  17952. $tw = $w;
  17953. if ($this->lMargin != $prevlMargin) {
  17954. $tw += ($prevlMargin - $this->lMargin);
  17955. }
  17956. if ($this->rMargin != $prevrMargin) {
  17957. $tw += ($prevrMargin - $this->rMargin);
  17958. }
  17959. $one_space_width = $this->GetStringWidth(chr(32));
  17960. $no = 0; // number of spaces on a line contained on a single block
  17961. if ($this->isRTLTextDir()) { // RTL
  17962. // remove left space if exist
  17963. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  17964. if ($pos1 > 0) {
  17965. $pos1 = intval($pos1);
  17966. if ($this->isUnicodeFont()) {
  17967. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  17968. $spacelen = 2;
  17969. } else {
  17970. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  17971. $spacelen = 1;
  17972. }
  17973. if ($pos1 == $pos2) {
  17974. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  17975. if (substr($pmid, $pos1, 4) == '[()]') {
  17976. $linew -= $one_space_width;
  17977. } elseif ($pos1 == strpos($pmid, '[(')) {
  17978. $no = 1;
  17979. }
  17980. }
  17981. }
  17982. } else { // LTR
  17983. // remove right space if exist
  17984. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  17985. if ($pos1 > 0) {
  17986. $pos1 = intval($pos1);
  17987. if ($this->isUnicodeFont()) {
  17988. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  17989. $spacelen = 2;
  17990. } else {
  17991. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  17992. $spacelen = 1;
  17993. }
  17994. if ($pos1 == $pos2) {
  17995. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  17996. $linew -= $one_space_width;
  17997. }
  17998. }
  17999. }
  18000. $mdiff = ($tw - $linew);
  18001. if ($plalign == 'C') {
  18002. if ($this->rtl) {
  18003. $t_x = -($mdiff / 2);
  18004. } else {
  18005. $t_x = ($mdiff / 2);
  18006. }
  18007. } elseif ($plalign == 'R') {
  18008. // right alignment on LTR document
  18009. $t_x = $mdiff;
  18010. } elseif ($plalign == 'L') {
  18011. // left alignment on RTL document
  18012. $t_x = -$mdiff;
  18013. }
  18014. } // end if startlinex
  18015. if (($t_x != 0) OR ($yshift < 0)) {
  18016. // shift the line
  18017. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  18018. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  18019. $endlinepos = strlen($pstart);
  18020. if ($this->inxobj) {
  18021. // we are inside an XObject template
  18022. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  18023. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  18024. if ($pak >= $pask) {
  18025. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  18026. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  18027. }
  18028. }
  18029. } else {
  18030. $this->setPageBuffer($startlinepage, $pstart.$pend);
  18031. // shift the annotations and links
  18032. if (isset($this->PageAnnots[$this->page])) {
  18033. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  18034. if ($pak >= $pask) {
  18035. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  18036. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  18037. }
  18038. }
  18039. }
  18040. }
  18041. $this->y -= $yshift;
  18042. $yshift = 0;
  18043. }
  18044. }
  18045. // restore previous values
  18046. $this->setGraphicVars($gvars);
  18047. if ($this->num_columns > 1) {
  18048. $this->selectColumn();
  18049. } elseif ($this->page > $prevPage) {
  18050. $this->lMargin = $this->pagedim[$this->page]['olm'];
  18051. $this->rMargin = $this->pagedim[$this->page]['orm'];
  18052. }
  18053. // restore previous list state
  18054. $this->cell_height_ratio = $prev_cell_height_ratio;
  18055. $this->listnum = $prev_listnum;
  18056. $this->listordered = $prev_listordered;
  18057. $this->listcount = $prev_listcount;
  18058. $this->lispacer = $prev_lispacer;
  18059. if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  18060. $this->Ln($this->lasth);
  18061. if (($this->y < $maxbottomliney) AND ($startlinepage == $this->page)) {
  18062. $this->y = $maxbottomliney;
  18063. }
  18064. }
  18065. unset($dom);
  18066. }
  18067. /**
  18068. * Process opening tags.
  18069. * @param $dom (array) html dom array
  18070. * @param $key (int) current element id
  18071. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  18072. * @return $dom array
  18073. * @protected
  18074. */
  18075. protected function openHTMLTagHandler($dom, $key, $cell) {
  18076. $tag = $dom[$key];
  18077. $parent = $dom[($dom[$key]['parent'])];
  18078. $firsttag = ($key == 1);
  18079. // check for text direction attribute
  18080. if (isset($tag['dir'])) {
  18081. $this->setTempRTL($tag['dir']);
  18082. } else {
  18083. $this->tmprtl = false;
  18084. }
  18085. if ($tag['block']) {
  18086. $hbz = 0; // distance from y to line bottom
  18087. $hb = 0; // vertical space between block tags
  18088. // calculate vertical space for block tags
  18089. if (isset($this->tagvspaces[$tag['value']][0]['h']) AND ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  18090. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  18091. } elseif (isset($tag['fontsize'])) {
  18092. $cur_h = $this->getCellHeight($tag['fontsize'] / $this->k);
  18093. } else {
  18094. $cur_h = $this->getCellHeight($this->FontSize);
  18095. }
  18096. if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  18097. $on = $this->tagvspaces[$tag['value']][0]['n'];
  18098. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18099. $on = 0.6;
  18100. } else {
  18101. $on = 1;
  18102. }
  18103. if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br', 'hr')))) {
  18104. $hb = 0;
  18105. } else {
  18106. $hb = ($on * $cur_h);
  18107. }
  18108. if (($this->htmlvspace <= 0) AND ($on > 0)) {
  18109. if (isset($parent['fontsize'])) {
  18110. $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  18111. } else {
  18112. $hbz = $this->getCellHeight($this->FontSize);
  18113. }
  18114. }
  18115. if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
  18116. // fix vertical space after table
  18117. $hbz = 0;
  18118. }
  18119. // closing vertical space
  18120. $hbc = 0;
  18121. if (isset($this->tagvspaces[$tag['value']][1]['h']) AND ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18122. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18123. } elseif (isset($parent['fontsize'])) {
  18124. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  18125. } else {
  18126. $pre_h = $this->getCellHeight($this->FontSize);
  18127. }
  18128. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18129. $cn = $this->tagvspaces[$tag['value']][1]['n'];
  18130. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18131. $cn = 0.6;
  18132. } else {
  18133. $cn = 1;
  18134. }
  18135. if (isset($this->tagvspaces[$tag['value']][1])) {
  18136. $hbc = ($cn * $pre_h);
  18137. }
  18138. }
  18139. // Opening tag
  18140. switch($tag['value']) {
  18141. case 'table': {
  18142. $cp = 0;
  18143. $cs = 0;
  18144. $dom[$key]['rowspans'] = array();
  18145. if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  18146. $this->htmlvspace = 0;
  18147. // set table header
  18148. if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) {
  18149. // set table header
  18150. $this->thead = $dom[$key]['thead'];
  18151. if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  18152. $this->theadMargins = array();
  18153. $this->theadMargins['cell_padding'] = $this->cell_padding;
  18154. $this->theadMargins['lmargin'] = $this->lMargin;
  18155. $this->theadMargins['rmargin'] = $this->rMargin;
  18156. $this->theadMargins['page'] = $this->page;
  18157. $this->theadMargins['cell'] = $cell;
  18158. $this->theadMargins['gvars'] = $this->getGraphicVars();
  18159. }
  18160. }
  18161. }
  18162. // store current margins and page
  18163. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  18164. if (isset($tag['attribute']['cellpadding'])) {
  18165. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  18166. $this->SetCellPadding($pad);
  18167. } elseif (isset($tag['padding'])) {
  18168. $this->cell_padding = $tag['padding'];
  18169. }
  18170. if (isset($tag['attribute']['cellspacing'])) {
  18171. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  18172. } elseif (isset($tag['border-spacing'])) {
  18173. $cs = $tag['border-spacing']['V'];
  18174. }
  18175. $prev_y = $this->y;
  18176. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
  18177. $this->inthead = true;
  18178. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18179. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18180. }
  18181. break;
  18182. }
  18183. case 'tr': {
  18184. // array of columns positions
  18185. $dom[$key]['cellpos'] = array();
  18186. break;
  18187. }
  18188. case 'hr': {
  18189. if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  18190. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  18191. } else {
  18192. $hrHeight = $this->GetLineWidth();
  18193. }
  18194. $this->addHTMLVertSpace($hbz, max($hb, ($hrHeight / 2)), $cell, $firsttag);
  18195. $x = $this->GetX();
  18196. $y = $this->GetY();
  18197. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  18198. if ($cell) {
  18199. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  18200. }
  18201. if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  18202. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  18203. } else {
  18204. $hrWidth = $wtmp;
  18205. }
  18206. $prevlinewidth = $this->GetLineWidth();
  18207. $this->SetLineWidth($hrHeight);
  18208. $this->Line($x, $y, $x + $hrWidth, $y);
  18209. $this->SetLineWidth($prevlinewidth);
  18210. $this->addHTMLVertSpace(max($hbc, ($hrHeight / 2)), 0, $cell, !isset($dom[($key + 1)]));
  18211. break;
  18212. }
  18213. case 'a': {
  18214. if (array_key_exists('href', $tag['attribute'])) {
  18215. $this->HREF['url'] = $tag['attribute']['href'];
  18216. }
  18217. break;
  18218. }
  18219. case 'img': {
  18220. if (empty($tag['attribute']['src'])) {
  18221. break;
  18222. }
  18223. $imgsrc = $tag['attribute']['src'];
  18224. if ($imgsrc[0] === '@') {
  18225. // data stream
  18226. $imgsrc = '@'.base64_decode(substr($imgsrc, 1));
  18227. $type = '';
  18228. } else {
  18229. if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  18230. // fix image path
  18231. $findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']);
  18232. if (($findroot === false) OR ($findroot > 1)) {
  18233. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  18234. $imgsrc = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc;
  18235. } else {
  18236. $imgsrc = $_SERVER['DOCUMENT_ROOT'].$imgsrc;
  18237. }
  18238. }
  18239. $imgsrc = urldecode($imgsrc);
  18240. $testscrtype = @parse_url($imgsrc);
  18241. if (empty($testscrtype['query'])) {
  18242. // convert URL to server path
  18243. $imgsrc = str_replace(K_PATH_URL, K_PATH_MAIN, $imgsrc);
  18244. } elseif (preg_match('|^https?://|', $imgsrc) !== 1) {
  18245. // convert URL to server path
  18246. $imgsrc = str_replace(K_PATH_MAIN, K_PATH_URL, $imgsrc);
  18247. }
  18248. }
  18249. // get image type
  18250. $type = TCPDF_IMAGES::getImageFileType($imgsrc);
  18251. }
  18252. if (!isset($tag['width'])) {
  18253. $tag['width'] = 0;
  18254. }
  18255. if (!isset($tag['height'])) {
  18256. $tag['height'] = 0;
  18257. }
  18258. //if (!isset($tag['attribute']['align'])) {
  18259. // the only alignment supported is "bottom"
  18260. // further development is required for other modes.
  18261. $tag['attribute']['align'] = 'bottom';
  18262. //}
  18263. switch($tag['attribute']['align']) {
  18264. case 'top': {
  18265. $align = 'T';
  18266. break;
  18267. }
  18268. case 'middle': {
  18269. $align = 'M';
  18270. break;
  18271. }
  18272. case 'bottom': {
  18273. $align = 'B';
  18274. break;
  18275. }
  18276. default: {
  18277. $align = 'B';
  18278. break;
  18279. }
  18280. }
  18281. $prevy = $this->y;
  18282. $xpos = $this->x;
  18283. $imglink = '';
  18284. if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) {
  18285. $imglink = $this->HREF['url'];
  18286. if ($imglink[0] == '#') {
  18287. // convert url to internal link
  18288. $lnkdata = explode(',', $imglink);
  18289. if (isset($lnkdata[0])) {
  18290. $page = intval(substr($lnkdata[0], 1));
  18291. if (empty($page) OR ($page <= 0)) {
  18292. $page = $this->page;
  18293. }
  18294. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  18295. $lnky = floatval($lnkdata[1]);
  18296. } else {
  18297. $lnky = 0;
  18298. }
  18299. $imglink = $this->AddLink();
  18300. $this->SetLink($imglink, $lnky, $page);
  18301. }
  18302. }
  18303. }
  18304. $border = 0;
  18305. if (isset($tag['border']) AND !empty($tag['border'])) {
  18306. // currently only support 1 (frame) or a combination of 'LTRB'
  18307. $border = $tag['border'];
  18308. }
  18309. $iw = '';
  18310. if (isset($tag['width'])) {
  18311. $iw = $this->getHTMLUnitToUnits($tag['width'], ($tag['fontsize'] / $this->k), 'px', false);
  18312. }
  18313. $ih = '';
  18314. if (isset($tag['height'])) {
  18315. $ih = $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k), 'px', false);
  18316. }
  18317. if (($type == 'eps') OR ($type == 'ai')) {
  18318. $this->ImageEps($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  18319. } elseif ($type == 'svg') {
  18320. $this->ImageSVG($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  18321. } else {
  18322. $this->Image($imgsrc, $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  18323. }
  18324. switch($align) {
  18325. case 'T': {
  18326. $this->y = $prevy;
  18327. break;
  18328. }
  18329. case 'M': {
  18330. $this->y = (($this->img_rb_y + $prevy - ($this->getCellHeight($tag['fontsize'] / $this->k))) / 2);
  18331. break;
  18332. }
  18333. case 'B': {
  18334. $this->y = $this->img_rb_y - ($this->getCellHeight($tag['fontsize'] / $this->k) - ($this->getFontDescent($tag['fontname'], $tag['fontstyle'], $tag['fontsize']) * $this->cell_height_ratio));
  18335. break;
  18336. }
  18337. }
  18338. break;
  18339. }
  18340. case 'dl': {
  18341. ++$this->listnum;
  18342. if ($this->listnum == 1) {
  18343. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18344. } else {
  18345. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18346. }
  18347. break;
  18348. }
  18349. case 'dt': {
  18350. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18351. break;
  18352. }
  18353. case 'dd': {
  18354. if ($this->rtl) {
  18355. $this->rMargin += $this->listindent;
  18356. } else {
  18357. $this->lMargin += $this->listindent;
  18358. }
  18359. ++$this->listindentlevel;
  18360. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18361. break;
  18362. }
  18363. case 'ul':
  18364. case 'ol': {
  18365. ++$this->listnum;
  18366. if ($tag['value'] == 'ol') {
  18367. $this->listordered[$this->listnum] = true;
  18368. } else {
  18369. $this->listordered[$this->listnum] = false;
  18370. }
  18371. if (isset($tag['attribute']['start'])) {
  18372. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  18373. } else {
  18374. $this->listcount[$this->listnum] = 0;
  18375. }
  18376. if ($this->rtl) {
  18377. $this->rMargin += $this->listindent;
  18378. $this->x -= $this->listindent;
  18379. } else {
  18380. $this->lMargin += $this->listindent;
  18381. $this->x += $this->listindent;
  18382. }
  18383. ++$this->listindentlevel;
  18384. if ($this->listnum == 1) {
  18385. if ($key > 1) {
  18386. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18387. }
  18388. } else {
  18389. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18390. }
  18391. break;
  18392. }
  18393. case 'li': {
  18394. if ($key > 2) {
  18395. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18396. }
  18397. if ($this->listordered[$this->listnum]) {
  18398. // ordered item
  18399. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18400. $this->lispacer = $parent['attribute']['type'];
  18401. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18402. $this->lispacer = $parent['listtype'];
  18403. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18404. $this->lispacer = $this->lisymbol;
  18405. } else {
  18406. $this->lispacer = '#';
  18407. }
  18408. ++$this->listcount[$this->listnum];
  18409. if (isset($tag['attribute']['value'])) {
  18410. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  18411. }
  18412. } else {
  18413. // unordered item
  18414. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18415. $this->lispacer = $parent['attribute']['type'];
  18416. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18417. $this->lispacer = $parent['listtype'];
  18418. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18419. $this->lispacer = $this->lisymbol;
  18420. } else {
  18421. $this->lispacer = '!';
  18422. }
  18423. }
  18424. break;
  18425. }
  18426. case 'blockquote': {
  18427. if ($this->rtl) {
  18428. $this->rMargin += $this->listindent;
  18429. } else {
  18430. $this->lMargin += $this->listindent;
  18431. }
  18432. ++$this->listindentlevel;
  18433. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18434. break;
  18435. }
  18436. case 'br': {
  18437. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18438. break;
  18439. }
  18440. case 'div': {
  18441. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18442. break;
  18443. }
  18444. case 'p': {
  18445. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18446. break;
  18447. }
  18448. case 'pre': {
  18449. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18450. $this->premode = true;
  18451. break;
  18452. }
  18453. case 'sup': {
  18454. $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  18455. break;
  18456. }
  18457. case 'sub': {
  18458. $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  18459. break;
  18460. }
  18461. case 'h1':
  18462. case 'h2':
  18463. case 'h3':
  18464. case 'h4':
  18465. case 'h5':
  18466. case 'h6': {
  18467. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18468. break;
  18469. }
  18470. // Form fields (since 4.8.000 - 2009-09-07)
  18471. case 'form': {
  18472. if (isset($tag['attribute']['action'])) {
  18473. $this->form_action = $tag['attribute']['action'];
  18474. } else {
  18475. $this->Error('Please explicitly set action attribute path!');
  18476. }
  18477. if (isset($tag['attribute']['enctype'])) {
  18478. $this->form_enctype = $tag['attribute']['enctype'];
  18479. } else {
  18480. $this->form_enctype = 'application/x-www-form-urlencoded';
  18481. }
  18482. if (isset($tag['attribute']['method'])) {
  18483. $this->form_mode = $tag['attribute']['method'];
  18484. } else {
  18485. $this->form_mode = 'post';
  18486. }
  18487. break;
  18488. }
  18489. case 'input': {
  18490. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18491. $name = $tag['attribute']['name'];
  18492. } else {
  18493. break;
  18494. }
  18495. $prop = array();
  18496. $opt = array();
  18497. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18498. $prop['readonly'] = true;
  18499. }
  18500. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18501. $value = $tag['attribute']['value'];
  18502. }
  18503. if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) {
  18504. $opt['maxlen'] = intval($tag['attribute']['maxlength']);
  18505. }
  18506. $h = $this->getCellHeight($this->FontSize);
  18507. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18508. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  18509. } else {
  18510. $w = $h;
  18511. }
  18512. if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  18513. $checked = true;
  18514. } else {
  18515. $checked = false;
  18516. }
  18517. if (isset($tag['align'])) {
  18518. switch ($tag['align']) {
  18519. case 'C': {
  18520. $opt['q'] = 1;
  18521. break;
  18522. }
  18523. case 'R': {
  18524. $opt['q'] = 2;
  18525. break;
  18526. }
  18527. case 'L':
  18528. default: {
  18529. break;
  18530. }
  18531. }
  18532. }
  18533. switch ($tag['attribute']['type']) {
  18534. case 'text': {
  18535. if (isset($value)) {
  18536. $opt['v'] = $value;
  18537. }
  18538. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18539. break;
  18540. }
  18541. case 'password': {
  18542. if (isset($value)) {
  18543. $opt['v'] = $value;
  18544. }
  18545. $prop['password'] = 'true';
  18546. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18547. break;
  18548. }
  18549. case 'checkbox': {
  18550. if (!isset($value)) {
  18551. break;
  18552. }
  18553. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  18554. break;
  18555. }
  18556. case 'radio': {
  18557. if (!isset($value)) {
  18558. break;
  18559. }
  18560. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  18561. break;
  18562. }
  18563. case 'submit': {
  18564. if (!isset($value)) {
  18565. $value = 'submit';
  18566. }
  18567. $w = $this->GetStringWidth($value) * 1.5;
  18568. $h *= 1.6;
  18569. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18570. $action = array();
  18571. $action['S'] = 'SubmitForm';
  18572. $action['F'] = $this->form_action;
  18573. if ($this->form_enctype != 'FDF') {
  18574. $action['Flags'] = array('ExportFormat');
  18575. }
  18576. if ($this->form_mode == 'get') {
  18577. $action['Flags'] = array('GetMethod');
  18578. }
  18579. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  18580. break;
  18581. }
  18582. case 'reset': {
  18583. if (!isset($value)) {
  18584. $value = 'reset';
  18585. }
  18586. $w = $this->GetStringWidth($value) * 1.5;
  18587. $h *= 1.6;
  18588. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18589. $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
  18590. break;
  18591. }
  18592. case 'file': {
  18593. $prop['fileSelect'] = 'true';
  18594. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18595. if (!isset($value)) {
  18596. $value = '*';
  18597. }
  18598. $w = $this->GetStringWidth($value) * 2;
  18599. $h *= 1.2;
  18600. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18601. $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  18602. $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18603. break;
  18604. }
  18605. case 'hidden': {
  18606. if (isset($value)) {
  18607. $opt['v'] = $value;
  18608. }
  18609. $opt['f'] = array('invisible', 'hidden');
  18610. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  18611. break;
  18612. }
  18613. case 'image': {
  18614. // THIS TYPE MUST BE FIXED
  18615. if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) {
  18616. $img = $tag['attribute']['src'];
  18617. } else {
  18618. break;
  18619. }
  18620. $value = 'img';
  18621. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  18622. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18623. $jsaction = $tag['attribute']['onclick'];
  18624. } else {
  18625. $jsaction = '';
  18626. }
  18627. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18628. break;
  18629. }
  18630. case 'button': {
  18631. if (!isset($value)) {
  18632. $value = ' ';
  18633. }
  18634. $w = $this->GetStringWidth($value) * 1.5;
  18635. $h *= 1.6;
  18636. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18637. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18638. $jsaction = $tag['attribute']['onclick'];
  18639. } else {
  18640. $jsaction = '';
  18641. }
  18642. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18643. break;
  18644. }
  18645. }
  18646. break;
  18647. }
  18648. case 'textarea': {
  18649. $prop = array();
  18650. $opt = array();
  18651. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18652. $prop['readonly'] = true;
  18653. }
  18654. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18655. $name = $tag['attribute']['name'];
  18656. } else {
  18657. break;
  18658. }
  18659. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18660. $opt['v'] = $tag['attribute']['value'];
  18661. }
  18662. if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) {
  18663. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  18664. } else {
  18665. $w = 40;
  18666. }
  18667. if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) {
  18668. $h = intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize);
  18669. } else {
  18670. $h = 10;
  18671. }
  18672. $prop['multiline'] = 'true';
  18673. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18674. break;
  18675. }
  18676. case 'select': {
  18677. $h = $this->getCellHeight($this->FontSize);
  18678. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18679. $h *= ($tag['attribute']['size'] + 1);
  18680. }
  18681. $prop = array();
  18682. $opt = array();
  18683. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18684. $name = $tag['attribute']['name'];
  18685. } else {
  18686. break;
  18687. }
  18688. $w = 0;
  18689. if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) {
  18690. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  18691. $values = array();
  18692. foreach ($options as $val) {
  18693. if (strpos($val, '#!TaB!#') !== false) {
  18694. $opts = explode('#!TaB!#', $val);
  18695. $values[] = $opts;
  18696. $w = max($w, $this->GetStringWidth($opts[1]));
  18697. } else {
  18698. $values[] = $val;
  18699. $w = max($w, $this->GetStringWidth($val));
  18700. }
  18701. }
  18702. } else {
  18703. break;
  18704. }
  18705. $w *= 2;
  18706. if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  18707. $prop['multipleSelection'] = 'true';
  18708. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18709. } else {
  18710. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18711. }
  18712. break;
  18713. }
  18714. case 'tcpdf': {
  18715. if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  18716. // Special tag used to call TCPDF methods
  18717. if (isset($tag['attribute']['method'])) {
  18718. $tcpdf_method = $tag['attribute']['method'];
  18719. if (method_exists($this, $tcpdf_method)) {
  18720. if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
  18721. $params = $this->unserializeTCPDFtagParameters($tag['attribute']['params']);
  18722. call_user_func_array(array($this, $tcpdf_method), $params);
  18723. } else {
  18724. $this->$tcpdf_method();
  18725. }
  18726. $this->newline = true;
  18727. }
  18728. }
  18729. }
  18730. break;
  18731. }
  18732. default: {
  18733. break;
  18734. }
  18735. }
  18736. // define tags that support borders and background colors
  18737. $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  18738. if (in_array($tag['value'], $bordertags)) {
  18739. // set border
  18740. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  18741. }
  18742. if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  18743. $pba = $dom[$key]['attribute']['pagebreakafter'];
  18744. // check for pagebreak
  18745. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  18746. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18747. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18748. }
  18749. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  18750. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  18751. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18752. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18753. }
  18754. }
  18755. return $dom;
  18756. }
  18757. /**
  18758. * Process closing tags.
  18759. * @param $dom (array) html dom array
  18760. * @param $key (int) current element id
  18761. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  18762. * @param $maxbottomliney (int) maximum y value of current line
  18763. * @return $dom array
  18764. * @protected
  18765. */
  18766. protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
  18767. $tag = $dom[$key];
  18768. $parent = $dom[($dom[$key]['parent'])];
  18769. $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
  18770. $in_table_head = false;
  18771. // maximum x position (used to draw borders)
  18772. if ($this->rtl) {
  18773. $xmax = $this->w;
  18774. } else {
  18775. $xmax = 0;
  18776. }
  18777. if ($tag['block']) {
  18778. $hbz = 0; // distance from y to line bottom
  18779. $hb = 0; // vertical space between block tags
  18780. // calculate vertical space for block tags
  18781. if (isset($this->tagvspaces[$tag['value']][1]['h']) AND ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18782. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18783. } elseif (isset($parent['fontsize'])) {
  18784. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  18785. } else {
  18786. $pre_h = $this->getCellHeight($this->FontSize);
  18787. }
  18788. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18789. $cn = $this->tagvspaces[$tag['value']][1]['n'];
  18790. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18791. $cn = 0.6;
  18792. } else {
  18793. $cn = 1;
  18794. }
  18795. if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
  18796. $hb = 0;
  18797. } else {
  18798. $hb = ($cn * $pre_h);
  18799. }
  18800. if ($maxbottomliney > $this->PageBreakTrigger) {
  18801. $hbz = $this->getCellHeight($this->FontSize);
  18802. } elseif ($this->y < $maxbottomliney) {
  18803. $hbz = ($maxbottomliney - $this->y);
  18804. }
  18805. }
  18806. // Closing tag
  18807. switch($tag['value']) {
  18808. case 'tr': {
  18809. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  18810. if (!isset($parent['endy'])) {
  18811. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  18812. $parent['endy'] = $this->y;
  18813. }
  18814. if (!isset($parent['endpage'])) {
  18815. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  18816. $parent['endpage'] = $this->page;
  18817. }
  18818. if (!isset($parent['endcolumn'])) {
  18819. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  18820. $parent['endcolumn'] = $this->current_column;
  18821. }
  18822. // update row-spanned cells
  18823. if (isset($dom[$table_el]['rowspans'])) {
  18824. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18825. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  18826. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18827. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  18828. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  18829. } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  18830. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18831. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  18832. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  18833. }
  18834. }
  18835. }
  18836. // report new endy and endpage to the rowspanned cells
  18837. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18838. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18839. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  18840. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  18841. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  18842. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  18843. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  18844. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18845. }
  18846. }
  18847. // update remaining rowspanned cells
  18848. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18849. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18850. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  18851. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  18852. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  18853. }
  18854. }
  18855. }
  18856. $prev_page = $this->page;
  18857. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  18858. if ($this->num_columns > 1) {
  18859. if (($prev_page < $this->page)
  18860. AND ((($this->current_column == 0) AND ($dom[($dom[$key]['parent'])]['endcolumn'] == ($this->num_columns - 1)))
  18861. OR ($this->current_column == $dom[($dom[$key]['parent'])]['endcolumn']))) {
  18862. // page jump
  18863. $this->selectColumn(0);
  18864. $dom[($dom[$key]['parent'])]['endcolumn'] = 0;
  18865. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  18866. } else {
  18867. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  18868. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  18869. }
  18870. } else {
  18871. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  18872. }
  18873. if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  18874. $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  18875. } elseif (isset($dom[$table_el]['border-spacing'])) {
  18876. $this->y += $dom[$table_el]['border-spacing']['V'];
  18877. }
  18878. $this->Ln(0, $cell);
  18879. if ($this->current_column == $parent['startcolumn']) {
  18880. $this->x = $parent['startx'];
  18881. }
  18882. // account for booklet mode
  18883. if ($this->page > $parent['startpage']) {
  18884. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  18885. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  18886. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  18887. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  18888. }
  18889. }
  18890. break;
  18891. }
  18892. case 'tablehead':
  18893. // closing tag used for the thead part
  18894. $in_table_head = true;
  18895. $this->inthead = false;
  18896. case 'table': {
  18897. $table_el = $parent;
  18898. // set default border
  18899. if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  18900. // set default border
  18901. $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
  18902. } else {
  18903. $border = 0;
  18904. }
  18905. $default_border = $border;
  18906. // fix bottom line alignment of last line before page break
  18907. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  18908. // update row-spanned cells
  18909. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  18910. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  18911. if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
  18912. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  18913. }
  18914. if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
  18915. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  18916. }
  18917. }
  18918. }
  18919. if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  18920. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  18921. $dom[$prevtrkey]['endy'] = $pgendy;
  18922. // update row-spanned cells
  18923. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  18924. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  18925. if (($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  18926. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  18927. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  18928. }
  18929. }
  18930. }
  18931. }
  18932. $prevtrkey = $trkey;
  18933. $table_el = $dom[($dom[$key]['parent'])];
  18934. }
  18935. // for each row
  18936. if (count($table_el['trids']) > 0) {
  18937. unset($xmax);
  18938. }
  18939. foreach ($table_el['trids'] as $j => $trkey) {
  18940. $parent = $dom[$trkey];
  18941. if (!isset($xmax)) {
  18942. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  18943. }
  18944. // for each cell on the row
  18945. foreach ($parent['cellpos'] as $k => $cellpos) {
  18946. if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  18947. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  18948. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  18949. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  18950. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  18951. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  18952. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  18953. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  18954. } else {
  18955. $endy = $parent['endy'];
  18956. $startpage = $parent['startpage'];
  18957. $endpage = $parent['endpage'];
  18958. $startcolumn = $parent['startcolumn'];
  18959. $endcolumn = $parent['endcolumn'];
  18960. }
  18961. if ($this->num_columns == 0) {
  18962. $this->num_columns = 1;
  18963. }
  18964. if (isset($cellpos['border'])) {
  18965. $border = $cellpos['border'];
  18966. }
  18967. if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  18968. $this->SetFillColorArray($cellpos['bgcolor']);
  18969. $fill = true;
  18970. } else {
  18971. $fill = false;
  18972. }
  18973. $x = $cellpos['startx'];
  18974. $y = $parent['starty'];
  18975. $starty = $y;
  18976. $w = abs($cellpos['endx'] - $cellpos['startx']);
  18977. // get border modes
  18978. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  18979. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  18980. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  18981. // design borders around HTML cells.
  18982. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  18983. $ccode = '';
  18984. $this->setPage($page);
  18985. if ($this->num_columns < 2) {
  18986. // single-column mode
  18987. $this->x = $x;
  18988. $this->y = $this->tMargin;
  18989. }
  18990. // account for margin changes
  18991. if ($page > $startpage) {
  18992. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  18993. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  18994. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  18995. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  18996. }
  18997. }
  18998. if ($startpage == $endpage) { // single page
  18999. $deltacol = 0;
  19000. $deltath = 0;
  19001. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19002. $this->selectColumn($column);
  19003. if ($startcolumn == $endcolumn) { // single column
  19004. $cborder = $border;
  19005. $h = $endy - $parent['starty'];
  19006. $this->y = $y;
  19007. $this->x = $x;
  19008. } elseif ($column == $startcolumn) { // first column
  19009. $cborder = $border_start;
  19010. $this->y = $starty;
  19011. $this->x = $x;
  19012. $h = $this->h - $this->y - $this->bMargin;
  19013. if ($this->rtl) {
  19014. $deltacol = $this->x + $this->rMargin - $this->w;
  19015. } else {
  19016. $deltacol = $this->x - $this->lMargin;
  19017. }
  19018. } elseif ($column == $endcolumn) { // end column
  19019. $cborder = $border_end;
  19020. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19021. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19022. }
  19023. $this->x += $deltacol;
  19024. $h = $endy - $this->y;
  19025. } else { // middle column
  19026. $cborder = $border_middle;
  19027. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19028. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19029. }
  19030. $this->x += $deltacol;
  19031. $h = $this->h - $this->y - $this->bMargin;
  19032. }
  19033. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19034. } // end for each column
  19035. } elseif ($page == $startpage) { // first page
  19036. $deltacol = 0;
  19037. $deltath = 0;
  19038. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19039. $this->selectColumn($column);
  19040. if ($column == $startcolumn) { // first column
  19041. $cborder = $border_start;
  19042. $this->y = $starty;
  19043. $this->x = $x;
  19044. $h = $this->h - $this->y - $this->bMargin;
  19045. if ($this->rtl) {
  19046. $deltacol = $this->x + $this->rMargin - $this->w;
  19047. } else {
  19048. $deltacol = $this->x - $this->lMargin;
  19049. }
  19050. } else { // middle column
  19051. $cborder = $border_middle;
  19052. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19053. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19054. }
  19055. $this->x += $deltacol;
  19056. $h = $this->h - $this->y - $this->bMargin;
  19057. }
  19058. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19059. } // end for each column
  19060. } elseif ($page == $endpage) { // last page
  19061. $deltacol = 0;
  19062. $deltath = 0;
  19063. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19064. $this->selectColumn($column);
  19065. if ($column == $endcolumn) { // end column
  19066. $cborder = $border_end;
  19067. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19068. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19069. }
  19070. $this->x += $deltacol;
  19071. $h = $endy - $this->y;
  19072. } else { // middle column
  19073. $cborder = $border_middle;
  19074. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19075. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19076. }
  19077. $this->x += $deltacol;
  19078. $h = $this->h - $this->y - $this->bMargin;
  19079. }
  19080. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19081. } // end for each column
  19082. } else { // middle page
  19083. $deltacol = 0;
  19084. $deltath = 0;
  19085. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19086. $this->selectColumn($column);
  19087. $cborder = $border_middle;
  19088. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19089. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19090. }
  19091. $this->x += $deltacol;
  19092. $h = $this->h - $this->y - $this->bMargin;
  19093. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19094. } // end for each column
  19095. }
  19096. if (!empty($cborder) OR !empty($fill)) {
  19097. $offsetlen = strlen($ccode);
  19098. // draw border and fill
  19099. if ($this->inxobj) {
  19100. // we are inside an XObject template
  19101. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19102. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19103. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19104. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19105. } else {
  19106. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19107. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19108. }
  19109. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19110. $pstart = substr($pagebuff, 0, $pagemark);
  19111. $pend = substr($pagebuff, $pagemark);
  19112. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19113. } else {
  19114. // draw border and fill
  19115. if (end($this->transfmrk[$this->page]) !== false) {
  19116. $pagemarkkey = key($this->transfmrk[$this->page]);
  19117. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19118. } elseif ($this->InFooter) {
  19119. $pagemark = $this->footerpos[$this->page];
  19120. } else {
  19121. $pagemark = $this->intmrk[$this->page];
  19122. }
  19123. $pagebuff = $this->getPageBuffer($this->page);
  19124. $pstart = substr($pagebuff, 0, $pagemark);
  19125. $pend = substr($pagebuff, $pagemark);
  19126. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19127. }
  19128. }
  19129. } // end for each page
  19130. // restore default border
  19131. $border = $default_border;
  19132. } // end for each cell on the row
  19133. if (isset($table_el['attribute']['cellspacing'])) {
  19134. $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  19135. } elseif (isset($table_el['border-spacing'])) {
  19136. $this->y += $table_el['border-spacing']['V'];
  19137. }
  19138. $this->Ln(0, $cell);
  19139. $this->x = $parent['startx'];
  19140. if ($endpage > $startpage) {
  19141. if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19142. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  19143. } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19144. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  19145. }
  19146. }
  19147. }
  19148. if (!$in_table_head) { // we are not inside a thead section
  19149. $this->cell_padding = $table_el['old_cell_padding'];
  19150. // reset row height
  19151. $this->resetLastH();
  19152. if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
  19153. $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  19154. if (($plendiff > 0) AND ($plendiff < 60)) {
  19155. $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  19156. if (substr($pagediff, 0, 5) == 'BT /F') {
  19157. // the difference is only a font setting
  19158. $plendiff = 0;
  19159. }
  19160. }
  19161. if ($plendiff == 0) {
  19162. // remove last blank page
  19163. $this->deletePage($this->numpages);
  19164. }
  19165. }
  19166. if (isset($this->theadMargins['top'])) {
  19167. // restore top margin
  19168. $this->tMargin = $this->theadMargins['top'];
  19169. }
  19170. if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  19171. // reset main table header
  19172. $this->thead = '';
  19173. $this->theadMargins = array();
  19174. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  19175. }
  19176. }
  19177. $parent = $table_el;
  19178. break;
  19179. }
  19180. case 'a': {
  19181. $this->HREF = array();
  19182. break;
  19183. }
  19184. case 'sup': {
  19185. $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  19186. break;
  19187. }
  19188. case 'sub': {
  19189. $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
  19190. break;
  19191. }
  19192. case 'div': {
  19193. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19194. break;
  19195. }
  19196. case 'blockquote': {
  19197. if ($this->rtl) {
  19198. $this->rMargin -= $this->listindent;
  19199. } else {
  19200. $this->lMargin -= $this->listindent;
  19201. }
  19202. --$this->listindentlevel;
  19203. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19204. break;
  19205. }
  19206. case 'p': {
  19207. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19208. break;
  19209. }
  19210. case 'pre': {
  19211. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19212. $this->premode = false;
  19213. break;
  19214. }
  19215. case 'dl': {
  19216. --$this->listnum;
  19217. if ($this->listnum <= 0) {
  19218. $this->listnum = 0;
  19219. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19220. } else {
  19221. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19222. }
  19223. $this->resetLastH();
  19224. break;
  19225. }
  19226. case 'dt': {
  19227. $this->lispacer = '';
  19228. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19229. break;
  19230. }
  19231. case 'dd': {
  19232. $this->lispacer = '';
  19233. if ($this->rtl) {
  19234. $this->rMargin -= $this->listindent;
  19235. } else {
  19236. $this->lMargin -= $this->listindent;
  19237. }
  19238. --$this->listindentlevel;
  19239. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19240. break;
  19241. }
  19242. case 'ul':
  19243. case 'ol': {
  19244. --$this->listnum;
  19245. $this->lispacer = '';
  19246. if ($this->rtl) {
  19247. $this->rMargin -= $this->listindent;
  19248. } else {
  19249. $this->lMargin -= $this->listindent;
  19250. }
  19251. --$this->listindentlevel;
  19252. if ($this->listnum <= 0) {
  19253. $this->listnum = 0;
  19254. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19255. } else {
  19256. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19257. }
  19258. $this->resetLastH();
  19259. break;
  19260. }
  19261. case 'li': {
  19262. $this->lispacer = '';
  19263. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19264. break;
  19265. }
  19266. case 'h1':
  19267. case 'h2':
  19268. case 'h3':
  19269. case 'h4':
  19270. case 'h5':
  19271. case 'h6': {
  19272. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19273. break;
  19274. }
  19275. // Form fields (since 4.8.000 - 2009-09-07)
  19276. case 'form': {
  19277. $this->form_action = '';
  19278. $this->form_enctype = 'application/x-www-form-urlencoded';
  19279. break;
  19280. }
  19281. default : {
  19282. break;
  19283. }
  19284. }
  19285. // draw border and background (if any)
  19286. $this->drawHTMLTagBorder($parent, $xmax);
  19287. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  19288. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  19289. // check for pagebreak
  19290. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  19291. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19292. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19293. }
  19294. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  19295. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  19296. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19297. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19298. }
  19299. }
  19300. $this->tmprtl = false;
  19301. return $dom;
  19302. }
  19303. /**
  19304. * Add vertical spaces if needed.
  19305. * @param $hbz (string) Distance between current y and line bottom.
  19306. * @param $hb (string) The height of the break.
  19307. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  19308. * @param $firsttag (boolean) set to true when the tag is the first.
  19309. * @param $lasttag (boolean) set to true when the tag is the last.
  19310. * @protected
  19311. */
  19312. protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
  19313. if ($firsttag) {
  19314. $this->Ln(0, $cell);
  19315. $this->htmlvspace = 0;
  19316. return;
  19317. }
  19318. if ($lasttag) {
  19319. $this->Ln($hbz, $cell);
  19320. $this->htmlvspace = 0;
  19321. return;
  19322. }
  19323. if ($hb < $this->htmlvspace) {
  19324. $hd = 0;
  19325. } else {
  19326. $hd = $hb - $this->htmlvspace;
  19327. $this->htmlvspace = $hb;
  19328. }
  19329. $this->Ln(($hbz + $hd), $cell);
  19330. }
  19331. /**
  19332. * Return the starting coordinates to draw an html border
  19333. * @return array containing top-left border coordinates
  19334. * @protected
  19335. * @since 5.7.000 (2010-08-03)
  19336. */
  19337. protected function getBorderStartPosition() {
  19338. if ($this->rtl) {
  19339. $xmax = $this->lMargin;
  19340. } else {
  19341. $xmax = $this->w - $this->rMargin;
  19342. }
  19343. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
  19344. }
  19345. /**
  19346. * Draw an HTML block border and fill
  19347. * @param $tag (array) array of tag properties.
  19348. * @param $xmax (int) end X coordinate for border.
  19349. * @protected
  19350. * @since 5.7.000 (2010-08-03)
  19351. */
  19352. protected function drawHTMLTagBorder($tag, $xmax) {
  19353. if (!isset($tag['borderposition'])) {
  19354. // nothing to draw
  19355. return;
  19356. }
  19357. $prev_x = $this->x;
  19358. $prev_y = $this->y;
  19359. $prev_lasth = $this->lasth;
  19360. $border = 0;
  19361. $fill = false;
  19362. $this->lasth = 0;
  19363. if (isset($tag['border']) AND !empty($tag['border'])) {
  19364. // get border style
  19365. $border = $tag['border'];
  19366. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  19367. // border for table header
  19368. $border = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19369. }
  19370. }
  19371. if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  19372. // get background color
  19373. $old_bgcolor = $this->bgcolor;
  19374. $this->SetFillColorArray($tag['bgcolor']);
  19375. $fill = true;
  19376. }
  19377. if (!$border AND !$fill) {
  19378. // nothing to draw
  19379. return;
  19380. }
  19381. if (isset($tag['attribute']['cellspacing'])) {
  19382. $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  19383. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  19384. } elseif (isset($tag['border-spacing'])) {
  19385. $cellspacing = $tag['border-spacing'];
  19386. } else {
  19387. $cellspacing = array('H' => 0, 'V' => 0);
  19388. }
  19389. if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  19390. // draw the border externally respect the sqare edge.
  19391. $border['mode'] = 'ext';
  19392. }
  19393. if ($this->rtl) {
  19394. if ($xmax >= $tag['borderposition']['x']) {
  19395. $xmax = $tag['borderposition']['xmax'];
  19396. }
  19397. $w = ($tag['borderposition']['x'] - $xmax);
  19398. } else {
  19399. if ($xmax <= $tag['borderposition']['x']) {
  19400. $xmax = $tag['borderposition']['xmax'];
  19401. }
  19402. $w = ($xmax - $tag['borderposition']['x']);
  19403. }
  19404. if ($w <= 0) {
  19405. return;
  19406. }
  19407. $w += $cellspacing['H'];
  19408. $startpage = $tag['borderposition']['page'];
  19409. $startcolumn = $tag['borderposition']['column'];
  19410. $x = $tag['borderposition']['x'];
  19411. $y = $tag['borderposition']['y'];
  19412. $endpage = $this->page;
  19413. $starty = $tag['borderposition']['y'] - $cellspacing['V'];
  19414. $currentY = $this->y;
  19415. $this->x = $x;
  19416. // get latest column
  19417. $endcolumn = $this->current_column;
  19418. if ($this->num_columns == 0) {
  19419. $this->num_columns = 1;
  19420. }
  19421. // get border modes
  19422. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19423. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19424. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19425. // temporary disable page regions
  19426. $temp_page_regions = $this->page_regions;
  19427. $this->page_regions = array();
  19428. // design borders around HTML cells.
  19429. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19430. $ccode = '';
  19431. $this->setPage($page);
  19432. if ($this->num_columns < 2) {
  19433. // single-column mode
  19434. $this->x = $x;
  19435. $this->y = $this->tMargin;
  19436. }
  19437. // account for margin changes
  19438. if ($page > $startpage) {
  19439. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19440. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19441. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19442. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19443. }
  19444. }
  19445. if ($startpage == $endpage) {
  19446. // single page
  19447. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19448. $this->selectColumn($column);
  19449. if ($startcolumn == $endcolumn) { // single column
  19450. $cborder = $border;
  19451. $h = ($currentY - $y) + $cellspacing['V'];
  19452. $this->y = $starty;
  19453. } elseif ($column == $startcolumn) { // first column
  19454. $cborder = $border_start;
  19455. $this->y = $starty;
  19456. $h = $this->h - $this->y - $this->bMargin;
  19457. } elseif ($column == $endcolumn) { // end column
  19458. $cborder = $border_end;
  19459. $h = $currentY - $this->y;
  19460. } else { // middle column
  19461. $cborder = $border_middle;
  19462. $h = $this->h - $this->y - $this->bMargin;
  19463. }
  19464. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19465. } // end for each column
  19466. } elseif ($page == $startpage) { // first page
  19467. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19468. $this->selectColumn($column);
  19469. if ($column == $startcolumn) { // first column
  19470. $cborder = $border_start;
  19471. $this->y = $starty;
  19472. $h = $this->h - $this->y - $this->bMargin;
  19473. } else { // middle column
  19474. $cborder = $border_middle;
  19475. $h = $this->h - $this->y - $this->bMargin;
  19476. }
  19477. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19478. } // end for each column
  19479. } elseif ($page == $endpage) { // last page
  19480. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19481. $this->selectColumn($column);
  19482. if ($column == $endcolumn) {
  19483. // end column
  19484. $cborder = $border_end;
  19485. $h = $currentY - $this->y;
  19486. } else {
  19487. // middle column
  19488. $cborder = $border_middle;
  19489. $h = $this->h - $this->y - $this->bMargin;
  19490. }
  19491. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19492. } // end for each column
  19493. } else { // middle page
  19494. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19495. $this->selectColumn($column);
  19496. $cborder = $border_middle;
  19497. $h = $this->h - $this->y - $this->bMargin;
  19498. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19499. } // end for each column
  19500. }
  19501. if ($cborder OR $fill) {
  19502. $offsetlen = strlen($ccode);
  19503. // draw border and fill
  19504. if ($this->inxobj) {
  19505. // we are inside an XObject template
  19506. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19507. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19508. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19509. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19510. } else {
  19511. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19512. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19513. }
  19514. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19515. $pstart = substr($pagebuff, 0, $pagemark);
  19516. $pend = substr($pagebuff, $pagemark);
  19517. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19518. } else {
  19519. if (end($this->transfmrk[$this->page]) !== false) {
  19520. $pagemarkkey = key($this->transfmrk[$this->page]);
  19521. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19522. } elseif ($this->InFooter) {
  19523. $pagemark = $this->footerpos[$this->page];
  19524. } else {
  19525. $pagemark = $this->intmrk[$this->page];
  19526. }
  19527. $pagebuff = $this->getPageBuffer($this->page);
  19528. $pstart = substr($pagebuff, 0, $pagemark);
  19529. $pend = substr($pagebuff, $pagemark);
  19530. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19531. $this->bordermrk[$this->page] += $offsetlen;
  19532. $this->cntmrk[$this->page] += $offsetlen;
  19533. }
  19534. }
  19535. } // end for each page
  19536. // restore page regions
  19537. $this->page_regions = $temp_page_regions;
  19538. if (isset($old_bgcolor)) {
  19539. // restore background color
  19540. $this->SetFillColorArray($old_bgcolor);
  19541. }
  19542. // restore pointer position
  19543. $this->x = $prev_x;
  19544. $this->y = $prev_y;
  19545. $this->lasth = $prev_lasth;
  19546. }
  19547. /**
  19548. * Set the default bullet to be used as LI bullet symbol
  19549. * @param $symbol (string) character or string to be used (legal values are: '' = automatic, '!' = auto bullet, '#' = auto numbering, 'disc', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek', 'img|type|width|height|image.ext')
  19550. * @public
  19551. * @since 4.0.028 (2008-09-26)
  19552. */
  19553. public function setLIsymbol($symbol='!') {
  19554. // check for custom image symbol
  19555. if (substr($symbol, 0, 4) == 'img|') {
  19556. $this->lisymbol = $symbol;
  19557. return;
  19558. }
  19559. $symbol = strtolower($symbol);
  19560. $valid_symbols = array('!', '#', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek');
  19561. if (in_array($symbol, $valid_symbols)) {
  19562. $this->lisymbol = $symbol;
  19563. } else {
  19564. $this->lisymbol = '';
  19565. }
  19566. }
  19567. /**
  19568. * Set the booklet mode for double-sided pages.
  19569. * @param $booklet (boolean) true set the booklet mode on, false otherwise.
  19570. * @param $inner (float) Inner page margin.
  19571. * @param $outer (float) Outer page margin.
  19572. * @public
  19573. * @since 4.2.000 (2008-10-29)
  19574. */
  19575. public function SetBooklet($booklet=true, $inner=-1, $outer=-1) {
  19576. $this->booklet = $booklet;
  19577. if ($inner >= 0) {
  19578. $this->lMargin = $inner;
  19579. }
  19580. if ($outer >= 0) {
  19581. $this->rMargin = $outer;
  19582. }
  19583. }
  19584. /**
  19585. * Swap the left and right margins.
  19586. * @param $reverse (boolean) if true swap left and right margins.
  19587. * @protected
  19588. * @since 4.2.000 (2008-10-29)
  19589. */
  19590. protected function swapMargins($reverse=true) {
  19591. if ($reverse) {
  19592. // swap left and right margins
  19593. $mtemp = $this->original_lMargin;
  19594. $this->original_lMargin = $this->original_rMargin;
  19595. $this->original_rMargin = $mtemp;
  19596. $deltam = $this->original_lMargin - $this->original_rMargin;
  19597. $this->lMargin += $deltam;
  19598. $this->rMargin -= $deltam;
  19599. }
  19600. }
  19601. /**
  19602. * Set the vertical spaces for HTML tags.
  19603. * The array must have the following structure (example):
  19604. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  19605. * The first array level contains the tag names,
  19606. * the second level contains 0 for opening tags or 1 for closing tags,
  19607. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  19608. * If the h parameter is not specified, default values are used.
  19609. * @param $tagvs (array) array of tags and relative vertical spaces.
  19610. * @public
  19611. * @since 4.2.001 (2008-10-30)
  19612. */
  19613. public function setHtmlVSpace($tagvs) {
  19614. $this->tagvspaces = $tagvs;
  19615. }
  19616. /**
  19617. * Set custom width for list indentation.
  19618. * @param $width (float) width of the indentation. Use negative value to disable it.
  19619. * @public
  19620. * @since 4.2.007 (2008-11-12)
  19621. */
  19622. public function setListIndentWidth($width) {
  19623. return $this->customlistindent = floatval($width);
  19624. }
  19625. /**
  19626. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  19627. * @param $isopen (boolean) if true keeps the top/bottom border open for the cell sides that cross the page.
  19628. * @public
  19629. * @since 4.2.010 (2008-11-14)
  19630. */
  19631. public function setOpenCell($isopen) {
  19632. $this->opencell = $isopen;
  19633. }
  19634. /**
  19635. * Set the color and font style for HTML links.
  19636. * @param $color (array) RGB array of colors
  19637. * @param $fontstyle (string) additional font styles to add
  19638. * @public
  19639. * @since 4.4.003 (2008-12-09)
  19640. */
  19641. public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
  19642. $this->htmlLinkColorArray = $color;
  19643. $this->htmlLinkFontStyle = $fontstyle;
  19644. }
  19645. /**
  19646. * Convert HTML string containing value and unit of measure to user's units or points.
  19647. * @param $htmlval (string) String containing values and unit.
  19648. * @param $refsize (string) Reference value in points.
  19649. * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  19650. * @param $points (boolean) If true returns points, otherwise returns value in user's units.
  19651. * @return float value in user's unit or point if $points=true
  19652. * @public
  19653. * @since 4.4.004 (2008-12-10)
  19654. */
  19655. public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
  19656. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  19657. $retval = 0;
  19658. $value = 0;
  19659. $unit = 'px';
  19660. if ($points) {
  19661. $k = 1;
  19662. } else {
  19663. $k = $this->k;
  19664. }
  19665. if (in_array($defaultunit, $supportedunits)) {
  19666. $unit = $defaultunit;
  19667. }
  19668. if (is_numeric($htmlval)) {
  19669. $value = floatval($htmlval);
  19670. } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
  19671. $value = floatval($mnum[1]);
  19672. if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
  19673. if (in_array($munit[1], $supportedunits)) {
  19674. $unit = $munit[1];
  19675. }
  19676. }
  19677. }
  19678. switch ($unit) {
  19679. // percentage
  19680. case '%': {
  19681. $retval = (($value * $refsize) / 100);
  19682. break;
  19683. }
  19684. // relative-size
  19685. case 'em': {
  19686. $retval = ($value * $refsize);
  19687. break;
  19688. }
  19689. // height of lower case 'x' (about half the font-size)
  19690. case 'ex': {
  19691. $retval = ($value * ($refsize / 2));
  19692. break;
  19693. }
  19694. // absolute-size
  19695. case 'in': {
  19696. $retval = (($value * $this->dpi) / $k);
  19697. break;
  19698. }
  19699. // centimeters
  19700. case 'cm': {
  19701. $retval = (($value / 2.54 * $this->dpi) / $k);
  19702. break;
  19703. }
  19704. // millimeters
  19705. case 'mm': {
  19706. $retval = (($value / 25.4 * $this->dpi) / $k);
  19707. break;
  19708. }
  19709. // one pica is 12 points
  19710. case 'pc': {
  19711. $retval = (($value * 12) / $k);
  19712. break;
  19713. }
  19714. // points
  19715. case 'pt': {
  19716. $retval = ($value / $k);
  19717. break;
  19718. }
  19719. // pixels
  19720. case 'px': {
  19721. $retval = $this->pixelsToUnits($value);
  19722. if ($points) {
  19723. $retval *= $this->k;
  19724. }
  19725. break;
  19726. }
  19727. }
  19728. return $retval;
  19729. }
  19730. /**
  19731. * Output an HTML list bullet or ordered item symbol
  19732. * @param $listdepth (int) list nesting level
  19733. * @param $listtype (string) type of list
  19734. * @param $size (float) current font size
  19735. * @protected
  19736. * @since 4.4.004 (2008-12-10)
  19737. */
  19738. protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
  19739. if ($this->state != 2) {
  19740. return;
  19741. }
  19742. $size /= $this->k;
  19743. $fill = '';
  19744. $bgcolor = $this->bgcolor;
  19745. $color = $this->fgcolor;
  19746. $strokecolor = $this->strokecolor;
  19747. $width = 0;
  19748. $textitem = '';
  19749. $tmpx = $this->x;
  19750. $lspace = $this->GetStringWidth(' ');
  19751. if ($listtype == '^') {
  19752. // special symbol used for avoid justification of rect bullet
  19753. $this->lispacer = '';
  19754. return;
  19755. } elseif ($listtype == '!') {
  19756. // set default list type for unordered list
  19757. $deftypes = array('disc', 'circle', 'square');
  19758. $listtype = $deftypes[($listdepth - 1) % 3];
  19759. } elseif ($listtype == '#') {
  19760. // set default list type for ordered list
  19761. $listtype = 'decimal';
  19762. } elseif (substr($listtype, 0, 4) == 'img|') {
  19763. // custom image type ('img|type|width|height|image.ext')
  19764. $img = explode('|', $listtype);
  19765. $listtype = 'img';
  19766. }
  19767. switch ($listtype) {
  19768. // unordered types
  19769. case 'none': {
  19770. break;
  19771. }
  19772. case 'disc': {
  19773. $r = $size / 6;
  19774. $lspace += (2 * $r);
  19775. if ($this->rtl) {
  19776. $this->x += $lspace;
  19777. } else {
  19778. $this->x -= $lspace;
  19779. }
  19780. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
  19781. break;
  19782. }
  19783. case 'circle': {
  19784. $r = $size / 6;
  19785. $lspace += (2 * $r);
  19786. if ($this->rtl) {
  19787. $this->x += $lspace;
  19788. } else {
  19789. $this->x -= $lspace;
  19790. }
  19791. $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
  19792. $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
  19793. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
  19794. $this->_out($prev_line_style); // restore line settings
  19795. break;
  19796. }
  19797. case 'square': {
  19798. $l = $size / 3;
  19799. $lspace += $l;
  19800. if ($this->rtl) {;
  19801. $this->x += $lspace;
  19802. } else {
  19803. $this->x -= $lspace;
  19804. }
  19805. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  19806. break;
  19807. }
  19808. case 'img': {
  19809. // 1=>type, 2=>width, 3=>height, 4=>image.ext
  19810. $lspace += $img[2];
  19811. if ($this->rtl) {;
  19812. $this->x += $lspace;
  19813. } else {
  19814. $this->x -= $lspace;
  19815. }
  19816. $imgtype = strtolower($img[1]);
  19817. $prev_y = $this->y;
  19818. switch ($imgtype) {
  19819. case 'svg': {
  19820. $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
  19821. break;
  19822. }
  19823. case 'ai':
  19824. case 'eps': {
  19825. $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
  19826. break;
  19827. }
  19828. default: {
  19829. $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);
  19830. break;
  19831. }
  19832. }
  19833. $this->y = $prev_y;
  19834. break;
  19835. }
  19836. // ordered types
  19837. // $this->listcount[$this->listnum];
  19838. // $textitem
  19839. case '1':
  19840. case 'decimal': {
  19841. $textitem = $this->listcount[$this->listnum];
  19842. break;
  19843. }
  19844. case 'decimal-leading-zero': {
  19845. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  19846. break;
  19847. }
  19848. case 'i':
  19849. case 'lower-roman': {
  19850. $textitem = strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]));
  19851. break;
  19852. }
  19853. case 'I':
  19854. case 'upper-roman': {
  19855. $textitem = TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]);
  19856. break;
  19857. }
  19858. case 'a':
  19859. case 'lower-alpha':
  19860. case 'lower-latin': {
  19861. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  19862. break;
  19863. }
  19864. case 'A':
  19865. case 'upper-alpha':
  19866. case 'upper-latin': {
  19867. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  19868. break;
  19869. }
  19870. case 'lower-greek': {
  19871. $textitem = TCPDF_FONTS::unichr((945 + $this->listcount[$this->listnum] - 1), $this->isunicode);
  19872. break;
  19873. }
  19874. /*
  19875. // Types to be implemented (special handling)
  19876. case 'hebrew': {
  19877. break;
  19878. }
  19879. case 'armenian': {
  19880. break;
  19881. }
  19882. case 'georgian': {
  19883. break;
  19884. }
  19885. case 'cjk-ideographic': {
  19886. break;
  19887. }
  19888. case 'hiragana': {
  19889. break;
  19890. }
  19891. case 'katakana': {
  19892. break;
  19893. }
  19894. case 'hiragana-iroha': {
  19895. break;
  19896. }
  19897. case 'katakana-iroha': {
  19898. break;
  19899. }
  19900. */
  19901. default: {
  19902. $textitem = $this->listcount[$this->listnum];
  19903. }
  19904. }
  19905. if (!TCPDF_STATIC::empty_string($textitem)) {
  19906. // Check whether we need a new page or new column
  19907. $prev_y = $this->y;
  19908. $h = $this->getCellHeight($this->FontSize);
  19909. if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
  19910. $tmpx = $this->x;
  19911. }
  19912. // print ordered item
  19913. if ($this->rtl) {
  19914. $textitem = '.'.$textitem;
  19915. } else {
  19916. $textitem = $textitem.'.';
  19917. }
  19918. $lspace += $this->GetStringWidth($textitem);
  19919. if ($this->rtl) {
  19920. $this->x += $lspace;
  19921. } else {
  19922. $this->x -= $lspace;
  19923. }
  19924. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  19925. }
  19926. $this->x = $tmpx;
  19927. $this->lispacer = '^';
  19928. // restore colors
  19929. $this->SetFillColorArray($bgcolor);
  19930. $this->SetDrawColorArray($strokecolor);
  19931. $this->SettextColorArray($color);
  19932. }
  19933. /**
  19934. * Returns current graphic variables as array.
  19935. * @return array of graphic variables
  19936. * @protected
  19937. * @since 4.2.010 (2008-11-14)
  19938. */
  19939. protected function getGraphicVars() {
  19940. $grapvars = array(
  19941. 'FontFamily' => $this->FontFamily,
  19942. 'FontStyle' => $this->FontStyle,
  19943. 'FontSizePt' => $this->FontSizePt,
  19944. 'rMargin' => $this->rMargin,
  19945. 'lMargin' => $this->lMargin,
  19946. 'cell_padding' => $this->cell_padding,
  19947. 'cell_margin' => $this->cell_margin,
  19948. 'LineWidth' => $this->LineWidth,
  19949. 'linestyleWidth' => $this->linestyleWidth,
  19950. 'linestyleCap' => $this->linestyleCap,
  19951. 'linestyleJoin' => $this->linestyleJoin,
  19952. 'linestyleDash' => $this->linestyleDash,
  19953. 'textrendermode' => $this->textrendermode,
  19954. 'textstrokewidth' => $this->textstrokewidth,
  19955. 'DrawColor' => $this->DrawColor,
  19956. 'FillColor' => $this->FillColor,
  19957. 'TextColor' => $this->TextColor,
  19958. 'ColorFlag' => $this->ColorFlag,
  19959. 'bgcolor' => $this->bgcolor,
  19960. 'fgcolor' => $this->fgcolor,
  19961. 'htmlvspace' => $this->htmlvspace,
  19962. 'listindent' => $this->listindent,
  19963. 'listindentlevel' => $this->listindentlevel,
  19964. 'listnum' => $this->listnum,
  19965. 'listordered' => $this->listordered,
  19966. 'listcount' => $this->listcount,
  19967. 'lispacer' => $this->lispacer,
  19968. 'cell_height_ratio' => $this->cell_height_ratio,
  19969. 'font_stretching' => $this->font_stretching,
  19970. 'font_spacing' => $this->font_spacing,
  19971. 'alpha' => $this->alpha,
  19972. // extended
  19973. 'lasth' => $this->lasth,
  19974. 'tMargin' => $this->tMargin,
  19975. 'bMargin' => $this->bMargin,
  19976. 'AutoPageBreak' => $this->AutoPageBreak,
  19977. 'PageBreakTrigger' => $this->PageBreakTrigger,
  19978. 'x' => $this->x,
  19979. 'y' => $this->y,
  19980. 'w' => $this->w,
  19981. 'h' => $this->h,
  19982. 'wPt' => $this->wPt,
  19983. 'hPt' => $this->hPt,
  19984. 'fwPt' => $this->fwPt,
  19985. 'fhPt' => $this->fhPt,
  19986. 'page' => $this->page,
  19987. 'current_column' => $this->current_column,
  19988. 'num_columns' => $this->num_columns
  19989. );
  19990. return $grapvars;
  19991. }
  19992. /**
  19993. * Set graphic variables.
  19994. * @param $gvars (array) array of graphic variablesto restore
  19995. * @param $extended (boolean) if true restore extended graphic variables
  19996. * @protected
  19997. * @since 4.2.010 (2008-11-14)
  19998. */
  19999. protected function setGraphicVars($gvars, $extended=false) {
  20000. if ($this->state != 2) {
  20001. return;
  20002. }
  20003. $this->FontFamily = $gvars['FontFamily'];
  20004. $this->FontStyle = $gvars['FontStyle'];
  20005. $this->FontSizePt = $gvars['FontSizePt'];
  20006. $this->rMargin = $gvars['rMargin'];
  20007. $this->lMargin = $gvars['lMargin'];
  20008. $this->cell_padding = $gvars['cell_padding'];
  20009. $this->cell_margin = $gvars['cell_margin'];
  20010. $this->LineWidth = $gvars['LineWidth'];
  20011. $this->linestyleWidth = $gvars['linestyleWidth'];
  20012. $this->linestyleCap = $gvars['linestyleCap'];
  20013. $this->linestyleJoin = $gvars['linestyleJoin'];
  20014. $this->linestyleDash = $gvars['linestyleDash'];
  20015. $this->textrendermode = $gvars['textrendermode'];
  20016. $this->textstrokewidth = $gvars['textstrokewidth'];
  20017. $this->DrawColor = $gvars['DrawColor'];
  20018. $this->FillColor = $gvars['FillColor'];
  20019. $this->TextColor = $gvars['TextColor'];
  20020. $this->ColorFlag = $gvars['ColorFlag'];
  20021. $this->bgcolor = $gvars['bgcolor'];
  20022. $this->fgcolor = $gvars['fgcolor'];
  20023. $this->htmlvspace = $gvars['htmlvspace'];
  20024. $this->listindent = $gvars['listindent'];
  20025. $this->listindentlevel = $gvars['listindentlevel'];
  20026. $this->listnum = $gvars['listnum'];
  20027. $this->listordered = $gvars['listordered'];
  20028. $this->listcount = $gvars['listcount'];
  20029. $this->lispacer = $gvars['lispacer'];
  20030. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  20031. $this->font_stretching = $gvars['font_stretching'];
  20032. $this->font_spacing = $gvars['font_spacing'];
  20033. $this->alpha = $gvars['alpha'];
  20034. if ($extended) {
  20035. // restore extended values
  20036. $this->lasth = $gvars['lasth'];
  20037. $this->tMargin = $gvars['tMargin'];
  20038. $this->bMargin = $gvars['bMargin'];
  20039. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  20040. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  20041. $this->x = $gvars['x'];
  20042. $this->y = $gvars['y'];
  20043. $this->w = $gvars['w'];
  20044. $this->h = $gvars['h'];
  20045. $this->wPt = $gvars['wPt'];
  20046. $this->hPt = $gvars['hPt'];
  20047. $this->fwPt = $gvars['fwPt'];
  20048. $this->fhPt = $gvars['fhPt'];
  20049. $this->page = $gvars['page'];
  20050. $this->current_column = $gvars['current_column'];
  20051. $this->num_columns = $gvars['num_columns'];
  20052. }
  20053. $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  20054. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  20055. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  20056. }
  20057. }
  20058. /**
  20059. * Outputs the "save graphics state" operator 'q'
  20060. * @protected
  20061. */
  20062. protected function _outSaveGraphicsState() {
  20063. $this->_out('q');
  20064. }
  20065. /**
  20066. * Outputs the "restore graphics state" operator 'Q'
  20067. * @protected
  20068. */
  20069. protected function _outRestoreGraphicsState() {
  20070. $this->_out('Q');
  20071. }
  20072. /**
  20073. * Set buffer content (always append data).
  20074. * @param $data (string) data
  20075. * @protected
  20076. * @since 4.5.000 (2009-01-02)
  20077. */
  20078. protected function setBuffer($data) {
  20079. $this->bufferlen += strlen($data);
  20080. $this->buffer .= $data;
  20081. }
  20082. /**
  20083. * Replace the buffer content
  20084. * @param $data (string) data
  20085. * @protected
  20086. * @since 5.5.000 (2010-06-22)
  20087. */
  20088. protected function replaceBuffer($data) {
  20089. $this->bufferlen = strlen($data);
  20090. $this->buffer = $data;
  20091. }
  20092. /**
  20093. * Get buffer content.
  20094. * @return string buffer content
  20095. * @protected
  20096. * @since 4.5.000 (2009-01-02)
  20097. */
  20098. protected function getBuffer() {
  20099. return $this->buffer;
  20100. }
  20101. /**
  20102. * Set page buffer content.
  20103. * @param $page (int) page number
  20104. * @param $data (string) page data
  20105. * @param $append (boolean) if true append data, false replace.
  20106. * @protected
  20107. * @since 4.5.000 (2008-12-31)
  20108. */
  20109. protected function setPageBuffer($page, $data, $append=false) {
  20110. if ($append) {
  20111. $this->pages[$page] .= $data;
  20112. } else {
  20113. $this->pages[$page] = $data;
  20114. }
  20115. if ($append AND isset($this->pagelen[$page])) {
  20116. $this->pagelen[$page] += strlen($data);
  20117. } else {
  20118. $this->pagelen[$page] = strlen($data);
  20119. }
  20120. }
  20121. /**
  20122. * Get page buffer content.
  20123. * @param $page (int) page number
  20124. * @return string page buffer content or false in case of error
  20125. * @protected
  20126. * @since 4.5.000 (2008-12-31)
  20127. */
  20128. protected function getPageBuffer($page) {
  20129. if (isset($this->pages[$page])) {
  20130. return $this->pages[$page];
  20131. }
  20132. return false;
  20133. }
  20134. /**
  20135. * Set image buffer content.
  20136. * @param $image (string) image key
  20137. * @param $data (array) image data
  20138. * @return int image index number
  20139. * @protected
  20140. * @since 4.5.000 (2008-12-31)
  20141. */
  20142. protected function setImageBuffer($image, $data) {
  20143. if (($data['i'] = array_search($image, $this->imagekeys)) === FALSE) {
  20144. $this->imagekeys[$this->numimages] = $image;
  20145. $data['i'] = $this->numimages;
  20146. ++$this->numimages;
  20147. }
  20148. $this->images[$image] = $data;
  20149. return $data['i'];
  20150. }
  20151. /**
  20152. * Set image buffer content for a specified sub-key.
  20153. * @param $image (string) image key
  20154. * @param $key (string) image sub-key
  20155. * @param $data (array) image data
  20156. * @protected
  20157. * @since 4.5.000 (2008-12-31)
  20158. */
  20159. protected function setImageSubBuffer($image, $key, $data) {
  20160. if (!isset($this->images[$image])) {
  20161. $this->setImageBuffer($image, array());
  20162. }
  20163. $this->images[$image][$key] = $data;
  20164. }
  20165. /**
  20166. * Get image buffer content.
  20167. * @param $image (string) image key
  20168. * @return string image buffer content or false in case of error
  20169. * @protected
  20170. * @since 4.5.000 (2008-12-31)
  20171. */
  20172. protected function getImageBuffer($image) {
  20173. if (isset($this->images[$image])) {
  20174. return $this->images[$image];
  20175. }
  20176. return false;
  20177. }
  20178. /**
  20179. * Set font buffer content.
  20180. * @param $font (string) font key
  20181. * @param $data (array) font data
  20182. * @protected
  20183. * @since 4.5.000 (2009-01-02)
  20184. */
  20185. protected function setFontBuffer($font, $data) {
  20186. $this->fonts[$font] = $data;
  20187. if (!in_array($font, $this->fontkeys)) {
  20188. $this->fontkeys[] = $font;
  20189. // store object ID for current font
  20190. ++$this->n;
  20191. $this->font_obj_ids[$font] = $this->n;
  20192. $this->setFontSubBuffer($font, 'n', $this->n);
  20193. }
  20194. }
  20195. /**
  20196. * Set font buffer content.
  20197. * @param $font (string) font key
  20198. * @param $key (string) font sub-key
  20199. * @param $data (array) font data
  20200. * @protected
  20201. * @since 4.5.000 (2009-01-02)
  20202. */
  20203. protected function setFontSubBuffer($font, $key, $data) {
  20204. if (!isset($this->fonts[$font])) {
  20205. $this->setFontBuffer($font, array());
  20206. }
  20207. $this->fonts[$font][$key] = $data;
  20208. }
  20209. /**
  20210. * Get font buffer content.
  20211. * @param $font (string) font key
  20212. * @return string font buffer content or false in case of error
  20213. * @protected
  20214. * @since 4.5.000 (2009-01-02)
  20215. */
  20216. protected function getFontBuffer($font) {
  20217. if (isset($this->fonts[$font])) {
  20218. return $this->fonts[$font];
  20219. }
  20220. return false;
  20221. }
  20222. /**
  20223. * Move a page to a previous position.
  20224. * @param $frompage (int) number of the source page
  20225. * @param $topage (int) number of the destination page (must be less than $frompage)
  20226. * @return true in case of success, false in case of error.
  20227. * @public
  20228. * @since 4.5.000 (2009-01-02)
  20229. */
  20230. public function movePage($frompage, $topage) {
  20231. if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
  20232. return false;
  20233. }
  20234. if ($frompage == $this->page) {
  20235. // close the page before moving it
  20236. $this->endPage();
  20237. }
  20238. // move all page-related states
  20239. $tmppage = $this->getPageBuffer($frompage);
  20240. $tmppagedim = $this->pagedim[$frompage];
  20241. $tmppagelen = $this->pagelen[$frompage];
  20242. $tmpintmrk = $this->intmrk[$frompage];
  20243. $tmpbordermrk = $this->bordermrk[$frompage];
  20244. $tmpcntmrk = $this->cntmrk[$frompage];
  20245. $tmppageobjects = $this->pageobjects[$frompage];
  20246. if (isset($this->footerpos[$frompage])) {
  20247. $tmpfooterpos = $this->footerpos[$frompage];
  20248. }
  20249. if (isset($this->footerlen[$frompage])) {
  20250. $tmpfooterlen = $this->footerlen[$frompage];
  20251. }
  20252. if (isset($this->transfmrk[$frompage])) {
  20253. $tmptransfmrk = $this->transfmrk[$frompage];
  20254. }
  20255. if (isset($this->PageAnnots[$frompage])) {
  20256. $tmpannots = $this->PageAnnots[$frompage];
  20257. }
  20258. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20259. for ($i = $frompage; $i > $topage; --$i) {
  20260. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
  20261. --$this->pagegroups[$this->newpagegroup[$i]];
  20262. break;
  20263. }
  20264. }
  20265. for ($i = $topage; $i > 0; --$i) {
  20266. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
  20267. ++$this->pagegroups[$this->newpagegroup[$i]];
  20268. break;
  20269. }
  20270. }
  20271. }
  20272. for ($i = $frompage; $i > $topage; --$i) {
  20273. $j = $i - 1;
  20274. // shift pages down
  20275. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20276. $this->pagedim[$i] = $this->pagedim[$j];
  20277. $this->pagelen[$i] = $this->pagelen[$j];
  20278. $this->intmrk[$i] = $this->intmrk[$j];
  20279. $this->bordermrk[$i] = $this->bordermrk[$j];
  20280. $this->cntmrk[$i] = $this->cntmrk[$j];
  20281. $this->pageobjects[$i] = $this->pageobjects[$j];
  20282. if (isset($this->footerpos[$j])) {
  20283. $this->footerpos[$i] = $this->footerpos[$j];
  20284. } elseif (isset($this->footerpos[$i])) {
  20285. unset($this->footerpos[$i]);
  20286. }
  20287. if (isset($this->footerlen[$j])) {
  20288. $this->footerlen[$i] = $this->footerlen[$j];
  20289. } elseif (isset($this->footerlen[$i])) {
  20290. unset($this->footerlen[$i]);
  20291. }
  20292. if (isset($this->transfmrk[$j])) {
  20293. $this->transfmrk[$i] = $this->transfmrk[$j];
  20294. } elseif (isset($this->transfmrk[$i])) {
  20295. unset($this->transfmrk[$i]);
  20296. }
  20297. if (isset($this->PageAnnots[$j])) {
  20298. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20299. } elseif (isset($this->PageAnnots[$i])) {
  20300. unset($this->PageAnnots[$i]);
  20301. }
  20302. if (isset($this->newpagegroup[$j])) {
  20303. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20304. unset($this->newpagegroup[$j]);
  20305. }
  20306. if ($this->currpagegroup == $j) {
  20307. $this->currpagegroup = $i;
  20308. }
  20309. }
  20310. $this->setPageBuffer($topage, $tmppage);
  20311. $this->pagedim[$topage] = $tmppagedim;
  20312. $this->pagelen[$topage] = $tmppagelen;
  20313. $this->intmrk[$topage] = $tmpintmrk;
  20314. $this->bordermrk[$topage] = $tmpbordermrk;
  20315. $this->cntmrk[$topage] = $tmpcntmrk;
  20316. $this->pageobjects[$topage] = $tmppageobjects;
  20317. if (isset($tmpfooterpos)) {
  20318. $this->footerpos[$topage] = $tmpfooterpos;
  20319. } elseif (isset($this->footerpos[$topage])) {
  20320. unset($this->footerpos[$topage]);
  20321. }
  20322. if (isset($tmpfooterlen)) {
  20323. $this->footerlen[$topage] = $tmpfooterlen;
  20324. } elseif (isset($this->footerlen[$topage])) {
  20325. unset($this->footerlen[$topage]);
  20326. }
  20327. if (isset($tmptransfmrk)) {
  20328. $this->transfmrk[$topage] = $tmptransfmrk;
  20329. } elseif (isset($this->transfmrk[$topage])) {
  20330. unset($this->transfmrk[$topage]);
  20331. }
  20332. if (isset($tmpannots)) {
  20333. $this->PageAnnots[$topage] = $tmpannots;
  20334. } elseif (isset($this->PageAnnots[$topage])) {
  20335. unset($this->PageAnnots[$topage]);
  20336. }
  20337. // adjust outlines
  20338. $tmpoutlines = $this->outlines;
  20339. foreach ($tmpoutlines as $key => $outline) {
  20340. if (!$outline['f']) {
  20341. if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  20342. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  20343. } elseif ($outline['p'] == $frompage) {
  20344. $this->outlines[$key]['p'] = $topage;
  20345. }
  20346. }
  20347. }
  20348. // adjust dests
  20349. $tmpdests = $this->dests;
  20350. foreach ($tmpdests as $key => $dest) {
  20351. if (!$dest['f']) {
  20352. if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
  20353. $this->dests[$key]['p'] = ($dest['p'] + 1);
  20354. } elseif ($dest['p'] == $frompage) {
  20355. $this->dests[$key]['p'] = $topage;
  20356. }
  20357. }
  20358. }
  20359. // adjust links
  20360. $tmplinks = $this->links;
  20361. foreach ($tmplinks as $key => $link) {
  20362. if (!$link['f']) {
  20363. if (($link['p'] >= $topage) AND ($link['p'] < $frompage)) {
  20364. $this->links[$key]['p'] = ($link['p'] + 1);
  20365. } elseif ($link['p'] == $frompage) {
  20366. $this->links[$key]['p'] = $topage;
  20367. }
  20368. }
  20369. }
  20370. // adjust javascript
  20371. $jfrompage = $frompage;
  20372. $jtopage = $topage;
  20373. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20374. foreach($pamatch[0] as $pk => $pmatch) {
  20375. $pagenum = intval($pamatch[3][$pk]) + 1;
  20376. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  20377. $newpage = ($pagenum + 1);
  20378. } elseif ($pagenum == $jfrompage) {
  20379. $newpage = $jtopage;
  20380. } else {
  20381. $newpage = $pagenum;
  20382. }
  20383. --$newpage;
  20384. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20385. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20386. }
  20387. unset($pamatch);
  20388. }
  20389. // return to last page
  20390. $this->lastPage(true);
  20391. return true;
  20392. }
  20393. /**
  20394. * Remove the specified page.
  20395. * @param $page (int) page to remove
  20396. * @return true in case of success, false in case of error.
  20397. * @public
  20398. * @since 4.6.004 (2009-04-23)
  20399. */
  20400. public function deletePage($page) {
  20401. if (($page < 1) OR ($page > $this->numpages)) {
  20402. return false;
  20403. }
  20404. // delete current page
  20405. unset($this->pages[$page]);
  20406. unset($this->pagedim[$page]);
  20407. unset($this->pagelen[$page]);
  20408. unset($this->intmrk[$page]);
  20409. unset($this->bordermrk[$page]);
  20410. unset($this->cntmrk[$page]);
  20411. foreach ($this->pageobjects[$page] as $oid) {
  20412. if (isset($this->offsets[$oid])){
  20413. unset($this->offsets[$oid]);
  20414. }
  20415. }
  20416. unset($this->pageobjects[$page]);
  20417. if (isset($this->footerpos[$page])) {
  20418. unset($this->footerpos[$page]);
  20419. }
  20420. if (isset($this->footerlen[$page])) {
  20421. unset($this->footerlen[$page]);
  20422. }
  20423. if (isset($this->transfmrk[$page])) {
  20424. unset($this->transfmrk[$page]);
  20425. }
  20426. if (isset($this->PageAnnots[$page])) {
  20427. unset($this->PageAnnots[$page]);
  20428. }
  20429. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20430. for ($i = $page; $i > 0; --$i) {
  20431. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
  20432. --$this->pagegroups[$this->newpagegroup[$i]];
  20433. break;
  20434. }
  20435. }
  20436. }
  20437. if (isset($this->pageopen[$page])) {
  20438. unset($this->pageopen[$page]);
  20439. }
  20440. if ($page < $this->numpages) {
  20441. // update remaining pages
  20442. for ($i = $page; $i < $this->numpages; ++$i) {
  20443. $j = $i + 1;
  20444. // shift pages
  20445. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20446. $this->pagedim[$i] = $this->pagedim[$j];
  20447. $this->pagelen[$i] = $this->pagelen[$j];
  20448. $this->intmrk[$i] = $this->intmrk[$j];
  20449. $this->bordermrk[$i] = $this->bordermrk[$j];
  20450. $this->cntmrk[$i] = $this->cntmrk[$j];
  20451. $this->pageobjects[$i] = $this->pageobjects[$j];
  20452. if (isset($this->footerpos[$j])) {
  20453. $this->footerpos[$i] = $this->footerpos[$j];
  20454. } elseif (isset($this->footerpos[$i])) {
  20455. unset($this->footerpos[$i]);
  20456. }
  20457. if (isset($this->footerlen[$j])) {
  20458. $this->footerlen[$i] = $this->footerlen[$j];
  20459. } elseif (isset($this->footerlen[$i])) {
  20460. unset($this->footerlen[$i]);
  20461. }
  20462. if (isset($this->transfmrk[$j])) {
  20463. $this->transfmrk[$i] = $this->transfmrk[$j];
  20464. } elseif (isset($this->transfmrk[$i])) {
  20465. unset($this->transfmrk[$i]);
  20466. }
  20467. if (isset($this->PageAnnots[$j])) {
  20468. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20469. } elseif (isset($this->PageAnnots[$i])) {
  20470. unset($this->PageAnnots[$i]);
  20471. }
  20472. if (isset($this->newpagegroup[$j])) {
  20473. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20474. unset($this->newpagegroup[$j]);
  20475. }
  20476. if ($this->currpagegroup == $j) {
  20477. $this->currpagegroup = $i;
  20478. }
  20479. if (isset($this->pageopen[$j])) {
  20480. $this->pageopen[$i] = $this->pageopen[$j];
  20481. } elseif (isset($this->pageopen[$i])) {
  20482. unset($this->pageopen[$i]);
  20483. }
  20484. }
  20485. // remove last page
  20486. unset($this->pages[$this->numpages]);
  20487. unset($this->pagedim[$this->numpages]);
  20488. unset($this->pagelen[$this->numpages]);
  20489. unset($this->intmrk[$this->numpages]);
  20490. unset($this->bordermrk[$this->numpages]);
  20491. unset($this->cntmrk[$this->numpages]);
  20492. foreach ($this->pageobjects[$this->numpages] as $oid) {
  20493. if (isset($this->offsets[$oid])){
  20494. unset($this->offsets[$oid]);
  20495. }
  20496. }
  20497. unset($this->pageobjects[$this->numpages]);
  20498. if (isset($this->footerpos[$this->numpages])) {
  20499. unset($this->footerpos[$this->numpages]);
  20500. }
  20501. if (isset($this->footerlen[$this->numpages])) {
  20502. unset($this->footerlen[$this->numpages]);
  20503. }
  20504. if (isset($this->transfmrk[$this->numpages])) {
  20505. unset($this->transfmrk[$this->numpages]);
  20506. }
  20507. if (isset($this->PageAnnots[$this->numpages])) {
  20508. unset($this->PageAnnots[$this->numpages]);
  20509. }
  20510. if (isset($this->newpagegroup[$this->numpages])) {
  20511. unset($this->newpagegroup[$this->numpages]);
  20512. }
  20513. if ($this->currpagegroup == $this->numpages) {
  20514. $this->currpagegroup = ($this->numpages - 1);
  20515. }
  20516. if (isset($this->pagegroups[$this->numpages])) {
  20517. unset($this->pagegroups[$this->numpages]);
  20518. }
  20519. if (isset($this->pageopen[$this->numpages])) {
  20520. unset($this->pageopen[$this->numpages]);
  20521. }
  20522. }
  20523. --$this->numpages;
  20524. $this->page = $this->numpages;
  20525. // adjust outlines
  20526. $tmpoutlines = $this->outlines;
  20527. foreach ($tmpoutlines as $key => $outline) {
  20528. if (!$outline['f']) {
  20529. if ($outline['p'] > $page) {
  20530. $this->outlines[$key]['p'] = $outline['p'] - 1;
  20531. } elseif ($outline['p'] == $page) {
  20532. unset($this->outlines[$key]);
  20533. }
  20534. }
  20535. }
  20536. // adjust dests
  20537. $tmpdests = $this->dests;
  20538. foreach ($tmpdests as $key => $dest) {
  20539. if (!$dest['f']) {
  20540. if ($dest['p'] > $page) {
  20541. $this->dests[$key]['p'] = $dest['p'] - 1;
  20542. } elseif ($dest['p'] == $page) {
  20543. unset($this->dests[$key]);
  20544. }
  20545. }
  20546. }
  20547. // adjust links
  20548. $tmplinks = $this->links;
  20549. foreach ($tmplinks as $key => $link) {
  20550. if (!$link['f']) {
  20551. if ($link['p'] > $page) {
  20552. $this->links[$key]['p'] = $link['p'] - 1;
  20553. } elseif ($link['p'] == $page) {
  20554. unset($this->links[$key]);
  20555. }
  20556. }
  20557. }
  20558. // adjust javascript
  20559. $jpage = $page;
  20560. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20561. foreach($pamatch[0] as $pk => $pmatch) {
  20562. $pagenum = intval($pamatch[3][$pk]) + 1;
  20563. if ($pagenum >= $jpage) {
  20564. $newpage = ($pagenum - 1);
  20565. } elseif ($pagenum == $jpage) {
  20566. $newpage = 1;
  20567. } else {
  20568. $newpage = $pagenum;
  20569. }
  20570. --$newpage;
  20571. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20572. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20573. }
  20574. unset($pamatch);
  20575. }
  20576. // return to last page
  20577. if ($this->numpages > 0) {
  20578. $this->lastPage(true);
  20579. }
  20580. return true;
  20581. }
  20582. /**
  20583. * Clone the specified page to a new page.
  20584. * @param $page (int) number of page to copy (0 = current page)
  20585. * @return true in case of success, false in case of error.
  20586. * @public
  20587. * @since 4.9.015 (2010-04-20)
  20588. */
  20589. public function copyPage($page=0) {
  20590. if ($page == 0) {
  20591. // default value
  20592. $page = $this->page;
  20593. }
  20594. if (($page < 1) OR ($page > $this->numpages)) {
  20595. return false;
  20596. }
  20597. // close the last page
  20598. $this->endPage();
  20599. // copy all page-related states
  20600. ++$this->numpages;
  20601. $this->page = $this->numpages;
  20602. $this->setPageBuffer($this->page, $this->getPageBuffer($page));
  20603. $this->pagedim[$this->page] = $this->pagedim[$page];
  20604. $this->pagelen[$this->page] = $this->pagelen[$page];
  20605. $this->intmrk[$this->page] = $this->intmrk[$page];
  20606. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  20607. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  20608. $this->pageobjects[$this->page] = $this->pageobjects[$page];
  20609. $this->pageopen[$this->page] = false;
  20610. if (isset($this->footerpos[$page])) {
  20611. $this->footerpos[$this->page] = $this->footerpos[$page];
  20612. }
  20613. if (isset($this->footerlen[$page])) {
  20614. $this->footerlen[$this->page] = $this->footerlen[$page];
  20615. }
  20616. if (isset($this->transfmrk[$page])) {
  20617. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  20618. }
  20619. if (isset($this->PageAnnots[$page])) {
  20620. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  20621. }
  20622. if (isset($this->newpagegroup[$page])) {
  20623. // start a new group
  20624. $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
  20625. $this->currpagegroup = $this->newpagegroup[$this->page];
  20626. $this->pagegroups[$this->currpagegroup] = 1;
  20627. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  20628. ++$this->pagegroups[$this->currpagegroup];
  20629. }
  20630. // copy outlines
  20631. $tmpoutlines = $this->outlines;
  20632. foreach ($tmpoutlines as $key => $outline) {
  20633. if ($outline['p'] == $page) {
  20634. $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'x' => $outline['x'], 'y' => $outline['y'], 'p' => $this->page, 'f' => $outline['f'], 's' => $outline['s'], 'c' => $outline['c']);
  20635. }
  20636. }
  20637. // copy links
  20638. $tmplinks = $this->links;
  20639. foreach ($tmplinks as $key => $link) {
  20640. if ($link['p'] == $page) {
  20641. $this->links[] = array('p' => $this->page, 'y' => $link['y'], 'f' => $link['f']);
  20642. }
  20643. }
  20644. // return to last page
  20645. $this->lastPage(true);
  20646. return true;
  20647. }
  20648. /**
  20649. * Output a Table of Content Index (TOC).
  20650. * This method must be called after all Bookmarks were set.
  20651. * Before calling this method you have to open the page using the addTOCPage() method.
  20652. * After calling this method you have to call endTOCPage() to close the TOC page.
  20653. * You can override this method to achieve different styles.
  20654. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  20655. * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment).
  20656. * @param $filler (string) string used to fill the space between text and page number.
  20657. * @param $toc_name (string) name to use for TOC bookmark.
  20658. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20659. * @param $color (array) RGB color array for bookmark title (values from 0 to 255).
  20660. * @public
  20661. * @author Nicola Asuni
  20662. * @since 4.5.000 (2009-01-02)
  20663. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  20664. */
  20665. public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
  20666. $fontsize = $this->FontSizePt;
  20667. $fontfamily = $this->FontFamily;
  20668. $fontstyle = $this->FontStyle;
  20669. $w = $this->w - $this->lMargin - $this->rMargin;
  20670. $spacer = $this->GetStringWidth(chr(32)) * 4;
  20671. $lmargin = $this->lMargin;
  20672. $rmargin = $this->rMargin;
  20673. $x_start = $this->GetX();
  20674. $page_first = $this->page;
  20675. $current_page = $this->page;
  20676. $page_fill_start = false;
  20677. $page_fill_end = false;
  20678. $current_column = $this->current_column;
  20679. if (TCPDF_STATIC::empty_string($numbersfont)) {
  20680. $numbersfont = $this->default_monospaced_font;
  20681. }
  20682. if (TCPDF_STATIC::empty_string($filler)) {
  20683. $filler = ' ';
  20684. }
  20685. if (TCPDF_STATIC::empty_string($page)) {
  20686. $gap = ' ';
  20687. } else {
  20688. $gap = '';
  20689. if ($page < 1) {
  20690. $page = 1;
  20691. }
  20692. }
  20693. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  20694. $numwidth = $this->GetStringWidth('00000');
  20695. $maxpage = 0; //used for pages on attached documents
  20696. foreach ($this->outlines as $key => $outline) {
  20697. // check for extra pages (used for attachments)
  20698. if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
  20699. $outline['p'] += ($this->page - $page_first);
  20700. }
  20701. if ($this->rtl) {
  20702. $aligntext = 'R';
  20703. $alignnum = 'L';
  20704. } else {
  20705. $aligntext = 'L';
  20706. $alignnum = 'R';
  20707. }
  20708. if ($outline['l'] == 0) {
  20709. $this->SetFont($fontfamily, $outline['s'].'B', $fontsize);
  20710. } else {
  20711. $this->SetFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
  20712. }
  20713. $this->SetTextColorArray($outline['c']);
  20714. // check for page break
  20715. $this->checkPageBreak(2 * $this->getCellHeight($this->FontSize));
  20716. // set margins and X position
  20717. if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  20718. $this->lMargin = $lmargin;
  20719. $this->rMargin = $rmargin;
  20720. } else {
  20721. if ($this->current_column != $current_column) {
  20722. if ($this->rtl) {
  20723. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  20724. } else {
  20725. $x_start = $this->columns[$this->current_column]['x'];
  20726. }
  20727. }
  20728. $lmargin = $this->lMargin;
  20729. $rmargin = $this->rMargin;
  20730. $current_page = $this->page;
  20731. $current_column = $this->current_column;
  20732. }
  20733. $this->SetX($x_start);
  20734. $indent = ($spacer * $outline['l']);
  20735. if ($this->rtl) {
  20736. $this->x -= $indent;
  20737. $this->rMargin = $this->w - $this->x;
  20738. } else {
  20739. $this->x += $indent;
  20740. $this->lMargin = $this->x;
  20741. }
  20742. $link = $this->AddLink();
  20743. $this->SetLink($link, $outline['y'], $outline['p']);
  20744. // write the text
  20745. if ($this->rtl) {
  20746. $txt = ' '.$outline['t'];
  20747. } else {
  20748. $txt = $outline['t'].' ';
  20749. }
  20750. $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
  20751. if ($this->rtl) {
  20752. $tw = $this->x - $this->lMargin;
  20753. } else {
  20754. $tw = $this->w - $this->rMargin - $this->x;
  20755. }
  20756. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  20757. if (TCPDF_STATIC::empty_string($page)) {
  20758. $pagenum = $outline['p'];
  20759. } else {
  20760. // placemark to be replaced with the correct number
  20761. $pagenum = '{#'.($outline['p']).'}';
  20762. if ($this->isUnicodeFont()) {
  20763. $pagenum = '{'.$pagenum.'}';
  20764. }
  20765. $maxpage = max($maxpage, $outline['p']);
  20766. }
  20767. $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
  20768. $wfiller = $this->GetStringWidth($filler);
  20769. if ($wfiller > 0) {
  20770. $numfills = floor($fw / $wfiller);
  20771. } else {
  20772. $numfills = 0;
  20773. }
  20774. if ($numfills > 0) {
  20775. $rowfill = str_repeat($filler, $numfills);
  20776. } else {
  20777. $rowfill = '';
  20778. }
  20779. if ($this->rtl) {
  20780. $pagenum = $pagenum.$gap.$rowfill;
  20781. } else {
  20782. $pagenum = $rowfill.$gap.$pagenum;
  20783. }
  20784. // write the number
  20785. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  20786. }
  20787. $page_last = $this->getPage();
  20788. $numpages = ($page_last - $page_first + 1);
  20789. // account for booklet mode
  20790. if ($this->booklet) {
  20791. // check if a blank page is required before TOC
  20792. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  20793. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  20794. if ($page_fill_start) {
  20795. // add a page at the end (to be moved before TOC)
  20796. $this->addPage();
  20797. ++$page_last;
  20798. ++$numpages;
  20799. }
  20800. if ($page_fill_end) {
  20801. // add a page at the end
  20802. $this->addPage();
  20803. ++$page_last;
  20804. ++$numpages;
  20805. }
  20806. }
  20807. $maxpage = max($maxpage, $page_last);
  20808. if (!TCPDF_STATIC::empty_string($page)) {
  20809. for ($p = $page_first; $p <= $page_last; ++$p) {
  20810. // get page data
  20811. $temppage = $this->getPageBuffer($p);
  20812. for ($n = 1; $n <= $maxpage; ++$n) {
  20813. // update page numbers
  20814. $a = '{#'.$n.'}';
  20815. // get page number aliases
  20816. $pnalias = $this->getInternalPageNumberAliases($a);
  20817. // calculate replacement number
  20818. if (($n >= $page) AND ($n <= $this->numpages)) {
  20819. $np = $n + $numpages;
  20820. } else {
  20821. $np = $n;
  20822. }
  20823. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  20824. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  20825. // replace aliases with numbers
  20826. foreach ($pnalias['u'] as $u) {
  20827. $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
  20828. if ($this->rtl) {
  20829. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  20830. } else {
  20831. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  20832. }
  20833. $temppage = str_replace($u, $nr, $temppage);
  20834. }
  20835. foreach ($pnalias['a'] as $a) {
  20836. $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
  20837. if ($this->rtl) {
  20838. $nr = $na.' '.$sfill;
  20839. } else {
  20840. $nr = $sfill.' '.$na;
  20841. }
  20842. $temppage = str_replace($a, $nr, $temppage);
  20843. }
  20844. }
  20845. // save changes
  20846. $this->setPageBuffer($p, $temppage);
  20847. }
  20848. // move pages
  20849. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  20850. if ($page_fill_start) {
  20851. $this->movePage($page_last, $page_first);
  20852. }
  20853. for ($i = 0; $i < $numpages; ++$i) {
  20854. $this->movePage($page_last, $page);
  20855. }
  20856. }
  20857. }
  20858. /**
  20859. * Output a Table Of Content Index (TOC) using HTML templates.
  20860. * This method must be called after all Bookmarks were set.
  20861. * Before calling this method you have to open the page using the addTOCPage() method.
  20862. * After calling this method you have to call endTOCPage() to close the TOC page.
  20863. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  20864. * @param $toc_name (string) name to use for TOC bookmark.
  20865. * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  20866. * @param $correct_align (boolean) if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL)
  20867. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20868. * @param $color (array) RGB color array for title (values from 0 to 255).
  20869. * @public
  20870. * @author Nicola Asuni
  20871. * @since 5.0.001 (2010-05-06)
  20872. * @see addTOCPage(), endTOCPage(), addTOC()
  20873. */
  20874. public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
  20875. $filler = ' ';
  20876. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  20877. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  20878. // set new style for link
  20879. $this->htmlLinkColorArray = array();
  20880. $this->htmlLinkFontStyle = '';
  20881. $page_first = $this->getPage();
  20882. $page_fill_start = false;
  20883. $page_fill_end = false;
  20884. // get the font type used for numbers in each template
  20885. $current_font = $this->FontFamily;
  20886. foreach ($templates as $level => $html) {
  20887. $dom = $this->getHtmlDomArray($html);
  20888. foreach ($dom as $key => $value) {
  20889. if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  20890. $this->SetFont($dom[($key - 1)]['fontname']);
  20891. $templates['F'.$level] = $this->isUnicodeFont();
  20892. }
  20893. }
  20894. }
  20895. $this->SetFont($current_font);
  20896. $maxpage = 0; //used for pages on attached documents
  20897. foreach ($this->outlines as $key => $outline) {
  20898. // get HTML template
  20899. $row = $templates[$outline['l']];
  20900. if (TCPDF_STATIC::empty_string($page)) {
  20901. $pagenum = $outline['p'];
  20902. } else {
  20903. // placemark to be replaced with the correct number
  20904. $pagenum = '{#'.($outline['p']).'}';
  20905. if (isset($templates['F'.$outline['l']]) && $templates['F'.$outline['l']]) {
  20906. $pagenum = '{'.$pagenum.'}';
  20907. }
  20908. $maxpage = max($maxpage, $outline['p']);
  20909. }
  20910. // replace templates with current values
  20911. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  20912. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  20913. // add link to page
  20914. $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  20915. // write bookmark entry
  20916. $this->writeHTML($row, false, false, true, false, '');
  20917. }
  20918. // restore link styles
  20919. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  20920. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  20921. // move TOC page and replace numbers
  20922. $page_last = $this->getPage();
  20923. $numpages = ($page_last - $page_first + 1);
  20924. // account for booklet mode
  20925. if ($this->booklet) {
  20926. // check if a blank page is required before TOC
  20927. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  20928. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  20929. if ($page_fill_start) {
  20930. // add a page at the end (to be moved before TOC)
  20931. $this->addPage();
  20932. ++$page_last;
  20933. ++$numpages;
  20934. }
  20935. if ($page_fill_end) {
  20936. // add a page at the end
  20937. $this->addPage();
  20938. ++$page_last;
  20939. ++$numpages;
  20940. }
  20941. }
  20942. $maxpage = max($maxpage, $page_last);
  20943. if (!TCPDF_STATIC::empty_string($page)) {
  20944. for ($p = $page_first; $p <= $page_last; ++$p) {
  20945. // get page data
  20946. $temppage = $this->getPageBuffer($p);
  20947. for ($n = 1; $n <= $maxpage; ++$n) {
  20948. // update page numbers
  20949. $a = '{#'.$n.'}';
  20950. // get page number aliases
  20951. $pnalias = $this->getInternalPageNumberAliases($a);
  20952. // calculate replacement number
  20953. if ($n >= $page) {
  20954. $np = $n + $numpages;
  20955. } else {
  20956. $np = $n;
  20957. }
  20958. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  20959. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  20960. // replace aliases with numbers
  20961. foreach ($pnalias['u'] as $u) {
  20962. if ($correct_align) {
  20963. $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
  20964. if ($this->rtl) {
  20965. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  20966. } else {
  20967. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  20968. }
  20969. } else {
  20970. $nr = $nu;
  20971. }
  20972. $temppage = str_replace($u, $nr, $temppage);
  20973. }
  20974. foreach ($pnalias['a'] as $a) {
  20975. if ($correct_align) {
  20976. $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
  20977. if ($this->rtl) {
  20978. $nr = $na.' '.$sfill;
  20979. } else {
  20980. $nr = $sfill.' '.$na;
  20981. }
  20982. } else {
  20983. $nr = $na;
  20984. }
  20985. $temppage = str_replace($a, $nr, $temppage);
  20986. }
  20987. }
  20988. // save changes
  20989. $this->setPageBuffer($p, $temppage);
  20990. }
  20991. // move pages
  20992. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  20993. if ($page_fill_start) {
  20994. $this->movePage($page_last, $page_first);
  20995. }
  20996. for ($i = 0; $i < $numpages; ++$i) {
  20997. $this->movePage($page_last, $page);
  20998. }
  20999. }
  21000. }
  21001. /**
  21002. * Stores a copy of the current TCPDF object used for undo operation.
  21003. * @public
  21004. * @since 4.5.029 (2009-03-19)
  21005. */
  21006. public function startTransaction() {
  21007. if (isset($this->objcopy)) {
  21008. // remove previous copy
  21009. $this->commitTransaction();
  21010. }
  21011. // record current page number and Y position
  21012. $this->start_transaction_page = $this->page;
  21013. $this->start_transaction_y = $this->y;
  21014. // clone current object
  21015. $this->objcopy = TCPDF_STATIC::objclone($this);
  21016. }
  21017. /**
  21018. * Delete the copy of the current TCPDF object used for undo operation.
  21019. * @public
  21020. * @since 4.5.029 (2009-03-19)
  21021. */
  21022. public function commitTransaction() {
  21023. if (isset($this->objcopy)) {
  21024. $this->objcopy->_destroy(true, true);
  21025. unset($this->objcopy);
  21026. }
  21027. }
  21028. /**
  21029. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  21030. * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value.
  21031. * @return TCPDF object.
  21032. * @public
  21033. * @since 4.5.029 (2009-03-19)
  21034. */
  21035. public function rollbackTransaction($self=false) {
  21036. if (isset($this->objcopy)) {
  21037. $this->_destroy(true, true);
  21038. if ($self) {
  21039. $objvars = get_object_vars($this->objcopy);
  21040. foreach ($objvars as $key => $value) {
  21041. $this->$key = $value;
  21042. }
  21043. }
  21044. return $this->objcopy;
  21045. }
  21046. return $this;
  21047. }
  21048. // --- MULTI COLUMNS METHODS -----------------------
  21049. /**
  21050. * Set multiple columns of the same size
  21051. * @param $numcols (int) number of columns (set to zero to disable columns mode)
  21052. * @param $width (int) column width
  21053. * @param $y (int) column starting Y position (leave empty for current Y position)
  21054. * @public
  21055. * @since 4.9.001 (2010-03-28)
  21056. */
  21057. public function setEqualColumns($numcols=0, $width=0, $y='') {
  21058. $this->columns = array();
  21059. if ($numcols < 2) {
  21060. $numcols = 0;
  21061. $this->columns = array();
  21062. } else {
  21063. // maximum column width
  21064. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  21065. if (($width == 0) OR ($width > $maxwidth)) {
  21066. $width = $maxwidth;
  21067. }
  21068. if (TCPDF_STATIC::empty_string($y)) {
  21069. $y = $this->y;
  21070. }
  21071. // space between columns
  21072. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  21073. // fill the columns array (with, space, starting Y position)
  21074. for ($i = 0; $i < $numcols; ++$i) {
  21075. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  21076. }
  21077. }
  21078. $this->num_columns = $numcols;
  21079. $this->current_column = 0;
  21080. $this->column_start_page = $this->page;
  21081. $this->selectColumn(0);
  21082. }
  21083. /**
  21084. * Remove columns and reset page margins.
  21085. * @public
  21086. * @since 5.9.072 (2011-04-26)
  21087. */
  21088. public function resetColumns() {
  21089. $this->lMargin = $this->original_lMargin;
  21090. $this->rMargin = $this->original_rMargin;
  21091. $this->setEqualColumns();
  21092. }
  21093. /**
  21094. * Set columns array.
  21095. * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  21096. * @param $columns (array)
  21097. * @public
  21098. * @since 4.9.001 (2010-03-28)
  21099. */
  21100. public function setColumnsArray($columns) {
  21101. $this->columns = $columns;
  21102. $this->num_columns = count($columns);
  21103. $this->current_column = 0;
  21104. $this->column_start_page = $this->page;
  21105. $this->selectColumn(0);
  21106. }
  21107. /**
  21108. * Set position at a given column
  21109. * @param $col (int) column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  21110. * @public
  21111. * @since 4.9.001 (2010-03-28)
  21112. */
  21113. public function selectColumn($col='') {
  21114. if (is_string($col)) {
  21115. $col = $this->current_column;
  21116. } elseif ($col >= $this->num_columns) {
  21117. $col = 0;
  21118. }
  21119. $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  21120. $enable_thead = false;
  21121. if ($this->num_columns > 1) {
  21122. if ($col != $this->current_column) {
  21123. // move Y pointer at the top of the column
  21124. if ($this->column_start_page == $this->page) {
  21125. $this->y = $this->columns[$col]['y'];
  21126. } else {
  21127. $this->y = $this->tMargin;
  21128. }
  21129. // Avoid to write table headers more than once
  21130. if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
  21131. $enable_thead = true;
  21132. $this->maxselcol['page'] = $this->page;
  21133. $this->maxselcol['column'] = $col;
  21134. }
  21135. }
  21136. $xshift = $this->colxshift;
  21137. // set X position of the current column by case
  21138. $listindent = ($this->listindentlevel * $this->listindent);
  21139. // calculate column X position
  21140. $colpos = 0;
  21141. for ($i = 0; $i < $col; ++$i) {
  21142. $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
  21143. }
  21144. if ($this->rtl) {
  21145. $x = $this->w - $this->original_rMargin - $colpos;
  21146. $this->rMargin = ($this->w - $x + $listindent);
  21147. $this->lMargin = ($x - $this->columns[$col]['w']);
  21148. $this->x = $x - $listindent;
  21149. } else {
  21150. $x = $this->original_lMargin + $colpos;
  21151. $this->lMargin = ($x + $listindent);
  21152. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  21153. $this->x = $x + $listindent;
  21154. }
  21155. $this->columns[$col]['x'] = $x;
  21156. }
  21157. $this->current_column = $col;
  21158. // fix for HTML mode
  21159. $this->newline = true;
  21160. // print HTML table header (if any)
  21161. if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) {
  21162. if ($enable_thead) {
  21163. // print table header
  21164. $this->writeHTML($this->thead, false, false, false, false, '');
  21165. $this->y += $xshift['s']['V'];
  21166. // store end of header position
  21167. if (!isset($this->columns[$col]['th'])) {
  21168. $this->columns[$col]['th'] = array();
  21169. }
  21170. $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  21171. $this->lasth = 0;
  21172. } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  21173. $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
  21174. }
  21175. }
  21176. // account for an html table cell over multiple columns
  21177. if ($this->rtl) {
  21178. $this->rMargin += $xshift['x'];
  21179. $this->x -= ($xshift['x'] + $xshift['p']['R']);
  21180. } else {
  21181. $this->lMargin += $xshift['x'];
  21182. $this->x += $xshift['x'] + $xshift['p']['L'];
  21183. }
  21184. }
  21185. /**
  21186. * Return the current column number
  21187. * @return int current column number
  21188. * @public
  21189. * @since 5.5.011 (2010-07-08)
  21190. */
  21191. public function getColumn() {
  21192. return $this->current_column;
  21193. }
  21194. /**
  21195. * Return the current number of columns.
  21196. * @return int number of columns
  21197. * @public
  21198. * @since 5.8.018 (2010-08-25)
  21199. */
  21200. public function getNumberOfColumns() {
  21201. return $this->num_columns;
  21202. }
  21203. /**
  21204. * Set Text rendering mode.
  21205. * @param $stroke (int) outline size in user units (0 = disable).
  21206. * @param $fill (boolean) if true fills the text (default).
  21207. * @param $clip (boolean) if true activate clipping mode
  21208. * @public
  21209. * @since 4.9.008 (2009-04-02)
  21210. */
  21211. public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
  21212. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  21213. // convert text rendering parameters
  21214. if ($stroke < 0) {
  21215. $stroke = 0;
  21216. }
  21217. if ($fill === true) {
  21218. if ($stroke > 0) {
  21219. if ($clip === true) {
  21220. // Fill, then stroke text and add to path for clipping
  21221. $textrendermode = 6;
  21222. } else {
  21223. // Fill, then stroke text
  21224. $textrendermode = 2;
  21225. }
  21226. $textstrokewidth = $stroke;
  21227. } else {
  21228. if ($clip === true) {
  21229. // Fill text and add to path for clipping
  21230. $textrendermode = 4;
  21231. } else {
  21232. // Fill text
  21233. $textrendermode = 0;
  21234. }
  21235. }
  21236. } else {
  21237. if ($stroke > 0) {
  21238. if ($clip === true) {
  21239. // Stroke text and add to path for clipping
  21240. $textrendermode = 5;
  21241. } else {
  21242. // Stroke text
  21243. $textrendermode = 1;
  21244. }
  21245. $textstrokewidth = $stroke;
  21246. } else {
  21247. if ($clip === true) {
  21248. // Add text to path for clipping
  21249. $textrendermode = 7;
  21250. } else {
  21251. // Neither fill nor stroke text (invisible)
  21252. $textrendermode = 3;
  21253. }
  21254. }
  21255. }
  21256. $this->textrendermode = $textrendermode;
  21257. $this->textstrokewidth = $stroke;
  21258. }
  21259. /**
  21260. * Set parameters for drop shadow effect for text.
  21261. * @param $params (array) Array of parameters: enabled (boolean) set to true to enable shadow; depth_w (float) shadow width in user units; depth_h (float) shadow height in user units; color (array) shadow color or false to use the stroke color; opacity (float) Alpha value: real value from 0 (transparent) to 1 (opaque); blend_mode (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity.
  21262. * @since 5.9.174 (2012-07-25)
  21263. * @public
  21264. */
  21265. public function setTextShadow($params=array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal')) {
  21266. if (isset($params['enabled'])) {
  21267. $this->txtshadow['enabled'] = $params['enabled']?true:false;
  21268. } else {
  21269. $this->txtshadow['enabled'] = false;
  21270. }
  21271. if (isset($params['depth_w'])) {
  21272. $this->txtshadow['depth_w'] = floatval($params['depth_w']);
  21273. } else {
  21274. $this->txtshadow['depth_w'] = 0;
  21275. }
  21276. if (isset($params['depth_h'])) {
  21277. $this->txtshadow['depth_h'] = floatval($params['depth_h']);
  21278. } else {
  21279. $this->txtshadow['depth_h'] = 0;
  21280. }
  21281. if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
  21282. $this->txtshadow['color'] = $params['color'];
  21283. } else {
  21284. $this->txtshadow['color'] = $this->strokecolor;
  21285. }
  21286. if (isset($params['opacity'])) {
  21287. $this->txtshadow['opacity'] = min(1, max(0, floatval($params['opacity'])));
  21288. } else {
  21289. $this->txtshadow['opacity'] = 1;
  21290. }
  21291. if (isset($params['blend_mode']) AND in_array($params['blend_mode'], array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  21292. $this->txtshadow['blend_mode'] = $params['blend_mode'];
  21293. } else {
  21294. $this->txtshadow['blend_mode'] = 'Normal';
  21295. }
  21296. if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
  21297. $this->txtshadow['enabled'] = false;
  21298. }
  21299. }
  21300. /**
  21301. * Return the text shadow parameters array.
  21302. * @return Array of parameters.
  21303. * @since 5.9.174 (2012-07-25)
  21304. * @public
  21305. */
  21306. public function getTextShadow() {
  21307. return $this->txtshadow;
  21308. }
  21309. /**
  21310. * Returns an array of chars containing soft hyphens.
  21311. * @param $word (array) array of chars
  21312. * @param $patterns (array) Array of hypenation patterns.
  21313. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm.
  21314. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  21315. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  21316. * @param $charmin (int) Minimum word length to apply the hyphenation algorithm.
  21317. * @param $charmax (int) Maximum length of broken piece of word.
  21318. * @return array text with soft hyphens
  21319. * @author Nicola Asuni
  21320. * @since 4.9.012 (2010-04-12)
  21321. * @protected
  21322. */
  21323. protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21324. $hyphenword = array(); // hyphens positions
  21325. $numchars = count($word);
  21326. if ($numchars <= $charmin) {
  21327. return $word;
  21328. }
  21329. $word_string = TCPDF_FONTS::UTF8ArrSubString($word, '', '', $this->isunicode);
  21330. // some words will be returned as-is
  21331. $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})(\]?)$/';
  21332. if (preg_match($pattern, $word_string) > 0) {
  21333. // email
  21334. return $word;
  21335. }
  21336. $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})(\]?)$/';
  21337. if (preg_match($pattern, $word_string) > 0) {
  21338. // URL
  21339. return $word;
  21340. }
  21341. if (isset($dictionary[$word_string])) {
  21342. return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont);
  21343. }
  21344. // surround word with '_' characters
  21345. $tmpword = array_merge(array(46), $word, array(46));
  21346. $tmpnumchars = $numchars + 2;
  21347. $maxpos = $tmpnumchars - 1;
  21348. for ($pos = 0; $pos < $maxpos; ++$pos) {
  21349. $imax = min(($tmpnumchars - $pos), $charmax);
  21350. for ($i = 1; $i <= $imax; ++$i) {
  21351. $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode));
  21352. if (isset($patterns[$subword])) {
  21353. $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont);
  21354. $pattern_length = count($pattern);
  21355. $digits = 1;
  21356. for ($j = 0; $j < $pattern_length; ++$j) {
  21357. // check if $pattern[$j] is a number = hyphenation level (only numbers from 1 to 5 are valid)
  21358. if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  21359. if ($j == 0) {
  21360. $zero = $pos - 1;
  21361. } else {
  21362. $zero = $pos + $j - $digits;
  21363. }
  21364. // get hyphenation level
  21365. $level = ($pattern[$j] - 48);
  21366. // if two levels from two different patterns match at the same point, the higher one is selected.
  21367. if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] < $level)) {
  21368. $hyphenword[$zero] = $level;
  21369. }
  21370. ++$digits;
  21371. }
  21372. }
  21373. }
  21374. }
  21375. }
  21376. $inserted = 0;
  21377. $maxpos = $numchars - $rightmin;
  21378. for ($i = $leftmin; $i <= $maxpos; ++$i) {
  21379. // only odd levels indicate allowed hyphenation points
  21380. if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  21381. // 173 = soft hyphen character
  21382. array_splice($word, $i + $inserted, 0, 173);
  21383. ++$inserted;
  21384. }
  21385. }
  21386. return $word;
  21387. }
  21388. /**
  21389. * Returns text with soft hyphens.
  21390. * @param $text (string) text to process
  21391. * @param $patterns (mixed) Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  21392. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm.
  21393. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  21394. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  21395. * @param $charmin (int) Minimum word length to apply the hyphenation algorithm.
  21396. * @param $charmax (int) Maximum length of broken piece of word.
  21397. * @return array text with soft hyphens
  21398. * @author Nicola Asuni
  21399. * @since 4.9.012 (2010-04-12)
  21400. * @public
  21401. */
  21402. public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21403. $text = $this->unhtmlentities($text);
  21404. $word = array(); // last word
  21405. $txtarr = array(); // text to be returned
  21406. $intag = false; // true if we are inside an HTML tag
  21407. $skip = false; // true to skip hyphenation
  21408. if (!is_array($patterns)) {
  21409. $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
  21410. }
  21411. // get array of characters
  21412. $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  21413. // for each char
  21414. foreach ($unichars as $char) {
  21415. if ((!$intag) AND (!$skip) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
  21416. // letter character
  21417. $word[] = $char;
  21418. } else {
  21419. // other type of character
  21420. if (!TCPDF_STATIC::empty_string($word)) {
  21421. // hypenate the word
  21422. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21423. $word = array();
  21424. }
  21425. $txtarr[] = $char;
  21426. if (chr($char) == '<') {
  21427. // we are inside an HTML tag
  21428. $intag = true;
  21429. } elseif ($intag AND (chr($char) == '>')) {
  21430. // end of HTML tag
  21431. $intag = false;
  21432. // check for style tag
  21433. $expected = array(115, 116, 121, 108, 101); // = 'style'
  21434. $current = array_slice($txtarr, -6, 5); // last 5 chars
  21435. $compare = array_diff($expected, $current);
  21436. if (empty($compare)) {
  21437. // check if it is a closing tag
  21438. $expected = array(47); // = '/'
  21439. $current = array_slice($txtarr, -7, 1);
  21440. $compare = array_diff($expected, $current);
  21441. if (empty($compare)) {
  21442. // closing style tag
  21443. $skip = false;
  21444. } else {
  21445. // opening style tag
  21446. $skip = true;
  21447. }
  21448. }
  21449. }
  21450. }
  21451. }
  21452. if (!TCPDF_STATIC::empty_string($word)) {
  21453. // hypenate the word
  21454. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21455. }
  21456. // convert char array to string and return
  21457. return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
  21458. }
  21459. /**
  21460. * Enable/disable rasterization of vector images using ImageMagick library.
  21461. * @param $mode (boolean) if true enable rasterization, false otherwise.
  21462. * @public
  21463. * @since 5.0.000 (2010-04-27)
  21464. */
  21465. public function setRasterizeVectorImages($mode) {
  21466. $this->rasterize_vector_images = $mode;
  21467. }
  21468. /**
  21469. * Enable or disable default option for font subsetting.
  21470. * @param $enable (boolean) if true enable font subsetting by default.
  21471. * @author Nicola Asuni
  21472. * @public
  21473. * @since 5.3.002 (2010-06-07)
  21474. */
  21475. public function setFontSubsetting($enable=true) {
  21476. if ($this->pdfa_mode) {
  21477. $this->font_subsetting = false;
  21478. } else {
  21479. $this->font_subsetting = $enable ? true : false;
  21480. }
  21481. }
  21482. /**
  21483. * Return the default option for font subsetting.
  21484. * @return boolean default font subsetting state.
  21485. * @author Nicola Asuni
  21486. * @public
  21487. * @since 5.3.002 (2010-06-07)
  21488. */
  21489. public function getFontSubsetting() {
  21490. return $this->font_subsetting;
  21491. }
  21492. /**
  21493. * Left trim the input string
  21494. * @param $str (string) string to trim
  21495. * @param $replace (string) string that replace spaces.
  21496. * @return left trimmed string
  21497. * @author Nicola Asuni
  21498. * @public
  21499. * @since 5.8.000 (2010-08-11)
  21500. */
  21501. public function stringLeftTrim($str, $replace='') {
  21502. return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
  21503. }
  21504. /**
  21505. * Right trim the input string
  21506. * @param $str (string) string to trim
  21507. * @param $replace (string) string that replace spaces.
  21508. * @return right trimmed string
  21509. * @author Nicola Asuni
  21510. * @public
  21511. * @since 5.8.000 (2010-08-11)
  21512. */
  21513. public function stringRightTrim($str, $replace='') {
  21514. return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
  21515. }
  21516. /**
  21517. * Trim the input string
  21518. * @param $str (string) string to trim
  21519. * @param $replace (string) string that replace spaces.
  21520. * @return trimmed string
  21521. * @author Nicola Asuni
  21522. * @public
  21523. * @since 5.8.000 (2010-08-11)
  21524. */
  21525. public function stringTrim($str, $replace='') {
  21526. $str = $this->stringLeftTrim($str, $replace);
  21527. $str = $this->stringRightTrim($str, $replace);
  21528. return $str;
  21529. }
  21530. /**
  21531. * Return true if the current font is unicode type.
  21532. * @return true for unicode font, false otherwise.
  21533. * @author Nicola Asuni
  21534. * @public
  21535. * @since 5.8.002 (2010-08-14)
  21536. */
  21537. public function isUnicodeFont() {
  21538. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  21539. }
  21540. /**
  21541. * Return normalized font name
  21542. * @param $fontfamily (string) property string containing font family names
  21543. * @return string normalized font name
  21544. * @author Nicola Asuni
  21545. * @public
  21546. * @since 5.8.004 (2010-08-17)
  21547. */
  21548. public function getFontFamilyName($fontfamily) {
  21549. // remove spaces and symbols
  21550. $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
  21551. // extract all font names
  21552. $fontslist = preg_split('/[,]/', $fontfamily);
  21553. // find first valid font name
  21554. foreach ($fontslist as $font) {
  21555. // replace font variations
  21556. $font = preg_replace('/regular$/', '', $font);
  21557. $font = preg_replace('/italic$/', 'I', $font);
  21558. $font = preg_replace('/oblique$/', 'I', $font);
  21559. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  21560. // replace common family names and core fonts
  21561. $pattern = array();
  21562. $replacement = array();
  21563. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  21564. $replacement[] = 'times';
  21565. $pattern[] = '/^sansserif/';
  21566. $replacement[] = 'helvetica';
  21567. $pattern[] = '/^monospace/';
  21568. $replacement[] = 'courier';
  21569. $font = preg_replace($pattern, $replacement, $font);
  21570. if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
  21571. return $font;
  21572. }
  21573. }
  21574. // return current font as default
  21575. return $this->CurrentFont['fontkey'];
  21576. }
  21577. /**
  21578. * Start a new XObject Template.
  21579. * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
  21580. * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
  21581. * Note: X,Y coordinates will be reset to 0,0.
  21582. * @param $w (int) Template width in user units (empty string or zero = page width less margins).
  21583. * @param $h (int) Template height in user units (empty string or zero = page height less margins).
  21584. * @param $group (mixed) Set transparency group. Can be a boolean value or an array specifying optional parameters: 'CS' (solour space name), 'I' (boolean flag to indicate isolated group) and 'K' (boolean flag to indicate knockout group).
  21585. * @return int the XObject Template ID in case of success or false in case of error.
  21586. * @author Nicola Asuni
  21587. * @public
  21588. * @since 5.8.017 (2010-08-24)
  21589. * @see endTemplate(), printTemplate()
  21590. */
  21591. public function startTemplate($w=0, $h=0, $group=false) {
  21592. if ($this->inxobj) {
  21593. // we are already inside an XObject template
  21594. return false;
  21595. }
  21596. $this->inxobj = true;
  21597. ++$this->n;
  21598. // XObject ID
  21599. $this->xobjid = 'XT'.$this->n;
  21600. // object ID
  21601. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  21602. // store current graphic state
  21603. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  21604. // initialize data
  21605. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  21606. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  21607. $this->xobjects[$this->xobjid]['outdata'] = '';
  21608. $this->xobjects[$this->xobjid]['xobjects'] = array();
  21609. $this->xobjects[$this->xobjid]['images'] = array();
  21610. $this->xobjects[$this->xobjid]['fonts'] = array();
  21611. $this->xobjects[$this->xobjid]['annotations'] = array();
  21612. $this->xobjects[$this->xobjid]['extgstates'] = array();
  21613. $this->xobjects[$this->xobjid]['gradients'] = array();
  21614. $this->xobjects[$this->xobjid]['spot_colors'] = array();
  21615. // set new environment
  21616. $this->num_columns = 1;
  21617. $this->current_column = 0;
  21618. $this->SetAutoPageBreak(false);
  21619. if (($w === '') OR ($w <= 0)) {
  21620. $w = $this->w - $this->lMargin - $this->rMargin;
  21621. }
  21622. if (($h === '') OR ($h <= 0)) {
  21623. $h = $this->h - $this->tMargin - $this->bMargin;
  21624. }
  21625. $this->xobjects[$this->xobjid]['x'] = 0;
  21626. $this->xobjects[$this->xobjid]['y'] = 0;
  21627. $this->xobjects[$this->xobjid]['w'] = $w;
  21628. $this->xobjects[$this->xobjid]['h'] = $h;
  21629. $this->w = $w;
  21630. $this->h = $h;
  21631. $this->wPt = $this->w * $this->k;
  21632. $this->hPt = $this->h * $this->k;
  21633. $this->fwPt = $this->wPt;
  21634. $this->fhPt = $this->hPt;
  21635. $this->x = 0;
  21636. $this->y = 0;
  21637. $this->lMargin = 0;
  21638. $this->rMargin = 0;
  21639. $this->tMargin = 0;
  21640. $this->bMargin = 0;
  21641. // set group mode
  21642. $this->xobjects[$this->xobjid]['group'] = $group;
  21643. return $this->xobjid;
  21644. }
  21645. /**
  21646. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  21647. * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
  21648. * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
  21649. * @return int the XObject Template ID in case of success or false in case of error.
  21650. * @author Nicola Asuni
  21651. * @public
  21652. * @since 5.8.017 (2010-08-24)
  21653. * @see startTemplate(), printTemplate()
  21654. */
  21655. public function endTemplate() {
  21656. if (!$this->inxobj) {
  21657. // we are not inside a template
  21658. return false;
  21659. }
  21660. $this->inxobj = false;
  21661. // restore previous graphic state
  21662. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  21663. return $this->xobjid;
  21664. }
  21665. /**
  21666. * Print an XObject Template.
  21667. * You can print an XObject Template inside the currently opened Template.
  21668. * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
  21669. * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
  21670. * @param $id (string) The ID of XObject Template to print.
  21671. * @param $x (int) X position in user units (empty string = current x position)
  21672. * @param $y (int) Y position in user units (empty string = current y position)
  21673. * @param $w (int) Width in user units (zero = remaining page width)
  21674. * @param $h (int) Height in user units (zero = remaining page height)
  21675. * @param $align (string) Indicates the alignment of the pointer next to template insertion relative to template height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  21676. * @param $palign (string) Allows to center or align the template on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  21677. * @param $fitonpage (boolean) If true the template is resized to not exceed page dimensions.
  21678. * @author Nicola Asuni
  21679. * @public
  21680. * @since 5.8.017 (2010-08-24)
  21681. * @see startTemplate(), endTemplate()
  21682. */
  21683. public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
  21684. if ($this->state != 2) {
  21685. return;
  21686. }
  21687. if (!isset($this->xobjects[$id])) {
  21688. $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  21689. }
  21690. if ($this->inxobj) {
  21691. if ($id == $this->xobjid) {
  21692. // close current template
  21693. $this->endTemplate();
  21694. } else {
  21695. // use the template as resource for the template currently opened
  21696. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  21697. }
  21698. }
  21699. // set default values
  21700. if ($x === '') {
  21701. $x = $this->x;
  21702. }
  21703. if ($y === '') {
  21704. $y = $this->y;
  21705. }
  21706. // check page for no-write regions and adapt page margins if necessary
  21707. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  21708. $ow = $this->xobjects[$id]['w'];
  21709. if ($ow <= 0) {
  21710. $ow = 1;
  21711. }
  21712. $oh = $this->xobjects[$id]['h'];
  21713. if ($oh <= 0) {
  21714. $oh = 1;
  21715. }
  21716. // calculate template width and height on document
  21717. if (($w <= 0) AND ($h <= 0)) {
  21718. $w = $ow;
  21719. $h = $oh;
  21720. } elseif ($w <= 0) {
  21721. $w = $h * $ow / $oh;
  21722. } elseif ($h <= 0) {
  21723. $h = $w * $oh / $ow;
  21724. }
  21725. // fit the template on available space
  21726. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  21727. // set page alignment
  21728. $rb_y = $y + $h;
  21729. // set alignment
  21730. if ($this->rtl) {
  21731. if ($palign == 'L') {
  21732. $xt = $this->lMargin;
  21733. } elseif ($palign == 'C') {
  21734. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21735. } elseif ($palign == 'R') {
  21736. $xt = $this->w - $this->rMargin - $w;
  21737. } else {
  21738. $xt = $x - $w;
  21739. }
  21740. $rb_x = $xt;
  21741. } else {
  21742. if ($palign == 'L') {
  21743. $xt = $this->lMargin;
  21744. } elseif ($palign == 'C') {
  21745. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21746. } elseif ($palign == 'R') {
  21747. $xt = $this->w - $this->rMargin - $w;
  21748. } else {
  21749. $xt = $x;
  21750. }
  21751. $rb_x = $xt + $w;
  21752. }
  21753. // print XObject Template + Transformation matrix
  21754. $this->StartTransform();
  21755. // translate and scale
  21756. $sx = ($w / $ow);
  21757. $sy = ($h / $oh);
  21758. $tm = array();
  21759. $tm[0] = $sx;
  21760. $tm[1] = 0;
  21761. $tm[2] = 0;
  21762. $tm[3] = $sy;
  21763. $tm[4] = $xt * $this->k;
  21764. $tm[5] = ($this->h - $h - $y) * $this->k;
  21765. $this->Transform($tm);
  21766. // set object
  21767. $this->_out('/'.$id.' Do');
  21768. $this->StopTransform();
  21769. // add annotations
  21770. if (!empty($this->xobjects[$id]['annotations'])) {
  21771. foreach ($this->xobjects[$id]['annotations'] as $annot) {
  21772. // transform original coordinates
  21773. $coordlt = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  21774. $ax = ($coordlt[4] / $this->k);
  21775. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  21776. $coordrb = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  21777. $aw = ($coordrb[4] / $this->k) - $ax;
  21778. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  21779. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  21780. }
  21781. }
  21782. // set pointer to align the next text/objects
  21783. switch($align) {
  21784. case 'T': {
  21785. $this->y = $y;
  21786. $this->x = $rb_x;
  21787. break;
  21788. }
  21789. case 'M': {
  21790. $this->y = $y + round($h/2);
  21791. $this->x = $rb_x;
  21792. break;
  21793. }
  21794. case 'B': {
  21795. $this->y = $rb_y;
  21796. $this->x = $rb_x;
  21797. break;
  21798. }
  21799. case 'N': {
  21800. $this->SetY($rb_y);
  21801. break;
  21802. }
  21803. default:{
  21804. break;
  21805. }
  21806. }
  21807. }
  21808. /**
  21809. * Set the percentage of character stretching.
  21810. * @param $perc (int) percentage of stretching (100 = no stretching)
  21811. * @author Nicola Asuni
  21812. * @public
  21813. * @since 5.9.000 (2010-09-29)
  21814. */
  21815. public function setFontStretching($perc=100) {
  21816. $this->font_stretching = $perc;
  21817. }
  21818. /**
  21819. * Get the percentage of character stretching.
  21820. * @return float stretching value
  21821. * @author Nicola Asuni
  21822. * @public
  21823. * @since 5.9.000 (2010-09-29)
  21824. */
  21825. public function getFontStretching() {
  21826. return $this->font_stretching;
  21827. }
  21828. /**
  21829. * Set the amount to increase or decrease the space between characters in a text.
  21830. * @param $spacing (float) amount to increase or decrease the space between characters in a text (0 = default spacing)
  21831. * @author Nicola Asuni
  21832. * @public
  21833. * @since 5.9.000 (2010-09-29)
  21834. */
  21835. public function setFontSpacing($spacing=0) {
  21836. $this->font_spacing = $spacing;
  21837. }
  21838. /**
  21839. * Get the amount to increase or decrease the space between characters in a text.
  21840. * @return int font spacing (tracking) value
  21841. * @author Nicola Asuni
  21842. * @public
  21843. * @since 5.9.000 (2010-09-29)
  21844. */
  21845. public function getFontSpacing() {
  21846. return $this->font_spacing;
  21847. }
  21848. /**
  21849. * Return an array of no-write page regions
  21850. * @return array of no-write page regions
  21851. * @author Nicola Asuni
  21852. * @public
  21853. * @since 5.9.003 (2010-10-13)
  21854. * @see setPageRegions(), addPageRegion()
  21855. */
  21856. public function getPageRegions() {
  21857. return $this->page_regions;
  21858. }
  21859. /**
  21860. * Set no-write regions on page.
  21861. * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
  21862. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21863. * You can set multiple regions for the same page.
  21864. * @param $regions (array) array of no-write regions. For each region you can define an array as follow: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right). Omit this parameter to remove all regions.
  21865. * @author Nicola Asuni
  21866. * @public
  21867. * @since 5.9.003 (2010-10-13)
  21868. * @see addPageRegion(), getPageRegions()
  21869. */
  21870. public function setPageRegions($regions=array()) {
  21871. // empty current regions array
  21872. $this->page_regions = array();
  21873. // add regions
  21874. foreach ($regions as $data) {
  21875. $this->addPageRegion($data);
  21876. }
  21877. }
  21878. /**
  21879. * Add a single no-write region on selected page.
  21880. * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
  21881. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21882. * You can set multiple regions for the same page.
  21883. * @param $region (array) array of a single no-write region array: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right).
  21884. * @author Nicola Asuni
  21885. * @public
  21886. * @since 5.9.003 (2010-10-13)
  21887. * @see setPageRegions(), getPageRegions()
  21888. */
  21889. public function addPageRegion($region) {
  21890. if (!isset($region['page']) OR empty($region['page'])) {
  21891. $region['page'] = $this->page;
  21892. }
  21893. if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  21894. AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  21895. AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  21896. $this->page_regions[] = $region;
  21897. }
  21898. }
  21899. /**
  21900. * Remove a single no-write region.
  21901. * @param $key (int) region key
  21902. * @author Nicola Asuni
  21903. * @public
  21904. * @since 5.9.003 (2010-10-13)
  21905. * @see setPageRegions(), getPageRegions()
  21906. */
  21907. public function removePageRegion($key) {
  21908. if (isset($this->page_regions[$key])) {
  21909. unset($this->page_regions[$key]);
  21910. }
  21911. }
  21912. /**
  21913. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  21914. * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
  21915. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21916. * @param $h (float) height of the text/image/object to print in user units
  21917. * @param $x (float) current X coordinate in user units
  21918. * @param $y (float) current Y coordinate in user units
  21919. * @return array($x, $y)
  21920. * @author Nicola Asuni
  21921. * @protected
  21922. * @since 5.9.003 (2010-10-13)
  21923. */
  21924. protected function checkPageRegions($h, $x, $y) {
  21925. // set default values
  21926. if ($x === '') {
  21927. $x = $this->x;
  21928. }
  21929. if ($y === '') {
  21930. $y = $this->y;
  21931. }
  21932. if (!$this->check_page_regions OR empty($this->page_regions)) {
  21933. // no page regions defined
  21934. return array($x, $y);
  21935. }
  21936. if (empty($h)) {
  21937. $h = $this->getCellHeight($this->FontSize);
  21938. }
  21939. // check for page break
  21940. if ($this->checkPageBreak($h, $y)) {
  21941. // the content will be printed on a new page
  21942. $x = $this->x;
  21943. $y = $this->y;
  21944. }
  21945. if ($this->num_columns > 1) {
  21946. if ($this->rtl) {
  21947. $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  21948. } else {
  21949. $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  21950. }
  21951. } else {
  21952. if ($this->rtl) {
  21953. $this->lMargin = max($this->clMargin, $this->original_lMargin);
  21954. } else {
  21955. $this->rMargin = max($this->crMargin, $this->original_rMargin);
  21956. }
  21957. }
  21958. // adjust coordinates and page margins
  21959. foreach ($this->page_regions as $regid => $regdata) {
  21960. if ($regdata['page'] == $this->page) {
  21961. // check region boundaries
  21962. if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  21963. // Y is inside the region
  21964. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  21965. $yt = max($y, $regdata['yt']);
  21966. $yb = min(($yt + $h), $regdata['yb']);
  21967. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  21968. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  21969. if ($regdata['side'] == 'L') { // left side
  21970. $new_margin = max($xt, $xb);
  21971. if ($this->lMargin < $new_margin) {
  21972. if ($this->rtl) {
  21973. // adjust left page margin
  21974. $this->lMargin = max(0, $new_margin);
  21975. }
  21976. if ($x < $new_margin) {
  21977. // adjust x position
  21978. $x = $new_margin;
  21979. if ($new_margin > ($this->w - $this->rMargin)) {
  21980. // adjust y position
  21981. $y = $regdata['yb'] - $h;
  21982. }
  21983. }
  21984. }
  21985. } elseif ($regdata['side'] == 'R') { // right side
  21986. $new_margin = min($xt, $xb);
  21987. if (($this->w - $this->rMargin) > $new_margin) {
  21988. if (!$this->rtl) {
  21989. // adjust right page margin
  21990. $this->rMargin = max(0, ($this->w - $new_margin));
  21991. }
  21992. if ($x > $new_margin) {
  21993. // adjust x position
  21994. $x = $new_margin;
  21995. if ($new_margin > $this->lMargin) {
  21996. // adjust y position
  21997. $y = $regdata['yb'] - $h;
  21998. }
  21999. }
  22000. }
  22001. }
  22002. }
  22003. }
  22004. }
  22005. return array($x, $y);
  22006. }
  22007. // --- SVG METHODS ---------------------------------------------------------
  22008. /**
  22009. * Embedd a Scalable Vector Graphics (SVG) image.
  22010. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  22011. * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string.
  22012. * @param $x (float) Abscissa of the upper-left corner.
  22013. * @param $y (float) Ordinate of the upper-left corner.
  22014. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22015. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22016. * @param $link (mixed) URL or identifier returned by AddLink().
  22017. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul> If the alignment is an empty string, then the pointer will be restored on the starting SVG position.
  22018. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  22019. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  22020. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  22021. * @author Nicola Asuni
  22022. * @since 5.0.000 (2010-05-02)
  22023. * @public
  22024. */
  22025. public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
  22026. if ($this->state != 2) {
  22027. return;
  22028. }
  22029. // reset SVG vars
  22030. $this->svggradients = array();
  22031. $this->svggradientid = 0;
  22032. $this->svgdefsmode = false;
  22033. $this->svgdefs = array();
  22034. $this->svgclipmode = false;
  22035. $this->svgclippaths = array();
  22036. $this->svgcliptm = array();
  22037. $this->svgclipid = 0;
  22038. $this->svgtext = '';
  22039. $this->svgtextmode = array();
  22040. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  22041. // convert SVG to raster image using GD or ImageMagick libraries
  22042. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22043. }
  22044. if ($file[0] === '@') { // image from string
  22045. $this->svgdir = '';
  22046. $svgdata = substr($file, 1);
  22047. } else { // SVG file
  22048. $this->svgdir = dirname($file);
  22049. $svgdata = TCPDF_STATIC::fileGetContents($file);
  22050. }
  22051. if ($svgdata === FALSE) {
  22052. $this->Error('SVG file not found: '.$file);
  22053. }
  22054. if ($x === '') {
  22055. $x = $this->x;
  22056. }
  22057. if ($y === '') {
  22058. $y = $this->y;
  22059. }
  22060. // check page for no-write regions and adapt page margins if necessary
  22061. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  22062. $k = $this->k;
  22063. $ox = 0;
  22064. $oy = 0;
  22065. $ow = $w;
  22066. $oh = $h;
  22067. $aspect_ratio_align = 'xMidYMid';
  22068. $aspect_ratio_ms = 'meet';
  22069. $regs = array();
  22070. // get original image width and height
  22071. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  22072. if (isset($regs[1]) AND !empty($regs[1])) {
  22073. $tmp = array();
  22074. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22075. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  22076. }
  22077. $tmp = array();
  22078. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22079. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  22080. }
  22081. $tmp = array();
  22082. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22083. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  22084. }
  22085. $tmp = array();
  22086. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22087. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  22088. }
  22089. $tmp = array();
  22090. $view_box = array();
  22091. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
  22092. if (count($tmp) == 5) {
  22093. array_shift($tmp);
  22094. foreach ($tmp as $key => $val) {
  22095. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  22096. }
  22097. $ox = $view_box[0];
  22098. $oy = $view_box[1];
  22099. }
  22100. // get aspect ratio
  22101. $tmp = array();
  22102. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22103. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  22104. switch (count($aspect_ratio)) {
  22105. case 3: {
  22106. $aspect_ratio_align = $aspect_ratio[1];
  22107. $aspect_ratio_ms = $aspect_ratio[2];
  22108. break;
  22109. }
  22110. case 2: {
  22111. $aspect_ratio_align = $aspect_ratio[0];
  22112. $aspect_ratio_ms = $aspect_ratio[1];
  22113. break;
  22114. }
  22115. case 1: {
  22116. $aspect_ratio_align = $aspect_ratio[0];
  22117. $aspect_ratio_ms = 'meet';
  22118. break;
  22119. }
  22120. }
  22121. }
  22122. }
  22123. }
  22124. if ($ow <= 0) {
  22125. $ow = 1;
  22126. }
  22127. if ($oh <= 0) {
  22128. $oh = 1;
  22129. }
  22130. // calculate image width and height on document
  22131. if (($w <= 0) AND ($h <= 0)) {
  22132. // convert image size to document unit
  22133. $w = $ow;
  22134. $h = $oh;
  22135. } elseif ($w <= 0) {
  22136. $w = $h * $ow / $oh;
  22137. } elseif ($h <= 0) {
  22138. $h = $w * $oh / $ow;
  22139. }
  22140. // fit the image on available space
  22141. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  22142. if ($this->rasterize_vector_images) {
  22143. // convert SVG to raster image using GD or ImageMagick libraries
  22144. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22145. }
  22146. // set alignment
  22147. $this->img_rb_y = $y + $h;
  22148. // set alignment
  22149. if ($this->rtl) {
  22150. if ($palign == 'L') {
  22151. $ximg = $this->lMargin;
  22152. } elseif ($palign == 'C') {
  22153. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22154. } elseif ($palign == 'R') {
  22155. $ximg = $this->w - $this->rMargin - $w;
  22156. } else {
  22157. $ximg = $x - $w;
  22158. }
  22159. $this->img_rb_x = $ximg;
  22160. } else {
  22161. if ($palign == 'L') {
  22162. $ximg = $this->lMargin;
  22163. } elseif ($palign == 'C') {
  22164. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22165. } elseif ($palign == 'R') {
  22166. $ximg = $this->w - $this->rMargin - $w;
  22167. } else {
  22168. $ximg = $x;
  22169. }
  22170. $this->img_rb_x = $ximg + $w;
  22171. }
  22172. // store current graphic vars
  22173. $gvars = $this->getGraphicVars();
  22174. // store SVG position and scale factors
  22175. $svgoffset_x = ($ximg - $ox) * $this->k;
  22176. $svgoffset_y = -($y - $oy) * $this->k;
  22177. if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  22178. $ow = $view_box[2];
  22179. $oh = $view_box[3];
  22180. } else {
  22181. if ($ow <= 0) {
  22182. $ow = $w;
  22183. }
  22184. if ($oh <= 0) {
  22185. $oh = $h;
  22186. }
  22187. }
  22188. $svgscale_x = $w / $ow;
  22189. $svgscale_y = $h / $oh;
  22190. // scaling and alignment
  22191. if ($aspect_ratio_align != 'none') {
  22192. // store current scaling values
  22193. $svgscale_old_x = $svgscale_x;
  22194. $svgscale_old_y = $svgscale_y;
  22195. // force uniform scaling
  22196. if ($aspect_ratio_ms == 'slice') {
  22197. // the entire viewport is covered by the viewBox
  22198. if ($svgscale_x > $svgscale_y) {
  22199. $svgscale_y = $svgscale_x;
  22200. } elseif ($svgscale_x < $svgscale_y) {
  22201. $svgscale_x = $svgscale_y;
  22202. }
  22203. } else { // meet
  22204. // the entire viewBox is visible within the viewport
  22205. if ($svgscale_x < $svgscale_y) {
  22206. $svgscale_y = $svgscale_x;
  22207. } elseif ($svgscale_x > $svgscale_y) {
  22208. $svgscale_x = $svgscale_y;
  22209. }
  22210. }
  22211. // correct X alignment
  22212. switch (substr($aspect_ratio_align, 1, 3)) {
  22213. case 'Min': {
  22214. // do nothing
  22215. break;
  22216. }
  22217. case 'Max': {
  22218. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  22219. break;
  22220. }
  22221. default:
  22222. case 'Mid': {
  22223. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  22224. break;
  22225. }
  22226. }
  22227. // correct Y alignment
  22228. switch (substr($aspect_ratio_align, 5)) {
  22229. case 'Min': {
  22230. // do nothing
  22231. break;
  22232. }
  22233. case 'Max': {
  22234. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  22235. break;
  22236. }
  22237. default:
  22238. case 'Mid': {
  22239. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  22240. break;
  22241. }
  22242. }
  22243. }
  22244. // store current page break mode
  22245. $page_break_mode = $this->AutoPageBreak;
  22246. $page_break_margin = $this->getBreakMargin();
  22247. $cell_padding = $this->cell_padding;
  22248. $this->SetCellPadding(0);
  22249. $this->SetAutoPageBreak(false);
  22250. // save the current graphic state
  22251. $this->_out('q'.$this->epsmarker);
  22252. // set initial clipping mask
  22253. $this->Rect($ximg, $y, $w, $h, 'CNZ', array(), array());
  22254. // scale and translate
  22255. $e = $ox * $this->k * (1 - $svgscale_x);
  22256. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  22257. $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e + $svgoffset_x), ($f + $svgoffset_y)));
  22258. // creates a new XML parser to be used by the other XML functions
  22259. $this->parser = xml_parser_create('UTF-8');
  22260. // the following function allows to use parser inside object
  22261. xml_set_object($this->parser, $this);
  22262. // disable case-folding for this XML parser
  22263. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  22264. // sets the element handler functions for the XML parser
  22265. xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler');
  22266. // sets the character data handler function for the XML parser
  22267. xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
  22268. // start parsing an XML document
  22269. if (!xml_parse($this->parser, $svgdata)) {
  22270. $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));
  22271. $this->Error($error_message);
  22272. }
  22273. // free this XML parser
  22274. xml_parser_free($this->parser);
  22275. // restore previous graphic state
  22276. $this->_out($this->epsmarker.'Q');
  22277. // restore graphic vars
  22278. $this->setGraphicVars($gvars);
  22279. $this->lasth = $gvars['lasth'];
  22280. if (!empty($border)) {
  22281. $bx = $this->x;
  22282. $by = $this->y;
  22283. $this->x = $ximg;
  22284. if ($this->rtl) {
  22285. $this->x += $w;
  22286. }
  22287. $this->y = $y;
  22288. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  22289. $this->x = $bx;
  22290. $this->y = $by;
  22291. }
  22292. if ($link) {
  22293. $this->Link($ximg, $y, $w, $h, $link, 0);
  22294. }
  22295. // set pointer to align the next text/objects
  22296. switch($align) {
  22297. case 'T':{
  22298. $this->y = $y;
  22299. $this->x = $this->img_rb_x;
  22300. break;
  22301. }
  22302. case 'M':{
  22303. $this->y = $y + round($h/2);
  22304. $this->x = $this->img_rb_x;
  22305. break;
  22306. }
  22307. case 'B':{
  22308. $this->y = $this->img_rb_y;
  22309. $this->x = $this->img_rb_x;
  22310. break;
  22311. }
  22312. case 'N':{
  22313. $this->SetY($this->img_rb_y);
  22314. break;
  22315. }
  22316. default:{
  22317. // restore pointer to starting position
  22318. $this->x = $gvars['x'];
  22319. $this->y = $gvars['y'];
  22320. $this->page = $gvars['page'];
  22321. $this->current_column = $gvars['current_column'];
  22322. $this->tMargin = $gvars['tMargin'];
  22323. $this->bMargin = $gvars['bMargin'];
  22324. $this->w = $gvars['w'];
  22325. $this->h = $gvars['h'];
  22326. $this->wPt = $gvars['wPt'];
  22327. $this->hPt = $gvars['hPt'];
  22328. $this->fwPt = $gvars['fwPt'];
  22329. $this->fhPt = $gvars['fhPt'];
  22330. break;
  22331. }
  22332. }
  22333. $this->endlinex = $this->img_rb_x;
  22334. // restore page break
  22335. $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
  22336. $this->cell_padding = $cell_padding;
  22337. }
  22338. /**
  22339. * Convert SVG transformation matrix to PDF.
  22340. * @param $tm (array) original SVG transformation matrix
  22341. * @return array transformation matrix
  22342. * @protected
  22343. * @since 5.0.000 (2010-05-02)
  22344. */
  22345. protected function convertSVGtMatrix($tm) {
  22346. $a = $tm[0];
  22347. $b = -$tm[1];
  22348. $c = -$tm[2];
  22349. $d = $tm[3];
  22350. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  22351. $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  22352. $x = 0;
  22353. $y = $this->h * $this->k;
  22354. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  22355. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  22356. return array($a, $b, $c, $d, $e, $f);
  22357. }
  22358. /**
  22359. * Apply SVG graphic transformation matrix.
  22360. * @param $tm (array) original SVG transformation matrix
  22361. * @protected
  22362. * @since 5.0.000 (2010-05-02)
  22363. */
  22364. protected function SVGTransform($tm) {
  22365. $this->Transform($this->convertSVGtMatrix($tm));
  22366. }
  22367. /**
  22368. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  22369. * @param $svgstyle (array) array of SVG styles to apply
  22370. * @param $prevsvgstyle (array) array of previous SVG style
  22371. * @param $x (int) X origin of the bounding box
  22372. * @param $y (int) Y origin of the bounding box
  22373. * @param $w (int) width of the bounding box
  22374. * @param $h (int) height of the bounding box
  22375. * @param $clip_function (string) clip function
  22376. * @param $clip_params (array) array of parameters for clipping function
  22377. * @return object style
  22378. * @author Nicola Asuni
  22379. * @since 5.0.000 (2010-05-02)
  22380. * @protected
  22381. */
  22382. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
  22383. if ($this->state != 2) {
  22384. return;
  22385. }
  22386. $objstyle = '';
  22387. $minlen = (0.01 / $this->k); // minimum acceptable length
  22388. if (!isset($svgstyle['opacity'])) {
  22389. return $objstyle;
  22390. }
  22391. // clip-path
  22392. $regs = array();
  22393. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
  22394. $clip_path = $this->svgclippaths[$regs[1]];
  22395. foreach ($clip_path as $cp) {
  22396. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  22397. }
  22398. }
  22399. // opacity
  22400. if ($svgstyle['opacity'] != 1) {
  22401. $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
  22402. }
  22403. // color
  22404. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors);
  22405. $this->SetFillColorArray($fill_color);
  22406. // text color
  22407. $text_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors);
  22408. $this->SetTextColorArray($text_color);
  22409. // clip
  22410. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
  22411. $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
  22412. $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
  22413. $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
  22414. $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
  22415. $cx = $x + $left;
  22416. $cy = $y + $top;
  22417. $cw = $w - $left - $right;
  22418. $ch = $h - $top - $bottom;
  22419. if ($svgstyle['clip-rule'] == 'evenodd') {
  22420. $clip_rule = 'CNZ';
  22421. } else {
  22422. $clip_rule = 'CEO';
  22423. }
  22424. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  22425. }
  22426. // fill
  22427. $regs = array();
  22428. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
  22429. // gradient
  22430. $gradient = $this->svggradients[$regs[1]];
  22431. if (isset($gradient['xref'])) {
  22432. // reference to another gradient definition
  22433. $newgradient = $this->svggradients[$gradient['xref']];
  22434. $newgradient['coords'] = $gradient['coords'];
  22435. $newgradient['mode'] = $gradient['mode'];
  22436. $newgradient['type'] = $gradient['type'];
  22437. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  22438. if (isset($gradient['gradientTransform'])) {
  22439. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  22440. }
  22441. $gradient = $newgradient;
  22442. }
  22443. //save current Graphic State
  22444. $this->_outSaveGraphicsState();
  22445. //set clipping area
  22446. if (!empty($clip_function) AND method_exists($this, $clip_function)) {
  22447. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  22448. if ((!isset($gradient['type']) OR ($gradient['type'] != 3)) AND is_array($bbox) AND (count($bbox) == 4)) {
  22449. list($x, $y, $w, $h) = $bbox;
  22450. }
  22451. }
  22452. if ($gradient['mode'] == 'measure') {
  22453. if (!isset($gradient['coords'][4])) {
  22454. $gradient['coords'][4] = 0.5;
  22455. }
  22456. if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  22457. $gtm = $gradient['gradientTransform'];
  22458. // apply transformation matrix
  22459. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  22460. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  22461. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  22462. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  22463. $r = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  22464. $gradient['coords'][0] = $xa;
  22465. $gradient['coords'][1] = $ya;
  22466. $gradient['coords'][2] = $xb;
  22467. $gradient['coords'][3] = $yb;
  22468. $gradient['coords'][4] = $r;
  22469. }
  22470. // convert SVG coordinates to user units
  22471. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  22472. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  22473. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  22474. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  22475. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  22476. if ($w <= $minlen) {
  22477. $w = $minlen;
  22478. }
  22479. if ($h <= $minlen) {
  22480. $h = $minlen;
  22481. }
  22482. // shift units
  22483. if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  22484. // convert to SVG coordinate system
  22485. $gradient['coords'][0] += $x;
  22486. $gradient['coords'][1] += $y;
  22487. $gradient['coords'][2] += $x;
  22488. $gradient['coords'][3] += $y;
  22489. }
  22490. // calculate percentages
  22491. $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
  22492. $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
  22493. $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
  22494. $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
  22495. $gradient['coords'][4] /= $w;
  22496. } elseif ($gradient['mode'] == 'percentage') {
  22497. foreach($gradient['coords'] as $key => $val) {
  22498. $gradient['coords'][$key] = (intval($val) / 100);
  22499. if ($val < 0) {
  22500. $gradient['coords'][$key] = 0;
  22501. } elseif ($val > 1) {
  22502. $gradient['coords'][$key] = 1;
  22503. }
  22504. }
  22505. }
  22506. if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  22507. // single color (no shading)
  22508. $gradient['coords'][0] = 1;
  22509. $gradient['coords'][1] = 0;
  22510. $gradient['coords'][2] = 0.999;
  22511. $gradient['coords'][3] = 0;
  22512. }
  22513. // swap Y coordinates
  22514. $tmp = $gradient['coords'][1];
  22515. $gradient['coords'][1] = $gradient['coords'][3];
  22516. $gradient['coords'][3] = $tmp;
  22517. // set transformation map for gradient
  22518. $cy = ($this->h - $y);
  22519. if ($gradient['type'] == 3) {
  22520. // circular gradient
  22521. $cy -= ($gradient['coords'][1] * ($w + $h));
  22522. $h = $w = max($w, $h);
  22523. } else {
  22524. $cy -= $h;
  22525. }
  22526. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), ($cy * $this->k)));
  22527. if (count($gradient['stops']) > 1) {
  22528. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  22529. }
  22530. } elseif ($svgstyle['fill'] != 'none') {
  22531. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
  22532. if ($svgstyle['fill-opacity'] != 1) {
  22533. $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
  22534. }
  22535. $this->SetFillColorArray($fill_color);
  22536. if ($svgstyle['fill-rule'] == 'evenodd') {
  22537. $objstyle .= 'F*';
  22538. } else {
  22539. $objstyle .= 'F';
  22540. }
  22541. }
  22542. // stroke
  22543. if ($svgstyle['stroke'] != 'none') {
  22544. if ($svgstyle['stroke-opacity'] != 1) {
  22545. $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false);
  22546. } elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i', $svgstyle['stroke'], $rgba_matches)) {
  22547. $this->setAlpha($rgba_matches[1], 'Normal', $this->alpha['ca'], false);
  22548. }
  22549. $stroke_style = array(
  22550. 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors),
  22551. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  22552. 'cap' => $svgstyle['stroke-linecap'],
  22553. 'join' => $svgstyle['stroke-linejoin']
  22554. );
  22555. if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  22556. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  22557. }
  22558. $this->SetLineStyle($stroke_style);
  22559. $objstyle .= 'D';
  22560. }
  22561. // font
  22562. $regs = array();
  22563. if (!empty($svgstyle['font'])) {
  22564. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
  22565. $font_family = $this->getFontFamilyName($regs[1]);
  22566. } else {
  22567. $font_family = $svgstyle['font-family'];
  22568. }
  22569. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22570. $font_size = trim($regs[1]);
  22571. } else {
  22572. $font_size = $svgstyle['font-size'];
  22573. }
  22574. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22575. $font_style = trim($regs[1]);
  22576. } else {
  22577. $font_style = $svgstyle['font-style'];
  22578. }
  22579. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22580. $font_weight = trim($regs[1]);
  22581. } else {
  22582. $font_weight = $svgstyle['font-weight'];
  22583. }
  22584. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22585. $font_stretch = trim($regs[1]);
  22586. } else {
  22587. $font_stretch = $svgstyle['font-stretch'];
  22588. }
  22589. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22590. $font_spacing = trim($regs[1]);
  22591. } else {
  22592. $font_spacing = $svgstyle['letter-spacing'];
  22593. }
  22594. } else {
  22595. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  22596. $font_size = $svgstyle['font-size'];
  22597. $font_style = $svgstyle['font-style'];
  22598. $font_weight = $svgstyle['font-weight'];
  22599. $font_stretch = $svgstyle['font-stretch'];
  22600. $font_spacing = $svgstyle['letter-spacing'];
  22601. }
  22602. $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit);
  22603. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  22604. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  22605. switch ($font_style) {
  22606. case 'italic': {
  22607. $font_style = 'I';
  22608. break;
  22609. }
  22610. case 'oblique': {
  22611. $font_style = 'I';
  22612. break;
  22613. }
  22614. default:
  22615. case 'normal': {
  22616. $font_style = '';
  22617. break;
  22618. }
  22619. }
  22620. switch ($font_weight) {
  22621. case 'bold':
  22622. case 'bolder': {
  22623. $font_style .= 'B';
  22624. break;
  22625. }
  22626. case 'normal': {
  22627. if ((substr($font_family, -1) == 'I') AND (substr($font_family, -2, 1) == 'B')) {
  22628. $font_family = substr($font_family, 0, -2).'I';
  22629. } elseif (substr($font_family, -1) == 'B') {
  22630. $font_family = substr($font_family, 0, -1);
  22631. }
  22632. break;
  22633. }
  22634. }
  22635. switch ($svgstyle['text-decoration']) {
  22636. case 'underline': {
  22637. $font_style .= 'U';
  22638. break;
  22639. }
  22640. case 'overline': {
  22641. $font_style .= 'O';
  22642. break;
  22643. }
  22644. case 'line-through': {
  22645. $font_style .= 'D';
  22646. break;
  22647. }
  22648. default:
  22649. case 'none': {
  22650. break;
  22651. }
  22652. }
  22653. $this->SetFont($font_family, $font_style, $font_size);
  22654. $this->setFontStretching($font_stretch);
  22655. $this->setFontSpacing($font_spacing);
  22656. return $objstyle;
  22657. }
  22658. /**
  22659. * Draws an SVG path
  22660. * @param $d (string) attribute d of the path SVG element
  22661. * @param $style (string) Style of rendering. Possible values are:
  22662. * <ul>
  22663. * <li>D or empty string: Draw (default).</li>
  22664. * <li>F: Fill.</li>
  22665. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22666. * <li>DF or FD: Draw and fill.</li>
  22667. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22668. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  22669. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  22670. * </ul>
  22671. * @return array of container box measures (x, y, w, h)
  22672. * @author Nicola Asuni
  22673. * @since 5.0.000 (2010-05-02)
  22674. * @protected
  22675. */
  22676. protected function SVGPath($d, $style='') {
  22677. if ($this->state != 2) {
  22678. return;
  22679. }
  22680. // set fill/stroke style
  22681. $op = TCPDF_STATIC::getPathPaintOperator($style, '');
  22682. if (empty($op)) {
  22683. return;
  22684. }
  22685. $paths = array();
  22686. $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
  22687. preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
  22688. $x = 0;
  22689. $y = 0;
  22690. $x1 = 0;
  22691. $y1 = 0;
  22692. $x2 = 0;
  22693. $y2 = 0;
  22694. $xmin = 2147483647;
  22695. $xmax = 0;
  22696. $ymin = 2147483647;
  22697. $ymax = 0;
  22698. $relcoord = false;
  22699. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  22700. $firstcmd = true; // used to print first point
  22701. // draw curve pieces
  22702. foreach ($paths as $key => $val) {
  22703. // get curve type
  22704. $cmd = trim($val[1]);
  22705. if (strtolower($cmd) == $cmd) {
  22706. // use relative coordinated instead of absolute
  22707. $relcoord = true;
  22708. $xoffset = $x;
  22709. $yoffset = $y;
  22710. } else {
  22711. $relcoord = false;
  22712. $xoffset = 0;
  22713. $yoffset = 0;
  22714. }
  22715. $params = array();
  22716. if (isset($val[2])) {
  22717. // get curve parameters
  22718. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  22719. $params = array();
  22720. foreach ($rawparams as $ck => $cp) {
  22721. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  22722. if (abs($params[$ck]) < $minlen) {
  22723. // approximate little values to zero
  22724. $params[$ck] = 0;
  22725. }
  22726. }
  22727. }
  22728. // store current origin point
  22729. $x0 = $x;
  22730. $y0 = $y;
  22731. switch (strtoupper($cmd)) {
  22732. case 'M': { // moveto
  22733. foreach ($params as $ck => $cp) {
  22734. if (($ck % 2) == 0) {
  22735. $x = $cp + $xoffset;
  22736. } else {
  22737. $y = $cp + $yoffset;
  22738. if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22739. if ($ck == 1) {
  22740. $this->_outPoint($x, $y);
  22741. $firstcmd = false;
  22742. } else {
  22743. $this->_outLine($x, $y);
  22744. }
  22745. $x0 = $x;
  22746. $y0 = $y;
  22747. }
  22748. $xmin = min($xmin, $x);
  22749. $ymin = min($ymin, $y);
  22750. $xmax = max($xmax, $x);
  22751. $ymax = max($ymax, $y);
  22752. if ($relcoord) {
  22753. $xoffset = $x;
  22754. $yoffset = $y;
  22755. }
  22756. }
  22757. }
  22758. break;
  22759. }
  22760. case 'L': { // lineto
  22761. foreach ($params as $ck => $cp) {
  22762. if (($ck % 2) == 0) {
  22763. $x = $cp + $xoffset;
  22764. } else {
  22765. $y = $cp + $yoffset;
  22766. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22767. $this->_outLine($x, $y);
  22768. $x0 = $x;
  22769. $y0 = $y;
  22770. }
  22771. $xmin = min($xmin, $x);
  22772. $ymin = min($ymin, $y);
  22773. $xmax = max($xmax, $x);
  22774. $ymax = max($ymax, $y);
  22775. if ($relcoord) {
  22776. $xoffset = $x;
  22777. $yoffset = $y;
  22778. }
  22779. }
  22780. }
  22781. break;
  22782. }
  22783. case 'H': { // horizontal lineto
  22784. foreach ($params as $ck => $cp) {
  22785. $x = $cp + $xoffset;
  22786. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22787. $this->_outLine($x, $y);
  22788. $x0 = $x;
  22789. $y0 = $y;
  22790. }
  22791. $xmin = min($xmin, $x);
  22792. $xmax = max($xmax, $x);
  22793. if ($relcoord) {
  22794. $xoffset = $x;
  22795. }
  22796. }
  22797. break;
  22798. }
  22799. case 'V': { // vertical lineto
  22800. foreach ($params as $ck => $cp) {
  22801. $y = $cp + $yoffset;
  22802. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22803. $this->_outLine($x, $y);
  22804. $x0 = $x;
  22805. $y0 = $y;
  22806. }
  22807. $ymin = min($ymin, $y);
  22808. $ymax = max($ymax, $y);
  22809. if ($relcoord) {
  22810. $yoffset = $y;
  22811. }
  22812. }
  22813. break;
  22814. }
  22815. case 'C': { // curveto
  22816. foreach ($params as $ck => $cp) {
  22817. $params[$ck] = $cp;
  22818. if ((($ck + 1) % 6) == 0) {
  22819. $x1 = $params[($ck - 5)] + $xoffset;
  22820. $y1 = $params[($ck - 4)] + $yoffset;
  22821. $x2 = $params[($ck - 3)] + $xoffset;
  22822. $y2 = $params[($ck - 2)] + $yoffset;
  22823. $x = $params[($ck - 1)] + $xoffset;
  22824. $y = $params[($ck)] + $yoffset;
  22825. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  22826. $xmin = min($xmin, $x, $x1, $x2);
  22827. $ymin = min($ymin, $y, $y1, $y2);
  22828. $xmax = max($xmax, $x, $x1, $x2);
  22829. $ymax = max($ymax, $y, $y1, $y2);
  22830. if ($relcoord) {
  22831. $xoffset = $x;
  22832. $yoffset = $y;
  22833. }
  22834. }
  22835. }
  22836. break;
  22837. }
  22838. case 'S': { // shorthand/smooth curveto
  22839. foreach ($params as $ck => $cp) {
  22840. $params[$ck] = $cp;
  22841. if ((($ck + 1) % 4) == 0) {
  22842. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
  22843. $x1 = (2 * $x) - $x2;
  22844. $y1 = (2 * $y) - $y2;
  22845. } else {
  22846. $x1 = $x;
  22847. $y1 = $y;
  22848. }
  22849. $x2 = $params[($ck - 3)] + $xoffset;
  22850. $y2 = $params[($ck - 2)] + $yoffset;
  22851. $x = $params[($ck - 1)] + $xoffset;
  22852. $y = $params[($ck)] + $yoffset;
  22853. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  22854. $xmin = min($xmin, $x, $x1, $x2);
  22855. $ymin = min($ymin, $y, $y1, $y2);
  22856. $xmax = max($xmax, $x, $x1, $x2);
  22857. $ymax = max($ymax, $y, $y1, $y2);
  22858. if ($relcoord) {
  22859. $xoffset = $x;
  22860. $yoffset = $y;
  22861. }
  22862. }
  22863. }
  22864. break;
  22865. }
  22866. case 'Q': { // quadratic Bezier curveto
  22867. foreach ($params as $ck => $cp) {
  22868. $params[$ck] = $cp;
  22869. if ((($ck + 1) % 4) == 0) {
  22870. // convert quadratic points to cubic points
  22871. $x1 = $params[($ck - 3)] + $xoffset;
  22872. $y1 = $params[($ck - 2)] + $yoffset;
  22873. $xa = ($x + (2 * $x1)) / 3;
  22874. $ya = ($y + (2 * $y1)) / 3;
  22875. $x = $params[($ck - 1)] + $xoffset;
  22876. $y = $params[($ck)] + $yoffset;
  22877. $xb = ($x + (2 * $x1)) / 3;
  22878. $yb = ($y + (2 * $y1)) / 3;
  22879. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  22880. $xmin = min($xmin, $x, $xa, $xb);
  22881. $ymin = min($ymin, $y, $ya, $yb);
  22882. $xmax = max($xmax, $x, $xa, $xb);
  22883. $ymax = max($ymax, $y, $ya, $yb);
  22884. if ($relcoord) {
  22885. $xoffset = $x;
  22886. $yoffset = $y;
  22887. }
  22888. }
  22889. }
  22890. break;
  22891. }
  22892. case 'T': { // shorthand/smooth quadratic Bezier curveto
  22893. foreach ($params as $ck => $cp) {
  22894. $params[$ck] = $cp;
  22895. if (($ck % 2) != 0) {
  22896. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
  22897. $x1 = (2 * $x) - $x1;
  22898. $y1 = (2 * $y) - $y1;
  22899. } else {
  22900. $x1 = $x;
  22901. $y1 = $y;
  22902. }
  22903. // convert quadratic points to cubic points
  22904. $xa = ($x + (2 * $x1)) / 3;
  22905. $ya = ($y + (2 * $y1)) / 3;
  22906. $x = $params[($ck - 1)] + $xoffset;
  22907. $y = $params[($ck)] + $yoffset;
  22908. $xb = ($x + (2 * $x1)) / 3;
  22909. $yb = ($y + (2 * $y1)) / 3;
  22910. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  22911. $xmin = min($xmin, $x, $xa, $xb);
  22912. $ymin = min($ymin, $y, $ya, $yb);
  22913. $xmax = max($xmax, $x, $xa, $xb);
  22914. $ymax = max($ymax, $y, $ya, $yb);
  22915. if ($relcoord) {
  22916. $xoffset = $x;
  22917. $yoffset = $y;
  22918. }
  22919. }
  22920. }
  22921. break;
  22922. }
  22923. case 'A': { // elliptical arc
  22924. foreach ($params as $ck => $cp) {
  22925. $params[$ck] = $cp;
  22926. if ((($ck + 1) % 7) == 0) {
  22927. $x0 = $x;
  22928. $y0 = $y;
  22929. $rx = abs($params[($ck - 6)]);
  22930. $ry = abs($params[($ck - 5)]);
  22931. $ang = -$rawparams[($ck - 4)];
  22932. $angle = deg2rad($ang);
  22933. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  22934. $fs = $rawparams[($ck - 2)]; // sweep-flag
  22935. $x = $params[($ck - 1)] + $xoffset;
  22936. $y = $params[$ck] + $yoffset;
  22937. if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
  22938. // endpoints are almost identical
  22939. $xmin = min($xmin, $x);
  22940. $ymin = min($ymin, $y);
  22941. $xmax = max($xmax, $x);
  22942. $ymax = max($ymax, $y);
  22943. } else {
  22944. $cos_ang = cos($angle);
  22945. $sin_ang = sin($angle);
  22946. $a = (($x0 - $x) / 2);
  22947. $b = (($y0 - $y) / 2);
  22948. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  22949. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  22950. $rx2 = $rx * $rx;
  22951. $ry2 = $ry * $ry;
  22952. $xa2 = $xa * $xa;
  22953. $ya2 = $ya * $ya;
  22954. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  22955. if ($delta > 1) {
  22956. $rx *= sqrt($delta);
  22957. $ry *= sqrt($delta);
  22958. $rx2 = $rx * $rx;
  22959. $ry2 = $ry * $ry;
  22960. }
  22961. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  22962. if ($numerator < 0) {
  22963. $root = 0;
  22964. } else {
  22965. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  22966. }
  22967. if ($fa == $fs){
  22968. $root *= -1;
  22969. }
  22970. $cax = $root * (($rx * $ya) / $ry);
  22971. $cay = -$root * (($ry * $xa) / $rx);
  22972. // coordinates of ellipse center
  22973. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  22974. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  22975. // get angles
  22976. $angs = TCPDF_STATIC::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  22977. $dang = TCPDF_STATIC::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
  22978. if (($fs == 0) AND ($dang > 0)) {
  22979. $dang -= (2 * M_PI);
  22980. } elseif (($fs == 1) AND ($dang < 0)) {
  22981. $dang += (2 * M_PI);
  22982. }
  22983. $angf = $angs - $dang;
  22984. if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
  22985. // reverse angles
  22986. $tmp = $angs;
  22987. $angs = $angf;
  22988. $angf = $tmp;
  22989. }
  22990. $angs = round(rad2deg($angs), 6);
  22991. $angf = round(rad2deg($angf), 6);
  22992. // covent angles to positive values
  22993. if (($angs < 0) AND ($angf < 0)) {
  22994. $angs += 360;
  22995. $angf += 360;
  22996. }
  22997. $pie = false;
  22998. if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
  22999. $pie = true;
  23000. }
  23001. list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
  23002. $xmin = min($xmin, $x, $axmin);
  23003. $ymin = min($ymin, $y, $aymin);
  23004. $xmax = max($xmax, $x, $axmax);
  23005. $ymax = max($ymax, $y, $aymax);
  23006. }
  23007. if ($relcoord) {
  23008. $xoffset = $x;
  23009. $yoffset = $y;
  23010. }
  23011. }
  23012. }
  23013. break;
  23014. }
  23015. case 'Z': {
  23016. $this->_out('h');
  23017. break;
  23018. }
  23019. }
  23020. $firstcmd = false;
  23021. } // end foreach
  23022. if (!empty($op)) {
  23023. $this->_out($op);
  23024. }
  23025. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  23026. }
  23027. /**
  23028. * Return the tag name without the namespace
  23029. * @param $name (string) Tag name
  23030. * @protected
  23031. */
  23032. protected function removeTagNamespace($name) {
  23033. if(strpos($name, ':') !== false) {
  23034. $parts = explode(':', $name);
  23035. return $parts[(sizeof($parts) - 1)];
  23036. }
  23037. return $name;
  23038. }
  23039. /**
  23040. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  23041. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  23042. * @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
  23043. * @param $attribs (array) The third parameter, attribs, contains an associative array with the element's attributes (if any). The keys of this array are the attribute names, the values are the attribute values. Attribute names are case-folded on the same criteria as element names. Attribute values are not case-folded. The original order of the attributes can be retrieved by walking through attribs the normal way, using each(). The first key in the array was the first attribute, and so on.
  23044. * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix).
  23045. * @author Nicola Asuni
  23046. * @since 5.0.000 (2010-05-02)
  23047. * @protected
  23048. */
  23049. protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
  23050. $name = $this->removeTagNamespace($name);
  23051. // check if we are in clip mode
  23052. if ($this->svgclipmode) {
  23053. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
  23054. return;
  23055. }
  23056. if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
  23057. if (isset($attribs['id'])) {
  23058. $attribs['child_elements'] = array();
  23059. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  23060. return;
  23061. }
  23062. if (end($this->svgdefs) !== FALSE) {
  23063. $last_svgdefs_id = key($this->svgdefs);
  23064. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23065. $attribs['id'] = 'DF_'.(count($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements']) + 1);
  23066. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  23067. return;
  23068. }
  23069. }
  23070. return;
  23071. }
  23072. $clipping = false;
  23073. if ($parser == 'clip-path') {
  23074. // set clipping mode
  23075. $clipping = true;
  23076. }
  23077. // get styling properties
  23078. $prev_svgstyle = $this->svgstyles[max(0,(count($this->svgstyles) - 1))]; // previous style
  23079. $svgstyle = $this->svgstyles[0]; // set default style
  23080. if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
  23081. // default fill attribute for clipping
  23082. $attribs['fill'] = 'none';
  23083. }
  23084. if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style']) AND ($attribs['style'][0] != ';')) {
  23085. // fix style for regular expression
  23086. $attribs['style'] = ';'.$attribs['style'];
  23087. }
  23088. foreach ($prev_svgstyle as $key => $val) {
  23089. if (in_array($key, TCPDF_IMAGES::$svginheritprop)) {
  23090. // inherit previous value
  23091. $svgstyle[$key] = $val;
  23092. }
  23093. if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) {
  23094. // specific attribute settings
  23095. if ($attribs[$key] == 'inherit') {
  23096. $svgstyle[$key] = $val;
  23097. } else {
  23098. $svgstyle[$key] = $attribs[$key];
  23099. }
  23100. } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  23101. // CSS style syntax
  23102. $attrval = array();
  23103. if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
  23104. if ($attrval[1] == 'inherit') {
  23105. $svgstyle[$key] = $val;
  23106. } else {
  23107. $svgstyle[$key] = $attrval[1];
  23108. }
  23109. }
  23110. }
  23111. }
  23112. // transformation matrix
  23113. if (!empty($ctm)) {
  23114. $tm = $ctm;
  23115. } else {
  23116. $tm = array(1,0,0,1,0,0);
  23117. }
  23118. if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  23119. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, TCPDF_STATIC::getSVGTransformMatrix($attribs['transform']));
  23120. }
  23121. $svgstyle['transfmatrix'] = $tm;
  23122. $invisible = false;
  23123. if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  23124. // the current graphics element is invisible (nothing is painted)
  23125. $invisible = true;
  23126. }
  23127. // process tag
  23128. switch($name) {
  23129. case 'defs': {
  23130. $this->svgdefsmode = true;
  23131. break;
  23132. }
  23133. // clipPath
  23134. case 'clipPath': {
  23135. if ($invisible) {
  23136. break;
  23137. }
  23138. $this->svgclipmode = true;
  23139. if (!isset($attribs['id'])) {
  23140. $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  23141. }
  23142. $this->svgclipid = $attribs['id'];
  23143. $this->svgclippaths[$this->svgclipid] = array();
  23144. $this->svgcliptm[$this->svgclipid] = $tm;
  23145. break;
  23146. }
  23147. case 'svg': {
  23148. // start of SVG object
  23149. if(++$this->svg_tag_depth <= 1) {
  23150. break;
  23151. }
  23152. // inner SVG
  23153. array_push($this->svgstyles, $svgstyle);
  23154. $this->StartTransform();
  23155. $svgX = (isset($attribs['x'])?$attribs['x']:0);
  23156. $svgY = (isset($attribs['y'])?$attribs['y']:0);
  23157. $svgW = (isset($attribs['width'])?$attribs['width']:0);
  23158. $svgH = (isset($attribs['height'])?$attribs['height']:0);
  23159. // set x, y position using transform matrix
  23160. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array( 1, 0, 0, 1, $svgX, $svgY));
  23161. $this->SVGTransform($tm);
  23162. // set clipping for width and height
  23163. $x = 0;
  23164. $y = 0;
  23165. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):$this->w);
  23166. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):$this->h);
  23167. // draw clipping rect
  23168. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  23169. // parse viewbox, calculate extra transformation matrix
  23170. if (isset($attribs['viewBox'])) {
  23171. $tmp = array();
  23172. preg_match_all("/[0-9]+/", $attribs['viewBox'], $tmp);
  23173. $tmp = $tmp[0];
  23174. if (sizeof($tmp) == 4) {
  23175. $vx = $tmp[0];
  23176. $vy = $tmp[1];
  23177. $vw = $tmp[2];
  23178. $vh = $tmp[3];
  23179. // get aspect ratio
  23180. $tmp = array();
  23181. $aspectX = 'xMid';
  23182. $aspectY = 'YMid';
  23183. $fit = 'meet';
  23184. if (isset($attribs['preserveAspectRatio'])) {
  23185. if($attribs['preserveAspectRatio'] == 'none') {
  23186. $fit = 'none';
  23187. } else {
  23188. preg_match_all('/[a-zA-Z]+/', $attribs['preserveAspectRatio'], $tmp);
  23189. $tmp = $tmp[0];
  23190. if ((sizeof($tmp) == 2) AND (strlen($tmp[0]) == 8) AND (in_array($tmp[1], array('meet', 'slice', 'none')))) {
  23191. $aspectX = substr($tmp[0], 0, 4);
  23192. $aspectY = substr($tmp[0], 4, 4);
  23193. $fit = $tmp[1];
  23194. }
  23195. }
  23196. }
  23197. $wr = ($svgW / $vw);
  23198. $hr = ($svgH / $vh);
  23199. $ax = $ay = 0;
  23200. if ((($fit == 'meet') AND ($hr < $wr)) OR (($fit == 'slice') AND ($hr > $wr))) {
  23201. if ($aspectX == 'xMax') {
  23202. $ax = (($vw * ($wr / $hr)) - $vw);
  23203. }
  23204. if ($aspectX == 'xMid') {
  23205. $ax = ((($vw * ($wr / $hr)) - $vw) / 2);
  23206. }
  23207. $wr = $hr;
  23208. } elseif ((($fit == 'meet') AND ($hr > $wr)) OR (($fit == 'slice') AND ($hr < $wr))) {
  23209. if ($aspectY == 'YMax') {
  23210. $ay = (($vh * ($hr / $wr)) - $vh);
  23211. }
  23212. if ($aspectY == 'YMid') {
  23213. $ay = ((($vh * ($hr / $wr)) - $vh) / 2);
  23214. }
  23215. $hr = $wr;
  23216. }
  23217. $newtm = array($wr, 0, 0, $hr, (($wr * ($ax - $vx)) - $svgX), (($hr * ($ay - $vy)) - $svgY));
  23218. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, $newtm);
  23219. $this->SVGTransform($tm);
  23220. }
  23221. }
  23222. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23223. break;
  23224. }
  23225. case 'g': {
  23226. // group together related graphics elements
  23227. array_push($this->svgstyles, $svgstyle);
  23228. $this->StartTransform();
  23229. $x = (isset($attribs['x'])?$attribs['x']:0);
  23230. $y = (isset($attribs['y'])?$attribs['y']:0);
  23231. $w = 1;//(isset($attribs['width'])?$attribs['width']:1);
  23232. $h = 1;//(isset($attribs['height'])?$attribs['height']:1);
  23233. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23234. $this->SVGTransform($tm);
  23235. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23236. break;
  23237. }
  23238. case 'linearGradient': {
  23239. if ($this->pdfa_mode) {
  23240. break;
  23241. }
  23242. if (!isset($attribs['id'])) {
  23243. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23244. }
  23245. $this->svggradientid = $attribs['id'];
  23246. $this->svggradients[$this->svggradientid] = array();
  23247. $this->svggradients[$this->svggradientid]['type'] = 2;
  23248. $this->svggradients[$this->svggradientid]['stops'] = array();
  23249. if (isset($attribs['gradientUnits'])) {
  23250. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23251. } else {
  23252. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23253. }
  23254. //$attribs['spreadMethod']
  23255. if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
  23256. OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
  23257. OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
  23258. OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
  23259. OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
  23260. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23261. } else {
  23262. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23263. }
  23264. $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
  23265. $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
  23266. $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
  23267. $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
  23268. if (isset($attribs['gradientTransform'])) {
  23269. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23270. }
  23271. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  23272. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23273. // gradient is defined on another place
  23274. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23275. }
  23276. break;
  23277. }
  23278. case 'radialGradient': {
  23279. if ($this->pdfa_mode) {
  23280. break;
  23281. }
  23282. if (!isset($attribs['id'])) {
  23283. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23284. }
  23285. $this->svggradientid = $attribs['id'];
  23286. $this->svggradients[$this->svggradientid] = array();
  23287. $this->svggradients[$this->svggradientid]['type'] = 3;
  23288. $this->svggradients[$this->svggradientid]['stops'] = array();
  23289. if (isset($attribs['gradientUnits'])) {
  23290. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23291. } else {
  23292. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23293. }
  23294. //$attribs['spreadMethod']
  23295. if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
  23296. OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
  23297. OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')))) {
  23298. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23299. } elseif (isset($attribs['r']) AND is_numeric($attribs['r']) AND ($attribs['r']) <= 1) {
  23300. $this->svggradients[$this->svggradientid]['mode'] = 'ratio';
  23301. } else {
  23302. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23303. }
  23304. $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  23305. $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  23306. $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  23307. $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  23308. $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  23309. if (isset($attribs['gradientTransform'])) {
  23310. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23311. }
  23312. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  23313. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23314. // gradient is defined on another place
  23315. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23316. }
  23317. break;
  23318. }
  23319. case 'stop': {
  23320. // gradient stops
  23321. if (substr($attribs['offset'], -1) == '%') {
  23322. $offset = floatval(substr($attribs['offset'], -1)) / 100;
  23323. } else {
  23324. $offset = floatval($attribs['offset']);
  23325. if ($offset > 1) {
  23326. $offset /= 100;
  23327. }
  23328. }
  23329. $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black';
  23330. $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  23331. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
  23332. break;
  23333. }
  23334. // paths
  23335. case 'path': {
  23336. if ($invisible) {
  23337. break;
  23338. }
  23339. if (isset($attribs['d'])) {
  23340. $d = trim($attribs['d']);
  23341. if (!empty($d)) {
  23342. $x = (isset($attribs['x'])?$attribs['x']:0);
  23343. $y = (isset($attribs['y'])?$attribs['y']:0);
  23344. $w = (isset($attribs['width'])?$attribs['width']:1);
  23345. $h = (isset($attribs['height'])?$attribs['height']:1);
  23346. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23347. if ($clipping) {
  23348. $this->SVGTransform($tm);
  23349. $this->SVGPath($d, 'CNZ');
  23350. } else {
  23351. $this->StartTransform();
  23352. $this->SVGTransform($tm);
  23353. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ'));
  23354. if (!empty($obstyle)) {
  23355. $this->SVGPath($d, $obstyle);
  23356. }
  23357. $this->StopTransform();
  23358. }
  23359. }
  23360. }
  23361. break;
  23362. }
  23363. // shapes
  23364. case 'rect': {
  23365. if ($invisible) {
  23366. break;
  23367. }
  23368. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23369. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23370. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23371. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23372. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  23373. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
  23374. if ($clipping) {
  23375. $this->SVGTransform($tm);
  23376. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  23377. } else {
  23378. $this->StartTransform();
  23379. $this->SVGTransform($tm);
  23380. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  23381. if (!empty($obstyle)) {
  23382. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  23383. }
  23384. $this->StopTransform();
  23385. }
  23386. break;
  23387. }
  23388. case 'circle': {
  23389. if ($invisible) {
  23390. break;
  23391. }
  23392. $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
  23393. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23394. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23395. $x = ($cx - $r);
  23396. $y = ($cy - $r);
  23397. $w = (2 * $r);
  23398. $h = $w;
  23399. if ($clipping) {
  23400. $this->SVGTransform($tm);
  23401. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  23402. } else {
  23403. $this->StartTransform();
  23404. $this->SVGTransform($tm);
  23405. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
  23406. if (!empty($obstyle)) {
  23407. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  23408. }
  23409. $this->StopTransform();
  23410. }
  23411. break;
  23412. }
  23413. case 'ellipse': {
  23414. if ($invisible) {
  23415. break;
  23416. }
  23417. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  23418. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
  23419. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23420. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23421. $x = ($cx - $rx);
  23422. $y = ($cy - $ry);
  23423. $w = (2 * $rx);
  23424. $h = (2 * $ry);
  23425. if ($clipping) {
  23426. $this->SVGTransform($tm);
  23427. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  23428. } else {
  23429. $this->StartTransform();
  23430. $this->SVGTransform($tm);
  23431. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  23432. if (!empty($obstyle)) {
  23433. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  23434. }
  23435. $this->StopTransform();
  23436. }
  23437. break;
  23438. }
  23439. case 'line': {
  23440. if ($invisible) {
  23441. break;
  23442. }
  23443. $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
  23444. $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
  23445. $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
  23446. $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
  23447. $x = $x1;
  23448. $y = $y1;
  23449. $w = abs($x2 - $x1);
  23450. $h = abs($y2 - $y1);
  23451. if (!$clipping) {
  23452. $this->StartTransform();
  23453. $this->SVGTransform($tm);
  23454. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
  23455. $this->Line($x1, $y1, $x2, $y2);
  23456. $this->StopTransform();
  23457. }
  23458. break;
  23459. }
  23460. case 'polyline':
  23461. case 'polygon': {
  23462. if ($invisible) {
  23463. break;
  23464. }
  23465. $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  23466. $points = trim($points);
  23467. // note that point may use a complex syntax not covered here
  23468. $points = preg_split('/[\,\s]+/si', $points);
  23469. if (count($points) < 4) {
  23470. break;
  23471. }
  23472. $p = array();
  23473. $xmin = 2147483647;
  23474. $xmax = 0;
  23475. $ymin = 2147483647;
  23476. $ymax = 0;
  23477. foreach ($points as $key => $val) {
  23478. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  23479. if (($key % 2) == 0) {
  23480. // X coordinate
  23481. $xmin = min($xmin, $p[$key]);
  23482. $xmax = max($xmax, $p[$key]);
  23483. } else {
  23484. // Y coordinate
  23485. $ymin = min($ymin, $p[$key]);
  23486. $ymax = max($ymax, $p[$key]);
  23487. }
  23488. }
  23489. $x = $xmin;
  23490. $y = $ymin;
  23491. $w = ($xmax - $xmin);
  23492. $h = ($ymax - $ymin);
  23493. if ($name == 'polyline') {
  23494. $this->StartTransform();
  23495. $this->SVGTransform($tm);
  23496. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
  23497. if (!empty($obstyle)) {
  23498. $this->PolyLine($p, $obstyle, array(), array());
  23499. }
  23500. $this->StopTransform();
  23501. } else { // polygon
  23502. if ($clipping) {
  23503. $this->SVGTransform($tm);
  23504. $this->Polygon($p, 'CNZ', array(), array(), true);
  23505. } else {
  23506. $this->StartTransform();
  23507. $this->SVGTransform($tm);
  23508. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
  23509. if (!empty($obstyle)) {
  23510. $this->Polygon($p, $obstyle, array(), array(), true);
  23511. }
  23512. $this->StopTransform();
  23513. }
  23514. }
  23515. break;
  23516. }
  23517. // image
  23518. case 'image': {
  23519. if ($invisible) {
  23520. break;
  23521. }
  23522. if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  23523. break;
  23524. }
  23525. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23526. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23527. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23528. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23529. $img = $attribs['xlink:href'];
  23530. if (!$clipping) {
  23531. $this->StartTransform();
  23532. $this->SVGTransform($tm);
  23533. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  23534. if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
  23535. // embedded image encoded as base64
  23536. $img = '@'.base64_decode(substr($img, strlen($m[0])));
  23537. } else {
  23538. // fix image path
  23539. if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) {
  23540. // replace relative path with full server path
  23541. $img = $this->svgdir.'/'.$img;
  23542. }
  23543. if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  23544. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  23545. if (($findroot === false) OR ($findroot > 1)) {
  23546. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  23547. $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
  23548. } else {
  23549. $img = $_SERVER['DOCUMENT_ROOT'].$img;
  23550. }
  23551. }
  23552. }
  23553. $img = urldecode($img);
  23554. $testscrtype = @parse_url($img);
  23555. if (empty($testscrtype['query'])) {
  23556. // convert URL to server path
  23557. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  23558. } elseif (preg_match('|^https?://|', $img) !== 1) {
  23559. // convert server path to URL
  23560. $img = str_replace(K_PATH_MAIN, K_PATH_URL, $img);
  23561. }
  23562. }
  23563. // get image type
  23564. $imgtype = TCPDF_IMAGES::getImageFileType($img);
  23565. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  23566. $this->ImageEps($img, $x, $y, $w, $h);
  23567. } elseif ($imgtype == 'svg') {
  23568. // store SVG vars
  23569. $svggradients = $this->svggradients;
  23570. $svggradientid = $this->svggradientid;
  23571. $svgdefsmode = $this->svgdefsmode;
  23572. $svgdefs = $this->svgdefs;
  23573. $svgclipmode = $this->svgclipmode;
  23574. $svgclippaths = $this->svgclippaths;
  23575. $svgcliptm = $this->svgcliptm;
  23576. $svgclipid = $this->svgclipid;
  23577. $svgtext = $this->svgtext;
  23578. $svgtextmode = $this->svgtextmode;
  23579. $this->ImageSVG($img, $x, $y, $w, $h);
  23580. // restore SVG vars
  23581. $this->svggradients = $svggradients;
  23582. $this->svggradientid = $svggradientid;
  23583. $this->svgdefsmode = $svgdefsmode;
  23584. $this->svgdefs = $svgdefs;
  23585. $this->svgclipmode = $svgclipmode;
  23586. $this->svgclippaths = $svgclippaths;
  23587. $this->svgcliptm = $svgcliptm;
  23588. $this->svgclipid = $svgclipid;
  23589. $this->svgtext = $svgtext;
  23590. $this->svgtextmode = $svgtextmode;
  23591. } else {
  23592. $this->Image($img, $x, $y, $w, $h);
  23593. }
  23594. $this->StopTransform();
  23595. }
  23596. break;
  23597. }
  23598. // text
  23599. case 'text':
  23600. case 'tspan': {
  23601. if (isset($this->svgtextmode['text-anchor']) AND !empty($this->svgtext)) {
  23602. // @TODO: unsupported feature
  23603. }
  23604. // only basic support - advanced features must be implemented
  23605. $this->svgtextmode['invisible'] = $invisible;
  23606. if ($invisible) {
  23607. break;
  23608. }
  23609. array_push($this->svgstyles, $svgstyle);
  23610. if (isset($attribs['x'])) {
  23611. $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false);
  23612. } elseif ($name == 'tspan') {
  23613. $x = $this->x;
  23614. } else {
  23615. $x = 0;
  23616. }
  23617. if (isset($attribs['dx'])) {
  23618. $x += $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit, false);
  23619. }
  23620. if (isset($attribs['y'])) {
  23621. $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false);
  23622. } elseif ($name == 'tspan') {
  23623. $y = $this->y;
  23624. } else {
  23625. $y = 0;
  23626. }
  23627. if (isset($attribs['dy'])) {
  23628. $y += $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit, false);
  23629. }
  23630. $svgstyle['text-color'] = $svgstyle['fill'];
  23631. $this->svgtext = '';
  23632. if (isset($svgstyle['text-anchor'])) {
  23633. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  23634. } else {
  23635. $this->svgtextmode['text-anchor'] = 'start';
  23636. }
  23637. if (isset($svgstyle['direction'])) {
  23638. if ($svgstyle['direction'] == 'rtl') {
  23639. $this->svgtextmode['rtl'] = true;
  23640. } else {
  23641. $this->svgtextmode['rtl'] = false;
  23642. }
  23643. } else {
  23644. $this->svgtextmode['rtl'] = false;
  23645. }
  23646. if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  23647. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  23648. } else {
  23649. $this->svgtextmode['stroke'] = false;
  23650. }
  23651. $this->StartTransform();
  23652. $this->SVGTransform($tm);
  23653. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  23654. $this->x = $x;
  23655. $this->y = $y;
  23656. break;
  23657. }
  23658. // use
  23659. case 'use': {
  23660. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23661. $svgdefid = substr($attribs['xlink:href'], 1);
  23662. if (isset($this->svgdefs[$svgdefid])) {
  23663. $use = $this->svgdefs[$svgdefid];
  23664. if (isset($attribs['xlink:href'])) {
  23665. unset($attribs['xlink:href']);
  23666. }
  23667. if (isset($attribs['id'])) {
  23668. unset($attribs['id']);
  23669. }
  23670. if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
  23671. $attribs['x'] += $use['attribs']['x'];
  23672. }
  23673. if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
  23674. $attribs['y'] += $use['attribs']['y'];
  23675. }
  23676. if (empty($attribs['style'])) {
  23677. $attribs['style'] = '';
  23678. }
  23679. if (!empty($use['attribs']['style'])) {
  23680. // merge styles
  23681. $attribs['style'] = str_replace(';;',';',';'.$use['attribs']['style'].$attribs['style']);
  23682. }
  23683. $attribs = array_merge($use['attribs'], $attribs);
  23684. $this->startSVGElementHandler($parser, $use['name'], $attribs);
  23685. return;
  23686. }
  23687. }
  23688. break;
  23689. }
  23690. default: {
  23691. break;
  23692. }
  23693. } // end of switch
  23694. // process child elements
  23695. if (!empty($attribs['child_elements'])) {
  23696. $child_elements = $attribs['child_elements'];
  23697. unset($attribs['child_elements']);
  23698. foreach($child_elements as $child_element) {
  23699. if (empty($child_element['attribs']['closing_tag'])) {
  23700. $this->startSVGElementHandler('child-tag', $child_element['name'], $child_element['attribs']);
  23701. } else {
  23702. if (isset($child_element['attribs']['content'])) {
  23703. $this->svgtext = $child_element['attribs']['content'];
  23704. }
  23705. $this->endSVGElementHandler('child-tag', $child_element['name']);
  23706. }
  23707. }
  23708. }
  23709. }
  23710. /**
  23711. * Sets the closing SVG element handler function for the XML parser.
  23712. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  23713. * @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
  23714. * @author Nicola Asuni
  23715. * @since 5.0.000 (2010-05-02)
  23716. * @protected
  23717. */
  23718. protected function endSVGElementHandler($parser, $name) {
  23719. $name = $this->removeTagNamespace($name);
  23720. if ($this->svgdefsmode AND !in_array($name, array('defs', 'clipPath', 'linearGradient', 'radialGradient', 'stop'))) {;
  23721. if (end($this->svgdefs) !== FALSE) {
  23722. $last_svgdefs_id = key($this->svgdefs);
  23723. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23724. foreach($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) {
  23725. if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) {
  23726. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext));
  23727. return;
  23728. }
  23729. }
  23730. if ($this->svgdefs[$last_svgdefs_id]['name'] == $name) {
  23731. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext));
  23732. return;
  23733. }
  23734. }
  23735. }
  23736. return;
  23737. }
  23738. switch($name) {
  23739. case 'defs': {
  23740. $this->svgdefsmode = false;
  23741. break;
  23742. }
  23743. // clipPath
  23744. case 'clipPath': {
  23745. $this->svgclipmode = false;
  23746. break;
  23747. }
  23748. case 'svg': {
  23749. if (--$this->svg_tag_depth <= 0) {
  23750. break;
  23751. }
  23752. }
  23753. case 'g': {
  23754. // ungroup: remove last style from array
  23755. array_pop($this->svgstyles);
  23756. $this->StopTransform();
  23757. break;
  23758. }
  23759. case 'text':
  23760. case 'tspan': {
  23761. if ($this->svgtextmode['invisible']) {
  23762. // This implementation must be fixed to following the rule:
  23763. // If the 'visibility' property is set to hidden on a 'tspan', 'tref' or 'altGlyph' element, then the text is invisible but still takes up space in text layout calculations.
  23764. break;
  23765. }
  23766. // print text
  23767. $text = $this->svgtext;
  23768. //$text = $this->stringTrim($text);
  23769. $textlen = $this->GetStringWidth($text);
  23770. if ($this->svgtextmode['text-anchor'] != 'start') {
  23771. // check if string is RTL text
  23772. if ($this->svgtextmode['text-anchor'] == 'end') {
  23773. if ($this->svgtextmode['rtl']) {
  23774. $this->x += $textlen;
  23775. } else {
  23776. $this->x -= $textlen;
  23777. }
  23778. } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  23779. if ($this->svgtextmode['rtl']) {
  23780. $this->x += ($textlen / 2);
  23781. } else {
  23782. $this->x -= ($textlen / 2);
  23783. }
  23784. }
  23785. }
  23786. $textrendermode = $this->textrendermode;
  23787. $textstrokewidth = $this->textstrokewidth;
  23788. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  23789. if ($name == 'text') {
  23790. // store current coordinates
  23791. $tmpx = $this->x;
  23792. $tmpy = $this->y;
  23793. }
  23794. // print the text
  23795. $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  23796. if ($name == 'text') {
  23797. // restore coordinates
  23798. $this->x = $tmpx;
  23799. $this->y = $tmpy;
  23800. }
  23801. // restore previous rendering mode
  23802. $this->textrendermode = $textrendermode;
  23803. $this->textstrokewidth = $textstrokewidth;
  23804. $this->svgtext = '';
  23805. $this->StopTransform();
  23806. if (!$this->svgdefsmode) {
  23807. array_pop($this->svgstyles);
  23808. }
  23809. break;
  23810. }
  23811. default: {
  23812. break;
  23813. }
  23814. }
  23815. }
  23816. /**
  23817. * Sets the character data handler function for the XML parser.
  23818. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  23819. * @param $data (string) The second parameter, data, contains the character data as a string.
  23820. * @author Nicola Asuni
  23821. * @since 5.0.000 (2010-05-02)
  23822. * @protected
  23823. */
  23824. protected function segSVGContentHandler($parser, $data) {
  23825. $this->svgtext .= $data;
  23826. }
  23827. // --- END SVG METHODS -----------------------------------------------------
  23828. } // END OF TCPDF CLASS
  23829. //============================================================+
  23830. // END OF FILE
  23831. //============================================================+