tcpdf.php 884 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 6.4.4
  5. // Begin : 2002-08-03
  6. // Last Update : 2021-12-31
  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-2021 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 ImageMagick (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 ImageMagick (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.3.2
  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.3.2
  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. * @var array<int,string|float|null>
  524. * @phpstan-var array{0: string, 1: string, 2: float|null}
  525. */
  526. protected $header_font;
  527. /**
  528. * Default font used on page footer.
  529. * @protected
  530. * @var array<int,string|float|null>
  531. * @phpstan-var array{0: string, 1: string, 2: float|null}
  532. */
  533. protected $footer_font;
  534. /**
  535. * Language templates.
  536. * @protected
  537. */
  538. protected $l;
  539. /**
  540. * Barcode to print on page footer (only if set).
  541. * @protected
  542. */
  543. protected $barcode = false;
  544. /**
  545. * Boolean flag to print/hide page header.
  546. * @protected
  547. */
  548. protected $print_header = true;
  549. /**
  550. * Boolean flag to print/hide page footer.
  551. * @protected
  552. */
  553. protected $print_footer = true;
  554. /**
  555. * Header image logo.
  556. * @protected
  557. */
  558. protected $header_logo = '';
  559. /**
  560. * Width of header image logo in user units.
  561. * @protected
  562. */
  563. protected $header_logo_width = 30;
  564. /**
  565. * Title to be printed on default page header.
  566. * @protected
  567. */
  568. protected $header_title = '';
  569. /**
  570. * String to print on page header after title.
  571. * @protected
  572. */
  573. protected $header_string = '';
  574. /**
  575. * Color for header text (RGB array).
  576. * @since 5.9.174 (2012-07-25)
  577. * @protected
  578. * @var int[]
  579. * @phpstan-var array{0: int, 1: int, 2: int}
  580. */
  581. protected $header_text_color = array(0,0,0);
  582. /**
  583. * Color for header line (RGB array).
  584. * @since 5.9.174 (2012-07-25)
  585. * @protected
  586. * @var int[]
  587. * @phpstan-var array{0: int, 1: int, 2: int}
  588. */
  589. protected $header_line_color = array(0,0,0);
  590. /**
  591. * Color for footer text (RGB array).
  592. * @since 5.9.174 (2012-07-25)
  593. * @protected
  594. * @var int[]
  595. * @phpstan-var array{0: int, 1: int, 2: int}
  596. */
  597. protected $footer_text_color = array(0,0,0);
  598. /**
  599. * Color for footer line (RGB array).
  600. * @since 5.9.174 (2012-07-25)
  601. * @protected
  602. * @var int[]
  603. * @phpstan-var array{0: int, 1: int, 2: int}
  604. */
  605. protected $footer_line_color = array(0,0,0);
  606. /**
  607. * Text shadow data array.
  608. * @since 5.9.174 (2012-07-25)
  609. * @protected
  610. */
  611. protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
  612. /**
  613. * Default number of columns for html table.
  614. * @protected
  615. */
  616. protected $default_table_columns = 4;
  617. // variables for html parser
  618. /**
  619. * HTML PARSER: array to store current link and rendering styles.
  620. * @protected
  621. */
  622. protected $HREF = array();
  623. /**
  624. * List of available fonts on filesystem.
  625. * @protected
  626. */
  627. protected $fontlist = array();
  628. /**
  629. * Current foreground color.
  630. * @protected
  631. */
  632. protected $fgcolor;
  633. /**
  634. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  635. * @protected
  636. */
  637. protected $listordered = array();
  638. /**
  639. * HTML PARSER: array count list items on nested lists.
  640. * @protected
  641. */
  642. protected $listcount = array();
  643. /**
  644. * HTML PARSER: current list nesting level.
  645. * @protected
  646. */
  647. protected $listnum = 0;
  648. /**
  649. * HTML PARSER: indent amount for lists.
  650. * @protected
  651. */
  652. protected $listindent = 0;
  653. /**
  654. * HTML PARSER: current list indententation level.
  655. * @protected
  656. */
  657. protected $listindentlevel = 0;
  658. /**
  659. * Current background color.
  660. * @protected
  661. */
  662. protected $bgcolor;
  663. /**
  664. * Temporary font size in points.
  665. * @protected
  666. */
  667. protected $tempfontsize = 10;
  668. /**
  669. * Spacer string for LI tags.
  670. * @protected
  671. */
  672. protected $lispacer = '';
  673. /**
  674. * Default encoding.
  675. * @protected
  676. * @since 1.53.0.TC010
  677. */
  678. protected $encoding = 'UTF-8';
  679. /**
  680. * Boolean flag to indicate if the document language is Right-To-Left.
  681. * @protected
  682. * @since 2.0.000
  683. */
  684. protected $rtl = false;
  685. /**
  686. * Boolean flag used to force RTL or LTR string direction.
  687. * @protected
  688. * @since 2.0.000
  689. */
  690. protected $tmprtl = false;
  691. // --- Variables used for document encryption:
  692. /**
  693. * IBoolean flag indicating whether document is protected.
  694. * @protected
  695. * @since 2.0.000 (2008-01-02)
  696. */
  697. protected $encrypted;
  698. /**
  699. * Array containing encryption settings.
  700. * @protected
  701. * @since 5.0.005 (2010-05-11)
  702. */
  703. protected $encryptdata = array();
  704. /**
  705. * Last RC4 key encrypted (cached for optimisation).
  706. * @protected
  707. * @since 2.0.000 (2008-01-02)
  708. */
  709. protected $last_enc_key;
  710. /**
  711. * Last RC4 computed key.
  712. * @protected
  713. * @since 2.0.000 (2008-01-02)
  714. */
  715. protected $last_enc_key_c;
  716. /**
  717. * File ID (used on document trailer).
  718. * @protected
  719. * @since 5.0.005 (2010-05-12)
  720. */
  721. protected $file_id;
  722. // --- bookmark ---
  723. /**
  724. * Outlines for bookmark.
  725. * @protected
  726. * @since 2.1.002 (2008-02-12)
  727. */
  728. protected $outlines = array();
  729. /**
  730. * Outline root for bookmark.
  731. * @protected
  732. * @since 2.1.002 (2008-02-12)
  733. */
  734. protected $OutlineRoot;
  735. // --- javascript and form ---
  736. /**
  737. * Javascript code.
  738. * @protected
  739. * @since 2.1.002 (2008-02-12)
  740. */
  741. protected $javascript = '';
  742. /**
  743. * Javascript counter.
  744. * @protected
  745. * @since 2.1.002 (2008-02-12)
  746. */
  747. protected $n_js;
  748. /**
  749. * line through state
  750. * @protected
  751. * @since 2.8.000 (2008-03-19)
  752. */
  753. protected $linethrough;
  754. /**
  755. * Array with additional document-wide usage rights for the document.
  756. * @protected
  757. * @since 5.8.014 (2010-08-23)
  758. */
  759. protected $ur = array();
  760. /**
  761. * DPI (Dot Per Inch) Document Resolution (do not change).
  762. * @protected
  763. * @since 3.0.000 (2008-03-27)
  764. */
  765. protected $dpi = 72;
  766. /**
  767. * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  768. * @protected
  769. * @since 3.0.000 (2008-03-27)
  770. */
  771. protected $newpagegroup = array();
  772. /**
  773. * Array that contains the number of pages in each page group.
  774. * @protected
  775. * @since 3.0.000 (2008-03-27)
  776. */
  777. protected $pagegroups = array();
  778. /**
  779. * Current page group number.
  780. * @protected
  781. * @since 3.0.000 (2008-03-27)
  782. */
  783. protected $currpagegroup = 0;
  784. /**
  785. * Array of transparency objects and parameters.
  786. * @protected
  787. * @since 3.0.000 (2008-03-27)
  788. */
  789. protected $extgstates;
  790. /**
  791. * Set the default JPEG compression quality (1-100).
  792. * @protected
  793. * @since 3.0.000 (2008-03-27)
  794. */
  795. protected $jpeg_quality;
  796. /**
  797. * Default cell height ratio.
  798. * @protected
  799. * @since 3.0.014 (2008-05-23)
  800. * @var float
  801. */
  802. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  803. /**
  804. * PDF viewer preferences.
  805. * @protected
  806. * @since 3.1.000 (2008-06-09)
  807. */
  808. protected $viewer_preferences;
  809. /**
  810. * A name object specifying how the document should be displayed when opened.
  811. * @protected
  812. * @since 3.1.000 (2008-06-09)
  813. */
  814. protected $PageMode;
  815. /**
  816. * Array for storing gradient information.
  817. * @protected
  818. * @since 3.1.000 (2008-06-09)
  819. */
  820. protected $gradients = array();
  821. /**
  822. * Array used to store positions inside the pages buffer (keys are the page numbers).
  823. * @protected
  824. * @since 3.2.000 (2008-06-26)
  825. */
  826. protected $intmrk = array();
  827. /**
  828. * Array used to store positions inside the pages buffer (keys are the page numbers).
  829. * @protected
  830. * @since 5.7.000 (2010-08-03)
  831. */
  832. protected $bordermrk = array();
  833. /**
  834. * Array used to store page positions to track empty pages (keys are the page numbers).
  835. * @protected
  836. * @since 5.8.007 (2010-08-18)
  837. */
  838. protected $emptypagemrk = array();
  839. /**
  840. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  841. * @protected
  842. * @since 4.6.021 (2009-07-20)
  843. */
  844. protected $cntmrk = array();
  845. /**
  846. * Array used to store footer positions of each page.
  847. * @protected
  848. * @since 3.2.000 (2008-07-01)
  849. */
  850. protected $footerpos = array();
  851. /**
  852. * Array used to store footer length of each page.
  853. * @protected
  854. * @since 4.0.014 (2008-07-29)
  855. */
  856. protected $footerlen = array();
  857. /**
  858. * Boolean flag to indicate if a new line is created.
  859. * @protected
  860. * @since 3.2.000 (2008-07-01)
  861. */
  862. protected $newline = true;
  863. /**
  864. * End position of the latest inserted line.
  865. * @protected
  866. * @since 3.2.000 (2008-07-01)
  867. */
  868. protected $endlinex = 0;
  869. /**
  870. * PDF string for width value of the last line.
  871. * @protected
  872. * @since 4.0.006 (2008-07-16)
  873. */
  874. protected $linestyleWidth = '';
  875. /**
  876. * PDF string for CAP value of the last line.
  877. * @protected
  878. * @since 4.0.006 (2008-07-16)
  879. */
  880. protected $linestyleCap = '0 J';
  881. /**
  882. * PDF string for join value of the last line.
  883. * @protected
  884. * @since 4.0.006 (2008-07-16)
  885. */
  886. protected $linestyleJoin = '0 j';
  887. /**
  888. * PDF string for dash value of the last line.
  889. * @protected
  890. * @since 4.0.006 (2008-07-16)
  891. */
  892. protected $linestyleDash = '[] 0 d';
  893. /**
  894. * Boolean flag to indicate if marked-content sequence is open.
  895. * @protected
  896. * @since 4.0.013 (2008-07-28)
  897. */
  898. protected $openMarkedContent = false;
  899. /**
  900. * Count the latest inserted vertical spaces on HTML.
  901. * @protected
  902. * @since 4.0.021 (2008-08-24)
  903. */
  904. protected $htmlvspace = 0;
  905. /**
  906. * Array of Spot colors.
  907. * @protected
  908. * @since 4.0.024 (2008-09-12)
  909. */
  910. protected $spot_colors = array();
  911. /**
  912. * Symbol used for HTML unordered list items.
  913. * @protected
  914. * @since 4.0.028 (2008-09-26)
  915. */
  916. protected $lisymbol = '';
  917. /**
  918. * String used to mark the beginning and end of EPS image blocks.
  919. * @protected
  920. * @since 4.1.000 (2008-10-18)
  921. */
  922. protected $epsmarker = 'x#!#EPS#!#x';
  923. /**
  924. * Array of transformation matrix.
  925. * @protected
  926. * @since 4.2.000 (2008-10-29)
  927. */
  928. protected $transfmatrix = array();
  929. /**
  930. * Current key for transformation matrix.
  931. * @protected
  932. * @since 4.8.005 (2009-09-17)
  933. */
  934. protected $transfmatrix_key = 0;
  935. /**
  936. * Booklet mode for double-sided pages.
  937. * @protected
  938. * @since 4.2.000 (2008-10-29)
  939. */
  940. protected $booklet = false;
  941. /**
  942. * Epsilon value used for float calculations.
  943. * @protected
  944. * @since 4.2.000 (2008-10-29)
  945. */
  946. protected $feps = 0.005;
  947. /**
  948. * Array used for custom vertical spaces for HTML tags.
  949. * @protected
  950. * @since 4.2.001 (2008-10-30)
  951. */
  952. protected $tagvspaces = array();
  953. /**
  954. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  955. * @protected
  956. * @since 4.2.007 (2008-11-12)
  957. */
  958. protected $customlistindent = -1;
  959. /**
  960. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  961. * @protected
  962. * @since 4.2.010 (2008-11-14)
  963. */
  964. protected $opencell = true;
  965. /**
  966. * Array of files to embedd.
  967. * @protected
  968. * @since 4.4.000 (2008-12-07)
  969. */
  970. protected $embeddedfiles = array();
  971. /**
  972. * Boolean flag to indicate if we are inside a PRE tag.
  973. * @protected
  974. * @since 4.4.001 (2008-12-08)
  975. */
  976. protected $premode = false;
  977. /**
  978. * Array used to store positions of graphics transformation blocks inside the page buffer.
  979. * keys are the page numbers
  980. * @protected
  981. * @since 4.4.002 (2008-12-09)
  982. */
  983. protected $transfmrk = array();
  984. /**
  985. * Default color for html links.
  986. * @protected
  987. * @since 4.4.003 (2008-12-09)
  988. */
  989. protected $htmlLinkColorArray = array(0, 0, 255);
  990. /**
  991. * Default font style to add to html links.
  992. * @protected
  993. * @since 4.4.003 (2008-12-09)
  994. */
  995. protected $htmlLinkFontStyle = 'U';
  996. /**
  997. * Counts the number of pages.
  998. * @protected
  999. * @since 4.5.000 (2008-12-31)
  1000. */
  1001. protected $numpages = 0;
  1002. /**
  1003. * Array containing page lengths in bytes.
  1004. * @protected
  1005. * @since 4.5.000 (2008-12-31)
  1006. */
  1007. protected $pagelen = array();
  1008. /**
  1009. * Counts the number of pages.
  1010. * @protected
  1011. * @since 4.5.000 (2008-12-31)
  1012. */
  1013. protected $numimages = 0;
  1014. /**
  1015. * Store the image keys.
  1016. * @protected
  1017. * @since 4.5.000 (2008-12-31)
  1018. */
  1019. protected $imagekeys = array();
  1020. /**
  1021. * Length of the buffer in bytes.
  1022. * @protected
  1023. * @since 4.5.000 (2008-12-31)
  1024. */
  1025. protected $bufferlen = 0;
  1026. /**
  1027. * Counts the number of fonts.
  1028. * @protected
  1029. * @since 4.5.000 (2009-01-02)
  1030. */
  1031. protected $numfonts = 0;
  1032. /**
  1033. * Store the font keys.
  1034. * @protected
  1035. * @since 4.5.000 (2009-01-02)
  1036. */
  1037. protected $fontkeys = array();
  1038. /**
  1039. * Store the font object IDs.
  1040. * @protected
  1041. * @since 4.8.001 (2009-09-09)
  1042. */
  1043. protected $font_obj_ids = array();
  1044. /**
  1045. * Store the fage status (true when opened, false when closed).
  1046. * @protected
  1047. * @since 4.5.000 (2009-01-02)
  1048. */
  1049. protected $pageopen = array();
  1050. /**
  1051. * Default monospace font.
  1052. * @protected
  1053. * @since 4.5.025 (2009-03-10)
  1054. */
  1055. protected $default_monospaced_font = 'courier';
  1056. /**
  1057. * Cloned copy of the current class object.
  1058. * @protected
  1059. * @since 4.5.029 (2009-03-19)
  1060. */
  1061. protected $objcopy;
  1062. /**
  1063. * Array used to store the lengths of cache files.
  1064. * @protected
  1065. * @since 4.5.029 (2009-03-19)
  1066. */
  1067. protected $cache_file_length = array();
  1068. /**
  1069. * Table header content to be repeated on each new page.
  1070. * @protected
  1071. * @since 4.5.030 (2009-03-20)
  1072. */
  1073. protected $thead = '';
  1074. /**
  1075. * Margins used for table header.
  1076. * @protected
  1077. * @since 4.5.030 (2009-03-20)
  1078. */
  1079. protected $theadMargins = array();
  1080. /**
  1081. * Boolean flag to enable document digital signature.
  1082. * @protected
  1083. * @since 4.6.005 (2009-04-24)
  1084. */
  1085. protected $sign = false;
  1086. /**
  1087. * Digital signature data.
  1088. * @protected
  1089. * @since 4.6.005 (2009-04-24)
  1090. */
  1091. protected $signature_data = array();
  1092. /**
  1093. * Digital signature max length.
  1094. * @protected
  1095. * @since 4.6.005 (2009-04-24)
  1096. */
  1097. protected $signature_max_length = 11742;
  1098. /**
  1099. * Data for digital signature appearance.
  1100. * @protected
  1101. * @since 5.3.011 (2010-06-16)
  1102. */
  1103. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1104. /**
  1105. * Array of empty digital signature appearances.
  1106. * @protected
  1107. * @since 5.9.101 (2011-07-06)
  1108. */
  1109. protected $empty_signature_appearance = array();
  1110. /**
  1111. * Boolean flag to enable document timestamping with TSA.
  1112. * @protected
  1113. * @since 6.0.085 (2014-06-19)
  1114. */
  1115. protected $tsa_timestamp = false;
  1116. /**
  1117. * Timestamping data.
  1118. * @protected
  1119. * @since 6.0.085 (2014-06-19)
  1120. */
  1121. protected $tsa_data = array();
  1122. /**
  1123. * Regular expression used to find blank characters (required for word-wrapping).
  1124. * @protected
  1125. * @since 4.6.006 (2009-04-28)
  1126. */
  1127. protected $re_spaces = '/[^\S\xa0]/';
  1128. /**
  1129. * Array of $re_spaces parts.
  1130. * @protected
  1131. * @since 5.5.011 (2010-07-09)
  1132. */
  1133. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1134. /**
  1135. * Digital signature object ID.
  1136. * @protected
  1137. * @since 4.6.022 (2009-06-23)
  1138. */
  1139. protected $sig_obj_id = 0;
  1140. /**
  1141. * ID of page objects.
  1142. * @protected
  1143. * @since 4.7.000 (2009-08-29)
  1144. */
  1145. protected $page_obj_id = array();
  1146. /**
  1147. * List of form annotations IDs.
  1148. * @protected
  1149. * @since 4.8.000 (2009-09-07)
  1150. */
  1151. protected $form_obj_id = array();
  1152. /**
  1153. * 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.
  1154. * @protected
  1155. * @since 4.8.000 (2009-09-07)
  1156. */
  1157. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1158. /**
  1159. * Javascript objects array.
  1160. * @protected
  1161. * @since 4.8.000 (2009-09-07)
  1162. */
  1163. protected $js_objects = array();
  1164. /**
  1165. * Current form action (used during XHTML rendering).
  1166. * @protected
  1167. * @since 4.8.000 (2009-09-07)
  1168. */
  1169. protected $form_action = '';
  1170. /**
  1171. * Current form encryption type (used during XHTML rendering).
  1172. * @protected
  1173. * @since 4.8.000 (2009-09-07)
  1174. */
  1175. protected $form_enctype = 'application/x-www-form-urlencoded';
  1176. /**
  1177. * Current method to submit forms.
  1178. * @protected
  1179. * @since 4.8.000 (2009-09-07)
  1180. */
  1181. protected $form_mode = 'post';
  1182. /**
  1183. * List of fonts used on form fields (fontname => fontkey).
  1184. * @protected
  1185. * @since 4.8.001 (2009-09-09)
  1186. */
  1187. protected $annotation_fonts = array();
  1188. /**
  1189. * List of radio buttons parent objects.
  1190. * @protected
  1191. * @since 4.8.001 (2009-09-09)
  1192. */
  1193. protected $radiobutton_groups = array();
  1194. /**
  1195. * List of radio group objects IDs.
  1196. * @protected
  1197. * @since 4.8.001 (2009-09-09)
  1198. */
  1199. protected $radio_groups = array();
  1200. /**
  1201. * Text indentation value (used for text-indent CSS attribute).
  1202. * @protected
  1203. * @since 4.8.006 (2009-09-23)
  1204. */
  1205. protected $textindent = 0;
  1206. /**
  1207. * Store page number when startTransaction() is called.
  1208. * @protected
  1209. * @since 4.8.006 (2009-09-23)
  1210. */
  1211. protected $start_transaction_page = 0;
  1212. /**
  1213. * Store Y position when startTransaction() is called.
  1214. * @protected
  1215. * @since 4.9.001 (2010-03-28)
  1216. */
  1217. protected $start_transaction_y = 0;
  1218. /**
  1219. * True when we are printing the thead section on a new page.
  1220. * @protected
  1221. * @since 4.8.027 (2010-01-25)
  1222. */
  1223. protected $inthead = false;
  1224. /**
  1225. * Array of column measures (width, space, starting Y position).
  1226. * @protected
  1227. * @since 4.9.001 (2010-03-28)
  1228. */
  1229. protected $columns = array();
  1230. /**
  1231. * Number of colums.
  1232. * @protected
  1233. * @since 4.9.001 (2010-03-28)
  1234. */
  1235. protected $num_columns = 1;
  1236. /**
  1237. * Current column number.
  1238. * @protected
  1239. * @since 4.9.001 (2010-03-28)
  1240. */
  1241. protected $current_column = 0;
  1242. /**
  1243. * Starting page for columns.
  1244. * @protected
  1245. * @since 4.9.001 (2010-03-28)
  1246. */
  1247. protected $column_start_page = 0;
  1248. /**
  1249. * Maximum page and column selected.
  1250. * @protected
  1251. * @since 5.8.000 (2010-08-11)
  1252. */
  1253. protected $maxselcol = array('page' => 0, 'column' => 0);
  1254. /**
  1255. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1256. * @protected
  1257. * @since 5.8.000 (2010-08-11)
  1258. */
  1259. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1260. /**
  1261. * 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.
  1262. * @protected
  1263. * @since 4.9.008 (2010-04-03)
  1264. */
  1265. protected $textrendermode = 0;
  1266. /**
  1267. * Text stroke width in doc units.
  1268. * @protected
  1269. * @since 4.9.008 (2010-04-03)
  1270. */
  1271. protected $textstrokewidth = 0;
  1272. /**
  1273. * Current stroke color.
  1274. * @protected
  1275. * @since 4.9.008 (2010-04-03)
  1276. */
  1277. protected $strokecolor;
  1278. /**
  1279. * Default unit of measure for document.
  1280. * @protected
  1281. * @since 5.0.000 (2010-04-22)
  1282. */
  1283. protected $pdfunit = 'mm';
  1284. /**
  1285. * Boolean flag true when we are on TOC (Table Of Content) page.
  1286. * @protected
  1287. */
  1288. protected $tocpage = false;
  1289. /**
  1290. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1291. * @protected
  1292. * @since 5.0.000 (2010-04-26)
  1293. */
  1294. protected $rasterize_vector_images = false;
  1295. /**
  1296. * Boolean flag: if true enables font subsetting by default.
  1297. * @protected
  1298. * @since 5.3.002 (2010-06-07)
  1299. */
  1300. protected $font_subsetting = true;
  1301. /**
  1302. * Array of default graphic settings.
  1303. * @protected
  1304. * @since 5.5.008 (2010-07-02)
  1305. */
  1306. protected $default_graphic_vars = array();
  1307. /**
  1308. * Array of XObjects.
  1309. * @protected
  1310. * @since 5.8.014 (2010-08-23)
  1311. */
  1312. protected $xobjects = array();
  1313. /**
  1314. * Boolean value true when we are inside an XObject.
  1315. * @protected
  1316. * @since 5.8.017 (2010-08-24)
  1317. */
  1318. protected $inxobj = false;
  1319. /**
  1320. * Current XObject ID.
  1321. * @protected
  1322. * @since 5.8.017 (2010-08-24)
  1323. */
  1324. protected $xobjid = '';
  1325. /**
  1326. * Percentage of character stretching.
  1327. * @protected
  1328. * @since 5.9.000 (2010-09-29)
  1329. */
  1330. protected $font_stretching = 100;
  1331. /**
  1332. * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1333. * @protected
  1334. * @since 5.9.000 (2010-09-29)
  1335. */
  1336. protected $font_spacing = 0;
  1337. /**
  1338. * Array of no-write regions.
  1339. * ('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)
  1340. * @protected
  1341. * @since 5.9.003 (2010-10-14)
  1342. */
  1343. protected $page_regions = array();
  1344. /**
  1345. * Boolean value true when page region check is active.
  1346. * @protected
  1347. */
  1348. protected $check_page_regions = true;
  1349. /**
  1350. * Array of PDF layers data.
  1351. * @protected
  1352. * @since 5.9.102 (2011-07-13)
  1353. */
  1354. protected $pdflayers = array();
  1355. /**
  1356. * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1357. * @protected
  1358. * @since 5.9.097 (2011-06-23)
  1359. */
  1360. protected $dests = array();
  1361. /**
  1362. * Object ID for Named Destinations
  1363. * @protected
  1364. * @since 5.9.097 (2011-06-23)
  1365. */
  1366. protected $n_dests;
  1367. /**
  1368. * Embedded Files Names
  1369. * @protected
  1370. * @since 5.9.204 (2013-01-23)
  1371. */
  1372. protected $efnames = array();
  1373. /**
  1374. * Directory used for the last SVG image.
  1375. * @protected
  1376. * @since 5.0.000 (2010-05-05)
  1377. */
  1378. protected $svgdir = '';
  1379. /**
  1380. * Deafult unit of measure for SVG.
  1381. * @protected
  1382. * @since 5.0.000 (2010-05-02)
  1383. */
  1384. protected $svgunit = 'px';
  1385. /**
  1386. * Array of SVG gradients.
  1387. * @protected
  1388. * @since 5.0.000 (2010-05-02)
  1389. */
  1390. protected $svggradients = array();
  1391. /**
  1392. * ID of last SVG gradient.
  1393. * @protected
  1394. * @since 5.0.000 (2010-05-02)
  1395. */
  1396. protected $svggradientid = 0;
  1397. /**
  1398. * Boolean value true when in SVG defs group.
  1399. * @protected
  1400. * @since 5.0.000 (2010-05-02)
  1401. */
  1402. protected $svgdefsmode = false;
  1403. /**
  1404. * Array of SVG defs.
  1405. * @protected
  1406. * @since 5.0.000 (2010-05-02)
  1407. */
  1408. protected $svgdefs = array();
  1409. /**
  1410. * Boolean value true when in SVG clipPath tag.
  1411. * @protected
  1412. * @since 5.0.000 (2010-04-26)
  1413. */
  1414. protected $svgclipmode = false;
  1415. /**
  1416. * Array of SVG clipPath commands.
  1417. * @protected
  1418. * @since 5.0.000 (2010-05-02)
  1419. */
  1420. protected $svgclippaths = array();
  1421. /**
  1422. * Array of SVG clipPath tranformation matrix.
  1423. * @protected
  1424. * @since 5.8.022 (2010-08-31)
  1425. */
  1426. protected $svgcliptm = array();
  1427. /**
  1428. * ID of last SVG clipPath.
  1429. * @protected
  1430. * @since 5.0.000 (2010-05-02)
  1431. */
  1432. protected $svgclipid = 0;
  1433. /**
  1434. * SVG text.
  1435. * @protected
  1436. * @since 5.0.000 (2010-05-02)
  1437. */
  1438. protected $svgtext = '';
  1439. /**
  1440. * SVG text properties.
  1441. * @protected
  1442. * @since 5.8.013 (2010-08-23)
  1443. */
  1444. protected $svgtextmode = array();
  1445. /**
  1446. * Array of SVG properties.
  1447. * @protected
  1448. * @since 5.0.000 (2010-05-02)
  1449. */
  1450. protected $svgstyles = array(array(
  1451. 'alignment-baseline' => 'auto',
  1452. 'baseline-shift' => 'baseline',
  1453. 'clip' => 'auto',
  1454. 'clip-path' => 'none',
  1455. 'clip-rule' => 'nonzero',
  1456. 'color' => 'black',
  1457. 'color-interpolation' => 'sRGB',
  1458. 'color-interpolation-filters' => 'linearRGB',
  1459. 'color-profile' => 'auto',
  1460. 'color-rendering' => 'auto',
  1461. 'cursor' => 'auto',
  1462. 'direction' => 'ltr',
  1463. 'display' => 'inline',
  1464. 'dominant-baseline' => 'auto',
  1465. 'enable-background' => 'accumulate',
  1466. 'fill' => 'black',
  1467. 'fill-opacity' => 1,
  1468. 'fill-rule' => 'nonzero',
  1469. 'filter' => 'none',
  1470. 'flood-color' => 'black',
  1471. 'flood-opacity' => 1,
  1472. 'font' => '',
  1473. 'font-family' => 'helvetica',
  1474. 'font-size' => 'medium',
  1475. 'font-size-adjust' => 'none',
  1476. 'font-stretch' => 'normal',
  1477. 'font-style' => 'normal',
  1478. 'font-variant' => 'normal',
  1479. 'font-weight' => 'normal',
  1480. 'glyph-orientation-horizontal' => '0deg',
  1481. 'glyph-orientation-vertical' => 'auto',
  1482. 'image-rendering' => 'auto',
  1483. 'kerning' => 'auto',
  1484. 'letter-spacing' => 'normal',
  1485. 'lighting-color' => 'white',
  1486. 'marker' => '',
  1487. 'marker-end' => 'none',
  1488. 'marker-mid' => 'none',
  1489. 'marker-start' => 'none',
  1490. 'mask' => 'none',
  1491. 'opacity' => 1,
  1492. 'overflow' => 'auto',
  1493. 'pointer-events' => 'visiblePainted',
  1494. 'shape-rendering' => 'auto',
  1495. 'stop-color' => 'black',
  1496. 'stop-opacity' => 1,
  1497. 'stroke' => 'none',
  1498. 'stroke-dasharray' => 'none',
  1499. 'stroke-dashoffset' => 0,
  1500. 'stroke-linecap' => 'butt',
  1501. 'stroke-linejoin' => 'miter',
  1502. 'stroke-miterlimit' => 4,
  1503. 'stroke-opacity' => 1,
  1504. 'stroke-width' => 1,
  1505. 'text-anchor' => 'start',
  1506. 'text-decoration' => 'none',
  1507. 'text-rendering' => 'auto',
  1508. 'unicode-bidi' => 'normal',
  1509. 'visibility' => 'visible',
  1510. 'word-spacing' => 'normal',
  1511. 'writing-mode' => 'lr-tb',
  1512. 'text-color' => 'black',
  1513. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1514. ));
  1515. /**
  1516. * If true force sRGB color profile for all document.
  1517. * @protected
  1518. * @since 5.9.121 (2011-09-28)
  1519. */
  1520. protected $force_srgb = false;
  1521. /**
  1522. * If true set the document to PDF/A mode.
  1523. * @protected
  1524. * @since 5.9.121 (2011-09-27)
  1525. */
  1526. protected $pdfa_mode = false;
  1527. /**
  1528. * version of PDF/A mode (1 - 3).
  1529. * @protected
  1530. * @since 6.2.26 (2019-03-12)
  1531. */
  1532. protected $pdfa_version = 1;
  1533. /**
  1534. * Document creation date-time
  1535. * @protected
  1536. * @since 5.9.152 (2012-03-22)
  1537. */
  1538. protected $doc_creation_timestamp;
  1539. /**
  1540. * Document modification date-time
  1541. * @protected
  1542. * @since 5.9.152 (2012-03-22)
  1543. */
  1544. protected $doc_modification_timestamp;
  1545. /**
  1546. * Custom XMP data.
  1547. * @protected
  1548. * @since 5.9.128 (2011-10-06)
  1549. */
  1550. protected $custom_xmp = '';
  1551. /**
  1552. * Custom XMP RDF data.
  1553. * @protected
  1554. * @since 6.3.0 (2019-09-19)
  1555. */
  1556. protected $custom_xmp_rdf = '';
  1557. /**
  1558. * Overprint mode array.
  1559. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1560. * @protected
  1561. * @since 5.9.152 (2012-03-23)
  1562. * @var array<string,bool|int>
  1563. */
  1564. protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
  1565. /**
  1566. * Alpha mode array.
  1567. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1568. * @protected
  1569. * @since 5.9.152 (2012-03-23)
  1570. */
  1571. protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
  1572. /**
  1573. * Define the page boundaries boxes to be set on document.
  1574. * @protected
  1575. * @since 5.9.152 (2012-03-23)
  1576. */
  1577. protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  1578. /**
  1579. * If true print TCPDF meta link.
  1580. * @protected
  1581. * @since 5.9.152 (2012-03-23)
  1582. */
  1583. protected $tcpdflink = true;
  1584. /**
  1585. * Cache array for computed GD gamma values.
  1586. * @protected
  1587. * @since 5.9.1632 (2012-06-05)
  1588. */
  1589. protected $gdgammacache = array();
  1590. /**
  1591. * Cache array for file content
  1592. * @protected
  1593. * @var array
  1594. * @since 6.3.5 (2020-09-28)
  1595. */
  1596. protected $fileContentCache = array();
  1597. /**
  1598. * Whether to allow local file path in image html tags, when prefixed with file://
  1599. *
  1600. * @var bool
  1601. * @protected
  1602. * @since 6.4 (2020-07-23)
  1603. */
  1604. protected $allowLocalFiles = false;
  1605. //------------------------------------------------------------
  1606. // METHODS
  1607. //------------------------------------------------------------
  1608. /**
  1609. * This is the class constructor.
  1610. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1611. *
  1612. * @param string $orientation 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>
  1613. * @param string $unit 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.
  1614. * @param mixed $format 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().
  1615. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1616. * @param string $encoding Charset encoding (used only when converting back html entities); default is UTF-8.
  1617. * @param boolean $diskcache DEPRECATED FEATURE
  1618. * @param false|integer $pdfa If not false, set the document to PDF/A mode and the good version (1 or 3).
  1619. * @public
  1620. * @see getPageSizeFromFormat(), setPageFormat()
  1621. */
  1622. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
  1623. // set file ID for trailer
  1624. $serformat = (is_array($format) ? json_encode($format) : $format);
  1625. $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
  1626. $this->font_obj_ids = array();
  1627. $this->page_obj_id = array();
  1628. $this->form_obj_id = array();
  1629. // set pdf/a mode
  1630. if ($pdfa != false) {
  1631. $this->pdfa_mode = true;
  1632. $this->pdfa_version = $pdfa; // 1 or 3
  1633. } else
  1634. $this->pdfa_mode = false;
  1635. $this->force_srgb = false;
  1636. // set language direction
  1637. $this->rtl = false;
  1638. $this->tmprtl = false;
  1639. // some checks
  1640. $this->_dochecks();
  1641. // initialization of properties
  1642. $this->isunicode = $unicode;
  1643. $this->page = 0;
  1644. $this->transfmrk[0] = array();
  1645. $this->pagedim = array();
  1646. $this->n = 2;
  1647. $this->buffer = '';
  1648. $this->pages = array();
  1649. $this->state = 0;
  1650. $this->fonts = array();
  1651. $this->FontFiles = array();
  1652. $this->diffs = array();
  1653. $this->images = array();
  1654. $this->links = array();
  1655. $this->gradients = array();
  1656. $this->InFooter = false;
  1657. $this->lasth = 0;
  1658. $this->FontFamily = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  1659. $this->FontStyle = '';
  1660. $this->FontSizePt = 12;
  1661. $this->underline = false;
  1662. $this->overline = false;
  1663. $this->linethrough = false;
  1664. $this->DrawColor = '0 G';
  1665. $this->FillColor = '0 g';
  1666. $this->TextColor = '0 g';
  1667. $this->ColorFlag = false;
  1668. $this->pdflayers = array();
  1669. // encryption values
  1670. $this->encrypted = false;
  1671. $this->last_enc_key = '';
  1672. // standard Unicode fonts
  1673. $this->CoreFonts = array(
  1674. 'courier'=>'Courier',
  1675. 'courierB'=>'Courier-Bold',
  1676. 'courierI'=>'Courier-Oblique',
  1677. 'courierBI'=>'Courier-BoldOblique',
  1678. 'helvetica'=>'Helvetica',
  1679. 'helveticaB'=>'Helvetica-Bold',
  1680. 'helveticaI'=>'Helvetica-Oblique',
  1681. 'helveticaBI'=>'Helvetica-BoldOblique',
  1682. 'times'=>'Times-Roman',
  1683. 'timesB'=>'Times-Bold',
  1684. 'timesI'=>'Times-Italic',
  1685. 'timesBI'=>'Times-BoldItalic',
  1686. 'symbol'=>'Symbol',
  1687. 'zapfdingbats'=>'ZapfDingbats'
  1688. );
  1689. // set scale factor
  1690. $this->setPageUnit($unit);
  1691. // set page format and orientation
  1692. $this->setPageFormat($format, $orientation);
  1693. // page margins (1 cm)
  1694. $margin = 28.35 / $this->k;
  1695. $this->setMargins($margin, $margin);
  1696. $this->clMargin = $this->lMargin;
  1697. $this->crMargin = $this->rMargin;
  1698. // internal cell padding
  1699. $cpadding = $margin / 10;
  1700. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1701. // cell margins
  1702. $this->setCellMargins(0, 0, 0, 0);
  1703. // line width (0.2 mm)
  1704. $this->LineWidth = 0.57 / $this->k;
  1705. $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
  1706. $this->linestyleCap = '0 J';
  1707. $this->linestyleJoin = '0 j';
  1708. $this->linestyleDash = '[] 0 d';
  1709. // automatic page break
  1710. $this->setAutoPageBreak(true, (2 * $margin));
  1711. // full width display mode
  1712. $this->setDisplayMode('fullwidth');
  1713. // compression
  1714. $this->setCompression();
  1715. // set default PDF version number
  1716. $this->setPDFVersion();
  1717. $this->tcpdflink = true;
  1718. $this->encoding = $encoding;
  1719. $this->HREF = array();
  1720. $this->getFontsList();
  1721. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1722. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1723. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1724. $this->extgstates = array();
  1725. $this->setTextShadow();
  1726. // signature
  1727. $this->sign = false;
  1728. $this->tsa_timestamp = false;
  1729. $this->tsa_data = array();
  1730. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
  1731. $this->empty_signature_appearance = array();
  1732. // user's rights
  1733. $this->ur['enabled'] = false;
  1734. $this->ur['document'] = '/FullSave';
  1735. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1736. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1737. $this->ur['signature'] = '/Modify';
  1738. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1739. $this->ur['formex'] = '';
  1740. // set default JPEG quality
  1741. $this->jpeg_quality = 75;
  1742. // initialize some settings
  1743. TCPDF_FONTS::utf8Bidi(array(), '', false, $this->isunicode, $this->CurrentFont);
  1744. // set default font
  1745. $this->setFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1746. $this->setHeaderFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
  1747. $this->setFooterFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
  1748. // check if PCRE Unicode support is enabled
  1749. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1750. // PCRE unicode support is turned ON
  1751. // \s : any whitespace character
  1752. // \p{Z} : any separator
  1753. // \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  1754. // \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  1755. //$this->setSpacesRE('/(?!\xa0)[\s\p{Z}\p{Lo}]/u');
  1756. $this->setSpacesRE('/(?!\xa0)[\s\p{Z}]/u');
  1757. } else {
  1758. // PCRE unicode support is turned OFF
  1759. $this->setSpacesRE('/[^\S\xa0]/');
  1760. }
  1761. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1762. // set document creation and modification timestamp
  1763. $this->doc_creation_timestamp = time();
  1764. $this->doc_modification_timestamp = $this->doc_creation_timestamp;
  1765. // get default graphic vars
  1766. $this->default_graphic_vars = $this->getGraphicVars();
  1767. $this->header_xobj_autoreset = false;
  1768. $this->custom_xmp = '';
  1769. $this->custom_xmp_rdf = '';
  1770. // Call cleanup method after script execution finishes or exit() is called.
  1771. // NOTE: This will not be executed if the process is killed with a SIGTERM or SIGKILL signal.
  1772. register_shutdown_function(array($this, '_destroy'), true);
  1773. }
  1774. /**
  1775. * Default destructor.
  1776. * @public
  1777. * @since 1.53.0.TC016
  1778. */
  1779. public function __destruct() {
  1780. // cleanup
  1781. $this->_destroy(true);
  1782. }
  1783. /**
  1784. * Set the units of measure for the document.
  1785. * @param string $unit 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.
  1786. * @public
  1787. * @since 3.0.015 (2008-06-06)
  1788. */
  1789. public function setPageUnit($unit) {
  1790. $unit = strtolower($unit);
  1791. //Set scale factor
  1792. switch ($unit) {
  1793. // points
  1794. case 'px':
  1795. case 'pt': {
  1796. $this->k = 1;
  1797. break;
  1798. }
  1799. // millimeters
  1800. case 'mm': {
  1801. $this->k = $this->dpi / 25.4;
  1802. break;
  1803. }
  1804. // centimeters
  1805. case 'cm': {
  1806. $this->k = $this->dpi / 2.54;
  1807. break;
  1808. }
  1809. // inches
  1810. case 'in': {
  1811. $this->k = $this->dpi;
  1812. break;
  1813. }
  1814. // unsupported unit
  1815. default : {
  1816. $this->Error('Incorrect unit: '.$unit);
  1817. break;
  1818. }
  1819. }
  1820. $this->pdfunit = $unit;
  1821. if (isset($this->CurOrientation)) {
  1822. $this->setPageOrientation($this->CurOrientation);
  1823. }
  1824. }
  1825. /**
  1826. * Change the format of the current page
  1827. * @param mixed $format 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>
  1828. * <li>['format'] = page format name (one of the above);</li>
  1829. * <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>
  1830. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  1831. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  1832. * <li>['MediaBox']['llx'] : lower-left x coordinate</li>
  1833. * <li>['MediaBox']['lly'] : lower-left y coordinate</li>
  1834. * <li>['MediaBox']['urx'] : upper-right x coordinate</li>
  1835. * <li>['MediaBox']['ury'] : upper-right y coordinate</li>
  1836. * <li>['CropBox'] : the visible region of default user space:</li>
  1837. * <li>['CropBox']['llx'] : lower-left x coordinate</li>
  1838. * <li>['CropBox']['lly'] : lower-left y coordinate</li>
  1839. * <li>['CropBox']['urx'] : upper-right x coordinate</li>
  1840. * <li>['CropBox']['ury'] : upper-right y coordinate</li>
  1841. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  1842. * <li>['BleedBox']['llx'] : lower-left x coordinate</li>
  1843. * <li>['BleedBox']['lly'] : lower-left y coordinate</li>
  1844. * <li>['BleedBox']['urx'] : upper-right x coordinate</li>
  1845. * <li>['BleedBox']['ury'] : upper-right y coordinate</li>
  1846. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  1847. * <li>['TrimBox']['llx'] : lower-left x coordinate</li>
  1848. * <li>['TrimBox']['lly'] : lower-left y coordinate</li>
  1849. * <li>['TrimBox']['urx'] : upper-right x coordinate</li>
  1850. * <li>['TrimBox']['ury'] : upper-right y coordinate</li>
  1851. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  1852. * <li>['ArtBox']['llx'] : lower-left x coordinate</li>
  1853. * <li>['ArtBox']['lly'] : lower-left y coordinate</li>
  1854. * <li>['ArtBox']['urx'] : upper-right x coordinate</li>
  1855. * <li>['ArtBox']['ury'] : upper-right y coordinate</li>
  1856. * <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>
  1857. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  1858. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  1859. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  1860. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  1861. * <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>
  1862. * <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>
  1863. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  1864. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  1865. * <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>
  1866. * <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>
  1867. * <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>
  1868. * <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>
  1869. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  1870. * </ul>
  1871. * @param string $orientation page orientation. Possible values are (case insensitive):<ul>
  1872. * <li>P or Portrait (default)</li>
  1873. * <li>L or Landscape</li>
  1874. * <li>'' (empty string) for automatic orientation</li>
  1875. * </ul>
  1876. * @protected
  1877. * @since 3.0.015 (2008-06-06)
  1878. * @see getPageSizeFromFormat()
  1879. */
  1880. protected function setPageFormat($format, $orientation='P') {
  1881. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  1882. // remove inherited values
  1883. unset($this->pagedim[$this->page]);
  1884. }
  1885. if (is_string($format)) {
  1886. // get page measures from format name
  1887. $pf = TCPDF_STATIC::getPageSizeFromFormat($format);
  1888. $this->fwPt = $pf[0];
  1889. $this->fhPt = $pf[1];
  1890. } else {
  1891. // the boundaries of the physical medium on which the page shall be displayed or printed
  1892. if (isset($format['MediaBox'])) {
  1893. $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);
  1894. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  1895. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  1896. } else {
  1897. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  1898. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  1899. } else {
  1900. if (!isset($format['format'])) {
  1901. // default value
  1902. $format['format'] = 'A4';
  1903. }
  1904. $pf = TCPDF_STATIC::getPageSizeFromFormat($format['format']);
  1905. }
  1906. $this->fwPt = $pf[0];
  1907. $this->fhPt = $pf[1];
  1908. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1909. }
  1910. // the visible region of default user space
  1911. if (isset($format['CropBox'])) {
  1912. $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);
  1913. }
  1914. // the region to which the contents of the page shall be clipped when output in a production environment
  1915. if (isset($format['BleedBox'])) {
  1916. $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);
  1917. }
  1918. // the intended dimensions of the finished page after trimming
  1919. if (isset($format['TrimBox'])) {
  1920. $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);
  1921. }
  1922. // the page's meaningful content (including potential white space)
  1923. if (isset($format['ArtBox'])) {
  1924. $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);
  1925. }
  1926. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  1927. if (isset($format['BoxColorInfo'])) {
  1928. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  1929. }
  1930. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  1931. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1932. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  1933. }
  1934. if (isset($format['PZ'])) {
  1935. // The page's preferred zoom (magnification) factor
  1936. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  1937. }
  1938. if (isset($format['trans'])) {
  1939. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  1940. if (isset($format['trans']['Dur'])) {
  1941. // The page's display duration
  1942. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  1943. }
  1944. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  1945. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  1946. // The transition style that shall be used when moving to this page from another during a presentation
  1947. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  1948. $valid_effect = array('Split', 'Blinds');
  1949. $valid_vals = array('H', 'V');
  1950. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  1951. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  1952. }
  1953. $valid_effect = array('Split', 'Box', 'Fly');
  1954. $valid_vals = array('I', 'O');
  1955. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  1956. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  1957. }
  1958. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  1959. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  1960. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  1961. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  1962. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  1963. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  1964. }
  1965. }
  1966. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  1967. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  1968. }
  1969. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  1970. $this->pagedim[$this->page]['trans']['B'] = 'true';
  1971. }
  1972. } else {
  1973. $this->pagedim[$this->page]['trans']['S'] = 'R';
  1974. }
  1975. if (isset($format['trans']['D'])) {
  1976. // The duration of the transition effect, in seconds
  1977. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  1978. } else {
  1979. $this->pagedim[$this->page]['trans']['D'] = 1;
  1980. }
  1981. }
  1982. }
  1983. $this->setPageOrientation($orientation);
  1984. }
  1985. /**
  1986. * Set page orientation.
  1987. * @param string $orientation 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>
  1988. * @param boolean|null $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1989. * @param float|null $bottommargin bottom margin of the page.
  1990. * @public
  1991. * @since 3.0.015 (2008-06-06)
  1992. */
  1993. public function setPageOrientation($orientation, $autopagebreak=null, $bottommargin=null) {
  1994. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  1995. // the boundaries of the physical medium on which the page shall be displayed or printed
  1996. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1997. }
  1998. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  1999. // the visible region of default user space
  2000. $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);
  2001. }
  2002. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  2003. // the region to which the contents of the page shall be clipped when output in a production environment
  2004. $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);
  2005. }
  2006. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  2007. // the intended dimensions of the finished page after trimming
  2008. $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);
  2009. }
  2010. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  2011. // the page's meaningful content (including potential white space)
  2012. $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);
  2013. }
  2014. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  2015. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2016. $this->pagedim[$this->page]['Rotate'] = 0;
  2017. }
  2018. if (!isset($this->pagedim[$this->page]['PZ'])) {
  2019. // The page's preferred zoom (magnification) factor
  2020. $this->pagedim[$this->page]['PZ'] = 1;
  2021. }
  2022. if ($this->fwPt > $this->fhPt) {
  2023. // landscape
  2024. $default_orientation = 'L';
  2025. } else {
  2026. // portrait
  2027. $default_orientation = 'P';
  2028. }
  2029. $valid_orientations = array('P', 'L');
  2030. if (empty($orientation)) {
  2031. $orientation = $default_orientation;
  2032. } else {
  2033. $orientation = strtoupper($orientation[0]);
  2034. }
  2035. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  2036. $this->CurOrientation = $orientation;
  2037. $this->wPt = $this->fhPt;
  2038. $this->hPt = $this->fwPt;
  2039. } else {
  2040. $this->CurOrientation = $default_orientation;
  2041. $this->wPt = $this->fwPt;
  2042. $this->hPt = $this->fhPt;
  2043. }
  2044. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2045. // swap X and Y coordinates (change page orientation)
  2046. $this->pagedim = TCPDF_STATIC::swapPageBoxCoordinates($this->page, $this->pagedim);
  2047. }
  2048. $this->w = ($this->wPt / $this->k);
  2049. $this->h = ($this->hPt / $this->k);
  2050. if (TCPDF_STATIC::empty_string($autopagebreak)) {
  2051. if (isset($this->AutoPageBreak)) {
  2052. $autopagebreak = $this->AutoPageBreak;
  2053. } else {
  2054. $autopagebreak = true;
  2055. }
  2056. }
  2057. if (TCPDF_STATIC::empty_string($bottommargin)) {
  2058. if (isset($this->bMargin)) {
  2059. $bottommargin = $this->bMargin;
  2060. } else {
  2061. // default value = 2 cm
  2062. $bottommargin = 2 * 28.35 / $this->k;
  2063. }
  2064. }
  2065. $this->setAutoPageBreak($autopagebreak, $bottommargin);
  2066. // store page dimensions
  2067. $this->pagedim[$this->page]['w'] = $this->wPt;
  2068. $this->pagedim[$this->page]['h'] = $this->hPt;
  2069. $this->pagedim[$this->page]['wk'] = $this->w;
  2070. $this->pagedim[$this->page]['hk'] = $this->h;
  2071. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2072. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2073. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2074. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2075. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2076. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2077. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2078. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2079. }
  2080. /**
  2081. * Set regular expression to detect withespaces or word separators.
  2082. * The pattern delimiter must be the forward-slash character "/".
  2083. * Some example patterns are:
  2084. * <pre>
  2085. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2086. * Unicode and PCRE unicode support: "/(?!\xa0)[\s\p{Z}]/u"
  2087. * Unicode and PCRE unicode support in Chinese mode: "/(?!\xa0)[\s\p{Z}\p{Lo}]/u"
  2088. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2089. * \s : any whitespace character
  2090. * \p{Z} : any separator
  2091. * \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  2092. * \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  2093. * </pre>
  2094. * @param string $re regular expression (leave empty for default).
  2095. * @public
  2096. * @since 4.6.016 (2009-06-15)
  2097. */
  2098. public function setSpacesRE($re='/[^\S\xa0]/') {
  2099. $this->re_spaces = $re;
  2100. $re_parts = explode('/', $re);
  2101. // get pattern parts
  2102. $this->re_space = array();
  2103. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2104. $this->re_space['p'] = $re_parts[1];
  2105. } else {
  2106. $this->re_space['p'] = '[\s]';
  2107. }
  2108. // set pattern modifiers
  2109. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2110. $this->re_space['m'] = $re_parts[2];
  2111. } else {
  2112. $this->re_space['m'] = '';
  2113. }
  2114. }
  2115. /**
  2116. * Enable or disable Right-To-Left language mode
  2117. * @param boolean $enable if true enable Right-To-Left language mode.
  2118. * @param boolean $resetx if true reset the X position on direction change.
  2119. * @public
  2120. * @since 2.0.000 (2008-01-03)
  2121. */
  2122. public function setRTL($enable, $resetx=true) {
  2123. $enable = $enable ? true : false;
  2124. $resetx = ($resetx AND ($enable != $this->rtl));
  2125. $this->rtl = $enable;
  2126. $this->tmprtl = false;
  2127. if ($resetx) {
  2128. $this->Ln(0);
  2129. }
  2130. }
  2131. /**
  2132. * Return the RTL status
  2133. * @return bool
  2134. * @public
  2135. * @since 4.0.012 (2008-07-24)
  2136. */
  2137. public function getRTL() {
  2138. return $this->rtl;
  2139. }
  2140. /**
  2141. * Force temporary RTL language direction
  2142. * @param false|string $mode can be false, 'L' for LTR or 'R' for RTL
  2143. * @public
  2144. * @since 2.1.000 (2008-01-09)
  2145. */
  2146. public function setTempRTL($mode) {
  2147. $newmode = false;
  2148. switch (strtoupper($mode)) {
  2149. case 'LTR':
  2150. case 'L': {
  2151. if ($this->rtl) {
  2152. $newmode = 'L';
  2153. }
  2154. break;
  2155. }
  2156. case 'RTL':
  2157. case 'R': {
  2158. if (!$this->rtl) {
  2159. $newmode = 'R';
  2160. }
  2161. break;
  2162. }
  2163. case false:
  2164. default: {
  2165. $newmode = false;
  2166. break;
  2167. }
  2168. }
  2169. $this->tmprtl = $newmode;
  2170. }
  2171. /**
  2172. * Return the current temporary RTL status
  2173. * @return bool
  2174. * @public
  2175. * @since 4.8.014 (2009-11-04)
  2176. */
  2177. public function isRTLTextDir() {
  2178. return ($this->rtl OR ($this->tmprtl == 'R'));
  2179. }
  2180. /**
  2181. * Set the last cell height.
  2182. * @param float $h cell height.
  2183. * @author Nicola Asuni
  2184. * @public
  2185. * @since 1.53.0.TC034
  2186. */
  2187. public function setLastH($h) {
  2188. $this->lasth = $h;
  2189. }
  2190. /**
  2191. * Return the cell height
  2192. * @param int $fontsize Font size in internal units
  2193. * @param boolean $padding If true add cell padding
  2194. * @public
  2195. * @return float
  2196. */
  2197. public function getCellHeight($fontsize, $padding=TRUE) {
  2198. $height = ($fontsize * $this->cell_height_ratio);
  2199. if ($padding) {
  2200. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  2201. }
  2202. return round($height, 6);
  2203. }
  2204. /**
  2205. * Reset the last cell height.
  2206. * @public
  2207. * @since 5.9.000 (2010-10-03)
  2208. */
  2209. public function resetLastH() {
  2210. $this->lasth = $this->getCellHeight($this->FontSize);
  2211. }
  2212. /**
  2213. * Get the last cell height.
  2214. * @return float last cell height
  2215. * @public
  2216. * @since 4.0.017 (2008-08-05)
  2217. */
  2218. public function getLastH() {
  2219. return $this->lasth;
  2220. }
  2221. /**
  2222. * Set the adjusting factor to convert pixels to user units.
  2223. * @param float $scale adjusting factor to convert pixels to user units.
  2224. * @author Nicola Asuni
  2225. * @public
  2226. * @since 1.5.2
  2227. */
  2228. public function setImageScale($scale) {
  2229. $this->imgscale = $scale;
  2230. }
  2231. /**
  2232. * Returns the adjusting factor to convert pixels to user units.
  2233. * @return float adjusting factor to convert pixels to user units.
  2234. * @author Nicola Asuni
  2235. * @public
  2236. * @since 1.5.2
  2237. */
  2238. public function getImageScale() {
  2239. return $this->imgscale;
  2240. }
  2241. /**
  2242. * Returns an array of page dimensions:
  2243. * <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>
  2244. * @param int|null $pagenum page number (empty = current page)
  2245. * @return array of page dimensions.
  2246. * @author Nicola Asuni
  2247. * @public
  2248. * @since 4.5.027 (2009-03-16)
  2249. */
  2250. public function getPageDimensions($pagenum=null) {
  2251. if (empty($pagenum)) {
  2252. $pagenum = $this->page;
  2253. }
  2254. return $this->pagedim[$pagenum];
  2255. }
  2256. /**
  2257. * Returns the page width in units.
  2258. * @param int|null $pagenum page number (empty = current page)
  2259. * @return int page width.
  2260. * @author Nicola Asuni
  2261. * @public
  2262. * @since 1.5.2
  2263. * @see getPageDimensions()
  2264. */
  2265. public function getPageWidth($pagenum=null) {
  2266. if (empty($pagenum)) {
  2267. return $this->w;
  2268. }
  2269. return $this->pagedim[$pagenum]['w'];
  2270. }
  2271. /**
  2272. * Returns the page height in units.
  2273. * @param int|null $pagenum page number (empty = current page)
  2274. * @return int page height.
  2275. * @author Nicola Asuni
  2276. * @public
  2277. * @since 1.5.2
  2278. * @see getPageDimensions()
  2279. */
  2280. public function getPageHeight($pagenum=null) {
  2281. if (empty($pagenum)) {
  2282. return $this->h;
  2283. }
  2284. return $this->pagedim[$pagenum]['h'];
  2285. }
  2286. /**
  2287. * Returns the page break margin.
  2288. * @param int|null $pagenum page number (empty = current page)
  2289. * @return int page break margin.
  2290. * @author Nicola Asuni
  2291. * @public
  2292. * @since 1.5.2
  2293. * @see getPageDimensions()
  2294. */
  2295. public function getBreakMargin($pagenum=null) {
  2296. if (empty($pagenum)) {
  2297. return $this->bMargin;
  2298. }
  2299. return $this->pagedim[$pagenum]['bm'];
  2300. }
  2301. /**
  2302. * Returns the scale factor (number of points in user unit).
  2303. * @return int scale factor.
  2304. * @author Nicola Asuni
  2305. * @public
  2306. * @since 1.5.2
  2307. */
  2308. public function getScaleFactor() {
  2309. return $this->k;
  2310. }
  2311. /**
  2312. * Defines the left, top and right margins.
  2313. * @param float $left Left margin.
  2314. * @param float $top Top margin.
  2315. * @param float $right Right margin. Default value is the left one.
  2316. * @param boolean $keepmargins if true overwrites the default page margins
  2317. * @public
  2318. * @since 1.0
  2319. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2320. */
  2321. public function setMargins($left, $top, $right=null, $keepmargins=false) {
  2322. //Set left, top and right margins
  2323. $this->lMargin = $left;
  2324. $this->tMargin = $top;
  2325. if ($right == -1 OR $right === null) {
  2326. $right = $left;
  2327. }
  2328. $this->rMargin = $right;
  2329. if ($keepmargins) {
  2330. // overwrite original values
  2331. $this->original_lMargin = $this->lMargin;
  2332. $this->original_rMargin = $this->rMargin;
  2333. }
  2334. }
  2335. /**
  2336. * 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.
  2337. * @param float $margin The margin.
  2338. * @public
  2339. * @since 1.4
  2340. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2341. */
  2342. public function setLeftMargin($margin) {
  2343. //Set left margin
  2344. $this->lMargin = $margin;
  2345. if (($this->page > 0) AND ($this->x < $margin)) {
  2346. $this->x = $margin;
  2347. }
  2348. }
  2349. /**
  2350. * Defines the top margin. The method can be called before creating the first page.
  2351. * @param float $margin The margin.
  2352. * @public
  2353. * @since 1.5
  2354. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2355. */
  2356. public function setTopMargin($margin) {
  2357. //Set top margin
  2358. $this->tMargin = $margin;
  2359. if (($this->page > 0) AND ($this->y < $margin)) {
  2360. $this->y = $margin;
  2361. }
  2362. }
  2363. /**
  2364. * Defines the right margin. The method can be called before creating the first page.
  2365. * @param float $margin The margin.
  2366. * @public
  2367. * @since 1.5
  2368. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2369. */
  2370. public function setRightMargin($margin) {
  2371. $this->rMargin = $margin;
  2372. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  2373. $this->x = $this->w - $margin;
  2374. }
  2375. }
  2376. /**
  2377. * Set the same internal Cell padding for top, right, bottom, left-
  2378. * @param float $pad internal padding.
  2379. * @public
  2380. * @since 2.1.000 (2008-01-09)
  2381. * @see getCellPaddings(), setCellPaddings()
  2382. */
  2383. public function setCellPadding($pad) {
  2384. if ($pad >= 0) {
  2385. $this->cell_padding['L'] = $pad;
  2386. $this->cell_padding['T'] = $pad;
  2387. $this->cell_padding['R'] = $pad;
  2388. $this->cell_padding['B'] = $pad;
  2389. }
  2390. }
  2391. /**
  2392. * Set the internal Cell paddings.
  2393. * @param float|null $left left padding
  2394. * @param float|null $top top padding
  2395. * @param float|null $right right padding
  2396. * @param float|null $bottom bottom padding
  2397. * @public
  2398. * @since 5.9.000 (2010-10-03)
  2399. * @see getCellPaddings(), SetCellPadding()
  2400. */
  2401. public function setCellPaddings($left=null, $top=null, $right=null, $bottom=null) {
  2402. if (!TCPDF_STATIC::empty_string($left) AND ($left >= 0)) {
  2403. $this->cell_padding['L'] = $left;
  2404. }
  2405. if (!TCPDF_STATIC::empty_string($top) AND ($top >= 0)) {
  2406. $this->cell_padding['T'] = $top;
  2407. }
  2408. if (!TCPDF_STATIC::empty_string($right) AND ($right >= 0)) {
  2409. $this->cell_padding['R'] = $right;
  2410. }
  2411. if (!TCPDF_STATIC::empty_string($bottom) AND ($bottom >= 0)) {
  2412. $this->cell_padding['B'] = $bottom;
  2413. }
  2414. }
  2415. /**
  2416. * Get the internal Cell padding array.
  2417. * @return array of padding values
  2418. * @public
  2419. * @since 5.9.000 (2010-10-03)
  2420. * @see setCellPaddings(), SetCellPadding()
  2421. */
  2422. public function getCellPaddings() {
  2423. return $this->cell_padding;
  2424. }
  2425. /**
  2426. * Set the internal Cell margins.
  2427. * @param float|null $left left margin
  2428. * @param float|null $top top margin
  2429. * @param float|null $right right margin
  2430. * @param float|null $bottom bottom margin
  2431. * @public
  2432. * @since 5.9.000 (2010-10-03)
  2433. * @see getCellMargins()
  2434. */
  2435. public function setCellMargins($left=null, $top=null, $right=null, $bottom=null) {
  2436. if (!TCPDF_STATIC::empty_string($left) AND ($left >= 0)) {
  2437. $this->cell_margin['L'] = $left;
  2438. }
  2439. if (!TCPDF_STATIC::empty_string($top) AND ($top >= 0)) {
  2440. $this->cell_margin['T'] = $top;
  2441. }
  2442. if (!TCPDF_STATIC::empty_string($right) AND ($right >= 0)) {
  2443. $this->cell_margin['R'] = $right;
  2444. }
  2445. if (!TCPDF_STATIC::empty_string($bottom) AND ($bottom >= 0)) {
  2446. $this->cell_margin['B'] = $bottom;
  2447. }
  2448. }
  2449. /**
  2450. * Get the internal Cell margin array.
  2451. * @return array of margin values
  2452. * @public
  2453. * @since 5.9.000 (2010-10-03)
  2454. * @see setCellMargins()
  2455. */
  2456. public function getCellMargins() {
  2457. return $this->cell_margin;
  2458. }
  2459. /**
  2460. * Adjust the internal Cell padding array to take account of the line width.
  2461. * @param string|array|int $brd 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)))
  2462. * @return void|array array of adjustments
  2463. * @public
  2464. * @since 5.9.000 (2010-10-03)
  2465. */
  2466. protected function adjustCellPadding($brd=0) {
  2467. if (empty($brd)) {
  2468. return;
  2469. }
  2470. if (is_string($brd)) {
  2471. // convert string to array
  2472. $slen = strlen($brd);
  2473. $newbrd = array();
  2474. for ($i = 0; $i < $slen; ++$i) {
  2475. $newbrd[$brd[$i]] = true;
  2476. }
  2477. $brd = $newbrd;
  2478. } elseif (
  2479. ($brd === 1)
  2480. || ($brd === true)
  2481. || (is_numeric($brd) && ((int)$brd > 0))
  2482. ) {
  2483. $brd = array('LRTB' => true);
  2484. }
  2485. if (!is_array($brd)) {
  2486. return;
  2487. }
  2488. // store current cell padding
  2489. $cp = $this->cell_padding;
  2490. // select border mode
  2491. if (isset($brd['mode'])) {
  2492. $mode = $brd['mode'];
  2493. unset($brd['mode']);
  2494. } else {
  2495. $mode = 'normal';
  2496. }
  2497. // process borders
  2498. foreach ($brd as $border => $style) {
  2499. $line_width = $this->LineWidth;
  2500. if (is_array($style) && isset($style['width'])) {
  2501. // get border width
  2502. $line_width = $style['width'];
  2503. }
  2504. $adj = 0; // line width inside the cell
  2505. switch ($mode) {
  2506. case 'ext': {
  2507. $adj = 0;
  2508. break;
  2509. }
  2510. case 'int': {
  2511. $adj = $line_width;
  2512. break;
  2513. }
  2514. case 'normal':
  2515. default: {
  2516. $adj = ($line_width / 2);
  2517. break;
  2518. }
  2519. }
  2520. // correct internal cell padding if required to avoid overlap between text and lines
  2521. if (
  2522. is_numeric($this->cell_padding['T'])
  2523. && ($this->cell_padding['T'] < $adj)
  2524. && (strpos($border, 'T') !== false)
  2525. ) {
  2526. $this->cell_padding['T'] = $adj;
  2527. }
  2528. if (
  2529. is_numeric($this->cell_padding['R'])
  2530. && ($this->cell_padding['R'] < $adj)
  2531. && (strpos($border, 'R') !== false)
  2532. ) {
  2533. $this->cell_padding['R'] = $adj;
  2534. }
  2535. if (
  2536. is_numeric($this->cell_padding['B'])
  2537. && ($this->cell_padding['B'] < $adj)
  2538. && (strpos($border, 'B') !== false)
  2539. ) {
  2540. $this->cell_padding['B'] = $adj;
  2541. }
  2542. if (
  2543. is_numeric($this->cell_padding['L'])
  2544. && ($this->cell_padding['L'] < $adj)
  2545. && (strpos($border, 'L') !== false)
  2546. ) {
  2547. $this->cell_padding['L'] = $adj;
  2548. }
  2549. }
  2550. return array(
  2551. 'T' => ($this->cell_padding['T'] - $cp['T']),
  2552. 'R' => ($this->cell_padding['R'] - $cp['R']),
  2553. 'B' => ($this->cell_padding['B'] - $cp['B']),
  2554. 'L' => ($this->cell_padding['L'] - $cp['L']),
  2555. );
  2556. }
  2557. /**
  2558. * 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.
  2559. * @param boolean $auto Boolean indicating if mode should be on or off.
  2560. * @param float $margin Distance from the bottom of the page.
  2561. * @public
  2562. * @since 1.0
  2563. * @see Cell(), MultiCell(), AcceptPageBreak()
  2564. */
  2565. public function setAutoPageBreak($auto, $margin=0) {
  2566. $this->AutoPageBreak = $auto ? true : false;
  2567. $this->bMargin = $margin;
  2568. $this->PageBreakTrigger = $this->h - $margin;
  2569. }
  2570. /**
  2571. * Return the auto-page-break mode (true or false).
  2572. * @return bool auto-page-break mode
  2573. * @public
  2574. * @since 5.9.088
  2575. */
  2576. public function getAutoPageBreak() {
  2577. return $this->AutoPageBreak;
  2578. }
  2579. /**
  2580. * Defines the way the document is to be displayed by the viewer.
  2581. * @param mixed $zoom 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>
  2582. * @param string $layout 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>
  2583. * @param string $mode 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>
  2584. * @public
  2585. * @since 1.2
  2586. */
  2587. public function setDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  2588. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  2589. $this->ZoomMode = $zoom;
  2590. } else {
  2591. $this->Error('Incorrect zoom display mode: '.$zoom);
  2592. }
  2593. $this->LayoutMode = TCPDF_STATIC::getPageLayoutMode($layout);
  2594. $this->PageMode = TCPDF_STATIC::getPageMode($mode);
  2595. }
  2596. /**
  2597. * 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.
  2598. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2599. * @param boolean $compress Boolean indicating if compression must be enabled.
  2600. * @public
  2601. * @since 1.4
  2602. */
  2603. public function setCompression($compress=true) {
  2604. $this->compress = false;
  2605. if (function_exists('gzcompress')) {
  2606. if ($compress) {
  2607. if ( !$this->pdfa_mode) {
  2608. $this->compress = true;
  2609. }
  2610. }
  2611. }
  2612. }
  2613. /**
  2614. * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  2615. * @param boolean $mode If true force sRGB output intent.
  2616. * @public
  2617. * @since 5.9.121 (2011-09-28)
  2618. */
  2619. public function setSRGBmode($mode=false) {
  2620. $this->force_srgb = $mode ? true : false;
  2621. }
  2622. /**
  2623. * Turn on/off Unicode mode for document information dictionary (meta tags).
  2624. * This has effect only when unicode mode is set to false.
  2625. * @param boolean $unicode if true set the meta information in Unicode
  2626. * @since 5.9.027 (2010-12-01)
  2627. * @public
  2628. */
  2629. public function setDocInfoUnicode($unicode=true) {
  2630. $this->docinfounicode = $unicode ? true : false;
  2631. }
  2632. /**
  2633. * Defines the title of the document.
  2634. * @param string $title The title.
  2635. * @public
  2636. * @since 1.2
  2637. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2638. */
  2639. public function setTitle($title) {
  2640. $this->title = $title;
  2641. }
  2642. /**
  2643. * Defines the subject of the document.
  2644. * @param string $subject The subject.
  2645. * @public
  2646. * @since 1.2
  2647. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2648. */
  2649. public function setSubject($subject) {
  2650. $this->subject = $subject;
  2651. }
  2652. /**
  2653. * Defines the author of the document.
  2654. * @param string $author The name of the author.
  2655. * @public
  2656. * @since 1.2
  2657. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2658. */
  2659. public function setAuthor($author) {
  2660. $this->author = $author;
  2661. }
  2662. /**
  2663. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2664. * @param string $keywords The list of keywords.
  2665. * @public
  2666. * @since 1.2
  2667. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2668. */
  2669. public function setKeywords($keywords) {
  2670. $this->keywords = $keywords;
  2671. }
  2672. /**
  2673. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2674. * @param string $creator The name of the creator.
  2675. * @public
  2676. * @since 1.2
  2677. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2678. */
  2679. public function setCreator($creator) {
  2680. $this->creator = $creator;
  2681. }
  2682. /**
  2683. * Whether to allow local file path in image html tags, when prefixed with file://
  2684. *
  2685. * @param bool $allowLocalFiles true, when local files should be allowed. Otherwise false.
  2686. * @public
  2687. * @since 6.4
  2688. */
  2689. public function setAllowLocalFiles($allowLocalFiles) {
  2690. $this->allowLocalFiles = (bool) $allowLocalFiles;
  2691. }
  2692. /**
  2693. * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
  2694. * @param string $msg The error message
  2695. * @public
  2696. * @since 1.0
  2697. */
  2698. public function Error($msg) {
  2699. // unset all class variables
  2700. $this->_destroy(true);
  2701. if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
  2702. die('<strong>TCPDF ERROR: </strong>'.$msg);
  2703. } else {
  2704. throw new Exception('TCPDF ERROR: '.$msg);
  2705. }
  2706. }
  2707. /**
  2708. * This method begins the generation of the PDF document.
  2709. * It is not necessary to call it explicitly because AddPage() does it automatically.
  2710. * Note: no page is created by this method
  2711. * @public
  2712. * @since 1.0
  2713. * @see AddPage(), Close()
  2714. */
  2715. public function Open() {
  2716. $this->state = 1;
  2717. }
  2718. /**
  2719. * Terminates the PDF document.
  2720. * It is not necessary to call this method explicitly because Output() does it automatically.
  2721. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2722. * @public
  2723. * @since 1.0
  2724. * @see Open(), Output()
  2725. */
  2726. public function Close() {
  2727. if ($this->state == 3) {
  2728. return;
  2729. }
  2730. if ($this->page == 0) {
  2731. $this->AddPage();
  2732. }
  2733. $this->endLayer();
  2734. if ($this->tcpdflink) {
  2735. // save current graphic settings
  2736. $gvars = $this->getGraphicVars();
  2737. $this->setEqualColumns();
  2738. $this->lastpage(true);
  2739. $this->setAutoPageBreak(false);
  2740. $this->x = 0;
  2741. $this->y = $this->h - (1 / $this->k);
  2742. $this->lMargin = 0;
  2743. $this->_outSaveGraphicsState();
  2744. $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  2745. $this->setFont($font, '', 1);
  2746. $this->setTextRenderingMode(0, false, false);
  2747. $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";
  2748. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  2749. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  2750. $this->_outRestoreGraphicsState();
  2751. // restore graphic settings
  2752. $this->setGraphicVars($gvars);
  2753. }
  2754. // close page
  2755. $this->endPage();
  2756. // close document
  2757. $this->_enddoc();
  2758. // unset all class variables (except critical ones)
  2759. $this->_destroy(false);
  2760. }
  2761. /**
  2762. * Move pointer at the specified document page and update page dimensions.
  2763. * @param int $pnum page number (1 ... numpages)
  2764. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2765. * @public
  2766. * @since 2.1.000 (2008-01-07)
  2767. * @see getPage(), lastpage(), getNumPages()
  2768. */
  2769. public function setPage($pnum, $resetmargins=false) {
  2770. if (($pnum == $this->page) AND ($this->state == 2)) {
  2771. return;
  2772. }
  2773. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  2774. $this->state = 2;
  2775. // save current graphic settings
  2776. //$gvars = $this->getGraphicVars();
  2777. $oldpage = $this->page;
  2778. $this->page = $pnum;
  2779. $this->wPt = $this->pagedim[$this->page]['w'];
  2780. $this->hPt = $this->pagedim[$this->page]['h'];
  2781. $this->w = $this->pagedim[$this->page]['wk'];
  2782. $this->h = $this->pagedim[$this->page]['hk'];
  2783. $this->tMargin = $this->pagedim[$this->page]['tm'];
  2784. $this->bMargin = $this->pagedim[$this->page]['bm'];
  2785. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2786. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2787. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2788. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2789. $this->setAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  2790. // restore graphic settings
  2791. //$this->setGraphicVars($gvars);
  2792. if ($resetmargins) {
  2793. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2794. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2795. $this->setY($this->tMargin);
  2796. } else {
  2797. // account for booklet mode
  2798. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  2799. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2800. $this->lMargin += $deltam;
  2801. $this->rMargin -= $deltam;
  2802. }
  2803. }
  2804. } else {
  2805. $this->Error('Wrong page number on setPage() function: '.$pnum);
  2806. }
  2807. }
  2808. /**
  2809. * Reset pointer to the last document page.
  2810. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2811. * @public
  2812. * @since 2.0.000 (2008-01-04)
  2813. * @see setPage(), getPage(), getNumPages()
  2814. */
  2815. public function lastPage($resetmargins=false) {
  2816. $this->setPage($this->getNumPages(), $resetmargins);
  2817. }
  2818. /**
  2819. * Get current document page number.
  2820. * @return int page number
  2821. * @public
  2822. * @since 2.1.000 (2008-01-07)
  2823. * @see setPage(), lastpage(), getNumPages()
  2824. */
  2825. public function getPage() {
  2826. return $this->page;
  2827. }
  2828. /**
  2829. * Get the total number of insered pages.
  2830. * @return int number of pages
  2831. * @public
  2832. * @since 2.1.000 (2008-01-07)
  2833. * @see setPage(), getPage(), lastpage()
  2834. */
  2835. public function getNumPages() {
  2836. return $this->numpages;
  2837. }
  2838. /**
  2839. * Adds a new TOC (Table Of Content) page to the document.
  2840. * @param string $orientation page orientation.
  2841. * @param mixed $format 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().
  2842. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  2843. * @public
  2844. * @since 5.0.001 (2010-05-06)
  2845. * @see AddPage(), startPage(), endPage(), endTOCPage()
  2846. */
  2847. public function addTOCPage($orientation='', $format='', $keepmargins=false) {
  2848. $this->AddPage($orientation, $format, $keepmargins, true);
  2849. }
  2850. /**
  2851. * Terminate the current TOC (Table Of Content) page
  2852. * @public
  2853. * @since 5.0.001 (2010-05-06)
  2854. * @see AddPage(), startPage(), endPage(), addTOCPage()
  2855. */
  2856. public function endTOCPage() {
  2857. $this->endPage(true);
  2858. }
  2859. /**
  2860. * 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).
  2861. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2862. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2863. * @param mixed $format 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().
  2864. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  2865. * @param boolean $tocpage if true set the tocpage state to true (the added page will be used to display Table Of Content).
  2866. * @public
  2867. * @since 1.0
  2868. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2869. */
  2870. public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
  2871. if ($this->inxobj) {
  2872. // we are inside an XObject template
  2873. return;
  2874. }
  2875. if (!isset($this->original_lMargin) OR $keepmargins) {
  2876. $this->original_lMargin = $this->lMargin;
  2877. }
  2878. if (!isset($this->original_rMargin) OR $keepmargins) {
  2879. $this->original_rMargin = $this->rMargin;
  2880. }
  2881. // terminate previous page
  2882. $this->endPage();
  2883. // start new page
  2884. $this->startPage($orientation, $format, $tocpage);
  2885. }
  2886. /**
  2887. * Terminate the current page
  2888. * @param boolean $tocpage if true set the tocpage state to false (end the page used to display Table Of Content).
  2889. * @public
  2890. * @since 4.2.010 (2008-11-14)
  2891. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  2892. */
  2893. public function endPage($tocpage=false) {
  2894. // check if page is already closed
  2895. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  2896. return;
  2897. }
  2898. // print page footer
  2899. $this->setFooter();
  2900. // close page
  2901. $this->_endpage();
  2902. // mark page as closed
  2903. $this->pageopen[$this->page] = false;
  2904. if ($tocpage) {
  2905. $this->tocpage = false;
  2906. }
  2907. }
  2908. /**
  2909. * Starts a new page to the document. The page must be closed using the endPage() function.
  2910. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2911. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2912. * @param mixed $format 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().
  2913. * @param boolean $tocpage if true the page is designated to contain the Table-Of-Content.
  2914. * @since 4.2.010 (2008-11-14)
  2915. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2916. * @public
  2917. */
  2918. public function startPage($orientation='', $format='', $tocpage=false) {
  2919. if ($tocpage) {
  2920. $this->tocpage = true;
  2921. }
  2922. // move page numbers of documents to be attached
  2923. if ($this->tocpage) {
  2924. // move reference to unexistent pages (used for page attachments)
  2925. // adjust outlines
  2926. $tmpoutlines = $this->outlines;
  2927. foreach ($tmpoutlines as $key => $outline) {
  2928. if (!$outline['f'] AND ($outline['p'] > $this->numpages)) {
  2929. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  2930. }
  2931. }
  2932. // adjust dests
  2933. $tmpdests = $this->dests;
  2934. foreach ($tmpdests as $key => $dest) {
  2935. if (!$dest['f'] AND ($dest['p'] > $this->numpages)) {
  2936. $this->dests[$key]['p'] = ($dest['p'] + 1);
  2937. }
  2938. }
  2939. // adjust links
  2940. $tmplinks = $this->links;
  2941. foreach ($tmplinks as $key => $link) {
  2942. if (!$link['f'] AND ($link['p'] > $this->numpages)) {
  2943. $this->links[$key]['p'] = ($link['p'] + 1);
  2944. }
  2945. }
  2946. }
  2947. if ($this->numpages > $this->page) {
  2948. // this page has been already added
  2949. $this->setPage($this->page + 1);
  2950. $this->setY($this->tMargin);
  2951. return;
  2952. }
  2953. // start a new page
  2954. if ($this->state == 0) {
  2955. $this->Open();
  2956. }
  2957. ++$this->numpages;
  2958. $this->swapMargins($this->booklet);
  2959. // save current graphic settings
  2960. $gvars = $this->getGraphicVars();
  2961. // start new page
  2962. $this->_beginpage($orientation, $format);
  2963. // mark page as open
  2964. $this->pageopen[$this->page] = true;
  2965. // restore graphic settings
  2966. $this->setGraphicVars($gvars);
  2967. // mark this point
  2968. $this->setPageMark();
  2969. // print page header
  2970. $this->setHeader();
  2971. // restore graphic settings
  2972. $this->setGraphicVars($gvars);
  2973. // mark this point
  2974. $this->setPageMark();
  2975. // print table header (if any)
  2976. $this->setTableHeader();
  2977. // set mark for empty page check
  2978. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  2979. }
  2980. /**
  2981. * Set start-writing mark on current page stream used to put borders and fills.
  2982. * Borders and fills are always created after content and inserted on the position marked by this method.
  2983. * This function must be called after calling Image() function for a background image.
  2984. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2985. * @public
  2986. * @since 4.0.016 (2008-07-30)
  2987. */
  2988. public function setPageMark() {
  2989. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2990. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  2991. $this->setContentMark();
  2992. }
  2993. /**
  2994. * Set start-writing mark on selected page.
  2995. * Borders and fills are always created after content and inserted on the position marked by this method.
  2996. * @param int $page page number (default is the current page)
  2997. * @protected
  2998. * @since 4.6.021 (2009-07-20)
  2999. */
  3000. protected function setContentMark($page=0) {
  3001. if ($page <= 0) {
  3002. $page = $this->page;
  3003. }
  3004. if (isset($this->footerlen[$page])) {
  3005. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  3006. } else {
  3007. $this->cntmrk[$page] = $this->pagelen[$page];
  3008. }
  3009. }
  3010. /**
  3011. * Set header data.
  3012. * @param string $ln header image logo
  3013. * @param int $lw header image logo width in mm
  3014. * @param string $ht string to print as title on document header
  3015. * @param string $hs string to print on document header
  3016. * @param int[] $tc RGB array color for text.
  3017. * @param int[] $lc RGB array color for line.
  3018. * @public
  3019. */
  3020. public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
  3021. $this->header_logo = $ln;
  3022. $this->header_logo_width = $lw;
  3023. $this->header_title = $ht;
  3024. $this->header_string = $hs;
  3025. $this->header_text_color = $tc;
  3026. $this->header_line_color = $lc;
  3027. }
  3028. /**
  3029. * Set footer data.
  3030. * @param int[] $tc RGB array color for text.
  3031. * @param int[] $lc RGB array color for line.
  3032. * @public
  3033. */
  3034. public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
  3035. $this->footer_text_color = $tc;
  3036. $this->footer_line_color = $lc;
  3037. }
  3038. /**
  3039. * Returns header data:
  3040. * <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>
  3041. * @return array<string,mixed>
  3042. * @public
  3043. * @since 4.0.012 (2008-07-24)
  3044. */
  3045. public function getHeaderData() {
  3046. $ret = array();
  3047. $ret['logo'] = $this->header_logo;
  3048. $ret['logo_width'] = $this->header_logo_width;
  3049. $ret['title'] = $this->header_title;
  3050. $ret['string'] = $this->header_string;
  3051. $ret['text_color'] = $this->header_text_color;
  3052. $ret['line_color'] = $this->header_line_color;
  3053. return $ret;
  3054. }
  3055. /**
  3056. * Set header margin.
  3057. * (minimum distance between header and top page margin)
  3058. * @param int $hm distance in user units
  3059. * @public
  3060. */
  3061. public function setHeaderMargin($hm=10) {
  3062. $this->header_margin = $hm;
  3063. }
  3064. /**
  3065. * Returns header margin in user units.
  3066. * @return float
  3067. * @since 4.0.012 (2008-07-24)
  3068. * @public
  3069. */
  3070. public function getHeaderMargin() {
  3071. return $this->header_margin;
  3072. }
  3073. /**
  3074. * Set footer margin.
  3075. * (minimum distance between footer and bottom page margin)
  3076. * @param int $fm distance in user units
  3077. * @public
  3078. */
  3079. public function setFooterMargin($fm=10) {
  3080. $this->footer_margin = $fm;
  3081. }
  3082. /**
  3083. * Returns footer margin in user units.
  3084. * @return float
  3085. * @since 4.0.012 (2008-07-24)
  3086. * @public
  3087. */
  3088. public function getFooterMargin() {
  3089. return $this->footer_margin;
  3090. }
  3091. /**
  3092. * Set a flag to print page header.
  3093. * @param boolean $val set to true to print the page header (default), false otherwise.
  3094. * @public
  3095. */
  3096. public function setPrintHeader($val=true) {
  3097. $this->print_header = $val ? true : false;
  3098. }
  3099. /**
  3100. * Set a flag to print page footer.
  3101. * @param boolean $val set to true to print the page footer (default), false otherwise.
  3102. * @public
  3103. */
  3104. public function setPrintFooter($val=true) {
  3105. $this->print_footer = $val ? true : false;
  3106. }
  3107. /**
  3108. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3109. * @return float
  3110. * @public
  3111. */
  3112. public function getImageRBX() {
  3113. return $this->img_rb_x;
  3114. }
  3115. /**
  3116. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3117. * @return float
  3118. * @public
  3119. */
  3120. public function getImageRBY() {
  3121. return $this->img_rb_y;
  3122. }
  3123. /**
  3124. * Reset the xobject template used by Header() method.
  3125. * @public
  3126. */
  3127. public function resetHeaderTemplate() {
  3128. $this->header_xobjid = false;
  3129. }
  3130. /**
  3131. * Set a flag to automatically reset the xobject template used by Header() method at each page.
  3132. * @param boolean $val set to true to reset Header xobject template at each page, false otherwise.
  3133. * @public
  3134. */
  3135. public function setHeaderTemplateAutoreset($val=true) {
  3136. $this->header_xobj_autoreset = $val ? true : false;
  3137. }
  3138. /**
  3139. * This method is used to render the page header.
  3140. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3141. * @public
  3142. */
  3143. public function Header() {
  3144. if ($this->header_xobjid === false) {
  3145. // start a new XObject Template
  3146. $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
  3147. $headerfont = $this->getHeaderFont();
  3148. $headerdata = $this->getHeaderData();
  3149. $this->y = $this->header_margin;
  3150. if ($this->rtl) {
  3151. $this->x = $this->w - $this->original_rMargin;
  3152. } else {
  3153. $this->x = $this->original_lMargin;
  3154. }
  3155. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3156. $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3157. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3158. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3159. } elseif ($imgtype == 'svg') {
  3160. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3161. } else {
  3162. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3163. }
  3164. $imgy = $this->getImageRBY();
  3165. } else {
  3166. $imgy = $this->y;
  3167. }
  3168. $cell_height = $this->getCellHeight($headerfont[2] / $this->k);
  3169. // set starting margin for text data cell
  3170. if ($this->getRTL()) {
  3171. $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  3172. } else {
  3173. $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  3174. }
  3175. $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  3176. $this->setTextColorArray($this->header_text_color);
  3177. // header title
  3178. $this->setFont($headerfont[0], 'B', $headerfont[2] + 1);
  3179. $this->setX($header_x);
  3180. $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  3181. // header string
  3182. $this->setFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3183. $this->setX($header_x);
  3184. $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
  3185. // print an ending header line
  3186. $this->setLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
  3187. $this->setY((2.835 / $this->k) + max($imgy, $this->y));
  3188. if ($this->rtl) {
  3189. $this->setX($this->original_rMargin);
  3190. } else {
  3191. $this->setX($this->original_lMargin);
  3192. }
  3193. $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
  3194. $this->endTemplate();
  3195. }
  3196. // print header template
  3197. $x = 0;
  3198. $dx = 0;
  3199. if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
  3200. // adjust margins for booklet mode
  3201. $dx = ($this->original_lMargin - $this->original_rMargin);
  3202. }
  3203. if ($this->rtl) {
  3204. $x = $this->w + $dx;
  3205. } else {
  3206. $x = 0 + $dx;
  3207. }
  3208. $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
  3209. if ($this->header_xobj_autoreset) {
  3210. // reset header xobject template at each page
  3211. $this->header_xobjid = false;
  3212. }
  3213. }
  3214. /**
  3215. * This method is used to render the page footer.
  3216. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3217. * @public
  3218. */
  3219. public function Footer() {
  3220. $cur_y = $this->y;
  3221. $this->setTextColorArray($this->footer_text_color);
  3222. //set style for cell border
  3223. $line_width = (0.85 / $this->k);
  3224. $this->setLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
  3225. //print document barcode
  3226. $barcode = $this->getBarcode();
  3227. if (!empty($barcode)) {
  3228. $this->Ln($line_width);
  3229. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
  3230. $style = array(
  3231. 'position' => $this->rtl?'R':'L',
  3232. 'align' => $this->rtl?'R':'L',
  3233. 'stretch' => false,
  3234. 'fitwidth' => true,
  3235. 'cellfitalign' => '',
  3236. 'border' => false,
  3237. 'padding' => 0,
  3238. 'fgcolor' => array(0,0,0),
  3239. 'bgcolor' => false,
  3240. 'text' => false
  3241. );
  3242. $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
  3243. }
  3244. $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
  3245. if (empty($this->pagegroups)) {
  3246. $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3247. } else {
  3248. $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3249. }
  3250. $this->setY($cur_y);
  3251. //Print page number
  3252. if ($this->getRTL()) {
  3253. $this->setX($this->original_rMargin);
  3254. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  3255. } else {
  3256. $this->setX($this->original_lMargin);
  3257. $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
  3258. }
  3259. }
  3260. /**
  3261. * This method is used to render the page header.
  3262. * @protected
  3263. * @since 4.0.012 (2008-07-24)
  3264. */
  3265. protected function setHeader() {
  3266. if (!$this->print_header OR ($this->state != 2)) {
  3267. return;
  3268. }
  3269. $this->InHeader = true;
  3270. $this->setGraphicVars($this->default_graphic_vars);
  3271. $temp_thead = $this->thead;
  3272. $temp_theadMargins = $this->theadMargins;
  3273. $lasth = $this->lasth;
  3274. $newline = $this->newline;
  3275. $this->_outSaveGraphicsState();
  3276. $this->rMargin = $this->original_rMargin;
  3277. $this->lMargin = $this->original_lMargin;
  3278. $this->setCellPadding(0);
  3279. //set current position
  3280. if ($this->rtl) {
  3281. $this->setXY($this->original_rMargin, $this->header_margin);
  3282. } else {
  3283. $this->setXY($this->original_lMargin, $this->header_margin);
  3284. }
  3285. $this->setFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3286. $this->Header();
  3287. //restore position
  3288. if ($this->rtl) {
  3289. $this->setXY($this->original_rMargin, $this->tMargin);
  3290. } else {
  3291. $this->setXY($this->original_lMargin, $this->tMargin);
  3292. }
  3293. $this->_outRestoreGraphicsState();
  3294. $this->lasth = $lasth;
  3295. $this->thead = $temp_thead;
  3296. $this->theadMargins = $temp_theadMargins;
  3297. $this->newline = $newline;
  3298. $this->InHeader = false;
  3299. }
  3300. /**
  3301. * This method is used to render the page footer.
  3302. * @protected
  3303. * @since 4.0.012 (2008-07-24)
  3304. */
  3305. protected function setFooter() {
  3306. if ($this->state != 2) {
  3307. return;
  3308. }
  3309. $this->InFooter = true;
  3310. // save current graphic settings
  3311. $gvars = $this->getGraphicVars();
  3312. // mark this point
  3313. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3314. $this->_out("\n");
  3315. if ($this->print_footer) {
  3316. $this->setGraphicVars($this->default_graphic_vars);
  3317. $this->current_column = 0;
  3318. $this->num_columns = 1;
  3319. $temp_thead = $this->thead;
  3320. $temp_theadMargins = $this->theadMargins;
  3321. $lasth = $this->lasth;
  3322. $this->_outSaveGraphicsState();
  3323. $this->rMargin = $this->original_rMargin;
  3324. $this->lMargin = $this->original_lMargin;
  3325. $this->setCellPadding(0);
  3326. //set current position
  3327. $footer_y = $this->h - $this->footer_margin;
  3328. if ($this->rtl) {
  3329. $this->setXY($this->original_rMargin, $footer_y);
  3330. } else {
  3331. $this->setXY($this->original_lMargin, $footer_y);
  3332. }
  3333. $this->setFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3334. $this->Footer();
  3335. //restore position
  3336. if ($this->rtl) {
  3337. $this->setXY($this->original_rMargin, $this->tMargin);
  3338. } else {
  3339. $this->setXY($this->original_lMargin, $this->tMargin);
  3340. }
  3341. $this->_outRestoreGraphicsState();
  3342. $this->lasth = $lasth;
  3343. $this->thead = $temp_thead;
  3344. $this->theadMargins = $temp_theadMargins;
  3345. }
  3346. // restore graphic settings
  3347. $this->setGraphicVars($gvars);
  3348. $this->current_column = $gvars['current_column'];
  3349. $this->num_columns = $gvars['num_columns'];
  3350. // calculate footer length
  3351. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3352. $this->InFooter = false;
  3353. }
  3354. /**
  3355. * Check if we are on the page body (excluding page header and footer).
  3356. * @return bool true if we are not in page header nor in page footer, false otherwise.
  3357. * @protected
  3358. * @since 5.9.091 (2011-06-15)
  3359. */
  3360. protected function inPageBody() {
  3361. return (($this->InHeader === false) AND ($this->InFooter === false));
  3362. }
  3363. /**
  3364. * This method is used to render the table header on new page (if any).
  3365. * @protected
  3366. * @since 4.5.030 (2009-03-25)
  3367. */
  3368. protected function setTableHeader() {
  3369. if ($this->num_columns > 1) {
  3370. // multi column mode
  3371. return;
  3372. }
  3373. if (isset($this->theadMargins['top'])) {
  3374. // restore the original top-margin
  3375. $this->tMargin = $this->theadMargins['top'];
  3376. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3377. $this->y = $this->tMargin;
  3378. }
  3379. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  3380. // set margins
  3381. $prev_lMargin = $this->lMargin;
  3382. $prev_rMargin = $this->rMargin;
  3383. $prev_cell_padding = $this->cell_padding;
  3384. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3385. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3386. $this->cell_padding = $this->theadMargins['cell_padding'];
  3387. if ($this->rtl) {
  3388. $this->x = $this->w - $this->rMargin;
  3389. } else {
  3390. $this->x = $this->lMargin;
  3391. }
  3392. // account for special "cell" mode
  3393. if ($this->theadMargins['cell']) {
  3394. if ($this->rtl) {
  3395. $this->x -= $this->cell_padding['R'];
  3396. } else {
  3397. $this->x += $this->cell_padding['L'];
  3398. }
  3399. }
  3400. $gvars = $this->getGraphicVars();
  3401. if (!empty($this->theadMargins['gvars'])) {
  3402. // set the correct graphic style
  3403. $this->setGraphicVars($this->theadMargins['gvars']);
  3404. $this->rMargin = $gvars['rMargin'];
  3405. $this->lMargin = $gvars['lMargin'];
  3406. }
  3407. // print table header
  3408. $this->writeHTML($this->thead, false, false, false, false, '');
  3409. $this->setGraphicVars($gvars);
  3410. // set new top margin to skip the table headers
  3411. if (!isset($this->theadMargins['top'])) {
  3412. $this->theadMargins['top'] = $this->tMargin;
  3413. }
  3414. // store end of header position
  3415. if (!isset($this->columns[0]['th'])) {
  3416. $this->columns[0]['th'] = array();
  3417. }
  3418. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3419. $this->tMargin = $this->y;
  3420. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3421. $this->lasth = 0;
  3422. $this->lMargin = $prev_lMargin;
  3423. $this->rMargin = $prev_rMargin;
  3424. $this->cell_padding = $prev_cell_padding;
  3425. }
  3426. }
  3427. /**
  3428. * Returns the current page number.
  3429. * @return int page number
  3430. * @public
  3431. * @since 1.0
  3432. * @see getAliasNbPages()
  3433. */
  3434. public function PageNo() {
  3435. return $this->page;
  3436. }
  3437. /**
  3438. * Returns the array of spot colors.
  3439. * @return array Spot colors array.
  3440. * @public
  3441. * @since 6.0.038 (2013-09-30)
  3442. */
  3443. public function getAllSpotColors() {
  3444. return $this->spot_colors;
  3445. }
  3446. /**
  3447. * Defines a new spot color.
  3448. * It can be expressed in RGB components or gray scale.
  3449. * The method can be called before the first page is created and the value is retained from page to page.
  3450. * @param string $name Full name of the spot color.
  3451. * @param float $c Cyan color for CMYK. Value between 0 and 100.
  3452. * @param float $m Magenta color for CMYK. Value between 0 and 100.
  3453. * @param float $y Yellow color for CMYK. Value between 0 and 100.
  3454. * @param float $k Key (Black) color for CMYK. Value between 0 and 100.
  3455. * @public
  3456. * @since 4.0.024 (2008-09-12)
  3457. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3458. */
  3459. public function AddSpotColor($name, $c, $m, $y, $k) {
  3460. if (!isset($this->spot_colors[$name])) {
  3461. $i = (1 + count($this->spot_colors));
  3462. $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
  3463. }
  3464. }
  3465. /**
  3466. * Set the spot color for the specified type ('draw', 'fill', 'text').
  3467. * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3468. * @param string $name Name of the spot color.
  3469. * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3470. * @return string PDF color command.
  3471. * @public
  3472. * @since 5.9.125 (2011-10-03)
  3473. */
  3474. public function setSpotColor($type, $name, $tint=100) {
  3475. $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
  3476. if ($spotcolor === false) {
  3477. $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
  3478. }
  3479. $tint = (max(0, min(100, $tint)) / 100);
  3480. $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
  3481. switch ($type) {
  3482. case 'draw': {
  3483. $pdfcolor .= sprintf('CS %F SCN', $tint);
  3484. $this->DrawColor = $pdfcolor;
  3485. $this->strokecolor = $spotcolor;
  3486. break;
  3487. }
  3488. case 'fill': {
  3489. $pdfcolor .= sprintf('cs %F scn', $tint);
  3490. $this->FillColor = $pdfcolor;
  3491. $this->bgcolor = $spotcolor;
  3492. break;
  3493. }
  3494. case 'text': {
  3495. $pdfcolor .= sprintf('cs %F scn', $tint);
  3496. $this->TextColor = $pdfcolor;
  3497. $this->fgcolor = $spotcolor;
  3498. break;
  3499. }
  3500. }
  3501. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3502. if ($this->state == 2) {
  3503. $this->_out($pdfcolor);
  3504. }
  3505. if ($this->inxobj) {
  3506. // we are inside an XObject template
  3507. $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  3508. }
  3509. return $pdfcolor;
  3510. }
  3511. /**
  3512. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  3513. * @param string $name Name of the spot color.
  3514. * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3515. * @public
  3516. * @since 4.0.024 (2008-09-12)
  3517. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3518. */
  3519. public function setDrawSpotColor($name, $tint=100) {
  3520. $this->setSpotColor('draw', $name, $tint);
  3521. }
  3522. /**
  3523. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  3524. * @param string $name Name of the spot color.
  3525. * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3526. * @public
  3527. * @since 4.0.024 (2008-09-12)
  3528. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  3529. */
  3530. public function setFillSpotColor($name, $tint=100) {
  3531. $this->setSpotColor('fill', $name, $tint);
  3532. }
  3533. /**
  3534. * Defines the spot color used for text.
  3535. * @param string $name Name of the spot color.
  3536. * @param int $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3537. * @public
  3538. * @since 4.0.024 (2008-09-12)
  3539. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3540. */
  3541. public function setTextSpotColor($name, $tint=100) {
  3542. $this->setSpotColor('text', $name, $tint);
  3543. }
  3544. /**
  3545. * Set the color array for the specified type ('draw', 'fill', 'text').
  3546. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3547. * The method can be called before the first page is created and the value is retained from page to page.
  3548. * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3549. * @param array $color Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  3550. * @param boolean $ret If true do not send the PDF command.
  3551. * @return string The PDF command or empty string.
  3552. * @public
  3553. * @since 3.1.000 (2008-06-11)
  3554. */
  3555. public function setColorArray($type, $color, $ret=false) {
  3556. if (is_array($color)) {
  3557. $color = array_values($color);
  3558. // component: grey, RGB red or CMYK cyan
  3559. $c = isset($color[0]) ? $color[0] : -1;
  3560. // component: RGB green or CMYK magenta
  3561. $m = isset($color[1]) ? $color[1] : -1;
  3562. // component: RGB blue or CMYK yellow
  3563. $y = isset($color[2]) ? $color[2] : -1;
  3564. // component: CMYK black
  3565. $k = isset($color[3]) ? $color[3] : -1;
  3566. // color name
  3567. $name = isset($color[4]) ? $color[4] : '';
  3568. if ($c >= 0) {
  3569. return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
  3570. }
  3571. }
  3572. return '';
  3573. }
  3574. /**
  3575. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3576. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3577. * The method can be called before the first page is created and the value is retained from page to page.
  3578. * @param array $color Array of colors (1, 3 or 4 values).
  3579. * @param boolean $ret If true do not send the PDF command.
  3580. * @return string the PDF command
  3581. * @public
  3582. * @since 3.1.000 (2008-06-11)
  3583. * @see SetDrawColor()
  3584. */
  3585. public function setDrawColorArray($color, $ret=false) {
  3586. return $this->setColorArray('draw', $color, $ret);
  3587. }
  3588. /**
  3589. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  3590. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3591. * The method can be called before the first page is created and the value is retained from page to page.
  3592. * @param array $color Array of colors (1, 3 or 4 values).
  3593. * @param boolean $ret If true do not send the PDF command.
  3594. * @public
  3595. * @since 3.1.000 (2008-6-11)
  3596. * @see SetFillColor()
  3597. */
  3598. public function setFillColorArray($color, $ret=false) {
  3599. return $this->setColorArray('fill', $color, $ret);
  3600. }
  3601. /**
  3602. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  3603. * The method can be called before the first page is created and the value is retained from page to page.
  3604. * @param array $color Array of colors (1, 3 or 4 values).
  3605. * @param boolean $ret If true do not send the PDF command.
  3606. * @public
  3607. * @since 3.1.000 (2008-6-11)
  3608. * @see SetFillColor()
  3609. */
  3610. public function setTextColorArray($color, $ret=false) {
  3611. return $this->setColorArray('text', $color, $ret);
  3612. }
  3613. /**
  3614. * Defines the color used by the specified type ('draw', 'fill', 'text').
  3615. * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3616. * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3617. * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3618. * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3619. * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3620. * @param boolean $ret If true do not send the command.
  3621. * @param string $name spot color name (if any)
  3622. * @return string The PDF command or empty string.
  3623. * @public
  3624. * @since 5.9.125 (2011-10-03)
  3625. */
  3626. public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3627. // set default values
  3628. if (!is_numeric($col1)) {
  3629. $col1 = 0;
  3630. }
  3631. if (!is_numeric($col2)) {
  3632. $col2 = -1;
  3633. }
  3634. if (!is_numeric($col3)) {
  3635. $col3 = -1;
  3636. }
  3637. if (!is_numeric($col4)) {
  3638. $col4 = -1;
  3639. }
  3640. // set color by case
  3641. $suffix = '';
  3642. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  3643. // Grey scale
  3644. $col1 = max(0, min(255, $col1));
  3645. $intcolor = array('G' => $col1);
  3646. $pdfcolor = sprintf('%F ', ($col1 / 255));
  3647. $suffix = 'g';
  3648. } elseif ($col4 == -1) {
  3649. // RGB
  3650. $col1 = max(0, min(255, $col1));
  3651. $col2 = max(0, min(255, $col2));
  3652. $col3 = max(0, min(255, $col3));
  3653. $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  3654. $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  3655. $suffix = 'rg';
  3656. } else {
  3657. $col1 = max(0, min(100, $col1));
  3658. $col2 = max(0, min(100, $col2));
  3659. $col3 = max(0, min(100, $col3));
  3660. $col4 = max(0, min(100, $col4));
  3661. if (empty($name)) {
  3662. // CMYK
  3663. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  3664. $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  3665. $suffix = 'k';
  3666. } else {
  3667. // SPOT COLOR
  3668. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  3669. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  3670. $pdfcolor = $this->setSpotColor($type, $name, 100);
  3671. }
  3672. }
  3673. switch ($type) {
  3674. case 'draw': {
  3675. $pdfcolor .= strtoupper($suffix);
  3676. $this->DrawColor = $pdfcolor;
  3677. $this->strokecolor = $intcolor;
  3678. break;
  3679. }
  3680. case 'fill': {
  3681. $pdfcolor .= $suffix;
  3682. $this->FillColor = $pdfcolor;
  3683. $this->bgcolor = $intcolor;
  3684. break;
  3685. }
  3686. case 'text': {
  3687. $pdfcolor .= $suffix;
  3688. $this->TextColor = $pdfcolor;
  3689. $this->fgcolor = $intcolor;
  3690. break;
  3691. }
  3692. }
  3693. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3694. if (($type != 'text') AND ($this->state == 2) AND $type !== 0) {
  3695. if (!$ret) {
  3696. $this->_out($pdfcolor);
  3697. }
  3698. return $pdfcolor;
  3699. }
  3700. return '';
  3701. }
  3702. /**
  3703. * 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.
  3704. * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3705. * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3706. * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3707. * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3708. * @param boolean $ret If true do not send the command.
  3709. * @param string $name spot color name (if any)
  3710. * @return string the PDF command
  3711. * @public
  3712. * @since 1.3
  3713. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3714. */
  3715. public function setDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3716. return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
  3717. }
  3718. /**
  3719. * 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.
  3720. * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3721. * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3722. * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3723. * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3724. * @param boolean $ret If true do not send the command.
  3725. * @param string $name Spot color name (if any).
  3726. * @return string The PDF command.
  3727. * @public
  3728. * @since 1.3
  3729. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  3730. */
  3731. public function setFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3732. return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
  3733. }
  3734. /**
  3735. * 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.
  3736. * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3737. * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3738. * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3739. * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3740. * @param boolean $ret If true do not send the command.
  3741. * @param string $name Spot color name (if any).
  3742. * @return string Empty string.
  3743. * @public
  3744. * @since 1.3
  3745. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  3746. */
  3747. public function setTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3748. return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
  3749. }
  3750. /**
  3751. * Returns the length of a string in user unit. A font must be selected.<br>
  3752. * @param string $s The string whose length is to be computed
  3753. * @param string $fontname 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.
  3754. * @param string $fontstyle 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.
  3755. * @param float $fontsize Font size in points. The default value is the current size.
  3756. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  3757. * @return float[]|float total string length or array of characted widths
  3758. * @author Nicola Asuni
  3759. * @public
  3760. * @since 1.2
  3761. */
  3762. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3763. 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);
  3764. }
  3765. /**
  3766. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  3767. * @param array $sa The array of chars whose total length is to be computed
  3768. * @param string $fontname 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.
  3769. * @param string $fontstyle 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.
  3770. * @param float $fontsize Font size in points. The default value is the current size.
  3771. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  3772. * @return float[]|float total string length or array of characted widths
  3773. * @author Nicola Asuni
  3774. * @public
  3775. * @since 2.4.000 (2008-03-06)
  3776. */
  3777. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3778. // store current values
  3779. if (!TCPDF_STATIC::empty_string($fontname)) {
  3780. $prev_FontFamily = $this->FontFamily;
  3781. $prev_FontStyle = $this->FontStyle;
  3782. $prev_FontSizePt = $this->FontSizePt;
  3783. $this->setFont($fontname, $fontstyle, $fontsize, '', 'default', false);
  3784. }
  3785. // convert UTF-8 array to Latin1 if required
  3786. if ($this->isunicode AND (!$this->isUnicodeFont())) {
  3787. $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
  3788. }
  3789. $w = 0; // total width
  3790. $wa = array(); // array of characters widths
  3791. foreach ($sa as $ck => $char) {
  3792. // character width
  3793. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  3794. $wa[] = $cw;
  3795. $w += $cw;
  3796. }
  3797. // restore previous values
  3798. if (!TCPDF_STATIC::empty_string($fontname)) {
  3799. $this->setFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
  3800. }
  3801. if ($getarray) {
  3802. return $wa;
  3803. }
  3804. return $w;
  3805. }
  3806. /**
  3807. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  3808. * @param int $char The char code whose length is to be returned
  3809. * @param boolean $notlast If false ignore the font-spacing.
  3810. * @return float char width
  3811. * @author Nicola Asuni
  3812. * @public
  3813. * @since 2.4.000 (2008-03-06)
  3814. */
  3815. public function GetCharWidth($char, $notlast=true) {
  3816. // get raw width
  3817. $chw = $this->getRawCharWidth($char);
  3818. if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
  3819. // increase/decrease font spacing
  3820. $chw += $this->font_spacing;
  3821. }
  3822. if ($this->font_stretching != 100) {
  3823. // fixed stretching mode
  3824. $chw *= ($this->font_stretching / 100);
  3825. }
  3826. return $chw;
  3827. }
  3828. /**
  3829. * Returns the length of the char in user unit for the current font.
  3830. * @param int $char The char code whose length is to be returned
  3831. * @return float char width
  3832. * @author Nicola Asuni
  3833. * @public
  3834. * @since 5.9.000 (2010-09-28)
  3835. */
  3836. public function getRawCharWidth($char) {
  3837. if ($char == 173) {
  3838. // SHY character will not be printed
  3839. return (0);
  3840. }
  3841. if (isset($this->CurrentFont['cw'][intval($char)])) {
  3842. $w = $this->CurrentFont['cw'][intval($char)];
  3843. } elseif (isset($this->CurrentFont['dw'])) {
  3844. // default width
  3845. $w = $this->CurrentFont['dw'];
  3846. } elseif (isset($this->CurrentFont['cw'][32])) {
  3847. // default width
  3848. $w = $this->CurrentFont['cw'][32];
  3849. } else {
  3850. $w = 600;
  3851. }
  3852. return $this->getAbsFontMeasure($w);
  3853. }
  3854. /**
  3855. * Returns the numbero of characters in a string.
  3856. * @param string $s The input string.
  3857. * @return int number of characters
  3858. * @public
  3859. * @since 2.0.0001 (2008-01-07)
  3860. */
  3861. public function GetNumChars($s) {
  3862. if ($this->isUnicodeFont()) {
  3863. return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
  3864. }
  3865. return strlen($s);
  3866. }
  3867. /**
  3868. * Fill the list of available fonts ($this->fontlist).
  3869. * @protected
  3870. * @since 4.0.013 (2008-07-28)
  3871. */
  3872. protected function getFontsList() {
  3873. if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) {
  3874. while (($file = readdir($fontsdir)) !== false) {
  3875. if (substr($file, -4) == '.php') {
  3876. array_push($this->fontlist, strtolower(basename($file, '.php')));
  3877. }
  3878. }
  3879. closedir($fontsdir);
  3880. }
  3881. }
  3882. /**
  3883. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3884. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3885. * 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.
  3886. * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3887. * @param string $style 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>
  3888. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3889. * @return array|false array containing the font data, or false in case of error.
  3890. * @param mixed $subset 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.
  3891. * @public
  3892. * @since 1.5
  3893. * @see SetFont(), setFontSubsetting()
  3894. */
  3895. public function AddFont($family, $style='', $fontfile='', $subset='default') {
  3896. if ($subset === 'default') {
  3897. $subset = $this->font_subsetting;
  3898. }
  3899. if ($this->pdfa_mode) {
  3900. $subset = false;
  3901. }
  3902. if (TCPDF_STATIC::empty_string($family)) {
  3903. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  3904. $family = $this->FontFamily;
  3905. } else {
  3906. $this->Error('Empty font family');
  3907. }
  3908. }
  3909. // move embedded styles on $style
  3910. if (substr($family, -1) == 'I') {
  3911. $style .= 'I';
  3912. $family = substr($family, 0, -1);
  3913. }
  3914. if (substr($family, -1) == 'B') {
  3915. $style .= 'B';
  3916. $family = substr($family, 0, -1);
  3917. }
  3918. // normalize family name
  3919. $family = strtolower($family);
  3920. if ((!$this->isunicode) AND ($family == 'arial')) {
  3921. $family = 'helvetica';
  3922. }
  3923. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  3924. $style = '';
  3925. }
  3926. if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  3927. // all fonts must be embedded
  3928. $family = 'pdfa'.$family;
  3929. }
  3930. $tempstyle = strtoupper($style);
  3931. $style = '';
  3932. // underline
  3933. if (strpos($tempstyle, 'U') !== false) {
  3934. $this->underline = true;
  3935. } else {
  3936. $this->underline = false;
  3937. }
  3938. // line-through (deleted)
  3939. if (strpos($tempstyle, 'D') !== false) {
  3940. $this->linethrough = true;
  3941. } else {
  3942. $this->linethrough = false;
  3943. }
  3944. // overline
  3945. if (strpos($tempstyle, 'O') !== false) {
  3946. $this->overline = true;
  3947. } else {
  3948. $this->overline = false;
  3949. }
  3950. // bold
  3951. if (strpos($tempstyle, 'B') !== false) {
  3952. $style .= 'B';
  3953. }
  3954. // oblique
  3955. if (strpos($tempstyle, 'I') !== false) {
  3956. $style .= 'I';
  3957. }
  3958. $bistyle = $style;
  3959. $fontkey = $family.$style;
  3960. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  3961. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  3962. // check if the font has been already added
  3963. $fb = $this->getFontBuffer($fontkey);
  3964. if ($fb !== false) {
  3965. if ($this->inxobj) {
  3966. // we are inside an XObject template
  3967. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  3968. }
  3969. return $fontdata;
  3970. }
  3971. // get specified font directory (if any)
  3972. $fontdir = false;
  3973. if (!TCPDF_STATIC::empty_string($fontfile)) {
  3974. $fontdir = dirname($fontfile);
  3975. if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) {
  3976. $fontdir = '';
  3977. } else {
  3978. $fontdir .= '/';
  3979. }
  3980. }
  3981. // true when the font style variation is missing
  3982. $missing_style = false;
  3983. // search and include font file
  3984. if (TCPDF_STATIC::empty_string($fontfile) OR (!@TCPDF_STATIC::file_exists($fontfile))) {
  3985. // build a standard filenames for specified font
  3986. $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
  3987. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3988. if (TCPDF_STATIC::empty_string($fontfile)) {
  3989. $missing_style = true;
  3990. // try to remove the style part
  3991. $tmp_fontfile = str_replace(' ', '', $family).'.php';
  3992. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3993. }
  3994. }
  3995. // include font file
  3996. if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) {
  3997. include($fontfile);
  3998. } else {
  3999. $this->Error('Could not include font definition file: '.$family.'');
  4000. }
  4001. // check font parameters
  4002. if ((!isset($type)) OR (!isset($cw))) {
  4003. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  4004. }
  4005. // SET default parameters
  4006. if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
  4007. $file = '';
  4008. }
  4009. if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
  4010. $enc = '';
  4011. }
  4012. if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
  4013. $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
  4014. $cidinfo['uni2cid'] = array();
  4015. }
  4016. if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
  4017. $ctg = '';
  4018. }
  4019. if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
  4020. $desc = array();
  4021. }
  4022. if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
  4023. $up = -100;
  4024. }
  4025. if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
  4026. $ut = 50;
  4027. }
  4028. if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
  4029. $cw = array();
  4030. }
  4031. if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
  4032. // set default width
  4033. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  4034. $dw = $desc['MissingWidth'];
  4035. } elseif (isset($cw[32])) {
  4036. $dw = $cw[32];
  4037. } else {
  4038. $dw = 600;
  4039. }
  4040. }
  4041. ++$this->numfonts;
  4042. if ($type == 'core') {
  4043. $name = $this->CoreFonts[$fontkey];
  4044. $subset = false;
  4045. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  4046. $subset = false;
  4047. } elseif ($type == 'TrueTypeUnicode') {
  4048. $enc = 'Identity-H';
  4049. } elseif ($type == 'cidfont0') {
  4050. if ($this->pdfa_mode) {
  4051. $this->Error('All fonts must be embedded in PDF/A mode!');
  4052. }
  4053. } else {
  4054. $this->Error('Unknow font type: '.$type.'');
  4055. }
  4056. // set name if unset
  4057. if (!isset($name) OR empty($name)) {
  4058. $name = $fontkey;
  4059. }
  4060. // create artificial font style variations if missing (only works with non-embedded fonts)
  4061. if (($type != 'core') AND $missing_style) {
  4062. // style variations
  4063. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  4064. $name .= $styles[$bistyle];
  4065. // artificial bold
  4066. if (strpos($bistyle, 'B') !== false) {
  4067. if (isset($desc['StemV'])) {
  4068. // from normal to bold
  4069. $desc['StemV'] = round($desc['StemV'] * 1.75);
  4070. } else {
  4071. // bold
  4072. $desc['StemV'] = 123;
  4073. }
  4074. }
  4075. // artificial italic
  4076. if (strpos($bistyle, 'I') !== false) {
  4077. if (isset($desc['ItalicAngle'])) {
  4078. $desc['ItalicAngle'] -= 11;
  4079. } else {
  4080. $desc['ItalicAngle'] = -11;
  4081. }
  4082. if (isset($desc['Flags'])) {
  4083. $desc['Flags'] |= 64; //bit 7
  4084. } else {
  4085. $desc['Flags'] = 64;
  4086. }
  4087. }
  4088. }
  4089. // check if the array of characters bounding boxes is defined
  4090. if (!isset($cbbox)) {
  4091. $cbbox = array();
  4092. }
  4093. // initialize subsetchars
  4094. $subsetchars = array_fill(0, 255, true);
  4095. $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));
  4096. if ($this->inxobj) {
  4097. // we are inside an XObject template
  4098. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4099. }
  4100. if (isset($diff) AND (!empty($diff))) {
  4101. //Search existing encodings
  4102. $d = 0;
  4103. $nb = count($this->diffs);
  4104. for ($i=1; $i <= $nb; ++$i) {
  4105. if ($this->diffs[$i] == $diff) {
  4106. $d = $i;
  4107. break;
  4108. }
  4109. }
  4110. if ($d == 0) {
  4111. $d = $nb + 1;
  4112. $this->diffs[$d] = $diff;
  4113. }
  4114. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4115. }
  4116. if (!TCPDF_STATIC::empty_string($file)) {
  4117. if (!isset($this->FontFiles[$file])) {
  4118. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4119. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4120. } elseif ($type != 'core') {
  4121. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4122. }
  4123. } else {
  4124. // update fontkeys that are sharing this font file
  4125. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4126. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  4127. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4128. }
  4129. }
  4130. }
  4131. return $fontdata;
  4132. }
  4133. /**
  4134. * Sets the font used to print character strings.
  4135. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4136. * The method can be called before the first page is created and the font is retained from page to page.
  4137. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4138. * 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 />
  4139. * @param string $family 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.
  4140. * @param string $style 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.
  4141. * @param float|null $size 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
  4142. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4143. * @param mixed $subset 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.
  4144. * @param boolean $out if true output the font size command, otherwise only set the font properties.
  4145. * @author Nicola Asuni
  4146. * @public
  4147. * @since 1.0
  4148. * @see AddFont(), SetFontSize()
  4149. */
  4150. public function setFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true) {
  4151. //Select a font; size given in points
  4152. if ($size === null) {
  4153. $size = $this->FontSizePt;
  4154. }
  4155. if ($size < 0) {
  4156. $size = 0;
  4157. }
  4158. // try to add font (if not already added)
  4159. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  4160. $this->FontFamily = $fontdata['family'];
  4161. $this->FontStyle = $fontdata['style'];
  4162. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  4163. // save subset chars of the previous font
  4164. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4165. }
  4166. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  4167. $this->setFontSize($size, $out);
  4168. }
  4169. /**
  4170. * Defines the size of the current font.
  4171. * @param float $size The font size in points.
  4172. * @param boolean $out if true output the font size command, otherwise only set the font properties.
  4173. * @public
  4174. * @since 1.0
  4175. * @see SetFont()
  4176. */
  4177. public function setFontSize($size, $out=true) {
  4178. $size = (float)$size;
  4179. // font size in points
  4180. $this->FontSizePt = $size;
  4181. // font size in user units
  4182. $this->FontSize = $size / $this->k;
  4183. // calculate some font metrics
  4184. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4185. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4186. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  4187. } else {
  4188. $font_height = $size * 1.219;
  4189. }
  4190. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4191. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  4192. }
  4193. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4194. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  4195. }
  4196. if (!isset($font_ascent) AND !isset($font_descent)) {
  4197. // core font
  4198. $font_ascent = 0.76 * $font_height;
  4199. $font_descent = $font_height - $font_ascent;
  4200. } elseif (!isset($font_descent)) {
  4201. $font_descent = $font_height - $font_ascent;
  4202. } elseif (!isset($font_ascent)) {
  4203. $font_ascent = $font_height - $font_descent;
  4204. }
  4205. $this->FontAscent = ($font_ascent / $this->k);
  4206. $this->FontDescent = ($font_descent / $this->k);
  4207. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  4208. $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4209. }
  4210. }
  4211. /**
  4212. * Returns the bounding box of the current font in user units.
  4213. * @return array
  4214. * @public
  4215. * @since 5.9.152 (2012-03-23)
  4216. */
  4217. public function getFontBBox() {
  4218. $fbbox = array();
  4219. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4220. $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4221. $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
  4222. } else {
  4223. // Find max width
  4224. if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  4225. $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  4226. } else {
  4227. $maxw = 0;
  4228. if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  4229. $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
  4230. }
  4231. if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  4232. $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
  4233. }
  4234. if (isset($this->CurrentFont['dw'])) {
  4235. $maxw = max($maxw, $this->CurrentFont['dw']);
  4236. }
  4237. foreach ($this->CurrentFont['cw'] as $char => $w) {
  4238. $maxw = max($maxw, $w);
  4239. }
  4240. if ($maxw == 0) {
  4241. $maxw = 600;
  4242. }
  4243. $maxw = $this->getAbsFontMeasure($maxw);
  4244. }
  4245. $fbbox = array(0, (0 - $this->FontDescent), $maxw, $this->FontAscent);
  4246. }
  4247. return $fbbox;
  4248. }
  4249. /**
  4250. * Convert a relative font measure into absolute value.
  4251. * @param int $s Font measure.
  4252. * @return float Absolute measure.
  4253. * @since 5.9.186 (2012-09-13)
  4254. */
  4255. public function getAbsFontMeasure($s) {
  4256. return ($s * $this->FontSize / 1000);
  4257. }
  4258. /**
  4259. * Returns the glyph bounding box of the specified character in the current font in user units.
  4260. * @param int $char Input character code.
  4261. * @return false|array array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  4262. * @since 5.9.186 (2012-09-13)
  4263. */
  4264. public function getCharBBox($char) {
  4265. $c = intval($char);
  4266. if (isset($this->CurrentFont['cw'][$c])) {
  4267. // glyph is defined ... use zero width & height for glyphs without outlines
  4268. $result = array(0,0,0,0);
  4269. if (isset($this->CurrentFont['cbbox'][$c])) {
  4270. $result = $this->CurrentFont['cbbox'][$c];
  4271. }
  4272. return array_map(array($this,'getAbsFontMeasure'), $result);
  4273. }
  4274. return false;
  4275. }
  4276. /**
  4277. * Return the font descent value
  4278. * @param string $font font name
  4279. * @param string $style font style
  4280. * @param float $size The size (in points)
  4281. * @return int font descent
  4282. * @public
  4283. * @author Nicola Asuni
  4284. * @since 4.9.003 (2010-03-30)
  4285. */
  4286. public function getFontDescent($font, $style='', $size=0) {
  4287. $fontdata = $this->AddFont($font, $style);
  4288. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4289. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4290. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  4291. } else {
  4292. $descent = (1.219 * 0.24 * $size);
  4293. }
  4294. return ($descent / $this->k);
  4295. }
  4296. /**
  4297. * Return the font ascent value.
  4298. * @param string $font font name
  4299. * @param string $style font style
  4300. * @param float $size The size (in points)
  4301. * @return int font ascent
  4302. * @public
  4303. * @author Nicola Asuni
  4304. * @since 4.9.003 (2010-03-30)
  4305. */
  4306. public function getFontAscent($font, $style='', $size=0) {
  4307. $fontdata = $this->AddFont($font, $style);
  4308. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4309. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4310. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  4311. } else {
  4312. $ascent = 1.219 * 0.76 * $size;
  4313. }
  4314. return ($ascent / $this->k);
  4315. }
  4316. /**
  4317. * Return true in the character is present in the specified font.
  4318. * @param mixed $char Character to check (integer value or string)
  4319. * @param string $font Font name (family name).
  4320. * @param string $style Font style.
  4321. * @return bool true if the char is defined, false otherwise.
  4322. * @public
  4323. * @since 5.9.153 (2012-03-28)
  4324. */
  4325. public function isCharDefined($char, $font='', $style='') {
  4326. if (is_string($char)) {
  4327. // get character code
  4328. $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont);
  4329. $char = $char[0];
  4330. }
  4331. if (TCPDF_STATIC::empty_string($font)) {
  4332. if (TCPDF_STATIC::empty_string($style)) {
  4333. return (isset($this->CurrentFont['cw'][intval($char)]));
  4334. }
  4335. $font = $this->FontFamily;
  4336. }
  4337. $fontdata = $this->AddFont($font, $style);
  4338. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4339. return (isset($fontinfo['cw'][intval($char)]));
  4340. }
  4341. /**
  4342. * Replace missing font characters on selected font with specified substitutions.
  4343. * @param string $text Text to process.
  4344. * @param string $font Font name (family name).
  4345. * @param string $style Font style.
  4346. * @param array $subs 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.
  4347. * @return string Processed text.
  4348. * @public
  4349. * @since 5.9.153 (2012-03-28)
  4350. */
  4351. public function replaceMissingChars($text, $font='', $style='', $subs=array()) {
  4352. if (empty($subs)) {
  4353. return $text;
  4354. }
  4355. if (TCPDF_STATIC::empty_string($font)) {
  4356. $font = $this->FontFamily;
  4357. }
  4358. $fontdata = $this->AddFont($font, $style);
  4359. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4360. $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  4361. foreach ($uniarr as $k => $chr) {
  4362. if (!isset($fontinfo['cw'][$chr])) {
  4363. // this character is missing on the selected font
  4364. if (isset($subs[$chr])) {
  4365. // we have available substitutions
  4366. if (is_array($subs[$chr])) {
  4367. foreach($subs[$chr] as $s) {
  4368. if (isset($fontinfo['cw'][$s])) {
  4369. $uniarr[$k] = $s;
  4370. break;
  4371. }
  4372. }
  4373. } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  4374. $uniarr[$k] = $subs[$chr];
  4375. }
  4376. }
  4377. }
  4378. }
  4379. return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr, $this->isunicode));
  4380. }
  4381. /**
  4382. * Defines the default monospaced font.
  4383. * @param string $font Font name.
  4384. * @public
  4385. * @since 4.5.025
  4386. */
  4387. public function setDefaultMonospacedFont($font) {
  4388. $this->default_monospaced_font = $font;
  4389. }
  4390. /**
  4391. * 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 />
  4392. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4393. * @public
  4394. * @since 1.5
  4395. * @see Cell(), Write(), Image(), Link(), SetLink()
  4396. */
  4397. public function AddLink() {
  4398. // create a new internal link
  4399. $n = count($this->links) + 1;
  4400. $this->links[$n] = array('p' => 0, 'y' => 0, 'f' => false);
  4401. return $n;
  4402. }
  4403. /**
  4404. * Defines the page and position a link points to.
  4405. * @param int $link The link identifier returned by AddLink()
  4406. * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4407. * @param int|string $page 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.
  4408. * @public
  4409. * @since 1.5
  4410. * @see AddLink()
  4411. */
  4412. public function setLink($link, $y=0, $page=-1) {
  4413. $fixed = false;
  4414. if (!empty($page) AND (substr($page, 0, 1) == '*')) {
  4415. $page = intval(substr($page, 1));
  4416. // this page number will not be changed when moving/add/deleting pages
  4417. $fixed = true;
  4418. }
  4419. if ($page < 0) {
  4420. $page = $this->page;
  4421. }
  4422. if ($y == -1) {
  4423. $y = $this->y;
  4424. }
  4425. $this->links[$link] = array('p' => $page, 'y' => $y, 'f' => $fixed);
  4426. }
  4427. /**
  4428. * Puts a link on a rectangular area of the page.
  4429. * 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.
  4430. * @param float $x Abscissa of the upper-left corner of the rectangle
  4431. * @param float $y Ordinate of the upper-left corner of the rectangle
  4432. * @param float $w Width of the rectangle
  4433. * @param float $h Height of the rectangle
  4434. * @param mixed $link URL or identifier returned by AddLink()
  4435. * @param int $spaces number of spaces on the text to link
  4436. * @public
  4437. * @since 1.5
  4438. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4439. */
  4440. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  4441. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  4442. }
  4443. /**
  4444. * Puts a markup annotation on a rectangular area of the page.
  4445. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4446. * @param float $x Abscissa of the upper-left corner of the rectangle
  4447. * @param float $y Ordinate of the upper-left corner of the rectangle
  4448. * @param float $w Width of the rectangle
  4449. * @param float $h Height of the rectangle
  4450. * @param string $text annotation text or alternate content
  4451. * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  4452. * @param int $spaces number of spaces on the text to link
  4453. * @public
  4454. * @since 4.0.018 (2008-08-06)
  4455. */
  4456. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  4457. if ($this->inxobj) {
  4458. // store parameters for later use on template
  4459. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  4460. return;
  4461. }
  4462. if ($x === '') {
  4463. $x = $this->x;
  4464. }
  4465. if ($y === '') {
  4466. $y = $this->y;
  4467. }
  4468. // check page for no-write regions and adapt page margins if necessary
  4469. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  4470. // recalculate coordinates to account for graphic transformations
  4471. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4472. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  4473. $maxid = count($this->transfmatrix[$i]) - 1;
  4474. for ($j=$maxid; $j >= 0; --$j) {
  4475. $ctm = $this->transfmatrix[$i][$j];
  4476. if (isset($ctm['a'])) {
  4477. $x = $x * $this->k;
  4478. $y = ($this->h - $y) * $this->k;
  4479. $w = $w * $this->k;
  4480. $h = $h * $this->k;
  4481. // top left
  4482. $xt = $x;
  4483. $yt = $y;
  4484. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4485. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4486. // top right
  4487. $xt = $x + $w;
  4488. $yt = $y;
  4489. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4490. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4491. // bottom left
  4492. $xt = $x;
  4493. $yt = $y - $h;
  4494. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4495. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4496. // bottom right
  4497. $xt = $x + $w;
  4498. $yt = $y - $h;
  4499. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4500. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4501. // new coordinates (rectangle area)
  4502. $x = min($x1, $x2, $x3, $x4);
  4503. $y = max($y1, $y2, $y3, $y4);
  4504. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  4505. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  4506. $x = $x / $this->k;
  4507. $y = $this->h - ($y / $this->k);
  4508. }
  4509. }
  4510. }
  4511. }
  4512. if ($this->page <= 0) {
  4513. $page = 1;
  4514. } else {
  4515. $page = $this->page;
  4516. }
  4517. if (!isset($this->PageAnnots[$page])) {
  4518. $this->PageAnnots[$page] = array();
  4519. }
  4520. $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  4521. if (!$this->pdfa_mode || ($this->pdfa_mode && $this->pdfa_version == 3)) {
  4522. if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
  4523. AND (@TCPDF_STATIC::file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
  4524. AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  4525. $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
  4526. }
  4527. }
  4528. // Add widgets annotation's icons
  4529. if (isset($opt['mk']['i']) AND @TCPDF_STATIC::file_exists($opt['mk']['i'])) {
  4530. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  4531. }
  4532. if (isset($opt['mk']['ri']) AND @TCPDF_STATIC::file_exists($opt['mk']['ri'])) {
  4533. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4534. }
  4535. if (isset($opt['mk']['ix']) AND @TCPDF_STATIC::file_exists($opt['mk']['ix'])) {
  4536. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4537. }
  4538. }
  4539. /**
  4540. * Embedd the attached files.
  4541. * @since 4.4.000 (2008-12-07)
  4542. * @protected
  4543. * @see Annotation()
  4544. */
  4545. protected function _putEmbeddedFiles() {
  4546. if ($this->pdfa_mode && $this->pdfa_version != 3) {
  4547. // embedded files are not allowed in PDF/A mode version 1 and 2
  4548. return;
  4549. }
  4550. reset($this->embeddedfiles);
  4551. foreach ($this->embeddedfiles as $filename => $filedata) {
  4552. $data = $this->getCachedFileContents($filedata['file']);
  4553. if ($data !== FALSE) {
  4554. $rawsize = strlen($data);
  4555. if ($rawsize > 0) {
  4556. // update name tree
  4557. $this->efnames[$filename] = $filedata['f'].' 0 R';
  4558. // embedded file specification object
  4559. $out = $this->_getobj($filedata['f'])."\n";
  4560. $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']);
  4561. $out .= ' /UF '.$this->_datastring($filename, $filedata['f']);
  4562. $out .= ' /AFRelationship /Source';
  4563. $out .= ' /EF <</F '.$filedata['n'].' 0 R>> >>';
  4564. $out .= "\n".'endobj';
  4565. $this->_out($out);
  4566. // embedded file object
  4567. $filter = '';
  4568. if ($this->compress) {
  4569. $data = gzcompress($data);
  4570. $filter = ' /Filter /FlateDecode';
  4571. }
  4572. if ($this->pdfa_version == 3) {
  4573. $filter = ' /Subtype /text#2Fxml';
  4574. }
  4575. $stream = $this->_getrawstream($data, $filedata['n']);
  4576. $out = $this->_getobj($filedata['n'])."\n";
  4577. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
  4578. $out .= ' stream'."\n".$stream."\n".'endstream';
  4579. $out .= "\n".'endobj';
  4580. $this->_out($out);
  4581. }
  4582. }
  4583. }
  4584. }
  4585. /**
  4586. * Prints a text cell at the specified position.
  4587. * This method allows to place a string precisely on the page.
  4588. * @param float $x Abscissa of the cell origin
  4589. * @param float $y Ordinate of the cell origin
  4590. * @param string $txt String to print
  4591. * @param int $fstroke outline size in user units (0 = disable)
  4592. * @param boolean $fclip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4593. * @param boolean $ffill if true fills the text
  4594. * @param mixed $border 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)))
  4595. * @param int $ln 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.
  4596. * @param string $align 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>
  4597. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4598. * @param mixed $link URL or identifier returned by AddLink().
  4599. * @param int $stretch 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.
  4600. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4601. * @param string $calign 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>
  4602. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4603. * @param boolean $rtloff if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4604. * @public
  4605. * @since 1.0
  4606. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4607. */
  4608. public function Text($x, $y, $txt, $fstroke=0, $fclip=false, $ffill=true, $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M', $rtloff=false) {
  4609. $textrendermode = $this->textrendermode;
  4610. $textstrokewidth = $this->textstrokewidth;
  4611. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  4612. $this->setXY($x, $y, $rtloff);
  4613. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  4614. // restore previous rendering mode
  4615. $this->textrendermode = $textrendermode;
  4616. $this->textstrokewidth = $textstrokewidth;
  4617. }
  4618. /**
  4619. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4620. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4621. * This method is called automatically and should not be called directly by the application.
  4622. * @return bool
  4623. * @public
  4624. * @since 1.4
  4625. * @see SetAutoPageBreak()
  4626. */
  4627. public function AcceptPageBreak() {
  4628. if ($this->num_columns > 1) {
  4629. // multi column mode
  4630. if ($this->current_column < ($this->num_columns - 1)) {
  4631. // go to next column
  4632. $this->selectColumn($this->current_column + 1);
  4633. } elseif ($this->AutoPageBreak) {
  4634. // add a new page
  4635. $this->AddPage();
  4636. // set first column
  4637. $this->selectColumn(0);
  4638. }
  4639. // avoid page breaking from checkPageBreak()
  4640. return false;
  4641. }
  4642. return $this->AutoPageBreak;
  4643. }
  4644. /**
  4645. * Add page if needed.
  4646. * @param float $h Cell height. Default value: 0.
  4647. * @param float|null $y starting y position, leave empty for current position.
  4648. * @param bool $addpage if true add a page, otherwise only return the true/false state
  4649. * @return bool true in case of page break, false otherwise.
  4650. * @since 3.2.000 (2008-07-01)
  4651. * @protected
  4652. */
  4653. protected function checkPageBreak($h=0, $y=null, $addpage=true) {
  4654. if (TCPDF_STATIC::empty_string($y)) {
  4655. $y = $this->y;
  4656. }
  4657. $current_page = $this->page;
  4658. if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  4659. if ($addpage) {
  4660. //Automatic page break
  4661. $x = $this->x;
  4662. $this->AddPage($this->CurOrientation);
  4663. $this->y = $this->tMargin;
  4664. $oldpage = $this->page - 1;
  4665. if ($this->rtl) {
  4666. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4667. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4668. } else {
  4669. $this->x = $x;
  4670. }
  4671. } else {
  4672. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4673. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4674. } else {
  4675. $this->x = $x;
  4676. }
  4677. }
  4678. }
  4679. return true;
  4680. }
  4681. if ($current_page != $this->page) {
  4682. // account for columns mode
  4683. return true;
  4684. }
  4685. return false;
  4686. }
  4687. /**
  4688. * 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 />
  4689. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4690. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  4691. * @param float $h Cell height. Default value: 0.
  4692. * @param string $txt String to print. Default value: empty string.
  4693. * @param mixed $border 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)))
  4694. * @param int $ln 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.
  4695. * @param string $align 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>
  4696. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4697. * @param mixed $link URL or identifier returned by AddLink().
  4698. * @param int $stretch 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.
  4699. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4700. * @param string $calign 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>
  4701. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4702. * @public
  4703. * @since 1.0
  4704. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  4705. */
  4706. 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') {
  4707. $prev_cell_margin = $this->cell_margin;
  4708. $prev_cell_padding = $this->cell_padding;
  4709. $this->adjustCellPadding($border);
  4710. if (!$ignore_min_height) {
  4711. $min_cell_height = $this->getCellHeight($this->FontSize);
  4712. if ($h < $min_cell_height) {
  4713. $h = $min_cell_height;
  4714. }
  4715. }
  4716. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  4717. // apply text shadow if enabled
  4718. if ($this->txtshadow['enabled']) {
  4719. // save data
  4720. $x = $this->x;
  4721. $y = $this->y;
  4722. $bc = $this->bgcolor;
  4723. $fc = $this->fgcolor;
  4724. $sc = $this->strokecolor;
  4725. $alpha = $this->alpha;
  4726. // print shadow
  4727. $this->x += $this->txtshadow['depth_w'];
  4728. $this->y += $this->txtshadow['depth_h'];
  4729. $this->setFillColorArray($this->txtshadow['color']);
  4730. $this->setTextColorArray($this->txtshadow['color']);
  4731. $this->setDrawColorArray($this->txtshadow['color']);
  4732. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4733. $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  4734. }
  4735. if ($this->state == 2) {
  4736. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4737. }
  4738. //restore data
  4739. $this->x = $x;
  4740. $this->y = $y;
  4741. $this->setFillColorArray($bc);
  4742. $this->setTextColorArray($fc);
  4743. $this->setDrawColorArray($sc);
  4744. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4745. $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  4746. }
  4747. }
  4748. if ($this->state == 2) {
  4749. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4750. }
  4751. $this->cell_padding = $prev_cell_padding;
  4752. $this->cell_margin = $prev_cell_margin;
  4753. }
  4754. /**
  4755. * 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 />
  4756. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4757. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  4758. * @param float $h Cell height. Default value: 0.
  4759. * @param string $txt String to print. Default value: empty string.
  4760. * @param mixed $border 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)))
  4761. * @param int $ln 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.
  4762. * @param string $align 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>
  4763. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4764. * @param mixed $link URL or identifier returned by AddLink().
  4765. * @param int $stretch 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.
  4766. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4767. * @param string $calign 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>
  4768. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
  4769. * @return string containing cell code
  4770. * @protected
  4771. * @since 1.0
  4772. * @see Cell()
  4773. */
  4774. 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') {
  4775. // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  4776. $txt = str_replace(TCPDF_FONTS::unichr(160, $this->isunicode), ' ', $txt);
  4777. $prev_cell_margin = $this->cell_margin;
  4778. $prev_cell_padding = $this->cell_padding;
  4779. $txt = TCPDF_STATIC::removeSHY($txt, $this->isunicode);
  4780. $rs = ''; //string to be returned
  4781. $this->adjustCellPadding($border);
  4782. if (!$ignore_min_height) {
  4783. $min_cell_height = $this->getCellHeight($this->FontSize);
  4784. if ($h < $min_cell_height) {
  4785. $h = $min_cell_height;
  4786. }
  4787. }
  4788. $k = $this->k;
  4789. // check page for no-write regions and adapt page margins if necessary
  4790. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  4791. if ($this->rtl) {
  4792. $x = $this->x - $this->cell_margin['R'];
  4793. } else {
  4794. $x = $this->x + $this->cell_margin['L'];
  4795. }
  4796. $y = $this->y + $this->cell_margin['T'];
  4797. $prev_font_stretching = $this->font_stretching;
  4798. $prev_font_spacing = $this->font_spacing;
  4799. // cell vertical alignment
  4800. switch ($calign) {
  4801. case 'A': {
  4802. // font top
  4803. switch ($valign) {
  4804. case 'T': {
  4805. // top
  4806. $y -= $this->cell_padding['T'];
  4807. break;
  4808. }
  4809. case 'B': {
  4810. // bottom
  4811. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  4812. break;
  4813. }
  4814. default:
  4815. case 'C':
  4816. case 'M': {
  4817. // center
  4818. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  4819. break;
  4820. }
  4821. }
  4822. break;
  4823. }
  4824. case 'L': {
  4825. // font baseline
  4826. switch ($valign) {
  4827. case 'T': {
  4828. // top
  4829. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  4830. break;
  4831. }
  4832. case 'B': {
  4833. // bottom
  4834. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  4835. break;
  4836. }
  4837. default:
  4838. case 'C':
  4839. case 'M': {
  4840. // center
  4841. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  4842. break;
  4843. }
  4844. }
  4845. break;
  4846. }
  4847. case 'D': {
  4848. // font bottom
  4849. switch ($valign) {
  4850. case 'T': {
  4851. // top
  4852. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  4853. break;
  4854. }
  4855. case 'B': {
  4856. // bottom
  4857. $y -= ($h - $this->cell_padding['B']);
  4858. break;
  4859. }
  4860. default:
  4861. case 'C':
  4862. case 'M': {
  4863. // center
  4864. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  4865. break;
  4866. }
  4867. }
  4868. break;
  4869. }
  4870. case 'B': {
  4871. // cell bottom
  4872. $y -= $h;
  4873. break;
  4874. }
  4875. case 'C':
  4876. case 'M': {
  4877. // cell center
  4878. $y -= ($h / 2);
  4879. break;
  4880. }
  4881. default:
  4882. case 'T': {
  4883. // cell top
  4884. break;
  4885. }
  4886. }
  4887. // text vertical alignment
  4888. switch ($valign) {
  4889. case 'T': {
  4890. // top
  4891. $yt = $y + $this->cell_padding['T'];
  4892. break;
  4893. }
  4894. case 'B': {
  4895. // bottom
  4896. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  4897. break;
  4898. }
  4899. default:
  4900. case 'C':
  4901. case 'M': {
  4902. // center
  4903. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  4904. break;
  4905. }
  4906. }
  4907. $basefonty = $yt + $this->FontAscent;
  4908. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  4909. if ($this->rtl) {
  4910. $w = $x - $this->lMargin;
  4911. } else {
  4912. $w = $this->w - $this->rMargin - $x;
  4913. }
  4914. }
  4915. $s = '';
  4916. // fill and borders
  4917. if (is_string($border) AND (strlen($border) == 4)) {
  4918. // full border
  4919. $border = 1;
  4920. }
  4921. if ($fill OR ($border == 1)) {
  4922. if ($fill) {
  4923. $op = ($border == 1) ? 'B' : 'f';
  4924. } else {
  4925. $op = 'S';
  4926. }
  4927. if ($this->rtl) {
  4928. $xk = (($x - $w) * $k);
  4929. } else {
  4930. $xk = ($x * $k);
  4931. }
  4932. $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  4933. }
  4934. // draw borders
  4935. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  4936. if ($txt != '') {
  4937. $txt2 = $txt;
  4938. if ($this->isunicode) {
  4939. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  4940. $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont);
  4941. } else {
  4942. $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values
  4943. $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont);
  4944. // replace thai chars (if any)
  4945. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  4946. // number of chars
  4947. $numchars = count($unicode);
  4948. // po pla, for far, for fan
  4949. $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
  4950. // do chada, to patak
  4951. $lowtail = array(0x0e0e, 0x0e0f);
  4952. // mai hun arkad, sara i, sara ii, sara ue, sara uee
  4953. $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
  4954. // mai ek, mai tho, mai tri, mai chattawa, karan
  4955. $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
  4956. // sara u, sara uu, pinthu
  4957. $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
  4958. $output = array();
  4959. for ($i = 0; $i < $numchars; $i++) {
  4960. if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  4961. $ch0 = $unicode[$i];
  4962. $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
  4963. $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
  4964. $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
  4965. if (in_array($ch0, $tonemark)) {
  4966. if ($chn == 0x0e33) {
  4967. // sara um
  4968. if (in_array($ch1, $longtail)) {
  4969. // tonemark at upper left
  4970. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4971. } else {
  4972. // tonemark at upper right (normal position)
  4973. $output[] = $ch0;
  4974. }
  4975. } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
  4976. // tonemark at lower left
  4977. $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
  4978. } elseif (in_array($ch1, $upvowel)) {
  4979. if (in_array($ch2, $longtail)) {
  4980. // tonemark at upper left
  4981. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4982. } else {
  4983. // tonemark at upper right (normal position)
  4984. $output[] = $ch0;
  4985. }
  4986. } else {
  4987. // tonemark at lower right
  4988. $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
  4989. }
  4990. } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
  4991. // add lower left nikhahit and sara aa
  4992. if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  4993. $output[] = 0xf711;
  4994. $this->CurrentFont['subsetchars'][0xf711] = true;
  4995. $output[] = 0x0e32;
  4996. $this->CurrentFont['subsetchars'][0x0e32] = true;
  4997. } else {
  4998. $output[] = $ch0;
  4999. }
  5000. } elseif (in_array($ch1, $longtail)) {
  5001. if ($ch0 == 0x0e31) {
  5002. // lower left mai hun arkad
  5003. $output[] = $this->replaceChar($ch0, 0xf710);
  5004. } elseif (in_array($ch0, $upvowel)) {
  5005. // lower left
  5006. $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
  5007. } elseif ($ch0 == 0x0e47) {
  5008. // lower left mai tai koo
  5009. $output[] = $this->replaceChar($ch0, 0xf712);
  5010. } else {
  5011. // normal character
  5012. $output[] = $ch0;
  5013. }
  5014. } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
  5015. // lower vowel
  5016. $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
  5017. } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
  5018. // yo ying without lower part
  5019. $output[] = $this->replaceChar($ch0, 0xf70f);
  5020. } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
  5021. // tho santan without lower part
  5022. $output[] = $this->replaceChar($ch0, 0xf700);
  5023. } else {
  5024. $output[] = $ch0;
  5025. }
  5026. } else {
  5027. // non-thai character
  5028. $output[] = $unicode[$i];
  5029. }
  5030. }
  5031. $unicode = $output;
  5032. // update font subsetchars
  5033. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  5034. } // end of K_THAI_TOPCHARS
  5035. $txt2 = TCPDF_FONTS::arrUTF8ToUTF16BE($unicode, false);
  5036. }
  5037. }
  5038. $txt2 = TCPDF_STATIC::_escape($txt2);
  5039. // get current text width (considering general font stretching and spacing)
  5040. $txwidth = $this->GetStringWidth($txt);
  5041. $width = $txwidth;
  5042. // check for stretch mode
  5043. if ($stretch > 0) {
  5044. // calculate ratio between cell width and text width
  5045. if ($width <= 0) {
  5046. $ratio = 1;
  5047. } else {
  5048. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  5049. }
  5050. // check if stretching is required
  5051. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  5052. // the text will be stretched to fit cell width
  5053. if ($stretch > 2) {
  5054. // set new character spacing
  5055. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  5056. } else {
  5057. // set new horizontal stretching
  5058. $this->font_stretching *= $ratio;
  5059. }
  5060. // recalculate text width (the text fills the entire cell)
  5061. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5062. // reset alignment
  5063. $align = '';
  5064. }
  5065. }
  5066. if ($this->font_stretching != 100) {
  5067. // apply font stretching
  5068. $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
  5069. }
  5070. if ($this->font_spacing != 0) {
  5071. // increase/decrease font spacing
  5072. $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
  5073. }
  5074. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5075. $s .= 'q '.$this->TextColor.' ';
  5076. }
  5077. // rendering mode
  5078. $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
  5079. // count number of spaces
  5080. $ns = substr_count($txt, chr(32));
  5081. // Justification
  5082. $spacewidth = 0;
  5083. if (($align == 'J') AND ($ns > 0)) {
  5084. if ($this->isUnicodeFont()) {
  5085. // get string width without spaces
  5086. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  5087. // calculate average space width
  5088. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
  5089. if ($this->font_stretching != 100) {
  5090. // word spacing is affected by stretching
  5091. $spacewidth /= ($this->font_stretching / 100);
  5092. }
  5093. // set word position to be used with TJ operator
  5094. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
  5095. $unicode_justification = true;
  5096. } else {
  5097. // get string width
  5098. $width = $txwidth;
  5099. // new space width
  5100. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5101. if ($this->font_stretching != 100) {
  5102. // word spacing (Tw) is affected by stretching
  5103. $spacewidth /= ($this->font_stretching / 100);
  5104. }
  5105. // set word spacing
  5106. $rs .= sprintf('BT %F Tw ET ', $spacewidth);
  5107. }
  5108. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5109. }
  5110. // replace carriage return characters
  5111. $txt2 = str_replace("\r", ' ', $txt2);
  5112. switch ($align) {
  5113. case 'C': {
  5114. $dx = ($w - $width) / 2;
  5115. break;
  5116. }
  5117. case 'R': {
  5118. if ($this->rtl) {
  5119. $dx = $this->cell_padding['R'];
  5120. } else {
  5121. $dx = $w - $width - $this->cell_padding['R'];
  5122. }
  5123. break;
  5124. }
  5125. case 'L': {
  5126. if ($this->rtl) {
  5127. $dx = $w - $width - $this->cell_padding['L'];
  5128. } else {
  5129. $dx = $this->cell_padding['L'];
  5130. }
  5131. break;
  5132. }
  5133. case 'J':
  5134. default: {
  5135. if ($this->rtl) {
  5136. $dx = $this->cell_padding['R'];
  5137. } else {
  5138. $dx = $this->cell_padding['L'];
  5139. }
  5140. break;
  5141. }
  5142. }
  5143. if ($this->rtl) {
  5144. $xdx = $x - $dx - $width;
  5145. } else {
  5146. $xdx = $x + $dx;
  5147. }
  5148. $xdk = $xdx * $k;
  5149. // print text
  5150. $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  5151. if (isset($uniblock)) {
  5152. // print overlapping characters as separate string
  5153. $xshift = 0; // horizontal shift
  5154. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  5155. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5156. foreach ($uniblock as $uk => $uniarr) {
  5157. if (($uk % 2) == 0) {
  5158. // x space to skip
  5159. if ($spacewidth != 0) {
  5160. // justification shift
  5161. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  5162. }
  5163. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5164. } else {
  5165. // character to print
  5166. $topchr = TCPDF_FONTS::arrUTF8ToUTF16BE($uniarr, false);
  5167. $topchr = TCPDF_STATIC::_escape($topchr);
  5168. $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  5169. }
  5170. }
  5171. }
  5172. if ($this->underline) {
  5173. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  5174. }
  5175. if ($this->linethrough) {
  5176. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  5177. }
  5178. if ($this->overline) {
  5179. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  5180. }
  5181. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5182. $s .= ' Q';
  5183. }
  5184. if ($link) {
  5185. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  5186. }
  5187. }
  5188. // output cell
  5189. if ($s) {
  5190. // output cell
  5191. $rs .= $s;
  5192. if ($this->font_spacing != 0) {
  5193. // reset font spacing mode
  5194. $rs .= ' BT 0 Tc ET';
  5195. }
  5196. if ($this->font_stretching != 100) {
  5197. // reset font stretching mode
  5198. $rs .= ' BT 100 Tz ET';
  5199. }
  5200. }
  5201. // reset word spacing
  5202. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5203. $rs .= ' BT 0 Tw ET';
  5204. }
  5205. // reset stretching and spacing
  5206. $this->font_stretching = $prev_font_stretching;
  5207. $this->font_spacing = $prev_font_spacing;
  5208. $this->lasth = $h;
  5209. if ($ln > 0) {
  5210. //Go to the beginning of the next line
  5211. $this->y = $y + $h + $this->cell_margin['B'];
  5212. if ($ln == 1) {
  5213. if ($this->rtl) {
  5214. $this->x = $this->w - $this->rMargin;
  5215. } else {
  5216. $this->x = $this->lMargin;
  5217. }
  5218. }
  5219. } else {
  5220. // go left or right by case
  5221. if ($this->rtl) {
  5222. $this->x = $x - $w - $this->cell_margin['L'];
  5223. } else {
  5224. $this->x = $x + $w + $this->cell_margin['R'];
  5225. }
  5226. }
  5227. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5228. $rs = $gstyles.$rs;
  5229. $this->cell_padding = $prev_cell_padding;
  5230. $this->cell_margin = $prev_cell_margin;
  5231. return $rs;
  5232. }
  5233. /**
  5234. * Replace a char if is defined on the current font.
  5235. * @param int $oldchar Integer code (unicode) of the character to replace.
  5236. * @param int $newchar Integer code (unicode) of the new character.
  5237. * @return int the replaced char or the old char in case the new char i not defined
  5238. * @protected
  5239. * @since 5.9.167 (2012-06-22)
  5240. */
  5241. protected function replaceChar($oldchar, $newchar) {
  5242. if ($this->isCharDefined($newchar)) {
  5243. // add the new char on the subset list
  5244. $this->CurrentFont['subsetchars'][$newchar] = true;
  5245. // return the new character
  5246. return $newchar;
  5247. }
  5248. // return the old char
  5249. return $oldchar;
  5250. }
  5251. /**
  5252. * Returns the code to draw the cell border
  5253. * @param float $x X coordinate.
  5254. * @param float $y Y coordinate.
  5255. * @param float $w Cell width.
  5256. * @param float $h Cell height.
  5257. * @param string|array|int $brd 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)))
  5258. * @return string containing cell border code
  5259. * @protected
  5260. * @see SetLineStyle()
  5261. * @since 5.7.000 (2010-08-02)
  5262. */
  5263. protected function getCellBorder($x, $y, $w, $h, $brd) {
  5264. $s = ''; // string to be returned
  5265. if (empty($brd)) {
  5266. return $s;
  5267. }
  5268. if ($brd == 1) {
  5269. $brd = array('LRTB' => true);
  5270. }
  5271. // calculate coordinates for border
  5272. $k = $this->k;
  5273. if ($this->rtl) {
  5274. $xeL = ($x - $w) * $k;
  5275. $xeR = $x * $k;
  5276. } else {
  5277. $xeL = $x * $k;
  5278. $xeR = ($x + $w) * $k;
  5279. }
  5280. $yeL = (($this->h - ($y + $h)) * $k);
  5281. $yeT = (($this->h - $y) * $k);
  5282. $xeT = $xeL;
  5283. $xeB = $xeR;
  5284. $yeR = $yeT;
  5285. $yeB = $yeL;
  5286. if (is_string($brd)) {
  5287. // convert string to array
  5288. $slen = strlen($brd);
  5289. $newbrd = array();
  5290. for ($i = 0; $i < $slen; ++$i) {
  5291. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  5292. }
  5293. $brd = $newbrd;
  5294. }
  5295. if (isset($brd['mode'])) {
  5296. $mode = $brd['mode'];
  5297. unset($brd['mode']);
  5298. } else {
  5299. $mode = 'normal';
  5300. }
  5301. foreach ($brd as $border => $style) {
  5302. if (is_array($style) AND !empty($style)) {
  5303. // apply border style
  5304. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5305. $s .= $this->setLineStyle($style, true)."\n";
  5306. }
  5307. switch ($mode) {
  5308. case 'ext': {
  5309. $off = (($this->LineWidth / 2) * $k);
  5310. $xL = $xeL - $off;
  5311. $xR = $xeR + $off;
  5312. $yT = $yeT + $off;
  5313. $yL = $yeL - $off;
  5314. $xT = $xL;
  5315. $xB = $xR;
  5316. $yR = $yT;
  5317. $yB = $yL;
  5318. $w += $this->LineWidth;
  5319. $h += $this->LineWidth;
  5320. break;
  5321. }
  5322. case 'int': {
  5323. $off = ($this->LineWidth / 2) * $k;
  5324. $xL = $xeL + $off;
  5325. $xR = $xeR - $off;
  5326. $yT = $yeT - $off;
  5327. $yL = $yeL + $off;
  5328. $xT = $xL;
  5329. $xB = $xR;
  5330. $yR = $yT;
  5331. $yB = $yL;
  5332. $w -= $this->LineWidth;
  5333. $h -= $this->LineWidth;
  5334. break;
  5335. }
  5336. case 'normal':
  5337. default: {
  5338. $xL = $xeL;
  5339. $xT = $xeT;
  5340. $xB = $xeB;
  5341. $xR = $xeR;
  5342. $yL = $yeL;
  5343. $yT = $yeT;
  5344. $yB = $yeB;
  5345. $yR = $yeR;
  5346. break;
  5347. }
  5348. }
  5349. // draw borders by case
  5350. if (strlen($border) == 4) {
  5351. $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  5352. } elseif (strlen($border) == 3) {
  5353. if (strpos($border,'B') === false) { // LTR
  5354. $s .= sprintf('%F %F m ', $xL, $yL);
  5355. $s .= sprintf('%F %F l ', $xT, $yT);
  5356. $s .= sprintf('%F %F l ', $xR, $yR);
  5357. $s .= sprintf('%F %F l ', $xB, $yB);
  5358. $s .= 'S ';
  5359. } elseif (strpos($border,'L') === false) { // TRB
  5360. $s .= sprintf('%F %F m ', $xT, $yT);
  5361. $s .= sprintf('%F %F l ', $xR, $yR);
  5362. $s .= sprintf('%F %F l ', $xB, $yB);
  5363. $s .= sprintf('%F %F l ', $xL, $yL);
  5364. $s .= 'S ';
  5365. } elseif (strpos($border,'T') === false) { // RBL
  5366. $s .= sprintf('%F %F m ', $xR, $yR);
  5367. $s .= sprintf('%F %F l ', $xB, $yB);
  5368. $s .= sprintf('%F %F l ', $xL, $yL);
  5369. $s .= sprintf('%F %F l ', $xT, $yT);
  5370. $s .= 'S ';
  5371. } elseif (strpos($border,'R') === false) { // BLT
  5372. $s .= sprintf('%F %F m ', $xB, $yB);
  5373. $s .= sprintf('%F %F l ', $xL, $yL);
  5374. $s .= sprintf('%F %F l ', $xT, $yT);
  5375. $s .= sprintf('%F %F l ', $xR, $yR);
  5376. $s .= 'S ';
  5377. }
  5378. } elseif (strlen($border) == 2) {
  5379. if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  5380. $s .= sprintf('%F %F m ', $xL, $yL);
  5381. $s .= sprintf('%F %F l ', $xT, $yT);
  5382. $s .= sprintf('%F %F l ', $xR, $yR);
  5383. $s .= 'S ';
  5384. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  5385. $s .= sprintf('%F %F m ', $xT, $yT);
  5386. $s .= sprintf('%F %F l ', $xR, $yR);
  5387. $s .= sprintf('%F %F l ', $xB, $yB);
  5388. $s .= 'S ';
  5389. } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  5390. $s .= sprintf('%F %F m ', $xR, $yR);
  5391. $s .= sprintf('%F %F l ', $xB, $yB);
  5392. $s .= sprintf('%F %F l ', $xL, $yL);
  5393. $s .= 'S ';
  5394. } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  5395. $s .= sprintf('%F %F m ', $xB, $yB);
  5396. $s .= sprintf('%F %F l ', $xL, $yL);
  5397. $s .= sprintf('%F %F l ', $xT, $yT);
  5398. $s .= 'S ';
  5399. } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  5400. $s .= sprintf('%F %F m ', $xL, $yL);
  5401. $s .= sprintf('%F %F l ', $xT, $yT);
  5402. $s .= 'S ';
  5403. $s .= sprintf('%F %F m ', $xR, $yR);
  5404. $s .= sprintf('%F %F l ', $xB, $yB);
  5405. $s .= 'S ';
  5406. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  5407. $s .= sprintf('%F %F m ', $xT, $yT);
  5408. $s .= sprintf('%F %F l ', $xR, $yR);
  5409. $s .= 'S ';
  5410. $s .= sprintf('%F %F m ', $xB, $yB);
  5411. $s .= sprintf('%F %F l ', $xL, $yL);
  5412. $s .= 'S ';
  5413. }
  5414. } else { // strlen($border) == 1
  5415. if (strpos($border,'L') !== false) { // L
  5416. $s .= sprintf('%F %F m ', $xL, $yL);
  5417. $s .= sprintf('%F %F l ', $xT, $yT);
  5418. $s .= 'S ';
  5419. } elseif (strpos($border,'T') !== false) { // T
  5420. $s .= sprintf('%F %F m ', $xT, $yT);
  5421. $s .= sprintf('%F %F l ', $xR, $yR);
  5422. $s .= 'S ';
  5423. } elseif (strpos($border,'R') !== false) { // R
  5424. $s .= sprintf('%F %F m ', $xR, $yR);
  5425. $s .= sprintf('%F %F l ', $xB, $yB);
  5426. $s .= 'S ';
  5427. } elseif (strpos($border,'B') !== false) { // B
  5428. $s .= sprintf('%F %F m ', $xB, $yB);
  5429. $s .= sprintf('%F %F l ', $xL, $yL);
  5430. $s .= 'S ';
  5431. }
  5432. }
  5433. if (is_array($style) AND !empty($style)) {
  5434. // reset border style to previous value
  5435. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5436. }
  5437. }
  5438. return $s;
  5439. }
  5440. /**
  5441. * This method allows printing text with line breaks.
  5442. * 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 />
  5443. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5444. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5445. * @param float $h Cell minimum height. The cell extends automatically if needed.
  5446. * @param string $txt String to print
  5447. * @param mixed $border 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)))
  5448. * @param string $align 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>
  5449. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  5450. * @param int $ln 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>
  5451. * @param float|null $x x position in user units
  5452. * @param float|null $y y position in user units
  5453. * @param boolean $reseth if true reset the last cell height (default true).
  5454. * @param int $stretch 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.
  5455. * @param boolean $ishtml 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.
  5456. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  5457. * @param float $maxh 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.
  5458. * @param string $valign 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.
  5459. * @param boolean $fitcell 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.
  5460. * @return int Return the number of cells or 1 for html mode.
  5461. * @public
  5462. * @since 1.3
  5463. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5464. */
  5465. public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x=null, $y=null, $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false) {
  5466. $prev_cell_margin = $this->cell_margin;
  5467. $prev_cell_padding = $this->cell_padding;
  5468. // adjust internal padding
  5469. $this->adjustCellPadding($border);
  5470. $mc_padding = $this->cell_padding;
  5471. $mc_margin = $this->cell_margin;
  5472. $this->cell_padding['T'] = 0;
  5473. $this->cell_padding['B'] = 0;
  5474. $this->setCellMargins(0, 0, 0, 0);
  5475. if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) {
  5476. // reset row height
  5477. $this->resetLastH();
  5478. }
  5479. if (!TCPDF_STATIC::empty_string($y)) {
  5480. $this->setY($y); // set y in order to convert negative y values to positive ones
  5481. }
  5482. $y = $this->GetY();
  5483. $resth = 0;
  5484. if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5485. // spit cell in more pages/columns
  5486. $newh = ($this->PageBreakTrigger - $y);
  5487. $resth = ($h - $newh); // cell to be printed on the next page/column
  5488. $h = $newh;
  5489. }
  5490. // get current page number
  5491. $startpage = $this->page;
  5492. // get current column
  5493. $startcolumn = $this->current_column;
  5494. if (!TCPDF_STATIC::empty_string($x)) {
  5495. $this->setX($x);
  5496. } else {
  5497. $x = $this->GetX();
  5498. }
  5499. // check page for no-write regions and adapt page margins if necessary
  5500. list($x, $y) = $this->checkPageRegions(0, $x, $y);
  5501. // apply margins
  5502. $oy = $y + $mc_margin['T'];
  5503. if ($this->rtl) {
  5504. $ox = ($this->w - $x - $mc_margin['R']);
  5505. } else {
  5506. $ox = ($x + $mc_margin['L']);
  5507. }
  5508. $this->x = $ox;
  5509. $this->y = $oy;
  5510. // set width
  5511. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5512. if ($this->rtl) {
  5513. $w = ($this->x - $this->lMargin - $mc_margin['L']);
  5514. } else {
  5515. $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
  5516. }
  5517. }
  5518. // store original margin values
  5519. $lMargin = $this->lMargin;
  5520. $rMargin = $this->rMargin;
  5521. if ($this->rtl) {
  5522. $this->rMargin = ($this->w - $this->x);
  5523. $this->lMargin = ($this->x - $w);
  5524. } else {
  5525. $this->lMargin = ($this->x);
  5526. $this->rMargin = ($this->w - $this->x - $w);
  5527. }
  5528. $this->clMargin = $this->lMargin;
  5529. $this->crMargin = $this->rMargin;
  5530. if ($autopadding) {
  5531. // add top padding
  5532. $this->y += $mc_padding['T'];
  5533. }
  5534. if ($ishtml) { // ******* Write HTML text
  5535. $this->writeHTML($txt, true, false, $reseth, true, $align);
  5536. $nl = 1;
  5537. } else { // ******* Write simple text
  5538. $prev_FontSizePt = $this->FontSizePt;
  5539. if ($fitcell) {
  5540. // ajust height values
  5541. $tobottom = ($this->h - $this->y - $this->bMargin - $this->cell_padding['T'] - $this->cell_padding['B']);
  5542. $h = $maxh = max(min($h, $tobottom), min($maxh, $tobottom));
  5543. }
  5544. // vertical alignment
  5545. if ($maxh > 0) {
  5546. // get text height
  5547. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5548. if ($fitcell AND ($text_height > $maxh) AND ($this->FontSizePt > 1)) {
  5549. // try to reduce font size to fit text on cell (use a quick search algorithm)
  5550. $fmin = 1;
  5551. $fmax = $this->FontSizePt;
  5552. $diff_epsilon = (1 / $this->k); // one point (min resolution)
  5553. $maxit = (2 * min(100, max(10, intval($fmax)))); // max number of iterations
  5554. while ($maxit >= 0) {
  5555. $fmid = (($fmax + $fmin) / 2);
  5556. $this->setFontSize($fmid, false);
  5557. $this->resetLastH();
  5558. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5559. $diff = ($maxh - $text_height);
  5560. if ($diff >= 0) {
  5561. if ($diff <= $diff_epsilon) {
  5562. break;
  5563. }
  5564. $fmin = $fmid;
  5565. } else {
  5566. $fmax = $fmid;
  5567. }
  5568. --$maxit;
  5569. }
  5570. if ($maxit < 0) {
  5571. // premature exit, we get the minimum font value to fit the cell
  5572. $this->setFontSize($fmin);
  5573. $this->resetLastH();
  5574. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5575. } else {
  5576. $this->setFontSize($fmid);
  5577. $this->resetLastH();
  5578. }
  5579. }
  5580. if ($text_height < $maxh) {
  5581. if ($valign == 'M') {
  5582. // text vertically centered
  5583. $this->y += (($maxh - $text_height) / 2);
  5584. } elseif ($valign == 'B') {
  5585. // text vertically aligned on bottom
  5586. $this->y += ($maxh - $text_height);
  5587. }
  5588. }
  5589. }
  5590. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  5591. if ($fitcell) {
  5592. // restore font size
  5593. $this->setFontSize($prev_FontSizePt);
  5594. }
  5595. }
  5596. if ($autopadding) {
  5597. // add bottom padding
  5598. $this->y += $mc_padding['B'];
  5599. }
  5600. // Get end-of-text Y position
  5601. $currentY = $this->y;
  5602. // get latest page number
  5603. $endpage = $this->page;
  5604. if ($resth > 0) {
  5605. $skip = ($endpage - $startpage);
  5606. $tmpresth = $resth;
  5607. while ($tmpresth > 0) {
  5608. if ($skip <= 0) {
  5609. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5610. $this->checkPageBreak($this->PageBreakTrigger + 1);
  5611. }
  5612. if ($this->num_columns > 1) {
  5613. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  5614. } else {
  5615. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  5616. }
  5617. --$skip;
  5618. }
  5619. $currentY = $this->y;
  5620. $endpage = $this->page;
  5621. }
  5622. // get latest column
  5623. $endcolumn = $this->current_column;
  5624. if ($this->num_columns == 0) {
  5625. $this->num_columns = 1;
  5626. }
  5627. // disable page regions check
  5628. $check_page_regions = $this->check_page_regions;
  5629. $this->check_page_regions = false;
  5630. // get border modes
  5631. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  5632. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  5633. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  5634. // design borders around HTML cells.
  5635. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  5636. $ccode = '';
  5637. $this->setPage($page);
  5638. if ($this->num_columns < 2) {
  5639. // single-column mode
  5640. $this->setX($x);
  5641. $this->y = $this->tMargin;
  5642. }
  5643. // account for margin changes
  5644. if ($page > $startpage) {
  5645. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5646. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5647. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5648. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5649. }
  5650. }
  5651. if ($startpage == $endpage) {
  5652. // single page
  5653. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  5654. if ($column != $this->current_column) {
  5655. $this->selectColumn($column);
  5656. }
  5657. if ($this->rtl) {
  5658. $this->x -= $mc_margin['R'];
  5659. } else {
  5660. $this->x += $mc_margin['L'];
  5661. }
  5662. if ($startcolumn == $endcolumn) { // single column
  5663. $cborder = $border;
  5664. $h = max($h, ($currentY - $oy));
  5665. $this->y = $oy;
  5666. } elseif ($column == $startcolumn) { // first column
  5667. $cborder = $border_start;
  5668. $this->y = $oy;
  5669. $h = $this->h - $this->y - $this->bMargin;
  5670. } elseif ($column == $endcolumn) { // end column
  5671. $cborder = $border_end;
  5672. $h = $currentY - $this->y;
  5673. if ($resth > $h) {
  5674. $h = $resth;
  5675. }
  5676. } else { // middle column
  5677. $cborder = $border_middle;
  5678. $h = $this->h - $this->y - $this->bMargin;
  5679. $resth -= $h;
  5680. }
  5681. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5682. } // end for each column
  5683. } elseif ($page == $startpage) { // first page
  5684. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  5685. if ($column != $this->current_column) {
  5686. $this->selectColumn($column);
  5687. }
  5688. if ($this->rtl) {
  5689. $this->x -= $mc_margin['R'];
  5690. } else {
  5691. $this->x += $mc_margin['L'];
  5692. }
  5693. if ($column == $startcolumn) { // first column
  5694. $cborder = $border_start;
  5695. $this->y = $oy;
  5696. $h = $this->h - $this->y - $this->bMargin;
  5697. } else { // middle column
  5698. $cborder = $border_middle;
  5699. $h = $this->h - $this->y - $this->bMargin;
  5700. $resth -= $h;
  5701. }
  5702. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5703. } // end for each column
  5704. } elseif ($page == $endpage) { // last page
  5705. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  5706. if ($column != $this->current_column) {
  5707. $this->selectColumn($column);
  5708. }
  5709. if ($this->rtl) {
  5710. $this->x -= $mc_margin['R'];
  5711. } else {
  5712. $this->x += $mc_margin['L'];
  5713. }
  5714. if ($column == $endcolumn) {
  5715. // end column
  5716. $cborder = $border_end;
  5717. $h = $currentY - $this->y;
  5718. if ($resth > $h) {
  5719. $h = $resth;
  5720. }
  5721. } else {
  5722. // middle column
  5723. $cborder = $border_middle;
  5724. $h = $this->h - $this->y - $this->bMargin;
  5725. $resth -= $h;
  5726. }
  5727. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5728. } // end for each column
  5729. } else { // middle page
  5730. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  5731. $this->selectColumn($column);
  5732. if ($this->rtl) {
  5733. $this->x -= $mc_margin['R'];
  5734. } else {
  5735. $this->x += $mc_margin['L'];
  5736. }
  5737. $cborder = $border_middle;
  5738. $h = $this->h - $this->y - $this->bMargin;
  5739. $resth -= $h;
  5740. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5741. } // end for each column
  5742. }
  5743. if ($cborder OR $fill) {
  5744. $offsetlen = strlen($ccode);
  5745. // draw border and fill
  5746. if ($this->inxobj) {
  5747. // we are inside an XObject template
  5748. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5749. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  5750. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5751. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  5752. } else {
  5753. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  5754. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  5755. }
  5756. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  5757. $pstart = substr($pagebuff, 0, $pagemark);
  5758. $pend = substr($pagebuff, $pagemark);
  5759. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5760. } else {
  5761. if (end($this->transfmrk[$this->page]) !== false) {
  5762. $pagemarkkey = key($this->transfmrk[$this->page]);
  5763. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  5764. $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  5765. } elseif ($this->InFooter) {
  5766. $pagemark = $this->footerpos[$this->page];
  5767. $this->footerpos[$this->page] += $offsetlen;
  5768. } else {
  5769. $pagemark = $this->intmrk[$this->page];
  5770. $this->intmrk[$this->page] += $offsetlen;
  5771. }
  5772. $pagebuff = $this->getPageBuffer($this->page);
  5773. $pstart = substr($pagebuff, 0, $pagemark);
  5774. $pend = substr($pagebuff, $pagemark);
  5775. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  5776. }
  5777. }
  5778. } // end for each page
  5779. // restore page regions check
  5780. $this->check_page_regions = $check_page_regions;
  5781. // Get end-of-cell Y position
  5782. $currentY = $this->GetY();
  5783. // restore previous values
  5784. if ($this->num_columns > 1) {
  5785. $this->selectColumn();
  5786. } else {
  5787. // restore original margins
  5788. $this->lMargin = $lMargin;
  5789. $this->rMargin = $rMargin;
  5790. if ($this->page > $startpage) {
  5791. // check for margin variations between pages (i.e. booklet mode)
  5792. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  5793. $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  5794. if (($dl != 0) OR ($dr != 0)) {
  5795. $this->lMargin += $dl;
  5796. $this->rMargin += $dr;
  5797. }
  5798. }
  5799. }
  5800. if ($ln > 0) {
  5801. //Go to the beginning of the next line
  5802. $this->setY($currentY + $mc_margin['B']);
  5803. if ($ln == 2) {
  5804. $this->setX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5805. }
  5806. } else {
  5807. // go left or right by case
  5808. $this->setPage($startpage);
  5809. $this->y = $y;
  5810. $this->setX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5811. }
  5812. $this->setContentMark();
  5813. $this->cell_padding = $prev_cell_padding;
  5814. $this->cell_margin = $prev_cell_margin;
  5815. $this->clMargin = $this->lMargin;
  5816. $this->crMargin = $this->rMargin;
  5817. return $nl;
  5818. }
  5819. /**
  5820. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  5821. * @param string $txt String for calculating his height
  5822. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5823. * @param boolean $reseth if true reset the last cell height (default false).
  5824. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  5825. * @param array|null $cellpadding Internal cell padding, if empty uses default cell padding.
  5826. * @param mixed $border 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)))
  5827. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5828. * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
  5829. * @public
  5830. * @since 4.5.011
  5831. */
  5832. public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding=null, $border=0) {
  5833. if ($txt === NULL) {
  5834. return 0;
  5835. }
  5836. if ($txt === '') {
  5837. // empty string
  5838. return 1;
  5839. }
  5840. // adjust internal padding
  5841. $prev_cell_padding = $this->cell_padding;
  5842. $prev_lasth = $this->lasth;
  5843. if (is_array($cellpadding)) {
  5844. $this->cell_padding = $cellpadding;
  5845. }
  5846. $this->adjustCellPadding($border);
  5847. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5848. if ($this->rtl) {
  5849. $w = $this->x - $this->lMargin;
  5850. } else {
  5851. $w = $this->w - $this->rMargin - $this->x;
  5852. }
  5853. }
  5854. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5855. if ($reseth) {
  5856. // reset row height
  5857. $this->resetLastH();
  5858. }
  5859. $lines = 1;
  5860. $sum = 0;
  5861. $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5862. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  5863. $length = count($chars);
  5864. $lastSeparator = -1;
  5865. for ($i = 0; $i < $length; ++$i) {
  5866. $c = $chars[$i];
  5867. $charWidth = $charsWidth[$i];
  5868. if (($c != 160)
  5869. AND (($c == 173)
  5870. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  5871. OR (($c == 45)
  5872. AND ($i > 0) AND ($i < ($length - 1))
  5873. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i - 1)], $this->isunicode))
  5874. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  5875. )
  5876. )
  5877. ) {
  5878. $lastSeparator = $i;
  5879. }
  5880. if ((($sum + $charWidth) > $wmax) OR ($c == 10)) {
  5881. ++$lines;
  5882. if ($c == 10) {
  5883. $lastSeparator = -1;
  5884. $sum = 0;
  5885. } elseif ($lastSeparator != -1) {
  5886. $i = $lastSeparator;
  5887. $lastSeparator = -1;
  5888. $sum = 0;
  5889. } else {
  5890. $sum = $charWidth;
  5891. }
  5892. } else {
  5893. $sum += $charWidth;
  5894. }
  5895. }
  5896. if ($chars[($length - 1)] == 10) {
  5897. --$lines;
  5898. }
  5899. $this->cell_padding = $prev_cell_padding;
  5900. $this->lasth = $prev_lasth;
  5901. return $lines;
  5902. }
  5903. /**
  5904. * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  5905. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  5906. * @pre
  5907. * // store current object
  5908. * $pdf->startTransaction();
  5909. * // store starting values
  5910. * $start_y = $pdf->GetY();
  5911. * $start_page = $pdf->getPage();
  5912. * // call your printing functions with your parameters
  5913. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5914. * $pdf->MultiCell($w=0, $h=0, $txt, $border=1, $align='L', $fill=false, $ln=1, $x=null, $y=null, $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
  5915. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5916. * // get the new Y
  5917. * $end_y = $pdf->GetY();
  5918. * $end_page = $pdf->getPage();
  5919. * // calculate height
  5920. * $height = 0;
  5921. * if ($end_page == $start_page) {
  5922. * $height = $end_y - $start_y;
  5923. * } else {
  5924. * for ($page=$start_page; $page <= $end_page; ++$page) {
  5925. * $this->setPage($page);
  5926. * if ($page == $start_page) {
  5927. * // first page
  5928. * $height += $this->h - $start_y - $this->bMargin;
  5929. * } elseif ($page == $end_page) {
  5930. * // last page
  5931. * $height += $end_y - $this->tMargin;
  5932. * } else {
  5933. * $height += $this->h - $this->tMargin - $this->bMargin;
  5934. * }
  5935. * }
  5936. * }
  5937. * // restore previous object
  5938. * $pdf = $pdf->rollbackTransaction();
  5939. *
  5940. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5941. * @param string $txt String for calculating his height
  5942. * @param boolean $reseth if true reset the last cell height (default false).
  5943. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  5944. * @param array|null $cellpadding Internal cell padding, if empty uses default cell padding.
  5945. * @param mixed $border 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)))
  5946. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5947. * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
  5948. * @public
  5949. */
  5950. public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding=null, $border=0) {
  5951. // adjust internal padding
  5952. $prev_cell_padding = $this->cell_padding;
  5953. $prev_lasth = $this->lasth;
  5954. if (is_array($cellpadding)) {
  5955. $this->cell_padding = $cellpadding;
  5956. }
  5957. $this->adjustCellPadding($border);
  5958. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  5959. $height = $this->getCellHeight(($lines * $this->FontSize), $autopadding);
  5960. $this->cell_padding = $prev_cell_padding;
  5961. $this->lasth = $prev_lasth;
  5962. return $height;
  5963. }
  5964. /**
  5965. * This method prints text from the current position.<br />
  5966. * @param float $h Line height
  5967. * @param string $txt String to print
  5968. * @param mixed $link URL or identifier returned by AddLink()
  5969. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  5970. * @param string $align 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>
  5971. * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  5972. * @param int $stretch 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.
  5973. * @param boolean $firstline if true prints only the first line and return the remaining string.
  5974. * @param boolean $firstblock if true the string is the starting of a line.
  5975. * @param float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
  5976. * @param float $wadj first line width will be reduced by this amount (used in HTML mode).
  5977. * @param array|null $margin margin array of the parent container
  5978. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  5979. * @public
  5980. * @since 1.5
  5981. */
  5982. public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin=null) {
  5983. // check page for no-write regions and adapt page margins if necessary
  5984. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  5985. if (strlen($txt) == 0) {
  5986. // fix empty text
  5987. $txt = ' ';
  5988. }
  5989. if (!is_array($margin)) {
  5990. // set default margins
  5991. $margin = $this->cell_margin;
  5992. }
  5993. // remove carriage returns
  5994. $s = str_replace("\r", '', $txt);
  5995. // check if string contains arabic text
  5996. if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $s)) {
  5997. $arabic = true;
  5998. } else {
  5999. $arabic = false;
  6000. }
  6001. // check if string contains RTL text
  6002. if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $s)) {
  6003. $rtlmode = true;
  6004. } else {
  6005. $rtlmode = false;
  6006. }
  6007. // get a char width
  6008. $chrwidth = $this->GetCharWidth(46); // dot character
  6009. // get array of unicode values
  6010. $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont);
  6011. // calculate maximum width for a single character on string
  6012. $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
  6013. array_walk($chrw, array($this, 'getRawCharWidth'));
  6014. $maxchwidth = max($chrw);
  6015. // get array of chars
  6016. $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode);
  6017. // get the number of characters
  6018. $nb = count($chars);
  6019. // replacement for SHY character (minus symbol)
  6020. $shy_replacement = 45;
  6021. $shy_replacement_char = TCPDF_FONTS::unichr($shy_replacement, $this->isunicode);
  6022. // widht for SHY replacement
  6023. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  6024. // page width
  6025. $pw = $w = $this->w - $this->lMargin - $this->rMargin;
  6026. // calculate remaining line width ($w)
  6027. if ($this->rtl) {
  6028. $w = $this->x - $this->lMargin;
  6029. } else {
  6030. $w = $this->w - $this->rMargin - $this->x;
  6031. }
  6032. // max column width
  6033. $wmax = ($w - $wadj);
  6034. if (!$firstline) {
  6035. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  6036. }
  6037. if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
  6038. // the maximum width character do not fit on column
  6039. return '';
  6040. }
  6041. // minimum row height
  6042. $row_height = max($h, $this->getCellHeight($this->FontSize));
  6043. // max Y
  6044. $maxy = $this->y + $maxh - max($row_height, $h);
  6045. $start_page = $this->page;
  6046. $i = 0; // character position
  6047. $j = 0; // current starting position
  6048. $sep = -1; // position of the last blank space
  6049. $prevsep = $sep; // previous separator
  6050. $shy = false; // true if the last blank is a soft hypen (SHY)
  6051. $prevshy = $shy; // previous shy mode
  6052. $l = 0; // current string length
  6053. $nl = 0; //number of lines
  6054. $linebreak = false;
  6055. $pc = 0; // previous character
  6056. // for each character
  6057. while ($i < $nb) {
  6058. if (($maxh > 0) AND ($this->y > $maxy) ) {
  6059. break;
  6060. }
  6061. //Get the current character
  6062. $c = $chars[$i];
  6063. if ($c == 10) { // 10 = "\n" = new line
  6064. //Explicit line break
  6065. if ($align == 'J') {
  6066. if ($this->rtl) {
  6067. $talign = 'R';
  6068. } else {
  6069. $talign = 'L';
  6070. }
  6071. } else {
  6072. $talign = $align;
  6073. }
  6074. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6075. if ($firstline) {
  6076. $startx = $this->x;
  6077. $tmparr = array_slice($chars, $j, ($i - $j));
  6078. if ($rtlmode) {
  6079. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6080. }
  6081. $linew = $this->GetArrStringWidth($tmparr);
  6082. unset($tmparr);
  6083. if ($this->rtl) {
  6084. $this->endlinex = $startx - $linew;
  6085. } else {
  6086. $this->endlinex = $startx + $linew;
  6087. }
  6088. $w = $linew;
  6089. $tmpcellpadding = $this->cell_padding;
  6090. if ($maxh == 0) {
  6091. $this->setCellPadding(0);
  6092. }
  6093. }
  6094. if ($firstblock AND $this->isRTLTextDir()) {
  6095. $tmpstr = $this->stringRightTrim($tmpstr);
  6096. }
  6097. // Skip newlines at the beginning of a page or column
  6098. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  6099. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  6100. }
  6101. unset($tmpstr);
  6102. if ($firstline) {
  6103. $this->cell_padding = $tmpcellpadding;
  6104. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6105. }
  6106. ++$nl;
  6107. $j = $i + 1;
  6108. $l = 0;
  6109. $sep = -1;
  6110. $prevsep = $sep;
  6111. $shy = false;
  6112. // account for margin changes
  6113. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6114. $this->AcceptPageBreak();
  6115. if ($this->rtl) {
  6116. $this->x -= $margin['R'];
  6117. } else {
  6118. $this->x += $margin['L'];
  6119. }
  6120. $this->lMargin += $margin['L'];
  6121. $this->rMargin += $margin['R'];
  6122. }
  6123. $w = $this->getRemainingWidth();
  6124. $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
  6125. } else {
  6126. // 160 is the non-breaking space.
  6127. // 173 is SHY (Soft Hypen).
  6128. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6129. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6130. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6131. if (($c != 160)
  6132. AND (($c == 173)
  6133. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  6134. OR (($c == 45)
  6135. AND ($i < ($nb - 1))
  6136. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc, $this->isunicode))
  6137. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  6138. )
  6139. )
  6140. ) {
  6141. // update last blank space position
  6142. $prevsep = $sep;
  6143. $sep = $i;
  6144. // check if is a SHY
  6145. if (($c == 173) OR ($c == 45)) {
  6146. $prevshy = $shy;
  6147. $shy = true;
  6148. if ($pc == 45) {
  6149. $tmp_shy_replacement_width = 0;
  6150. $tmp_shy_replacement_char = '';
  6151. } else {
  6152. $tmp_shy_replacement_width = $shy_replacement_width;
  6153. $tmp_shy_replacement_char = $shy_replacement_char;
  6154. }
  6155. } else {
  6156. $shy = false;
  6157. }
  6158. }
  6159. // update string length
  6160. if ($this->isUnicodeFont() AND ($arabic)) {
  6161. // with bidirectional algorithm some chars may be changed affecting the line length
  6162. // *** very slow ***
  6163. $l = $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl, $this->isunicode, $this->CurrentFont));
  6164. } else {
  6165. $l += $this->GetCharWidth($c, ($i+1 < $nb));
  6166. }
  6167. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) >= $wmax))) {
  6168. if (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) {
  6169. $sep = $prevsep;
  6170. $shy = $prevshy;
  6171. }
  6172. // we have reached the end of column
  6173. if ($sep == -1) {
  6174. // check if the line was already started
  6175. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  6176. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  6177. // print a void cell and go to next line
  6178. $this->Cell($w, $h, '', 0, 1);
  6179. $linebreak = true;
  6180. if ($firstline) {
  6181. return (TCPDF_FONTS::UniArrSubString($uchars, $j));
  6182. }
  6183. } else {
  6184. // truncate the word because do not fit on column
  6185. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6186. if ($firstline) {
  6187. $startx = $this->x;
  6188. $tmparr = array_slice($chars, $j, ($i - $j));
  6189. if ($rtlmode) {
  6190. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6191. }
  6192. $linew = $this->GetArrStringWidth($tmparr);
  6193. unset($tmparr);
  6194. if ($this->rtl) {
  6195. $this->endlinex = $startx - $linew;
  6196. } else {
  6197. $this->endlinex = $startx + $linew;
  6198. }
  6199. $w = $linew;
  6200. $tmpcellpadding = $this->cell_padding;
  6201. if ($maxh == 0) {
  6202. $this->setCellPadding(0);
  6203. }
  6204. }
  6205. if ($firstblock AND $this->isRTLTextDir()) {
  6206. $tmpstr = $this->stringRightTrim($tmpstr);
  6207. }
  6208. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6209. unset($tmpstr);
  6210. if ($firstline) {
  6211. $this->cell_padding = $tmpcellpadding;
  6212. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6213. }
  6214. $j = $i;
  6215. --$i;
  6216. }
  6217. } else {
  6218. // word wrapping
  6219. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  6220. $endspace = 1;
  6221. } else {
  6222. $endspace = 0;
  6223. }
  6224. // check the length of the next string
  6225. $strrest = TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace));
  6226. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $this->stringTrim($strrest));
  6227. if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  6228. // truncate the word because do not fit on a full page width
  6229. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6230. if ($firstline) {
  6231. $startx = $this->x;
  6232. $tmparr = array_slice($chars, $j, ($i - $j));
  6233. if ($rtlmode) {
  6234. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6235. }
  6236. $linew = $this->GetArrStringWidth($tmparr);
  6237. unset($tmparr);
  6238. if ($this->rtl) {
  6239. $this->endlinex = ($startx - $linew);
  6240. } else {
  6241. $this->endlinex = ($startx + $linew);
  6242. }
  6243. $w = $linew;
  6244. $tmpcellpadding = $this->cell_padding;
  6245. if ($maxh == 0) {
  6246. $this->setCellPadding(0);
  6247. }
  6248. }
  6249. if ($firstblock AND $this->isRTLTextDir()) {
  6250. $tmpstr = $this->stringRightTrim($tmpstr);
  6251. }
  6252. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6253. unset($tmpstr);
  6254. if ($firstline) {
  6255. $this->cell_padding = $tmpcellpadding;
  6256. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6257. }
  6258. $j = $i;
  6259. --$i;
  6260. } else {
  6261. // word wrapping
  6262. if ($shy) {
  6263. // add hypen (minus symbol) at the end of the line
  6264. $shy_width = $tmp_shy_replacement_width;
  6265. if ($this->rtl) {
  6266. $shy_char_left = $tmp_shy_replacement_char;
  6267. $shy_char_right = '';
  6268. } else {
  6269. $shy_char_left = '';
  6270. $shy_char_right = $tmp_shy_replacement_char;
  6271. }
  6272. } else {
  6273. $shy_width = 0;
  6274. $shy_char_left = '';
  6275. $shy_char_right = '';
  6276. }
  6277. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, ($sep + $endspace));
  6278. if ($firstline) {
  6279. $startx = $this->x;
  6280. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  6281. if ($rtlmode) {
  6282. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6283. }
  6284. $linew = $this->GetArrStringWidth($tmparr);
  6285. unset($tmparr);
  6286. if ($this->rtl) {
  6287. $this->endlinex = $startx - $linew - $shy_width;
  6288. } else {
  6289. $this->endlinex = $startx + $linew + $shy_width;
  6290. }
  6291. $w = $linew;
  6292. $tmpcellpadding = $this->cell_padding;
  6293. if ($maxh == 0) {
  6294. $this->setCellPadding(0);
  6295. }
  6296. }
  6297. // print the line
  6298. if ($firstblock AND $this->isRTLTextDir()) {
  6299. $tmpstr = $this->stringRightTrim($tmpstr);
  6300. }
  6301. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  6302. unset($tmpstr);
  6303. if ($firstline) {
  6304. if ($chars[$sep] == 45) {
  6305. $endspace += 1;
  6306. }
  6307. // return the remaining text
  6308. $this->cell_padding = $tmpcellpadding;
  6309. return (TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace)));
  6310. }
  6311. $i = $sep;
  6312. $sep = -1;
  6313. $shy = false;
  6314. $j = ($i + 1);
  6315. }
  6316. }
  6317. // account for margin changes
  6318. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6319. $this->AcceptPageBreak();
  6320. if ($this->rtl) {
  6321. $this->x -= $margin['R'];
  6322. } else {
  6323. $this->x += $margin['L'];
  6324. }
  6325. $this->lMargin += $margin['L'];
  6326. $this->rMargin += $margin['R'];
  6327. }
  6328. $w = $this->getRemainingWidth();
  6329. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6330. if ($linebreak) {
  6331. $linebreak = false;
  6332. } else {
  6333. ++$nl;
  6334. $l = 0;
  6335. }
  6336. }
  6337. }
  6338. // save last character
  6339. $pc = $c;
  6340. ++$i;
  6341. } // end while i < nb
  6342. // print last substring (if any)
  6343. if ($l > 0) {
  6344. switch ($align) {
  6345. case 'J':
  6346. case 'C': {
  6347. break;
  6348. }
  6349. case 'L': {
  6350. if (!$this->rtl) {
  6351. $w = $l;
  6352. }
  6353. break;
  6354. }
  6355. case 'R': {
  6356. if ($this->rtl) {
  6357. $w = $l;
  6358. }
  6359. break;
  6360. }
  6361. default: {
  6362. $w = $l;
  6363. break;
  6364. }
  6365. }
  6366. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $nb);
  6367. if ($firstline) {
  6368. $startx = $this->x;
  6369. $tmparr = array_slice($chars, $j, ($nb - $j));
  6370. if ($rtlmode) {
  6371. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6372. }
  6373. $linew = $this->GetArrStringWidth($tmparr);
  6374. unset($tmparr);
  6375. if ($this->rtl) {
  6376. $this->endlinex = $startx - $linew;
  6377. } else {
  6378. $this->endlinex = $startx + $linew;
  6379. }
  6380. $w = $linew;
  6381. $tmpcellpadding = $this->cell_padding;
  6382. if ($maxh == 0) {
  6383. $this->setCellPadding(0);
  6384. }
  6385. }
  6386. if ($firstblock AND $this->isRTLTextDir()) {
  6387. $tmpstr = $this->stringRightTrim($tmpstr);
  6388. }
  6389. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  6390. unset($tmpstr);
  6391. if ($firstline) {
  6392. $this->cell_padding = $tmpcellpadding;
  6393. return (TCPDF_FONTS::UniArrSubString($uchars, $nb));
  6394. }
  6395. ++$nl;
  6396. }
  6397. if ($firstline) {
  6398. return '';
  6399. }
  6400. return $nl;
  6401. }
  6402. /**
  6403. * Returns the remaining width between the current position and margins.
  6404. * @return float Return the remaining width
  6405. * @protected
  6406. */
  6407. protected function getRemainingWidth() {
  6408. list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
  6409. if ($this->rtl) {
  6410. return ($this->x - $this->lMargin);
  6411. } else {
  6412. return ($this->w - $this->rMargin - $this->x);
  6413. }
  6414. }
  6415. /**
  6416. * Set the block dimensions accounting for page breaks and page/column fitting
  6417. * @param float $w width
  6418. * @param float $h height
  6419. * @param float $x X coordinate
  6420. * @param float $y Y coodiante
  6421. * @param boolean $fitonpage if true the block is resized to not exceed page dimensions.
  6422. * @return array array($w, $h, $x, $y)
  6423. * @protected
  6424. * @since 5.5.009 (2010-07-05)
  6425. */
  6426. protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
  6427. if ($w <= 0) {
  6428. // set maximum width
  6429. $w = ($this->w - $this->lMargin - $this->rMargin);
  6430. if ($w <= 0) {
  6431. $w = 1;
  6432. }
  6433. }
  6434. if ($h <= 0) {
  6435. // set maximum height
  6436. $h = ($this->PageBreakTrigger - $this->tMargin);
  6437. if ($h <= 0) {
  6438. $h = 1;
  6439. }
  6440. }
  6441. // resize the block to be vertically contained on a single page or single column
  6442. if ($fitonpage OR $this->AutoPageBreak) {
  6443. $ratio_wh = ($w / $h);
  6444. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  6445. $h = $this->PageBreakTrigger - $this->tMargin;
  6446. $w = ($h * $ratio_wh);
  6447. }
  6448. // resize the block to be horizontally contained on a single page or single column
  6449. if ($fitonpage) {
  6450. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  6451. if ($w > $maxw) {
  6452. $w = $maxw;
  6453. $h = ($w / $ratio_wh);
  6454. }
  6455. }
  6456. }
  6457. // Check whether we need a new page or new column first as this does not fit
  6458. $prev_x = $this->x;
  6459. $prev_y = $this->y;
  6460. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  6461. $y = $this->y;
  6462. if ($this->rtl) {
  6463. $x += ($prev_x - $this->x);
  6464. } else {
  6465. $x += ($this->x - $prev_x);
  6466. }
  6467. $this->newline = true;
  6468. }
  6469. // resize the block to be contained on the remaining available page or column space
  6470. if ($fitonpage) {
  6471. $ratio_wh = ($w / $h);
  6472. if (($y + $h) > $this->PageBreakTrigger) {
  6473. $h = $this->PageBreakTrigger - $y;
  6474. $w = ($h * $ratio_wh);
  6475. }
  6476. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  6477. $w = $this->w - $this->rMargin - $x;
  6478. $h = ($w / $ratio_wh);
  6479. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  6480. $w = $x - $this->lMargin;
  6481. $h = ($w / $ratio_wh);
  6482. }
  6483. }
  6484. return array($w, $h, $x, $y);
  6485. }
  6486. /**
  6487. * Puts an image in the page.
  6488. * The upper-left corner must be given.
  6489. * The dimensions can be specified in different ways:<ul>
  6490. * <li>explicit width and height (expressed in user unit)</li>
  6491. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6492. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6493. * 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;
  6494. * The format can be specified explicitly or inferred from the file extension.<br />
  6495. * It is possible to put a link on the image.<br />
  6496. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6497. * @param string $file 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').
  6498. * @param float|null $x Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6499. * @param float|null $y Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6500. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6501. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6502. * @param string $type 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.
  6503. * @param mixed $link URL or identifier returned by AddLink().
  6504. * @param string $align 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>
  6505. * @param mixed $resize 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).
  6506. * @param int $dpi dot-per-inch resolution used on resize
  6507. * @param string $palign 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>
  6508. * @param boolean $ismask true if this image is a mask, false otherwise
  6509. * @param mixed $imgmask image object returned by this function or false
  6510. * @param mixed $border 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)))
  6511. * @param mixed $fitbox 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).
  6512. * @param boolean $hidden If true do not display the image.
  6513. * @param boolean $fitonpage If true the image is resized to not exceed page dimensions.
  6514. * @param boolean $alt If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  6515. * @param array $altimgs 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.
  6516. * @return mixed|false image information
  6517. * @public
  6518. * @since 1.1
  6519. */
  6520. public function Image($file, $x=null, $y=null, $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()) {
  6521. if ($this->state != 2) {
  6522. return false;
  6523. }
  6524. if (TCPDF_STATIC::empty_string($x)) {
  6525. $x = $this->x;
  6526. }
  6527. if (TCPDF_STATIC::empty_string($y)) {
  6528. $y = $this->y;
  6529. }
  6530. // check page for no-write regions and adapt page margins if necessary
  6531. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  6532. $exurl = ''; // external streams
  6533. $imsize = FALSE;
  6534. // Make sure the file variable is not empty or null because accessing $file[0] later
  6535. // results in error when running PHP 7.4
  6536. if (empty($file)) {
  6537. return false;
  6538. }
  6539. // check if we are passing an image as file or string
  6540. if ($file[0] === '@') {
  6541. // image from string
  6542. $imgdata = substr($file, 1);
  6543. } else { // image file
  6544. if ($file[0] === '*') {
  6545. // image as external stream
  6546. $file = substr($file, 1);
  6547. $exurl = $file;
  6548. }
  6549. // check if file exist and it is valid
  6550. if (!@$this->fileExists($file)) {
  6551. return false;
  6552. }
  6553. if (false !== $info = $this->getImageBuffer($file)) {
  6554. $imsize = array($info['w'], $info['h']);
  6555. } elseif (($imsize = @getimagesize($file)) === FALSE && strpos($file, '__tcpdf_'.$this->file_id.'_img') === FALSE){
  6556. $imgdata = $this->getCachedFileContents($file);
  6557. }
  6558. }
  6559. if (!empty($imgdata)) {
  6560. // copy image to cache
  6561. $original_file = $file;
  6562. $file = TCPDF_STATIC::getObjFilename('img', $this->file_id);
  6563. $fp = TCPDF_STATIC::fopenLocal($file, 'w');
  6564. if (!$fp) {
  6565. $this->Error('Unable to write file: '.$file);
  6566. }
  6567. fwrite($fp, $imgdata);
  6568. fclose($fp);
  6569. unset($imgdata);
  6570. $imsize = @getimagesize($file);
  6571. if ($imsize === FALSE) {
  6572. unlink($file);
  6573. $file = $original_file;
  6574. }
  6575. }
  6576. if ($imsize === FALSE) {
  6577. if (($w > 0) AND ($h > 0)) {
  6578. // get measures from specified data
  6579. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6580. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6581. $imsize = array($pw, $ph);
  6582. } else {
  6583. $this->Error('[Image] Unable to get the size of the image: '.$file);
  6584. }
  6585. }
  6586. // file hash
  6587. $filehash = md5($file);
  6588. // get original image width and height in pixels
  6589. list($pixw, $pixh) = $imsize;
  6590. // calculate image width and height on document
  6591. if (($w <= 0) AND ($h <= 0)) {
  6592. // convert image size to document unit
  6593. $w = $this->pixelsToUnits($pixw);
  6594. $h = $this->pixelsToUnits($pixh);
  6595. } elseif ($w <= 0) {
  6596. $w = $h * $pixw / $pixh;
  6597. } elseif ($h <= 0) {
  6598. $h = $w * $pixh / $pixw;
  6599. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  6600. if (strlen($fitbox) !== 2) {
  6601. // set default alignment
  6602. $fitbox = '--';
  6603. }
  6604. // scale image dimensions proportionally to fit within the ($w, $h) box
  6605. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  6606. // store current height
  6607. $oldh = $h;
  6608. // calculate new height
  6609. $h = $w * $pixh / $pixw;
  6610. // height difference
  6611. $hdiff = ($oldh - $h);
  6612. // vertical alignment
  6613. switch (strtoupper($fitbox[1])) {
  6614. case 'T': {
  6615. break;
  6616. }
  6617. case 'M': {
  6618. $y += ($hdiff / 2);
  6619. break;
  6620. }
  6621. case 'B': {
  6622. $y += $hdiff;
  6623. break;
  6624. }
  6625. }
  6626. } else {
  6627. // store current width
  6628. $oldw = $w;
  6629. // calculate new width
  6630. $w = $h * $pixw / $pixh;
  6631. // width difference
  6632. $wdiff = ($oldw - $w);
  6633. // horizontal alignment
  6634. switch (strtoupper($fitbox[0])) {
  6635. case 'L': {
  6636. if ($this->rtl) {
  6637. $x -= $wdiff;
  6638. }
  6639. break;
  6640. }
  6641. case 'C': {
  6642. if ($this->rtl) {
  6643. $x -= ($wdiff / 2);
  6644. } else {
  6645. $x += ($wdiff / 2);
  6646. }
  6647. break;
  6648. }
  6649. case 'R': {
  6650. if (!$this->rtl) {
  6651. $x += $wdiff;
  6652. }
  6653. break;
  6654. }
  6655. }
  6656. }
  6657. }
  6658. // fit the image on available space
  6659. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  6660. // calculate new minimum dimensions in pixels
  6661. $neww = round($w * $this->k * $dpi / $this->dpi);
  6662. $newh = round($h * $this->k * $dpi / $this->dpi);
  6663. // check if resize is necessary (resize is used only to reduce the image)
  6664. $newsize = ($neww * $newh);
  6665. $pixsize = ($pixw * $pixh);
  6666. if (intval($resize) == 2) {
  6667. $resize = true;
  6668. } elseif ($newsize >= $pixsize) {
  6669. $resize = false;
  6670. }
  6671. // check if image has been already added on document
  6672. $newimage = true;
  6673. if (in_array($file, $this->imagekeys)) {
  6674. $newimage = false;
  6675. // get existing image data
  6676. $info = $this->getImageBuffer($file);
  6677. if (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE) {
  6678. // check if the newer image is larger
  6679. $oldsize = ($info['w'] * $info['h']);
  6680. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6681. $newimage = true;
  6682. }
  6683. }
  6684. } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)) {
  6685. // create temp image file (without alpha channel)
  6686. $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6687. // create temp alpha file
  6688. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6689. // check for cached images
  6690. if (in_array($tempfile_plain, $this->imagekeys)) {
  6691. // get existing image data
  6692. $info = $this->getImageBuffer($tempfile_plain);
  6693. // check if the newer image is larger
  6694. $oldsize = ($info['w'] * $info['h']);
  6695. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6696. $newimage = true;
  6697. } else {
  6698. $newimage = false;
  6699. // embed mask image
  6700. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6701. // embed image, masked with previously embedded mask
  6702. return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6703. }
  6704. }
  6705. }
  6706. if ($newimage) {
  6707. //First use of image, get info
  6708. $type = strtolower($type);
  6709. if ($type == '') {
  6710. $type = TCPDF_IMAGES::getImageFileType($file, $imsize);
  6711. } elseif ($type == 'jpg') {
  6712. $type = 'jpeg';
  6713. }
  6714. $mqr = TCPDF_STATIC::get_mqr();
  6715. TCPDF_STATIC::set_mqr(false);
  6716. // Specific image handlers (defined on TCPDF_IMAGES CLASS)
  6717. $mtd = '_parse'.$type;
  6718. // GD image handler function
  6719. $gdfunction = 'imagecreatefrom'.$type;
  6720. $info = false;
  6721. if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  6722. // TCPDF image functions
  6723. $info = TCPDF_IMAGES::$mtd($file);
  6724. if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)
  6725. AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
  6726. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
  6727. }
  6728. }
  6729. if (($info === false) AND function_exists($gdfunction)) {
  6730. try {
  6731. // GD library
  6732. $img = $gdfunction($file);
  6733. if ($img !== false) {
  6734. if ($resize) {
  6735. $imgr = imagecreatetruecolor($neww, $newh);
  6736. if (($type == 'gif') OR ($type == 'png')) {
  6737. $imgr = TCPDF_IMAGES::setGDImageTransparency($imgr, $img);
  6738. }
  6739. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  6740. $img = $imgr;
  6741. }
  6742. if (($type == 'gif') OR ($type == 'png')) {
  6743. $info = TCPDF_IMAGES::_toPNG($img, TCPDF_STATIC::getObjFilename('img', $this->file_id));
  6744. } else {
  6745. $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality, TCPDF_STATIC::getObjFilename('img', $this->file_id));
  6746. }
  6747. }
  6748. } catch(Exception $e) {
  6749. $info = false;
  6750. }
  6751. }
  6752. if (($info === false) AND extension_loaded('imagick')) {
  6753. try {
  6754. // ImageMagick library
  6755. $img = new Imagick();
  6756. if ($type == 'svg') {
  6757. if ($file[0] === '@') {
  6758. // image from string
  6759. $svgimg = substr($file, 1);
  6760. } else {
  6761. // get SVG file content
  6762. $svgimg = $this->getCachedFileContents($file);
  6763. }
  6764. if ($svgimg !== FALSE) {
  6765. // get width and height
  6766. $regs = array();
  6767. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  6768. $svgtag = $regs[1];
  6769. $tmp = array();
  6770. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6771. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6772. $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit;
  6773. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  6774. } else {
  6775. $ow = $w;
  6776. }
  6777. $tmp = array();
  6778. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6779. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6780. $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit;
  6781. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  6782. } else {
  6783. $oh = $h;
  6784. }
  6785. $tmp = array();
  6786. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  6787. $vbw = ($ow * $this->imgscale * $this->k);
  6788. $vbh = ($oh * $this->imgscale * $this->k);
  6789. $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
  6790. $svgtag = $vbox.$svgtag;
  6791. }
  6792. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  6793. }
  6794. $img->readImageBlob($svgimg);
  6795. }
  6796. } else {
  6797. $img->readImage($file);
  6798. }
  6799. if ($resize) {
  6800. $img->resizeImage($neww, $newh, 10, 1, false);
  6801. }
  6802. $img->setCompressionQuality($this->jpeg_quality);
  6803. $img->setImageFormat('jpeg');
  6804. $tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id);
  6805. $img->writeImage($tempname);
  6806. $info = TCPDF_IMAGES::_parsejpeg($tempname);
  6807. unlink($tempname);
  6808. $img->destroy();
  6809. } catch(Exception $e) {
  6810. $info = false;
  6811. }
  6812. }
  6813. if ($info === false) {
  6814. // unable to process image
  6815. return false;
  6816. }
  6817. TCPDF_STATIC::set_mqr($mqr);
  6818. if ($ismask) {
  6819. // force grayscale
  6820. $info['cs'] = 'DeviceGray';
  6821. }
  6822. if ($imgmask !== false) {
  6823. $info['masked'] = $imgmask;
  6824. }
  6825. if (!empty($exurl)) {
  6826. $info['exurl'] = $exurl;
  6827. }
  6828. // array of alternative images
  6829. $info['altimgs'] = $altimgs;
  6830. // add image to document
  6831. $info['i'] = $this->setImageBuffer($file, $info);
  6832. }
  6833. // set alignment
  6834. $this->img_rb_x = $x + $w;
  6835. $this->img_rb_y = $y + $h;
  6836. // set alignment
  6837. if ($palign == 'L') {
  6838. $ximg = $this->lMargin;
  6839. } elseif ($palign == 'C') {
  6840. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6841. } elseif ($palign == 'R') {
  6842. $ximg = $this->w - $this->rMargin - $w;
  6843. } else {
  6844. $ximg = $x;
  6845. }
  6846. if ($ismask OR $hidden) {
  6847. // image is not displayed
  6848. return $info['i'];
  6849. }
  6850. $xkimg = $ximg * $this->k;
  6851. if (!$alt) {
  6852. // only non-alternative immages will be set
  6853. $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']));
  6854. }
  6855. if (!empty($border)) {
  6856. $bx = $this->x;
  6857. $by = $this->y;
  6858. $this->x = $ximg;
  6859. if ($this->rtl) {
  6860. $this->x += $w;
  6861. }
  6862. $this->y = $y;
  6863. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  6864. $this->x = $bx;
  6865. $this->y = $by;
  6866. }
  6867. if ($link) {
  6868. $this->Link($ximg, $y, $w, $h, $link, 0);
  6869. }
  6870. // set pointer to align the next text/objects
  6871. switch($align) {
  6872. case 'T': {
  6873. $this->y = $y;
  6874. $this->x = $this->img_rb_x;
  6875. break;
  6876. }
  6877. case 'M': {
  6878. $this->y = $y + round($h/2);
  6879. $this->x = $this->img_rb_x;
  6880. break;
  6881. }
  6882. case 'B': {
  6883. $this->y = $this->img_rb_y;
  6884. $this->x = $this->img_rb_x;
  6885. break;
  6886. }
  6887. case 'N': {
  6888. $this->setY($this->img_rb_y);
  6889. break;
  6890. }
  6891. default:{
  6892. break;
  6893. }
  6894. }
  6895. $this->endlinex = $this->img_rb_x;
  6896. if ($this->inxobj) {
  6897. // we are inside an XObject template
  6898. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  6899. }
  6900. return $info['i'];
  6901. }
  6902. /**
  6903. * Extract info from a PNG image with alpha channel using the Imagick or GD library.
  6904. * @param string $file Name of the file containing the image.
  6905. * @param float $x Abscissa of the upper-left corner.
  6906. * @param float $y Ordinate of the upper-left corner.
  6907. * @param float $wpx Original width of the image in pixels.
  6908. * @param float $hpx original height of the image in pixels.
  6909. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6910. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6911. * @param string $type 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.
  6912. * @param mixed $link URL or identifier returned by AddLink().
  6913. * @param string $align 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>
  6914. * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  6915. * @param int $dpi dot-per-inch resolution used on resize
  6916. * @param string $palign 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>
  6917. * @param string $filehash File hash used to build unique file names.
  6918. * @author Nicola Asuni
  6919. * @protected
  6920. * @since 4.3.007 (2008-12-04)
  6921. * @see Image()
  6922. */
  6923. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
  6924. // create temp images
  6925. if (empty($filehash)) {
  6926. $filehash = md5($file);
  6927. }
  6928. // create temp image file (without alpha channel)
  6929. $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6930. // create temp alpha file
  6931. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6932. $parsed = false;
  6933. $parse_error = '';
  6934. // ImageMagick extension
  6935. if (($parsed === false) AND extension_loaded('imagick')) {
  6936. try {
  6937. // ImageMagick library
  6938. $img = new Imagick();
  6939. $img->readImage($file);
  6940. // clone image object
  6941. $imga = TCPDF_STATIC::objclone($img);
  6942. // extract alpha channel
  6943. if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
  6944. $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
  6945. } else {
  6946. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  6947. $img->negateImage(true);
  6948. }
  6949. $img->setImageFormat('png');
  6950. $img->writeImage($tempfile_alpha);
  6951. // remove alpha channel
  6952. if (method_exists($imga, 'setImageMatte')) {
  6953. $imga->setImageMatte(false);
  6954. } else {
  6955. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  6956. }
  6957. $imga->setImageFormat('png');
  6958. $imga->writeImage($tempfile_plain);
  6959. $parsed = true;
  6960. } catch (Exception $e) {
  6961. // Imagemagick fails, try with GD
  6962. $parse_error = 'Imagick library error: '.$e->getMessage();
  6963. }
  6964. }
  6965. // GD extension
  6966. if (($parsed === false) AND function_exists('imagecreatefrompng')) {
  6967. try {
  6968. // generate images
  6969. $img = imagecreatefrompng($file);
  6970. $imgalpha = imagecreate($wpx, $hpx);
  6971. // generate gray scale palette (0 -> 255)
  6972. for ($c = 0; $c < 256; ++$c) {
  6973. ImageColorAllocate($imgalpha, $c, $c, $c);
  6974. }
  6975. // extract alpha channel
  6976. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  6977. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  6978. $color = imagecolorat($img, $xpx, $ypx);
  6979. // get and correct gamma color
  6980. $alpha = $this->getGDgamma($img, $color);
  6981. imagesetpixel($imgalpha, (int) $xpx, (int) $ypx, (int) $alpha);
  6982. }
  6983. }
  6984. imagepng($imgalpha, $tempfile_alpha);
  6985. imagedestroy($imgalpha);
  6986. // extract image without alpha channel
  6987. $imgplain = imagecreatetruecolor($wpx, $hpx);
  6988. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  6989. imagepng($imgplain, $tempfile_plain);
  6990. imagedestroy($imgplain);
  6991. $parsed = true;
  6992. } catch (Exception $e) {
  6993. // GD fails
  6994. $parse_error = 'GD library error: '.$e->getMessage();
  6995. }
  6996. }
  6997. if ($parsed === false) {
  6998. if (empty($parse_error)) {
  6999. $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  7000. } else {
  7001. $this->Error($parse_error);
  7002. }
  7003. }
  7004. // embed mask image
  7005. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  7006. // embed image, masked with previously embedded mask
  7007. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  7008. }
  7009. /**
  7010. * Get the GD-corrected PNG gamma value from alpha color
  7011. * @param resource $img GD image Resource ID.
  7012. * @param int $c alpha color
  7013. * @protected
  7014. * @since 4.3.007 (2008-12-04)
  7015. */
  7016. protected function getGDgamma($img, $c) {
  7017. if (!isset($this->gdgammacache['#'.$c])) {
  7018. $colors = imagecolorsforindex($img, $c);
  7019. // GD alpha is only 7 bit (0 -> 127)
  7020. $this->gdgammacache['#'.$c] = (int) (((127 - $colors['alpha']) / 127) * 255);
  7021. // correct gamma
  7022. $this->gdgammacache['#'.$c] = (int) (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255);
  7023. // store the latest values on cache to improve performances
  7024. if (count($this->gdgammacache) > 8) {
  7025. // remove one element from the cache array
  7026. array_shift($this->gdgammacache);
  7027. }
  7028. }
  7029. return $this->gdgammacache['#'.$c];
  7030. }
  7031. /**
  7032. * Performs a line break.
  7033. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  7034. * @param float|null $h The height of the break. By default, the value equals the height of the last printed cell.
  7035. * @param boolean $cell if true add the current left (or right o for RTL) padding to the X coordinate
  7036. * @public
  7037. * @since 1.0
  7038. * @see Cell()
  7039. */
  7040. public function Ln($h=null, $cell=false) {
  7041. 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'])) {
  7042. // revove vertical space from the top of the column
  7043. return;
  7044. }
  7045. if ($cell) {
  7046. if ($this->rtl) {
  7047. $cellpadding = $this->cell_padding['R'];
  7048. } else {
  7049. $cellpadding = $this->cell_padding['L'];
  7050. }
  7051. } else {
  7052. $cellpadding = 0;
  7053. }
  7054. if ($this->rtl) {
  7055. $this->x = $this->w - $this->rMargin - $cellpadding;
  7056. } else {
  7057. $this->x = $this->lMargin + $cellpadding;
  7058. }
  7059. if (TCPDF_STATIC::empty_string($h)) {
  7060. $h = $this->lasth;
  7061. }
  7062. $this->y += $h;
  7063. $this->newline = true;
  7064. }
  7065. /**
  7066. * Returns the relative X value of current position.
  7067. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  7068. * @return float
  7069. * @public
  7070. * @since 1.2
  7071. * @see SetX(), GetY(), SetY()
  7072. */
  7073. public function GetX() {
  7074. //Get x position
  7075. if ($this->rtl) {
  7076. return ($this->w - $this->x);
  7077. } else {
  7078. return $this->x;
  7079. }
  7080. }
  7081. /**
  7082. * Returns the absolute X value of current position.
  7083. * @return float
  7084. * @public
  7085. * @since 1.2
  7086. * @see SetX(), GetY(), SetY()
  7087. */
  7088. public function GetAbsX() {
  7089. return $this->x;
  7090. }
  7091. /**
  7092. * Returns the ordinate of the current position.
  7093. * @return float
  7094. * @public
  7095. * @since 1.0
  7096. * @see SetY(), GetX(), SetX()
  7097. */
  7098. public function GetY() {
  7099. return $this->y;
  7100. }
  7101. /**
  7102. * Defines the abscissa of the current position.
  7103. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  7104. * @param float $x The value of the abscissa in user units.
  7105. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7106. * @public
  7107. * @since 1.2
  7108. * @see GetX(), GetY(), SetY(), SetXY()
  7109. */
  7110. public function setX($x, $rtloff=false) {
  7111. $x = floatval($x);
  7112. if (!$rtloff AND $this->rtl) {
  7113. if ($x >= 0) {
  7114. $this->x = $this->w - $x;
  7115. } else {
  7116. $this->x = abs($x);
  7117. }
  7118. } else {
  7119. if ($x >= 0) {
  7120. $this->x = $x;
  7121. } else {
  7122. $this->x = $this->w + $x;
  7123. }
  7124. }
  7125. if ($this->x < 0) {
  7126. $this->x = 0;
  7127. }
  7128. if ($this->x > $this->w) {
  7129. $this->x = $this->w;
  7130. }
  7131. }
  7132. /**
  7133. * Moves the current abscissa back to the left margin and sets the ordinate.
  7134. * If the passed value is negative, it is relative to the bottom of the page.
  7135. * @param float $y The value of the ordinate in user units.
  7136. * @param bool $resetx if true (default) reset the X position.
  7137. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7138. * @public
  7139. * @since 1.0
  7140. * @see GetX(), GetY(), SetY(), SetXY()
  7141. */
  7142. public function setY($y, $resetx=true, $rtloff=false) {
  7143. $y = floatval($y);
  7144. if ($resetx) {
  7145. //reset x
  7146. if (!$rtloff AND $this->rtl) {
  7147. $this->x = $this->w - $this->rMargin;
  7148. } else {
  7149. $this->x = $this->lMargin;
  7150. }
  7151. }
  7152. if ($y >= 0) {
  7153. $this->y = $y;
  7154. } else {
  7155. $this->y = $this->h + $y;
  7156. }
  7157. if ($this->y < 0) {
  7158. $this->y = 0;
  7159. }
  7160. if ($this->y > $this->h) {
  7161. $this->y = $this->h;
  7162. }
  7163. }
  7164. /**
  7165. * Defines the abscissa and ordinate of the current position.
  7166. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7167. * @param float $x The value of the abscissa.
  7168. * @param float $y The value of the ordinate.
  7169. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7170. * @public
  7171. * @since 1.2
  7172. * @see SetX(), SetY()
  7173. */
  7174. public function setXY($x, $y, $rtloff=false) {
  7175. $this->setY($y, false, $rtloff);
  7176. $this->setX($x, $rtloff);
  7177. }
  7178. /**
  7179. * Set the absolute X coordinate of the current pointer.
  7180. * @param float $x The value of the abscissa in user units.
  7181. * @public
  7182. * @since 5.9.186 (2012-09-13)
  7183. * @see setAbsX(), setAbsY(), SetAbsXY()
  7184. */
  7185. public function setAbsX($x) {
  7186. $this->x = floatval($x);
  7187. }
  7188. /**
  7189. * Set the absolute Y coordinate of the current pointer.
  7190. * @param float $y (float) The value of the ordinate in user units.
  7191. * @public
  7192. * @since 5.9.186 (2012-09-13)
  7193. * @see setAbsX(), setAbsY(), SetAbsXY()
  7194. */
  7195. public function setAbsY($y) {
  7196. $this->y = floatval($y);
  7197. }
  7198. /**
  7199. * Set the absolute X and Y coordinates of the current pointer.
  7200. * @param float $x The value of the abscissa in user units.
  7201. * @param float $y (float) The value of the ordinate in user units.
  7202. * @public
  7203. * @since 5.9.186 (2012-09-13)
  7204. * @see setAbsX(), setAbsY(), SetAbsXY()
  7205. */
  7206. public function setAbsXY($x, $y) {
  7207. $this->setAbsX($x);
  7208. $this->setAbsY($y);
  7209. }
  7210. /**
  7211. * Send the document to a given destination: string, local file or browser.
  7212. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7213. * The method first calls Close() if necessary to terminate the document.
  7214. * @param string $name The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  7215. * @param string $dest 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>
  7216. * @return string
  7217. * @public
  7218. * @since 1.0
  7219. * @see Close()
  7220. */
  7221. public function Output($name='doc.pdf', $dest='I') {
  7222. //Output PDF to some destination
  7223. //Finish document if necessary
  7224. if ($this->state < 3) {
  7225. $this->Close();
  7226. }
  7227. //Normalize parameters
  7228. if (is_bool($dest)) {
  7229. $dest = $dest ? 'D' : 'F';
  7230. }
  7231. $dest = strtoupper($dest);
  7232. if ($dest[0] != 'F') {
  7233. $name = preg_replace('/[\s]+/', '_', $name);
  7234. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  7235. }
  7236. if ($this->sign) {
  7237. // *** apply digital signature to the document ***
  7238. // get the document content
  7239. $pdfdoc = $this->getBuffer();
  7240. // remove last newline
  7241. $pdfdoc = substr($pdfdoc, 0, -1);
  7242. // remove filler space
  7243. $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string);
  7244. // define the ByteRange
  7245. $byte_range = array();
  7246. $byte_range[0] = 0;
  7247. $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10;
  7248. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  7249. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7250. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  7251. // replace the ByteRange
  7252. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  7253. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  7254. $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc);
  7255. // write the document to a temporary folder
  7256. $tempdoc = TCPDF_STATIC::getObjFilename('doc', $this->file_id);
  7257. $f = TCPDF_STATIC::fopenLocal($tempdoc, 'wb');
  7258. if (!$f) {
  7259. $this->Error('Unable to create temporary file: '.$tempdoc);
  7260. }
  7261. $pdfdoc_length = strlen($pdfdoc);
  7262. fwrite($f, $pdfdoc, $pdfdoc_length);
  7263. fclose($f);
  7264. // get digital signature via openssl library
  7265. $tempsign = TCPDF_STATIC::getObjFilename('sig', $this->file_id);
  7266. if (empty($this->signature_data['extracerts'])) {
  7267. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  7268. } else {
  7269. 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']);
  7270. }
  7271. // read signature
  7272. $signature = file_get_contents($tempsign);
  7273. // extract signature
  7274. $signature = substr($signature, $pdfdoc_length);
  7275. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  7276. $tmparr = explode("\n\n", $signature);
  7277. $signature = $tmparr[1];
  7278. // decode signature
  7279. $signature = base64_decode(trim($signature));
  7280. // add TSA timestamp to signature
  7281. $signature = $this->applyTSA($signature);
  7282. // convert signature to hex
  7283. $signature = current(unpack('H*', $signature));
  7284. $signature = str_pad($signature, $this->signature_max_length, '0');
  7285. // Add signature to the document
  7286. $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  7287. $this->bufferlen = strlen($this->buffer);
  7288. }
  7289. switch($dest) {
  7290. case 'I': {
  7291. // Send PDF to the standard output
  7292. if (ob_get_contents()) {
  7293. $this->Error('Some data has already been output, can\'t send PDF file');
  7294. }
  7295. if (php_sapi_name() != 'cli') {
  7296. // send output to a browser
  7297. header('Content-Type: application/pdf');
  7298. if (headers_sent()) {
  7299. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7300. }
  7301. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7302. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7303. header('Pragma: public');
  7304. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7305. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7306. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7307. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7308. } else {
  7309. echo $this->getBuffer();
  7310. }
  7311. break;
  7312. }
  7313. case 'D': {
  7314. // download PDF as file
  7315. if (ob_get_contents()) {
  7316. $this->Error('Some data has already been output, can\'t send PDF file');
  7317. }
  7318. header('Content-Description: File Transfer');
  7319. if (headers_sent()) {
  7320. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7321. }
  7322. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7323. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7324. header('Pragma: public');
  7325. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7326. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7327. // force download dialog
  7328. if (strpos(php_sapi_name(), 'cgi') === false) {
  7329. header('Content-Type: application/force-download');
  7330. header('Content-Type: application/octet-stream', false);
  7331. header('Content-Type: application/download', false);
  7332. header('Content-Type: application/pdf', false);
  7333. } else {
  7334. header('Content-Type: application/pdf');
  7335. }
  7336. // use the Content-Disposition header to supply a recommended filename
  7337. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7338. header('Content-Transfer-Encoding: binary');
  7339. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7340. break;
  7341. }
  7342. case 'F':
  7343. case 'FI':
  7344. case 'FD': {
  7345. // save PDF to a local file
  7346. $f = TCPDF_STATIC::fopenLocal($name, 'wb');
  7347. if (!$f) {
  7348. $this->Error('Unable to create output file: '.$name);
  7349. }
  7350. fwrite($f, $this->getBuffer(), $this->bufferlen);
  7351. fclose($f);
  7352. if ($dest == 'FI') {
  7353. // send headers to browser
  7354. header('Content-Type: application/pdf');
  7355. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7356. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7357. header('Pragma: public');
  7358. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7359. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7360. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7361. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7362. } elseif ($dest == 'FD') {
  7363. // send headers to browser
  7364. if (ob_get_contents()) {
  7365. $this->Error('Some data has already been output, can\'t send PDF file');
  7366. }
  7367. header('Content-Description: File Transfer');
  7368. if (headers_sent()) {
  7369. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7370. }
  7371. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7372. header('Pragma: public');
  7373. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7374. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7375. // force download dialog
  7376. if (strpos(php_sapi_name(), 'cgi') === false) {
  7377. header('Content-Type: application/force-download');
  7378. header('Content-Type: application/octet-stream', false);
  7379. header('Content-Type: application/download', false);
  7380. header('Content-Type: application/pdf', false);
  7381. } else {
  7382. header('Content-Type: application/pdf');
  7383. }
  7384. // use the Content-Disposition header to supply a recommended filename
  7385. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7386. header('Content-Transfer-Encoding: binary');
  7387. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7388. }
  7389. break;
  7390. }
  7391. case 'E': {
  7392. // return PDF as base64 mime multi-part email attachment (RFC 2045)
  7393. $retval = 'Content-Type: application/pdf;'."\r\n";
  7394. $retval .= ' name="'.$name.'"'."\r\n";
  7395. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7396. $retval .= 'Content-Disposition: attachment;'."\r\n";
  7397. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7398. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  7399. return $retval;
  7400. }
  7401. case 'S': {
  7402. // returns PDF as a string
  7403. return $this->getBuffer();
  7404. }
  7405. default: {
  7406. $this->Error('Incorrect output destination: '.$dest);
  7407. }
  7408. }
  7409. return '';
  7410. }
  7411. protected static $cleaned_ids = array();
  7412. /**
  7413. * Unset all class variables except the following critical variables.
  7414. * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  7415. * @param boolean $preserve_objcopy if true preserves the objcopy variable
  7416. * @public
  7417. * @since 4.5.016 (2009-02-24)
  7418. */
  7419. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  7420. if (isset(self::$cleaned_ids[$this->file_id])) {
  7421. $destroyall = false;
  7422. }
  7423. if ($destroyall AND !$preserve_objcopy && isset($this->file_id)) {
  7424. self::$cleaned_ids[$this->file_id] = true;
  7425. // remove all temporary files
  7426. if ($handle = @opendir(K_PATH_CACHE)) {
  7427. while ( false !== ( $file_name = readdir( $handle ) ) ) {
  7428. if (strpos($file_name, '__tcpdf_'.$this->file_id.'_') === 0) {
  7429. unlink(K_PATH_CACHE.$file_name);
  7430. }
  7431. }
  7432. closedir($handle);
  7433. }
  7434. if (isset($this->imagekeys)) {
  7435. foreach($this->imagekeys as $file) {
  7436. if (strpos($file, K_PATH_CACHE) === 0 && TCPDF_STATIC::file_exists($file)) {
  7437. @unlink($file);
  7438. }
  7439. }
  7440. }
  7441. }
  7442. $preserve = array(
  7443. 'file_id',
  7444. 'state',
  7445. 'bufferlen',
  7446. 'buffer',
  7447. 'cached_files',
  7448. 'imagekeys',
  7449. 'sign',
  7450. 'signature_data',
  7451. 'signature_max_length',
  7452. 'byterange_string',
  7453. 'tsa_timestamp',
  7454. 'tsa_data'
  7455. );
  7456. foreach (array_keys(get_object_vars($this)) as $val) {
  7457. if ($destroyall OR !in_array($val, $preserve)) {
  7458. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
  7459. unset($this->$val);
  7460. }
  7461. }
  7462. }
  7463. }
  7464. /**
  7465. * Check for locale-related bug
  7466. * @protected
  7467. */
  7468. protected function _dochecks() {
  7469. //Check for locale-related bug
  7470. if (1.1 == 1) {
  7471. $this->Error('Don\'t alter the locale before including class file');
  7472. }
  7473. //Check for decimal separator
  7474. if (sprintf('%.1F', 1.0) != '1.0') {
  7475. setlocale(LC_NUMERIC, 'C');
  7476. }
  7477. }
  7478. /**
  7479. * Return an array containing variations for the basic page number alias.
  7480. * @param string $a Base alias.
  7481. * @return array of page number aliases
  7482. * @protected
  7483. */
  7484. protected function getInternalPageNumberAliases($a= '') {
  7485. $alias = array();
  7486. // build array of Unicode + ASCII variants (the order is important)
  7487. $alias = array('u' => array(), 'a' => array());
  7488. $u = '{'.$a.'}';
  7489. $alias['u'][] = TCPDF_STATIC::_escape($u);
  7490. if ($this->isunicode) {
  7491. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont));
  7492. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7493. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont));
  7494. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7495. }
  7496. $alias['a'][] = TCPDF_STATIC::_escape($a);
  7497. return $alias;
  7498. }
  7499. /**
  7500. * Return an array containing all internal page aliases.
  7501. * @return array of page number aliases
  7502. * @protected
  7503. */
  7504. protected function getAllInternalPageNumberAliases() {
  7505. $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);
  7506. $pnalias = array();
  7507. foreach($basic_alias as $k => $a) {
  7508. $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  7509. }
  7510. return $pnalias;
  7511. }
  7512. /**
  7513. * Replace right shift page number aliases with spaces to correct right alignment.
  7514. * This works perfectly only when using monospaced fonts.
  7515. * @param string $page Page content.
  7516. * @param array $aliases Array of page aliases.
  7517. * @param int $diff initial difference to add.
  7518. * @return string replaced page content.
  7519. * @protected
  7520. */
  7521. protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
  7522. foreach ($aliases as $type => $alias) {
  7523. foreach ($alias as $a) {
  7524. // find position of compensation factor
  7525. $startnum = (strpos($a, ':') + 1);
  7526. $a = substr($a, 0, $startnum);
  7527. if (($pos = strpos($page, $a)) !== false) {
  7528. // end of alias
  7529. $endnum = strpos($page, '}', $pos);
  7530. // string to be replaced
  7531. $aa = substr($page, $pos, ($endnum - $pos + 1));
  7532. // get compensation factor
  7533. $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
  7534. $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
  7535. $ratio = floatval($ratio);
  7536. if ($type == 'u') {
  7537. $chrdiff = floor(($diff + 12) * $ratio);
  7538. $shift = str_repeat(' ', $chrdiff);
  7539. $shift = TCPDF_FONTS::UTF8ToUTF16BE($shift, false, $this->isunicode, $this->CurrentFont);
  7540. } else {
  7541. $chrdiff = floor(($diff + 11) * $ratio);
  7542. $shift = str_repeat(' ', $chrdiff);
  7543. }
  7544. $page = str_replace($aa, $shift, $page);
  7545. }
  7546. }
  7547. }
  7548. return $page;
  7549. }
  7550. /**
  7551. * Set page boxes to be included on page descriptions.
  7552. * @param array $boxes Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  7553. * @protected
  7554. */
  7555. protected function setPageBoxTypes($boxes) {
  7556. $this->page_boxes = array();
  7557. foreach ($boxes as $box) {
  7558. if (in_array($box, TCPDF_STATIC::$pageboxes)) {
  7559. $this->page_boxes[] = $box;
  7560. }
  7561. }
  7562. }
  7563. /**
  7564. * Output pages (and replace page number aliases).
  7565. * @protected
  7566. */
  7567. protected function _putpages() {
  7568. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7569. // get internal aliases for page numbers
  7570. $pnalias = $this->getAllInternalPageNumberAliases();
  7571. $num_pages = $this->numpages;
  7572. $ptpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $num_pages - 1));
  7573. $ptpu = TCPDF_FONTS::UTF8ToUTF16BE($ptpa, false, $this->isunicode, $this->CurrentFont);
  7574. $ptp_num_chars = $this->GetNumChars($ptpa);
  7575. $pagegroupnum = 0;
  7576. $groupnum = 0;
  7577. $ptgu = 1;
  7578. $ptga = 1;
  7579. $ptg_num_chars = 1;
  7580. for ($n = 1; $n <= $num_pages; ++$n) {
  7581. // get current page
  7582. $temppage = $this->getPageBuffer($n);
  7583. $pagelen = strlen($temppage);
  7584. // set replacements for total pages number
  7585. $pnpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $n - 1));
  7586. $pnpu = TCPDF_FONTS::UTF8ToUTF16BE($pnpa, false, $this->isunicode, $this->CurrentFont);
  7587. $pnp_num_chars = $this->GetNumChars($pnpa);
  7588. $pdiff = 0; // difference used for right shift alignment of page numbers
  7589. $gdiff = 0; // difference used for right shift alignment of page group numbers
  7590. if (!empty($this->pagegroups)) {
  7591. if (isset($this->newpagegroup[$n])) {
  7592. $pagegroupnum = 0;
  7593. ++$groupnum;
  7594. $ptga = TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]);
  7595. $ptgu = TCPDF_FONTS::UTF8ToUTF16BE($ptga, false, $this->isunicode, $this->CurrentFont);
  7596. $ptg_num_chars = $this->GetNumChars($ptga);
  7597. }
  7598. ++$pagegroupnum;
  7599. $pnga = TCPDF_STATIC::formatPageNumber($pagegroupnum);
  7600. $pngu = TCPDF_FONTS::UTF8ToUTF16BE($pnga, false, $this->isunicode, $this->CurrentFont);
  7601. $png_num_chars = $this->GetNumChars($pnga);
  7602. // replace page numbers
  7603. $replace = array();
  7604. $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
  7605. $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
  7606. $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
  7607. $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
  7608. list($temppage, $gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $gdiff);
  7609. }
  7610. // replace page numbers
  7611. $replace = array();
  7612. $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
  7613. $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
  7614. $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
  7615. $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
  7616. list($temppage, $pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $pdiff);
  7617. // replace right shift alias
  7618. $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
  7619. // replace EPS marker
  7620. $temppage = str_replace($this->epsmarker, '', $temppage);
  7621. //Page
  7622. $this->page_obj_id[$n] = $this->_newobj();
  7623. $out = '<<';
  7624. $out .= ' /Type /Page';
  7625. $out .= ' /Parent 1 0 R';
  7626. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  7627. $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp);
  7628. }
  7629. $out .= ' /Resources 2 0 R';
  7630. foreach ($this->page_boxes as $box) {
  7631. $out .= ' /'.$box;
  7632. $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']);
  7633. }
  7634. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7635. $out .= ' /BoxColorInfo <<';
  7636. foreach ($this->page_boxes as $box) {
  7637. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7638. $out .= ' /'.$box.' <<';
  7639. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7640. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7641. $out .= ' /C [';
  7642. $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  7643. $out .= ' ]';
  7644. }
  7645. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  7646. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  7647. }
  7648. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  7649. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  7650. }
  7651. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  7652. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  7653. $out .= ' /D [';
  7654. foreach ($dashes as $dash) {
  7655. $out .= sprintf(' %F', ($dash * $this->k));
  7656. }
  7657. $out .= ' ]';
  7658. }
  7659. $out .= ' >>';
  7660. }
  7661. }
  7662. $out .= ' >>';
  7663. }
  7664. $out .= ' /Contents '.($this->n + 1).' 0 R';
  7665. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  7666. if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  7667. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  7668. }
  7669. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  7670. // page transitions
  7671. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  7672. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  7673. }
  7674. $out .= ' /Trans <<';
  7675. $out .= ' /Type /Trans';
  7676. if (isset($this->pagedim[$n]['trans']['S'])) {
  7677. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  7678. }
  7679. if (isset($this->pagedim[$n]['trans']['D'])) {
  7680. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  7681. }
  7682. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  7683. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  7684. }
  7685. if (isset($this->pagedim[$n]['trans']['M'])) {
  7686. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  7687. }
  7688. if (isset($this->pagedim[$n]['trans']['Di'])) {
  7689. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  7690. }
  7691. if (isset($this->pagedim[$n]['trans']['SS'])) {
  7692. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  7693. }
  7694. if (isset($this->pagedim[$n]['trans']['B'])) {
  7695. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  7696. }
  7697. $out .= ' >>';
  7698. }
  7699. $out .= $this->_getannotsrefs($n);
  7700. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  7701. $out .= ' >>';
  7702. $out .= "\n".'endobj';
  7703. $this->_out($out);
  7704. //Page content
  7705. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  7706. $this->_newobj();
  7707. $p = $this->_getrawstream($p);
  7708. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  7709. }
  7710. //Pages root
  7711. $out = $this->_getobj(1)."\n";
  7712. $out .= '<< /Type /Pages /Kids [';
  7713. foreach($this->page_obj_id as $page_obj) {
  7714. $out .= ' '.$page_obj.' 0 R';
  7715. }
  7716. $out .= ' ] /Count '.$num_pages.' >>';
  7717. $out .= "\n".'endobj';
  7718. $this->_out($out);
  7719. }
  7720. /**
  7721. * Get references to page annotations.
  7722. * @param int $n page number
  7723. * @return string
  7724. * @protected
  7725. * @author Nicola Asuni
  7726. * @since 5.0.010 (2010-05-17)
  7727. */
  7728. protected function _getannotsrefs($n) {
  7729. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  7730. return '';
  7731. }
  7732. $out = ' /Annots [';
  7733. if (isset($this->PageAnnots[$n])) {
  7734. foreach ($this->PageAnnots[$n] as $key => $val) {
  7735. if (!in_array($val['n'], $this->radio_groups)) {
  7736. $out .= ' '.$val['n'].' 0 R';
  7737. }
  7738. }
  7739. // add radiobutton groups
  7740. if (isset($this->radiobutton_groups[$n])) {
  7741. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  7742. if (isset($data['n'])) {
  7743. $out .= ' '.$data['n'].' 0 R';
  7744. }
  7745. }
  7746. }
  7747. }
  7748. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  7749. // set reference for signature object
  7750. $out .= ' '.$this->sig_obj_id.' 0 R';
  7751. }
  7752. if (!empty($this->empty_signature_appearance)) {
  7753. foreach ($this->empty_signature_appearance as $esa) {
  7754. if ($esa['page'] == $n) {
  7755. // set reference for empty signature objects
  7756. $out .= ' '.$esa['objid'].' 0 R';
  7757. }
  7758. }
  7759. }
  7760. $out .= ' ]';
  7761. return $out;
  7762. }
  7763. /**
  7764. * Output annotations objects for all pages.
  7765. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  7766. * See section 12.5 of PDF 32000_2008 reference.
  7767. * @protected
  7768. * @author Nicola Asuni
  7769. * @since 4.0.018 (2008-08-06)
  7770. */
  7771. protected function _putannotsobjs() {
  7772. // reset object counter
  7773. for ($n=1; $n <= $this->numpages; ++$n) {
  7774. if (isset($this->PageAnnots[$n])) {
  7775. // set page annotations
  7776. foreach ($this->PageAnnots[$n] as $key => $pl) {
  7777. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  7778. // create annotation object for grouping radiobuttons
  7779. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  7780. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  7781. $annots = '<<';
  7782. $annots .= ' /Type /Annot';
  7783. $annots .= ' /Subtype /Widget';
  7784. $annots .= ' /Rect [0 0 0 0]';
  7785. if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  7786. // read only
  7787. $annots .= ' /F 68';
  7788. $annots .= ' /Ff 49153';
  7789. } else {
  7790. $annots .= ' /F 4'; // default print for PDF/A
  7791. $annots .= ' /Ff 49152';
  7792. }
  7793. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  7794. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  7795. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  7796. }
  7797. $annots .= ' /FT /Btn';
  7798. $annots .= ' /Kids [';
  7799. $defval = '';
  7800. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  7801. if (isset($data['kid'])) {
  7802. $annots .= ' '.$data['kid'].' 0 R';
  7803. if ($data['def'] !== 'Off') {
  7804. $defval = $data['def'];
  7805. }
  7806. }
  7807. }
  7808. $annots .= ' ]';
  7809. if (!empty($defval)) {
  7810. $annots .= ' /V /'.$defval;
  7811. }
  7812. $annots .= ' >>';
  7813. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  7814. $this->form_obj_id[] = $radio_button_obj_id;
  7815. // store object id to be used on Parent entry of Kids
  7816. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  7817. }
  7818. $formfield = false;
  7819. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  7820. $a = $pl['x'] * $this->k;
  7821. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  7822. $c = $pl['w'] * $this->k;
  7823. $d = $pl['h'] * $this->k;
  7824. $rect = sprintf('%F %F %F %F', $a, $b, $a+$c, $b+$d);
  7825. // create new annotation object
  7826. $annots = '<</Type /Annot';
  7827. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  7828. $annots .= ' /Rect ['.$rect.']';
  7829. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  7830. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  7831. $annots .= ' /FT /'.$pl['opt']['ft'];
  7832. $formfield = true;
  7833. }
  7834. if ($pl['opt']['subtype'] !== 'Link') {
  7835. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  7836. }
  7837. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  7838. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  7839. $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
  7840. if (isset($pl['opt']['f'])) {
  7841. $fval = 0;
  7842. if (is_array($pl['opt']['f'])) {
  7843. foreach ($pl['opt']['f'] as $f) {
  7844. switch (strtolower($f)) {
  7845. case 'invisible': {
  7846. $fval += 1 << 0;
  7847. break;
  7848. }
  7849. case 'hidden': {
  7850. $fval += 1 << 1;
  7851. break;
  7852. }
  7853. case 'print': {
  7854. $fval += 1 << 2;
  7855. break;
  7856. }
  7857. case 'nozoom': {
  7858. $fval += 1 << 3;
  7859. break;
  7860. }
  7861. case 'norotate': {
  7862. $fval += 1 << 4;
  7863. break;
  7864. }
  7865. case 'noview': {
  7866. $fval += 1 << 5;
  7867. break;
  7868. }
  7869. case 'readonly': {
  7870. $fval += 1 << 6;
  7871. break;
  7872. }
  7873. case 'locked': {
  7874. $fval += 1 << 8;
  7875. break;
  7876. }
  7877. case 'togglenoview': {
  7878. $fval += 1 << 9;
  7879. break;
  7880. }
  7881. case 'lockedcontents': {
  7882. $fval += 1 << 10;
  7883. break;
  7884. }
  7885. default: {
  7886. break;
  7887. }
  7888. }
  7889. }
  7890. } else {
  7891. $fval = intval($pl['opt']['f']);
  7892. }
  7893. } else {
  7894. $fval = 4;
  7895. }
  7896. if ($this->pdfa_mode) {
  7897. // force print flag for PDF/A mode
  7898. $fval |= 4;
  7899. }
  7900. $annots .= ' /F '.intval($fval);
  7901. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  7902. $annots .= ' /AS /'.$pl['opt']['as'];
  7903. }
  7904. if (isset($pl['opt']['ap'])) {
  7905. // appearance stream
  7906. $annots .= ' /AP <<';
  7907. if (is_array($pl['opt']['ap'])) {
  7908. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  7909. // $apmode can be: n = normal; r = rollover; d = down;
  7910. $annots .= ' /'.strtoupper($apmode);
  7911. if (is_array($apdef)) {
  7912. $annots .= ' <<';
  7913. foreach ($apdef as $apstate => $stream) {
  7914. // reference to XObject that define the appearance for this mode-state
  7915. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  7916. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  7917. }
  7918. $annots .= ' >>';
  7919. } else {
  7920. // reference to XObject that define the appearance for this mode
  7921. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  7922. $annots .= ' '.$apsobjid.' 0 R';
  7923. }
  7924. }
  7925. } else {
  7926. $annots .= $pl['opt']['ap'];
  7927. }
  7928. $annots .= ' >>';
  7929. }
  7930. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  7931. $annots .= ' /BS <<';
  7932. $annots .= ' /Type /Border';
  7933. if (isset($pl['opt']['bs']['w'])) {
  7934. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  7935. }
  7936. $bstyles = array('S', 'D', 'B', 'I', 'U');
  7937. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  7938. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7939. }
  7940. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  7941. $annots .= ' /D [';
  7942. foreach ($pl['opt']['bs']['d'] as $cord) {
  7943. $annots .= ' '.intval($cord);
  7944. }
  7945. $annots .= ']';
  7946. }
  7947. $annots .= ' >>';
  7948. } else {
  7949. $annots .= ' /Border [';
  7950. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  7951. $annots .= intval($pl['opt']['border'][0]).' ';
  7952. $annots .= intval($pl['opt']['border'][1]).' ';
  7953. $annots .= intval($pl['opt']['border'][2]);
  7954. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  7955. $annots .= ' [';
  7956. foreach ($pl['opt']['border'][3] as $dash) {
  7957. $annots .= intval($dash).' ';
  7958. }
  7959. $annots .= ']';
  7960. }
  7961. } else {
  7962. $annots .= '0 0 0';
  7963. }
  7964. $annots .= ']';
  7965. }
  7966. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  7967. $annots .= ' /BE <<';
  7968. $bstyles = array('S', 'C');
  7969. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  7970. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7971. } else {
  7972. $annots .= ' /S /S';
  7973. }
  7974. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  7975. $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
  7976. }
  7977. $annots .= '>>';
  7978. }
  7979. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  7980. $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']);
  7981. }
  7982. //$annots .= ' /StructParent ';
  7983. //$annots .= ' /OC ';
  7984. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  7985. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  7986. // this is a markup type
  7987. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  7988. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  7989. }
  7990. //$annots .= ' /Popup ';
  7991. if (isset($pl['opt']['ca'])) {
  7992. $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
  7993. }
  7994. if (isset($pl['opt']['rc'])) {
  7995. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  7996. }
  7997. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
  7998. //$annots .= ' /IRT ';
  7999. if (isset($pl['opt']['subj'])) {
  8000. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  8001. }
  8002. //$annots .= ' /RT ';
  8003. //$annots .= ' /IT ';
  8004. //$annots .= ' /ExData ';
  8005. }
  8006. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  8007. // Annotation types
  8008. switch (strtolower($pl['opt']['subtype'])) {
  8009. case 'text': {
  8010. if (isset($pl['opt']['open'])) {
  8011. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  8012. }
  8013. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  8014. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8015. $annots .= ' /Name /'.$pl['opt']['name'];
  8016. } else {
  8017. $annots .= ' /Name /Note';
  8018. }
  8019. $hasStateModel = isset($pl['opt']['statemodel']);
  8020. $hasState = isset($pl['opt']['state']);
  8021. $statemodels = array('Marked', 'Review');
  8022. if (!$hasStateModel && !$hasState) {
  8023. break;
  8024. }
  8025. if ($hasStateModel AND in_array($pl['opt']['statemodel'], $statemodels)) {
  8026. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8027. } else {
  8028. $pl['opt']['statemodel'] = 'Marked';
  8029. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8030. }
  8031. if ($pl['opt']['statemodel'] == 'Marked') {
  8032. $states = array('Accepted', 'Unmarked');
  8033. } else {
  8034. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  8035. }
  8036. if ($hasState AND in_array($pl['opt']['state'], $states)) {
  8037. $annots .= ' /State /'.$pl['opt']['state'];
  8038. } else {
  8039. if ($pl['opt']['statemodel'] == 'Marked') {
  8040. $annots .= ' /State /Unmarked';
  8041. } else {
  8042. $annots .= ' /State /None';
  8043. }
  8044. }
  8045. break;
  8046. }
  8047. case 'link': {
  8048. if (is_string($pl['txt']) && !empty($pl['txt'])) {
  8049. if ($pl['txt'][0] == '#') {
  8050. // internal destination
  8051. $annots .= ' /A <</S /GoTo /D /'.TCPDF_STATIC::encodeNameObject(substr($pl['txt'], 1)).'>>';
  8052. } elseif ($pl['txt'][0] == '%') {
  8053. // embedded PDF file
  8054. $filename = basename(substr($pl['txt'], 1));
  8055. $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  8056. } elseif ($pl['txt'][0] == '*') {
  8057. // embedded generic file
  8058. $filename = basename(substr($pl['txt'], 1));
  8059. $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});';
  8060. $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
  8061. } else {
  8062. $parsedUrl = parse_url($pl['txt']);
  8063. if (empty($parsedUrl['scheme']) AND (!empty($parsedUrl['path']) && strtolower(substr($parsedUrl['path'], -4)) == '.pdf')) {
  8064. // relative link to a PDF file
  8065. $dest = '[0 /Fit]'; // default page 0
  8066. if (!empty($parsedUrl['fragment'])) {
  8067. // check for named destination
  8068. $tmp = explode('=', $parsedUrl['fragment']);
  8069. $dest = '('.((count($tmp) == 2) ? $tmp[1] : $tmp[0]).')';
  8070. }
  8071. $annots .= ' /A <</S /GoToR /D '.$dest.' /F '.$this->_datastring($this->unhtmlentities($parsedUrl['path']), $annot_obj_id).' /NewWindow true>>';
  8072. } else {
  8073. // external URI link
  8074. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  8075. }
  8076. }
  8077. } elseif (isset($this->links[$pl['txt']])) {
  8078. // internal link ID
  8079. $l = $this->links[$pl['txt']];
  8080. if (isset($this->page_obj_id[($l['p'])])) {
  8081. $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)));
  8082. }
  8083. }
  8084. $hmodes = array('N', 'I', 'O', 'P');
  8085. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  8086. $annots .= ' /H /'.$pl['opt']['h'];
  8087. } else {
  8088. $annots .= ' /H /I';
  8089. }
  8090. //$annots .= ' /PA ';
  8091. //$annots .= ' /Quadpoints ';
  8092. break;
  8093. }
  8094. case 'freetext': {
  8095. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8096. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8097. }
  8098. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8099. $annots .= ' /Q '.intval($pl['opt']['q']);
  8100. }
  8101. if (isset($pl['opt']['rc'])) {
  8102. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8103. }
  8104. if (isset($pl['opt']['ds'])) {
  8105. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  8106. }
  8107. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  8108. $annots .= ' /CL [';
  8109. foreach ($pl['opt']['cl'] as $cl) {
  8110. $annots .= sprintf('%F ', $cl * $this->k);
  8111. }
  8112. $annots .= ']';
  8113. }
  8114. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  8115. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  8116. $annots .= ' /IT /'.$pl['opt']['it'];
  8117. }
  8118. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  8119. $l = $pl['opt']['rd'][0] * $this->k;
  8120. $r = $pl['opt']['rd'][1] * $this->k;
  8121. $t = $pl['opt']['rd'][2] * $this->k;
  8122. $b = $pl['opt']['rd'][3] * $this->k;
  8123. $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
  8124. }
  8125. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8126. $annots .= ' /LE /'.$pl['opt']['le'];
  8127. }
  8128. break;
  8129. }
  8130. case 'line': {
  8131. break;
  8132. }
  8133. case 'square': {
  8134. break;
  8135. }
  8136. case 'circle': {
  8137. break;
  8138. }
  8139. case 'polygon': {
  8140. break;
  8141. }
  8142. case 'polyline': {
  8143. break;
  8144. }
  8145. case 'highlight': {
  8146. break;
  8147. }
  8148. case 'underline': {
  8149. break;
  8150. }
  8151. case 'squiggly': {
  8152. break;
  8153. }
  8154. case 'strikeout': {
  8155. break;
  8156. }
  8157. case 'stamp': {
  8158. break;
  8159. }
  8160. case 'caret': {
  8161. break;
  8162. }
  8163. case 'ink': {
  8164. break;
  8165. }
  8166. case 'popup': {
  8167. break;
  8168. }
  8169. case 'fileattachment': {
  8170. if ($this->pdfa_mode && $this->pdfa_version != 3) {
  8171. // embedded files are not allowed in PDF/A mode version 1 and 2
  8172. break;
  8173. }
  8174. if (!isset($pl['opt']['fs'])) {
  8175. break;
  8176. }
  8177. $filename = basename($pl['opt']['fs']);
  8178. if (isset($this->embeddedfiles[$filename]['f'])) {
  8179. $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8180. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  8181. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8182. $annots .= ' /Name /'.$pl['opt']['name'];
  8183. } else {
  8184. $annots .= ' /Name /PushPin';
  8185. }
  8186. // index (zero-based) of the annotation in the Annots array of this page
  8187. $this->embeddedfiles[$filename]['a'] = $key;
  8188. }
  8189. break;
  8190. }
  8191. case 'sound': {
  8192. if (!isset($pl['opt']['fs'])) {
  8193. break;
  8194. }
  8195. $filename = basename($pl['opt']['fs']);
  8196. if (isset($this->embeddedfiles[$filename]['f'])) {
  8197. // ... TO BE COMPLETED ...
  8198. // /R /C /B /E /CO /CP
  8199. $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8200. $iconsapp = array('Speaker', 'Mic');
  8201. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8202. $annots .= ' /Name /'.$pl['opt']['name'];
  8203. } else {
  8204. $annots .= ' /Name /Speaker';
  8205. }
  8206. }
  8207. break;
  8208. }
  8209. case 'movie': {
  8210. break;
  8211. }
  8212. case 'widget': {
  8213. $hmode = array('N', 'I', 'O', 'P', 'T');
  8214. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8215. $annots .= ' /H /'.$pl['opt']['h'];
  8216. }
  8217. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8218. $annots .= ' /MK <<';
  8219. if (isset($pl['opt']['mk']['r'])) {
  8220. $annots .= ' /R '.$pl['opt']['mk']['r'];
  8221. }
  8222. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8223. $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']);
  8224. }
  8225. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8226. $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']);
  8227. }
  8228. if (isset($pl['opt']['mk']['ca'])) {
  8229. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8230. }
  8231. if (isset($pl['opt']['mk']['rc'])) {
  8232. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8233. }
  8234. if (isset($pl['opt']['mk']['ac'])) {
  8235. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8236. }
  8237. if (isset($pl['opt']['mk']['i'])) {
  8238. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  8239. if ($info !== false) {
  8240. $annots .= ' /I '.$info['n'].' 0 R';
  8241. }
  8242. }
  8243. if (isset($pl['opt']['mk']['ri'])) {
  8244. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  8245. if ($info !== false) {
  8246. $annots .= ' /RI '.$info['n'].' 0 R';
  8247. }
  8248. }
  8249. if (isset($pl['opt']['mk']['ix'])) {
  8250. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  8251. if ($info !== false) {
  8252. $annots .= ' /IX '.$info['n'].' 0 R';
  8253. }
  8254. }
  8255. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8256. $annots .= ' /IF <<';
  8257. $if_sw = array('A', 'B', 'S', 'N');
  8258. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8259. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8260. }
  8261. $if_s = array('A', 'P');
  8262. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8263. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8264. }
  8265. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8266. $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8267. }
  8268. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8269. $annots .= ' /FB true';
  8270. }
  8271. $annots .= '>>';
  8272. }
  8273. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8274. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8275. }
  8276. $annots .= '>>';
  8277. } // end MK
  8278. // --- Entries for field dictionaries ---
  8279. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8280. // set parent
  8281. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8282. }
  8283. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8284. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8285. }
  8286. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8287. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8288. }
  8289. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8290. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8291. }
  8292. if (isset($pl['opt']['ff'])) {
  8293. if (is_array($pl['opt']['ff'])) {
  8294. // array of bit settings
  8295. $flag = 0;
  8296. foreach($pl['opt']['ff'] as $val) {
  8297. $flag += 1 << ($val - 1);
  8298. }
  8299. } else {
  8300. $flag = intval($pl['opt']['ff']);
  8301. }
  8302. $annots .= ' /Ff '.$flag;
  8303. }
  8304. if (isset($pl['opt']['maxlen'])) {
  8305. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8306. }
  8307. if (isset($pl['opt']['v'])) {
  8308. $annots .= ' /V';
  8309. if (is_array($pl['opt']['v'])) {
  8310. foreach ($pl['opt']['v'] AS $optval) {
  8311. if (is_float($optval)) {
  8312. $optval = sprintf('%F', $optval);
  8313. }
  8314. $annots .= ' '.$optval;
  8315. }
  8316. } else {
  8317. $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  8318. }
  8319. }
  8320. if (isset($pl['opt']['dv'])) {
  8321. $annots .= ' /DV';
  8322. if (is_array($pl['opt']['dv'])) {
  8323. foreach ($pl['opt']['dv'] AS $optval) {
  8324. if (is_float($optval)) {
  8325. $optval = sprintf('%F', $optval);
  8326. }
  8327. $annots .= ' '.$optval;
  8328. }
  8329. } else {
  8330. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8331. }
  8332. }
  8333. if (isset($pl['opt']['rv'])) {
  8334. $annots .= ' /RV';
  8335. if (is_array($pl['opt']['rv'])) {
  8336. foreach ($pl['opt']['rv'] AS $optval) {
  8337. if (is_float($optval)) {
  8338. $optval = sprintf('%F', $optval);
  8339. }
  8340. $annots .= ' '.$optval;
  8341. }
  8342. } else {
  8343. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8344. }
  8345. }
  8346. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8347. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8348. }
  8349. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8350. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8351. }
  8352. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8353. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8354. }
  8355. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8356. $annots .= ' /Q '.intval($pl['opt']['q']);
  8357. }
  8358. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8359. $annots .= ' /Opt [';
  8360. foreach($pl['opt']['opt'] AS $copt) {
  8361. if (is_array($copt)) {
  8362. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8363. } else {
  8364. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  8365. }
  8366. }
  8367. $annots .= ']';
  8368. }
  8369. if (isset($pl['opt']['ti'])) {
  8370. $annots .= ' /TI '.intval($pl['opt']['ti']);
  8371. }
  8372. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8373. $annots .= ' /I [';
  8374. foreach($pl['opt']['i'] AS $copt) {
  8375. $annots .= intval($copt).' ';
  8376. }
  8377. $annots .= ']';
  8378. }
  8379. break;
  8380. }
  8381. case 'screen': {
  8382. break;
  8383. }
  8384. case 'printermark': {
  8385. break;
  8386. }
  8387. case 'trapnet': {
  8388. break;
  8389. }
  8390. case 'watermark': {
  8391. break;
  8392. }
  8393. case '3d': {
  8394. break;
  8395. }
  8396. default: {
  8397. break;
  8398. }
  8399. }
  8400. $annots .= '>>';
  8401. // create new annotation object
  8402. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8403. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8404. // store reference of form object
  8405. $this->form_obj_id[] = $annot_obj_id;
  8406. }
  8407. }
  8408. }
  8409. } // end for each page
  8410. }
  8411. /**
  8412. * Put appearance streams XObject used to define annotation's appearance states.
  8413. * @param int $w annotation width
  8414. * @param int $h annotation height
  8415. * @param string $stream appearance stream
  8416. * @return int object ID
  8417. * @protected
  8418. * @since 4.8.001 (2009-09-09)
  8419. */
  8420. protected function _putAPXObject($w=0, $h=0, $stream='') {
  8421. $stream = trim($stream);
  8422. $out = $this->_getobj()."\n";
  8423. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8424. $out .= '<<';
  8425. $out .= ' /Type /XObject';
  8426. $out .= ' /Subtype /Form';
  8427. $out .= ' /FormType 1';
  8428. if ($this->compress) {
  8429. $stream = gzcompress($stream);
  8430. $out .= ' /Filter /FlateDecode';
  8431. }
  8432. $rect = sprintf('%F %F', $w, $h);
  8433. $out .= ' /BBox [0 0 '.$rect.']';
  8434. $out .= ' /Matrix [1 0 0 1 0 0]';
  8435. $out .= ' /Resources 2 0 R';
  8436. $stream = $this->_getrawstream($stream);
  8437. $out .= ' /Length '.strlen($stream);
  8438. $out .= ' >>';
  8439. $out .= ' stream'."\n".$stream."\n".'endstream';
  8440. $out .= "\n".'endobj';
  8441. $this->_out($out);
  8442. return $this->n;
  8443. }
  8444. /**
  8445. * Output fonts.
  8446. * @author Nicola Asuni
  8447. * @protected
  8448. */
  8449. protected function _putfonts() {
  8450. $nf = $this->n;
  8451. foreach ($this->diffs as $diff) {
  8452. //Encodings
  8453. $this->_newobj();
  8454. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  8455. }
  8456. $mqr = TCPDF_STATIC::get_mqr();
  8457. TCPDF_STATIC::set_mqr(false);
  8458. foreach ($this->FontFiles as $file => $info) {
  8459. // search and get font file to embedd
  8460. $fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']);
  8461. if (!TCPDF_STATIC::empty_string($fontfile)) {
  8462. $font = file_get_contents($fontfile);
  8463. $compressed = (substr($file, -2) == '.z');
  8464. if ((!$compressed) AND (isset($info['length2']))) {
  8465. $header = (ord($font[0]) == 128);
  8466. if ($header) {
  8467. // strip first binary header
  8468. $font = substr($font, 6);
  8469. }
  8470. if ($header AND (ord($font[$info['length1']]) == 128)) {
  8471. // strip second binary header
  8472. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  8473. }
  8474. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  8475. if ($compressed) {
  8476. // uncompress font
  8477. $font = gzuncompress($font);
  8478. }
  8479. // merge subset characters
  8480. $subsetchars = array(); // used chars
  8481. foreach ($info['fontkeys'] as $fontkey) {
  8482. $fontinfo = $this->getFontBuffer($fontkey);
  8483. $subsetchars += $fontinfo['subsetchars'];
  8484. }
  8485. // rebuild a font subset
  8486. $font = TCPDF_FONTS::_getTrueTypeFontSubset($font, $subsetchars);
  8487. // calculate new font length
  8488. $info['length1'] = strlen($font);
  8489. if ($compressed) {
  8490. // recompress font
  8491. $font = gzcompress($font);
  8492. }
  8493. }
  8494. $this->_newobj();
  8495. $this->FontFiles[$file]['n'] = $this->n;
  8496. $stream = $this->_getrawstream($font);
  8497. $out = '<< /Length '.strlen($stream);
  8498. if ($compressed) {
  8499. $out .= ' /Filter /FlateDecode';
  8500. }
  8501. $out .= ' /Length1 '.$info['length1'];
  8502. if (isset($info['length2'])) {
  8503. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  8504. }
  8505. $out .= ' >>';
  8506. $out .= ' stream'."\n".$stream."\n".'endstream';
  8507. $out .= "\n".'endobj';
  8508. $this->_out($out);
  8509. }
  8510. }
  8511. TCPDF_STATIC::set_mqr($mqr);
  8512. foreach ($this->fontkeys as $k) {
  8513. //Font objects
  8514. $font = $this->getFontBuffer($k);
  8515. $type = $font['type'];
  8516. $name = $font['name'];
  8517. if ($type == 'core') {
  8518. // standard core font
  8519. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8520. $out .= '<</Type /Font';
  8521. $out .= ' /Subtype /Type1';
  8522. $out .= ' /BaseFont /'.$name;
  8523. $out .= ' /Name /F'.$font['i'];
  8524. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  8525. $out .= ' /Encoding /WinAnsiEncoding';
  8526. }
  8527. if ($k == 'helvetica') {
  8528. // add default font for annotations
  8529. $this->annotation_fonts[$k] = $font['i'];
  8530. }
  8531. $out .= ' >>';
  8532. $out .= "\n".'endobj';
  8533. $this->_out($out);
  8534. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  8535. // additional Type1 or TrueType font
  8536. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8537. $out .= '<</Type /Font';
  8538. $out .= ' /Subtype /'.$type;
  8539. $out .= ' /BaseFont /'.$name;
  8540. $out .= ' /Name /F'.$font['i'];
  8541. $out .= ' /FirstChar 32 /LastChar 255';
  8542. $out .= ' /Widths '.($this->n + 1).' 0 R';
  8543. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  8544. if ($font['enc']) {
  8545. if (isset($font['diff'])) {
  8546. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  8547. } else {
  8548. $out .= ' /Encoding /WinAnsiEncoding';
  8549. }
  8550. }
  8551. $out .= ' >>';
  8552. $out .= "\n".'endobj';
  8553. $this->_out($out);
  8554. // Widths
  8555. $this->_newobj();
  8556. $s = '[';
  8557. for ($i = 32; $i < 256; ++$i) {
  8558. if (isset($font['cw'][$i])) {
  8559. $s .= $font['cw'][$i].' ';
  8560. } else {
  8561. $s .= $font['dw'].' ';
  8562. }
  8563. }
  8564. $s .= ']';
  8565. $s .= "\n".'endobj';
  8566. $this->_out($s);
  8567. //Descriptor
  8568. $this->_newobj();
  8569. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8570. foreach ($font['desc'] as $fdk => $fdv) {
  8571. if (is_float($fdv)) {
  8572. $fdv = sprintf('%F', $fdv);
  8573. }
  8574. $s .= ' /'.$fdk.' '.$fdv.'';
  8575. }
  8576. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8577. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8578. }
  8579. $s .= '>>';
  8580. $s .= "\n".'endobj';
  8581. $this->_out($s);
  8582. } else {
  8583. // additional types
  8584. $mtd = '_put'.strtolower($type);
  8585. if (!method_exists($this, $mtd)) {
  8586. $this->Error('Unsupported font type: '.$type);
  8587. }
  8588. $this->$mtd($font);
  8589. }
  8590. }
  8591. }
  8592. /**
  8593. * Adds unicode fonts.<br>
  8594. * Based on PDF Reference 1.3 (section 5)
  8595. * @param array $font font data
  8596. * @protected
  8597. * @author Nicola Asuni
  8598. * @since 1.52.0.TC005 (2005-01-05)
  8599. */
  8600. protected function _puttruetypeunicode($font) {
  8601. $fontname = '';
  8602. if ($font['subset']) {
  8603. // change name for font subsetting
  8604. $subtag = sprintf('%06u', $font['i']);
  8605. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  8606. $fontname .= $subtag.'+';
  8607. }
  8608. $fontname .= $font['name'];
  8609. // Type0 Font
  8610. // A composite font composed of other fonts, organized hierarchically
  8611. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8612. $out .= '<< /Type /Font';
  8613. $out .= ' /Subtype /Type0';
  8614. $out .= ' /BaseFont /'.$fontname;
  8615. $out .= ' /Name /F'.$font['i'];
  8616. $out .= ' /Encoding /'.$font['enc'];
  8617. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  8618. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  8619. $out .= ' >>';
  8620. $out .= "\n".'endobj';
  8621. $this->_out($out);
  8622. // ToUnicode map for Identity-H
  8623. $stream = TCPDF_FONT_DATA::$uni_identity_h;
  8624. // ToUnicode Object
  8625. $this->_newobj();
  8626. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  8627. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8628. $stream = $this->_getrawstream($stream);
  8629. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  8630. // CIDFontType2
  8631. // A CIDFont whose glyph descriptions are based on TrueType font technology
  8632. $oid = $this->_newobj();
  8633. $out = '<< /Type /Font';
  8634. $out .= ' /Subtype /CIDFontType2';
  8635. $out .= ' /BaseFont /'.$fontname;
  8636. // A dictionary containing entries that define the character collection of the CIDFont.
  8637. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8638. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8639. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8640. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  8641. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8642. $out .= ' /DW '.$font['dw']; // default width
  8643. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, 0);
  8644. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8645. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  8646. }
  8647. $out .= ' >>';
  8648. $out .= "\n".'endobj';
  8649. $this->_out($out);
  8650. // Font descriptor
  8651. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  8652. $this->_newobj();
  8653. $out = '<< /Type /FontDescriptor';
  8654. $out .= ' /FontName /'.$fontname;
  8655. foreach ($font['desc'] as $key => $value) {
  8656. if (is_float($value)) {
  8657. $value = sprintf('%F', $value);
  8658. }
  8659. $out .= ' /'.$key.' '.$value;
  8660. }
  8661. $fontdir = false;
  8662. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8663. // A stream containing a TrueType font
  8664. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8665. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  8666. }
  8667. $out .= ' >>';
  8668. $out .= "\n".'endobj';
  8669. $this->_out($out);
  8670. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8671. $this->_newobj();
  8672. // Embed CIDToGIDMap
  8673. // A specification of the mapping from CIDs to glyph indices
  8674. // search and get CTG font file to embedd
  8675. $ctgfile = strtolower($font['ctg']);
  8676. // search and get ctg font file to embedd
  8677. $fontfile = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir);
  8678. if (TCPDF_STATIC::empty_string($fontfile)) {
  8679. $this->Error('Font file not found: '.$ctgfile);
  8680. }
  8681. $stream = $this->_getrawstream(file_get_contents($fontfile));
  8682. $out = '<< /Length '.strlen($stream).'';
  8683. if (substr($fontfile, -2) == '.z') { // check file extension
  8684. // Decompresses data encoded using the public-domain
  8685. // zlib/deflate compression method, reproducing the
  8686. // original text or binary data
  8687. $out .= ' /Filter /FlateDecode';
  8688. }
  8689. $out .= ' >>';
  8690. $out .= ' stream'."\n".$stream."\n".'endstream';
  8691. $out .= "\n".'endobj';
  8692. $this->_out($out);
  8693. }
  8694. }
  8695. /**
  8696. * Output CID-0 fonts.
  8697. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  8698. * @param array $font font data
  8699. * @protected
  8700. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  8701. * @since 3.2.000 (2008-06-23)
  8702. */
  8703. protected function _putcidfont0($font) {
  8704. $cidoffset = 0;
  8705. if (!isset($font['cw'][1])) {
  8706. $cidoffset = 31;
  8707. }
  8708. if (isset($font['cidinfo']['uni2cid'])) {
  8709. // convert unicode to cid.
  8710. $uni2cid = $font['cidinfo']['uni2cid'];
  8711. $cw = array();
  8712. foreach ($font['cw'] as $uni => $width) {
  8713. if (isset($uni2cid[$uni])) {
  8714. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  8715. } elseif ($uni < 256) {
  8716. $cw[$uni] = $width;
  8717. } // else unknown character
  8718. }
  8719. $font = array_merge($font, array('cw' => $cw));
  8720. }
  8721. $name = $font['name'];
  8722. $enc = $font['enc'];
  8723. if ($enc) {
  8724. $longname = $name.'-'.$enc;
  8725. } else {
  8726. $longname = $name;
  8727. }
  8728. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8729. $out .= '<</Type /Font';
  8730. $out .= ' /Subtype /Type0';
  8731. $out .= ' /BaseFont /'.$longname;
  8732. $out .= ' /Name /F'.$font['i'];
  8733. if ($enc) {
  8734. $out .= ' /Encoding /'.$enc;
  8735. }
  8736. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  8737. $out .= ' >>';
  8738. $out .= "\n".'endobj';
  8739. $this->_out($out);
  8740. $oid = $this->_newobj();
  8741. $out = '<</Type /Font';
  8742. $out .= ' /Subtype /CIDFontType0';
  8743. $out .= ' /BaseFont /'.$name;
  8744. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8745. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8746. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8747. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  8748. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8749. $out .= ' /DW '.$font['dw'];
  8750. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, $cidoffset);
  8751. $out .= ' >>';
  8752. $out .= "\n".'endobj';
  8753. $this->_out($out);
  8754. $this->_newobj();
  8755. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8756. foreach ($font['desc'] as $k => $v) {
  8757. if ($k != 'Style') {
  8758. if (is_float($v)) {
  8759. $v = sprintf('%F', $v);
  8760. }
  8761. $s .= ' /'.$k.' '.$v.'';
  8762. }
  8763. }
  8764. $s .= '>>';
  8765. $s .= "\n".'endobj';
  8766. $this->_out($s);
  8767. }
  8768. /**
  8769. * Output images.
  8770. * @protected
  8771. */
  8772. protected function _putimages() {
  8773. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8774. foreach ($this->imagekeys as $file) {
  8775. $info = $this->getImageBuffer($file);
  8776. // set object for alternate images array
  8777. if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
  8778. $altoid = $this->_newobj();
  8779. $out = '[';
  8780. foreach ($info['altimgs'] as $altimage) {
  8781. if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
  8782. $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
  8783. $out .= ' /DefaultForPrinting';
  8784. if ($altimage[1] === true) {
  8785. $out .= ' true';
  8786. } else {
  8787. $out .= ' false';
  8788. }
  8789. $out .= ' >>';
  8790. }
  8791. }
  8792. $out .= ' ]';
  8793. $out .= "\n".'endobj';
  8794. $this->_out($out);
  8795. }
  8796. // set image object
  8797. $oid = $this->_newobj();
  8798. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  8799. $this->setImageSubBuffer($file, 'n', $this->n);
  8800. $out = '<</Type /XObject';
  8801. $out .= ' /Subtype /Image';
  8802. $out .= ' /Width '.$info['w'];
  8803. $out .= ' /Height '.$info['h'];
  8804. if (array_key_exists('masked', $info)) {
  8805. $out .= ' /SMask '.($this->n - 1).' 0 R';
  8806. }
  8807. // set color space
  8808. $icc = false;
  8809. if (isset($info['icc']) AND ($info['icc'] !== false)) {
  8810. // ICC Colour Space
  8811. $icc = true;
  8812. $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
  8813. } elseif ($info['cs'] == 'Indexed') {
  8814. // Indexed Colour Space
  8815. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  8816. } else {
  8817. // Device Colour Space
  8818. $out .= ' /ColorSpace /'.$info['cs'];
  8819. }
  8820. if ($info['cs'] == 'DeviceCMYK') {
  8821. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  8822. }
  8823. $out .= ' /BitsPerComponent '.$info['bpc'];
  8824. if (isset($altoid) AND ($altoid > 0)) {
  8825. // reference to alternate images dictionary
  8826. $out .= ' /Alternates '.$altoid.' 0 R';
  8827. }
  8828. if (isset($info['exurl']) AND !empty($info['exurl'])) {
  8829. // external stream
  8830. $out .= ' /Length 0';
  8831. $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
  8832. if (isset($info['f'])) {
  8833. $out .= ' /FFilter /'.$info['f'];
  8834. }
  8835. $out .= ' >>';
  8836. $out .= ' stream'."\n".'endstream';
  8837. } else {
  8838. if (isset($info['f'])) {
  8839. $out .= ' /Filter /'.$info['f'];
  8840. }
  8841. if (isset($info['parms'])) {
  8842. $out .= ' '.$info['parms'];
  8843. }
  8844. if (isset($info['trns']) AND is_array($info['trns'])) {
  8845. $trns = '';
  8846. $count_info = count($info['trns']);
  8847. if ($info['cs'] == 'Indexed') {
  8848. $maxval =(pow(2, $info['bpc']) - 1);
  8849. for ($i = 0; $i < $count_info; ++$i) {
  8850. if (($info['trns'][$i] != 0) AND ($info['trns'][$i] != $maxval)) {
  8851. // this is not a binary type mask @TODO: create a SMask
  8852. $trns = '';
  8853. break;
  8854. } elseif (empty($trns) AND ($info['trns'][$i] == 0)) {
  8855. // store the first fully transparent value
  8856. $trns .= $i.' '.$i.' ';
  8857. }
  8858. }
  8859. } else {
  8860. // grayscale or RGB
  8861. for ($i = 0; $i < $count_info; ++$i) {
  8862. if ($info['trns'][$i] == 0) {
  8863. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  8864. }
  8865. }
  8866. }
  8867. // Colour Key Masking
  8868. if (!empty($trns)) {
  8869. $out .= ' /Mask ['.$trns.']';
  8870. }
  8871. }
  8872. $stream = $this->_getrawstream($info['data']);
  8873. $out .= ' /Length '.strlen($stream).' >>';
  8874. $out .= ' stream'."\n".$stream."\n".'endstream';
  8875. }
  8876. $out .= "\n".'endobj';
  8877. $this->_out($out);
  8878. if ($icc) {
  8879. // ICC colour profile
  8880. $this->_newobj();
  8881. $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
  8882. $icc = $this->_getrawstream($icc);
  8883. $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  8884. } elseif ($info['cs'] == 'Indexed') {
  8885. // colour palette
  8886. $this->_newobj();
  8887. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  8888. $pal = $this->_getrawstream($pal);
  8889. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  8890. }
  8891. }
  8892. }
  8893. /**
  8894. * Output Form XObjects Templates.
  8895. * @author Nicola Asuni
  8896. * @since 5.8.017 (2010-08-24)
  8897. * @protected
  8898. * @see startTemplate(), endTemplate(), printTemplate()
  8899. */
  8900. protected function _putxobjects() {
  8901. foreach ($this->xobjects as $key => $data) {
  8902. if (isset($data['outdata'])) {
  8903. $stream = str_replace($this->epsmarker, '', trim($data['outdata']));
  8904. $out = $this->_getobj($data['n'])."\n";
  8905. $out .= '<<';
  8906. $out .= ' /Type /XObject';
  8907. $out .= ' /Subtype /Form';
  8908. $out .= ' /FormType 1';
  8909. if ($this->compress) {
  8910. $stream = gzcompress($stream);
  8911. $out .= ' /Filter /FlateDecode';
  8912. }
  8913. $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));
  8914. $out .= ' /Matrix [1 0 0 1 0 0]';
  8915. $out .= ' /Resources <<';
  8916. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8917. if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  8918. // transparency
  8919. if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
  8920. $out .= ' /ExtGState <<';
  8921. foreach ($data['extgstates'] as $k => $extgstate) {
  8922. if (isset($this->extgstates[$k]['name'])) {
  8923. $out .= ' /'.$this->extgstates[$k]['name'];
  8924. } else {
  8925. $out .= ' /GS'.$k;
  8926. }
  8927. $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
  8928. }
  8929. $out .= ' >>';
  8930. }
  8931. if (isset($data['gradients']) AND !empty($data['gradients'])) {
  8932. $gp = '';
  8933. $gs = '';
  8934. foreach ($data['gradients'] as $id => $grad) {
  8935. // gradient patterns
  8936. $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
  8937. // gradient shadings
  8938. $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
  8939. }
  8940. $out .= ' /Pattern <<'.$gp.' >>';
  8941. $out .= ' /Shading <<'.$gs.' >>';
  8942. }
  8943. }
  8944. // spot colors
  8945. if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
  8946. $out .= ' /ColorSpace <<';
  8947. foreach ($data['spot_colors'] as $name => $color) {
  8948. $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
  8949. }
  8950. $out .= ' >>';
  8951. }
  8952. // fonts
  8953. if (!empty($data['fonts'])) {
  8954. $out .= ' /Font <<';
  8955. foreach ($data['fonts'] as $fontkey => $fontid) {
  8956. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  8957. }
  8958. $out .= ' >>';
  8959. }
  8960. // images or nested xobjects
  8961. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  8962. $out .= ' /XObject <<';
  8963. foreach ($data['images'] as $imgid) {
  8964. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  8965. }
  8966. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  8967. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  8968. }
  8969. $out .= ' >>';
  8970. }
  8971. $out .= ' >>'; //end resources
  8972. if (isset($data['group']) AND ($data['group'] !== false)) {
  8973. // set transparency group
  8974. $out .= ' /Group << /Type /Group /S /Transparency';
  8975. if (is_array($data['group'])) {
  8976. if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
  8977. $out .= ' /CS /'.$data['group']['CS'];
  8978. }
  8979. if (isset($data['group']['I'])) {
  8980. $out .= ' /I /'.($data['group']['I']===true?'true':'false');
  8981. }
  8982. if (isset($data['group']['K'])) {
  8983. $out .= ' /K /'.($data['group']['K']===true?'true':'false');
  8984. }
  8985. }
  8986. $out .= ' >>';
  8987. }
  8988. $stream = $this->_getrawstream($stream, $data['n']);
  8989. $out .= ' /Length '.strlen($stream);
  8990. $out .= ' >>';
  8991. $out .= ' stream'."\n".$stream."\n".'endstream';
  8992. $out .= "\n".'endobj';
  8993. $this->_out($out);
  8994. }
  8995. }
  8996. }
  8997. /**
  8998. * Output Spot Colors Resources.
  8999. * @protected
  9000. * @since 4.0.024 (2008-09-12)
  9001. */
  9002. protected function _putspotcolors() {
  9003. foreach ($this->spot_colors as $name => $color) {
  9004. $this->_newobj();
  9005. $this->spot_colors[$name]['n'] = $this->n;
  9006. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  9007. $out .= ' /DeviceCMYK <<';
  9008. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  9009. $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
  9010. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  9011. $out .= "\n".'endobj';
  9012. $this->_out($out);
  9013. }
  9014. }
  9015. /**
  9016. * Return XObjects Dictionary.
  9017. * @return string XObjects dictionary
  9018. * @protected
  9019. * @since 5.8.014 (2010-08-23)
  9020. */
  9021. protected function _getxobjectdict() {
  9022. $out = '';
  9023. foreach ($this->xobjects as $id => $objid) {
  9024. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  9025. }
  9026. return $out;
  9027. }
  9028. /**
  9029. * Output Resources Dictionary.
  9030. * @protected
  9031. */
  9032. protected function _putresourcedict() {
  9033. $out = $this->_getobj(2)."\n";
  9034. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  9035. $out .= ' /Font <<';
  9036. foreach ($this->fontkeys as $fontkey) {
  9037. $font = $this->getFontBuffer($fontkey);
  9038. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  9039. }
  9040. $out .= ' >>';
  9041. $out .= ' /XObject <<';
  9042. $out .= $this->_getxobjectdict();
  9043. $out .= ' >>';
  9044. // layers
  9045. if (!empty($this->pdflayers)) {
  9046. $out .= ' /Properties <<';
  9047. foreach ($this->pdflayers as $layer) {
  9048. $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
  9049. }
  9050. $out .= ' >>';
  9051. }
  9052. if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  9053. // transparency
  9054. if (isset($this->extgstates) AND !empty($this->extgstates)) {
  9055. $out .= ' /ExtGState <<';
  9056. foreach ($this->extgstates as $k => $extgstate) {
  9057. if (isset($extgstate['name'])) {
  9058. $out .= ' /'.$extgstate['name'];
  9059. } else {
  9060. $out .= ' /GS'.$k;
  9061. }
  9062. $out .= ' '.$extgstate['n'].' 0 R';
  9063. }
  9064. $out .= ' >>';
  9065. }
  9066. if (isset($this->gradients) AND !empty($this->gradients)) {
  9067. $gp = '';
  9068. $gs = '';
  9069. foreach ($this->gradients as $id => $grad) {
  9070. // gradient patterns
  9071. $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  9072. // gradient shadings
  9073. $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  9074. }
  9075. $out .= ' /Pattern <<'.$gp.' >>';
  9076. $out .= ' /Shading <<'.$gs.' >>';
  9077. }
  9078. }
  9079. // spot colors
  9080. if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
  9081. $out .= ' /ColorSpace <<';
  9082. foreach ($this->spot_colors as $color) {
  9083. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  9084. }
  9085. $out .= ' >>';
  9086. }
  9087. $out .= ' >>';
  9088. $out .= "\n".'endobj';
  9089. $this->_out($out);
  9090. }
  9091. /**
  9092. * Output Resources.
  9093. * @protected
  9094. */
  9095. protected function _putresources() {
  9096. $this->_putextgstates();
  9097. $this->_putocg();
  9098. $this->_putfonts();
  9099. $this->_putimages();
  9100. $this->_putspotcolors();
  9101. $this->_putshaders();
  9102. $this->_putxobjects();
  9103. $this->_putresourcedict();
  9104. $this->_putdests();
  9105. $this->_putEmbeddedFiles();
  9106. $this->_putannotsobjs();
  9107. $this->_putjavascript();
  9108. $this->_putbookmarks();
  9109. $this->_putencryption();
  9110. }
  9111. /**
  9112. * Adds some Metadata information (Document Information Dictionary)
  9113. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  9114. * @return int object id
  9115. * @protected
  9116. */
  9117. protected function _putinfo() {
  9118. $oid = $this->_newobj();
  9119. $out = '<<';
  9120. // store current isunicode value
  9121. $prev_isunicode = $this->isunicode;
  9122. if ($this->docinfounicode) {
  9123. $this->isunicode = true;
  9124. }
  9125. if (!TCPDF_STATIC::empty_string($this->title)) {
  9126. // The document's title.
  9127. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  9128. }
  9129. if (!TCPDF_STATIC::empty_string($this->author)) {
  9130. // The name of the person who created the document.
  9131. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  9132. }
  9133. if (!TCPDF_STATIC::empty_string($this->subject)) {
  9134. // The subject of the document.
  9135. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  9136. }
  9137. if (!TCPDF_STATIC::empty_string($this->keywords)) {
  9138. // Keywords associated with the document.
  9139. $out .= ' /Keywords '.$this->_textstring($this->keywords, $oid);
  9140. }
  9141. if (!TCPDF_STATIC::empty_string($this->creator)) {
  9142. // 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.
  9143. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  9144. }
  9145. // restore previous isunicode value
  9146. $this->isunicode = $prev_isunicode;
  9147. // default producer
  9148. $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid);
  9149. // The date and time the document was created, in human-readable form
  9150. $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp);
  9151. // The date and time the document was most recently modified, in human-readable form
  9152. $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp);
  9153. // A name object indicating whether the document has been modified to include trapping information
  9154. $out .= ' /Trapped /False';
  9155. $out .= ' >>';
  9156. $out .= "\n".'endobj';
  9157. $this->_out($out);
  9158. return $oid;
  9159. }
  9160. /**
  9161. * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
  9162. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9163. * @param string $xmp Custom XMP data.
  9164. * @since 5.9.128 (2011-10-06)
  9165. * @public
  9166. */
  9167. public function setExtraXMP($xmp) {
  9168. $this->custom_xmp = $xmp;
  9169. }
  9170. /**
  9171. * Set additional XMP data to be added on the default XMP data just before the end of "rdf:RDF" tag.
  9172. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9173. * @param string $xmp Custom XMP RDF data.
  9174. * @since 6.3.0 (2019-09-19)
  9175. * @public
  9176. */
  9177. public function setExtraXMPRDF($xmp) {
  9178. $this->custom_xmp_rdf = $xmp;
  9179. }
  9180. /**
  9181. * Put XMP data object and return ID.
  9182. * @return int The object ID.
  9183. * @since 5.9.121 (2011-09-28)
  9184. * @protected
  9185. */
  9186. protected function _putXMP() {
  9187. $oid = $this->_newobj();
  9188. // store current isunicode value
  9189. $prev_isunicode = $this->isunicode;
  9190. $this->isunicode = true;
  9191. $prev_encrypted = $this->encrypted;
  9192. $this->encrypted = false;
  9193. // set XMP data
  9194. $xmp = '<?xpacket begin="'.TCPDF_FONTS::unichr(0xfeff, $this->isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
  9195. $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";
  9196. $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  9197. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  9198. $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
  9199. $xmp .= "\t\t\t".'<dc:title>'."\n";
  9200. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9201. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->title).'</rdf:li>'."\n";
  9202. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9203. $xmp .= "\t\t\t".'</dc:title>'."\n";
  9204. $xmp .= "\t\t\t".'<dc:creator>'."\n";
  9205. $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
  9206. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->author).'</rdf:li>'."\n";
  9207. $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
  9208. $xmp .= "\t\t\t".'</dc:creator>'."\n";
  9209. $xmp .= "\t\t\t".'<dc:description>'."\n";
  9210. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9211. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->subject).'</rdf:li>'."\n";
  9212. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9213. $xmp .= "\t\t\t".'</dc:description>'."\n";
  9214. $xmp .= "\t\t\t".'<dc:subject>'."\n";
  9215. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9216. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->keywords).'</rdf:li>'."\n";
  9217. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9218. $xmp .= "\t\t\t".'</dc:subject>'."\n";
  9219. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9220. // convert doc creation date format
  9221. $dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
  9222. $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
  9223. $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
  9224. $doccreationdate .= substr($dcdate, 14, 3).':'.substr($dcdate, 18, 2);
  9225. $doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate);
  9226. // convert doc modification date format
  9227. $dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
  9228. $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
  9229. $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
  9230. $docmoddate .= substr($dmdate, 14, 3).':'.substr($dmdate, 18, 2);
  9231. $docmoddate = TCPDF_STATIC::_escapeXML($docmoddate);
  9232. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  9233. $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
  9234. $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  9235. $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
  9236. $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
  9237. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9238. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  9239. $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC::_escapeXML($this->keywords).'</pdf:Keywords>'."\n";
  9240. $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).'</pdf:Producer>'."\n";
  9241. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9242. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  9243. $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);
  9244. $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
  9245. $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
  9246. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9247. if ($this->pdfa_mode) {
  9248. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
  9249. $xmp .= "\t\t\t".'<pdfaid:part>'.$this->pdfa_version.'</pdfaid:part>'."\n";
  9250. $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
  9251. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9252. }
  9253. // XMP extension schemas
  9254. $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";
  9255. $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
  9256. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9257. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9258. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
  9259. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
  9260. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
  9261. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9262. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9263. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9264. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9265. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Adobe PDF Schema</pdfaProperty:description>'."\n";
  9266. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9267. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9268. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9269. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9270. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9271. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9272. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9273. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
  9274. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
  9275. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
  9276. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9277. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9278. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9279. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9280. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
  9281. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9282. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9283. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9284. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9285. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9286. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9287. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9288. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
  9289. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
  9290. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
  9291. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9292. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9293. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9294. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9295. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
  9296. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
  9297. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
  9298. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9299. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9300. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9301. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
  9302. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
  9303. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9304. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9305. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9306. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9307. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
  9308. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
  9309. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9310. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9311. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9312. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9313. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9314. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9315. $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
  9316. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9317. $xmp .= $this->custom_xmp_rdf;
  9318. $xmp .= "\t".'</rdf:RDF>'."\n";
  9319. $xmp .= $this->custom_xmp;
  9320. $xmp .= '</x:xmpmeta>'."\n";
  9321. $xmp .= '<?xpacket end="w"?>';
  9322. $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
  9323. // restore previous isunicode value
  9324. $this->isunicode = $prev_isunicode;
  9325. $this->encrypted = $prev_encrypted;
  9326. $this->_out($out);
  9327. return $oid;
  9328. }
  9329. /**
  9330. * Output Catalog.
  9331. * @return int object id
  9332. * @protected
  9333. */
  9334. protected function _putcatalog() {
  9335. // put XMP
  9336. $xmpobj = $this->_putXMP();
  9337. // if required, add standard sRGB ICC colour profile
  9338. if ($this->pdfa_mode OR $this->force_srgb) {
  9339. $iccobj = $this->_newobj();
  9340. $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
  9341. $filter = '';
  9342. if ($this->compress) {
  9343. $filter = ' /Filter /FlateDecode';
  9344. $icc = gzcompress($icc);
  9345. }
  9346. $icc = $this->_getrawstream($icc);
  9347. $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  9348. }
  9349. // start catalog
  9350. $oid = $this->_newobj();
  9351. $out = '<< /Type /Catalog';
  9352. $out .= ' /Version /'.$this->PDFVersion;
  9353. //$out .= ' /Extensions <<>>';
  9354. $out .= ' /Pages 1 0 R';
  9355. //$out .= ' /PageLabels ' //...;
  9356. $out .= ' /Names <<';
  9357. if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
  9358. $out .= ' /JavaScript '.$this->n_js;
  9359. }
  9360. if (!empty($this->efnames)) {
  9361. $out .= ' /EmbeddedFiles <</Names [';
  9362. foreach ($this->efnames AS $fn => $fref) {
  9363. $out .= ' '.$this->_datastring($fn).' '.$fref;
  9364. }
  9365. $out .= ' ]>>';
  9366. }
  9367. $out .= ' >>';
  9368. if (!empty($this->dests)) {
  9369. $out .= ' /Dests '.($this->n_dests).' 0 R';
  9370. }
  9371. $out .= $this->_putviewerpreferences();
  9372. if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) {
  9373. $out .= ' /PageLayout /'.$this->LayoutMode;
  9374. }
  9375. if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) {
  9376. $out .= ' /PageMode /'.$this->PageMode;
  9377. }
  9378. if (count($this->outlines) > 0) {
  9379. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  9380. $out .= ' /PageMode /UseOutlines';
  9381. }
  9382. //$out .= ' /Threads []';
  9383. if ($this->ZoomMode == 'fullpage') {
  9384. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  9385. } elseif ($this->ZoomMode == 'fullwidth') {
  9386. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  9387. } elseif ($this->ZoomMode == 'real') {
  9388. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  9389. } elseif (!is_string($this->ZoomMode)) {
  9390. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode / 100));
  9391. }
  9392. //$out .= ' /AA <<>>';
  9393. //$out .= ' /URI <<>>';
  9394. $out .= ' /Metadata '.$xmpobj.' 0 R';
  9395. //$out .= ' /StructTreeRoot <<>>';
  9396. //$out .= ' /MarkInfo <<>>';
  9397. if (isset($this->l['a_meta_language'])) {
  9398. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  9399. }
  9400. //$out .= ' /SpiderInfo <<>>';
  9401. // set OutputIntent to sRGB IEC61966-2.1 if required
  9402. if ($this->pdfa_mode OR $this->force_srgb) {
  9403. $out .= ' /OutputIntents [<<';
  9404. $out .= ' /Type /OutputIntent';
  9405. $out .= ' /S /GTS_PDFA1';
  9406. $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9407. $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9408. $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
  9409. $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9410. $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
  9411. $out .= ' >>]';
  9412. }
  9413. //$out .= ' /PieceInfo <<>>';
  9414. if (!empty($this->pdflayers)) {
  9415. $lyrobjs = '';
  9416. $lyrobjs_off = '';
  9417. $lyrobjs_lock = '';
  9418. foreach ($this->pdflayers as $layer) {
  9419. $layer_obj_ref = ' '.$layer['objid'].' 0 R';
  9420. $lyrobjs .= $layer_obj_ref;
  9421. if ($layer['view'] === false) {
  9422. $lyrobjs_off .= $layer_obj_ref;
  9423. }
  9424. if ($layer['lock']) {
  9425. $lyrobjs_lock .= $layer_obj_ref;
  9426. }
  9427. }
  9428. $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
  9429. $out .= ' /D <<';
  9430. $out .= ' /Name '.$this->_textstring('Layers', $oid);
  9431. $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
  9432. $out .= ' /BaseState /ON';
  9433. $out .= ' /OFF ['.$lyrobjs_off.']';
  9434. $out .= ' /Locked ['.$lyrobjs_lock.']';
  9435. $out .= ' /Intent /View';
  9436. $out .= ' /AS [';
  9437. $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
  9438. $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
  9439. $out .= ' ]';
  9440. $out .= ' /Order ['.$lyrobjs.']';
  9441. $out .= ' /ListMode /AllPages';
  9442. //$out .= ' /RBGroups ['..']';
  9443. //$out .= ' /Locked ['..']';
  9444. $out .= ' >>';
  9445. $out .= ' >>';
  9446. }
  9447. // AcroForm
  9448. if (!empty($this->form_obj_id)
  9449. OR ($this->sign AND isset($this->signature_data['cert_type']))
  9450. OR !empty($this->empty_signature_appearance)) {
  9451. $out .= ' /AcroForm <<';
  9452. $objrefs = '';
  9453. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9454. // set reference for signature object
  9455. $objrefs .= $this->sig_obj_id.' 0 R';
  9456. }
  9457. if (!empty($this->empty_signature_appearance)) {
  9458. foreach ($this->empty_signature_appearance as $esa) {
  9459. // set reference for empty signature objects
  9460. $objrefs .= ' '.$esa['objid'].' 0 R';
  9461. }
  9462. }
  9463. if (!empty($this->form_obj_id)) {
  9464. foreach($this->form_obj_id as $objid) {
  9465. $objrefs .= ' '.$objid.' 0 R';
  9466. }
  9467. }
  9468. $out .= ' /Fields ['.$objrefs.']';
  9469. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  9470. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  9471. $out .= ' /NeedAppearances false';
  9472. }
  9473. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9474. if ($this->signature_data['cert_type'] > 0) {
  9475. $out .= ' /SigFlags 3';
  9476. } else {
  9477. $out .= ' /SigFlags 1';
  9478. }
  9479. }
  9480. //$out .= ' /CO ';
  9481. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  9482. $out .= ' /DR <<';
  9483. $out .= ' /Font <<';
  9484. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  9485. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9486. }
  9487. $out .= ' >> >>';
  9488. }
  9489. $font = $this->getFontBuffer('helvetica');
  9490. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  9491. $out .= ' /Q '.(($this->rtl)?'2':'0');
  9492. //$out .= ' /XFA ';
  9493. $out .= ' >>';
  9494. // signatures
  9495. if ($this->sign AND isset($this->signature_data['cert_type'])
  9496. AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) {
  9497. if ($this->signature_data['cert_type'] > 0) {
  9498. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  9499. } else {
  9500. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  9501. }
  9502. }
  9503. }
  9504. //$out .= ' /Legal <<>>';
  9505. //$out .= ' /Requirements []';
  9506. //$out .= ' /Collection <<>>';
  9507. //$out .= ' /NeedsRendering true';
  9508. $out .= ' >>';
  9509. $out .= "\n".'endobj';
  9510. $this->_out($out);
  9511. return $oid;
  9512. }
  9513. /**
  9514. * Output viewer preferences.
  9515. * @return string for viewer preferences
  9516. * @author Nicola asuni
  9517. * @since 3.1.000 (2008-06-09)
  9518. * @protected
  9519. */
  9520. protected function _putviewerpreferences() {
  9521. $vp = $this->viewer_preferences;
  9522. $out = ' /ViewerPreferences <<';
  9523. if ($this->rtl) {
  9524. $out .= ' /Direction /R2L';
  9525. } else {
  9526. $out .= ' /Direction /L2R';
  9527. }
  9528. if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
  9529. $out .= ' /HideToolbar true';
  9530. }
  9531. if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
  9532. $out .= ' /HideMenubar true';
  9533. }
  9534. if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
  9535. $out .= ' /HideWindowUI true';
  9536. }
  9537. if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
  9538. $out .= ' /FitWindow true';
  9539. }
  9540. if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
  9541. $out .= ' /CenterWindow true';
  9542. }
  9543. if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
  9544. $out .= ' /DisplayDocTitle true';
  9545. }
  9546. if (isset($vp['NonFullScreenPageMode'])) {
  9547. $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
  9548. }
  9549. if (isset($vp['ViewArea'])) {
  9550. $out .= ' /ViewArea /'.$vp['ViewArea'];
  9551. }
  9552. if (isset($vp['ViewClip'])) {
  9553. $out .= ' /ViewClip /'.$vp['ViewClip'];
  9554. }
  9555. if (isset($vp['PrintArea'])) {
  9556. $out .= ' /PrintArea /'.$vp['PrintArea'];
  9557. }
  9558. if (isset($vp['PrintClip'])) {
  9559. $out .= ' /PrintClip /'.$vp['PrintClip'];
  9560. }
  9561. if (isset($vp['PrintScaling'])) {
  9562. $out .= ' /PrintScaling /'.$vp['PrintScaling'];
  9563. }
  9564. if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) {
  9565. $out .= ' /Duplex /'.$vp['Duplex'];
  9566. }
  9567. if (isset($vp['PickTrayByPDFSize'])) {
  9568. if ($vp['PickTrayByPDFSize']) {
  9569. $out .= ' /PickTrayByPDFSize true';
  9570. } else {
  9571. $out .= ' /PickTrayByPDFSize false';
  9572. }
  9573. }
  9574. if (isset($vp['PrintPageRange'])) {
  9575. $PrintPageRangeNum = '';
  9576. foreach ($vp['PrintPageRange'] as $k => $v) {
  9577. $PrintPageRangeNum .= ' '.($v - 1).'';
  9578. }
  9579. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  9580. }
  9581. if (isset($vp['NumCopies'])) {
  9582. $out .= ' /NumCopies '.intval($vp['NumCopies']);
  9583. }
  9584. $out .= ' >>';
  9585. return $out;
  9586. }
  9587. /**
  9588. * Output PDF File Header (7.5.2).
  9589. * @protected
  9590. */
  9591. protected function _putheader() {
  9592. $this->_out('%PDF-'.$this->PDFVersion);
  9593. $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
  9594. }
  9595. /**
  9596. * Output end of document (EOF).
  9597. * @protected
  9598. */
  9599. protected function _enddoc() {
  9600. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  9601. // save subset chars of the previous font
  9602. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  9603. }
  9604. $this->state = 1;
  9605. $this->_putheader();
  9606. $this->_putpages();
  9607. $this->_putresources();
  9608. // empty signature fields
  9609. if (!empty($this->empty_signature_appearance)) {
  9610. foreach ($this->empty_signature_appearance as $key => $esa) {
  9611. // widget annotation for empty signature
  9612. $out = $this->_getobj($esa['objid'])."\n";
  9613. $out .= '<< /Type /Annot';
  9614. $out .= ' /Subtype /Widget';
  9615. $out .= ' /Rect ['.$esa['rect'].']';
  9616. $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
  9617. $out .= ' /F 4';
  9618. $out .= ' /FT /Sig';
  9619. $signame = $esa['name'].sprintf(' [%03d]', ($key + 1));
  9620. $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
  9621. $out .= ' /Ff 0';
  9622. $out .= ' >>';
  9623. $out .= "\n".'endobj';
  9624. $this->_out($out);
  9625. }
  9626. }
  9627. // Signature
  9628. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9629. // widget annotation for signature
  9630. $out = $this->_getobj($this->sig_obj_id)."\n";
  9631. $out .= '<< /Type /Annot';
  9632. $out .= ' /Subtype /Widget';
  9633. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  9634. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  9635. $out .= ' /F 4';
  9636. $out .= ' /FT /Sig';
  9637. $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id);
  9638. $out .= ' /Ff 0';
  9639. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  9640. $out .= ' >>';
  9641. $out .= "\n".'endobj';
  9642. $this->_out($out);
  9643. // signature
  9644. $this->_putsignature();
  9645. }
  9646. // Info
  9647. $objid_info = $this->_putinfo();
  9648. // Catalog
  9649. $objid_catalog = $this->_putcatalog();
  9650. // Cross-ref
  9651. $o = $this->bufferlen;
  9652. // XREF section
  9653. $this->_out('xref');
  9654. $this->_out('0 '.($this->n + 1));
  9655. $this->_out('0000000000 65535 f ');
  9656. $freegen = ($this->n + 2);
  9657. for ($i=1; $i <= $this->n; ++$i) {
  9658. if (!isset($this->offsets[$i]) AND ($i > 1)) {
  9659. $this->_out(sprintf('0000000000 %05d f ', $freegen));
  9660. ++$freegen;
  9661. } else {
  9662. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  9663. }
  9664. }
  9665. // TRAILER
  9666. $out = 'trailer'."\n";
  9667. $out .= '<<';
  9668. $out .= ' /Size '.($this->n + 1);
  9669. $out .= ' /Root '.$objid_catalog.' 0 R';
  9670. $out .= ' /Info '.$objid_info.' 0 R';
  9671. if ($this->encrypted) {
  9672. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  9673. }
  9674. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  9675. $out .= ' >>';
  9676. $this->_out($out);
  9677. $this->_out('startxref');
  9678. $this->_out($o);
  9679. $this->_out('%%EOF');
  9680. $this->state = 3; // end-of-doc
  9681. }
  9682. /**
  9683. * Initialize a new page.
  9684. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  9685. * @param mixed $format 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().
  9686. * @protected
  9687. * @see getPageSizeFromFormat(), setPageFormat()
  9688. */
  9689. protected function _beginpage($orientation='', $format='') {
  9690. ++$this->page;
  9691. $this->pageobjects[$this->page] = array();
  9692. $this->setPageBuffer($this->page, '');
  9693. // initialize array for graphics tranformation positions inside a page buffer
  9694. $this->transfmrk[$this->page] = array();
  9695. $this->state = 2;
  9696. if (TCPDF_STATIC::empty_string($orientation)) {
  9697. if (isset($this->CurOrientation)) {
  9698. $orientation = $this->CurOrientation;
  9699. } elseif ($this->fwPt > $this->fhPt) {
  9700. // landscape
  9701. $orientation = 'L';
  9702. } else {
  9703. // portrait
  9704. $orientation = 'P';
  9705. }
  9706. }
  9707. if (TCPDF_STATIC::empty_string($format)) {
  9708. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  9709. $this->setPageOrientation($orientation);
  9710. } else {
  9711. $this->setPageFormat($format, $orientation);
  9712. }
  9713. if ($this->rtl) {
  9714. $this->x = $this->w - $this->rMargin;
  9715. } else {
  9716. $this->x = $this->lMargin;
  9717. }
  9718. $this->y = $this->tMargin;
  9719. if (isset($this->newpagegroup[$this->page])) {
  9720. // start a new group
  9721. $this->currpagegroup = $this->newpagegroup[$this->page];
  9722. $this->pagegroups[$this->currpagegroup] = 1;
  9723. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  9724. ++$this->pagegroups[$this->currpagegroup];
  9725. }
  9726. }
  9727. /**
  9728. * Mark end of page.
  9729. * @protected
  9730. */
  9731. protected function _endpage() {
  9732. $this->setVisibility('all');
  9733. $this->state = 1;
  9734. }
  9735. /**
  9736. * Begin a new object and return the object number.
  9737. * @return int object number
  9738. * @protected
  9739. */
  9740. protected function _newobj() {
  9741. $this->_out($this->_getobj());
  9742. return $this->n;
  9743. }
  9744. /**
  9745. * Return the starting object string for the selected object ID.
  9746. * @param int|null $objid Object ID (leave empty to get a new ID).
  9747. * @return string the starting object string
  9748. * @protected
  9749. * @since 5.8.009 (2010-08-20)
  9750. */
  9751. protected function _getobj($objid=null) {
  9752. if (TCPDF_STATIC::empty_string($objid)) {
  9753. ++$this->n;
  9754. $objid = $this->n;
  9755. }
  9756. $this->offsets[$objid] = $this->bufferlen;
  9757. $this->pageobjects[$this->page][] = $objid;
  9758. return $objid.' 0 obj';
  9759. }
  9760. /**
  9761. * Underline text.
  9762. * @param int $x X coordinate
  9763. * @param int $y Y coordinate
  9764. * @param string $txt text to underline
  9765. * @protected
  9766. */
  9767. protected function _dounderline($x, $y, $txt) {
  9768. $w = $this->GetStringWidth($txt);
  9769. return $this->_dounderlinew($x, $y, $w);
  9770. }
  9771. /**
  9772. * Underline for rectangular text area.
  9773. * @param int $x X coordinate
  9774. * @param int $y Y coordinate
  9775. * @param int $w width to underline
  9776. * @protected
  9777. * @since 4.8.008 (2009-09-29)
  9778. */
  9779. protected function _dounderlinew($x, $y, $w) {
  9780. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9781. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  9782. }
  9783. /**
  9784. * Line through text.
  9785. * @param int $x X coordinate
  9786. * @param int $y Y coordinate
  9787. * @param string $txt text to linethrough
  9788. * @protected
  9789. */
  9790. protected function _dolinethrough($x, $y, $txt) {
  9791. $w = $this->GetStringWidth($txt);
  9792. return $this->_dolinethroughw($x, $y, $w);
  9793. }
  9794. /**
  9795. * Line through for rectangular text area.
  9796. * @param int $x X coordinate
  9797. * @param int $y Y coordinate
  9798. * @param int $w line length (width)
  9799. * @protected
  9800. * @since 4.9.008 (2009-09-29)
  9801. */
  9802. protected function _dolinethroughw($x, $y, $w) {
  9803. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9804. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  9805. }
  9806. /**
  9807. * Overline text.
  9808. * @param int $x X coordinate
  9809. * @param int $y Y coordinate
  9810. * @param string $txt text to overline
  9811. * @protected
  9812. * @since 4.9.015 (2010-04-19)
  9813. */
  9814. protected function _dooverline($x, $y, $txt) {
  9815. $w = $this->GetStringWidth($txt);
  9816. return $this->_dooverlinew($x, $y, $w);
  9817. }
  9818. /**
  9819. * Overline for rectangular text area.
  9820. * @param int $x X coordinate
  9821. * @param int $y Y coordinate
  9822. * @param int $w width to overline
  9823. * @protected
  9824. * @since 4.9.015 (2010-04-19)
  9825. */
  9826. protected function _dooverlinew($x, $y, $w) {
  9827. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9828. return sprintf('%F %F %F %F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  9829. }
  9830. /**
  9831. * Format a data string for meta information
  9832. * @param string $s data string to escape.
  9833. * @param int $n object ID
  9834. * @return string escaped string.
  9835. * @protected
  9836. */
  9837. protected function _datastring($s, $n=0) {
  9838. if ($n == 0) {
  9839. $n = $this->n;
  9840. }
  9841. $s = $this->_encrypt_data($n, $s);
  9842. return '('. TCPDF_STATIC::_escape($s).')';
  9843. }
  9844. /**
  9845. * Set the document creation timestamp
  9846. * @param mixed $time Document creation timestamp in seconds or date-time string.
  9847. * @public
  9848. * @since 5.9.152 (2012-03-23)
  9849. */
  9850. public function setDocCreationTimestamp($time) {
  9851. if (is_string($time)) {
  9852. $time = TCPDF_STATIC::getTimestamp($time);
  9853. }
  9854. $this->doc_creation_timestamp = intval($time);
  9855. }
  9856. /**
  9857. * Set the document modification timestamp
  9858. * @param mixed $time Document modification timestamp in seconds or date-time string.
  9859. * @public
  9860. * @since 5.9.152 (2012-03-23)
  9861. */
  9862. public function setDocModificationTimestamp($time) {
  9863. if (is_string($time)) {
  9864. $time = TCPDF_STATIC::getTimestamp($time);
  9865. }
  9866. $this->doc_modification_timestamp = intval($time);
  9867. }
  9868. /**
  9869. * Returns document creation timestamp in seconds.
  9870. * @return int Creation timestamp in seconds.
  9871. * @public
  9872. * @since 5.9.152 (2012-03-23)
  9873. */
  9874. public function getDocCreationTimestamp() {
  9875. return $this->doc_creation_timestamp;
  9876. }
  9877. /**
  9878. * Returns document modification timestamp in seconds.
  9879. * @return int Modfication timestamp in seconds.
  9880. * @public
  9881. * @since 5.9.152 (2012-03-23)
  9882. */
  9883. public function getDocModificationTimestamp() {
  9884. return $this->doc_modification_timestamp;
  9885. }
  9886. /**
  9887. * Returns a formatted date for meta information
  9888. * @param int $n Object ID.
  9889. * @param int $timestamp Timestamp to convert.
  9890. * @return string escaped date string.
  9891. * @protected
  9892. * @since 4.6.028 (2009-08-25)
  9893. */
  9894. protected function _datestring($n=0, $timestamp=0) {
  9895. if ((empty($timestamp)) OR ($timestamp < 0)) {
  9896. $timestamp = $this->doc_creation_timestamp;
  9897. }
  9898. return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n);
  9899. }
  9900. /**
  9901. * Format a text string for meta information
  9902. * @param string $s string to escape.
  9903. * @param int $n object ID
  9904. * @return string escaped string.
  9905. * @protected
  9906. */
  9907. protected function _textstring($s, $n=0) {
  9908. if ($this->isunicode) {
  9909. //Convert string to UTF-16BE
  9910. $s = TCPDF_FONTS::UTF8ToUTF16BE($s, true, $this->isunicode, $this->CurrentFont);
  9911. }
  9912. return $this->_datastring($s, $n);
  9913. }
  9914. /**
  9915. * get raw output stream.
  9916. * @param string $s string to output.
  9917. * @param int $n object reference for encryption mode
  9918. * @protected
  9919. * @author Nicola Asuni
  9920. * @since 5.5.000 (2010-06-22)
  9921. */
  9922. protected function _getrawstream($s, $n=0) {
  9923. if ($n <= 0) {
  9924. // default to current object
  9925. $n = $this->n;
  9926. }
  9927. return $this->_encrypt_data($n, $s);
  9928. }
  9929. /**
  9930. * Output a string to the document.
  9931. * @param string $s string to output.
  9932. * @protected
  9933. */
  9934. protected function _out($s) {
  9935. if ($this->state == 2) {
  9936. if ($this->inxobj) {
  9937. // we are inside an XObject template
  9938. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  9939. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  9940. // puts data before page footer
  9941. $pagebuff = $this->getPageBuffer($this->page);
  9942. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  9943. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  9944. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  9945. // update footer position
  9946. $this->footerpos[$this->page] += strlen($s."\n");
  9947. } else {
  9948. // set page data
  9949. $this->setPageBuffer($this->page, $s."\n", true);
  9950. }
  9951. } elseif ($this->state > 0) {
  9952. // set general data
  9953. $this->setBuffer($s."\n");
  9954. }
  9955. }
  9956. /**
  9957. * Set header font.
  9958. * @param array<int,string|float|null> $font Array describing the basic font parameters: (family, style, size).
  9959. * @phpstan-param array{0: string, 1: string, 2: float|null} $font
  9960. * @public
  9961. * @since 1.1
  9962. */
  9963. public function setHeaderFont($font) {
  9964. $this->header_font = $font;
  9965. }
  9966. /**
  9967. * Get header font.
  9968. * @return array<int,string|float|null> Array describing the basic font parameters: (family, style, size).
  9969. * @phpstan-return array{0: string, 1: string, 2: float|null}
  9970. * @public
  9971. * @since 4.0.012 (2008-07-24)
  9972. */
  9973. public function getHeaderFont() {
  9974. return $this->header_font;
  9975. }
  9976. /**
  9977. * Set footer font.
  9978. * @param array<int,string|float|null> $font Array describing the basic font parameters: (family, style, size).
  9979. * @phpstan-param array{0: string, 1: string, 2: float|null} $font
  9980. * @public
  9981. * @since 1.1
  9982. */
  9983. public function setFooterFont($font) {
  9984. $this->footer_font = $font;
  9985. }
  9986. /**
  9987. * Get Footer font.
  9988. * @return array<int,string|float|null> Array describing the basic font parameters: (family, style, size).
  9989. * @phpstan-return array{0: string, 1: string, 2: float|null} $font
  9990. * @public
  9991. * @since 4.0.012 (2008-07-24)
  9992. */
  9993. public function getFooterFont() {
  9994. return $this->footer_font;
  9995. }
  9996. /**
  9997. * Set language array.
  9998. * @param array $language
  9999. * @public
  10000. * @since 1.1
  10001. */
  10002. public function setLanguageArray($language) {
  10003. $this->l = $language;
  10004. if (isset($this->l['a_meta_dir'])) {
  10005. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  10006. } else {
  10007. $this->rtl = false;
  10008. }
  10009. }
  10010. /**
  10011. * Returns the PDF data.
  10012. * @public
  10013. */
  10014. public function getPDFData() {
  10015. if ($this->state < 3) {
  10016. $this->Close();
  10017. }
  10018. return $this->buffer;
  10019. }
  10020. /**
  10021. * Output anchor link.
  10022. * @param string $url 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;)
  10023. * @param string $name link name
  10024. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  10025. * @param boolean $firstline if true prints only the first line and return the remaining string.
  10026. * @param array|null $color array of RGB text color
  10027. * @param string $style font style (U, D, B, I)
  10028. * @param boolean $firstblock if true the string is the starting of a line.
  10029. * @return int the number of cells used or the remaining text if $firstline = true;
  10030. * @public
  10031. */
  10032. public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color=null, $style=-1, $firstblock=false) {
  10033. if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
  10034. // convert url to internal link
  10035. $lnkdata = explode(',', $url);
  10036. if (isset($lnkdata[0]) ) {
  10037. $page = substr($lnkdata[0], 1);
  10038. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  10039. $lnky = floatval($lnkdata[1]);
  10040. } else {
  10041. $lnky = 0;
  10042. }
  10043. $url = $this->AddLink();
  10044. $this->setLink($url, $lnky, $page);
  10045. }
  10046. }
  10047. // store current settings
  10048. $prevcolor = $this->fgcolor;
  10049. $prevstyle = $this->FontStyle;
  10050. if (empty($color)) {
  10051. $this->setTextColorArray($this->htmlLinkColorArray);
  10052. } else {
  10053. $this->setTextColorArray($color);
  10054. }
  10055. if ($style == -1) {
  10056. $this->setFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  10057. } else {
  10058. $this->setFont('', $this->FontStyle.$style);
  10059. }
  10060. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  10061. // restore settings
  10062. $this->setFont('', $prevstyle);
  10063. $this->setTextColorArray($prevcolor);
  10064. return $ret;
  10065. }
  10066. /**
  10067. * Converts pixels to User's Units.
  10068. * @param int $px pixels
  10069. * @return float value in user's unit
  10070. * @public
  10071. * @see setImageScale(), getImageScale()
  10072. */
  10073. public function pixelsToUnits($px) {
  10074. return ($px / ($this->imgscale * $this->k));
  10075. }
  10076. /**
  10077. * Reverse function for htmlentities.
  10078. * Convert entities in UTF-8.
  10079. * @param string $text_to_convert Text to convert.
  10080. * @return string converted text string
  10081. * @public
  10082. */
  10083. public function unhtmlentities($text_to_convert) {
  10084. return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  10085. }
  10086. // ENCRYPTION METHODS ----------------------------------
  10087. /**
  10088. * Compute encryption key depending on object number where the encrypted data is stored.
  10089. * This is used for all strings and streams without crypt filter specifier.
  10090. * @param int $n object number
  10091. * @return int object key
  10092. * @protected
  10093. * @author Nicola Asuni
  10094. * @since 2.0.000 (2008-01-02)
  10095. */
  10096. protected function _objectkey($n) {
  10097. $objkey = $this->encryptdata['key'].pack('VXxx', $n);
  10098. if ($this->encryptdata['mode'] == 2) { // AES-128
  10099. // AES padding
  10100. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  10101. }
  10102. $objkey = substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  10103. $objkey = substr($objkey, 0, 16);
  10104. return $objkey;
  10105. }
  10106. /**
  10107. * Encrypt the input string.
  10108. * @param int $n object number
  10109. * @param string $s data string to encrypt
  10110. * @return string encrypted string
  10111. * @protected
  10112. * @author Nicola Asuni
  10113. * @since 5.0.005 (2010-05-11)
  10114. */
  10115. protected function _encrypt_data($n, $s) {
  10116. if (!$this->encrypted) {
  10117. return $s;
  10118. }
  10119. switch ($this->encryptdata['mode']) {
  10120. case 0: // RC4-40
  10121. case 1: { // RC4-128
  10122. $s = TCPDF_STATIC::_RC4($this->_objectkey($n), $s, $this->last_enc_key, $this->last_enc_key_c);
  10123. break;
  10124. }
  10125. case 2: { // AES-128
  10126. $s = TCPDF_STATIC::_AES($this->_objectkey($n), $s);
  10127. break;
  10128. }
  10129. case 3: { // AES-256
  10130. $s = TCPDF_STATIC::_AES($this->encryptdata['key'], $s);
  10131. break;
  10132. }
  10133. }
  10134. return $s;
  10135. }
  10136. /**
  10137. * Put encryption on PDF document.
  10138. * @protected
  10139. * @author Nicola Asuni
  10140. * @since 2.0.000 (2008-01-02)
  10141. */
  10142. protected function _putencryption() {
  10143. if (!$this->encrypted) {
  10144. return;
  10145. }
  10146. $this->encryptdata['objid'] = $this->_newobj();
  10147. $out = '<<';
  10148. if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  10149. $this->encryptdata['Filter'] = 'Standard';
  10150. }
  10151. $out .= ' /Filter /'.$this->encryptdata['Filter'];
  10152. if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  10153. $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  10154. }
  10155. if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  10156. $this->encryptdata['V'] = 1;
  10157. }
  10158. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  10159. $out .= ' /V '.$this->encryptdata['V'];
  10160. if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  10161. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  10162. $out .= ' /Length '.$this->encryptdata['Length'];
  10163. } else {
  10164. $out .= ' /Length 40';
  10165. }
  10166. if ($this->encryptdata['V'] >= 4) {
  10167. if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  10168. $this->encryptdata['StmF'] = 'Identity';
  10169. }
  10170. if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  10171. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10172. $this->encryptdata['StrF'] = 'Identity';
  10173. }
  10174. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  10175. if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  10176. $out .= ' /CF <<';
  10177. $out .= ' /'.$this->encryptdata['StmF'].' <<';
  10178. $out .= ' /Type /CryptFilter';
  10179. if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  10180. // The method used
  10181. $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  10182. if ($this->encryptdata['pubkey']) {
  10183. $out .= ' /Recipients [';
  10184. foreach ($this->encryptdata['Recipients'] as $rec) {
  10185. $out .= ' <'.$rec.'>';
  10186. }
  10187. $out .= ' ]';
  10188. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  10189. $out .= ' /EncryptMetadata false';
  10190. } else {
  10191. $out .= ' /EncryptMetadata true';
  10192. }
  10193. }
  10194. } else {
  10195. $out .= ' /CFM /None';
  10196. }
  10197. if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  10198. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  10199. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  10200. } else {
  10201. $out .= ' /AuthEvent /DocOpen';
  10202. }
  10203. if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  10204. // The bit length of the encryption key.
  10205. $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  10206. }
  10207. $out .= ' >> >>';
  10208. }
  10209. // The name of the crypt filter that shall be used by default when decrypting streams.
  10210. $out .= ' /StmF /'.$this->encryptdata['StmF'];
  10211. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10212. $out .= ' /StrF /'.$this->encryptdata['StrF'];
  10213. if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  10214. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  10215. $out .= ' /EFF /'.$this->encryptdata[''];
  10216. }
  10217. }
  10218. // Additional encryption dictionary entries for the standard security handler
  10219. if ($this->encryptdata['pubkey']) {
  10220. if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  10221. $out .= ' /Recipients [';
  10222. foreach ($this->encryptdata['Recipients'] as $rec) {
  10223. $out .= ' <'.$rec.'>';
  10224. }
  10225. $out .= ' ]';
  10226. }
  10227. } else {
  10228. $out .= ' /R';
  10229. if ($this->encryptdata['V'] == 5) { // AES-256
  10230. $out .= ' 5';
  10231. $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')';
  10232. $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')';
  10233. $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')';
  10234. } elseif ($this->encryptdata['V'] == 4) { // AES-128
  10235. $out .= ' 4';
  10236. } elseif ($this->encryptdata['V'] < 2) { // RC-40
  10237. $out .= ' 2';
  10238. } else { // RC-128
  10239. $out .= ' 3';
  10240. }
  10241. $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')';
  10242. $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')';
  10243. $out .= ' /P '.$this->encryptdata['P'];
  10244. if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  10245. $out .= ' /EncryptMetadata false';
  10246. } else {
  10247. $out .= ' /EncryptMetadata true';
  10248. }
  10249. }
  10250. $out .= ' >>';
  10251. $out .= "\n".'endobj';
  10252. $this->_out($out);
  10253. }
  10254. /**
  10255. * Compute U value (used for encryption)
  10256. * @return string U value
  10257. * @protected
  10258. * @since 2.0.000 (2008-01-02)
  10259. * @author Nicola Asuni
  10260. */
  10261. protected function _Uvalue() {
  10262. if ($this->encryptdata['mode'] == 0) { // RC4-40
  10263. return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding, $this->last_enc_key, $this->last_enc_key_c);
  10264. } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  10265. $tmp = TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']);
  10266. $enc = TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp, $this->last_enc_key, $this->last_enc_key_c);
  10267. $len = strlen($tmp);
  10268. for ($i = 1; $i <= 19; ++$i) {
  10269. $ek = '';
  10270. for ($j = 0; $j < $len; ++$j) {
  10271. $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
  10272. }
  10273. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10274. }
  10275. $enc .= str_repeat("\x00", 16);
  10276. return substr($enc, 0, 32);
  10277. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10278. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10279. // User Validation Salt
  10280. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  10281. // User Key Salt
  10282. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  10283. return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  10284. }
  10285. }
  10286. /**
  10287. * Compute UE value (used for encryption)
  10288. * @return string UE value
  10289. * @protected
  10290. * @since 5.9.006 (2010-10-19)
  10291. * @author Nicola Asuni
  10292. */
  10293. protected function _UEvalue() {
  10294. $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  10295. return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
  10296. }
  10297. /**
  10298. * Compute O value (used for encryption)
  10299. * @return string O value
  10300. * @protected
  10301. * @since 2.0.000 (2008-01-02)
  10302. * @author Nicola Asuni
  10303. */
  10304. protected function _Ovalue() {
  10305. if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  10306. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']);
  10307. if ($this->encryptdata['mode'] > 0) {
  10308. for ($i = 0; $i < 50; ++$i) {
  10309. $tmp = TCPDF_STATIC::_md5_16($tmp);
  10310. }
  10311. }
  10312. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  10313. $enc = TCPDF_STATIC::_RC4($owner_key, $this->encryptdata['user_password'], $this->last_enc_key, $this->last_enc_key_c);
  10314. if ($this->encryptdata['mode'] > 0) {
  10315. $len = strlen($owner_key);
  10316. for ($i = 1; $i <= 19; ++$i) {
  10317. $ek = '';
  10318. for ($j = 0; $j < $len; ++$j) {
  10319. $ek .= chr(ord($owner_key[$j]) ^ $i);
  10320. }
  10321. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10322. }
  10323. }
  10324. return $enc;
  10325. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10326. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10327. // Owner Validation Salt
  10328. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  10329. // Owner Key Salt
  10330. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  10331. return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  10332. }
  10333. }
  10334. /**
  10335. * Compute OE value (used for encryption)
  10336. * @return string OE value
  10337. * @protected
  10338. * @since 5.9.006 (2010-10-19)
  10339. * @author Nicola Asuni
  10340. */
  10341. protected function _OEvalue() {
  10342. $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  10343. return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
  10344. }
  10345. /**
  10346. * Convert password for AES-256 encryption mode
  10347. * @param string $password password
  10348. * @return string password
  10349. * @protected
  10350. * @since 5.9.006 (2010-10-19)
  10351. * @author Nicola Asuni
  10352. */
  10353. protected function _fixAES256Password($password) {
  10354. $psw = ''; // password to be returned
  10355. $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont);
  10356. foreach ($psw_array as $c) {
  10357. $psw .= TCPDF_FONTS::unichr($c, $this->isunicode);
  10358. }
  10359. return substr($psw, 0, 127);
  10360. }
  10361. /**
  10362. * Compute encryption key
  10363. * @protected
  10364. * @since 2.0.000 (2008-01-02)
  10365. * @author Nicola Asuni
  10366. */
  10367. protected function _generateencryptionkey() {
  10368. $keybytelen = ($this->encryptdata['Length'] / 8);
  10369. if (!$this->encryptdata['pubkey']) { // standard mode
  10370. if ($this->encryptdata['mode'] == 3) { // AES-256
  10371. // generate 256 bit random key
  10372. $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen);
  10373. // truncate passwords
  10374. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  10375. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  10376. // Compute U value
  10377. $this->encryptdata['U'] = $this->_Uvalue();
  10378. // Compute UE value
  10379. $this->encryptdata['UE'] = $this->_UEvalue();
  10380. // Compute O value
  10381. $this->encryptdata['O'] = $this->_Ovalue();
  10382. // Compute OE value
  10383. $this->encryptdata['OE'] = $this->_OEvalue();
  10384. // Compute P value
  10385. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10386. // Computing the encryption dictionary's Perms (permissions) value
  10387. $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  10388. $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  10389. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  10390. $perms .= 'F';
  10391. } else {
  10392. $perms .= 'T';
  10393. }
  10394. $perms .= 'adb'; // bytes 9-11
  10395. $perms .= 'nick'; // bytes 12-15
  10396. $this->encryptdata['perms'] = TCPDF_STATIC::_AESnopad($this->encryptdata['key'], $perms);
  10397. } else { // RC4-40, RC4-128, AES-128
  10398. // Pad passwords
  10399. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10400. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10401. // Compute O value
  10402. $this->encryptdata['O'] = $this->_Ovalue();
  10403. // get default permissions (reverse byte order)
  10404. $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
  10405. // Compute encryption key
  10406. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  10407. if ($this->encryptdata['mode'] > 0) {
  10408. for ($i = 0; $i < 50; ++$i) {
  10409. $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen));
  10410. }
  10411. }
  10412. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  10413. // Compute U value
  10414. $this->encryptdata['U'] = $this->_Uvalue();
  10415. // Compute P value
  10416. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10417. }
  10418. } else { // Public-Key mode
  10419. // random 20-byte seed
  10420. $seed = sha1(TCPDF_STATIC::getRandomSeed(), true);
  10421. $recipient_bytes = '';
  10422. foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  10423. // for each public certificate
  10424. if (isset($pubkey['p'])) {
  10425. $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  10426. } else {
  10427. $pkprotection = $this->encryptdata['protection'];
  10428. }
  10429. // get default permissions (reverse byte order)
  10430. $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection);
  10431. // envelope data
  10432. $envelope = $seed.$pkpermissions;
  10433. // write the envelope data to a temporary file
  10434. $tempkeyfile = TCPDF_STATIC::getObjFilename('key', $this->file_id);
  10435. $f = TCPDF_STATIC::fopenLocal($tempkeyfile, 'wb');
  10436. if (!$f) {
  10437. $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  10438. }
  10439. $envelope_length = strlen($envelope);
  10440. fwrite($f, $envelope, $envelope_length);
  10441. fclose($f);
  10442. $tempencfile = TCPDF_STATIC::getObjFilename('enc', $this->file_id);
  10443. if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
  10444. $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  10445. }
  10446. // read encryption signature
  10447. $signature = file_get_contents($tempencfile, false, null, $envelope_length);
  10448. // extract signature
  10449. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  10450. $tmparr = explode("\n\n", $signature);
  10451. $signature = trim($tmparr[1]);
  10452. unset($tmparr);
  10453. // decode signature
  10454. $signature = base64_decode($signature);
  10455. // convert signature to hex
  10456. $hexsignature = current(unpack('H*', $signature));
  10457. // store signature on recipients array
  10458. $this->encryptdata['Recipients'][] = $hexsignature;
  10459. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  10460. $recipient_bytes .= $signature;
  10461. }
  10462. // calculate encryption key
  10463. if ($this->encryptdata['mode'] == 3) { // AES-256
  10464. $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
  10465. } else { // RC4-40, RC4-128, AES-128
  10466. $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
  10467. }
  10468. }
  10469. }
  10470. /**
  10471. * Set document protection
  10472. * Remark: the protection against modification is for people who have the full Acrobat product.
  10473. * 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.
  10474. * 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.
  10475. * @param array $permissions 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>
  10476. * @param string $user_pass user password. Empty by default.
  10477. * @param string|null $owner_pass owner password. If not specified, a random value is used.
  10478. * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  10479. * @param array|null $pubkeys 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')))
  10480. * @public
  10481. * @since 2.0.000 (2008-01-02)
  10482. * @author Nicola Asuni
  10483. */
  10484. 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) {
  10485. if ($this->pdfa_mode) {
  10486. // encryption is not allowed in PDF/A mode
  10487. return;
  10488. }
  10489. $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions, $mode);
  10490. if (($pubkeys !== null) AND (is_array($pubkeys))) {
  10491. // public-key mode
  10492. $this->encryptdata['pubkeys'] = $pubkeys;
  10493. if ($mode == 0) {
  10494. // public-Key Security requires at least 128 bit
  10495. $mode = 1;
  10496. }
  10497. if (!function_exists('openssl_pkcs7_encrypt')) {
  10498. $this->Error('Public-Key Security requires openssl library.');
  10499. }
  10500. // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  10501. $this->encryptdata['pubkey'] = true;
  10502. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  10503. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  10504. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  10505. } else {
  10506. // standard mode (password mode)
  10507. $this->encryptdata['pubkey'] = false;
  10508. $this->encryptdata['Filter'] = 'Standard';
  10509. $this->encryptdata['StmF'] = 'StdCF';
  10510. $this->encryptdata['StrF'] = 'StdCF';
  10511. }
  10512. if ($mode > 1) { // AES
  10513. if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) {
  10514. $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).');
  10515. }
  10516. if (extension_loaded('openssl') && !in_array('aes-256-cbc', openssl_get_cipher_methods())) {
  10517. $this->Error('AES encryption requires openssl/aes-256-cbc cypher.');
  10518. }
  10519. if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  10520. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  10521. }
  10522. if (($mode == 3) AND !function_exists('hash')) {
  10523. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  10524. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  10525. }
  10526. }
  10527. if ($owner_pass === null) {
  10528. $owner_pass = md5(TCPDF_STATIC::getRandomSeed());
  10529. }
  10530. $this->encryptdata['user_password'] = $user_pass;
  10531. $this->encryptdata['owner_password'] = $owner_pass;
  10532. $this->encryptdata['mode'] = $mode;
  10533. switch ($mode) {
  10534. case 0: { // RC4 40 bit
  10535. $this->encryptdata['V'] = 1;
  10536. $this->encryptdata['Length'] = 40;
  10537. $this->encryptdata['CF']['CFM'] = 'V2';
  10538. break;
  10539. }
  10540. case 1: { // RC4 128 bit
  10541. $this->encryptdata['V'] = 2;
  10542. $this->encryptdata['Length'] = 128;
  10543. $this->encryptdata['CF']['CFM'] = 'V2';
  10544. if ($this->encryptdata['pubkey']) {
  10545. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  10546. $this->encryptdata['Recipients'] = array();
  10547. }
  10548. break;
  10549. }
  10550. case 2: { // AES 128 bit
  10551. $this->encryptdata['V'] = 4;
  10552. $this->encryptdata['Length'] = 128;
  10553. $this->encryptdata['CF']['CFM'] = 'AESV2';
  10554. $this->encryptdata['CF']['Length'] = 128;
  10555. if ($this->encryptdata['pubkey']) {
  10556. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10557. $this->encryptdata['Recipients'] = array();
  10558. }
  10559. break;
  10560. }
  10561. case 3: { // AES 256 bit
  10562. $this->encryptdata['V'] = 5;
  10563. $this->encryptdata['Length'] = 256;
  10564. $this->encryptdata['CF']['CFM'] = 'AESV3';
  10565. $this->encryptdata['CF']['Length'] = 256;
  10566. if ($this->encryptdata['pubkey']) {
  10567. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10568. $this->encryptdata['Recipients'] = array();
  10569. }
  10570. break;
  10571. }
  10572. }
  10573. $this->encrypted = true;
  10574. $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id);
  10575. $this->_generateencryptionkey();
  10576. }
  10577. // END OF ENCRYPTION FUNCTIONS -------------------------
  10578. // START TRANSFORMATIONS SECTION -----------------------
  10579. /**
  10580. * Starts a 2D tranformation saving current graphic state.
  10581. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  10582. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10583. * @public
  10584. * @since 2.1.000 (2008-01-07)
  10585. * @see StartTransform(), StopTransform()
  10586. */
  10587. public function StartTransform() {
  10588. if ($this->state != 2) {
  10589. return;
  10590. }
  10591. $this->_outSaveGraphicsState();
  10592. if ($this->inxobj) {
  10593. // we are inside an XObject template
  10594. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10595. } else {
  10596. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  10597. }
  10598. ++$this->transfmatrix_key;
  10599. $this->transfmatrix[$this->transfmatrix_key] = array();
  10600. }
  10601. /**
  10602. * Stops a 2D tranformation restoring previous graphic state.
  10603. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  10604. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10605. * @public
  10606. * @since 2.1.000 (2008-01-07)
  10607. * @see StartTransform(), StopTransform()
  10608. */
  10609. public function StopTransform() {
  10610. if ($this->state != 2) {
  10611. return;
  10612. }
  10613. $this->_outRestoreGraphicsState();
  10614. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  10615. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  10616. --$this->transfmatrix_key;
  10617. }
  10618. if ($this->inxobj) {
  10619. // we are inside an XObject template
  10620. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  10621. } else {
  10622. array_pop($this->transfmrk[$this->page]);
  10623. }
  10624. }
  10625. /**
  10626. * Horizontal Scaling.
  10627. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  10628. * @param int $x abscissa of the scaling center. Default is current x position
  10629. * @param int $y ordinate of the scaling center. Default is current y position
  10630. * @public
  10631. * @since 2.1.000 (2008-01-07)
  10632. * @see StartTransform(), StopTransform()
  10633. */
  10634. public function ScaleX($s_x, $x='', $y='') {
  10635. $this->Scale($s_x, 100, $x, $y);
  10636. }
  10637. /**
  10638. * Vertical Scaling.
  10639. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  10640. * @param int $x abscissa of the scaling center. Default is current x position
  10641. * @param int $y ordinate of the scaling center. Default is current y position
  10642. * @public
  10643. * @since 2.1.000 (2008-01-07)
  10644. * @see StartTransform(), StopTransform()
  10645. */
  10646. public function ScaleY($s_y, $x='', $y='') {
  10647. $this->Scale(100, $s_y, $x, $y);
  10648. }
  10649. /**
  10650. * Vertical and horizontal proportional Scaling.
  10651. * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  10652. * @param int $x abscissa of the scaling center. Default is current x position
  10653. * @param int $y ordinate of the scaling center. Default is current y position
  10654. * @public
  10655. * @since 2.1.000 (2008-01-07)
  10656. * @see StartTransform(), StopTransform()
  10657. */
  10658. public function ScaleXY($s, $x='', $y='') {
  10659. $this->Scale($s, $s, $x, $y);
  10660. }
  10661. /**
  10662. * Vertical and horizontal non-proportional Scaling.
  10663. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  10664. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  10665. * @param float|null $x abscissa of the scaling center. Default is current x position
  10666. * @param float|null $y ordinate of the scaling center. Default is current y position
  10667. * @public
  10668. * @since 2.1.000 (2008-01-07)
  10669. * @see StartTransform(), StopTransform()
  10670. */
  10671. public function Scale($s_x, $s_y, $x=null, $y=null) {
  10672. if (TCPDF_STATIC::empty_string($x)) {
  10673. $x = $this->x;
  10674. }
  10675. if (TCPDF_STATIC::empty_string($y)) {
  10676. $y = $this->y;
  10677. }
  10678. if (($s_x == 0) OR ($s_y == 0)) {
  10679. $this->Error('Please do not use values equal to zero for scaling');
  10680. }
  10681. $y = ($this->h - $y) * $this->k;
  10682. $x *= $this->k;
  10683. //calculate elements of transformation matrix
  10684. $s_x /= 100;
  10685. $s_y /= 100;
  10686. $tm = array();
  10687. $tm[0] = $s_x;
  10688. $tm[1] = 0;
  10689. $tm[2] = 0;
  10690. $tm[3] = $s_y;
  10691. $tm[4] = $x * (1 - $s_x);
  10692. $tm[5] = $y * (1 - $s_y);
  10693. //scale the coordinate system
  10694. $this->Transform($tm);
  10695. }
  10696. /**
  10697. * Horizontal Mirroring.
  10698. * @param float|null $x abscissa of the point. Default is current x position
  10699. * @public
  10700. * @since 2.1.000 (2008-01-07)
  10701. * @see StartTransform(), StopTransform()
  10702. */
  10703. public function MirrorH($x=null) {
  10704. $this->Scale(-100, 100, $x);
  10705. }
  10706. /**
  10707. * Verical Mirroring.
  10708. * @param float|null $y ordinate of the point. Default is current y position
  10709. * @public
  10710. * @since 2.1.000 (2008-01-07)
  10711. * @see StartTransform(), StopTransform()
  10712. */
  10713. public function MirrorV($y=null) {
  10714. $this->Scale(100, -100, null, $y);
  10715. }
  10716. /**
  10717. * Point reflection mirroring.
  10718. * @param float|null $x abscissa of the point. Default is current x position
  10719. * @param float|null $y ordinate of the point. Default is current y position
  10720. * @public
  10721. * @since 2.1.000 (2008-01-07)
  10722. * @see StartTransform(), StopTransform()
  10723. */
  10724. public function MirrorP($x=null,$y=null) {
  10725. $this->Scale(-100, -100, $x, $y);
  10726. }
  10727. /**
  10728. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  10729. * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  10730. * @param float|null $x abscissa of the point. Default is current x position
  10731. * @param float|null $y ordinate of the point. Default is current y position
  10732. * @public
  10733. * @since 2.1.000 (2008-01-07)
  10734. * @see StartTransform(), StopTransform()
  10735. */
  10736. public function MirrorL($angle=0, $x=null,$y=null) {
  10737. $this->Scale(-100, 100, $x, $y);
  10738. $this->Rotate(-2*($angle-90), $x, $y);
  10739. }
  10740. /**
  10741. * Translate graphic object horizontally.
  10742. * @param int $t_x movement to the right (or left for RTL)
  10743. * @public
  10744. * @since 2.1.000 (2008-01-07)
  10745. * @see StartTransform(), StopTransform()
  10746. */
  10747. public function TranslateX($t_x) {
  10748. $this->Translate($t_x, 0);
  10749. }
  10750. /**
  10751. * Translate graphic object vertically.
  10752. * @param int $t_y movement to the bottom
  10753. * @public
  10754. * @since 2.1.000 (2008-01-07)
  10755. * @see StartTransform(), StopTransform()
  10756. */
  10757. public function TranslateY($t_y) {
  10758. $this->Translate(0, $t_y);
  10759. }
  10760. /**
  10761. * Translate graphic object horizontally and vertically.
  10762. * @param int $t_x movement to the right
  10763. * @param int $t_y movement to the bottom
  10764. * @public
  10765. * @since 2.1.000 (2008-01-07)
  10766. * @see StartTransform(), StopTransform()
  10767. */
  10768. public function Translate($t_x, $t_y) {
  10769. //calculate elements of transformation matrix
  10770. $tm = array();
  10771. $tm[0] = 1;
  10772. $tm[1] = 0;
  10773. $tm[2] = 0;
  10774. $tm[3] = 1;
  10775. $tm[4] = $t_x * $this->k;
  10776. $tm[5] = -$t_y * $this->k;
  10777. //translate the coordinate system
  10778. $this->Transform($tm);
  10779. }
  10780. /**
  10781. * Rotate object.
  10782. * @param float $angle angle in degrees for counter-clockwise rotation
  10783. * @param float|null $x abscissa of the rotation center. Default is current x position
  10784. * @param float|null $y ordinate of the rotation center. Default is current y position
  10785. * @public
  10786. * @since 2.1.000 (2008-01-07)
  10787. * @see StartTransform(), StopTransform()
  10788. */
  10789. public function Rotate($angle, $x=null, $y=null) {
  10790. if (TCPDF_STATIC::empty_string($x)) {
  10791. $x = $this->x;
  10792. }
  10793. if (TCPDF_STATIC::empty_string($y)) {
  10794. $y = $this->y;
  10795. }
  10796. $y = ($this->h - $y) * $this->k;
  10797. $x *= $this->k;
  10798. //calculate elements of transformation matrix
  10799. $tm = array();
  10800. $tm[0] = cos(deg2rad($angle));
  10801. $tm[1] = sin(deg2rad($angle));
  10802. $tm[2] = -$tm[1];
  10803. $tm[3] = $tm[0];
  10804. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  10805. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  10806. //rotate the coordinate system around ($x,$y)
  10807. $this->Transform($tm);
  10808. }
  10809. /**
  10810. * Skew horizontally.
  10811. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10812. * @param float|null $x abscissa of the skewing center. default is current x position
  10813. * @param float|null $y ordinate of the skewing center. default is current y position
  10814. * @public
  10815. * @since 2.1.000 (2008-01-07)
  10816. * @see StartTransform(), StopTransform()
  10817. */
  10818. public function SkewX($angle_x, $x=null, $y=null) {
  10819. $this->Skew($angle_x, 0, $x, $y);
  10820. }
  10821. /**
  10822. * Skew vertically.
  10823. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10824. * @param float|null $x abscissa of the skewing center. default is current x position
  10825. * @param float|null $y ordinate of the skewing center. default is current y position
  10826. * @public
  10827. * @since 2.1.000 (2008-01-07)
  10828. * @see StartTransform(), StopTransform()
  10829. */
  10830. public function SkewY($angle_y, $x=null, $y=null) {
  10831. $this->Skew(0, $angle_y, $x, $y);
  10832. }
  10833. /**
  10834. * Skew.
  10835. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10836. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10837. * @param float|null $x abscissa of the skewing center. default is current x position
  10838. * @param float|null $y ordinate of the skewing center. default is current y position
  10839. * @public
  10840. * @since 2.1.000 (2008-01-07)
  10841. * @see StartTransform(), StopTransform()
  10842. */
  10843. public function Skew($angle_x, $angle_y, $x=null, $y=null) {
  10844. if (TCPDF_STATIC::empty_string($x)) {
  10845. $x = $this->x;
  10846. }
  10847. if (TCPDF_STATIC::empty_string($y)) {
  10848. $y = $this->y;
  10849. }
  10850. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  10851. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  10852. }
  10853. $x *= $this->k;
  10854. $y = ($this->h - $y) * $this->k;
  10855. //calculate elements of transformation matrix
  10856. $tm = array();
  10857. $tm[0] = 1;
  10858. $tm[1] = tan(deg2rad($angle_y));
  10859. $tm[2] = tan(deg2rad($angle_x));
  10860. $tm[3] = 1;
  10861. $tm[4] = -$tm[2] * $y;
  10862. $tm[5] = -$tm[1] * $x;
  10863. //skew the coordinate system
  10864. $this->Transform($tm);
  10865. }
  10866. /**
  10867. * Apply graphic transformations.
  10868. * @param array $tm transformation matrix
  10869. * @protected
  10870. * @since 2.1.000 (2008-01-07)
  10871. * @see StartTransform(), StopTransform()
  10872. */
  10873. protected function Transform($tm) {
  10874. if ($this->state != 2) {
  10875. return;
  10876. }
  10877. $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  10878. // add tranformation matrix
  10879. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  10880. // update transformation mark
  10881. if ($this->inxobj) {
  10882. // we are inside an XObject template
  10883. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  10884. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  10885. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10886. }
  10887. } elseif (end($this->transfmrk[$this->page]) !== false) {
  10888. $key = key($this->transfmrk[$this->page]);
  10889. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  10890. }
  10891. }
  10892. // END TRANSFORMATIONS SECTION -------------------------
  10893. // START GRAPHIC FUNCTIONS SECTION ---------------------
  10894. // The following section is based on the code provided by David Hernandez Sanz
  10895. /**
  10896. * 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.
  10897. * @param float $width The width.
  10898. * @public
  10899. * @since 1.0
  10900. * @see Line(), Rect(), Cell(), MultiCell()
  10901. */
  10902. public function setLineWidth($width) {
  10903. //Set line width
  10904. $this->LineWidth = $width;
  10905. $this->linestyleWidth = sprintf('%F w', ($width * $this->k));
  10906. if ($this->state == 2) {
  10907. $this->_out($this->linestyleWidth);
  10908. }
  10909. }
  10910. /**
  10911. * Returns the current the line width.
  10912. * @return int Line width
  10913. * @public
  10914. * @since 2.1.000 (2008-01-07)
  10915. * @see Line(), SetLineWidth()
  10916. */
  10917. public function GetLineWidth() {
  10918. return $this->LineWidth;
  10919. }
  10920. /**
  10921. * Set line style.
  10922. * @param array $style Line style. Array with keys among the following:
  10923. * <ul>
  10924. * <li>width (float): Width of the line in user units.</li>
  10925. * <li>cap (string): Type of cap to put on the line. Possible values are:
  10926. * butt, round, square. The difference between "square" and "butt" is that
  10927. * "square" projects a flat end past the end of the line.</li>
  10928. * <li>join (string): Type of join. Possible values are: miter, round,
  10929. * bevel.</li>
  10930. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  10931. * series of length values, which are the lengths of the on and off dashes.
  10932. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  10933. * 1 off, 2 on, 1 off, ...</li>
  10934. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  10935. * the point at which the pattern starts.</li>
  10936. * <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>
  10937. * </ul>
  10938. * @param boolean $ret if true do not send the command.
  10939. * @return string the PDF command
  10940. * @public
  10941. * @since 2.1.000 (2008-01-08)
  10942. */
  10943. public function setLineStyle($style, $ret=false) {
  10944. $s = ''; // string to be returned
  10945. if (!is_array($style)) {
  10946. return $s;
  10947. }
  10948. if (isset($style['width'])) {
  10949. $this->LineWidth = $style['width'];
  10950. $this->linestyleWidth = sprintf('%F w', ($style['width'] * $this->k));
  10951. $s .= $this->linestyleWidth.' ';
  10952. }
  10953. if (isset($style['cap'])) {
  10954. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  10955. if (isset($ca[$style['cap']])) {
  10956. $this->linestyleCap = $ca[$style['cap']].' J';
  10957. $s .= $this->linestyleCap.' ';
  10958. }
  10959. }
  10960. if (isset($style['join'])) {
  10961. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  10962. if (isset($ja[$style['join']])) {
  10963. $this->linestyleJoin = $ja[$style['join']].' j';
  10964. $s .= $this->linestyleJoin.' ';
  10965. }
  10966. }
  10967. if (isset($style['dash'])) {
  10968. $dash_string = '';
  10969. if ($style['dash']) {
  10970. if (preg_match('/^.+,/', $style['dash']) > 0) {
  10971. $tab = explode(',', $style['dash']);
  10972. } else {
  10973. $tab = array($style['dash']);
  10974. }
  10975. $dash_string = '';
  10976. foreach ($tab as $i => $v) {
  10977. if ($i) {
  10978. $dash_string .= ' ';
  10979. }
  10980. $dash_string .= sprintf('%F', $v);
  10981. }
  10982. }
  10983. if (!isset($style['phase']) OR !$style['dash']) {
  10984. $style['phase'] = 0;
  10985. }
  10986. $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']);
  10987. $s .= $this->linestyleDash.' ';
  10988. }
  10989. if (isset($style['color'])) {
  10990. $s .= $this->setDrawColorArray($style['color'], true).' ';
  10991. }
  10992. if (!$ret AND ($this->state == 2)) {
  10993. $this->_out($s);
  10994. }
  10995. return $s;
  10996. }
  10997. /**
  10998. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  10999. * @param float $x Abscissa of point.
  11000. * @param float $y Ordinate of point.
  11001. * @protected
  11002. * @since 2.1.000 (2008-01-08)
  11003. */
  11004. protected function _outPoint($x, $y) {
  11005. if ($this->state == 2) {
  11006. $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k)));
  11007. }
  11008. }
  11009. /**
  11010. * Append a straight line segment from the current point to the point (x, y).
  11011. * The new current point shall be (x, y).
  11012. * @param float $x Abscissa of end point.
  11013. * @param float $y Ordinate of end point.
  11014. * @protected
  11015. * @since 2.1.000 (2008-01-08)
  11016. */
  11017. protected function _outLine($x, $y) {
  11018. if ($this->state == 2) {
  11019. $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k)));
  11020. }
  11021. }
  11022. /**
  11023. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  11024. * @param float $x Abscissa of upper-left corner.
  11025. * @param float $y Ordinate of upper-left corner.
  11026. * @param float $w Width.
  11027. * @param float $h Height.
  11028. * @param string $op options
  11029. * @protected
  11030. * @since 2.1.000 (2008-01-08)
  11031. */
  11032. protected function _outRect($x, $y, $w, $h, $op) {
  11033. if ($this->state == 2) {
  11034. $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k), (($this->h - $y) * $this->k), ($w * $this->k), (-$h * $this->k), $op));
  11035. }
  11036. }
  11037. /**
  11038. * 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.
  11039. * The new current point shall be (x3, y3).
  11040. * @param float $x1 Abscissa of control point 1.
  11041. * @param float $y1 Ordinate of control point 1.
  11042. * @param float $x2 Abscissa of control point 2.
  11043. * @param float $y2 Ordinate of control point 2.
  11044. * @param float $x3 Abscissa of end point.
  11045. * @param float $y3 Ordinate of end point.
  11046. * @protected
  11047. * @since 2.1.000 (2008-01-08)
  11048. */
  11049. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
  11050. if ($this->state == 2) {
  11051. $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)));
  11052. }
  11053. }
  11054. /**
  11055. * 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.
  11056. * The new current point shall be (x3, y3).
  11057. * @param float $x2 Abscissa of control point 2.
  11058. * @param float $y2 Ordinate of control point 2.
  11059. * @param float $x3 Abscissa of end point.
  11060. * @param float $y3 Ordinate of end point.
  11061. * @protected
  11062. * @since 4.9.019 (2010-04-26)
  11063. */
  11064. protected function _outCurveV($x2, $y2, $x3, $y3) {
  11065. if ($this->state == 2) {
  11066. $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  11067. }
  11068. }
  11069. /**
  11070. * 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.
  11071. * The new current point shall be (x3, y3).
  11072. * @param float $x1 Abscissa of control point 1.
  11073. * @param float $y1 Ordinate of control point 1.
  11074. * @param float $x3 Abscissa of end point.
  11075. * @param float $y3 Ordinate of end point.
  11076. * @protected
  11077. * @since 2.1.000 (2008-01-08)
  11078. */
  11079. protected function _outCurveY($x1, $y1, $x3, $y3) {
  11080. if ($this->state == 2) {
  11081. $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  11082. }
  11083. }
  11084. /**
  11085. * Draws a line between two points.
  11086. * @param float $x1 Abscissa of first point.
  11087. * @param float $y1 Ordinate of first point.
  11088. * @param float $x2 Abscissa of second point.
  11089. * @param float $y2 Ordinate of second point.
  11090. * @param array $style Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  11091. * @public
  11092. * @since 1.0
  11093. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  11094. */
  11095. public function Line($x1, $y1, $x2, $y2, $style=array()) {
  11096. if ($this->state != 2) {
  11097. return;
  11098. }
  11099. if (is_array($style)) {
  11100. $this->setLineStyle($style);
  11101. }
  11102. $this->_outPoint($x1, $y1);
  11103. $this->_outLine($x2, $y2);
  11104. $this->_out('S');
  11105. }
  11106. /**
  11107. * Draws a rectangle.
  11108. * @param float $x Abscissa of upper-left corner.
  11109. * @param float $y Ordinate of upper-left corner.
  11110. * @param float $w Width.
  11111. * @param float $h Height.
  11112. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11113. * @param array $border_style Border style of rectangle. Array with keys among the following:
  11114. * <ul>
  11115. * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  11116. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  11117. * </ul>
  11118. * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
  11119. * @param array $fill_color 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).
  11120. * @public
  11121. * @since 1.0
  11122. * @see SetLineStyle()
  11123. */
  11124. public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
  11125. if ($this->state != 2) {
  11126. return;
  11127. }
  11128. if (empty($style)) {
  11129. $style = 'S';
  11130. }
  11131. if (!(strpos($style, 'F') === false) AND !empty($fill_color)) {
  11132. // set background color
  11133. $this->setFillColorArray($fill_color);
  11134. }
  11135. if (!empty($border_style)) {
  11136. if (isset($border_style['all']) AND !empty($border_style['all'])) {
  11137. //set global style for border
  11138. $this->setLineStyle($border_style['all']);
  11139. $border_style = array();
  11140. } else {
  11141. // remove stroke operator from style
  11142. $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*' );
  11143. if (isset($opnostroke[$style])) {
  11144. $style = $opnostroke[$style];
  11145. }
  11146. }
  11147. }
  11148. if (!empty($style)) {
  11149. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11150. $this->_outRect($x, $y, $w, $h, $op);
  11151. }
  11152. if (!empty($border_style)) {
  11153. $border_style2 = array();
  11154. foreach ($border_style as $line => $value) {
  11155. $length = strlen($line);
  11156. for ($i = 0; $i < $length; ++$i) {
  11157. $border_style2[$line[$i]] = $value;
  11158. }
  11159. }
  11160. $border_style = $border_style2;
  11161. if (isset($border_style['L']) AND $border_style['L']) {
  11162. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  11163. }
  11164. if (isset($border_style['T']) AND $border_style['T']) {
  11165. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  11166. }
  11167. if (isset($border_style['R']) AND $border_style['R']) {
  11168. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  11169. }
  11170. if (isset($border_style['B']) AND $border_style['B']) {
  11171. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  11172. }
  11173. }
  11174. }
  11175. /**
  11176. * Draws a Bezier curve.
  11177. * The Bezier curve is a tangent to the line between the control points at
  11178. * either end of the curve.
  11179. * @param float $x0 Abscissa of start point.
  11180. * @param float $y0 Ordinate of start point.
  11181. * @param float $x1 Abscissa of control point 1.
  11182. * @param float $y1 Ordinate of control point 1.
  11183. * @param float $x2 Abscissa of control point 2.
  11184. * @param float $y2 Ordinate of control point 2.
  11185. * @param float $x3 Abscissa of end point.
  11186. * @param float $y3 Ordinate of end point.
  11187. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11188. * @param array $line_style Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11189. * @param array $fill_color 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).
  11190. * @public
  11191. * @see SetLineStyle()
  11192. * @since 2.1.000 (2008-01-08)
  11193. */
  11194. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
  11195. if ($this->state != 2) {
  11196. return;
  11197. }
  11198. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11199. $this->setFillColorArray($fill_color);
  11200. }
  11201. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11202. if ($line_style) {
  11203. $this->setLineStyle($line_style);
  11204. }
  11205. $this->_outPoint($x0, $y0);
  11206. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11207. $this->_out($op);
  11208. }
  11209. /**
  11210. * Draws a poly-Bezier curve.
  11211. * Each Bezier curve segment is a tangent to the line between the control points at
  11212. * either end of the curve.
  11213. * @param float $x0 Abscissa of start point.
  11214. * @param float $y0 Ordinate of start point.
  11215. * @param float[] $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  11216. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11217. * @param array $line_style Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11218. * @param array $fill_color 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).
  11219. * @public
  11220. * @see SetLineStyle()
  11221. * @since 3.0008 (2008-05-12)
  11222. */
  11223. public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
  11224. if ($this->state != 2) {
  11225. return;
  11226. }
  11227. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11228. $this->setFillColorArray($fill_color);
  11229. }
  11230. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11231. if ($op == 'f') {
  11232. $line_style = array();
  11233. }
  11234. if ($line_style) {
  11235. $this->setLineStyle($line_style);
  11236. }
  11237. $this->_outPoint($x0, $y0);
  11238. foreach ($segments as $segment) {
  11239. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  11240. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11241. }
  11242. $this->_out($op);
  11243. }
  11244. /**
  11245. * Draws an ellipse.
  11246. * An ellipse is formed from n Bezier curves.
  11247. * @param float $x0 Abscissa of center point.
  11248. * @param float $y0 Ordinate of center point.
  11249. * @param float $rx Horizontal radius.
  11250. * @param float $ry Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11251. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11252. * @param float $astart Angle start of draw line. Default value: 0.
  11253. * @param float $afinish Angle finish of draw line. Default value: 360.
  11254. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11255. * @param array $line_style Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  11256. * @param array $fill_color 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).
  11257. * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
  11258. * @author Nicola Asuni
  11259. * @public
  11260. * @since 2.1.000 (2008-01-08)
  11261. */
  11262. public function Ellipse($x0, $y0, $rx, $ry=0, $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11263. if ($this->state != 2) {
  11264. return;
  11265. }
  11266. if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
  11267. $ry = $rx;
  11268. }
  11269. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11270. $this->setFillColorArray($fill_color);
  11271. }
  11272. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11273. if ($op == 'f') {
  11274. $line_style = array();
  11275. }
  11276. if ($line_style) {
  11277. $this->setLineStyle($line_style);
  11278. }
  11279. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
  11280. $this->_out($op);
  11281. }
  11282. /**
  11283. * Append an elliptical arc to the current path.
  11284. * An ellipse is formed from n Bezier curves.
  11285. * @param float $xc Abscissa of center point.
  11286. * @param float $yc Ordinate of center point.
  11287. * @param float $rx Horizontal radius.
  11288. * @param float $ry Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11289. * @param float $xang Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  11290. * @param float $angs Angle start of draw line. Default value: 0.
  11291. * @param float $angf Angle finish of draw line. Default value: 360.
  11292. * @param boolean $pie if true do not mark the border point (used to draw pie sectors).
  11293. * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
  11294. * @param boolean $startpoint if true output a starting point.
  11295. * @param boolean $ccw if true draws in counter-clockwise.
  11296. * @param boolean $svg if true the angles are in svg mode (already calculated).
  11297. * @return array bounding box coordinates (x min, y min, x max, y max)
  11298. * @author Nicola Asuni
  11299. * @protected
  11300. * @since 4.9.019 (2010-04-26)
  11301. */
  11302. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
  11303. if (($rx <= 0) OR ($ry < 0)) {
  11304. return;
  11305. }
  11306. $k = $this->k;
  11307. if ($nc < 2) {
  11308. $nc = 2;
  11309. }
  11310. $xmin = 2147483647;
  11311. $ymin = 2147483647;
  11312. $xmax = 0;
  11313. $ymax = 0;
  11314. if ($pie) {
  11315. // center of the arc
  11316. $this->_outPoint($xc, $yc);
  11317. }
  11318. $xang = deg2rad((float) $xang);
  11319. $angs = deg2rad((float) $angs);
  11320. $angf = deg2rad((float) $angf);
  11321. if ($svg) {
  11322. $as = $angs;
  11323. $af = $angf;
  11324. } else {
  11325. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  11326. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  11327. }
  11328. if ($as < 0) {
  11329. $as += (2 * M_PI);
  11330. }
  11331. if ($af < 0) {
  11332. $af += (2 * M_PI);
  11333. }
  11334. if ($ccw AND ($as > $af)) {
  11335. // reverse rotation
  11336. $as -= (2 * M_PI);
  11337. } elseif (!$ccw AND ($as < $af)) {
  11338. // reverse rotation
  11339. $af -= (2 * M_PI);
  11340. }
  11341. $total_angle = ($af - $as);
  11342. if ($nc < 2) {
  11343. $nc = 2;
  11344. }
  11345. // total arcs to draw
  11346. $nc *= (2 * abs($total_angle) / M_PI);
  11347. $nc = round($nc) + 1;
  11348. // angle of each arc
  11349. $arcang = ($total_angle / $nc);
  11350. // center point in PDF coordinates
  11351. $x0 = $xc;
  11352. $y0 = ($this->h - $yc);
  11353. // starting angle
  11354. $ang = $as;
  11355. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  11356. $cos_xang = cos($xang);
  11357. $sin_xang = sin($xang);
  11358. $cos_ang = cos($ang);
  11359. $sin_ang = sin($ang);
  11360. // first arc point
  11361. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11362. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11363. // first Bezier control point
  11364. $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11365. $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11366. if ($pie) {
  11367. // line from center to arc starting point
  11368. $this->_outLine($px1, $this->h - $py1);
  11369. } elseif ($startpoint) {
  11370. // arc starting point
  11371. $this->_outPoint($px1, $this->h - $py1);
  11372. }
  11373. // draw arcs
  11374. for ($i = 1; $i <= $nc; ++$i) {
  11375. // starting angle
  11376. $ang = $as + ($i * $arcang);
  11377. if ($i == $nc) {
  11378. $ang = $af;
  11379. }
  11380. $cos_ang = cos($ang);
  11381. $sin_ang = sin($ang);
  11382. // second arc point
  11383. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11384. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11385. // second Bezier control point
  11386. $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11387. $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11388. // draw arc
  11389. $cx1 = ($px1 + $qx1);
  11390. $cy1 = ($this->h - ($py1 + $qy1));
  11391. $cx2 = ($px2 - $qx2);
  11392. $cy2 = ($this->h - ($py2 - $qy2));
  11393. $cx3 = $px2;
  11394. $cy3 = ($this->h - $py2);
  11395. $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
  11396. // get bounding box coordinates
  11397. $xmin = min($xmin, $cx1, $cx2, $cx3);
  11398. $ymin = min($ymin, $cy1, $cy2, $cy3);
  11399. $xmax = max($xmax, $cx1, $cx2, $cx3);
  11400. $ymax = max($ymax, $cy1, $cy2, $cy3);
  11401. // move to next point
  11402. $px1 = $px2;
  11403. $py1 = $py2;
  11404. $qx1 = $qx2;
  11405. $qy1 = $qy2;
  11406. }
  11407. if ($pie) {
  11408. $this->_outLine($xc, $yc);
  11409. // get bounding box coordinates
  11410. $xmin = min($xmin, $xc);
  11411. $ymin = min($ymin, $yc);
  11412. $xmax = max($xmax, $xc);
  11413. $ymax = max($ymax, $yc);
  11414. }
  11415. return array($xmin, $ymin, $xmax, $ymax);
  11416. }
  11417. /**
  11418. * Draws a circle.
  11419. * A circle is formed from n Bezier curves.
  11420. * @param float $x0 Abscissa of center point.
  11421. * @param float $y0 Ordinate of center point.
  11422. * @param float $r Radius.
  11423. * @param float $angstr Angle start of draw line. Default value: 0.
  11424. * @param float $angend Angle finish of draw line. Default value: 360.
  11425. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11426. * @param array $line_style Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11427. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11428. * @param integer $nc Number of curves used to draw a 90 degrees portion of circle.
  11429. * @public
  11430. * @since 2.1.000 (2008-01-08)
  11431. */
  11432. public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11433. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  11434. }
  11435. /**
  11436. * Draws a polygonal line
  11437. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11438. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11439. * @param array $line_style Line style of polygon. Array with keys among the following:
  11440. * <ul>
  11441. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11442. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11443. * </ul>
  11444. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11445. * @param array $fill_color 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).
  11446. * @since 4.8.003 (2009-09-15)
  11447. * @public
  11448. */
  11449. public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
  11450. $this->Polygon($p, $style, $line_style, $fill_color, false);
  11451. }
  11452. /**
  11453. * Draws a polygon.
  11454. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11455. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11456. * @param array $line_style Line style of polygon. Array with keys among the following:
  11457. * <ul>
  11458. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11459. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11460. * </ul>
  11461. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11462. * @param array $fill_color 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).
  11463. * @param boolean $closed if true the polygon is closes, otherwise will remain open
  11464. * @public
  11465. * @since 2.1.000 (2008-01-08)
  11466. */
  11467. public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
  11468. if ($this->state != 2) {
  11469. return;
  11470. }
  11471. $nc = count($p); // number of coordinates
  11472. $np = $nc / 2; // number of points
  11473. if ($closed) {
  11474. // close polygon by adding the first 2 points at the end (one line)
  11475. for ($i = 0; $i < 4; ++$i) {
  11476. $p[$nc + $i] = $p[$i];
  11477. }
  11478. // copy style for the last added line
  11479. if (isset($line_style[0])) {
  11480. $line_style[$np] = $line_style[0];
  11481. }
  11482. $nc += 4;
  11483. }
  11484. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11485. $this->setFillColorArray($fill_color);
  11486. }
  11487. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11488. if ($op == 'f') {
  11489. $line_style = array();
  11490. }
  11491. $draw = true;
  11492. if ($line_style) {
  11493. if (isset($line_style['all'])) {
  11494. $this->setLineStyle($line_style['all']);
  11495. } else {
  11496. $draw = false;
  11497. if ($op == 'B') {
  11498. // draw fill
  11499. $op = 'f';
  11500. $this->_outPoint($p[0], $p[1]);
  11501. for ($i = 2; $i < $nc; $i = $i + 2) {
  11502. $this->_outLine($p[$i], $p[$i + 1]);
  11503. }
  11504. $this->_out($op);
  11505. }
  11506. // draw outline
  11507. $this->_outPoint($p[0], $p[1]);
  11508. for ($i = 2; $i < $nc; $i = $i + 2) {
  11509. $line_num = ($i / 2) - 1;
  11510. if (isset($line_style[$line_num])) {
  11511. if ($line_style[$line_num] != 0) {
  11512. if (is_array($line_style[$line_num])) {
  11513. $this->_out('S');
  11514. $this->setLineStyle($line_style[$line_num]);
  11515. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  11516. $this->_outLine($p[$i], $p[$i + 1]);
  11517. $this->_out('S');
  11518. $this->_outPoint($p[$i], $p[$i + 1]);
  11519. } else {
  11520. $this->_outLine($p[$i], $p[$i + 1]);
  11521. }
  11522. }
  11523. } else {
  11524. $this->_outLine($p[$i], $p[$i + 1]);
  11525. }
  11526. }
  11527. $this->_out($op);
  11528. }
  11529. }
  11530. if ($draw) {
  11531. $this->_outPoint($p[0], $p[1]);
  11532. for ($i = 2; $i < $nc; $i = $i + 2) {
  11533. $this->_outLine($p[$i], $p[$i + 1]);
  11534. }
  11535. $this->_out($op);
  11536. }
  11537. }
  11538. /**
  11539. * Draws a regular polygon.
  11540. * @param float $x0 Abscissa of center point.
  11541. * @param float $y0 Ordinate of center point.
  11542. * @param float $r Radius of inscribed circle.
  11543. * @param integer $ns Number of sides.
  11544. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11545. * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  11546. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11547. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  11548. * <ul>
  11549. * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  11550. * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  11551. * </ul>
  11552. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11553. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11554. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  11555. * <ul>
  11556. * <li>D or empty string: Draw (default).</li>
  11557. * <li>F: Fill.</li>
  11558. * <li>DF or FD: Draw and fill.</li>
  11559. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11560. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11561. * </ul>
  11562. * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11563. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11564. * @public
  11565. * @since 2.1.000 (2008-01-08)
  11566. */
  11567. 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()) {
  11568. if (3 > $ns) {
  11569. $ns = 3;
  11570. }
  11571. if ($draw_circle) {
  11572. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11573. }
  11574. $p = array();
  11575. for ($i = 0; $i < $ns; ++$i) {
  11576. $a = $angle + ($i * 360 / $ns);
  11577. $a_rad = deg2rad((float) $a);
  11578. $p[] = $x0 + ($r * sin($a_rad));
  11579. $p[] = $y0 + ($r * cos($a_rad));
  11580. }
  11581. $this->Polygon($p, $style, $line_style, $fill_color);
  11582. }
  11583. /**
  11584. * Draws a star polygon
  11585. * @param float $x0 Abscissa of center point.
  11586. * @param float $y0 Ordinate of center point.
  11587. * @param float $r Radius of inscribed circle.
  11588. * @param integer $nv Number of vertices.
  11589. * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  11590. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11591. * @param boolean $draw_circle Draw inscribed circle or not. Default value is false.
  11592. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11593. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  11594. * <ul>
  11595. * <li>all: Line style of all sides. Array like for
  11596. * SetLineStyle().</li>
  11597. * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  11598. * </ul>
  11599. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11600. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11601. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  11602. * <ul>
  11603. * <li>D or empty string: Draw (default).</li>
  11604. * <li>F: Fill.</li>
  11605. * <li>DF or FD: Draw and fill.</li>
  11606. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11607. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11608. * </ul>
  11609. * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11610. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11611. * @public
  11612. * @since 2.1.000 (2008-01-08)
  11613. */
  11614. 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()) {
  11615. if ($nv < 2) {
  11616. $nv = 2;
  11617. }
  11618. if ($draw_circle) {
  11619. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11620. }
  11621. $p2 = array();
  11622. $visited = array();
  11623. for ($i = 0; $i < $nv; ++$i) {
  11624. $a = $angle + ($i * 360 / $nv);
  11625. $a_rad = deg2rad((float) $a);
  11626. $p2[] = $x0 + ($r * sin($a_rad));
  11627. $p2[] = $y0 + ($r * cos($a_rad));
  11628. $visited[] = false;
  11629. }
  11630. $p = array();
  11631. $i = 0;
  11632. do {
  11633. $p[] = $p2[$i * 2];
  11634. $p[] = $p2[($i * 2) + 1];
  11635. $visited[$i] = true;
  11636. $i += $ng;
  11637. $i %= $nv;
  11638. } while (!$visited[$i]);
  11639. $this->Polygon($p, $style, $line_style, $fill_color);
  11640. }
  11641. /**
  11642. * Draws a rounded rectangle.
  11643. * @param float $x Abscissa of upper-left corner.
  11644. * @param float $y Ordinate of upper-left corner.
  11645. * @param float $w Width.
  11646. * @param float $h Height.
  11647. * @param float $r the radius of the circle used to round off the corners of the rectangle.
  11648. * @param string $round_corner 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").
  11649. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11650. * @param array $border_style Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11651. * @param array $fill_color 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).
  11652. * @public
  11653. * @since 2.1.000 (2008-01-08)
  11654. */
  11655. public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11656. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  11657. }
  11658. /**
  11659. * Draws a rounded rectangle.
  11660. * @param float $x Abscissa of upper-left corner.
  11661. * @param float $y Ordinate of upper-left corner.
  11662. * @param float $w Width.
  11663. * @param float $h Height.
  11664. * @param float $rx the x-axis radius of the ellipse used to round off the corners of the rectangle.
  11665. * @param float $ry the y-axis radius of the ellipse used to round off the corners of the rectangle.
  11666. * @param string $round_corner 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").
  11667. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11668. * @param array $border_style Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11669. * @param array $fill_color 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).
  11670. * @public
  11671. * @since 4.9.019 (2010-04-22)
  11672. */
  11673. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11674. if ($this->state != 2) {
  11675. return;
  11676. }
  11677. if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  11678. // Not rounded
  11679. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  11680. return;
  11681. }
  11682. // Rounded
  11683. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11684. $this->setFillColorArray($fill_color);
  11685. }
  11686. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11687. if ($op == 'f') {
  11688. $border_style = array();
  11689. }
  11690. if ($border_style) {
  11691. $this->setLineStyle($border_style);
  11692. }
  11693. $MyArc = 4 / 3 * (sqrt(2) - 1);
  11694. $this->_outPoint($x + $rx, $y);
  11695. $xc = $x + $w - $rx;
  11696. $yc = $y + $ry;
  11697. $this->_outLine($xc, $y);
  11698. if ($round_corner[0]) {
  11699. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  11700. } else {
  11701. $this->_outLine($x + $w, $y);
  11702. }
  11703. $xc = $x + $w - $rx;
  11704. $yc = $y + $h - $ry;
  11705. $this->_outLine($x + $w, $yc);
  11706. if ($round_corner[1]) {
  11707. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  11708. } else {
  11709. $this->_outLine($x + $w, $y + $h);
  11710. }
  11711. $xc = $x + $rx;
  11712. $yc = $y + $h - $ry;
  11713. $this->_outLine($xc, $y + $h);
  11714. if ($round_corner[2]) {
  11715. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  11716. } else {
  11717. $this->_outLine($x, $y + $h);
  11718. }
  11719. $xc = $x + $rx;
  11720. $yc = $y + $ry;
  11721. $this->_outLine($x, $yc);
  11722. if ($round_corner[3]) {
  11723. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  11724. } else {
  11725. $this->_outLine($x, $y);
  11726. $this->_outLine($x + $rx, $y);
  11727. }
  11728. $this->_out($op);
  11729. }
  11730. /**
  11731. * Draws a grahic arrow.
  11732. * @param float $x0 Abscissa of first point.
  11733. * @param float $y0 Ordinate of first point.
  11734. * @param float $x1 Abscissa of second point.
  11735. * @param float $y1 Ordinate of second point.
  11736. * @param int $head_style (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  11737. * @param float $arm_size length of arrowhead arms
  11738. * @param int $arm_angle angle between an arm and the shaft
  11739. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  11740. * @since 4.6.018 (2009-07-10)
  11741. */
  11742. public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
  11743. // getting arrow direction angle
  11744. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  11745. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  11746. if ($dir_angle < 0) {
  11747. $dir_angle += (2 * M_PI);
  11748. }
  11749. $arm_angle = deg2rad($arm_angle);
  11750. $sx1 = $x1;
  11751. $sy1 = $y1;
  11752. if ($head_style > 0) {
  11753. // calculate the stopping point for the arrow shaft
  11754. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  11755. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  11756. }
  11757. // main arrow line / shaft
  11758. $this->Line($x0, $y0, $sx1, $sy1);
  11759. // left arrowhead arm tip
  11760. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  11761. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  11762. // right arrowhead arm tip
  11763. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  11764. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  11765. $mode = 'D';
  11766. $style = array();
  11767. switch ($head_style) {
  11768. case 0: {
  11769. // draw only arrowhead arms
  11770. $mode = 'D';
  11771. $style = array(1, 1, 0);
  11772. break;
  11773. }
  11774. case 1: {
  11775. // draw closed arrowhead, but no fill
  11776. $mode = 'D';
  11777. break;
  11778. }
  11779. case 2: {
  11780. // closed and filled arrowhead
  11781. $mode = 'DF';
  11782. break;
  11783. }
  11784. case 3: {
  11785. // filled arrowhead
  11786. $mode = 'F';
  11787. break;
  11788. }
  11789. }
  11790. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  11791. }
  11792. // END GRAPHIC FUNCTIONS SECTION -----------------------
  11793. /**
  11794. * Add a Named Destination.
  11795. * NOTE: destination names are unique, so only last entry will be saved.
  11796. * @param string $name Destination name.
  11797. * @param float $y Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
  11798. * @param int|string $page 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.
  11799. * @param float $x X position in user units of the destiantion on the selected page (default = -1 = current position;).
  11800. * @return string|false Stripped named destination identifier or false in case of error.
  11801. * @public
  11802. * @author Christian Deligant, Nicola Asuni
  11803. * @since 5.9.097 (2011-06-23)
  11804. */
  11805. public function setDestination($name, $y=-1, $page='', $x=-1) {
  11806. // remove unsupported characters
  11807. $name = TCPDF_STATIC::encodeNameObject($name);
  11808. if (TCPDF_STATIC::empty_string($name)) {
  11809. return false;
  11810. }
  11811. if ($y == -1) {
  11812. $y = $this->GetY();
  11813. } elseif ($y < 0) {
  11814. $y = 0;
  11815. } elseif ($y > $this->h) {
  11816. $y = $this->h;
  11817. }
  11818. if ($x == -1) {
  11819. $x = $this->GetX();
  11820. } elseif ($x < 0) {
  11821. $x = 0;
  11822. } elseif ($x > $this->w) {
  11823. $x = $this->w;
  11824. }
  11825. $fixed = false;
  11826. if (!empty($page) AND (substr($page, 0, 1) == '*')) {
  11827. $page = intval(substr($page, 1));
  11828. // this page number will not be changed when moving/add/deleting pages
  11829. $fixed = true;
  11830. }
  11831. if (empty($page)) {
  11832. $page = $this->PageNo();
  11833. if (empty($page)) {
  11834. return;
  11835. }
  11836. }
  11837. $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed);
  11838. return $name;
  11839. }
  11840. /**
  11841. * Return the Named Destination array.
  11842. * @return array Named Destination array.
  11843. * @public
  11844. * @author Nicola Asuni
  11845. * @since 5.9.097 (2011-06-23)
  11846. */
  11847. public function getDestination() {
  11848. return $this->dests;
  11849. }
  11850. /**
  11851. * Insert Named Destinations.
  11852. * @protected
  11853. * @author Johannes G\FCntert, Nicola Asuni
  11854. * @since 5.9.098 (2011-06-23)
  11855. */
  11856. protected function _putdests() {
  11857. if (empty($this->dests)) {
  11858. return;
  11859. }
  11860. $this->n_dests = $this->_newobj();
  11861. $out = ' <<';
  11862. foreach($this->dests as $name => $o) {
  11863. $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)));
  11864. }
  11865. $out .= ' >>';
  11866. $out .= "\n".'endobj';
  11867. $this->_out($out);
  11868. }
  11869. /**
  11870. * Adds a bookmark - alias for Bookmark().
  11871. * @param string $txt Bookmark description.
  11872. * @param int $level Bookmark level (minimum value is 0).
  11873. * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11874. * @param int|string $page 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.
  11875. * @param string $style Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11876. * @param array $color RGB color array (values from 0 to 255).
  11877. * @param float $x X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11878. * @param mixed $link URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  11879. * @public
  11880. */
  11881. public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11882. $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
  11883. }
  11884. /**
  11885. * Adds a bookmark.
  11886. * @param string $txt Bookmark description.
  11887. * @param int $level Bookmark level (minimum value is 0).
  11888. * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11889. * @param int|string $page 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.
  11890. * @param string $style Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11891. * @param array $color RGB color array (values from 0 to 255).
  11892. * @param float $x X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11893. * @param mixed $link URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  11894. * @public
  11895. * @since 2.1.002 (2008-02-12)
  11896. */
  11897. public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11898. if ($level < 0) {
  11899. $level = 0;
  11900. }
  11901. if (isset($this->outlines[0])) {
  11902. $lastoutline = end($this->outlines);
  11903. $maxlevel = $lastoutline['l'] + 1;
  11904. } else {
  11905. $maxlevel = 0;
  11906. }
  11907. if ($level > $maxlevel) {
  11908. $level = $maxlevel;
  11909. }
  11910. if ($y == -1) {
  11911. $y = $this->GetY();
  11912. } elseif ($y < 0) {
  11913. $y = 0;
  11914. } elseif ($y > $this->h) {
  11915. $y = $this->h;
  11916. }
  11917. if ($x == -1) {
  11918. $x = $this->GetX();
  11919. } elseif ($x < 0) {
  11920. $x = 0;
  11921. } elseif ($x > $this->w) {
  11922. $x = $this->w;
  11923. }
  11924. $fixed = false;
  11925. $pageAsString = (string) $page;
  11926. if ($pageAsString && $pageAsString[0] == '*') {
  11927. $page = intval(substr($page, 1));
  11928. // this page number will not be changed when moving/add/deleting pages
  11929. $fixed = true;
  11930. }
  11931. if (empty($page)) {
  11932. $page = $this->PageNo();
  11933. if (empty($page)) {
  11934. return;
  11935. }
  11936. }
  11937. $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
  11938. }
  11939. /**
  11940. * Sort bookmarks for page and key.
  11941. * @protected
  11942. * @since 5.9.119 (2011-09-19)
  11943. */
  11944. protected function sortBookmarks() {
  11945. // get sorting columns
  11946. $outline_p = array();
  11947. $outline_y = array();
  11948. foreach ($this->outlines as $key => $row) {
  11949. $outline_p[$key] = $row['p'];
  11950. $outline_k[$key] = $key;
  11951. }
  11952. // sort outlines by page and original position
  11953. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  11954. }
  11955. /**
  11956. * Create a bookmark PDF string.
  11957. * @protected
  11958. * @author Olivier Plathey, Nicola Asuni
  11959. * @since 2.1.002 (2008-02-12)
  11960. */
  11961. protected function _putbookmarks() {
  11962. $nb = count($this->outlines);
  11963. if ($nb == 0) {
  11964. return;
  11965. }
  11966. // sort bookmarks
  11967. $this->sortBookmarks();
  11968. $lru = array();
  11969. $level = 0;
  11970. foreach ($this->outlines as $i => $o) {
  11971. if ($o['l'] > 0) {
  11972. $parent = $lru[($o['l'] - 1)];
  11973. //Set parent and last pointers
  11974. $this->outlines[$i]['parent'] = $parent;
  11975. $this->outlines[$parent]['last'] = $i;
  11976. if ($o['l'] > $level) {
  11977. //Level increasing: set first pointer
  11978. $this->outlines[$parent]['first'] = $i;
  11979. }
  11980. } else {
  11981. $this->outlines[$i]['parent'] = $nb;
  11982. }
  11983. if (($o['l'] <= $level) AND ($i > 0)) {
  11984. //Set prev and next pointers
  11985. $prev = $lru[$o['l']];
  11986. $this->outlines[$prev]['next'] = $i;
  11987. $this->outlines[$i]['prev'] = $prev;
  11988. }
  11989. $lru[$o['l']] = $i;
  11990. $level = $o['l'];
  11991. }
  11992. //Outline items
  11993. $n = $this->n + 1;
  11994. $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';
  11995. foreach ($this->outlines as $i => $o) {
  11996. $oid = $this->_newobj();
  11997. // covert HTML title to string
  11998. $title = preg_replace($nltags, "\n", $o['t']);
  11999. $title = preg_replace("/[\r]+/si", '', $title);
  12000. $title = preg_replace("/[\n]+/si", "\n", $title);
  12001. $title = strip_tags($title);
  12002. $title = $this->stringTrim($title);
  12003. $out = '<</Title '.$this->_textstring($title, $oid);
  12004. $out .= ' /Parent '.($n + $o['parent']).' 0 R';
  12005. if (isset($o['prev'])) {
  12006. $out .= ' /Prev '.($n + $o['prev']).' 0 R';
  12007. }
  12008. if (isset($o['next'])) {
  12009. $out .= ' /Next '.($n + $o['next']).' 0 R';
  12010. }
  12011. if (isset($o['first'])) {
  12012. $out .= ' /First '.($n + $o['first']).' 0 R';
  12013. }
  12014. if (isset($o['last'])) {
  12015. $out .= ' /Last '.($n + $o['last']).' 0 R';
  12016. }
  12017. if (isset($o['u']) AND !empty($o['u'])) {
  12018. // link
  12019. if (is_string($o['u'])) {
  12020. if ($o['u'][0] == '#') {
  12021. // internal destination
  12022. $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1));
  12023. } elseif ($o['u'][0] == '%') {
  12024. // embedded PDF file
  12025. $filename = basename(substr($o['u'], 1));
  12026. $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  12027. } elseif ($o['u'][0] == '*') {
  12028. // embedded generic file
  12029. $filename = basename(substr($o['u'], 1));
  12030. $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});';
  12031. $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
  12032. } else {
  12033. // external URI link
  12034. $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
  12035. }
  12036. } elseif (isset($this->links[$o['u']])) {
  12037. // internal link ID
  12038. $l = $this->links[$o['u']];
  12039. if (isset($this->page_obj_id[($l['p'])])) {
  12040. $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)));
  12041. }
  12042. }
  12043. } elseif (isset($this->page_obj_id[($o['p'])])) {
  12044. // link to a page
  12045. $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)));
  12046. }
  12047. // set font style
  12048. $style = 0;
  12049. if (!empty($o['s'])) {
  12050. // bold
  12051. if (strpos($o['s'], 'B') !== false) {
  12052. $style |= 2;
  12053. }
  12054. // oblique
  12055. if (strpos($o['s'], 'I') !== false) {
  12056. $style |= 1;
  12057. }
  12058. }
  12059. $out .= sprintf(' /F %d', $style);
  12060. // set bookmark color
  12061. if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
  12062. $color = array_values($o['c']);
  12063. $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  12064. } else {
  12065. // black
  12066. $out .= ' /C [0.0 0.0 0.0]';
  12067. }
  12068. $out .= ' /Count 0'; // normally closed item
  12069. $out .= ' >>';
  12070. $out .= "\n".'endobj';
  12071. $this->_out($out);
  12072. }
  12073. //Outline root
  12074. $this->OutlineRoot = $this->_newobj();
  12075. $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
  12076. }
  12077. // --- JAVASCRIPT ------------------------------------------------------
  12078. /**
  12079. * Adds a javascript
  12080. * @param string $script Javascript code
  12081. * @public
  12082. * @author Johannes G\FCntert, Nicola Asuni
  12083. * @since 2.1.002 (2008-02-12)
  12084. */
  12085. public function IncludeJS($script) {
  12086. $this->javascript .= $script;
  12087. }
  12088. /**
  12089. * Adds a javascript object and return object ID
  12090. * @param string $script Javascript code
  12091. * @param boolean $onload if true executes this object when opening the document
  12092. * @return int internal object ID
  12093. * @public
  12094. * @author Nicola Asuni
  12095. * @since 4.8.000 (2009-09-07)
  12096. */
  12097. public function addJavascriptObject($script, $onload=false) {
  12098. if ($this->pdfa_mode) {
  12099. // javascript is not allowed in PDF/A mode
  12100. return false;
  12101. }
  12102. ++$this->n;
  12103. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  12104. return $this->n;
  12105. }
  12106. /**
  12107. * Create a javascript PDF string.
  12108. * @protected
  12109. * @author Johannes G\FCntert, Nicola Asuni
  12110. * @since 2.1.002 (2008-02-12)
  12111. */
  12112. protected function _putjavascript() {
  12113. if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
  12114. return;
  12115. }
  12116. if (strpos($this->javascript, 'this.addField') > 0) {
  12117. if (!$this->ur['enabled']) {
  12118. //$this->setUserRights();
  12119. }
  12120. // the following two lines are used to avoid form fields duplication after saving
  12121. // The addField method only works when releasing user rights (UR3)
  12122. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  12123. $jsb = "getField('tcpdfdocsaved').value='saved';";
  12124. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  12125. }
  12126. // name tree for javascript
  12127. $this->n_js = '<< /Names [';
  12128. if (!empty($this->javascript)) {
  12129. $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
  12130. }
  12131. if (!empty($this->js_objects)) {
  12132. foreach ($this->js_objects as $key => $val) {
  12133. if ($val['onload']) {
  12134. $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
  12135. }
  12136. }
  12137. }
  12138. $this->n_js .= ' ] >>';
  12139. // default Javascript object
  12140. if (!empty($this->javascript)) {
  12141. $obj_id = $this->_newobj();
  12142. $out = '<< /S /JavaScript';
  12143. $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
  12144. $out .= ' >>';
  12145. $out .= "\n".'endobj';
  12146. $this->_out($out);
  12147. }
  12148. // additional Javascript objects
  12149. if (!empty($this->js_objects)) {
  12150. foreach ($this->js_objects as $key => $val) {
  12151. $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  12152. $this->_out($out);
  12153. }
  12154. }
  12155. }
  12156. /**
  12157. * Adds a javascript form field.
  12158. * @param string $type field type
  12159. * @param string $name field name
  12160. * @param int $x horizontal position
  12161. * @param int $y vertical position
  12162. * @param int $w width
  12163. * @param int $h height
  12164. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12165. * @protected
  12166. * @author Denis Van Nuffelen, Nicola Asuni
  12167. * @since 2.1.002 (2008-02-12)
  12168. */
  12169. protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
  12170. if ($this->rtl) {
  12171. $x = $x - $w;
  12172. }
  12173. // the followind avoid fields duplication after saving the document
  12174. $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
  12175. $k = $this->k;
  12176. $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";
  12177. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  12178. foreach($prop as $key => $val) {
  12179. if (strcmp(substr($key, -5), 'Color') == 0) {
  12180. $val = TCPDF_COLORS::_JScolor($val);
  12181. } else {
  12182. $val = "'".$val."'";
  12183. }
  12184. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  12185. }
  12186. if ($this->rtl) {
  12187. $this->x -= $w;
  12188. } else {
  12189. $this->x += $w;
  12190. }
  12191. $this->javascript .= '}';
  12192. }
  12193. // --- FORM FIELDS -----------------------------------------------------
  12194. /**
  12195. * Set default properties for form fields.
  12196. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12197. * @public
  12198. * @author Nicola Asuni
  12199. * @since 4.8.000 (2009-09-06)
  12200. */
  12201. public function setFormDefaultProp($prop=array()) {
  12202. $this->default_form_prop = $prop;
  12203. }
  12204. /**
  12205. * Return the default properties for form fields.
  12206. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12207. * @public
  12208. * @author Nicola Asuni
  12209. * @since 4.8.000 (2009-09-06)
  12210. */
  12211. public function getFormDefaultProp() {
  12212. return $this->default_form_prop;
  12213. }
  12214. /**
  12215. * Creates a text field
  12216. * @param string $name field name
  12217. * @param float $w Width of the rectangle
  12218. * @param float $h Height of the rectangle
  12219. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12220. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12221. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12222. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12223. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12224. * @public
  12225. * @author Nicola Asuni
  12226. * @since 4.8.000 (2009-09-07)
  12227. */
  12228. public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
  12229. if (TCPDF_STATIC::empty_string($x)) {
  12230. $x = $this->x;
  12231. }
  12232. if (TCPDF_STATIC::empty_string($y)) {
  12233. $y = $this->y;
  12234. }
  12235. // check page for no-write regions and adapt page margins if necessary
  12236. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12237. if ($js) {
  12238. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  12239. return;
  12240. }
  12241. // get default style
  12242. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12243. // get annotation data
  12244. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12245. // set default appearance stream
  12246. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12247. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12248. $popt['da'] = $fontstyle;
  12249. // build appearance stream
  12250. $popt['ap'] = array();
  12251. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12252. $text = '';
  12253. if (isset($prop['value']) AND !empty($prop['value'])) {
  12254. $text = $prop['value'];
  12255. } elseif (isset($opt['v']) AND !empty($opt['v'])) {
  12256. $text = $opt['v'];
  12257. }
  12258. $tmpid = $this->startTemplate($w, $h, false);
  12259. $align = '';
  12260. if (isset($popt['q'])) {
  12261. switch ($popt['q']) {
  12262. case 0: {
  12263. $align = 'L';
  12264. break;
  12265. }
  12266. case 1: {
  12267. $align = 'C';
  12268. break;
  12269. }
  12270. case 2: {
  12271. $align = 'R';
  12272. break;
  12273. }
  12274. default: {
  12275. $align = '';
  12276. break;
  12277. }
  12278. }
  12279. }
  12280. $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12281. $this->endTemplate();
  12282. --$this->n;
  12283. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12284. unset($this->xobjects[$tmpid]);
  12285. $popt['ap']['n'] .= 'Q EMC';
  12286. // merge options
  12287. $opt = array_merge($popt, $opt);
  12288. // remove some conflicting options
  12289. unset($opt['bs']);
  12290. // set remaining annotation data
  12291. $opt['Subtype'] = 'Widget';
  12292. $opt['ft'] = 'Tx';
  12293. $opt['t'] = $name;
  12294. // Additional annotation's parameters (check _putannotsobj() method):
  12295. //$opt['f']
  12296. //$opt['as']
  12297. //$opt['bs']
  12298. //$opt['be']
  12299. //$opt['c']
  12300. //$opt['border']
  12301. //$opt['h']
  12302. //$opt['mk'];
  12303. //$opt['mk']['r']
  12304. //$opt['mk']['bc'];
  12305. //$opt['mk']['bg'];
  12306. unset($opt['mk']['ca']);
  12307. unset($opt['mk']['rc']);
  12308. unset($opt['mk']['ac']);
  12309. unset($opt['mk']['i']);
  12310. unset($opt['mk']['ri']);
  12311. unset($opt['mk']['ix']);
  12312. unset($opt['mk']['if']);
  12313. //$opt['mk']['if']['sw'];
  12314. //$opt['mk']['if']['s'];
  12315. //$opt['mk']['if']['a'];
  12316. //$opt['mk']['if']['fb'];
  12317. unset($opt['mk']['tp']);
  12318. //$opt['tu']
  12319. //$opt['tm']
  12320. //$opt['ff']
  12321. //$opt['v']
  12322. //$opt['dv']
  12323. //$opt['a']
  12324. //$opt['aa']
  12325. //$opt['q']
  12326. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12327. if ($this->rtl) {
  12328. $this->x -= $w;
  12329. } else {
  12330. $this->x += $w;
  12331. }
  12332. }
  12333. /**
  12334. * Creates a RadioButton field.
  12335. * @param string $name Field name.
  12336. * @param int $w Width of the radio button.
  12337. * @param array $prop Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12338. * @param array $opt Annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12339. * @param string $onvalue Value to be returned if selected.
  12340. * @param boolean $checked Define the initial state.
  12341. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12342. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12343. * @param boolean $js If true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12344. * @public
  12345. * @author Nicola Asuni
  12346. * @since 4.8.000 (2009-09-07)
  12347. */
  12348. public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x=null, $y=null, $js=false) {
  12349. if (TCPDF_STATIC::empty_string($x)) {
  12350. $x = $this->x;
  12351. }
  12352. if (TCPDF_STATIC::empty_string($y)) {
  12353. $y = $this->y;
  12354. }
  12355. // check page for no-write regions and adapt page margins if necessary
  12356. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12357. if ($js) {
  12358. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  12359. return;
  12360. }
  12361. if (TCPDF_STATIC::empty_string($onvalue)) {
  12362. $onvalue = 'On';
  12363. }
  12364. if ($checked) {
  12365. $defval = $onvalue;
  12366. } else {
  12367. $defval = 'Off';
  12368. }
  12369. // set font
  12370. $font = 'zapfdingbats';
  12371. if ($this->pdfa_mode) {
  12372. // all fonts must be embedded
  12373. $font = 'pdfa'.$font;
  12374. }
  12375. $this->AddFont($font);
  12376. $tmpfont = $this->getFontBuffer($font);
  12377. // set data for parent group
  12378. if (!isset($this->radiobutton_groups[$this->page])) {
  12379. $this->radiobutton_groups[$this->page] = array();
  12380. }
  12381. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  12382. $this->radiobutton_groups[$this->page][$name] = array();
  12383. ++$this->n;
  12384. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  12385. $this->radio_groups[] = $this->n;
  12386. }
  12387. $kid = ($this->n + 1);
  12388. // save object ID to be added on Kids entry on parent object
  12389. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  12390. // get default style
  12391. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12392. $prop['NoToggleToOff'] = 'true';
  12393. $prop['Radio'] = 'true';
  12394. $prop['borderStyle'] = 'inset';
  12395. // get annotation data
  12396. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12397. // set additional default options
  12398. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12399. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12400. $popt['da'] = $fontstyle;
  12401. // build appearance stream
  12402. $popt['ap'] = array();
  12403. $popt['ap']['n'] = array();
  12404. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
  12405. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12406. $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);
  12407. $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);
  12408. if (!isset($popt['mk'])) {
  12409. $popt['mk'] = array();
  12410. }
  12411. $popt['mk']['ca'] = '(l)';
  12412. // merge options
  12413. $opt = array_merge($popt, $opt);
  12414. // set remaining annotation data
  12415. $opt['Subtype'] = 'Widget';
  12416. $opt['ft'] = 'Btn';
  12417. if ($checked) {
  12418. $opt['v'] = array('/'.$onvalue);
  12419. $opt['as'] = $onvalue;
  12420. } else {
  12421. $opt['as'] = 'Off';
  12422. }
  12423. // store readonly flag
  12424. if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
  12425. $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
  12426. }
  12427. $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
  12428. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12429. if ($this->rtl) {
  12430. $this->x -= $w;
  12431. } else {
  12432. $this->x += $w;
  12433. }
  12434. }
  12435. /**
  12436. * Creates a List-box field
  12437. * @param string $name field name
  12438. * @param int $w width
  12439. * @param int $h height
  12440. * @param array $values array containing the list of values.
  12441. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12442. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12443. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12444. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12445. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12446. * @public
  12447. * @author Nicola Asuni
  12448. * @since 4.8.000 (2009-09-07)
  12449. */
  12450. public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
  12451. if (TCPDF_STATIC::empty_string($x)) {
  12452. $x = $this->x;
  12453. }
  12454. if (TCPDF_STATIC::empty_string($y)) {
  12455. $y = $this->y;
  12456. }
  12457. // check page for no-write regions and adapt page margins if necessary
  12458. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12459. if ($js) {
  12460. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  12461. $s = '';
  12462. foreach ($values as $value) {
  12463. if (is_array($value)) {
  12464. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12465. } else {
  12466. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12467. }
  12468. }
  12469. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12470. return;
  12471. }
  12472. // get default style
  12473. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12474. // get annotation data
  12475. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12476. // set additional default values
  12477. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12478. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12479. $popt['da'] = $fontstyle;
  12480. // build appearance stream
  12481. $popt['ap'] = array();
  12482. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12483. $text = '';
  12484. foreach($values as $item) {
  12485. if (is_array($item)) {
  12486. $text .= $item[1]."\n";
  12487. } else {
  12488. $text .= $item."\n";
  12489. }
  12490. }
  12491. $tmpid = $this->startTemplate($w, $h, false);
  12492. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12493. $this->endTemplate();
  12494. --$this->n;
  12495. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12496. unset($this->xobjects[$tmpid]);
  12497. $popt['ap']['n'] .= 'Q EMC';
  12498. // merge options
  12499. $opt = array_merge($popt, $opt);
  12500. // set remaining annotation data
  12501. $opt['Subtype'] = 'Widget';
  12502. $opt['ft'] = 'Ch';
  12503. $opt['t'] = $name;
  12504. $opt['opt'] = $values;
  12505. unset($opt['mk']['ca']);
  12506. unset($opt['mk']['rc']);
  12507. unset($opt['mk']['ac']);
  12508. unset($opt['mk']['i']);
  12509. unset($opt['mk']['ri']);
  12510. unset($opt['mk']['ix']);
  12511. unset($opt['mk']['if']);
  12512. unset($opt['mk']['tp']);
  12513. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12514. if ($this->rtl) {
  12515. $this->x -= $w;
  12516. } else {
  12517. $this->x += $w;
  12518. }
  12519. }
  12520. /**
  12521. * Creates a Combo-box field
  12522. * @param string $name field name
  12523. * @param int $w width
  12524. * @param int $h height
  12525. * @param array $values array containing the list of values.
  12526. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12527. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12528. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12529. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12530. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12531. * @public
  12532. * @author Nicola Asuni
  12533. * @since 4.8.000 (2009-09-07)
  12534. */
  12535. public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
  12536. if (TCPDF_STATIC::empty_string($x)) {
  12537. $x = $this->x;
  12538. }
  12539. if (TCPDF_STATIC::empty_string($y)) {
  12540. $y = $this->y;
  12541. }
  12542. // check page for no-write regions and adapt page margins if necessary
  12543. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12544. if ($js) {
  12545. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  12546. $s = '';
  12547. foreach ($values as $value) {
  12548. if (is_array($value)) {
  12549. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12550. } else {
  12551. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12552. }
  12553. }
  12554. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12555. return;
  12556. }
  12557. // get default style
  12558. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12559. $prop['Combo'] = true;
  12560. // get annotation data
  12561. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12562. // set additional default options
  12563. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12564. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12565. $popt['da'] = $fontstyle;
  12566. // build appearance stream
  12567. $popt['ap'] = array();
  12568. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12569. $text = '';
  12570. foreach($values as $item) {
  12571. if (is_array($item)) {
  12572. $text .= $item[1]."\n";
  12573. } else {
  12574. $text .= $item."\n";
  12575. }
  12576. }
  12577. $tmpid = $this->startTemplate($w, $h, false);
  12578. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12579. $this->endTemplate();
  12580. --$this->n;
  12581. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12582. unset($this->xobjects[$tmpid]);
  12583. $popt['ap']['n'] .= 'Q EMC';
  12584. // merge options
  12585. $opt = array_merge($popt, $opt);
  12586. // set remaining annotation data
  12587. $opt['Subtype'] = 'Widget';
  12588. $opt['ft'] = 'Ch';
  12589. $opt['t'] = $name;
  12590. $opt['opt'] = $values;
  12591. unset($opt['mk']['ca']);
  12592. unset($opt['mk']['rc']);
  12593. unset($opt['mk']['ac']);
  12594. unset($opt['mk']['i']);
  12595. unset($opt['mk']['ri']);
  12596. unset($opt['mk']['ix']);
  12597. unset($opt['mk']['if']);
  12598. unset($opt['mk']['tp']);
  12599. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12600. if ($this->rtl) {
  12601. $this->x -= $w;
  12602. } else {
  12603. $this->x += $w;
  12604. }
  12605. }
  12606. /**
  12607. * Creates a CheckBox field
  12608. * @param string $name field name
  12609. * @param int $w width
  12610. * @param boolean $checked define the initial state.
  12611. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12612. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12613. * @param string $onvalue value to be returned if selected.
  12614. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12615. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12616. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12617. * @public
  12618. * @author Nicola Asuni
  12619. * @since 4.8.000 (2009-09-07)
  12620. */
  12621. public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x=null, $y=null, $js=false) {
  12622. if (TCPDF_STATIC::empty_string($x)) {
  12623. $x = $this->x;
  12624. }
  12625. if (TCPDF_STATIC::empty_string($y)) {
  12626. $y = $this->y;
  12627. }
  12628. // check page for no-write regions and adapt page margins if necessary
  12629. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12630. if ($js) {
  12631. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  12632. return;
  12633. }
  12634. if (!isset($prop['value'])) {
  12635. $prop['value'] = array('Yes');
  12636. }
  12637. // get default style
  12638. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12639. $prop['borderStyle'] = 'inset';
  12640. // get annotation data
  12641. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12642. // set additional default options
  12643. $font = 'zapfdingbats';
  12644. if ($this->pdfa_mode) {
  12645. // all fonts must be embedded
  12646. $font = 'pdfa'.$font;
  12647. }
  12648. $this->AddFont($font);
  12649. $tmpfont = $this->getFontBuffer($font);
  12650. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12651. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12652. $popt['da'] = $fontstyle;
  12653. // build appearance stream
  12654. $popt['ap'] = array();
  12655. $popt['ap']['n'] = array();
  12656. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
  12657. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12658. $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);
  12659. $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);
  12660. // merge options
  12661. $opt = array_merge($popt, $opt);
  12662. // set remaining annotation data
  12663. $opt['Subtype'] = 'Widget';
  12664. $opt['ft'] = 'Btn';
  12665. $opt['t'] = $name;
  12666. if (TCPDF_STATIC::empty_string($onvalue)) {
  12667. $onvalue = 'Yes';
  12668. }
  12669. $opt['opt'] = array($onvalue);
  12670. if ($checked) {
  12671. $opt['v'] = array('/Yes');
  12672. $opt['as'] = 'Yes';
  12673. } else {
  12674. $opt['v'] = array('/Off');
  12675. $opt['as'] = 'Off';
  12676. }
  12677. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12678. if ($this->rtl) {
  12679. $this->x -= $w;
  12680. } else {
  12681. $this->x += $w;
  12682. }
  12683. }
  12684. /**
  12685. * Creates a button field
  12686. * @param string $name field name
  12687. * @param int $w width
  12688. * @param int $h height
  12689. * @param string $caption caption.
  12690. * @param mixed $action 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.
  12691. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12692. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12693. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12694. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12695. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12696. * @public
  12697. * @author Nicola Asuni
  12698. * @since 4.8.000 (2009-09-07)
  12699. */
  12700. public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
  12701. if (TCPDF_STATIC::empty_string($x)) {
  12702. $x = $this->x;
  12703. }
  12704. if (TCPDF_STATIC::empty_string($y)) {
  12705. $y = $this->y;
  12706. }
  12707. // check page for no-write regions and adapt page margins if necessary
  12708. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12709. if ($js) {
  12710. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  12711. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  12712. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  12713. $this->javascript .= 'f'.$name.".highlight='push';\n";
  12714. $this->javascript .= 'f'.$name.".print=false;\n";
  12715. return;
  12716. }
  12717. // get default style
  12718. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12719. $prop['Pushbutton'] = 'true';
  12720. $prop['highlight'] = 'push';
  12721. $prop['display'] = 'display.noPrint';
  12722. // get annotation data
  12723. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12724. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12725. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12726. $popt['da'] = $fontstyle;
  12727. // build appearance stream
  12728. $popt['ap'] = array();
  12729. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12730. $tmpid = $this->startTemplate($w, $h, false);
  12731. $bw = (2 / $this->k); // border width
  12732. $border = array(
  12733. 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12734. 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
  12735. 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12736. 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
  12737. $this->setFillColor(204);
  12738. $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
  12739. $this->endTemplate();
  12740. --$this->n;
  12741. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12742. unset($this->xobjects[$tmpid]);
  12743. $popt['ap']['n'] .= 'Q EMC';
  12744. // set additional default options
  12745. if (!isset($popt['mk'])) {
  12746. $popt['mk'] = array();
  12747. }
  12748. $ann_obj_id = ($this->n + 1);
  12749. if (!empty($action) AND !is_array($action)) {
  12750. $ann_obj_id = ($this->n + 2);
  12751. }
  12752. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  12753. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  12754. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  12755. // merge options
  12756. $opt = array_merge($popt, $opt);
  12757. // set remaining annotation data
  12758. $opt['Subtype'] = 'Widget';
  12759. $opt['ft'] = 'Btn';
  12760. $opt['t'] = $caption;
  12761. $opt['v'] = $name;
  12762. if (!empty($action)) {
  12763. if (is_array($action)) {
  12764. // form action options as on section 12.7.5 of PDF32000_2008.
  12765. $opt['aa'] = '/D <<';
  12766. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  12767. foreach ($action AS $key => $val) {
  12768. if (($key == 'S') AND in_array($val, $bmode)) {
  12769. $opt['aa'] .= ' /S /'.$val;
  12770. } elseif (($key == 'F') AND (!empty($val))) {
  12771. $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
  12772. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  12773. $opt['aa'] .= ' /Fields [';
  12774. foreach ($val AS $field) {
  12775. $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
  12776. }
  12777. $opt['aa'] .= ']';
  12778. } elseif (($key == 'Flags')) {
  12779. $ff = 0;
  12780. if (is_array($val)) {
  12781. foreach ($val AS $flag) {
  12782. switch ($flag) {
  12783. case 'Include/Exclude': {
  12784. $ff += 1 << 0;
  12785. break;
  12786. }
  12787. case 'IncludeNoValueFields': {
  12788. $ff += 1 << 1;
  12789. break;
  12790. }
  12791. case 'ExportFormat': {
  12792. $ff += 1 << 2;
  12793. break;
  12794. }
  12795. case 'GetMethod': {
  12796. $ff += 1 << 3;
  12797. break;
  12798. }
  12799. case 'SubmitCoordinates': {
  12800. $ff += 1 << 4;
  12801. break;
  12802. }
  12803. case 'XFDF': {
  12804. $ff += 1 << 5;
  12805. break;
  12806. }
  12807. case 'IncludeAppendSaves': {
  12808. $ff += 1 << 6;
  12809. break;
  12810. }
  12811. case 'IncludeAnnotations': {
  12812. $ff += 1 << 7;
  12813. break;
  12814. }
  12815. case 'SubmitPDF': {
  12816. $ff += 1 << 8;
  12817. break;
  12818. }
  12819. case 'CanonicalFormat': {
  12820. $ff += 1 << 9;
  12821. break;
  12822. }
  12823. case 'ExclNonUserAnnots': {
  12824. $ff += 1 << 10;
  12825. break;
  12826. }
  12827. case 'ExclFKey': {
  12828. $ff += 1 << 11;
  12829. break;
  12830. }
  12831. case 'EmbedForm': {
  12832. $ff += 1 << 13;
  12833. break;
  12834. }
  12835. }
  12836. }
  12837. } else {
  12838. $ff = intval($val);
  12839. }
  12840. $opt['aa'] .= ' /Flags '.$ff;
  12841. }
  12842. }
  12843. $opt['aa'] .= ' >>';
  12844. } else {
  12845. // Javascript action or raw action command
  12846. $js_obj_id = $this->addJavascriptObject($action);
  12847. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  12848. }
  12849. }
  12850. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12851. if ($this->rtl) {
  12852. $this->x -= $w;
  12853. } else {
  12854. $this->x += $w;
  12855. }
  12856. }
  12857. // --- END FORMS FIELDS ------------------------------------------------
  12858. /**
  12859. * Add certification signature (DocMDP or UR3)
  12860. * You can set only one signature type
  12861. * @protected
  12862. * @author Nicola Asuni
  12863. * @since 4.6.008 (2009-05-07)
  12864. */
  12865. protected function _putsignature() {
  12866. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  12867. return;
  12868. }
  12869. $sigobjid = ($this->sig_obj_id + 1);
  12870. $out = $this->_getobj($sigobjid)."\n";
  12871. $out .= '<< /Type /Sig';
  12872. $out .= ' /Filter /Adobe.PPKLite';
  12873. $out .= ' /SubFilter /adbe.pkcs7.detached';
  12874. $out .= ' '.TCPDF_STATIC::$byterange_string;
  12875. $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
  12876. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  12877. $out .= ' /Reference ['; // array of signature reference dictionaries
  12878. $out .= ' << /Type /SigRef';
  12879. if ($this->signature_data['cert_type'] > 0) {
  12880. $out .= ' /TransformMethod /DocMDP';
  12881. $out .= ' /TransformParams <<';
  12882. $out .= ' /Type /TransformParams';
  12883. $out .= ' /P '.$this->signature_data['cert_type'];
  12884. $out .= ' /V /1.2';
  12885. } else {
  12886. $out .= ' /TransformMethod /UR3';
  12887. $out .= ' /TransformParams <<';
  12888. $out .= ' /Type /TransformParams';
  12889. $out .= ' /V /2.2';
  12890. if (!TCPDF_STATIC::empty_string($this->ur['document'])) {
  12891. $out .= ' /Document['.$this->ur['document'].']';
  12892. }
  12893. if (!TCPDF_STATIC::empty_string($this->ur['form'])) {
  12894. $out .= ' /Form['.$this->ur['form'].']';
  12895. }
  12896. if (!TCPDF_STATIC::empty_string($this->ur['signature'])) {
  12897. $out .= ' /Signature['.$this->ur['signature'].']';
  12898. }
  12899. if (!TCPDF_STATIC::empty_string($this->ur['annots'])) {
  12900. $out .= ' /Annots['.$this->ur['annots'].']';
  12901. }
  12902. if (!TCPDF_STATIC::empty_string($this->ur['ef'])) {
  12903. $out .= ' /EF['.$this->ur['ef'].']';
  12904. }
  12905. if (!TCPDF_STATIC::empty_string($this->ur['formex'])) {
  12906. $out .= ' /FormEX['.$this->ur['formex'].']';
  12907. }
  12908. }
  12909. $out .= ' >>'; // close TransformParams
  12910. // optional digest data (values must be calculated and replaced later)
  12911. //$out .= ' /Data ********** 0 R';
  12912. //$out .= ' /DigestMethod/MD5';
  12913. //$out .= ' /DigestLocation[********** 34]';
  12914. //$out .= ' /DigestValue<********************************>';
  12915. $out .= ' >>';
  12916. $out .= ' ]'; // end of reference
  12917. }
  12918. if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) {
  12919. $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
  12920. }
  12921. if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) {
  12922. $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
  12923. }
  12924. if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) {
  12925. $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
  12926. }
  12927. if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) {
  12928. $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
  12929. }
  12930. $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp);
  12931. $out .= ' >>';
  12932. $out .= "\n".'endobj';
  12933. $this->_out($out);
  12934. }
  12935. /**
  12936. * Set User's Rights for PDF Reader
  12937. * WARNING: This is experimental and currently do not work.
  12938. * Check the PDF Reference 8.7.1 Transform Methods,
  12939. * Table 8.105 Entries in the UR transform parameters dictionary
  12940. * @param boolean $enable if true enable user's rights on PDF reader
  12941. * @param string $document 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.
  12942. * @param string $annots 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.
  12943. * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  12944. * @param string $signature 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.
  12945. * @param string $ef 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
  12946. Names specifying additional embedded-files-related usage rights for the document.
  12947. * @param string $formex 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.
  12948. * @public
  12949. * @author Nicola Asuni
  12950. * @since 2.9.000 (2008-03-26)
  12951. */
  12952. public function setUserRights(
  12953. $enable=true,
  12954. $document='/FullSave',
  12955. $annots='/Create/Delete/Modify/Copy/Import/Export',
  12956. $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  12957. $signature='/Modify',
  12958. $ef='/Create/Delete/Modify/Import',
  12959. $formex='') {
  12960. $this->ur['enabled'] = $enable;
  12961. $this->ur['document'] = $document;
  12962. $this->ur['annots'] = $annots;
  12963. $this->ur['form'] = $form;
  12964. $this->ur['signature'] = $signature;
  12965. $this->ur['ef'] = $ef;
  12966. $this->ur['formex'] = $formex;
  12967. if (!$this->sign) {
  12968. $this->setSignature('', '', '', '', 0, array());
  12969. }
  12970. }
  12971. /**
  12972. * Enable document signature (requires the OpenSSL Library).
  12973. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  12974. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12975. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12976. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  12977. * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://')
  12978. * @param mixed $private_key private key (string or filename prefixed with 'file://')
  12979. * @param string $private_key_password password
  12980. * @param string $extracerts 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.
  12981. * @param int $cert_type 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.
  12982. * @param array $info array of option information: Name, Location, Reason, ContactInfo.
  12983. * @param string $approval Enable approval signature eg. for PDF incremental update
  12984. * @public
  12985. * @author Nicola Asuni
  12986. * @since 4.6.005 (2009-04-24)
  12987. */
  12988. public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array(), $approval='') {
  12989. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12990. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12991. // to convert pfx certificate to pem: openssl
  12992. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  12993. $this->sign = true;
  12994. ++$this->n;
  12995. $this->sig_obj_id = $this->n; // signature widget
  12996. ++$this->n; // signature object ($this->sig_obj_id + 1)
  12997. $this->signature_data = array();
  12998. if (strlen($signing_cert) == 0) {
  12999. $this->Error('Please provide a certificate file and password!');
  13000. }
  13001. if (strlen($private_key) == 0) {
  13002. $private_key = $signing_cert;
  13003. }
  13004. $this->signature_data['signcert'] = $signing_cert;
  13005. $this->signature_data['privkey'] = $private_key;
  13006. $this->signature_data['password'] = $private_key_password;
  13007. $this->signature_data['extracerts'] = $extracerts;
  13008. $this->signature_data['cert_type'] = $cert_type;
  13009. $this->signature_data['info'] = $info;
  13010. $this->signature_data['approval'] = $approval;
  13011. }
  13012. /**
  13013. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  13014. * @param float $x Abscissa of the upper-left corner.
  13015. * @param float $y Ordinate of the upper-left corner.
  13016. * @param float $w Width of the signature area.
  13017. * @param float $h Height of the signature area.
  13018. * @param int $page option page number (if < 0 the current page is used).
  13019. * @param string $name Name of the signature.
  13020. * @public
  13021. * @author Nicola Asuni
  13022. * @since 5.3.011 (2010-06-17)
  13023. */
  13024. public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  13025. $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  13026. }
  13027. /**
  13028. * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
  13029. * @param float $x Abscissa of the upper-left corner.
  13030. * @param float $y Ordinate of the upper-left corner.
  13031. * @param float $w Width of the signature area.
  13032. * @param float $h Height of the signature area.
  13033. * @param int $page option page number (if < 0 the current page is used).
  13034. * @param string $name Name of the signature.
  13035. * @public
  13036. * @author Nicola Asuni
  13037. * @since 5.9.101 (2011-07-06)
  13038. */
  13039. public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  13040. ++$this->n;
  13041. $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  13042. }
  13043. /**
  13044. * Get the array that defines the signature appearance (page and rectangle coordinates).
  13045. * @param float $x Abscissa of the upper-left corner.
  13046. * @param float $y Ordinate of the upper-left corner.
  13047. * @param float $w Width of the signature area.
  13048. * @param float $h Height of the signature area.
  13049. * @param int $page option page number (if < 0 the current page is used).
  13050. * @param string $name Name of the signature.
  13051. * @return array Array defining page and rectangle coordinates of signature appearance.
  13052. * @protected
  13053. * @author Nicola Asuni
  13054. * @since 5.9.101 (2011-07-06)
  13055. */
  13056. protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  13057. $sigapp = array();
  13058. if (($page < 1) OR ($page > $this->numpages)) {
  13059. $sigapp['page'] = $this->page;
  13060. } else {
  13061. $sigapp['page'] = intval($page);
  13062. }
  13063. if (empty($name)) {
  13064. $sigapp['name'] = 'Signature';
  13065. } else {
  13066. $sigapp['name'] = $name;
  13067. }
  13068. $a = $x * $this->k;
  13069. $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
  13070. $c = $w * $this->k;
  13071. $d = $h * $this->k;
  13072. $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a + $c), ($b + $d));
  13073. return $sigapp;
  13074. }
  13075. /**
  13076. * Enable document timestamping (requires the OpenSSL Library).
  13077. * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded.
  13078. * Use with digital signature only!
  13079. * @param string $tsa_host Time Stamping Authority (TSA) server (prefixed with 'https://')
  13080. * @param string $tsa_username Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional)
  13081. * @param string $tsa_password Specifies the password for TSA authorization (optional)
  13082. * @param string $tsa_cert Specifies the location of TSA certificate for authorization (optional for cURL)
  13083. * @public
  13084. * @author Richard Stockinger
  13085. * @since 6.0.090 (2014-06-16)
  13086. */
  13087. public function setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='') {
  13088. $this->tsa_data = array();
  13089. if (!function_exists('curl_init')) {
  13090. $this->Error('Please enable cURL PHP extension!');
  13091. }
  13092. if (strlen($tsa_host) == 0) {
  13093. $this->Error('Please specify the host of Time Stamping Authority (TSA)!');
  13094. }
  13095. $this->tsa_data['tsa_host'] = $tsa_host;
  13096. if (is_file($tsa_username)) {
  13097. $this->tsa_data['tsa_auth'] = $tsa_username;
  13098. } else {
  13099. $this->tsa_data['tsa_username'] = $tsa_username;
  13100. }
  13101. $this->tsa_data['tsa_password'] = $tsa_password;
  13102. $this->tsa_data['tsa_cert'] = $tsa_cert;
  13103. $this->tsa_timestamp = true;
  13104. }
  13105. /**
  13106. * NOT YET IMPLEMENTED
  13107. * Request TSA for a timestamp
  13108. * @param string $signature Digital signature as binary string
  13109. * @return string Timestamped digital signature
  13110. * @protected
  13111. * @author Richard Stockinger
  13112. * @since 6.0.090 (2014-06-16)
  13113. */
  13114. protected function applyTSA($signature) {
  13115. if (!$this->tsa_timestamp) {
  13116. return $signature;
  13117. }
  13118. //@TODO: implement this feature
  13119. return $signature;
  13120. }
  13121. /**
  13122. * Create a new page group.
  13123. * NOTE: call this function before calling AddPage()
  13124. * @param int|null $page starting group page (leave empty for next page).
  13125. * @public
  13126. * @since 3.0.000 (2008-03-27)
  13127. */
  13128. public function startPageGroup($page=null) {
  13129. if (empty($page)) {
  13130. $page = $this->page + 1;
  13131. }
  13132. $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
  13133. }
  13134. /**
  13135. * Set the starting page number.
  13136. * @param int $num Starting page number.
  13137. * @since 5.9.093 (2011-06-16)
  13138. * @public
  13139. */
  13140. public function setStartingPageNumber($num=1) {
  13141. $this->starting_page_number = max(0, intval($num));
  13142. }
  13143. /**
  13144. * Returns the string alias used right align page numbers.
  13145. * If the current font is unicode type, the returned string wil contain an additional open curly brace.
  13146. * @return string
  13147. * @since 5.9.099 (2011-06-27)
  13148. * @public
  13149. */
  13150. public function getAliasRightShift() {
  13151. // calculate aproximatively the ratio between widths of aliases and replacements.
  13152. $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}';
  13153. $rep = str_repeat(' ', $this->GetNumChars($ref));
  13154. $wrep = $this->GetStringWidth($rep);
  13155. if ($wrep > 0) {
  13156. $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep));
  13157. } else {
  13158. $wdiff = 1;
  13159. }
  13160. $sdiff = sprintf('%F', $wdiff);
  13161. $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}';
  13162. if ($this->isUnicodeFont()) {
  13163. $alias = '{'.$alias;
  13164. }
  13165. return $alias;
  13166. }
  13167. /**
  13168. * Returns the string alias used for the total number of pages.
  13169. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13170. * This alias will be replaced by the total number of pages in the document.
  13171. * @return string
  13172. * @since 4.0.018 (2008-08-08)
  13173. * @public
  13174. */
  13175. public function getAliasNbPages() {
  13176. if ($this->isUnicodeFont()) {
  13177. return '{'.TCPDF_STATIC::$alias_tot_pages.'}';
  13178. }
  13179. return TCPDF_STATIC::$alias_tot_pages;
  13180. }
  13181. /**
  13182. * Returns the string alias used for the page number.
  13183. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13184. * This alias will be replaced by the page number.
  13185. * @return string
  13186. * @since 4.5.000 (2009-01-02)
  13187. * @public
  13188. */
  13189. public function getAliasNumPage() {
  13190. if ($this->isUnicodeFont()) {
  13191. return '{'.TCPDF_STATIC::$alias_num_page.'}';
  13192. }
  13193. return TCPDF_STATIC::$alias_num_page;
  13194. }
  13195. /**
  13196. * Return the alias for the total number of pages in the current page group.
  13197. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13198. * This alias will be replaced by the total number of pages in this group.
  13199. * @return string alias of the current page group
  13200. * @public
  13201. * @since 3.0.000 (2008-03-27)
  13202. */
  13203. public function getPageGroupAlias() {
  13204. if ($this->isUnicodeFont()) {
  13205. return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}';
  13206. }
  13207. return TCPDF_STATIC::$alias_group_tot_pages;
  13208. }
  13209. /**
  13210. * Return the alias for the page number on the current page group.
  13211. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13212. * This alias will be replaced by the page number (relative to the belonging group).
  13213. * @return string alias of the current page group
  13214. * @public
  13215. * @since 4.5.000 (2009-01-02)
  13216. */
  13217. public function getPageNumGroupAlias() {
  13218. if ($this->isUnicodeFont()) {
  13219. return '{'.TCPDF_STATIC::$alias_group_num_page.'}';
  13220. }
  13221. return TCPDF_STATIC::$alias_group_num_page;
  13222. }
  13223. /**
  13224. * Return the current page in the group.
  13225. * @return int current page in the group
  13226. * @public
  13227. * @since 3.0.000 (2008-03-27)
  13228. */
  13229. public function getGroupPageNo() {
  13230. return $this->pagegroups[$this->currpagegroup];
  13231. }
  13232. /**
  13233. * Returns the current group page number formatted as a string.
  13234. * @public
  13235. * @since 4.3.003 (2008-11-18)
  13236. * @see PaneNo(), formatPageNumber()
  13237. */
  13238. public function getGroupPageNoFormatted() {
  13239. return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo());
  13240. }
  13241. /**
  13242. * Returns the current page number formatted as a string.
  13243. * @public
  13244. * @since 4.2.005 (2008-11-06)
  13245. * @see PaneNo(), formatPageNumber()
  13246. */
  13247. public function PageNoFormatted() {
  13248. return TCPDF_STATIC::formatPageNumber($this->PageNo());
  13249. }
  13250. /**
  13251. * Put pdf layers.
  13252. * @protected
  13253. * @since 3.0.000 (2008-03-27)
  13254. */
  13255. protected function _putocg() {
  13256. if (empty($this->pdflayers)) {
  13257. return;
  13258. }
  13259. foreach ($this->pdflayers as $key => $layer) {
  13260. $this->pdflayers[$key]['objid'] = $this->_newobj();
  13261. $out = '<< /Type /OCG';
  13262. $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
  13263. $out .= ' /Usage <<';
  13264. if (isset($layer['print']) AND ($layer['print'] !== NULL)) {
  13265. $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
  13266. }
  13267. $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
  13268. $out .= ' >> >>';
  13269. $out .= "\n".'endobj';
  13270. $this->_out($out);
  13271. }
  13272. }
  13273. /**
  13274. * Start a new pdf layer.
  13275. * @param string $name Layer name (only a-z letters and numbers). Leave empty for automatic name.
  13276. * @param boolean|null $print Set to TRUE to print this layer, FALSE to not print and NULL to not set this option
  13277. * @param boolean $view Set to true to view this layer.
  13278. * @param boolean $lock If true lock the layer
  13279. * @public
  13280. * @since 5.9.102 (2011-07-13)
  13281. */
  13282. public function startLayer($name='', $print=true, $view=true, $lock=true) {
  13283. if ($this->state != 2) {
  13284. return;
  13285. }
  13286. $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
  13287. if (empty($name)) {
  13288. $name = $layer;
  13289. } else {
  13290. $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
  13291. }
  13292. $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view, 'lock' => $lock);
  13293. $this->openMarkedContent = true;
  13294. $this->_out('/OC /'.$layer.' BDC');
  13295. }
  13296. /**
  13297. * End the current PDF layer.
  13298. * @public
  13299. * @since 5.9.102 (2011-07-13)
  13300. */
  13301. public function endLayer() {
  13302. if ($this->state != 2) {
  13303. return;
  13304. }
  13305. if ($this->openMarkedContent) {
  13306. // close existing open marked-content layer
  13307. $this->_out('EMC');
  13308. $this->openMarkedContent = false;
  13309. }
  13310. }
  13311. /**
  13312. * Set the visibility of the successive elements.
  13313. * This can be useful, for instance, to put a background
  13314. * image or color that will show on screen but won't print.
  13315. * @param string $v visibility mode. Legal values are: all, print, screen or view.
  13316. * @public
  13317. * @since 3.0.000 (2008-03-27)
  13318. */
  13319. public function setVisibility($v) {
  13320. if ($this->state != 2) {
  13321. return;
  13322. }
  13323. $this->endLayer();
  13324. switch($v) {
  13325. case 'print': {
  13326. $this->startLayer('Print', true, false);
  13327. break;
  13328. }
  13329. case 'view':
  13330. case 'screen': {
  13331. $this->startLayer('View', false, true);
  13332. break;
  13333. }
  13334. case 'all': {
  13335. $this->_out('');
  13336. break;
  13337. }
  13338. default: {
  13339. $this->Error('Incorrect visibility: '.$v);
  13340. break;
  13341. }
  13342. }
  13343. }
  13344. /**
  13345. * Add transparency parameters to the current extgstate
  13346. * @param array $parms parameters
  13347. * @return int|void the number of extgstates
  13348. * @protected
  13349. * @since 3.0.000 (2008-03-27)
  13350. */
  13351. protected function addExtGState($parms) {
  13352. if ($this->pdfa_mode || $this->pdfa_version >= 2) {
  13353. // transparencies are not allowed in PDF/A mode
  13354. return;
  13355. }
  13356. // check if this ExtGState already exist
  13357. foreach ($this->extgstates as $i => $ext) {
  13358. if ($ext['parms'] == $parms) {
  13359. if ($this->inxobj) {
  13360. // we are inside an XObject template
  13361. $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
  13362. }
  13363. // return reference to existing ExtGState
  13364. return $i;
  13365. }
  13366. }
  13367. $n = (count($this->extgstates) + 1);
  13368. $this->extgstates[$n] = array('parms' => $parms);
  13369. if ($this->inxobj) {
  13370. // we are inside an XObject template
  13371. $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
  13372. }
  13373. return $n;
  13374. }
  13375. /**
  13376. * Add an extgstate
  13377. * @param int $gs extgstate
  13378. * @protected
  13379. * @since 3.0.000 (2008-03-27)
  13380. */
  13381. protected function setExtGState($gs) {
  13382. if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
  13383. // transparency is not allowed in PDF/A-1 mode
  13384. return;
  13385. }
  13386. $this->_out(sprintf('/GS%d gs', $gs));
  13387. }
  13388. /**
  13389. * Put extgstates for object transparency
  13390. * @protected
  13391. * @since 3.0.000 (2008-03-27)
  13392. */
  13393. protected function _putextgstates() {
  13394. foreach ($this->extgstates as $i => $ext) {
  13395. $this->extgstates[$i]['n'] = $this->_newobj();
  13396. $out = '<< /Type /ExtGState';
  13397. foreach ($ext['parms'] as $k => $v) {
  13398. if (is_float($v)) {
  13399. $v = sprintf('%F', $v);
  13400. } elseif ($v === true) {
  13401. $v = 'true';
  13402. } elseif ($v === false) {
  13403. $v = 'false';
  13404. }
  13405. $out .= ' /'.$k.' '.$v;
  13406. }
  13407. $out .= ' >>';
  13408. $out .= "\n".'endobj';
  13409. $this->_out($out);
  13410. }
  13411. }
  13412. /**
  13413. * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
  13414. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13415. * @param boolean $stroking If true apply overprint for stroking operations.
  13416. * @param boolean|null $nonstroking If true apply overprint for painting operations other than stroking.
  13417. * @param integer $mode 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).
  13418. * @public
  13419. * @since 5.9.152 (2012-03-23)
  13420. */
  13421. public function setOverprint($stroking=true, $nonstroking=null, $mode=0) {
  13422. if ($this->state != 2) {
  13423. return;
  13424. }
  13425. $stroking = $stroking ? true : false;
  13426. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13427. // default value if not set
  13428. $nonstroking = $stroking;
  13429. } else {
  13430. $nonstroking = $nonstroking ? true : false;
  13431. }
  13432. if (($mode != 0) AND ($mode != 1)) {
  13433. $mode = 0;
  13434. }
  13435. $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
  13436. $gs = $this->addExtGState($this->overprint);
  13437. $this->setExtGState($gs);
  13438. }
  13439. /**
  13440. * Get the overprint mode array (OP, op, OPM).
  13441. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13442. * @return array<string,bool|int>
  13443. * @public
  13444. * @since 5.9.152 (2012-03-23)
  13445. */
  13446. public function getOverprint() {
  13447. return $this->overprint;
  13448. }
  13449. /**
  13450. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  13451. * @param float $stroking Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
  13452. * @param string $bm blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  13453. * @param float|null $nonstroking Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
  13454. * @param boolean $ais
  13455. * @public
  13456. * @since 3.0.000 (2008-03-27)
  13457. */
  13458. public function setAlpha($stroking=1, $bm='Normal', $nonstroking=null, $ais=false) {
  13459. if ($this->pdfa_mode && $this->pdfa_version < 2) {
  13460. // transparency is not allowed in PDF/A-1 mode
  13461. return;
  13462. }
  13463. $stroking = floatval($stroking);
  13464. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13465. // default value if not set
  13466. $nonstroking = $stroking;
  13467. } else {
  13468. $nonstroking = floatval($nonstroking);
  13469. }
  13470. if ($bm[0] == '/') {
  13471. // remove trailing slash
  13472. $bm = substr($bm, 1);
  13473. }
  13474. if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  13475. $bm = 'Normal';
  13476. }
  13477. $ais = $ais ? true : false;
  13478. $this->alpha = array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
  13479. $gs = $this->addExtGState($this->alpha);
  13480. $this->setExtGState($gs);
  13481. }
  13482. /**
  13483. * Get the alpha mode array (CA, ca, BM, AIS).
  13484. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13485. * @return array<string,bool|string>
  13486. * @public
  13487. * @since 5.9.152 (2012-03-23)
  13488. */
  13489. public function getAlpha() {
  13490. return $this->alpha;
  13491. }
  13492. /**
  13493. * Set the default JPEG compression quality (1-100)
  13494. * @param int $quality JPEG quality, integer between 1 and 100
  13495. * @public
  13496. * @since 3.0.000 (2008-03-27)
  13497. */
  13498. public function setJPEGQuality($quality) {
  13499. if (($quality < 1) OR ($quality > 100)) {
  13500. $quality = 75;
  13501. }
  13502. $this->jpeg_quality = intval($quality);
  13503. }
  13504. /**
  13505. * Set the default number of columns in a row for HTML tables.
  13506. * @param int $cols number of columns
  13507. * @public
  13508. * @since 3.0.014 (2008-06-04)
  13509. */
  13510. public function setDefaultTableColumns($cols=4) {
  13511. $this->default_table_columns = intval($cols);
  13512. }
  13513. /**
  13514. * Set the height of the cell (line height) respect the font height.
  13515. * @param float $h cell proportion respect font height (typical value = 1.25).
  13516. * @public
  13517. * @since 3.0.014 (2008-06-04)
  13518. */
  13519. public function setCellHeightRatio($h) {
  13520. $this->cell_height_ratio = $h;
  13521. }
  13522. /**
  13523. * return the height of cell repect font height.
  13524. * @public
  13525. * @return float
  13526. * @since 4.0.012 (2008-07-24)
  13527. */
  13528. public function getCellHeightRatio() {
  13529. return $this->cell_height_ratio;
  13530. }
  13531. /**
  13532. * Set the PDF version (check PDF reference for valid values).
  13533. * @param string $version PDF document version.
  13534. * @public
  13535. * @since 3.1.000 (2008-06-09)
  13536. */
  13537. public function setPDFVersion($version='1.7') {
  13538. if ($this->pdfa_mode && $this->pdfa_version == 1 ) {
  13539. // PDF/A-1 mode
  13540. $this->PDFVersion = '1.4';
  13541. } elseif ($this->pdfa_mode && $this->pdfa_version >= 2 ) {
  13542. // PDF/A-2 mode
  13543. $this->PDFVersion = '1.7';
  13544. } else {
  13545. $this->PDFVersion = $version;
  13546. }
  13547. }
  13548. /**
  13549. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  13550. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  13551. * <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>
  13552. * @param array $preferences array of options.
  13553. * @author Nicola Asuni
  13554. * @public
  13555. * @since 3.1.000 (2008-06-09)
  13556. */
  13557. public function setViewerPreferences($preferences) {
  13558. $this->viewer_preferences = $preferences;
  13559. }
  13560. /**
  13561. * Paints color transition registration bars
  13562. * @param float $x abscissa of the top left corner of the rectangle.
  13563. * @param float $y ordinate of the top left corner of the rectangle.
  13564. * @param float $w width of the rectangle.
  13565. * @param float $h height of the rectangle.
  13566. * @param boolean $transition if true prints tcolor transitions to white.
  13567. * @param boolean $vertical if true prints bar vertically.
  13568. * @param string $colors 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.
  13569. * @author Nicola Asuni
  13570. * @since 4.9.000 (2010-03-26)
  13571. * @public
  13572. */
  13573. public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
  13574. if (strpos($colors, 'ALLSPOT') !== false) {
  13575. // expand spot colors
  13576. $spot_colors = '';
  13577. foreach ($this->spot_colors as $spot_color_name => $v) {
  13578. $spot_colors .= ','.$spot_color_name;
  13579. }
  13580. if (!empty($spot_colors)) {
  13581. $spot_colors = substr($spot_colors, 1);
  13582. $colors = str_replace('ALLSPOT', $spot_colors, $colors);
  13583. } else {
  13584. $colors = str_replace('ALLSPOT', 'NONE', $colors);
  13585. }
  13586. }
  13587. $bars = explode(',', $colors);
  13588. $numbars = count($bars); // number of bars to print
  13589. if ($numbars <= 0) {
  13590. return;
  13591. }
  13592. // set bar measures
  13593. if ($vertical) {
  13594. $coords = array(0, 0, 0, 1);
  13595. $wb = $w / $numbars; // bar width
  13596. $hb = $h; // bar height
  13597. $xd = $wb; // delta x
  13598. $yd = 0; // delta y
  13599. } else {
  13600. $coords = array(1, 0, 0, 0);
  13601. $wb = $w; // bar width
  13602. $hb = $h / $numbars; // bar height
  13603. $xd = 0; // delta x
  13604. $yd = $hb; // delta y
  13605. }
  13606. $xb = $x;
  13607. $yb = $y;
  13608. foreach ($bars as $col) {
  13609. switch ($col) {
  13610. // set transition colors
  13611. case 'A': { // BLACK (GRAYSCALE)
  13612. $col_a = array(255);
  13613. $col_b = array(0);
  13614. break;
  13615. }
  13616. case 'W': { // WHITE (GRAYSCALE)
  13617. $col_a = array(0);
  13618. $col_b = array(255);
  13619. break;
  13620. }
  13621. case 'R': { // RED (RGB)
  13622. $col_a = array(255,255,255);
  13623. $col_b = array(255,0,0);
  13624. break;
  13625. }
  13626. case 'G': { // GREEN (RGB)
  13627. $col_a = array(255,255,255);
  13628. $col_b = array(0,255,0);
  13629. break;
  13630. }
  13631. case 'B': { // BLUE (RGB)
  13632. $col_a = array(255,255,255);
  13633. $col_b = array(0,0,255);
  13634. break;
  13635. }
  13636. case 'C': { // CYAN (CMYK)
  13637. $col_a = array(0,0,0,0);
  13638. $col_b = array(100,0,0,0);
  13639. break;
  13640. }
  13641. case 'M': { // MAGENTA (CMYK)
  13642. $col_a = array(0,0,0,0);
  13643. $col_b = array(0,100,0,0);
  13644. break;
  13645. }
  13646. case 'Y': { // YELLOW (CMYK)
  13647. $col_a = array(0,0,0,0);
  13648. $col_b = array(0,0,100,0);
  13649. break;
  13650. }
  13651. case 'K': { // KEY - BLACK (CMYK)
  13652. $col_a = array(0,0,0,0);
  13653. $col_b = array(0,0,0,100);
  13654. break;
  13655. }
  13656. case 'RGB': { // BLACK REGISTRATION (RGB)
  13657. $col_a = array(255,255,255);
  13658. $col_b = array(0,0,0);
  13659. break;
  13660. }
  13661. case 'CMYK': { // BLACK REGISTRATION (CMYK)
  13662. $col_a = array(0,0,0,0);
  13663. $col_b = array(100,100,100,100);
  13664. break;
  13665. }
  13666. case 'ALL': { // SPOT COLOR REGISTRATION
  13667. $col_a = array(0,0,0,0,'None');
  13668. $col_b = array(100,100,100,100,'All');
  13669. break;
  13670. }
  13671. case 'NONE': { // SKIP THIS COLOR
  13672. $col_a = array(0,0,0,0,'None');
  13673. $col_b = array(0,0,0,0,'None');
  13674. break;
  13675. }
  13676. default: { // SPECIFIC SPOT COLOR NAME
  13677. $col_a = array(0,0,0,0,'None');
  13678. $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors);
  13679. if ($col_b === false) {
  13680. // in case of error defaults to the registration color
  13681. $col_b = array(100,100,100,100,'All');
  13682. }
  13683. break;
  13684. }
  13685. }
  13686. if ($col != 'NONE') {
  13687. if ($transition) {
  13688. // color gradient
  13689. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  13690. } else {
  13691. $this->setFillColorArray($col_b);
  13692. // colored rectangle
  13693. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  13694. }
  13695. $xb += $xd;
  13696. $yb += $yd;
  13697. }
  13698. }
  13699. }
  13700. /**
  13701. * Paints crop marks.
  13702. * @param float $x abscissa of the crop mark center.
  13703. * @param float $y ordinate of the crop mark center.
  13704. * @param float $w width of the crop mark.
  13705. * @param float $h height of the crop mark.
  13706. * @param string $type 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.
  13707. * @param array $color crop mark color (default spot registration color).
  13708. * @author Nicola Asuni
  13709. * @since 4.9.000 (2010-03-26)
  13710. * @public
  13711. */
  13712. public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(100,100,100,100,'All')) {
  13713. $this->setLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  13714. $type = strtoupper($type);
  13715. $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
  13716. // split type in single components
  13717. $type = str_replace('-', ',', $type);
  13718. $type = str_replace('TL', 'T,L', $type);
  13719. $type = str_replace('TR', 'T,R', $type);
  13720. $type = str_replace('BL', 'F,L', $type);
  13721. $type = str_replace('BR', 'F,R', $type);
  13722. $type = str_replace('A', 'T,L', $type);
  13723. $type = str_replace('B', 'T,R', $type);
  13724. $type = str_replace('T,RO', 'BO', $type);
  13725. $type = str_replace('C', 'F,L', $type);
  13726. $type = str_replace('D', 'F,R', $type);
  13727. $crops = explode(',', strtoupper($type));
  13728. // remove duplicates
  13729. $crops = array_unique($crops);
  13730. $dw = ($w / 4); // horizontal space to leave before the intersection point
  13731. $dh = ($h / 4); // vertical space to leave before the intersection point
  13732. foreach ($crops as $crop) {
  13733. switch ($crop) {
  13734. case 'T':
  13735. case 'TOP': {
  13736. $x1 = $x;
  13737. $y1 = ($y - $h);
  13738. $x2 = $x;
  13739. $y2 = ($y - $dh);
  13740. break;
  13741. }
  13742. case 'F':
  13743. case 'BOTTOM': {
  13744. $x1 = $x;
  13745. $y1 = ($y + $dh);
  13746. $x2 = $x;
  13747. $y2 = ($y + $h);
  13748. break;
  13749. }
  13750. case 'L':
  13751. case 'LEFT': {
  13752. $x1 = ($x - $w);
  13753. $y1 = $y;
  13754. $x2 = ($x - $dw);
  13755. $y2 = $y;
  13756. break;
  13757. }
  13758. case 'R':
  13759. case 'RIGHT': {
  13760. $x1 = ($x + $dw);
  13761. $y1 = $y;
  13762. $x2 = ($x + $w);
  13763. $y2 = $y;
  13764. break;
  13765. }
  13766. }
  13767. $this->Line($x1, $y1, $x2, $y2);
  13768. }
  13769. }
  13770. /**
  13771. * Paints a registration mark
  13772. * @param float $x abscissa of the registration mark center.
  13773. * @param float $y ordinate of the registration mark center.
  13774. * @param float $r radius of the crop mark.
  13775. * @param boolean $double if true print two concentric crop marks.
  13776. * @param array $cola crop mark color (default spot registration color 'All').
  13777. * @param array $colb second crop mark color (default spot registration color 'None').
  13778. * @author Nicola Asuni
  13779. * @since 4.9.000 (2010-03-26)
  13780. * @public
  13781. */
  13782. public function registrationMark($x, $y, $r, $double=false, $cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) {
  13783. $line_style = array('width' => max((0.5 / $this->k),($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  13784. $this->setFillColorArray($cola);
  13785. $this->PieSector($x, $y, $r, 90, 180, 'F');
  13786. $this->PieSector($x, $y, $r, 270, 360, 'F');
  13787. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13788. if ($double) {
  13789. $ri = $r * 0.5;
  13790. $this->setFillColorArray($colb);
  13791. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13792. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13793. $this->setFillColorArray($cola);
  13794. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13795. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13796. $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8);
  13797. }
  13798. }
  13799. /**
  13800. * Paints a CMYK registration mark
  13801. * @param float $x abscissa of the registration mark center.
  13802. * @param float $y ordinate of the registration mark center.
  13803. * @param float $r radius of the crop mark.
  13804. * @author Nicola Asuni
  13805. * @since 6.0.038 (2013-09-30)
  13806. * @public
  13807. */
  13808. public function registrationMarkCMYK($x, $y, $r) {
  13809. // line width
  13810. $lw = max((0.5 / $this->k),($r / 8));
  13811. // internal radius
  13812. $ri = ($r * 0.6);
  13813. // external radius
  13814. $re = ($r * 1.3);
  13815. // Cyan
  13816. $this->setFillColorArray(array(100,0,0,0));
  13817. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13818. // Magenta
  13819. $this->setFillColorArray(array(0,100,0,0));
  13820. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13821. // Yellow
  13822. $this->setFillColorArray(array(0,0,100,0));
  13823. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13824. // Key - black
  13825. $this->setFillColorArray(array(0,0,0,100));
  13826. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13827. // registration color
  13828. $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All'));
  13829. $this->setFillColorArray(array(100,100,100,100,'All'));
  13830. // external circle
  13831. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13832. // cross lines
  13833. $this->Line($x, ($y - $re), $x, ($y - $ri));
  13834. $this->Line($x, ($y + $ri), $x, ($y + $re));
  13835. $this->Line(($x - $re), $y, ($x - $ri), $y);
  13836. $this->Line(($x + $ri), $y, ($x + $re), $y);
  13837. }
  13838. /**
  13839. * Paints a linear colour gradient.
  13840. * @param float $x abscissa of the top left corner of the rectangle.
  13841. * @param float $y ordinate of the top left corner of the rectangle.
  13842. * @param float $w width of the rectangle.
  13843. * @param float $h height of the rectangle.
  13844. * @param array $col1 first color (Grayscale, RGB or CMYK components).
  13845. * @param array $col2 second color (Grayscale, RGB or CMYK components).
  13846. * @param array $coords 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).
  13847. * @author Andreas W\FCrmser, Nicola Asuni
  13848. * @since 3.1.000 (2008-06-09)
  13849. * @public
  13850. */
  13851. public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  13852. $this->Clip($x, $y, $w, $h);
  13853. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13854. }
  13855. /**
  13856. * Paints a radial colour gradient.
  13857. * @param float $x abscissa of the top left corner of the rectangle.
  13858. * @param float $y ordinate of the top left corner of the rectangle.
  13859. * @param float $w width of the rectangle.
  13860. * @param float $h height of the rectangle.
  13861. * @param array $col1 first color (Grayscale, RGB or CMYK components).
  13862. * @param array $col2 second color (Grayscale, RGB or CMYK components).
  13863. * @param array $coords 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.
  13864. * @author Andreas W\FCrmser, Nicola Asuni
  13865. * @since 3.1.000 (2008-06-09)
  13866. * @public
  13867. */
  13868. public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  13869. $this->Clip($x, $y, $w, $h);
  13870. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13871. }
  13872. /**
  13873. * Paints a coons patch mesh.
  13874. * @param float $x abscissa of the top left corner of the rectangle.
  13875. * @param float $y ordinate of the top left corner of the rectangle.
  13876. * @param float $w width of the rectangle.
  13877. * @param float $h height of the rectangle.
  13878. * @param array $col1 first color (lower left corner) (RGB components).
  13879. * @param array $col2 second color (lower right corner) (RGB components).
  13880. * @param array $col3 third color (upper right corner) (RGB components).
  13881. * @param array $col4 fourth color (upper left corner) (RGB components).
  13882. * @param array $coords <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>
  13883. * @param array $coords_min minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0
  13884. * @param array $coords_max maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1
  13885. * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13886. * @author Andreas W\FCrmser, Nicola Asuni
  13887. * @since 3.1.000 (2008-06-09)
  13888. * @public
  13889. */
  13890. 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) {
  13891. if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
  13892. return;
  13893. }
  13894. $this->Clip($x, $y, $w, $h);
  13895. $n = count($this->gradients) + 1;
  13896. $this->gradients[$n] = array();
  13897. $this->gradients[$n]['type'] = 6; //coons patch mesh
  13898. $this->gradients[$n]['coords'] = array();
  13899. $this->gradients[$n]['antialias'] = $antialias;
  13900. $this->gradients[$n]['colors'] = array();
  13901. $this->gradients[$n]['transparency'] = false;
  13902. //check the coords array if it is the simple array or the multi patch array
  13903. if (!isset($coords[0]['f'])) {
  13904. //simple array -> convert to multi patch array
  13905. if (!isset($col1[1])) {
  13906. $col1[1] = $col1[2] = $col1[0];
  13907. }
  13908. if (!isset($col2[1])) {
  13909. $col2[1] = $col2[2] = $col2[0];
  13910. }
  13911. if (!isset($col3[1])) {
  13912. $col3[1] = $col3[2] = $col3[0];
  13913. }
  13914. if (!isset($col4[1])) {
  13915. $col4[1] = $col4[2] = $col4[0];
  13916. }
  13917. $patch_array[0]['f'] = 0;
  13918. $patch_array[0]['points'] = $coords;
  13919. $patch_array[0]['colors'][0]['r'] = $col1[0];
  13920. $patch_array[0]['colors'][0]['g'] = $col1[1];
  13921. $patch_array[0]['colors'][0]['b'] = $col1[2];
  13922. $patch_array[0]['colors'][1]['r'] = $col2[0];
  13923. $patch_array[0]['colors'][1]['g'] = $col2[1];
  13924. $patch_array[0]['colors'][1]['b'] = $col2[2];
  13925. $patch_array[0]['colors'][2]['r'] = $col3[0];
  13926. $patch_array[0]['colors'][2]['g'] = $col3[1];
  13927. $patch_array[0]['colors'][2]['b'] = $col3[2];
  13928. $patch_array[0]['colors'][3]['r'] = $col4[0];
  13929. $patch_array[0]['colors'][3]['g'] = $col4[1];
  13930. $patch_array[0]['colors'][3]['b'] = $col4[2];
  13931. } else {
  13932. //multi patch array
  13933. $patch_array = $coords;
  13934. }
  13935. $bpcd = 65535; //16 bits per coordinate
  13936. //build the data stream
  13937. $this->gradients[$n]['stream'] = '';
  13938. $count_patch = count($patch_array);
  13939. for ($i=0; $i < $count_patch; ++$i) {
  13940. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  13941. $count_points = count($patch_array[$i]['points']);
  13942. for ($j=0; $j < $count_points; ++$j) {
  13943. //each point as 16 bit
  13944. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  13945. if ($patch_array[$i]['points'][$j] < 0) {
  13946. $patch_array[$i]['points'][$j] = 0;
  13947. }
  13948. if ($patch_array[$i]['points'][$j] > $bpcd) {
  13949. $patch_array[$i]['points'][$j] = $bpcd;
  13950. }
  13951. $this->gradients[$n]['stream'] .= chr((int) floor($patch_array[$i]['points'][$j] / 256));
  13952. $this->gradients[$n]['stream'] .= chr((int) floor(intval($patch_array[$i]['points'][$j]) % 256));
  13953. }
  13954. $count_cols = count($patch_array[$i]['colors']);
  13955. for ($j=0; $j < $count_cols; ++$j) {
  13956. //each color component as 8 bit
  13957. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  13958. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  13959. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  13960. }
  13961. }
  13962. //paint the gradient
  13963. $this->_out('/Sh'.$n.' sh');
  13964. //restore previous Graphic State
  13965. $this->_outRestoreGraphicsState();
  13966. if ($this->inxobj) {
  13967. // we are inside an XObject template
  13968. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13969. }
  13970. }
  13971. /**
  13972. * Set a rectangular clipping area.
  13973. * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  13974. * @param float $y ordinate of the top left corner of the rectangle.
  13975. * @param float $w width of the rectangle.
  13976. * @param float $h height of the rectangle.
  13977. * @author Andreas W\FCrmser, Nicola Asuni
  13978. * @since 3.1.000 (2008-06-09)
  13979. * @protected
  13980. */
  13981. protected function Clip($x, $y, $w, $h) {
  13982. if ($this->state != 2) {
  13983. return;
  13984. }
  13985. if ($this->rtl) {
  13986. $x = $this->w - $x - $w;
  13987. }
  13988. //save current Graphic State
  13989. $s = 'q';
  13990. //set clipping area
  13991. $s .= sprintf(' %F %F %F %F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  13992. //set up transformation matrix for gradient
  13993. $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  13994. $this->_out($s);
  13995. }
  13996. /**
  13997. * Output gradient.
  13998. * @param int $type 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)
  13999. * @param array $coords array of coordinates.
  14000. * @param array $stops 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).
  14001. * @param array $background An array of colour components appropriate to the colour space, specifying a single background colour value.
  14002. * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  14003. * @author Nicola Asuni
  14004. * @since 3.1.000 (2008-06-09)
  14005. * @public
  14006. */
  14007. public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
  14008. if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
  14009. return;
  14010. }
  14011. $n = count($this->gradients) + 1;
  14012. $this->gradients[$n] = array();
  14013. $this->gradients[$n]['type'] = $type;
  14014. $this->gradients[$n]['coords'] = $coords;
  14015. $this->gradients[$n]['antialias'] = $antialias;
  14016. $this->gradients[$n]['colors'] = array();
  14017. $this->gradients[$n]['transparency'] = false;
  14018. // color space
  14019. $numcolspace = count($stops[0]['color']);
  14020. $bcolor = array_values($background);
  14021. switch($numcolspace) {
  14022. case 5: // SPOT
  14023. case 4: { // CMYK
  14024. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  14025. if (!empty($background)) {
  14026. $this->gradients[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
  14027. }
  14028. break;
  14029. }
  14030. case 3: { // RGB
  14031. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  14032. if (!empty($background)) {
  14033. $this->gradients[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
  14034. }
  14035. break;
  14036. }
  14037. case 1: { // GRAY SCALE
  14038. $this->gradients[$n]['colspace'] = 'DeviceGray';
  14039. if (!empty($background)) {
  14040. $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255);
  14041. }
  14042. break;
  14043. }
  14044. }
  14045. $num_stops = count($stops);
  14046. $last_stop_id = $num_stops - 1;
  14047. foreach ($stops as $key => $stop) {
  14048. $this->gradients[$n]['colors'][$key] = array();
  14049. // offset represents a location along the gradient vector
  14050. if (isset($stop['offset'])) {
  14051. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  14052. } else {
  14053. if ($key == 0) {
  14054. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  14055. } elseif ($key == $last_stop_id) {
  14056. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  14057. } else {
  14058. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  14059. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  14060. }
  14061. }
  14062. if (isset($stop['opacity'])) {
  14063. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  14064. if ((!($this->pdfa_mode && $this->pdfa_version < 2)) AND ($stop['opacity'] < 1)) {
  14065. $this->gradients[$n]['transparency'] = true;
  14066. }
  14067. } else {
  14068. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  14069. }
  14070. // exponent for the exponential interpolation function
  14071. if (isset($stop['exponent'])) {
  14072. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  14073. } else {
  14074. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  14075. }
  14076. // set colors
  14077. $color = array_values($stop['color']);
  14078. switch($numcolspace) {
  14079. case 5: // SPOT
  14080. case 4: { // CMYK
  14081. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
  14082. break;
  14083. }
  14084. case 3: { // RGB
  14085. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
  14086. break;
  14087. }
  14088. case 1: { // GRAY SCALE
  14089. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
  14090. break;
  14091. }
  14092. }
  14093. }
  14094. if ($this->gradients[$n]['transparency']) {
  14095. // paint luminosity gradient
  14096. $this->_out('/TGS'.$n.' gs');
  14097. }
  14098. //paint the gradient
  14099. $this->_out('/Sh'.$n.' sh');
  14100. //restore previous Graphic State
  14101. $this->_outRestoreGraphicsState();
  14102. if ($this->inxobj) {
  14103. // we are inside an XObject template
  14104. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  14105. }
  14106. }
  14107. /**
  14108. * Output gradient shaders.
  14109. * @author Nicola Asuni
  14110. * @since 3.1.000 (2008-06-09)
  14111. * @protected
  14112. */
  14113. function _putshaders() {
  14114. if ($this->pdfa_mode && $this->pdfa_version < 2) {
  14115. return;
  14116. }
  14117. $idt = count($this->gradients); //index for transparency gradients
  14118. foreach ($this->gradients as $id => $grad) {
  14119. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  14120. $fc = $this->_newobj();
  14121. $out = '<<';
  14122. $out .= ' /FunctionType 3';
  14123. $out .= ' /Domain [0 1]';
  14124. $functions = '';
  14125. $bounds = '';
  14126. $encode = '';
  14127. $i = 1;
  14128. $num_cols = count($grad['colors']);
  14129. $lastcols = $num_cols - 1;
  14130. for ($i = 1; $i < $num_cols; ++$i) {
  14131. $functions .= ($fc + $i).' 0 R ';
  14132. if ($i < $lastcols) {
  14133. $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
  14134. }
  14135. $encode .= '0 1 ';
  14136. }
  14137. $out .= ' /Functions ['.trim($functions).']';
  14138. $out .= ' /Bounds ['.trim($bounds).']';
  14139. $out .= ' /Encode ['.trim($encode).']';
  14140. $out .= ' >>';
  14141. $out .= "\n".'endobj';
  14142. $this->_out($out);
  14143. for ($i = 1; $i < $num_cols; ++$i) {
  14144. $this->_newobj();
  14145. $out = '<<';
  14146. $out .= ' /FunctionType 2';
  14147. $out .= ' /Domain [0 1]';
  14148. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
  14149. $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  14150. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14151. $out .= ' >>';
  14152. $out .= "\n".'endobj';
  14153. $this->_out($out);
  14154. }
  14155. // set transparency functions
  14156. if ($grad['transparency']) {
  14157. $ft = $this->_newobj();
  14158. $out = '<<';
  14159. $out .= ' /FunctionType 3';
  14160. $out .= ' /Domain [0 1]';
  14161. $functions = '';
  14162. $i = 1;
  14163. $num_cols = count($grad['colors']);
  14164. for ($i = 1; $i < $num_cols; ++$i) {
  14165. $functions .= ($ft + $i).' 0 R ';
  14166. }
  14167. $out .= ' /Functions ['.trim($functions).']';
  14168. $out .= ' /Bounds ['.trim($bounds).']';
  14169. $out .= ' /Encode ['.trim($encode).']';
  14170. $out .= ' >>';
  14171. $out .= "\n".'endobj';
  14172. $this->_out($out);
  14173. for ($i = 1; $i < $num_cols; ++$i) {
  14174. $this->_newobj();
  14175. $out = '<<';
  14176. $out .= ' /FunctionType 2';
  14177. $out .= ' /Domain [0 1]';
  14178. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
  14179. $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  14180. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14181. $out .= ' >>';
  14182. $out .= "\n".'endobj';
  14183. $this->_out($out);
  14184. }
  14185. }
  14186. }
  14187. // set shading object
  14188. $this->_newobj();
  14189. $out = '<< /ShadingType '.$grad['type'];
  14190. if (isset($grad['colspace'])) {
  14191. $out .= ' /ColorSpace /'.$grad['colspace'];
  14192. } else {
  14193. $out .= ' /ColorSpace /DeviceRGB';
  14194. }
  14195. if (isset($grad['background']) AND !empty($grad['background'])) {
  14196. $out .= ' /Background ['.$grad['background'].']';
  14197. }
  14198. if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  14199. $out .= ' /AntiAlias true';
  14200. }
  14201. if ($grad['type'] == 2) {
  14202. $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  14203. $out .= ' /Domain [0 1]';
  14204. $out .= ' /Function '.$fc.' 0 R';
  14205. $out .= ' /Extend [true true]';
  14206. $out .= ' >>';
  14207. } elseif ($grad['type'] == 3) {
  14208. //x0, y0, r0, x1, y1, r1
  14209. //at this this time radius of inner circle is 0
  14210. $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  14211. $out .= ' /Domain [0 1]';
  14212. $out .= ' /Function '.$fc.' 0 R';
  14213. $out .= ' /Extend [true true]';
  14214. $out .= ' >>';
  14215. } elseif ($grad['type'] == 6) {
  14216. $out .= ' /BitsPerCoordinate 16';
  14217. $out .= ' /BitsPerComponent 8';
  14218. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  14219. $out .= ' /BitsPerFlag 8';
  14220. $stream = $this->_getrawstream($grad['stream']);
  14221. $out .= ' /Length '.strlen($stream);
  14222. $out .= ' >>';
  14223. $out .= ' stream'."\n".$stream."\n".'endstream';
  14224. }
  14225. $out .= "\n".'endobj';
  14226. $this->_out($out);
  14227. if ($grad['transparency']) {
  14228. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  14229. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
  14230. }
  14231. $this->gradients[$id]['id'] = $this->n;
  14232. // set pattern object
  14233. $this->_newobj();
  14234. $out = '<< /Type /Pattern /PatternType 2';
  14235. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  14236. $out .= ' >>';
  14237. $out .= "\n".'endobj';
  14238. $this->_out($out);
  14239. $this->gradients[$id]['pattern'] = $this->n;
  14240. // set shading and pattern for transparency mask
  14241. if ($grad['transparency']) {
  14242. // luminosity pattern
  14243. $idgs = $id + $idt;
  14244. $this->_newobj();
  14245. $this->_out($shading_transparency);
  14246. $this->gradients[$idgs]['id'] = $this->n;
  14247. $this->_newobj();
  14248. $out = '<< /Type /Pattern /PatternType 2';
  14249. $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  14250. $out .= ' >>';
  14251. $out .= "\n".'endobj';
  14252. $this->_out($out);
  14253. $this->gradients[$idgs]['pattern'] = $this->n;
  14254. // luminosity XObject
  14255. $oid = $this->_newobj();
  14256. $this->xobjects['LX'.$oid] = array('n' => $oid);
  14257. $filter = '';
  14258. $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  14259. if ($this->compress) {
  14260. $filter = ' /Filter /FlateDecode';
  14261. $stream = gzcompress($stream);
  14262. }
  14263. $stream = $this->_getrawstream($stream);
  14264. $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  14265. $out .= ' /Length '.strlen($stream);
  14266. $rect = sprintf('%F %F', $this->wPt, $this->hPt);
  14267. $out .= ' /BBox [0 0 '.$rect.']';
  14268. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  14269. $out .= ' /Resources <<';
  14270. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  14271. $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  14272. $out .= ' >>';
  14273. $out .= ' >> ';
  14274. $out .= ' stream'."\n".$stream."\n".'endstream';
  14275. $out .= "\n".'endobj';
  14276. $this->_out($out);
  14277. // SMask
  14278. $this->_newobj();
  14279. $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
  14280. $this->_out($out);
  14281. // ExtGState
  14282. $this->_newobj();
  14283. $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
  14284. $this->_out($out);
  14285. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
  14286. }
  14287. }
  14288. }
  14289. /**
  14290. * Draw the sector of a circle.
  14291. * It can be used for instance to render pie charts.
  14292. * @param float $xc abscissa of the center.
  14293. * @param float $yc ordinate of the center.
  14294. * @param float $r radius.
  14295. * @param float $a start angle (in degrees).
  14296. * @param float $b end angle (in degrees).
  14297. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  14298. * @param float $cw indicates whether to go clockwise (default: true).
  14299. * @param float $o origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90.
  14300. * @author Maxime Delorme, Nicola Asuni
  14301. * @since 3.1.000 (2008-06-09)
  14302. * @public
  14303. */
  14304. public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
  14305. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  14306. }
  14307. /**
  14308. * Draw the sector of an ellipse.
  14309. * It can be used for instance to render pie charts.
  14310. * @param float $xc abscissa of the center.
  14311. * @param float $yc ordinate of the center.
  14312. * @param float $rx the x-axis radius.
  14313. * @param float $ry the y-axis radius.
  14314. * @param float $a start angle (in degrees).
  14315. * @param float $b end angle (in degrees).
  14316. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  14317. * @param float $cw indicates whether to go clockwise.
  14318. * @param float $o origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  14319. * @param integer $nc Number of curves used to draw a 90 degrees portion of arc.
  14320. * @author Maxime Delorme, Nicola Asuni
  14321. * @since 3.1.000 (2008-06-09)
  14322. * @public
  14323. */
  14324. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
  14325. if ($this->state != 2) {
  14326. return;
  14327. }
  14328. if ($this->rtl) {
  14329. $xc = ($this->w - $xc);
  14330. }
  14331. $op = TCPDF_STATIC::getPathPaintOperator($style);
  14332. if ($op == 'f') {
  14333. $line_style = array();
  14334. }
  14335. if ($cw) {
  14336. $d = $b;
  14337. $b = (360 - $a + $o);
  14338. $a = (360 - $d + $o);
  14339. } else {
  14340. $b += $o;
  14341. $a += $o;
  14342. }
  14343. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  14344. $this->_out($op);
  14345. }
  14346. /**
  14347. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  14348. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  14349. * Only vector drawing is supported, not text or bitmap.
  14350. * 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).
  14351. * @param string $file Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  14352. * @param float|null $x Abscissa of the upper-left corner.
  14353. * @param float|null $y Ordinate of the upper-left corner.
  14354. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14355. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14356. * @param mixed $link URL or identifier returned by AddLink().
  14357. * @param boolean $useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  14358. * @param string $align 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>
  14359. * @param string $palign 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>
  14360. * @param mixed $border 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)))
  14361. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  14362. * @param boolean $fixoutvals if true remove values outside the bounding box.
  14363. * @author Valentin Schmidt, Nicola Asuni
  14364. * @since 3.1.000 (2008-06-09)
  14365. * @public
  14366. */
  14367. public function ImageEps($file, $x=null, $y=null, $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
  14368. if ($this->state != 2) {
  14369. return;
  14370. }
  14371. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  14372. // convert EPS to raster image using GD or ImageMagick libraries
  14373. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14374. }
  14375. if (TCPDF_STATIC::empty_string($x)) {
  14376. $x = $this->x;
  14377. }
  14378. if (TCPDF_STATIC::empty_string($y)) {
  14379. $y = $this->y;
  14380. }
  14381. // check page for no-write regions and adapt page margins if necessary
  14382. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14383. $k = $this->k;
  14384. if ($file[0] === '@') { // image from string
  14385. $data = substr($file, 1);
  14386. } else { // EPS/AI file
  14387. $data = $this->getCachedFileContents($file);
  14388. }
  14389. if ($data === FALSE) {
  14390. $this->Error('EPS file not found: '.$file);
  14391. }
  14392. $regs = array();
  14393. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  14394. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  14395. if (count($regs) > 1) {
  14396. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  14397. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  14398. $versexp = explode(' ', $version_str);
  14399. $version = (float)array_pop($versexp);
  14400. if ($version >= 9) {
  14401. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  14402. }
  14403. }
  14404. }
  14405. // strip binary bytes in front of PS-header
  14406. $start = strpos($data, '%!PS-Adobe');
  14407. if ($start > 0) {
  14408. $data = substr($data, $start);
  14409. }
  14410. // find BoundingBox params
  14411. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  14412. if (count($regs) > 1) {
  14413. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  14414. } else {
  14415. $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  14416. }
  14417. $start = strpos($data, '%%EndSetup');
  14418. if ($start === false) {
  14419. $start = strpos($data, '%%EndProlog');
  14420. }
  14421. if ($start === false) {
  14422. $start = strpos($data, '%%BoundingBox');
  14423. }
  14424. $data = substr($data, $start);
  14425. $end = strpos($data, '%%PageTrailer');
  14426. if ($end===false) {
  14427. $end = strpos($data, 'showpage');
  14428. }
  14429. if ($end) {
  14430. $data = substr($data, 0, $end);
  14431. }
  14432. // calculate image width and height on document
  14433. if (($w <= 0) AND ($h <= 0)) {
  14434. $w = ($x2 - $x1) / $k;
  14435. $h = ($y2 - $y1) / $k;
  14436. } elseif ($w <= 0) {
  14437. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  14438. } elseif ($h <= 0) {
  14439. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  14440. }
  14441. // fit the image on available space
  14442. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  14443. if ($this->rasterize_vector_images) {
  14444. // convert EPS to raster image using GD or ImageMagick libraries
  14445. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14446. }
  14447. // set scaling factors
  14448. $scale_x = $w / (($x2 - $x1) / $k);
  14449. $scale_y = $h / (($y2 - $y1) / $k);
  14450. // set alignment
  14451. $this->img_rb_y = $y + $h;
  14452. // set alignment
  14453. if ($this->rtl) {
  14454. if ($palign == 'L') {
  14455. $ximg = $this->lMargin;
  14456. } elseif ($palign == 'C') {
  14457. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14458. } elseif ($palign == 'R') {
  14459. $ximg = $this->w - $this->rMargin - $w;
  14460. } else {
  14461. $ximg = $x - $w;
  14462. }
  14463. $this->img_rb_x = $ximg;
  14464. } else {
  14465. if ($palign == 'L') {
  14466. $ximg = $this->lMargin;
  14467. } elseif ($palign == 'C') {
  14468. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14469. } elseif ($palign == 'R') {
  14470. $ximg = $this->w - $this->rMargin - $w;
  14471. } else {
  14472. $ximg = $x;
  14473. }
  14474. $this->img_rb_x = $ximg + $w;
  14475. }
  14476. if ($useBoundingBox) {
  14477. $dx = $ximg * $k - $x1;
  14478. $dy = $y * $k - $y1;
  14479. } else {
  14480. $dx = $ximg * $k;
  14481. $dy = $y * $k;
  14482. }
  14483. // save the current graphic state
  14484. $this->_out('q'.$this->epsmarker);
  14485. // translate
  14486. $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  14487. // scale
  14488. if (isset($scale_x)) {
  14489. $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  14490. }
  14491. // handle pc/unix/mac line endings
  14492. $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
  14493. $u=0;
  14494. $cnt = count($lines);
  14495. for ($i=0; $i < $cnt; ++$i) {
  14496. $line = $lines[$i];
  14497. if (($line == '') OR ($line[0] == '%')) {
  14498. continue;
  14499. }
  14500. $len = strlen($line);
  14501. // check for spot color names
  14502. $color_name = '';
  14503. if (strcasecmp('x', substr(trim($line), -1)) == 0) {
  14504. if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
  14505. // extract spot color name
  14506. $color_name = $matches[0];
  14507. // remove color name from string
  14508. $line = str_replace(' '.$color_name, '', $line);
  14509. // remove pharentesis from color name
  14510. $color_name = substr($color_name, 1, -1);
  14511. }
  14512. }
  14513. $chunks = explode(' ', $line);
  14514. $cmd = trim(array_pop($chunks));
  14515. // RGB
  14516. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  14517. $b = array_pop($chunks);
  14518. $g = array_pop($chunks);
  14519. $r = array_pop($chunks);
  14520. $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!
  14521. continue;
  14522. }
  14523. $skip = false;
  14524. if ($fixoutvals) {
  14525. // check for values outside the bounding box
  14526. switch ($cmd) {
  14527. case 'm':
  14528. case 'l':
  14529. case 'L': {
  14530. // skip values outside bounding box
  14531. foreach ($chunks as $key => $val) {
  14532. if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
  14533. $skip = true;
  14534. } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
  14535. $skip = true;
  14536. }
  14537. }
  14538. }
  14539. }
  14540. }
  14541. switch ($cmd) {
  14542. case 'm':
  14543. case 'l':
  14544. case 'v':
  14545. case 'y':
  14546. case 'c':
  14547. case 'k':
  14548. case 'K':
  14549. case 'g':
  14550. case 'G':
  14551. case 's':
  14552. case 'S':
  14553. case 'J':
  14554. case 'j':
  14555. case 'w':
  14556. case 'M':
  14557. case 'd':
  14558. case 'n': {
  14559. if ($skip) {
  14560. break;
  14561. }
  14562. $this->_out($line);
  14563. break;
  14564. }
  14565. case 'x': {// custom fill color
  14566. if (empty($color_name)) {
  14567. // CMYK color
  14568. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14569. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  14570. } else {
  14571. // Spot Color (CMYK + tint)
  14572. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14573. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14574. $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14575. $this->_out($color_cmd);
  14576. }
  14577. break;
  14578. }
  14579. case 'X': { // custom stroke color
  14580. if (empty($color_name)) {
  14581. // CMYK color
  14582. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14583. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  14584. } else {
  14585. // Spot Color (CMYK + tint)
  14586. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14587. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14588. $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14589. $this->_out($color_cmd);
  14590. }
  14591. break;
  14592. }
  14593. case 'Y':
  14594. case 'N':
  14595. case 'V':
  14596. case 'L':
  14597. case 'C': {
  14598. if ($skip) {
  14599. break;
  14600. }
  14601. $line[($len - 1)] = strtolower($cmd);
  14602. $this->_out($line);
  14603. break;
  14604. }
  14605. case 'b':
  14606. case 'B': {
  14607. $this->_out($cmd . '*');
  14608. break;
  14609. }
  14610. case 'f':
  14611. case 'F': {
  14612. if ($u > 0) {
  14613. $isU = false;
  14614. $max = min(($i + 5), $cnt);
  14615. for ($j = ($i + 1); $j < $max; ++$j) {
  14616. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  14617. }
  14618. if ($isU) {
  14619. $this->_out('f*');
  14620. }
  14621. } else {
  14622. $this->_out('f*');
  14623. }
  14624. break;
  14625. }
  14626. case '*u': {
  14627. ++$u;
  14628. break;
  14629. }
  14630. case '*U': {
  14631. --$u;
  14632. break;
  14633. }
  14634. }
  14635. }
  14636. // restore previous graphic state
  14637. $this->_out($this->epsmarker.'Q');
  14638. if (!empty($border)) {
  14639. $bx = $this->x;
  14640. $by = $this->y;
  14641. $this->x = $ximg;
  14642. if ($this->rtl) {
  14643. $this->x += $w;
  14644. }
  14645. $this->y = $y;
  14646. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  14647. $this->x = $bx;
  14648. $this->y = $by;
  14649. }
  14650. if ($link) {
  14651. $this->Link($ximg, $y, $w, $h, $link, 0);
  14652. }
  14653. // set pointer to align the next text/objects
  14654. switch($align) {
  14655. case 'T':{
  14656. $this->y = $y;
  14657. $this->x = $this->img_rb_x;
  14658. break;
  14659. }
  14660. case 'M':{
  14661. $this->y = $y + round($h/2);
  14662. $this->x = $this->img_rb_x;
  14663. break;
  14664. }
  14665. case 'B':{
  14666. $this->y = $this->img_rb_y;
  14667. $this->x = $this->img_rb_x;
  14668. break;
  14669. }
  14670. case 'N':{
  14671. $this->setY($this->img_rb_y);
  14672. break;
  14673. }
  14674. default:{
  14675. break;
  14676. }
  14677. }
  14678. $this->endlinex = $this->img_rb_x;
  14679. }
  14680. /**
  14681. * Set document barcode.
  14682. * @param string $bc barcode
  14683. * @public
  14684. */
  14685. public function setBarcode($bc='') {
  14686. $this->barcode = $bc;
  14687. }
  14688. /**
  14689. * Get current barcode.
  14690. * @return string
  14691. * @public
  14692. * @since 4.0.012 (2008-07-24)
  14693. */
  14694. public function getBarcode() {
  14695. return $this->barcode;
  14696. }
  14697. /**
  14698. * Print a Linear Barcode.
  14699. * @param string $code code to print
  14700. * @param string $type type of barcode (see tcpdf_barcodes_1d.php for supported formats).
  14701. * @param float|null $x x position in user units (null = current x position)
  14702. * @param float|null $y y position in user units (null = current y position)
  14703. * @param float|null $w width in user units (null = remaining page width)
  14704. * @param float|null $h height in user units (null = remaining page height)
  14705. * @param float|null $xres width of the smallest bar in user units (null = default value = 0.4mm)
  14706. * @param array $style array of options:<ul>
  14707. * <li>boolean $style['border'] if true prints a border</li>
  14708. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  14709. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  14710. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  14711. * <li>array $style['fgcolor'] color array for bars and text</li>
  14712. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  14713. * <li>boolean $style['text'] if true prints text below the barcode</li>
  14714. * <li>string $style['label'] override default label</li>
  14715. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  14716. * <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>
  14717. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  14718. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  14719. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  14720. * <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>
  14721. * <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>
  14722. * @param string $align 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>
  14723. * @author Nicola Asuni
  14724. * @since 3.1.000 (2008-06-09)
  14725. * @public
  14726. */
  14727. public function write1DBarcode($code, $type, $x=null, $y=null, $w=null, $h=null, $xres=null, $style=array(), $align='') {
  14728. if (TCPDF_STATIC::empty_string(trim($code))) {
  14729. return;
  14730. }
  14731. require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php');
  14732. // save current graphic settings
  14733. $gvars = $this->getGraphicVars();
  14734. // create new barcode object
  14735. $barcodeobj = new TCPDFBarcode($code, $type);
  14736. $arrcode = $barcodeobj->getBarcodeArray();
  14737. if (empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
  14738. $this->Error('Error in 1D barcode string');
  14739. }
  14740. if ($arrcode['maxh'] <= 0) {
  14741. $arrcode['maxh'] = 1;
  14742. }
  14743. // set default values
  14744. if (!isset($style['position'])) {
  14745. $style['position'] = '';
  14746. } elseif ($style['position'] == 'S') {
  14747. // keep this for backward compatibility
  14748. $style['position'] = '';
  14749. $style['stretch'] = true;
  14750. }
  14751. if (!isset($style['fitwidth'])) {
  14752. if (!isset($style['stretch'])) {
  14753. $style['fitwidth'] = true;
  14754. } else {
  14755. $style['fitwidth'] = false;
  14756. }
  14757. }
  14758. if ($style['fitwidth']) {
  14759. // disable stretch
  14760. $style['stretch'] = false;
  14761. }
  14762. if (!isset($style['stretch'])) {
  14763. if (($w === '') OR ($w <= 0)) {
  14764. $style['stretch'] = false;
  14765. } else {
  14766. $style['stretch'] = true;
  14767. }
  14768. }
  14769. if (!isset($style['fgcolor'])) {
  14770. $style['fgcolor'] = array(0,0,0); // default black
  14771. }
  14772. if (!isset($style['bgcolor'])) {
  14773. $style['bgcolor'] = false; // default transparent
  14774. }
  14775. if (!isset($style['border'])) {
  14776. $style['border'] = false;
  14777. }
  14778. $fontsize = 0;
  14779. if (!isset($style['text'])) {
  14780. $style['text'] = false;
  14781. }
  14782. if ($style['text'] AND isset($style['font'])) {
  14783. if (isset($style['fontsize'])) {
  14784. $fontsize = $style['fontsize'];
  14785. }
  14786. $this->setFont($style['font'], '', $fontsize);
  14787. }
  14788. if (!isset($style['stretchtext'])) {
  14789. $style['stretchtext'] = 4;
  14790. }
  14791. if (TCPDF_STATIC::empty_string($x)) {
  14792. $x = $this->x;
  14793. }
  14794. if (TCPDF_STATIC::empty_string($y)) {
  14795. $y = $this->y;
  14796. }
  14797. // check page for no-write regions and adapt page margins if necessary
  14798. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14799. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  14800. if ($this->rtl) {
  14801. $w = $x - $this->lMargin;
  14802. } else {
  14803. $w = $this->w - $this->rMargin - $x;
  14804. }
  14805. }
  14806. // padding
  14807. if (!isset($style['padding'])) {
  14808. $padding = 0;
  14809. } elseif ($style['padding'] === 'auto') {
  14810. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  14811. } else {
  14812. $padding = floatval($style['padding']);
  14813. }
  14814. // horizontal padding
  14815. if (!isset($style['hpadding'])) {
  14816. $hpadding = $padding;
  14817. } elseif ($style['hpadding'] === 'auto') {
  14818. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  14819. } else {
  14820. $hpadding = floatval($style['hpadding']);
  14821. }
  14822. // vertical padding
  14823. if (!isset($style['vpadding'])) {
  14824. $vpadding = $padding;
  14825. } elseif ($style['vpadding'] === 'auto') {
  14826. $vpadding = ($hpadding / 2);
  14827. } else {
  14828. $vpadding = floatval($style['vpadding']);
  14829. }
  14830. // calculate xres (single bar width)
  14831. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  14832. if ($style['stretch']) {
  14833. $xres = $max_xres;
  14834. } else {
  14835. if (TCPDF_STATIC::empty_string($xres)) {
  14836. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  14837. }
  14838. if ($xres > $max_xres) {
  14839. // correct xres to fit on $w
  14840. $xres = $max_xres;
  14841. }
  14842. if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  14843. OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  14844. $hpadding = 10 * $xres;
  14845. if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  14846. $vpadding = ($hpadding / 2);
  14847. }
  14848. }
  14849. }
  14850. if ($style['fitwidth']) {
  14851. $wold = $w;
  14852. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  14853. if (isset($style['cellfitalign'])) {
  14854. switch ($style['cellfitalign']) {
  14855. case 'L': {
  14856. if ($this->rtl) {
  14857. $x -= ($wold - $w);
  14858. }
  14859. break;
  14860. }
  14861. case 'R': {
  14862. if (!$this->rtl) {
  14863. $x += ($wold - $w);
  14864. }
  14865. break;
  14866. }
  14867. case 'C': {
  14868. if ($this->rtl) {
  14869. $x -= (($wold - $w) / 2);
  14870. } else {
  14871. $x += (($wold - $w) / 2);
  14872. }
  14873. break;
  14874. }
  14875. default : {
  14876. break;
  14877. }
  14878. }
  14879. }
  14880. }
  14881. $text_height = $this->getCellHeight($fontsize / $this->k);
  14882. // height
  14883. if (TCPDF_STATIC::empty_string($h) OR ($h <= 0)) {
  14884. // set default height
  14885. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  14886. }
  14887. $barh = $h - $text_height - (2 * $vpadding);
  14888. if ($barh <=0) {
  14889. // try to reduce font or padding to fit barcode on available height
  14890. if ($text_height > $h) {
  14891. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  14892. $text_height = $this->getCellHeight($fontsize / $this->k);
  14893. $this->setFont($style['font'], '', $fontsize);
  14894. }
  14895. if ($vpadding > 0) {
  14896. $vpadding = (($h - $text_height) / 4);
  14897. }
  14898. $barh = $h - $text_height - (2 * $vpadding);
  14899. }
  14900. // fit the barcode on available space
  14901. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  14902. // set alignment
  14903. $this->img_rb_y = $y + $h;
  14904. // set alignment
  14905. if ($this->rtl) {
  14906. if ($style['position'] == 'L') {
  14907. $xpos = $this->lMargin;
  14908. } elseif ($style['position'] == 'C') {
  14909. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14910. } elseif ($style['position'] == 'R') {
  14911. $xpos = $this->w - $this->rMargin - $w;
  14912. } else {
  14913. $xpos = $x - $w;
  14914. }
  14915. $this->img_rb_x = $xpos;
  14916. } else {
  14917. if ($style['position'] == 'L') {
  14918. $xpos = $this->lMargin;
  14919. } elseif ($style['position'] == 'C') {
  14920. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14921. } elseif ($style['position'] == 'R') {
  14922. $xpos = $this->w - $this->rMargin - $w;
  14923. } else {
  14924. $xpos = $x;
  14925. }
  14926. $this->img_rb_x = $xpos + $w;
  14927. }
  14928. $xpos_rect = $xpos;
  14929. if (!isset($style['align'])) {
  14930. $style['align'] = 'C';
  14931. }
  14932. switch ($style['align']) {
  14933. case 'L': {
  14934. $xpos = $xpos_rect + $hpadding;
  14935. break;
  14936. }
  14937. case 'R': {
  14938. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  14939. break;
  14940. }
  14941. case 'C':
  14942. default : {
  14943. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  14944. break;
  14945. }
  14946. }
  14947. $xpos_text = $xpos;
  14948. // barcode is always printed in LTR direction
  14949. $tempRTL = $this->rtl;
  14950. $this->rtl = false;
  14951. // print background color
  14952. if ($style['bgcolor']) {
  14953. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  14954. } elseif ($style['border']) {
  14955. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  14956. }
  14957. // set foreground color
  14958. $this->setDrawColorArray($style['fgcolor']);
  14959. $this->setTextColorArray($style['fgcolor']);
  14960. // print bars
  14961. foreach ($arrcode['bcode'] as $k => $v) {
  14962. $bw = ($v['w'] * $xres);
  14963. if ($v['t']) {
  14964. // draw a vertical bar
  14965. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  14966. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  14967. }
  14968. $xpos += $bw;
  14969. }
  14970. // print text
  14971. if ($style['text']) {
  14972. if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) {
  14973. $label = $style['label'];
  14974. } else {
  14975. $label = $code;
  14976. }
  14977. $txtwidth = ($arrcode['maxw'] * $xres);
  14978. if ($this->GetStringWidth($label) > $txtwidth) {
  14979. $style['stretchtext'] = 2;
  14980. }
  14981. // print text
  14982. $this->x = $xpos_text;
  14983. $this->y = $y + $vpadding + $barh;
  14984. $cellpadding = $this->cell_padding;
  14985. $this->setCellPadding(0);
  14986. $this->Cell($txtwidth, 0, $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
  14987. $this->cell_padding = $cellpadding;
  14988. }
  14989. // restore original direction
  14990. $this->rtl = $tempRTL;
  14991. // restore previous settings
  14992. $this->setGraphicVars($gvars);
  14993. // set pointer to align the next text/objects
  14994. switch($align) {
  14995. case 'T':{
  14996. $this->y = $y;
  14997. $this->x = $this->img_rb_x;
  14998. break;
  14999. }
  15000. case 'M':{
  15001. $this->y = $y + round($h / 2);
  15002. $this->x = $this->img_rb_x;
  15003. break;
  15004. }
  15005. case 'B':{
  15006. $this->y = $this->img_rb_y;
  15007. $this->x = $this->img_rb_x;
  15008. break;
  15009. }
  15010. case 'N':{
  15011. $this->setY($this->img_rb_y);
  15012. break;
  15013. }
  15014. default:{
  15015. break;
  15016. }
  15017. }
  15018. $this->endlinex = $this->img_rb_x;
  15019. }
  15020. /**
  15021. * Print 2D Barcode.
  15022. * @param string $code code to print
  15023. * @param string $type type of barcode (see tcpdf_barcodes_2d.php for supported formats).
  15024. * @param float|null $x x position in user units
  15025. * @param float|null $y y position in user units
  15026. * @param float|null $w width in user units
  15027. * @param float|null $h height in user units
  15028. * @param array $style array of options:<ul>
  15029. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  15030. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  15031. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  15032. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  15033. * <li>int $style['module_width'] width of a single module in points</li>
  15034. * <li>int $style['module_height'] height of a single module in points</li>
  15035. * <li>array $style['fgcolor'] color array for bars and text</li>
  15036. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  15037. * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li>
  15038. * @param string $align 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>
  15039. * @param boolean $distort if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  15040. * @author Nicola Asuni
  15041. * @since 4.5.037 (2009-04-07)
  15042. * @public
  15043. */
  15044. public function write2DBarcode($code, $type, $x=null, $y=null, $w=null, $h=null, $style=array(), $align='', $distort=false) {
  15045. if (TCPDF_STATIC::empty_string(trim($code))) {
  15046. return;
  15047. }
  15048. require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php');
  15049. // save current graphic settings
  15050. $gvars = $this->getGraphicVars();
  15051. // create new barcode object
  15052. $barcodeobj = new TCPDF2DBarcode($code, $type);
  15053. $arrcode = $barcodeobj->getBarcodeArray();
  15054. if (empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
  15055. $this->Error('Error in 2D barcode string');
  15056. }
  15057. // set default values
  15058. if (!isset($style['position'])) {
  15059. $style['position'] = '';
  15060. }
  15061. if (!isset($style['fgcolor'])) {
  15062. $style['fgcolor'] = array(0,0,0); // default black
  15063. }
  15064. if (!isset($style['bgcolor'])) {
  15065. $style['bgcolor'] = false; // default transparent
  15066. }
  15067. if (!isset($style['border'])) {
  15068. $style['border'] = false;
  15069. }
  15070. // padding
  15071. if (!isset($style['padding'])) {
  15072. $style['padding'] = 0;
  15073. } elseif ($style['padding'] === 'auto') {
  15074. $style['padding'] = 4;
  15075. }
  15076. if (!isset($style['hpadding'])) {
  15077. $style['hpadding'] = $style['padding'];
  15078. } elseif ($style['hpadding'] === 'auto') {
  15079. $style['hpadding'] = 4;
  15080. }
  15081. if (!isset($style['vpadding'])) {
  15082. $style['vpadding'] = $style['padding'];
  15083. } elseif ($style['vpadding'] === 'auto') {
  15084. $style['vpadding'] = 4;
  15085. }
  15086. $hpad = (2 * $style['hpadding']);
  15087. $vpad = (2 * $style['vpadding']);
  15088. // cell (module) dimension
  15089. if (!isset($style['module_width'])) {
  15090. $style['module_width'] = 1; // width of a single module in points
  15091. }
  15092. if (!isset($style['module_height'])) {
  15093. $style['module_height'] = 1; // height of a single module in points
  15094. }
  15095. if (TCPDF_STATIC::empty_string($x)) {
  15096. $x = $this->x;
  15097. }
  15098. if (TCPDF_STATIC::empty_string($y)) {
  15099. $y = $this->y;
  15100. }
  15101. // check page for no-write regions and adapt page margins if necessary
  15102. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  15103. // number of barcode columns and rows
  15104. $rows = $arrcode['num_rows'];
  15105. $cols = $arrcode['num_cols'];
  15106. if (($rows <= 0) || ($cols <= 0)){
  15107. $this->Error('Error in 2D barcode string');
  15108. }
  15109. // module width and height
  15110. $mw = $style['module_width'];
  15111. $mh = $style['module_height'];
  15112. if (($mw <= 0) OR ($mh <= 0)) {
  15113. $this->Error('Error in 2D barcode string');
  15114. }
  15115. // get max dimensions
  15116. if ($this->rtl) {
  15117. $maxw = $x - $this->lMargin;
  15118. } else {
  15119. $maxw = $this->w - $this->rMargin - $x;
  15120. }
  15121. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  15122. $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
  15123. $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
  15124. if (!$distort) {
  15125. if (($maxw * $ratioHW) > $maxh) {
  15126. $maxw = $maxh * $ratioWH;
  15127. }
  15128. if (($maxh * $ratioWH) > $maxw) {
  15129. $maxh = $maxw * $ratioHW;
  15130. }
  15131. }
  15132. // set maximum dimensions
  15133. if ($w > $maxw) {
  15134. $w = $maxw;
  15135. }
  15136. if ($h > $maxh) {
  15137. $h = $maxh;
  15138. }
  15139. // set dimensions
  15140. if ((TCPDF_STATIC::empty_string($w) OR ($w <= 0)) AND (TCPDF_STATIC::empty_string($h) OR ($h <= 0))) {
  15141. $w = ($cols + $hpad) * ($mw / $this->k);
  15142. $h = ($rows + $vpad) * ($mh / $this->k);
  15143. } elseif (($w === '') OR ($w <= 0)) {
  15144. $w = $h * $ratioWH;
  15145. } elseif (($h === '') OR ($h <= 0)) {
  15146. $h = $w * $ratioHW;
  15147. }
  15148. // barcode size (excluding padding)
  15149. $bw = ($w * $cols) / ($cols + $hpad);
  15150. $bh = ($h * $rows) / ($rows + $vpad);
  15151. // dimension of single barcode cell unit
  15152. $cw = $bw / $cols;
  15153. $ch = $bh / $rows;
  15154. if (!$distort) {
  15155. if (($cw / $ch) > ($mw / $mh)) {
  15156. // correct horizontal distortion
  15157. $cw = $ch * $mw / $mh;
  15158. $bw = $cw * $cols;
  15159. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  15160. } else {
  15161. // correct vertical distortion
  15162. $ch = $cw * $mh / $mw;
  15163. $bh = $ch * $rows;
  15164. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  15165. }
  15166. }
  15167. // fit the barcode on available space
  15168. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  15169. // set alignment
  15170. $this->img_rb_y = $y + $h;
  15171. // set alignment
  15172. if ($this->rtl) {
  15173. if ($style['position'] == 'L') {
  15174. $xpos = $this->lMargin;
  15175. } elseif ($style['position'] == 'C') {
  15176. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15177. } elseif ($style['position'] == 'R') {
  15178. $xpos = $this->w - $this->rMargin - $w;
  15179. } else {
  15180. $xpos = $x - $w;
  15181. }
  15182. $this->img_rb_x = $xpos;
  15183. } else {
  15184. if ($style['position'] == 'L') {
  15185. $xpos = $this->lMargin;
  15186. } elseif ($style['position'] == 'C') {
  15187. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15188. } elseif ($style['position'] == 'R') {
  15189. $xpos = $this->w - $this->rMargin - $w;
  15190. } else {
  15191. $xpos = $x;
  15192. }
  15193. $this->img_rb_x = $xpos + $w;
  15194. }
  15195. $xstart = $xpos + ($style['hpadding'] * $cw);
  15196. $ystart = $y + ($style['vpadding'] * $ch);
  15197. // barcode is always printed in LTR direction
  15198. $tempRTL = $this->rtl;
  15199. $this->rtl = false;
  15200. // print background color
  15201. if ($style['bgcolor']) {
  15202. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  15203. } elseif ($style['border']) {
  15204. $this->Rect($xpos, $y, $w, $h, 'D');
  15205. }
  15206. // set foreground color
  15207. $this->setDrawColorArray($style['fgcolor']);
  15208. // print barcode cells
  15209. // for each row
  15210. for ($r = 0; $r < $rows; ++$r) {
  15211. $xr = $xstart;
  15212. // for each column
  15213. for ($c = 0; $c < $cols; ++$c) {
  15214. if ($arrcode['bcode'][$r][$c] == 1) {
  15215. // draw a single barcode cell
  15216. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  15217. }
  15218. $xr += $cw;
  15219. }
  15220. $ystart += $ch;
  15221. }
  15222. // restore original direction
  15223. $this->rtl = $tempRTL;
  15224. // restore previous settings
  15225. $this->setGraphicVars($gvars);
  15226. // set pointer to align the next text/objects
  15227. switch($align) {
  15228. case 'T':{
  15229. $this->y = $y;
  15230. $this->x = $this->img_rb_x;
  15231. break;
  15232. }
  15233. case 'M':{
  15234. $this->y = $y + round($h/2);
  15235. $this->x = $this->img_rb_x;
  15236. break;
  15237. }
  15238. case 'B':{
  15239. $this->y = $this->img_rb_y;
  15240. $this->x = $this->img_rb_x;
  15241. break;
  15242. }
  15243. case 'N':{
  15244. $this->setY($this->img_rb_y);
  15245. break;
  15246. }
  15247. default:{
  15248. break;
  15249. }
  15250. }
  15251. $this->endlinex = $this->img_rb_x;
  15252. }
  15253. /**
  15254. * Returns an array containing current margins:
  15255. * <ul>
  15256. <li>$ret['left'] = left margin</li>
  15257. <li>$ret['right'] = right margin</li>
  15258. <li>$ret['top'] = top margin</li>
  15259. <li>$ret['bottom'] = bottom margin</li>
  15260. <li>$ret['header'] = header margin</li>
  15261. <li>$ret['footer'] = footer margin</li>
  15262. <li>$ret['cell'] = cell padding array</li>
  15263. <li>$ret['padding_left'] = cell left padding</li>
  15264. <li>$ret['padding_top'] = cell top padding</li>
  15265. <li>$ret['padding_right'] = cell right padding</li>
  15266. <li>$ret['padding_bottom'] = cell bottom padding</li>
  15267. * </ul>
  15268. * @return array containing all margins measures
  15269. * @public
  15270. * @since 3.2.000 (2008-06-23)
  15271. */
  15272. public function getMargins() {
  15273. $ret = array(
  15274. 'left' => $this->lMargin,
  15275. 'right' => $this->rMargin,
  15276. 'top' => $this->tMargin,
  15277. 'bottom' => $this->bMargin,
  15278. 'header' => $this->header_margin,
  15279. 'footer' => $this->footer_margin,
  15280. 'cell' => $this->cell_padding,
  15281. 'padding_left' => $this->cell_padding['L'],
  15282. 'padding_top' => $this->cell_padding['T'],
  15283. 'padding_right' => $this->cell_padding['R'],
  15284. 'padding_bottom' => $this->cell_padding['B']
  15285. );
  15286. return $ret;
  15287. }
  15288. /**
  15289. * Returns an array containing original margins:
  15290. * <ul>
  15291. <li>$ret['left'] = left margin</li>
  15292. <li>$ret['right'] = right margin</li>
  15293. * </ul>
  15294. * @return array containing all margins measures
  15295. * @public
  15296. * @since 4.0.012 (2008-07-24)
  15297. */
  15298. public function getOriginalMargins() {
  15299. $ret = array(
  15300. 'left' => $this->original_lMargin,
  15301. 'right' => $this->original_rMargin
  15302. );
  15303. return $ret;
  15304. }
  15305. /**
  15306. * Returns the current font size.
  15307. * @return float current font size
  15308. * @public
  15309. * @since 3.2.000 (2008-06-23)
  15310. */
  15311. public function getFontSize() {
  15312. return $this->FontSize;
  15313. }
  15314. /**
  15315. * Returns the current font size in points unit.
  15316. * @return int current font size in points unit
  15317. * @public
  15318. * @since 3.2.000 (2008-06-23)
  15319. */
  15320. public function getFontSizePt() {
  15321. return $this->FontSizePt;
  15322. }
  15323. /**
  15324. * Returns the current font family name.
  15325. * @return string current font family name
  15326. * @public
  15327. * @since 4.3.008 (2008-12-05)
  15328. */
  15329. public function getFontFamily() {
  15330. return $this->FontFamily;
  15331. }
  15332. /**
  15333. * Returns the current font style.
  15334. * @return string current font style
  15335. * @public
  15336. * @since 4.3.008 (2008-12-05)
  15337. */
  15338. public function getFontStyle() {
  15339. return $this->FontStyle;
  15340. }
  15341. /**
  15342. * Cleanup HTML code (requires HTML Tidy library).
  15343. * @param string $html htmlcode to fix
  15344. * @param string $default_css CSS commands to add
  15345. * @param array|null $tagvs parameters for setHtmlVSpace method
  15346. * @param array|null $tidy_options options for tidy_parse_string function
  15347. * @return string XHTML code cleaned up
  15348. * @author Nicola Asuni
  15349. * @public
  15350. * @since 5.9.017 (2010-11-16)
  15351. * @see setHtmlVSpace()
  15352. */
  15353. public function fixHTMLCode($html, $default_css='', $tagvs=null, $tidy_options=null) {
  15354. return TCPDF_STATIC::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces);
  15355. }
  15356. /**
  15357. * Returns the border width from CSS property
  15358. * @param string $width border width
  15359. * @return int with in user units
  15360. * @protected
  15361. * @since 5.7.000 (2010-08-02)
  15362. */
  15363. protected function getCSSBorderWidth($width) {
  15364. if ($width == 'thin') {
  15365. $width = (2 / $this->k);
  15366. } elseif ($width == 'medium') {
  15367. $width = (4 / $this->k);
  15368. } elseif ($width == 'thick') {
  15369. $width = (6 / $this->k);
  15370. } else {
  15371. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  15372. }
  15373. return $width;
  15374. }
  15375. /**
  15376. * Returns the border dash style from CSS property
  15377. * @param string $style border style to convert
  15378. * @return int sash style (return -1 in case of none or hidden border)
  15379. * @protected
  15380. * @since 5.7.000 (2010-08-02)
  15381. */
  15382. protected function getCSSBorderDashStyle($style) {
  15383. switch (strtolower($style)) {
  15384. case 'none':
  15385. case 'hidden': {
  15386. $dash = -1;
  15387. break;
  15388. }
  15389. case 'dotted': {
  15390. $dash = 1;
  15391. break;
  15392. }
  15393. case 'dashed': {
  15394. $dash = 3;
  15395. break;
  15396. }
  15397. case 'double':
  15398. case 'groove':
  15399. case 'ridge':
  15400. case 'inset':
  15401. case 'outset':
  15402. case 'solid':
  15403. default: {
  15404. $dash = 0;
  15405. break;
  15406. }
  15407. }
  15408. return $dash;
  15409. }
  15410. /**
  15411. * Returns the border style array from CSS border properties
  15412. * @param string $cssborder border properties
  15413. * @return array containing border properties
  15414. * @protected
  15415. * @since 5.7.000 (2010-08-02)
  15416. */
  15417. protected function getCSSBorderStyle($cssborder) {
  15418. $bprop = preg_split('/[\s]+/', trim($cssborder));
  15419. $border = array(); // value to be returned
  15420. switch (count($bprop)) {
  15421. case 3: {
  15422. $width = $bprop[0];
  15423. $style = $bprop[1];
  15424. $color = $bprop[2];
  15425. break;
  15426. }
  15427. case 2: {
  15428. $width = 'medium';
  15429. $style = $bprop[0];
  15430. $color = $bprop[1];
  15431. break;
  15432. }
  15433. case 1: {
  15434. $width = 'medium';
  15435. $style = $bprop[0];
  15436. $color = 'black';
  15437. break;
  15438. }
  15439. default: {
  15440. $width = 'medium';
  15441. $style = 'solid';
  15442. $color = 'black';
  15443. break;
  15444. }
  15445. }
  15446. if ($style == 'none') {
  15447. return array();
  15448. }
  15449. $border['cap'] = 'square';
  15450. $border['join'] = 'miter';
  15451. $border['dash'] = $this->getCSSBorderDashStyle($style);
  15452. if ($border['dash'] < 0) {
  15453. return array();
  15454. }
  15455. $border['width'] = $this->getCSSBorderWidth($width);
  15456. $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color, $this->spot_colors);
  15457. return $border;
  15458. }
  15459. /**
  15460. * Get the internal Cell padding from CSS attribute.
  15461. * @param string $csspadding padding properties
  15462. * @param float $width width of the containing element
  15463. * @return array of cell paddings
  15464. * @public
  15465. * @since 5.9.000 (2010-10-04)
  15466. */
  15467. public function getCSSPadding($csspadding, $width=0) {
  15468. $padding = preg_split('/[\s]+/', trim($csspadding));
  15469. $cell_padding = array(); // value to be returned
  15470. switch (count($padding)) {
  15471. case 4: {
  15472. $cell_padding['T'] = $padding[0];
  15473. $cell_padding['R'] = $padding[1];
  15474. $cell_padding['B'] = $padding[2];
  15475. $cell_padding['L'] = $padding[3];
  15476. break;
  15477. }
  15478. case 3: {
  15479. $cell_padding['T'] = $padding[0];
  15480. $cell_padding['R'] = $padding[1];
  15481. $cell_padding['B'] = $padding[2];
  15482. $cell_padding['L'] = $padding[1];
  15483. break;
  15484. }
  15485. case 2: {
  15486. $cell_padding['T'] = $padding[0];
  15487. $cell_padding['R'] = $padding[1];
  15488. $cell_padding['B'] = $padding[0];
  15489. $cell_padding['L'] = $padding[1];
  15490. break;
  15491. }
  15492. case 1: {
  15493. $cell_padding['T'] = $padding[0];
  15494. $cell_padding['R'] = $padding[0];
  15495. $cell_padding['B'] = $padding[0];
  15496. $cell_padding['L'] = $padding[0];
  15497. break;
  15498. }
  15499. default: {
  15500. return $this->cell_padding;
  15501. }
  15502. }
  15503. if ($width == 0) {
  15504. $width = $this->w - $this->lMargin - $this->rMargin;
  15505. }
  15506. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  15507. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  15508. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  15509. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  15510. return $cell_padding;
  15511. }
  15512. /**
  15513. * Get the internal Cell margin from CSS attribute.
  15514. * @param string $cssmargin margin properties
  15515. * @param float $width width of the containing element
  15516. * @return array of cell margins
  15517. * @public
  15518. * @since 5.9.000 (2010-10-04)
  15519. */
  15520. public function getCSSMargin($cssmargin, $width=0) {
  15521. $margin = preg_split('/[\s]+/', trim($cssmargin));
  15522. $cell_margin = array(); // value to be returned
  15523. switch (count($margin)) {
  15524. case 4: {
  15525. $cell_margin['T'] = $margin[0];
  15526. $cell_margin['R'] = $margin[1];
  15527. $cell_margin['B'] = $margin[2];
  15528. $cell_margin['L'] = $margin[3];
  15529. break;
  15530. }
  15531. case 3: {
  15532. $cell_margin['T'] = $margin[0];
  15533. $cell_margin['R'] = $margin[1];
  15534. $cell_margin['B'] = $margin[2];
  15535. $cell_margin['L'] = $margin[1];
  15536. break;
  15537. }
  15538. case 2: {
  15539. $cell_margin['T'] = $margin[0];
  15540. $cell_margin['R'] = $margin[1];
  15541. $cell_margin['B'] = $margin[0];
  15542. $cell_margin['L'] = $margin[1];
  15543. break;
  15544. }
  15545. case 1: {
  15546. $cell_margin['T'] = $margin[0];
  15547. $cell_margin['R'] = $margin[0];
  15548. $cell_margin['B'] = $margin[0];
  15549. $cell_margin['L'] = $margin[0];
  15550. break;
  15551. }
  15552. default: {
  15553. return $this->cell_margin;
  15554. }
  15555. }
  15556. if ($width == 0) {
  15557. $width = $this->w - $this->lMargin - $this->rMargin;
  15558. }
  15559. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  15560. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  15561. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  15562. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  15563. return $cell_margin;
  15564. }
  15565. /**
  15566. * Get the border-spacing from CSS attribute.
  15567. * @param string $cssbspace border-spacing CSS properties
  15568. * @param float $width width of the containing element
  15569. * @return array of border spacings
  15570. * @public
  15571. * @since 5.9.010 (2010-10-27)
  15572. */
  15573. public function getCSSBorderMargin($cssbspace, $width=0) {
  15574. $space = preg_split('/[\s]+/', trim($cssbspace));
  15575. $border_spacing = array(); // value to be returned
  15576. switch (count($space)) {
  15577. case 2: {
  15578. $border_spacing['H'] = $space[0];
  15579. $border_spacing['V'] = $space[1];
  15580. break;
  15581. }
  15582. case 1: {
  15583. $border_spacing['H'] = $space[0];
  15584. $border_spacing['V'] = $space[0];
  15585. break;
  15586. }
  15587. default: {
  15588. return array('H' => 0, 'V' => 0);
  15589. }
  15590. }
  15591. if ($width == 0) {
  15592. $width = $this->w - $this->lMargin - $this->rMargin;
  15593. }
  15594. $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
  15595. $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
  15596. return $border_spacing;
  15597. }
  15598. /**
  15599. * Returns the letter-spacing value from CSS value
  15600. * @param string $spacing letter-spacing value
  15601. * @param float $parent font spacing (tracking) value of the parent element
  15602. * @return float quantity to increases or decreases the space between characters in a text.
  15603. * @protected
  15604. * @since 5.9.000 (2010-10-02)
  15605. */
  15606. protected function getCSSFontSpacing($spacing, $parent=0) {
  15607. $val = 0; // value to be returned
  15608. $spacing = trim($spacing);
  15609. switch ($spacing) {
  15610. case 'normal': {
  15611. $val = 0;
  15612. break;
  15613. }
  15614. case 'inherit': {
  15615. if ($parent == 'normal') {
  15616. $val = 0;
  15617. } else {
  15618. $val = $parent;
  15619. }
  15620. break;
  15621. }
  15622. default: {
  15623. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  15624. }
  15625. }
  15626. return $val;
  15627. }
  15628. /**
  15629. * Returns the percentage of font stretching from CSS value
  15630. * @param string $stretch stretch mode
  15631. * @param float $parent stretch value of the parent element
  15632. * @return float font stretching percentage
  15633. * @protected
  15634. * @since 5.9.000 (2010-10-02)
  15635. */
  15636. protected function getCSSFontStretching($stretch, $parent=100) {
  15637. $val = 100; // value to be returned
  15638. $stretch = trim($stretch);
  15639. switch ($stretch) {
  15640. case 'ultra-condensed': {
  15641. $val = 40;
  15642. break;
  15643. }
  15644. case 'extra-condensed': {
  15645. $val = 55;
  15646. break;
  15647. }
  15648. case 'condensed': {
  15649. $val = 70;
  15650. break;
  15651. }
  15652. case 'semi-condensed': {
  15653. $val = 85;
  15654. break;
  15655. }
  15656. case 'normal': {
  15657. $val = 100;
  15658. break;
  15659. }
  15660. case 'semi-expanded': {
  15661. $val = 115;
  15662. break;
  15663. }
  15664. case 'expanded': {
  15665. $val = 130;
  15666. break;
  15667. }
  15668. case 'extra-expanded': {
  15669. $val = 145;
  15670. break;
  15671. }
  15672. case 'ultra-expanded': {
  15673. $val = 160;
  15674. break;
  15675. }
  15676. case 'wider': {
  15677. $val = ($parent + 10);
  15678. break;
  15679. }
  15680. case 'narrower': {
  15681. $val = ($parent - 10);
  15682. break;
  15683. }
  15684. case 'inherit': {
  15685. if ($parent == 'normal') {
  15686. $val = 100;
  15687. } else {
  15688. $val = $parent;
  15689. }
  15690. break;
  15691. }
  15692. default: {
  15693. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  15694. }
  15695. }
  15696. return $val;
  15697. }
  15698. /**
  15699. * Convert HTML string containing font size value to points
  15700. * @param string $val String containing font size value and unit.
  15701. * @param float $refsize Reference font size in points.
  15702. * @param float $parent_size Parent font size in points.
  15703. * @param string $defaultunit Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  15704. * @return float value in points
  15705. * @public
  15706. */
  15707. public function getHTMLFontUnits($val, $refsize=12, $parent_size=12, $defaultunit='pt') {
  15708. $refsize = TCPDF_FONTS::getFontRefSize($refsize);
  15709. $parent_size = TCPDF_FONTS::getFontRefSize($parent_size, $refsize);
  15710. switch ($val) {
  15711. case 'xx-small': {
  15712. $size = ($refsize - 4);
  15713. break;
  15714. }
  15715. case 'x-small': {
  15716. $size = ($refsize - 3);
  15717. break;
  15718. }
  15719. case 'small': {
  15720. $size = ($refsize - 2);
  15721. break;
  15722. }
  15723. case 'medium': {
  15724. $size = $refsize;
  15725. break;
  15726. }
  15727. case 'large': {
  15728. $size = ($refsize + 2);
  15729. break;
  15730. }
  15731. case 'x-large': {
  15732. $size = ($refsize + 4);
  15733. break;
  15734. }
  15735. case 'xx-large': {
  15736. $size = ($refsize + 6);
  15737. break;
  15738. }
  15739. case 'smaller': {
  15740. $size = ($parent_size - 3);
  15741. break;
  15742. }
  15743. case 'larger': {
  15744. $size = ($parent_size + 3);
  15745. break;
  15746. }
  15747. default: {
  15748. $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true);
  15749. }
  15750. }
  15751. return $size;
  15752. }
  15753. /**
  15754. * Returns the HTML DOM array.
  15755. * @param string $html html code
  15756. * @return array
  15757. * @protected
  15758. * @since 3.2.000 (2008-06-20)
  15759. */
  15760. protected function getHtmlDomArray($html) {
  15761. // array of CSS styles ( selector => properties).
  15762. $css = array();
  15763. // get CSS array defined at previous call
  15764. $matches = array();
  15765. if (preg_match_all('/<cssarray>([^\<]*?)<\/cssarray>/is', $html, $matches) > 0) {
  15766. if (isset($matches[1][0])) {
  15767. $css = array_merge($css, json_decode($this->unhtmlentities($matches[1][0]), true));
  15768. }
  15769. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/is', '', $html);
  15770. }
  15771. // extract external CSS files
  15772. $matches = array();
  15773. if (preg_match_all('/<link([^\>]*?)>/is', $html, $matches) > 0) {
  15774. foreach ($matches[1] as $key => $link) {
  15775. $type = array();
  15776. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
  15777. $type = array();
  15778. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  15779. // get 'all' and 'print' media, other media types are discarded
  15780. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15781. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15782. $type = array();
  15783. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
  15784. // read CSS data file
  15785. $cssdata = $this->getCachedFileContents(trim($type[1]));
  15786. if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) {
  15787. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15788. }
  15789. }
  15790. }
  15791. }
  15792. }
  15793. }
  15794. // extract style tags
  15795. $matches = array();
  15796. if (preg_match_all('/<style([^\>]*?)>([^\<]*?)<\/style>/is', $html, $matches) > 0) {
  15797. foreach ($matches[1] as $key => $media) {
  15798. $type = array();
  15799. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  15800. // get 'all' and 'print' media, other media types are discarded
  15801. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15802. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15803. $cssdata = $matches[2][$key];
  15804. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15805. }
  15806. }
  15807. }
  15808. // create a special tag to contain the CSS array (used for table content)
  15809. $csstagarray = '<cssarray>'.htmlentities(json_encode($css)).'</cssarray>';
  15810. // remove head and style blocks
  15811. $html = preg_replace('/<head([^\>]*?)>(.*?)<\/head>/is', '', $html);
  15812. $html = preg_replace('/<style([^\>]*?)>([^\<]*?)<\/style>/is', '', $html);
  15813. // define block tags
  15814. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  15815. // define self-closing tags
  15816. $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  15817. // remove all unsupported tags (the line below lists all supported tags)
  15818. $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>');
  15819. //replace some blank characters
  15820. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  15821. $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);
  15822. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  15823. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  15824. $html = strtr($html, $repTable);
  15825. $offset = 0;
  15826. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  15827. $html_a = substr($html, 0, $offset);
  15828. $html_b = substr($html, $offset, ($pos - $offset + 6));
  15829. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  15830. // preserve newlines on <pre> tag
  15831. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  15832. }
  15833. while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  15834. // preserve spaces on <pre> tag
  15835. $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  15836. }
  15837. $html = $html_a.$html_b.substr($html, $pos + 6);
  15838. $offset = strlen($html_a.$html_b);
  15839. }
  15840. $offset = 0;
  15841. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  15842. $html_a = substr($html, 0, $offset);
  15843. $html_b = substr($html, $offset, ($pos - $offset + 11));
  15844. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  15845. // preserve newlines on <textarea> tag
  15846. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  15847. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  15848. }
  15849. $html = $html_a.$html_b.substr($html, $pos + 11);
  15850. $offset = strlen($html_a.$html_b);
  15851. }
  15852. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  15853. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  15854. $offset = 0;
  15855. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  15856. $html_a = substr($html, 0, $offset);
  15857. $html_b = substr($html, $offset, ($pos - $offset + 9));
  15858. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  15859. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  15860. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  15861. }
  15862. $html = $html_a.$html_b.substr($html, $pos + 9);
  15863. $offset = strlen($html_a.$html_b);
  15864. }
  15865. if (preg_match("'</select'si", $html)) {
  15866. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  15867. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  15868. }
  15869. $html = str_replace("\n", ' ', $html);
  15870. // restore textarea newlines
  15871. $html = str_replace('<TBR>', "\n", $html);
  15872. // remove extra spaces from code
  15873. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  15874. $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
  15875. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  15876. $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
  15877. $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);
  15878. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  15879. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  15880. $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
  15881. $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
  15882. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  15883. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  15884. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  15885. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  15886. $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  15887. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  15888. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  15889. $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
  15890. $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
  15891. $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  15892. // trim string
  15893. $html = $this->stringTrim($html);
  15894. // fix br tag after li
  15895. $html = preg_replace('/<li><br([^\>]*)>/', '<li> <br\\1>', $html);
  15896. // fix first image tag alignment
  15897. $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
  15898. // pattern for generic tag
  15899. $tagpattern = '/(<[^>]+>)/';
  15900. // explodes the string
  15901. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  15902. // count elements
  15903. $maxel = count($a);
  15904. $elkey = 0;
  15905. $key = 0;
  15906. // create an array of elements
  15907. $dom = array();
  15908. $dom[$key] = array();
  15909. // set inheritable properties fot the first void element
  15910. // 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
  15911. $dom[$key]['tag'] = false;
  15912. $dom[$key]['block'] = false;
  15913. $dom[$key]['value'] = '';
  15914. $dom[$key]['parent'] = 0;
  15915. $dom[$key]['hide'] = false;
  15916. $dom[$key]['fontname'] = $this->FontFamily;
  15917. $dom[$key]['fontstyle'] = $this->FontStyle;
  15918. $dom[$key]['fontsize'] = $this->FontSizePt;
  15919. $dom[$key]['font-stretch'] = $this->font_stretching;
  15920. $dom[$key]['letter-spacing'] = $this->font_spacing;
  15921. $dom[$key]['stroke'] = $this->textstrokewidth;
  15922. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  15923. $dom[$key]['clip'] = ($this->textrendermode > 3);
  15924. $dom[$key]['line-height'] = $this->cell_height_ratio;
  15925. $dom[$key]['bgcolor'] = false;
  15926. $dom[$key]['fgcolor'] = $this->fgcolor; // color
  15927. $dom[$key]['strokecolor'] = $this->strokecolor;
  15928. $dom[$key]['align'] = '';
  15929. $dom[$key]['listtype'] = '';
  15930. $dom[$key]['text-indent'] = 0;
  15931. $dom[$key]['text-transform'] = '';
  15932. $dom[$key]['border'] = array();
  15933. $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
  15934. $thead = false; // true when we are inside the THEAD tag
  15935. ++$key;
  15936. $level = array();
  15937. array_push($level, 0); // root
  15938. while ($elkey < $maxel) {
  15939. $dom[$key] = array();
  15940. $element = $a[$elkey];
  15941. $dom[$key]['elkey'] = $elkey;
  15942. if (preg_match($tagpattern, $element)) {
  15943. // html tag
  15944. $element = substr($element, 1, -1);
  15945. // get tag name
  15946. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  15947. $tagname = strtolower($tag[1]);
  15948. // check if we are inside a table header
  15949. if ($tagname == 'thead') {
  15950. if ($element[0] == '/') {
  15951. $thead = false;
  15952. } else {
  15953. $thead = true;
  15954. }
  15955. ++$elkey;
  15956. continue;
  15957. }
  15958. $dom[$key]['tag'] = true;
  15959. $dom[$key]['value'] = $tagname;
  15960. if (in_array($dom[$key]['value'], $blocktags)) {
  15961. $dom[$key]['block'] = true;
  15962. } else {
  15963. $dom[$key]['block'] = false;
  15964. }
  15965. if ($element[0] == '/') {
  15966. // *** closing html tag
  15967. $dom[$key]['opening'] = false;
  15968. $dom[$key]['parent'] = end($level);
  15969. array_pop($level);
  15970. $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
  15971. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  15972. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  15973. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  15974. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  15975. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  15976. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  15977. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  15978. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  15979. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  15980. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  15981. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  15982. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  15983. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  15984. $dom[$key]['text-transform'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['text-transform'];
  15985. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  15986. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  15987. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  15988. }
  15989. // set the number of columns in table tag
  15990. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  15991. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  15992. }
  15993. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  15994. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  15995. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  15996. $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]);
  15997. }
  15998. $key = $i;
  15999. // mark nested tables
  16000. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  16001. // remove thead sections from nested tables
  16002. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  16003. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  16004. }
  16005. // store header rows on a new table
  16006. if (
  16007. ($dom[$key]['value'] === 'tr')
  16008. && !empty($dom[($dom[$key]['parent'])]['thead'])
  16009. && ($dom[($dom[$key]['parent'])]['thead'] === true)
  16010. ) {
  16011. if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  16012. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  16013. }
  16014. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  16015. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  16016. }
  16017. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  16018. $dom[($dom[$key]['parent'])]['attribute'] = array();
  16019. }
  16020. // header elements must be always contained in a single page
  16021. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  16022. }
  16023. if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  16024. // remove the nobr attributes from the table header
  16025. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  16026. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  16027. }
  16028. } else {
  16029. // *** opening or self-closing html tag
  16030. $dom[$key]['opening'] = true;
  16031. $dom[$key]['parent'] = end($level);
  16032. if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  16033. // self-closing tag
  16034. $dom[$key]['self'] = true;
  16035. } else {
  16036. // opening tag
  16037. array_push($level, $key);
  16038. $dom[$key]['self'] = false;
  16039. }
  16040. // copy some values from parent
  16041. $parentkey = 0;
  16042. if ($key > 0) {
  16043. $parentkey = $dom[$key]['parent'];
  16044. $dom[$key]['hide'] = $dom[$parentkey]['hide'];
  16045. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  16046. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  16047. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  16048. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  16049. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  16050. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  16051. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  16052. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  16053. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16054. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  16055. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  16056. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  16057. $dom[$key]['align'] = $dom[$parentkey]['align'];
  16058. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  16059. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  16060. $dom[$key]['text-transform'] = $dom[$parentkey]['text-transform'];
  16061. $dom[$key]['border'] = array();
  16062. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  16063. }
  16064. // get attributes
  16065. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  16066. $dom[$key]['attribute'] = array(); // reset attribute array
  16067. foreach($attr_array[1] as $id => $name) {
  16068. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  16069. }
  16070. if (!empty($css)) {
  16071. // merge CSS style to current style
  16072. list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom, $key, $css);
  16073. $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']);
  16074. }
  16075. // split style attributes
  16076. if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  16077. // get style attributes
  16078. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  16079. $dom[$key]['style'] = array(); // reset style attribute array
  16080. foreach($style_array[1] as $id => $name) {
  16081. // in case of duplicate attribute the last replace the previous
  16082. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  16083. }
  16084. // --- get some style attributes ---
  16085. // text direction
  16086. if (isset($dom[$key]['style']['direction'])) {
  16087. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  16088. }
  16089. // display
  16090. if (isset($dom[$key]['style']['display'])) {
  16091. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
  16092. }
  16093. // font family
  16094. if (isset($dom[$key]['style']['font-family'])) {
  16095. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  16096. }
  16097. // list-style-type
  16098. if (isset($dom[$key]['style']['list-style-type'])) {
  16099. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  16100. if ($dom[$key]['listtype'] == 'inherit') {
  16101. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  16102. }
  16103. }
  16104. // text-indent
  16105. if (isset($dom[$key]['style']['text-indent'])) {
  16106. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  16107. if ($dom[$key]['text-indent'] == 'inherit') {
  16108. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  16109. }
  16110. }
  16111. // text-transform
  16112. if (isset($dom[$key]['style']['text-transform'])) {
  16113. $dom[$key]['text-transform'] = $dom[$key]['style']['text-transform'];
  16114. }
  16115. // font size
  16116. if (isset($dom[$key]['style']['font-size'])) {
  16117. $fsize = trim($dom[$key]['style']['font-size']);
  16118. $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
  16119. }
  16120. // font-stretch
  16121. if (isset($dom[$key]['style']['font-stretch'])) {
  16122. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  16123. }
  16124. // letter-spacing
  16125. if (isset($dom[$key]['style']['letter-spacing'])) {
  16126. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  16127. }
  16128. // line-height (internally is the cell height ratio)
  16129. if (isset($dom[$key]['style']['line-height'])) {
  16130. $lineheight = trim($dom[$key]['style']['line-height']);
  16131. switch ($lineheight) {
  16132. // A normal line height. This is default
  16133. case 'normal': {
  16134. $dom[$key]['line-height'] = $dom[0]['line-height'];
  16135. break;
  16136. }
  16137. case 'inherit': {
  16138. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16139. }
  16140. default: {
  16141. if (is_numeric($lineheight)) {
  16142. // convert to percentage of font height
  16143. $lineheight = ($lineheight * 100).'%';
  16144. }
  16145. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  16146. if (substr($lineheight, -1) !== '%') {
  16147. if ($dom[$key]['fontsize'] <= 0) {
  16148. $dom[$key]['line-height'] = 1;
  16149. } else {
  16150. $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding['T'] - $this->cell_padding['B']) / $dom[$key]['fontsize']);
  16151. }
  16152. }
  16153. }
  16154. }
  16155. }
  16156. // font style
  16157. if (isset($dom[$key]['style']['font-weight'])) {
  16158. if (strtolower($dom[$key]['style']['font-weight'][0]) == 'n') {
  16159. if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
  16160. $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
  16161. }
  16162. } elseif (strtolower($dom[$key]['style']['font-weight'][0]) == 'b') {
  16163. $dom[$key]['fontstyle'] .= 'B';
  16164. }
  16165. }
  16166. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style'][0]) == 'i')) {
  16167. $dom[$key]['fontstyle'] .= 'I';
  16168. }
  16169. // font color
  16170. if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) {
  16171. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors);
  16172. } elseif ($dom[$key]['value'] == 'a') {
  16173. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16174. }
  16175. // background color
  16176. if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) {
  16177. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors);
  16178. }
  16179. // text-decoration
  16180. if (isset($dom[$key]['style']['text-decoration'])) {
  16181. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  16182. foreach ($decors as $dec) {
  16183. $dec = trim($dec);
  16184. if (!TCPDF_STATIC::empty_string($dec)) {
  16185. if ($dec[0] == 'u') {
  16186. // underline
  16187. $dom[$key]['fontstyle'] .= 'U';
  16188. } elseif ($dec[0] == 'l') {
  16189. // line-through
  16190. $dom[$key]['fontstyle'] .= 'D';
  16191. } elseif ($dec[0] == 'o') {
  16192. // overline
  16193. $dom[$key]['fontstyle'] .= 'O';
  16194. }
  16195. }
  16196. }
  16197. } elseif ($dom[$key]['value'] == 'a') {
  16198. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16199. }
  16200. // check for width attribute
  16201. if (isset($dom[$key]['style']['width'])) {
  16202. $dom[$key]['width'] = $dom[$key]['style']['width'];
  16203. }
  16204. // check for height attribute
  16205. if (isset($dom[$key]['style']['height'])) {
  16206. $dom[$key]['height'] = $dom[$key]['style']['height'];
  16207. }
  16208. // check for text alignment
  16209. if (isset($dom[$key]['style']['text-align'])) {
  16210. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align'][0]);
  16211. }
  16212. // check for CSS border properties
  16213. if (isset($dom[$key]['style']['border'])) {
  16214. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  16215. if (!empty($borderstyle)) {
  16216. $dom[$key]['border']['LTRB'] = $borderstyle;
  16217. }
  16218. }
  16219. if (isset($dom[$key]['style']['border-color'])) {
  16220. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  16221. if (isset($brd_colors[3])) {
  16222. $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors);
  16223. }
  16224. if (isset($brd_colors[1])) {
  16225. $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors);
  16226. }
  16227. if (isset($brd_colors[0])) {
  16228. $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors);
  16229. }
  16230. if (isset($brd_colors[2])) {
  16231. $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors);
  16232. }
  16233. }
  16234. if (isset($dom[$key]['style']['border-width'])) {
  16235. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  16236. if (isset($brd_widths[3])) {
  16237. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  16238. }
  16239. if (isset($brd_widths[1])) {
  16240. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  16241. }
  16242. if (isset($brd_widths[0])) {
  16243. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  16244. }
  16245. if (isset($brd_widths[2])) {
  16246. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  16247. }
  16248. }
  16249. if (isset($dom[$key]['style']['border-style'])) {
  16250. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  16251. if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
  16252. $dom[$key]['border']['L']['cap'] = 'square';
  16253. $dom[$key]['border']['L']['join'] = 'miter';
  16254. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  16255. if ($dom[$key]['border']['L']['dash'] < 0) {
  16256. $dom[$key]['border']['L'] = array();
  16257. }
  16258. }
  16259. if (isset($brd_styles[1])) {
  16260. $dom[$key]['border']['R']['cap'] = 'square';
  16261. $dom[$key]['border']['R']['join'] = 'miter';
  16262. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  16263. if ($dom[$key]['border']['R']['dash'] < 0) {
  16264. $dom[$key]['border']['R'] = array();
  16265. }
  16266. }
  16267. if (isset($brd_styles[0])) {
  16268. $dom[$key]['border']['T']['cap'] = 'square';
  16269. $dom[$key]['border']['T']['join'] = 'miter';
  16270. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  16271. if ($dom[$key]['border']['T']['dash'] < 0) {
  16272. $dom[$key]['border']['T'] = array();
  16273. }
  16274. }
  16275. if (isset($brd_styles[2])) {
  16276. $dom[$key]['border']['B']['cap'] = 'square';
  16277. $dom[$key]['border']['B']['join'] = 'miter';
  16278. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  16279. if ($dom[$key]['border']['B']['dash'] < 0) {
  16280. $dom[$key]['border']['B'] = array();
  16281. }
  16282. }
  16283. }
  16284. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  16285. foreach ($cellside as $bsk => $bsv) {
  16286. if (isset($dom[$key]['style']['border-'.$bsv])) {
  16287. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  16288. if (!empty($borderstyle)) {
  16289. $dom[$key]['border'][$bsk] = $borderstyle;
  16290. }
  16291. }
  16292. if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  16293. $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors);
  16294. }
  16295. if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  16296. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  16297. }
  16298. if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  16299. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  16300. if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  16301. $dom[$key]['border'][$bsk] = array();
  16302. }
  16303. }
  16304. }
  16305. // check for CSS padding properties
  16306. if (isset($dom[$key]['style']['padding'])) {
  16307. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  16308. } else {
  16309. $dom[$key]['padding'] = $this->cell_padding;
  16310. }
  16311. foreach ($cellside as $psk => $psv) {
  16312. if (isset($dom[$key]['style']['padding-'.$psv])) {
  16313. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
  16314. }
  16315. }
  16316. // check for CSS margin properties
  16317. if (isset($dom[$key]['style']['margin'])) {
  16318. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  16319. } else {
  16320. $dom[$key]['margin'] = $this->cell_margin;
  16321. }
  16322. foreach ($cellside as $psk => $psv) {
  16323. if (isset($dom[$key]['style']['margin-'.$psv])) {
  16324. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
  16325. }
  16326. }
  16327. // check for CSS border-spacing properties
  16328. if (isset($dom[$key]['style']['border-spacing'])) {
  16329. $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  16330. }
  16331. // page-break-inside
  16332. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  16333. $dom[$key]['attribute']['nobr'] = 'true';
  16334. }
  16335. // page-break-before
  16336. if (isset($dom[$key]['style']['page-break-before'])) {
  16337. if ($dom[$key]['style']['page-break-before'] == 'always') {
  16338. $dom[$key]['attribute']['pagebreak'] = 'true';
  16339. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  16340. $dom[$key]['attribute']['pagebreak'] = 'left';
  16341. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  16342. $dom[$key]['attribute']['pagebreak'] = 'right';
  16343. }
  16344. }
  16345. // page-break-after
  16346. if (isset($dom[$key]['style']['page-break-after'])) {
  16347. if ($dom[$key]['style']['page-break-after'] == 'always') {
  16348. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  16349. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  16350. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  16351. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  16352. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  16353. }
  16354. }
  16355. }
  16356. if (isset($dom[$key]['attribute']['display'])) {
  16357. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
  16358. }
  16359. if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  16360. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  16361. if (!empty($borderstyle)) {
  16362. $dom[$key]['border']['LTRB'] = $borderstyle;
  16363. }
  16364. }
  16365. // check for font tag
  16366. if ($dom[$key]['value'] == 'font') {
  16367. // font family
  16368. if (isset($dom[$key]['attribute']['face'])) {
  16369. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  16370. }
  16371. // font size
  16372. if (isset($dom[$key]['attribute']['size'])) {
  16373. if ($key > 0) {
  16374. if ($dom[$key]['attribute']['size'][0] == '+') {
  16375. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  16376. } elseif ($dom[$key]['attribute']['size'][0] == '-') {
  16377. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  16378. } else {
  16379. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16380. }
  16381. } else {
  16382. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16383. }
  16384. }
  16385. }
  16386. // force natural alignment for lists
  16387. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  16388. AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  16389. if ($this->rtl) {
  16390. $dom[$key]['align'] = 'R';
  16391. } else {
  16392. $dom[$key]['align'] = 'L';
  16393. }
  16394. }
  16395. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  16396. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16397. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  16398. }
  16399. }
  16400. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  16401. $dom[$key]['fontstyle'] .= 'B';
  16402. }
  16403. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  16404. $dom[$key]['fontstyle'] .= 'I';
  16405. }
  16406. if ($dom[$key]['value'] == 'u') {
  16407. $dom[$key]['fontstyle'] .= 'U';
  16408. }
  16409. if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  16410. $dom[$key]['fontstyle'] .= 'D';
  16411. }
  16412. if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  16413. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16414. }
  16415. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  16416. $dom[$key]['fontname'] = $this->default_monospaced_font;
  16417. }
  16418. 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)) {
  16419. // headings h1, h2, h3, h4, h5, h6
  16420. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16421. $headsize = (4 - intval($dom[$key]['value'][1])) * 2;
  16422. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  16423. }
  16424. if (!isset($dom[$key]['style']['font-weight'])) {
  16425. $dom[$key]['fontstyle'] .= 'B';
  16426. }
  16427. }
  16428. if (($dom[$key]['value'] == 'table')) {
  16429. $dom[$key]['rows'] = 0; // number of rows
  16430. $dom[$key]['trids'] = array(); // IDs of TR elements
  16431. $dom[$key]['thead'] = ''; // table header rows
  16432. }
  16433. if (($dom[$key]['value'] == 'tr')) {
  16434. $dom[$key]['cols'] = 0;
  16435. if ($thead) {
  16436. $dom[$key]['thead'] = true;
  16437. // rows on thead block are printed as a separate table
  16438. } else {
  16439. $dom[$key]['thead'] = false;
  16440. $parent = $dom[$key]['parent'];
  16441. if (!isset($dom[$parent]['rows'])) {
  16442. $dom[$parent]['rows'] = 0;
  16443. }
  16444. // store the number of rows on table element
  16445. ++$dom[$parent]['rows'];
  16446. if (!isset($dom[$parent]['trids'])) {
  16447. $dom[$parent]['trids'] = array();
  16448. }
  16449. // store the TR elements IDs on table element
  16450. array_push($dom[$parent]['trids'], $key);
  16451. }
  16452. }
  16453. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  16454. if (isset($dom[$key]['attribute']['colspan'])) {
  16455. $colspan = intval($dom[$key]['attribute']['colspan']);
  16456. } else {
  16457. $colspan = 1;
  16458. }
  16459. $dom[$key]['attribute']['colspan'] = $colspan;
  16460. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  16461. }
  16462. // text direction
  16463. if (isset($dom[$key]['attribute']['dir'])) {
  16464. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  16465. }
  16466. // set foreground color attribute
  16467. if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) {
  16468. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors);
  16469. } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  16470. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16471. }
  16472. // set background color attribute
  16473. if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) {
  16474. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors);
  16475. }
  16476. // set stroke color attribute
  16477. if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) {
  16478. $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors);
  16479. }
  16480. // check for width attribute
  16481. if (isset($dom[$key]['attribute']['width'])) {
  16482. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  16483. }
  16484. // check for height attribute
  16485. if (isset($dom[$key]['attribute']['height'])) {
  16486. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  16487. }
  16488. // check for text alignment
  16489. if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  16490. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align'][0]);
  16491. }
  16492. // check for text rendering mode (the following attributes do not exist in HTML)
  16493. if (isset($dom[$key]['attribute']['stroke'])) {
  16494. // font stroke width
  16495. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  16496. }
  16497. if (isset($dom[$key]['attribute']['fill'])) {
  16498. // font fill
  16499. if ($dom[$key]['attribute']['fill'] == 'true') {
  16500. $dom[$key]['fill'] = true;
  16501. } else {
  16502. $dom[$key]['fill'] = false;
  16503. }
  16504. }
  16505. if (isset($dom[$key]['attribute']['clip'])) {
  16506. // clipping mode
  16507. if ($dom[$key]['attribute']['clip'] == 'true') {
  16508. $dom[$key]['clip'] = true;
  16509. } else {
  16510. $dom[$key]['clip'] = false;
  16511. }
  16512. }
  16513. } // end opening tag
  16514. } else {
  16515. // text
  16516. $dom[$key]['tag'] = false;
  16517. $dom[$key]['block'] = false;
  16518. $dom[$key]['parent'] = end($level);
  16519. $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  16520. if (!empty($dom[$dom[$key]['parent']]['text-transform'])) {
  16521. // text-transform for unicode requires mb_convert_case (Multibyte String Functions)
  16522. if (function_exists('mb_convert_case')) {
  16523. $ttm = array('capitalize' => MB_CASE_TITLE, 'uppercase' => MB_CASE_UPPER, 'lowercase' => MB_CASE_LOWER);
  16524. if (isset($ttm[$dom[$dom[$key]['parent']]['text-transform']])) {
  16525. $element = mb_convert_case($element, $ttm[$dom[$dom[$key]['parent']]['text-transform']], $this->encoding);
  16526. }
  16527. } elseif (!$this->isunicode) {
  16528. switch ($dom[$dom[$key]['parent']]['text-transform']) {
  16529. case 'capitalize': {
  16530. $element = ucwords(strtolower($element));
  16531. break;
  16532. }
  16533. case 'uppercase': {
  16534. $element = strtoupper($element);
  16535. break;
  16536. }
  16537. case 'lowercase': {
  16538. $element = strtolower($element);
  16539. break;
  16540. }
  16541. }
  16542. }
  16543. $element = preg_replace("/&NBSP;/i", "&nbsp;", $element);
  16544. }
  16545. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  16546. }
  16547. ++$elkey;
  16548. ++$key;
  16549. }
  16550. return $dom;
  16551. }
  16552. /**
  16553. * Returns the string used to find spaces
  16554. * @return string
  16555. * @protected
  16556. * @author Nicola Asuni
  16557. * @since 4.8.024 (2010-01-15)
  16558. */
  16559. protected function getSpaceString() {
  16560. $spacestr = chr(32);
  16561. if ($this->isUnicodeFont()) {
  16562. $spacestr = chr(0).chr(32);
  16563. }
  16564. return $spacestr;
  16565. }
  16566. /**
  16567. * Return an hash code used to ensure that the serialized data has been generated by this TCPDF instance.
  16568. * @param string $data serialized data
  16569. * @return string
  16570. * @public static
  16571. */
  16572. protected function getHashForTCPDFtagParams($data) {
  16573. return md5(strlen($data).$this->file_id.$data);
  16574. }
  16575. /**
  16576. * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  16577. * @param array $data parameters array
  16578. * @return string containing serialized data
  16579. * @public static
  16580. */
  16581. public function serializeTCPDFtagParameters($data) {
  16582. $encoded = urlencode(json_encode($data));
  16583. return $this->getHashForTCPDFtagParams($encoded).$encoded;
  16584. }
  16585. /**
  16586. * Unserialize parameters to be used with TCPDF tag in HTML code.
  16587. * @param string $data serialized data
  16588. * @return array containing unserialized data
  16589. * @protected static
  16590. */
  16591. protected function unserializeTCPDFtagParameters($data) {
  16592. $hash = substr($data, 0, 32);
  16593. $encoded = substr($data, 32);
  16594. if ($hash != $this->getHashForTCPDFtagParams($encoded)) {
  16595. $this->Error('Invalid parameters');
  16596. }
  16597. return json_decode(urldecode($encoded), true);
  16598. }
  16599. /**
  16600. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  16601. * 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 />
  16602. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  16603. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16604. * 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
  16605. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16606. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  16607. * @param float $h Cell minimum height. The cell extends automatically if needed.
  16608. * @param float|null $x upper-left corner X coordinate
  16609. * @param float|null $y upper-left corner Y coordinate
  16610. * @param string $html html text to print. Default value: empty string.
  16611. * @param mixed $border 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)))
  16612. * @param int $ln 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>
  16613. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  16614. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  16615. * @param boolean $reseth if true reset the last cell height (default true).
  16616. * @param string $align 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>
  16617. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  16618. * @see Multicell(), writeHTML()
  16619. * @public
  16620. */
  16621. public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
  16622. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
  16623. }
  16624. /**
  16625. * Allows to preserve some HTML formatting (limited support).<br />
  16626. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16627. * 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
  16628. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16629. * @param string $html text to display
  16630. * @param boolean $ln if true add a new line after text (default = true)
  16631. * @param boolean $fill Indicates if the background must be painted (true) or transparent (false).
  16632. * @param boolean $reseth if true reset the last cell height (default false).
  16633. * @param boolean $cell if true add the current left (or right for RTL) padding to each Write (default false).
  16634. * @param string $align 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>
  16635. * @public
  16636. */
  16637. public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
  16638. $gvars = $this->getGraphicVars();
  16639. // store current values
  16640. $prev_cell_margin = $this->cell_margin;
  16641. $prev_cell_padding = $this->cell_padding;
  16642. $prevPage = $this->page;
  16643. $prevlMargin = $this->lMargin;
  16644. $prevrMargin = $this->rMargin;
  16645. $curfontname = $this->FontFamily;
  16646. $curfontstyle = $this->FontStyle;
  16647. $curfontsize = $this->FontSizePt;
  16648. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  16649. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  16650. $curfontstretcing = $this->font_stretching;
  16651. $curfonttracking = $this->font_spacing;
  16652. $this->newline = true;
  16653. $newline = true;
  16654. $startlinepage = $this->page;
  16655. $minstartliney = $this->y;
  16656. $maxbottomliney = 0;
  16657. $startlinex = $this->x;
  16658. $startliney = $this->y;
  16659. $yshift = 0;
  16660. $loop = 0;
  16661. $curpos = 0;
  16662. $this_method_vars = array();
  16663. $undo = false;
  16664. $fontaligned = false;
  16665. $reverse_dir = false; // true when the text direction is reversed
  16666. $this->premode = false;
  16667. if ($this->inxobj) {
  16668. // we are inside an XObject template
  16669. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  16670. } elseif (isset($this->PageAnnots[$this->page])) {
  16671. $pask = count($this->PageAnnots[$this->page]);
  16672. } else {
  16673. $pask = 0;
  16674. }
  16675. if ($this->inxobj) {
  16676. // we are inside an XObject template
  16677. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  16678. } elseif (!$this->InFooter) {
  16679. if (isset($this->footerlen[$this->page])) {
  16680. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  16681. } else {
  16682. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  16683. }
  16684. $startlinepos = $this->footerpos[$this->page];
  16685. } else {
  16686. // we are inside the footer
  16687. $startlinepos = $this->pagelen[$this->page];
  16688. }
  16689. $lalign = $align;
  16690. $plalign = $align;
  16691. if ($this->rtl) {
  16692. $w = $this->x - $this->lMargin;
  16693. } else {
  16694. $w = $this->w - $this->rMargin - $this->x;
  16695. }
  16696. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  16697. if ($cell) {
  16698. if ($this->rtl) {
  16699. $this->x -= $this->cell_padding['R'];
  16700. $this->lMargin += $this->cell_padding['L'];
  16701. } else {
  16702. $this->x += $this->cell_padding['L'];
  16703. $this->rMargin += $this->cell_padding['R'];
  16704. }
  16705. }
  16706. if ($this->customlistindent >= 0) {
  16707. $this->listindent = $this->customlistindent;
  16708. } else {
  16709. $this->listindent = $this->GetStringWidth('000000');
  16710. }
  16711. $this->listindentlevel = 0;
  16712. // save previous states
  16713. $prev_cell_height_ratio = $this->cell_height_ratio;
  16714. $prev_listnum = $this->listnum;
  16715. $prev_listordered = $this->listordered;
  16716. $prev_listcount = $this->listcount;
  16717. $prev_lispacer = $this->lispacer;
  16718. $this->listnum = 0;
  16719. $this->listordered = array();
  16720. $this->listcount = array();
  16721. $this->lispacer = '';
  16722. if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) {
  16723. // reset row height
  16724. $this->resetLastH();
  16725. }
  16726. $dom = $this->getHtmlDomArray($html);
  16727. $maxel = count($dom);
  16728. $key = 0;
  16729. while ($key < $maxel) {
  16730. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
  16731. // store the node key
  16732. $hidden_node_key = $key;
  16733. if ($dom[$key]['self']) {
  16734. // skip just this self-closing tag
  16735. ++$key;
  16736. } else {
  16737. // skip this and all children tags
  16738. while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
  16739. // skip hidden objects
  16740. ++$key;
  16741. }
  16742. ++$key;
  16743. }
  16744. }
  16745. if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  16746. // check for pagebreak
  16747. if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  16748. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16749. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16750. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16751. }
  16752. if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  16753. OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  16754. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16755. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16756. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16757. }
  16758. }
  16759. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  16760. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  16761. $dom[$key]['attribute']['nobr'] = false;
  16762. } else {
  16763. // store current object
  16764. $this->startTransaction();
  16765. // save this method vars
  16766. $this_method_vars['html'] = $html;
  16767. $this_method_vars['ln'] = $ln;
  16768. $this_method_vars['fill'] = $fill;
  16769. $this_method_vars['reseth'] = $reseth;
  16770. $this_method_vars['cell'] = $cell;
  16771. $this_method_vars['align'] = $align;
  16772. $this_method_vars['gvars'] = $gvars;
  16773. $this_method_vars['prevPage'] = $prevPage;
  16774. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  16775. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  16776. $this_method_vars['prevlMargin'] = $prevlMargin;
  16777. $this_method_vars['prevrMargin'] = $prevrMargin;
  16778. $this_method_vars['curfontname'] = $curfontname;
  16779. $this_method_vars['curfontstyle'] = $curfontstyle;
  16780. $this_method_vars['curfontsize'] = $curfontsize;
  16781. $this_method_vars['curfontascent'] = $curfontascent;
  16782. $this_method_vars['curfontdescent'] = $curfontdescent;
  16783. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  16784. $this_method_vars['curfonttracking'] = $curfonttracking;
  16785. $this_method_vars['minstartliney'] = $minstartliney;
  16786. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  16787. $this_method_vars['yshift'] = $yshift;
  16788. $this_method_vars['startlinepage'] = $startlinepage;
  16789. $this_method_vars['startlinepos'] = $startlinepos;
  16790. $this_method_vars['startlinex'] = $startlinex;
  16791. $this_method_vars['startliney'] = $startliney;
  16792. $this_method_vars['newline'] = $newline;
  16793. $this_method_vars['loop'] = $loop;
  16794. $this_method_vars['curpos'] = $curpos;
  16795. $this_method_vars['pask'] = $pask;
  16796. $this_method_vars['lalign'] = $lalign;
  16797. $this_method_vars['plalign'] = $plalign;
  16798. $this_method_vars['w'] = $w;
  16799. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  16800. $this_method_vars['prev_listnum'] = $prev_listnum;
  16801. $this_method_vars['prev_listordered'] = $prev_listordered;
  16802. $this_method_vars['prev_listcount'] = $prev_listcount;
  16803. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  16804. $this_method_vars['fontaligned'] = $fontaligned;
  16805. $this_method_vars['key'] = $key;
  16806. $this_method_vars['dom'] = $dom;
  16807. }
  16808. }
  16809. // print THEAD block
  16810. if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  16811. if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) {
  16812. $this->inthead = true;
  16813. // print table header (thead)
  16814. $this->writeHTML($this->thead, false, false, false, false, '');
  16815. // check if we are on a new page or on a new column
  16816. if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
  16817. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  16818. // restore previous object
  16819. $this->rollbackTransaction(true);
  16820. // restore previous values
  16821. foreach ($this_method_vars as $vkey => $vval) {
  16822. $$vkey = $vval;
  16823. }
  16824. // disable table header
  16825. $tmp_thead = $this->thead;
  16826. $this->thead = '';
  16827. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16828. $pre_y = $this->y;
  16829. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  16830. // fix for multicolumn mode
  16831. $startliney = $this->y;
  16832. }
  16833. $this->start_transaction_page = $this->page;
  16834. $this->start_transaction_y = $this->y;
  16835. // restore table header
  16836. $this->thead = $tmp_thead;
  16837. // fix table border properties
  16838. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  16839. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  16840. } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  16841. $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
  16842. } else {
  16843. $tmp_cellspacing = 0;
  16844. }
  16845. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  16846. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  16847. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  16848. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  16849. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  16850. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  16851. // print table header (thead)
  16852. $this->writeHTML($this->thead, false, false, false, false, '');
  16853. }
  16854. }
  16855. // move $key index forward to skip THEAD block
  16856. while ( ($key < $maxel) AND (!(
  16857. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  16858. OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  16859. ++$key;
  16860. }
  16861. }
  16862. if ($dom[$key]['tag'] OR ($key == 0)) {
  16863. if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  16864. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  16865. }
  16866. // vertically align image in line
  16867. if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  16868. // get image height
  16869. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], ($dom[$key]['fontsize'] / $this->k), 'px');
  16870. $autolinebreak = false;
  16871. if (!empty($dom[$key]['width'])) {
  16872. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], ($dom[$key]['fontsize'] / $this->k), 'px', false);
  16873. if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
  16874. AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
  16875. OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
  16876. // add automatic line break
  16877. $autolinebreak = true;
  16878. $this->Ln('', $cell);
  16879. if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  16880. // go back to evaluate this line break
  16881. --$key;
  16882. }
  16883. }
  16884. }
  16885. if (!$autolinebreak) {
  16886. if ($this->inPageBody()) {
  16887. $pre_y = $this->y;
  16888. // check for page break
  16889. if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
  16890. // fix for multicolumn mode
  16891. $startliney = $this->y;
  16892. }
  16893. }
  16894. if ($this->page > $startlinepage) {
  16895. // fix line splitted over two pages
  16896. if (isset($this->footerlen[$startlinepage])) {
  16897. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16898. }
  16899. // line to be moved one page forward
  16900. $pagebuff = $this->getPageBuffer($startlinepage);
  16901. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16902. $tstart = substr($pagebuff, 0, $startlinepos);
  16903. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16904. // remove line from previous page
  16905. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16906. $pagebuff = $this->getPageBuffer($this->page);
  16907. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16908. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16909. // add line start to current page
  16910. $yshift = ($minstartliney - $this->y);
  16911. if ($fontaligned) {
  16912. $yshift += ($curfontsize / $this->k);
  16913. }
  16914. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16915. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16916. // shift the annotations and links
  16917. if (isset($this->PageAnnots[$this->page])) {
  16918. $next_pask = count($this->PageAnnots[$this->page]);
  16919. } else {
  16920. $next_pask = 0;
  16921. }
  16922. if (isset($this->PageAnnots[$startlinepage])) {
  16923. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16924. if ($pak >= $pask) {
  16925. $this->PageAnnots[$this->page][] = $pac;
  16926. unset($this->PageAnnots[$startlinepage][$pak]);
  16927. $npak = count($this->PageAnnots[$this->page]) - 1;
  16928. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16929. }
  16930. }
  16931. }
  16932. $pask = $next_pask;
  16933. $startlinepos = $this->cntmrk[$this->page];
  16934. $startlinepage = $this->page;
  16935. $startliney = $this->y;
  16936. $this->newline = false;
  16937. }
  16938. $this->y += ($this->getCellHeight($curfontsize / $this->k) - ($curfontdescent * $this->cell_height_ratio) - $imgh);
  16939. $minstartliney = min($this->y, $minstartliney);
  16940. $maxbottomliney = ($startliney + $this->getCellHeight($curfontsize / $this->k));
  16941. }
  16942. } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  16943. // account for different font size
  16944. $pfontname = $curfontname;
  16945. $pfontstyle = $curfontstyle;
  16946. $pfontsize = $curfontsize;
  16947. $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname);
  16948. $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle);
  16949. $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize);
  16950. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  16951. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  16952. if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  16953. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16954. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  16955. if (($key < ($maxel - 1)) AND (
  16956. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
  16957. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16958. OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize)
  16959. AND ($fontsize >= 0) AND ($curfontsize >= 0)
  16960. AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname)))
  16961. )) {
  16962. if ($this->page > $startlinepage) {
  16963. // fix lines splitted over two pages
  16964. if (isset($this->footerlen[$startlinepage])) {
  16965. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16966. }
  16967. // line to be moved one page forward
  16968. $pagebuff = $this->getPageBuffer($startlinepage);
  16969. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16970. $tstart = substr($pagebuff, 0, $startlinepos);
  16971. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16972. // remove line start from previous page
  16973. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16974. $pagebuff = $this->getPageBuffer($this->page);
  16975. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16976. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16977. // add line start to current page
  16978. $yshift = ($minstartliney - $this->y);
  16979. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16980. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16981. // shift the annotations and links
  16982. if (isset($this->PageAnnots[$this->page])) {
  16983. $next_pask = count($this->PageAnnots[$this->page]);
  16984. } else {
  16985. $next_pask = 0;
  16986. }
  16987. if (isset($this->PageAnnots[$startlinepage])) {
  16988. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16989. if ($pak >= $pask) {
  16990. $this->PageAnnots[$this->page][] = $pac;
  16991. unset($this->PageAnnots[$startlinepage][$pak]);
  16992. $npak = count($this->PageAnnots[$this->page]) - 1;
  16993. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16994. }
  16995. }
  16996. }
  16997. $pask = $next_pask;
  16998. $startlinepos = $this->cntmrk[$this->page];
  16999. $startlinepage = $this->page;
  17000. $startliney = $this->y;
  17001. }
  17002. if (!isset($dom[$key]['line-height'])) {
  17003. $dom[$key]['line-height'] = $this->cell_height_ratio;
  17004. }
  17005. if (!$dom[$key]['block']) {
  17006. 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']))) {
  17007. $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  17008. }
  17009. if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  17010. $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
  17011. 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)))) {
  17012. $minstartliney = min($this->y, $line_align_data[1]);
  17013. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $line_align_data[2]);
  17014. } else {
  17015. $minstartliney = min($this->y, $minstartliney);
  17016. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $maxbottomliney);
  17017. }
  17018. $line_align_data = $current_line_align_data;
  17019. }
  17020. }
  17021. $this->cell_height_ratio = $dom[$key]['line-height'];
  17022. $fontaligned = true;
  17023. }
  17024. $this->setFont($fontname, $fontstyle, $fontsize);
  17025. // reset row height
  17026. $this->resetLastH();
  17027. $curfontname = $fontname;
  17028. $curfontstyle = $fontstyle;
  17029. $curfontsize = $fontsize;
  17030. $curfontascent = $fontascent;
  17031. $curfontdescent = $fontdescent;
  17032. }
  17033. }
  17034. // set text rendering mode
  17035. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  17036. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  17037. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  17038. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  17039. if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  17040. $this->setFontStretching($dom[$key]['font-stretch']);
  17041. }
  17042. if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  17043. $this->setFontSpacing($dom[$key]['letter-spacing']);
  17044. }
  17045. if (($plalign == 'J') AND $dom[$key]['block']) {
  17046. $plalign = '';
  17047. }
  17048. // get current position on page buffer
  17049. $curpos = $this->pagelen[$startlinepage];
  17050. if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  17051. $this->setFillColorArray($dom[$key]['bgcolor']);
  17052. $wfill = true;
  17053. } else {
  17054. $wfill = $fill | false;
  17055. }
  17056. if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  17057. $this->setTextColorArray($dom[$key]['fgcolor']);
  17058. }
  17059. if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  17060. $this->setDrawColorArray($dom[$key]['strokecolor']);
  17061. }
  17062. if (isset($dom[$key]['align'])) {
  17063. $lalign = $dom[$key]['align'];
  17064. }
  17065. if (TCPDF_STATIC::empty_string($lalign)) {
  17066. $lalign = $align;
  17067. }
  17068. }
  17069. // align lines
  17070. if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  17071. $newline = true;
  17072. $fontaligned = false;
  17073. // we are at the beginning of a new line
  17074. if (isset($startlinex)) {
  17075. $yshift = ($minstartliney - $startliney);
  17076. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  17077. $yshift = 0;
  17078. }
  17079. $t_x = 0;
  17080. // the last line must be shifted to be aligned as requested
  17081. $linew = abs($this->endlinex - $startlinex);
  17082. if ($this->inxobj) {
  17083. // we are inside an XObject template
  17084. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  17085. if (isset($opentagpos)) {
  17086. $midpos = $opentagpos;
  17087. } else {
  17088. $midpos = 0;
  17089. }
  17090. if ($midpos > 0) {
  17091. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  17092. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  17093. } else {
  17094. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  17095. $pend = '';
  17096. }
  17097. } else {
  17098. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  17099. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17100. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17101. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  17102. } elseif (isset($opentagpos)) {
  17103. $midpos = $opentagpos;
  17104. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17105. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17106. $midpos = $this->footerpos[$startlinepage];
  17107. } else {
  17108. $midpos = 0;
  17109. }
  17110. if ($midpos > 0) {
  17111. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  17112. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  17113. } else {
  17114. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  17115. $pend = '';
  17116. }
  17117. }
  17118. if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  17119. // calculate shifting amount
  17120. $tw = $w;
  17121. if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
  17122. $tw += $this->cell_padding['R'];
  17123. }
  17124. if ($this->lMargin != $prevlMargin) {
  17125. $tw += ($prevlMargin - $this->lMargin);
  17126. }
  17127. if ($this->rMargin != $prevrMargin) {
  17128. $tw += ($prevrMargin - $this->rMargin);
  17129. }
  17130. $one_space_width = $this->GetStringWidth(chr(32));
  17131. $no = 0; // number of spaces on a line contained on a single block
  17132. if ($this->isRTLTextDir()) { // RTL
  17133. // remove left space if exist
  17134. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  17135. if ($pos1 > 0) {
  17136. $pos1 = intval($pos1);
  17137. if ($this->isUnicodeFont()) {
  17138. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  17139. $spacelen = 2;
  17140. } else {
  17141. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  17142. $spacelen = 1;
  17143. }
  17144. if ($pos1 == $pos2) {
  17145. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  17146. if (substr($pmid, $pos1, 4) == '[()]') {
  17147. $linew -= $one_space_width;
  17148. } elseif ($pos1 == strpos($pmid, '[(')) {
  17149. $no = 1;
  17150. }
  17151. }
  17152. }
  17153. } else { // LTR
  17154. // remove right space if exist
  17155. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  17156. if ($pos1 > 0) {
  17157. $pos1 = intval($pos1);
  17158. if ($this->isUnicodeFont()) {
  17159. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  17160. $spacelen = 2;
  17161. } else {
  17162. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  17163. $spacelen = 1;
  17164. }
  17165. if ($pos1 == $pos2) {
  17166. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  17167. $linew -= $one_space_width;
  17168. }
  17169. }
  17170. }
  17171. $mdiff = ($tw - $linew);
  17172. if ($plalign == 'C') {
  17173. if ($this->rtl) {
  17174. $t_x = -($mdiff / 2);
  17175. } else {
  17176. $t_x = ($mdiff / 2);
  17177. }
  17178. } elseif ($plalign == 'R') {
  17179. // right alignment on LTR document
  17180. $t_x = $mdiff;
  17181. } elseif ($plalign == 'L') {
  17182. // left alignment on RTL document
  17183. $t_x = -$mdiff;
  17184. } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  17185. // Justification
  17186. if ($this->isRTLTextDir()) {
  17187. // align text on the left
  17188. $t_x = -$mdiff;
  17189. }
  17190. $ns = 0; // number of spaces
  17191. $pmidtemp = $pmid;
  17192. // escape special characters
  17193. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  17194. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  17195. // search spaces
  17196. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
  17197. $spacestr = $this->getSpaceString();
  17198. $maxkk = count($lnstring[1]) - 1;
  17199. for ($kk=0; $kk <= $maxkk; ++$kk) {
  17200. // restore special characters
  17201. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  17202. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  17203. // store number of spaces on the strings
  17204. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  17205. // count total spaces on line
  17206. $ns += $lnstring[2][$kk];
  17207. $lnstring[3][$kk] = $ns;
  17208. }
  17209. if ($ns == 0) {
  17210. $ns = 1;
  17211. }
  17212. // calculate additional space to add to each existing space
  17213. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  17214. if ($this->FontSize <= 0) {
  17215. $this->FontSize = 1;
  17216. }
  17217. $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  17218. if ($this->font_spacing != 0) {
  17219. // fixed spacing mode
  17220. $osw = -1000 * $this->font_spacing / $this->FontSize;
  17221. $spacewidthu += $osw;
  17222. }
  17223. $nsmax = $ns;
  17224. $ns = 0;
  17225. reset($lnstring);
  17226. $offset = 0;
  17227. $strcount = 0;
  17228. $prev_epsposbeg = 0;
  17229. $textpos = 0;
  17230. if ($this->isRTLTextDir()) {
  17231. $textpos = $this->wPt;
  17232. }
  17233. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
  17234. // check if we are inside a string section '[( ... )]'
  17235. $stroffset = strpos($pmid, '[(', $offset);
  17236. if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  17237. // set offset to the end of string section
  17238. $offset = strpos($pmid, ')]', $stroffset);
  17239. while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
  17240. $offset = strpos($pmid, ')]', ($offset + 1));
  17241. }
  17242. if ($offset === false) {
  17243. $this->Error('HTML Justification: malformed PDF code.');
  17244. }
  17245. continue;
  17246. }
  17247. if ($this->isRTLTextDir()) {
  17248. $spacew = ($spacewidth * ($nsmax - $ns));
  17249. } else {
  17250. $spacew = ($spacewidth * $ns);
  17251. }
  17252. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  17253. $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset);
  17254. if ($epsposend !== null) {
  17255. $epsposend += strlen($this->epsmarker.'Q');
  17256. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
  17257. if ($epsposbeg === null) {
  17258. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
  17259. $prev_epsposbeg = $epsposbeg;
  17260. }
  17261. if (($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) {
  17262. // shift EPS images
  17263. $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
  17264. $pmid_b = substr($pmid, 0, $epsposbeg);
  17265. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  17266. $pmid_e = substr($pmid, $epsposend);
  17267. $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  17268. $offset = $epsposend;
  17269. continue;
  17270. }
  17271. }
  17272. $currentxpos = 0;
  17273. // shift blocks of code
  17274. switch ($strpiece[2][0]) {
  17275. case 'Td':
  17276. case 'cm':
  17277. case 'm':
  17278. case 'l': {
  17279. // get current X position
  17280. preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
  17281. if (!isset($xmatches[1])) {
  17282. break;
  17283. }
  17284. $currentxpos = $xmatches[1];
  17285. $textpos = $currentxpos;
  17286. if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  17287. $ns = $lnstring[3][$strcount];
  17288. if ($this->isRTLTextDir()) {
  17289. $spacew = ($spacewidth * ($nsmax - $ns));
  17290. }
  17291. ++$strcount;
  17292. }
  17293. // justify block
  17294. if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $pmatch) == 1) {
  17295. $newpmid = sprintf('%F',(floatval($pmatch[1]) + $spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4];
  17296. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17297. unset($pmatch, $newpmid);
  17298. }
  17299. break;
  17300. }
  17301. case 're': {
  17302. // justify block
  17303. if (!TCPDF_STATIC::empty_string($this->lispacer)) {
  17304. $this->lispacer = '';
  17305. break;
  17306. }
  17307. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
  17308. if (!isset($xmatches[1])) {
  17309. break;
  17310. }
  17311. $currentxpos = $xmatches[1];
  17312. $x_diff = 0;
  17313. $w_diff = 0;
  17314. if ($this->isRTLTextDir()) { // RTL
  17315. if ($currentxpos < $textpos) {
  17316. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  17317. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17318. } else {
  17319. if ($strcount > 0) {
  17320. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  17321. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17322. }
  17323. }
  17324. } else { // LTR
  17325. if ($currentxpos > $textpos) {
  17326. if ($strcount > 0) {
  17327. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  17328. }
  17329. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17330. } else {
  17331. if ($strcount > 1) {
  17332. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  17333. }
  17334. if ($strcount > 0) {
  17335. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17336. }
  17337. }
  17338. }
  17339. if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $pmatch) == 1) {
  17340. $newx = sprintf('%F',(floatval($pmatch[1]) + $x_diff));
  17341. $neww = sprintf('%F',(floatval($pmatch[3]) + $w_diff));
  17342. $newpmid = $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6];
  17343. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17344. unset($pmatch, $newpmid, $newx, $neww);
  17345. }
  17346. break;
  17347. }
  17348. case 'c': {
  17349. // get current X position
  17350. 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);
  17351. if (!isset($xmatches[1])) {
  17352. break;
  17353. }
  17354. $currentxpos = $xmatches[1];
  17355. // justify block
  17356. 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) {
  17357. $newx1 = sprintf('%F',(floatval($pmatch[1]) + $spacew));
  17358. $newx2 = sprintf('%F',(floatval($pmatch[3]) + $spacew));
  17359. $newx3 = sprintf('%F',(floatval($pmatch[5]) + $spacew));
  17360. $newpmid = $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8];
  17361. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17362. unset($pmatch, $newpmid, $newx1, $newx2, $newx3);
  17363. }
  17364. break;
  17365. }
  17366. }
  17367. // shift the annotations and links
  17368. $cxpos = ($currentxpos / $this->k);
  17369. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  17370. if ($this->inxobj) {
  17371. // we are inside an XObject template
  17372. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17373. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17374. if ($cxpos > $lmpos) {
  17375. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  17376. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17377. } else {
  17378. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17379. }
  17380. break;
  17381. }
  17382. }
  17383. } elseif (isset($this->PageAnnots[$this->page])) {
  17384. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17385. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17386. if ($cxpos > $lmpos) {
  17387. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  17388. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17389. } else {
  17390. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17391. }
  17392. break;
  17393. }
  17394. }
  17395. }
  17396. } // end of while
  17397. // remove markers
  17398. $pmid = str_replace('x*#!#*x', '', $pmid);
  17399. if ($this->isUnicodeFont()) {
  17400. // multibyte characters
  17401. $spacew = $spacewidthu;
  17402. if ($this->font_stretching != 100) {
  17403. // word spacing is affected by stretching
  17404. $spacew /= ($this->font_stretching / 100);
  17405. }
  17406. // escape special characters
  17407. $pos = 0;
  17408. $pmid = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmid);
  17409. $pmid = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmid);
  17410. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmid, $pamatch) > 0) {
  17411. foreach($pamatch[0] as $pk => $pmatch) {
  17412. $replace = $pamatch[1][$pk];
  17413. $replace = str_replace('#!#OP#!#', '(', $replace);
  17414. $replace = str_replace('#!#CP#!#', ')', $replace);
  17415. $newpmid = '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacew).' (', $replace).')]';
  17416. $pos = strpos($pmid, $pmatch, $pos);
  17417. if ($pos !== FALSE) {
  17418. $pmid = substr_replace($pmid, $newpmid, $pos, strlen($pmatch));
  17419. }
  17420. ++$pos;
  17421. }
  17422. unset($pamatch);
  17423. }
  17424. if ($this->inxobj) {
  17425. // we are inside an XObject template
  17426. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  17427. } else {
  17428. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
  17429. }
  17430. $endlinepos = strlen($pstart."\n".$pmid."\n");
  17431. } else {
  17432. // non-unicode (single-byte characters)
  17433. if ($this->font_stretching != 100) {
  17434. // word spacing (Tw) is affected by stretching
  17435. $spacewidth /= ($this->font_stretching / 100);
  17436. }
  17437. $rs = sprintf('%F Tw', $spacewidth);
  17438. $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
  17439. if ($this->inxobj) {
  17440. // we are inside an XObject template
  17441. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  17442. } else {
  17443. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  17444. }
  17445. $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  17446. }
  17447. }
  17448. } // end of J
  17449. } // end if $startlinex
  17450. if (($t_x != 0) OR ($yshift < 0)) {
  17451. // shift the line
  17452. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  17453. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17454. $endlinepos = strlen($pstart);
  17455. if ($this->inxobj) {
  17456. // we are inside an XObject template
  17457. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17458. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17459. if ($pak >= $pask) {
  17460. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17461. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17462. }
  17463. }
  17464. } else {
  17465. $this->setPageBuffer($startlinepage, $pstart.$pend);
  17466. // shift the annotations and links
  17467. if (isset($this->PageAnnots[$this->page])) {
  17468. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17469. if ($pak >= $pask) {
  17470. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17471. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17472. }
  17473. }
  17474. }
  17475. }
  17476. $this->y -= $yshift;
  17477. }
  17478. }
  17479. $pbrk = $this->checkPageBreak($this->lasth);
  17480. $this->newline = false;
  17481. $startlinex = $this->x;
  17482. $startliney = $this->y;
  17483. if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  17484. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  17485. } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  17486. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  17487. } else {
  17488. $minstartliney = $startliney;
  17489. $maxbottomliney = ($this->y + $this->getCellHeight($fontsize / $this->k));
  17490. }
  17491. $startlinepage = $this->page;
  17492. if (isset($endlinepos) AND (!$pbrk)) {
  17493. $startlinepos = $endlinepos;
  17494. } else {
  17495. if ($this->inxobj) {
  17496. // we are inside an XObject template
  17497. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17498. } elseif (!$this->InFooter) {
  17499. if (isset($this->footerlen[$this->page])) {
  17500. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17501. } else {
  17502. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17503. }
  17504. $startlinepos = $this->footerpos[$this->page];
  17505. } else {
  17506. $startlinepos = $this->pagelen[$this->page];
  17507. }
  17508. }
  17509. unset($endlinepos);
  17510. $plalign = $lalign;
  17511. if (isset($this->PageAnnots[$this->page])) {
  17512. $pask = count($this->PageAnnots[$this->page]);
  17513. } else {
  17514. $pask = 0;
  17515. }
  17516. if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  17517. AND (isset($this->emptypagemrk[$this->page]))
  17518. AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  17519. $this->setFont($fontname, $fontstyle, $fontsize);
  17520. if ($wfill) {
  17521. $this->setFillColorArray($this->bgcolor);
  17522. }
  17523. }
  17524. } // end newline
  17525. if (isset($opentagpos)) {
  17526. unset($opentagpos);
  17527. }
  17528. if ($dom[$key]['tag']) {
  17529. if ($dom[$key]['opening']) {
  17530. // get text indentation (if any)
  17531. if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  17532. $this->textindent = $dom[$key]['text-indent'];
  17533. $this->newline = true;
  17534. }
  17535. // table
  17536. if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
  17537. // available page width
  17538. if ($this->rtl) {
  17539. $wtmp = $this->x - $this->lMargin;
  17540. } else {
  17541. $wtmp = $this->w - $this->rMargin - $this->x;
  17542. }
  17543. // get cell spacing
  17544. if (isset($dom[$key]['attribute']['cellspacing'])) {
  17545. $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  17546. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  17547. } elseif (isset($dom[$key]['border-spacing'])) {
  17548. $cellspacing = $dom[$key]['border-spacing'];
  17549. } else {
  17550. $cellspacing = array('H' => 0, 'V' => 0);
  17551. }
  17552. // table width
  17553. if (isset($dom[$key]['width'])) {
  17554. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  17555. } else {
  17556. $table_width = $wtmp;
  17557. }
  17558. $table_width -= (2 * $cellspacing['H']);
  17559. if (!$this->inthead) {
  17560. $this->y += $cellspacing['V'];
  17561. }
  17562. if ($this->rtl) {
  17563. $cellspacingx = -$cellspacing['H'];
  17564. } else {
  17565. $cellspacingx = $cellspacing['H'];
  17566. }
  17567. // total table width without cellspaces
  17568. $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  17569. // minimum column width
  17570. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  17571. // array of custom column widths
  17572. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  17573. }
  17574. // table row
  17575. if ($dom[$key]['value'] == 'tr') {
  17576. // reset column counter
  17577. $colid = 0;
  17578. }
  17579. // table cell
  17580. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  17581. $trid = $dom[$key]['parent'];
  17582. $table_el = $dom[$trid]['parent'];
  17583. if (!isset($dom[$table_el]['cols'])) {
  17584. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  17585. }
  17586. // store border info
  17587. $tdborder = 0;
  17588. if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  17589. $tdborder = $dom[$key]['border'];
  17590. }
  17591. $colspan = intval($dom[$key]['attribute']['colspan']);
  17592. if ($colspan <= 0) {
  17593. $colspan = 1;
  17594. }
  17595. $old_cell_padding = $this->cell_padding;
  17596. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  17597. $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  17598. $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
  17599. } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  17600. $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
  17601. } else {
  17602. $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
  17603. }
  17604. $this->cell_padding = $current_cell_padding;
  17605. if (isset($dom[$key]['height'])) {
  17606. // minimum cell height
  17607. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  17608. } else {
  17609. $cellh = 0;
  17610. }
  17611. if (isset($dom[$key]['content'])) {
  17612. $cell_content = $dom[$key]['content'];
  17613. } else {
  17614. $cell_content = '&nbsp;';
  17615. }
  17616. $tagtype = $dom[$key]['value'];
  17617. $parentid = $key;
  17618. while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  17619. // move $key index forward
  17620. ++$key;
  17621. }
  17622. if (!isset($dom[$trid]['startpage'])) {
  17623. $dom[$trid]['startpage'] = $this->page;
  17624. } else {
  17625. $this->setPage($dom[$trid]['startpage']);
  17626. }
  17627. if (!isset($dom[$trid]['startcolumn'])) {
  17628. $dom[$trid]['startcolumn'] = $this->current_column;
  17629. } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  17630. $tmpx = $this->x;
  17631. $this->selectColumn($dom[$trid]['startcolumn']);
  17632. $this->x = $tmpx;
  17633. }
  17634. if (!isset($dom[$trid]['starty'])) {
  17635. $dom[$trid]['starty'] = $this->y;
  17636. } else {
  17637. $this->y = $dom[$trid]['starty'];
  17638. }
  17639. if (!isset($dom[$trid]['startx'])) {
  17640. $dom[$trid]['startx'] = $this->x;
  17641. $this->x += $cellspacingx;
  17642. } else {
  17643. $this->x += ($cellspacingx / 2);
  17644. }
  17645. if (isset($dom[$parentid]['attribute']['rowspan'])) {
  17646. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  17647. } else {
  17648. $rowspan = 1;
  17649. }
  17650. // skip row-spanned cells started on the previous rows
  17651. if (isset($dom[$table_el]['rowspans'])) {
  17652. $rsk = 0;
  17653. $rskmax = count($dom[$table_el]['rowspans']);
  17654. while ($rsk < $rskmax) {
  17655. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  17656. $rsstartx = $trwsp['startx'];
  17657. $rsendx = $trwsp['endx'];
  17658. // account for margin changes
  17659. if ($trwsp['startpage'] < $this->page) {
  17660. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  17661. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  17662. $rsstartx -= $dl;
  17663. $rsendx -= $dl;
  17664. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  17665. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  17666. $rsstartx += $dl;
  17667. $rsendx += $dl;
  17668. }
  17669. }
  17670. if (($trwsp['rowspan'] > 0)
  17671. AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  17672. AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  17673. AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  17674. // set the starting X position of the current cell
  17675. $this->x = $rsendx + $cellspacingx;
  17676. // increment column indicator
  17677. $colid += $trwsp['colspan'];
  17678. if (($trwsp['rowspan'] == 1)
  17679. AND (isset($dom[$trid]['endy']))
  17680. AND (isset($dom[$trid]['endpage']))
  17681. AND (isset($dom[$trid]['endcolumn']))
  17682. AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  17683. AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17684. // set ending Y position for row
  17685. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17686. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  17687. }
  17688. $rsk = 0;
  17689. } else {
  17690. ++$rsk;
  17691. }
  17692. }
  17693. }
  17694. if (isset($dom[$parentid]['width'])) {
  17695. // user specified width
  17696. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  17697. $tmpcw = ($cellw / $colspan);
  17698. for ($i = 0; $i < $colspan; ++$i) {
  17699. $table_colwidths[($colid + $i)] = $tmpcw;
  17700. }
  17701. } else {
  17702. // inherit column width
  17703. $cellw = 0;
  17704. for ($i = 0; $i < $colspan; ++$i) {
  17705. $cellw += (isset($table_colwidths[($colid + $i)]) ? $table_colwidths[($colid + $i)] : 0);
  17706. }
  17707. }
  17708. $cellw += (($colspan - 1) * $cellspacing['H']);
  17709. // increment column indicator
  17710. $colid += $colspan;
  17711. // add rowspan information to table element
  17712. if ($rowspan > 1) {
  17713. $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));
  17714. }
  17715. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  17716. if ($rowspan > 1) {
  17717. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  17718. }
  17719. // push background colors
  17720. if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  17721. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  17722. }
  17723. // store border info
  17724. if (isset($tdborder) AND !empty($tdborder)) {
  17725. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  17726. }
  17727. $prevLastH = $this->lasth;
  17728. // store some info for multicolumn mode
  17729. if ($this->rtl) {
  17730. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  17731. } else {
  17732. $this->colxshift['x'] = $this->x - $this->lMargin;
  17733. }
  17734. $this->colxshift['s'] = $cellspacing;
  17735. $this->colxshift['p'] = $current_cell_padding;
  17736. // ****** write the cell content ******
  17737. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
  17738. // restore some values
  17739. $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  17740. $this->lasth = $prevLastH;
  17741. $this->cell_padding = $old_cell_padding;
  17742. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  17743. // update the end of row position
  17744. if ($rowspan <= 1) {
  17745. if (isset($dom[$trid]['endy'])) {
  17746. if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  17747. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  17748. } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
  17749. $dom[$trid]['endy'] = $this->y;
  17750. }
  17751. } else {
  17752. $dom[$trid]['endy'] = $this->y;
  17753. }
  17754. if (isset($dom[$trid]['endpage'])) {
  17755. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  17756. } else {
  17757. $dom[$trid]['endpage'] = $this->page;
  17758. }
  17759. if (isset($dom[$trid]['endcolumn'])) {
  17760. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  17761. } else {
  17762. $dom[$trid]['endcolumn'] = $this->current_column;
  17763. }
  17764. } else {
  17765. // account for row-spanned cells
  17766. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  17767. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  17768. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  17769. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  17770. }
  17771. if (isset($dom[$table_el]['rowspans'])) {
  17772. // update endy and endpage on rowspanned cells
  17773. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  17774. if ($trwsp['rowspan'] > 0) {
  17775. if (isset($dom[$trid]['endpage'])) {
  17776. if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17777. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17778. } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  17779. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  17780. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  17781. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  17782. } else {
  17783. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  17784. }
  17785. }
  17786. }
  17787. }
  17788. }
  17789. $this->x += ($cellspacingx / 2);
  17790. } else {
  17791. // opening tag (or self-closing tag)
  17792. if (!isset($opentagpos)) {
  17793. if ($this->inxobj) {
  17794. // we are inside an XObject template
  17795. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17796. } elseif (!$this->InFooter) {
  17797. if (isset($this->footerlen[$this->page])) {
  17798. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17799. } else {
  17800. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17801. }
  17802. $opentagpos = $this->footerpos[$this->page];
  17803. }
  17804. }
  17805. $dom = $this->openHTMLTagHandler($dom, $key, $cell);
  17806. }
  17807. } else { // closing tag
  17808. $prev_numpages = $this->numpages;
  17809. $old_bordermrk = $this->bordermrk[$this->page];
  17810. $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  17811. if ($this->bordermrk[$this->page] > $old_bordermrk) {
  17812. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  17813. }
  17814. if ($prev_numpages > $this->numpages) {
  17815. $startlinepage = $this->page;
  17816. }
  17817. }
  17818. } elseif (strlen($dom[$key]['value']) > 0) {
  17819. // print list-item
  17820. if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  17821. $this->setFont($pfontname, $pfontstyle, $pfontsize);
  17822. $this->resetLastH();
  17823. $minstartliney = $this->y;
  17824. $maxbottomliney = ($startliney + $this->getCellHeight($this->FontSize));
  17825. if (is_numeric($pfontsize) AND ($pfontsize > 0)) {
  17826. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  17827. }
  17828. $this->setFont($curfontname, $curfontstyle, $curfontsize);
  17829. $this->resetLastH();
  17830. if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
  17831. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  17832. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  17833. $this->y += ($this->getCellHeight(($pfontsize - $curfontsize) / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  17834. $minstartliney = min($this->y, $minstartliney);
  17835. $maxbottomliney = max(($this->y + $this->getCellHeight($pfontsize / $this->k)), $maxbottomliney);
  17836. }
  17837. }
  17838. // text
  17839. $this->htmlvspace = 0;
  17840. $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']);
  17841. if ((!$this->premode) AND $this->isRTLTextDir() AND !$isRTLString) {
  17842. // reverse spaces order
  17843. $lsp = ''; // left spaces
  17844. $rsp = ''; // right spaces
  17845. if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17846. $lsp = $matches[1];
  17847. }
  17848. if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17849. $rsp = $matches[1];
  17850. }
  17851. $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  17852. }
  17853. if ($newline) {
  17854. if (!$this->premode) {
  17855. $prelen = strlen($dom[$key]['value']);
  17856. if ($this->isRTLTextDir() AND !$isRTLString) {
  17857. // right trim except non-breaking space
  17858. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  17859. } else {
  17860. // left trim except non-breaking space
  17861. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  17862. }
  17863. $postlen = strlen($dom[$key]['value']);
  17864. if (($postlen == 0) AND ($prelen > 0)) {
  17865. $dom[$key]['trimmed_space'] = true;
  17866. }
  17867. }
  17868. $newline = false;
  17869. $firstblock = true;
  17870. } else {
  17871. $firstblock = false;
  17872. // replace empty multiple spaces string with a single space
  17873. $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  17874. }
  17875. $strrest = '';
  17876. if ($this->rtl) {
  17877. $this->x -= $this->textindent;
  17878. } else {
  17879. $this->x += $this->textindent;
  17880. }
  17881. if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  17882. $strlinelen = $this->GetStringWidth($dom[$key]['value']);
  17883. if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  17884. // HTML <a> Link
  17885. $hrefcolor = '';
  17886. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  17887. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  17888. }
  17889. $hrefstyle = -1;
  17890. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  17891. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  17892. }
  17893. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  17894. } else {
  17895. $wadj = 0; // space to leave for block continuity
  17896. if ($this->rtl) {
  17897. $cwa = ($this->x - $this->lMargin);
  17898. } else {
  17899. $cwa = ($this->w - $this->rMargin - $this->x);
  17900. }
  17901. if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
  17902. // check the next text blocks for continuity
  17903. $nkey = ($key + 1);
  17904. $write_block = true;
  17905. $same_textdir = true;
  17906. $tmp_fontname = $this->FontFamily;
  17907. $tmp_fontstyle = $this->FontStyle;
  17908. $tmp_fontsize = $this->FontSizePt;
  17909. while ($write_block AND isset($dom[$nkey])) {
  17910. if ($dom[$nkey]['tag']) {
  17911. if ($dom[$nkey]['block']) {
  17912. // end of block
  17913. $write_block = false;
  17914. }
  17915. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  17916. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  17917. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  17918. $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  17919. } else {
  17920. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/', $this->re_space['m'], $dom[$nkey]['value']);
  17921. if (isset($nextstr[0]) AND $same_textdir) {
  17922. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  17923. if (isset($nextstr[1])) {
  17924. $write_block = false;
  17925. }
  17926. }
  17927. }
  17928. ++$nkey;
  17929. }
  17930. }
  17931. if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
  17932. $wadj = 0;
  17933. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $dom[$key]['value']);
  17934. $numblks = count($nextstr);
  17935. if ($numblks > 1) {
  17936. // try to split on blank spaces
  17937. $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
  17938. } else {
  17939. // set the entire block on new line
  17940. $wadj = $this->GetStringWidth($nextstr[0]);
  17941. }
  17942. }
  17943. // check for reversed text direction
  17944. if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  17945. // LTR text on RTL direction or RTL text on LTR direction
  17946. $reverse_dir = true;
  17947. $this->rtl = !$this->rtl;
  17948. $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
  17949. if ($this->rtl) {
  17950. $this->x += $revshift;
  17951. } else {
  17952. $this->x -= $revshift;
  17953. }
  17954. $xws = $this->x;
  17955. }
  17956. // ****** write only until the end of the line and get the rest ******
  17957. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  17958. // restore default direction
  17959. if ($reverse_dir AND ($wadj == 0)) {
  17960. $this->x = $xws;
  17961. $this->rtl = !$this->rtl;
  17962. $reverse_dir = false;
  17963. }
  17964. }
  17965. }
  17966. $this->textindent = 0;
  17967. if (strlen($strrest) > 0) {
  17968. // store the remaining string on the previous $key position
  17969. $this->newline = true;
  17970. if ($strrest == $dom[$key]['value']) {
  17971. // used to avoid infinite loop
  17972. ++$loop;
  17973. } else {
  17974. $loop = 0;
  17975. }
  17976. $dom[$key]['value'] = $strrest;
  17977. if ($cell) {
  17978. if ($this->rtl) {
  17979. $this->x -= $this->cell_padding['R'];
  17980. } else {
  17981. $this->x += $this->cell_padding['L'];
  17982. }
  17983. }
  17984. if ($loop < 3) {
  17985. --$key;
  17986. }
  17987. } else {
  17988. $loop = 0;
  17989. // add the positive font spacing of the last character (if any)
  17990. if ($this->font_spacing > 0) {
  17991. if ($this->rtl) {
  17992. $this->x -= $this->font_spacing;
  17993. } else {
  17994. $this->x += $this->font_spacing;
  17995. }
  17996. }
  17997. }
  17998. }
  17999. ++$key;
  18000. 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')) {
  18001. // check if we are on a new page or on a new column
  18002. if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
  18003. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  18004. // restore previous object
  18005. $this->rollbackTransaction(true);
  18006. // restore previous values
  18007. foreach ($this_method_vars as $vkey => $vval) {
  18008. $$vkey = $vval;
  18009. }
  18010. if (!empty($dom[$key]['thead'])) {
  18011. $this->inthead = true;
  18012. }
  18013. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18014. $pre_y = $this->y;
  18015. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  18016. $startliney = $this->y;
  18017. }
  18018. $undo = true; // avoid infinite loop
  18019. } else {
  18020. $undo = false;
  18021. }
  18022. }
  18023. } // end for each $key
  18024. // align the last line
  18025. if (isset($startlinex)) {
  18026. $yshift = ($minstartliney - $startliney);
  18027. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  18028. $yshift = 0;
  18029. }
  18030. $t_x = 0;
  18031. // the last line must be shifted to be aligned as requested
  18032. $linew = abs($this->endlinex - $startlinex);
  18033. if ($this->inxobj) {
  18034. // we are inside an XObject template
  18035. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  18036. if (isset($opentagpos)) {
  18037. $midpos = $opentagpos;
  18038. } else {
  18039. $midpos = 0;
  18040. }
  18041. if ($midpos > 0) {
  18042. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  18043. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  18044. } else {
  18045. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  18046. $pend = '';
  18047. }
  18048. } else {
  18049. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  18050. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18051. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18052. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  18053. } elseif (isset($opentagpos)) {
  18054. $midpos = $opentagpos;
  18055. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18056. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18057. $midpos = $this->footerpos[$startlinepage];
  18058. } else {
  18059. $midpos = 0;
  18060. }
  18061. if ($midpos > 0) {
  18062. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  18063. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  18064. } else {
  18065. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  18066. $pend = '';
  18067. }
  18068. }
  18069. if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  18070. // calculate shifting amount
  18071. $tw = $w;
  18072. if ($this->lMargin != $prevlMargin) {
  18073. $tw += ($prevlMargin - $this->lMargin);
  18074. }
  18075. if ($this->rMargin != $prevrMargin) {
  18076. $tw += ($prevrMargin - $this->rMargin);
  18077. }
  18078. $one_space_width = $this->GetStringWidth(chr(32));
  18079. $no = 0; // number of spaces on a line contained on a single block
  18080. if ($this->isRTLTextDir()) { // RTL
  18081. // remove left space if exist
  18082. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  18083. if ($pos1 > 0) {
  18084. $pos1 = intval($pos1);
  18085. if ($this->isUnicodeFont()) {
  18086. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  18087. $spacelen = 2;
  18088. } else {
  18089. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  18090. $spacelen = 1;
  18091. }
  18092. if ($pos1 == $pos2) {
  18093. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  18094. if (substr($pmid, $pos1, 4) == '[()]') {
  18095. $linew -= $one_space_width;
  18096. } elseif ($pos1 == strpos($pmid, '[(')) {
  18097. $no = 1;
  18098. }
  18099. }
  18100. }
  18101. } else { // LTR
  18102. // remove right space if exist
  18103. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  18104. if ($pos1 > 0) {
  18105. $pos1 = intval($pos1);
  18106. if ($this->isUnicodeFont()) {
  18107. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  18108. $spacelen = 2;
  18109. } else {
  18110. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  18111. $spacelen = 1;
  18112. }
  18113. if ($pos1 == $pos2) {
  18114. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  18115. $linew -= $one_space_width;
  18116. }
  18117. }
  18118. }
  18119. $mdiff = ($tw - $linew);
  18120. if ($plalign == 'C') {
  18121. if ($this->rtl) {
  18122. $t_x = -($mdiff / 2);
  18123. } else {
  18124. $t_x = ($mdiff / 2);
  18125. }
  18126. } elseif ($plalign == 'R') {
  18127. // right alignment on LTR document
  18128. $t_x = $mdiff;
  18129. } elseif ($plalign == 'L') {
  18130. // left alignment on RTL document
  18131. $t_x = -$mdiff;
  18132. }
  18133. } // end if startlinex
  18134. if (($t_x != 0) OR ($yshift < 0)) {
  18135. // shift the line
  18136. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  18137. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  18138. $endlinepos = strlen($pstart);
  18139. if ($this->inxobj) {
  18140. // we are inside an XObject template
  18141. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  18142. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  18143. if ($pak >= $pask) {
  18144. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  18145. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  18146. }
  18147. }
  18148. } else {
  18149. $this->setPageBuffer($startlinepage, $pstart.$pend);
  18150. // shift the annotations and links
  18151. if (isset($this->PageAnnots[$this->page])) {
  18152. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  18153. if ($pak >= $pask) {
  18154. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  18155. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  18156. }
  18157. }
  18158. }
  18159. }
  18160. $this->y -= $yshift;
  18161. $yshift = 0;
  18162. }
  18163. }
  18164. // restore previous values
  18165. $this->setGraphicVars($gvars);
  18166. if ($this->num_columns > 1) {
  18167. $this->selectColumn();
  18168. } elseif ($this->page > $prevPage) {
  18169. $this->lMargin = $this->pagedim[$this->page]['olm'];
  18170. $this->rMargin = $this->pagedim[$this->page]['orm'];
  18171. }
  18172. // restore previous list state
  18173. $this->cell_height_ratio = $prev_cell_height_ratio;
  18174. $this->listnum = $prev_listnum;
  18175. $this->listordered = $prev_listordered;
  18176. $this->listcount = $prev_listcount;
  18177. $this->lispacer = $prev_lispacer;
  18178. if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  18179. $this->Ln($this->lasth);
  18180. if (($this->y < $maxbottomliney) AND ($startlinepage == $this->page)) {
  18181. $this->y = $maxbottomliney;
  18182. }
  18183. }
  18184. unset($dom);
  18185. }
  18186. /**
  18187. * Process opening tags.
  18188. * @param array $dom html dom array
  18189. * @param int $key current element id
  18190. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  18191. * @return array $dom
  18192. * @protected
  18193. */
  18194. protected function openHTMLTagHandler($dom, $key, $cell) {
  18195. $tag = $dom[$key];
  18196. $parent = $dom[($dom[$key]['parent'])];
  18197. $firsttag = ($key == 1);
  18198. // check for text direction attribute
  18199. if (isset($tag['dir'])) {
  18200. $this->setTempRTL($tag['dir']);
  18201. } else {
  18202. $this->tmprtl = false;
  18203. }
  18204. if ($tag['block']) {
  18205. $hbz = 0; // distance from y to line bottom
  18206. $hb = 0; // vertical space between block tags
  18207. // calculate vertical space for block tags
  18208. if (isset($this->tagvspaces[$tag['value']][0]['h']) && !empty($this->tagvspaces[$tag['value']][0]['h']) && ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  18209. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  18210. } elseif (isset($tag['fontsize'])) {
  18211. $cur_h = $this->getCellHeight($tag['fontsize'] / $this->k);
  18212. } else {
  18213. $cur_h = $this->getCellHeight($this->FontSize);
  18214. }
  18215. if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  18216. $on = $this->tagvspaces[$tag['value']][0]['n'];
  18217. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18218. $on = 0.6;
  18219. } else {
  18220. $on = 1;
  18221. }
  18222. if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br', 'hr')))) {
  18223. $hb = 0;
  18224. } else {
  18225. $hb = ($on * $cur_h);
  18226. }
  18227. if (($this->htmlvspace <= 0) AND ($on > 0)) {
  18228. if (isset($parent['fontsize'])) {
  18229. $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  18230. } else {
  18231. $hbz = $this->getCellHeight($this->FontSize);
  18232. }
  18233. }
  18234. if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
  18235. // fix vertical space after table
  18236. $hbz = 0;
  18237. }
  18238. // closing vertical space
  18239. $hbc = 0;
  18240. if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18241. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18242. } elseif (isset($parent['fontsize'])) {
  18243. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  18244. } else {
  18245. $pre_h = $this->getCellHeight($this->FontSize);
  18246. }
  18247. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18248. $cn = $this->tagvspaces[$tag['value']][1]['n'];
  18249. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18250. $cn = 0.6;
  18251. } else {
  18252. $cn = 1;
  18253. }
  18254. if (isset($this->tagvspaces[$tag['value']][1])) {
  18255. $hbc = ($cn * $pre_h);
  18256. }
  18257. }
  18258. // Opening tag
  18259. switch($tag['value']) {
  18260. case 'table': {
  18261. $cp = 0;
  18262. $cs = 0;
  18263. $dom[$key]['rowspans'] = array();
  18264. if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  18265. $this->htmlvspace = 0;
  18266. // set table header
  18267. if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) {
  18268. // set table header
  18269. $this->thead = $dom[$key]['thead'];
  18270. if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  18271. $this->theadMargins = array();
  18272. $this->theadMargins['cell_padding'] = $this->cell_padding;
  18273. $this->theadMargins['lmargin'] = $this->lMargin;
  18274. $this->theadMargins['rmargin'] = $this->rMargin;
  18275. $this->theadMargins['page'] = $this->page;
  18276. $this->theadMargins['cell'] = $cell;
  18277. $this->theadMargins['gvars'] = $this->getGraphicVars();
  18278. }
  18279. }
  18280. }
  18281. // store current margins and page
  18282. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  18283. if (isset($tag['attribute']['cellpadding'])) {
  18284. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  18285. $this->setCellPadding($pad);
  18286. } elseif (isset($tag['padding'])) {
  18287. $this->cell_padding = $tag['padding'];
  18288. }
  18289. if (isset($tag['attribute']['cellspacing'])) {
  18290. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  18291. } elseif (isset($tag['border-spacing'])) {
  18292. $cs = $tag['border-spacing']['V'];
  18293. }
  18294. $prev_y = $this->y;
  18295. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
  18296. $this->inthead = true;
  18297. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18298. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18299. }
  18300. break;
  18301. }
  18302. case 'tr': {
  18303. // array of columns positions
  18304. $dom[$key]['cellpos'] = array();
  18305. break;
  18306. }
  18307. case 'hr': {
  18308. if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  18309. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  18310. } else {
  18311. $hrHeight = $this->GetLineWidth();
  18312. }
  18313. $this->addHTMLVertSpace($hbz, max($hb, ($hrHeight / 2)), $cell, $firsttag);
  18314. $x = $this->GetX();
  18315. $y = $this->GetY();
  18316. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  18317. if ($cell) {
  18318. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  18319. }
  18320. if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  18321. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  18322. } else {
  18323. $hrWidth = $wtmp;
  18324. }
  18325. $prevlinewidth = $this->GetLineWidth();
  18326. $this->setLineWidth($hrHeight);
  18327. $lineStyle = array();
  18328. if (isset($tag['fgcolor'])) {
  18329. $lineStyle['color'] = $tag['fgcolor'];
  18330. }
  18331. if (isset($tag['fgcolor'])) {
  18332. $lineStyle['color'] = $tag['fgcolor'];
  18333. }
  18334. if (isset($tag['style']['cap'])) {
  18335. $lineStyle['cap'] = $tag['style']['cap'];
  18336. }
  18337. if (isset($tag['style']['join'])) {
  18338. $lineStyle['join'] = $tag['style']['join'];
  18339. }
  18340. if (isset($tag['style']['dash'])) {
  18341. $lineStyle['dash'] = $tag['style']['dash'];
  18342. }
  18343. if (isset($tag['style']['phase'])) {
  18344. $lineStyle['phase'] = $tag['style']['phase'];
  18345. }
  18346. $lineStyle = array_filter($lineStyle);
  18347. $this->Line($x, $y, $x + $hrWidth, $y, $lineStyle);
  18348. $this->setLineWidth($prevlinewidth);
  18349. $this->addHTMLVertSpace(max($hbc, ($hrHeight / 2)), 0, $cell, !isset($dom[($key + 1)]));
  18350. break;
  18351. }
  18352. case 'a': {
  18353. if (array_key_exists('href', $tag['attribute'])) {
  18354. $this->HREF['url'] = $tag['attribute']['href'];
  18355. }
  18356. break;
  18357. }
  18358. case 'img': {
  18359. if (empty($tag['attribute']['src'])) {
  18360. break;
  18361. }
  18362. $imgsrc = $tag['attribute']['src'];
  18363. if ($imgsrc[0] === '@') {
  18364. // data stream
  18365. $imgsrc = '@'.base64_decode(substr($imgsrc, 1));
  18366. $type = '';
  18367. } elseif ( $this->allowLocalFiles && substr($imgsrc, 0, 7) === 'file://') {
  18368. // get image type from a local file path
  18369. $imgsrc = substr($imgsrc, 7);
  18370. $type = TCPDF_IMAGES::getImageFileType($imgsrc);
  18371. } else {
  18372. if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  18373. // fix image path
  18374. $findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']);
  18375. if (($findroot === false) OR ($findroot > 1)) {
  18376. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  18377. $imgsrc = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc;
  18378. } else {
  18379. $imgsrc = $_SERVER['DOCUMENT_ROOT'].$imgsrc;
  18380. }
  18381. }
  18382. $imgsrc = urldecode($imgsrc);
  18383. $testscrtype = @parse_url($imgsrc);
  18384. if (empty($testscrtype['query'])) {
  18385. // convert URL to server path
  18386. $imgsrc = str_replace(K_PATH_URL, K_PATH_MAIN, $imgsrc);
  18387. } elseif (preg_match('|^https?://|', $imgsrc) !== 1) {
  18388. // convert URL to server path
  18389. $imgsrc = str_replace(K_PATH_MAIN, K_PATH_URL, $imgsrc);
  18390. }
  18391. }
  18392. // get image type
  18393. $type = TCPDF_IMAGES::getImageFileType($imgsrc);
  18394. }
  18395. if (!isset($tag['width'])) {
  18396. $tag['width'] = 0;
  18397. }
  18398. if (!isset($tag['height'])) {
  18399. $tag['height'] = 0;
  18400. }
  18401. //if (!isset($tag['attribute']['align'])) {
  18402. // the only alignment supported is "bottom"
  18403. // further development is required for other modes.
  18404. $tag['attribute']['align'] = 'bottom';
  18405. //}
  18406. switch($tag['attribute']['align']) {
  18407. case 'top': {
  18408. $align = 'T';
  18409. break;
  18410. }
  18411. case 'middle': {
  18412. $align = 'M';
  18413. break;
  18414. }
  18415. case 'bottom': {
  18416. $align = 'B';
  18417. break;
  18418. }
  18419. default: {
  18420. $align = 'B';
  18421. break;
  18422. }
  18423. }
  18424. $prevy = $this->y;
  18425. $xpos = $this->x;
  18426. $imglink = '';
  18427. if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) {
  18428. $imglink = $this->HREF['url'];
  18429. if ($imglink[0] == '#') {
  18430. // convert url to internal link
  18431. $lnkdata = explode(',', $imglink);
  18432. if (isset($lnkdata[0])) {
  18433. $page = intval(substr($lnkdata[0], 1));
  18434. if (empty($page) OR ($page <= 0)) {
  18435. $page = $this->page;
  18436. }
  18437. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  18438. $lnky = floatval($lnkdata[1]);
  18439. } else {
  18440. $lnky = 0;
  18441. }
  18442. $imglink = $this->AddLink();
  18443. $this->setLink($imglink, $lnky, $page);
  18444. }
  18445. }
  18446. }
  18447. $border = 0;
  18448. if (isset($tag['border']) AND !empty($tag['border'])) {
  18449. // currently only support 1 (frame) or a combination of 'LTRB'
  18450. $border = $tag['border'];
  18451. }
  18452. $iw = '';
  18453. if (isset($tag['width'])) {
  18454. $iw = $this->getHTMLUnitToUnits($tag['width'], ($tag['fontsize'] / $this->k), 'px', false);
  18455. }
  18456. $ih = '';
  18457. if (isset($tag['height'])) {
  18458. $ih = $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k), 'px', false);
  18459. }
  18460. if (($type == 'eps') OR ($type == 'ai')) {
  18461. $this->ImageEps($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  18462. } elseif ($type == 'svg') {
  18463. $this->ImageSVG($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  18464. } else {
  18465. $this->Image($imgsrc, $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  18466. }
  18467. switch($align) {
  18468. case 'T': {
  18469. $this->y = $prevy;
  18470. break;
  18471. }
  18472. case 'M': {
  18473. $this->y = (($this->img_rb_y + $prevy - ($this->getCellHeight($tag['fontsize'] / $this->k))) / 2);
  18474. break;
  18475. }
  18476. case 'B': {
  18477. $this->y = $this->img_rb_y - ($this->getCellHeight($tag['fontsize'] / $this->k) - ($this->getFontDescent($tag['fontname'], $tag['fontstyle'], $tag['fontsize']) * $this->cell_height_ratio));
  18478. break;
  18479. }
  18480. }
  18481. break;
  18482. }
  18483. case 'dl': {
  18484. ++$this->listnum;
  18485. if ($this->listnum == 1) {
  18486. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18487. } else {
  18488. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18489. }
  18490. break;
  18491. }
  18492. case 'dt': {
  18493. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18494. break;
  18495. }
  18496. case 'dd': {
  18497. if ($this->rtl) {
  18498. $this->rMargin += $this->listindent;
  18499. } else {
  18500. $this->lMargin += $this->listindent;
  18501. }
  18502. ++$this->listindentlevel;
  18503. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18504. break;
  18505. }
  18506. case 'ul':
  18507. case 'ol': {
  18508. ++$this->listnum;
  18509. if ($tag['value'] == 'ol') {
  18510. $this->listordered[$this->listnum] = true;
  18511. } else {
  18512. $this->listordered[$this->listnum] = false;
  18513. }
  18514. if (isset($tag['attribute']['start'])) {
  18515. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  18516. } else {
  18517. $this->listcount[$this->listnum] = 0;
  18518. }
  18519. if ($this->rtl) {
  18520. $this->rMargin += $this->listindent;
  18521. $this->x -= $this->listindent;
  18522. } else {
  18523. $this->lMargin += $this->listindent;
  18524. $this->x += $this->listindent;
  18525. }
  18526. ++$this->listindentlevel;
  18527. if ($this->listnum == 1) {
  18528. if ($key > 1) {
  18529. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18530. }
  18531. } else {
  18532. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18533. }
  18534. break;
  18535. }
  18536. case 'li': {
  18537. if ($key > 2) {
  18538. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18539. }
  18540. if ($this->listordered[$this->listnum]) {
  18541. // ordered item
  18542. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18543. $this->lispacer = $parent['attribute']['type'];
  18544. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18545. $this->lispacer = $parent['listtype'];
  18546. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18547. $this->lispacer = $this->lisymbol;
  18548. } else {
  18549. $this->lispacer = '#';
  18550. }
  18551. ++$this->listcount[$this->listnum];
  18552. if (isset($tag['attribute']['value'])) {
  18553. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  18554. }
  18555. } else {
  18556. // unordered item
  18557. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18558. $this->lispacer = $parent['attribute']['type'];
  18559. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18560. $this->lispacer = $parent['listtype'];
  18561. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18562. $this->lispacer = $this->lisymbol;
  18563. } else {
  18564. $this->lispacer = '!';
  18565. }
  18566. }
  18567. break;
  18568. }
  18569. case 'blockquote': {
  18570. if ($this->rtl) {
  18571. $this->rMargin += $this->listindent;
  18572. } else {
  18573. $this->lMargin += $this->listindent;
  18574. }
  18575. ++$this->listindentlevel;
  18576. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18577. break;
  18578. }
  18579. case 'br': {
  18580. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18581. break;
  18582. }
  18583. case 'div': {
  18584. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18585. break;
  18586. }
  18587. case 'p': {
  18588. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18589. break;
  18590. }
  18591. case 'pre': {
  18592. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18593. $this->premode = true;
  18594. break;
  18595. }
  18596. case 'sup': {
  18597. $this->setXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  18598. break;
  18599. }
  18600. case 'sub': {
  18601. $this->setXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  18602. break;
  18603. }
  18604. case 'h1':
  18605. case 'h2':
  18606. case 'h3':
  18607. case 'h4':
  18608. case 'h5':
  18609. case 'h6': {
  18610. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18611. break;
  18612. }
  18613. // Form fields (since 4.8.000 - 2009-09-07)
  18614. case 'form': {
  18615. if (isset($tag['attribute']['action'])) {
  18616. $this->form_action = $tag['attribute']['action'];
  18617. } else {
  18618. $this->Error('Please explicitly set action attribute path!');
  18619. }
  18620. if (isset($tag['attribute']['enctype'])) {
  18621. $this->form_enctype = $tag['attribute']['enctype'];
  18622. } else {
  18623. $this->form_enctype = 'application/x-www-form-urlencoded';
  18624. }
  18625. if (isset($tag['attribute']['method'])) {
  18626. $this->form_mode = $tag['attribute']['method'];
  18627. } else {
  18628. $this->form_mode = 'post';
  18629. }
  18630. break;
  18631. }
  18632. case 'input': {
  18633. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18634. $name = $tag['attribute']['name'];
  18635. } else {
  18636. break;
  18637. }
  18638. $prop = array();
  18639. $opt = array();
  18640. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18641. $prop['readonly'] = true;
  18642. }
  18643. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18644. $value = $tag['attribute']['value'];
  18645. }
  18646. if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) {
  18647. $opt['maxlen'] = intval($tag['attribute']['maxlength']);
  18648. }
  18649. $h = $this->getCellHeight($this->FontSize);
  18650. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18651. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  18652. } else {
  18653. $w = $h;
  18654. }
  18655. if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  18656. $checked = true;
  18657. } else {
  18658. $checked = false;
  18659. }
  18660. if (isset($tag['align'])) {
  18661. switch ($tag['align']) {
  18662. case 'C': {
  18663. $opt['q'] = 1;
  18664. break;
  18665. }
  18666. case 'R': {
  18667. $opt['q'] = 2;
  18668. break;
  18669. }
  18670. case 'L':
  18671. default: {
  18672. break;
  18673. }
  18674. }
  18675. }
  18676. switch ($tag['attribute']['type']) {
  18677. case 'text': {
  18678. if (isset($value)) {
  18679. $opt['v'] = $value;
  18680. }
  18681. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18682. break;
  18683. }
  18684. case 'password': {
  18685. if (isset($value)) {
  18686. $opt['v'] = $value;
  18687. }
  18688. $prop['password'] = 'true';
  18689. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18690. break;
  18691. }
  18692. case 'checkbox': {
  18693. if (!isset($value)) {
  18694. break;
  18695. }
  18696. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  18697. break;
  18698. }
  18699. case 'radio': {
  18700. if (!isset($value)) {
  18701. break;
  18702. }
  18703. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  18704. break;
  18705. }
  18706. case 'submit': {
  18707. if (!isset($value)) {
  18708. $value = 'submit';
  18709. }
  18710. $w = $this->GetStringWidth($value) * 1.5;
  18711. $h *= 1.6;
  18712. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18713. $action = array();
  18714. $action['S'] = 'SubmitForm';
  18715. $action['F'] = $this->form_action;
  18716. if ($this->form_enctype != 'FDF') {
  18717. $action['Flags'] = array('ExportFormat');
  18718. }
  18719. if ($this->form_mode == 'get') {
  18720. $action['Flags'] = array('GetMethod');
  18721. }
  18722. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  18723. break;
  18724. }
  18725. case 'reset': {
  18726. if (!isset($value)) {
  18727. $value = 'reset';
  18728. }
  18729. $w = $this->GetStringWidth($value) * 1.5;
  18730. $h *= 1.6;
  18731. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18732. $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
  18733. break;
  18734. }
  18735. case 'file': {
  18736. $prop['fileSelect'] = 'true';
  18737. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18738. if (!isset($value)) {
  18739. $value = '*';
  18740. }
  18741. $w = $this->GetStringWidth($value) * 2;
  18742. $h *= 1.2;
  18743. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18744. $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  18745. $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18746. break;
  18747. }
  18748. case 'hidden': {
  18749. if (isset($value)) {
  18750. $opt['v'] = $value;
  18751. }
  18752. $opt['f'] = array('invisible', 'hidden');
  18753. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  18754. break;
  18755. }
  18756. case 'image': {
  18757. // THIS TYPE MUST BE FIXED
  18758. if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) {
  18759. $img = $tag['attribute']['src'];
  18760. } else {
  18761. break;
  18762. }
  18763. $value = 'img';
  18764. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  18765. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18766. $jsaction = $tag['attribute']['onclick'];
  18767. } else {
  18768. $jsaction = '';
  18769. }
  18770. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18771. break;
  18772. }
  18773. case 'button': {
  18774. if (!isset($value)) {
  18775. $value = ' ';
  18776. }
  18777. $w = $this->GetStringWidth($value) * 1.5;
  18778. $h *= 1.6;
  18779. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18780. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18781. $jsaction = $tag['attribute']['onclick'];
  18782. } else {
  18783. $jsaction = '';
  18784. }
  18785. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18786. break;
  18787. }
  18788. }
  18789. break;
  18790. }
  18791. case 'textarea': {
  18792. $prop = array();
  18793. $opt = array();
  18794. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18795. $prop['readonly'] = true;
  18796. }
  18797. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18798. $name = $tag['attribute']['name'];
  18799. } else {
  18800. break;
  18801. }
  18802. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18803. $opt['v'] = $tag['attribute']['value'];
  18804. }
  18805. if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) {
  18806. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  18807. } else {
  18808. $w = 40;
  18809. }
  18810. if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) {
  18811. $h = intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize);
  18812. } else {
  18813. $h = 10;
  18814. }
  18815. $prop['multiline'] = 'true';
  18816. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18817. break;
  18818. }
  18819. case 'select': {
  18820. $h = $this->getCellHeight($this->FontSize);
  18821. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18822. $h *= ($tag['attribute']['size'] + 1);
  18823. }
  18824. $prop = array();
  18825. $opt = array();
  18826. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18827. $name = $tag['attribute']['name'];
  18828. } else {
  18829. break;
  18830. }
  18831. $w = 0;
  18832. if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) {
  18833. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  18834. $values = array();
  18835. foreach ($options as $val) {
  18836. if (strpos($val, '#!TaB!#') !== false) {
  18837. $opts = explode('#!TaB!#', $val);
  18838. $values[] = $opts;
  18839. $w = max($w, $this->GetStringWidth($opts[1]));
  18840. } else {
  18841. $values[] = $val;
  18842. $w = max($w, $this->GetStringWidth($val));
  18843. }
  18844. }
  18845. } else {
  18846. break;
  18847. }
  18848. $w *= 2;
  18849. if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  18850. $prop['multipleSelection'] = 'true';
  18851. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18852. } else {
  18853. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18854. }
  18855. break;
  18856. }
  18857. case 'tcpdf': {
  18858. if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  18859. // Special tag used to call TCPDF methods
  18860. if (isset($tag['attribute']['method'])) {
  18861. $tcpdf_method = $tag['attribute']['method'];
  18862. if (method_exists($this, $tcpdf_method)) {
  18863. if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
  18864. $params = $this->unserializeTCPDFtagParameters($tag['attribute']['params']);
  18865. call_user_func_array(array($this, $tcpdf_method), $params);
  18866. } else {
  18867. $this->$tcpdf_method();
  18868. }
  18869. $this->newline = true;
  18870. }
  18871. }
  18872. }
  18873. break;
  18874. }
  18875. default: {
  18876. break;
  18877. }
  18878. }
  18879. // define tags that support borders and background colors
  18880. $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  18881. if (in_array($tag['value'], $bordertags)) {
  18882. // set border
  18883. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  18884. }
  18885. if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  18886. $pba = $dom[$key]['attribute']['pagebreakafter'];
  18887. // check for pagebreak
  18888. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  18889. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18890. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18891. }
  18892. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  18893. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  18894. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18895. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18896. }
  18897. }
  18898. return $dom;
  18899. }
  18900. /**
  18901. * Process closing tags.
  18902. * @param array $dom html dom array
  18903. * @param int $key current element id
  18904. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  18905. * @param int $maxbottomliney maximum y value of current line
  18906. * @return array $dom
  18907. * @protected
  18908. */
  18909. protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
  18910. $tag = $dom[$key];
  18911. $parent = $dom[($dom[$key]['parent'])];
  18912. $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
  18913. $in_table_head = false;
  18914. // maximum x position (used to draw borders)
  18915. if ($this->rtl) {
  18916. $xmax = $this->w;
  18917. } else {
  18918. $xmax = 0;
  18919. }
  18920. if ($tag['block']) {
  18921. $hbz = 0; // distance from y to line bottom
  18922. $hb = 0; // vertical space between block tags
  18923. // calculate vertical space for block tags
  18924. if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18925. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18926. } elseif (isset($parent['fontsize'])) {
  18927. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  18928. } else {
  18929. $pre_h = $this->getCellHeight($this->FontSize);
  18930. }
  18931. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18932. $cn = $this->tagvspaces[$tag['value']][1]['n'];
  18933. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18934. $cn = 0.6;
  18935. } else {
  18936. $cn = 1;
  18937. }
  18938. if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
  18939. $hb = 0;
  18940. } else {
  18941. $hb = ($cn * $pre_h);
  18942. }
  18943. if ($maxbottomliney > $this->PageBreakTrigger) {
  18944. $hbz = $this->getCellHeight($this->FontSize);
  18945. } elseif ($this->y < $maxbottomliney) {
  18946. $hbz = ($maxbottomliney - $this->y);
  18947. }
  18948. }
  18949. // Closing tag
  18950. switch($tag['value']) {
  18951. case 'tr': {
  18952. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  18953. if (!isset($parent['endy'])) {
  18954. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  18955. $parent['endy'] = $this->y;
  18956. }
  18957. if (!isset($parent['endpage'])) {
  18958. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  18959. $parent['endpage'] = $this->page;
  18960. }
  18961. if (!isset($parent['endcolumn'])) {
  18962. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  18963. $parent['endcolumn'] = $this->current_column;
  18964. }
  18965. // update row-spanned cells
  18966. if (isset($dom[$table_el]['rowspans'])) {
  18967. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18968. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  18969. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18970. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  18971. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  18972. } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  18973. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18974. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  18975. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  18976. }
  18977. }
  18978. }
  18979. // report new endy and endpage to the rowspanned cells
  18980. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18981. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18982. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  18983. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  18984. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  18985. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  18986. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  18987. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18988. }
  18989. }
  18990. // update remaining rowspanned cells
  18991. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18992. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18993. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  18994. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  18995. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  18996. }
  18997. }
  18998. }
  18999. $prev_page = $this->page;
  19000. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  19001. if ($this->num_columns > 1) {
  19002. if (($prev_page < $this->page)
  19003. AND ((($this->current_column == 0) AND ($dom[($dom[$key]['parent'])]['endcolumn'] == ($this->num_columns - 1)))
  19004. OR ($this->current_column == $dom[($dom[$key]['parent'])]['endcolumn']))) {
  19005. // page jump
  19006. $this->selectColumn(0);
  19007. $dom[($dom[$key]['parent'])]['endcolumn'] = 0;
  19008. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  19009. } else {
  19010. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  19011. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  19012. }
  19013. } else {
  19014. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  19015. }
  19016. if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  19017. $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  19018. } elseif (isset($dom[$table_el]['border-spacing'])) {
  19019. $this->y += $dom[$table_el]['border-spacing']['V'];
  19020. }
  19021. $this->Ln(0, $cell);
  19022. if ($this->current_column == $parent['startcolumn']) {
  19023. $this->x = $parent['startx'];
  19024. }
  19025. // account for booklet mode
  19026. if ($this->page > $parent['startpage']) {
  19027. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  19028. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  19029. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  19030. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  19031. }
  19032. }
  19033. break;
  19034. }
  19035. case 'tablehead':
  19036. // closing tag used for the thead part
  19037. $in_table_head = true;
  19038. $this->inthead = false;
  19039. case 'table': {
  19040. $table_el = $parent;
  19041. // set default border
  19042. if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  19043. // set default border
  19044. $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
  19045. } else {
  19046. $border = 0;
  19047. }
  19048. $default_border = $border;
  19049. // fix bottom line alignment of last line before page break
  19050. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  19051. // update row-spanned cells
  19052. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  19053. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  19054. if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
  19055. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  19056. }
  19057. if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
  19058. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  19059. }
  19060. }
  19061. }
  19062. if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  19063. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  19064. $dom[$prevtrkey]['endy'] = $pgendy;
  19065. // update row-spanned cells
  19066. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  19067. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  19068. if (($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  19069. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  19070. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  19071. }
  19072. }
  19073. }
  19074. }
  19075. $prevtrkey = $trkey;
  19076. $table_el = $dom[($dom[$key]['parent'])];
  19077. }
  19078. // for each row
  19079. if (count($table_el['trids']) > 0) {
  19080. unset($xmax);
  19081. }
  19082. foreach ($table_el['trids'] as $j => $trkey) {
  19083. $parent = $dom[$trkey];
  19084. if (!isset($xmax)) {
  19085. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  19086. }
  19087. // for each cell on the row
  19088. foreach ($parent['cellpos'] as $k => $cellpos) {
  19089. if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  19090. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  19091. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  19092. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  19093. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  19094. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  19095. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  19096. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  19097. } else {
  19098. $endy = $parent['endy'];
  19099. $startpage = $parent['startpage'];
  19100. $endpage = $parent['endpage'];
  19101. $startcolumn = $parent['startcolumn'];
  19102. $endcolumn = $parent['endcolumn'];
  19103. }
  19104. if ($this->num_columns == 0) {
  19105. $this->num_columns = 1;
  19106. }
  19107. if (isset($cellpos['border'])) {
  19108. $border = $cellpos['border'];
  19109. }
  19110. if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  19111. $this->setFillColorArray($cellpos['bgcolor']);
  19112. $fill = true;
  19113. } else {
  19114. $fill = false;
  19115. }
  19116. $x = $cellpos['startx'];
  19117. $y = $parent['starty'];
  19118. $starty = $y;
  19119. $w = abs($cellpos['endx'] - $cellpos['startx']);
  19120. // get border modes
  19121. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19122. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19123. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19124. // design borders around HTML cells.
  19125. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19126. $ccode = '';
  19127. $this->setPage($page);
  19128. if ($this->num_columns < 2) {
  19129. // single-column mode
  19130. $this->x = $x;
  19131. $this->y = $this->tMargin;
  19132. }
  19133. // account for margin changes
  19134. if ($page > $startpage) {
  19135. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19136. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19137. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19138. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19139. }
  19140. }
  19141. if ($startpage == $endpage) { // single page
  19142. $deltacol = 0;
  19143. $deltath = 0;
  19144. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19145. $this->selectColumn($column);
  19146. if ($startcolumn == $endcolumn) { // single column
  19147. $cborder = $border;
  19148. $h = $endy - $parent['starty'];
  19149. $this->y = $y;
  19150. $this->x = $x;
  19151. } elseif ($column == $startcolumn) { // first column
  19152. $cborder = $border_start;
  19153. $this->y = $starty;
  19154. $this->x = $x;
  19155. $h = $this->h - $this->y - $this->bMargin;
  19156. if ($this->rtl) {
  19157. $deltacol = $this->x + $this->rMargin - $this->w;
  19158. } else {
  19159. $deltacol = $this->x - $this->lMargin;
  19160. }
  19161. } elseif ($column == $endcolumn) { // end column
  19162. $cborder = $border_end;
  19163. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19164. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19165. }
  19166. $this->x += $deltacol;
  19167. $h = $endy - $this->y;
  19168. } else { // middle column
  19169. $cborder = $border_middle;
  19170. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19171. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19172. }
  19173. $this->x += $deltacol;
  19174. $h = $this->h - $this->y - $this->bMargin;
  19175. }
  19176. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19177. } // end for each column
  19178. } elseif ($page == $startpage) { // first page
  19179. $deltacol = 0;
  19180. $deltath = 0;
  19181. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19182. $this->selectColumn($column);
  19183. if ($column == $startcolumn) { // first column
  19184. $cborder = $border_start;
  19185. $this->y = $starty;
  19186. $this->x = $x;
  19187. $h = $this->h - $this->y - $this->bMargin;
  19188. if ($this->rtl) {
  19189. $deltacol = $this->x + $this->rMargin - $this->w;
  19190. } else {
  19191. $deltacol = $this->x - $this->lMargin;
  19192. }
  19193. } else { // middle column
  19194. $cborder = $border_middle;
  19195. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19196. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19197. }
  19198. $this->x += $deltacol;
  19199. $h = $this->h - $this->y - $this->bMargin;
  19200. }
  19201. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19202. } // end for each column
  19203. } elseif ($page == $endpage) { // last page
  19204. $deltacol = 0;
  19205. $deltath = 0;
  19206. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19207. $this->selectColumn($column);
  19208. if ($column == $endcolumn) { // end column
  19209. $cborder = $border_end;
  19210. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19211. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19212. }
  19213. $this->x += $deltacol;
  19214. $h = $endy - $this->y;
  19215. } else { // middle column
  19216. $cborder = $border_middle;
  19217. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19218. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19219. }
  19220. $this->x += $deltacol;
  19221. $h = $this->h - $this->y - $this->bMargin;
  19222. }
  19223. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19224. } // end for each column
  19225. } else { // middle page
  19226. $deltacol = 0;
  19227. $deltath = 0;
  19228. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19229. $this->selectColumn($column);
  19230. $cborder = $border_middle;
  19231. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19232. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19233. }
  19234. $this->x += $deltacol;
  19235. $h = $this->h - $this->y - $this->bMargin;
  19236. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19237. } // end for each column
  19238. }
  19239. if (!empty($cborder) OR !empty($fill)) {
  19240. $offsetlen = strlen($ccode);
  19241. // draw border and fill
  19242. if ($this->inxobj) {
  19243. // we are inside an XObject template
  19244. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19245. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19246. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19247. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19248. } else {
  19249. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19250. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19251. }
  19252. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19253. $pstart = substr($pagebuff, 0, $pagemark);
  19254. $pend = substr($pagebuff, $pagemark);
  19255. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19256. } else {
  19257. // draw border and fill
  19258. if (end($this->transfmrk[$this->page]) !== false) {
  19259. $pagemarkkey = key($this->transfmrk[$this->page]);
  19260. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19261. } elseif ($this->InFooter) {
  19262. $pagemark = $this->footerpos[$this->page];
  19263. } else {
  19264. $pagemark = $this->intmrk[$this->page];
  19265. }
  19266. $pagebuff = $this->getPageBuffer($this->page);
  19267. $pstart = substr($pagebuff, 0, $pagemark);
  19268. $pend = substr($pagebuff, $pagemark);
  19269. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19270. }
  19271. }
  19272. } // end for each page
  19273. // restore default border
  19274. $border = $default_border;
  19275. } // end for each cell on the row
  19276. if (isset($table_el['attribute']['cellspacing'])) {
  19277. $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  19278. } elseif (isset($table_el['border-spacing'])) {
  19279. $this->y += $table_el['border-spacing']['V'];
  19280. }
  19281. $this->Ln(0, $cell);
  19282. $this->x = $parent['startx'];
  19283. if ($endpage > $startpage) {
  19284. if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19285. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  19286. } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19287. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  19288. }
  19289. }
  19290. }
  19291. if (!$in_table_head) { // we are not inside a thead section
  19292. $this->cell_padding = isset($table_el['old_cell_padding']) ? $table_el['old_cell_padding'] : null;
  19293. // reset row height
  19294. $this->resetLastH();
  19295. if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
  19296. $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  19297. if (($plendiff > 0) AND ($plendiff < 60)) {
  19298. $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  19299. if (substr($pagediff, 0, 5) == 'BT /F') {
  19300. // the difference is only a font setting
  19301. $plendiff = 0;
  19302. }
  19303. }
  19304. if ($plendiff == 0) {
  19305. // remove last blank page
  19306. $this->deletePage($this->numpages);
  19307. }
  19308. }
  19309. if (isset($this->theadMargins['top'])) {
  19310. // restore top margin
  19311. $this->tMargin = $this->theadMargins['top'];
  19312. }
  19313. if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  19314. // reset main table header
  19315. $this->thead = '';
  19316. $this->theadMargins = array();
  19317. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  19318. }
  19319. }
  19320. $parent = $table_el;
  19321. break;
  19322. }
  19323. case 'a': {
  19324. $this->HREF = array();
  19325. break;
  19326. }
  19327. case 'sup': {
  19328. $this->setXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  19329. break;
  19330. }
  19331. case 'sub': {
  19332. $this->setXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
  19333. break;
  19334. }
  19335. case 'div': {
  19336. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19337. break;
  19338. }
  19339. case 'blockquote': {
  19340. if ($this->rtl) {
  19341. $this->rMargin -= $this->listindent;
  19342. } else {
  19343. $this->lMargin -= $this->listindent;
  19344. }
  19345. --$this->listindentlevel;
  19346. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19347. break;
  19348. }
  19349. case 'p': {
  19350. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19351. break;
  19352. }
  19353. case 'pre': {
  19354. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19355. $this->premode = false;
  19356. break;
  19357. }
  19358. case 'dl': {
  19359. --$this->listnum;
  19360. if ($this->listnum <= 0) {
  19361. $this->listnum = 0;
  19362. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19363. } else {
  19364. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19365. }
  19366. $this->resetLastH();
  19367. break;
  19368. }
  19369. case 'dt': {
  19370. $this->lispacer = '';
  19371. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19372. break;
  19373. }
  19374. case 'dd': {
  19375. $this->lispacer = '';
  19376. if ($this->rtl) {
  19377. $this->rMargin -= $this->listindent;
  19378. } else {
  19379. $this->lMargin -= $this->listindent;
  19380. }
  19381. --$this->listindentlevel;
  19382. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19383. break;
  19384. }
  19385. case 'ul':
  19386. case 'ol': {
  19387. --$this->listnum;
  19388. $this->lispacer = '';
  19389. if ($this->rtl) {
  19390. $this->rMargin -= $this->listindent;
  19391. } else {
  19392. $this->lMargin -= $this->listindent;
  19393. }
  19394. --$this->listindentlevel;
  19395. if ($this->listnum <= 0) {
  19396. $this->listnum = 0;
  19397. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19398. } else {
  19399. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19400. }
  19401. $this->resetLastH();
  19402. break;
  19403. }
  19404. case 'li': {
  19405. $this->lispacer = '';
  19406. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19407. break;
  19408. }
  19409. case 'h1':
  19410. case 'h2':
  19411. case 'h3':
  19412. case 'h4':
  19413. case 'h5':
  19414. case 'h6': {
  19415. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19416. break;
  19417. }
  19418. // Form fields (since 4.8.000 - 2009-09-07)
  19419. case 'form': {
  19420. $this->form_action = '';
  19421. $this->form_enctype = 'application/x-www-form-urlencoded';
  19422. break;
  19423. }
  19424. default : {
  19425. break;
  19426. }
  19427. }
  19428. // draw border and background (if any)
  19429. $this->drawHTMLTagBorder($parent, $xmax);
  19430. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  19431. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  19432. // check for pagebreak
  19433. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  19434. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19435. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19436. }
  19437. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  19438. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  19439. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19440. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19441. }
  19442. }
  19443. $this->tmprtl = false;
  19444. return $dom;
  19445. }
  19446. /**
  19447. * Add vertical spaces if needed.
  19448. * @param string $hbz Distance between current y and line bottom.
  19449. * @param string $hb The height of the break.
  19450. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  19451. * @param boolean $firsttag set to true when the tag is the first.
  19452. * @param boolean $lasttag set to true when the tag is the last.
  19453. * @protected
  19454. */
  19455. protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
  19456. if ($firsttag) {
  19457. $this->Ln(0, $cell);
  19458. $this->htmlvspace = 0;
  19459. return;
  19460. }
  19461. if ($lasttag) {
  19462. $this->Ln($hbz, $cell);
  19463. $this->htmlvspace = 0;
  19464. return;
  19465. }
  19466. if ($hb < $this->htmlvspace) {
  19467. $hd = 0;
  19468. } else {
  19469. $hd = $hb - $this->htmlvspace;
  19470. $this->htmlvspace = $hb;
  19471. }
  19472. $this->Ln(($hbz + $hd), $cell);
  19473. }
  19474. /**
  19475. * Return the starting coordinates to draw an html border
  19476. * @return array containing top-left border coordinates
  19477. * @protected
  19478. * @since 5.7.000 (2010-08-03)
  19479. */
  19480. protected function getBorderStartPosition() {
  19481. if ($this->rtl) {
  19482. $xmax = $this->lMargin;
  19483. } else {
  19484. $xmax = $this->w - $this->rMargin;
  19485. }
  19486. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
  19487. }
  19488. /**
  19489. * Draw an HTML block border and fill
  19490. * @param array $tag array of tag properties.
  19491. * @param int $xmax end X coordinate for border.
  19492. * @protected
  19493. * @since 5.7.000 (2010-08-03)
  19494. */
  19495. protected function drawHTMLTagBorder($tag, $xmax) {
  19496. if (!isset($tag['borderposition'])) {
  19497. // nothing to draw
  19498. return;
  19499. }
  19500. $prev_x = $this->x;
  19501. $prev_y = $this->y;
  19502. $prev_lasth = $this->lasth;
  19503. $border = 0;
  19504. $fill = false;
  19505. $this->lasth = 0;
  19506. if (isset($tag['border']) AND !empty($tag['border'])) {
  19507. // get border style
  19508. $border = $tag['border'];
  19509. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  19510. // border for table header
  19511. $border = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19512. }
  19513. }
  19514. if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  19515. // get background color
  19516. $old_bgcolor = $this->bgcolor;
  19517. $this->setFillColorArray($tag['bgcolor']);
  19518. $fill = true;
  19519. }
  19520. if (!$border AND !$fill) {
  19521. // nothing to draw
  19522. return;
  19523. }
  19524. if (isset($tag['attribute']['cellspacing'])) {
  19525. $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  19526. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  19527. } elseif (isset($tag['border-spacing'])) {
  19528. $cellspacing = $tag['border-spacing'];
  19529. } else {
  19530. $cellspacing = array('H' => 0, 'V' => 0);
  19531. }
  19532. if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  19533. // draw the border externally respect the sqare edge.
  19534. $border['mode'] = 'ext';
  19535. }
  19536. if ($this->rtl) {
  19537. if ($xmax >= $tag['borderposition']['x']) {
  19538. $xmax = $tag['borderposition']['xmax'];
  19539. }
  19540. $w = ($tag['borderposition']['x'] - $xmax);
  19541. } else {
  19542. if ($xmax <= $tag['borderposition']['x']) {
  19543. $xmax = $tag['borderposition']['xmax'];
  19544. }
  19545. $w = ($xmax - $tag['borderposition']['x']);
  19546. }
  19547. if ($w <= 0) {
  19548. return;
  19549. }
  19550. $w += $cellspacing['H'];
  19551. $startpage = $tag['borderposition']['page'];
  19552. $startcolumn = $tag['borderposition']['column'];
  19553. $x = $tag['borderposition']['x'];
  19554. $y = $tag['borderposition']['y'];
  19555. $endpage = $this->page;
  19556. $starty = $tag['borderposition']['y'] - $cellspacing['V'];
  19557. $currentY = $this->y;
  19558. $this->x = $x;
  19559. // get latest column
  19560. $endcolumn = $this->current_column;
  19561. if ($this->num_columns == 0) {
  19562. $this->num_columns = 1;
  19563. }
  19564. // get border modes
  19565. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19566. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19567. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19568. // temporary disable page regions
  19569. $temp_page_regions = $this->page_regions;
  19570. $this->page_regions = array();
  19571. // design borders around HTML cells.
  19572. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19573. $ccode = '';
  19574. $this->setPage($page);
  19575. if ($this->num_columns < 2) {
  19576. // single-column mode
  19577. $this->x = $x;
  19578. $this->y = $this->tMargin;
  19579. }
  19580. // account for margin changes
  19581. if ($page > $startpage) {
  19582. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19583. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19584. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19585. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19586. }
  19587. }
  19588. if ($startpage == $endpage) {
  19589. // single page
  19590. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19591. $this->selectColumn($column);
  19592. if ($startcolumn == $endcolumn) { // single column
  19593. $cborder = $border;
  19594. $h = ($currentY - $y) + $cellspacing['V'];
  19595. $this->y = $starty;
  19596. } elseif ($column == $startcolumn) { // first column
  19597. $cborder = $border_start;
  19598. $this->y = $starty;
  19599. $h = $this->h - $this->y - $this->bMargin;
  19600. } elseif ($column == $endcolumn) { // end column
  19601. $cborder = $border_end;
  19602. $h = $currentY - $this->y;
  19603. } else { // middle column
  19604. $cborder = $border_middle;
  19605. $h = $this->h - $this->y - $this->bMargin;
  19606. }
  19607. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19608. } // end for each column
  19609. } elseif ($page == $startpage) { // first page
  19610. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19611. $this->selectColumn($column);
  19612. if ($column == $startcolumn) { // first column
  19613. $cborder = $border_start;
  19614. $this->y = $starty;
  19615. $h = $this->h - $this->y - $this->bMargin;
  19616. } else { // middle column
  19617. $cborder = $border_middle;
  19618. $h = $this->h - $this->y - $this->bMargin;
  19619. }
  19620. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19621. } // end for each column
  19622. } elseif ($page == $endpage) { // last page
  19623. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19624. $this->selectColumn($column);
  19625. if ($column == $endcolumn) {
  19626. // end column
  19627. $cborder = $border_end;
  19628. $h = $currentY - $this->y;
  19629. } else {
  19630. // middle column
  19631. $cborder = $border_middle;
  19632. $h = $this->h - $this->y - $this->bMargin;
  19633. }
  19634. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19635. } // end for each column
  19636. } else { // middle page
  19637. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19638. $this->selectColumn($column);
  19639. $cborder = $border_middle;
  19640. $h = $this->h - $this->y - $this->bMargin;
  19641. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19642. } // end for each column
  19643. }
  19644. if ($cborder OR $fill) {
  19645. $offsetlen = strlen($ccode);
  19646. // draw border and fill
  19647. if ($this->inxobj) {
  19648. // we are inside an XObject template
  19649. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19650. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19651. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19652. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19653. } else {
  19654. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19655. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19656. }
  19657. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19658. $pstart = substr($pagebuff, 0, $pagemark);
  19659. $pend = substr($pagebuff, $pagemark);
  19660. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19661. } else {
  19662. if (end($this->transfmrk[$this->page]) !== false) {
  19663. $pagemarkkey = key($this->transfmrk[$this->page]);
  19664. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19665. } elseif ($this->InFooter) {
  19666. $pagemark = $this->footerpos[$this->page];
  19667. } else {
  19668. $pagemark = $this->intmrk[$this->page];
  19669. }
  19670. $pagebuff = $this->getPageBuffer($this->page);
  19671. $pstart = substr($pagebuff, 0, $pagemark);
  19672. $pend = substr($pagebuff, $pagemark);
  19673. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19674. $this->bordermrk[$this->page] += $offsetlen;
  19675. $this->cntmrk[$this->page] += $offsetlen;
  19676. }
  19677. }
  19678. } // end for each page
  19679. // restore page regions
  19680. $this->page_regions = $temp_page_regions;
  19681. if (isset($old_bgcolor)) {
  19682. // restore background color
  19683. $this->setFillColorArray($old_bgcolor);
  19684. }
  19685. // restore pointer position
  19686. $this->x = $prev_x;
  19687. $this->y = $prev_y;
  19688. $this->lasth = $prev_lasth;
  19689. }
  19690. /**
  19691. * Set the default bullet to be used as LI bullet symbol
  19692. * @param string $symbol 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')
  19693. * @public
  19694. * @since 4.0.028 (2008-09-26)
  19695. */
  19696. public function setLIsymbol($symbol='!') {
  19697. // check for custom image symbol
  19698. if (substr($symbol, 0, 4) == 'img|') {
  19699. $this->lisymbol = $symbol;
  19700. return;
  19701. }
  19702. $symbol = strtolower($symbol);
  19703. $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');
  19704. if (in_array($symbol, $valid_symbols)) {
  19705. $this->lisymbol = $symbol;
  19706. } else {
  19707. $this->lisymbol = '';
  19708. }
  19709. }
  19710. /**
  19711. * Set the booklet mode for double-sided pages.
  19712. * @param boolean $booklet true set the booklet mode on, false otherwise.
  19713. * @param float $inner Inner page margin.
  19714. * @param float $outer Outer page margin.
  19715. * @public
  19716. * @since 4.2.000 (2008-10-29)
  19717. */
  19718. public function setBooklet($booklet=true, $inner=-1, $outer=-1) {
  19719. $this->booklet = $booklet;
  19720. if ($inner >= 0) {
  19721. $this->lMargin = $inner;
  19722. }
  19723. if ($outer >= 0) {
  19724. $this->rMargin = $outer;
  19725. }
  19726. }
  19727. /**
  19728. * Swap the left and right margins.
  19729. * @param boolean $reverse if true swap left and right margins.
  19730. * @protected
  19731. * @since 4.2.000 (2008-10-29)
  19732. */
  19733. protected function swapMargins($reverse=true) {
  19734. if ($reverse) {
  19735. // swap left and right margins
  19736. $mtemp = $this->original_lMargin;
  19737. $this->original_lMargin = $this->original_rMargin;
  19738. $this->original_rMargin = $mtemp;
  19739. $deltam = $this->original_lMargin - $this->original_rMargin;
  19740. $this->lMargin += $deltam;
  19741. $this->rMargin -= $deltam;
  19742. }
  19743. }
  19744. /**
  19745. * Set the vertical spaces for HTML tags.
  19746. * The array must have the following structure (example):
  19747. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  19748. * The first array level contains the tag names,
  19749. * the second level contains 0 for opening tags or 1 for closing tags,
  19750. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  19751. * If the h parameter is not specified, default values are used.
  19752. * @param array $tagvs array of tags and relative vertical spaces.
  19753. * @public
  19754. * @since 4.2.001 (2008-10-30)
  19755. */
  19756. public function setHtmlVSpace($tagvs) {
  19757. $this->tagvspaces = $tagvs;
  19758. }
  19759. /**
  19760. * Set custom width for list indentation.
  19761. * @param float $width width of the indentation. Use negative value to disable it.
  19762. * @public
  19763. * @since 4.2.007 (2008-11-12)
  19764. */
  19765. public function setListIndentWidth($width) {
  19766. return $this->customlistindent = floatval($width);
  19767. }
  19768. /**
  19769. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  19770. * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page.
  19771. * @public
  19772. * @since 4.2.010 (2008-11-14)
  19773. */
  19774. public function setOpenCell($isopen) {
  19775. $this->opencell = $isopen;
  19776. }
  19777. /**
  19778. * Set the color and font style for HTML links.
  19779. * @param array $color RGB array of colors
  19780. * @param string $fontstyle additional font styles to add
  19781. * @public
  19782. * @since 4.4.003 (2008-12-09)
  19783. */
  19784. public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
  19785. $this->htmlLinkColorArray = $color;
  19786. $this->htmlLinkFontStyle = $fontstyle;
  19787. }
  19788. /**
  19789. * Convert HTML string containing value and unit of measure to user's units or points.
  19790. * @param string $htmlval String containing values and unit.
  19791. * @param string $refsize Reference value in points.
  19792. * @param string $defaultunit Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  19793. * @param boolean $points If true returns points, otherwise returns value in user's units.
  19794. * @return float value in user's unit or point if $points=true
  19795. * @public
  19796. * @since 4.4.004 (2008-12-10)
  19797. */
  19798. public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
  19799. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  19800. $retval = 0;
  19801. $value = 0;
  19802. $unit = 'px';
  19803. if ($points) {
  19804. $k = 1;
  19805. } else {
  19806. $k = $this->k;
  19807. }
  19808. if (in_array($defaultunit, $supportedunits)) {
  19809. $unit = $defaultunit;
  19810. }
  19811. if (is_numeric($htmlval)) {
  19812. $value = floatval($htmlval);
  19813. } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
  19814. $value = floatval($mnum[1]);
  19815. if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
  19816. if (in_array($munit[1], $supportedunits)) {
  19817. $unit = $munit[1];
  19818. }
  19819. }
  19820. }
  19821. switch ($unit) {
  19822. // percentage
  19823. case '%': {
  19824. $retval = (($value * $refsize) / 100);
  19825. break;
  19826. }
  19827. // relative-size
  19828. case 'em': {
  19829. $retval = ($value * $refsize);
  19830. break;
  19831. }
  19832. // height of lower case 'x' (about half the font-size)
  19833. case 'ex': {
  19834. $retval = ($value * ($refsize / 2));
  19835. break;
  19836. }
  19837. // absolute-size
  19838. case 'in': {
  19839. $retval = (($value * $this->dpi) / $k);
  19840. break;
  19841. }
  19842. // centimeters
  19843. case 'cm': {
  19844. $retval = (($value / 2.54 * $this->dpi) / $k);
  19845. break;
  19846. }
  19847. // millimeters
  19848. case 'mm': {
  19849. $retval = (($value / 25.4 * $this->dpi) / $k);
  19850. break;
  19851. }
  19852. // one pica is 12 points
  19853. case 'pc': {
  19854. $retval = (($value * 12) / $k);
  19855. break;
  19856. }
  19857. // points
  19858. case 'pt': {
  19859. $retval = ($value / $k);
  19860. break;
  19861. }
  19862. // pixels
  19863. case 'px': {
  19864. $retval = $this->pixelsToUnits($value);
  19865. if ($points) {
  19866. $retval *= $this->k;
  19867. }
  19868. break;
  19869. }
  19870. }
  19871. return $retval;
  19872. }
  19873. /**
  19874. * Output an HTML list bullet or ordered item symbol
  19875. * @param int $listdepth list nesting level
  19876. * @param string $listtype type of list
  19877. * @param float $size current font size
  19878. * @protected
  19879. * @since 4.4.004 (2008-12-10)
  19880. */
  19881. protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
  19882. if ($this->state != 2) {
  19883. return;
  19884. }
  19885. $size /= $this->k;
  19886. $fill = '';
  19887. $bgcolor = $this->bgcolor;
  19888. $color = $this->fgcolor;
  19889. $strokecolor = $this->strokecolor;
  19890. $width = 0;
  19891. $textitem = '';
  19892. $tmpx = $this->x;
  19893. $lspace = $this->GetStringWidth(' ');
  19894. if ($listtype == '^') {
  19895. // special symbol used for avoid justification of rect bullet
  19896. $this->lispacer = '';
  19897. return;
  19898. } elseif ($listtype == '!') {
  19899. // set default list type for unordered list
  19900. $deftypes = array('disc', 'circle', 'square');
  19901. $listtype = $deftypes[($listdepth - 1) % 3];
  19902. } elseif ($listtype == '#') {
  19903. // set default list type for ordered list
  19904. $listtype = 'decimal';
  19905. } elseif (substr($listtype, 0, 4) == 'img|') {
  19906. // custom image type ('img|type|width|height|image.ext')
  19907. $img = explode('|', $listtype);
  19908. $listtype = 'img';
  19909. }
  19910. switch ($listtype) {
  19911. // unordered types
  19912. case 'none': {
  19913. break;
  19914. }
  19915. case 'disc': {
  19916. $r = $size / 6;
  19917. $lspace += (2 * $r);
  19918. if ($this->rtl) {
  19919. $this->x += $lspace;
  19920. } else {
  19921. $this->x -= $lspace;
  19922. }
  19923. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
  19924. break;
  19925. }
  19926. case 'circle': {
  19927. $r = $size / 6;
  19928. $lspace += (2 * $r);
  19929. if ($this->rtl) {
  19930. $this->x += $lspace;
  19931. } else {
  19932. $this->x -= $lspace;
  19933. }
  19934. $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
  19935. $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
  19936. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
  19937. $this->_out($prev_line_style); // restore line settings
  19938. break;
  19939. }
  19940. case 'square': {
  19941. $l = $size / 3;
  19942. $lspace += $l;
  19943. if ($this->rtl) {;
  19944. $this->x += $lspace;
  19945. } else {
  19946. $this->x -= $lspace;
  19947. }
  19948. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  19949. break;
  19950. }
  19951. case 'img': {
  19952. // 1=>type, 2=>width, 3=>height, 4=>image.ext
  19953. $lspace += $img[2];
  19954. if ($this->rtl) {;
  19955. $this->x += $lspace;
  19956. } else {
  19957. $this->x -= $lspace;
  19958. }
  19959. $imgtype = strtolower($img[1]);
  19960. $prev_y = $this->y;
  19961. switch ($imgtype) {
  19962. case 'svg': {
  19963. $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
  19964. break;
  19965. }
  19966. case 'ai':
  19967. case 'eps': {
  19968. $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
  19969. break;
  19970. }
  19971. default: {
  19972. $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);
  19973. break;
  19974. }
  19975. }
  19976. $this->y = $prev_y;
  19977. break;
  19978. }
  19979. // ordered types
  19980. // $this->listcount[$this->listnum];
  19981. // $textitem
  19982. case '1':
  19983. case 'decimal': {
  19984. $textitem = $this->listcount[$this->listnum];
  19985. break;
  19986. }
  19987. case 'decimal-leading-zero': {
  19988. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  19989. break;
  19990. }
  19991. case 'i':
  19992. case 'lower-roman': {
  19993. $textitem = strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]));
  19994. break;
  19995. }
  19996. case 'I':
  19997. case 'upper-roman': {
  19998. $textitem = TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]);
  19999. break;
  20000. }
  20001. case 'a':
  20002. case 'lower-alpha':
  20003. case 'lower-latin': {
  20004. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  20005. break;
  20006. }
  20007. case 'A':
  20008. case 'upper-alpha':
  20009. case 'upper-latin': {
  20010. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  20011. break;
  20012. }
  20013. case 'lower-greek': {
  20014. $textitem = TCPDF_FONTS::unichr((945 + $this->listcount[$this->listnum] - 1), $this->isunicode);
  20015. break;
  20016. }
  20017. /*
  20018. // Types to be implemented (special handling)
  20019. case 'hebrew': {
  20020. break;
  20021. }
  20022. case 'armenian': {
  20023. break;
  20024. }
  20025. case 'georgian': {
  20026. break;
  20027. }
  20028. case 'cjk-ideographic': {
  20029. break;
  20030. }
  20031. case 'hiragana': {
  20032. break;
  20033. }
  20034. case 'katakana': {
  20035. break;
  20036. }
  20037. case 'hiragana-iroha': {
  20038. break;
  20039. }
  20040. case 'katakana-iroha': {
  20041. break;
  20042. }
  20043. */
  20044. default: {
  20045. $textitem = $this->listcount[$this->listnum];
  20046. }
  20047. }
  20048. if (!TCPDF_STATIC::empty_string($textitem)) {
  20049. // Check whether we need a new page or new column
  20050. $prev_y = $this->y;
  20051. $h = $this->getCellHeight($this->FontSize);
  20052. if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
  20053. $tmpx = $this->x;
  20054. }
  20055. // print ordered item
  20056. if ($this->rtl) {
  20057. $textitem = '.'.$textitem;
  20058. } else {
  20059. $textitem = $textitem.'.';
  20060. }
  20061. $lspace += $this->GetStringWidth($textitem);
  20062. if ($this->rtl) {
  20063. $this->x += $lspace;
  20064. } else {
  20065. $this->x -= $lspace;
  20066. }
  20067. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  20068. }
  20069. $this->x = $tmpx;
  20070. $this->lispacer = '^';
  20071. // restore colors
  20072. $this->setFillColorArray($bgcolor);
  20073. $this->setDrawColorArray($strokecolor);
  20074. $this->settextColorArray($color);
  20075. }
  20076. /**
  20077. * Returns current graphic variables as array.
  20078. * @return array of graphic variables
  20079. * @protected
  20080. * @since 4.2.010 (2008-11-14)
  20081. */
  20082. protected function getGraphicVars() {
  20083. $grapvars = array(
  20084. 'FontFamily' => $this->FontFamily,
  20085. 'FontStyle' => $this->FontStyle,
  20086. 'FontSizePt' => $this->FontSizePt,
  20087. 'rMargin' => $this->rMargin,
  20088. 'lMargin' => $this->lMargin,
  20089. 'cell_padding' => $this->cell_padding,
  20090. 'cell_margin' => $this->cell_margin,
  20091. 'LineWidth' => $this->LineWidth,
  20092. 'linestyleWidth' => $this->linestyleWidth,
  20093. 'linestyleCap' => $this->linestyleCap,
  20094. 'linestyleJoin' => $this->linestyleJoin,
  20095. 'linestyleDash' => $this->linestyleDash,
  20096. 'textrendermode' => $this->textrendermode,
  20097. 'textstrokewidth' => $this->textstrokewidth,
  20098. 'DrawColor' => $this->DrawColor,
  20099. 'FillColor' => $this->FillColor,
  20100. 'TextColor' => $this->TextColor,
  20101. 'ColorFlag' => $this->ColorFlag,
  20102. 'bgcolor' => $this->bgcolor,
  20103. 'fgcolor' => $this->fgcolor,
  20104. 'htmlvspace' => $this->htmlvspace,
  20105. 'listindent' => $this->listindent,
  20106. 'listindentlevel' => $this->listindentlevel,
  20107. 'listnum' => $this->listnum,
  20108. 'listordered' => $this->listordered,
  20109. 'listcount' => $this->listcount,
  20110. 'lispacer' => $this->lispacer,
  20111. 'cell_height_ratio' => $this->cell_height_ratio,
  20112. 'font_stretching' => $this->font_stretching,
  20113. 'font_spacing' => $this->font_spacing,
  20114. 'alpha' => $this->alpha,
  20115. // extended
  20116. 'lasth' => $this->lasth,
  20117. 'tMargin' => $this->tMargin,
  20118. 'bMargin' => $this->bMargin,
  20119. 'AutoPageBreak' => $this->AutoPageBreak,
  20120. 'PageBreakTrigger' => $this->PageBreakTrigger,
  20121. 'x' => $this->x,
  20122. 'y' => $this->y,
  20123. 'w' => $this->w,
  20124. 'h' => $this->h,
  20125. 'wPt' => $this->wPt,
  20126. 'hPt' => $this->hPt,
  20127. 'fwPt' => $this->fwPt,
  20128. 'fhPt' => $this->fhPt,
  20129. 'page' => $this->page,
  20130. 'current_column' => $this->current_column,
  20131. 'num_columns' => $this->num_columns
  20132. );
  20133. return $grapvars;
  20134. }
  20135. /**
  20136. * Set graphic variables.
  20137. * @param array $gvars array of graphic variablesto restore
  20138. * @param boolean $extended if true restore extended graphic variables
  20139. * @protected
  20140. * @since 4.2.010 (2008-11-14)
  20141. */
  20142. protected function setGraphicVars($gvars, $extended=false) {
  20143. if ($this->state != 2) {
  20144. return;
  20145. }
  20146. $this->FontFamily = $gvars['FontFamily'];
  20147. $this->FontStyle = $gvars['FontStyle'];
  20148. $this->FontSizePt = $gvars['FontSizePt'];
  20149. $this->rMargin = $gvars['rMargin'];
  20150. $this->lMargin = $gvars['lMargin'];
  20151. $this->cell_padding = $gvars['cell_padding'];
  20152. $this->cell_margin = $gvars['cell_margin'];
  20153. $this->LineWidth = $gvars['LineWidth'];
  20154. $this->linestyleWidth = $gvars['linestyleWidth'];
  20155. $this->linestyleCap = $gvars['linestyleCap'];
  20156. $this->linestyleJoin = $gvars['linestyleJoin'];
  20157. $this->linestyleDash = $gvars['linestyleDash'];
  20158. $this->textrendermode = $gvars['textrendermode'];
  20159. $this->textstrokewidth = $gvars['textstrokewidth'];
  20160. $this->DrawColor = $gvars['DrawColor'];
  20161. $this->FillColor = $gvars['FillColor'];
  20162. $this->TextColor = $gvars['TextColor'];
  20163. $this->ColorFlag = $gvars['ColorFlag'];
  20164. $this->bgcolor = $gvars['bgcolor'];
  20165. $this->fgcolor = $gvars['fgcolor'];
  20166. $this->htmlvspace = $gvars['htmlvspace'];
  20167. $this->listindent = $gvars['listindent'];
  20168. $this->listindentlevel = $gvars['listindentlevel'];
  20169. $this->listnum = $gvars['listnum'];
  20170. $this->listordered = $gvars['listordered'];
  20171. $this->listcount = $gvars['listcount'];
  20172. $this->lispacer = $gvars['lispacer'];
  20173. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  20174. $this->font_stretching = $gvars['font_stretching'];
  20175. $this->font_spacing = $gvars['font_spacing'];
  20176. $this->alpha = $gvars['alpha'];
  20177. if ($extended) {
  20178. // restore extended values
  20179. $this->lasth = $gvars['lasth'];
  20180. $this->tMargin = $gvars['tMargin'];
  20181. $this->bMargin = $gvars['bMargin'];
  20182. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  20183. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  20184. $this->x = $gvars['x'];
  20185. $this->y = $gvars['y'];
  20186. $this->w = $gvars['w'];
  20187. $this->h = $gvars['h'];
  20188. $this->wPt = $gvars['wPt'];
  20189. $this->hPt = $gvars['hPt'];
  20190. $this->fwPt = $gvars['fwPt'];
  20191. $this->fhPt = $gvars['fhPt'];
  20192. $this->page = $gvars['page'];
  20193. $this->current_column = $gvars['current_column'];
  20194. $this->num_columns = $gvars['num_columns'];
  20195. }
  20196. $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  20197. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  20198. $this->setFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  20199. }
  20200. }
  20201. /**
  20202. * Outputs the "save graphics state" operator 'q'
  20203. * @protected
  20204. */
  20205. protected function _outSaveGraphicsState() {
  20206. $this->_out('q');
  20207. }
  20208. /**
  20209. * Outputs the "restore graphics state" operator 'Q'
  20210. * @protected
  20211. */
  20212. protected function _outRestoreGraphicsState() {
  20213. $this->_out('Q');
  20214. }
  20215. /**
  20216. * Set buffer content (always append data).
  20217. * @param string $data data
  20218. * @protected
  20219. * @since 4.5.000 (2009-01-02)
  20220. */
  20221. protected function setBuffer($data) {
  20222. $this->bufferlen += strlen($data);
  20223. $this->buffer .= $data;
  20224. }
  20225. /**
  20226. * Replace the buffer content
  20227. * @param string $data data
  20228. * @protected
  20229. * @since 5.5.000 (2010-06-22)
  20230. */
  20231. protected function replaceBuffer($data) {
  20232. $this->bufferlen = strlen($data);
  20233. $this->buffer = $data;
  20234. }
  20235. /**
  20236. * Get buffer content.
  20237. * @return string buffer content
  20238. * @protected
  20239. * @since 4.5.000 (2009-01-02)
  20240. */
  20241. protected function getBuffer() {
  20242. return $this->buffer;
  20243. }
  20244. /**
  20245. * Set page buffer content.
  20246. * @param int $page page number
  20247. * @param string $data page data
  20248. * @param boolean $append if true append data, false replace.
  20249. * @protected
  20250. * @since 4.5.000 (2008-12-31)
  20251. */
  20252. protected function setPageBuffer($page, $data, $append=false) {
  20253. if ($append) {
  20254. $this->pages[$page] .= $data;
  20255. } else {
  20256. $this->pages[$page] = $data;
  20257. }
  20258. if ($append AND isset($this->pagelen[$page])) {
  20259. $this->pagelen[$page] += strlen($data);
  20260. } else {
  20261. $this->pagelen[$page] = strlen($data);
  20262. }
  20263. }
  20264. /**
  20265. * Get page buffer content.
  20266. * @param int $page page number
  20267. * @return string page buffer content or false in case of error
  20268. * @protected
  20269. * @since 4.5.000 (2008-12-31)
  20270. */
  20271. protected function getPageBuffer($page) {
  20272. if (isset($this->pages[$page])) {
  20273. return $this->pages[$page];
  20274. }
  20275. return false;
  20276. }
  20277. /**
  20278. * Set image buffer content.
  20279. * @param string $image image key
  20280. * @param array $data image data
  20281. * @return int image index number
  20282. * @protected
  20283. * @since 4.5.000 (2008-12-31)
  20284. */
  20285. protected function setImageBuffer($image, $data) {
  20286. if (($data['i'] = array_search($image, $this->imagekeys)) === FALSE) {
  20287. $this->imagekeys[$this->numimages] = $image;
  20288. $data['i'] = $this->numimages;
  20289. ++$this->numimages;
  20290. }
  20291. $this->images[$image] = $data;
  20292. return $data['i'];
  20293. }
  20294. /**
  20295. * Set image buffer content for a specified sub-key.
  20296. * @param string $image image key
  20297. * @param string $key image sub-key
  20298. * @param array $data image data
  20299. * @protected
  20300. * @since 4.5.000 (2008-12-31)
  20301. */
  20302. protected function setImageSubBuffer($image, $key, $data) {
  20303. if (!isset($this->images[$image])) {
  20304. $this->setImageBuffer($image, array());
  20305. }
  20306. $this->images[$image][$key] = $data;
  20307. }
  20308. /**
  20309. * Get image buffer content.
  20310. * @param string $image image key
  20311. * @return string|false image buffer content or false in case of error
  20312. * @protected
  20313. * @since 4.5.000 (2008-12-31)
  20314. */
  20315. protected function getImageBuffer($image) {
  20316. if (isset($this->images[$image])) {
  20317. return $this->images[$image];
  20318. }
  20319. return false;
  20320. }
  20321. /**
  20322. * Set font buffer content.
  20323. * @param string $font font key
  20324. * @param array $data font data
  20325. * @protected
  20326. * @since 4.5.000 (2009-01-02)
  20327. */
  20328. protected function setFontBuffer($font, $data) {
  20329. $this->fonts[$font] = $data;
  20330. if (!in_array($font, $this->fontkeys)) {
  20331. $this->fontkeys[] = $font;
  20332. // store object ID for current font
  20333. ++$this->n;
  20334. $this->font_obj_ids[$font] = $this->n;
  20335. $this->setFontSubBuffer($font, 'n', $this->n);
  20336. }
  20337. }
  20338. /**
  20339. * Set font buffer content.
  20340. * @param string $font font key
  20341. * @param string $key font sub-key
  20342. * @param mixed $data font data
  20343. * @protected
  20344. * @since 4.5.000 (2009-01-02)
  20345. */
  20346. protected function setFontSubBuffer($font, $key, $data) {
  20347. if (!isset($this->fonts[$font])) {
  20348. $this->setFontBuffer($font, array());
  20349. }
  20350. $this->fonts[$font][$key] = $data;
  20351. }
  20352. /**
  20353. * Get font buffer content.
  20354. * @param string $font font key
  20355. * @return string|false font buffer content or false in case of error
  20356. * @protected
  20357. * @since 4.5.000 (2009-01-02)
  20358. */
  20359. protected function getFontBuffer($font) {
  20360. if (isset($this->fonts[$font])) {
  20361. return $this->fonts[$font];
  20362. }
  20363. return false;
  20364. }
  20365. /**
  20366. * Move a page to a previous position.
  20367. * @param int $frompage number of the source page
  20368. * @param int $topage number of the destination page (must be less than $frompage)
  20369. * @return bool true in case of success, false in case of error.
  20370. * @public
  20371. * @since 4.5.000 (2009-01-02)
  20372. */
  20373. public function movePage($frompage, $topage) {
  20374. if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
  20375. return false;
  20376. }
  20377. if ($frompage == $this->page) {
  20378. // close the page before moving it
  20379. $this->endPage();
  20380. }
  20381. // move all page-related states
  20382. $tmppage = $this->getPageBuffer($frompage);
  20383. $tmppagedim = $this->pagedim[$frompage];
  20384. $tmppagelen = $this->pagelen[$frompage];
  20385. $tmpintmrk = $this->intmrk[$frompage];
  20386. $tmpbordermrk = $this->bordermrk[$frompage];
  20387. $tmpcntmrk = $this->cntmrk[$frompage];
  20388. $tmppageobjects = $this->pageobjects[$frompage];
  20389. if (isset($this->footerpos[$frompage])) {
  20390. $tmpfooterpos = $this->footerpos[$frompage];
  20391. }
  20392. if (isset($this->footerlen[$frompage])) {
  20393. $tmpfooterlen = $this->footerlen[$frompage];
  20394. }
  20395. if (isset($this->transfmrk[$frompage])) {
  20396. $tmptransfmrk = $this->transfmrk[$frompage];
  20397. }
  20398. if (isset($this->PageAnnots[$frompage])) {
  20399. $tmpannots = $this->PageAnnots[$frompage];
  20400. }
  20401. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20402. for ($i = $frompage; $i > $topage; --$i) {
  20403. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
  20404. --$this->pagegroups[$this->newpagegroup[$i]];
  20405. break;
  20406. }
  20407. }
  20408. for ($i = $topage; $i > 0; --$i) {
  20409. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
  20410. ++$this->pagegroups[$this->newpagegroup[$i]];
  20411. break;
  20412. }
  20413. }
  20414. }
  20415. for ($i = $frompage; $i > $topage; --$i) {
  20416. $j = $i - 1;
  20417. // shift pages down
  20418. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20419. $this->pagedim[$i] = $this->pagedim[$j];
  20420. $this->pagelen[$i] = $this->pagelen[$j];
  20421. $this->intmrk[$i] = $this->intmrk[$j];
  20422. $this->bordermrk[$i] = $this->bordermrk[$j];
  20423. $this->cntmrk[$i] = $this->cntmrk[$j];
  20424. $this->pageobjects[$i] = $this->pageobjects[$j];
  20425. if (isset($this->footerpos[$j])) {
  20426. $this->footerpos[$i] = $this->footerpos[$j];
  20427. } elseif (isset($this->footerpos[$i])) {
  20428. unset($this->footerpos[$i]);
  20429. }
  20430. if (isset($this->footerlen[$j])) {
  20431. $this->footerlen[$i] = $this->footerlen[$j];
  20432. } elseif (isset($this->footerlen[$i])) {
  20433. unset($this->footerlen[$i]);
  20434. }
  20435. if (isset($this->transfmrk[$j])) {
  20436. $this->transfmrk[$i] = $this->transfmrk[$j];
  20437. } elseif (isset($this->transfmrk[$i])) {
  20438. unset($this->transfmrk[$i]);
  20439. }
  20440. if (isset($this->PageAnnots[$j])) {
  20441. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20442. } elseif (isset($this->PageAnnots[$i])) {
  20443. unset($this->PageAnnots[$i]);
  20444. }
  20445. if (isset($this->newpagegroup[$j])) {
  20446. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20447. unset($this->newpagegroup[$j]);
  20448. }
  20449. if ($this->currpagegroup == $j) {
  20450. $this->currpagegroup = $i;
  20451. }
  20452. }
  20453. $this->setPageBuffer($topage, $tmppage);
  20454. $this->pagedim[$topage] = $tmppagedim;
  20455. $this->pagelen[$topage] = $tmppagelen;
  20456. $this->intmrk[$topage] = $tmpintmrk;
  20457. $this->bordermrk[$topage] = $tmpbordermrk;
  20458. $this->cntmrk[$topage] = $tmpcntmrk;
  20459. $this->pageobjects[$topage] = $tmppageobjects;
  20460. if (isset($tmpfooterpos)) {
  20461. $this->footerpos[$topage] = $tmpfooterpos;
  20462. } elseif (isset($this->footerpos[$topage])) {
  20463. unset($this->footerpos[$topage]);
  20464. }
  20465. if (isset($tmpfooterlen)) {
  20466. $this->footerlen[$topage] = $tmpfooterlen;
  20467. } elseif (isset($this->footerlen[$topage])) {
  20468. unset($this->footerlen[$topage]);
  20469. }
  20470. if (isset($tmptransfmrk)) {
  20471. $this->transfmrk[$topage] = $tmptransfmrk;
  20472. } elseif (isset($this->transfmrk[$topage])) {
  20473. unset($this->transfmrk[$topage]);
  20474. }
  20475. if (isset($tmpannots)) {
  20476. $this->PageAnnots[$topage] = $tmpannots;
  20477. } elseif (isset($this->PageAnnots[$topage])) {
  20478. unset($this->PageAnnots[$topage]);
  20479. }
  20480. // adjust outlines
  20481. $tmpoutlines = $this->outlines;
  20482. foreach ($tmpoutlines as $key => $outline) {
  20483. if (!$outline['f']) {
  20484. if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  20485. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  20486. } elseif ($outline['p'] == $frompage) {
  20487. $this->outlines[$key]['p'] = $topage;
  20488. }
  20489. }
  20490. }
  20491. // adjust dests
  20492. $tmpdests = $this->dests;
  20493. foreach ($tmpdests as $key => $dest) {
  20494. if (!$dest['f']) {
  20495. if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
  20496. $this->dests[$key]['p'] = ($dest['p'] + 1);
  20497. } elseif ($dest['p'] == $frompage) {
  20498. $this->dests[$key]['p'] = $topage;
  20499. }
  20500. }
  20501. }
  20502. // adjust links
  20503. $tmplinks = $this->links;
  20504. foreach ($tmplinks as $key => $link) {
  20505. if (!$link['f']) {
  20506. if (($link['p'] >= $topage) AND ($link['p'] < $frompage)) {
  20507. $this->links[$key]['p'] = ($link['p'] + 1);
  20508. } elseif ($link['p'] == $frompage) {
  20509. $this->links[$key]['p'] = $topage;
  20510. }
  20511. }
  20512. }
  20513. // adjust javascript
  20514. $jfrompage = $frompage;
  20515. $jtopage = $topage;
  20516. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20517. foreach($pamatch[0] as $pk => $pmatch) {
  20518. $pagenum = intval($pamatch[3][$pk]) + 1;
  20519. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  20520. $newpage = ($pagenum + 1);
  20521. } elseif ($pagenum == $jfrompage) {
  20522. $newpage = $jtopage;
  20523. } else {
  20524. $newpage = $pagenum;
  20525. }
  20526. --$newpage;
  20527. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20528. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20529. }
  20530. unset($pamatch);
  20531. }
  20532. // return to last page
  20533. $this->lastPage(true);
  20534. return true;
  20535. }
  20536. /**
  20537. * Remove the specified page.
  20538. * @param int $page page to remove
  20539. * @return bool true in case of success, false in case of error.
  20540. * @public
  20541. * @since 4.6.004 (2009-04-23)
  20542. */
  20543. public function deletePage($page) {
  20544. if (($page < 1) OR ($page > $this->numpages)) {
  20545. return false;
  20546. }
  20547. // delete current page
  20548. unset($this->pages[$page]);
  20549. unset($this->pagedim[$page]);
  20550. unset($this->pagelen[$page]);
  20551. unset($this->intmrk[$page]);
  20552. unset($this->bordermrk[$page]);
  20553. unset($this->cntmrk[$page]);
  20554. foreach ($this->pageobjects[$page] as $oid) {
  20555. if (isset($this->offsets[$oid])){
  20556. unset($this->offsets[$oid]);
  20557. }
  20558. }
  20559. unset($this->pageobjects[$page]);
  20560. if (isset($this->footerpos[$page])) {
  20561. unset($this->footerpos[$page]);
  20562. }
  20563. if (isset($this->footerlen[$page])) {
  20564. unset($this->footerlen[$page]);
  20565. }
  20566. if (isset($this->transfmrk[$page])) {
  20567. unset($this->transfmrk[$page]);
  20568. }
  20569. if (isset($this->PageAnnots[$page])) {
  20570. unset($this->PageAnnots[$page]);
  20571. }
  20572. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20573. for ($i = $page; $i > 0; --$i) {
  20574. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
  20575. --$this->pagegroups[$this->newpagegroup[$i]];
  20576. break;
  20577. }
  20578. }
  20579. }
  20580. if (isset($this->pageopen[$page])) {
  20581. unset($this->pageopen[$page]);
  20582. }
  20583. if ($page < $this->numpages) {
  20584. // update remaining pages
  20585. for ($i = $page; $i < $this->numpages; ++$i) {
  20586. $j = $i + 1;
  20587. // shift pages
  20588. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20589. $this->pagedim[$i] = $this->pagedim[$j];
  20590. $this->pagelen[$i] = $this->pagelen[$j];
  20591. $this->intmrk[$i] = $this->intmrk[$j];
  20592. $this->bordermrk[$i] = $this->bordermrk[$j];
  20593. $this->cntmrk[$i] = $this->cntmrk[$j];
  20594. $this->pageobjects[$i] = $this->pageobjects[$j];
  20595. if (isset($this->footerpos[$j])) {
  20596. $this->footerpos[$i] = $this->footerpos[$j];
  20597. } elseif (isset($this->footerpos[$i])) {
  20598. unset($this->footerpos[$i]);
  20599. }
  20600. if (isset($this->footerlen[$j])) {
  20601. $this->footerlen[$i] = $this->footerlen[$j];
  20602. } elseif (isset($this->footerlen[$i])) {
  20603. unset($this->footerlen[$i]);
  20604. }
  20605. if (isset($this->transfmrk[$j])) {
  20606. $this->transfmrk[$i] = $this->transfmrk[$j];
  20607. } elseif (isset($this->transfmrk[$i])) {
  20608. unset($this->transfmrk[$i]);
  20609. }
  20610. if (isset($this->PageAnnots[$j])) {
  20611. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20612. } elseif (isset($this->PageAnnots[$i])) {
  20613. unset($this->PageAnnots[$i]);
  20614. }
  20615. if (isset($this->newpagegroup[$j])) {
  20616. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20617. unset($this->newpagegroup[$j]);
  20618. }
  20619. if ($this->currpagegroup == $j) {
  20620. $this->currpagegroup = $i;
  20621. }
  20622. if (isset($this->pageopen[$j])) {
  20623. $this->pageopen[$i] = $this->pageopen[$j];
  20624. } elseif (isset($this->pageopen[$i])) {
  20625. unset($this->pageopen[$i]);
  20626. }
  20627. }
  20628. // remove last page
  20629. unset($this->pages[$this->numpages]);
  20630. unset($this->pagedim[$this->numpages]);
  20631. unset($this->pagelen[$this->numpages]);
  20632. unset($this->intmrk[$this->numpages]);
  20633. unset($this->bordermrk[$this->numpages]);
  20634. unset($this->cntmrk[$this->numpages]);
  20635. foreach ($this->pageobjects[$this->numpages] as $oid) {
  20636. if (isset($this->offsets[$oid])){
  20637. unset($this->offsets[$oid]);
  20638. }
  20639. }
  20640. unset($this->pageobjects[$this->numpages]);
  20641. if (isset($this->footerpos[$this->numpages])) {
  20642. unset($this->footerpos[$this->numpages]);
  20643. }
  20644. if (isset($this->footerlen[$this->numpages])) {
  20645. unset($this->footerlen[$this->numpages]);
  20646. }
  20647. if (isset($this->transfmrk[$this->numpages])) {
  20648. unset($this->transfmrk[$this->numpages]);
  20649. }
  20650. if (isset($this->PageAnnots[$this->numpages])) {
  20651. unset($this->PageAnnots[$this->numpages]);
  20652. }
  20653. if (isset($this->newpagegroup[$this->numpages])) {
  20654. unset($this->newpagegroup[$this->numpages]);
  20655. }
  20656. if ($this->currpagegroup == $this->numpages) {
  20657. $this->currpagegroup = ($this->numpages - 1);
  20658. }
  20659. if (isset($this->pagegroups[$this->numpages])) {
  20660. unset($this->pagegroups[$this->numpages]);
  20661. }
  20662. if (isset($this->pageopen[$this->numpages])) {
  20663. unset($this->pageopen[$this->numpages]);
  20664. }
  20665. }
  20666. --$this->numpages;
  20667. $this->page = $this->numpages;
  20668. // adjust outlines
  20669. $tmpoutlines = $this->outlines;
  20670. foreach ($tmpoutlines as $key => $outline) {
  20671. if (!$outline['f']) {
  20672. if ($outline['p'] > $page) {
  20673. $this->outlines[$key]['p'] = $outline['p'] - 1;
  20674. } elseif ($outline['p'] == $page) {
  20675. unset($this->outlines[$key]);
  20676. }
  20677. }
  20678. }
  20679. // adjust dests
  20680. $tmpdests = $this->dests;
  20681. foreach ($tmpdests as $key => $dest) {
  20682. if (!$dest['f']) {
  20683. if ($dest['p'] > $page) {
  20684. $this->dests[$key]['p'] = $dest['p'] - 1;
  20685. } elseif ($dest['p'] == $page) {
  20686. unset($this->dests[$key]);
  20687. }
  20688. }
  20689. }
  20690. // adjust links
  20691. $tmplinks = $this->links;
  20692. foreach ($tmplinks as $key => $link) {
  20693. if (!$link['f']) {
  20694. if ($link['p'] > $page) {
  20695. $this->links[$key]['p'] = $link['p'] - 1;
  20696. } elseif ($link['p'] == $page) {
  20697. unset($this->links[$key]);
  20698. }
  20699. }
  20700. }
  20701. // adjust javascript
  20702. $jpage = $page;
  20703. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20704. foreach($pamatch[0] as $pk => $pmatch) {
  20705. $pagenum = intval($pamatch[3][$pk]) + 1;
  20706. if ($pagenum >= $jpage) {
  20707. $newpage = ($pagenum - 1);
  20708. } elseif ($pagenum == $jpage) {
  20709. $newpage = 1;
  20710. } else {
  20711. $newpage = $pagenum;
  20712. }
  20713. --$newpage;
  20714. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20715. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20716. }
  20717. unset($pamatch);
  20718. }
  20719. // return to last page
  20720. if ($this->numpages > 0) {
  20721. $this->lastPage(true);
  20722. }
  20723. return true;
  20724. }
  20725. /**
  20726. * Clone the specified page to a new page.
  20727. * @param int $page number of page to copy (0 = current page)
  20728. * @return bool true in case of success, false in case of error.
  20729. * @public
  20730. * @since 4.9.015 (2010-04-20)
  20731. */
  20732. public function copyPage($page=0) {
  20733. if ($page == 0) {
  20734. // default value
  20735. $page = $this->page;
  20736. }
  20737. if (($page < 1) OR ($page > $this->numpages)) {
  20738. return false;
  20739. }
  20740. // close the last page
  20741. $this->endPage();
  20742. // copy all page-related states
  20743. ++$this->numpages;
  20744. $this->page = $this->numpages;
  20745. $this->setPageBuffer($this->page, $this->getPageBuffer($page));
  20746. $this->pagedim[$this->page] = $this->pagedim[$page];
  20747. $this->pagelen[$this->page] = $this->pagelen[$page];
  20748. $this->intmrk[$this->page] = $this->intmrk[$page];
  20749. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  20750. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  20751. $this->pageobjects[$this->page] = $this->pageobjects[$page];
  20752. $this->pageopen[$this->page] = false;
  20753. if (isset($this->footerpos[$page])) {
  20754. $this->footerpos[$this->page] = $this->footerpos[$page];
  20755. }
  20756. if (isset($this->footerlen[$page])) {
  20757. $this->footerlen[$this->page] = $this->footerlen[$page];
  20758. }
  20759. if (isset($this->transfmrk[$page])) {
  20760. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  20761. }
  20762. if (isset($this->PageAnnots[$page])) {
  20763. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  20764. }
  20765. if (isset($this->newpagegroup[$page])) {
  20766. // start a new group
  20767. $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
  20768. $this->currpagegroup = $this->newpagegroup[$this->page];
  20769. $this->pagegroups[$this->currpagegroup] = 1;
  20770. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  20771. ++$this->pagegroups[$this->currpagegroup];
  20772. }
  20773. // copy outlines
  20774. $tmpoutlines = $this->outlines;
  20775. foreach ($tmpoutlines as $key => $outline) {
  20776. if ($outline['p'] == $page) {
  20777. $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']);
  20778. }
  20779. }
  20780. // copy links
  20781. $tmplinks = $this->links;
  20782. foreach ($tmplinks as $key => $link) {
  20783. if ($link['p'] == $page) {
  20784. $this->links[] = array('p' => $this->page, 'y' => $link['y'], 'f' => $link['f']);
  20785. }
  20786. }
  20787. // return to last page
  20788. $this->lastPage(true);
  20789. return true;
  20790. }
  20791. /**
  20792. * Output a Table of Content Index (TOC).
  20793. * This method must be called after all Bookmarks were set.
  20794. * Before calling this method you have to open the page using the addTOCPage() method.
  20795. * After calling this method you have to call endTOCPage() to close the TOC page.
  20796. * You can override this method to achieve different styles.
  20797. * @param int|null $page page number where this TOC should be inserted (leave empty for current page).
  20798. * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment).
  20799. * @param string $filler string used to fill the space between text and page number.
  20800. * @param string $toc_name name to use for TOC bookmark.
  20801. * @param string $style Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20802. * @param array $color RGB color array for bookmark title (values from 0 to 255).
  20803. * @public
  20804. * @author Nicola Asuni
  20805. * @since 4.5.000 (2009-01-02)
  20806. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  20807. */
  20808. public function addTOC($page=null, $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
  20809. $fontsize = $this->FontSizePt;
  20810. $fontfamily = $this->FontFamily;
  20811. $fontstyle = $this->FontStyle;
  20812. $w = $this->w - $this->lMargin - $this->rMargin;
  20813. $spacer = $this->GetStringWidth(chr(32)) * 4;
  20814. $lmargin = $this->lMargin;
  20815. $rmargin = $this->rMargin;
  20816. $x_start = $this->GetX();
  20817. $page_first = $this->page;
  20818. $current_page = $this->page;
  20819. $page_fill_start = false;
  20820. $page_fill_end = false;
  20821. $current_column = $this->current_column;
  20822. if (TCPDF_STATIC::empty_string($numbersfont)) {
  20823. $numbersfont = $this->default_monospaced_font;
  20824. }
  20825. if (TCPDF_STATIC::empty_string($filler)) {
  20826. $filler = ' ';
  20827. }
  20828. if (TCPDF_STATIC::empty_string($page)) {
  20829. $gap = ' ';
  20830. } else {
  20831. $gap = '';
  20832. if ($page < 1) {
  20833. $page = 1;
  20834. }
  20835. }
  20836. $this->setFont($numbersfont, $fontstyle, $fontsize);
  20837. $numwidth = $this->GetStringWidth('00000');
  20838. $maxpage = 0; //used for pages on attached documents
  20839. foreach ($this->outlines as $key => $outline) {
  20840. // check for extra pages (used for attachments)
  20841. if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
  20842. $outline['p'] += ($this->page - $page_first);
  20843. }
  20844. if ($this->rtl) {
  20845. $aligntext = 'R';
  20846. $alignnum = 'L';
  20847. } else {
  20848. $aligntext = 'L';
  20849. $alignnum = 'R';
  20850. }
  20851. if ($outline['l'] == 0) {
  20852. $this->setFont($fontfamily, $outline['s'].'B', $fontsize);
  20853. } else {
  20854. $this->setFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
  20855. }
  20856. $this->setTextColorArray($outline['c']);
  20857. // check for page break
  20858. $this->checkPageBreak(2 * $this->getCellHeight($this->FontSize));
  20859. // set margins and X position
  20860. if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  20861. $this->lMargin = $lmargin;
  20862. $this->rMargin = $rmargin;
  20863. } else {
  20864. if ($this->current_column != $current_column) {
  20865. if ($this->rtl) {
  20866. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  20867. } else {
  20868. $x_start = $this->columns[$this->current_column]['x'];
  20869. }
  20870. }
  20871. $lmargin = $this->lMargin;
  20872. $rmargin = $this->rMargin;
  20873. $current_page = $this->page;
  20874. $current_column = $this->current_column;
  20875. }
  20876. $this->setX($x_start);
  20877. $indent = ($spacer * $outline['l']);
  20878. if ($this->rtl) {
  20879. $this->x -= $indent;
  20880. $this->rMargin = $this->w - $this->x;
  20881. } else {
  20882. $this->x += $indent;
  20883. $this->lMargin = $this->x;
  20884. }
  20885. $link = $this->AddLink();
  20886. $this->setLink($link, $outline['y'], $outline['p']);
  20887. // write the text
  20888. if ($this->rtl) {
  20889. $txt = ' '.$outline['t'];
  20890. } else {
  20891. $txt = $outline['t'].' ';
  20892. }
  20893. $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
  20894. if ($this->rtl) {
  20895. $tw = $this->x - $this->lMargin;
  20896. } else {
  20897. $tw = $this->w - $this->rMargin - $this->x;
  20898. }
  20899. $this->setFont($numbersfont, $fontstyle, $fontsize);
  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 ($this->isUnicodeFont()) {
  20906. $pagenum = '{'.$pagenum.'}';
  20907. }
  20908. $maxpage = max($maxpage, $outline['p']);
  20909. }
  20910. $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
  20911. $wfiller = $this->GetStringWidth($filler);
  20912. if ($wfiller > 0) {
  20913. $numfills = floor($fw / $wfiller);
  20914. } else {
  20915. $numfills = 0;
  20916. }
  20917. if ($numfills > 0) {
  20918. $rowfill = str_repeat($filler, $numfills);
  20919. } else {
  20920. $rowfill = '';
  20921. }
  20922. if ($this->rtl) {
  20923. $pagenum = $pagenum.$gap.$rowfill;
  20924. } else {
  20925. $pagenum = $rowfill.$gap.$pagenum;
  20926. }
  20927. // write the number
  20928. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  20929. }
  20930. $page_last = $this->getPage();
  20931. $numpages = ($page_last - $page_first + 1);
  20932. // account for booklet mode
  20933. if ($this->booklet) {
  20934. // check if a blank page is required before TOC
  20935. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  20936. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  20937. if ($page_fill_start) {
  20938. // add a page at the end (to be moved before TOC)
  20939. $this->addPage();
  20940. ++$page_last;
  20941. ++$numpages;
  20942. }
  20943. if ($page_fill_end) {
  20944. // add a page at the end
  20945. $this->addPage();
  20946. ++$page_last;
  20947. ++$numpages;
  20948. }
  20949. }
  20950. $maxpage = max($maxpage, $page_last);
  20951. if (!TCPDF_STATIC::empty_string($page)) {
  20952. for ($p = $page_first; $p <= $page_last; ++$p) {
  20953. // get page data
  20954. $temppage = $this->getPageBuffer($p);
  20955. for ($n = 1; $n <= $maxpage; ++$n) {
  20956. // update page numbers
  20957. $a = '{#'.$n.'}';
  20958. // get page number aliases
  20959. $pnalias = $this->getInternalPageNumberAliases($a);
  20960. // calculate replacement number
  20961. if (($n >= $page) AND ($n <= $this->numpages)) {
  20962. $np = $n + $numpages;
  20963. } else {
  20964. $np = $n;
  20965. }
  20966. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  20967. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  20968. // replace aliases with numbers
  20969. foreach ($pnalias['u'] as $u) {
  20970. $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
  20971. if ($this->rtl) {
  20972. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  20973. } else {
  20974. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  20975. }
  20976. $temppage = str_replace($u, $nr, $temppage);
  20977. }
  20978. foreach ($pnalias['a'] as $a) {
  20979. $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
  20980. if ($this->rtl) {
  20981. $nr = $na.' '.$sfill;
  20982. } else {
  20983. $nr = $sfill.' '.$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. * Output a Table Of Content Index (TOC) using HTML templates.
  21003. * This method must be called after all Bookmarks were set.
  21004. * Before calling this method you have to open the page using the addTOCPage() method.
  21005. * After calling this method you have to call endTOCPage() to close the TOC page.
  21006. * @param int|null $page page number where this TOC should be inserted (leave empty for current page).
  21007. * @param string $toc_name name to use for TOC bookmark.
  21008. * @param array $templates array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  21009. * @param boolean $correct_align if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL)
  21010. * @param string $style Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  21011. * @param array $color RGB color array for title (values from 0 to 255).
  21012. * @public
  21013. * @author Nicola Asuni
  21014. * @since 5.0.001 (2010-05-06)
  21015. * @see addTOCPage(), endTOCPage(), addTOC()
  21016. */
  21017. public function addHTMLTOC($page=null, $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
  21018. $filler = ' ';
  21019. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  21020. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  21021. // set new style for link
  21022. $this->htmlLinkColorArray = array();
  21023. $this->htmlLinkFontStyle = '';
  21024. $page_first = $this->getPage();
  21025. $page_fill_start = false;
  21026. $page_fill_end = false;
  21027. // get the font type used for numbers in each template
  21028. $current_font = $this->FontFamily;
  21029. foreach ($templates as $level => $html) {
  21030. $dom = $this->getHtmlDomArray($html);
  21031. foreach ($dom as $key => $value) {
  21032. if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  21033. $this->setFont($dom[($key - 1)]['fontname']);
  21034. $templates['F'.$level] = $this->isUnicodeFont();
  21035. }
  21036. }
  21037. }
  21038. $this->setFont($current_font);
  21039. $maxpage = 0; //used for pages on attached documents
  21040. foreach ($this->outlines as $key => $outline) {
  21041. // get HTML template
  21042. $row = $templates[$outline['l']];
  21043. if (TCPDF_STATIC::empty_string($page)) {
  21044. $pagenum = $outline['p'];
  21045. } else {
  21046. // placemark to be replaced with the correct number
  21047. $pagenum = '{#'.($outline['p']).'}';
  21048. if (isset($templates['F'.$outline['l']]) && $templates['F'.$outline['l']]) {
  21049. $pagenum = '{'.$pagenum.'}';
  21050. }
  21051. $maxpage = max($maxpage, $outline['p']);
  21052. }
  21053. // replace templates with current values
  21054. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  21055. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  21056. // add link to page
  21057. $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  21058. // write bookmark entry
  21059. $this->writeHTML($row, false, false, true, false, '');
  21060. }
  21061. // restore link styles
  21062. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  21063. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  21064. // move TOC page and replace numbers
  21065. $page_last = $this->getPage();
  21066. $numpages = ($page_last - $page_first + 1);
  21067. // account for booklet mode
  21068. if ($this->booklet) {
  21069. // check if a blank page is required before TOC
  21070. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  21071. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  21072. if ($page_fill_start) {
  21073. // add a page at the end (to be moved before TOC)
  21074. $this->addPage();
  21075. ++$page_last;
  21076. ++$numpages;
  21077. }
  21078. if ($page_fill_end) {
  21079. // add a page at the end
  21080. $this->addPage();
  21081. ++$page_last;
  21082. ++$numpages;
  21083. }
  21084. }
  21085. $maxpage = max($maxpage, $page_last);
  21086. if (!TCPDF_STATIC::empty_string($page)) {
  21087. for ($p = $page_first; $p <= $page_last; ++$p) {
  21088. // get page data
  21089. $temppage = $this->getPageBuffer($p);
  21090. for ($n = 1; $n <= $maxpage; ++$n) {
  21091. // update page numbers
  21092. $a = '{#'.$n.'}';
  21093. // get page number aliases
  21094. $pnalias = $this->getInternalPageNumberAliases($a);
  21095. // calculate replacement number
  21096. if ($n >= $page) {
  21097. $np = $n + $numpages;
  21098. } else {
  21099. $np = $n;
  21100. }
  21101. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  21102. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  21103. // replace aliases with numbers
  21104. foreach ($pnalias['u'] as $u) {
  21105. if ($correct_align) {
  21106. $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
  21107. if ($this->rtl) {
  21108. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  21109. } else {
  21110. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  21111. }
  21112. } else {
  21113. $nr = $nu;
  21114. }
  21115. $temppage = str_replace($u, $nr, $temppage);
  21116. }
  21117. foreach ($pnalias['a'] as $a) {
  21118. if ($correct_align) {
  21119. $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
  21120. if ($this->rtl) {
  21121. $nr = $na.' '.$sfill;
  21122. } else {
  21123. $nr = $sfill.' '.$na;
  21124. }
  21125. } else {
  21126. $nr = $na;
  21127. }
  21128. $temppage = str_replace($a, $nr, $temppage);
  21129. }
  21130. }
  21131. // save changes
  21132. $this->setPageBuffer($p, $temppage);
  21133. }
  21134. // move pages
  21135. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  21136. if ($page_fill_start) {
  21137. $this->movePage($page_last, $page_first);
  21138. }
  21139. for ($i = 0; $i < $numpages; ++$i) {
  21140. $this->movePage($page_last, $page);
  21141. }
  21142. }
  21143. }
  21144. /**
  21145. * Stores a copy of the current TCPDF object used for undo operation.
  21146. * @public
  21147. * @since 4.5.029 (2009-03-19)
  21148. */
  21149. public function startTransaction() {
  21150. if (isset($this->objcopy)) {
  21151. // remove previous copy
  21152. $this->commitTransaction();
  21153. }
  21154. // record current page number and Y position
  21155. $this->start_transaction_page = $this->page;
  21156. $this->start_transaction_y = $this->y;
  21157. // clone current object
  21158. $this->objcopy = TCPDF_STATIC::objclone($this);
  21159. }
  21160. /**
  21161. * Delete the copy of the current TCPDF object used for undo operation.
  21162. * @public
  21163. * @since 4.5.029 (2009-03-19)
  21164. */
  21165. public function commitTransaction() {
  21166. if (isset($this->objcopy)) {
  21167. $this->objcopy->_destroy(true, true);
  21168. /* The unique file_id should not be used during cleanup again */
  21169. $this->objcopy->file_id = NULL;
  21170. unset($this->objcopy);
  21171. }
  21172. }
  21173. /**
  21174. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  21175. * @param boolean $self if true restores current class object to previous state without the need of reassignment via the returned value.
  21176. * @return TCPDF object.
  21177. * @public
  21178. * @since 4.5.029 (2009-03-19)
  21179. */
  21180. public function rollbackTransaction($self=false) {
  21181. if (isset($this->objcopy)) {
  21182. $objcopy = $this->objcopy;
  21183. $this->_destroy(true, true);
  21184. if ($self) {
  21185. $objvars = get_object_vars($objcopy);
  21186. foreach ($objvars as $key => $value) {
  21187. $this->$key = $value;
  21188. }
  21189. $objcopy->_destroy(true, true);
  21190. /* The unique file_id should not be used during cleanup again */
  21191. $objcopy->file_id = NULL;
  21192. unset($objcopy);
  21193. return $this;
  21194. }
  21195. /* The unique file_id should not be used during cleanup again */
  21196. $this->file_id = NULL;
  21197. return $objcopy;
  21198. }
  21199. return $this;
  21200. }
  21201. // --- MULTI COLUMNS METHODS -----------------------
  21202. /**
  21203. * Set multiple columns of the same size
  21204. * @param int $numcols number of columns (set to zero to disable columns mode)
  21205. * @param int $width column width
  21206. * @param int|null $y column starting Y position (leave empty for current Y position)
  21207. * @public
  21208. * @since 4.9.001 (2010-03-28)
  21209. */
  21210. public function setEqualColumns($numcols=0, $width=0, $y=null) {
  21211. $this->columns = array();
  21212. if ($numcols < 2) {
  21213. $numcols = 0;
  21214. $this->columns = array();
  21215. } else {
  21216. // maximum column width
  21217. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  21218. if (($width == 0) OR ($width > $maxwidth)) {
  21219. $width = $maxwidth;
  21220. }
  21221. if (TCPDF_STATIC::empty_string($y)) {
  21222. $y = $this->y;
  21223. }
  21224. // space between columns
  21225. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  21226. // fill the columns array (with, space, starting Y position)
  21227. for ($i = 0; $i < $numcols; ++$i) {
  21228. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  21229. }
  21230. }
  21231. $this->num_columns = $numcols;
  21232. $this->current_column = 0;
  21233. $this->column_start_page = $this->page;
  21234. $this->selectColumn(0);
  21235. }
  21236. /**
  21237. * Remove columns and reset page margins.
  21238. * @public
  21239. * @since 5.9.072 (2011-04-26)
  21240. */
  21241. public function resetColumns() {
  21242. $this->lMargin = $this->original_lMargin;
  21243. $this->rMargin = $this->original_rMargin;
  21244. $this->setEqualColumns();
  21245. }
  21246. /**
  21247. * Set columns array.
  21248. * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  21249. * @param array $columns
  21250. * @public
  21251. * @since 4.9.001 (2010-03-28)
  21252. */
  21253. public function setColumnsArray($columns) {
  21254. $this->columns = $columns;
  21255. $this->num_columns = count($columns);
  21256. $this->current_column = 0;
  21257. $this->column_start_page = $this->page;
  21258. $this->selectColumn(0);
  21259. }
  21260. /**
  21261. * Set position at a given column
  21262. * @param int|null $col column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  21263. * @public
  21264. * @since 4.9.001 (2010-03-28)
  21265. */
  21266. public function selectColumn($col=null) {
  21267. if (TCPDF_STATIC::empty_string($col)) {
  21268. $col = $this->current_column;
  21269. } elseif ($col >= $this->num_columns) {
  21270. $col = 0;
  21271. }
  21272. $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  21273. $enable_thead = false;
  21274. if ($this->num_columns > 1) {
  21275. if ($col != $this->current_column) {
  21276. // move Y pointer at the top of the column
  21277. if ($this->column_start_page == $this->page) {
  21278. $this->y = $this->columns[$col]['y'];
  21279. } else {
  21280. $this->y = $this->tMargin;
  21281. }
  21282. // Avoid to write table headers more than once
  21283. if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
  21284. $enable_thead = true;
  21285. $this->maxselcol['page'] = $this->page;
  21286. $this->maxselcol['column'] = $col;
  21287. }
  21288. }
  21289. $xshift = $this->colxshift;
  21290. // set X position of the current column by case
  21291. $listindent = ($this->listindentlevel * $this->listindent);
  21292. // calculate column X position
  21293. $colpos = 0;
  21294. for ($i = 0; $i < $col; ++$i) {
  21295. $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
  21296. }
  21297. if ($this->rtl) {
  21298. $x = $this->w - $this->original_rMargin - $colpos;
  21299. $this->rMargin = ($this->w - $x + $listindent);
  21300. $this->lMargin = ($x - $this->columns[$col]['w']);
  21301. $this->x = $x - $listindent;
  21302. } else {
  21303. $x = $this->original_lMargin + $colpos;
  21304. $this->lMargin = ($x + $listindent);
  21305. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  21306. $this->x = $x + $listindent;
  21307. }
  21308. $this->columns[$col]['x'] = $x;
  21309. }
  21310. $this->current_column = $col;
  21311. // fix for HTML mode
  21312. $this->newline = true;
  21313. // print HTML table header (if any)
  21314. if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) {
  21315. if ($enable_thead) {
  21316. // print table header
  21317. $this->writeHTML($this->thead, false, false, false, false, '');
  21318. $this->y += $xshift['s']['V'];
  21319. // store end of header position
  21320. if (!isset($this->columns[$col]['th'])) {
  21321. $this->columns[$col]['th'] = array();
  21322. }
  21323. $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  21324. $this->lasth = 0;
  21325. } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  21326. $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
  21327. }
  21328. }
  21329. // account for an html table cell over multiple columns
  21330. if ($this->rtl) {
  21331. $this->rMargin += $xshift['x'];
  21332. $this->x -= ($xshift['x'] + $xshift['p']['R']);
  21333. } else {
  21334. $this->lMargin += $xshift['x'];
  21335. $this->x += $xshift['x'] + $xshift['p']['L'];
  21336. }
  21337. }
  21338. /**
  21339. * Return the current column number
  21340. * @return int current column number
  21341. * @public
  21342. * @since 5.5.011 (2010-07-08)
  21343. */
  21344. public function getColumn() {
  21345. return $this->current_column;
  21346. }
  21347. /**
  21348. * Return the current number of columns.
  21349. * @return int number of columns
  21350. * @public
  21351. * @since 5.8.018 (2010-08-25)
  21352. */
  21353. public function getNumberOfColumns() {
  21354. return $this->num_columns;
  21355. }
  21356. /**
  21357. * Set Text rendering mode.
  21358. * @param int $stroke outline size in user units (0 = disable).
  21359. * @param boolean $fill if true fills the text (default).
  21360. * @param boolean $clip if true activate clipping mode
  21361. * @public
  21362. * @since 4.9.008 (2009-04-02)
  21363. */
  21364. public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
  21365. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  21366. // convert text rendering parameters
  21367. if ($stroke < 0) {
  21368. $stroke = 0;
  21369. }
  21370. if ($fill === true) {
  21371. if ($stroke > 0) {
  21372. if ($clip === true) {
  21373. // Fill, then stroke text and add to path for clipping
  21374. $textrendermode = 6;
  21375. } else {
  21376. // Fill, then stroke text
  21377. $textrendermode = 2;
  21378. }
  21379. $textstrokewidth = $stroke;
  21380. } else {
  21381. if ($clip === true) {
  21382. // Fill text and add to path for clipping
  21383. $textrendermode = 4;
  21384. } else {
  21385. // Fill text
  21386. $textrendermode = 0;
  21387. }
  21388. }
  21389. } else {
  21390. if ($stroke > 0) {
  21391. if ($clip === true) {
  21392. // Stroke text and add to path for clipping
  21393. $textrendermode = 5;
  21394. } else {
  21395. // Stroke text
  21396. $textrendermode = 1;
  21397. }
  21398. $textstrokewidth = $stroke;
  21399. } else {
  21400. if ($clip === true) {
  21401. // Add text to path for clipping
  21402. $textrendermode = 7;
  21403. } else {
  21404. // Neither fill nor stroke text (invisible)
  21405. $textrendermode = 3;
  21406. }
  21407. }
  21408. }
  21409. $this->textrendermode = $textrendermode;
  21410. $this->textstrokewidth = $stroke;
  21411. }
  21412. /**
  21413. * Set parameters for drop shadow effect for text.
  21414. * @param array $params 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.
  21415. * @since 5.9.174 (2012-07-25)
  21416. * @public
  21417. */
  21418. public function setTextShadow($params=array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal')) {
  21419. if (isset($params['enabled'])) {
  21420. $this->txtshadow['enabled'] = $params['enabled']?true:false;
  21421. } else {
  21422. $this->txtshadow['enabled'] = false;
  21423. }
  21424. if (isset($params['depth_w'])) {
  21425. $this->txtshadow['depth_w'] = floatval($params['depth_w']);
  21426. } else {
  21427. $this->txtshadow['depth_w'] = 0;
  21428. }
  21429. if (isset($params['depth_h'])) {
  21430. $this->txtshadow['depth_h'] = floatval($params['depth_h']);
  21431. } else {
  21432. $this->txtshadow['depth_h'] = 0;
  21433. }
  21434. if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
  21435. $this->txtshadow['color'] = $params['color'];
  21436. } else {
  21437. $this->txtshadow['color'] = $this->strokecolor;
  21438. }
  21439. if (isset($params['opacity'])) {
  21440. $this->txtshadow['opacity'] = min(1, max(0, floatval($params['opacity'])));
  21441. } else {
  21442. $this->txtshadow['opacity'] = 1;
  21443. }
  21444. 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'))) {
  21445. $this->txtshadow['blend_mode'] = $params['blend_mode'];
  21446. } else {
  21447. $this->txtshadow['blend_mode'] = 'Normal';
  21448. }
  21449. if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
  21450. $this->txtshadow['enabled'] = false;
  21451. }
  21452. }
  21453. /**
  21454. * Return the text shadow parameters array.
  21455. * @return array array of parameters.
  21456. * @since 5.9.174 (2012-07-25)
  21457. * @public
  21458. */
  21459. public function getTextShadow() {
  21460. return $this->txtshadow;
  21461. }
  21462. /**
  21463. * Returns an array of chars containing soft hyphens.
  21464. * @param array $word array of chars
  21465. * @param array $patterns Array of hypenation patterns.
  21466. * @param array $dictionary Array of words to be returned without applying the hyphenation algorithm.
  21467. * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
  21468. * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
  21469. * @param int $charmin Minimum word length to apply the hyphenation algorithm.
  21470. * @param int $charmax Maximum length of broken piece of word.
  21471. * @return array text with soft hyphens
  21472. * @author Nicola Asuni
  21473. * @since 4.9.012 (2010-04-12)
  21474. * @protected
  21475. */
  21476. protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21477. $hyphenword = array(); // hyphens positions
  21478. $numchars = count($word);
  21479. if ($numchars <= $charmin) {
  21480. return $word;
  21481. }
  21482. $word_string = TCPDF_FONTS::UTF8ArrSubString($word, '', '', $this->isunicode);
  21483. // some words will be returned as-is
  21484. $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})(\]?)$/';
  21485. if (preg_match($pattern, $word_string) > 0) {
  21486. // email
  21487. return $word;
  21488. }
  21489. $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})(\]?)$/';
  21490. if (preg_match($pattern, $word_string) > 0) {
  21491. // URL
  21492. return $word;
  21493. }
  21494. if (isset($dictionary[$word_string])) {
  21495. return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont);
  21496. }
  21497. // surround word with '_' characters
  21498. $tmpword = array_merge(array(46), $word, array(46));
  21499. $tmpnumchars = $numchars + 2;
  21500. $maxpos = $tmpnumchars - 1;
  21501. for ($pos = 0; $pos < $maxpos; ++$pos) {
  21502. $imax = min(($tmpnumchars - $pos), $charmax);
  21503. for ($i = 1; $i <= $imax; ++$i) {
  21504. $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode));
  21505. if (isset($patterns[$subword])) {
  21506. $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont);
  21507. $pattern_length = count($pattern);
  21508. $digits = 1;
  21509. for ($j = 0; $j < $pattern_length; ++$j) {
  21510. // check if $pattern[$j] is a number = hyphenation level (only numbers from 1 to 5 are valid)
  21511. if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  21512. if ($j == 0) {
  21513. $zero = $pos - 1;
  21514. } else {
  21515. $zero = $pos + $j - $digits;
  21516. }
  21517. // get hyphenation level
  21518. $level = ($pattern[$j] - 48);
  21519. // if two levels from two different patterns match at the same point, the higher one is selected.
  21520. if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] < $level)) {
  21521. $hyphenword[$zero] = $level;
  21522. }
  21523. ++$digits;
  21524. }
  21525. }
  21526. }
  21527. }
  21528. }
  21529. $inserted = 0;
  21530. $maxpos = $numchars - $rightmin;
  21531. for ($i = $leftmin; $i <= $maxpos; ++$i) {
  21532. // only odd levels indicate allowed hyphenation points
  21533. if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  21534. // 173 = soft hyphen character
  21535. array_splice($word, $i + $inserted, 0, 173);
  21536. ++$inserted;
  21537. }
  21538. }
  21539. return $word;
  21540. }
  21541. /**
  21542. * Returns text with soft hyphens.
  21543. * @param string $text text to process
  21544. * @param mixed $patterns 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/
  21545. * @param array $dictionary Array of words to be returned without applying the hyphenation algorithm.
  21546. * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
  21547. * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
  21548. * @param int $charmin Minimum word length to apply the hyphenation algorithm.
  21549. * @param int $charmax Maximum length of broken piece of word.
  21550. * @return string text with soft hyphens
  21551. * @author Nicola Asuni
  21552. * @since 4.9.012 (2010-04-12)
  21553. * @public
  21554. */
  21555. public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21556. $text = $this->unhtmlentities($text);
  21557. $word = array(); // last word
  21558. $txtarr = array(); // text to be returned
  21559. $intag = false; // true if we are inside an HTML tag
  21560. $skip = false; // true to skip hyphenation
  21561. if (!is_array($patterns)) {
  21562. $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
  21563. }
  21564. // get array of characters
  21565. $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  21566. // for each char
  21567. foreach ($unichars as $char) {
  21568. if ((!$intag) AND (!$skip) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
  21569. // letter character
  21570. $word[] = $char;
  21571. } else {
  21572. // other type of character
  21573. if (!TCPDF_STATIC::empty_string($word)) {
  21574. // hypenate the word
  21575. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21576. $word = array();
  21577. }
  21578. $txtarr[] = $char;
  21579. if (chr($char) == '<') {
  21580. // we are inside an HTML tag
  21581. $intag = true;
  21582. } elseif ($intag AND (chr($char) == '>')) {
  21583. // end of HTML tag
  21584. $intag = false;
  21585. // check for style tag
  21586. $expected = array(115, 116, 121, 108, 101); // = 'style'
  21587. $current = array_slice($txtarr, -6, 5); // last 5 chars
  21588. $compare = array_diff($expected, $current);
  21589. if (empty($compare)) {
  21590. // check if it is a closing tag
  21591. $expected = array(47); // = '/'
  21592. $current = array_slice($txtarr, -7, 1);
  21593. $compare = array_diff($expected, $current);
  21594. if (empty($compare)) {
  21595. // closing style tag
  21596. $skip = false;
  21597. } else {
  21598. // opening style tag
  21599. $skip = true;
  21600. }
  21601. }
  21602. }
  21603. }
  21604. }
  21605. if (!TCPDF_STATIC::empty_string($word)) {
  21606. // hypenate the word
  21607. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21608. }
  21609. // convert char array to string and return
  21610. return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
  21611. }
  21612. /**
  21613. * Enable/disable rasterization of vector images using ImageMagick library.
  21614. * @param boolean $mode if true enable rasterization, false otherwise.
  21615. * @public
  21616. * @since 5.0.000 (2010-04-27)
  21617. */
  21618. public function setRasterizeVectorImages($mode) {
  21619. $this->rasterize_vector_images = $mode;
  21620. }
  21621. /**
  21622. * Enable or disable default option for font subsetting.
  21623. * @param boolean $enable if true enable font subsetting by default.
  21624. * @author Nicola Asuni
  21625. * @public
  21626. * @since 5.3.002 (2010-06-07)
  21627. */
  21628. public function setFontSubsetting($enable=true) {
  21629. if ($this->pdfa_mode) {
  21630. $this->font_subsetting = false;
  21631. } else {
  21632. $this->font_subsetting = $enable ? true : false;
  21633. }
  21634. }
  21635. /**
  21636. * Return the default option for font subsetting.
  21637. * @return bool default font subsetting state.
  21638. * @author Nicola Asuni
  21639. * @public
  21640. * @since 5.3.002 (2010-06-07)
  21641. */
  21642. public function getFontSubsetting() {
  21643. return $this->font_subsetting;
  21644. }
  21645. /**
  21646. * Left trim the input string
  21647. * @param string $str string to trim
  21648. * @param string $replace string that replace spaces.
  21649. * @return string left trimmed string
  21650. * @author Nicola Asuni
  21651. * @public
  21652. * @since 5.8.000 (2010-08-11)
  21653. */
  21654. public function stringLeftTrim($str, $replace='') {
  21655. return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
  21656. }
  21657. /**
  21658. * Right trim the input string
  21659. * @param string $str string to trim
  21660. * @param string $replace string that replace spaces.
  21661. * @return string right trimmed string
  21662. * @author Nicola Asuni
  21663. * @public
  21664. * @since 5.8.000 (2010-08-11)
  21665. */
  21666. public function stringRightTrim($str, $replace='') {
  21667. return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
  21668. }
  21669. /**
  21670. * Trim the input string
  21671. * @param string $str string to trim
  21672. * @param string $replace string that replace spaces.
  21673. * @return string trimmed string
  21674. * @author Nicola Asuni
  21675. * @public
  21676. * @since 5.8.000 (2010-08-11)
  21677. */
  21678. public function stringTrim($str, $replace='') {
  21679. $str = $this->stringLeftTrim($str, $replace);
  21680. $str = $this->stringRightTrim($str, $replace);
  21681. return $str;
  21682. }
  21683. /**
  21684. * Return true if the current font is unicode type.
  21685. * @return bool true for unicode font, false otherwise.
  21686. * @author Nicola Asuni
  21687. * @public
  21688. * @since 5.8.002 (2010-08-14)
  21689. */
  21690. public function isUnicodeFont() {
  21691. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  21692. }
  21693. /**
  21694. * Return normalized font name
  21695. * @param string $fontfamily property string containing font family names
  21696. * @return string normalized font name
  21697. * @author Nicola Asuni
  21698. * @public
  21699. * @since 5.8.004 (2010-08-17)
  21700. */
  21701. public function getFontFamilyName($fontfamily) {
  21702. // remove spaces and symbols
  21703. $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
  21704. // extract all font names
  21705. $fontslist = preg_split('/[,]/', $fontfamily);
  21706. // find first valid font name
  21707. foreach ($fontslist as $font) {
  21708. // replace font variations
  21709. $font = preg_replace('/regular$/', '', $font);
  21710. $font = preg_replace('/italic$/', 'I', $font);
  21711. $font = preg_replace('/oblique$/', 'I', $font);
  21712. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  21713. // replace common family names and core fonts
  21714. $pattern = array();
  21715. $replacement = array();
  21716. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  21717. $replacement[] = 'times';
  21718. $pattern[] = '/^sansserif/';
  21719. $replacement[] = 'helvetica';
  21720. $pattern[] = '/^monospace/';
  21721. $replacement[] = 'courier';
  21722. $font = preg_replace($pattern, $replacement, $font);
  21723. if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
  21724. return $font;
  21725. }
  21726. }
  21727. // return current font as default
  21728. return $this->CurrentFont['fontkey'];
  21729. }
  21730. /**
  21731. * Start a new XObject Template.
  21732. * 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).
  21733. * 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.
  21734. * Note: X,Y coordinates will be reset to 0,0.
  21735. * @param int $w Template width in user units (empty string or zero = page width less margins).
  21736. * @param int $h Template height in user units (empty string or zero = page height less margins).
  21737. * @param mixed $group 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).
  21738. * @return string|false the XObject Template ID in case of success or false in case of error.
  21739. * @author Nicola Asuni
  21740. * @public
  21741. * @since 5.8.017 (2010-08-24)
  21742. * @see endTemplate(), printTemplate()
  21743. */
  21744. public function startTemplate($w=0, $h=0, $group=false) {
  21745. if ($this->inxobj) {
  21746. // we are already inside an XObject template
  21747. return false;
  21748. }
  21749. $this->inxobj = true;
  21750. ++$this->n;
  21751. // XObject ID
  21752. $this->xobjid = 'XT'.$this->n;
  21753. // object ID
  21754. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  21755. // store current graphic state
  21756. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  21757. // initialize data
  21758. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  21759. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  21760. $this->xobjects[$this->xobjid]['outdata'] = '';
  21761. $this->xobjects[$this->xobjid]['xobjects'] = array();
  21762. $this->xobjects[$this->xobjid]['images'] = array();
  21763. $this->xobjects[$this->xobjid]['fonts'] = array();
  21764. $this->xobjects[$this->xobjid]['annotations'] = array();
  21765. $this->xobjects[$this->xobjid]['extgstates'] = array();
  21766. $this->xobjects[$this->xobjid]['gradients'] = array();
  21767. $this->xobjects[$this->xobjid]['spot_colors'] = array();
  21768. // set new environment
  21769. $this->num_columns = 1;
  21770. $this->current_column = 0;
  21771. $this->setAutoPageBreak(false);
  21772. if (($w === '') OR ($w <= 0)) {
  21773. $w = $this->w - $this->lMargin - $this->rMargin;
  21774. }
  21775. if (($h === '') OR ($h <= 0)) {
  21776. $h = $this->h - $this->tMargin - $this->bMargin;
  21777. }
  21778. $this->xobjects[$this->xobjid]['x'] = 0;
  21779. $this->xobjects[$this->xobjid]['y'] = 0;
  21780. $this->xobjects[$this->xobjid]['w'] = $w;
  21781. $this->xobjects[$this->xobjid]['h'] = $h;
  21782. $this->w = $w;
  21783. $this->h = $h;
  21784. $this->wPt = $this->w * $this->k;
  21785. $this->hPt = $this->h * $this->k;
  21786. $this->fwPt = $this->wPt;
  21787. $this->fhPt = $this->hPt;
  21788. $this->x = 0;
  21789. $this->y = 0;
  21790. $this->lMargin = 0;
  21791. $this->rMargin = 0;
  21792. $this->tMargin = 0;
  21793. $this->bMargin = 0;
  21794. // set group mode
  21795. $this->xobjects[$this->xobjid]['group'] = $group;
  21796. return $this->xobjid;
  21797. }
  21798. /**
  21799. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  21800. * 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).
  21801. * 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.
  21802. * @return string|false the XObject Template ID in case of success or false in case of error.
  21803. * @author Nicola Asuni
  21804. * @public
  21805. * @since 5.8.017 (2010-08-24)
  21806. * @see startTemplate(), printTemplate()
  21807. */
  21808. public function endTemplate() {
  21809. if (!$this->inxobj) {
  21810. // we are not inside a template
  21811. return false;
  21812. }
  21813. $this->inxobj = false;
  21814. // restore previous graphic state
  21815. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  21816. return $this->xobjid;
  21817. }
  21818. /**
  21819. * Print an XObject Template.
  21820. * You can print an XObject Template inside the currently opened Template.
  21821. * 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).
  21822. * 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.
  21823. * @param string $id The ID of XObject Template to print.
  21824. * @param float|null $x X position in user units (empty string = current x position)
  21825. * @param float|null $y Y position in user units (empty string = current y position)
  21826. * @param float $w Width in user units (zero = remaining page width)
  21827. * @param float $h Height in user units (zero = remaining page height)
  21828. * @param string $align 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>
  21829. * @param string $palign 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>
  21830. * @param boolean $fitonpage If true the template is resized to not exceed page dimensions.
  21831. * @author Nicola Asuni
  21832. * @public
  21833. * @since 5.8.017 (2010-08-24)
  21834. * @see startTemplate(), endTemplate()
  21835. */
  21836. public function printTemplate($id, $x=null, $y=null, $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
  21837. if ($this->state != 2) {
  21838. return;
  21839. }
  21840. if (!isset($this->xobjects[$id])) {
  21841. $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  21842. }
  21843. if ($this->inxobj) {
  21844. if ($id == $this->xobjid) {
  21845. // close current template
  21846. $this->endTemplate();
  21847. } else {
  21848. // use the template as resource for the template currently opened
  21849. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  21850. }
  21851. }
  21852. // set default values
  21853. if (TCPDF_STATIC::empty_string($x)) {
  21854. $x = $this->x;
  21855. }
  21856. if (TCPDF_STATIC::empty_string($y)) {
  21857. $y = $this->y;
  21858. }
  21859. // check page for no-write regions and adapt page margins if necessary
  21860. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  21861. $ow = $this->xobjects[$id]['w'];
  21862. if ($ow <= 0) {
  21863. $ow = 1;
  21864. }
  21865. $oh = $this->xobjects[$id]['h'];
  21866. if ($oh <= 0) {
  21867. $oh = 1;
  21868. }
  21869. // calculate template width and height on document
  21870. if (($w <= 0) AND ($h <= 0)) {
  21871. $w = $ow;
  21872. $h = $oh;
  21873. } elseif ($w <= 0) {
  21874. $w = $h * $ow / $oh;
  21875. } elseif ($h <= 0) {
  21876. $h = $w * $oh / $ow;
  21877. }
  21878. // fit the template on available space
  21879. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  21880. // set page alignment
  21881. $rb_y = $y + $h;
  21882. // set alignment
  21883. if ($this->rtl) {
  21884. if ($palign == 'L') {
  21885. $xt = $this->lMargin;
  21886. } elseif ($palign == 'C') {
  21887. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21888. } elseif ($palign == 'R') {
  21889. $xt = $this->w - $this->rMargin - $w;
  21890. } else {
  21891. $xt = $x - $w;
  21892. }
  21893. $rb_x = $xt;
  21894. } else {
  21895. if ($palign == 'L') {
  21896. $xt = $this->lMargin;
  21897. } elseif ($palign == 'C') {
  21898. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21899. } elseif ($palign == 'R') {
  21900. $xt = $this->w - $this->rMargin - $w;
  21901. } else {
  21902. $xt = $x;
  21903. }
  21904. $rb_x = $xt + $w;
  21905. }
  21906. // print XObject Template + Transformation matrix
  21907. $this->StartTransform();
  21908. // translate and scale
  21909. $sx = ($w / $ow);
  21910. $sy = ($h / $oh);
  21911. $tm = array();
  21912. $tm[0] = $sx;
  21913. $tm[1] = 0;
  21914. $tm[2] = 0;
  21915. $tm[3] = $sy;
  21916. $tm[4] = $xt * $this->k;
  21917. $tm[5] = ($this->h - $h - $y) * $this->k;
  21918. $this->Transform($tm);
  21919. // set object
  21920. $this->_out('/'.$id.' Do');
  21921. $this->StopTransform();
  21922. // add annotations
  21923. if (!empty($this->xobjects[$id]['annotations'])) {
  21924. foreach ($this->xobjects[$id]['annotations'] as $annot) {
  21925. // transform original coordinates
  21926. $coordlt = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  21927. $ax = ($coordlt[4] / $this->k);
  21928. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  21929. $coordrb = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  21930. $aw = ($coordrb[4] / $this->k) - $ax;
  21931. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  21932. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  21933. }
  21934. }
  21935. // set pointer to align the next text/objects
  21936. switch($align) {
  21937. case 'T': {
  21938. $this->y = $y;
  21939. $this->x = $rb_x;
  21940. break;
  21941. }
  21942. case 'M': {
  21943. $this->y = $y + round($h/2);
  21944. $this->x = $rb_x;
  21945. break;
  21946. }
  21947. case 'B': {
  21948. $this->y = $rb_y;
  21949. $this->x = $rb_x;
  21950. break;
  21951. }
  21952. case 'N': {
  21953. $this->setY($rb_y);
  21954. break;
  21955. }
  21956. default:{
  21957. break;
  21958. }
  21959. }
  21960. }
  21961. /**
  21962. * Set the percentage of character stretching.
  21963. * @param int $perc percentage of stretching (100 = no stretching)
  21964. * @author Nicola Asuni
  21965. * @public
  21966. * @since 5.9.000 (2010-09-29)
  21967. */
  21968. public function setFontStretching($perc=100) {
  21969. $this->font_stretching = $perc;
  21970. }
  21971. /**
  21972. * Get the percentage of character stretching.
  21973. * @return float stretching value
  21974. * @author Nicola Asuni
  21975. * @public
  21976. * @since 5.9.000 (2010-09-29)
  21977. */
  21978. public function getFontStretching() {
  21979. return $this->font_stretching;
  21980. }
  21981. /**
  21982. * Set the amount to increase or decrease the space between characters in a text.
  21983. * @param float $spacing amount to increase or decrease the space between characters in a text (0 = default spacing)
  21984. * @author Nicola Asuni
  21985. * @public
  21986. * @since 5.9.000 (2010-09-29)
  21987. */
  21988. public function setFontSpacing($spacing=0) {
  21989. $this->font_spacing = $spacing;
  21990. }
  21991. /**
  21992. * Get the amount to increase or decrease the space between characters in a text.
  21993. * @return int font spacing (tracking) value
  21994. * @author Nicola Asuni
  21995. * @public
  21996. * @since 5.9.000 (2010-09-29)
  21997. */
  21998. public function getFontSpacing() {
  21999. return $this->font_spacing;
  22000. }
  22001. /**
  22002. * Return an array of no-write page regions
  22003. * @return array of no-write page regions
  22004. * @author Nicola Asuni
  22005. * @public
  22006. * @since 5.9.003 (2010-10-13)
  22007. * @see setPageRegions(), addPageRegion()
  22008. */
  22009. public function getPageRegions() {
  22010. return $this->page_regions;
  22011. }
  22012. /**
  22013. * Set no-write regions on page.
  22014. * 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.
  22015. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22016. * You can set multiple regions for the same page.
  22017. * @param array $regions 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.
  22018. * @author Nicola Asuni
  22019. * @public
  22020. * @since 5.9.003 (2010-10-13)
  22021. * @see addPageRegion(), getPageRegions()
  22022. */
  22023. public function setPageRegions($regions=array()) {
  22024. // empty current regions array
  22025. $this->page_regions = array();
  22026. // add regions
  22027. foreach ($regions as $data) {
  22028. $this->addPageRegion($data);
  22029. }
  22030. }
  22031. /**
  22032. * Add a single no-write region on selected page.
  22033. * 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.
  22034. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22035. * You can set multiple regions for the same page.
  22036. * @param array $region 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).
  22037. * @author Nicola Asuni
  22038. * @public
  22039. * @since 5.9.003 (2010-10-13)
  22040. * @see setPageRegions(), getPageRegions()
  22041. */
  22042. public function addPageRegion($region) {
  22043. if (!isset($region['page']) OR empty($region['page'])) {
  22044. $region['page'] = $this->page;
  22045. }
  22046. if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  22047. AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  22048. AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  22049. $this->page_regions[] = $region;
  22050. }
  22051. }
  22052. /**
  22053. * Remove a single no-write region.
  22054. * @param int $key region key
  22055. * @author Nicola Asuni
  22056. * @public
  22057. * @since 5.9.003 (2010-10-13)
  22058. * @see setPageRegions(), getPageRegions()
  22059. */
  22060. public function removePageRegion($key) {
  22061. if (isset($this->page_regions[$key])) {
  22062. unset($this->page_regions[$key]);
  22063. }
  22064. }
  22065. /**
  22066. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  22067. * 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.
  22068. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22069. * @param float $h height of the text/image/object to print in user units
  22070. * @param float $x current X coordinate in user units
  22071. * @param float $y current Y coordinate in user units
  22072. * @return float[] array($x, $y)
  22073. * @author Nicola Asuni
  22074. * @protected
  22075. * @since 5.9.003 (2010-10-13)
  22076. */
  22077. protected function checkPageRegions($h, $x, $y) {
  22078. // set default values
  22079. if ($x === '') {
  22080. $x = $this->x;
  22081. }
  22082. if ($y === '') {
  22083. $y = $this->y;
  22084. }
  22085. if (!$this->check_page_regions OR empty($this->page_regions)) {
  22086. // no page regions defined
  22087. return array($x, $y);
  22088. }
  22089. if (empty($h)) {
  22090. $h = $this->getCellHeight($this->FontSize);
  22091. }
  22092. // check for page break
  22093. if ($this->checkPageBreak($h, $y)) {
  22094. // the content will be printed on a new page
  22095. $x = $this->x;
  22096. $y = $this->y;
  22097. }
  22098. if ($this->num_columns > 1) {
  22099. if ($this->rtl) {
  22100. $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  22101. } else {
  22102. $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  22103. }
  22104. } else {
  22105. if ($this->rtl) {
  22106. $this->lMargin = max($this->clMargin, $this->original_lMargin);
  22107. } else {
  22108. $this->rMargin = max($this->crMargin, $this->original_rMargin);
  22109. }
  22110. }
  22111. // adjust coordinates and page margins
  22112. foreach ($this->page_regions as $regid => $regdata) {
  22113. if ($regdata['page'] == $this->page) {
  22114. // check region boundaries
  22115. if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  22116. // Y is inside the region
  22117. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  22118. $yt = max($y, $regdata['yt']);
  22119. $yb = min(($yt + $h), $regdata['yb']);
  22120. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  22121. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  22122. if ($regdata['side'] == 'L') { // left side
  22123. $new_margin = max($xt, $xb);
  22124. if ($this->lMargin < $new_margin) {
  22125. if ($this->rtl) {
  22126. // adjust left page margin
  22127. $this->lMargin = max(0, $new_margin);
  22128. }
  22129. if ($x < $new_margin) {
  22130. // adjust x position
  22131. $x = $new_margin;
  22132. if ($new_margin > ($this->w - $this->rMargin)) {
  22133. // adjust y position
  22134. $y = $regdata['yb'] - $h;
  22135. }
  22136. }
  22137. }
  22138. } elseif ($regdata['side'] == 'R') { // right side
  22139. $new_margin = min($xt, $xb);
  22140. if (($this->w - $this->rMargin) > $new_margin) {
  22141. if (!$this->rtl) {
  22142. // adjust right page margin
  22143. $this->rMargin = max(0, ($this->w - $new_margin));
  22144. }
  22145. if ($x > $new_margin) {
  22146. // adjust x position
  22147. $x = $new_margin;
  22148. if ($new_margin > $this->lMargin) {
  22149. // adjust y position
  22150. $y = $regdata['yb'] - $h;
  22151. }
  22152. }
  22153. }
  22154. }
  22155. }
  22156. }
  22157. }
  22158. return array($x, $y);
  22159. }
  22160. // --- SVG METHODS ---------------------------------------------------------
  22161. /**
  22162. * Embedd a Scalable Vector Graphics (SVG) image.
  22163. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  22164. * @param string $file Name of the SVG file or a '@' character followed by the SVG data string.
  22165. * @param float|null $x Abscissa of the upper-left corner.
  22166. * @param float|null $y Ordinate of the upper-left corner.
  22167. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22168. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22169. * @param mixed $link URL or identifier returned by AddLink().
  22170. * @param string $align 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.
  22171. * @param string $palign 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>
  22172. * @param mixed $border 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)))
  22173. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  22174. * @author Nicola Asuni
  22175. * @since 5.0.000 (2010-05-02)
  22176. * @public
  22177. */
  22178. public function ImageSVG($file, $x=null, $y=null, $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
  22179. if ($this->state != 2) {
  22180. return;
  22181. }
  22182. // reset SVG vars
  22183. $this->svggradients = array();
  22184. $this->svggradientid = 0;
  22185. $this->svgdefsmode = false;
  22186. $this->svgdefs = array();
  22187. $this->svgclipmode = false;
  22188. $this->svgclippaths = array();
  22189. $this->svgcliptm = array();
  22190. $this->svgclipid = 0;
  22191. $this->svgtext = '';
  22192. $this->svgtextmode = array();
  22193. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  22194. // convert SVG to raster image using GD or ImageMagick libraries
  22195. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22196. }
  22197. if ($file[0] === '@') { // image from string
  22198. $this->svgdir = '';
  22199. $svgdata = substr($file, 1);
  22200. } else { // SVG file
  22201. $this->svgdir = dirname($file);
  22202. $svgdata = $this->getCachedFileContents($file);
  22203. }
  22204. if ($svgdata === FALSE) {
  22205. $this->Error('SVG file not found: '.$file);
  22206. }
  22207. if (TCPDF_STATIC::empty_string($x)) {
  22208. $x = $this->x;
  22209. }
  22210. if (TCPDF_STATIC::empty_string($y)) {
  22211. $y = $this->y;
  22212. }
  22213. // check page for no-write regions and adapt page margins if necessary
  22214. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  22215. $k = $this->k;
  22216. $ox = 0;
  22217. $oy = 0;
  22218. $ow = $w;
  22219. $oh = $h;
  22220. $aspect_ratio_align = 'xMidYMid';
  22221. $aspect_ratio_ms = 'meet';
  22222. $regs = array();
  22223. // get original image width and height
  22224. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  22225. if (isset($regs[1]) AND !empty($regs[1])) {
  22226. $tmp = array();
  22227. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22228. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  22229. }
  22230. $tmp = array();
  22231. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22232. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  22233. }
  22234. $tmp = array();
  22235. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22236. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  22237. }
  22238. $tmp = array();
  22239. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22240. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  22241. }
  22242. $tmp = array();
  22243. $view_box = array();
  22244. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
  22245. if (count($tmp) == 5) {
  22246. array_shift($tmp);
  22247. foreach ($tmp as $key => $val) {
  22248. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  22249. }
  22250. $ox = $view_box[0];
  22251. $oy = $view_box[1];
  22252. }
  22253. // get aspect ratio
  22254. $tmp = array();
  22255. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22256. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  22257. switch (count($aspect_ratio)) {
  22258. case 3: {
  22259. $aspect_ratio_align = $aspect_ratio[1];
  22260. $aspect_ratio_ms = $aspect_ratio[2];
  22261. break;
  22262. }
  22263. case 2: {
  22264. $aspect_ratio_align = $aspect_ratio[0];
  22265. $aspect_ratio_ms = $aspect_ratio[1];
  22266. break;
  22267. }
  22268. case 1: {
  22269. $aspect_ratio_align = $aspect_ratio[0];
  22270. $aspect_ratio_ms = 'meet';
  22271. break;
  22272. }
  22273. }
  22274. }
  22275. }
  22276. }
  22277. if ($ow <= 0) {
  22278. $ow = 1;
  22279. }
  22280. if ($oh <= 0) {
  22281. $oh = 1;
  22282. }
  22283. // calculate image width and height on document
  22284. if (($w <= 0) AND ($h <= 0)) {
  22285. // convert image size to document unit
  22286. $w = $ow;
  22287. $h = $oh;
  22288. } elseif ($w <= 0) {
  22289. $w = $h * $ow / $oh;
  22290. } elseif ($h <= 0) {
  22291. $h = $w * $oh / $ow;
  22292. }
  22293. // fit the image on available space
  22294. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  22295. if ($this->rasterize_vector_images) {
  22296. // convert SVG to raster image using GD or ImageMagick libraries
  22297. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22298. }
  22299. // set alignment
  22300. $this->img_rb_y = $y + $h;
  22301. // set alignment
  22302. if ($this->rtl) {
  22303. if ($palign == 'L') {
  22304. $ximg = $this->lMargin;
  22305. } elseif ($palign == 'C') {
  22306. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22307. } elseif ($palign == 'R') {
  22308. $ximg = $this->w - $this->rMargin - $w;
  22309. } else {
  22310. $ximg = $x - $w;
  22311. }
  22312. $this->img_rb_x = $ximg;
  22313. } else {
  22314. if ($palign == 'L') {
  22315. $ximg = $this->lMargin;
  22316. } elseif ($palign == 'C') {
  22317. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22318. } elseif ($palign == 'R') {
  22319. $ximg = $this->w - $this->rMargin - $w;
  22320. } else {
  22321. $ximg = $x;
  22322. }
  22323. $this->img_rb_x = $ximg + $w;
  22324. }
  22325. // store current graphic vars
  22326. $gvars = $this->getGraphicVars();
  22327. // store SVG position and scale factors
  22328. $svgoffset_x = ($ximg - $ox) * $this->k;
  22329. $svgoffset_y = -($y - $oy) * $this->k;
  22330. if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  22331. $ow = $view_box[2];
  22332. $oh = $view_box[3];
  22333. } else {
  22334. if ($ow <= 0) {
  22335. $ow = $w;
  22336. }
  22337. if ($oh <= 0) {
  22338. $oh = $h;
  22339. }
  22340. }
  22341. $svgscale_x = $w / $ow;
  22342. $svgscale_y = $h / $oh;
  22343. // scaling and alignment
  22344. if ($aspect_ratio_align != 'none') {
  22345. // store current scaling values
  22346. $svgscale_old_x = $svgscale_x;
  22347. $svgscale_old_y = $svgscale_y;
  22348. // force uniform scaling
  22349. if ($aspect_ratio_ms == 'slice') {
  22350. // the entire viewport is covered by the viewBox
  22351. if ($svgscale_x > $svgscale_y) {
  22352. $svgscale_y = $svgscale_x;
  22353. } elseif ($svgscale_x < $svgscale_y) {
  22354. $svgscale_x = $svgscale_y;
  22355. }
  22356. } else { // meet
  22357. // the entire viewBox is visible within the viewport
  22358. if ($svgscale_x < $svgscale_y) {
  22359. $svgscale_y = $svgscale_x;
  22360. } elseif ($svgscale_x > $svgscale_y) {
  22361. $svgscale_x = $svgscale_y;
  22362. }
  22363. }
  22364. // correct X alignment
  22365. switch (substr($aspect_ratio_align, 1, 3)) {
  22366. case 'Min': {
  22367. // do nothing
  22368. break;
  22369. }
  22370. case 'Max': {
  22371. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  22372. break;
  22373. }
  22374. default:
  22375. case 'Mid': {
  22376. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  22377. break;
  22378. }
  22379. }
  22380. // correct Y alignment
  22381. switch (substr($aspect_ratio_align, 5)) {
  22382. case 'Min': {
  22383. // do nothing
  22384. break;
  22385. }
  22386. case 'Max': {
  22387. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  22388. break;
  22389. }
  22390. default:
  22391. case 'Mid': {
  22392. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  22393. break;
  22394. }
  22395. }
  22396. }
  22397. // store current page break mode
  22398. $page_break_mode = $this->AutoPageBreak;
  22399. $page_break_margin = $this->getBreakMargin();
  22400. $cell_padding = $this->cell_padding;
  22401. $this->setCellPadding(0);
  22402. $this->setAutoPageBreak(false);
  22403. // save the current graphic state
  22404. $this->_out('q'.$this->epsmarker);
  22405. // set initial clipping mask
  22406. $this->Rect($ximg, $y, $w, $h, 'CNZ', array(), array());
  22407. // scale and translate
  22408. $e = $ox * $this->k * (1 - $svgscale_x);
  22409. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  22410. $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e + $svgoffset_x), ($f + $svgoffset_y)));
  22411. // creates a new XML parser to be used by the other XML functions
  22412. $parser = xml_parser_create('UTF-8');
  22413. // the following function allows to use parser inside object
  22414. xml_set_object($parser, $this);
  22415. // disable case-folding for this XML parser
  22416. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  22417. // sets the element handler functions for the XML parser
  22418. xml_set_element_handler($parser, 'startSVGElementHandler', 'endSVGElementHandler');
  22419. // sets the character data handler function for the XML parser
  22420. xml_set_character_data_handler($parser, 'segSVGContentHandler');
  22421. // start parsing an XML document
  22422. if (!xml_parse($parser, $svgdata)) {
  22423. $error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser));
  22424. $this->Error($error_message);
  22425. }
  22426. // free this XML parser
  22427. xml_parser_free($parser);
  22428. // >= PHP 7.0.0 "explicitly unset the reference to parser to avoid memory leaks"
  22429. unset($parser);
  22430. // restore previous graphic state
  22431. $this->_out($this->epsmarker.'Q');
  22432. // restore graphic vars
  22433. $this->setGraphicVars($gvars);
  22434. $this->lasth = $gvars['lasth'];
  22435. if (!empty($border)) {
  22436. $bx = $this->x;
  22437. $by = $this->y;
  22438. $this->x = $ximg;
  22439. if ($this->rtl) {
  22440. $this->x += $w;
  22441. }
  22442. $this->y = $y;
  22443. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  22444. $this->x = $bx;
  22445. $this->y = $by;
  22446. }
  22447. if ($link) {
  22448. $this->Link($ximg, $y, $w, $h, $link, 0);
  22449. }
  22450. // set pointer to align the next text/objects
  22451. switch($align) {
  22452. case 'T':{
  22453. $this->y = $y;
  22454. $this->x = $this->img_rb_x;
  22455. break;
  22456. }
  22457. case 'M':{
  22458. $this->y = $y + round($h/2);
  22459. $this->x = $this->img_rb_x;
  22460. break;
  22461. }
  22462. case 'B':{
  22463. $this->y = $this->img_rb_y;
  22464. $this->x = $this->img_rb_x;
  22465. break;
  22466. }
  22467. case 'N':{
  22468. $this->setY($this->img_rb_y);
  22469. break;
  22470. }
  22471. default:{
  22472. // restore pointer to starting position
  22473. $this->x = $gvars['x'];
  22474. $this->y = $gvars['y'];
  22475. $this->page = $gvars['page'];
  22476. $this->current_column = $gvars['current_column'];
  22477. $this->tMargin = $gvars['tMargin'];
  22478. $this->bMargin = $gvars['bMargin'];
  22479. $this->w = $gvars['w'];
  22480. $this->h = $gvars['h'];
  22481. $this->wPt = $gvars['wPt'];
  22482. $this->hPt = $gvars['hPt'];
  22483. $this->fwPt = $gvars['fwPt'];
  22484. $this->fhPt = $gvars['fhPt'];
  22485. break;
  22486. }
  22487. }
  22488. $this->endlinex = $this->img_rb_x;
  22489. // restore page break
  22490. $this->setAutoPageBreak($page_break_mode, $page_break_margin);
  22491. $this->cell_padding = $cell_padding;
  22492. }
  22493. /**
  22494. * Convert SVG transformation matrix to PDF.
  22495. * @param array $tm original SVG transformation matrix
  22496. * @return array transformation matrix
  22497. * @protected
  22498. * @since 5.0.000 (2010-05-02)
  22499. */
  22500. protected function convertSVGtMatrix($tm) {
  22501. $a = $tm[0];
  22502. $b = -$tm[1];
  22503. $c = -$tm[2];
  22504. $d = $tm[3];
  22505. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  22506. $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  22507. $x = 0;
  22508. $y = $this->h * $this->k;
  22509. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  22510. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  22511. return array($a, $b, $c, $d, $e, $f);
  22512. }
  22513. /**
  22514. * Apply SVG graphic transformation matrix.
  22515. * @param array $tm original SVG transformation matrix
  22516. * @protected
  22517. * @since 5.0.000 (2010-05-02)
  22518. */
  22519. protected function SVGTransform($tm) {
  22520. $this->Transform($this->convertSVGtMatrix($tm));
  22521. }
  22522. /**
  22523. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  22524. * @param array $svgstyle array of SVG styles to apply
  22525. * @param array $prevsvgstyle array of previous SVG style
  22526. * @param int $x X origin of the bounding box
  22527. * @param int $y Y origin of the bounding box
  22528. * @param int $w width of the bounding box
  22529. * @param int $h height of the bounding box
  22530. * @param string $clip_function clip function
  22531. * @param array $clip_params array of parameters for clipping function
  22532. * @return string style
  22533. * @author Nicola Asuni
  22534. * @since 5.0.000 (2010-05-02)
  22535. * @protected
  22536. */
  22537. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
  22538. if ($this->state != 2) {
  22539. return;
  22540. }
  22541. $objstyle = '';
  22542. $minlen = (0.01 / $this->k); // minimum acceptable length
  22543. if (!isset($svgstyle['opacity'])) {
  22544. return $objstyle;
  22545. }
  22546. // clip-path
  22547. $regs = array();
  22548. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
  22549. $clip_path = $this->svgclippaths[$regs[1]];
  22550. foreach ($clip_path as $cp) {
  22551. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  22552. }
  22553. }
  22554. // opacity
  22555. if ($svgstyle['opacity'] != 1) {
  22556. $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
  22557. }
  22558. // color
  22559. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors);
  22560. $this->setFillColorArray($fill_color);
  22561. // text color
  22562. $text_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors);
  22563. $this->setTextColorArray($text_color);
  22564. // clip
  22565. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
  22566. $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
  22567. $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
  22568. $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
  22569. $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
  22570. $cx = $x + $left;
  22571. $cy = $y + $top;
  22572. $cw = $w - $left - $right;
  22573. $ch = $h - $top - $bottom;
  22574. if ($svgstyle['clip-rule'] == 'evenodd') {
  22575. $clip_rule = 'CNZ';
  22576. } else {
  22577. $clip_rule = 'CEO';
  22578. }
  22579. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  22580. }
  22581. // fill
  22582. $regs = array();
  22583. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
  22584. // gradient
  22585. $gradient = $this->svggradients[$regs[1]];
  22586. if (isset($gradient['xref'])) {
  22587. // reference to another gradient definition
  22588. $newgradient = $this->svggradients[$gradient['xref']];
  22589. $newgradient['coords'] = $gradient['coords'];
  22590. $newgradient['mode'] = $gradient['mode'];
  22591. $newgradient['type'] = $gradient['type'];
  22592. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  22593. if (isset($gradient['gradientTransform'])) {
  22594. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  22595. }
  22596. $gradient = $newgradient;
  22597. }
  22598. //save current Graphic State
  22599. $this->_outSaveGraphicsState();
  22600. //set clipping area
  22601. if (!empty($clip_function) AND method_exists($this, $clip_function)) {
  22602. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  22603. if ((!isset($gradient['type']) OR ($gradient['type'] != 3)) AND is_array($bbox) AND (count($bbox) == 4)) {
  22604. list($x, $y, $w, $h) = $bbox;
  22605. }
  22606. }
  22607. if ($gradient['mode'] == 'measure') {
  22608. if (!isset($gradient['coords'][4])) {
  22609. $gradient['coords'][4] = 0.5;
  22610. }
  22611. if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  22612. $gtm = $gradient['gradientTransform'];
  22613. // apply transformation matrix
  22614. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  22615. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  22616. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  22617. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  22618. $r = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  22619. $gradient['coords'][0] = $xa;
  22620. $gradient['coords'][1] = $ya;
  22621. $gradient['coords'][2] = $xb;
  22622. $gradient['coords'][3] = $yb;
  22623. $gradient['coords'][4] = $r;
  22624. }
  22625. // convert SVG coordinates to user units
  22626. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  22627. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  22628. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  22629. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  22630. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  22631. if ($w <= $minlen) {
  22632. $w = $minlen;
  22633. }
  22634. if ($h <= $minlen) {
  22635. $h = $minlen;
  22636. }
  22637. // shift units
  22638. if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  22639. // convert to SVG coordinate system
  22640. $gradient['coords'][0] += $x;
  22641. $gradient['coords'][1] += $y;
  22642. $gradient['coords'][2] += $x;
  22643. $gradient['coords'][3] += $y;
  22644. }
  22645. // calculate percentages
  22646. $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
  22647. $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
  22648. $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
  22649. $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
  22650. $gradient['coords'][4] /= $w;
  22651. } elseif ($gradient['mode'] == 'percentage') {
  22652. foreach($gradient['coords'] as $key => $val) {
  22653. $gradient['coords'][$key] = (intval($val) / 100);
  22654. if ($val < 0) {
  22655. $gradient['coords'][$key] = 0;
  22656. } elseif ($val > 1) {
  22657. $gradient['coords'][$key] = 1;
  22658. }
  22659. }
  22660. }
  22661. if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  22662. // single color (no shading)
  22663. $gradient['coords'][0] = 1;
  22664. $gradient['coords'][1] = 0;
  22665. $gradient['coords'][2] = 0.999;
  22666. $gradient['coords'][3] = 0;
  22667. }
  22668. // swap Y coordinates
  22669. $tmp = $gradient['coords'][1];
  22670. $gradient['coords'][1] = $gradient['coords'][3];
  22671. $gradient['coords'][3] = $tmp;
  22672. // set transformation map for gradient
  22673. $cy = ($this->h - $y);
  22674. if ($gradient['type'] == 3) {
  22675. // circular gradient
  22676. $cy -= ($gradient['coords'][1] * ($w + $h));
  22677. $h = $w = max($w, $h);
  22678. } else {
  22679. $cy -= $h;
  22680. }
  22681. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), ($cy * $this->k)));
  22682. if (count($gradient['stops']) > 1) {
  22683. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  22684. }
  22685. } elseif ($svgstyle['fill'] != 'none') {
  22686. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
  22687. if ($svgstyle['fill-opacity'] != 1) {
  22688. $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
  22689. }
  22690. $this->setFillColorArray($fill_color);
  22691. if ($svgstyle['fill-rule'] == 'evenodd') {
  22692. $objstyle .= 'F*';
  22693. } else {
  22694. $objstyle .= 'F';
  22695. }
  22696. }
  22697. // stroke
  22698. if ($svgstyle['stroke'] != 'none') {
  22699. if ($svgstyle['stroke-opacity'] != 1) {
  22700. $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false);
  22701. } elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i', $svgstyle['stroke'], $rgba_matches)) {
  22702. $this->setAlpha($rgba_matches[1], 'Normal', $this->alpha['ca'], false);
  22703. }
  22704. $stroke_style = array(
  22705. 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors),
  22706. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  22707. 'cap' => $svgstyle['stroke-linecap'],
  22708. 'join' => $svgstyle['stroke-linejoin']
  22709. );
  22710. if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  22711. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  22712. }
  22713. $this->setLineStyle($stroke_style);
  22714. $objstyle .= 'D';
  22715. }
  22716. // font
  22717. $regs = array();
  22718. if (!empty($svgstyle['font'])) {
  22719. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
  22720. $font_family = $this->getFontFamilyName($regs[1]);
  22721. } else {
  22722. $font_family = $svgstyle['font-family'];
  22723. }
  22724. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22725. $font_size = trim($regs[1]);
  22726. } else {
  22727. $font_size = $svgstyle['font-size'];
  22728. }
  22729. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22730. $font_style = trim($regs[1]);
  22731. } else {
  22732. $font_style = $svgstyle['font-style'];
  22733. }
  22734. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22735. $font_weight = trim($regs[1]);
  22736. } else {
  22737. $font_weight = $svgstyle['font-weight'];
  22738. }
  22739. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22740. $font_stretch = trim($regs[1]);
  22741. } else {
  22742. $font_stretch = $svgstyle['font-stretch'];
  22743. }
  22744. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22745. $font_spacing = trim($regs[1]);
  22746. } else {
  22747. $font_spacing = $svgstyle['letter-spacing'];
  22748. }
  22749. } else {
  22750. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  22751. $font_size = $svgstyle['font-size'];
  22752. $font_style = $svgstyle['font-style'];
  22753. $font_weight = $svgstyle['font-weight'];
  22754. $font_stretch = $svgstyle['font-stretch'];
  22755. $font_spacing = $svgstyle['letter-spacing'];
  22756. }
  22757. $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit);
  22758. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  22759. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  22760. switch ($font_style) {
  22761. case 'italic': {
  22762. $font_style = 'I';
  22763. break;
  22764. }
  22765. case 'oblique': {
  22766. $font_style = 'I';
  22767. break;
  22768. }
  22769. default:
  22770. case 'normal': {
  22771. $font_style = '';
  22772. break;
  22773. }
  22774. }
  22775. switch ($font_weight) {
  22776. case 'bold':
  22777. case 'bolder': {
  22778. $font_style .= 'B';
  22779. break;
  22780. }
  22781. case 'normal': {
  22782. if ((substr($font_family, -1) == 'I') AND (substr($font_family, -2, 1) == 'B')) {
  22783. $font_family = substr($font_family, 0, -2).'I';
  22784. } elseif (substr($font_family, -1) == 'B') {
  22785. $font_family = substr($font_family, 0, -1);
  22786. }
  22787. break;
  22788. }
  22789. }
  22790. switch ($svgstyle['text-decoration']) {
  22791. case 'underline': {
  22792. $font_style .= 'U';
  22793. break;
  22794. }
  22795. case 'overline': {
  22796. $font_style .= 'O';
  22797. break;
  22798. }
  22799. case 'line-through': {
  22800. $font_style .= 'D';
  22801. break;
  22802. }
  22803. default:
  22804. case 'none': {
  22805. break;
  22806. }
  22807. }
  22808. $this->setFont($font_family, $font_style, $font_size);
  22809. $this->setFontStretching($font_stretch);
  22810. $this->setFontSpacing($font_spacing);
  22811. return $objstyle;
  22812. }
  22813. /**
  22814. * Draws an SVG path
  22815. * @param string $d attribute d of the path SVG element
  22816. * @param string $style Style of rendering. Possible values are:
  22817. * <ul>
  22818. * <li>D or empty string: Draw (default).</li>
  22819. * <li>F: Fill.</li>
  22820. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22821. * <li>DF or FD: Draw and fill.</li>
  22822. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22823. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  22824. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  22825. * </ul>
  22826. * @return array of container box measures (x, y, w, h)
  22827. * @author Nicola Asuni
  22828. * @since 5.0.000 (2010-05-02)
  22829. * @protected
  22830. */
  22831. protected function SVGPath($d, $style='') {
  22832. if ($this->state != 2) {
  22833. return;
  22834. }
  22835. // set fill/stroke style
  22836. $op = TCPDF_STATIC::getPathPaintOperator($style, '');
  22837. if (empty($op)) {
  22838. return;
  22839. }
  22840. $paths = array();
  22841. $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
  22842. $d = preg_replace('/(\.[0-9]+)(\.)/s', '\\1 \\2', $d);
  22843. preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
  22844. $x = 0;
  22845. $y = 0;
  22846. $x1 = 0;
  22847. $y1 = 0;
  22848. $x2 = 0;
  22849. $y2 = 0;
  22850. $xmin = 2147483647;
  22851. $xmax = 0;
  22852. $ymin = 2147483647;
  22853. $ymax = 0;
  22854. $xinitial = 0;
  22855. $yinitial = 0;
  22856. $relcoord = false;
  22857. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  22858. $firstcmd = true; // used to print first point
  22859. // draw curve pieces
  22860. foreach ($paths as $key => $val) {
  22861. // get curve type
  22862. $cmd = trim($val[1]);
  22863. if (strtolower($cmd) == $cmd) {
  22864. // use relative coordinated instead of absolute
  22865. $relcoord = true;
  22866. $xoffset = $x;
  22867. $yoffset = $y;
  22868. } else {
  22869. $relcoord = false;
  22870. $xoffset = 0;
  22871. $yoffset = 0;
  22872. }
  22873. $params = array();
  22874. if (isset($val[2])) {
  22875. // get curve parameters
  22876. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  22877. $params = array();
  22878. foreach ($rawparams as $ck => $cp) {
  22879. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  22880. if (abs($params[$ck]) < $minlen) {
  22881. // approximate little values to zero
  22882. $params[$ck] = 0;
  22883. }
  22884. }
  22885. }
  22886. // store current origin point
  22887. $x0 = $x;
  22888. $y0 = $y;
  22889. switch (strtoupper($cmd)) {
  22890. case 'M': { // moveto
  22891. foreach ($params as $ck => $cp) {
  22892. if (($ck % 2) == 0) {
  22893. $x = $cp + $xoffset;
  22894. } else {
  22895. $y = $cp + $yoffset;
  22896. if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22897. if ($ck == 1) {
  22898. $this->_outPoint($x, $y);
  22899. $firstcmd = false;
  22900. $xinitial = $x;
  22901. $yinitial = $y;
  22902. } else {
  22903. $this->_outLine($x, $y);
  22904. }
  22905. $x0 = $x;
  22906. $y0 = $y;
  22907. }
  22908. $xmin = min($xmin, $x);
  22909. $ymin = min($ymin, $y);
  22910. $xmax = max($xmax, $x);
  22911. $ymax = max($ymax, $y);
  22912. if ($relcoord) {
  22913. $xoffset = $x;
  22914. $yoffset = $y;
  22915. }
  22916. }
  22917. }
  22918. break;
  22919. }
  22920. case 'L': { // lineto
  22921. foreach ($params as $ck => $cp) {
  22922. if (($ck % 2) == 0) {
  22923. $x = $cp + $xoffset;
  22924. } else {
  22925. $y = $cp + $yoffset;
  22926. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22927. $this->_outLine($x, $y);
  22928. $x0 = $x;
  22929. $y0 = $y;
  22930. }
  22931. $xmin = min($xmin, $x);
  22932. $ymin = min($ymin, $y);
  22933. $xmax = max($xmax, $x);
  22934. $ymax = max($ymax, $y);
  22935. if ($relcoord) {
  22936. $xoffset = $x;
  22937. $yoffset = $y;
  22938. }
  22939. }
  22940. }
  22941. break;
  22942. }
  22943. case 'H': { // horizontal lineto
  22944. foreach ($params as $ck => $cp) {
  22945. $x = $cp + $xoffset;
  22946. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22947. $this->_outLine($x, $y);
  22948. $x0 = $x;
  22949. $y0 = $y;
  22950. }
  22951. $xmin = min($xmin, $x);
  22952. $xmax = max($xmax, $x);
  22953. if ($relcoord) {
  22954. $xoffset = $x;
  22955. }
  22956. }
  22957. break;
  22958. }
  22959. case 'V': { // vertical lineto
  22960. foreach ($params as $ck => $cp) {
  22961. $y = $cp + $yoffset;
  22962. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22963. $this->_outLine($x, $y);
  22964. $x0 = $x;
  22965. $y0 = $y;
  22966. }
  22967. $ymin = min($ymin, $y);
  22968. $ymax = max($ymax, $y);
  22969. if ($relcoord) {
  22970. $yoffset = $y;
  22971. }
  22972. }
  22973. break;
  22974. }
  22975. case 'C': { // curveto
  22976. foreach ($params as $ck => $cp) {
  22977. $params[$ck] = $cp;
  22978. if ((($ck + 1) % 6) == 0) {
  22979. $x1 = $params[($ck - 5)] + $xoffset;
  22980. $y1 = $params[($ck - 4)] + $yoffset;
  22981. $x2 = $params[($ck - 3)] + $xoffset;
  22982. $y2 = $params[($ck - 2)] + $yoffset;
  22983. $x = $params[($ck - 1)] + $xoffset;
  22984. $y = $params[($ck)] + $yoffset;
  22985. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  22986. $xmin = min($xmin, $x, $x1, $x2);
  22987. $ymin = min($ymin, $y, $y1, $y2);
  22988. $xmax = max($xmax, $x, $x1, $x2);
  22989. $ymax = max($ymax, $y, $y1, $y2);
  22990. if ($relcoord) {
  22991. $xoffset = $x;
  22992. $yoffset = $y;
  22993. }
  22994. }
  22995. }
  22996. break;
  22997. }
  22998. case 'S': { // shorthand/smooth curveto
  22999. foreach ($params as $ck => $cp) {
  23000. $params[$ck] = $cp;
  23001. if ((($ck + 1) % 4) == 0) {
  23002. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
  23003. $x1 = (2 * $x) - $x2;
  23004. $y1 = (2 * $y) - $y2;
  23005. } else {
  23006. $x1 = $x;
  23007. $y1 = $y;
  23008. }
  23009. $x2 = $params[($ck - 3)] + $xoffset;
  23010. $y2 = $params[($ck - 2)] + $yoffset;
  23011. $x = $params[($ck - 1)] + $xoffset;
  23012. $y = $params[($ck)] + $yoffset;
  23013. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  23014. $xmin = min($xmin, $x, $x1, $x2);
  23015. $ymin = min($ymin, $y, $y1, $y2);
  23016. $xmax = max($xmax, $x, $x1, $x2);
  23017. $ymax = max($ymax, $y, $y1, $y2);
  23018. if ($relcoord) {
  23019. $xoffset = $x;
  23020. $yoffset = $y;
  23021. }
  23022. }
  23023. }
  23024. break;
  23025. }
  23026. case 'Q': { // quadratic Bezier curveto
  23027. foreach ($params as $ck => $cp) {
  23028. $params[$ck] = $cp;
  23029. if ((($ck + 1) % 4) == 0) {
  23030. // convert quadratic points to cubic points
  23031. $x1 = $params[($ck - 3)] + $xoffset;
  23032. $y1 = $params[($ck - 2)] + $yoffset;
  23033. $xa = ($x + (2 * $x1)) / 3;
  23034. $ya = ($y + (2 * $y1)) / 3;
  23035. $x = $params[($ck - 1)] + $xoffset;
  23036. $y = $params[($ck)] + $yoffset;
  23037. $xb = ($x + (2 * $x1)) / 3;
  23038. $yb = ($y + (2 * $y1)) / 3;
  23039. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  23040. $xmin = min($xmin, $x, $xa, $xb);
  23041. $ymin = min($ymin, $y, $ya, $yb);
  23042. $xmax = max($xmax, $x, $xa, $xb);
  23043. $ymax = max($ymax, $y, $ya, $yb);
  23044. if ($relcoord) {
  23045. $xoffset = $x;
  23046. $yoffset = $y;
  23047. }
  23048. }
  23049. }
  23050. break;
  23051. }
  23052. case 'T': { // shorthand/smooth quadratic Bezier curveto
  23053. foreach ($params as $ck => $cp) {
  23054. $params[$ck] = $cp;
  23055. if (($ck % 2) != 0) {
  23056. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
  23057. $x1 = (2 * $x) - $x1;
  23058. $y1 = (2 * $y) - $y1;
  23059. } else {
  23060. $x1 = $x;
  23061. $y1 = $y;
  23062. }
  23063. // convert quadratic points to cubic points
  23064. $xa = ($x + (2 * $x1)) / 3;
  23065. $ya = ($y + (2 * $y1)) / 3;
  23066. $x = $params[($ck - 1)] + $xoffset;
  23067. $y = $params[($ck)] + $yoffset;
  23068. $xb = ($x + (2 * $x1)) / 3;
  23069. $yb = ($y + (2 * $y1)) / 3;
  23070. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  23071. $xmin = min($xmin, $x, $xa, $xb);
  23072. $ymin = min($ymin, $y, $ya, $yb);
  23073. $xmax = max($xmax, $x, $xa, $xb);
  23074. $ymax = max($ymax, $y, $ya, $yb);
  23075. if ($relcoord) {
  23076. $xoffset = $x;
  23077. $yoffset = $y;
  23078. }
  23079. }
  23080. }
  23081. break;
  23082. }
  23083. case 'A': { // elliptical arc
  23084. foreach ($params as $ck => $cp) {
  23085. $params[$ck] = $cp;
  23086. if ((($ck + 1) % 7) == 0) {
  23087. $x0 = $x;
  23088. $y0 = $y;
  23089. $rx = max(abs($params[($ck - 6)]), .000000001);
  23090. $ry = max(abs($params[($ck - 5)]), .000000001);
  23091. $ang = -$rawparams[($ck - 4)];
  23092. $angle = deg2rad($ang);
  23093. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  23094. $fs = $rawparams[($ck - 2)]; // sweep-flag
  23095. $x = $params[($ck - 1)] + $xoffset;
  23096. $y = $params[$ck] + $yoffset;
  23097. if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
  23098. // endpoints are almost identical
  23099. $xmin = min($xmin, $x);
  23100. $ymin = min($ymin, $y);
  23101. $xmax = max($xmax, $x);
  23102. $ymax = max($ymax, $y);
  23103. } else {
  23104. $cos_ang = cos($angle);
  23105. $sin_ang = sin($angle);
  23106. $a = (($x0 - $x) / 2);
  23107. $b = (($y0 - $y) / 2);
  23108. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  23109. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  23110. $rx2 = $rx * $rx;
  23111. $ry2 = $ry * $ry;
  23112. $xa2 = $xa * $xa;
  23113. $ya2 = $ya * $ya;
  23114. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  23115. if ($delta > 1) {
  23116. $rx *= sqrt($delta);
  23117. $ry *= sqrt($delta);
  23118. $rx2 = $rx * $rx;
  23119. $ry2 = $ry * $ry;
  23120. }
  23121. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  23122. if ($numerator < 0) {
  23123. $root = 0;
  23124. } else {
  23125. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  23126. }
  23127. if ($fa == $fs){
  23128. $root *= -1;
  23129. }
  23130. $cax = $root * (($rx * $ya) / $ry);
  23131. $cay = -$root * (($ry * $xa) / $rx);
  23132. // coordinates of ellipse center
  23133. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  23134. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  23135. // get angles
  23136. $angs = TCPDF_STATIC::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  23137. $dang = TCPDF_STATIC::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
  23138. if (($fs == 0) AND ($dang > 0)) {
  23139. $dang -= (2 * M_PI);
  23140. } elseif (($fs == 1) AND ($dang < 0)) {
  23141. $dang += (2 * M_PI);
  23142. }
  23143. $angf = $angs - $dang;
  23144. if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
  23145. // reverse angles
  23146. $tmp = $angs;
  23147. $angs = $angf;
  23148. $angf = $tmp;
  23149. }
  23150. $angs = round(rad2deg($angs), 6);
  23151. $angf = round(rad2deg($angf), 6);
  23152. // covent angles to positive values
  23153. if (($angs < 0) AND ($angf < 0)) {
  23154. $angs += 360;
  23155. $angf += 360;
  23156. }
  23157. $pie = false;
  23158. if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
  23159. $pie = true;
  23160. }
  23161. list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
  23162. $xmin = min($xmin, $x, $axmin);
  23163. $ymin = min($ymin, $y, $aymin);
  23164. $xmax = max($xmax, $x, $axmax);
  23165. $ymax = max($ymax, $y, $aymax);
  23166. }
  23167. if ($relcoord) {
  23168. $xoffset = $x;
  23169. $yoffset = $y;
  23170. }
  23171. }
  23172. }
  23173. break;
  23174. }
  23175. case 'Z': {
  23176. $this->_out('h');
  23177. $x = $x0 = $xinitial;
  23178. $y = $y0 = $yinitial;
  23179. break;
  23180. }
  23181. }
  23182. $firstcmd = false;
  23183. } // end foreach
  23184. if (!empty($op)) {
  23185. $this->_out($op);
  23186. }
  23187. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  23188. }
  23189. /**
  23190. * Return the tag name without the namespace
  23191. * @param string $name Tag name
  23192. * @protected
  23193. */
  23194. protected function removeTagNamespace($name) {
  23195. if(strpos($name, ':') !== false) {
  23196. $parts = explode(':', $name);
  23197. return $parts[(sizeof($parts) - 1)];
  23198. }
  23199. return $name;
  23200. }
  23201. /**
  23202. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  23203. * @param resource|string $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  23204. * @param string $name 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.
  23205. * @param array $attribs 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.
  23206. * @param array $ctm tranformation matrix for clipping mode (starting transformation matrix).
  23207. * @author Nicola Asuni
  23208. * @since 5.0.000 (2010-05-02)
  23209. * @protected
  23210. */
  23211. protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
  23212. $name = $this->removeTagNamespace($name);
  23213. // check if we are in clip mode
  23214. if ($this->svgclipmode) {
  23215. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
  23216. return;
  23217. }
  23218. if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
  23219. if (isset($attribs['id'])) {
  23220. $attribs['child_elements'] = array();
  23221. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  23222. return;
  23223. }
  23224. if (end($this->svgdefs) !== FALSE) {
  23225. $last_svgdefs_id = key($this->svgdefs);
  23226. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23227. $attribs['id'] = 'DF_'.(count($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements']) + 1);
  23228. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  23229. return;
  23230. }
  23231. }
  23232. return;
  23233. }
  23234. $clipping = false;
  23235. if ($parser == 'clip-path') {
  23236. // set clipping mode
  23237. $clipping = true;
  23238. }
  23239. // get styling properties
  23240. $prev_svgstyle = $this->svgstyles[max(0,(count($this->svgstyles) - 1))]; // previous style
  23241. $svgstyle = $this->svgstyles[0]; // set default style
  23242. if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
  23243. // default fill attribute for clipping
  23244. $attribs['fill'] = 'none';
  23245. }
  23246. if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style']) AND ($attribs['style'][0] != ';')) {
  23247. // fix style for regular expression
  23248. $attribs['style'] = ';'.$attribs['style'];
  23249. }
  23250. foreach ($prev_svgstyle as $key => $val) {
  23251. if (in_array($key, TCPDF_IMAGES::$svginheritprop)) {
  23252. // inherit previous value
  23253. $svgstyle[$key] = $val;
  23254. }
  23255. if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) {
  23256. // specific attribute settings
  23257. if ($attribs[$key] == 'inherit') {
  23258. $svgstyle[$key] = $val;
  23259. } else {
  23260. $svgstyle[$key] = $attribs[$key];
  23261. }
  23262. } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  23263. // CSS style syntax
  23264. $attrval = array();
  23265. if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
  23266. if ($attrval[1] == 'inherit') {
  23267. $svgstyle[$key] = $val;
  23268. } else {
  23269. $svgstyle[$key] = $attrval[1];
  23270. }
  23271. }
  23272. }
  23273. }
  23274. // transformation matrix
  23275. if (!empty($ctm)) {
  23276. $tm = $ctm;
  23277. } else {
  23278. $tm = array(1,0,0,1,0,0);
  23279. }
  23280. if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  23281. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, TCPDF_STATIC::getSVGTransformMatrix($attribs['transform']));
  23282. }
  23283. $svgstyle['transfmatrix'] = $tm;
  23284. $invisible = false;
  23285. if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  23286. // the current graphics element is invisible (nothing is painted)
  23287. $invisible = true;
  23288. }
  23289. // process tag
  23290. switch($name) {
  23291. case 'defs': {
  23292. $this->svgdefsmode = true;
  23293. break;
  23294. }
  23295. // clipPath
  23296. case 'clipPath': {
  23297. if ($invisible) {
  23298. break;
  23299. }
  23300. $this->svgclipmode = true;
  23301. if (!isset($attribs['id'])) {
  23302. $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  23303. }
  23304. $this->svgclipid = $attribs['id'];
  23305. $this->svgclippaths[$this->svgclipid] = array();
  23306. $this->svgcliptm[$this->svgclipid] = $tm;
  23307. break;
  23308. }
  23309. case 'svg': {
  23310. // start of SVG object
  23311. if(++$this->svg_tag_depth <= 1) {
  23312. break;
  23313. }
  23314. // inner SVG
  23315. array_push($this->svgstyles, $svgstyle);
  23316. $this->StartTransform();
  23317. $svgX = (isset($attribs['x'])?$attribs['x']:0);
  23318. $svgY = (isset($attribs['y'])?$attribs['y']:0);
  23319. $svgW = (isset($attribs['width'])?$attribs['width']:0);
  23320. $svgH = (isset($attribs['height'])?$attribs['height']:0);
  23321. // set x, y position using transform matrix
  23322. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array( 1, 0, 0, 1, $svgX, $svgY));
  23323. $this->SVGTransform($tm);
  23324. // set clipping for width and height
  23325. $x = 0;
  23326. $y = 0;
  23327. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):$this->w);
  23328. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):$this->h);
  23329. // draw clipping rect
  23330. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  23331. // parse viewbox, calculate extra transformation matrix
  23332. if (isset($attribs['viewBox'])) {
  23333. $tmp = array();
  23334. preg_match_all("/[0-9]+/", $attribs['viewBox'], $tmp);
  23335. $tmp = $tmp[0];
  23336. if (sizeof($tmp) == 4) {
  23337. $vx = $tmp[0];
  23338. $vy = $tmp[1];
  23339. $vw = $tmp[2];
  23340. $vh = $tmp[3];
  23341. // get aspect ratio
  23342. $tmp = array();
  23343. $aspectX = 'xMid';
  23344. $aspectY = 'YMid';
  23345. $fit = 'meet';
  23346. if (isset($attribs['preserveAspectRatio'])) {
  23347. if($attribs['preserveAspectRatio'] == 'none') {
  23348. $fit = 'none';
  23349. } else {
  23350. preg_match_all('/[a-zA-Z]+/', $attribs['preserveAspectRatio'], $tmp);
  23351. $tmp = $tmp[0];
  23352. if ((sizeof($tmp) == 2) AND (strlen($tmp[0]) == 8) AND (in_array($tmp[1], array('meet', 'slice', 'none')))) {
  23353. $aspectX = substr($tmp[0], 0, 4);
  23354. $aspectY = substr($tmp[0], 4, 4);
  23355. $fit = $tmp[1];
  23356. }
  23357. }
  23358. }
  23359. $wr = ($svgW / $vw);
  23360. $hr = ($svgH / $vh);
  23361. $ax = $ay = 0;
  23362. if ((($fit == 'meet') AND ($hr < $wr)) OR (($fit == 'slice') AND ($hr > $wr))) {
  23363. if ($aspectX == 'xMax') {
  23364. $ax = (($vw * ($wr / $hr)) - $vw);
  23365. }
  23366. if ($aspectX == 'xMid') {
  23367. $ax = ((($vw * ($wr / $hr)) - $vw) / 2);
  23368. }
  23369. $wr = $hr;
  23370. } elseif ((($fit == 'meet') AND ($hr > $wr)) OR (($fit == 'slice') AND ($hr < $wr))) {
  23371. if ($aspectY == 'YMax') {
  23372. $ay = (($vh * ($hr / $wr)) - $vh);
  23373. }
  23374. if ($aspectY == 'YMid') {
  23375. $ay = ((($vh * ($hr / $wr)) - $vh) / 2);
  23376. }
  23377. $hr = $wr;
  23378. }
  23379. $newtm = array($wr, 0, 0, $hr, (($wr * ($ax - $vx)) - $svgX), (($hr * ($ay - $vy)) - $svgY));
  23380. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, $newtm);
  23381. $this->SVGTransform($tm);
  23382. }
  23383. }
  23384. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23385. break;
  23386. }
  23387. case 'g': {
  23388. // group together related graphics elements
  23389. array_push($this->svgstyles, $svgstyle);
  23390. $this->StartTransform();
  23391. $x = (isset($attribs['x'])?$attribs['x']:0);
  23392. $y = (isset($attribs['y'])?$attribs['y']:0);
  23393. $w = 1;//(isset($attribs['width'])?$attribs['width']:1);
  23394. $h = 1;//(isset($attribs['height'])?$attribs['height']:1);
  23395. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23396. $this->SVGTransform($tm);
  23397. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23398. break;
  23399. }
  23400. case 'linearGradient': {
  23401. if ($this->pdfa_mode && $this->pdfa_version < 2) {
  23402. break;
  23403. }
  23404. if (!isset($attribs['id'])) {
  23405. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23406. }
  23407. $this->svggradientid = $attribs['id'];
  23408. $this->svggradients[$this->svggradientid] = array();
  23409. $this->svggradients[$this->svggradientid]['type'] = 2;
  23410. $this->svggradients[$this->svggradientid]['stops'] = array();
  23411. if (isset($attribs['gradientUnits'])) {
  23412. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23413. } else {
  23414. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23415. }
  23416. //$attribs['spreadMethod']
  23417. if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
  23418. OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
  23419. OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
  23420. OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
  23421. OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
  23422. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23423. } else {
  23424. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23425. }
  23426. $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
  23427. $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
  23428. $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
  23429. $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
  23430. if (isset($attribs['gradientTransform'])) {
  23431. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23432. }
  23433. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  23434. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23435. // gradient is defined on another place
  23436. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23437. }
  23438. break;
  23439. }
  23440. case 'radialGradient': {
  23441. if ($this->pdfa_mode && $this->pdfa_version < 2) {
  23442. break;
  23443. }
  23444. if (!isset($attribs['id'])) {
  23445. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23446. }
  23447. $this->svggradientid = $attribs['id'];
  23448. $this->svggradients[$this->svggradientid] = array();
  23449. $this->svggradients[$this->svggradientid]['type'] = 3;
  23450. $this->svggradients[$this->svggradientid]['stops'] = array();
  23451. if (isset($attribs['gradientUnits'])) {
  23452. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23453. } else {
  23454. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23455. }
  23456. //$attribs['spreadMethod']
  23457. if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
  23458. OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
  23459. OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')))) {
  23460. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23461. } elseif (isset($attribs['r']) AND is_numeric($attribs['r']) AND ($attribs['r']) <= 1) {
  23462. $this->svggradients[$this->svggradientid]['mode'] = 'ratio';
  23463. } else {
  23464. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23465. }
  23466. $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  23467. $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  23468. $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  23469. $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  23470. $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  23471. if (isset($attribs['gradientTransform'])) {
  23472. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23473. }
  23474. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  23475. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23476. // gradient is defined on another place
  23477. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23478. }
  23479. break;
  23480. }
  23481. case 'stop': {
  23482. // gradient stops
  23483. if (substr($attribs['offset'], -1) == '%') {
  23484. $offset = floatval(substr($attribs['offset'], 0, -1)) / 100;
  23485. } else {
  23486. $offset = floatval($attribs['offset']);
  23487. if ($offset > 1) {
  23488. $offset /= 100;
  23489. }
  23490. }
  23491. $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black';
  23492. $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  23493. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
  23494. break;
  23495. }
  23496. // paths
  23497. case 'path': {
  23498. if ($invisible) {
  23499. break;
  23500. }
  23501. if (isset($attribs['d'])) {
  23502. $d = trim($attribs['d']);
  23503. if (!empty($d)) {
  23504. $x = (isset($attribs['x'])?$attribs['x']:0);
  23505. $y = (isset($attribs['y'])?$attribs['y']:0);
  23506. $w = (isset($attribs['width'])?$attribs['width']:1);
  23507. $h = (isset($attribs['height'])?$attribs['height']:1);
  23508. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23509. if ($clipping) {
  23510. $this->SVGTransform($tm);
  23511. $this->SVGPath($d, 'CNZ');
  23512. } else {
  23513. $this->StartTransform();
  23514. $this->SVGTransform($tm);
  23515. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ'));
  23516. if (!empty($obstyle)) {
  23517. $this->SVGPath($d, $obstyle);
  23518. }
  23519. $this->StopTransform();
  23520. }
  23521. }
  23522. }
  23523. break;
  23524. }
  23525. // shapes
  23526. case 'rect': {
  23527. if ($invisible) {
  23528. break;
  23529. }
  23530. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23531. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23532. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23533. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23534. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  23535. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
  23536. if ($clipping) {
  23537. $this->SVGTransform($tm);
  23538. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  23539. } else {
  23540. $this->StartTransform();
  23541. $this->SVGTransform($tm);
  23542. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  23543. if (!empty($obstyle)) {
  23544. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  23545. }
  23546. $this->StopTransform();
  23547. }
  23548. break;
  23549. }
  23550. case 'circle': {
  23551. if ($invisible) {
  23552. break;
  23553. }
  23554. $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
  23555. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23556. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23557. $x = ($cx - $r);
  23558. $y = ($cy - $r);
  23559. $w = (2 * $r);
  23560. $h = $w;
  23561. if ($clipping) {
  23562. $this->SVGTransform($tm);
  23563. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  23564. } else {
  23565. $this->StartTransform();
  23566. $this->SVGTransform($tm);
  23567. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
  23568. if (!empty($obstyle)) {
  23569. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  23570. }
  23571. $this->StopTransform();
  23572. }
  23573. break;
  23574. }
  23575. case 'ellipse': {
  23576. if ($invisible) {
  23577. break;
  23578. }
  23579. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  23580. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
  23581. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23582. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23583. $x = ($cx - $rx);
  23584. $y = ($cy - $ry);
  23585. $w = (2 * $rx);
  23586. $h = (2 * $ry);
  23587. if ($clipping) {
  23588. $this->SVGTransform($tm);
  23589. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  23590. } else {
  23591. $this->StartTransform();
  23592. $this->SVGTransform($tm);
  23593. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  23594. if (!empty($obstyle)) {
  23595. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  23596. }
  23597. $this->StopTransform();
  23598. }
  23599. break;
  23600. }
  23601. case 'line': {
  23602. if ($invisible) {
  23603. break;
  23604. }
  23605. $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
  23606. $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
  23607. $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
  23608. $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
  23609. $x = $x1;
  23610. $y = $y1;
  23611. $w = abs($x2 - $x1);
  23612. $h = abs($y2 - $y1);
  23613. if (!$clipping) {
  23614. $this->StartTransform();
  23615. $this->SVGTransform($tm);
  23616. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
  23617. $this->Line($x1, $y1, $x2, $y2);
  23618. $this->StopTransform();
  23619. }
  23620. break;
  23621. }
  23622. case 'polyline':
  23623. case 'polygon': {
  23624. if ($invisible) {
  23625. break;
  23626. }
  23627. $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  23628. $points = trim($points);
  23629. // note that point may use a complex syntax not covered here
  23630. $points = preg_split('/[\,\s]+/si', $points);
  23631. if (count($points) < 4) {
  23632. break;
  23633. }
  23634. $p = array();
  23635. $xmin = 2147483647;
  23636. $xmax = 0;
  23637. $ymin = 2147483647;
  23638. $ymax = 0;
  23639. foreach ($points as $key => $val) {
  23640. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  23641. if (($key % 2) == 0) {
  23642. // X coordinate
  23643. $xmin = min($xmin, $p[$key]);
  23644. $xmax = max($xmax, $p[$key]);
  23645. } else {
  23646. // Y coordinate
  23647. $ymin = min($ymin, $p[$key]);
  23648. $ymax = max($ymax, $p[$key]);
  23649. }
  23650. }
  23651. $x = $xmin;
  23652. $y = $ymin;
  23653. $w = ($xmax - $xmin);
  23654. $h = ($ymax - $ymin);
  23655. if ($name == 'polyline') {
  23656. $this->StartTransform();
  23657. $this->SVGTransform($tm);
  23658. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
  23659. if (!empty($obstyle)) {
  23660. $this->PolyLine($p, $obstyle, array(), array());
  23661. }
  23662. $this->StopTransform();
  23663. } else { // polygon
  23664. if ($clipping) {
  23665. $this->SVGTransform($tm);
  23666. $this->Polygon($p, 'CNZ', array(), array(), true);
  23667. } else {
  23668. $this->StartTransform();
  23669. $this->SVGTransform($tm);
  23670. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
  23671. if (!empty($obstyle)) {
  23672. $this->Polygon($p, $obstyle, array(), array(), true);
  23673. }
  23674. $this->StopTransform();
  23675. }
  23676. }
  23677. break;
  23678. }
  23679. // image
  23680. case 'image': {
  23681. if ($invisible) {
  23682. break;
  23683. }
  23684. if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  23685. break;
  23686. }
  23687. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23688. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23689. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23690. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23691. $img = $attribs['xlink:href'];
  23692. if (!$clipping) {
  23693. $this->StartTransform();
  23694. $this->SVGTransform($tm);
  23695. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  23696. if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
  23697. // embedded image encoded as base64
  23698. $img = '@'.base64_decode(substr($img, strlen($m[0])));
  23699. } else {
  23700. // fix image path
  23701. if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) {
  23702. // replace relative path with full server path
  23703. $img = $this->svgdir.'/'.$img;
  23704. }
  23705. if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  23706. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  23707. if (($findroot === false) OR ($findroot > 1)) {
  23708. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  23709. $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
  23710. } else {
  23711. $img = $_SERVER['DOCUMENT_ROOT'].$img;
  23712. }
  23713. }
  23714. }
  23715. $img = urldecode($img);
  23716. $testscrtype = @parse_url($img);
  23717. if (empty($testscrtype['query'])) {
  23718. // convert URL to server path
  23719. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  23720. } elseif (preg_match('|^https?://|', $img) !== 1) {
  23721. // convert server path to URL
  23722. $img = str_replace(K_PATH_MAIN, K_PATH_URL, $img);
  23723. }
  23724. }
  23725. // get image type
  23726. $imgtype = TCPDF_IMAGES::getImageFileType($img);
  23727. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  23728. $this->ImageEps($img, $x, $y, $w, $h);
  23729. } elseif ($imgtype == 'svg') {
  23730. // store SVG vars
  23731. $svggradients = $this->svggradients;
  23732. $svggradientid = $this->svggradientid;
  23733. $svgdefsmode = $this->svgdefsmode;
  23734. $svgdefs = $this->svgdefs;
  23735. $svgclipmode = $this->svgclipmode;
  23736. $svgclippaths = $this->svgclippaths;
  23737. $svgcliptm = $this->svgcliptm;
  23738. $svgclipid = $this->svgclipid;
  23739. $svgtext = $this->svgtext;
  23740. $svgtextmode = $this->svgtextmode;
  23741. $this->ImageSVG($img, $x, $y, $w, $h);
  23742. // restore SVG vars
  23743. $this->svggradients = $svggradients;
  23744. $this->svggradientid = $svggradientid;
  23745. $this->svgdefsmode = $svgdefsmode;
  23746. $this->svgdefs = $svgdefs;
  23747. $this->svgclipmode = $svgclipmode;
  23748. $this->svgclippaths = $svgclippaths;
  23749. $this->svgcliptm = $svgcliptm;
  23750. $this->svgclipid = $svgclipid;
  23751. $this->svgtext = $svgtext;
  23752. $this->svgtextmode = $svgtextmode;
  23753. } else {
  23754. $this->Image($img, $x, $y, $w, $h);
  23755. }
  23756. $this->StopTransform();
  23757. }
  23758. break;
  23759. }
  23760. // text
  23761. case 'text':
  23762. case 'tspan': {
  23763. if (isset($this->svgtextmode['text-anchor']) AND !empty($this->svgtext)) {
  23764. // @TODO: unsupported feature
  23765. }
  23766. // only basic support - advanced features must be implemented
  23767. $this->svgtextmode['invisible'] = $invisible;
  23768. if ($invisible) {
  23769. break;
  23770. }
  23771. array_push($this->svgstyles, $svgstyle);
  23772. if (isset($attribs['x'])) {
  23773. $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false);
  23774. } elseif ($name == 'tspan') {
  23775. $x = $this->x;
  23776. } else {
  23777. $x = 0;
  23778. }
  23779. if (isset($attribs['dx'])) {
  23780. $x += $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit, false);
  23781. }
  23782. if (isset($attribs['y'])) {
  23783. $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false);
  23784. } elseif ($name == 'tspan') {
  23785. $y = $this->y;
  23786. } else {
  23787. $y = 0;
  23788. }
  23789. if (isset($attribs['dy'])) {
  23790. $y += $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit, false);
  23791. }
  23792. $svgstyle['text-color'] = $svgstyle['fill'];
  23793. $this->svgtext = '';
  23794. if (isset($svgstyle['text-anchor'])) {
  23795. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  23796. } else {
  23797. $this->svgtextmode['text-anchor'] = 'start';
  23798. }
  23799. if (isset($svgstyle['direction'])) {
  23800. if ($svgstyle['direction'] == 'rtl') {
  23801. $this->svgtextmode['rtl'] = true;
  23802. } else {
  23803. $this->svgtextmode['rtl'] = false;
  23804. }
  23805. } else {
  23806. $this->svgtextmode['rtl'] = false;
  23807. }
  23808. if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  23809. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  23810. } else {
  23811. $this->svgtextmode['stroke'] = false;
  23812. }
  23813. $this->StartTransform();
  23814. $this->SVGTransform($tm);
  23815. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  23816. $this->x = $x;
  23817. $this->y = $y;
  23818. break;
  23819. }
  23820. // use
  23821. case 'use': {
  23822. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23823. $svgdefid = substr($attribs['xlink:href'], 1);
  23824. if (isset($this->svgdefs[$svgdefid])) {
  23825. $use = $this->svgdefs[$svgdefid];
  23826. if (isset($attribs['xlink:href'])) {
  23827. unset($attribs['xlink:href']);
  23828. }
  23829. if (isset($attribs['id'])) {
  23830. unset($attribs['id']);
  23831. }
  23832. if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
  23833. $attribs['x'] += $use['attribs']['x'];
  23834. }
  23835. if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
  23836. $attribs['y'] += $use['attribs']['y'];
  23837. }
  23838. if (empty($attribs['style'])) {
  23839. $attribs['style'] = '';
  23840. }
  23841. if (!empty($use['attribs']['style'])) {
  23842. // merge styles
  23843. $attribs['style'] = str_replace(';;',';',';'.$use['attribs']['style'].$attribs['style']);
  23844. }
  23845. $attribs = array_merge($use['attribs'], $attribs);
  23846. $this->startSVGElementHandler($parser, $use['name'], $attribs);
  23847. return;
  23848. }
  23849. }
  23850. break;
  23851. }
  23852. default: {
  23853. break;
  23854. }
  23855. } // end of switch
  23856. // process child elements
  23857. if (!empty($attribs['child_elements'])) {
  23858. $child_elements = $attribs['child_elements'];
  23859. unset($attribs['child_elements']);
  23860. foreach($child_elements as $child_element) {
  23861. if (empty($child_element['attribs']['closing_tag'])) {
  23862. $this->startSVGElementHandler('child-tag', $child_element['name'], $child_element['attribs']);
  23863. } else {
  23864. if (isset($child_element['attribs']['content'])) {
  23865. $this->svgtext = $child_element['attribs']['content'];
  23866. }
  23867. $this->endSVGElementHandler('child-tag', $child_element['name']);
  23868. }
  23869. }
  23870. }
  23871. }
  23872. /**
  23873. * Sets the closing SVG element handler function for the XML parser.
  23874. * @param resource|string $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  23875. * @param string $name 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.
  23876. * @author Nicola Asuni
  23877. * @since 5.0.000 (2010-05-02)
  23878. * @protected
  23879. */
  23880. protected function endSVGElementHandler($parser, $name) {
  23881. $name = $this->removeTagNamespace($name);
  23882. if ($this->svgdefsmode AND !in_array($name, array('defs', 'clipPath', 'linearGradient', 'radialGradient', 'stop'))) {;
  23883. if (end($this->svgdefs) !== FALSE) {
  23884. $last_svgdefs_id = key($this->svgdefs);
  23885. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23886. foreach($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) {
  23887. if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) {
  23888. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext));
  23889. return;
  23890. }
  23891. }
  23892. if ($this->svgdefs[$last_svgdefs_id]['name'] == $name) {
  23893. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext));
  23894. return;
  23895. }
  23896. }
  23897. }
  23898. return;
  23899. }
  23900. switch($name) {
  23901. case 'defs': {
  23902. $this->svgdefsmode = false;
  23903. break;
  23904. }
  23905. // clipPath
  23906. case 'clipPath': {
  23907. $this->svgclipmode = false;
  23908. break;
  23909. }
  23910. case 'svg': {
  23911. if (--$this->svg_tag_depth <= 0) {
  23912. break;
  23913. }
  23914. }
  23915. case 'g': {
  23916. // ungroup: remove last style from array
  23917. array_pop($this->svgstyles);
  23918. $this->StopTransform();
  23919. break;
  23920. }
  23921. case 'text':
  23922. case 'tspan': {
  23923. if ($this->svgtextmode['invisible']) {
  23924. // This implementation must be fixed to following the rule:
  23925. // 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.
  23926. break;
  23927. }
  23928. // print text
  23929. $text = $this->svgtext;
  23930. //$text = $this->stringTrim($text);
  23931. $textlen = $this->GetStringWidth($text);
  23932. if ($this->svgtextmode['text-anchor'] != 'start') {
  23933. // check if string is RTL text
  23934. if ($this->svgtextmode['text-anchor'] == 'end') {
  23935. if ($this->svgtextmode['rtl']) {
  23936. $this->x += $textlen;
  23937. } else {
  23938. $this->x -= $textlen;
  23939. }
  23940. } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  23941. if ($this->svgtextmode['rtl']) {
  23942. $this->x += ($textlen / 2);
  23943. } else {
  23944. $this->x -= ($textlen / 2);
  23945. }
  23946. }
  23947. }
  23948. $textrendermode = $this->textrendermode;
  23949. $textstrokewidth = $this->textstrokewidth;
  23950. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  23951. if ($name == 'text') {
  23952. // store current coordinates
  23953. $tmpx = $this->x;
  23954. $tmpy = $this->y;
  23955. }
  23956. // print the text
  23957. $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  23958. if ($name == 'text') {
  23959. // restore coordinates
  23960. $this->x = $tmpx;
  23961. $this->y = $tmpy;
  23962. }
  23963. // restore previous rendering mode
  23964. $this->textrendermode = $textrendermode;
  23965. $this->textstrokewidth = $textstrokewidth;
  23966. $this->svgtext = '';
  23967. $this->StopTransform();
  23968. if (!$this->svgdefsmode) {
  23969. array_pop($this->svgstyles);
  23970. }
  23971. break;
  23972. }
  23973. default: {
  23974. break;
  23975. }
  23976. }
  23977. }
  23978. /**
  23979. * Sets the character data handler function for the XML parser.
  23980. * @param resource $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  23981. * @param string $data The second parameter, data, contains the character data as a string.
  23982. * @author Nicola Asuni
  23983. * @since 5.0.000 (2010-05-02)
  23984. * @protected
  23985. */
  23986. protected function segSVGContentHandler($parser, $data) {
  23987. $this->svgtext .= $data;
  23988. }
  23989. // --- END SVG METHODS -----------------------------------------------------
  23990. /**
  23991. * Keeps files in memory, so it doesn't need to downloaded everytime in a loop
  23992. * @param string $file
  23993. * @return string
  23994. */
  23995. protected function getCachedFileContents($file)
  23996. {
  23997. if (!isset($this->fileContentCache[$file])) {
  23998. $this->fileContentCache[$file] = TCPDF_STATIC::fileGetContents($file);
  23999. }
  24000. return $this->fileContentCache[$file];
  24001. }
  24002. /**
  24003. * Avoid multiple calls to an external server to see if a file exists
  24004. * @param string $file
  24005. * @return bool
  24006. */
  24007. protected function fileExists($file)
  24008. {
  24009. if (isset($this->fileContentCache[$file]) || false !== $this->getImageBuffer($file)) {
  24010. return true;
  24011. }
  24012. return TCPDF_STATIC::file_exists($file);
  24013. }
  24014. } // END OF TCPDF CLASS
  24015. //============================================================+
  24016. // END OF FILE
  24017. //============================================================+