tcpdf.php 886 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 6.7.6
  5. // Begin : 2002-08-03
  6. // Last Update : 2024-10-06
  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-2024 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.6.5
  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.7.6
  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. * @var float
  502. */
  503. protected $header_margin;
  504. /**
  505. * Minimum distance between footer and bottom page margin.
  506. * @protected
  507. * @var float
  508. */
  509. protected $footer_margin;
  510. /**
  511. * Original left margin value.
  512. * @protected
  513. * @since 1.53.0.TC013
  514. */
  515. protected $original_lMargin;
  516. /**
  517. * Original right margin value.
  518. * @protected
  519. * @since 1.53.0.TC013
  520. */
  521. protected $original_rMargin;
  522. /**
  523. * Default font used on page header.
  524. * @protected
  525. * @var array<int,string|float|null>
  526. * @phpstan-var array{0: string, 1: string, 2: float|null}
  527. */
  528. protected $header_font;
  529. /**
  530. * Default font used on page footer.
  531. * @protected
  532. * @var array<int,string|float|null>
  533. * @phpstan-var array{0: string, 1: string, 2: float|null}
  534. */
  535. protected $footer_font;
  536. /**
  537. * Language templates.
  538. * @protected
  539. */
  540. protected $l;
  541. /**
  542. * Barcode to print on page footer (only if set).
  543. * @protected
  544. */
  545. protected $barcode = false;
  546. /**
  547. * Boolean flag to print/hide page header.
  548. * @protected
  549. */
  550. protected $print_header = true;
  551. /**
  552. * Boolean flag to print/hide page footer.
  553. * @protected
  554. */
  555. protected $print_footer = true;
  556. /**
  557. * Header image logo.
  558. * @protected
  559. */
  560. protected $header_logo = '';
  561. /**
  562. * Width of header image logo in user units.
  563. * @protected
  564. */
  565. protected $header_logo_width = 30;
  566. /**
  567. * Title to be printed on default page header.
  568. * @protected
  569. */
  570. protected $header_title = '';
  571. /**
  572. * String to print on page header after title.
  573. * @protected
  574. */
  575. protected $header_string = '';
  576. /**
  577. * Color for header text (RGB array).
  578. * @since 5.9.174 (2012-07-25)
  579. * @protected
  580. * @var int[]
  581. * @phpstan-var array{0: int, 1: int, 2: int}
  582. */
  583. protected $header_text_color = array(0,0,0);
  584. /**
  585. * Color for header line (RGB array).
  586. * @since 5.9.174 (2012-07-25)
  587. * @protected
  588. * @var int[]
  589. * @phpstan-var array{0: int, 1: int, 2: int}
  590. */
  591. protected $header_line_color = array(0,0,0);
  592. /**
  593. * Color for footer text (RGB array).
  594. * @since 5.9.174 (2012-07-25)
  595. * @protected
  596. * @var int[]
  597. * @phpstan-var array{0: int, 1: int, 2: int}
  598. */
  599. protected $footer_text_color = array(0,0,0);
  600. /**
  601. * Color for footer line (RGB array).
  602. * @since 5.9.174 (2012-07-25)
  603. * @protected
  604. * @var int[]
  605. * @phpstan-var array{0: int, 1: int, 2: int}
  606. */
  607. protected $footer_line_color = array(0,0,0);
  608. /**
  609. * Text shadow data array.
  610. * @since 5.9.174 (2012-07-25)
  611. * @protected
  612. */
  613. protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
  614. /**
  615. * Default number of columns for html table.
  616. * @protected
  617. */
  618. protected $default_table_columns = 4;
  619. // variables for html parser
  620. /**
  621. * HTML PARSER: array to store current link and rendering styles.
  622. * @protected
  623. */
  624. protected $HREF = array();
  625. /**
  626. * List of available fonts on filesystem.
  627. * @protected
  628. */
  629. protected $fontlist = array();
  630. /**
  631. * Current foreground color.
  632. * @protected
  633. */
  634. protected $fgcolor;
  635. /**
  636. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  637. * @protected
  638. */
  639. protected $listordered = array();
  640. /**
  641. * HTML PARSER: array count list items on nested lists.
  642. * @protected
  643. */
  644. protected $listcount = array();
  645. /**
  646. * HTML PARSER: current list nesting level.
  647. * @protected
  648. */
  649. protected $listnum = 0;
  650. /**
  651. * HTML PARSER: indent amount for lists.
  652. * @protected
  653. */
  654. protected $listindent = 0;
  655. /**
  656. * HTML PARSER: current list indententation level.
  657. * @protected
  658. */
  659. protected $listindentlevel = 0;
  660. /**
  661. * Current background color.
  662. * @protected
  663. */
  664. protected $bgcolor;
  665. /**
  666. * Temporary font size in points.
  667. * @protected
  668. */
  669. protected $tempfontsize = 10;
  670. /**
  671. * Spacer string for LI tags.
  672. * @protected
  673. */
  674. protected $lispacer = '';
  675. /**
  676. * Default encoding.
  677. * @protected
  678. * @since 1.53.0.TC010
  679. */
  680. protected $encoding = 'UTF-8';
  681. /**
  682. * Boolean flag to indicate if the document language is Right-To-Left.
  683. * @protected
  684. * @since 2.0.000
  685. */
  686. protected $rtl = false;
  687. /**
  688. * Boolean flag used to force RTL or LTR string direction.
  689. * @protected
  690. * @since 2.0.000
  691. */
  692. protected $tmprtl = false;
  693. // --- Variables used for document encryption:
  694. /**
  695. * IBoolean flag indicating whether document is protected.
  696. * @protected
  697. * @since 2.0.000 (2008-01-02)
  698. */
  699. protected $encrypted;
  700. /**
  701. * Array containing encryption settings.
  702. * @protected
  703. * @since 5.0.005 (2010-05-11)
  704. */
  705. protected $encryptdata = array();
  706. /**
  707. * Last RC4 key encrypted (cached for optimisation).
  708. * @protected
  709. * @since 2.0.000 (2008-01-02)
  710. */
  711. protected $last_enc_key;
  712. /**
  713. * Last RC4 computed key.
  714. * @protected
  715. * @since 2.0.000 (2008-01-02)
  716. */
  717. protected $last_enc_key_c;
  718. /**
  719. * File ID (used on document trailer).
  720. * @protected
  721. * @since 5.0.005 (2010-05-12)
  722. */
  723. protected $file_id;
  724. /**
  725. * Internal secret used to encrypt data.
  726. * @protected
  727. * @since 6.7.5 (2024-03-21)
  728. */
  729. protected $hash_key;
  730. // --- bookmark ---
  731. /**
  732. * Outlines for bookmark.
  733. * @protected
  734. * @since 2.1.002 (2008-02-12)
  735. */
  736. protected $outlines = array();
  737. /**
  738. * Outline root for bookmark.
  739. * @protected
  740. * @since 2.1.002 (2008-02-12)
  741. */
  742. protected $OutlineRoot;
  743. // --- javascript and form ---
  744. /**
  745. * Javascript code.
  746. * @protected
  747. * @since 2.1.002 (2008-02-12)
  748. */
  749. protected $javascript = '';
  750. /**
  751. * Javascript counter.
  752. * @protected
  753. * @since 2.1.002 (2008-02-12)
  754. */
  755. protected $n_js;
  756. /**
  757. * line through state
  758. * @protected
  759. * @since 2.8.000 (2008-03-19)
  760. */
  761. protected $linethrough;
  762. /**
  763. * Array with additional document-wide usage rights for the document.
  764. * @protected
  765. * @since 5.8.014 (2010-08-23)
  766. */
  767. protected $ur = array();
  768. /**
  769. * DPI (Dot Per Inch) Document Resolution (do not change).
  770. * @protected
  771. * @since 3.0.000 (2008-03-27)
  772. */
  773. protected $dpi = 72;
  774. /**
  775. * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  776. * @protected
  777. * @since 3.0.000 (2008-03-27)
  778. */
  779. protected $newpagegroup = array();
  780. /**
  781. * Array that contains the number of pages in each page group.
  782. * @protected
  783. * @since 3.0.000 (2008-03-27)
  784. */
  785. protected $pagegroups = array();
  786. /**
  787. * Current page group number.
  788. * @protected
  789. * @since 3.0.000 (2008-03-27)
  790. */
  791. protected $currpagegroup = 0;
  792. /**
  793. * Array of transparency objects and parameters.
  794. * @protected
  795. * @since 3.0.000 (2008-03-27)
  796. */
  797. protected $extgstates;
  798. /**
  799. * Set the default JPEG compression quality (1-100).
  800. * @protected
  801. * @since 3.0.000 (2008-03-27)
  802. */
  803. protected $jpeg_quality;
  804. /**
  805. * Default cell height ratio.
  806. * @protected
  807. * @since 3.0.014 (2008-05-23)
  808. * @var float
  809. */
  810. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  811. /**
  812. * PDF viewer preferences.
  813. * @protected
  814. * @since 3.1.000 (2008-06-09)
  815. */
  816. protected $viewer_preferences;
  817. /**
  818. * A name object specifying how the document should be displayed when opened.
  819. * @protected
  820. * @since 3.1.000 (2008-06-09)
  821. */
  822. protected $PageMode;
  823. /**
  824. * Array for storing gradient information.
  825. * @protected
  826. * @since 3.1.000 (2008-06-09)
  827. */
  828. protected $gradients = array();
  829. /**
  830. * Array used to store positions inside the pages buffer (keys are the page numbers).
  831. * @protected
  832. * @since 3.2.000 (2008-06-26)
  833. */
  834. protected $intmrk = array();
  835. /**
  836. * Array used to store positions inside the pages buffer (keys are the page numbers).
  837. * @protected
  838. * @since 5.7.000 (2010-08-03)
  839. */
  840. protected $bordermrk = array();
  841. /**
  842. * Array used to store page positions to track empty pages (keys are the page numbers).
  843. * @protected
  844. * @since 5.8.007 (2010-08-18)
  845. */
  846. protected $emptypagemrk = array();
  847. /**
  848. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  849. * @protected
  850. * @since 4.6.021 (2009-07-20)
  851. */
  852. protected $cntmrk = array();
  853. /**
  854. * Array used to store footer positions of each page.
  855. * @protected
  856. * @since 3.2.000 (2008-07-01)
  857. */
  858. protected $footerpos = array();
  859. /**
  860. * Array used to store footer length of each page.
  861. * @protected
  862. * @since 4.0.014 (2008-07-29)
  863. */
  864. protected $footerlen = array();
  865. /**
  866. * Boolean flag to indicate if a new line is created.
  867. * @protected
  868. * @since 3.2.000 (2008-07-01)
  869. */
  870. protected $newline = true;
  871. /**
  872. * End position of the latest inserted line.
  873. * @protected
  874. * @since 3.2.000 (2008-07-01)
  875. */
  876. protected $endlinex = 0;
  877. /**
  878. * PDF string for width value of the last line.
  879. * @protected
  880. * @since 4.0.006 (2008-07-16)
  881. */
  882. protected $linestyleWidth = '';
  883. /**
  884. * PDF string for CAP value of the last line.
  885. * @protected
  886. * @since 4.0.006 (2008-07-16)
  887. */
  888. protected $linestyleCap = '0 J';
  889. /**
  890. * PDF string for join value of the last line.
  891. * @protected
  892. * @since 4.0.006 (2008-07-16)
  893. */
  894. protected $linestyleJoin = '0 j';
  895. /**
  896. * PDF string for dash value of the last line.
  897. * @protected
  898. * @since 4.0.006 (2008-07-16)
  899. */
  900. protected $linestyleDash = '[] 0 d';
  901. /**
  902. * Boolean flag to indicate if marked-content sequence is open.
  903. * @protected
  904. * @since 4.0.013 (2008-07-28)
  905. */
  906. protected $openMarkedContent = false;
  907. /**
  908. * Count the latest inserted vertical spaces on HTML.
  909. * @protected
  910. * @since 4.0.021 (2008-08-24)
  911. */
  912. protected $htmlvspace = 0;
  913. /**
  914. * Array of Spot colors.
  915. * @protected
  916. * @since 4.0.024 (2008-09-12)
  917. */
  918. protected $spot_colors = array();
  919. /**
  920. * Symbol used for HTML unordered list items.
  921. * @protected
  922. * @since 4.0.028 (2008-09-26)
  923. */
  924. protected $lisymbol = '';
  925. /**
  926. * String used to mark the beginning and end of EPS image blocks.
  927. * @protected
  928. * @since 4.1.000 (2008-10-18)
  929. */
  930. protected $epsmarker = 'x#!#EPS#!#x';
  931. /**
  932. * Array of transformation matrix.
  933. * @protected
  934. * @since 4.2.000 (2008-10-29)
  935. */
  936. protected $transfmatrix = array();
  937. /**
  938. * Current key for transformation matrix.
  939. * @protected
  940. * @since 4.8.005 (2009-09-17)
  941. */
  942. protected $transfmatrix_key = 0;
  943. /**
  944. * Booklet mode for double-sided pages.
  945. * @protected
  946. * @since 4.2.000 (2008-10-29)
  947. */
  948. protected $booklet = false;
  949. /**
  950. * Epsilon value used for float calculations.
  951. * @protected
  952. * @since 4.2.000 (2008-10-29)
  953. */
  954. protected $feps = 0.005;
  955. /**
  956. * Array used for custom vertical spaces for HTML tags.
  957. * @protected
  958. * @since 4.2.001 (2008-10-30)
  959. */
  960. protected $tagvspaces = array();
  961. /**
  962. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  963. * @protected
  964. * @since 4.2.007 (2008-11-12)
  965. */
  966. protected $customlistindent = -1;
  967. /**
  968. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  969. * @protected
  970. * @since 4.2.010 (2008-11-14)
  971. */
  972. protected $opencell = true;
  973. /**
  974. * Array of files to embedd.
  975. * @protected
  976. * @since 4.4.000 (2008-12-07)
  977. */
  978. protected $embeddedfiles = array();
  979. /**
  980. * Boolean flag to indicate if we are inside a PRE tag.
  981. * @protected
  982. * @since 4.4.001 (2008-12-08)
  983. */
  984. protected $premode = false;
  985. /**
  986. * Array used to store positions of graphics transformation blocks inside the page buffer.
  987. * keys are the page numbers
  988. * @protected
  989. * @since 4.4.002 (2008-12-09)
  990. */
  991. protected $transfmrk = array();
  992. /**
  993. * Default color for html links.
  994. * @protected
  995. * @since 4.4.003 (2008-12-09)
  996. */
  997. protected $htmlLinkColorArray = array(0, 0, 255);
  998. /**
  999. * Default font style to add to html links.
  1000. * @protected
  1001. * @since 4.4.003 (2008-12-09)
  1002. */
  1003. protected $htmlLinkFontStyle = 'U';
  1004. /**
  1005. * Counts the number of pages.
  1006. * @protected
  1007. * @since 4.5.000 (2008-12-31)
  1008. */
  1009. protected $numpages = 0;
  1010. /**
  1011. * Array containing page lengths in bytes.
  1012. * @protected
  1013. * @since 4.5.000 (2008-12-31)
  1014. */
  1015. protected $pagelen = array();
  1016. /**
  1017. * Counts the number of pages.
  1018. * @protected
  1019. * @since 4.5.000 (2008-12-31)
  1020. */
  1021. protected $numimages = 0;
  1022. /**
  1023. * Store the image keys.
  1024. * @protected
  1025. * @since 4.5.000 (2008-12-31)
  1026. */
  1027. protected $imagekeys = array();
  1028. /**
  1029. * Length of the buffer in bytes.
  1030. * @protected
  1031. * @since 4.5.000 (2008-12-31)
  1032. */
  1033. protected $bufferlen = 0;
  1034. /**
  1035. * Counts the number of fonts.
  1036. * @protected
  1037. * @since 4.5.000 (2009-01-02)
  1038. */
  1039. protected $numfonts = 0;
  1040. /**
  1041. * Store the font keys.
  1042. * @protected
  1043. * @since 4.5.000 (2009-01-02)
  1044. */
  1045. protected $fontkeys = array();
  1046. /**
  1047. * Store the font object IDs.
  1048. * @protected
  1049. * @since 4.8.001 (2009-09-09)
  1050. */
  1051. protected $font_obj_ids = array();
  1052. /**
  1053. * Store the fage status (true when opened, false when closed).
  1054. * @protected
  1055. * @since 4.5.000 (2009-01-02)
  1056. */
  1057. protected $pageopen = array();
  1058. /**
  1059. * Default monospace font.
  1060. * @protected
  1061. * @since 4.5.025 (2009-03-10)
  1062. */
  1063. protected $default_monospaced_font = 'courier';
  1064. /**
  1065. * Cloned copy of the current class object.
  1066. * @protected
  1067. * @since 4.5.029 (2009-03-19)
  1068. */
  1069. protected $objcopy;
  1070. /**
  1071. * Array used to store the lengths of cache files.
  1072. * @protected
  1073. * @since 4.5.029 (2009-03-19)
  1074. */
  1075. protected $cache_file_length = array();
  1076. /**
  1077. * Table header content to be repeated on each new page.
  1078. * @protected
  1079. * @since 4.5.030 (2009-03-20)
  1080. */
  1081. protected $thead = '';
  1082. /**
  1083. * Margins used for table header.
  1084. * @protected
  1085. * @since 4.5.030 (2009-03-20)
  1086. */
  1087. protected $theadMargins = array();
  1088. /**
  1089. * Boolean flag to enable document digital signature.
  1090. * @protected
  1091. * @since 4.6.005 (2009-04-24)
  1092. */
  1093. protected $sign = false;
  1094. /**
  1095. * Digital signature data.
  1096. * @protected
  1097. * @since 4.6.005 (2009-04-24)
  1098. */
  1099. protected $signature_data = array();
  1100. /**
  1101. * Digital signature max length.
  1102. * @protected
  1103. * @since 4.6.005 (2009-04-24)
  1104. */
  1105. protected $signature_max_length = 11742;
  1106. /**
  1107. * Data for digital signature appearance.
  1108. * @protected
  1109. * @since 5.3.011 (2010-06-16)
  1110. */
  1111. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1112. /**
  1113. * Array of empty digital signature appearances.
  1114. * @protected
  1115. * @since 5.9.101 (2011-07-06)
  1116. */
  1117. protected $empty_signature_appearance = array();
  1118. /**
  1119. * Boolean flag to enable document timestamping with TSA.
  1120. * @protected
  1121. * @since 6.0.085 (2014-06-19)
  1122. */
  1123. protected $tsa_timestamp = false;
  1124. /**
  1125. * Timestamping data.
  1126. * @protected
  1127. * @since 6.0.085 (2014-06-19)
  1128. */
  1129. protected $tsa_data = array();
  1130. /**
  1131. * Regular expression used to find blank characters (required for word-wrapping).
  1132. * @protected
  1133. * @since 4.6.006 (2009-04-28)
  1134. */
  1135. protected $re_spaces = '/[^\S\xa0]/';
  1136. /**
  1137. * Array of $re_spaces parts.
  1138. * @protected
  1139. * @since 5.5.011 (2010-07-09)
  1140. */
  1141. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1142. /**
  1143. * Digital signature object ID.
  1144. * @protected
  1145. * @since 4.6.022 (2009-06-23)
  1146. */
  1147. protected $sig_obj_id = 0;
  1148. /**
  1149. * ID of page objects.
  1150. * @protected
  1151. * @since 4.7.000 (2009-08-29)
  1152. */
  1153. protected $page_obj_id = array();
  1154. /**
  1155. * List of form annotations IDs.
  1156. * @protected
  1157. * @since 4.8.000 (2009-09-07)
  1158. */
  1159. protected $form_obj_id = array();
  1160. /**
  1161. * 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.
  1162. * @protected
  1163. * @since 4.8.000 (2009-09-07)
  1164. */
  1165. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1166. /**
  1167. * Javascript objects array.
  1168. * @protected
  1169. * @since 4.8.000 (2009-09-07)
  1170. */
  1171. protected $js_objects = array();
  1172. /**
  1173. * Current form action (used during XHTML rendering).
  1174. * @protected
  1175. * @since 4.8.000 (2009-09-07)
  1176. */
  1177. protected $form_action = '';
  1178. /**
  1179. * Current form encryption type (used during XHTML rendering).
  1180. * @protected
  1181. * @since 4.8.000 (2009-09-07)
  1182. */
  1183. protected $form_enctype = 'application/x-www-form-urlencoded';
  1184. /**
  1185. * Current method to submit forms.
  1186. * @protected
  1187. * @since 4.8.000 (2009-09-07)
  1188. */
  1189. protected $form_mode = 'post';
  1190. /**
  1191. * List of fonts used on form fields (fontname => fontkey).
  1192. * @protected
  1193. * @since 4.8.001 (2009-09-09)
  1194. */
  1195. protected $annotation_fonts = array();
  1196. /**
  1197. * List of radio buttons parent objects.
  1198. * @protected
  1199. * @since 4.8.001 (2009-09-09)
  1200. */
  1201. protected $radiobutton_groups = array();
  1202. /**
  1203. * List of radio group objects IDs.
  1204. * @protected
  1205. * @since 4.8.001 (2009-09-09)
  1206. */
  1207. protected $radio_groups = array();
  1208. /**
  1209. * Text indentation value (used for text-indent CSS attribute).
  1210. * @protected
  1211. * @since 4.8.006 (2009-09-23)
  1212. */
  1213. protected $textindent = 0;
  1214. /**
  1215. * Store page number when startTransaction() is called.
  1216. * @protected
  1217. * @since 4.8.006 (2009-09-23)
  1218. */
  1219. protected $start_transaction_page = 0;
  1220. /**
  1221. * Store Y position when startTransaction() is called.
  1222. * @protected
  1223. * @since 4.9.001 (2010-03-28)
  1224. */
  1225. protected $start_transaction_y = 0;
  1226. /**
  1227. * True when we are printing the thead section on a new page.
  1228. * @protected
  1229. * @since 4.8.027 (2010-01-25)
  1230. */
  1231. protected $inthead = false;
  1232. /**
  1233. * Array of column measures (width, space, starting Y position).
  1234. * @protected
  1235. * @since 4.9.001 (2010-03-28)
  1236. */
  1237. protected $columns = array();
  1238. /**
  1239. * Number of colums.
  1240. * @protected
  1241. * @since 4.9.001 (2010-03-28)
  1242. */
  1243. protected $num_columns = 1;
  1244. /**
  1245. * Current column number.
  1246. * @protected
  1247. * @since 4.9.001 (2010-03-28)
  1248. */
  1249. protected $current_column = 0;
  1250. /**
  1251. * Starting page for columns.
  1252. * @protected
  1253. * @since 4.9.001 (2010-03-28)
  1254. */
  1255. protected $column_start_page = 0;
  1256. /**
  1257. * Maximum page and column selected.
  1258. * @protected
  1259. * @since 5.8.000 (2010-08-11)
  1260. */
  1261. protected $maxselcol = array('page' => 0, 'column' => 0);
  1262. /**
  1263. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1264. * @protected
  1265. * @since 5.8.000 (2010-08-11)
  1266. */
  1267. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1268. /**
  1269. * 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.
  1270. * @protected
  1271. * @since 4.9.008 (2010-04-03)
  1272. */
  1273. protected $textrendermode = 0;
  1274. /**
  1275. * Text stroke width in doc units.
  1276. * @protected
  1277. * @since 4.9.008 (2010-04-03)
  1278. */
  1279. protected $textstrokewidth = 0;
  1280. /**
  1281. * Current stroke color.
  1282. * @protected
  1283. * @since 4.9.008 (2010-04-03)
  1284. */
  1285. protected $strokecolor;
  1286. /**
  1287. * Default unit of measure for document.
  1288. * @protected
  1289. * @since 5.0.000 (2010-04-22)
  1290. */
  1291. protected $pdfunit = 'mm';
  1292. /**
  1293. * Boolean flag true when we are on TOC (Table Of Content) page.
  1294. * @protected
  1295. */
  1296. protected $tocpage = false;
  1297. /**
  1298. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1299. * @protected
  1300. * @since 5.0.000 (2010-04-26)
  1301. */
  1302. protected $rasterize_vector_images = false;
  1303. /**
  1304. * Boolean flag: if true enables font subsetting by default.
  1305. * @protected
  1306. * @since 5.3.002 (2010-06-07)
  1307. */
  1308. protected $font_subsetting = true;
  1309. /**
  1310. * Array of default graphic settings.
  1311. * @protected
  1312. * @since 5.5.008 (2010-07-02)
  1313. */
  1314. protected $default_graphic_vars = array();
  1315. /**
  1316. * Array of XObjects.
  1317. * @protected
  1318. * @since 5.8.014 (2010-08-23)
  1319. */
  1320. protected $xobjects = array();
  1321. /**
  1322. * Boolean value true when we are inside an XObject.
  1323. * @protected
  1324. * @since 5.8.017 (2010-08-24)
  1325. */
  1326. protected $inxobj = false;
  1327. /**
  1328. * Current XObject ID.
  1329. * @protected
  1330. * @since 5.8.017 (2010-08-24)
  1331. */
  1332. protected $xobjid = '';
  1333. /**
  1334. * Percentage of character stretching.
  1335. * @protected
  1336. * @since 5.9.000 (2010-09-29)
  1337. */
  1338. protected $font_stretching = 100;
  1339. /**
  1340. * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1341. * @protected
  1342. * @since 5.9.000 (2010-09-29)
  1343. */
  1344. protected $font_spacing = 0;
  1345. /**
  1346. * Array of no-write regions.
  1347. * ('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)
  1348. * @protected
  1349. * @since 5.9.003 (2010-10-14)
  1350. */
  1351. protected $page_regions = array();
  1352. /**
  1353. * Boolean value true when page region check is active.
  1354. * @protected
  1355. */
  1356. protected $check_page_regions = true;
  1357. /**
  1358. * Array of PDF layers data.
  1359. * @protected
  1360. * @since 5.9.102 (2011-07-13)
  1361. */
  1362. protected $pdflayers = array();
  1363. /**
  1364. * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1365. * @protected
  1366. * @since 5.9.097 (2011-06-23)
  1367. */
  1368. protected $dests = array();
  1369. /**
  1370. * Object ID for Named Destinations
  1371. * @protected
  1372. * @since 5.9.097 (2011-06-23)
  1373. */
  1374. protected $n_dests;
  1375. /**
  1376. * Embedded Files Names
  1377. * @protected
  1378. * @since 5.9.204 (2013-01-23)
  1379. */
  1380. protected $efnames = array();
  1381. /**
  1382. * Directory used for the last SVG image.
  1383. * @protected
  1384. * @since 5.0.000 (2010-05-05)
  1385. */
  1386. protected $svgdir = '';
  1387. /**
  1388. * Deafult unit of measure for SVG.
  1389. * @protected
  1390. * @since 5.0.000 (2010-05-02)
  1391. */
  1392. protected $svgunit = 'px';
  1393. /**
  1394. * Array of SVG gradients.
  1395. * @protected
  1396. * @since 5.0.000 (2010-05-02)
  1397. */
  1398. protected $svggradients = array();
  1399. /**
  1400. * ID of last SVG gradient.
  1401. * @protected
  1402. * @since 5.0.000 (2010-05-02)
  1403. */
  1404. protected $svggradientid = 0;
  1405. /**
  1406. * Boolean value true when in SVG defs group.
  1407. * @protected
  1408. * @since 5.0.000 (2010-05-02)
  1409. */
  1410. protected $svgdefsmode = false;
  1411. /**
  1412. * Array of SVG defs.
  1413. * @protected
  1414. * @since 5.0.000 (2010-05-02)
  1415. */
  1416. protected $svgdefs = array();
  1417. /**
  1418. * Boolean value true when in SVG clipPath tag.
  1419. * @protected
  1420. * @since 5.0.000 (2010-04-26)
  1421. */
  1422. protected $svgclipmode = false;
  1423. /**
  1424. * Array of SVG clipPath commands.
  1425. * @protected
  1426. * @since 5.0.000 (2010-05-02)
  1427. */
  1428. protected $svgclippaths = array();
  1429. /**
  1430. * Array of SVG clipPath tranformation matrix.
  1431. * @protected
  1432. * @since 5.8.022 (2010-08-31)
  1433. */
  1434. protected $svgcliptm = array();
  1435. /**
  1436. * ID of last SVG clipPath.
  1437. * @protected
  1438. * @since 5.0.000 (2010-05-02)
  1439. */
  1440. protected $svgclipid = 0;
  1441. /**
  1442. * SVG text.
  1443. * @protected
  1444. * @since 5.0.000 (2010-05-02)
  1445. */
  1446. protected $svgtext = '';
  1447. /**
  1448. * SVG text properties.
  1449. * @protected
  1450. * @since 5.8.013 (2010-08-23)
  1451. */
  1452. protected $svgtextmode = array();
  1453. /**
  1454. * Array of SVG properties.
  1455. * @protected
  1456. * @since 5.0.000 (2010-05-02)
  1457. */
  1458. protected $svgstyles = array(array(
  1459. 'alignment-baseline' => 'auto',
  1460. 'baseline-shift' => 'baseline',
  1461. 'clip' => 'auto',
  1462. 'clip-path' => 'none',
  1463. 'clip-rule' => 'nonzero',
  1464. 'color' => 'black',
  1465. 'color-interpolation' => 'sRGB',
  1466. 'color-interpolation-filters' => 'linearRGB',
  1467. 'color-profile' => 'auto',
  1468. 'color-rendering' => 'auto',
  1469. 'cursor' => 'auto',
  1470. 'direction' => 'ltr',
  1471. 'display' => 'inline',
  1472. 'dominant-baseline' => 'auto',
  1473. 'enable-background' => 'accumulate',
  1474. 'fill' => 'black',
  1475. 'fill-opacity' => 1,
  1476. 'fill-rule' => 'nonzero',
  1477. 'filter' => 'none',
  1478. 'flood-color' => 'black',
  1479. 'flood-opacity' => 1,
  1480. 'font' => '',
  1481. 'font-family' => 'helvetica',
  1482. 'font-size' => 'medium',
  1483. 'font-size-adjust' => 'none',
  1484. 'font-stretch' => 'normal',
  1485. 'font-style' => 'normal',
  1486. 'font-variant' => 'normal',
  1487. 'font-weight' => 'normal',
  1488. 'glyph-orientation-horizontal' => '0deg',
  1489. 'glyph-orientation-vertical' => 'auto',
  1490. 'image-rendering' => 'auto',
  1491. 'kerning' => 'auto',
  1492. 'letter-spacing' => 'normal',
  1493. 'lighting-color' => 'white',
  1494. 'marker' => '',
  1495. 'marker-end' => 'none',
  1496. 'marker-mid' => 'none',
  1497. 'marker-start' => 'none',
  1498. 'mask' => 'none',
  1499. 'opacity' => 1,
  1500. 'overflow' => 'auto',
  1501. 'pointer-events' => 'visiblePainted',
  1502. 'shape-rendering' => 'auto',
  1503. 'stop-color' => 'black',
  1504. 'stop-opacity' => 1,
  1505. 'stroke' => 'none',
  1506. 'stroke-dasharray' => 'none',
  1507. 'stroke-dashoffset' => 0,
  1508. 'stroke-linecap' => 'butt',
  1509. 'stroke-linejoin' => 'miter',
  1510. 'stroke-miterlimit' => 4,
  1511. 'stroke-opacity' => 1,
  1512. 'stroke-width' => 1,
  1513. 'text-anchor' => 'start',
  1514. 'text-decoration' => 'none',
  1515. 'text-rendering' => 'auto',
  1516. 'unicode-bidi' => 'normal',
  1517. 'visibility' => 'visible',
  1518. 'word-spacing' => 'normal',
  1519. 'writing-mode' => 'lr-tb',
  1520. 'text-color' => 'black',
  1521. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1522. ));
  1523. /**
  1524. * If true force sRGB color profile for all document.
  1525. * @protected
  1526. * @since 5.9.121 (2011-09-28)
  1527. */
  1528. protected $force_srgb = false;
  1529. /**
  1530. * If true set the document to PDF/A mode.
  1531. * @protected
  1532. * @since 5.9.121 (2011-09-27)
  1533. */
  1534. protected $pdfa_mode = false;
  1535. /**
  1536. * version of PDF/A mode (1 - 3).
  1537. * @protected
  1538. * @since 6.2.26 (2019-03-12)
  1539. */
  1540. protected $pdfa_version = 1;
  1541. /**
  1542. * Document creation date-time
  1543. * @protected
  1544. * @since 5.9.152 (2012-03-22)
  1545. */
  1546. protected $doc_creation_timestamp;
  1547. /**
  1548. * Document modification date-time
  1549. * @protected
  1550. * @since 5.9.152 (2012-03-22)
  1551. */
  1552. protected $doc_modification_timestamp;
  1553. /**
  1554. * Custom XMP data.
  1555. * @protected
  1556. * @since 5.9.128 (2011-10-06)
  1557. */
  1558. protected $custom_xmp = '';
  1559. /**
  1560. * Custom XMP RDF data.
  1561. * @protected
  1562. * @since 6.3.0 (2019-09-19)
  1563. */
  1564. protected $custom_xmp_rdf = '';
  1565. /**
  1566. * Overprint 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. * @var array<string,bool|int>
  1571. */
  1572. protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
  1573. /**
  1574. * Alpha mode array.
  1575. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1576. * @protected
  1577. * @since 5.9.152 (2012-03-23)
  1578. */
  1579. protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
  1580. /**
  1581. * Define the page boundaries boxes to be set on document.
  1582. * @protected
  1583. * @since 5.9.152 (2012-03-23)
  1584. */
  1585. protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  1586. /**
  1587. * If true print TCPDF meta link.
  1588. * @protected
  1589. * @since 5.9.152 (2012-03-23)
  1590. */
  1591. protected $tcpdflink = true;
  1592. /**
  1593. * Cache array for computed GD gamma values.
  1594. * @protected
  1595. * @since 5.9.1632 (2012-06-05)
  1596. */
  1597. protected $gdgammacache = array();
  1598. /**
  1599. * Cache array for file content
  1600. * @protected
  1601. * @var array
  1602. * @since 6.3.5 (2020-09-28)
  1603. */
  1604. protected $fileContentCache = array();
  1605. /**
  1606. * Whether to allow local file path in image html tags, when prefixed with file://
  1607. *
  1608. * @var bool
  1609. * @protected
  1610. * @since 6.4 (2020-07-23)
  1611. */
  1612. protected $allowLocalFiles = false;
  1613. //------------------------------------------------------------
  1614. // METHODS
  1615. //------------------------------------------------------------
  1616. /**
  1617. * This is the class constructor.
  1618. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1619. *
  1620. * @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>
  1621. * @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.
  1622. * @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().
  1623. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1624. * @param string $encoding Charset encoding (used only when converting back html entities); default is UTF-8.
  1625. * @param boolean $diskcache DEPRECATED FEATURE
  1626. * @param false|integer $pdfa If not false, set the document to PDF/A mode and the good version (1 or 3).
  1627. * @public
  1628. * @see getPageSizeFromFormat(), setPageFormat()
  1629. */
  1630. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
  1631. // set file ID for trailer
  1632. $serformat = (is_array($format) ? json_encode($format) : $format);
  1633. $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
  1634. $this->hash_key = hash_hmac('sha256', TCPDF_STATIC::getRandomSeed($this->file_id), TCPDF_STATIC::getRandomSeed('TCPDF'), false);
  1635. $this->font_obj_ids = array();
  1636. $this->page_obj_id = array();
  1637. $this->form_obj_id = array();
  1638. // set pdf/a mode
  1639. if ($pdfa != false) {
  1640. $this->pdfa_mode = true;
  1641. $this->pdfa_version = $pdfa; // 1 or 3
  1642. } else
  1643. $this->pdfa_mode = false;
  1644. $this->force_srgb = false;
  1645. // set language direction
  1646. $this->rtl = false;
  1647. $this->tmprtl = false;
  1648. // some checks
  1649. $this->_dochecks();
  1650. // initialization of properties
  1651. $this->isunicode = $unicode;
  1652. $this->page = 0;
  1653. $this->transfmrk[0] = array();
  1654. $this->pagedim = array();
  1655. $this->n = 2;
  1656. $this->buffer = '';
  1657. $this->pages = array();
  1658. $this->state = 0;
  1659. $this->fonts = array();
  1660. $this->FontFiles = array();
  1661. $this->diffs = array();
  1662. $this->images = array();
  1663. $this->links = array();
  1664. $this->gradients = array();
  1665. $this->InFooter = false;
  1666. $this->lasth = 0;
  1667. $this->FontFamily = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  1668. $this->FontStyle = '';
  1669. $this->FontSizePt = 12;
  1670. $this->underline = false;
  1671. $this->overline = false;
  1672. $this->linethrough = false;
  1673. $this->DrawColor = '0 G';
  1674. $this->FillColor = '0 g';
  1675. $this->TextColor = '0 g';
  1676. $this->ColorFlag = false;
  1677. $this->pdflayers = array();
  1678. // encryption values
  1679. $this->encrypted = false;
  1680. $this->last_enc_key = '';
  1681. // standard Unicode fonts
  1682. $this->CoreFonts = array(
  1683. 'courier'=>'Courier',
  1684. 'courierB'=>'Courier-Bold',
  1685. 'courierI'=>'Courier-Oblique',
  1686. 'courierBI'=>'Courier-BoldOblique',
  1687. 'helvetica'=>'Helvetica',
  1688. 'helveticaB'=>'Helvetica-Bold',
  1689. 'helveticaI'=>'Helvetica-Oblique',
  1690. 'helveticaBI'=>'Helvetica-BoldOblique',
  1691. 'times'=>'Times-Roman',
  1692. 'timesB'=>'Times-Bold',
  1693. 'timesI'=>'Times-Italic',
  1694. 'timesBI'=>'Times-BoldItalic',
  1695. 'symbol'=>'Symbol',
  1696. 'zapfdingbats'=>'ZapfDingbats'
  1697. );
  1698. // set scale factor
  1699. $this->setPageUnit($unit);
  1700. // set page format and orientation
  1701. $this->setPageFormat($format, $orientation);
  1702. // page margins (1 cm)
  1703. $margin = 28.35 / $this->k;
  1704. $this->setMargins($margin, $margin);
  1705. $this->clMargin = $this->lMargin;
  1706. $this->crMargin = $this->rMargin;
  1707. // internal cell padding
  1708. $cpadding = $margin / 10;
  1709. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1710. // cell margins
  1711. $this->setCellMargins(0, 0, 0, 0);
  1712. // line width (0.2 mm)
  1713. $this->LineWidth = 0.57 / $this->k;
  1714. $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
  1715. $this->linestyleCap = '0 J';
  1716. $this->linestyleJoin = '0 j';
  1717. $this->linestyleDash = '[] 0 d';
  1718. // automatic page break
  1719. $this->setAutoPageBreak(true, (2 * $margin));
  1720. // full width display mode
  1721. $this->setDisplayMode('fullwidth');
  1722. // compression
  1723. $this->setCompression();
  1724. // set default PDF version number
  1725. $this->setPDFVersion();
  1726. $this->tcpdflink = true;
  1727. $this->encoding = $encoding;
  1728. $this->HREF = array();
  1729. $this->getFontsList();
  1730. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1731. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1732. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1733. $this->extgstates = array();
  1734. $this->setTextShadow();
  1735. // signature
  1736. $this->sign = false;
  1737. $this->tsa_timestamp = false;
  1738. $this->tsa_data = array();
  1739. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
  1740. $this->empty_signature_appearance = array();
  1741. // user's rights
  1742. $this->ur['enabled'] = false;
  1743. $this->ur['document'] = '/FullSave';
  1744. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1745. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1746. $this->ur['signature'] = '/Modify';
  1747. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1748. $this->ur['formex'] = '';
  1749. // set default JPEG quality
  1750. $this->jpeg_quality = 75;
  1751. // initialize some settings
  1752. TCPDF_FONTS::utf8Bidi(array(), '', false, $this->isunicode, $this->CurrentFont);
  1753. // set default font
  1754. $this->setFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1755. $this->setHeaderFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
  1756. $this->setFooterFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
  1757. // check if PCRE Unicode support is enabled
  1758. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1759. // PCRE unicode support is turned ON
  1760. // \s : any whitespace character
  1761. // \p{Z} : any separator
  1762. // \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  1763. // \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  1764. //$this->setSpacesRE('/(?!\xa0)[\s\p{Z}\p{Lo}]/u');
  1765. $this->setSpacesRE('/(?!\xa0)[\s\p{Z}]/u');
  1766. } else {
  1767. // PCRE unicode support is turned OFF
  1768. $this->setSpacesRE('/[^\S\xa0]/');
  1769. }
  1770. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1771. // set document creation and modification timestamp
  1772. $this->doc_creation_timestamp = time();
  1773. $this->doc_modification_timestamp = $this->doc_creation_timestamp;
  1774. // get default graphic vars
  1775. $this->default_graphic_vars = $this->getGraphicVars();
  1776. $this->header_xobj_autoreset = false;
  1777. $this->custom_xmp = '';
  1778. $this->custom_xmp_rdf = '';
  1779. }
  1780. /**
  1781. * Default destructor.
  1782. * @public
  1783. * @since 1.53.0.TC016
  1784. */
  1785. public function __destruct() {
  1786. // cleanup
  1787. $this->_destroy(true);
  1788. }
  1789. /**
  1790. * Set the units of measure for the document.
  1791. * @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.
  1792. * @public
  1793. * @since 3.0.015 (2008-06-06)
  1794. */
  1795. public function setPageUnit($unit) {
  1796. $unit = strtolower($unit);
  1797. //Set scale factor
  1798. switch ($unit) {
  1799. // points
  1800. case 'px':
  1801. case 'pt': {
  1802. $this->k = 1;
  1803. break;
  1804. }
  1805. // millimeters
  1806. case 'mm': {
  1807. $this->k = $this->dpi / 25.4;
  1808. break;
  1809. }
  1810. // centimeters
  1811. case 'cm': {
  1812. $this->k = $this->dpi / 2.54;
  1813. break;
  1814. }
  1815. // inches
  1816. case 'in': {
  1817. $this->k = $this->dpi;
  1818. break;
  1819. }
  1820. // unsupported unit
  1821. default : {
  1822. $this->Error('Incorrect unit: '.$unit);
  1823. break;
  1824. }
  1825. }
  1826. $this->pdfunit = $unit;
  1827. if (isset($this->CurOrientation)) {
  1828. $this->setPageOrientation($this->CurOrientation);
  1829. }
  1830. }
  1831. /**
  1832. * Change the format of the current page
  1833. * @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>
  1834. * <li>['format'] = page format name (one of the above);</li>
  1835. * <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>
  1836. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  1837. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  1838. * <li>['MediaBox']['llx'] : lower-left x coordinate</li>
  1839. * <li>['MediaBox']['lly'] : lower-left y coordinate</li>
  1840. * <li>['MediaBox']['urx'] : upper-right x coordinate</li>
  1841. * <li>['MediaBox']['ury'] : upper-right y coordinate</li>
  1842. * <li>['CropBox'] : the visible region of default user space:</li>
  1843. * <li>['CropBox']['llx'] : lower-left x coordinate</li>
  1844. * <li>['CropBox']['lly'] : lower-left y coordinate</li>
  1845. * <li>['CropBox']['urx'] : upper-right x coordinate</li>
  1846. * <li>['CropBox']['ury'] : upper-right y coordinate</li>
  1847. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  1848. * <li>['BleedBox']['llx'] : lower-left x coordinate</li>
  1849. * <li>['BleedBox']['lly'] : lower-left y coordinate</li>
  1850. * <li>['BleedBox']['urx'] : upper-right x coordinate</li>
  1851. * <li>['BleedBox']['ury'] : upper-right y coordinate</li>
  1852. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  1853. * <li>['TrimBox']['llx'] : lower-left x coordinate</li>
  1854. * <li>['TrimBox']['lly'] : lower-left y coordinate</li>
  1855. * <li>['TrimBox']['urx'] : upper-right x coordinate</li>
  1856. * <li>['TrimBox']['ury'] : upper-right y coordinate</li>
  1857. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  1858. * <li>['ArtBox']['llx'] : lower-left x coordinate</li>
  1859. * <li>['ArtBox']['lly'] : lower-left y coordinate</li>
  1860. * <li>['ArtBox']['urx'] : upper-right x coordinate</li>
  1861. * <li>['ArtBox']['ury'] : upper-right y coordinate</li>
  1862. * <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>
  1863. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  1864. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  1865. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  1866. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  1867. * <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>
  1868. * <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>
  1869. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  1870. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  1871. * <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>
  1872. * <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>
  1873. * <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>
  1874. * <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>
  1875. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  1876. * </ul>
  1877. * @param string $orientation page orientation. Possible values are (case insensitive):<ul>
  1878. * <li>P or Portrait (default)</li>
  1879. * <li>L or Landscape</li>
  1880. * <li>'' (empty string) for automatic orientation</li>
  1881. * </ul>
  1882. * @protected
  1883. * @since 3.0.015 (2008-06-06)
  1884. * @see getPageSizeFromFormat()
  1885. */
  1886. protected function setPageFormat($format, $orientation='P') {
  1887. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  1888. // remove inherited values
  1889. unset($this->pagedim[$this->page]);
  1890. }
  1891. if (is_string($format)) {
  1892. // get page measures from format name
  1893. $pf = TCPDF_STATIC::getPageSizeFromFormat($format);
  1894. $this->fwPt = $pf[0];
  1895. $this->fhPt = $pf[1];
  1896. } else {
  1897. // the boundaries of the physical medium on which the page shall be displayed or printed
  1898. if (isset($format['MediaBox'])) {
  1899. $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);
  1900. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  1901. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  1902. } else {
  1903. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  1904. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  1905. } else {
  1906. if (!isset($format['format'])) {
  1907. // default value
  1908. $format['format'] = 'A4';
  1909. }
  1910. $pf = TCPDF_STATIC::getPageSizeFromFormat($format['format']);
  1911. }
  1912. $this->fwPt = $pf[0];
  1913. $this->fhPt = $pf[1];
  1914. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1915. }
  1916. // the visible region of default user space
  1917. if (isset($format['CropBox'])) {
  1918. $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);
  1919. }
  1920. // the region to which the contents of the page shall be clipped when output in a production environment
  1921. if (isset($format['BleedBox'])) {
  1922. $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);
  1923. }
  1924. // the intended dimensions of the finished page after trimming
  1925. if (isset($format['TrimBox'])) {
  1926. $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);
  1927. }
  1928. // the page's meaningful content (including potential white space)
  1929. if (isset($format['ArtBox'])) {
  1930. $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);
  1931. }
  1932. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  1933. if (isset($format['BoxColorInfo'])) {
  1934. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  1935. }
  1936. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  1937. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1938. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  1939. }
  1940. if (isset($format['PZ'])) {
  1941. // The page's preferred zoom (magnification) factor
  1942. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  1943. }
  1944. if (isset($format['trans'])) {
  1945. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  1946. if (isset($format['trans']['Dur'])) {
  1947. // The page's display duration
  1948. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  1949. }
  1950. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  1951. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  1952. // The transition style that shall be used when moving to this page from another during a presentation
  1953. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  1954. $valid_effect = array('Split', 'Blinds');
  1955. $valid_vals = array('H', 'V');
  1956. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  1957. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  1958. }
  1959. $valid_effect = array('Split', 'Box', 'Fly');
  1960. $valid_vals = array('I', 'O');
  1961. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  1962. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  1963. }
  1964. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  1965. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  1966. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  1967. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  1968. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  1969. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  1970. }
  1971. }
  1972. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  1973. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  1974. }
  1975. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  1976. $this->pagedim[$this->page]['trans']['B'] = 'true';
  1977. }
  1978. } else {
  1979. $this->pagedim[$this->page]['trans']['S'] = 'R';
  1980. }
  1981. if (isset($format['trans']['D'])) {
  1982. // The duration of the transition effect, in seconds
  1983. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  1984. } else {
  1985. $this->pagedim[$this->page]['trans']['D'] = 1;
  1986. }
  1987. }
  1988. }
  1989. $this->setPageOrientation($orientation);
  1990. }
  1991. /**
  1992. * Set page orientation.
  1993. * @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>
  1994. * @param boolean|null $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1995. * @param float|null $bottommargin bottom margin of the page.
  1996. * @public
  1997. * @since 3.0.015 (2008-06-06)
  1998. */
  1999. public function setPageOrientation($orientation, $autopagebreak=null, $bottommargin=null) {
  2000. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  2001. // the boundaries of the physical medium on which the page shall be displayed or printed
  2002. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  2003. }
  2004. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  2005. // the visible region of default user space
  2006. $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);
  2007. }
  2008. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  2009. // the region to which the contents of the page shall be clipped when output in a production environment
  2010. $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);
  2011. }
  2012. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  2013. // the intended dimensions of the finished page after trimming
  2014. $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);
  2015. }
  2016. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  2017. // the page's meaningful content (including potential white space)
  2018. $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);
  2019. }
  2020. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  2021. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2022. $this->pagedim[$this->page]['Rotate'] = 0;
  2023. }
  2024. if (!isset($this->pagedim[$this->page]['PZ'])) {
  2025. // The page's preferred zoom (magnification) factor
  2026. $this->pagedim[$this->page]['PZ'] = 1;
  2027. }
  2028. if ($this->fwPt > $this->fhPt) {
  2029. // landscape
  2030. $default_orientation = 'L';
  2031. } else {
  2032. // portrait
  2033. $default_orientation = 'P';
  2034. }
  2035. $valid_orientations = array('P', 'L');
  2036. if (empty($orientation)) {
  2037. $orientation = $default_orientation;
  2038. } else {
  2039. $orientation = strtoupper($orientation[0]);
  2040. }
  2041. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  2042. $this->CurOrientation = $orientation;
  2043. $this->wPt = $this->fhPt;
  2044. $this->hPt = $this->fwPt;
  2045. } else {
  2046. $this->CurOrientation = $default_orientation;
  2047. $this->wPt = $this->fwPt;
  2048. $this->hPt = $this->fhPt;
  2049. }
  2050. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2051. // swap X and Y coordinates (change page orientation)
  2052. $this->pagedim = TCPDF_STATIC::swapPageBoxCoordinates($this->page, $this->pagedim);
  2053. }
  2054. $this->w = ($this->wPt / $this->k);
  2055. $this->h = ($this->hPt / $this->k);
  2056. if (TCPDF_STATIC::empty_string($autopagebreak)) {
  2057. if (isset($this->AutoPageBreak)) {
  2058. $autopagebreak = $this->AutoPageBreak;
  2059. } else {
  2060. $autopagebreak = true;
  2061. }
  2062. }
  2063. if (TCPDF_STATIC::empty_string($bottommargin)) {
  2064. if (isset($this->bMargin)) {
  2065. $bottommargin = $this->bMargin;
  2066. } else {
  2067. // default value = 2 cm
  2068. $bottommargin = 2 * 28.35 / $this->k;
  2069. }
  2070. }
  2071. $this->setAutoPageBreak($autopagebreak, $bottommargin);
  2072. // store page dimensions
  2073. $this->pagedim[$this->page]['w'] = $this->wPt;
  2074. $this->pagedim[$this->page]['h'] = $this->hPt;
  2075. $this->pagedim[$this->page]['wk'] = $this->w;
  2076. $this->pagedim[$this->page]['hk'] = $this->h;
  2077. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2078. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2079. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2080. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2081. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2082. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2083. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2084. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2085. }
  2086. /**
  2087. * Set regular expression to detect withespaces or word separators.
  2088. * The pattern delimiter must be the forward-slash character "/".
  2089. * Some example patterns are:
  2090. * <pre>
  2091. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2092. * Unicode and PCRE unicode support: "/(?!\xa0)[\s\p{Z}]/u"
  2093. * Unicode and PCRE unicode support in Chinese mode: "/(?!\xa0)[\s\p{Z}\p{Lo}]/u"
  2094. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2095. * \s : any whitespace character
  2096. * \p{Z} : any separator
  2097. * \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  2098. * \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  2099. * </pre>
  2100. * @param string $re regular expression (leave empty for default).
  2101. * @public
  2102. * @since 4.6.016 (2009-06-15)
  2103. */
  2104. public function setSpacesRE($re='/[^\S\xa0]/') {
  2105. $this->re_spaces = $re;
  2106. $re_parts = explode('/', $re);
  2107. // get pattern parts
  2108. $this->re_space = array();
  2109. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2110. $this->re_space['p'] = $re_parts[1];
  2111. } else {
  2112. $this->re_space['p'] = '[\s]';
  2113. }
  2114. // set pattern modifiers
  2115. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2116. $this->re_space['m'] = $re_parts[2];
  2117. } else {
  2118. $this->re_space['m'] = '';
  2119. }
  2120. }
  2121. /**
  2122. * Enable or disable Right-To-Left language mode
  2123. * @param boolean $enable if true enable Right-To-Left language mode.
  2124. * @param boolean $resetx if true reset the X position on direction change.
  2125. * @public
  2126. * @since 2.0.000 (2008-01-03)
  2127. */
  2128. public function setRTL($enable, $resetx=true) {
  2129. $enable = $enable ? true : false;
  2130. $resetx = ($resetx AND ($enable != $this->rtl));
  2131. $this->rtl = $enable;
  2132. $this->tmprtl = false;
  2133. if ($resetx) {
  2134. $this->Ln(0);
  2135. }
  2136. }
  2137. /**
  2138. * Return the RTL status
  2139. * @return bool
  2140. * @public
  2141. * @since 4.0.012 (2008-07-24)
  2142. */
  2143. public function getRTL() {
  2144. return $this->rtl;
  2145. }
  2146. /**
  2147. * Force temporary RTL language direction
  2148. * @param false|string $mode can be false, 'L' for LTR or 'R' for RTL
  2149. * @public
  2150. * @since 2.1.000 (2008-01-09)
  2151. */
  2152. public function setTempRTL($mode) {
  2153. $newmode = false;
  2154. switch (strtoupper($mode)) {
  2155. case 'LTR':
  2156. case 'L': {
  2157. if ($this->rtl) {
  2158. $newmode = 'L';
  2159. }
  2160. break;
  2161. }
  2162. case 'RTL':
  2163. case 'R': {
  2164. if (!$this->rtl) {
  2165. $newmode = 'R';
  2166. }
  2167. break;
  2168. }
  2169. case false:
  2170. default: {
  2171. $newmode = false;
  2172. break;
  2173. }
  2174. }
  2175. $this->tmprtl = $newmode;
  2176. }
  2177. /**
  2178. * Return the current temporary RTL status
  2179. * @return bool
  2180. * @public
  2181. * @since 4.8.014 (2009-11-04)
  2182. */
  2183. public function isRTLTextDir() {
  2184. return ($this->rtl OR ($this->tmprtl == 'R'));
  2185. }
  2186. /**
  2187. * Set the last cell height.
  2188. * @param float $h cell height.
  2189. * @author Nicola Asuni
  2190. * @public
  2191. * @since 1.53.0.TC034
  2192. */
  2193. public function setLastH($h) {
  2194. $this->lasth = $h;
  2195. }
  2196. /**
  2197. * Return the cell height
  2198. * @param int $fontsize Font size in internal units
  2199. * @param boolean $padding If true add cell padding
  2200. * @public
  2201. * @return float
  2202. */
  2203. public function getCellHeight($fontsize, $padding=TRUE) {
  2204. $height = ($fontsize * $this->cell_height_ratio);
  2205. if ($padding && !empty($this->cell_padding)) {
  2206. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  2207. }
  2208. return round($height, 6);
  2209. }
  2210. /**
  2211. * Reset the last cell height.
  2212. * @public
  2213. * @since 5.9.000 (2010-10-03)
  2214. */
  2215. public function resetLastH() {
  2216. $this->lasth = $this->getCellHeight($this->FontSize);
  2217. }
  2218. /**
  2219. * Get the last cell height.
  2220. * @return float last cell height
  2221. * @public
  2222. * @since 4.0.017 (2008-08-05)
  2223. */
  2224. public function getLastH() {
  2225. return $this->lasth;
  2226. }
  2227. /**
  2228. * Set the adjusting factor to convert pixels to user units.
  2229. * @param float $scale adjusting factor to convert pixels to user units.
  2230. * @author Nicola Asuni
  2231. * @public
  2232. * @since 1.5.2
  2233. */
  2234. public function setImageScale($scale) {
  2235. $this->imgscale = $scale;
  2236. }
  2237. /**
  2238. * Returns the adjusting factor to convert pixels to user units.
  2239. * @return float adjusting factor to convert pixels to user units.
  2240. * @author Nicola Asuni
  2241. * @public
  2242. * @since 1.5.2
  2243. */
  2244. public function getImageScale() {
  2245. return $this->imgscale;
  2246. }
  2247. /**
  2248. * Returns an array of page dimensions:
  2249. * <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>
  2250. * @param int|null $pagenum page number (empty = current page)
  2251. * @return array of page dimensions.
  2252. * @author Nicola Asuni
  2253. * @public
  2254. * @since 4.5.027 (2009-03-16)
  2255. */
  2256. public function getPageDimensions($pagenum=null) {
  2257. if (empty($pagenum)) {
  2258. $pagenum = $this->page;
  2259. }
  2260. return $this->pagedim[$pagenum];
  2261. }
  2262. /**
  2263. * Returns the page width in units.
  2264. * @param int|null $pagenum page number (empty = current page)
  2265. * @return int|float page width.
  2266. * @author Nicola Asuni
  2267. * @public
  2268. * @since 1.5.2
  2269. * @see getPageDimensions()
  2270. */
  2271. public function getPageWidth($pagenum=null) {
  2272. if (empty($pagenum)) {
  2273. return $this->w;
  2274. }
  2275. return $this->pagedim[$pagenum]['w'];
  2276. }
  2277. /**
  2278. * Returns the page height in units.
  2279. * @param int|null $pagenum page number (empty = current page)
  2280. * @return int|float page height.
  2281. * @author Nicola Asuni
  2282. * @public
  2283. * @since 1.5.2
  2284. * @see getPageDimensions()
  2285. */
  2286. public function getPageHeight($pagenum=null) {
  2287. if (empty($pagenum)) {
  2288. return $this->h;
  2289. }
  2290. return $this->pagedim[$pagenum]['h'];
  2291. }
  2292. /**
  2293. * Returns the page break margin.
  2294. * @param int|null $pagenum page number (empty = current page)
  2295. * @return int|float page break margin.
  2296. * @author Nicola Asuni
  2297. * @public
  2298. * @since 1.5.2
  2299. * @see getPageDimensions()
  2300. */
  2301. public function getBreakMargin($pagenum=null) {
  2302. if (empty($pagenum)) {
  2303. return $this->bMargin;
  2304. }
  2305. return $this->pagedim[$pagenum]['bm'];
  2306. }
  2307. /**
  2308. * Returns the scale factor (number of points in user unit).
  2309. * @return int scale factor.
  2310. * @author Nicola Asuni
  2311. * @public
  2312. * @since 1.5.2
  2313. */
  2314. public function getScaleFactor() {
  2315. return $this->k;
  2316. }
  2317. /**
  2318. * Defines the left, top and right margins.
  2319. * @param int|float $left Left margin.
  2320. * @param int|float $top Top margin.
  2321. * @param int|float|null $right Right margin. Default value is the left one.
  2322. * @param boolean $keepmargins if true overwrites the default page margins
  2323. * @public
  2324. * @since 1.0
  2325. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2326. */
  2327. public function setMargins($left, $top, $right=null, $keepmargins=false) {
  2328. //Set left, top and right margins
  2329. $this->lMargin = $left;
  2330. $this->tMargin = $top;
  2331. if ($right == -1 OR $right === null) {
  2332. $right = $left;
  2333. }
  2334. $this->rMargin = $right;
  2335. if ($keepmargins) {
  2336. // overwrite original values
  2337. $this->original_lMargin = $this->lMargin;
  2338. $this->original_rMargin = $this->rMargin;
  2339. }
  2340. }
  2341. /**
  2342. * 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.
  2343. * @param int|float $margin The margin.
  2344. * @public
  2345. * @since 1.4
  2346. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2347. */
  2348. public function setLeftMargin($margin) {
  2349. //Set left margin
  2350. $this->lMargin = $margin;
  2351. if (($this->page > 0) AND ($this->x < $margin)) {
  2352. $this->x = $margin;
  2353. }
  2354. }
  2355. /**
  2356. * Defines the top margin. The method can be called before creating the first page.
  2357. * @param int|float $margin The margin.
  2358. * @public
  2359. * @since 1.5
  2360. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2361. */
  2362. public function setTopMargin($margin) {
  2363. //Set top margin
  2364. $this->tMargin = $margin;
  2365. if (($this->page > 0) AND ($this->y < $margin)) {
  2366. $this->y = $margin;
  2367. }
  2368. }
  2369. /**
  2370. * Defines the right margin. The method can be called before creating the first page.
  2371. * @param int|float $margin The margin.
  2372. * @public
  2373. * @since 1.5
  2374. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2375. */
  2376. public function setRightMargin($margin) {
  2377. $this->rMargin = $margin;
  2378. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  2379. $this->x = $this->w - $margin;
  2380. }
  2381. }
  2382. /**
  2383. * Set the same internal Cell padding for top, right, bottom, left-
  2384. * @param int|float $pad internal padding.
  2385. * @public
  2386. * @since 2.1.000 (2008-01-09)
  2387. * @see getCellPaddings(), setCellPaddings()
  2388. */
  2389. public function setCellPadding($pad) {
  2390. if ($pad >= 0) {
  2391. $this->cell_padding['L'] = $pad;
  2392. $this->cell_padding['T'] = $pad;
  2393. $this->cell_padding['R'] = $pad;
  2394. $this->cell_padding['B'] = $pad;
  2395. }
  2396. }
  2397. /**
  2398. * Set the internal Cell paddings.
  2399. * @param int|float|null $left left padding
  2400. * @param int|float|null $top top padding
  2401. * @param int|float|null $right right padding
  2402. * @param int|float|null $bottom bottom padding
  2403. * @public
  2404. * @since 5.9.000 (2010-10-03)
  2405. * @see getCellPaddings(), SetCellPadding()
  2406. */
  2407. public function setCellPaddings($left=null, $top=null, $right=null, $bottom=null) {
  2408. if (!TCPDF_STATIC::empty_string($left) AND ($left >= 0)) {
  2409. $this->cell_padding['L'] = $left;
  2410. }
  2411. if (!TCPDF_STATIC::empty_string($top) AND ($top >= 0)) {
  2412. $this->cell_padding['T'] = $top;
  2413. }
  2414. if (!TCPDF_STATIC::empty_string($right) AND ($right >= 0)) {
  2415. $this->cell_padding['R'] = $right;
  2416. }
  2417. if (!TCPDF_STATIC::empty_string($bottom) AND ($bottom >= 0)) {
  2418. $this->cell_padding['B'] = $bottom;
  2419. }
  2420. }
  2421. /**
  2422. * Get the internal Cell padding array.
  2423. * @return array of padding values
  2424. * @public
  2425. * @since 5.9.000 (2010-10-03)
  2426. * @see setCellPaddings(), SetCellPadding()
  2427. */
  2428. public function getCellPaddings() {
  2429. return $this->cell_padding;
  2430. }
  2431. /**
  2432. * Set the internal Cell margins.
  2433. * @param int|float|null $left left margin
  2434. * @param int|float|null $top top margin
  2435. * @param int|float|null $right right margin
  2436. * @param int|float|null $bottom bottom margin
  2437. * @public
  2438. * @since 5.9.000 (2010-10-03)
  2439. * @see getCellMargins()
  2440. */
  2441. public function setCellMargins($left=null, $top=null, $right=null, $bottom=null) {
  2442. if (!TCPDF_STATIC::empty_string($left) AND ($left >= 0)) {
  2443. $this->cell_margin['L'] = $left;
  2444. }
  2445. if (!TCPDF_STATIC::empty_string($top) AND ($top >= 0)) {
  2446. $this->cell_margin['T'] = $top;
  2447. }
  2448. if (!TCPDF_STATIC::empty_string($right) AND ($right >= 0)) {
  2449. $this->cell_margin['R'] = $right;
  2450. }
  2451. if (!TCPDF_STATIC::empty_string($bottom) AND ($bottom >= 0)) {
  2452. $this->cell_margin['B'] = $bottom;
  2453. }
  2454. }
  2455. /**
  2456. * Get the internal Cell margin array.
  2457. * @return array of margin values
  2458. * @public
  2459. * @since 5.9.000 (2010-10-03)
  2460. * @see setCellMargins()
  2461. */
  2462. public function getCellMargins() {
  2463. return $this->cell_margin;
  2464. }
  2465. /**
  2466. * Adjust the internal Cell padding array to take account of the line width.
  2467. * @param string|array|int|bool $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)))
  2468. * @return void|array array of adjustments
  2469. * @public
  2470. * @since 5.9.000 (2010-10-03)
  2471. */
  2472. protected function adjustCellPadding($brd=0) {
  2473. if (empty($brd)) {
  2474. return;
  2475. }
  2476. if (is_string($brd)) {
  2477. // convert string to array
  2478. $slen = strlen($brd);
  2479. $newbrd = array();
  2480. for ($i = 0; $i < $slen; ++$i) {
  2481. $newbrd[$brd[$i]] = true;
  2482. }
  2483. $brd = $newbrd;
  2484. } elseif (
  2485. ($brd === 1)
  2486. || ($brd === true)
  2487. || (is_numeric($brd) && ((int)$brd > 0))
  2488. ) {
  2489. $brd = array('LRTB' => true);
  2490. }
  2491. if (!is_array($brd)) {
  2492. return;
  2493. }
  2494. // store current cell padding
  2495. $cp = $this->cell_padding;
  2496. // select border mode
  2497. if (isset($brd['mode'])) {
  2498. $mode = $brd['mode'];
  2499. unset($brd['mode']);
  2500. } else {
  2501. $mode = 'normal';
  2502. }
  2503. // process borders
  2504. foreach ($brd as $border => $style) {
  2505. $line_width = $this->LineWidth;
  2506. if (is_array($style) && isset($style['width'])) {
  2507. // get border width
  2508. $line_width = $style['width'];
  2509. }
  2510. $adj = 0; // line width inside the cell
  2511. switch ($mode) {
  2512. case 'ext': {
  2513. $adj = 0;
  2514. break;
  2515. }
  2516. case 'int': {
  2517. $adj = $line_width;
  2518. break;
  2519. }
  2520. case 'normal':
  2521. default: {
  2522. $adj = ($line_width / 2);
  2523. break;
  2524. }
  2525. }
  2526. // correct internal cell padding if required to avoid overlap between text and lines
  2527. if (
  2528. is_numeric($this->cell_padding['T'])
  2529. && ($this->cell_padding['T'] < $adj)
  2530. && (strpos($border, 'T') !== false)
  2531. ) {
  2532. $this->cell_padding['T'] = $adj;
  2533. }
  2534. if (
  2535. is_numeric($this->cell_padding['R'])
  2536. && ($this->cell_padding['R'] < $adj)
  2537. && (strpos($border, 'R') !== false)
  2538. ) {
  2539. $this->cell_padding['R'] = $adj;
  2540. }
  2541. if (
  2542. is_numeric($this->cell_padding['B'])
  2543. && ($this->cell_padding['B'] < $adj)
  2544. && (strpos($border, 'B') !== false)
  2545. ) {
  2546. $this->cell_padding['B'] = $adj;
  2547. }
  2548. if (
  2549. is_numeric($this->cell_padding['L'])
  2550. && ($this->cell_padding['L'] < $adj)
  2551. && (strpos($border, 'L') !== false)
  2552. ) {
  2553. $this->cell_padding['L'] = $adj;
  2554. }
  2555. }
  2556. return array(
  2557. 'T' => ($this->cell_padding['T'] - $cp['T']),
  2558. 'R' => ($this->cell_padding['R'] - $cp['R']),
  2559. 'B' => ($this->cell_padding['B'] - $cp['B']),
  2560. 'L' => ($this->cell_padding['L'] - $cp['L']),
  2561. );
  2562. }
  2563. /**
  2564. * 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.
  2565. * @param boolean $auto Boolean indicating if mode should be on or off.
  2566. * @param float $margin Distance from the bottom of the page.
  2567. * @public
  2568. * @since 1.0
  2569. * @see Cell(), MultiCell(), AcceptPageBreak()
  2570. */
  2571. public function setAutoPageBreak($auto, $margin=0) {
  2572. $this->AutoPageBreak = $auto ? true : false;
  2573. $this->bMargin = $margin;
  2574. $this->PageBreakTrigger = $this->h - $margin;
  2575. }
  2576. /**
  2577. * Return the auto-page-break mode (true or false).
  2578. * @return bool auto-page-break mode
  2579. * @public
  2580. * @since 5.9.088
  2581. */
  2582. public function getAutoPageBreak() {
  2583. return $this->AutoPageBreak;
  2584. }
  2585. /**
  2586. * Defines the way the document is to be displayed by the viewer.
  2587. * @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>
  2588. * @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>
  2589. * @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>
  2590. * @public
  2591. * @since 1.2
  2592. */
  2593. public function setDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  2594. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  2595. $this->ZoomMode = $zoom;
  2596. } else {
  2597. $this->Error('Incorrect zoom display mode: '.$zoom);
  2598. }
  2599. $this->LayoutMode = TCPDF_STATIC::getPageLayoutMode($layout);
  2600. $this->PageMode = TCPDF_STATIC::getPageMode($mode);
  2601. }
  2602. /**
  2603. * 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.
  2604. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2605. * @param boolean $compress Boolean indicating if compression must be enabled.
  2606. * @public
  2607. * @since 1.4
  2608. */
  2609. public function setCompression($compress=true) {
  2610. $this->compress = false;
  2611. if (function_exists('gzcompress')) {
  2612. if ($compress) {
  2613. if ( !$this->pdfa_mode) {
  2614. $this->compress = true;
  2615. }
  2616. }
  2617. }
  2618. }
  2619. /**
  2620. * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  2621. * @param boolean $mode If true force sRGB output intent.
  2622. * @public
  2623. * @since 5.9.121 (2011-09-28)
  2624. */
  2625. public function setSRGBmode($mode=false) {
  2626. $this->force_srgb = $mode ? true : false;
  2627. }
  2628. /**
  2629. * Turn on/off Unicode mode for document information dictionary (meta tags).
  2630. * This has effect only when unicode mode is set to false.
  2631. * @param boolean $unicode if true set the meta information in Unicode
  2632. * @since 5.9.027 (2010-12-01)
  2633. * @public
  2634. */
  2635. public function setDocInfoUnicode($unicode=true) {
  2636. $this->docinfounicode = $unicode ? true : false;
  2637. }
  2638. /**
  2639. * Defines the title of the document.
  2640. * @param string $title The title.
  2641. * @public
  2642. * @since 1.2
  2643. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2644. */
  2645. public function setTitle($title) {
  2646. $this->title = $title;
  2647. }
  2648. /**
  2649. * Defines the subject of the document.
  2650. * @param string $subject The subject.
  2651. * @public
  2652. * @since 1.2
  2653. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2654. */
  2655. public function setSubject($subject) {
  2656. $this->subject = $subject;
  2657. }
  2658. /**
  2659. * Defines the author of the document.
  2660. * @param string $author The name of the author.
  2661. * @public
  2662. * @since 1.2
  2663. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2664. */
  2665. public function setAuthor($author) {
  2666. $this->author = $author;
  2667. }
  2668. /**
  2669. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2670. * @param string $keywords The list of keywords.
  2671. * @public
  2672. * @since 1.2
  2673. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2674. */
  2675. public function setKeywords($keywords) {
  2676. $this->keywords = $keywords;
  2677. }
  2678. /**
  2679. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2680. * @param string $creator The name of the creator.
  2681. * @public
  2682. * @since 1.2
  2683. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2684. */
  2685. public function setCreator($creator) {
  2686. $this->creator = $creator;
  2687. }
  2688. /**
  2689. * Whether to allow local file path in image html tags, when prefixed with file://
  2690. *
  2691. * @param bool $allowLocalFiles true, when local files should be allowed. Otherwise false.
  2692. * @public
  2693. * @since 6.4
  2694. */
  2695. public function setAllowLocalFiles($allowLocalFiles) {
  2696. $this->allowLocalFiles = (bool) $allowLocalFiles;
  2697. }
  2698. /**
  2699. * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
  2700. * @param string $msg The error message
  2701. * @public
  2702. * @since 1.0
  2703. */
  2704. public function Error($msg) {
  2705. // unset all class variables
  2706. $this->_destroy(true);
  2707. if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
  2708. die('<strong>TCPDF ERROR: </strong>'.$msg);
  2709. } else {
  2710. throw new Exception('TCPDF ERROR: '.$msg);
  2711. }
  2712. }
  2713. /**
  2714. * This method begins the generation of the PDF document.
  2715. * It is not necessary to call it explicitly because AddPage() does it automatically.
  2716. * Note: no page is created by this method
  2717. * @public
  2718. * @since 1.0
  2719. * @see AddPage(), Close()
  2720. */
  2721. public function Open() {
  2722. $this->state = 1;
  2723. }
  2724. /**
  2725. * Terminates the PDF document.
  2726. * It is not necessary to call this method explicitly because Output() does it automatically.
  2727. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2728. * @public
  2729. * @since 1.0
  2730. * @see Open(), Output()
  2731. */
  2732. public function Close() {
  2733. if ($this->state == 3) {
  2734. return;
  2735. }
  2736. if ($this->page == 0) {
  2737. $this->AddPage();
  2738. }
  2739. $this->endLayer();
  2740. if ($this->tcpdflink) {
  2741. // save current graphic settings
  2742. $gvars = $this->getGraphicVars();
  2743. $this->setEqualColumns();
  2744. $this->lastpage(true);
  2745. $this->setAutoPageBreak(false);
  2746. $this->x = 0;
  2747. $this->y = $this->h - (1 / $this->k);
  2748. $this->lMargin = 0;
  2749. $this->_outSaveGraphicsState();
  2750. $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  2751. $this->setFont($font, '', 1);
  2752. $this->setTextRenderingMode(0, false, false);
  2753. $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";
  2754. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  2755. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  2756. $this->_outRestoreGraphicsState();
  2757. // restore graphic settings
  2758. $this->setGraphicVars($gvars);
  2759. }
  2760. // close page
  2761. $this->endPage();
  2762. // close document
  2763. $this->_enddoc();
  2764. // unset all class variables (except critical ones)
  2765. $this->_destroy(false);
  2766. }
  2767. /**
  2768. * Move pointer at the specified document page and update page dimensions.
  2769. * @param int $pnum page number (1 ... numpages)
  2770. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2771. * @public
  2772. * @since 2.1.000 (2008-01-07)
  2773. * @see getPage(), lastpage(), getNumPages()
  2774. */
  2775. public function setPage($pnum, $resetmargins=false) {
  2776. if (($pnum == $this->page) AND ($this->state == 2)) {
  2777. return;
  2778. }
  2779. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  2780. $this->state = 2;
  2781. // save current graphic settings
  2782. //$gvars = $this->getGraphicVars();
  2783. $oldpage = $this->page;
  2784. $this->page = $pnum;
  2785. $this->wPt = $this->pagedim[$this->page]['w'];
  2786. $this->hPt = $this->pagedim[$this->page]['h'];
  2787. $this->w = $this->pagedim[$this->page]['wk'];
  2788. $this->h = $this->pagedim[$this->page]['hk'];
  2789. $this->tMargin = $this->pagedim[$this->page]['tm'];
  2790. $this->bMargin = $this->pagedim[$this->page]['bm'];
  2791. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2792. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2793. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2794. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2795. $this->setAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  2796. // restore graphic settings
  2797. //$this->setGraphicVars($gvars);
  2798. if ($resetmargins) {
  2799. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2800. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2801. $this->setY($this->tMargin);
  2802. } else {
  2803. // account for booklet mode
  2804. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  2805. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2806. $this->lMargin += $deltam;
  2807. $this->rMargin -= $deltam;
  2808. }
  2809. }
  2810. } else {
  2811. $this->Error('Wrong page number on setPage() function: '.$pnum);
  2812. }
  2813. }
  2814. /**
  2815. * Reset pointer to the last document page.
  2816. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2817. * @public
  2818. * @since 2.0.000 (2008-01-04)
  2819. * @see setPage(), getPage(), getNumPages()
  2820. */
  2821. public function lastPage($resetmargins=false) {
  2822. $this->setPage($this->getNumPages(), $resetmargins);
  2823. }
  2824. /**
  2825. * Get current document page number.
  2826. * @return int page number
  2827. * @public
  2828. * @since 2.1.000 (2008-01-07)
  2829. * @see setPage(), lastpage(), getNumPages()
  2830. */
  2831. public function getPage() {
  2832. return $this->page;
  2833. }
  2834. /**
  2835. * Get the total number of insered pages.
  2836. * @return int number of pages
  2837. * @public
  2838. * @since 2.1.000 (2008-01-07)
  2839. * @see setPage(), getPage(), lastpage()
  2840. */
  2841. public function getNumPages() {
  2842. return $this->numpages;
  2843. }
  2844. /**
  2845. * Adds a new TOC (Table Of Content) page to the document.
  2846. * @param string $orientation page orientation.
  2847. * @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().
  2848. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  2849. * @public
  2850. * @since 5.0.001 (2010-05-06)
  2851. * @see AddPage(), startPage(), endPage(), endTOCPage()
  2852. */
  2853. public function addTOCPage($orientation='', $format='', $keepmargins=false) {
  2854. $this->AddPage($orientation, $format, $keepmargins, true);
  2855. }
  2856. /**
  2857. * Terminate the current TOC (Table Of Content) page
  2858. * @public
  2859. * @since 5.0.001 (2010-05-06)
  2860. * @see AddPage(), startPage(), endPage(), addTOCPage()
  2861. */
  2862. public function endTOCPage() {
  2863. $this->endPage(true);
  2864. }
  2865. /**
  2866. * 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).
  2867. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2868. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2869. * @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().
  2870. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  2871. * @param boolean $tocpage if true set the tocpage state to true (the added page will be used to display Table Of Content).
  2872. * @public
  2873. * @since 1.0
  2874. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2875. */
  2876. public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
  2877. if ($this->inxobj) {
  2878. // we are inside an XObject template
  2879. return;
  2880. }
  2881. if (!isset($this->original_lMargin) OR $keepmargins) {
  2882. $this->original_lMargin = $this->lMargin;
  2883. }
  2884. if (!isset($this->original_rMargin) OR $keepmargins) {
  2885. $this->original_rMargin = $this->rMargin;
  2886. }
  2887. // terminate previous page
  2888. $this->endPage();
  2889. // start new page
  2890. $this->startPage($orientation, $format, $tocpage);
  2891. }
  2892. /**
  2893. * Terminate the current page
  2894. * @param boolean $tocpage if true set the tocpage state to false (end the page used to display Table Of Content).
  2895. * @public
  2896. * @since 4.2.010 (2008-11-14)
  2897. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  2898. */
  2899. public function endPage($tocpage=false) {
  2900. // check if page is already closed
  2901. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  2902. return;
  2903. }
  2904. // print page footer
  2905. $this->setFooter();
  2906. // close page
  2907. $this->_endpage();
  2908. // mark page as closed
  2909. $this->pageopen[$this->page] = false;
  2910. if ($tocpage) {
  2911. $this->tocpage = false;
  2912. }
  2913. }
  2914. /**
  2915. * Starts a new page to the document. The page must be closed using the endPage() function.
  2916. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2917. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2918. * @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().
  2919. * @param boolean $tocpage if true the page is designated to contain the Table-Of-Content.
  2920. * @since 4.2.010 (2008-11-14)
  2921. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2922. * @public
  2923. */
  2924. public function startPage($orientation='', $format='', $tocpage=false) {
  2925. if ($tocpage) {
  2926. $this->tocpage = true;
  2927. }
  2928. // move page numbers of documents to be attached
  2929. if ($this->tocpage) {
  2930. // move reference to unexistent pages (used for page attachments)
  2931. // adjust outlines
  2932. $tmpoutlines = $this->outlines;
  2933. foreach ($tmpoutlines as $key => $outline) {
  2934. if (!$outline['f'] AND ($outline['p'] > $this->numpages)) {
  2935. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  2936. }
  2937. }
  2938. // adjust dests
  2939. $tmpdests = $this->dests;
  2940. foreach ($tmpdests as $key => $dest) {
  2941. if (!$dest['f'] AND ($dest['p'] > $this->numpages)) {
  2942. $this->dests[$key]['p'] = ($dest['p'] + 1);
  2943. }
  2944. }
  2945. // adjust links
  2946. $tmplinks = $this->links;
  2947. foreach ($tmplinks as $key => $link) {
  2948. if (!$link['f'] AND ($link['p'] > $this->numpages)) {
  2949. $this->links[$key]['p'] = ($link['p'] + 1);
  2950. }
  2951. }
  2952. }
  2953. if ($this->numpages > $this->page) {
  2954. // this page has been already added
  2955. $this->setPage($this->page + 1);
  2956. $this->setY($this->tMargin);
  2957. return;
  2958. }
  2959. // start a new page
  2960. if ($this->state == 0) {
  2961. $this->Open();
  2962. }
  2963. ++$this->numpages;
  2964. $this->swapMargins($this->booklet);
  2965. // save current graphic settings
  2966. $gvars = $this->getGraphicVars();
  2967. // start new page
  2968. $this->_beginpage($orientation, $format);
  2969. // mark page as open
  2970. $this->pageopen[$this->page] = true;
  2971. // restore graphic settings
  2972. $this->setGraphicVars($gvars);
  2973. // mark this point
  2974. $this->setPageMark();
  2975. // print page header
  2976. $this->setHeader();
  2977. // restore graphic settings
  2978. $this->setGraphicVars($gvars);
  2979. // mark this point
  2980. $this->setPageMark();
  2981. // print table header (if any)
  2982. $this->setTableHeader();
  2983. // set mark for empty page check
  2984. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  2985. }
  2986. /**
  2987. * Set start-writing mark on current page stream used to put borders and fills.
  2988. * Borders and fills are always created after content and inserted on the position marked by this method.
  2989. * This function must be called after calling Image() function for a background image.
  2990. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2991. * @public
  2992. * @since 4.0.016 (2008-07-30)
  2993. */
  2994. public function setPageMark() {
  2995. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2996. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  2997. $this->setContentMark();
  2998. }
  2999. /**
  3000. * Set start-writing mark on selected page.
  3001. * Borders and fills are always created after content and inserted on the position marked by this method.
  3002. * @param int $page page number (default is the current page)
  3003. * @protected
  3004. * @since 4.6.021 (2009-07-20)
  3005. */
  3006. protected function setContentMark($page=0) {
  3007. if ($page <= 0) {
  3008. $page = $this->page;
  3009. }
  3010. if (isset($this->footerlen[$page])) {
  3011. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  3012. } else {
  3013. $this->cntmrk[$page] = $this->pagelen[$page];
  3014. }
  3015. }
  3016. /**
  3017. * Set header data.
  3018. * @param string $ln header image logo
  3019. * @param int $lw header image logo width in mm
  3020. * @param string $ht string to print as title on document header
  3021. * @param string $hs string to print on document header
  3022. * @param int[] $tc RGB array color for text.
  3023. * @param int[] $lc RGB array color for line.
  3024. * @public
  3025. */
  3026. public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
  3027. $this->header_logo = $ln;
  3028. $this->header_logo_width = $lw;
  3029. $this->header_title = $ht;
  3030. $this->header_string = $hs;
  3031. $this->header_text_color = $tc;
  3032. $this->header_line_color = $lc;
  3033. }
  3034. /**
  3035. * Set footer data.
  3036. * @param int[] $tc RGB array color for text.
  3037. * @param int[] $lc RGB array color for line.
  3038. * @public
  3039. */
  3040. public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
  3041. $this->footer_text_color = $tc;
  3042. $this->footer_line_color = $lc;
  3043. }
  3044. /**
  3045. * Returns header data:
  3046. * <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>
  3047. * @return array<string,mixed>
  3048. * @public
  3049. * @since 4.0.012 (2008-07-24)
  3050. */
  3051. public function getHeaderData() {
  3052. $ret = array();
  3053. $ret['logo'] = $this->header_logo;
  3054. $ret['logo_width'] = $this->header_logo_width;
  3055. $ret['title'] = $this->header_title;
  3056. $ret['string'] = $this->header_string;
  3057. $ret['text_color'] = $this->header_text_color;
  3058. $ret['line_color'] = $this->header_line_color;
  3059. return $ret;
  3060. }
  3061. /**
  3062. * Set header margin.
  3063. * (minimum distance between header and top page margin)
  3064. * @param float $hm distance in user units
  3065. * @public
  3066. */
  3067. public function setHeaderMargin($hm=10) {
  3068. $this->header_margin = $hm;
  3069. }
  3070. /**
  3071. * Returns header margin in user units.
  3072. * @return float
  3073. * @since 4.0.012 (2008-07-24)
  3074. * @public
  3075. */
  3076. public function getHeaderMargin() {
  3077. return $this->header_margin;
  3078. }
  3079. /**
  3080. * Set footer margin.
  3081. * (minimum distance between footer and bottom page margin)
  3082. * @param float $fm distance in user units
  3083. * @public
  3084. */
  3085. public function setFooterMargin($fm=10) {
  3086. $this->footer_margin = $fm;
  3087. }
  3088. /**
  3089. * Returns footer margin in user units.
  3090. * @return float
  3091. * @since 4.0.012 (2008-07-24)
  3092. * @public
  3093. */
  3094. public function getFooterMargin() {
  3095. return $this->footer_margin;
  3096. }
  3097. /**
  3098. * Set a flag to print page header.
  3099. * @param boolean $val set to true to print the page header (default), false otherwise.
  3100. * @public
  3101. */
  3102. public function setPrintHeader($val=true) {
  3103. $this->print_header = $val ? true : false;
  3104. }
  3105. /**
  3106. * Set a flag to print page footer.
  3107. * @param boolean $val set to true to print the page footer (default), false otherwise.
  3108. * @public
  3109. */
  3110. public function setPrintFooter($val=true) {
  3111. $this->print_footer = $val ? true : false;
  3112. }
  3113. /**
  3114. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3115. * @return float
  3116. * @public
  3117. */
  3118. public function getImageRBX() {
  3119. return $this->img_rb_x;
  3120. }
  3121. /**
  3122. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3123. * @return float
  3124. * @public
  3125. */
  3126. public function getImageRBY() {
  3127. return $this->img_rb_y;
  3128. }
  3129. /**
  3130. * Reset the xobject template used by Header() method.
  3131. * @public
  3132. */
  3133. public function resetHeaderTemplate() {
  3134. $this->header_xobjid = false;
  3135. }
  3136. /**
  3137. * Set a flag to automatically reset the xobject template used by Header() method at each page.
  3138. * @param boolean $val set to true to reset Header xobject template at each page, false otherwise.
  3139. * @public
  3140. */
  3141. public function setHeaderTemplateAutoreset($val=true) {
  3142. $this->header_xobj_autoreset = $val ? true : false;
  3143. }
  3144. /**
  3145. * This method is used to render the page header.
  3146. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3147. * @public
  3148. */
  3149. public function Header() {
  3150. if ($this->header_xobjid === false) {
  3151. // start a new XObject Template
  3152. $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
  3153. $headerfont = $this->getHeaderFont();
  3154. $headerdata = $this->getHeaderData();
  3155. $this->y = $this->header_margin;
  3156. if ($this->rtl) {
  3157. $this->x = $this->w - $this->original_rMargin;
  3158. } else {
  3159. $this->x = $this->original_lMargin;
  3160. }
  3161. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3162. $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3163. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3164. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3165. } elseif ($imgtype == 'svg') {
  3166. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3167. } else {
  3168. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3169. }
  3170. $imgy = $this->getImageRBY();
  3171. } else {
  3172. $imgy = $this->y;
  3173. }
  3174. $cell_height = $this->getCellHeight($headerfont[2] / $this->k);
  3175. // set starting margin for text data cell
  3176. if ($this->getRTL()) {
  3177. $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  3178. } else {
  3179. $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  3180. }
  3181. $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  3182. $this->setTextColorArray($this->header_text_color);
  3183. // header title
  3184. $this->setFont($headerfont[0], 'B', $headerfont[2] + 1);
  3185. $this->setX($header_x);
  3186. $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  3187. // header string
  3188. $this->setFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3189. $this->setX($header_x);
  3190. $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
  3191. // print an ending header line
  3192. $this->setLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
  3193. $this->setY((2.835 / $this->k) + max($imgy, $this->y));
  3194. if ($this->rtl) {
  3195. $this->setX($this->original_rMargin);
  3196. } else {
  3197. $this->setX($this->original_lMargin);
  3198. }
  3199. $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
  3200. $this->endTemplate();
  3201. }
  3202. // print header template
  3203. $x = 0;
  3204. $dx = 0;
  3205. if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
  3206. // adjust margins for booklet mode
  3207. $dx = ($this->original_lMargin - $this->original_rMargin);
  3208. }
  3209. if ($this->rtl) {
  3210. $x = $this->w + $dx;
  3211. } else {
  3212. $x = 0 + $dx;
  3213. }
  3214. $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
  3215. if ($this->header_xobj_autoreset) {
  3216. // reset header xobject template at each page
  3217. $this->header_xobjid = false;
  3218. }
  3219. }
  3220. /**
  3221. * This method is used to render the page footer.
  3222. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3223. * @public
  3224. */
  3225. public function Footer() {
  3226. $cur_y = $this->y;
  3227. $this->setTextColorArray($this->footer_text_color);
  3228. //set style for cell border
  3229. $line_width = (0.85 / $this->k);
  3230. $this->setLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
  3231. //print document barcode
  3232. $barcode = $this->getBarcode();
  3233. if (!empty($barcode)) {
  3234. $this->Ln($line_width);
  3235. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
  3236. $style = array(
  3237. 'position' => $this->rtl?'R':'L',
  3238. 'align' => $this->rtl?'R':'L',
  3239. 'stretch' => false,
  3240. 'fitwidth' => true,
  3241. 'cellfitalign' => '',
  3242. 'border' => false,
  3243. 'padding' => 0,
  3244. 'fgcolor' => array(0,0,0),
  3245. 'bgcolor' => false,
  3246. 'text' => false
  3247. );
  3248. $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
  3249. }
  3250. $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
  3251. if (empty($this->pagegroups)) {
  3252. $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3253. } else {
  3254. $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3255. }
  3256. $this->setY($cur_y);
  3257. //Print page number
  3258. if ($this->getRTL()) {
  3259. $this->setX($this->original_rMargin);
  3260. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  3261. } else {
  3262. $this->setX($this->original_lMargin);
  3263. $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
  3264. }
  3265. }
  3266. /**
  3267. * This method is used to render the page header.
  3268. * @protected
  3269. * @since 4.0.012 (2008-07-24)
  3270. */
  3271. protected function setHeader() {
  3272. if (!$this->print_header OR ($this->state != 2)) {
  3273. return;
  3274. }
  3275. $this->InHeader = true;
  3276. $this->setGraphicVars($this->default_graphic_vars);
  3277. $temp_thead = $this->thead;
  3278. $temp_theadMargins = $this->theadMargins;
  3279. $lasth = $this->lasth;
  3280. $newline = $this->newline;
  3281. $this->_outSaveGraphicsState();
  3282. $this->rMargin = $this->original_rMargin;
  3283. $this->lMargin = $this->original_lMargin;
  3284. $this->setCellPadding(0);
  3285. //set current position
  3286. if ($this->rtl) {
  3287. $this->setXY($this->original_rMargin, $this->header_margin);
  3288. } else {
  3289. $this->setXY($this->original_lMargin, $this->header_margin);
  3290. }
  3291. $this->setFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3292. $this->Header();
  3293. //restore position
  3294. if ($this->rtl) {
  3295. $this->setXY($this->original_rMargin, $this->tMargin);
  3296. } else {
  3297. $this->setXY($this->original_lMargin, $this->tMargin);
  3298. }
  3299. $this->_outRestoreGraphicsState();
  3300. $this->lasth = $lasth;
  3301. $this->thead = $temp_thead;
  3302. $this->theadMargins = $temp_theadMargins;
  3303. $this->newline = $newline;
  3304. $this->InHeader = false;
  3305. }
  3306. /**
  3307. * This method is used to render the page footer.
  3308. * @protected
  3309. * @since 4.0.012 (2008-07-24)
  3310. */
  3311. protected function setFooter() {
  3312. if ($this->state != 2) {
  3313. return;
  3314. }
  3315. $this->InFooter = true;
  3316. // save current graphic settings
  3317. $gvars = $this->getGraphicVars();
  3318. // mark this point
  3319. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3320. $this->_out("\n");
  3321. if ($this->print_footer) {
  3322. $this->setGraphicVars($this->default_graphic_vars);
  3323. $this->current_column = 0;
  3324. $this->num_columns = 1;
  3325. $temp_thead = $this->thead;
  3326. $temp_theadMargins = $this->theadMargins;
  3327. $lasth = $this->lasth;
  3328. $this->_outSaveGraphicsState();
  3329. $this->rMargin = $this->original_rMargin;
  3330. $this->lMargin = $this->original_lMargin;
  3331. $this->setCellPadding(0);
  3332. //set current position
  3333. $footer_y = $this->h - $this->footer_margin;
  3334. if ($this->rtl) {
  3335. $this->setXY($this->original_rMargin, $footer_y);
  3336. } else {
  3337. $this->setXY($this->original_lMargin, $footer_y);
  3338. }
  3339. $this->setFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3340. $this->Footer();
  3341. //restore position
  3342. if ($this->rtl) {
  3343. $this->setXY($this->original_rMargin, $this->tMargin);
  3344. } else {
  3345. $this->setXY($this->original_lMargin, $this->tMargin);
  3346. }
  3347. $this->_outRestoreGraphicsState();
  3348. $this->lasth = $lasth;
  3349. $this->thead = $temp_thead;
  3350. $this->theadMargins = $temp_theadMargins;
  3351. }
  3352. // restore graphic settings
  3353. $this->setGraphicVars($gvars);
  3354. $this->current_column = $gvars['current_column'];
  3355. $this->num_columns = $gvars['num_columns'];
  3356. // calculate footer length
  3357. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3358. $this->InFooter = false;
  3359. }
  3360. /**
  3361. * Check if we are on the page body (excluding page header and footer).
  3362. * @return bool true if we are not in page header nor in page footer, false otherwise.
  3363. * @protected
  3364. * @since 5.9.091 (2011-06-15)
  3365. */
  3366. protected function inPageBody() {
  3367. return (($this->InHeader === false) AND ($this->InFooter === false));
  3368. }
  3369. /**
  3370. * This method is used to render the table header on new page (if any).
  3371. * @protected
  3372. * @since 4.5.030 (2009-03-25)
  3373. */
  3374. protected function setTableHeader() {
  3375. if ($this->num_columns > 1) {
  3376. // multi column mode
  3377. return;
  3378. }
  3379. if (isset($this->theadMargins['top'])) {
  3380. // restore the original top-margin
  3381. $this->tMargin = $this->theadMargins['top'];
  3382. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3383. $this->y = $this->tMargin;
  3384. }
  3385. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  3386. // set margins
  3387. $prev_lMargin = $this->lMargin;
  3388. $prev_rMargin = $this->rMargin;
  3389. $prev_cell_padding = $this->cell_padding;
  3390. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3391. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3392. $this->cell_padding = $this->theadMargins['cell_padding'];
  3393. if ($this->rtl) {
  3394. $this->x = $this->w - $this->rMargin;
  3395. } else {
  3396. $this->x = $this->lMargin;
  3397. }
  3398. // account for special "cell" mode
  3399. if ($this->theadMargins['cell']) {
  3400. if ($this->rtl) {
  3401. $this->x -= $this->cell_padding['R'];
  3402. } else {
  3403. $this->x += $this->cell_padding['L'];
  3404. }
  3405. }
  3406. $gvars = $this->getGraphicVars();
  3407. if (!empty($this->theadMargins['gvars'])) {
  3408. // set the correct graphic style
  3409. $this->setGraphicVars($this->theadMargins['gvars']);
  3410. $this->rMargin = $gvars['rMargin'];
  3411. $this->lMargin = $gvars['lMargin'];
  3412. }
  3413. // print table header
  3414. $this->writeHTML($this->thead, false, false, false, false, '');
  3415. $this->setGraphicVars($gvars);
  3416. // set new top margin to skip the table headers
  3417. if (!isset($this->theadMargins['top'])) {
  3418. $this->theadMargins['top'] = $this->tMargin;
  3419. }
  3420. // store end of header position
  3421. if (!isset($this->columns[0]['th'])) {
  3422. $this->columns[0]['th'] = array();
  3423. }
  3424. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3425. $this->tMargin = $this->y;
  3426. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3427. $this->lasth = 0;
  3428. $this->lMargin = $prev_lMargin;
  3429. $this->rMargin = $prev_rMargin;
  3430. $this->cell_padding = $prev_cell_padding;
  3431. }
  3432. }
  3433. /**
  3434. * Returns the current page number.
  3435. * @return int page number
  3436. * @public
  3437. * @since 1.0
  3438. * @see getAliasNbPages()
  3439. */
  3440. public function PageNo() {
  3441. return $this->page;
  3442. }
  3443. /**
  3444. * Returns the array of spot colors.
  3445. * @return array Spot colors array.
  3446. * @public
  3447. * @since 6.0.038 (2013-09-30)
  3448. */
  3449. public function getAllSpotColors() {
  3450. return $this->spot_colors;
  3451. }
  3452. /**
  3453. * Defines a new spot color.
  3454. * It can be expressed in RGB components or gray scale.
  3455. * The method can be called before the first page is created and the value is retained from page to page.
  3456. * @param string $name Full name of the spot color.
  3457. * @param float $c Cyan color for CMYK. Value between 0 and 100.
  3458. * @param float $m Magenta color for CMYK. Value between 0 and 100.
  3459. * @param float $y Yellow color for CMYK. Value between 0 and 100.
  3460. * @param float $k Key (Black) color for CMYK. Value between 0 and 100.
  3461. * @public
  3462. * @since 4.0.024 (2008-09-12)
  3463. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3464. */
  3465. public function AddSpotColor($name, $c, $m, $y, $k) {
  3466. if (!isset($this->spot_colors[$name])) {
  3467. $i = (1 + count($this->spot_colors));
  3468. $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
  3469. }
  3470. }
  3471. /**
  3472. * Set the spot color for the specified type ('draw', 'fill', 'text').
  3473. * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3474. * @param string $name Name of the spot color.
  3475. * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3476. * @return string PDF color command.
  3477. * @public
  3478. * @since 5.9.125 (2011-10-03)
  3479. */
  3480. public function setSpotColor($type, $name, $tint=100) {
  3481. $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
  3482. if ($spotcolor === false) {
  3483. $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
  3484. }
  3485. $tint = (max(0, min(100, $tint)) / 100);
  3486. $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
  3487. switch ($type) {
  3488. case 'draw': {
  3489. $pdfcolor .= sprintf('CS %F SCN', $tint);
  3490. $this->DrawColor = $pdfcolor;
  3491. $this->strokecolor = $spotcolor;
  3492. break;
  3493. }
  3494. case 'fill': {
  3495. $pdfcolor .= sprintf('cs %F scn', $tint);
  3496. $this->FillColor = $pdfcolor;
  3497. $this->bgcolor = $spotcolor;
  3498. break;
  3499. }
  3500. case 'text': {
  3501. $pdfcolor .= sprintf('cs %F scn', $tint);
  3502. $this->TextColor = $pdfcolor;
  3503. $this->fgcolor = $spotcolor;
  3504. break;
  3505. }
  3506. }
  3507. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3508. if ($this->state == 2) {
  3509. $this->_out($pdfcolor);
  3510. }
  3511. if ($this->inxobj) {
  3512. // we are inside an XObject template
  3513. $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  3514. }
  3515. return $pdfcolor;
  3516. }
  3517. /**
  3518. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  3519. * @param string $name Name of the spot color.
  3520. * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3521. * @public
  3522. * @since 4.0.024 (2008-09-12)
  3523. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3524. */
  3525. public function setDrawSpotColor($name, $tint=100) {
  3526. $this->setSpotColor('draw', $name, $tint);
  3527. }
  3528. /**
  3529. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  3530. * @param string $name Name of the spot color.
  3531. * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3532. * @public
  3533. * @since 4.0.024 (2008-09-12)
  3534. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  3535. */
  3536. public function setFillSpotColor($name, $tint=100) {
  3537. $this->setSpotColor('fill', $name, $tint);
  3538. }
  3539. /**
  3540. * Defines the spot color used for text.
  3541. * @param string $name Name of the spot color.
  3542. * @param int $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3543. * @public
  3544. * @since 4.0.024 (2008-09-12)
  3545. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3546. */
  3547. public function setTextSpotColor($name, $tint=100) {
  3548. $this->setSpotColor('text', $name, $tint);
  3549. }
  3550. /**
  3551. * Set the color array for the specified type ('draw', 'fill', 'text').
  3552. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3553. * The method can be called before the first page is created and the value is retained from page to page.
  3554. * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3555. * @param array $color Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  3556. * @param boolean $ret If true do not send the PDF command.
  3557. * @return string The PDF command or empty string.
  3558. * @public
  3559. * @since 3.1.000 (2008-06-11)
  3560. */
  3561. public function setColorArray($type, $color, $ret=false) {
  3562. if (is_array($color)) {
  3563. $color = array_values($color);
  3564. // component: grey, RGB red or CMYK cyan
  3565. $c = isset($color[0]) ? $color[0] : -1;
  3566. // component: RGB green or CMYK magenta
  3567. $m = isset($color[1]) ? $color[1] : -1;
  3568. // component: RGB blue or CMYK yellow
  3569. $y = isset($color[2]) ? $color[2] : -1;
  3570. // component: CMYK black
  3571. $k = isset($color[3]) ? $color[3] : -1;
  3572. // color name
  3573. $name = isset($color[4]) ? $color[4] : '';
  3574. if ($c >= 0) {
  3575. return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
  3576. }
  3577. }
  3578. return '';
  3579. }
  3580. /**
  3581. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3582. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3583. * The method can be called before the first page is created and the value is retained from page to page.
  3584. * @param array $color Array of colors (1, 3 or 4 values).
  3585. * @param boolean $ret If true do not send the PDF command.
  3586. * @return string the PDF command
  3587. * @public
  3588. * @since 3.1.000 (2008-06-11)
  3589. * @see SetDrawColor()
  3590. */
  3591. public function setDrawColorArray($color, $ret=false) {
  3592. return $this->setColorArray('draw', $color, $ret);
  3593. }
  3594. /**
  3595. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  3596. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3597. * The method can be called before the first page is created and the value is retained from page to page.
  3598. * @param array $color Array of colors (1, 3 or 4 values).
  3599. * @param boolean $ret If true do not send the PDF command.
  3600. * @public
  3601. * @since 3.1.000 (2008-6-11)
  3602. * @see SetFillColor()
  3603. */
  3604. public function setFillColorArray($color, $ret=false) {
  3605. return $this->setColorArray('fill', $color, $ret);
  3606. }
  3607. /**
  3608. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  3609. * The method can be called before the first page is created and the value is retained from page to page.
  3610. * @param array $color Array of colors (1, 3 or 4 values).
  3611. * @param boolean $ret If true do not send the PDF command.
  3612. * @public
  3613. * @since 3.1.000 (2008-6-11)
  3614. * @see SetFillColor()
  3615. */
  3616. public function setTextColorArray($color, $ret=false) {
  3617. return $this->setColorArray('text', $color, $ret);
  3618. }
  3619. /**
  3620. * Defines the color used by the specified type ('draw', 'fill', 'text').
  3621. * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3622. * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3623. * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3624. * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3625. * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3626. * @param boolean $ret If true do not send the command.
  3627. * @param string $name spot color name (if any)
  3628. * @return string The PDF command or empty string.
  3629. * @public
  3630. * @since 5.9.125 (2011-10-03)
  3631. */
  3632. public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3633. // set default values
  3634. if (!is_numeric($col1)) {
  3635. $col1 = 0;
  3636. }
  3637. if (!is_numeric($col2)) {
  3638. $col2 = -1;
  3639. }
  3640. if (!is_numeric($col3)) {
  3641. $col3 = -1;
  3642. }
  3643. if (!is_numeric($col4)) {
  3644. $col4 = -1;
  3645. }
  3646. // set color by case
  3647. $suffix = '';
  3648. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  3649. // Grey scale
  3650. $col1 = max(0, min(255, $col1));
  3651. $intcolor = array('G' => $col1);
  3652. $pdfcolor = sprintf('%F ', ($col1 / 255));
  3653. $suffix = 'g';
  3654. } elseif ($col4 == -1) {
  3655. // RGB
  3656. $col1 = max(0, min(255, $col1));
  3657. $col2 = max(0, min(255, $col2));
  3658. $col3 = max(0, min(255, $col3));
  3659. $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  3660. $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  3661. $suffix = 'rg';
  3662. } else {
  3663. $col1 = max(0, min(100, $col1));
  3664. $col2 = max(0, min(100, $col2));
  3665. $col3 = max(0, min(100, $col3));
  3666. $col4 = max(0, min(100, $col4));
  3667. if (empty($name)) {
  3668. // CMYK
  3669. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  3670. $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  3671. $suffix = 'k';
  3672. } else {
  3673. // SPOT COLOR
  3674. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  3675. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  3676. $pdfcolor = $this->setSpotColor($type, $name, 100);
  3677. }
  3678. }
  3679. switch ($type) {
  3680. case 'draw': {
  3681. $pdfcolor .= strtoupper($suffix);
  3682. $this->DrawColor = $pdfcolor;
  3683. $this->strokecolor = $intcolor;
  3684. break;
  3685. }
  3686. case 'fill': {
  3687. $pdfcolor .= $suffix;
  3688. $this->FillColor = $pdfcolor;
  3689. $this->bgcolor = $intcolor;
  3690. break;
  3691. }
  3692. case 'text': {
  3693. $pdfcolor .= $suffix;
  3694. $this->TextColor = $pdfcolor;
  3695. $this->fgcolor = $intcolor;
  3696. break;
  3697. }
  3698. }
  3699. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3700. if (($type != 'text') AND ($this->state == 2) AND $type !== 0) {
  3701. if (!$ret) {
  3702. $this->_out($pdfcolor);
  3703. }
  3704. return $pdfcolor;
  3705. }
  3706. return '';
  3707. }
  3708. /**
  3709. * 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.
  3710. * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3711. * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3712. * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3713. * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3714. * @param boolean $ret If true do not send the command.
  3715. * @param string $name spot color name (if any)
  3716. * @return string the PDF command
  3717. * @public
  3718. * @since 1.3
  3719. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3720. */
  3721. public function setDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3722. return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
  3723. }
  3724. /**
  3725. * 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.
  3726. * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3727. * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3728. * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3729. * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3730. * @param boolean $ret If true do not send the command.
  3731. * @param string $name Spot color name (if any).
  3732. * @return string The PDF command.
  3733. * @public
  3734. * @since 1.3
  3735. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  3736. */
  3737. public function setFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3738. return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
  3739. }
  3740. /**
  3741. * 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.
  3742. * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3743. * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3744. * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3745. * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3746. * @param boolean $ret If true do not send the command.
  3747. * @param string $name Spot color name (if any).
  3748. * @return string Empty string.
  3749. * @public
  3750. * @since 1.3
  3751. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  3752. */
  3753. public function setTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3754. return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
  3755. }
  3756. /**
  3757. * Returns the length of a string in user unit. A font must be selected.<br>
  3758. * @param string $s The string whose length is to be computed
  3759. * @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.
  3760. * @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.
  3761. * @param float $fontsize Font size in points. The default value is the current size.
  3762. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  3763. * @return float[]|float total string length or array of characted widths
  3764. * @phpstan-return ($getarray is true ? float[] : float) total string length or array of characted widths
  3765. * @author Nicola Asuni
  3766. * @public
  3767. * @since 1.2
  3768. */
  3769. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3770. 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);
  3771. }
  3772. /**
  3773. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  3774. * @param array $sa The array of chars whose total length is to be computed
  3775. * @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.
  3776. * @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.
  3777. * @param float $fontsize Font size in points. The default value is the current size.
  3778. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  3779. * @return float[]|float total string length or array of characted widths
  3780. * @phpstan-return ($getarray is true ? float[] : float) total string length or array of characted widths
  3781. * @author Nicola Asuni
  3782. * @public
  3783. * @since 2.4.000 (2008-03-06)
  3784. */
  3785. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3786. // store current values
  3787. if (!TCPDF_STATIC::empty_string($fontname)) {
  3788. $prev_FontFamily = $this->FontFamily;
  3789. $prev_FontStyle = $this->FontStyle;
  3790. $prev_FontSizePt = $this->FontSizePt;
  3791. $this->setFont($fontname, $fontstyle, $fontsize, '', 'default', false);
  3792. }
  3793. // convert UTF-8 array to Latin1 if required
  3794. if ($this->isunicode AND (!$this->isUnicodeFont())) {
  3795. $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
  3796. }
  3797. $w = 0; // total width
  3798. $wa = array(); // array of characters widths
  3799. foreach ($sa as $ck => $char) {
  3800. // character width
  3801. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  3802. $wa[] = $cw;
  3803. $w += $cw;
  3804. }
  3805. // restore previous values
  3806. if (!TCPDF_STATIC::empty_string($fontname)) {
  3807. $this->setFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
  3808. }
  3809. if ($getarray) {
  3810. return $wa;
  3811. }
  3812. return $w;
  3813. }
  3814. /**
  3815. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  3816. * @param int $char The char code whose length is to be returned
  3817. * @param boolean $notlast If false ignore the font-spacing.
  3818. * @return float char width
  3819. * @author Nicola Asuni
  3820. * @public
  3821. * @since 2.4.000 (2008-03-06)
  3822. */
  3823. public function GetCharWidth($char, $notlast=true) {
  3824. // get raw width
  3825. $chw = $this->getRawCharWidth($char);
  3826. if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
  3827. // increase/decrease font spacing
  3828. $chw += $this->font_spacing;
  3829. }
  3830. if ($this->font_stretching != 100) {
  3831. // fixed stretching mode
  3832. $chw *= ($this->font_stretching / 100);
  3833. }
  3834. return $chw;
  3835. }
  3836. /**
  3837. * Returns the length of the char in user unit for the current font.
  3838. * @param int $char The char code whose length is to be returned
  3839. * @return float char width
  3840. * @author Nicola Asuni
  3841. * @public
  3842. * @since 5.9.000 (2010-09-28)
  3843. */
  3844. public function getRawCharWidth($char) {
  3845. if ($char == 173) {
  3846. // SHY character will not be printed
  3847. return (0);
  3848. }
  3849. if (isset($this->CurrentFont['cw'][intval($char)])) {
  3850. $w = $this->CurrentFont['cw'][intval($char)];
  3851. } elseif (isset($this->CurrentFont['dw'])) {
  3852. // default width
  3853. $w = $this->CurrentFont['dw'];
  3854. } elseif (isset($this->CurrentFont['cw'][32])) {
  3855. // default width
  3856. $w = $this->CurrentFont['cw'][32];
  3857. } else {
  3858. $w = 600;
  3859. }
  3860. return $this->getAbsFontMeasure($w);
  3861. }
  3862. /**
  3863. * Returns the numbero of characters in a string.
  3864. * @param string $s The input string.
  3865. * @return int number of characters
  3866. * @public
  3867. * @since 2.0.0001 (2008-01-07)
  3868. */
  3869. public function GetNumChars($s) {
  3870. if ($this->isUnicodeFont()) {
  3871. return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
  3872. }
  3873. return strlen($s);
  3874. }
  3875. /**
  3876. * Fill the list of available fonts ($this->fontlist).
  3877. * @protected
  3878. * @since 4.0.013 (2008-07-28)
  3879. */
  3880. protected function getFontsList() {
  3881. if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) {
  3882. while (($file = readdir($fontsdir)) !== false) {
  3883. if (substr($file, -4) == '.php') {
  3884. array_push($this->fontlist, strtolower(basename($file, '.php')));
  3885. }
  3886. }
  3887. closedir($fontsdir);
  3888. }
  3889. }
  3890. /**
  3891. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3892. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3893. * 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.
  3894. * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3895. * @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>
  3896. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3897. * @return array|false array containing the font data, or false in case of error.
  3898. * @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.
  3899. * @public
  3900. * @since 1.5
  3901. * @see SetFont(), setFontSubsetting()
  3902. */
  3903. public function AddFont($family, $style='', $fontfile='', $subset='default') {
  3904. if ($subset === 'default') {
  3905. $subset = $this->font_subsetting;
  3906. }
  3907. if ($this->pdfa_mode) {
  3908. $subset = false;
  3909. }
  3910. if (TCPDF_STATIC::empty_string($family)) {
  3911. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  3912. $family = $this->FontFamily;
  3913. } else {
  3914. $this->Error('Empty font family');
  3915. }
  3916. }
  3917. // move embedded styles on $style
  3918. if (substr($family, -1) == 'I') {
  3919. $style .= 'I';
  3920. $family = substr($family, 0, -1);
  3921. }
  3922. if (substr($family, -1) == 'B') {
  3923. $style .= 'B';
  3924. $family = substr($family, 0, -1);
  3925. }
  3926. // normalize family name
  3927. $family = strtolower($family);
  3928. if ((!$this->isunicode) AND ($family == 'arial')) {
  3929. $family = 'helvetica';
  3930. }
  3931. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  3932. $style = '';
  3933. }
  3934. if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  3935. // all fonts must be embedded
  3936. $family = 'pdfa'.$family;
  3937. }
  3938. $tempstyle = strtoupper($style === null ? '' : $style);
  3939. $style = '';
  3940. // underline
  3941. if (strpos($tempstyle, 'U') !== false) {
  3942. $this->underline = true;
  3943. } else {
  3944. $this->underline = false;
  3945. }
  3946. // line-through (deleted)
  3947. if (strpos($tempstyle, 'D') !== false) {
  3948. $this->linethrough = true;
  3949. } else {
  3950. $this->linethrough = false;
  3951. }
  3952. // overline
  3953. if (strpos($tempstyle, 'O') !== false) {
  3954. $this->overline = true;
  3955. } else {
  3956. $this->overline = false;
  3957. }
  3958. // bold
  3959. if (strpos($tempstyle, 'B') !== false) {
  3960. $style .= 'B';
  3961. }
  3962. // oblique
  3963. if (strpos($tempstyle, 'I') !== false) {
  3964. $style .= 'I';
  3965. }
  3966. $bistyle = $style;
  3967. $fontkey = $family.$style;
  3968. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  3969. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  3970. // check if the font has been already added
  3971. $fb = $this->getFontBuffer($fontkey);
  3972. if ($fb !== false) {
  3973. if ($this->inxobj) {
  3974. // we are inside an XObject template
  3975. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  3976. }
  3977. return $fontdata;
  3978. }
  3979. // get specified font directory (if any)
  3980. $fontdir = false;
  3981. if (!TCPDF_STATIC::empty_string($fontfile)) {
  3982. $fontdir = dirname($fontfile);
  3983. if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) {
  3984. $fontdir = '';
  3985. } else {
  3986. $fontdir .= '/';
  3987. }
  3988. }
  3989. // true when the font style variation is missing
  3990. $missing_style = false;
  3991. // search and include font file
  3992. if (TCPDF_STATIC::empty_string($fontfile) OR (!@TCPDF_STATIC::file_exists($fontfile))) {
  3993. // build a standard filenames for specified font
  3994. $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
  3995. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3996. if (TCPDF_STATIC::empty_string($fontfile)) {
  3997. $missing_style = true;
  3998. // try to remove the style part
  3999. $tmp_fontfile = str_replace(' ', '', $family).'.php';
  4000. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  4001. }
  4002. }
  4003. // include font file
  4004. if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) {
  4005. $type=null;
  4006. $name=null;
  4007. $desc=null;
  4008. $up=-null;
  4009. $ut=null;
  4010. $cw=null;
  4011. $cbbox=null;
  4012. $dw=null;
  4013. $enc=null;
  4014. $cidinfo=null;
  4015. $file=null;
  4016. $ctg=null;
  4017. $diff=null;
  4018. $originalsize=null;
  4019. $size1=null;
  4020. $size2=null;
  4021. include($fontfile);
  4022. } else {
  4023. $this->Error('Could not include font definition file: '.$family.'');
  4024. }
  4025. // check font parameters
  4026. if ((!isset($type)) OR (!isset($cw))) {
  4027. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  4028. }
  4029. // SET default parameters
  4030. if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
  4031. $file = '';
  4032. }
  4033. if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
  4034. $enc = '';
  4035. }
  4036. if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
  4037. $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
  4038. $cidinfo['uni2cid'] = array();
  4039. }
  4040. if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
  4041. $ctg = '';
  4042. }
  4043. if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
  4044. $desc = array();
  4045. }
  4046. if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
  4047. $up = -100;
  4048. }
  4049. if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
  4050. $ut = 50;
  4051. }
  4052. if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
  4053. $cw = array();
  4054. }
  4055. if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
  4056. // set default width
  4057. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  4058. $dw = $desc['MissingWidth'];
  4059. } elseif (isset($cw[32])) {
  4060. $dw = $cw[32];
  4061. } else {
  4062. $dw = 600;
  4063. }
  4064. }
  4065. ++$this->numfonts;
  4066. if ($type == 'core') {
  4067. $name = $this->CoreFonts[$fontkey];
  4068. $subset = false;
  4069. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  4070. $subset = false;
  4071. } elseif ($type == 'TrueTypeUnicode') {
  4072. $enc = 'Identity-H';
  4073. } elseif ($type == 'cidfont0') {
  4074. if ($this->pdfa_mode) {
  4075. $this->Error('All fonts must be embedded in PDF/A mode!');
  4076. }
  4077. } else {
  4078. $this->Error('Unknow font type: '.$type.'');
  4079. }
  4080. // set name if unset
  4081. if (empty($name)) {
  4082. $name = $fontkey;
  4083. }
  4084. // create artificial font style variations if missing (only works with non-embedded fonts)
  4085. if (($type != 'core') AND $missing_style) {
  4086. // style variations
  4087. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  4088. $name .= $styles[$bistyle];
  4089. // artificial bold
  4090. if (strpos($bistyle, 'B') !== false) {
  4091. if (isset($desc['StemV'])) {
  4092. // from normal to bold
  4093. $desc['StemV'] = round($desc['StemV'] * 1.75);
  4094. } else {
  4095. // bold
  4096. $desc['StemV'] = 123;
  4097. }
  4098. }
  4099. // artificial italic
  4100. if (strpos($bistyle, 'I') !== false) {
  4101. if (isset($desc['ItalicAngle'])) {
  4102. $desc['ItalicAngle'] -= 11;
  4103. } else {
  4104. $desc['ItalicAngle'] = -11;
  4105. }
  4106. if (isset($desc['Flags'])) {
  4107. $desc['Flags'] |= 64; //bit 7
  4108. } else {
  4109. $desc['Flags'] = 64;
  4110. }
  4111. }
  4112. }
  4113. // check if the array of characters bounding boxes is defined
  4114. if (!isset($cbbox)) {
  4115. $cbbox = array();
  4116. }
  4117. // initialize subsetchars
  4118. $subsetchars = array_fill(0, 255, true);
  4119. $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));
  4120. if ($this->inxobj) {
  4121. // we are inside an XObject template
  4122. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4123. }
  4124. if (!empty($diff)) {
  4125. //Search existing encodings
  4126. $d = 0;
  4127. $nb = count($this->diffs);
  4128. for ($i=1; $i <= $nb; ++$i) {
  4129. if ($this->diffs[$i] == $diff) {
  4130. $d = $i;
  4131. break;
  4132. }
  4133. }
  4134. if ($d == 0) {
  4135. $d = $nb + 1;
  4136. $this->diffs[$d] = $diff;
  4137. }
  4138. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4139. }
  4140. if (!TCPDF_STATIC::empty_string($file)) {
  4141. if (!isset($this->FontFiles[$file])) {
  4142. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4143. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4144. } elseif ($type != 'core') {
  4145. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4146. }
  4147. } else {
  4148. // update fontkeys that are sharing this font file
  4149. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4150. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  4151. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4152. }
  4153. }
  4154. }
  4155. return $fontdata;
  4156. }
  4157. /**
  4158. * Sets the font used to print character strings.
  4159. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4160. * The method can be called before the first page is created and the font is retained from page to page.
  4161. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4162. * 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 />
  4163. * @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.
  4164. * @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.
  4165. * @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
  4166. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4167. * @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.
  4168. * @param boolean $out if true output the font size command, otherwise only set the font properties.
  4169. * @author Nicola Asuni
  4170. * @public
  4171. * @since 1.0
  4172. * @see AddFont(), SetFontSize()
  4173. */
  4174. public function setFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true) {
  4175. //Select a font; size given in points
  4176. if ($size === null) {
  4177. $size = $this->FontSizePt;
  4178. }
  4179. if ($size < 0) {
  4180. $size = 0;
  4181. }
  4182. // try to add font (if not already added)
  4183. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  4184. $this->FontFamily = $fontdata['family'];
  4185. $this->FontStyle = $fontdata['style'];
  4186. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  4187. // save subset chars of the previous font
  4188. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4189. }
  4190. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  4191. $this->setFontSize($size, $out);
  4192. }
  4193. /**
  4194. * Defines the size of the current font.
  4195. * @param float $size The font size in points.
  4196. * @param boolean $out if true output the font size command, otherwise only set the font properties.
  4197. * @public
  4198. * @since 1.0
  4199. * @see SetFont()
  4200. */
  4201. public function setFontSize($size, $out=true) {
  4202. $size = (float)$size;
  4203. // font size in points
  4204. $this->FontSizePt = $size;
  4205. // font size in user units
  4206. $this->FontSize = $size / $this->k;
  4207. // calculate some font metrics
  4208. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4209. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4210. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  4211. } else {
  4212. $font_height = $size * 1.219;
  4213. }
  4214. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4215. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  4216. }
  4217. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4218. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  4219. }
  4220. if (!isset($font_ascent) AND !isset($font_descent)) {
  4221. // core font
  4222. $font_ascent = 0.76 * $font_height;
  4223. $font_descent = $font_height - $font_ascent;
  4224. } elseif (!isset($font_descent)) {
  4225. $font_descent = $font_height - $font_ascent;
  4226. } elseif (!isset($font_ascent)) {
  4227. $font_ascent = $font_height - $font_descent;
  4228. }
  4229. $this->FontAscent = ($font_ascent / $this->k);
  4230. $this->FontDescent = ($font_descent / $this->k);
  4231. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  4232. $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4233. }
  4234. }
  4235. /**
  4236. * Returns the bounding box of the current font in user units.
  4237. * @return array
  4238. * @public
  4239. * @since 5.9.152 (2012-03-23)
  4240. */
  4241. public function getFontBBox() {
  4242. $fbbox = array();
  4243. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4244. $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4245. $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
  4246. } else {
  4247. // Find max width
  4248. if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  4249. $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  4250. } else {
  4251. $maxw = 0;
  4252. if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  4253. $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
  4254. }
  4255. if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  4256. $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
  4257. }
  4258. if (isset($this->CurrentFont['dw'])) {
  4259. $maxw = max($maxw, $this->CurrentFont['dw']);
  4260. }
  4261. foreach ($this->CurrentFont['cw'] as $char => $w) {
  4262. $maxw = max($maxw, $w);
  4263. }
  4264. if ($maxw == 0) {
  4265. $maxw = 600;
  4266. }
  4267. $maxw = $this->getAbsFontMeasure($maxw);
  4268. }
  4269. $fbbox = array(0, (0 - $this->FontDescent), $maxw, $this->FontAscent);
  4270. }
  4271. return $fbbox;
  4272. }
  4273. /**
  4274. * Convert a relative font measure into absolute value.
  4275. * @param int $s Font measure.
  4276. * @return float Absolute measure.
  4277. * @since 5.9.186 (2012-09-13)
  4278. */
  4279. public function getAbsFontMeasure($s) {
  4280. return ($s * $this->FontSize / 1000);
  4281. }
  4282. /**
  4283. * Returns the glyph bounding box of the specified character in the current font in user units.
  4284. * @param int $char Input character code.
  4285. * @return false|array array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  4286. * @since 5.9.186 (2012-09-13)
  4287. */
  4288. public function getCharBBox($char) {
  4289. $c = intval($char);
  4290. if (isset($this->CurrentFont['cw'][$c])) {
  4291. // glyph is defined ... use zero width & height for glyphs without outlines
  4292. $result = array(0,0,0,0);
  4293. if (isset($this->CurrentFont['cbbox'][$c])) {
  4294. $result = $this->CurrentFont['cbbox'][$c];
  4295. }
  4296. return array_map(array($this,'getAbsFontMeasure'), $result);
  4297. }
  4298. return false;
  4299. }
  4300. /**
  4301. * Return the font descent value
  4302. * @param string $font font name
  4303. * @param string $style font style
  4304. * @param float $size The size (in points)
  4305. * @return int font descent
  4306. * @public
  4307. * @author Nicola Asuni
  4308. * @since 4.9.003 (2010-03-30)
  4309. */
  4310. public function getFontDescent($font, $style='', $size=0) {
  4311. $fontdata = $this->AddFont($font, $style);
  4312. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4313. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4314. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  4315. } else {
  4316. $descent = (1.219 * 0.24 * $size);
  4317. }
  4318. return ($descent / $this->k);
  4319. }
  4320. /**
  4321. * Return the font ascent value.
  4322. * @param string $font font name
  4323. * @param string $style font style
  4324. * @param float $size The size (in points)
  4325. * @return int font ascent
  4326. * @public
  4327. * @author Nicola Asuni
  4328. * @since 4.9.003 (2010-03-30)
  4329. */
  4330. public function getFontAscent($font, $style='', $size=0) {
  4331. $fontdata = $this->AddFont($font, $style);
  4332. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4333. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4334. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  4335. } else {
  4336. $ascent = 1.219 * 0.76 * $size;
  4337. }
  4338. return ($ascent / $this->k);
  4339. }
  4340. /**
  4341. * Return true in the character is present in the specified font.
  4342. * @param mixed $char Character to check (integer value or string)
  4343. * @param string $font Font name (family name).
  4344. * @param string $style Font style.
  4345. * @return bool true if the char is defined, false otherwise.
  4346. * @public
  4347. * @since 5.9.153 (2012-03-28)
  4348. */
  4349. public function isCharDefined($char, $font='', $style='') {
  4350. if (is_string($char)) {
  4351. // get character code
  4352. $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont);
  4353. $char = $char[0];
  4354. }
  4355. if (TCPDF_STATIC::empty_string($font)) {
  4356. if (TCPDF_STATIC::empty_string($style)) {
  4357. return (isset($this->CurrentFont['cw'][intval($char)]));
  4358. }
  4359. $font = $this->FontFamily;
  4360. }
  4361. $fontdata = $this->AddFont($font, $style);
  4362. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4363. return (isset($fontinfo['cw'][intval($char)]));
  4364. }
  4365. /**
  4366. * Replace missing font characters on selected font with specified substitutions.
  4367. * @param string $text Text to process.
  4368. * @param string $font Font name (family name).
  4369. * @param string $style Font style.
  4370. * @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.
  4371. * @return string Processed text.
  4372. * @public
  4373. * @since 5.9.153 (2012-03-28)
  4374. */
  4375. public function replaceMissingChars($text, $font='', $style='', $subs=array()) {
  4376. if (empty($subs)) {
  4377. return $text;
  4378. }
  4379. if (TCPDF_STATIC::empty_string($font)) {
  4380. $font = $this->FontFamily;
  4381. }
  4382. $fontdata = $this->AddFont($font, $style);
  4383. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4384. $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  4385. foreach ($uniarr as $k => $chr) {
  4386. if (!isset($fontinfo['cw'][$chr])) {
  4387. // this character is missing on the selected font
  4388. if (isset($subs[$chr])) {
  4389. // we have available substitutions
  4390. if (is_array($subs[$chr])) {
  4391. foreach($subs[$chr] as $s) {
  4392. if (isset($fontinfo['cw'][$s])) {
  4393. $uniarr[$k] = $s;
  4394. break;
  4395. }
  4396. }
  4397. } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  4398. $uniarr[$k] = $subs[$chr];
  4399. }
  4400. }
  4401. }
  4402. }
  4403. return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr, $this->isunicode));
  4404. }
  4405. /**
  4406. * Defines the default monospaced font.
  4407. * @param string $font Font name.
  4408. * @public
  4409. * @since 4.5.025
  4410. */
  4411. public function setDefaultMonospacedFont($font) {
  4412. $this->default_monospaced_font = $font;
  4413. }
  4414. /**
  4415. * 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 />
  4416. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4417. * @public
  4418. * @since 1.5
  4419. * @see Cell(), Write(), Image(), Link(), SetLink()
  4420. */
  4421. public function AddLink() {
  4422. // create a new internal link
  4423. $n = count($this->links) + 1;
  4424. $this->links[$n] = array('p' => 0, 'y' => 0, 'f' => false);
  4425. return $n;
  4426. }
  4427. /**
  4428. * Defines the page and position a link points to.
  4429. * @param int $link The link identifier returned by AddLink()
  4430. * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4431. * @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.
  4432. * @public
  4433. * @since 1.5
  4434. * @see AddLink()
  4435. */
  4436. public function setLink($link, $y=0, $page=-1) {
  4437. $fixed = false;
  4438. if (!empty($page) AND (substr($page, 0, 1) == '*')) {
  4439. $page = intval(substr($page, 1));
  4440. // this page number will not be changed when moving/add/deleting pages
  4441. $fixed = true;
  4442. }
  4443. if ($page < 0) {
  4444. $page = $this->page;
  4445. }
  4446. if ($y == -1) {
  4447. $y = $this->y;
  4448. }
  4449. $this->links[$link] = array('p' => $page, 'y' => $y, 'f' => $fixed);
  4450. }
  4451. /**
  4452. * Puts a link on a rectangular area of the page.
  4453. * 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.
  4454. * @param float $x Abscissa of the upper-left corner of the rectangle
  4455. * @param float $y Ordinate of the upper-left corner of the rectangle
  4456. * @param float $w Width of the rectangle
  4457. * @param float $h Height of the rectangle
  4458. * @param mixed $link URL or identifier returned by AddLink()
  4459. * @param int $spaces number of spaces on the text to link
  4460. * @public
  4461. * @since 1.5
  4462. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4463. */
  4464. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  4465. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  4466. }
  4467. /**
  4468. * Puts a markup annotation on a rectangular area of the page.
  4469. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4470. * @param float $x Abscissa of the upper-left corner of the rectangle
  4471. * @param float $y Ordinate of the upper-left corner of the rectangle
  4472. * @param float $w Width of the rectangle
  4473. * @param float $h Height of the rectangle
  4474. * @param string $text annotation text or alternate content
  4475. * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  4476. * @param int $spaces number of spaces on the text to link
  4477. * @public
  4478. * @since 4.0.018 (2008-08-06)
  4479. */
  4480. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  4481. if ($this->inxobj) {
  4482. // store parameters for later use on template
  4483. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  4484. return;
  4485. }
  4486. if ($x === '') {
  4487. $x = $this->x;
  4488. }
  4489. if ($y === '') {
  4490. $y = $this->y;
  4491. }
  4492. // check page for no-write regions and adapt page margins if necessary
  4493. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  4494. // recalculate coordinates to account for graphic transformations
  4495. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4496. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  4497. $maxid = count($this->transfmatrix[$i]) - 1;
  4498. for ($j=$maxid; $j >= 0; --$j) {
  4499. $ctm = $this->transfmatrix[$i][$j];
  4500. if (isset($ctm['a'])) {
  4501. $x = $x * $this->k;
  4502. $y = ($this->h - $y) * $this->k;
  4503. $w = $w * $this->k;
  4504. $h = $h * $this->k;
  4505. // top left
  4506. $xt = $x;
  4507. $yt = $y;
  4508. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4509. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4510. // top right
  4511. $xt = $x + $w;
  4512. $yt = $y;
  4513. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4514. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4515. // bottom left
  4516. $xt = $x;
  4517. $yt = $y - $h;
  4518. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4519. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4520. // bottom right
  4521. $xt = $x + $w;
  4522. $yt = $y - $h;
  4523. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4524. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4525. // new coordinates (rectangle area)
  4526. $x = min($x1, $x2, $x3, $x4);
  4527. $y = max($y1, $y2, $y3, $y4);
  4528. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  4529. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  4530. $x = $x / $this->k;
  4531. $y = $this->h - ($y / $this->k);
  4532. }
  4533. }
  4534. }
  4535. }
  4536. if ($this->page <= 0) {
  4537. $page = 1;
  4538. } else {
  4539. $page = $this->page;
  4540. }
  4541. if (!isset($this->PageAnnots[$page])) {
  4542. $this->PageAnnots[$page] = array();
  4543. }
  4544. $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  4545. if (!$this->pdfa_mode || ($this->pdfa_mode && $this->pdfa_version == 3)) {
  4546. if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
  4547. AND (@TCPDF_STATIC::file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
  4548. AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  4549. $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
  4550. }
  4551. }
  4552. // Add widgets annotation's icons
  4553. if (isset($opt['mk']['i']) AND @TCPDF_STATIC::file_exists($opt['mk']['i'])) {
  4554. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  4555. }
  4556. if (isset($opt['mk']['ri']) AND @TCPDF_STATIC::file_exists($opt['mk']['ri'])) {
  4557. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4558. }
  4559. if (isset($opt['mk']['ix']) AND @TCPDF_STATIC::file_exists($opt['mk']['ix'])) {
  4560. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4561. }
  4562. }
  4563. /**
  4564. * Embedd the attached files.
  4565. * @since 4.4.000 (2008-12-07)
  4566. * @protected
  4567. * @see Annotation()
  4568. */
  4569. protected function _putEmbeddedFiles() {
  4570. if ($this->pdfa_mode && $this->pdfa_version != 3) {
  4571. // embedded files are not allowed in PDF/A mode version 1 and 2
  4572. return;
  4573. }
  4574. reset($this->embeddedfiles);
  4575. foreach ($this->embeddedfiles as $filename => $filedata) {
  4576. $data = $this->getCachedFileContents($filedata['file']);
  4577. if ($data !== FALSE) {
  4578. $rawsize = strlen($data);
  4579. if ($rawsize > 0) {
  4580. // update name tree
  4581. $this->efnames[$filename] = $filedata['f'].' 0 R';
  4582. // embedded file specification object
  4583. $out = $this->_getobj($filedata['f'])."\n";
  4584. $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']);
  4585. $out .= ' /UF '.$this->_datastring($filename, $filedata['f']);
  4586. $out .= ' /AFRelationship /Source';
  4587. $out .= ' /EF <</F '.$filedata['n'].' 0 R>> >>';
  4588. $out .= "\n".'endobj';
  4589. $this->_out($out);
  4590. // embedded file object
  4591. $filter = '';
  4592. if ($this->compress) {
  4593. $data = gzcompress($data);
  4594. $filter = ' /Filter /FlateDecode';
  4595. }
  4596. if ($this->pdfa_version == 3) {
  4597. $filter = ' /Subtype /text#2Fxml';
  4598. }
  4599. $stream = $this->_getrawstream($data, $filedata['n']);
  4600. $out = $this->_getobj($filedata['n'])."\n";
  4601. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
  4602. $out .= ' stream'."\n".$stream."\n".'endstream';
  4603. $out .= "\n".'endobj';
  4604. $this->_out($out);
  4605. }
  4606. }
  4607. }
  4608. }
  4609. /**
  4610. * Prints a text cell at the specified position.
  4611. * This method allows to place a string precisely on the page.
  4612. * @param float $x Abscissa of the cell origin
  4613. * @param float $y Ordinate of the cell origin
  4614. * @param string $txt String to print
  4615. * @param int $fstroke outline size in user units (0 = disable)
  4616. * @param boolean $fclip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4617. * @param boolean $ffill if true fills the text
  4618. * @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)))
  4619. * @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.
  4620. * @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>
  4621. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4622. * @param mixed $link URL or identifier returned by AddLink().
  4623. * @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.
  4624. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4625. * @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>
  4626. * @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>
  4627. * @param boolean $rtloff if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4628. * @public
  4629. * @since 1.0
  4630. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4631. */
  4632. 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) {
  4633. $textrendermode = $this->textrendermode;
  4634. $textstrokewidth = $this->textstrokewidth;
  4635. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  4636. $this->setXY($x, $y, $rtloff);
  4637. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  4638. // restore previous rendering mode
  4639. $this->textrendermode = $textrendermode;
  4640. $this->textstrokewidth = $textstrokewidth;
  4641. }
  4642. /**
  4643. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4644. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4645. * This method is called automatically and should not be called directly by the application.
  4646. * @return bool
  4647. * @public
  4648. * @since 1.4
  4649. * @see SetAutoPageBreak()
  4650. */
  4651. public function AcceptPageBreak() {
  4652. if ($this->num_columns > 1) {
  4653. // multi column mode
  4654. if ($this->current_column < ($this->num_columns - 1)) {
  4655. // go to next column
  4656. $this->selectColumn($this->current_column + 1);
  4657. } elseif ($this->AutoPageBreak) {
  4658. // add a new page
  4659. $this->AddPage();
  4660. // set first column
  4661. $this->selectColumn(0);
  4662. }
  4663. // avoid page breaking from checkPageBreak()
  4664. return false;
  4665. }
  4666. return $this->AutoPageBreak;
  4667. }
  4668. /**
  4669. * Add page if needed.
  4670. * @param float $h Cell height. Default value: 0.
  4671. * @param float|null $y starting y position, leave empty for current position.
  4672. * @param bool $addpage if true add a page, otherwise only return the true/false state
  4673. * @return bool true in case of page break, false otherwise.
  4674. * @since 3.2.000 (2008-07-01)
  4675. * @protected
  4676. */
  4677. protected function checkPageBreak($h=0, $y=null, $addpage=true) {
  4678. if (TCPDF_STATIC::empty_string($y)) {
  4679. $y = $this->y;
  4680. }
  4681. $current_page = $this->page;
  4682. if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  4683. if ($addpage) {
  4684. //Automatic page break
  4685. $x = $this->x;
  4686. $this->AddPage($this->CurOrientation);
  4687. $this->y = $this->tMargin;
  4688. $oldpage = $this->page - 1;
  4689. if ($this->rtl) {
  4690. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4691. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4692. } else {
  4693. $this->x = $x;
  4694. }
  4695. } else {
  4696. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4697. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4698. } else {
  4699. $this->x = $x;
  4700. }
  4701. }
  4702. }
  4703. return true;
  4704. }
  4705. if ($current_page != $this->page) {
  4706. // account for columns mode
  4707. return true;
  4708. }
  4709. return false;
  4710. }
  4711. /**
  4712. * 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 />
  4713. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4714. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  4715. * @param float $h Cell height. Default value: 0.
  4716. * @param string $txt String to print. Default value: empty string.
  4717. * @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)))
  4718. * @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.
  4719. * @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>
  4720. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4721. * @param mixed $link URL or identifier returned by AddLink().
  4722. * @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.
  4723. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4724. * @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>
  4725. * @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>
  4726. * @public
  4727. * @since 1.0
  4728. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  4729. */
  4730. 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') {
  4731. $prev_cell_margin = $this->cell_margin;
  4732. $prev_cell_padding = $this->cell_padding;
  4733. $this->adjustCellPadding($border);
  4734. if (!$ignore_min_height) {
  4735. $min_cell_height = $this->getCellHeight($this->FontSize);
  4736. if ($h < $min_cell_height) {
  4737. $h = $min_cell_height;
  4738. }
  4739. }
  4740. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  4741. // apply text shadow if enabled
  4742. if ($this->txtshadow['enabled']) {
  4743. // save data
  4744. $x = $this->x;
  4745. $y = $this->y;
  4746. $bc = $this->bgcolor;
  4747. $fc = $this->fgcolor;
  4748. $sc = $this->strokecolor;
  4749. $alpha = $this->alpha;
  4750. // print shadow
  4751. $this->x += $this->txtshadow['depth_w'];
  4752. $this->y += $this->txtshadow['depth_h'];
  4753. $this->setFillColorArray($this->txtshadow['color']);
  4754. $this->setTextColorArray($this->txtshadow['color']);
  4755. $this->setDrawColorArray($this->txtshadow['color']);
  4756. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4757. $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  4758. }
  4759. if ($this->state == 2) {
  4760. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4761. }
  4762. //restore data
  4763. $this->x = $x;
  4764. $this->y = $y;
  4765. $this->setFillColorArray($bc);
  4766. $this->setTextColorArray($fc);
  4767. $this->setDrawColorArray($sc);
  4768. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4769. $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  4770. }
  4771. }
  4772. if ($this->state == 2) {
  4773. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4774. }
  4775. $this->cell_padding = $prev_cell_padding;
  4776. $this->cell_margin = $prev_cell_margin;
  4777. }
  4778. /**
  4779. * 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 />
  4780. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4781. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  4782. * @param float $h Cell height. Default value: 0.
  4783. * @param string $txt String to print. Default value: empty string.
  4784. * @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)))
  4785. * @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.
  4786. * @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>
  4787. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4788. * @param mixed $link URL or identifier returned by AddLink().
  4789. * @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.
  4790. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4791. * @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>
  4792. * @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>
  4793. * @return string containing cell code
  4794. * @protected
  4795. * @since 1.0
  4796. * @see Cell()
  4797. */
  4798. 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') {
  4799. // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  4800. $txt = is_null($txt) ? '' : $txt;
  4801. $txt = str_replace(TCPDF_FONTS::unichr(160, $this->isunicode), ' ', $txt);
  4802. $prev_cell_margin = $this->cell_margin;
  4803. $prev_cell_padding = $this->cell_padding;
  4804. $txt = TCPDF_STATIC::removeSHY($txt, $this->isunicode);
  4805. $rs = ''; //string to be returned
  4806. $this->adjustCellPadding($border);
  4807. if (!$ignore_min_height) {
  4808. $min_cell_height = $this->getCellHeight($this->FontSize);
  4809. if ($h < $min_cell_height) {
  4810. $h = $min_cell_height;
  4811. }
  4812. }
  4813. $k = $this->k;
  4814. // check page for no-write regions and adapt page margins if necessary
  4815. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  4816. if ($this->rtl) {
  4817. $x = $this->x - $this->cell_margin['R'];
  4818. } else {
  4819. $x = $this->x + $this->cell_margin['L'];
  4820. }
  4821. $y = $this->y + $this->cell_margin['T'];
  4822. $prev_font_stretching = $this->font_stretching;
  4823. $prev_font_spacing = $this->font_spacing;
  4824. // cell vertical alignment
  4825. switch ($calign) {
  4826. case 'A': {
  4827. // font top
  4828. switch ($valign) {
  4829. case 'T': {
  4830. // top
  4831. $y -= $this->cell_padding['T'];
  4832. break;
  4833. }
  4834. case 'B': {
  4835. // bottom
  4836. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  4837. break;
  4838. }
  4839. default:
  4840. case 'C':
  4841. case 'M': {
  4842. // center
  4843. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  4844. break;
  4845. }
  4846. }
  4847. break;
  4848. }
  4849. case 'L': {
  4850. // font baseline
  4851. switch ($valign) {
  4852. case 'T': {
  4853. // top
  4854. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  4855. break;
  4856. }
  4857. case 'B': {
  4858. // bottom
  4859. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  4860. break;
  4861. }
  4862. default:
  4863. case 'C':
  4864. case 'M': {
  4865. // center
  4866. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  4867. break;
  4868. }
  4869. }
  4870. break;
  4871. }
  4872. case 'D': {
  4873. // font bottom
  4874. switch ($valign) {
  4875. case 'T': {
  4876. // top
  4877. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  4878. break;
  4879. }
  4880. case 'B': {
  4881. // bottom
  4882. $y -= ($h - $this->cell_padding['B']);
  4883. break;
  4884. }
  4885. default:
  4886. case 'C':
  4887. case 'M': {
  4888. // center
  4889. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  4890. break;
  4891. }
  4892. }
  4893. break;
  4894. }
  4895. case 'B': {
  4896. // cell bottom
  4897. $y -= $h;
  4898. break;
  4899. }
  4900. case 'C':
  4901. case 'M': {
  4902. // cell center
  4903. $y -= ($h / 2);
  4904. break;
  4905. }
  4906. default:
  4907. case 'T': {
  4908. // cell top
  4909. break;
  4910. }
  4911. }
  4912. // text vertical alignment
  4913. switch ($valign) {
  4914. case 'T': {
  4915. // top
  4916. $yt = $y + $this->cell_padding['T'];
  4917. break;
  4918. }
  4919. case 'B': {
  4920. // bottom
  4921. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  4922. break;
  4923. }
  4924. default:
  4925. case 'C':
  4926. case 'M': {
  4927. // center
  4928. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  4929. break;
  4930. }
  4931. }
  4932. $basefonty = $yt + $this->FontAscent;
  4933. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  4934. if ($this->rtl) {
  4935. $w = $x - $this->lMargin;
  4936. } else {
  4937. $w = $this->w - $this->rMargin - $x;
  4938. }
  4939. }
  4940. $s = '';
  4941. // fill and borders
  4942. if (is_string($border) AND (strlen($border) == 4)) {
  4943. // full border
  4944. $border = 1;
  4945. }
  4946. if ($fill OR ($border == 1)) {
  4947. if ($fill) {
  4948. $op = ($border == 1) ? 'B' : 'f';
  4949. } else {
  4950. $op = 'S';
  4951. }
  4952. if ($this->rtl) {
  4953. $xk = (($x - $w) * $k);
  4954. } else {
  4955. $xk = ($x * $k);
  4956. }
  4957. $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  4958. }
  4959. // draw borders
  4960. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  4961. if ($txt != '') {
  4962. $txt2 = $txt;
  4963. if ($this->isunicode) {
  4964. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  4965. $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont);
  4966. } else {
  4967. $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values
  4968. $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont);
  4969. // replace thai chars (if any)
  4970. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  4971. // number of chars
  4972. $numchars = count($unicode);
  4973. // po pla, for far, for fan
  4974. $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
  4975. // do chada, to patak
  4976. $lowtail = array(0x0e0e, 0x0e0f);
  4977. // mai hun arkad, sara i, sara ii, sara ue, sara uee
  4978. $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
  4979. // mai ek, mai tho, mai tri, mai chattawa, karan
  4980. $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
  4981. // sara u, sara uu, pinthu
  4982. $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
  4983. $output = array();
  4984. for ($i = 0; $i < $numchars; $i++) {
  4985. if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  4986. $ch0 = $unicode[$i];
  4987. $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
  4988. $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
  4989. $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
  4990. if (in_array($ch0, $tonemark)) {
  4991. if ($chn == 0x0e33) {
  4992. // sara um
  4993. if (in_array($ch1, $longtail)) {
  4994. // tonemark at upper left
  4995. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4996. } else {
  4997. // tonemark at upper right (normal position)
  4998. $output[] = $ch0;
  4999. }
  5000. } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
  5001. // tonemark at lower left
  5002. $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
  5003. } elseif (in_array($ch1, $upvowel)) {
  5004. if (in_array($ch2, $longtail)) {
  5005. // tonemark at upper left
  5006. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  5007. } else {
  5008. // tonemark at upper right (normal position)
  5009. $output[] = $ch0;
  5010. }
  5011. } else {
  5012. // tonemark at lower right
  5013. $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
  5014. }
  5015. } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
  5016. // add lower left nikhahit and sara aa
  5017. if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  5018. $output[] = 0xf711;
  5019. $this->CurrentFont['subsetchars'][0xf711] = true;
  5020. $output[] = 0x0e32;
  5021. $this->CurrentFont['subsetchars'][0x0e32] = true;
  5022. } else {
  5023. $output[] = $ch0;
  5024. }
  5025. } elseif (in_array($ch1, $longtail)) {
  5026. if ($ch0 == 0x0e31) {
  5027. // lower left mai hun arkad
  5028. $output[] = $this->replaceChar($ch0, 0xf710);
  5029. } elseif (in_array($ch0, $upvowel)) {
  5030. // lower left
  5031. $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
  5032. } elseif ($ch0 == 0x0e47) {
  5033. // lower left mai tai koo
  5034. $output[] = $this->replaceChar($ch0, 0xf712);
  5035. } else {
  5036. // normal character
  5037. $output[] = $ch0;
  5038. }
  5039. } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
  5040. // lower vowel
  5041. $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
  5042. } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
  5043. // yo ying without lower part
  5044. $output[] = $this->replaceChar($ch0, 0xf70f);
  5045. } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
  5046. // tho santan without lower part
  5047. $output[] = $this->replaceChar($ch0, 0xf700);
  5048. } else {
  5049. $output[] = $ch0;
  5050. }
  5051. } else {
  5052. // non-thai character
  5053. $output[] = $unicode[$i];
  5054. }
  5055. }
  5056. $unicode = $output;
  5057. // update font subsetchars
  5058. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  5059. } // end of K_THAI_TOPCHARS
  5060. $txt2 = TCPDF_FONTS::arrUTF8ToUTF16BE($unicode, false);
  5061. }
  5062. }
  5063. $txt2 = TCPDF_STATIC::_escape($txt2);
  5064. // get current text width (considering general font stretching and spacing)
  5065. $txwidth = $this->GetStringWidth($txt);
  5066. $width = $txwidth;
  5067. // check for stretch mode
  5068. if ($stretch > 0) {
  5069. // calculate ratio between cell width and text width
  5070. if ($width <= 0) {
  5071. $ratio = 1;
  5072. } else {
  5073. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  5074. }
  5075. // check if stretching is required
  5076. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  5077. // the text will be stretched to fit cell width
  5078. if ($stretch > 2) {
  5079. // set new character spacing
  5080. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  5081. } else {
  5082. // set new horizontal stretching
  5083. $this->font_stretching *= $ratio;
  5084. }
  5085. // recalculate text width (the text fills the entire cell)
  5086. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5087. // reset alignment
  5088. $align = '';
  5089. }
  5090. }
  5091. if ($this->font_stretching != 100) {
  5092. // apply font stretching
  5093. $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
  5094. }
  5095. if ($this->font_spacing != 0) {
  5096. // increase/decrease font spacing
  5097. $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
  5098. }
  5099. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5100. $s .= 'q '.$this->TextColor.' ';
  5101. }
  5102. // rendering mode
  5103. $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
  5104. // count number of spaces
  5105. $ns = substr_count($txt, chr(32));
  5106. // Justification
  5107. $spacewidth = 0;
  5108. if (($align == 'J') AND ($ns > 0)) {
  5109. if ($this->isUnicodeFont()) {
  5110. // get string width without spaces
  5111. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  5112. // calculate average space width
  5113. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
  5114. if ($this->font_stretching != 100) {
  5115. // word spacing is affected by stretching
  5116. $spacewidth /= ($this->font_stretching / 100);
  5117. }
  5118. // set word position to be used with TJ operator
  5119. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
  5120. $unicode_justification = true;
  5121. } else {
  5122. // get string width
  5123. $width = $txwidth;
  5124. // new space width
  5125. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5126. if ($this->font_stretching != 100) {
  5127. // word spacing (Tw) is affected by stretching
  5128. $spacewidth /= ($this->font_stretching / 100);
  5129. }
  5130. // set word spacing
  5131. $rs .= sprintf('BT %F Tw ET ', $spacewidth);
  5132. }
  5133. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5134. }
  5135. // replace carriage return characters
  5136. $txt2 = str_replace("\r", ' ', $txt2);
  5137. switch ($align) {
  5138. case 'C': {
  5139. $dx = ($w - $width) / 2;
  5140. break;
  5141. }
  5142. case 'R': {
  5143. if ($this->rtl) {
  5144. $dx = $this->cell_padding['R'];
  5145. } else {
  5146. $dx = $w - $width - $this->cell_padding['R'];
  5147. }
  5148. break;
  5149. }
  5150. case 'L': {
  5151. if ($this->rtl) {
  5152. $dx = $w - $width - $this->cell_padding['L'];
  5153. } else {
  5154. $dx = $this->cell_padding['L'];
  5155. }
  5156. break;
  5157. }
  5158. case 'J':
  5159. default: {
  5160. if ($this->rtl) {
  5161. $dx = $this->cell_padding['R'];
  5162. } else {
  5163. $dx = $this->cell_padding['L'];
  5164. }
  5165. break;
  5166. }
  5167. }
  5168. if ($this->rtl) {
  5169. $xdx = $x - $dx - $width;
  5170. } else {
  5171. $xdx = $x + $dx;
  5172. }
  5173. $xdk = $xdx * $k;
  5174. // print text
  5175. $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  5176. if (isset($uniblock)) { // @phpstan-ignore-line
  5177. // print overlapping characters as separate string
  5178. $xshift = 0; // horizontal shift
  5179. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  5180. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5181. foreach ($uniblock as $uk => $uniarr) { // @phpstan-ignore-line
  5182. if (($uk % 2) == 0) {
  5183. // x space to skip
  5184. if ($spacewidth != 0) {
  5185. // justification shift
  5186. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  5187. }
  5188. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5189. } else {
  5190. // character to print
  5191. $topchr = TCPDF_FONTS::arrUTF8ToUTF16BE($uniarr, false);
  5192. $topchr = TCPDF_STATIC::_escape($topchr);
  5193. $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  5194. }
  5195. }
  5196. }
  5197. if ($this->underline) {
  5198. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  5199. }
  5200. if ($this->linethrough) {
  5201. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  5202. }
  5203. if ($this->overline) {
  5204. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  5205. }
  5206. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5207. $s .= ' Q';
  5208. }
  5209. if ($link) {
  5210. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  5211. }
  5212. }
  5213. // output cell
  5214. if ($s) {
  5215. // output cell
  5216. $rs .= $s;
  5217. if ($this->font_spacing != 0) {
  5218. // reset font spacing mode
  5219. $rs .= ' BT 0 Tc ET';
  5220. }
  5221. if ($this->font_stretching != 100) {
  5222. // reset font stretching mode
  5223. $rs .= ' BT 100 Tz ET';
  5224. }
  5225. }
  5226. // reset word spacing
  5227. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5228. $rs .= ' BT 0 Tw ET';
  5229. }
  5230. // reset stretching and spacing
  5231. $this->font_stretching = $prev_font_stretching;
  5232. $this->font_spacing = $prev_font_spacing;
  5233. $this->lasth = $h;
  5234. if ($ln > 0) {
  5235. //Go to the beginning of the next line
  5236. $this->y = $y + $h + $this->cell_margin['B'];
  5237. if ($ln == 1) {
  5238. if ($this->rtl) {
  5239. $this->x = $this->w - $this->rMargin;
  5240. } else {
  5241. $this->x = $this->lMargin;
  5242. }
  5243. }
  5244. } else {
  5245. // go left or right by case
  5246. if ($this->rtl) {
  5247. $this->x = $x - $w - $this->cell_margin['L'];
  5248. } else {
  5249. $this->x = $x + $w + $this->cell_margin['R'];
  5250. }
  5251. }
  5252. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5253. $rs = $gstyles.$rs;
  5254. $this->cell_padding = $prev_cell_padding;
  5255. $this->cell_margin = $prev_cell_margin;
  5256. return $rs;
  5257. }
  5258. /**
  5259. * Replace a char if is defined on the current font.
  5260. * @param int $oldchar Integer code (unicode) of the character to replace.
  5261. * @param int $newchar Integer code (unicode) of the new character.
  5262. * @return int the replaced char or the old char in case the new char i not defined
  5263. * @protected
  5264. * @since 5.9.167 (2012-06-22)
  5265. */
  5266. protected function replaceChar($oldchar, $newchar) {
  5267. if ($this->isCharDefined($newchar)) {
  5268. // add the new char on the subset list
  5269. $this->CurrentFont['subsetchars'][$newchar] = true;
  5270. // return the new character
  5271. return $newchar;
  5272. }
  5273. // return the old char
  5274. return $oldchar;
  5275. }
  5276. /**
  5277. * Returns the code to draw the cell border
  5278. * @param float $x X coordinate.
  5279. * @param float $y Y coordinate.
  5280. * @param float $w Cell width.
  5281. * @param float $h Cell height.
  5282. * @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)))
  5283. * @return string containing cell border code
  5284. * @protected
  5285. * @see SetLineStyle()
  5286. * @since 5.7.000 (2010-08-02)
  5287. */
  5288. protected function getCellBorder($x, $y, $w, $h, $brd) {
  5289. $s = ''; // string to be returned
  5290. if (empty($brd)) {
  5291. return $s;
  5292. }
  5293. if ($brd == 1) {
  5294. $brd = array('LRTB' => true);
  5295. }
  5296. // calculate coordinates for border
  5297. $k = $this->k;
  5298. if ($this->rtl) {
  5299. $xeL = ($x - $w) * $k;
  5300. $xeR = $x * $k;
  5301. } else {
  5302. $xeL = $x * $k;
  5303. $xeR = ($x + $w) * $k;
  5304. }
  5305. $yeL = (($this->h - ($y + $h)) * $k);
  5306. $yeT = (($this->h - $y) * $k);
  5307. $xeT = $xeL;
  5308. $xeB = $xeR;
  5309. $yeR = $yeT;
  5310. $yeB = $yeL;
  5311. if (is_string($brd)) {
  5312. // convert string to array
  5313. $slen = strlen($brd);
  5314. $newbrd = array();
  5315. for ($i = 0; $i < $slen; ++$i) {
  5316. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  5317. }
  5318. $brd = $newbrd;
  5319. }
  5320. if (isset($brd['mode'])) {
  5321. $mode = $brd['mode'];
  5322. unset($brd['mode']);
  5323. } else {
  5324. $mode = 'normal';
  5325. }
  5326. foreach ($brd as $border => $style) {
  5327. if (is_array($style) AND !empty($style)) {
  5328. // apply border style
  5329. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5330. $s .= $this->setLineStyle($style, true)."\n";
  5331. }
  5332. switch ($mode) {
  5333. case 'ext': {
  5334. $off = (($this->LineWidth / 2) * $k);
  5335. $xL = $xeL - $off;
  5336. $xR = $xeR + $off;
  5337. $yT = $yeT + $off;
  5338. $yL = $yeL - $off;
  5339. $xT = $xL;
  5340. $xB = $xR;
  5341. $yR = $yT;
  5342. $yB = $yL;
  5343. $w += $this->LineWidth;
  5344. $h += $this->LineWidth;
  5345. break;
  5346. }
  5347. case 'int': {
  5348. $off = ($this->LineWidth / 2) * $k;
  5349. $xL = $xeL + $off;
  5350. $xR = $xeR - $off;
  5351. $yT = $yeT - $off;
  5352. $yL = $yeL + $off;
  5353. $xT = $xL;
  5354. $xB = $xR;
  5355. $yR = $yT;
  5356. $yB = $yL;
  5357. $w -= $this->LineWidth;
  5358. $h -= $this->LineWidth;
  5359. break;
  5360. }
  5361. case 'normal':
  5362. default: {
  5363. $xL = $xeL;
  5364. $xT = $xeT;
  5365. $xB = $xeB;
  5366. $xR = $xeR;
  5367. $yL = $yeL;
  5368. $yT = $yeT;
  5369. $yB = $yeB;
  5370. $yR = $yeR;
  5371. break;
  5372. }
  5373. }
  5374. // draw borders by case
  5375. if (strlen($border) == 4) {
  5376. $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  5377. } elseif (strlen($border) == 3) {
  5378. if (strpos($border,'B') === false) { // LTR
  5379. $s .= sprintf('%F %F m ', $xL, $yL);
  5380. $s .= sprintf('%F %F l ', $xT, $yT);
  5381. $s .= sprintf('%F %F l ', $xR, $yR);
  5382. $s .= sprintf('%F %F l ', $xB, $yB);
  5383. $s .= 'S ';
  5384. } elseif (strpos($border,'L') === false) { // TRB
  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 .= sprintf('%F %F l ', $xL, $yL);
  5389. $s .= 'S ';
  5390. } elseif (strpos($border,'T') === false) { // RBL
  5391. $s .= sprintf('%F %F m ', $xR, $yR);
  5392. $s .= sprintf('%F %F l ', $xB, $yB);
  5393. $s .= sprintf('%F %F l ', $xL, $yL);
  5394. $s .= sprintf('%F %F l ', $xT, $yT);
  5395. $s .= 'S ';
  5396. } elseif (strpos($border,'R') === false) { // BLT
  5397. $s .= sprintf('%F %F m ', $xB, $yB);
  5398. $s .= sprintf('%F %F l ', $xL, $yL);
  5399. $s .= sprintf('%F %F l ', $xT, $yT);
  5400. $s .= sprintf('%F %F l ', $xR, $yR);
  5401. $s .= 'S ';
  5402. }
  5403. } elseif (strlen($border) == 2) {
  5404. if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  5405. $s .= sprintf('%F %F m ', $xL, $yL);
  5406. $s .= sprintf('%F %F l ', $xT, $yT);
  5407. $s .= sprintf('%F %F l ', $xR, $yR);
  5408. $s .= 'S ';
  5409. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  5410. $s .= sprintf('%F %F m ', $xT, $yT);
  5411. $s .= sprintf('%F %F l ', $xR, $yR);
  5412. $s .= sprintf('%F %F l ', $xB, $yB);
  5413. $s .= 'S ';
  5414. } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  5415. $s .= sprintf('%F %F m ', $xR, $yR);
  5416. $s .= sprintf('%F %F l ', $xB, $yB);
  5417. $s .= sprintf('%F %F l ', $xL, $yL);
  5418. $s .= 'S ';
  5419. } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  5420. $s .= sprintf('%F %F m ', $xB, $yB);
  5421. $s .= sprintf('%F %F l ', $xL, $yL);
  5422. $s .= sprintf('%F %F l ', $xT, $yT);
  5423. $s .= 'S ';
  5424. } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  5425. $s .= sprintf('%F %F m ', $xL, $yL);
  5426. $s .= sprintf('%F %F l ', $xT, $yT);
  5427. $s .= 'S ';
  5428. $s .= sprintf('%F %F m ', $xR, $yR);
  5429. $s .= sprintf('%F %F l ', $xB, $yB);
  5430. $s .= 'S ';
  5431. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  5432. $s .= sprintf('%F %F m ', $xT, $yT);
  5433. $s .= sprintf('%F %F l ', $xR, $yR);
  5434. $s .= 'S ';
  5435. $s .= sprintf('%F %F m ', $xB, $yB);
  5436. $s .= sprintf('%F %F l ', $xL, $yL);
  5437. $s .= 'S ';
  5438. }
  5439. } else { // strlen($border) == 1
  5440. if (strpos($border,'L') !== false) { // L
  5441. $s .= sprintf('%F %F m ', $xL, $yL);
  5442. $s .= sprintf('%F %F l ', $xT, $yT);
  5443. $s .= 'S ';
  5444. } elseif (strpos($border,'T') !== false) { // T
  5445. $s .= sprintf('%F %F m ', $xT, $yT);
  5446. $s .= sprintf('%F %F l ', $xR, $yR);
  5447. $s .= 'S ';
  5448. } elseif (strpos($border,'R') !== false) { // R
  5449. $s .= sprintf('%F %F m ', $xR, $yR);
  5450. $s .= sprintf('%F %F l ', $xB, $yB);
  5451. $s .= 'S ';
  5452. } elseif (strpos($border,'B') !== false) { // B
  5453. $s .= sprintf('%F %F m ', $xB, $yB);
  5454. $s .= sprintf('%F %F l ', $xL, $yL);
  5455. $s .= 'S ';
  5456. }
  5457. }
  5458. if (is_array($style) AND !empty($style)) {
  5459. // reset border style to previous value
  5460. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5461. }
  5462. }
  5463. return $s;
  5464. }
  5465. /**
  5466. * This method allows printing text with line breaks.
  5467. * 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 />
  5468. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5469. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5470. * @param float $h Cell minimum height. The cell extends automatically if needed.
  5471. * @param string $txt String to print
  5472. * @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)))
  5473. * @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>
  5474. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  5475. * @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>
  5476. * @param float|null $x x position in user units
  5477. * @param float|null $y y position in user units
  5478. * @param boolean $reseth if true reset the last cell height (default true).
  5479. * @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.
  5480. * @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.
  5481. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  5482. * @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.
  5483. * @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.
  5484. * @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.
  5485. * @return int Return the number of cells or 1 for html mode.
  5486. * @public
  5487. * @since 1.3
  5488. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5489. */
  5490. 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) {
  5491. $prev_cell_margin = $this->cell_margin;
  5492. $prev_cell_padding = $this->cell_padding;
  5493. // adjust internal padding
  5494. $this->adjustCellPadding($border);
  5495. $mc_padding = $this->cell_padding;
  5496. $mc_margin = $this->cell_margin;
  5497. $this->cell_padding['T'] = 0;
  5498. $this->cell_padding['B'] = 0;
  5499. $this->setCellMargins(0, 0, 0, 0);
  5500. if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) {
  5501. // reset row height
  5502. $this->resetLastH();
  5503. }
  5504. if (!TCPDF_STATIC::empty_string($y)) {
  5505. $this->setY($y); // set y in order to convert negative y values to positive ones
  5506. }
  5507. $y = $this->GetY();
  5508. $resth = 0;
  5509. if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5510. // spit cell in more pages/columns
  5511. $newh = ($this->PageBreakTrigger - $y);
  5512. $resth = ($h - $newh); // cell to be printed on the next page/column
  5513. $h = $newh;
  5514. }
  5515. // get current page number
  5516. $startpage = $this->page;
  5517. // get current column
  5518. $startcolumn = $this->current_column;
  5519. if (!TCPDF_STATIC::empty_string($x)) {
  5520. $this->setX($x);
  5521. } else {
  5522. $x = $this->GetX();
  5523. }
  5524. // check page for no-write regions and adapt page margins if necessary
  5525. list($x, $y) = $this->checkPageRegions(0, $x, $y);
  5526. // apply margins
  5527. $oy = $y + $mc_margin['T'];
  5528. if ($this->rtl) {
  5529. $ox = ($this->w - $x - $mc_margin['R']);
  5530. } else {
  5531. $ox = ($x + $mc_margin['L']);
  5532. }
  5533. $this->x = $ox;
  5534. $this->y = $oy;
  5535. // set width
  5536. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5537. if ($this->rtl) {
  5538. $w = ($this->x - $this->lMargin - $mc_margin['L']);
  5539. } else {
  5540. $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
  5541. }
  5542. }
  5543. // store original margin values
  5544. $lMargin = $this->lMargin;
  5545. $rMargin = $this->rMargin;
  5546. if ($this->rtl) {
  5547. $this->rMargin = ($this->w - $this->x);
  5548. $this->lMargin = ($this->x - $w);
  5549. } else {
  5550. $this->lMargin = ($this->x);
  5551. $this->rMargin = ($this->w - $this->x - $w);
  5552. }
  5553. $this->clMargin = $this->lMargin;
  5554. $this->crMargin = $this->rMargin;
  5555. if ($autopadding) {
  5556. // add top padding
  5557. $this->y += $mc_padding['T'];
  5558. }
  5559. if ($ishtml) { // ******* Write HTML text
  5560. $this->writeHTML($txt, true, false, $reseth, true, $align);
  5561. $nl = 1;
  5562. } else { // ******* Write simple text
  5563. $prev_FontSizePt = $this->FontSizePt;
  5564. if ($fitcell) {
  5565. // ajust height values
  5566. $tobottom = ($this->h - $this->y - $this->bMargin - $this->cell_padding['T'] - $this->cell_padding['B']);
  5567. $h = $maxh = max(min($h, $tobottom), min($maxh, $tobottom));
  5568. }
  5569. // vertical alignment
  5570. if ($maxh > 0) {
  5571. // get text height
  5572. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5573. if ($fitcell AND ($text_height > $maxh) AND ($this->FontSizePt > 1)) {
  5574. // try to reduce font size to fit text on cell (use a quick search algorithm)
  5575. $fmin = 1;
  5576. $fmax = $this->FontSizePt;
  5577. $diff_epsilon = (1 / $this->k); // one point (min resolution)
  5578. $maxit = (2 * min(100, max(10, intval($fmax)))); // max number of iterations
  5579. while ($maxit >= 0) {
  5580. $fmid = (($fmax + $fmin) / 2);
  5581. $this->setFontSize($fmid, false);
  5582. $this->resetLastH();
  5583. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5584. $diff = ($maxh - $text_height);
  5585. if ($diff >= 0) {
  5586. if ($diff <= $diff_epsilon) {
  5587. break;
  5588. }
  5589. $fmin = $fmid;
  5590. } else {
  5591. $fmax = $fmid;
  5592. }
  5593. --$maxit;
  5594. }
  5595. if ($maxit < 0) {
  5596. // premature exit, we get the minimum font value to fit the cell
  5597. $this->setFontSize($fmin);
  5598. $this->resetLastH();
  5599. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5600. } else {
  5601. $this->setFontSize($fmid);
  5602. $this->resetLastH();
  5603. }
  5604. }
  5605. if ($text_height < $maxh) {
  5606. if ($valign == 'M') {
  5607. // text vertically centered
  5608. $this->y += (($maxh - $text_height) / 2);
  5609. } elseif ($valign == 'B') {
  5610. // text vertically aligned on bottom
  5611. $this->y += ($maxh - $text_height);
  5612. }
  5613. }
  5614. }
  5615. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  5616. if ($fitcell) {
  5617. // restore font size
  5618. $this->setFontSize($prev_FontSizePt);
  5619. }
  5620. }
  5621. if ($autopadding) {
  5622. // add bottom padding
  5623. $this->y += $mc_padding['B'];
  5624. }
  5625. // Get end-of-text Y position
  5626. $currentY = $this->y;
  5627. // get latest page number
  5628. $endpage = $this->page;
  5629. if ($resth > 0) {
  5630. $skip = ($endpage - $startpage);
  5631. $tmpresth = $resth;
  5632. while ($tmpresth > 0) {
  5633. if ($skip <= 0) {
  5634. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5635. $this->checkPageBreak($this->PageBreakTrigger + 1);
  5636. }
  5637. if ($this->num_columns > 1) {
  5638. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  5639. } else {
  5640. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  5641. }
  5642. --$skip;
  5643. }
  5644. $currentY = $this->y;
  5645. $endpage = $this->page;
  5646. }
  5647. // get latest column
  5648. $endcolumn = $this->current_column;
  5649. if ($this->num_columns == 0) {
  5650. $this->num_columns = 1;
  5651. }
  5652. // disable page regions check
  5653. $check_page_regions = $this->check_page_regions;
  5654. $this->check_page_regions = false;
  5655. // get border modes
  5656. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  5657. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  5658. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  5659. // design borders around HTML cells.
  5660. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  5661. $ccode = '';
  5662. $this->setPage($page);
  5663. if ($this->num_columns < 2) {
  5664. // single-column mode
  5665. $this->setX($x);
  5666. $this->y = $this->tMargin;
  5667. }
  5668. // account for margin changes
  5669. if ($page > $startpage) {
  5670. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5671. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5672. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5673. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5674. }
  5675. }
  5676. if ($startpage == $endpage) {
  5677. // single page
  5678. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  5679. if ($column != $this->current_column) {
  5680. $this->selectColumn($column);
  5681. }
  5682. if ($this->rtl) {
  5683. $this->x -= $mc_margin['R'];
  5684. } else {
  5685. $this->x += $mc_margin['L'];
  5686. }
  5687. if ($startcolumn == $endcolumn) { // single column
  5688. $cborder = $border;
  5689. $h = max($h, ($currentY - $oy));
  5690. $this->y = $oy;
  5691. } elseif ($column == $startcolumn) { // first column
  5692. $cborder = $border_start;
  5693. $this->y = $oy;
  5694. $h = $this->h - $this->y - $this->bMargin;
  5695. } elseif ($column == $endcolumn) { // end column
  5696. $cborder = $border_end;
  5697. $h = $currentY - $this->y;
  5698. if ($resth > $h) {
  5699. $h = $resth;
  5700. }
  5701. } else { // middle column
  5702. $cborder = $border_middle;
  5703. $h = $this->h - $this->y - $this->bMargin;
  5704. $resth -= $h;
  5705. }
  5706. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5707. } // end for each column
  5708. } elseif ($page == $startpage) { // first page
  5709. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  5710. if ($column != $this->current_column) {
  5711. $this->selectColumn($column);
  5712. }
  5713. if ($this->rtl) {
  5714. $this->x -= $mc_margin['R'];
  5715. } else {
  5716. $this->x += $mc_margin['L'];
  5717. }
  5718. if ($column == $startcolumn) { // first column
  5719. $cborder = $border_start;
  5720. $this->y = $oy;
  5721. $h = $this->h - $this->y - $this->bMargin;
  5722. } else { // 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. } elseif ($page == $endpage) { // last page
  5730. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  5731. if ($column != $this->current_column) {
  5732. $this->selectColumn($column);
  5733. }
  5734. if ($this->rtl) {
  5735. $this->x -= $mc_margin['R'];
  5736. } else {
  5737. $this->x += $mc_margin['L'];
  5738. }
  5739. if ($column == $endcolumn) {
  5740. // end column
  5741. $cborder = $border_end;
  5742. $h = $currentY - $this->y;
  5743. if ($resth > $h) {
  5744. $h = $resth;
  5745. }
  5746. } else {
  5747. // middle column
  5748. $cborder = $border_middle;
  5749. $h = $this->h - $this->y - $this->bMargin;
  5750. $resth -= $h;
  5751. }
  5752. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5753. } // end for each column
  5754. } else { // middle page
  5755. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  5756. $this->selectColumn($column);
  5757. if ($this->rtl) {
  5758. $this->x -= $mc_margin['R'];
  5759. } else {
  5760. $this->x += $mc_margin['L'];
  5761. }
  5762. $cborder = $border_middle;
  5763. $h = $this->h - $this->y - $this->bMargin;
  5764. $resth -= $h;
  5765. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5766. } // end for each column
  5767. }
  5768. if ($cborder OR $fill) {
  5769. $offsetlen = strlen($ccode);
  5770. // draw border and fill
  5771. if ($this->inxobj) {
  5772. // we are inside an XObject template
  5773. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5774. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  5775. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5776. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  5777. } else {
  5778. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  5779. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  5780. }
  5781. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  5782. $pstart = substr($pagebuff, 0, $pagemark);
  5783. $pend = substr($pagebuff, $pagemark);
  5784. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5785. } else {
  5786. if (end($this->transfmrk[$this->page]) !== false) {
  5787. $pagemarkkey = key($this->transfmrk[$this->page]);
  5788. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  5789. $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  5790. } elseif ($this->InFooter) {
  5791. $pagemark = $this->footerpos[$this->page];
  5792. $this->footerpos[$this->page] += $offsetlen;
  5793. } else {
  5794. $pagemark = $this->intmrk[$this->page];
  5795. $this->intmrk[$this->page] += $offsetlen;
  5796. }
  5797. $pagebuff = $this->getPageBuffer($this->page);
  5798. $pstart = substr($pagebuff, 0, $pagemark);
  5799. $pend = substr($pagebuff, $pagemark);
  5800. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  5801. }
  5802. }
  5803. } // end for each page
  5804. // restore page regions check
  5805. $this->check_page_regions = $check_page_regions;
  5806. // Get end-of-cell Y position
  5807. $currentY = $this->GetY();
  5808. // restore previous values
  5809. if ($this->num_columns > 1) {
  5810. $this->selectColumn();
  5811. } else {
  5812. // restore original margins
  5813. $this->lMargin = $lMargin;
  5814. $this->rMargin = $rMargin;
  5815. if ($this->page > $startpage) {
  5816. // check for margin variations between pages (i.e. booklet mode)
  5817. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  5818. $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  5819. if (($dl != 0) OR ($dr != 0)) {
  5820. $this->lMargin += $dl;
  5821. $this->rMargin += $dr;
  5822. }
  5823. }
  5824. }
  5825. if ($ln > 0) {
  5826. //Go to the beginning of the next line
  5827. $this->setY($currentY + $mc_margin['B']);
  5828. if ($ln == 2) {
  5829. $this->setX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5830. }
  5831. } else {
  5832. // go left or right by case
  5833. $this->setPage($startpage);
  5834. $this->y = $y;
  5835. $this->setX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5836. }
  5837. $this->setContentMark();
  5838. $this->cell_padding = $prev_cell_padding;
  5839. $this->cell_margin = $prev_cell_margin;
  5840. $this->clMargin = $this->lMargin;
  5841. $this->crMargin = $this->rMargin;
  5842. return $nl;
  5843. }
  5844. /**
  5845. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  5846. * @param string $txt String for calculating his height
  5847. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5848. * @param boolean $reseth if true reset the last cell height (default false).
  5849. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  5850. * @param array|null $cellpadding Internal cell padding, if empty uses default cell padding.
  5851. * @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)))
  5852. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5853. * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
  5854. * @public
  5855. * @since 4.5.011
  5856. */
  5857. public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding=null, $border=0) {
  5858. if ($txt === NULL) {
  5859. return 0;
  5860. }
  5861. if ($txt === '') {
  5862. // empty string
  5863. return 1;
  5864. }
  5865. // adjust internal padding
  5866. $prev_cell_padding = $this->cell_padding;
  5867. $prev_lasth = $this->lasth;
  5868. if (is_array($cellpadding)) {
  5869. $this->cell_padding = $cellpadding;
  5870. }
  5871. $this->adjustCellPadding($border);
  5872. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5873. if ($this->rtl) {
  5874. $w = $this->x - $this->lMargin;
  5875. } else {
  5876. $w = $this->w - $this->rMargin - $this->x;
  5877. }
  5878. }
  5879. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5880. if ($reseth) {
  5881. // reset row height
  5882. $this->resetLastH();
  5883. }
  5884. $lines = 1;
  5885. $sum = 0;
  5886. $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5887. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  5888. $length = count($chars);
  5889. $lastSeparator = -1;
  5890. for ($i = 0; $i < $length; ++$i) {
  5891. $c = $chars[$i];
  5892. $charWidth = $charsWidth[$i];
  5893. if (($c != 160)
  5894. AND (($c == 173)
  5895. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  5896. OR (($c == 45)
  5897. AND ($i > 0) AND ($i < ($length - 1))
  5898. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i - 1)], $this->isunicode))
  5899. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  5900. )
  5901. )
  5902. ) {
  5903. $lastSeparator = $i;
  5904. }
  5905. if ((($sum + $charWidth) > $wmax) OR ($c == 10)) {
  5906. ++$lines;
  5907. if ($c == 10) {
  5908. $lastSeparator = -1;
  5909. $sum = 0;
  5910. } elseif ($lastSeparator != -1) {
  5911. $i = $lastSeparator;
  5912. $lastSeparator = -1;
  5913. $sum = 0;
  5914. } else {
  5915. $sum = $charWidth;
  5916. }
  5917. } else {
  5918. $sum += $charWidth;
  5919. }
  5920. }
  5921. if ($chars[($length - 1)] == 10) {
  5922. --$lines;
  5923. }
  5924. $this->cell_padding = $prev_cell_padding;
  5925. $this->lasth = $prev_lasth;
  5926. return $lines;
  5927. }
  5928. /**
  5929. * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  5930. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  5931. * @pre
  5932. * // store current object
  5933. * $pdf->startTransaction();
  5934. * // store starting values
  5935. * $start_y = $pdf->GetY();
  5936. * $start_page = $pdf->getPage();
  5937. * // call your printing functions with your parameters
  5938. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5939. * $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);
  5940. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5941. * // get the new Y
  5942. * $end_y = $pdf->GetY();
  5943. * $end_page = $pdf->getPage();
  5944. * // calculate height
  5945. * $height = 0;
  5946. * if ($end_page == $start_page) {
  5947. * $height = $end_y - $start_y;
  5948. * } else {
  5949. * for ($page=$start_page; $page <= $end_page; ++$page) {
  5950. * $this->setPage($page);
  5951. * if ($page == $start_page) {
  5952. * // first page
  5953. * $height += $this->h - $start_y - $this->bMargin;
  5954. * } elseif ($page == $end_page) {
  5955. * // last page
  5956. * $height += $end_y - $this->tMargin;
  5957. * } else {
  5958. * $height += $this->h - $this->tMargin - $this->bMargin;
  5959. * }
  5960. * }
  5961. * }
  5962. * // restore previous object
  5963. * $pdf = $pdf->rollbackTransaction();
  5964. *
  5965. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5966. * @param string $txt String for calculating his height
  5967. * @param boolean $reseth if true reset the last cell height (default false).
  5968. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  5969. * @param array|null $cellpadding Internal cell padding, if empty uses default cell padding.
  5970. * @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)))
  5971. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5972. * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
  5973. * @public
  5974. */
  5975. public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding=null, $border=0) {
  5976. // adjust internal padding
  5977. $prev_cell_padding = $this->cell_padding;
  5978. $prev_lasth = $this->lasth;
  5979. if (is_array($cellpadding)) {
  5980. $this->cell_padding = $cellpadding;
  5981. }
  5982. $this->adjustCellPadding($border);
  5983. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  5984. $height = $this->getCellHeight(($lines * $this->FontSize), $autopadding);
  5985. $this->cell_padding = $prev_cell_padding;
  5986. $this->lasth = $prev_lasth;
  5987. return $height;
  5988. }
  5989. /**
  5990. * This method prints text from the current position.<br />
  5991. * @param float $h Line height
  5992. * @param string $txt String to print
  5993. * @param mixed $link URL or identifier returned by AddLink()
  5994. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  5995. * @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>
  5996. * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  5997. * @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.
  5998. * @param boolean $firstline if true prints only the first line and return the remaining string.
  5999. * @param boolean $firstblock if true the string is the starting of a line.
  6000. * @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.
  6001. * @param float $wadj first line width will be reduced by this amount (used in HTML mode).
  6002. * @param array|null $margin margin array of the parent container
  6003. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  6004. * @public
  6005. * @since 1.5
  6006. */
  6007. public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin=null) {
  6008. // check page for no-write regions and adapt page margins if necessary
  6009. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  6010. if (strlen($txt) == 0) {
  6011. // fix empty text
  6012. $txt = ' ';
  6013. }
  6014. if (!is_array($margin)) {
  6015. // set default margins
  6016. $margin = $this->cell_margin;
  6017. }
  6018. // remove carriage returns
  6019. $s = str_replace("\r", '', $txt);
  6020. // check if string contains arabic text
  6021. if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $s)) {
  6022. $arabic = true;
  6023. } else {
  6024. $arabic = false;
  6025. }
  6026. // check if string contains RTL text
  6027. if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $s)) {
  6028. $rtlmode = true;
  6029. } else {
  6030. $rtlmode = false;
  6031. }
  6032. // get a char width
  6033. $chrwidth = $this->GetCharWidth(46); // dot character
  6034. // get array of unicode values
  6035. $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont);
  6036. // calculate maximum width for a single character on string
  6037. $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
  6038. array_walk($chrw, array($this, 'getRawCharWidth'));
  6039. $maxchwidth = ((is_array($chrw) || $chrw instanceof Countable) && count($chrw) > 0) ? max($chrw) : 0;
  6040. // get array of chars
  6041. $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode);
  6042. // get the number of characters
  6043. $nb = count($chars);
  6044. // replacement for SHY character (minus symbol)
  6045. $shy_replacement = 45;
  6046. $shy_replacement_char = TCPDF_FONTS::unichr($shy_replacement, $this->isunicode);
  6047. // widht for SHY replacement
  6048. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  6049. // page width
  6050. $pw = $w = $this->w - $this->lMargin - $this->rMargin;
  6051. // calculate remaining line width ($w)
  6052. if ($this->rtl) {
  6053. $w = $this->x - $this->lMargin;
  6054. } else {
  6055. $w = $this->w - $this->rMargin - $this->x;
  6056. }
  6057. // max column width
  6058. $wmax = ($w - $wadj);
  6059. if (!$firstline) {
  6060. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  6061. }
  6062. if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
  6063. // the maximum width character do not fit on column
  6064. return '';
  6065. }
  6066. // minimum row height
  6067. $row_height = max($h, $this->getCellHeight($this->FontSize));
  6068. // max Y
  6069. $maxy = $this->y + $maxh - max($row_height, $h);
  6070. $start_page = $this->page;
  6071. $i = 0; // character position
  6072. $j = 0; // current starting position
  6073. $sep = -1; // position of the last blank space
  6074. $prevsep = $sep; // previous separator
  6075. $shy = false; // true if the last blank is a soft hypen (SHY)
  6076. $prevshy = $shy; // previous shy mode
  6077. $l = 0; // current string length
  6078. $nl = 0; //number of lines
  6079. $linebreak = false;
  6080. $pc = 0; // previous character
  6081. // for each character
  6082. while ($i < $nb) {
  6083. if (($maxh > 0) AND ($this->y > $maxy) ) {
  6084. break;
  6085. }
  6086. //Get the current character
  6087. $c = $chars[$i];
  6088. if ($c == 10) { // 10 = "\n" = new line
  6089. //Explicit line break
  6090. if ($align == 'J') {
  6091. if ($this->rtl) {
  6092. $talign = 'R';
  6093. } else {
  6094. $talign = 'L';
  6095. }
  6096. } else {
  6097. $talign = $align;
  6098. }
  6099. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6100. if ($firstline) {
  6101. $startx = $this->x;
  6102. $tmparr = array_slice($chars, $j, ($i - $j));
  6103. if ($rtlmode) {
  6104. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6105. }
  6106. $linew = $this->GetArrStringWidth($tmparr);
  6107. unset($tmparr);
  6108. if ($this->rtl) {
  6109. $this->endlinex = $startx - $linew;
  6110. } else {
  6111. $this->endlinex = $startx + $linew;
  6112. }
  6113. $w = $linew;
  6114. $tmpcellpadding = $this->cell_padding;
  6115. if ($maxh == 0) {
  6116. $this->setCellPadding(0);
  6117. }
  6118. }
  6119. if ($firstblock AND $this->isRTLTextDir()) {
  6120. $tmpstr = $this->stringRightTrim($tmpstr);
  6121. }
  6122. // Skip newlines at the beginning of a page or column
  6123. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  6124. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  6125. }
  6126. unset($tmpstr);
  6127. if ($firstline) {
  6128. $this->cell_padding = $tmpcellpadding;
  6129. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6130. }
  6131. ++$nl;
  6132. $j = $i + 1;
  6133. $l = 0;
  6134. $sep = -1;
  6135. $prevsep = $sep;
  6136. $shy = false;
  6137. // account for margin changes
  6138. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6139. if ($this->AcceptPageBreak())
  6140. {
  6141. if ($this->rtl) {
  6142. $this->x -= $margin['R'];
  6143. } else {
  6144. $this->x += $margin['L'];
  6145. }
  6146. $this->lMargin += $margin['L'];
  6147. $this->rMargin += $margin['R'];
  6148. }
  6149. }
  6150. $w = $this->getRemainingWidth();
  6151. $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
  6152. } else {
  6153. // 160 is the non-breaking space.
  6154. // 173 is SHY (Soft Hypen).
  6155. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6156. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6157. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6158. if (($c != 160)
  6159. AND (($c == 173)
  6160. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  6161. OR (($c == 45)
  6162. AND ($i < ($nb - 1))
  6163. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc, $this->isunicode))
  6164. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  6165. )
  6166. )
  6167. ) {
  6168. // update last blank space position
  6169. $prevsep = $sep;
  6170. $sep = $i;
  6171. // check if is a SHY
  6172. if (($c == 173) OR ($c == 45)) {
  6173. $prevshy = $shy;
  6174. $shy = true;
  6175. if ($pc == 45) {
  6176. $tmp_shy_replacement_width = 0;
  6177. $tmp_shy_replacement_char = '';
  6178. } else {
  6179. $tmp_shy_replacement_width = $shy_replacement_width;
  6180. $tmp_shy_replacement_char = $shy_replacement_char;
  6181. }
  6182. } else {
  6183. $shy = false;
  6184. }
  6185. }
  6186. // update string length
  6187. if ($this->isUnicodeFont() AND ($arabic)) {
  6188. // with bidirectional algorithm some chars may be changed affecting the line length
  6189. // *** very slow ***
  6190. $l = $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl, $this->isunicode, $this->CurrentFont));
  6191. } else {
  6192. $l += $this->GetCharWidth($c, ($i+1 < $nb));
  6193. }
  6194. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) >= $wmax))) {
  6195. if (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) {
  6196. $sep = $prevsep;
  6197. $shy = $prevshy;
  6198. }
  6199. // we have reached the end of column
  6200. if ($sep == -1) {
  6201. // check if the line was already started
  6202. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  6203. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  6204. // print a void cell and go to next line
  6205. $this->Cell($w, $h, '', 0, 1);
  6206. $linebreak = true;
  6207. if ($firstline) {
  6208. return (TCPDF_FONTS::UniArrSubString($uchars, $j));
  6209. }
  6210. } else {
  6211. // truncate the word because do not fit on column
  6212. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6213. if ($firstline) {
  6214. $startx = $this->x;
  6215. $tmparr = array_slice($chars, $j, ($i - $j));
  6216. if ($rtlmode) {
  6217. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6218. }
  6219. $linew = $this->GetArrStringWidth($tmparr);
  6220. unset($tmparr);
  6221. if ($this->rtl) {
  6222. $this->endlinex = $startx - $linew;
  6223. } else {
  6224. $this->endlinex = $startx + $linew;
  6225. }
  6226. $w = $linew;
  6227. $tmpcellpadding = $this->cell_padding;
  6228. if ($maxh == 0) {
  6229. $this->setCellPadding(0);
  6230. }
  6231. }
  6232. if ($firstblock AND $this->isRTLTextDir()) {
  6233. $tmpstr = $this->stringRightTrim($tmpstr);
  6234. }
  6235. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6236. unset($tmpstr);
  6237. if ($firstline) {
  6238. $this->cell_padding = $tmpcellpadding;
  6239. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6240. }
  6241. $j = $i;
  6242. --$i;
  6243. }
  6244. } else {
  6245. // word wrapping
  6246. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  6247. $endspace = 1;
  6248. } else {
  6249. $endspace = 0;
  6250. }
  6251. // check the length of the next string
  6252. $strrest = TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace));
  6253. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $this->stringTrim($strrest));
  6254. if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  6255. // truncate the word because do not fit on a full page width
  6256. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6257. if ($firstline) {
  6258. $startx = $this->x;
  6259. $tmparr = array_slice($chars, $j, ($i - $j));
  6260. if ($rtlmode) {
  6261. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6262. }
  6263. $linew = $this->GetArrStringWidth($tmparr);
  6264. unset($tmparr);
  6265. if ($this->rtl) {
  6266. $this->endlinex = ($startx - $linew);
  6267. } else {
  6268. $this->endlinex = ($startx + $linew);
  6269. }
  6270. $w = $linew;
  6271. $tmpcellpadding = $this->cell_padding;
  6272. if ($maxh == 0) {
  6273. $this->setCellPadding(0);
  6274. }
  6275. }
  6276. if ($firstblock AND $this->isRTLTextDir()) {
  6277. $tmpstr = $this->stringRightTrim($tmpstr);
  6278. }
  6279. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6280. unset($tmpstr);
  6281. if ($firstline) {
  6282. $this->cell_padding = $tmpcellpadding;
  6283. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6284. }
  6285. $j = $i;
  6286. --$i;
  6287. } else {
  6288. // word wrapping
  6289. if ($shy) {
  6290. // add hypen (minus symbol) at the end of the line
  6291. $shy_width = $tmp_shy_replacement_width;
  6292. if ($this->rtl) {
  6293. $shy_char_left = $tmp_shy_replacement_char;
  6294. $shy_char_right = '';
  6295. } else {
  6296. $shy_char_left = '';
  6297. $shy_char_right = $tmp_shy_replacement_char;
  6298. }
  6299. } else {
  6300. $shy_width = 0;
  6301. $shy_char_left = '';
  6302. $shy_char_right = '';
  6303. }
  6304. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, ($sep + $endspace));
  6305. if ($firstline) {
  6306. $startx = $this->x;
  6307. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  6308. if ($rtlmode) {
  6309. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6310. }
  6311. $linew = $this->GetArrStringWidth($tmparr);
  6312. unset($tmparr);
  6313. if ($this->rtl) {
  6314. $this->endlinex = $startx - $linew - $shy_width;
  6315. } else {
  6316. $this->endlinex = $startx + $linew + $shy_width;
  6317. }
  6318. $w = $linew;
  6319. $tmpcellpadding = $this->cell_padding;
  6320. if ($maxh == 0) {
  6321. $this->setCellPadding(0);
  6322. }
  6323. }
  6324. // print the line
  6325. if ($firstblock AND $this->isRTLTextDir()) {
  6326. $tmpstr = $this->stringRightTrim($tmpstr);
  6327. }
  6328. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  6329. unset($tmpstr);
  6330. if ($firstline) {
  6331. if ($chars[$sep] == 45) {
  6332. $endspace += 1;
  6333. }
  6334. // return the remaining text
  6335. $this->cell_padding = $tmpcellpadding;
  6336. return (TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace)));
  6337. }
  6338. $i = $sep;
  6339. $sep = -1;
  6340. $shy = false;
  6341. $j = ($i + 1);
  6342. }
  6343. }
  6344. // account for margin changes
  6345. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6346. if ($this->AcceptPageBreak())
  6347. {
  6348. if ($this->rtl) {
  6349. $this->x -= $margin['R'];
  6350. } else {
  6351. $this->x += $margin['L'];
  6352. }
  6353. $this->lMargin += $margin['L'];
  6354. $this->rMargin += $margin['R'];
  6355. }
  6356. }
  6357. $w = $this->getRemainingWidth();
  6358. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6359. if ($linebreak) {
  6360. $linebreak = false;
  6361. } else {
  6362. ++$nl;
  6363. $l = 0;
  6364. }
  6365. }
  6366. }
  6367. // save last character
  6368. $pc = $c;
  6369. ++$i;
  6370. } // end while i < nb
  6371. // print last substring (if any)
  6372. if ($l > 0) {
  6373. switch ($align) {
  6374. case 'J':
  6375. case 'C': {
  6376. break;
  6377. }
  6378. case 'L': {
  6379. if (!$this->rtl) {
  6380. $w = $l;
  6381. }
  6382. break;
  6383. }
  6384. case 'R': {
  6385. if ($this->rtl) {
  6386. $w = $l;
  6387. }
  6388. break;
  6389. }
  6390. default: {
  6391. $w = $l;
  6392. break;
  6393. }
  6394. }
  6395. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $nb);
  6396. if ($firstline) {
  6397. $startx = $this->x;
  6398. $tmparr = array_slice($chars, $j, ($nb - $j));
  6399. if ($rtlmode) {
  6400. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6401. }
  6402. $linew = $this->GetArrStringWidth($tmparr);
  6403. unset($tmparr);
  6404. if ($this->rtl) {
  6405. $this->endlinex = $startx - $linew;
  6406. } else {
  6407. $this->endlinex = $startx + $linew;
  6408. }
  6409. $w = $linew;
  6410. $tmpcellpadding = $this->cell_padding;
  6411. if ($maxh == 0) {
  6412. $this->setCellPadding(0);
  6413. }
  6414. }
  6415. if ($firstblock AND $this->isRTLTextDir()) {
  6416. $tmpstr = $this->stringRightTrim($tmpstr);
  6417. }
  6418. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  6419. unset($tmpstr);
  6420. if ($firstline) {
  6421. $this->cell_padding = $tmpcellpadding;
  6422. return (TCPDF_FONTS::UniArrSubString($uchars, $nb));
  6423. }
  6424. ++$nl;
  6425. }
  6426. if ($firstline) {
  6427. return '';
  6428. }
  6429. return $nl;
  6430. }
  6431. /**
  6432. * Returns the remaining width between the current position and margins.
  6433. * @return float Return the remaining width
  6434. * @protected
  6435. */
  6436. protected function getRemainingWidth() {
  6437. list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
  6438. if ($this->rtl) {
  6439. return ($this->x - $this->lMargin);
  6440. } else {
  6441. return ($this->w - $this->rMargin - $this->x);
  6442. }
  6443. }
  6444. /**
  6445. * Set the block dimensions accounting for page breaks and page/column fitting
  6446. * @param float $w width
  6447. * @param float $h height
  6448. * @param float $x X coordinate
  6449. * @param float $y Y coodiante
  6450. * @param boolean $fitonpage if true the block is resized to not exceed page dimensions.
  6451. * @return array array($w, $h, $x, $y)
  6452. * @protected
  6453. * @since 5.5.009 (2010-07-05)
  6454. */
  6455. protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
  6456. if ($w <= 0) {
  6457. // set maximum width
  6458. $w = ($this->w - $this->lMargin - $this->rMargin);
  6459. if ($w <= 0) {
  6460. $w = 1;
  6461. }
  6462. }
  6463. if ($h <= 0) {
  6464. // set maximum height
  6465. $h = ($this->PageBreakTrigger - $this->tMargin);
  6466. if ($h <= 0) {
  6467. $h = 1;
  6468. }
  6469. }
  6470. // resize the block to be vertically contained on a single page or single column
  6471. if ($fitonpage OR $this->AutoPageBreak) {
  6472. $ratio_wh = ($w / $h);
  6473. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  6474. $h = $this->PageBreakTrigger - $this->tMargin;
  6475. $w = ($h * $ratio_wh);
  6476. }
  6477. // resize the block to be horizontally contained on a single page or single column
  6478. if ($fitonpage) {
  6479. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  6480. if ($w > $maxw) {
  6481. $w = $maxw;
  6482. $h = ($w / $ratio_wh);
  6483. }
  6484. }
  6485. }
  6486. // Check whether we need a new page or new column first as this does not fit
  6487. $prev_x = $this->x;
  6488. $prev_y = $this->y;
  6489. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  6490. $y = $this->y;
  6491. if ($this->rtl) {
  6492. $x += ($prev_x - $this->x);
  6493. } else {
  6494. $x += ($this->x - $prev_x);
  6495. }
  6496. $this->newline = true;
  6497. }
  6498. // resize the block to be contained on the remaining available page or column space
  6499. if ($fitonpage) {
  6500. // fallback to avoid division by zero
  6501. $h = $h == 0 ? 1 : $h;
  6502. $ratio_wh = ($w / $h);
  6503. if (($y + $h) > $this->PageBreakTrigger) {
  6504. $h = $this->PageBreakTrigger - $y;
  6505. $w = ($h * $ratio_wh);
  6506. }
  6507. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  6508. $w = $this->w - $this->rMargin - $x;
  6509. $h = ($w / $ratio_wh);
  6510. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  6511. $w = $x - $this->lMargin;
  6512. $h = ($w / $ratio_wh);
  6513. }
  6514. }
  6515. return array($w, $h, $x, $y);
  6516. }
  6517. /**
  6518. * Puts an image in the page.
  6519. * The upper-left corner must be given.
  6520. * The dimensions can be specified in different ways:<ul>
  6521. * <li>explicit width and height (expressed in user unit)</li>
  6522. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6523. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6524. * 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;
  6525. * The format can be specified explicitly or inferred from the file extension.<br />
  6526. * It is possible to put a link on the image.<br />
  6527. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6528. * @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').
  6529. * @param float|null $x Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6530. * @param float|null $y Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6531. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6532. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6533. * @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.
  6534. * @param mixed $link URL or identifier returned by AddLink().
  6535. * @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>
  6536. * @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).
  6537. * @param int $dpi dot-per-inch resolution used on resize
  6538. * @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>
  6539. * @param boolean $ismask true if this image is a mask, false otherwise
  6540. * @param mixed $imgmask image object returned by this function or false
  6541. * @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)))
  6542. * @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).
  6543. * @param boolean $hidden If true do not display the image.
  6544. * @param boolean $fitonpage If true the image is resized to not exceed page dimensions.
  6545. * @param boolean $alt If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  6546. * @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.
  6547. * @return mixed|false image information
  6548. * @public
  6549. * @since 1.1
  6550. */
  6551. 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()) {
  6552. if ($this->state != 2) {
  6553. return false;
  6554. }
  6555. if (TCPDF_STATIC::empty_string($x)) {
  6556. $x = $this->x;
  6557. }
  6558. if (TCPDF_STATIC::empty_string($y)) {
  6559. $y = $this->y;
  6560. }
  6561. // check page for no-write regions and adapt page margins if necessary
  6562. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  6563. $exurl = ''; // external streams
  6564. $imsize = FALSE;
  6565. // Make sure the file variable is not empty or null because accessing $file[0] later
  6566. // results in error when running PHP 7.4
  6567. if (empty($file)) {
  6568. return false;
  6569. }
  6570. // check if we are passing an image as file or string
  6571. if ($file[0] === '@') {
  6572. // image from string
  6573. $imgdata = substr($file, 1);
  6574. } else { // image file
  6575. if ($file[0] === '*') {
  6576. // image as external stream
  6577. $file = substr($file, 1);
  6578. $exurl = $file;
  6579. }
  6580. // check if file exist and it is valid
  6581. if (!@$this->fileExists($file)) {
  6582. return false;
  6583. }
  6584. if (false !== $info = $this->getImageBuffer($file)) {
  6585. $imsize = array($info['w'], $info['h']);
  6586. } elseif (($imsize = @getimagesize($file)) === FALSE && strpos($file, '__tcpdf_'.$this->file_id.'_img') === FALSE){
  6587. $imgdata = $this->getCachedFileContents($file);
  6588. }
  6589. }
  6590. if (!empty($imgdata)) {
  6591. // copy image to cache
  6592. $original_file = $file;
  6593. $file = TCPDF_STATIC::getObjFilename('img', $this->file_id);
  6594. $fp = TCPDF_STATIC::fopenLocal($file, 'w');
  6595. if (!$fp) {
  6596. $this->Error('Unable to write file: '.$file);
  6597. }
  6598. fwrite($fp, $imgdata);
  6599. fclose($fp);
  6600. unset($imgdata);
  6601. $imsize = @getimagesize($file);
  6602. if ($imsize === FALSE) {
  6603. unlink($file);
  6604. $file = $original_file;
  6605. }
  6606. }
  6607. if ($imsize === FALSE) {
  6608. if (($w > 0) AND ($h > 0)) {
  6609. // get measures from specified data
  6610. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6611. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6612. $imsize = array($pw, $ph);
  6613. } else {
  6614. $this->Error('[Image] Unable to get the size of the image: '.$file);
  6615. }
  6616. }
  6617. // file hash
  6618. $filehash = md5($file);
  6619. // get original image width and height in pixels
  6620. list($pixw, $pixh) = $imsize;
  6621. // calculate image width and height on document
  6622. if (($w <= 0) AND ($h <= 0)) {
  6623. // convert image size to document unit
  6624. $w = $this->pixelsToUnits($pixw);
  6625. $h = $this->pixelsToUnits($pixh);
  6626. } elseif ($w <= 0) {
  6627. $w = $h * $pixw / $pixh;
  6628. } elseif ($h <= 0) {
  6629. $h = $w * $pixh / $pixw;
  6630. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  6631. if (strlen($fitbox) !== 2) {
  6632. // set default alignment
  6633. $fitbox = '--';
  6634. }
  6635. // scale image dimensions proportionally to fit within the ($w, $h) box
  6636. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  6637. // store current height
  6638. $oldh = $h;
  6639. // calculate new height
  6640. $h = $w * $pixh / $pixw;
  6641. // height difference
  6642. $hdiff = ($oldh - $h);
  6643. // vertical alignment
  6644. switch (strtoupper($fitbox[1])) {
  6645. case 'T': {
  6646. break;
  6647. }
  6648. case 'M': {
  6649. $y += ($hdiff / 2);
  6650. break;
  6651. }
  6652. case 'B': {
  6653. $y += $hdiff;
  6654. break;
  6655. }
  6656. }
  6657. } else {
  6658. // store current width
  6659. $oldw = $w;
  6660. // calculate new width
  6661. $w = $h * $pixw / $pixh;
  6662. // width difference
  6663. $wdiff = ($oldw - $w);
  6664. // horizontal alignment
  6665. switch (strtoupper($fitbox[0])) {
  6666. case 'L': {
  6667. if ($this->rtl) {
  6668. $x -= $wdiff;
  6669. }
  6670. break;
  6671. }
  6672. case 'C': {
  6673. if ($this->rtl) {
  6674. $x -= ($wdiff / 2);
  6675. } else {
  6676. $x += ($wdiff / 2);
  6677. }
  6678. break;
  6679. }
  6680. case 'R': {
  6681. if (!$this->rtl) {
  6682. $x += $wdiff;
  6683. }
  6684. break;
  6685. }
  6686. }
  6687. }
  6688. }
  6689. // fit the image on available space
  6690. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  6691. // calculate new minimum dimensions in pixels
  6692. $neww = round($w * $this->k * $dpi / $this->dpi);
  6693. $newh = round($h * $this->k * $dpi / $this->dpi);
  6694. // check if resize is necessary (resize is used only to reduce the image)
  6695. $newsize = ($neww * $newh);
  6696. $pixsize = ($pixw * $pixh);
  6697. if (intval($resize) == 2) {
  6698. $resize = true;
  6699. } elseif ($newsize >= $pixsize) {
  6700. $resize = false;
  6701. }
  6702. // check if image has been already added on document
  6703. $newimage = true;
  6704. if (in_array($file, $this->imagekeys)) {
  6705. $newimage = false;
  6706. // get existing image data
  6707. $info = $this->getImageBuffer($file);
  6708. if (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE) {
  6709. // check if the newer image is larger
  6710. $oldsize = ($info['w'] * $info['h']);
  6711. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6712. $newimage = true;
  6713. }
  6714. }
  6715. } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)) {
  6716. // create temp image file (without alpha channel)
  6717. $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6718. // create temp alpha file
  6719. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6720. // check for cached images
  6721. if (in_array($tempfile_plain, $this->imagekeys)) {
  6722. // get existing image data
  6723. $info = $this->getImageBuffer($tempfile_plain);
  6724. // check if the newer image is larger
  6725. $oldsize = ($info['w'] * $info['h']);
  6726. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6727. $newimage = true;
  6728. } else {
  6729. $newimage = false;
  6730. // embed mask image
  6731. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6732. // embed image, masked with previously embedded mask
  6733. return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6734. }
  6735. }
  6736. }
  6737. if ($newimage) {
  6738. //First use of image, get info
  6739. $type = strtolower($type);
  6740. if ($type == '') {
  6741. $type = TCPDF_IMAGES::getImageFileType($file, $imsize);
  6742. } elseif ($type == 'jpg') {
  6743. $type = 'jpeg';
  6744. }
  6745. // Specific image handlers (defined on TCPDF_IMAGES CLASS)
  6746. $mtd = '_parse'.$type;
  6747. // GD image handler function
  6748. $gdfunction = 'imagecreatefrom'.$type;
  6749. $info = false;
  6750. if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  6751. // TCPDF image functions
  6752. $info = TCPDF_IMAGES::$mtd($file);
  6753. if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)
  6754. AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
  6755. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
  6756. }
  6757. }
  6758. if (($info === false) AND function_exists($gdfunction)) {
  6759. try {
  6760. // GD library
  6761. $img = $gdfunction($file);
  6762. if ($img !== false) {
  6763. if ($resize) {
  6764. $imgr = imagecreatetruecolor($neww, $newh);
  6765. if (($type == 'gif') OR ($type == 'png')) {
  6766. $imgr = TCPDF_IMAGES::setGDImageTransparency($imgr, $img);
  6767. }
  6768. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  6769. $img = $imgr;
  6770. }
  6771. if (($type == 'gif') OR ($type == 'png')) {
  6772. $info = TCPDF_IMAGES::_toPNG($img, TCPDF_STATIC::getObjFilename('img', $this->file_id));
  6773. } else {
  6774. $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality, TCPDF_STATIC::getObjFilename('img', $this->file_id));
  6775. }
  6776. }
  6777. } catch(Exception $e) {
  6778. $info = false;
  6779. }
  6780. }
  6781. if (($info === false) AND extension_loaded('imagick')) {
  6782. try {
  6783. // ImageMagick library
  6784. $img = new Imagick();
  6785. if ($type == 'svg') {
  6786. if ($file[0] === '@') {
  6787. // image from string
  6788. $svgimg = substr($file, 1);
  6789. } else {
  6790. // get SVG file content
  6791. $svgimg = $this->getCachedFileContents($file);
  6792. }
  6793. if ($svgimg !== FALSE) {
  6794. // get width and height
  6795. $regs = array();
  6796. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  6797. $svgtag = $regs[1];
  6798. $tmp = array();
  6799. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6800. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6801. $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit;
  6802. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  6803. } else {
  6804. $ow = $w;
  6805. }
  6806. $tmp = array();
  6807. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6808. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6809. $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit;
  6810. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  6811. } else {
  6812. $oh = $h;
  6813. }
  6814. $tmp = array();
  6815. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  6816. $vbw = ($ow * $this->imgscale * $this->k);
  6817. $vbh = ($oh * $this->imgscale * $this->k);
  6818. $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
  6819. $svgtag = $vbox.$svgtag;
  6820. }
  6821. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  6822. }
  6823. $img->readImageBlob($svgimg);
  6824. }
  6825. } else {
  6826. $img->readImage($file);
  6827. }
  6828. if ($resize) {
  6829. $img->resizeImage($neww, $newh, 10, 1, false);
  6830. }
  6831. $img->setCompressionQuality($this->jpeg_quality);
  6832. $img->setImageFormat('jpeg');
  6833. $tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id);
  6834. $img->writeImage($tempname);
  6835. $info = TCPDF_IMAGES::_parsejpeg($tempname);
  6836. unlink($tempname);
  6837. $img->destroy();
  6838. } catch(Exception $e) {
  6839. $info = false;
  6840. }
  6841. }
  6842. if ($info === false) {
  6843. // unable to process image
  6844. return false;
  6845. }
  6846. if ($ismask) {
  6847. // force grayscale
  6848. $info['cs'] = 'DeviceGray';
  6849. }
  6850. if ($imgmask !== false) {
  6851. $info['masked'] = $imgmask;
  6852. }
  6853. if (!empty($exurl)) {
  6854. $info['exurl'] = $exurl;
  6855. }
  6856. // array of alternative images
  6857. $info['altimgs'] = $altimgs;
  6858. // add image to document
  6859. $info['i'] = $this->setImageBuffer($file, $info);
  6860. }
  6861. // set alignment
  6862. $this->img_rb_x = $x + $w;
  6863. $this->img_rb_y = $y + $h;
  6864. // set alignment
  6865. if ($palign == 'L') {
  6866. $ximg = $this->lMargin;
  6867. } elseif ($palign == 'C') {
  6868. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6869. } elseif ($palign == 'R') {
  6870. $ximg = $this->w - $this->rMargin - $w;
  6871. } else {
  6872. $ximg = $this->rtl ? $x - $w : $x;
  6873. }
  6874. if ($ismask OR $hidden) {
  6875. // image is not displayed
  6876. return $info['i'];
  6877. }
  6878. $xkimg = $ximg * $this->k;
  6879. if (!$alt) {
  6880. // only non-alternative immages will be set
  6881. $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']));
  6882. }
  6883. if (!empty($border)) {
  6884. $bx = $this->x;
  6885. $by = $this->y;
  6886. $this->x = $ximg;
  6887. if ($this->rtl) {
  6888. $this->x += $w;
  6889. }
  6890. $this->y = $y;
  6891. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  6892. $this->x = $bx;
  6893. $this->y = $by;
  6894. }
  6895. if ($link) {
  6896. $this->Link($ximg, $y, $w, $h, $link, 0);
  6897. }
  6898. // set pointer to align the next text/objects
  6899. switch($align) {
  6900. case 'T': {
  6901. $this->y = $y;
  6902. $this->x = $this->img_rb_x;
  6903. break;
  6904. }
  6905. case 'M': {
  6906. $this->y = $y + round($h/2);
  6907. $this->x = $this->img_rb_x;
  6908. break;
  6909. }
  6910. case 'B': {
  6911. $this->y = $this->img_rb_y;
  6912. $this->x = $this->img_rb_x;
  6913. break;
  6914. }
  6915. case 'N': {
  6916. $this->setY($this->img_rb_y);
  6917. break;
  6918. }
  6919. default:{
  6920. break;
  6921. }
  6922. }
  6923. $this->endlinex = $this->img_rb_x;
  6924. if ($this->inxobj) {
  6925. // we are inside an XObject template
  6926. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  6927. }
  6928. return $info['i'];
  6929. }
  6930. /**
  6931. * Extract info from a PNG image with alpha channel using the Imagick or GD library.
  6932. * @param string $file Name of the file containing the image.
  6933. * @param float $x Abscissa of the upper-left corner.
  6934. * @param float $y Ordinate of the upper-left corner.
  6935. * @param float $wpx Original width of the image in pixels.
  6936. * @param float $hpx original height of the image in pixels.
  6937. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6938. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6939. * @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.
  6940. * @param mixed $link URL or identifier returned by AddLink().
  6941. * @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>
  6942. * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  6943. * @param int $dpi dot-per-inch resolution used on resize
  6944. * @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>
  6945. * @param string $filehash File hash used to build unique file names.
  6946. * @author Nicola Asuni
  6947. * @protected
  6948. * @since 4.3.007 (2008-12-04)
  6949. * @see Image()
  6950. */
  6951. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
  6952. // create temp images
  6953. if (empty($filehash)) {
  6954. $filehash = md5($file);
  6955. }
  6956. // create temp image file (without alpha channel)
  6957. $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6958. // create temp alpha file
  6959. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6960. $parsed = false;
  6961. $parse_error = '';
  6962. // ImageMagick extension
  6963. if (($parsed === false) AND extension_loaded('imagick')) {
  6964. try {
  6965. // ImageMagick library
  6966. $img = new Imagick();
  6967. $img->readImage($file);
  6968. // clone image object
  6969. $imga = TCPDF_STATIC::objclone($img);
  6970. // extract alpha channel
  6971. if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
  6972. $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
  6973. } else {
  6974. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  6975. $img->negateImage(true);
  6976. }
  6977. $img->setImageFormat('png');
  6978. $img->writeImage($tempfile_alpha);
  6979. // remove alpha channel
  6980. if (method_exists($imga, 'setImageMatte')) {
  6981. $imga->setImageMatte(false);
  6982. } else {
  6983. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  6984. }
  6985. $imga->setImageFormat('png');
  6986. $imga->writeImage($tempfile_plain);
  6987. $parsed = true;
  6988. } catch (Exception $e) {
  6989. // Imagemagick fails, try with GD
  6990. $parse_error = 'Imagick library error: '.$e->getMessage();
  6991. }
  6992. }
  6993. // GD extension
  6994. if (($parsed === false) AND function_exists('imagecreatefrompng')) {
  6995. try {
  6996. // generate images
  6997. $img = imagecreatefrompng($file);
  6998. $imgalpha = imagecreate($wpx, $hpx);
  6999. // generate gray scale palette (0 -> 255)
  7000. for ($c = 0; $c < 256; ++$c) {
  7001. ImageColorAllocate($imgalpha, $c, $c, $c);
  7002. }
  7003. // extract alpha channel
  7004. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  7005. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  7006. $color = imagecolorat($img, $xpx, $ypx);
  7007. // get and correct gamma color
  7008. $alpha = $this->getGDgamma($img, $color);
  7009. imagesetpixel($imgalpha, (int) $xpx, (int) $ypx, (int) $alpha);
  7010. }
  7011. }
  7012. imagepng($imgalpha, $tempfile_alpha);
  7013. imagedestroy($imgalpha);
  7014. // extract image without alpha channel
  7015. $imgplain = imagecreatetruecolor($wpx, $hpx);
  7016. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  7017. imagepng($imgplain, $tempfile_plain);
  7018. imagedestroy($imgplain);
  7019. $parsed = true;
  7020. } catch (Exception $e) {
  7021. // GD fails
  7022. $parse_error = 'GD library error: '.$e->getMessage();
  7023. }
  7024. }
  7025. if ($parsed === false) {
  7026. if (empty($parse_error)) {
  7027. $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  7028. } else {
  7029. $this->Error($parse_error);
  7030. }
  7031. }
  7032. // embed mask image
  7033. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  7034. // embed image, masked with previously embedded mask
  7035. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  7036. }
  7037. /**
  7038. * Get the GD-corrected PNG gamma value from alpha color
  7039. * @param resource $img GD image Resource ID.
  7040. * @param int $c alpha color
  7041. * @protected
  7042. * @since 4.3.007 (2008-12-04)
  7043. */
  7044. protected function getGDgamma($img, $c) {
  7045. if (!isset($this->gdgammacache['#'.$c])) {
  7046. $colors = imagecolorsforindex($img, $c);
  7047. // GD alpha is only 7 bit (0 -> 127)
  7048. $this->gdgammacache['#'.$c] = (int) (((127 - $colors['alpha']) / 127) * 255);
  7049. // correct gamma
  7050. $this->gdgammacache['#'.$c] = (int) (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255);
  7051. // store the latest values on cache to improve performances
  7052. if (count($this->gdgammacache) > 8) {
  7053. // remove one element from the cache array
  7054. array_shift($this->gdgammacache);
  7055. }
  7056. }
  7057. return $this->gdgammacache['#'.$c];
  7058. }
  7059. /**
  7060. * Performs a line break.
  7061. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  7062. * @param float|null $h The height of the break. By default, the value equals the height of the last printed cell.
  7063. * @param boolean $cell if true add the current left (or right o for RTL) padding to the X coordinate
  7064. * @public
  7065. * @since 1.0
  7066. * @see Cell()
  7067. */
  7068. public function Ln($h=null, $cell=false) {
  7069. 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'])) {
  7070. // revove vertical space from the top of the column
  7071. return;
  7072. }
  7073. if ($cell) {
  7074. if ($this->rtl) {
  7075. $cellpadding = $this->cell_padding['R'];
  7076. } else {
  7077. $cellpadding = $this->cell_padding['L'];
  7078. }
  7079. } else {
  7080. $cellpadding = 0;
  7081. }
  7082. if ($this->rtl) {
  7083. $this->x = $this->w - $this->rMargin - $cellpadding;
  7084. } else {
  7085. $this->x = $this->lMargin + $cellpadding;
  7086. }
  7087. if (TCPDF_STATIC::empty_string($h)) {
  7088. $h = $this->lasth;
  7089. }
  7090. $this->y += $h;
  7091. $this->newline = true;
  7092. }
  7093. /**
  7094. * Returns the relative X value of current position.
  7095. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  7096. * @return float
  7097. * @public
  7098. * @since 1.2
  7099. * @see SetX(), GetY(), SetY()
  7100. */
  7101. public function GetX() {
  7102. //Get x position
  7103. if ($this->rtl) {
  7104. return ($this->w - $this->x);
  7105. } else {
  7106. return $this->x;
  7107. }
  7108. }
  7109. /**
  7110. * Returns the absolute X value of current position.
  7111. * @return float
  7112. * @public
  7113. * @since 1.2
  7114. * @see SetX(), GetY(), SetY()
  7115. */
  7116. public function GetAbsX() {
  7117. return $this->x;
  7118. }
  7119. /**
  7120. * Returns the ordinate of the current position.
  7121. * @return float
  7122. * @public
  7123. * @since 1.0
  7124. * @see SetY(), GetX(), SetX()
  7125. */
  7126. public function GetY() {
  7127. return $this->y;
  7128. }
  7129. /**
  7130. * Defines the abscissa of the current position.
  7131. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  7132. * @param float $x The value of the abscissa in user units.
  7133. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7134. * @public
  7135. * @since 1.2
  7136. * @see GetX(), GetY(), SetY(), SetXY()
  7137. */
  7138. public function setX($x, $rtloff=false) {
  7139. $x = floatval($x);
  7140. if (!$rtloff AND $this->rtl) {
  7141. if ($x >= 0) {
  7142. $this->x = $this->w - $x;
  7143. } else {
  7144. $this->x = abs($x);
  7145. }
  7146. } else {
  7147. if ($x >= 0) {
  7148. $this->x = $x;
  7149. } else {
  7150. $this->x = $this->w + $x;
  7151. }
  7152. }
  7153. if ($this->x < 0) {
  7154. $this->x = 0;
  7155. }
  7156. if ($this->x > $this->w) {
  7157. $this->x = $this->w;
  7158. }
  7159. }
  7160. /**
  7161. * Moves the current abscissa back to the left margin and sets the ordinate.
  7162. * If the passed value is negative, it is relative to the bottom of the page.
  7163. * @param float $y The value of the ordinate in user units.
  7164. * @param bool $resetx if true (default) reset the X position.
  7165. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7166. * @public
  7167. * @since 1.0
  7168. * @see GetX(), GetY(), SetY(), SetXY()
  7169. */
  7170. public function setY($y, $resetx=true, $rtloff=false) {
  7171. $y = floatval($y);
  7172. if ($resetx) {
  7173. //reset x
  7174. if (!$rtloff AND $this->rtl) {
  7175. $this->x = $this->w - $this->rMargin;
  7176. } else {
  7177. $this->x = $this->lMargin;
  7178. }
  7179. }
  7180. if ($y >= 0) {
  7181. $this->y = $y;
  7182. } else {
  7183. $this->y = $this->h + $y;
  7184. }
  7185. if ($this->y < 0) {
  7186. $this->y = 0;
  7187. }
  7188. if ($this->y > $this->h) {
  7189. $this->y = $this->h;
  7190. }
  7191. }
  7192. /**
  7193. * Defines the abscissa and ordinate of the current position.
  7194. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7195. * @param float $x The value of the abscissa.
  7196. * @param float $y The value of the ordinate.
  7197. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7198. * @public
  7199. * @since 1.2
  7200. * @see SetX(), SetY()
  7201. */
  7202. public function setXY($x, $y, $rtloff=false) {
  7203. $this->setY($y, false, $rtloff);
  7204. $this->setX($x, $rtloff);
  7205. }
  7206. /**
  7207. * Set the absolute X coordinate of the current pointer.
  7208. * @param float $x The value of the abscissa in user units.
  7209. * @public
  7210. * @since 5.9.186 (2012-09-13)
  7211. * @see setAbsX(), setAbsY(), SetAbsXY()
  7212. */
  7213. public function setAbsX($x) {
  7214. $this->x = floatval($x);
  7215. }
  7216. /**
  7217. * Set the absolute Y coordinate of the current pointer.
  7218. * @param float $y (float) The value of the ordinate in user units.
  7219. * @public
  7220. * @since 5.9.186 (2012-09-13)
  7221. * @see setAbsX(), setAbsY(), SetAbsXY()
  7222. */
  7223. public function setAbsY($y) {
  7224. $this->y = floatval($y);
  7225. }
  7226. /**
  7227. * Set the absolute X and Y coordinates of the current pointer.
  7228. * @param float $x The value of the abscissa in user units.
  7229. * @param float $y (float) The value of the ordinate in user units.
  7230. * @public
  7231. * @since 5.9.186 (2012-09-13)
  7232. * @see setAbsX(), setAbsY(), SetAbsXY()
  7233. */
  7234. public function setAbsXY($x, $y) {
  7235. $this->setAbsX($x);
  7236. $this->setAbsY($y);
  7237. }
  7238. /**
  7239. * Send the document to a given destination: string, local file or browser.
  7240. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7241. * The method first calls Close() if necessary to terminate the document.
  7242. * @param string $name The name of the file when saved
  7243. * @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>
  7244. * @return string
  7245. * @public
  7246. * @since 1.0
  7247. * @see Close()
  7248. */
  7249. public function Output($name='doc.pdf', $dest='I') {
  7250. //Output PDF to some destination
  7251. //Finish document if necessary
  7252. if ($this->state < 3) {
  7253. $this->Close();
  7254. }
  7255. //Normalize parameters
  7256. if (is_bool($dest)) {
  7257. $dest = $dest ? 'D' : 'F';
  7258. }
  7259. $dest = strtoupper($dest);
  7260. if ($this->sign) {
  7261. // *** apply digital signature to the document ***
  7262. // get the document content
  7263. $pdfdoc = $this->getBuffer();
  7264. // remove last newline
  7265. $pdfdoc = substr($pdfdoc, 0, -1);
  7266. // remove filler space
  7267. $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string);
  7268. // define the ByteRange
  7269. $byte_range = array();
  7270. $byte_range[0] = 0;
  7271. $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10;
  7272. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  7273. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7274. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  7275. // replace the ByteRange
  7276. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  7277. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  7278. $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc);
  7279. // write the document to a temporary folder
  7280. $tempdoc = TCPDF_STATIC::getObjFilename('doc', $this->file_id);
  7281. $f = TCPDF_STATIC::fopenLocal($tempdoc, 'wb');
  7282. if (!$f) {
  7283. $this->Error('Unable to create temporary file: '.$tempdoc);
  7284. }
  7285. $pdfdoc_length = strlen($pdfdoc);
  7286. fwrite($f, $pdfdoc, $pdfdoc_length);
  7287. fclose($f);
  7288. // get digital signature via openssl library
  7289. $tempsign = TCPDF_STATIC::getObjFilename('sig', $this->file_id);
  7290. if (empty($this->signature_data['extracerts'])) {
  7291. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  7292. } else {
  7293. 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']);
  7294. }
  7295. // read signature
  7296. $signature = file_get_contents($tempsign);
  7297. // extract signature
  7298. $signature = substr($signature, $pdfdoc_length);
  7299. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  7300. $tmparr = explode("\n\n", $signature);
  7301. $signature = $tmparr[1];
  7302. // decode signature
  7303. $signature = base64_decode(trim($signature));
  7304. // add TSA timestamp to signature
  7305. $signature = $this->applyTSA($signature);
  7306. // convert signature to hex
  7307. $signature = current(unpack('H*', $signature));
  7308. $signature = str_pad($signature, $this->signature_max_length, '0');
  7309. // Add signature to the document
  7310. $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  7311. $this->bufferlen = strlen($this->buffer);
  7312. }
  7313. switch($dest) {
  7314. case 'I': {
  7315. // Send PDF to the standard output
  7316. if (ob_get_contents()) {
  7317. $this->Error('Some data has already been output, can\'t send PDF file');
  7318. }
  7319. if (php_sapi_name() != 'cli') {
  7320. // send output to a browser
  7321. header('Content-Type: application/pdf');
  7322. if (headers_sent()) {
  7323. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7324. }
  7325. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7326. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7327. header('Pragma: public');
  7328. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7329. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7330. header('Content-Disposition: inline; filename="' . rawurlencode(basename($name)) . '"; ' .
  7331. 'filename*=UTF-8\'\'' . rawurlencode(basename($name)));
  7332. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7333. } else {
  7334. echo $this->getBuffer();
  7335. }
  7336. break;
  7337. }
  7338. case 'D': {
  7339. // download PDF as file
  7340. if (ob_get_contents()) {
  7341. $this->Error('Some data has already been output, can\'t send PDF file');
  7342. }
  7343. header('Content-Description: File Transfer');
  7344. if (headers_sent()) {
  7345. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7346. }
  7347. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7348. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7349. header('Pragma: public');
  7350. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7351. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7352. // force download dialog
  7353. if (strpos(php_sapi_name(), 'cgi') === false) {
  7354. header('Content-Type: application/force-download');
  7355. header('Content-Type: application/octet-stream', false);
  7356. header('Content-Type: application/download', false);
  7357. header('Content-Type: application/pdf', false);
  7358. } else {
  7359. header('Content-Type: application/pdf');
  7360. }
  7361. // use the Content-Disposition header to supply a recommended filename
  7362. header('Content-Disposition: attachment; filename="' . rawurlencode(basename($name)) . '"; ' .
  7363. 'filename*=UTF-8\'\'' . rawurlencode(basename($name)));
  7364. header('Content-Transfer-Encoding: binary');
  7365. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7366. break;
  7367. }
  7368. case 'F':
  7369. case 'FI':
  7370. case 'FD': {
  7371. // save PDF to a local file
  7372. $f = TCPDF_STATIC::fopenLocal($name, 'wb');
  7373. if (!$f) {
  7374. $this->Error('Unable to create output file: '.$name);
  7375. }
  7376. fwrite($f, $this->getBuffer(), $this->bufferlen);
  7377. fclose($f);
  7378. if ($dest == 'FI') {
  7379. // send headers to browser
  7380. header('Content-Type: application/pdf');
  7381. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7382. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7383. header('Pragma: public');
  7384. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7385. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7386. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7387. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7388. } elseif ($dest == 'FD') {
  7389. // send headers to browser
  7390. if (ob_get_contents()) {
  7391. $this->Error('Some data has already been output, can\'t send PDF file');
  7392. }
  7393. header('Content-Description: File Transfer');
  7394. if (headers_sent()) {
  7395. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7396. }
  7397. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7398. header('Pragma: public');
  7399. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7400. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7401. // force download dialog
  7402. if (strpos(php_sapi_name(), 'cgi') === false) {
  7403. header('Content-Type: application/force-download');
  7404. header('Content-Type: application/octet-stream', false);
  7405. header('Content-Type: application/download', false);
  7406. header('Content-Type: application/pdf', false);
  7407. } else {
  7408. header('Content-Type: application/pdf');
  7409. }
  7410. // use the Content-Disposition header to supply a recommended filename
  7411. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7412. header('Content-Transfer-Encoding: binary');
  7413. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7414. }
  7415. break;
  7416. }
  7417. case 'E': {
  7418. // return PDF as base64 mime multi-part email attachment (RFC 2045)
  7419. $retval = 'Content-Type: application/pdf;'."\r\n";
  7420. $retval .= ' name="'.$name.'"'."\r\n";
  7421. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7422. $retval .= 'Content-Disposition: attachment;'."\r\n";
  7423. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7424. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  7425. return $retval;
  7426. }
  7427. case 'S': {
  7428. // returns PDF as a string
  7429. return $this->getBuffer();
  7430. }
  7431. default: {
  7432. $this->Error('Incorrect output destination: '.$dest);
  7433. }
  7434. }
  7435. return '';
  7436. }
  7437. protected static $cleaned_ids = array();
  7438. /**
  7439. * Unset all class variables except the following critical variables.
  7440. * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  7441. * @param boolean $preserve_objcopy if true preserves the objcopy variable
  7442. * @public
  7443. * @since 4.5.016 (2009-02-24)
  7444. */
  7445. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  7446. if (isset(self::$cleaned_ids[$this->file_id])) {
  7447. $destroyall = false;
  7448. }
  7449. if ($destroyall AND !$preserve_objcopy && isset($this->file_id)) {
  7450. self::$cleaned_ids[$this->file_id] = true;
  7451. // remove all temporary files
  7452. if ($handle = @opendir(K_PATH_CACHE)) {
  7453. while ( false !== ( $file_name = readdir( $handle ) ) ) {
  7454. if (strpos($file_name, '__tcpdf_'.$this->file_id.'_') === 0) {
  7455. unlink(K_PATH_CACHE.$file_name);
  7456. }
  7457. }
  7458. closedir($handle);
  7459. }
  7460. if (isset($this->imagekeys)) {
  7461. foreach($this->imagekeys as $file) {
  7462. if (strpos($file, K_PATH_CACHE) === 0 && TCPDF_STATIC::file_exists($file)) {
  7463. @unlink($file);
  7464. }
  7465. }
  7466. }
  7467. }
  7468. $preserve = array(
  7469. 'file_id',
  7470. 'state',
  7471. 'bufferlen',
  7472. 'buffer',
  7473. 'cached_files',
  7474. 'imagekeys',
  7475. 'sign',
  7476. 'signature_data',
  7477. 'signature_max_length',
  7478. 'byterange_string',
  7479. 'tsa_timestamp',
  7480. 'tsa_data'
  7481. );
  7482. foreach (array_keys(get_object_vars($this)) as $val) {
  7483. if ($destroyall OR !in_array($val, $preserve)) {
  7484. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
  7485. unset($this->$val);
  7486. }
  7487. }
  7488. }
  7489. }
  7490. /**
  7491. * Check for locale-related bug
  7492. * @protected
  7493. */
  7494. protected function _dochecks() {
  7495. //Check for locale-related bug
  7496. if (1.1 == 1) {
  7497. $this->Error('Don\'t alter the locale before including class file');
  7498. }
  7499. //Check for decimal separator
  7500. if (sprintf('%.1F', 1.0) != '1.0') {
  7501. setlocale(LC_NUMERIC, 'C');
  7502. }
  7503. }
  7504. /**
  7505. * Return an array containing variations for the basic page number alias.
  7506. * @param string $a Base alias.
  7507. * @return array of page number aliases
  7508. * @protected
  7509. */
  7510. protected function getInternalPageNumberAliases($a= '') {
  7511. $alias = array();
  7512. // build array of Unicode + ASCII variants (the order is important)
  7513. $alias = array('u' => array(), 'a' => array());
  7514. $u = '{'.$a.'}';
  7515. $alias['u'][] = TCPDF_STATIC::_escape($u);
  7516. if ($this->isunicode) {
  7517. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont));
  7518. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7519. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont));
  7520. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7521. }
  7522. $alias['a'][] = TCPDF_STATIC::_escape($a);
  7523. return $alias;
  7524. }
  7525. /**
  7526. * Return an array containing all internal page aliases.
  7527. * @return array of page number aliases
  7528. * @protected
  7529. */
  7530. protected function getAllInternalPageNumberAliases() {
  7531. $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);
  7532. $pnalias = array();
  7533. foreach($basic_alias as $k => $a) {
  7534. $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  7535. }
  7536. return $pnalias;
  7537. }
  7538. /**
  7539. * Replace right shift page number aliases with spaces to correct right alignment.
  7540. * This works perfectly only when using monospaced fonts.
  7541. * @param string $page Page content.
  7542. * @param array $aliases Array of page aliases.
  7543. * @param int $diff initial difference to add.
  7544. * @return string replaced page content.
  7545. * @protected
  7546. */
  7547. protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
  7548. foreach ($aliases as $type => $alias) {
  7549. foreach ($alias as $a) {
  7550. // find position of compensation factor
  7551. $startnum = (strpos($a, ':') + 1);
  7552. $a = substr($a, 0, $startnum);
  7553. if (($pos = strpos($page, $a)) !== false) {
  7554. // end of alias
  7555. $endnum = strpos($page, '}', $pos);
  7556. // string to be replaced
  7557. $aa = substr($page, $pos, ($endnum - $pos + 1));
  7558. // get compensation factor
  7559. $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
  7560. $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
  7561. $ratio = floatval($ratio);
  7562. if ($type == 'u') {
  7563. $chrdiff = floor(($diff + 12) * $ratio);
  7564. $shift = str_repeat(' ', $chrdiff);
  7565. $shift = TCPDF_FONTS::UTF8ToUTF16BE($shift, false, $this->isunicode, $this->CurrentFont);
  7566. } else {
  7567. $chrdiff = floor(($diff + 11) * $ratio);
  7568. $shift = str_repeat(' ', $chrdiff);
  7569. }
  7570. $page = str_replace($aa, $shift, $page);
  7571. }
  7572. }
  7573. }
  7574. return $page;
  7575. }
  7576. /**
  7577. * Set page boxes to be included on page descriptions.
  7578. * @param array $boxes Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  7579. * @protected
  7580. */
  7581. protected function setPageBoxTypes($boxes) {
  7582. $this->page_boxes = array();
  7583. foreach ($boxes as $box) {
  7584. if (in_array($box, TCPDF_STATIC::$pageboxes)) {
  7585. $this->page_boxes[] = $box;
  7586. }
  7587. }
  7588. }
  7589. /**
  7590. * Output pages (and replace page number aliases).
  7591. * @protected
  7592. */
  7593. protected function _putpages() {
  7594. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7595. // get internal aliases for page numbers
  7596. $pnalias = $this->getAllInternalPageNumberAliases();
  7597. $num_pages = $this->numpages;
  7598. $ptpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $num_pages - 1));
  7599. $ptpu = TCPDF_FONTS::UTF8ToUTF16BE($ptpa, false, $this->isunicode, $this->CurrentFont);
  7600. $ptp_num_chars = $this->GetNumChars($ptpa);
  7601. $pagegroupnum = 0;
  7602. $groupnum = 0;
  7603. $ptgu = 1;
  7604. $ptga = 1;
  7605. $ptg_num_chars = 1;
  7606. for ($n = 1; $n <= $num_pages; ++$n) {
  7607. // get current page
  7608. $temppage = $this->getPageBuffer($n);
  7609. $pagelen = strlen($temppage);
  7610. // set replacements for total pages number
  7611. $pnpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $n - 1));
  7612. $pnpu = TCPDF_FONTS::UTF8ToUTF16BE($pnpa, false, $this->isunicode, $this->CurrentFont);
  7613. $pnp_num_chars = $this->GetNumChars($pnpa);
  7614. $pdiff = 0; // difference used for right shift alignment of page numbers
  7615. $gdiff = 0; // difference used for right shift alignment of page group numbers
  7616. if (!empty($this->pagegroups)) {
  7617. if (isset($this->newpagegroup[$n])) {
  7618. $pagegroupnum = 0;
  7619. ++$groupnum;
  7620. $ptga = TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]);
  7621. $ptgu = TCPDF_FONTS::UTF8ToUTF16BE($ptga, false, $this->isunicode, $this->CurrentFont);
  7622. $ptg_num_chars = $this->GetNumChars($ptga);
  7623. }
  7624. ++$pagegroupnum;
  7625. $pnga = TCPDF_STATIC::formatPageNumber($pagegroupnum);
  7626. $pngu = TCPDF_FONTS::UTF8ToUTF16BE($pnga, false, $this->isunicode, $this->CurrentFont);
  7627. $png_num_chars = $this->GetNumChars($pnga);
  7628. // replace page numbers
  7629. $replace = array();
  7630. $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
  7631. $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
  7632. $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
  7633. $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
  7634. list($temppage, $gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $gdiff);
  7635. }
  7636. // replace page numbers
  7637. $replace = array();
  7638. $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
  7639. $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
  7640. $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
  7641. $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
  7642. list($temppage, $pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $pdiff);
  7643. // replace right shift alias
  7644. $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
  7645. // replace EPS marker
  7646. $temppage = str_replace($this->epsmarker, '', $temppage);
  7647. //Page
  7648. $this->page_obj_id[$n] = $this->_newobj();
  7649. $out = '<<';
  7650. $out .= ' /Type /Page';
  7651. $out .= ' /Parent 1 0 R';
  7652. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  7653. $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp);
  7654. }
  7655. $out .= ' /Resources 2 0 R';
  7656. foreach ($this->page_boxes as $box) {
  7657. $out .= ' /'.$box;
  7658. $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']);
  7659. }
  7660. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7661. $out .= ' /BoxColorInfo <<';
  7662. foreach ($this->page_boxes as $box) {
  7663. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7664. $out .= ' /'.$box.' <<';
  7665. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7666. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7667. $out .= ' /C [';
  7668. $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  7669. $out .= ' ]';
  7670. }
  7671. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  7672. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  7673. }
  7674. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  7675. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  7676. }
  7677. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  7678. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  7679. $out .= ' /D [';
  7680. foreach ($dashes as $dash) {
  7681. $out .= sprintf(' %F', ($dash * $this->k));
  7682. }
  7683. $out .= ' ]';
  7684. }
  7685. $out .= ' >>';
  7686. }
  7687. }
  7688. $out .= ' >>';
  7689. }
  7690. $out .= ' /Contents '.($this->n + 1).' 0 R';
  7691. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  7692. if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  7693. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  7694. }
  7695. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  7696. // page transitions
  7697. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  7698. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  7699. }
  7700. $out .= ' /Trans <<';
  7701. $out .= ' /Type /Trans';
  7702. if (isset($this->pagedim[$n]['trans']['S'])) {
  7703. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  7704. }
  7705. if (isset($this->pagedim[$n]['trans']['D'])) {
  7706. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  7707. }
  7708. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  7709. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  7710. }
  7711. if (isset($this->pagedim[$n]['trans']['M'])) {
  7712. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  7713. }
  7714. if (isset($this->pagedim[$n]['trans']['Di'])) {
  7715. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  7716. }
  7717. if (isset($this->pagedim[$n]['trans']['SS'])) {
  7718. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  7719. }
  7720. if (isset($this->pagedim[$n]['trans']['B'])) {
  7721. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  7722. }
  7723. $out .= ' >>';
  7724. }
  7725. $out .= $this->_getannotsrefs($n);
  7726. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  7727. $out .= ' >>';
  7728. $out .= "\n".'endobj';
  7729. $this->_out($out);
  7730. //Page content
  7731. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  7732. $this->_newobj();
  7733. $p = $this->_getrawstream($p);
  7734. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  7735. }
  7736. //Pages root
  7737. $out = $this->_getobj(1)."\n";
  7738. $out .= '<< /Type /Pages /Kids [';
  7739. foreach($this->page_obj_id as $page_obj) {
  7740. $out .= ' '.$page_obj.' 0 R';
  7741. }
  7742. $out .= ' ] /Count '.$num_pages.' >>';
  7743. $out .= "\n".'endobj';
  7744. $this->_out($out);
  7745. }
  7746. /**
  7747. * Get references to page annotations.
  7748. * @param int $n page number
  7749. * @return string
  7750. * @protected
  7751. * @author Nicola Asuni
  7752. * @since 5.0.010 (2010-05-17)
  7753. */
  7754. protected function _getannotsrefs($n) {
  7755. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  7756. return '';
  7757. }
  7758. $out = ' /Annots [';
  7759. if (isset($this->PageAnnots[$n])) {
  7760. foreach ($this->PageAnnots[$n] as $key => $val) {
  7761. if (!in_array($val['n'], $this->radio_groups)) {
  7762. $out .= ' '.$val['n'].' 0 R';
  7763. }
  7764. }
  7765. // add radiobutton groups
  7766. if (isset($this->radiobutton_groups[$n])) {
  7767. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  7768. if (isset($data['n'])) {
  7769. $out .= ' '.$data['n'].' 0 R';
  7770. }
  7771. }
  7772. }
  7773. }
  7774. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  7775. // set reference for signature object
  7776. $out .= ' '.$this->sig_obj_id.' 0 R';
  7777. }
  7778. if (!empty($this->empty_signature_appearance)) {
  7779. foreach ($this->empty_signature_appearance as $esa) {
  7780. if ($esa['page'] == $n) {
  7781. // set reference for empty signature objects
  7782. $out .= ' '.$esa['objid'].' 0 R';
  7783. }
  7784. }
  7785. }
  7786. $out .= ' ]';
  7787. return $out;
  7788. }
  7789. /**
  7790. * Output annotations objects for all pages.
  7791. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  7792. * See section 12.5 of PDF 32000_2008 reference.
  7793. * @protected
  7794. * @author Nicola Asuni
  7795. * @since 4.0.018 (2008-08-06)
  7796. */
  7797. protected function _putannotsobjs() {
  7798. // reset object counter
  7799. for ($n=1; $n <= $this->numpages; ++$n) {
  7800. if (isset($this->PageAnnots[$n])) {
  7801. // set page annotations
  7802. foreach ($this->PageAnnots[$n] as $key => $pl) {
  7803. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  7804. // create annotation object for grouping radiobuttons
  7805. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  7806. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  7807. $annots = '<<';
  7808. $annots .= ' /Type /Annot';
  7809. $annots .= ' /Subtype /Widget';
  7810. $annots .= ' /Rect [0 0 0 0]';
  7811. if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  7812. // read only
  7813. $annots .= ' /F 68';
  7814. $annots .= ' /Ff 49153';
  7815. } else {
  7816. $annots .= ' /F 4'; // default print for PDF/A
  7817. $annots .= ' /Ff 49152';
  7818. }
  7819. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  7820. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  7821. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  7822. }
  7823. $annots .= ' /FT /Btn';
  7824. $annots .= ' /Kids [';
  7825. $defval = '';
  7826. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  7827. if (isset($data['kid'])) {
  7828. $annots .= ' '.$data['kid'].' 0 R';
  7829. if ($data['def'] !== 'Off') {
  7830. $defval = $data['def'];
  7831. }
  7832. }
  7833. }
  7834. $annots .= ' ]';
  7835. if (!empty($defval)) {
  7836. $annots .= ' /V /'.$defval;
  7837. }
  7838. $annots .= ' >>';
  7839. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  7840. $this->form_obj_id[] = $radio_button_obj_id;
  7841. // store object id to be used on Parent entry of Kids
  7842. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  7843. }
  7844. $formfield = false;
  7845. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  7846. $a = $pl['x'] * $this->k;
  7847. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  7848. $c = $pl['w'] * $this->k;
  7849. $d = $pl['h'] * $this->k;
  7850. $rect = sprintf('%F %F %F %F', $a, $b, $a+$c, $b+$d);
  7851. // create new annotation object
  7852. $annots = '<</Type /Annot';
  7853. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  7854. $annots .= ' /Rect ['.$rect.']';
  7855. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  7856. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  7857. $annots .= ' /FT /'.$pl['opt']['ft'];
  7858. $formfield = true;
  7859. }
  7860. if ($pl['opt']['subtype'] !== 'Link') {
  7861. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  7862. }
  7863. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  7864. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  7865. $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
  7866. if (isset($pl['opt']['f'])) {
  7867. $fval = 0;
  7868. if (is_array($pl['opt']['f'])) {
  7869. foreach ($pl['opt']['f'] as $f) {
  7870. switch (strtolower($f)) {
  7871. case 'invisible': {
  7872. $fval += 1 << 0;
  7873. break;
  7874. }
  7875. case 'hidden': {
  7876. $fval += 1 << 1;
  7877. break;
  7878. }
  7879. case 'print': {
  7880. $fval += 1 << 2;
  7881. break;
  7882. }
  7883. case 'nozoom': {
  7884. $fval += 1 << 3;
  7885. break;
  7886. }
  7887. case 'norotate': {
  7888. $fval += 1 << 4;
  7889. break;
  7890. }
  7891. case 'noview': {
  7892. $fval += 1 << 5;
  7893. break;
  7894. }
  7895. case 'readonly': {
  7896. $fval += 1 << 6;
  7897. break;
  7898. }
  7899. case 'locked': {
  7900. $fval += 1 << 8;
  7901. break;
  7902. }
  7903. case 'togglenoview': {
  7904. $fval += 1 << 9;
  7905. break;
  7906. }
  7907. case 'lockedcontents': {
  7908. $fval += 1 << 10;
  7909. break;
  7910. }
  7911. default: {
  7912. break;
  7913. }
  7914. }
  7915. }
  7916. } else {
  7917. $fval = intval($pl['opt']['f']);
  7918. }
  7919. } else {
  7920. $fval = 4;
  7921. }
  7922. if ($this->pdfa_mode) {
  7923. // force print flag for PDF/A mode
  7924. $fval |= 4;
  7925. }
  7926. $annots .= ' /F '.intval($fval);
  7927. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  7928. $annots .= ' /AS /'.$pl['opt']['as'];
  7929. }
  7930. if (isset($pl['opt']['ap'])) {
  7931. // appearance stream
  7932. $annots .= ' /AP <<';
  7933. if (is_array($pl['opt']['ap'])) {
  7934. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  7935. // $apmode can be: n = normal; r = rollover; d = down;
  7936. $annots .= ' /'.strtoupper($apmode);
  7937. if (is_array($apdef)) {
  7938. $annots .= ' <<';
  7939. foreach ($apdef as $apstate => $stream) {
  7940. // reference to XObject that define the appearance for this mode-state
  7941. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  7942. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  7943. }
  7944. $annots .= ' >>';
  7945. } else {
  7946. // reference to XObject that define the appearance for this mode
  7947. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  7948. $annots .= ' '.$apsobjid.' 0 R';
  7949. }
  7950. }
  7951. } else {
  7952. $annots .= $pl['opt']['ap'];
  7953. }
  7954. $annots .= ' >>';
  7955. }
  7956. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  7957. $annots .= ' /BS <<';
  7958. $annots .= ' /Type /Border';
  7959. if (isset($pl['opt']['bs']['w'])) {
  7960. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  7961. }
  7962. $bstyles = array('S', 'D', 'B', 'I', 'U');
  7963. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  7964. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7965. }
  7966. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  7967. $annots .= ' /D [';
  7968. foreach ($pl['opt']['bs']['d'] as $cord) {
  7969. $annots .= ' '.intval($cord);
  7970. }
  7971. $annots .= ']';
  7972. }
  7973. $annots .= ' >>';
  7974. } else {
  7975. $annots .= ' /Border [';
  7976. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  7977. $annots .= intval($pl['opt']['border'][0]).' ';
  7978. $annots .= intval($pl['opt']['border'][1]).' ';
  7979. $annots .= intval($pl['opt']['border'][2]);
  7980. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  7981. $annots .= ' [';
  7982. foreach ($pl['opt']['border'][3] as $dash) {
  7983. $annots .= intval($dash).' ';
  7984. }
  7985. $annots .= ']';
  7986. }
  7987. } else {
  7988. $annots .= '0 0 0';
  7989. }
  7990. $annots .= ']';
  7991. }
  7992. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  7993. $annots .= ' /BE <<';
  7994. $bstyles = array('S', 'C');
  7995. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  7996. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7997. } else {
  7998. $annots .= ' /S /S';
  7999. }
  8000. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  8001. $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
  8002. }
  8003. $annots .= '>>';
  8004. }
  8005. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  8006. $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']);
  8007. }
  8008. //$annots .= ' /StructParent ';
  8009. //$annots .= ' /OC ';
  8010. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  8011. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  8012. // this is a markup type
  8013. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8014. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  8015. }
  8016. //$annots .= ' /Popup ';
  8017. if (isset($pl['opt']['ca'])) {
  8018. $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
  8019. }
  8020. if (isset($pl['opt']['rc'])) {
  8021. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8022. }
  8023. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
  8024. //$annots .= ' /IRT ';
  8025. if (isset($pl['opt']['subj'])) {
  8026. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  8027. }
  8028. //$annots .= ' /RT ';
  8029. //$annots .= ' /IT ';
  8030. //$annots .= ' /ExData ';
  8031. }
  8032. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  8033. // Annotation types
  8034. switch (strtolower($pl['opt']['subtype'])) {
  8035. case 'text': {
  8036. if (isset($pl['opt']['open'])) {
  8037. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  8038. }
  8039. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  8040. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8041. $annots .= ' /Name /'.$pl['opt']['name'];
  8042. } else {
  8043. $annots .= ' /Name /Note';
  8044. }
  8045. $hasStateModel = isset($pl['opt']['statemodel']);
  8046. $hasState = isset($pl['opt']['state']);
  8047. $statemodels = array('Marked', 'Review');
  8048. if (!$hasStateModel && !$hasState) {
  8049. break;
  8050. }
  8051. if ($hasStateModel AND in_array($pl['opt']['statemodel'], $statemodels)) {
  8052. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8053. } else {
  8054. $pl['opt']['statemodel'] = 'Marked';
  8055. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8056. }
  8057. if ($pl['opt']['statemodel'] == 'Marked') {
  8058. $states = array('Accepted', 'Unmarked');
  8059. } else {
  8060. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  8061. }
  8062. if ($hasState AND in_array($pl['opt']['state'], $states)) {
  8063. $annots .= ' /State /'.$pl['opt']['state'];
  8064. } else {
  8065. if ($pl['opt']['statemodel'] == 'Marked') {
  8066. $annots .= ' /State /Unmarked';
  8067. } else {
  8068. $annots .= ' /State /None';
  8069. }
  8070. }
  8071. break;
  8072. }
  8073. case 'link': {
  8074. if (is_string($pl['txt']) && !empty($pl['txt'])) {
  8075. if ($pl['txt'][0] == '#') {
  8076. // internal destination
  8077. $annots .= ' /A <</S /GoTo /D /'.TCPDF_STATIC::encodeNameObject(substr($pl['txt'], 1)).'>>';
  8078. } elseif ($pl['txt'][0] == '%') {
  8079. // embedded PDF file
  8080. $filename = basename(substr($pl['txt'], 1));
  8081. $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  8082. } elseif ($pl['txt'][0] == '*') {
  8083. // embedded generic file
  8084. $filename = basename(substr($pl['txt'], 1));
  8085. $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});';
  8086. $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
  8087. } else {
  8088. $parsedUrl = parse_url($pl['txt']);
  8089. if (empty($parsedUrl['scheme']) AND (!empty($parsedUrl['path']) && strtolower(substr($parsedUrl['path'], -4)) == '.pdf')) {
  8090. // relative link to a PDF file
  8091. $dest = '[0 /Fit]'; // default page 0
  8092. if (!empty($parsedUrl['fragment'])) {
  8093. // check for named destination
  8094. $tmp = explode('=', $parsedUrl['fragment']);
  8095. $dest = '('.((count($tmp) == 2) ? $tmp[1] : $tmp[0]).')';
  8096. }
  8097. $annots .= ' /A <</S /GoToR /D '.$dest.' /F '.$this->_datastring($this->unhtmlentities($parsedUrl['path']), $annot_obj_id).' /NewWindow true>>';
  8098. } else {
  8099. // external URI link
  8100. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  8101. }
  8102. }
  8103. } elseif (isset($this->links[$pl['txt']])) {
  8104. // internal link ID
  8105. $l = $this->links[$pl['txt']];
  8106. if (isset($this->page_obj_id[($l['p'])])) {
  8107. $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)));
  8108. }
  8109. }
  8110. $hmodes = array('N', 'I', 'O', 'P');
  8111. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  8112. $annots .= ' /H /'.$pl['opt']['h'];
  8113. } else {
  8114. $annots .= ' /H /I';
  8115. }
  8116. //$annots .= ' /PA ';
  8117. //$annots .= ' /Quadpoints ';
  8118. break;
  8119. }
  8120. case 'freetext': {
  8121. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8122. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8123. }
  8124. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8125. $annots .= ' /Q '.intval($pl['opt']['q']);
  8126. }
  8127. if (isset($pl['opt']['rc'])) {
  8128. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8129. }
  8130. if (isset($pl['opt']['ds'])) {
  8131. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  8132. }
  8133. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  8134. $annots .= ' /CL [';
  8135. foreach ($pl['opt']['cl'] as $cl) {
  8136. $annots .= sprintf('%F ', $cl * $this->k);
  8137. }
  8138. $annots .= ']';
  8139. }
  8140. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  8141. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  8142. $annots .= ' /IT /'.$pl['opt']['it'];
  8143. }
  8144. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  8145. $l = $pl['opt']['rd'][0] * $this->k;
  8146. $r = $pl['opt']['rd'][1] * $this->k;
  8147. $t = $pl['opt']['rd'][2] * $this->k;
  8148. $b = $pl['opt']['rd'][3] * $this->k;
  8149. $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
  8150. }
  8151. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8152. $annots .= ' /LE /'.$pl['opt']['le'];
  8153. }
  8154. break;
  8155. }
  8156. case 'line': {
  8157. break;
  8158. }
  8159. case 'square': {
  8160. break;
  8161. }
  8162. case 'circle': {
  8163. break;
  8164. }
  8165. case 'polygon': {
  8166. break;
  8167. }
  8168. case 'polyline': {
  8169. break;
  8170. }
  8171. case 'highlight': {
  8172. break;
  8173. }
  8174. case 'underline': {
  8175. break;
  8176. }
  8177. case 'squiggly': {
  8178. break;
  8179. }
  8180. case 'strikeout': {
  8181. break;
  8182. }
  8183. case 'stamp': {
  8184. break;
  8185. }
  8186. case 'caret': {
  8187. break;
  8188. }
  8189. case 'ink': {
  8190. break;
  8191. }
  8192. case 'popup': {
  8193. break;
  8194. }
  8195. case 'fileattachment': {
  8196. if ($this->pdfa_mode && $this->pdfa_version != 3) {
  8197. // embedded files are not allowed in PDF/A mode version 1 and 2
  8198. break;
  8199. }
  8200. if (!isset($pl['opt']['fs'])) {
  8201. break;
  8202. }
  8203. $filename = basename($pl['opt']['fs']);
  8204. if (isset($this->embeddedfiles[$filename]['f'])) {
  8205. $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8206. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  8207. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8208. $annots .= ' /Name /'.$pl['opt']['name'];
  8209. } else {
  8210. $annots .= ' /Name /PushPin';
  8211. }
  8212. // index (zero-based) of the annotation in the Annots array of this page
  8213. $this->embeddedfiles[$filename]['a'] = $key;
  8214. }
  8215. break;
  8216. }
  8217. case 'sound': {
  8218. if (!isset($pl['opt']['fs'])) {
  8219. break;
  8220. }
  8221. $filename = basename($pl['opt']['fs']);
  8222. if (isset($this->embeddedfiles[$filename]['f'])) {
  8223. // ... TO BE COMPLETED ...
  8224. // /R /C /B /E /CO /CP
  8225. $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8226. $iconsapp = array('Speaker', 'Mic');
  8227. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8228. $annots .= ' /Name /'.$pl['opt']['name'];
  8229. } else {
  8230. $annots .= ' /Name /Speaker';
  8231. }
  8232. }
  8233. break;
  8234. }
  8235. case 'movie': {
  8236. break;
  8237. }
  8238. case 'widget': {
  8239. $hmode = array('N', 'I', 'O', 'P', 'T');
  8240. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8241. $annots .= ' /H /'.$pl['opt']['h'];
  8242. }
  8243. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8244. $annots .= ' /MK <<';
  8245. if (isset($pl['opt']['mk']['r'])) {
  8246. $annots .= ' /R '.$pl['opt']['mk']['r'];
  8247. }
  8248. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8249. $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']);
  8250. }
  8251. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8252. $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']);
  8253. }
  8254. if (isset($pl['opt']['mk']['ca'])) {
  8255. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8256. }
  8257. if (isset($pl['opt']['mk']['rc'])) {
  8258. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8259. }
  8260. if (isset($pl['opt']['mk']['ac'])) {
  8261. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8262. }
  8263. if (isset($pl['opt']['mk']['i'])) {
  8264. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  8265. if ($info !== false) {
  8266. $annots .= ' /I '.$info['n'].' 0 R';
  8267. }
  8268. }
  8269. if (isset($pl['opt']['mk']['ri'])) {
  8270. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  8271. if ($info !== false) {
  8272. $annots .= ' /RI '.$info['n'].' 0 R';
  8273. }
  8274. }
  8275. if (isset($pl['opt']['mk']['ix'])) {
  8276. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  8277. if ($info !== false) {
  8278. $annots .= ' /IX '.$info['n'].' 0 R';
  8279. }
  8280. }
  8281. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8282. $annots .= ' /IF <<';
  8283. $if_sw = array('A', 'B', 'S', 'N');
  8284. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8285. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8286. }
  8287. $if_s = array('A', 'P');
  8288. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8289. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8290. }
  8291. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8292. $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8293. }
  8294. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8295. $annots .= ' /FB true';
  8296. }
  8297. $annots .= '>>';
  8298. }
  8299. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8300. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8301. }
  8302. $annots .= '>>';
  8303. } // end MK
  8304. // --- Entries for field dictionaries ---
  8305. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8306. // set parent
  8307. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8308. }
  8309. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8310. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8311. }
  8312. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8313. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8314. }
  8315. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8316. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8317. }
  8318. if (isset($pl['opt']['ff'])) {
  8319. if (is_array($pl['opt']['ff'])) {
  8320. // array of bit settings
  8321. $flag = 0;
  8322. foreach($pl['opt']['ff'] as $val) {
  8323. $flag += 1 << ($val - 1);
  8324. }
  8325. } else {
  8326. $flag = intval($pl['opt']['ff']);
  8327. }
  8328. $annots .= ' /Ff '.$flag;
  8329. }
  8330. if (isset($pl['opt']['maxlen'])) {
  8331. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8332. }
  8333. if (isset($pl['opt']['v'])) {
  8334. $annots .= ' /V';
  8335. if (is_array($pl['opt']['v'])) {
  8336. foreach ($pl['opt']['v'] 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']['v'], $annot_obj_id);
  8344. }
  8345. }
  8346. if (isset($pl['opt']['dv'])) {
  8347. $annots .= ' /DV';
  8348. if (is_array($pl['opt']['dv'])) {
  8349. foreach ($pl['opt']['dv'] AS $optval) {
  8350. if (is_float($optval)) {
  8351. $optval = sprintf('%F', $optval);
  8352. }
  8353. $annots .= ' '.$optval;
  8354. }
  8355. } else {
  8356. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8357. }
  8358. }
  8359. if (isset($pl['opt']['rv'])) {
  8360. $annots .= ' /RV';
  8361. if (is_array($pl['opt']['rv'])) {
  8362. foreach ($pl['opt']['rv'] AS $optval) {
  8363. if (is_float($optval)) {
  8364. $optval = sprintf('%F', $optval);
  8365. }
  8366. $annots .= ' '.$optval;
  8367. }
  8368. } else {
  8369. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8370. }
  8371. }
  8372. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8373. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8374. }
  8375. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8376. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8377. }
  8378. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8379. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8380. }
  8381. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8382. $annots .= ' /Q '.intval($pl['opt']['q']);
  8383. }
  8384. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8385. $annots .= ' /Opt [';
  8386. foreach($pl['opt']['opt'] AS $copt) {
  8387. if (is_array($copt)) {
  8388. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8389. } else {
  8390. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  8391. }
  8392. }
  8393. $annots .= ']';
  8394. }
  8395. if (isset($pl['opt']['ti'])) {
  8396. $annots .= ' /TI '.intval($pl['opt']['ti']);
  8397. }
  8398. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8399. $annots .= ' /I [';
  8400. foreach($pl['opt']['i'] AS $copt) {
  8401. $annots .= intval($copt).' ';
  8402. }
  8403. $annots .= ']';
  8404. }
  8405. break;
  8406. }
  8407. case 'screen': {
  8408. break;
  8409. }
  8410. case 'printermark': {
  8411. break;
  8412. }
  8413. case 'trapnet': {
  8414. break;
  8415. }
  8416. case 'watermark': {
  8417. break;
  8418. }
  8419. case '3d': {
  8420. break;
  8421. }
  8422. default: {
  8423. break;
  8424. }
  8425. }
  8426. $annots .= '>>';
  8427. // create new annotation object
  8428. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8429. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8430. // store reference of form object
  8431. $this->form_obj_id[] = $annot_obj_id;
  8432. }
  8433. }
  8434. }
  8435. } // end for each page
  8436. }
  8437. /**
  8438. * Put appearance streams XObject used to define annotation's appearance states.
  8439. * @param int $w annotation width
  8440. * @param int $h annotation height
  8441. * @param string $stream appearance stream
  8442. * @return int object ID
  8443. * @protected
  8444. * @since 4.8.001 (2009-09-09)
  8445. */
  8446. protected function _putAPXObject($w=0, $h=0, $stream='') {
  8447. $stream = trim($stream);
  8448. $out = $this->_getobj()."\n";
  8449. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8450. $out .= '<<';
  8451. $out .= ' /Type /XObject';
  8452. $out .= ' /Subtype /Form';
  8453. $out .= ' /FormType 1';
  8454. if ($this->compress) {
  8455. $stream = gzcompress($stream);
  8456. $out .= ' /Filter /FlateDecode';
  8457. }
  8458. $rect = sprintf('%F %F', $w, $h);
  8459. $out .= ' /BBox [0 0 '.$rect.']';
  8460. $out .= ' /Matrix [1 0 0 1 0 0]';
  8461. $out .= ' /Resources 2 0 R';
  8462. $stream = $this->_getrawstream($stream);
  8463. $out .= ' /Length '.strlen($stream);
  8464. $out .= ' >>';
  8465. $out .= ' stream'."\n".$stream."\n".'endstream';
  8466. $out .= "\n".'endobj';
  8467. $this->_out($out);
  8468. return $this->n;
  8469. }
  8470. /**
  8471. * Output fonts.
  8472. * @author Nicola Asuni
  8473. * @protected
  8474. */
  8475. protected function _putfonts() {
  8476. $nf = $this->n;
  8477. foreach ($this->diffs as $diff) {
  8478. //Encodings
  8479. $this->_newobj();
  8480. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  8481. }
  8482. foreach ($this->FontFiles as $file => $info) {
  8483. // search and get font file to embedd
  8484. $fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']);
  8485. if (!TCPDF_STATIC::empty_string($fontfile)) {
  8486. $font = file_get_contents($fontfile);
  8487. $compressed = (substr($file, -2) == '.z');
  8488. if ((!$compressed) AND (isset($info['length2']))) {
  8489. $header = (ord($font[0]) == 128);
  8490. if ($header) {
  8491. // strip first binary header
  8492. $font = substr($font, 6);
  8493. }
  8494. if ($header AND (ord($font[$info['length1']]) == 128)) {
  8495. // strip second binary header
  8496. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  8497. }
  8498. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  8499. if ($compressed) {
  8500. // uncompress font
  8501. $font = gzuncompress($font);
  8502. }
  8503. // merge subset characters
  8504. $subsetchars = array(); // used chars
  8505. foreach ($info['fontkeys'] as $fontkey) {
  8506. $fontinfo = $this->getFontBuffer($fontkey);
  8507. $subsetchars += $fontinfo['subsetchars'];
  8508. }
  8509. // rebuild a font subset
  8510. $font = TCPDF_FONTS::_getTrueTypeFontSubset($font, $subsetchars);
  8511. // calculate new font length
  8512. $info['length1'] = strlen($font);
  8513. if ($compressed) {
  8514. // recompress font
  8515. $font = gzcompress($font);
  8516. }
  8517. }
  8518. $this->_newobj();
  8519. $this->FontFiles[$file]['n'] = $this->n;
  8520. $stream = $this->_getrawstream($font);
  8521. $out = '<< /Length '.strlen($stream);
  8522. if ($compressed) {
  8523. $out .= ' /Filter /FlateDecode';
  8524. }
  8525. $out .= ' /Length1 '.$info['length1'];
  8526. if (isset($info['length2'])) {
  8527. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  8528. }
  8529. $out .= ' >>';
  8530. $out .= ' stream'."\n".$stream."\n".'endstream';
  8531. $out .= "\n".'endobj';
  8532. $this->_out($out);
  8533. }
  8534. }
  8535. foreach ($this->fontkeys as $k) {
  8536. //Font objects
  8537. $font = $this->getFontBuffer($k);
  8538. $type = $font['type'];
  8539. $name = $font['name'];
  8540. if ($type == 'core') {
  8541. // standard core font
  8542. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8543. $out .= '<</Type /Font';
  8544. $out .= ' /Subtype /Type1';
  8545. $out .= ' /BaseFont /'.$name;
  8546. $out .= ' /Name /F'.$font['i'];
  8547. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  8548. $out .= ' /Encoding /WinAnsiEncoding';
  8549. }
  8550. if ($k == 'helvetica') {
  8551. // add default font for annotations
  8552. $this->annotation_fonts[$k] = $font['i'];
  8553. }
  8554. $out .= ' >>';
  8555. $out .= "\n".'endobj';
  8556. $this->_out($out);
  8557. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  8558. // additional Type1 or TrueType font
  8559. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8560. $out .= '<</Type /Font';
  8561. $out .= ' /Subtype /'.$type;
  8562. $out .= ' /BaseFont /'.$name;
  8563. $out .= ' /Name /F'.$font['i'];
  8564. $out .= ' /FirstChar 32 /LastChar 255';
  8565. $out .= ' /Widths '.($this->n + 1).' 0 R';
  8566. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  8567. if ($font['enc']) {
  8568. if (isset($font['diff'])) {
  8569. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  8570. } else {
  8571. $out .= ' /Encoding /WinAnsiEncoding';
  8572. }
  8573. }
  8574. $out .= ' >>';
  8575. $out .= "\n".'endobj';
  8576. $this->_out($out);
  8577. // Widths
  8578. $this->_newobj();
  8579. $s = '[';
  8580. for ($i = 32; $i < 256; ++$i) {
  8581. if (isset($font['cw'][$i])) {
  8582. $s .= $font['cw'][$i].' ';
  8583. } else {
  8584. $s .= $font['dw'].' ';
  8585. }
  8586. }
  8587. $s .= ']';
  8588. $s .= "\n".'endobj';
  8589. $this->_out($s);
  8590. //Descriptor
  8591. $this->_newobj();
  8592. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8593. foreach ($font['desc'] as $fdk => $fdv) {
  8594. if (is_float($fdv)) {
  8595. $fdv = sprintf('%F', $fdv);
  8596. }
  8597. $s .= ' /'.$fdk.' '.$fdv.'';
  8598. }
  8599. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8600. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8601. }
  8602. $s .= '>>';
  8603. $s .= "\n".'endobj';
  8604. $this->_out($s);
  8605. } else {
  8606. // additional types
  8607. $mtd = '_put'.strtolower($type);
  8608. if (!method_exists($this, $mtd)) {
  8609. $this->Error('Unsupported font type: '.$type);
  8610. }
  8611. $this->$mtd($font);
  8612. }
  8613. }
  8614. }
  8615. /**
  8616. * Adds unicode fonts.<br>
  8617. * Based on PDF Reference 1.3 (section 5)
  8618. * @param array $font font data
  8619. * @protected
  8620. * @author Nicola Asuni
  8621. * @since 1.52.0.TC005 (2005-01-05)
  8622. */
  8623. protected function _puttruetypeunicode($font) {
  8624. $fontname = '';
  8625. if ($font['subset']) {
  8626. // change name for font subsetting
  8627. $subtag = sprintf('%06u', $font['i']);
  8628. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  8629. $fontname .= $subtag.'+';
  8630. }
  8631. $fontname .= $font['name'];
  8632. // Type0 Font
  8633. // A composite font composed of other fonts, organized hierarchically
  8634. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8635. $out .= '<< /Type /Font';
  8636. $out .= ' /Subtype /Type0';
  8637. $out .= ' /BaseFont /'.$fontname;
  8638. $out .= ' /Name /F'.$font['i'];
  8639. $out .= ' /Encoding /'.$font['enc'];
  8640. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  8641. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  8642. $out .= ' >>';
  8643. $out .= "\n".'endobj';
  8644. $this->_out($out);
  8645. // ToUnicode map for Identity-H
  8646. $stream = TCPDF_FONT_DATA::$uni_identity_h;
  8647. // ToUnicode Object
  8648. $this->_newobj();
  8649. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  8650. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8651. $stream = $this->_getrawstream($stream);
  8652. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  8653. // CIDFontType2
  8654. // A CIDFont whose glyph descriptions are based on TrueType font technology
  8655. $oid = $this->_newobj();
  8656. $out = '<< /Type /Font';
  8657. $out .= ' /Subtype /CIDFontType2';
  8658. $out .= ' /BaseFont /'.$fontname;
  8659. // A dictionary containing entries that define the character collection of the CIDFont.
  8660. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8661. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8662. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8663. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  8664. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8665. $out .= ' /DW '.$font['dw']; // default width
  8666. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, 0);
  8667. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8668. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  8669. }
  8670. $out .= ' >>';
  8671. $out .= "\n".'endobj';
  8672. $this->_out($out);
  8673. // Font descriptor
  8674. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  8675. $this->_newobj();
  8676. $out = '<< /Type /FontDescriptor';
  8677. $out .= ' /FontName /'.$fontname;
  8678. foreach ($font['desc'] as $key => $value) {
  8679. if (is_float($value)) {
  8680. $value = sprintf('%F', $value);
  8681. }
  8682. $out .= ' /'.$key.' '.$value;
  8683. }
  8684. $fontdir = false;
  8685. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8686. // A stream containing a TrueType font
  8687. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8688. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  8689. }
  8690. $out .= ' >>';
  8691. $out .= "\n".'endobj';
  8692. $this->_out($out);
  8693. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8694. $this->_newobj();
  8695. // Embed CIDToGIDMap
  8696. // A specification of the mapping from CIDs to glyph indices
  8697. // search and get CTG font file to embedd
  8698. $ctgfile = strtolower($font['ctg']);
  8699. // search and get ctg font file to embedd
  8700. $fontfile = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir);
  8701. if (TCPDF_STATIC::empty_string($fontfile)) {
  8702. $this->Error('Font file not found: '.$ctgfile);
  8703. }
  8704. $stream = $this->_getrawstream(file_get_contents($fontfile));
  8705. $out = '<< /Length '.strlen($stream).'';
  8706. if (substr($fontfile, -2) == '.z') { // check file extension
  8707. // Decompresses data encoded using the public-domain
  8708. // zlib/deflate compression method, reproducing the
  8709. // original text or binary data
  8710. $out .= ' /Filter /FlateDecode';
  8711. }
  8712. $out .= ' >>';
  8713. $out .= ' stream'."\n".$stream."\n".'endstream';
  8714. $out .= "\n".'endobj';
  8715. $this->_out($out);
  8716. }
  8717. }
  8718. /**
  8719. * Output CID-0 fonts.
  8720. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  8721. * @param array $font font data
  8722. * @protected
  8723. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  8724. * @since 3.2.000 (2008-06-23)
  8725. */
  8726. protected function _putcidfont0($font) {
  8727. $cidoffset = 0;
  8728. if (!isset($font['cw'][1])) {
  8729. $cidoffset = 31;
  8730. }
  8731. if (isset($font['cidinfo']['uni2cid'])) {
  8732. // convert unicode to cid.
  8733. $uni2cid = $font['cidinfo']['uni2cid'];
  8734. $cw = array();
  8735. foreach ($font['cw'] as $uni => $width) {
  8736. if (isset($uni2cid[$uni])) {
  8737. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  8738. } elseif ($uni < 256) {
  8739. $cw[$uni] = $width;
  8740. } // else unknown character
  8741. }
  8742. $font = array_merge($font, array('cw' => $cw));
  8743. }
  8744. $name = $font['name'];
  8745. $enc = $font['enc'];
  8746. if ($enc) {
  8747. $longname = $name.'-'.$enc;
  8748. } else {
  8749. $longname = $name;
  8750. }
  8751. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8752. $out .= '<</Type /Font';
  8753. $out .= ' /Subtype /Type0';
  8754. $out .= ' /BaseFont /'.$longname;
  8755. $out .= ' /Name /F'.$font['i'];
  8756. if ($enc) {
  8757. $out .= ' /Encoding /'.$enc;
  8758. }
  8759. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  8760. $out .= ' >>';
  8761. $out .= "\n".'endobj';
  8762. $this->_out($out);
  8763. $oid = $this->_newobj();
  8764. $out = '<</Type /Font';
  8765. $out .= ' /Subtype /CIDFontType0';
  8766. $out .= ' /BaseFont /'.$name;
  8767. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8768. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8769. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8770. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  8771. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8772. $out .= ' /DW '.$font['dw'];
  8773. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, $cidoffset);
  8774. $out .= ' >>';
  8775. $out .= "\n".'endobj';
  8776. $this->_out($out);
  8777. $this->_newobj();
  8778. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8779. foreach ($font['desc'] as $k => $v) {
  8780. if ($k != 'Style') {
  8781. if (is_float($v)) {
  8782. $v = sprintf('%F', $v);
  8783. }
  8784. $s .= ' /'.$k.' '.$v.'';
  8785. }
  8786. }
  8787. $s .= '>>';
  8788. $s .= "\n".'endobj';
  8789. $this->_out($s);
  8790. }
  8791. /**
  8792. * Output images.
  8793. * @protected
  8794. */
  8795. protected function _putimages() {
  8796. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8797. foreach ($this->imagekeys as $file) {
  8798. $info = $this->getImageBuffer($file);
  8799. // set object for alternate images array
  8800. $altoid = null;
  8801. if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
  8802. $altoid = $this->_newobj();
  8803. $out = '[';
  8804. foreach ($info['altimgs'] as $altimage) {
  8805. if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
  8806. $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
  8807. $out .= ' /DefaultForPrinting';
  8808. if ($altimage[1] === true) {
  8809. $out .= ' true';
  8810. } else {
  8811. $out .= ' false';
  8812. }
  8813. $out .= ' >>';
  8814. }
  8815. }
  8816. $out .= ' ]';
  8817. $out .= "\n".'endobj';
  8818. $this->_out($out);
  8819. }
  8820. // set image object
  8821. $oid = $this->_newobj();
  8822. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  8823. $this->setImageSubBuffer($file, 'n', $this->n);
  8824. $out = '<</Type /XObject';
  8825. $out .= ' /Subtype /Image';
  8826. $out .= ' /Width '.$info['w'];
  8827. $out .= ' /Height '.$info['h'];
  8828. if (array_key_exists('masked', $info)) {
  8829. $out .= ' /SMask '.($this->n - 1).' 0 R';
  8830. }
  8831. // set color space
  8832. $icc = false;
  8833. if (isset($info['icc']) AND ($info['icc'] !== false)) {
  8834. // ICC Colour Space
  8835. $icc = true;
  8836. $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
  8837. } elseif ($info['cs'] == 'Indexed') {
  8838. // Indexed Colour Space
  8839. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  8840. } else {
  8841. // Device Colour Space
  8842. $out .= ' /ColorSpace /'.$info['cs'];
  8843. }
  8844. if ($info['cs'] == 'DeviceCMYK') {
  8845. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  8846. }
  8847. $out .= ' /BitsPerComponent '.$info['bpc'];
  8848. if ($altoid > 0) {
  8849. // reference to alternate images dictionary
  8850. $out .= ' /Alternates '.$altoid.' 0 R';
  8851. }
  8852. if (isset($info['exurl']) AND !empty($info['exurl'])) {
  8853. // external stream
  8854. $out .= ' /Length 0';
  8855. $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
  8856. if (isset($info['f'])) {
  8857. $out .= ' /FFilter /'.$info['f'];
  8858. }
  8859. $out .= ' >>';
  8860. $out .= ' stream'."\n".'endstream';
  8861. } else {
  8862. if (isset($info['f'])) {
  8863. $out .= ' /Filter /'.$info['f'];
  8864. }
  8865. if (isset($info['parms'])) {
  8866. $out .= ' '.$info['parms'];
  8867. }
  8868. if (isset($info['trns']) AND is_array($info['trns'])) {
  8869. $trns = '';
  8870. $count_info = count($info['trns']);
  8871. if ($info['cs'] == 'Indexed') {
  8872. $maxval =(pow(2, $info['bpc']) - 1);
  8873. for ($i = 0; $i < $count_info; ++$i) {
  8874. if (($info['trns'][$i] != 0) AND ($info['trns'][$i] != $maxval)) {
  8875. // this is not a binary type mask @TODO: create a SMask
  8876. $trns = '';
  8877. break;
  8878. } elseif (empty($trns) AND ($info['trns'][$i] == 0)) {
  8879. // store the first fully transparent value
  8880. $trns .= $i.' '.$i.' ';
  8881. }
  8882. }
  8883. } else {
  8884. // grayscale or RGB
  8885. for ($i = 0; $i < $count_info; ++$i) {
  8886. if ($info['trns'][$i] == 0) {
  8887. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  8888. }
  8889. }
  8890. }
  8891. // Colour Key Masking
  8892. if (!empty($trns)) {
  8893. $out .= ' /Mask ['.$trns.']';
  8894. }
  8895. }
  8896. $stream = $this->_getrawstream($info['data']);
  8897. $out .= ' /Length '.strlen($stream).' >>';
  8898. $out .= ' stream'."\n".$stream."\n".'endstream';
  8899. }
  8900. $out .= "\n".'endobj';
  8901. $this->_out($out);
  8902. if ($icc) {
  8903. // ICC colour profile
  8904. $this->_newobj();
  8905. $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
  8906. $icc = $this->_getrawstream($icc);
  8907. $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  8908. } elseif ($info['cs'] == 'Indexed') {
  8909. // colour palette
  8910. $this->_newobj();
  8911. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  8912. $pal = $this->_getrawstream($pal);
  8913. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  8914. }
  8915. }
  8916. }
  8917. /**
  8918. * Output Form XObjects Templates.
  8919. * @author Nicola Asuni
  8920. * @since 5.8.017 (2010-08-24)
  8921. * @protected
  8922. * @see startTemplate(), endTemplate(), printTemplate()
  8923. */
  8924. protected function _putxobjects() {
  8925. foreach ($this->xobjects as $key => $data) {
  8926. if (isset($data['outdata'])) {
  8927. $stream = str_replace($this->epsmarker, '', trim($data['outdata']));
  8928. $out = $this->_getobj($data['n'])."\n";
  8929. $out .= '<<';
  8930. $out .= ' /Type /XObject';
  8931. $out .= ' /Subtype /Form';
  8932. $out .= ' /FormType 1';
  8933. if ($this->compress) {
  8934. $stream = gzcompress($stream);
  8935. $out .= ' /Filter /FlateDecode';
  8936. }
  8937. $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));
  8938. $out .= ' /Matrix [1 0 0 1 0 0]';
  8939. $out .= ' /Resources <<';
  8940. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8941. if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  8942. // transparency
  8943. if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
  8944. $out .= ' /ExtGState <<';
  8945. foreach ($data['extgstates'] as $k => $extgstate) {
  8946. if (isset($this->extgstates[$k]['name'])) {
  8947. $out .= ' /'.$this->extgstates[$k]['name'];
  8948. } else {
  8949. $out .= ' /GS'.$k;
  8950. }
  8951. $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
  8952. }
  8953. $out .= ' >>';
  8954. }
  8955. if (isset($data['gradients']) AND !empty($data['gradients'])) {
  8956. $gp = '';
  8957. $gs = '';
  8958. foreach ($data['gradients'] as $id => $grad) {
  8959. // gradient patterns
  8960. $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
  8961. // gradient shadings
  8962. $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
  8963. }
  8964. $out .= ' /Pattern <<'.$gp.' >>';
  8965. $out .= ' /Shading <<'.$gs.' >>';
  8966. }
  8967. }
  8968. // spot colors
  8969. if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
  8970. $out .= ' /ColorSpace <<';
  8971. foreach ($data['spot_colors'] as $name => $color) {
  8972. $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
  8973. }
  8974. $out .= ' >>';
  8975. }
  8976. // fonts
  8977. if (!empty($data['fonts'])) {
  8978. $out .= ' /Font <<';
  8979. foreach ($data['fonts'] as $fontkey => $fontid) {
  8980. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  8981. }
  8982. $out .= ' >>';
  8983. }
  8984. // images or nested xobjects
  8985. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  8986. $out .= ' /XObject <<';
  8987. foreach ($data['images'] as $imgid) {
  8988. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  8989. }
  8990. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  8991. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  8992. }
  8993. $out .= ' >>';
  8994. }
  8995. $out .= ' >>'; //end resources
  8996. if (isset($data['group']) AND ($data['group'] !== false)) {
  8997. // set transparency group
  8998. $out .= ' /Group << /Type /Group /S /Transparency';
  8999. if (is_array($data['group'])) {
  9000. if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
  9001. $out .= ' /CS /'.$data['group']['CS'];
  9002. }
  9003. if (isset($data['group']['I'])) {
  9004. $out .= ' /I /'.($data['group']['I']===true?'true':'false');
  9005. }
  9006. if (isset($data['group']['K'])) {
  9007. $out .= ' /K /'.($data['group']['K']===true?'true':'false');
  9008. }
  9009. }
  9010. $out .= ' >>';
  9011. }
  9012. $stream = $this->_getrawstream($stream, $data['n']);
  9013. $out .= ' /Length '.strlen($stream);
  9014. $out .= ' >>';
  9015. $out .= ' stream'."\n".$stream."\n".'endstream';
  9016. $out .= "\n".'endobj';
  9017. $this->_out($out);
  9018. }
  9019. }
  9020. }
  9021. /**
  9022. * Output Spot Colors Resources.
  9023. * @protected
  9024. * @since 4.0.024 (2008-09-12)
  9025. */
  9026. protected function _putspotcolors() {
  9027. foreach ($this->spot_colors as $name => $color) {
  9028. $this->_newobj();
  9029. $this->spot_colors[$name]['n'] = $this->n;
  9030. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  9031. $out .= ' /DeviceCMYK <<';
  9032. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  9033. $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
  9034. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  9035. $out .= "\n".'endobj';
  9036. $this->_out($out);
  9037. }
  9038. }
  9039. /**
  9040. * Return XObjects Dictionary.
  9041. * @return string XObjects dictionary
  9042. * @protected
  9043. * @since 5.8.014 (2010-08-23)
  9044. */
  9045. protected function _getxobjectdict() {
  9046. $out = '';
  9047. foreach ($this->xobjects as $id => $objid) {
  9048. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  9049. }
  9050. return $out;
  9051. }
  9052. /**
  9053. * Output Resources Dictionary.
  9054. * @protected
  9055. */
  9056. protected function _putresourcedict() {
  9057. $out = $this->_getobj(2)."\n";
  9058. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  9059. $out .= ' /Font <<';
  9060. foreach ($this->fontkeys as $fontkey) {
  9061. $font = $this->getFontBuffer($fontkey);
  9062. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  9063. }
  9064. $out .= ' >>';
  9065. $out .= ' /XObject <<';
  9066. $out .= $this->_getxobjectdict();
  9067. $out .= ' >>';
  9068. // layers
  9069. if (!empty($this->pdflayers)) {
  9070. $out .= ' /Properties <<';
  9071. foreach ($this->pdflayers as $layer) {
  9072. $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
  9073. }
  9074. $out .= ' >>';
  9075. }
  9076. if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  9077. // transparency
  9078. if (isset($this->extgstates) AND !empty($this->extgstates)) {
  9079. $out .= ' /ExtGState <<';
  9080. foreach ($this->extgstates as $k => $extgstate) {
  9081. if (isset($extgstate['name'])) {
  9082. $out .= ' /'.$extgstate['name'];
  9083. } else {
  9084. $out .= ' /GS'.$k;
  9085. }
  9086. $out .= ' '.$extgstate['n'].' 0 R';
  9087. }
  9088. $out .= ' >>';
  9089. }
  9090. if (isset($this->gradients) AND !empty($this->gradients)) {
  9091. $gp = '';
  9092. $gs = '';
  9093. foreach ($this->gradients as $id => $grad) {
  9094. // gradient patterns
  9095. $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  9096. // gradient shadings
  9097. $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  9098. }
  9099. $out .= ' /Pattern <<'.$gp.' >>';
  9100. $out .= ' /Shading <<'.$gs.' >>';
  9101. }
  9102. }
  9103. // spot colors
  9104. if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
  9105. $out .= ' /ColorSpace <<';
  9106. foreach ($this->spot_colors as $color) {
  9107. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  9108. }
  9109. $out .= ' >>';
  9110. }
  9111. $out .= ' >>';
  9112. $out .= "\n".'endobj';
  9113. $this->_out($out);
  9114. }
  9115. /**
  9116. * Output Resources.
  9117. * @protected
  9118. */
  9119. protected function _putresources() {
  9120. $this->_putextgstates();
  9121. $this->_putocg();
  9122. $this->_putfonts();
  9123. $this->_putimages();
  9124. $this->_putspotcolors();
  9125. $this->_putshaders();
  9126. $this->_putxobjects();
  9127. $this->_putresourcedict();
  9128. $this->_putdests();
  9129. $this->_putEmbeddedFiles();
  9130. $this->_putannotsobjs();
  9131. $this->_putjavascript();
  9132. $this->_putbookmarks();
  9133. $this->_putencryption();
  9134. }
  9135. /**
  9136. * Adds some Metadata information (Document Information Dictionary)
  9137. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  9138. * @return int object id
  9139. * @protected
  9140. */
  9141. protected function _putinfo() {
  9142. $oid = $this->_newobj();
  9143. $out = '<<';
  9144. // store current isunicode value
  9145. $prev_isunicode = $this->isunicode;
  9146. if ($this->docinfounicode) {
  9147. $this->isunicode = true;
  9148. }
  9149. if (!TCPDF_STATIC::empty_string($this->title)) {
  9150. // The document's title.
  9151. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  9152. }
  9153. if (!TCPDF_STATIC::empty_string($this->author)) {
  9154. // The name of the person who created the document.
  9155. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  9156. }
  9157. if (!TCPDF_STATIC::empty_string($this->subject)) {
  9158. // The subject of the document.
  9159. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  9160. }
  9161. if (!TCPDF_STATIC::empty_string($this->keywords)) {
  9162. // Keywords associated with the document.
  9163. $out .= ' /Keywords '.$this->_textstring($this->keywords, $oid);
  9164. }
  9165. if (!TCPDF_STATIC::empty_string($this->creator)) {
  9166. // 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.
  9167. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  9168. }
  9169. // restore previous isunicode value
  9170. $this->isunicode = $prev_isunicode;
  9171. // default producer
  9172. $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid);
  9173. // The date and time the document was created, in human-readable form
  9174. $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp);
  9175. // The date and time the document was most recently modified, in human-readable form
  9176. $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp);
  9177. // A name object indicating whether the document has been modified to include trapping information
  9178. $out .= ' /Trapped /False';
  9179. $out .= ' >>';
  9180. $out .= "\n".'endobj';
  9181. $this->_out($out);
  9182. return $oid;
  9183. }
  9184. /**
  9185. * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
  9186. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9187. * @param string $xmp Custom XMP data.
  9188. * @since 5.9.128 (2011-10-06)
  9189. * @public
  9190. */
  9191. public function setExtraXMP($xmp) {
  9192. $this->custom_xmp = $xmp;
  9193. }
  9194. /**
  9195. * Set additional XMP data to be added on the default XMP data just before the end of "rdf:RDF" tag.
  9196. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9197. * @param string $xmp Custom XMP RDF data.
  9198. * @since 6.3.0 (2019-09-19)
  9199. * @public
  9200. */
  9201. public function setExtraXMPRDF($xmp) {
  9202. $this->custom_xmp_rdf = $xmp;
  9203. }
  9204. /**
  9205. * Put XMP data object and return ID.
  9206. * @return int The object ID.
  9207. * @since 5.9.121 (2011-09-28)
  9208. * @protected
  9209. */
  9210. protected function _putXMP() {
  9211. $oid = $this->_newobj();
  9212. // store current isunicode value
  9213. $prev_isunicode = $this->isunicode;
  9214. $this->isunicode = true;
  9215. $prev_encrypted = $this->encrypted;
  9216. $this->encrypted = false;
  9217. // set XMP data
  9218. $xmp = '<?xpacket begin="'.TCPDF_FONTS::unichr(0xfeff, $this->isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
  9219. $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";
  9220. $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  9221. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  9222. $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
  9223. $xmp .= "\t\t\t".'<dc:title>'."\n";
  9224. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9225. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->title).'</rdf:li>'."\n";
  9226. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9227. $xmp .= "\t\t\t".'</dc:title>'."\n";
  9228. $xmp .= "\t\t\t".'<dc:creator>'."\n";
  9229. $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
  9230. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->author).'</rdf:li>'."\n";
  9231. $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
  9232. $xmp .= "\t\t\t".'</dc:creator>'."\n";
  9233. $xmp .= "\t\t\t".'<dc:description>'."\n";
  9234. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9235. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->subject).'</rdf:li>'."\n";
  9236. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9237. $xmp .= "\t\t\t".'</dc:description>'."\n";
  9238. $xmp .= "\t\t\t".'<dc:subject>'."\n";
  9239. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9240. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->keywords).'</rdf:li>'."\n";
  9241. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9242. $xmp .= "\t\t\t".'</dc:subject>'."\n";
  9243. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9244. // convert doc creation date format
  9245. $dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
  9246. $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
  9247. $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
  9248. $doccreationdate .= substr($dcdate, 14, 3).':'.substr($dcdate, 18, 2);
  9249. $doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate);
  9250. // convert doc modification date format
  9251. $dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
  9252. $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
  9253. $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
  9254. $docmoddate .= substr($dmdate, 14, 3).':'.substr($dmdate, 18, 2);
  9255. $docmoddate = TCPDF_STATIC::_escapeXML($docmoddate);
  9256. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  9257. $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
  9258. $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  9259. $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
  9260. $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
  9261. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9262. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  9263. $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC::_escapeXML($this->keywords).'</pdf:Keywords>'."\n";
  9264. $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).'</pdf:Producer>'."\n";
  9265. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9266. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  9267. $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);
  9268. $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
  9269. $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
  9270. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9271. if ($this->pdfa_mode) {
  9272. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
  9273. $xmp .= "\t\t\t".'<pdfaid:part>'.$this->pdfa_version.'</pdfaid:part>'."\n";
  9274. $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
  9275. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9276. }
  9277. // XMP extension schemas
  9278. $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";
  9279. $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
  9280. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9281. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9282. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
  9283. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
  9284. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
  9285. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9286. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9287. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9288. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9289. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Adobe PDF Schema</pdfaProperty:description>'."\n";
  9290. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9291. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9292. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9293. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9294. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9295. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9296. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9297. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
  9298. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
  9299. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
  9300. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9301. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9302. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9303. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9304. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
  9305. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9306. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9307. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9308. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9309. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9310. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9311. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9312. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
  9313. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
  9314. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
  9315. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9316. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9317. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9318. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9319. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
  9320. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
  9321. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
  9322. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9323. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9324. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9325. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
  9326. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
  9327. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9328. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9329. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9330. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9331. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
  9332. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
  9333. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9334. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9335. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9336. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9337. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9338. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9339. $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
  9340. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9341. $xmp .= $this->custom_xmp_rdf;
  9342. $xmp .= "\t".'</rdf:RDF>'."\n";
  9343. $xmp .= $this->custom_xmp;
  9344. $xmp .= '</x:xmpmeta>'."\n";
  9345. $xmp .= '<?xpacket end="w"?>';
  9346. $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
  9347. // restore previous isunicode value
  9348. $this->isunicode = $prev_isunicode;
  9349. $this->encrypted = $prev_encrypted;
  9350. $this->_out($out);
  9351. return $oid;
  9352. }
  9353. /**
  9354. * Output Catalog.
  9355. * @return int object id
  9356. * @protected
  9357. */
  9358. protected function _putcatalog() {
  9359. // put XMP
  9360. $xmpobj = $this->_putXMP();
  9361. // if required, add standard sRGB ICC colour profile
  9362. if ($this->pdfa_mode OR $this->force_srgb) {
  9363. $iccobj = $this->_newobj();
  9364. $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
  9365. $filter = '';
  9366. if ($this->compress) {
  9367. $filter = ' /Filter /FlateDecode';
  9368. $icc = gzcompress($icc);
  9369. }
  9370. $icc = $this->_getrawstream($icc);
  9371. $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  9372. }
  9373. // start catalog
  9374. $oid = $this->_newobj();
  9375. $out = '<< /Type /Catalog';
  9376. $out .= ' /Version /'.$this->PDFVersion;
  9377. //$out .= ' /Extensions <<>>';
  9378. $out .= ' /Pages 1 0 R';
  9379. //$out .= ' /PageLabels ' //...;
  9380. $out .= ' /Names <<';
  9381. if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
  9382. $out .= ' /JavaScript '.$this->n_js;
  9383. }
  9384. if (!empty($this->efnames)) {
  9385. $out .= ' /EmbeddedFiles <</Names [';
  9386. foreach ($this->efnames AS $fn => $fref) {
  9387. $out .= ' '.$this->_datastring($fn).' '.$fref;
  9388. }
  9389. $out .= ' ]>>';
  9390. }
  9391. $out .= ' >>';
  9392. if (!empty($this->dests)) {
  9393. $out .= ' /Dests '.($this->n_dests).' 0 R';
  9394. }
  9395. $out .= $this->_putviewerpreferences();
  9396. if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) {
  9397. $out .= ' /PageLayout /'.$this->LayoutMode;
  9398. }
  9399. if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) {
  9400. $out .= ' /PageMode /'.$this->PageMode;
  9401. }
  9402. if (count($this->outlines) > 0) {
  9403. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  9404. $out .= ' /PageMode /UseOutlines';
  9405. }
  9406. //$out .= ' /Threads []';
  9407. if ($this->ZoomMode == 'fullpage') {
  9408. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  9409. } elseif ($this->ZoomMode == 'fullwidth') {
  9410. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  9411. } elseif ($this->ZoomMode == 'real') {
  9412. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  9413. } elseif (!is_string($this->ZoomMode)) {
  9414. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode / 100));
  9415. }
  9416. //$out .= ' /AA <<>>';
  9417. //$out .= ' /URI <<>>';
  9418. $out .= ' /Metadata '.$xmpobj.' 0 R';
  9419. //$out .= ' /StructTreeRoot <<>>';
  9420. //$out .= ' /MarkInfo <<>>';
  9421. if (isset($this->l['a_meta_language'])) {
  9422. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  9423. }
  9424. //$out .= ' /SpiderInfo <<>>';
  9425. // set OutputIntent to sRGB IEC61966-2.1 if required
  9426. if ($this->pdfa_mode OR $this->force_srgb) {
  9427. $out .= ' /OutputIntents [<<';
  9428. $out .= ' /Type /OutputIntent';
  9429. $out .= ' /S /GTS_PDFA1';
  9430. $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9431. $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9432. $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
  9433. $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9434. $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
  9435. $out .= ' >>]';
  9436. }
  9437. //$out .= ' /PieceInfo <<>>';
  9438. if (!empty($this->pdflayers)) {
  9439. $lyrobjs = '';
  9440. $lyrobjs_off = '';
  9441. $lyrobjs_lock = '';
  9442. foreach ($this->pdflayers as $layer) {
  9443. $layer_obj_ref = ' '.$layer['objid'].' 0 R';
  9444. $lyrobjs .= $layer_obj_ref;
  9445. if ($layer['view'] === false) {
  9446. $lyrobjs_off .= $layer_obj_ref;
  9447. }
  9448. if ($layer['lock']) {
  9449. $lyrobjs_lock .= $layer_obj_ref;
  9450. }
  9451. }
  9452. $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
  9453. $out .= ' /D <<';
  9454. $out .= ' /Name '.$this->_textstring('Layers', $oid);
  9455. $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
  9456. $out .= ' /BaseState /ON';
  9457. $out .= ' /OFF ['.$lyrobjs_off.']';
  9458. $out .= ' /Locked ['.$lyrobjs_lock.']';
  9459. $out .= ' /Intent /View';
  9460. $out .= ' /AS [';
  9461. $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
  9462. $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
  9463. $out .= ' ]';
  9464. $out .= ' /Order ['.$lyrobjs.']';
  9465. $out .= ' /ListMode /AllPages';
  9466. //$out .= ' /RBGroups ['..']';
  9467. //$out .= ' /Locked ['..']';
  9468. $out .= ' >>';
  9469. $out .= ' >>';
  9470. }
  9471. // AcroForm
  9472. if (!empty($this->form_obj_id)
  9473. OR ($this->sign AND isset($this->signature_data['cert_type']))
  9474. OR !empty($this->empty_signature_appearance)) {
  9475. $out .= ' /AcroForm <<';
  9476. $objrefs = '';
  9477. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9478. // set reference for signature object
  9479. $objrefs .= $this->sig_obj_id.' 0 R';
  9480. }
  9481. if (!empty($this->empty_signature_appearance)) {
  9482. foreach ($this->empty_signature_appearance as $esa) {
  9483. // set reference for empty signature objects
  9484. $objrefs .= ' '.$esa['objid'].' 0 R';
  9485. }
  9486. }
  9487. if (!empty($this->form_obj_id)) {
  9488. foreach($this->form_obj_id as $objid) {
  9489. $objrefs .= ' '.$objid.' 0 R';
  9490. }
  9491. }
  9492. $out .= ' /Fields ['.$objrefs.']';
  9493. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  9494. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  9495. $out .= ' /NeedAppearances false';
  9496. }
  9497. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9498. if ($this->signature_data['cert_type'] > 0) {
  9499. $out .= ' /SigFlags 3';
  9500. } else {
  9501. $out .= ' /SigFlags 1';
  9502. }
  9503. }
  9504. //$out .= ' /CO ';
  9505. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  9506. $out .= ' /DR <<';
  9507. $out .= ' /Font <<';
  9508. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  9509. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9510. }
  9511. $out .= ' >> >>';
  9512. }
  9513. $font = $this->getFontBuffer((($this->pdfa_mode) ? 'pdfa' : '') .'helvetica');
  9514. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  9515. $out .= ' /Q '.(($this->rtl)?'2':'0');
  9516. //$out .= ' /XFA ';
  9517. $out .= ' >>';
  9518. // signatures
  9519. if ($this->sign AND isset($this->signature_data['cert_type'])
  9520. AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) {
  9521. if ($this->signature_data['cert_type'] > 0) {
  9522. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  9523. } else {
  9524. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  9525. }
  9526. }
  9527. }
  9528. //$out .= ' /Legal <<>>';
  9529. //$out .= ' /Requirements []';
  9530. //$out .= ' /Collection <<>>';
  9531. //$out .= ' /NeedsRendering true';
  9532. $out .= ' >>';
  9533. $out .= "\n".'endobj';
  9534. $this->_out($out);
  9535. return $oid;
  9536. }
  9537. /**
  9538. * Output viewer preferences.
  9539. * @return string for viewer preferences
  9540. * @author Nicola asuni
  9541. * @since 3.1.000 (2008-06-09)
  9542. * @protected
  9543. */
  9544. protected function _putviewerpreferences() {
  9545. $vp = $this->viewer_preferences;
  9546. $out = ' /ViewerPreferences <<';
  9547. if ($this->rtl) {
  9548. $out .= ' /Direction /R2L';
  9549. } else {
  9550. $out .= ' /Direction /L2R';
  9551. }
  9552. if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
  9553. $out .= ' /HideToolbar true';
  9554. }
  9555. if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
  9556. $out .= ' /HideMenubar true';
  9557. }
  9558. if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
  9559. $out .= ' /HideWindowUI true';
  9560. }
  9561. if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
  9562. $out .= ' /FitWindow true';
  9563. }
  9564. if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
  9565. $out .= ' /CenterWindow true';
  9566. }
  9567. if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
  9568. $out .= ' /DisplayDocTitle true';
  9569. }
  9570. if (isset($vp['NonFullScreenPageMode'])) {
  9571. $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
  9572. }
  9573. if (isset($vp['ViewArea'])) {
  9574. $out .= ' /ViewArea /'.$vp['ViewArea'];
  9575. }
  9576. if (isset($vp['ViewClip'])) {
  9577. $out .= ' /ViewClip /'.$vp['ViewClip'];
  9578. }
  9579. if (isset($vp['PrintArea'])) {
  9580. $out .= ' /PrintArea /'.$vp['PrintArea'];
  9581. }
  9582. if (isset($vp['PrintClip'])) {
  9583. $out .= ' /PrintClip /'.$vp['PrintClip'];
  9584. }
  9585. if (isset($vp['PrintScaling'])) {
  9586. $out .= ' /PrintScaling /'.$vp['PrintScaling'];
  9587. }
  9588. if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) {
  9589. $out .= ' /Duplex /'.$vp['Duplex'];
  9590. }
  9591. if (isset($vp['PickTrayByPDFSize'])) {
  9592. if ($vp['PickTrayByPDFSize']) {
  9593. $out .= ' /PickTrayByPDFSize true';
  9594. } else {
  9595. $out .= ' /PickTrayByPDFSize false';
  9596. }
  9597. }
  9598. if (isset($vp['PrintPageRange'])) {
  9599. $PrintPageRangeNum = '';
  9600. foreach ($vp['PrintPageRange'] as $k => $v) {
  9601. $PrintPageRangeNum .= ' '.($v - 1).'';
  9602. }
  9603. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  9604. }
  9605. if (isset($vp['NumCopies'])) {
  9606. $out .= ' /NumCopies '.intval($vp['NumCopies']);
  9607. }
  9608. $out .= ' >>';
  9609. return $out;
  9610. }
  9611. /**
  9612. * Output PDF File Header (7.5.2).
  9613. * @protected
  9614. */
  9615. protected function _putheader() {
  9616. $this->_out('%PDF-'.$this->PDFVersion);
  9617. $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
  9618. }
  9619. /**
  9620. * Output end of document (EOF).
  9621. * @protected
  9622. */
  9623. protected function _enddoc() {
  9624. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  9625. // save subset chars of the previous font
  9626. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  9627. }
  9628. $this->state = 1;
  9629. $this->_putheader();
  9630. $this->_putpages();
  9631. $this->_putresources();
  9632. // empty signature fields
  9633. if (!empty($this->empty_signature_appearance)) {
  9634. foreach ($this->empty_signature_appearance as $key => $esa) {
  9635. // widget annotation for empty signature
  9636. $out = $this->_getobj($esa['objid'])."\n";
  9637. $out .= '<< /Type /Annot';
  9638. $out .= ' /Subtype /Widget';
  9639. $out .= ' /Rect ['.$esa['rect'].']';
  9640. $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
  9641. $out .= ' /F 4';
  9642. $out .= ' /FT /Sig';
  9643. $signame = $esa['name'].sprintf(' [%03d]', ($key + 1));
  9644. $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
  9645. $out .= ' /Ff 0';
  9646. $out .= ' >>';
  9647. $out .= "\n".'endobj';
  9648. $this->_out($out);
  9649. }
  9650. }
  9651. // Signature
  9652. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9653. // widget annotation for signature
  9654. $out = $this->_getobj($this->sig_obj_id)."\n";
  9655. $out .= '<< /Type /Annot';
  9656. $out .= ' /Subtype /Widget';
  9657. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  9658. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  9659. $out .= ' /F 4';
  9660. $out .= ' /FT /Sig';
  9661. $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id);
  9662. $out .= ' /Ff 0';
  9663. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  9664. $out .= ' >>';
  9665. $out .= "\n".'endobj';
  9666. $this->_out($out);
  9667. // signature
  9668. $this->_putsignature();
  9669. }
  9670. // Info
  9671. $objid_info = $this->_putinfo();
  9672. // Catalog
  9673. $objid_catalog = $this->_putcatalog();
  9674. // Cross-ref
  9675. $o = $this->bufferlen;
  9676. // XREF section
  9677. $this->_out('xref');
  9678. $this->_out('0 '.($this->n + 1));
  9679. $this->_out('0000000000 65535 f ');
  9680. $freegen = ($this->n + 2);
  9681. for ($i=1; $i <= $this->n; ++$i) {
  9682. if (!isset($this->offsets[$i]) AND ($i > 1)) {
  9683. $this->_out(sprintf('0000000000 %05d f ', $freegen));
  9684. ++$freegen;
  9685. } else {
  9686. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  9687. }
  9688. }
  9689. // TRAILER
  9690. $out = 'trailer'."\n";
  9691. $out .= '<<';
  9692. $out .= ' /Size '.($this->n + 1);
  9693. $out .= ' /Root '.$objid_catalog.' 0 R';
  9694. $out .= ' /Info '.$objid_info.' 0 R';
  9695. if ($this->encrypted) {
  9696. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  9697. }
  9698. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  9699. $out .= ' >>';
  9700. $this->_out($out);
  9701. $this->_out('startxref');
  9702. $this->_out($o);
  9703. $this->_out('%%EOF');
  9704. $this->state = 3; // end-of-doc
  9705. }
  9706. /**
  9707. * Initialize a new page.
  9708. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  9709. * @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().
  9710. * @protected
  9711. * @see getPageSizeFromFormat(), setPageFormat()
  9712. */
  9713. protected function _beginpage($orientation='', $format='') {
  9714. ++$this->page;
  9715. $this->pageobjects[$this->page] = array();
  9716. $this->setPageBuffer($this->page, '');
  9717. // initialize array for graphics tranformation positions inside a page buffer
  9718. $this->transfmrk[$this->page] = array();
  9719. $this->state = 2;
  9720. if (TCPDF_STATIC::empty_string($orientation)) {
  9721. if (isset($this->CurOrientation)) {
  9722. $orientation = $this->CurOrientation;
  9723. } elseif ($this->fwPt > $this->fhPt) {
  9724. // landscape
  9725. $orientation = 'L';
  9726. } else {
  9727. // portrait
  9728. $orientation = 'P';
  9729. }
  9730. }
  9731. if (TCPDF_STATIC::empty_string($format)) {
  9732. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  9733. $this->setPageOrientation($orientation);
  9734. } else {
  9735. $this->setPageFormat($format, $orientation);
  9736. }
  9737. if ($this->rtl) {
  9738. $this->x = $this->w - $this->rMargin;
  9739. } else {
  9740. $this->x = $this->lMargin;
  9741. }
  9742. $this->y = $this->tMargin;
  9743. if (isset($this->newpagegroup[$this->page])) {
  9744. // start a new group
  9745. $this->currpagegroup = $this->newpagegroup[$this->page];
  9746. $this->pagegroups[$this->currpagegroup] = 1;
  9747. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  9748. ++$this->pagegroups[$this->currpagegroup];
  9749. }
  9750. }
  9751. /**
  9752. * Mark end of page.
  9753. * @protected
  9754. */
  9755. protected function _endpage() {
  9756. $this->setVisibility('all');
  9757. $this->state = 1;
  9758. }
  9759. /**
  9760. * Begin a new object and return the object number.
  9761. * @return int object number
  9762. * @protected
  9763. */
  9764. protected function _newobj() {
  9765. $this->_out($this->_getobj());
  9766. return $this->n;
  9767. }
  9768. /**
  9769. * Return the starting object string for the selected object ID.
  9770. * @param int|null $objid Object ID (leave empty to get a new ID).
  9771. * @return string the starting object string
  9772. * @protected
  9773. * @since 5.8.009 (2010-08-20)
  9774. */
  9775. protected function _getobj($objid=null) {
  9776. if (TCPDF_STATIC::empty_string($objid)) {
  9777. ++$this->n;
  9778. $objid = $this->n;
  9779. }
  9780. $this->offsets[$objid] = $this->bufferlen;
  9781. $this->pageobjects[$this->page][] = $objid;
  9782. return $objid.' 0 obj';
  9783. }
  9784. /**
  9785. * Underline text.
  9786. * @param int $x X coordinate
  9787. * @param int $y Y coordinate
  9788. * @param string $txt text to underline
  9789. * @protected
  9790. */
  9791. protected function _dounderline($x, $y, $txt) {
  9792. $w = $this->GetStringWidth($txt);
  9793. return $this->_dounderlinew($x, $y, $w);
  9794. }
  9795. /**
  9796. * Underline for rectangular text area.
  9797. * @param int $x X coordinate
  9798. * @param int $y Y coordinate
  9799. * @param int $w width to underline
  9800. * @protected
  9801. * @since 4.8.008 (2009-09-29)
  9802. */
  9803. protected function _dounderlinew($x, $y, $w) {
  9804. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9805. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  9806. }
  9807. /**
  9808. * Line through text.
  9809. * @param int $x X coordinate
  9810. * @param int $y Y coordinate
  9811. * @param string $txt text to linethrough
  9812. * @protected
  9813. */
  9814. protected function _dolinethrough($x, $y, $txt) {
  9815. $w = $this->GetStringWidth($txt);
  9816. return $this->_dolinethroughw($x, $y, $w);
  9817. }
  9818. /**
  9819. * Line through for rectangular text area.
  9820. * @param int $x X coordinate
  9821. * @param int $y Y coordinate
  9822. * @param int $w line length (width)
  9823. * @protected
  9824. * @since 4.9.008 (2009-09-29)
  9825. */
  9826. protected function _dolinethroughw($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->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  9829. }
  9830. /**
  9831. * Overline text.
  9832. * @param int $x X coordinate
  9833. * @param int $y Y coordinate
  9834. * @param string $txt text to overline
  9835. * @protected
  9836. * @since 4.9.015 (2010-04-19)
  9837. */
  9838. protected function _dooverline($x, $y, $txt) {
  9839. $w = $this->GetStringWidth($txt);
  9840. return $this->_dooverlinew($x, $y, $w);
  9841. }
  9842. /**
  9843. * Overline for rectangular text area.
  9844. * @param int $x X coordinate
  9845. * @param int $y Y coordinate
  9846. * @param int $w width to overline
  9847. * @protected
  9848. * @since 4.9.015 (2010-04-19)
  9849. */
  9850. protected function _dooverlinew($x, $y, $w) {
  9851. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9852. return sprintf('%F %F %F %F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  9853. }
  9854. /**
  9855. * Format a data string for meta information
  9856. * @param string $s data string to escape.
  9857. * @param int $n object ID
  9858. * @return string escaped string.
  9859. * @protected
  9860. */
  9861. protected function _datastring($s, $n=0) {
  9862. if ($n == 0) {
  9863. $n = $this->n;
  9864. }
  9865. $s = $this->_encrypt_data($n, $s);
  9866. return '('. TCPDF_STATIC::_escape($s).')';
  9867. }
  9868. /**
  9869. * Set the document creation timestamp
  9870. * @param mixed $time Document creation timestamp in seconds or date-time string.
  9871. * @public
  9872. * @since 5.9.152 (2012-03-23)
  9873. */
  9874. public function setDocCreationTimestamp($time) {
  9875. if (is_string($time)) {
  9876. $time = TCPDF_STATIC::getTimestamp($time);
  9877. }
  9878. $this->doc_creation_timestamp = intval($time);
  9879. }
  9880. /**
  9881. * Set the document modification timestamp
  9882. * @param mixed $time Document modification timestamp in seconds or date-time string.
  9883. * @public
  9884. * @since 5.9.152 (2012-03-23)
  9885. */
  9886. public function setDocModificationTimestamp($time) {
  9887. if (is_string($time)) {
  9888. $time = TCPDF_STATIC::getTimestamp($time);
  9889. }
  9890. $this->doc_modification_timestamp = intval($time);
  9891. }
  9892. /**
  9893. * Returns document creation timestamp in seconds.
  9894. * @return int Creation timestamp in seconds.
  9895. * @public
  9896. * @since 5.9.152 (2012-03-23)
  9897. */
  9898. public function getDocCreationTimestamp() {
  9899. return $this->doc_creation_timestamp;
  9900. }
  9901. /**
  9902. * Returns document modification timestamp in seconds.
  9903. * @return int Modfication timestamp in seconds.
  9904. * @public
  9905. * @since 5.9.152 (2012-03-23)
  9906. */
  9907. public function getDocModificationTimestamp() {
  9908. return $this->doc_modification_timestamp;
  9909. }
  9910. /**
  9911. * Returns a formatted date for meta information
  9912. * @param int $n Object ID.
  9913. * @param int $timestamp Timestamp to convert.
  9914. * @return string escaped date string.
  9915. * @protected
  9916. * @since 4.6.028 (2009-08-25)
  9917. */
  9918. protected function _datestring($n=0, $timestamp=0) {
  9919. if ((empty($timestamp)) OR ($timestamp < 0)) {
  9920. $timestamp = $this->doc_creation_timestamp;
  9921. }
  9922. return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n);
  9923. }
  9924. /**
  9925. * Format a text string for meta information
  9926. * @param string $s string to escape.
  9927. * @param int $n object ID
  9928. * @return string escaped string.
  9929. * @protected
  9930. */
  9931. protected function _textstring($s, $n=0) {
  9932. if ($this->isunicode) {
  9933. //Convert string to UTF-16BE
  9934. $s = TCPDF_FONTS::UTF8ToUTF16BE($s, true, $this->isunicode, $this->CurrentFont);
  9935. }
  9936. return $this->_datastring($s, $n);
  9937. }
  9938. /**
  9939. * get raw output stream.
  9940. * @param string $s string to output.
  9941. * @param int $n object reference for encryption mode
  9942. * @protected
  9943. * @author Nicola Asuni
  9944. * @since 5.5.000 (2010-06-22)
  9945. */
  9946. protected function _getrawstream($s, $n=0) {
  9947. if ($n <= 0) {
  9948. // default to current object
  9949. $n = $this->n;
  9950. }
  9951. return $this->_encrypt_data($n, $s);
  9952. }
  9953. /**
  9954. * Output a string to the document.
  9955. * @param string $s string to output.
  9956. * @protected
  9957. */
  9958. protected function _out($s) {
  9959. if ($this->state == 2) {
  9960. if ($this->inxobj) {
  9961. // we are inside an XObject template
  9962. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  9963. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  9964. // puts data before page footer
  9965. $pagebuff = $this->getPageBuffer($this->page);
  9966. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  9967. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  9968. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  9969. // update footer position
  9970. $this->footerpos[$this->page] += strlen($s."\n");
  9971. } else {
  9972. // set page data
  9973. $this->setPageBuffer($this->page, $s."\n", true);
  9974. }
  9975. } elseif ($this->state > 0) {
  9976. // set general data
  9977. $this->setBuffer($s."\n");
  9978. }
  9979. }
  9980. /**
  9981. * Set header font.
  9982. * @param array<int,string|float|null> $font Array describing the basic font parameters: (family, style, size).
  9983. * @phpstan-param array{0: string, 1: string, 2: float|null} $font
  9984. * @public
  9985. * @since 1.1
  9986. */
  9987. public function setHeaderFont($font) {
  9988. $this->header_font = $font;
  9989. }
  9990. /**
  9991. * Get header font.
  9992. * @return array<int,string|float|null> Array describing the basic font parameters: (family, style, size).
  9993. * @phpstan-return array{0: string, 1: string, 2: float|null}
  9994. * @public
  9995. * @since 4.0.012 (2008-07-24)
  9996. */
  9997. public function getHeaderFont() {
  9998. return $this->header_font;
  9999. }
  10000. /**
  10001. * Set footer font.
  10002. * @param array<int,string|float|null> $font Array describing the basic font parameters: (family, style, size).
  10003. * @phpstan-param array{0: string, 1: string, 2: float|null} $font
  10004. * @public
  10005. * @since 1.1
  10006. */
  10007. public function setFooterFont($font) {
  10008. $this->footer_font = $font;
  10009. }
  10010. /**
  10011. * Get Footer font.
  10012. * @return array<int,string|float|null> Array describing the basic font parameters: (family, style, size).
  10013. * @phpstan-return array{0: string, 1: string, 2: float|null} $font
  10014. * @public
  10015. * @since 4.0.012 (2008-07-24)
  10016. */
  10017. public function getFooterFont() {
  10018. return $this->footer_font;
  10019. }
  10020. /**
  10021. * Set language array.
  10022. * @param array $language
  10023. * @public
  10024. * @since 1.1
  10025. */
  10026. public function setLanguageArray($language) {
  10027. $this->l = $language;
  10028. if (isset($this->l['a_meta_dir'])) {
  10029. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  10030. } else {
  10031. $this->rtl = false;
  10032. }
  10033. }
  10034. /**
  10035. * Returns the PDF data.
  10036. * @public
  10037. */
  10038. public function getPDFData() {
  10039. if ($this->state < 3) {
  10040. $this->Close();
  10041. }
  10042. return $this->buffer;
  10043. }
  10044. /**
  10045. * Output anchor link.
  10046. * @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;)
  10047. * @param string $name link name
  10048. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  10049. * @param boolean $firstline if true prints only the first line and return the remaining string.
  10050. * @param array|null $color array of RGB text color
  10051. * @param string $style font style (U, D, B, I)
  10052. * @param boolean $firstblock if true the string is the starting of a line.
  10053. * @return int the number of cells used or the remaining text if $firstline = true;
  10054. * @public
  10055. */
  10056. public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color=null, $style=-1, $firstblock=false) {
  10057. if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
  10058. // convert url to internal link
  10059. $lnkdata = explode(',', $url);
  10060. if (isset($lnkdata[0]) ) {
  10061. $page = substr($lnkdata[0], 1);
  10062. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  10063. $lnky = floatval($lnkdata[1]);
  10064. } else {
  10065. $lnky = 0;
  10066. }
  10067. $url = $this->AddLink();
  10068. $this->setLink($url, $lnky, $page);
  10069. }
  10070. }
  10071. // store current settings
  10072. $prevcolor = $this->fgcolor;
  10073. $prevstyle = $this->FontStyle;
  10074. if (empty($color)) {
  10075. $this->setTextColorArray($this->htmlLinkColorArray);
  10076. } else {
  10077. $this->setTextColorArray($color);
  10078. }
  10079. if ($style == -1) {
  10080. $this->setFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  10081. } else {
  10082. $this->setFont('', $this->FontStyle.$style);
  10083. }
  10084. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  10085. // restore settings
  10086. $this->setFont('', $prevstyle);
  10087. $this->setTextColorArray($prevcolor);
  10088. return $ret;
  10089. }
  10090. /**
  10091. * Converts pixels to User's Units.
  10092. * @param int $px pixels
  10093. * @return float value in user's unit
  10094. * @public
  10095. * @see setImageScale(), getImageScale()
  10096. */
  10097. public function pixelsToUnits($px) {
  10098. return ($px / ($this->imgscale * $this->k));
  10099. }
  10100. /**
  10101. * Reverse function for htmlentities.
  10102. * Convert entities in UTF-8.
  10103. * @param string $text_to_convert Text to convert.
  10104. * @return string converted text string
  10105. * @public
  10106. */
  10107. public function unhtmlentities($text_to_convert) {
  10108. return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  10109. }
  10110. // ENCRYPTION METHODS ----------------------------------
  10111. /**
  10112. * Compute encryption key depending on object number where the encrypted data is stored.
  10113. * This is used for all strings and streams without crypt filter specifier.
  10114. * @param int $n object number
  10115. * @return int object key
  10116. * @protected
  10117. * @author Nicola Asuni
  10118. * @since 2.0.000 (2008-01-02)
  10119. */
  10120. protected function _objectkey($n) {
  10121. $objkey = $this->encryptdata['key'].pack('VXxx', $n);
  10122. if ($this->encryptdata['mode'] == 2) { // AES-128
  10123. // AES padding
  10124. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  10125. }
  10126. $objkey = substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  10127. $objkey = substr($objkey, 0, 16);
  10128. return $objkey;
  10129. }
  10130. /**
  10131. * Encrypt the input string.
  10132. * @param int $n object number
  10133. * @param string $s data string to encrypt
  10134. * @return string encrypted string
  10135. * @protected
  10136. * @author Nicola Asuni
  10137. * @since 5.0.005 (2010-05-11)
  10138. */
  10139. protected function _encrypt_data($n, $s) {
  10140. if (!$this->encrypted) {
  10141. return $s;
  10142. }
  10143. switch ($this->encryptdata['mode']) {
  10144. case 0: // RC4-40
  10145. case 1: { // RC4-128
  10146. $s = TCPDF_STATIC::_RC4($this->_objectkey($n), $s, $this->last_enc_key, $this->last_enc_key_c);
  10147. break;
  10148. }
  10149. case 2: { // AES-128
  10150. $s = TCPDF_STATIC::_AES($this->_objectkey($n), $s);
  10151. break;
  10152. }
  10153. case 3: { // AES-256
  10154. $s = TCPDF_STATIC::_AES($this->encryptdata['key'], $s);
  10155. break;
  10156. }
  10157. }
  10158. return $s;
  10159. }
  10160. /**
  10161. * Put encryption on PDF document.
  10162. * @protected
  10163. * @author Nicola Asuni
  10164. * @since 2.0.000 (2008-01-02)
  10165. */
  10166. protected function _putencryption() {
  10167. if (!$this->encrypted) {
  10168. return;
  10169. }
  10170. $this->encryptdata['objid'] = $this->_newobj();
  10171. $out = '<<';
  10172. if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  10173. $this->encryptdata['Filter'] = 'Standard';
  10174. }
  10175. $out .= ' /Filter /'.$this->encryptdata['Filter'];
  10176. if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  10177. $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  10178. }
  10179. if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  10180. $this->encryptdata['V'] = 1;
  10181. }
  10182. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  10183. $out .= ' /V '.$this->encryptdata['V'];
  10184. if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  10185. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  10186. $out .= ' /Length '.$this->encryptdata['Length'];
  10187. } else {
  10188. $out .= ' /Length 40';
  10189. }
  10190. if ($this->encryptdata['V'] >= 4) {
  10191. if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  10192. $this->encryptdata['StmF'] = 'Identity';
  10193. }
  10194. if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  10195. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10196. $this->encryptdata['StrF'] = 'Identity';
  10197. }
  10198. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  10199. if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  10200. $out .= ' /CF <<';
  10201. $out .= ' /'.$this->encryptdata['StmF'].' <<';
  10202. $out .= ' /Type /CryptFilter';
  10203. if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  10204. // The method used
  10205. $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  10206. if ($this->encryptdata['pubkey']) {
  10207. $out .= ' /Recipients [';
  10208. foreach ($this->encryptdata['Recipients'] as $rec) {
  10209. $out .= ' <'.$rec.'>';
  10210. }
  10211. $out .= ' ]';
  10212. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  10213. $out .= ' /EncryptMetadata false';
  10214. } else {
  10215. $out .= ' /EncryptMetadata true';
  10216. }
  10217. }
  10218. } else {
  10219. $out .= ' /CFM /None';
  10220. }
  10221. if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  10222. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  10223. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  10224. } else {
  10225. $out .= ' /AuthEvent /DocOpen';
  10226. }
  10227. if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  10228. // The bit length of the encryption key.
  10229. $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  10230. }
  10231. $out .= ' >> >>';
  10232. }
  10233. // The name of the crypt filter that shall be used by default when decrypting streams.
  10234. $out .= ' /StmF /'.$this->encryptdata['StmF'];
  10235. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10236. $out .= ' /StrF /'.$this->encryptdata['StrF'];
  10237. if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  10238. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  10239. $out .= ' /EFF /'.$this->encryptdata[''];
  10240. }
  10241. }
  10242. // Additional encryption dictionary entries for the standard security handler
  10243. if ($this->encryptdata['pubkey']) {
  10244. if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  10245. $out .= ' /Recipients [';
  10246. foreach ($this->encryptdata['Recipients'] as $rec) {
  10247. $out .= ' <'.$rec.'>';
  10248. }
  10249. $out .= ' ]';
  10250. }
  10251. } else {
  10252. $out .= ' /R';
  10253. if ($this->encryptdata['V'] == 5) { // AES-256
  10254. $out .= ' 5';
  10255. $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')';
  10256. $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')';
  10257. $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')';
  10258. } elseif ($this->encryptdata['V'] == 4) { // AES-128
  10259. $out .= ' 4';
  10260. } elseif ($this->encryptdata['V'] < 2) { // RC-40
  10261. $out .= ' 2';
  10262. } else { // RC-128
  10263. $out .= ' 3';
  10264. }
  10265. $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')';
  10266. $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')';
  10267. $out .= ' /P '.$this->encryptdata['P'];
  10268. if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  10269. $out .= ' /EncryptMetadata false';
  10270. } else {
  10271. $out .= ' /EncryptMetadata true';
  10272. }
  10273. }
  10274. $out .= ' >>';
  10275. $out .= "\n".'endobj';
  10276. $this->_out($out);
  10277. }
  10278. /**
  10279. * Compute U value (used for encryption)
  10280. * @return string U value
  10281. * @protected
  10282. * @since 2.0.000 (2008-01-02)
  10283. * @author Nicola Asuni
  10284. */
  10285. protected function _Uvalue() {
  10286. if ($this->encryptdata['mode'] == 0) { // RC4-40
  10287. return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding, $this->last_enc_key, $this->last_enc_key_c);
  10288. } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  10289. $tmp = TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']);
  10290. $enc = TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp, $this->last_enc_key, $this->last_enc_key_c);
  10291. $len = strlen($tmp);
  10292. for ($i = 1; $i <= 19; ++$i) {
  10293. $ek = '';
  10294. for ($j = 0; $j < $len; ++$j) {
  10295. $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
  10296. }
  10297. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10298. }
  10299. $enc .= str_repeat("\x00", 16);
  10300. return substr($enc, 0, 32);
  10301. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10302. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10303. // User Validation Salt
  10304. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  10305. // User Key Salt
  10306. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  10307. return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  10308. }
  10309. }
  10310. /**
  10311. * Compute UE value (used for encryption)
  10312. * @return string UE value
  10313. * @protected
  10314. * @since 5.9.006 (2010-10-19)
  10315. * @author Nicola Asuni
  10316. */
  10317. protected function _UEvalue() {
  10318. $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  10319. return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
  10320. }
  10321. /**
  10322. * Compute O value (used for encryption)
  10323. * @return string O value
  10324. * @protected
  10325. * @since 2.0.000 (2008-01-02)
  10326. * @author Nicola Asuni
  10327. */
  10328. protected function _Ovalue() {
  10329. if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  10330. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']);
  10331. if ($this->encryptdata['mode'] > 0) {
  10332. for ($i = 0; $i < 50; ++$i) {
  10333. $tmp = TCPDF_STATIC::_md5_16($tmp);
  10334. }
  10335. }
  10336. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  10337. $enc = TCPDF_STATIC::_RC4($owner_key, $this->encryptdata['user_password'], $this->last_enc_key, $this->last_enc_key_c);
  10338. if ($this->encryptdata['mode'] > 0) {
  10339. $len = strlen($owner_key);
  10340. for ($i = 1; $i <= 19; ++$i) {
  10341. $ek = '';
  10342. for ($j = 0; $j < $len; ++$j) {
  10343. $ek .= chr(ord($owner_key[$j]) ^ $i);
  10344. }
  10345. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10346. }
  10347. }
  10348. return $enc;
  10349. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10350. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10351. // Owner Validation Salt
  10352. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  10353. // Owner Key Salt
  10354. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  10355. return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  10356. }
  10357. }
  10358. /**
  10359. * Compute OE value (used for encryption)
  10360. * @return string OE value
  10361. * @protected
  10362. * @since 5.9.006 (2010-10-19)
  10363. * @author Nicola Asuni
  10364. */
  10365. protected function _OEvalue() {
  10366. $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  10367. return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
  10368. }
  10369. /**
  10370. * Convert password for AES-256 encryption mode
  10371. * @param string $password password
  10372. * @return string password
  10373. * @protected
  10374. * @since 5.9.006 (2010-10-19)
  10375. * @author Nicola Asuni
  10376. */
  10377. protected function _fixAES256Password($password) {
  10378. $psw = ''; // password to be returned
  10379. $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont);
  10380. foreach ($psw_array as $c) {
  10381. $psw .= TCPDF_FONTS::unichr($c, $this->isunicode);
  10382. }
  10383. return substr($psw, 0, 127);
  10384. }
  10385. /**
  10386. * Compute encryption key
  10387. * @protected
  10388. * @since 2.0.000 (2008-01-02)
  10389. * @author Nicola Asuni
  10390. */
  10391. protected function _generateencryptionkey() {
  10392. $keybytelen = ($this->encryptdata['Length'] / 8);
  10393. if (!$this->encryptdata['pubkey']) { // standard mode
  10394. if ($this->encryptdata['mode'] == 3) { // AES-256
  10395. // generate 256 bit random key
  10396. $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen);
  10397. // truncate passwords
  10398. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  10399. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  10400. // Compute U value
  10401. $this->encryptdata['U'] = $this->_Uvalue();
  10402. // Compute UE value
  10403. $this->encryptdata['UE'] = $this->_UEvalue();
  10404. // Compute O value
  10405. $this->encryptdata['O'] = $this->_Ovalue();
  10406. // Compute OE value
  10407. $this->encryptdata['OE'] = $this->_OEvalue();
  10408. // Compute P value
  10409. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10410. // Computing the encryption dictionary's Perms (permissions) value
  10411. $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  10412. $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  10413. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  10414. $perms .= 'F';
  10415. } else {
  10416. $perms .= 'T';
  10417. }
  10418. $perms .= 'adb'; // bytes 9-11
  10419. $perms .= 'nick'; // bytes 12-15
  10420. $this->encryptdata['perms'] = TCPDF_STATIC::_AESnopad($this->encryptdata['key'], $perms);
  10421. } else { // RC4-40, RC4-128, AES-128
  10422. // Pad passwords
  10423. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10424. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10425. // Compute O value
  10426. $this->encryptdata['O'] = $this->_Ovalue();
  10427. // get default permissions (reverse byte order)
  10428. $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
  10429. // Compute encryption key
  10430. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  10431. if ($this->encryptdata['mode'] > 0) {
  10432. for ($i = 0; $i < 50; ++$i) {
  10433. $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen));
  10434. }
  10435. }
  10436. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  10437. // Compute U value
  10438. $this->encryptdata['U'] = $this->_Uvalue();
  10439. // Compute P value
  10440. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10441. }
  10442. } else { // Public-Key mode
  10443. // random 20-byte seed
  10444. $seed = sha1(TCPDF_STATIC::getRandomSeed(), true);
  10445. $recipient_bytes = '';
  10446. foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  10447. // for each public certificate
  10448. if (isset($pubkey['p'])) {
  10449. $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  10450. } else {
  10451. $pkprotection = $this->encryptdata['protection'];
  10452. }
  10453. // get default permissions (reverse byte order)
  10454. $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection);
  10455. // envelope data
  10456. $envelope = $seed.$pkpermissions;
  10457. // write the envelope data to a temporary file
  10458. $tempkeyfile = TCPDF_STATIC::getObjFilename('key', $this->file_id);
  10459. $f = TCPDF_STATIC::fopenLocal($tempkeyfile, 'wb');
  10460. if (!$f) {
  10461. $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  10462. }
  10463. $envelope_length = strlen($envelope);
  10464. fwrite($f, $envelope, $envelope_length);
  10465. fclose($f);
  10466. $tempencfile = TCPDF_STATIC::getObjFilename('enc', $this->file_id);
  10467. if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
  10468. $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  10469. }
  10470. // read encryption signature
  10471. $signature = file_get_contents($tempencfile, false, null, $envelope_length);
  10472. // extract signature
  10473. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  10474. $tmparr = explode("\n\n", $signature);
  10475. $signature = trim($tmparr[1]);
  10476. unset($tmparr);
  10477. // decode signature
  10478. $signature = base64_decode($signature);
  10479. // convert signature to hex
  10480. $hexsignature = current(unpack('H*', $signature));
  10481. // store signature on recipients array
  10482. $this->encryptdata['Recipients'][] = $hexsignature;
  10483. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  10484. $recipient_bytes .= $signature;
  10485. }
  10486. // calculate encryption key
  10487. if ($this->encryptdata['mode'] == 3) { // AES-256
  10488. $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
  10489. } else { // RC4-40, RC4-128, AES-128
  10490. $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
  10491. }
  10492. }
  10493. }
  10494. /**
  10495. * Set document protection
  10496. * Remark: the protection against modification is for people who have the full Acrobat product.
  10497. * 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.
  10498. * 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.
  10499. * @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>
  10500. * @param string $user_pass user password. Empty by default.
  10501. * @param string|null $owner_pass owner password. If not specified, a random value is used.
  10502. * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  10503. * @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')))
  10504. * @public
  10505. * @since 2.0.000 (2008-01-02)
  10506. * @author Nicola Asuni
  10507. */
  10508. 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) {
  10509. if ($this->pdfa_mode) {
  10510. // encryption is not allowed in PDF/A mode
  10511. return;
  10512. }
  10513. $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions, $mode);
  10514. if (($pubkeys !== null) AND (is_array($pubkeys))) {
  10515. // public-key mode
  10516. $this->encryptdata['pubkeys'] = $pubkeys;
  10517. if ($mode == 0) {
  10518. // public-Key Security requires at least 128 bit
  10519. $mode = 1;
  10520. }
  10521. if (!function_exists('openssl_pkcs7_encrypt')) {
  10522. $this->Error('Public-Key Security requires openssl library.');
  10523. }
  10524. // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  10525. $this->encryptdata['pubkey'] = true;
  10526. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  10527. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  10528. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  10529. } else {
  10530. // standard mode (password mode)
  10531. $this->encryptdata['pubkey'] = false;
  10532. $this->encryptdata['Filter'] = 'Standard';
  10533. $this->encryptdata['StmF'] = 'StdCF';
  10534. $this->encryptdata['StrF'] = 'StdCF';
  10535. }
  10536. if ($mode > 1) { // AES
  10537. if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) {
  10538. $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).');
  10539. }
  10540. if (extension_loaded('openssl') && !in_array('aes-256-cbc', openssl_get_cipher_methods())) {
  10541. $this->Error('AES encryption requires openssl/aes-256-cbc cypher.');
  10542. }
  10543. if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  10544. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  10545. }
  10546. if (($mode == 3) AND !function_exists('hash')) {
  10547. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  10548. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  10549. }
  10550. }
  10551. if ($owner_pass === null) {
  10552. $owner_pass = md5(TCPDF_STATIC::getRandomSeed());
  10553. }
  10554. $this->encryptdata['user_password'] = $user_pass;
  10555. $this->encryptdata['owner_password'] = $owner_pass;
  10556. $this->encryptdata['mode'] = $mode;
  10557. switch ($mode) {
  10558. case 0: { // RC4 40 bit
  10559. $this->encryptdata['V'] = 1;
  10560. $this->encryptdata['Length'] = 40;
  10561. $this->encryptdata['CF']['CFM'] = 'V2';
  10562. break;
  10563. }
  10564. case 1: { // RC4 128 bit
  10565. $this->encryptdata['V'] = 2;
  10566. $this->encryptdata['Length'] = 128;
  10567. $this->encryptdata['CF']['CFM'] = 'V2';
  10568. if ($this->encryptdata['pubkey']) {
  10569. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  10570. $this->encryptdata['Recipients'] = array();
  10571. }
  10572. break;
  10573. }
  10574. case 2: { // AES 128 bit
  10575. $this->encryptdata['V'] = 4;
  10576. $this->encryptdata['Length'] = 128;
  10577. $this->encryptdata['CF']['CFM'] = 'AESV2';
  10578. $this->encryptdata['CF']['Length'] = 128;
  10579. if ($this->encryptdata['pubkey']) {
  10580. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10581. $this->encryptdata['Recipients'] = array();
  10582. }
  10583. break;
  10584. }
  10585. case 3: { // AES 256 bit
  10586. $this->encryptdata['V'] = 5;
  10587. $this->encryptdata['Length'] = 256;
  10588. $this->encryptdata['CF']['CFM'] = 'AESV3';
  10589. $this->encryptdata['CF']['Length'] = 256;
  10590. if ($this->encryptdata['pubkey']) {
  10591. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10592. $this->encryptdata['Recipients'] = array();
  10593. }
  10594. break;
  10595. }
  10596. }
  10597. $this->encrypted = true;
  10598. $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id);
  10599. $this->_generateencryptionkey();
  10600. }
  10601. // END OF ENCRYPTION FUNCTIONS -------------------------
  10602. // START TRANSFORMATIONS SECTION -----------------------
  10603. /**
  10604. * Starts a 2D tranformation saving current graphic state.
  10605. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  10606. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10607. * @public
  10608. * @since 2.1.000 (2008-01-07)
  10609. * @see StartTransform(), StopTransform()
  10610. */
  10611. public function StartTransform() {
  10612. if ($this->state != 2) {
  10613. return;
  10614. }
  10615. $this->_outSaveGraphicsState();
  10616. if ($this->inxobj) {
  10617. // we are inside an XObject template
  10618. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10619. } else {
  10620. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  10621. }
  10622. ++$this->transfmatrix_key;
  10623. $this->transfmatrix[$this->transfmatrix_key] = array();
  10624. }
  10625. /**
  10626. * Stops a 2D tranformation restoring previous graphic state.
  10627. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  10628. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10629. * @public
  10630. * @since 2.1.000 (2008-01-07)
  10631. * @see StartTransform(), StopTransform()
  10632. */
  10633. public function StopTransform() {
  10634. if ($this->state != 2) {
  10635. return;
  10636. }
  10637. $this->_outRestoreGraphicsState();
  10638. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  10639. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  10640. --$this->transfmatrix_key;
  10641. }
  10642. if ($this->inxobj) {
  10643. // we are inside an XObject template
  10644. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  10645. } else {
  10646. array_pop($this->transfmrk[$this->page]);
  10647. }
  10648. }
  10649. /**
  10650. * Horizontal Scaling.
  10651. * @param float $s_x scaling factor for width 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 ScaleX($s_x, $x='', $y='') {
  10659. $this->Scale($s_x, 100, $x, $y);
  10660. }
  10661. /**
  10662. * Vertical Scaling.
  10663. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  10664. * @param int $x abscissa of the scaling center. Default is current x position
  10665. * @param int $y ordinate of the scaling center. Default is current y position
  10666. * @public
  10667. * @since 2.1.000 (2008-01-07)
  10668. * @see StartTransform(), StopTransform()
  10669. */
  10670. public function ScaleY($s_y, $x='', $y='') {
  10671. $this->Scale(100, $s_y, $x, $y);
  10672. }
  10673. /**
  10674. * Vertical and horizontal proportional Scaling.
  10675. * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  10676. * @param int $x abscissa of the scaling center. Default is current x position
  10677. * @param int $y ordinate of the scaling center. Default is current y position
  10678. * @public
  10679. * @since 2.1.000 (2008-01-07)
  10680. * @see StartTransform(), StopTransform()
  10681. */
  10682. public function ScaleXY($s, $x='', $y='') {
  10683. $this->Scale($s, $s, $x, $y);
  10684. }
  10685. /**
  10686. * Vertical and horizontal non-proportional Scaling.
  10687. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  10688. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  10689. * @param float|null $x abscissa of the scaling center. Default is current x position
  10690. * @param float|null $y ordinate of the scaling center. Default is current y position
  10691. * @public
  10692. * @since 2.1.000 (2008-01-07)
  10693. * @see StartTransform(), StopTransform()
  10694. */
  10695. public function Scale($s_x, $s_y, $x=null, $y=null) {
  10696. if (TCPDF_STATIC::empty_string($x)) {
  10697. $x = $this->x;
  10698. }
  10699. if (TCPDF_STATIC::empty_string($y)) {
  10700. $y = $this->y;
  10701. }
  10702. if (($s_x == 0) OR ($s_y == 0)) {
  10703. $this->Error('Please do not use values equal to zero for scaling');
  10704. }
  10705. $y = ($this->h - $y) * $this->k;
  10706. $x *= $this->k;
  10707. //calculate elements of transformation matrix
  10708. $s_x /= 100;
  10709. $s_y /= 100;
  10710. $tm = array();
  10711. $tm[0] = $s_x;
  10712. $tm[1] = 0;
  10713. $tm[2] = 0;
  10714. $tm[3] = $s_y;
  10715. $tm[4] = $x * (1 - $s_x);
  10716. $tm[5] = $y * (1 - $s_y);
  10717. //scale the coordinate system
  10718. $this->Transform($tm);
  10719. }
  10720. /**
  10721. * Horizontal Mirroring.
  10722. * @param float|null $x abscissa of the point. Default is current x position
  10723. * @public
  10724. * @since 2.1.000 (2008-01-07)
  10725. * @see StartTransform(), StopTransform()
  10726. */
  10727. public function MirrorH($x=null) {
  10728. $this->Scale(-100, 100, $x);
  10729. }
  10730. /**
  10731. * Verical Mirroring.
  10732. * @param float|null $y ordinate of the point. Default is current y position
  10733. * @public
  10734. * @since 2.1.000 (2008-01-07)
  10735. * @see StartTransform(), StopTransform()
  10736. */
  10737. public function MirrorV($y=null) {
  10738. $this->Scale(100, -100, null, $y);
  10739. }
  10740. /**
  10741. * Point reflection mirroring.
  10742. * @param float|null $x abscissa of the point. Default is current x position
  10743. * @param float|null $y ordinate of the point. Default is current y position
  10744. * @public
  10745. * @since 2.1.000 (2008-01-07)
  10746. * @see StartTransform(), StopTransform()
  10747. */
  10748. public function MirrorP($x=null,$y=null) {
  10749. $this->Scale(-100, -100, $x, $y);
  10750. }
  10751. /**
  10752. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  10753. * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  10754. * @param float|null $x abscissa of the point. Default is current x position
  10755. * @param float|null $y ordinate of the point. Default is current y position
  10756. * @public
  10757. * @since 2.1.000 (2008-01-07)
  10758. * @see StartTransform(), StopTransform()
  10759. */
  10760. public function MirrorL($angle=0, $x=null,$y=null) {
  10761. $this->Scale(-100, 100, $x, $y);
  10762. $this->Rotate(-2*($angle-90), $x, $y);
  10763. }
  10764. /**
  10765. * Translate graphic object horizontally.
  10766. * @param int $t_x movement to the right (or left for RTL)
  10767. * @public
  10768. * @since 2.1.000 (2008-01-07)
  10769. * @see StartTransform(), StopTransform()
  10770. */
  10771. public function TranslateX($t_x) {
  10772. $this->Translate($t_x, 0);
  10773. }
  10774. /**
  10775. * Translate graphic object vertically.
  10776. * @param int $t_y movement to the bottom
  10777. * @public
  10778. * @since 2.1.000 (2008-01-07)
  10779. * @see StartTransform(), StopTransform()
  10780. */
  10781. public function TranslateY($t_y) {
  10782. $this->Translate(0, $t_y);
  10783. }
  10784. /**
  10785. * Translate graphic object horizontally and vertically.
  10786. * @param int $t_x movement to the right
  10787. * @param int $t_y movement to the bottom
  10788. * @public
  10789. * @since 2.1.000 (2008-01-07)
  10790. * @see StartTransform(), StopTransform()
  10791. */
  10792. public function Translate($t_x, $t_y) {
  10793. //calculate elements of transformation matrix
  10794. $tm = array();
  10795. $tm[0] = 1;
  10796. $tm[1] = 0;
  10797. $tm[2] = 0;
  10798. $tm[3] = 1;
  10799. $tm[4] = $t_x * $this->k;
  10800. $tm[5] = -$t_y * $this->k;
  10801. //translate the coordinate system
  10802. $this->Transform($tm);
  10803. }
  10804. /**
  10805. * Rotate object.
  10806. * @param float $angle angle in degrees for counter-clockwise rotation
  10807. * @param float|null $x abscissa of the rotation center. Default is current x position
  10808. * @param float|null $y ordinate of the rotation center. Default is current y position
  10809. * @public
  10810. * @since 2.1.000 (2008-01-07)
  10811. * @see StartTransform(), StopTransform()
  10812. */
  10813. public function Rotate($angle, $x=null, $y=null) {
  10814. if (TCPDF_STATIC::empty_string($x)) {
  10815. $x = $this->x;
  10816. }
  10817. if (TCPDF_STATIC::empty_string($y)) {
  10818. $y = $this->y;
  10819. }
  10820. $y = ($this->h - $y) * $this->k;
  10821. $x *= $this->k;
  10822. //calculate elements of transformation matrix
  10823. $tm = array();
  10824. $tm[0] = cos(deg2rad($angle));
  10825. $tm[1] = sin(deg2rad($angle));
  10826. $tm[2] = -$tm[1];
  10827. $tm[3] = $tm[0];
  10828. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  10829. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  10830. //rotate the coordinate system around ($x,$y)
  10831. $this->Transform($tm);
  10832. }
  10833. /**
  10834. * Skew horizontally.
  10835. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10836. * @param float|null $x abscissa of the skewing center. default is current x position
  10837. * @param float|null $y ordinate of the skewing center. default is current y position
  10838. * @public
  10839. * @since 2.1.000 (2008-01-07)
  10840. * @see StartTransform(), StopTransform()
  10841. */
  10842. public function SkewX($angle_x, $x=null, $y=null) {
  10843. $this->Skew($angle_x, 0, $x, $y);
  10844. }
  10845. /**
  10846. * Skew vertically.
  10847. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10848. * @param float|null $x abscissa of the skewing center. default is current x position
  10849. * @param float|null $y ordinate of the skewing center. default is current y position
  10850. * @public
  10851. * @since 2.1.000 (2008-01-07)
  10852. * @see StartTransform(), StopTransform()
  10853. */
  10854. public function SkewY($angle_y, $x=null, $y=null) {
  10855. $this->Skew(0, $angle_y, $x, $y);
  10856. }
  10857. /**
  10858. * Skew.
  10859. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10860. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10861. * @param float|null $x abscissa of the skewing center. default is current x position
  10862. * @param float|null $y ordinate of the skewing center. default is current y position
  10863. * @public
  10864. * @since 2.1.000 (2008-01-07)
  10865. * @see StartTransform(), StopTransform()
  10866. */
  10867. public function Skew($angle_x, $angle_y, $x=null, $y=null) {
  10868. if (TCPDF_STATIC::empty_string($x)) {
  10869. $x = $this->x;
  10870. }
  10871. if (TCPDF_STATIC::empty_string($y)) {
  10872. $y = $this->y;
  10873. }
  10874. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  10875. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  10876. }
  10877. $x *= $this->k;
  10878. $y = ($this->h - $y) * $this->k;
  10879. //calculate elements of transformation matrix
  10880. $tm = array();
  10881. $tm[0] = 1;
  10882. $tm[1] = tan(deg2rad($angle_y));
  10883. $tm[2] = tan(deg2rad($angle_x));
  10884. $tm[3] = 1;
  10885. $tm[4] = -$tm[2] * $y;
  10886. $tm[5] = -$tm[1] * $x;
  10887. //skew the coordinate system
  10888. $this->Transform($tm);
  10889. }
  10890. /**
  10891. * Apply graphic transformations.
  10892. * @param array $tm transformation matrix
  10893. * @protected
  10894. * @since 2.1.000 (2008-01-07)
  10895. * @see StartTransform(), StopTransform()
  10896. */
  10897. protected function Transform($tm) {
  10898. if ($this->state != 2) {
  10899. return;
  10900. }
  10901. $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  10902. // add tranformation matrix
  10903. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  10904. // update transformation mark
  10905. if ($this->inxobj) {
  10906. // we are inside an XObject template
  10907. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  10908. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  10909. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10910. }
  10911. } elseif (end($this->transfmrk[$this->page]) !== false) {
  10912. $key = key($this->transfmrk[$this->page]);
  10913. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  10914. }
  10915. }
  10916. // END TRANSFORMATIONS SECTION -------------------------
  10917. // START GRAPHIC FUNCTIONS SECTION ---------------------
  10918. // The following section is based on the code provided by David Hernandez Sanz
  10919. /**
  10920. * 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.
  10921. * @param float $width The width.
  10922. * @public
  10923. * @since 1.0
  10924. * @see Line(), Rect(), Cell(), MultiCell()
  10925. */
  10926. public function setLineWidth($width) {
  10927. //Set line width
  10928. $this->LineWidth = $width;
  10929. $this->linestyleWidth = sprintf('%F w', ($width * $this->k));
  10930. if ($this->state == 2) {
  10931. $this->_out($this->linestyleWidth);
  10932. }
  10933. }
  10934. /**
  10935. * Returns the current the line width.
  10936. * @return int Line width
  10937. * @public
  10938. * @since 2.1.000 (2008-01-07)
  10939. * @see Line(), SetLineWidth()
  10940. */
  10941. public function GetLineWidth() {
  10942. return $this->LineWidth;
  10943. }
  10944. /**
  10945. * Set line style.
  10946. * @param array $style Line style. Array with keys among the following:
  10947. * <ul>
  10948. * <li>width (float): Width of the line in user units.</li>
  10949. * <li>cap (string): Type of cap to put on the line. Possible values are:
  10950. * butt, round, square. The difference between "square" and "butt" is that
  10951. * "square" projects a flat end past the end of the line.</li>
  10952. * <li>join (string): Type of join. Possible values are: miter, round,
  10953. * bevel.</li>
  10954. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  10955. * series of length values, which are the lengths of the on and off dashes.
  10956. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  10957. * 1 off, 2 on, 1 off, ...</li>
  10958. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  10959. * the point at which the pattern starts.</li>
  10960. * <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>
  10961. * </ul>
  10962. * @param boolean $ret if true do not send the command.
  10963. * @return string the PDF command
  10964. * @public
  10965. * @since 2.1.000 (2008-01-08)
  10966. */
  10967. public function setLineStyle($style, $ret=false) {
  10968. $s = ''; // string to be returned
  10969. if (!is_array($style)) {
  10970. return $s;
  10971. }
  10972. if (isset($style['width'])) {
  10973. $this->LineWidth = $style['width'];
  10974. $this->linestyleWidth = sprintf('%F w', ($style['width'] * $this->k));
  10975. $s .= $this->linestyleWidth.' ';
  10976. }
  10977. if (isset($style['cap'])) {
  10978. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  10979. if (isset($ca[$style['cap']])) {
  10980. $this->linestyleCap = $ca[$style['cap']].' J';
  10981. $s .= $this->linestyleCap.' ';
  10982. }
  10983. }
  10984. if (isset($style['join'])) {
  10985. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  10986. if (isset($ja[$style['join']])) {
  10987. $this->linestyleJoin = $ja[$style['join']].' j';
  10988. $s .= $this->linestyleJoin.' ';
  10989. }
  10990. }
  10991. if (isset($style['dash'])) {
  10992. $dash_string = '';
  10993. if ($style['dash']) {
  10994. if (preg_match('/^.+,/', $style['dash']) > 0) {
  10995. $tab = explode(',', $style['dash']);
  10996. } else {
  10997. $tab = array($style['dash']);
  10998. }
  10999. $dash_string = '';
  11000. foreach ($tab as $i => $v) {
  11001. if ($i) {
  11002. $dash_string .= ' ';
  11003. }
  11004. $dash_string .= sprintf('%F', $v);
  11005. }
  11006. }
  11007. if (!isset($style['phase']) OR !$style['dash']) {
  11008. $style['phase'] = 0;
  11009. }
  11010. $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']);
  11011. $s .= $this->linestyleDash.' ';
  11012. }
  11013. if (isset($style['color'])) {
  11014. $s .= $this->setDrawColorArray($style['color'], true).' ';
  11015. }
  11016. if (!$ret AND ($this->state == 2)) {
  11017. $this->_out($s);
  11018. }
  11019. return $s;
  11020. }
  11021. /**
  11022. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  11023. * @param float $x Abscissa of point.
  11024. * @param float $y Ordinate of point.
  11025. * @protected
  11026. * @since 2.1.000 (2008-01-08)
  11027. */
  11028. protected function _outPoint($x, $y) {
  11029. if ($this->state == 2) {
  11030. $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k)));
  11031. }
  11032. }
  11033. /**
  11034. * Append a straight line segment from the current point to the point (x, y).
  11035. * The new current point shall be (x, y).
  11036. * @param float $x Abscissa of end point.
  11037. * @param float $y Ordinate of end point.
  11038. * @protected
  11039. * @since 2.1.000 (2008-01-08)
  11040. */
  11041. protected function _outLine($x, $y) {
  11042. if ($this->state == 2) {
  11043. $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k)));
  11044. }
  11045. }
  11046. /**
  11047. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  11048. * @param float $x Abscissa of upper-left corner.
  11049. * @param float $y Ordinate of upper-left corner.
  11050. * @param float $w Width.
  11051. * @param float $h Height.
  11052. * @param string $op options
  11053. * @protected
  11054. * @since 2.1.000 (2008-01-08)
  11055. */
  11056. protected function _outRect($x, $y, $w, $h, $op) {
  11057. if ($this->state == 2) {
  11058. $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k), (($this->h - $y) * $this->k), ($w * $this->k), (-$h * $this->k), $op));
  11059. }
  11060. }
  11061. /**
  11062. * 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.
  11063. * The new current point shall be (x3, y3).
  11064. * @param float $x1 Abscissa of control point 1.
  11065. * @param float $y1 Ordinate of control point 1.
  11066. * @param float $x2 Abscissa of control point 2.
  11067. * @param float $y2 Ordinate of control point 2.
  11068. * @param float $x3 Abscissa of end point.
  11069. * @param float $y3 Ordinate of end point.
  11070. * @protected
  11071. * @since 2.1.000 (2008-01-08)
  11072. */
  11073. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
  11074. if ($this->state == 2) {
  11075. $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)));
  11076. }
  11077. }
  11078. /**
  11079. * 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.
  11080. * The new current point shall be (x3, y3).
  11081. * @param float $x2 Abscissa of control point 2.
  11082. * @param float $y2 Ordinate of control point 2.
  11083. * @param float $x3 Abscissa of end point.
  11084. * @param float $y3 Ordinate of end point.
  11085. * @protected
  11086. * @since 4.9.019 (2010-04-26)
  11087. */
  11088. protected function _outCurveV($x2, $y2, $x3, $y3) {
  11089. if ($this->state == 2) {
  11090. $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  11091. }
  11092. }
  11093. /**
  11094. * 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.
  11095. * The new current point shall be (x3, y3).
  11096. * @param float $x1 Abscissa of control point 1.
  11097. * @param float $y1 Ordinate of control point 1.
  11098. * @param float $x3 Abscissa of end point.
  11099. * @param float $y3 Ordinate of end point.
  11100. * @protected
  11101. * @since 2.1.000 (2008-01-08)
  11102. */
  11103. protected function _outCurveY($x1, $y1, $x3, $y3) {
  11104. if ($this->state == 2) {
  11105. $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  11106. }
  11107. }
  11108. /**
  11109. * Draws a line between two points.
  11110. * @param float $x1 Abscissa of first point.
  11111. * @param float $y1 Ordinate of first point.
  11112. * @param float $x2 Abscissa of second point.
  11113. * @param float $y2 Ordinate of second point.
  11114. * @param array $style Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  11115. * @public
  11116. * @since 1.0
  11117. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  11118. */
  11119. public function Line($x1, $y1, $x2, $y2, $style=array()) {
  11120. if ($this->state != 2) {
  11121. return;
  11122. }
  11123. if (is_array($style)) {
  11124. $this->setLineStyle($style);
  11125. }
  11126. $this->_outPoint($x1, $y1);
  11127. $this->_outLine($x2, $y2);
  11128. $this->_out('S');
  11129. }
  11130. /**
  11131. * Draws a rectangle.
  11132. * @param float $x Abscissa of upper-left corner.
  11133. * @param float $y Ordinate of upper-left corner.
  11134. * @param float $w Width.
  11135. * @param float $h Height.
  11136. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11137. * @param array $border_style Border style of rectangle. Array with keys among the following:
  11138. * <ul>
  11139. * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  11140. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  11141. * </ul>
  11142. * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
  11143. * @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).
  11144. * @public
  11145. * @since 1.0
  11146. * @see SetLineStyle()
  11147. */
  11148. public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
  11149. if ($this->state != 2) {
  11150. return;
  11151. }
  11152. if (empty($style)) {
  11153. $style = 'S';
  11154. }
  11155. if (!(strpos($style, 'F') === false) AND !empty($fill_color)) {
  11156. // set background color
  11157. $this->setFillColorArray($fill_color);
  11158. }
  11159. if (!empty($border_style)) {
  11160. if (isset($border_style['all']) AND !empty($border_style['all'])) {
  11161. //set global style for border
  11162. $this->setLineStyle($border_style['all']);
  11163. $border_style = array();
  11164. } else {
  11165. // remove stroke operator from style
  11166. $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*' );
  11167. if (isset($opnostroke[$style])) {
  11168. $style = $opnostroke[$style];
  11169. }
  11170. }
  11171. }
  11172. if (!empty($style)) {
  11173. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11174. $this->_outRect($x, $y, $w, $h, $op);
  11175. }
  11176. if (!empty($border_style)) {
  11177. $border_style2 = array();
  11178. foreach ($border_style as $line => $value) {
  11179. $length = strlen($line);
  11180. for ($i = 0; $i < $length; ++$i) {
  11181. $border_style2[$line[$i]] = $value;
  11182. }
  11183. }
  11184. $border_style = $border_style2;
  11185. if (isset($border_style['L']) AND $border_style['L']) {
  11186. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  11187. }
  11188. if (isset($border_style['T']) AND $border_style['T']) {
  11189. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  11190. }
  11191. if (isset($border_style['R']) AND $border_style['R']) {
  11192. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  11193. }
  11194. if (isset($border_style['B']) AND $border_style['B']) {
  11195. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  11196. }
  11197. }
  11198. }
  11199. /**
  11200. * Draws a Bezier curve.
  11201. * The Bezier curve is a tangent to the line between the control points at
  11202. * either end of the curve.
  11203. * @param float $x0 Abscissa of start point.
  11204. * @param float $y0 Ordinate of start point.
  11205. * @param float $x1 Abscissa of control point 1.
  11206. * @param float $y1 Ordinate of control point 1.
  11207. * @param float $x2 Abscissa of control point 2.
  11208. * @param float $y2 Ordinate of control point 2.
  11209. * @param float $x3 Abscissa of end point.
  11210. * @param float $y3 Ordinate of end point.
  11211. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11212. * @param array $line_style Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11213. * @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).
  11214. * @public
  11215. * @see SetLineStyle()
  11216. * @since 2.1.000 (2008-01-08)
  11217. */
  11218. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
  11219. if ($this->state != 2) {
  11220. return;
  11221. }
  11222. if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
  11223. $this->setFillColorArray($fill_color);
  11224. }
  11225. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11226. if ($line_style) {
  11227. $this->setLineStyle($line_style);
  11228. }
  11229. $this->_outPoint($x0, $y0);
  11230. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11231. $this->_out($op);
  11232. }
  11233. /**
  11234. * Draws a poly-Bezier curve.
  11235. * Each Bezier curve segment is a tangent to the line between the control points at
  11236. * either end of the curve.
  11237. * @param float $x0 Abscissa of start point.
  11238. * @param float $y0 Ordinate of start point.
  11239. * @param float[] $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  11240. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11241. * @param array $line_style Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11242. * @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).
  11243. * @public
  11244. * @see SetLineStyle()
  11245. * @since 3.0008 (2008-05-12)
  11246. */
  11247. public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
  11248. if ($this->state != 2) {
  11249. return;
  11250. }
  11251. if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
  11252. $this->setFillColorArray($fill_color);
  11253. }
  11254. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11255. if ($op == 'f') {
  11256. $line_style = array();
  11257. }
  11258. if ($line_style) {
  11259. $this->setLineStyle($line_style);
  11260. }
  11261. $this->_outPoint($x0, $y0);
  11262. foreach ($segments as $segment) {
  11263. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  11264. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11265. }
  11266. $this->_out($op);
  11267. }
  11268. /**
  11269. * Draws an ellipse.
  11270. * An ellipse is formed from n Bezier curves.
  11271. * @param float $x0 Abscissa of center point.
  11272. * @param float $y0 Ordinate of center point.
  11273. * @param float $rx Horizontal radius.
  11274. * @param float $ry Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11275. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11276. * @param float $astart Angle start of draw line. Default value: 0.
  11277. * @param float $afinish Angle finish of draw line. Default value: 360.
  11278. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11279. * @param array $line_style Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  11280. * @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).
  11281. * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
  11282. * @author Nicola Asuni
  11283. * @public
  11284. * @since 2.1.000 (2008-01-08)
  11285. */
  11286. public function Ellipse($x0, $y0, $rx, $ry=0, $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11287. if ($this->state != 2) {
  11288. return;
  11289. }
  11290. if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
  11291. $ry = $rx;
  11292. }
  11293. if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
  11294. $this->setFillColorArray($fill_color);
  11295. }
  11296. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11297. if ($op == 'f') {
  11298. $line_style = array();
  11299. }
  11300. if ($line_style) {
  11301. $this->setLineStyle($line_style);
  11302. }
  11303. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
  11304. $this->_out($op);
  11305. }
  11306. /**
  11307. * Append an elliptical arc to the current path.
  11308. * An ellipse is formed from n Bezier curves.
  11309. * @param float $xc Abscissa of center point.
  11310. * @param float $yc Ordinate of center point.
  11311. * @param float $rx Horizontal radius.
  11312. * @param float $ry Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11313. * @param float $xang Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  11314. * @param float $angs Angle start of draw line. Default value: 0.
  11315. * @param float $angf Angle finish of draw line. Default value: 360.
  11316. * @param boolean $pie if true do not mark the border point (used to draw pie sectors).
  11317. * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
  11318. * @param boolean $startpoint if true output a starting point.
  11319. * @param boolean $ccw if true draws in counter-clockwise.
  11320. * @param boolean $svg if true the angles are in svg mode (already calculated).
  11321. * @return array bounding box coordinates (x min, y min, x max, y max)
  11322. * @author Nicola Asuni
  11323. * @protected
  11324. * @since 4.9.019 (2010-04-26)
  11325. */
  11326. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
  11327. if (($rx <= 0) OR ($ry < 0)) {
  11328. return;
  11329. }
  11330. $k = $this->k;
  11331. if ($nc < 2) {
  11332. $nc = 2;
  11333. }
  11334. $xmin = 2147483647;
  11335. $ymin = 2147483647;
  11336. $xmax = 0;
  11337. $ymax = 0;
  11338. if ($pie) {
  11339. // center of the arc
  11340. $this->_outPoint($xc, $yc);
  11341. }
  11342. $xang = deg2rad((float) $xang);
  11343. $angs = deg2rad((float) $angs);
  11344. $angf = deg2rad((float) $angf);
  11345. if ($svg) {
  11346. $as = $angs;
  11347. $af = $angf;
  11348. } else {
  11349. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  11350. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  11351. }
  11352. if ($as < 0) {
  11353. $as += (2 * M_PI);
  11354. }
  11355. if ($af < 0) {
  11356. $af += (2 * M_PI);
  11357. }
  11358. if ($ccw AND ($as > $af)) {
  11359. // reverse rotation
  11360. $as -= (2 * M_PI);
  11361. } elseif (!$ccw AND ($as < $af)) {
  11362. // reverse rotation
  11363. $af -= (2 * M_PI);
  11364. }
  11365. $total_angle = ($af - $as);
  11366. if ($nc < 2) {
  11367. $nc = 2;
  11368. }
  11369. // total arcs to draw
  11370. $nc *= (2 * abs($total_angle) / M_PI);
  11371. $nc = round($nc) + 1;
  11372. // angle of each arc
  11373. $arcang = ($total_angle / $nc);
  11374. // center point in PDF coordinates
  11375. $x0 = $xc;
  11376. $y0 = ($this->h - $yc);
  11377. // starting angle
  11378. $ang = $as;
  11379. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  11380. $cos_xang = cos($xang);
  11381. $sin_xang = sin($xang);
  11382. $cos_ang = cos($ang);
  11383. $sin_ang = sin($ang);
  11384. // first arc point
  11385. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11386. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11387. // first Bezier control point
  11388. $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11389. $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11390. if ($pie) {
  11391. // line from center to arc starting point
  11392. $this->_outLine($px1, $this->h - $py1);
  11393. } elseif ($startpoint) {
  11394. // arc starting point
  11395. $this->_outPoint($px1, $this->h - $py1);
  11396. }
  11397. // draw arcs
  11398. for ($i = 1; $i <= $nc; ++$i) {
  11399. // starting angle
  11400. $ang = $as + ($i * $arcang);
  11401. if ($i == $nc) {
  11402. $ang = $af;
  11403. }
  11404. $cos_ang = cos($ang);
  11405. $sin_ang = sin($ang);
  11406. // second arc point
  11407. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11408. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11409. // second Bezier control point
  11410. $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11411. $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11412. // draw arc
  11413. $cx1 = ($px1 + $qx1);
  11414. $cy1 = ($this->h - ($py1 + $qy1));
  11415. $cx2 = ($px2 - $qx2);
  11416. $cy2 = ($this->h - ($py2 - $qy2));
  11417. $cx3 = $px2;
  11418. $cy3 = ($this->h - $py2);
  11419. $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
  11420. // get bounding box coordinates
  11421. $xmin = min($xmin, $cx1, $cx2, $cx3);
  11422. $ymin = min($ymin, $cy1, $cy2, $cy3);
  11423. $xmax = max($xmax, $cx1, $cx2, $cx3);
  11424. $ymax = max($ymax, $cy1, $cy2, $cy3);
  11425. // move to next point
  11426. $px1 = $px2;
  11427. $py1 = $py2;
  11428. $qx1 = $qx2;
  11429. $qy1 = $qy2;
  11430. }
  11431. if ($pie) {
  11432. $this->_outLine($xc, $yc);
  11433. // get bounding box coordinates
  11434. $xmin = min($xmin, $xc);
  11435. $ymin = min($ymin, $yc);
  11436. $xmax = max($xmax, $xc);
  11437. $ymax = max($ymax, $yc);
  11438. }
  11439. return array($xmin, $ymin, $xmax, $ymax);
  11440. }
  11441. /**
  11442. * Draws a circle.
  11443. * A circle is formed from n Bezier curves.
  11444. * @param float $x0 Abscissa of center point.
  11445. * @param float $y0 Ordinate of center point.
  11446. * @param float $r Radius.
  11447. * @param float $angstr Angle start of draw line. Default value: 0.
  11448. * @param float $angend Angle finish of draw line. Default value: 360.
  11449. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11450. * @param array $line_style Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11451. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11452. * @param integer $nc Number of curves used to draw a 90 degrees portion of circle.
  11453. * @public
  11454. * @since 2.1.000 (2008-01-08)
  11455. */
  11456. public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11457. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  11458. }
  11459. /**
  11460. * Draws a polygonal line
  11461. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11462. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11463. * @param array $line_style Line style of polygon. Array with keys among the following:
  11464. * <ul>
  11465. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11466. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11467. * </ul>
  11468. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11469. * @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).
  11470. * @since 4.8.003 (2009-09-15)
  11471. * @public
  11472. */
  11473. public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
  11474. $this->Polygon($p, $style, $line_style, $fill_color, false);
  11475. }
  11476. /**
  11477. * Draws a polygon.
  11478. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11479. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11480. * @param array $line_style Line style of polygon. Array with keys among the following:
  11481. * <ul>
  11482. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11483. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11484. * </ul>
  11485. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11486. * @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).
  11487. * @param boolean $closed if true the polygon is closes, otherwise will remain open
  11488. * @public
  11489. * @since 2.1.000 (2008-01-08)
  11490. */
  11491. public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
  11492. if ($this->state != 2) {
  11493. return;
  11494. }
  11495. $nc = count($p); // number of coordinates
  11496. $np = $nc / 2; // number of points
  11497. if ($closed) {
  11498. // close polygon by adding the first 2 points at the end (one line)
  11499. for ($i = 0; $i < 4; ++$i) {
  11500. $p[$nc + $i] = $p[$i];
  11501. }
  11502. // copy style for the last added line
  11503. if (isset($line_style[0])) {
  11504. $line_style[$np] = $line_style[0];
  11505. }
  11506. $nc += 4;
  11507. }
  11508. if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
  11509. $this->setFillColorArray($fill_color);
  11510. }
  11511. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11512. if ($op == 'f') {
  11513. $line_style = array();
  11514. }
  11515. $draw = true;
  11516. if ($line_style) {
  11517. if (isset($line_style['all'])) {
  11518. $this->setLineStyle($line_style['all']);
  11519. } else {
  11520. $draw = false;
  11521. if ($op == 'B') {
  11522. // draw fill
  11523. $op = 'f';
  11524. $this->_outPoint($p[0], $p[1]);
  11525. for ($i = 2; $i < $nc; $i = $i + 2) {
  11526. $this->_outLine($p[$i], $p[$i + 1]);
  11527. }
  11528. $this->_out($op);
  11529. }
  11530. // draw outline
  11531. $this->_outPoint($p[0], $p[1]);
  11532. for ($i = 2; $i < $nc; $i = $i + 2) {
  11533. $line_num = ($i / 2) - 1;
  11534. if (isset($line_style[$line_num])) {
  11535. if ($line_style[$line_num] != 0) {
  11536. if (is_array($line_style[$line_num])) {
  11537. $this->_out('S');
  11538. $this->setLineStyle($line_style[$line_num]);
  11539. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  11540. $this->_outLine($p[$i], $p[$i + 1]);
  11541. $this->_out('S');
  11542. $this->_outPoint($p[$i], $p[$i + 1]);
  11543. } else {
  11544. $this->_outLine($p[$i], $p[$i + 1]);
  11545. }
  11546. }
  11547. } else {
  11548. $this->_outLine($p[$i], $p[$i + 1]);
  11549. }
  11550. }
  11551. $this->_out($op);
  11552. }
  11553. }
  11554. if ($draw) {
  11555. $this->_outPoint($p[0], $p[1]);
  11556. for ($i = 2; $i < $nc; $i = $i + 2) {
  11557. $this->_outLine($p[$i], $p[$i + 1]);
  11558. }
  11559. $this->_out($op);
  11560. }
  11561. }
  11562. /**
  11563. * Draws a regular polygon.
  11564. * @param float $x0 Abscissa of center point.
  11565. * @param float $y0 Ordinate of center point.
  11566. * @param float $r Radius of inscribed circle.
  11567. * @param integer $ns Number of sides.
  11568. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11569. * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  11570. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11571. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  11572. * <ul>
  11573. * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  11574. * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  11575. * </ul>
  11576. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11577. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11578. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  11579. * <ul>
  11580. * <li>D or empty string: Draw (default).</li>
  11581. * <li>F: Fill.</li>
  11582. * <li>DF or FD: Draw and fill.</li>
  11583. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11584. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11585. * </ul>
  11586. * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11587. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11588. * @public
  11589. * @since 2.1.000 (2008-01-08)
  11590. */
  11591. 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()) {
  11592. if (3 > $ns) {
  11593. $ns = 3;
  11594. }
  11595. if ($draw_circle) {
  11596. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11597. }
  11598. $p = array();
  11599. for ($i = 0; $i < $ns; ++$i) {
  11600. $a = $angle + ($i * 360 / $ns);
  11601. $a_rad = deg2rad((float) $a);
  11602. $p[] = $x0 + ($r * sin($a_rad));
  11603. $p[] = $y0 + ($r * cos($a_rad));
  11604. }
  11605. $this->Polygon($p, $style, $line_style, $fill_color);
  11606. }
  11607. /**
  11608. * Draws a star polygon
  11609. * @param float $x0 Abscissa of center point.
  11610. * @param float $y0 Ordinate of center point.
  11611. * @param float $r Radius of inscribed circle.
  11612. * @param integer $nv Number of vertices.
  11613. * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  11614. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11615. * @param boolean $draw_circle Draw inscribed circle or not. Default value is false.
  11616. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11617. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  11618. * <ul>
  11619. * <li>all: Line style of all sides. Array like for
  11620. * SetLineStyle().</li>
  11621. * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  11622. * </ul>
  11623. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11624. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11625. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  11626. * <ul>
  11627. * <li>D or empty string: Draw (default).</li>
  11628. * <li>F: Fill.</li>
  11629. * <li>DF or FD: Draw and fill.</li>
  11630. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11631. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11632. * </ul>
  11633. * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11634. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11635. * @public
  11636. * @since 2.1.000 (2008-01-08)
  11637. */
  11638. 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()) {
  11639. if ($nv < 2) {
  11640. $nv = 2;
  11641. }
  11642. if ($draw_circle) {
  11643. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11644. }
  11645. $p2 = array();
  11646. $visited = array();
  11647. for ($i = 0; $i < $nv; ++$i) {
  11648. $a = $angle + ($i * 360 / $nv);
  11649. $a_rad = deg2rad((float) $a);
  11650. $p2[] = $x0 + ($r * sin($a_rad));
  11651. $p2[] = $y0 + ($r * cos($a_rad));
  11652. $visited[] = false;
  11653. }
  11654. $p = array();
  11655. $i = 0;
  11656. do {
  11657. $p[] = $p2[$i * 2];
  11658. $p[] = $p2[($i * 2) + 1];
  11659. $visited[$i] = true;
  11660. $i += $ng;
  11661. $i %= $nv;
  11662. } while (!$visited[$i]);
  11663. $this->Polygon($p, $style, $line_style, $fill_color);
  11664. }
  11665. /**
  11666. * Draws a rounded rectangle.
  11667. * @param float $x Abscissa of upper-left corner.
  11668. * @param float $y Ordinate of upper-left corner.
  11669. * @param float $w Width.
  11670. * @param float $h Height.
  11671. * @param float $r the radius of the circle used to round off the corners of the rectangle.
  11672. * @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").
  11673. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11674. * @param array $border_style Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11675. * @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).
  11676. * @public
  11677. * @since 2.1.000 (2008-01-08)
  11678. */
  11679. public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11680. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  11681. }
  11682. /**
  11683. * Draws a rounded rectangle.
  11684. * @param float $x Abscissa of upper-left corner.
  11685. * @param float $y Ordinate of upper-left corner.
  11686. * @param float $w Width.
  11687. * @param float $h Height.
  11688. * @param float $rx the x-axis radius of the ellipse used to round off the corners of the rectangle.
  11689. * @param float $ry the y-axis radius of the ellipse used to round off the corners of the rectangle.
  11690. * @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").
  11691. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11692. * @param array $border_style Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11693. * @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).
  11694. * @public
  11695. * @since 4.9.019 (2010-04-22)
  11696. */
  11697. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11698. if ($this->state != 2) {
  11699. return;
  11700. }
  11701. if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  11702. // Not rounded
  11703. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  11704. return;
  11705. }
  11706. // Rounded
  11707. if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
  11708. $this->setFillColorArray($fill_color);
  11709. }
  11710. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11711. if ($op == 'f') {
  11712. $border_style = array();
  11713. }
  11714. if ($border_style) {
  11715. $this->setLineStyle($border_style);
  11716. }
  11717. $MyArc = 4 / 3 * (sqrt(2) - 1);
  11718. $this->_outPoint($x + $rx, $y);
  11719. $xc = $x + $w - $rx;
  11720. $yc = $y + $ry;
  11721. $this->_outLine($xc, $y);
  11722. if ($round_corner[0]) {
  11723. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  11724. } else {
  11725. $this->_outLine($x + $w, $y);
  11726. }
  11727. $xc = $x + $w - $rx;
  11728. $yc = $y + $h - $ry;
  11729. $this->_outLine($x + $w, $yc);
  11730. if ($round_corner[1]) {
  11731. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  11732. } else {
  11733. $this->_outLine($x + $w, $y + $h);
  11734. }
  11735. $xc = $x + $rx;
  11736. $yc = $y + $h - $ry;
  11737. $this->_outLine($xc, $y + $h);
  11738. if ($round_corner[2]) {
  11739. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  11740. } else {
  11741. $this->_outLine($x, $y + $h);
  11742. }
  11743. $xc = $x + $rx;
  11744. $yc = $y + $ry;
  11745. $this->_outLine($x, $yc);
  11746. if ($round_corner[3]) {
  11747. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  11748. } else {
  11749. $this->_outLine($x, $y);
  11750. $this->_outLine($x + $rx, $y);
  11751. }
  11752. $this->_out($op);
  11753. }
  11754. /**
  11755. * Draws a grahic arrow.
  11756. * @param float $x0 Abscissa of first point.
  11757. * @param float $y0 Ordinate of first point.
  11758. * @param float $x1 Abscissa of second point.
  11759. * @param float $y1 Ordinate of second point.
  11760. * @param int $head_style (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  11761. * @param float $arm_size length of arrowhead arms
  11762. * @param int $arm_angle angle between an arm and the shaft
  11763. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  11764. * @since 4.6.018 (2009-07-10)
  11765. */
  11766. public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
  11767. // getting arrow direction angle
  11768. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  11769. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  11770. if ($dir_angle < 0) {
  11771. $dir_angle += (2 * M_PI);
  11772. }
  11773. $arm_angle = deg2rad($arm_angle);
  11774. $sx1 = $x1;
  11775. $sy1 = $y1;
  11776. if ($head_style > 0) {
  11777. // calculate the stopping point for the arrow shaft
  11778. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  11779. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  11780. }
  11781. // main arrow line / shaft
  11782. $this->Line($x0, $y0, $sx1, $sy1);
  11783. // left arrowhead arm tip
  11784. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  11785. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  11786. // right arrowhead arm tip
  11787. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  11788. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  11789. $mode = 'D';
  11790. $style = array();
  11791. switch ($head_style) {
  11792. case 0: {
  11793. // draw only arrowhead arms
  11794. $mode = 'D';
  11795. $style = array(1, 1, 0);
  11796. break;
  11797. }
  11798. case 1: {
  11799. // draw closed arrowhead, but no fill
  11800. $mode = 'D';
  11801. break;
  11802. }
  11803. case 2: {
  11804. // closed and filled arrowhead
  11805. $mode = 'DF';
  11806. break;
  11807. }
  11808. case 3: {
  11809. // filled arrowhead
  11810. $mode = 'F';
  11811. break;
  11812. }
  11813. }
  11814. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  11815. }
  11816. // END GRAPHIC FUNCTIONS SECTION -----------------------
  11817. /**
  11818. * Add a Named Destination.
  11819. * NOTE: destination names are unique, so only last entry will be saved.
  11820. * @param string $name Destination name.
  11821. * @param float $y Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
  11822. * @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.
  11823. * @param float $x X position in user units of the destiantion on the selected page (default = -1 = current position;).
  11824. * @return string|false Stripped named destination identifier or false in case of error.
  11825. * @public
  11826. * @author Christian Deligant, Nicola Asuni
  11827. * @since 5.9.097 (2011-06-23)
  11828. */
  11829. public function setDestination($name, $y=-1, $page='', $x=-1) {
  11830. // remove unsupported characters
  11831. $name = TCPDF_STATIC::encodeNameObject($name);
  11832. if (TCPDF_STATIC::empty_string($name)) {
  11833. return false;
  11834. }
  11835. if ($y == -1) {
  11836. $y = $this->GetY();
  11837. } elseif ($y < 0) {
  11838. $y = 0;
  11839. } elseif ($y > $this->h) {
  11840. $y = $this->h;
  11841. }
  11842. if ($x == -1) {
  11843. $x = $this->GetX();
  11844. } elseif ($x < 0) {
  11845. $x = 0;
  11846. } elseif ($x > $this->w) {
  11847. $x = $this->w;
  11848. }
  11849. $fixed = false;
  11850. if (!empty($page) AND (substr($page, 0, 1) == '*')) {
  11851. $page = intval(substr($page, 1));
  11852. // this page number will not be changed when moving/add/deleting pages
  11853. $fixed = true;
  11854. }
  11855. if (empty($page)) {
  11856. $page = $this->PageNo();
  11857. if (empty($page)) {
  11858. return;
  11859. }
  11860. }
  11861. $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed);
  11862. return $name;
  11863. }
  11864. /**
  11865. * Return the Named Destination array.
  11866. * @return array Named Destination array.
  11867. * @public
  11868. * @author Nicola Asuni
  11869. * @since 5.9.097 (2011-06-23)
  11870. */
  11871. public function getDestination() {
  11872. return $this->dests;
  11873. }
  11874. /**
  11875. * Insert Named Destinations.
  11876. * @protected
  11877. * @author Johannes G\FCntert, Nicola Asuni
  11878. * @since 5.9.098 (2011-06-23)
  11879. */
  11880. protected function _putdests() {
  11881. if (empty($this->dests)) {
  11882. return;
  11883. }
  11884. $this->n_dests = $this->_newobj();
  11885. $out = ' <<';
  11886. foreach($this->dests as $name => $o) {
  11887. $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)));
  11888. }
  11889. $out .= ' >>';
  11890. $out .= "\n".'endobj';
  11891. $this->_out($out);
  11892. }
  11893. /**
  11894. * Adds a bookmark - alias for Bookmark().
  11895. * @param string $txt Bookmark description.
  11896. * @param int $level Bookmark level (minimum value is 0).
  11897. * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11898. * @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.
  11899. * @param string $style Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11900. * @param array $color RGB color array (values from 0 to 255).
  11901. * @param float $x X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11902. * @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).
  11903. * @public
  11904. */
  11905. public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11906. $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
  11907. }
  11908. /**
  11909. * Adds a bookmark.
  11910. * @param string $txt Bookmark description.
  11911. * @param int $level Bookmark level (minimum value is 0).
  11912. * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11913. * @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.
  11914. * @param string $style Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11915. * @param array $color RGB color array (values from 0 to 255).
  11916. * @param float $x X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11917. * @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).
  11918. * @public
  11919. * @since 2.1.002 (2008-02-12)
  11920. */
  11921. public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11922. if ($level < 0) {
  11923. $level = 0;
  11924. }
  11925. if (isset($this->outlines[0])) {
  11926. $lastoutline = end($this->outlines);
  11927. $maxlevel = $lastoutline['l'] + 1;
  11928. } else {
  11929. $maxlevel = 0;
  11930. }
  11931. if ($level > $maxlevel) {
  11932. $level = $maxlevel;
  11933. }
  11934. if ($y == -1) {
  11935. $y = $this->GetY();
  11936. } elseif ($y < 0) {
  11937. $y = 0;
  11938. } elseif ($y > $this->h) {
  11939. $y = $this->h;
  11940. }
  11941. if ($x == -1) {
  11942. $x = $this->GetX();
  11943. } elseif ($x < 0) {
  11944. $x = 0;
  11945. } elseif ($x > $this->w) {
  11946. $x = $this->w;
  11947. }
  11948. $fixed = false;
  11949. $pageAsString = (string) $page;
  11950. if ($pageAsString && $pageAsString[0] == '*') {
  11951. $page = intval(substr($page, 1));
  11952. // this page number will not be changed when moving/add/deleting pages
  11953. $fixed = true;
  11954. }
  11955. if (empty($page)) {
  11956. $page = $this->PageNo();
  11957. if (empty($page)) {
  11958. return;
  11959. }
  11960. }
  11961. $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
  11962. }
  11963. /**
  11964. * Sort bookmarks for page and key.
  11965. * @protected
  11966. * @since 5.9.119 (2011-09-19)
  11967. */
  11968. protected function sortBookmarks() {
  11969. // get sorting columns
  11970. $outline_p = array();
  11971. $outline_y = array();
  11972. foreach ($this->outlines as $key => $row) {
  11973. $outline_p[$key] = $row['p'];
  11974. $outline_k[$key] = $key;
  11975. }
  11976. // sort outlines by page and original position
  11977. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  11978. }
  11979. /**
  11980. * Create a bookmark PDF string.
  11981. * @protected
  11982. * @author Olivier Plathey, Nicola Asuni
  11983. * @since 2.1.002 (2008-02-12)
  11984. */
  11985. protected function _putbookmarks() {
  11986. $nb = count($this->outlines);
  11987. if ($nb == 0) {
  11988. return;
  11989. }
  11990. // sort bookmarks
  11991. $this->sortBookmarks();
  11992. $lru = array();
  11993. $level = 0;
  11994. foreach ($this->outlines as $i => $o) {
  11995. if ($o['l'] > 0) {
  11996. $parent = $lru[($o['l'] - 1)];
  11997. //Set parent and last pointers
  11998. $this->outlines[$i]['parent'] = $parent;
  11999. $this->outlines[$parent]['last'] = $i;
  12000. if ($o['l'] > $level) {
  12001. //Level increasing: set first pointer
  12002. $this->outlines[$parent]['first'] = $i;
  12003. }
  12004. } else {
  12005. $this->outlines[$i]['parent'] = $nb;
  12006. }
  12007. if (($o['l'] <= $level) AND ($i > 0)) {
  12008. //Set prev and next pointers
  12009. $prev = $lru[$o['l']];
  12010. $this->outlines[$prev]['next'] = $i;
  12011. $this->outlines[$i]['prev'] = $prev;
  12012. }
  12013. $lru[$o['l']] = $i;
  12014. $level = $o['l'];
  12015. }
  12016. //Outline items
  12017. $n = $this->n + 1;
  12018. $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';
  12019. foreach ($this->outlines as $i => $o) {
  12020. $oid = $this->_newobj();
  12021. // covert HTML title to string
  12022. $title = preg_replace($nltags, "\n", $o['t']);
  12023. $title = preg_replace("/[\r]+/si", '', $title);
  12024. $title = preg_replace("/[\n]+/si", "\n", $title);
  12025. $title = strip_tags($title);
  12026. $title = $this->stringTrim($title);
  12027. $out = '<</Title '.$this->_textstring($title, $oid);
  12028. $out .= ' /Parent '.($n + $o['parent']).' 0 R';
  12029. if (isset($o['prev'])) {
  12030. $out .= ' /Prev '.($n + $o['prev']).' 0 R';
  12031. }
  12032. if (isset($o['next'])) {
  12033. $out .= ' /Next '.($n + $o['next']).' 0 R';
  12034. }
  12035. if (isset($o['first'])) {
  12036. $out .= ' /First '.($n + $o['first']).' 0 R';
  12037. }
  12038. if (isset($o['last'])) {
  12039. $out .= ' /Last '.($n + $o['last']).' 0 R';
  12040. }
  12041. if (isset($o['u']) AND !empty($o['u'])) {
  12042. // link
  12043. if (is_string($o['u'])) {
  12044. if ($o['u'][0] == '#') {
  12045. // internal destination
  12046. $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1));
  12047. } elseif ($o['u'][0] == '%') {
  12048. // embedded PDF file
  12049. $filename = basename(substr($o['u'], 1));
  12050. $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  12051. } elseif ($o['u'][0] == '*') {
  12052. // embedded generic file
  12053. $filename = basename(substr($o['u'], 1));
  12054. $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});';
  12055. $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
  12056. } else {
  12057. // external URI link
  12058. $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
  12059. }
  12060. } elseif (isset($this->links[$o['u']])) {
  12061. // internal link ID
  12062. $l = $this->links[$o['u']];
  12063. if (isset($this->page_obj_id[($l['p'])])) {
  12064. $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)));
  12065. }
  12066. }
  12067. } elseif (isset($this->page_obj_id[($o['p'])])) {
  12068. // link to a page
  12069. $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)));
  12070. }
  12071. // set font style
  12072. $style = 0;
  12073. if (!empty($o['s'])) {
  12074. // bold
  12075. if (strpos($o['s'], 'B') !== false) {
  12076. $style |= 2;
  12077. }
  12078. // oblique
  12079. if (strpos($o['s'], 'I') !== false) {
  12080. $style |= 1;
  12081. }
  12082. }
  12083. $out .= sprintf(' /F %d', $style);
  12084. // set bookmark color
  12085. if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
  12086. $color = array_values($o['c']);
  12087. $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  12088. } else {
  12089. // black
  12090. $out .= ' /C [0.0 0.0 0.0]';
  12091. }
  12092. $out .= ' /Count 0'; // normally closed item
  12093. $out .= ' >>';
  12094. $out .= "\n".'endobj';
  12095. $this->_out($out);
  12096. }
  12097. //Outline root
  12098. $this->OutlineRoot = $this->_newobj();
  12099. $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
  12100. }
  12101. // --- JAVASCRIPT ------------------------------------------------------
  12102. /**
  12103. * Adds a javascript
  12104. * @param string $script Javascript code
  12105. * @public
  12106. * @author Johannes G\FCntert, Nicola Asuni
  12107. * @since 2.1.002 (2008-02-12)
  12108. */
  12109. public function IncludeJS($script) {
  12110. $this->javascript .= $script;
  12111. }
  12112. /**
  12113. * Adds a javascript object and return object ID
  12114. * @param string $script Javascript code
  12115. * @param boolean $onload if true executes this object when opening the document
  12116. * @return int internal object ID
  12117. * @public
  12118. * @author Nicola Asuni
  12119. * @since 4.8.000 (2009-09-07)
  12120. */
  12121. public function addJavascriptObject($script, $onload=false) {
  12122. if ($this->pdfa_mode) {
  12123. // javascript is not allowed in PDF/A mode
  12124. return false;
  12125. }
  12126. ++$this->n;
  12127. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  12128. return $this->n;
  12129. }
  12130. /**
  12131. * Create a javascript PDF string.
  12132. * @protected
  12133. * @author Johannes G\FCntert, Nicola Asuni
  12134. * @since 2.1.002 (2008-02-12)
  12135. */
  12136. protected function _putjavascript() {
  12137. if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
  12138. return;
  12139. }
  12140. if (strpos($this->javascript, 'this.addField') > 0) {
  12141. if (!$this->ur['enabled']) {
  12142. //$this->setUserRights();
  12143. }
  12144. // the following two lines are used to avoid form fields duplication after saving
  12145. // The addField method only works when releasing user rights (UR3)
  12146. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  12147. $jsb = "getField('tcpdfdocsaved').value='saved';";
  12148. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  12149. }
  12150. // name tree for javascript
  12151. $this->n_js = '<< /Names [';
  12152. if (!empty($this->javascript)) {
  12153. $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
  12154. }
  12155. if (!empty($this->js_objects)) {
  12156. foreach ($this->js_objects as $key => $val) {
  12157. if ($val['onload']) {
  12158. $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
  12159. }
  12160. }
  12161. }
  12162. $this->n_js .= ' ] >>';
  12163. // default Javascript object
  12164. if (!empty($this->javascript)) {
  12165. $obj_id = $this->_newobj();
  12166. $out = '<< /S /JavaScript';
  12167. $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
  12168. $out .= ' >>';
  12169. $out .= "\n".'endobj';
  12170. $this->_out($out);
  12171. }
  12172. // additional Javascript objects
  12173. if (!empty($this->js_objects)) {
  12174. foreach ($this->js_objects as $key => $val) {
  12175. $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  12176. $this->_out($out);
  12177. }
  12178. }
  12179. }
  12180. /**
  12181. * Adds a javascript form field.
  12182. * @param string $type field type
  12183. * @param string $name field name
  12184. * @param int $x horizontal position
  12185. * @param int $y vertical position
  12186. * @param int $w width
  12187. * @param int $h height
  12188. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12189. * @protected
  12190. * @author Denis Van Nuffelen, Nicola Asuni
  12191. * @since 2.1.002 (2008-02-12)
  12192. */
  12193. protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
  12194. if ($this->rtl) {
  12195. $x = $x - $w;
  12196. }
  12197. // the followind avoid fields duplication after saving the document
  12198. $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
  12199. $k = $this->k;
  12200. $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";
  12201. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  12202. foreach($prop as $key => $val) {
  12203. if (strcmp(substr($key, -5), 'Color') == 0) {
  12204. $val = TCPDF_COLORS::_JScolor($val);
  12205. } else {
  12206. $val = "'".$val."'";
  12207. }
  12208. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  12209. }
  12210. if ($this->rtl) {
  12211. $this->x -= $w;
  12212. } else {
  12213. $this->x += $w;
  12214. }
  12215. $this->javascript .= '}';
  12216. }
  12217. // --- FORM FIELDS -----------------------------------------------------
  12218. /**
  12219. * Set default properties for form fields.
  12220. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12221. * @public
  12222. * @author Nicola Asuni
  12223. * @since 4.8.000 (2009-09-06)
  12224. */
  12225. public function setFormDefaultProp($prop=array()) {
  12226. $this->default_form_prop = $prop;
  12227. }
  12228. /**
  12229. * Return the default properties for form fields.
  12230. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12231. * @public
  12232. * @author Nicola Asuni
  12233. * @since 4.8.000 (2009-09-06)
  12234. */
  12235. public function getFormDefaultProp() {
  12236. return $this->default_form_prop;
  12237. }
  12238. /**
  12239. * Creates a text field
  12240. * @param string $name field name
  12241. * @param float $w Width of the rectangle
  12242. * @param float $h Height of the rectangle
  12243. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12244. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12245. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12246. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12247. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12248. * @public
  12249. * @author Nicola Asuni
  12250. * @since 4.8.000 (2009-09-07)
  12251. */
  12252. public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
  12253. if (TCPDF_STATIC::empty_string($x)) {
  12254. $x = $this->x;
  12255. }
  12256. if (TCPDF_STATIC::empty_string($y)) {
  12257. $y = $this->y;
  12258. }
  12259. // check page for no-write regions and adapt page margins if necessary
  12260. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12261. if ($js) {
  12262. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  12263. return;
  12264. }
  12265. // get default style
  12266. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12267. // get annotation data
  12268. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12269. // set default appearance stream
  12270. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12271. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12272. $popt['da'] = $fontstyle;
  12273. // build appearance stream
  12274. $popt['ap'] = array();
  12275. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12276. $text = '';
  12277. if (isset($prop['value']) AND !empty($prop['value'])) {
  12278. $text = $prop['value'];
  12279. } elseif (isset($opt['v']) AND !empty($opt['v'])) {
  12280. $text = $opt['v'];
  12281. }
  12282. $tmpid = $this->startTemplate($w, $h, false);
  12283. $align = '';
  12284. if (isset($popt['q'])) {
  12285. switch ($popt['q']) {
  12286. case 0: {
  12287. $align = 'L';
  12288. break;
  12289. }
  12290. case 1: {
  12291. $align = 'C';
  12292. break;
  12293. }
  12294. case 2: {
  12295. $align = 'R';
  12296. break;
  12297. }
  12298. default: {
  12299. $align = '';
  12300. break;
  12301. }
  12302. }
  12303. }
  12304. $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12305. $this->endTemplate();
  12306. --$this->n;
  12307. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12308. unset($this->xobjects[$tmpid]);
  12309. $popt['ap']['n'] .= 'Q EMC';
  12310. // merge options
  12311. $opt = array_merge($popt, $opt);
  12312. // remove some conflicting options
  12313. unset($opt['bs']);
  12314. // set remaining annotation data
  12315. $opt['Subtype'] = 'Widget';
  12316. $opt['ft'] = 'Tx';
  12317. $opt['t'] = $name;
  12318. // Additional annotation's parameters (check _putannotsobj() method):
  12319. //$opt['f']
  12320. //$opt['as']
  12321. //$opt['bs']
  12322. //$opt['be']
  12323. //$opt['c']
  12324. //$opt['border']
  12325. //$opt['h']
  12326. //$opt['mk'];
  12327. //$opt['mk']['r']
  12328. //$opt['mk']['bc'];
  12329. //$opt['mk']['bg'];
  12330. unset($opt['mk']['ca']);
  12331. unset($opt['mk']['rc']);
  12332. unset($opt['mk']['ac']);
  12333. unset($opt['mk']['i']);
  12334. unset($opt['mk']['ri']);
  12335. unset($opt['mk']['ix']);
  12336. unset($opt['mk']['if']);
  12337. //$opt['mk']['if']['sw'];
  12338. //$opt['mk']['if']['s'];
  12339. //$opt['mk']['if']['a'];
  12340. //$opt['mk']['if']['fb'];
  12341. unset($opt['mk']['tp']);
  12342. //$opt['tu']
  12343. //$opt['tm']
  12344. //$opt['ff']
  12345. //$opt['v']
  12346. //$opt['dv']
  12347. //$opt['a']
  12348. //$opt['aa']
  12349. //$opt['q']
  12350. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12351. if ($this->rtl) {
  12352. $this->x -= $w;
  12353. } else {
  12354. $this->x += $w;
  12355. }
  12356. }
  12357. /**
  12358. * Creates a RadioButton field.
  12359. * @param string $name Field name.
  12360. * @param int $w Width of the radio button.
  12361. * @param array $prop Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12362. * @param array $opt Annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12363. * @param string $onvalue Value to be returned if selected.
  12364. * @param boolean $checked Define the initial state.
  12365. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12366. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12367. * @param boolean $js If true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12368. * @public
  12369. * @author Nicola Asuni
  12370. * @since 4.8.000 (2009-09-07)
  12371. */
  12372. public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x=null, $y=null, $js=false) {
  12373. if (TCPDF_STATIC::empty_string($x)) {
  12374. $x = $this->x;
  12375. }
  12376. if (TCPDF_STATIC::empty_string($y)) {
  12377. $y = $this->y;
  12378. }
  12379. // check page for no-write regions and adapt page margins if necessary
  12380. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12381. if ($js) {
  12382. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  12383. return;
  12384. }
  12385. if (TCPDF_STATIC::empty_string($onvalue)) {
  12386. $onvalue = 'On';
  12387. }
  12388. if ($checked) {
  12389. $defval = $onvalue;
  12390. } else {
  12391. $defval = 'Off';
  12392. }
  12393. // set font
  12394. $font = 'zapfdingbats';
  12395. if ($this->pdfa_mode) {
  12396. // all fonts must be embedded
  12397. $font = 'pdfa'.$font;
  12398. }
  12399. $this->AddFont($font);
  12400. $tmpfont = $this->getFontBuffer($font);
  12401. // set data for parent group
  12402. if (!isset($this->radiobutton_groups[$this->page])) {
  12403. $this->radiobutton_groups[$this->page] = array();
  12404. }
  12405. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  12406. $this->radiobutton_groups[$this->page][$name] = array();
  12407. ++$this->n;
  12408. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  12409. $this->radio_groups[] = $this->n;
  12410. }
  12411. $kid = ($this->n + 1);
  12412. // save object ID to be added on Kids entry on parent object
  12413. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  12414. // get default style
  12415. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12416. $prop['NoToggleToOff'] = 'true';
  12417. $prop['Radio'] = 'true';
  12418. $prop['borderStyle'] = 'inset';
  12419. // get annotation data
  12420. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12421. // set additional default options
  12422. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12423. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12424. $popt['da'] = $fontstyle;
  12425. // build appearance stream
  12426. $popt['ap'] = array();
  12427. $popt['ap']['n'] = array();
  12428. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
  12429. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12430. $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);
  12431. $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);
  12432. if (!isset($popt['mk'])) {
  12433. $popt['mk'] = array();
  12434. }
  12435. $popt['mk']['ca'] = '(l)';
  12436. // merge options
  12437. $opt = array_merge($popt, $opt);
  12438. // set remaining annotation data
  12439. $opt['Subtype'] = 'Widget';
  12440. $opt['ft'] = 'Btn';
  12441. if ($checked) {
  12442. $opt['v'] = array('/'.$onvalue);
  12443. $opt['as'] = $onvalue;
  12444. } else {
  12445. $opt['as'] = 'Off';
  12446. }
  12447. // store readonly flag
  12448. if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
  12449. $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
  12450. }
  12451. $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
  12452. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12453. if ($this->rtl) {
  12454. $this->x -= $w;
  12455. } else {
  12456. $this->x += $w;
  12457. }
  12458. }
  12459. /**
  12460. * Creates a List-box field
  12461. * @param string $name field name
  12462. * @param int $w width
  12463. * @param int $h height
  12464. * @param array $values array containing the list of values.
  12465. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12466. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12467. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12468. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12469. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12470. * @public
  12471. * @author Nicola Asuni
  12472. * @since 4.8.000 (2009-09-07)
  12473. */
  12474. public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
  12475. if (TCPDF_STATIC::empty_string($x)) {
  12476. $x = $this->x;
  12477. }
  12478. if (TCPDF_STATIC::empty_string($y)) {
  12479. $y = $this->y;
  12480. }
  12481. // check page for no-write regions and adapt page margins if necessary
  12482. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12483. if ($js) {
  12484. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  12485. $s = '';
  12486. foreach ($values as $value) {
  12487. if (is_array($value)) {
  12488. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12489. } else {
  12490. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12491. }
  12492. }
  12493. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12494. return;
  12495. }
  12496. // get default style
  12497. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12498. // get annotation data
  12499. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12500. // set additional default values
  12501. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12502. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12503. $popt['da'] = $fontstyle;
  12504. // build appearance stream
  12505. $popt['ap'] = array();
  12506. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12507. $text = '';
  12508. foreach($values as $item) {
  12509. if (is_array($item)) {
  12510. $text .= $item[1]."\n";
  12511. } else {
  12512. $text .= $item."\n";
  12513. }
  12514. }
  12515. $tmpid = $this->startTemplate($w, $h, false);
  12516. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12517. $this->endTemplate();
  12518. --$this->n;
  12519. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12520. unset($this->xobjects[$tmpid]);
  12521. $popt['ap']['n'] .= 'Q EMC';
  12522. // merge options
  12523. $opt = array_merge($popt, $opt);
  12524. // set remaining annotation data
  12525. $opt['Subtype'] = 'Widget';
  12526. $opt['ft'] = 'Ch';
  12527. $opt['t'] = $name;
  12528. $opt['opt'] = $values;
  12529. unset($opt['mk']['ca']);
  12530. unset($opt['mk']['rc']);
  12531. unset($opt['mk']['ac']);
  12532. unset($opt['mk']['i']);
  12533. unset($opt['mk']['ri']);
  12534. unset($opt['mk']['ix']);
  12535. unset($opt['mk']['if']);
  12536. unset($opt['mk']['tp']);
  12537. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12538. if ($this->rtl) {
  12539. $this->x -= $w;
  12540. } else {
  12541. $this->x += $w;
  12542. }
  12543. }
  12544. /**
  12545. * Creates a Combo-box field
  12546. * @param string $name field name
  12547. * @param int $w width
  12548. * @param int $h height
  12549. * @param array $values array containing the list of values.
  12550. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12551. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12552. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12553. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12554. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12555. * @public
  12556. * @author Nicola Asuni
  12557. * @since 4.8.000 (2009-09-07)
  12558. */
  12559. public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
  12560. if (TCPDF_STATIC::empty_string($x)) {
  12561. $x = $this->x;
  12562. }
  12563. if (TCPDF_STATIC::empty_string($y)) {
  12564. $y = $this->y;
  12565. }
  12566. // check page for no-write regions and adapt page margins if necessary
  12567. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12568. if ($js) {
  12569. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  12570. $s = '';
  12571. foreach ($values as $value) {
  12572. if (is_array($value)) {
  12573. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12574. } else {
  12575. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12576. }
  12577. }
  12578. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12579. return;
  12580. }
  12581. // get default style
  12582. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12583. $prop['Combo'] = true;
  12584. // get annotation data
  12585. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12586. // set additional default options
  12587. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12588. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12589. $popt['da'] = $fontstyle;
  12590. // build appearance stream
  12591. $popt['ap'] = array();
  12592. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12593. $text = '';
  12594. foreach($values as $item) {
  12595. if (is_array($item)) {
  12596. $text .= $item[1]."\n";
  12597. } else {
  12598. $text .= $item."\n";
  12599. }
  12600. }
  12601. $tmpid = $this->startTemplate($w, $h, false);
  12602. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12603. $this->endTemplate();
  12604. --$this->n;
  12605. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12606. unset($this->xobjects[$tmpid]);
  12607. $popt['ap']['n'] .= 'Q EMC';
  12608. // merge options
  12609. $opt = array_merge($popt, $opt);
  12610. // set remaining annotation data
  12611. $opt['Subtype'] = 'Widget';
  12612. $opt['ft'] = 'Ch';
  12613. $opt['t'] = $name;
  12614. $opt['opt'] = $values;
  12615. unset($opt['mk']['ca']);
  12616. unset($opt['mk']['rc']);
  12617. unset($opt['mk']['ac']);
  12618. unset($opt['mk']['i']);
  12619. unset($opt['mk']['ri']);
  12620. unset($opt['mk']['ix']);
  12621. unset($opt['mk']['if']);
  12622. unset($opt['mk']['tp']);
  12623. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12624. if ($this->rtl) {
  12625. $this->x -= $w;
  12626. } else {
  12627. $this->x += $w;
  12628. }
  12629. }
  12630. /**
  12631. * Creates a CheckBox field
  12632. * @param string $name field name
  12633. * @param int $w width
  12634. * @param boolean $checked define the initial state.
  12635. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12636. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12637. * @param string $onvalue value to be returned if selected.
  12638. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12639. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12640. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12641. * @public
  12642. * @author Nicola Asuni
  12643. * @since 4.8.000 (2009-09-07)
  12644. */
  12645. public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x=null, $y=null, $js=false) {
  12646. if (TCPDF_STATIC::empty_string($x)) {
  12647. $x = $this->x;
  12648. }
  12649. if (TCPDF_STATIC::empty_string($y)) {
  12650. $y = $this->y;
  12651. }
  12652. // check page for no-write regions and adapt page margins if necessary
  12653. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12654. if ($js) {
  12655. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  12656. return;
  12657. }
  12658. if (!isset($prop['value'])) {
  12659. $prop['value'] = array('Yes');
  12660. }
  12661. // get default style
  12662. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12663. $prop['borderStyle'] = 'inset';
  12664. // get annotation data
  12665. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12666. // set additional default options
  12667. $font = 'zapfdingbats';
  12668. if ($this->pdfa_mode) {
  12669. // all fonts must be embedded
  12670. $font = 'pdfa'.$font;
  12671. }
  12672. $this->AddFont($font);
  12673. $tmpfont = $this->getFontBuffer($font);
  12674. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12675. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12676. $popt['da'] = $fontstyle;
  12677. // build appearance stream
  12678. $popt['ap'] = array();
  12679. $popt['ap']['n'] = array();
  12680. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
  12681. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12682. $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);
  12683. $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);
  12684. // merge options
  12685. $opt = array_merge($popt, $opt);
  12686. // set remaining annotation data
  12687. $opt['Subtype'] = 'Widget';
  12688. $opt['ft'] = 'Btn';
  12689. $opt['t'] = $name;
  12690. if (TCPDF_STATIC::empty_string($onvalue)) {
  12691. $onvalue = 'Yes';
  12692. }
  12693. $opt['opt'] = array($onvalue);
  12694. if ($checked) {
  12695. $opt['v'] = array('/Yes');
  12696. $opt['as'] = 'Yes';
  12697. } else {
  12698. $opt['v'] = array('/Off');
  12699. $opt['as'] = 'Off';
  12700. }
  12701. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12702. if ($this->rtl) {
  12703. $this->x -= $w;
  12704. } else {
  12705. $this->x += $w;
  12706. }
  12707. }
  12708. /**
  12709. * Creates a button field
  12710. * @param string $name field name
  12711. * @param int $w width
  12712. * @param int $h height
  12713. * @param string $caption caption.
  12714. * @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.
  12715. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12716. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12717. * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12718. * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12719. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12720. * @public
  12721. * @author Nicola Asuni
  12722. * @since 4.8.000 (2009-09-07)
  12723. */
  12724. public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
  12725. if (TCPDF_STATIC::empty_string($x)) {
  12726. $x = $this->x;
  12727. }
  12728. if (TCPDF_STATIC::empty_string($y)) {
  12729. $y = $this->y;
  12730. }
  12731. // check page for no-write regions and adapt page margins if necessary
  12732. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12733. if ($js) {
  12734. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  12735. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  12736. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  12737. $this->javascript .= 'f'.$name.".highlight='push';\n";
  12738. $this->javascript .= 'f'.$name.".print=false;\n";
  12739. return;
  12740. }
  12741. // get default style
  12742. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12743. $prop['Pushbutton'] = 'true';
  12744. $prop['highlight'] = 'push';
  12745. $prop['display'] = 'display.noPrint';
  12746. // get annotation data
  12747. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12748. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12749. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12750. $popt['da'] = $fontstyle;
  12751. // build appearance stream
  12752. $popt['ap'] = array();
  12753. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12754. $tmpid = $this->startTemplate($w, $h, false);
  12755. $bw = (2 / $this->k); // border width
  12756. $border = array(
  12757. 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12758. 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
  12759. 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12760. 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
  12761. $this->setFillColor(204);
  12762. $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
  12763. $this->endTemplate();
  12764. --$this->n;
  12765. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12766. unset($this->xobjects[$tmpid]);
  12767. $popt['ap']['n'] .= 'Q EMC';
  12768. // set additional default options
  12769. if (!isset($popt['mk'])) {
  12770. $popt['mk'] = array();
  12771. }
  12772. $ann_obj_id = ($this->n + 1);
  12773. if (!empty($action) AND !is_array($action)) {
  12774. $ann_obj_id = ($this->n + 2);
  12775. }
  12776. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  12777. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  12778. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  12779. // merge options
  12780. $opt = array_merge($popt, $opt);
  12781. // set remaining annotation data
  12782. $opt['Subtype'] = 'Widget';
  12783. $opt['ft'] = 'Btn';
  12784. $opt['t'] = $caption;
  12785. $opt['v'] = $name;
  12786. if (!empty($action)) {
  12787. if (is_array($action)) {
  12788. // form action options as on section 12.7.5 of PDF32000_2008.
  12789. $opt['aa'] = '/D <<';
  12790. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  12791. foreach ($action AS $key => $val) {
  12792. if (($key == 'S') AND in_array($val, $bmode)) {
  12793. $opt['aa'] .= ' /S /'.$val;
  12794. } elseif (($key == 'F') AND (!empty($val))) {
  12795. $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
  12796. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  12797. $opt['aa'] .= ' /Fields [';
  12798. foreach ($val AS $field) {
  12799. $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
  12800. }
  12801. $opt['aa'] .= ']';
  12802. } elseif (($key == 'Flags')) {
  12803. $ff = 0;
  12804. if (is_array($val)) {
  12805. foreach ($val AS $flag) {
  12806. switch ($flag) {
  12807. case 'Include/Exclude': {
  12808. $ff += 1 << 0;
  12809. break;
  12810. }
  12811. case 'IncludeNoValueFields': {
  12812. $ff += 1 << 1;
  12813. break;
  12814. }
  12815. case 'ExportFormat': {
  12816. $ff += 1 << 2;
  12817. break;
  12818. }
  12819. case 'GetMethod': {
  12820. $ff += 1 << 3;
  12821. break;
  12822. }
  12823. case 'SubmitCoordinates': {
  12824. $ff += 1 << 4;
  12825. break;
  12826. }
  12827. case 'XFDF': {
  12828. $ff += 1 << 5;
  12829. break;
  12830. }
  12831. case 'IncludeAppendSaves': {
  12832. $ff += 1 << 6;
  12833. break;
  12834. }
  12835. case 'IncludeAnnotations': {
  12836. $ff += 1 << 7;
  12837. break;
  12838. }
  12839. case 'SubmitPDF': {
  12840. $ff += 1 << 8;
  12841. break;
  12842. }
  12843. case 'CanonicalFormat': {
  12844. $ff += 1 << 9;
  12845. break;
  12846. }
  12847. case 'ExclNonUserAnnots': {
  12848. $ff += 1 << 10;
  12849. break;
  12850. }
  12851. case 'ExclFKey': {
  12852. $ff += 1 << 11;
  12853. break;
  12854. }
  12855. case 'EmbedForm': {
  12856. $ff += 1 << 13;
  12857. break;
  12858. }
  12859. }
  12860. }
  12861. } else {
  12862. $ff = intval($val);
  12863. }
  12864. $opt['aa'] .= ' /Flags '.$ff;
  12865. }
  12866. }
  12867. $opt['aa'] .= ' >>';
  12868. } else {
  12869. // Javascript action or raw action command
  12870. $js_obj_id = $this->addJavascriptObject($action);
  12871. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  12872. }
  12873. }
  12874. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12875. if ($this->rtl) {
  12876. $this->x -= $w;
  12877. } else {
  12878. $this->x += $w;
  12879. }
  12880. }
  12881. // --- END FORMS FIELDS ------------------------------------------------
  12882. /**
  12883. * Add certification signature (DocMDP or UR3)
  12884. * You can set only one signature type
  12885. * @protected
  12886. * @author Nicola Asuni
  12887. * @since 4.6.008 (2009-05-07)
  12888. */
  12889. protected function _putsignature() {
  12890. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  12891. return;
  12892. }
  12893. $sigobjid = ($this->sig_obj_id + 1);
  12894. $out = $this->_getobj($sigobjid)."\n";
  12895. $out .= '<< /Type /Sig';
  12896. $out .= ' /Filter /Adobe.PPKLite';
  12897. $out .= ' /SubFilter /adbe.pkcs7.detached';
  12898. $out .= ' '.TCPDF_STATIC::$byterange_string;
  12899. $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
  12900. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  12901. $out .= ' /Reference ['; // array of signature reference dictionaries
  12902. $out .= ' << /Type /SigRef';
  12903. if ($this->signature_data['cert_type'] > 0) {
  12904. $out .= ' /TransformMethod /DocMDP';
  12905. $out .= ' /TransformParams <<';
  12906. $out .= ' /Type /TransformParams';
  12907. $out .= ' /P '.$this->signature_data['cert_type'];
  12908. $out .= ' /V /1.2';
  12909. } else {
  12910. $out .= ' /TransformMethod /UR3';
  12911. $out .= ' /TransformParams <<';
  12912. $out .= ' /Type /TransformParams';
  12913. $out .= ' /V /2.2';
  12914. if (!TCPDF_STATIC::empty_string($this->ur['document'])) {
  12915. $out .= ' /Document['.$this->ur['document'].']';
  12916. }
  12917. if (!TCPDF_STATIC::empty_string($this->ur['form'])) {
  12918. $out .= ' /Form['.$this->ur['form'].']';
  12919. }
  12920. if (!TCPDF_STATIC::empty_string($this->ur['signature'])) {
  12921. $out .= ' /Signature['.$this->ur['signature'].']';
  12922. }
  12923. if (!TCPDF_STATIC::empty_string($this->ur['annots'])) {
  12924. $out .= ' /Annots['.$this->ur['annots'].']';
  12925. }
  12926. if (!TCPDF_STATIC::empty_string($this->ur['ef'])) {
  12927. $out .= ' /EF['.$this->ur['ef'].']';
  12928. }
  12929. if (!TCPDF_STATIC::empty_string($this->ur['formex'])) {
  12930. $out .= ' /FormEX['.$this->ur['formex'].']';
  12931. }
  12932. }
  12933. $out .= ' >>'; // close TransformParams
  12934. // optional digest data (values must be calculated and replaced later)
  12935. //$out .= ' /Data ********** 0 R';
  12936. //$out .= ' /DigestMethod/MD5';
  12937. //$out .= ' /DigestLocation[********** 34]';
  12938. //$out .= ' /DigestValue<********************************>';
  12939. $out .= ' >>';
  12940. $out .= ' ]'; // end of reference
  12941. }
  12942. if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) {
  12943. $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
  12944. }
  12945. if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) {
  12946. $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
  12947. }
  12948. if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) {
  12949. $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
  12950. }
  12951. if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) {
  12952. $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
  12953. }
  12954. $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp);
  12955. $out .= ' >>';
  12956. $out .= "\n".'endobj';
  12957. $this->_out($out);
  12958. }
  12959. /**
  12960. * Set User's Rights for PDF Reader
  12961. * WARNING: This is experimental and currently do not work.
  12962. * Check the PDF Reference 8.7.1 Transform Methods,
  12963. * Table 8.105 Entries in the UR transform parameters dictionary
  12964. * @param boolean $enable if true enable user's rights on PDF reader
  12965. * @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.
  12966. * @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.
  12967. * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  12968. * @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.
  12969. * @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
  12970. Names specifying additional embedded-files-related usage rights for the document.
  12971. * @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.
  12972. * @public
  12973. * @author Nicola Asuni
  12974. * @since 2.9.000 (2008-03-26)
  12975. */
  12976. public function setUserRights(
  12977. $enable=true,
  12978. $document='/FullSave',
  12979. $annots='/Create/Delete/Modify/Copy/Import/Export',
  12980. $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  12981. $signature='/Modify',
  12982. $ef='/Create/Delete/Modify/Import',
  12983. $formex='') {
  12984. $this->ur['enabled'] = $enable;
  12985. $this->ur['document'] = $document;
  12986. $this->ur['annots'] = $annots;
  12987. $this->ur['form'] = $form;
  12988. $this->ur['signature'] = $signature;
  12989. $this->ur['ef'] = $ef;
  12990. $this->ur['formex'] = $formex;
  12991. if (!$this->sign) {
  12992. $this->setSignature('', '', '', '', 0, array());
  12993. }
  12994. }
  12995. /**
  12996. * Enable document signature (requires the OpenSSL Library).
  12997. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  12998. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12999. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  13000. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  13001. * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://')
  13002. * @param mixed $private_key private key (string or filename prefixed with 'file://')
  13003. * @param string $private_key_password password
  13004. * @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.
  13005. * @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.
  13006. * @param array $info array of option information: Name, Location, Reason, ContactInfo.
  13007. * @param string $approval Enable approval signature eg. for PDF incremental update
  13008. * @public
  13009. * @author Nicola Asuni
  13010. * @since 4.6.005 (2009-04-24)
  13011. */
  13012. public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array(), $approval='') {
  13013. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  13014. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  13015. // to convert pfx certificate to pem: openssl
  13016. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  13017. $this->sign = true;
  13018. ++$this->n;
  13019. $this->sig_obj_id = $this->n; // signature widget
  13020. ++$this->n; // signature object ($this->sig_obj_id + 1)
  13021. $this->signature_data = array();
  13022. if (strlen($signing_cert) == 0) {
  13023. $this->Error('Please provide a certificate file and password!');
  13024. }
  13025. if (strlen($private_key) == 0) {
  13026. $private_key = $signing_cert;
  13027. }
  13028. $this->signature_data['signcert'] = $signing_cert;
  13029. $this->signature_data['privkey'] = $private_key;
  13030. $this->signature_data['password'] = $private_key_password;
  13031. $this->signature_data['extracerts'] = $extracerts;
  13032. $this->signature_data['cert_type'] = $cert_type;
  13033. $this->signature_data['info'] = $info;
  13034. $this->signature_data['approval'] = $approval;
  13035. }
  13036. /**
  13037. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  13038. * @param float $x Abscissa of the upper-left corner.
  13039. * @param float $y Ordinate of the upper-left corner.
  13040. * @param float $w Width of the signature area.
  13041. * @param float $h Height of the signature area.
  13042. * @param int $page option page number (if < 0 the current page is used).
  13043. * @param string $name Name of the signature.
  13044. * @public
  13045. * @author Nicola Asuni
  13046. * @since 5.3.011 (2010-06-17)
  13047. */
  13048. public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  13049. $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  13050. }
  13051. /**
  13052. * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
  13053. * @param float $x Abscissa of the upper-left corner.
  13054. * @param float $y Ordinate of the upper-left corner.
  13055. * @param float $w Width of the signature area.
  13056. * @param float $h Height of the signature area.
  13057. * @param int $page option page number (if < 0 the current page is used).
  13058. * @param string $name Name of the signature.
  13059. * @public
  13060. * @author Nicola Asuni
  13061. * @since 5.9.101 (2011-07-06)
  13062. */
  13063. public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  13064. ++$this->n;
  13065. $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  13066. }
  13067. /**
  13068. * Get the array that defines the signature appearance (page and rectangle coordinates).
  13069. * @param float $x Abscissa of the upper-left corner.
  13070. * @param float $y Ordinate of the upper-left corner.
  13071. * @param float $w Width of the signature area.
  13072. * @param float $h Height of the signature area.
  13073. * @param int $page option page number (if < 0 the current page is used).
  13074. * @param string $name Name of the signature.
  13075. * @return array Array defining page and rectangle coordinates of signature appearance.
  13076. * @protected
  13077. * @author Nicola Asuni
  13078. * @since 5.9.101 (2011-07-06)
  13079. */
  13080. protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  13081. $sigapp = array();
  13082. if (($page < 1) OR ($page > $this->numpages)) {
  13083. $sigapp['page'] = $this->page;
  13084. } else {
  13085. $sigapp['page'] = intval($page);
  13086. }
  13087. if (empty($name)) {
  13088. $sigapp['name'] = 'Signature';
  13089. } else {
  13090. $sigapp['name'] = $name;
  13091. }
  13092. $a = $x * $this->k;
  13093. $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
  13094. $c = $w * $this->k;
  13095. $d = $h * $this->k;
  13096. $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a + $c), ($b + $d));
  13097. return $sigapp;
  13098. }
  13099. /**
  13100. * Enable document timestamping (requires the OpenSSL Library).
  13101. * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded.
  13102. * Use with digital signature only!
  13103. * @param string $tsa_host Time Stamping Authority (TSA) server (prefixed with 'https://')
  13104. * @param string $tsa_username Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional)
  13105. * @param string $tsa_password Specifies the password for TSA authorization (optional)
  13106. * @param string $tsa_cert Specifies the location of TSA certificate for authorization (optional for cURL)
  13107. * @public
  13108. * @author Richard Stockinger
  13109. * @since 6.0.090 (2014-06-16)
  13110. */
  13111. public function setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='') {
  13112. $this->tsa_data = array();
  13113. if (!function_exists('curl_init')) {
  13114. $this->Error('Please enable cURL PHP extension!');
  13115. }
  13116. if (strlen($tsa_host) == 0) {
  13117. $this->Error('Please specify the host of Time Stamping Authority (TSA)!');
  13118. }
  13119. $this->tsa_data['tsa_host'] = $tsa_host;
  13120. if (is_file($tsa_username)) {
  13121. $this->tsa_data['tsa_auth'] = $tsa_username;
  13122. } else {
  13123. $this->tsa_data['tsa_username'] = $tsa_username;
  13124. }
  13125. $this->tsa_data['tsa_password'] = $tsa_password;
  13126. $this->tsa_data['tsa_cert'] = $tsa_cert;
  13127. $this->tsa_timestamp = true;
  13128. }
  13129. /**
  13130. * NOT YET IMPLEMENTED
  13131. * Request TSA for a timestamp
  13132. * @param string $signature Digital signature as binary string
  13133. * @return string Timestamped digital signature
  13134. * @protected
  13135. * @author Richard Stockinger
  13136. * @since 6.0.090 (2014-06-16)
  13137. */
  13138. protected function applyTSA($signature) {
  13139. if (!$this->tsa_timestamp) {
  13140. return $signature;
  13141. }
  13142. //@TODO: implement this feature
  13143. return $signature;
  13144. }
  13145. /**
  13146. * Create a new page group.
  13147. * NOTE: call this function before calling AddPage()
  13148. * @param int|null $page starting group page (leave empty for next page).
  13149. * @public
  13150. * @since 3.0.000 (2008-03-27)
  13151. */
  13152. public function startPageGroup($page=null) {
  13153. if (empty($page)) {
  13154. $page = $this->page + 1;
  13155. }
  13156. $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
  13157. }
  13158. /**
  13159. * Set the starting page number.
  13160. * @param int $num Starting page number.
  13161. * @since 5.9.093 (2011-06-16)
  13162. * @public
  13163. */
  13164. public function setStartingPageNumber($num=1) {
  13165. $this->starting_page_number = max(0, intval($num));
  13166. }
  13167. /**
  13168. * Returns the string alias used right align page numbers.
  13169. * If the current font is unicode type, the returned string wil contain an additional open curly brace.
  13170. * @return string
  13171. * @since 5.9.099 (2011-06-27)
  13172. * @public
  13173. */
  13174. public function getAliasRightShift() {
  13175. // calculate aproximatively the ratio between widths of aliases and replacements.
  13176. $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}';
  13177. $rep = str_repeat(' ', $this->GetNumChars($ref));
  13178. $wrep = $this->GetStringWidth($rep);
  13179. if ($wrep > 0) {
  13180. $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep));
  13181. } else {
  13182. $wdiff = 1;
  13183. }
  13184. $sdiff = sprintf('%F', $wdiff);
  13185. $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}';
  13186. if ($this->isUnicodeFont()) {
  13187. $alias = '{'.$alias;
  13188. }
  13189. return $alias;
  13190. }
  13191. /**
  13192. * Returns the string alias used for the total number of pages.
  13193. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13194. * This alias will be replaced by the total number of pages in the document.
  13195. * @return string
  13196. * @since 4.0.018 (2008-08-08)
  13197. * @public
  13198. */
  13199. public function getAliasNbPages() {
  13200. if ($this->isUnicodeFont()) {
  13201. return '{'.TCPDF_STATIC::$alias_tot_pages.'}';
  13202. }
  13203. return TCPDF_STATIC::$alias_tot_pages;
  13204. }
  13205. /**
  13206. * Returns the string alias used for the page number.
  13207. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13208. * This alias will be replaced by the page number.
  13209. * @return string
  13210. * @since 4.5.000 (2009-01-02)
  13211. * @public
  13212. */
  13213. public function getAliasNumPage() {
  13214. if ($this->isUnicodeFont()) {
  13215. return '{'.TCPDF_STATIC::$alias_num_page.'}';
  13216. }
  13217. return TCPDF_STATIC::$alias_num_page;
  13218. }
  13219. /**
  13220. * Return the alias for the total number of pages in the current page group.
  13221. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13222. * This alias will be replaced by the total number of pages in this group.
  13223. * @return string alias of the current page group
  13224. * @public
  13225. * @since 3.0.000 (2008-03-27)
  13226. */
  13227. public function getPageGroupAlias() {
  13228. if ($this->isUnicodeFont()) {
  13229. return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}';
  13230. }
  13231. return TCPDF_STATIC::$alias_group_tot_pages;
  13232. }
  13233. /**
  13234. * Return the alias for the page number on the current page group.
  13235. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13236. * This alias will be replaced by the page number (relative to the belonging group).
  13237. * @return string alias of the current page group
  13238. * @public
  13239. * @since 4.5.000 (2009-01-02)
  13240. */
  13241. public function getPageNumGroupAlias() {
  13242. if ($this->isUnicodeFont()) {
  13243. return '{'.TCPDF_STATIC::$alias_group_num_page.'}';
  13244. }
  13245. return TCPDF_STATIC::$alias_group_num_page;
  13246. }
  13247. /**
  13248. * Return the current page in the group.
  13249. * @return int current page in the group
  13250. * @public
  13251. * @since 3.0.000 (2008-03-27)
  13252. */
  13253. public function getGroupPageNo() {
  13254. return $this->pagegroups[$this->currpagegroup];
  13255. }
  13256. /**
  13257. * Returns the current group page number formatted as a string.
  13258. * @public
  13259. * @since 4.3.003 (2008-11-18)
  13260. * @see PaneNo(), formatPageNumber()
  13261. */
  13262. public function getGroupPageNoFormatted() {
  13263. return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo());
  13264. }
  13265. /**
  13266. * Returns the current page number formatted as a string.
  13267. * @public
  13268. * @since 4.2.005 (2008-11-06)
  13269. * @see PaneNo(), formatPageNumber()
  13270. */
  13271. public function PageNoFormatted() {
  13272. return TCPDF_STATIC::formatPageNumber($this->PageNo());
  13273. }
  13274. /**
  13275. * Put pdf layers.
  13276. * @protected
  13277. * @since 3.0.000 (2008-03-27)
  13278. */
  13279. protected function _putocg() {
  13280. if (empty($this->pdflayers)) {
  13281. return;
  13282. }
  13283. foreach ($this->pdflayers as $key => $layer) {
  13284. $this->pdflayers[$key]['objid'] = $this->_newobj();
  13285. $out = '<< /Type /OCG';
  13286. $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
  13287. $out .= ' /Usage <<';
  13288. if (isset($layer['print']) AND ($layer['print'] !== NULL)) {
  13289. $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
  13290. }
  13291. $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
  13292. $out .= ' >> >>';
  13293. $out .= "\n".'endobj';
  13294. $this->_out($out);
  13295. }
  13296. }
  13297. /**
  13298. * Start a new pdf layer.
  13299. * @param string $name Layer name (only a-z letters and numbers). Leave empty for automatic name.
  13300. * @param boolean|null $print Set to TRUE to print this layer, FALSE to not print and NULL to not set this option
  13301. * @param boolean $view Set to true to view this layer.
  13302. * @param boolean $lock If true lock the layer
  13303. * @public
  13304. * @since 5.9.102 (2011-07-13)
  13305. */
  13306. public function startLayer($name='', $print=true, $view=true, $lock=true) {
  13307. if ($this->state != 2) {
  13308. return;
  13309. }
  13310. $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
  13311. if (empty($name)) {
  13312. $name = $layer;
  13313. } else {
  13314. $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
  13315. }
  13316. $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view, 'lock' => $lock);
  13317. $this->openMarkedContent = true;
  13318. $this->_out('/OC /'.$layer.' BDC');
  13319. }
  13320. /**
  13321. * End the current PDF layer.
  13322. * @public
  13323. * @since 5.9.102 (2011-07-13)
  13324. */
  13325. public function endLayer() {
  13326. if ($this->state != 2) {
  13327. return;
  13328. }
  13329. if ($this->openMarkedContent) {
  13330. // close existing open marked-content layer
  13331. $this->_out('EMC');
  13332. $this->openMarkedContent = false;
  13333. }
  13334. }
  13335. /**
  13336. * Set the visibility of the successive elements.
  13337. * This can be useful, for instance, to put a background
  13338. * image or color that will show on screen but won't print.
  13339. * @param string $v visibility mode. Legal values are: all, print, screen or view.
  13340. * @public
  13341. * @since 3.0.000 (2008-03-27)
  13342. */
  13343. public function setVisibility($v) {
  13344. if ($this->state != 2) {
  13345. return;
  13346. }
  13347. $this->endLayer();
  13348. switch($v) {
  13349. case 'print': {
  13350. $this->startLayer('Print', true, false);
  13351. break;
  13352. }
  13353. case 'view':
  13354. case 'screen': {
  13355. $this->startLayer('View', false, true);
  13356. break;
  13357. }
  13358. case 'all': {
  13359. $this->_out('');
  13360. break;
  13361. }
  13362. default: {
  13363. $this->Error('Incorrect visibility: '.$v);
  13364. break;
  13365. }
  13366. }
  13367. }
  13368. /**
  13369. * Add transparency parameters to the current extgstate
  13370. * @param array $parms parameters
  13371. * @return int|void the number of extgstates
  13372. * @protected
  13373. * @since 3.0.000 (2008-03-27)
  13374. */
  13375. protected function addExtGState($parms) {
  13376. if ($this->pdfa_mode || $this->pdfa_version >= 2) {
  13377. // transparencies are not allowed in PDF/A mode
  13378. return;
  13379. }
  13380. // check if this ExtGState already exist
  13381. foreach ($this->extgstates as $i => $ext) {
  13382. if ($ext['parms'] == $parms) {
  13383. if ($this->inxobj) {
  13384. // we are inside an XObject template
  13385. $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
  13386. }
  13387. // return reference to existing ExtGState
  13388. return $i;
  13389. }
  13390. }
  13391. $n = (count($this->extgstates) + 1);
  13392. $this->extgstates[$n] = array('parms' => $parms);
  13393. if ($this->inxobj) {
  13394. // we are inside an XObject template
  13395. $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
  13396. }
  13397. return $n;
  13398. }
  13399. /**
  13400. * Add an extgstate
  13401. * @param int $gs extgstate
  13402. * @protected
  13403. * @since 3.0.000 (2008-03-27)
  13404. */
  13405. protected function setExtGState($gs) {
  13406. if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
  13407. // transparency is not allowed in PDF/A-1 mode
  13408. return;
  13409. }
  13410. $this->_out(sprintf('/GS%d gs', $gs));
  13411. }
  13412. /**
  13413. * Put extgstates for object transparency
  13414. * @protected
  13415. * @since 3.0.000 (2008-03-27)
  13416. */
  13417. protected function _putextgstates() {
  13418. foreach ($this->extgstates as $i => $ext) {
  13419. $this->extgstates[$i]['n'] = $this->_newobj();
  13420. $out = '<< /Type /ExtGState';
  13421. foreach ($ext['parms'] as $k => $v) {
  13422. if (is_float($v)) {
  13423. $v = sprintf('%F', $v);
  13424. } elseif ($v === true) {
  13425. $v = 'true';
  13426. } elseif ($v === false) {
  13427. $v = 'false';
  13428. }
  13429. $out .= ' /'.$k.' '.$v;
  13430. }
  13431. $out .= ' >>';
  13432. $out .= "\n".'endobj';
  13433. $this->_out($out);
  13434. }
  13435. }
  13436. /**
  13437. * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
  13438. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13439. * @param boolean $stroking If true apply overprint for stroking operations.
  13440. * @param boolean|null $nonstroking If true apply overprint for painting operations other than stroking.
  13441. * @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).
  13442. * @public
  13443. * @since 5.9.152 (2012-03-23)
  13444. */
  13445. public function setOverprint($stroking=true, $nonstroking=null, $mode=0) {
  13446. if ($this->state != 2) {
  13447. return;
  13448. }
  13449. $stroking = $stroking ? true : false;
  13450. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13451. // default value if not set
  13452. $nonstroking = $stroking;
  13453. } else {
  13454. $nonstroking = $nonstroking ? true : false;
  13455. }
  13456. if (($mode != 0) AND ($mode != 1)) {
  13457. $mode = 0;
  13458. }
  13459. $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
  13460. $gs = $this->addExtGState($this->overprint);
  13461. $this->setExtGState($gs);
  13462. }
  13463. /**
  13464. * Get the overprint mode array (OP, op, OPM).
  13465. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13466. * @return array<string,bool|int>
  13467. * @public
  13468. * @since 5.9.152 (2012-03-23)
  13469. */
  13470. public function getOverprint() {
  13471. return $this->overprint;
  13472. }
  13473. /**
  13474. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  13475. * @param float $stroking Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
  13476. * @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
  13477. * @param float|null $nonstroking Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
  13478. * @param boolean $ais
  13479. * @public
  13480. * @since 3.0.000 (2008-03-27)
  13481. */
  13482. public function setAlpha($stroking=1, $bm='Normal', $nonstroking=null, $ais=false) {
  13483. if ($this->pdfa_mode && $this->pdfa_version < 2) {
  13484. // transparency is not allowed in PDF/A-1 mode
  13485. return;
  13486. }
  13487. $stroking = floatval($stroking);
  13488. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13489. // default value if not set
  13490. $nonstroking = $stroking;
  13491. } else {
  13492. $nonstroking = floatval($nonstroking);
  13493. }
  13494. if ($bm[0] == '/') {
  13495. // remove trailing slash
  13496. $bm = substr($bm, 1);
  13497. }
  13498. if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  13499. $bm = 'Normal';
  13500. }
  13501. $ais = $ais ? true : false;
  13502. $this->alpha = array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
  13503. $gs = $this->addExtGState($this->alpha);
  13504. $this->setExtGState($gs);
  13505. }
  13506. /**
  13507. * Get the alpha mode array (CA, ca, BM, AIS).
  13508. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13509. * @return array<string,bool|string>
  13510. * @public
  13511. * @since 5.9.152 (2012-03-23)
  13512. */
  13513. public function getAlpha() {
  13514. return $this->alpha;
  13515. }
  13516. /**
  13517. * Set the default JPEG compression quality (1-100)
  13518. * @param int $quality JPEG quality, integer between 1 and 100
  13519. * @public
  13520. * @since 3.0.000 (2008-03-27)
  13521. */
  13522. public function setJPEGQuality($quality) {
  13523. if (($quality < 1) OR ($quality > 100)) {
  13524. $quality = 75;
  13525. }
  13526. $this->jpeg_quality = intval($quality);
  13527. }
  13528. /**
  13529. * Set the default number of columns in a row for HTML tables.
  13530. * @param int $cols number of columns
  13531. * @public
  13532. * @since 3.0.014 (2008-06-04)
  13533. */
  13534. public function setDefaultTableColumns($cols=4) {
  13535. $this->default_table_columns = intval($cols);
  13536. }
  13537. /**
  13538. * Set the height of the cell (line height) respect the font height.
  13539. * @param float $h cell proportion respect font height (typical value = 1.25).
  13540. * @public
  13541. * @since 3.0.014 (2008-06-04)
  13542. */
  13543. public function setCellHeightRatio($h) {
  13544. $this->cell_height_ratio = $h;
  13545. }
  13546. /**
  13547. * return the height of cell repect font height.
  13548. * @public
  13549. * @return float
  13550. * @since 4.0.012 (2008-07-24)
  13551. */
  13552. public function getCellHeightRatio() {
  13553. return $this->cell_height_ratio;
  13554. }
  13555. /**
  13556. * Set the PDF version (check PDF reference for valid values).
  13557. * @param string $version PDF document version.
  13558. * @public
  13559. * @since 3.1.000 (2008-06-09)
  13560. */
  13561. public function setPDFVersion($version='1.7') {
  13562. if ($this->pdfa_mode && $this->pdfa_version == 1 ) {
  13563. // PDF/A-1 mode
  13564. $this->PDFVersion = '1.4';
  13565. } elseif ($this->pdfa_mode && $this->pdfa_version >= 2 ) {
  13566. // PDF/A-2 mode
  13567. $this->PDFVersion = '1.7';
  13568. } else {
  13569. $this->PDFVersion = $version;
  13570. }
  13571. }
  13572. /**
  13573. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  13574. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  13575. * <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>
  13576. * @param array $preferences array of options.
  13577. * @author Nicola Asuni
  13578. * @public
  13579. * @since 3.1.000 (2008-06-09)
  13580. */
  13581. public function setViewerPreferences($preferences) {
  13582. $this->viewer_preferences = $preferences;
  13583. }
  13584. /**
  13585. * Paints color transition registration bars
  13586. * @param float $x abscissa of the top left corner of the rectangle.
  13587. * @param float $y ordinate of the top left corner of the rectangle.
  13588. * @param float $w width of the rectangle.
  13589. * @param float $h height of the rectangle.
  13590. * @param boolean $transition if true prints tcolor transitions to white.
  13591. * @param boolean $vertical if true prints bar vertically.
  13592. * @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.
  13593. * @author Nicola Asuni
  13594. * @since 4.9.000 (2010-03-26)
  13595. * @public
  13596. */
  13597. public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
  13598. if (strpos($colors, 'ALLSPOT') !== false) {
  13599. // expand spot colors
  13600. $spot_colors = '';
  13601. foreach ($this->spot_colors as $spot_color_name => $v) {
  13602. $spot_colors .= ','.$spot_color_name;
  13603. }
  13604. if (!empty($spot_colors)) {
  13605. $spot_colors = substr($spot_colors, 1);
  13606. $colors = str_replace('ALLSPOT', $spot_colors, $colors);
  13607. } else {
  13608. $colors = str_replace('ALLSPOT', 'NONE', $colors);
  13609. }
  13610. }
  13611. $bars = explode(',', $colors);
  13612. $numbars = count($bars); // number of bars to print
  13613. if ($numbars <= 0) {
  13614. return;
  13615. }
  13616. // set bar measures
  13617. if ($vertical) {
  13618. $coords = array(0, 0, 0, 1);
  13619. $wb = $w / $numbars; // bar width
  13620. $hb = $h; // bar height
  13621. $xd = $wb; // delta x
  13622. $yd = 0; // delta y
  13623. } else {
  13624. $coords = array(1, 0, 0, 0);
  13625. $wb = $w; // bar width
  13626. $hb = $h / $numbars; // bar height
  13627. $xd = 0; // delta x
  13628. $yd = $hb; // delta y
  13629. }
  13630. $xb = $x;
  13631. $yb = $y;
  13632. foreach ($bars as $col) {
  13633. switch ($col) {
  13634. // set transition colors
  13635. case 'A': { // BLACK (GRAYSCALE)
  13636. $col_a = array(255);
  13637. $col_b = array(0);
  13638. break;
  13639. }
  13640. case 'W': { // WHITE (GRAYSCALE)
  13641. $col_a = array(0);
  13642. $col_b = array(255);
  13643. break;
  13644. }
  13645. case 'R': { // RED (RGB)
  13646. $col_a = array(255,255,255);
  13647. $col_b = array(255,0,0);
  13648. break;
  13649. }
  13650. case 'G': { // GREEN (RGB)
  13651. $col_a = array(255,255,255);
  13652. $col_b = array(0,255,0);
  13653. break;
  13654. }
  13655. case 'B': { // BLUE (RGB)
  13656. $col_a = array(255,255,255);
  13657. $col_b = array(0,0,255);
  13658. break;
  13659. }
  13660. case 'C': { // CYAN (CMYK)
  13661. $col_a = array(0,0,0,0);
  13662. $col_b = array(100,0,0,0);
  13663. break;
  13664. }
  13665. case 'M': { // MAGENTA (CMYK)
  13666. $col_a = array(0,0,0,0);
  13667. $col_b = array(0,100,0,0);
  13668. break;
  13669. }
  13670. case 'Y': { // YELLOW (CMYK)
  13671. $col_a = array(0,0,0,0);
  13672. $col_b = array(0,0,100,0);
  13673. break;
  13674. }
  13675. case 'K': { // KEY - BLACK (CMYK)
  13676. $col_a = array(0,0,0,0);
  13677. $col_b = array(0,0,0,100);
  13678. break;
  13679. }
  13680. case 'RGB': { // BLACK REGISTRATION (RGB)
  13681. $col_a = array(255,255,255);
  13682. $col_b = array(0,0,0);
  13683. break;
  13684. }
  13685. case 'CMYK': { // BLACK REGISTRATION (CMYK)
  13686. $col_a = array(0,0,0,0);
  13687. $col_b = array(100,100,100,100);
  13688. break;
  13689. }
  13690. case 'ALL': { // SPOT COLOR REGISTRATION
  13691. $col_a = array(0,0,0,0,'None');
  13692. $col_b = array(100,100,100,100,'All');
  13693. break;
  13694. }
  13695. case 'NONE': { // SKIP THIS COLOR
  13696. $col_a = array(0,0,0,0,'None');
  13697. $col_b = array(0,0,0,0,'None');
  13698. break;
  13699. }
  13700. default: { // SPECIFIC SPOT COLOR NAME
  13701. $col_a = array(0,0,0,0,'None');
  13702. $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors);
  13703. if ($col_b === false) {
  13704. // in case of error defaults to the registration color
  13705. $col_b = array(100,100,100,100,'All');
  13706. }
  13707. break;
  13708. }
  13709. }
  13710. if ($col != 'NONE') {
  13711. if ($transition) {
  13712. // color gradient
  13713. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  13714. } else {
  13715. $this->setFillColorArray($col_b);
  13716. // colored rectangle
  13717. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  13718. }
  13719. $xb += $xd;
  13720. $yb += $yd;
  13721. }
  13722. }
  13723. }
  13724. /**
  13725. * Paints crop marks.
  13726. * @param float $x abscissa of the crop mark center.
  13727. * @param float $y ordinate of the crop mark center.
  13728. * @param float $w width of the crop mark.
  13729. * @param float $h height of the crop mark.
  13730. * @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.
  13731. * @param array $color crop mark color (default spot registration color).
  13732. * @author Nicola Asuni
  13733. * @since 4.9.000 (2010-03-26)
  13734. * @public
  13735. */
  13736. public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(100,100,100,100,'All')) {
  13737. $this->setLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  13738. $type = strtoupper($type);
  13739. $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
  13740. // split type in single components
  13741. $type = str_replace('-', ',', $type);
  13742. $type = str_replace('TL', 'T,L', $type);
  13743. $type = str_replace('TR', 'T,R', $type);
  13744. $type = str_replace('BL', 'F,L', $type);
  13745. $type = str_replace('BR', 'F,R', $type);
  13746. $type = str_replace('A', 'T,L', $type);
  13747. $type = str_replace('B', 'T,R', $type);
  13748. $type = str_replace('T,RO', 'BO', $type);
  13749. $type = str_replace('C', 'F,L', $type);
  13750. $type = str_replace('D', 'F,R', $type);
  13751. $crops = explode(',', strtoupper($type));
  13752. // remove duplicates
  13753. $crops = array_unique($crops);
  13754. $dw = ($w / 4); // horizontal space to leave before the intersection point
  13755. $dh = ($h / 4); // vertical space to leave before the intersection point
  13756. foreach ($crops as $crop) {
  13757. switch ($crop) {
  13758. case 'T':
  13759. case 'TOP': {
  13760. $x1 = $x;
  13761. $y1 = ($y - $h);
  13762. $x2 = $x;
  13763. $y2 = ($y - $dh);
  13764. break;
  13765. }
  13766. case 'F':
  13767. case 'BOTTOM': {
  13768. $x1 = $x;
  13769. $y1 = ($y + $dh);
  13770. $x2 = $x;
  13771. $y2 = ($y + $h);
  13772. break;
  13773. }
  13774. case 'L':
  13775. case 'LEFT': {
  13776. $x1 = ($x - $w);
  13777. $y1 = $y;
  13778. $x2 = ($x - $dw);
  13779. $y2 = $y;
  13780. break;
  13781. }
  13782. case 'R':
  13783. case 'RIGHT': {
  13784. $x1 = ($x + $dw);
  13785. $y1 = $y;
  13786. $x2 = ($x + $w);
  13787. $y2 = $y;
  13788. break;
  13789. }
  13790. }
  13791. $this->Line($x1, $y1, $x2, $y2);
  13792. }
  13793. }
  13794. /**
  13795. * Paints a registration mark
  13796. * @param float $x abscissa of the registration mark center.
  13797. * @param float $y ordinate of the registration mark center.
  13798. * @param float $r radius of the crop mark.
  13799. * @param boolean $double if true print two concentric crop marks.
  13800. * @param array $cola crop mark color (default spot registration color 'All').
  13801. * @param array $colb second crop mark color (default spot registration color 'None').
  13802. * @author Nicola Asuni
  13803. * @since 4.9.000 (2010-03-26)
  13804. * @public
  13805. */
  13806. public function registrationMark($x, $y, $r, $double=false, $cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) {
  13807. $line_style = array('width' => max((0.5 / $this->k),($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  13808. $this->setFillColorArray($cola);
  13809. $this->PieSector($x, $y, $r, 90, 180, 'F');
  13810. $this->PieSector($x, $y, $r, 270, 360, 'F');
  13811. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13812. if ($double) {
  13813. $ri = $r * 0.5;
  13814. $this->setFillColorArray($colb);
  13815. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13816. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13817. $this->setFillColorArray($cola);
  13818. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13819. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13820. $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8);
  13821. }
  13822. }
  13823. /**
  13824. * Paints a CMYK registration mark
  13825. * @param float $x abscissa of the registration mark center.
  13826. * @param float $y ordinate of the registration mark center.
  13827. * @param float $r radius of the crop mark.
  13828. * @author Nicola Asuni
  13829. * @since 6.0.038 (2013-09-30)
  13830. * @public
  13831. */
  13832. public function registrationMarkCMYK($x, $y, $r) {
  13833. // line width
  13834. $lw = max((0.5 / $this->k),($r / 8));
  13835. // internal radius
  13836. $ri = ($r * 0.6);
  13837. // external radius
  13838. $re = ($r * 1.3);
  13839. // Cyan
  13840. $this->setFillColorArray(array(100,0,0,0));
  13841. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13842. // Magenta
  13843. $this->setFillColorArray(array(0,100,0,0));
  13844. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13845. // Yellow
  13846. $this->setFillColorArray(array(0,0,100,0));
  13847. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13848. // Key - black
  13849. $this->setFillColorArray(array(0,0,0,100));
  13850. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13851. // registration color
  13852. $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All'));
  13853. $this->setFillColorArray(array(100,100,100,100,'All'));
  13854. // external circle
  13855. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13856. // cross lines
  13857. $this->Line($x, ($y - $re), $x, ($y - $ri));
  13858. $this->Line($x, ($y + $ri), $x, ($y + $re));
  13859. $this->Line(($x - $re), $y, ($x - $ri), $y);
  13860. $this->Line(($x + $ri), $y, ($x + $re), $y);
  13861. }
  13862. /**
  13863. * Paints a linear colour gradient.
  13864. * @param float $x abscissa of the top left corner of the rectangle.
  13865. * @param float $y ordinate of the top left corner of the rectangle.
  13866. * @param float $w width of the rectangle.
  13867. * @param float $h height of the rectangle.
  13868. * @param array $col1 first color (Grayscale, RGB or CMYK components).
  13869. * @param array $col2 second color (Grayscale, RGB or CMYK components).
  13870. * @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).
  13871. * @author Andreas W\FCrmser, Nicola Asuni
  13872. * @since 3.1.000 (2008-06-09)
  13873. * @public
  13874. */
  13875. public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  13876. $this->Clip($x, $y, $w, $h);
  13877. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13878. }
  13879. /**
  13880. * Paints a radial colour gradient.
  13881. * @param float $x abscissa of the top left corner of the rectangle.
  13882. * @param float $y ordinate of the top left corner of the rectangle.
  13883. * @param float $w width of the rectangle.
  13884. * @param float $h height of the rectangle.
  13885. * @param array $col1 first color (Grayscale, RGB or CMYK components).
  13886. * @param array $col2 second color (Grayscale, RGB or CMYK components).
  13887. * @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.
  13888. * @author Andreas W\FCrmser, Nicola Asuni
  13889. * @since 3.1.000 (2008-06-09)
  13890. * @public
  13891. */
  13892. public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  13893. $this->Clip($x, $y, $w, $h);
  13894. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13895. }
  13896. /**
  13897. * Paints a coons patch mesh.
  13898. * @param float $x abscissa of the top left corner of the rectangle.
  13899. * @param float $y ordinate of the top left corner of the rectangle.
  13900. * @param float $w width of the rectangle.
  13901. * @param float $h height of the rectangle.
  13902. * @param array $col1 first color (lower left corner) (RGB components).
  13903. * @param array $col2 second color (lower right corner) (RGB components).
  13904. * @param array $col3 third color (upper right corner) (RGB components).
  13905. * @param array $col4 fourth color (upper left corner) (RGB components).
  13906. * @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>
  13907. * @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
  13908. * @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
  13909. * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13910. * @author Andreas W\FCrmser, Nicola Asuni
  13911. * @since 3.1.000 (2008-06-09)
  13912. * @public
  13913. */
  13914. 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) {
  13915. if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
  13916. return;
  13917. }
  13918. $this->Clip($x, $y, $w, $h);
  13919. $n = count($this->gradients) + 1;
  13920. $this->gradients[$n] = array();
  13921. $this->gradients[$n]['type'] = 6; //coons patch mesh
  13922. $this->gradients[$n]['coords'] = array();
  13923. $this->gradients[$n]['antialias'] = $antialias;
  13924. $this->gradients[$n]['colors'] = array();
  13925. $this->gradients[$n]['transparency'] = false;
  13926. //check the coords array if it is the simple array or the multi patch array
  13927. if (!isset($coords[0]['f'])) {
  13928. //simple array -> convert to multi patch array
  13929. if (!isset($col1[1])) {
  13930. $col1[1] = $col1[2] = $col1[0];
  13931. }
  13932. if (!isset($col2[1])) {
  13933. $col2[1] = $col2[2] = $col2[0];
  13934. }
  13935. if (!isset($col3[1])) {
  13936. $col3[1] = $col3[2] = $col3[0];
  13937. }
  13938. if (!isset($col4[1])) {
  13939. $col4[1] = $col4[2] = $col4[0];
  13940. }
  13941. $patch_array[0]['f'] = 0;
  13942. $patch_array[0]['points'] = $coords;
  13943. $patch_array[0]['colors'][0]['r'] = $col1[0];
  13944. $patch_array[0]['colors'][0]['g'] = $col1[1];
  13945. $patch_array[0]['colors'][0]['b'] = $col1[2];
  13946. $patch_array[0]['colors'][1]['r'] = $col2[0];
  13947. $patch_array[0]['colors'][1]['g'] = $col2[1];
  13948. $patch_array[0]['colors'][1]['b'] = $col2[2];
  13949. $patch_array[0]['colors'][2]['r'] = $col3[0];
  13950. $patch_array[0]['colors'][2]['g'] = $col3[1];
  13951. $patch_array[0]['colors'][2]['b'] = $col3[2];
  13952. $patch_array[0]['colors'][3]['r'] = $col4[0];
  13953. $patch_array[0]['colors'][3]['g'] = $col4[1];
  13954. $patch_array[0]['colors'][3]['b'] = $col4[2];
  13955. } else {
  13956. //multi patch array
  13957. $patch_array = $coords;
  13958. }
  13959. $bpcd = 65535; //16 bits per coordinate
  13960. //build the data stream
  13961. $this->gradients[$n]['stream'] = '';
  13962. $count_patch = count($patch_array);
  13963. for ($i=0; $i < $count_patch; ++$i) {
  13964. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  13965. $count_points = count($patch_array[$i]['points']);
  13966. for ($j=0; $j < $count_points; ++$j) {
  13967. //each point as 16 bit
  13968. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  13969. if ($patch_array[$i]['points'][$j] < 0) {
  13970. $patch_array[$i]['points'][$j] = 0;
  13971. }
  13972. if ($patch_array[$i]['points'][$j] > $bpcd) {
  13973. $patch_array[$i]['points'][$j] = $bpcd;
  13974. }
  13975. $this->gradients[$n]['stream'] .= chr((int) floor($patch_array[$i]['points'][$j] / 256));
  13976. $this->gradients[$n]['stream'] .= chr((int) floor(intval($patch_array[$i]['points'][$j]) % 256));
  13977. }
  13978. $count_cols = count($patch_array[$i]['colors']);
  13979. for ($j=0; $j < $count_cols; ++$j) {
  13980. //each color component as 8 bit
  13981. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  13982. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  13983. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  13984. }
  13985. }
  13986. //paint the gradient
  13987. $this->_out('/Sh'.$n.' sh');
  13988. //restore previous Graphic State
  13989. $this->_outRestoreGraphicsState();
  13990. if ($this->inxobj) {
  13991. // we are inside an XObject template
  13992. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13993. }
  13994. }
  13995. /**
  13996. * Set a rectangular clipping area.
  13997. * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  13998. * @param float $y ordinate of the top left corner of the rectangle.
  13999. * @param float $w width of the rectangle.
  14000. * @param float $h height of the rectangle.
  14001. * @author Andreas W\FCrmser, Nicola Asuni
  14002. * @since 3.1.000 (2008-06-09)
  14003. * @protected
  14004. */
  14005. protected function Clip($x, $y, $w, $h) {
  14006. if ($this->state != 2) {
  14007. return;
  14008. }
  14009. if ($this->rtl) {
  14010. $x = $this->w - $x - $w;
  14011. }
  14012. //save current Graphic State
  14013. $s = 'q';
  14014. //set clipping area
  14015. $s .= sprintf(' %F %F %F %F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  14016. //set up transformation matrix for gradient
  14017. $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  14018. $this->_out($s);
  14019. }
  14020. /**
  14021. * Output gradient.
  14022. * @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)
  14023. * @param array $coords array of coordinates.
  14024. * @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).
  14025. * @param array $background An array of colour components appropriate to the colour space, specifying a single background colour value.
  14026. * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  14027. * @author Nicola Asuni
  14028. * @since 3.1.000 (2008-06-09)
  14029. * @public
  14030. */
  14031. public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
  14032. if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
  14033. return;
  14034. }
  14035. $n = count($this->gradients) + 1;
  14036. $this->gradients[$n] = array();
  14037. $this->gradients[$n]['type'] = $type;
  14038. $this->gradients[$n]['coords'] = $coords;
  14039. $this->gradients[$n]['antialias'] = $antialias;
  14040. $this->gradients[$n]['colors'] = array();
  14041. $this->gradients[$n]['transparency'] = false;
  14042. // color space
  14043. $numcolspace = count($stops[0]['color']);
  14044. $bcolor = array_values($background);
  14045. switch($numcolspace) {
  14046. case 5: // SPOT
  14047. case 4: { // CMYK
  14048. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  14049. if (!empty($background)) {
  14050. $this->gradients[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
  14051. }
  14052. break;
  14053. }
  14054. case 3: { // RGB
  14055. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  14056. if (!empty($background)) {
  14057. $this->gradients[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
  14058. }
  14059. break;
  14060. }
  14061. case 1: { // GRAY SCALE
  14062. $this->gradients[$n]['colspace'] = 'DeviceGray';
  14063. if (!empty($background)) {
  14064. $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255);
  14065. }
  14066. break;
  14067. }
  14068. }
  14069. $num_stops = count($stops);
  14070. $last_stop_id = $num_stops - 1;
  14071. foreach ($stops as $key => $stop) {
  14072. $this->gradients[$n]['colors'][$key] = array();
  14073. // offset represents a location along the gradient vector
  14074. if (isset($stop['offset'])) {
  14075. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  14076. } else {
  14077. if ($key == 0) {
  14078. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  14079. } elseif ($key == $last_stop_id) {
  14080. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  14081. } else {
  14082. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  14083. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  14084. }
  14085. }
  14086. if (isset($stop['opacity'])) {
  14087. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  14088. if ((!($this->pdfa_mode && $this->pdfa_version < 2)) AND ($stop['opacity'] < 1)) {
  14089. $this->gradients[$n]['transparency'] = true;
  14090. }
  14091. } else {
  14092. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  14093. }
  14094. // exponent for the exponential interpolation function
  14095. if (isset($stop['exponent'])) {
  14096. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  14097. } else {
  14098. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  14099. }
  14100. // set colors
  14101. $color = array_values($stop['color']);
  14102. switch($numcolspace) {
  14103. case 5: // SPOT
  14104. case 4: { // CMYK
  14105. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
  14106. break;
  14107. }
  14108. case 3: { // RGB
  14109. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
  14110. break;
  14111. }
  14112. case 1: { // GRAY SCALE
  14113. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
  14114. break;
  14115. }
  14116. }
  14117. }
  14118. if ($this->gradients[$n]['transparency']) {
  14119. // paint luminosity gradient
  14120. $this->_out('/TGS'.$n.' gs');
  14121. }
  14122. //paint the gradient
  14123. $this->_out('/Sh'.$n.' sh');
  14124. //restore previous Graphic State
  14125. $this->_outRestoreGraphicsState();
  14126. if ($this->inxobj) {
  14127. // we are inside an XObject template
  14128. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  14129. }
  14130. }
  14131. /**
  14132. * Output gradient shaders.
  14133. * @author Nicola Asuni
  14134. * @since 3.1.000 (2008-06-09)
  14135. * @protected
  14136. */
  14137. function _putshaders() {
  14138. if ($this->pdfa_mode && $this->pdfa_version < 2) {
  14139. return;
  14140. }
  14141. $idt = count($this->gradients); //index for transparency gradients
  14142. foreach ($this->gradients as $id => $grad) {
  14143. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  14144. $fc = $this->_newobj();
  14145. $out = '<<';
  14146. $out .= ' /FunctionType 3';
  14147. $out .= ' /Domain [0 1]';
  14148. $functions = '';
  14149. $bounds = '';
  14150. $encode = '';
  14151. $i = 1;
  14152. $num_cols = count($grad['colors']);
  14153. $lastcols = $num_cols - 1;
  14154. for ($i = 1; $i < $num_cols; ++$i) {
  14155. $functions .= ($fc + $i).' 0 R ';
  14156. if ($i < $lastcols) {
  14157. $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
  14158. }
  14159. $encode .= '0 1 ';
  14160. }
  14161. $out .= ' /Functions ['.trim($functions).']';
  14162. $out .= ' /Bounds ['.trim($bounds).']';
  14163. $out .= ' /Encode ['.trim($encode).']';
  14164. $out .= ' >>';
  14165. $out .= "\n".'endobj';
  14166. $this->_out($out);
  14167. for ($i = 1; $i < $num_cols; ++$i) {
  14168. $this->_newobj();
  14169. $out = '<<';
  14170. $out .= ' /FunctionType 2';
  14171. $out .= ' /Domain [0 1]';
  14172. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
  14173. $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  14174. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14175. $out .= ' >>';
  14176. $out .= "\n".'endobj';
  14177. $this->_out($out);
  14178. }
  14179. // set transparency functions
  14180. if ($grad['transparency']) {
  14181. $ft = $this->_newobj();
  14182. $out = '<<';
  14183. $out .= ' /FunctionType 3';
  14184. $out .= ' /Domain [0 1]';
  14185. $functions = '';
  14186. $i = 1;
  14187. $num_cols = count($grad['colors']);
  14188. for ($i = 1; $i < $num_cols; ++$i) {
  14189. $functions .= ($ft + $i).' 0 R ';
  14190. }
  14191. $out .= ' /Functions ['.trim($functions).']';
  14192. $out .= ' /Bounds ['.trim($bounds).']';
  14193. $out .= ' /Encode ['.trim($encode).']';
  14194. $out .= ' >>';
  14195. $out .= "\n".'endobj';
  14196. $this->_out($out);
  14197. for ($i = 1; $i < $num_cols; ++$i) {
  14198. $this->_newobj();
  14199. $out = '<<';
  14200. $out .= ' /FunctionType 2';
  14201. $out .= ' /Domain [0 1]';
  14202. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
  14203. $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  14204. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14205. $out .= ' >>';
  14206. $out .= "\n".'endobj';
  14207. $this->_out($out);
  14208. }
  14209. }
  14210. }
  14211. // set shading object
  14212. $this->_newobj();
  14213. $out = '<< /ShadingType '.$grad['type'];
  14214. if (isset($grad['colspace'])) {
  14215. $out .= ' /ColorSpace /'.$grad['colspace'];
  14216. } else {
  14217. $out .= ' /ColorSpace /DeviceRGB';
  14218. }
  14219. if (isset($grad['background']) AND !empty($grad['background'])) {
  14220. $out .= ' /Background ['.$grad['background'].']';
  14221. }
  14222. if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  14223. $out .= ' /AntiAlias true';
  14224. }
  14225. if ($grad['type'] == 2) {
  14226. $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  14227. $out .= ' /Domain [0 1]';
  14228. $out .= ' /Function '.$fc.' 0 R';
  14229. $out .= ' /Extend [true true]';
  14230. $out .= ' >>';
  14231. } elseif ($grad['type'] == 3) {
  14232. //x0, y0, r0, x1, y1, r1
  14233. //at this this time radius of inner circle is 0
  14234. $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  14235. $out .= ' /Domain [0 1]';
  14236. $out .= ' /Function '.$fc.' 0 R';
  14237. $out .= ' /Extend [true true]';
  14238. $out .= ' >>';
  14239. } elseif ($grad['type'] == 6) {
  14240. $out .= ' /BitsPerCoordinate 16';
  14241. $out .= ' /BitsPerComponent 8';
  14242. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  14243. $out .= ' /BitsPerFlag 8';
  14244. $stream = $this->_getrawstream($grad['stream']);
  14245. $out .= ' /Length '.strlen($stream);
  14246. $out .= ' >>';
  14247. $out .= ' stream'."\n".$stream."\n".'endstream';
  14248. }
  14249. $out .= "\n".'endobj';
  14250. $this->_out($out);
  14251. if ($grad['transparency']) {
  14252. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  14253. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
  14254. }
  14255. $this->gradients[$id]['id'] = $this->n;
  14256. // set pattern object
  14257. $this->_newobj();
  14258. $out = '<< /Type /Pattern /PatternType 2';
  14259. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  14260. $out .= ' >>';
  14261. $out .= "\n".'endobj';
  14262. $this->_out($out);
  14263. $this->gradients[$id]['pattern'] = $this->n;
  14264. // set shading and pattern for transparency mask
  14265. if ($grad['transparency']) {
  14266. // luminosity pattern
  14267. $idgs = $id + $idt;
  14268. $this->_newobj();
  14269. $this->_out($shading_transparency);
  14270. $this->gradients[$idgs]['id'] = $this->n;
  14271. $this->_newobj();
  14272. $out = '<< /Type /Pattern /PatternType 2';
  14273. $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  14274. $out .= ' >>';
  14275. $out .= "\n".'endobj';
  14276. $this->_out($out);
  14277. $this->gradients[$idgs]['pattern'] = $this->n;
  14278. // luminosity XObject
  14279. $oid = $this->_newobj();
  14280. $this->xobjects['LX'.$oid] = array('n' => $oid);
  14281. $filter = '';
  14282. $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  14283. if ($this->compress) {
  14284. $filter = ' /Filter /FlateDecode';
  14285. $stream = gzcompress($stream);
  14286. }
  14287. $stream = $this->_getrawstream($stream);
  14288. $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  14289. $out .= ' /Length '.strlen($stream);
  14290. $rect = sprintf('%F %F', $this->wPt, $this->hPt);
  14291. $out .= ' /BBox [0 0 '.$rect.']';
  14292. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  14293. $out .= ' /Resources <<';
  14294. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  14295. $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  14296. $out .= ' >>';
  14297. $out .= ' >> ';
  14298. $out .= ' stream'."\n".$stream."\n".'endstream';
  14299. $out .= "\n".'endobj';
  14300. $this->_out($out);
  14301. // SMask
  14302. $this->_newobj();
  14303. $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
  14304. $this->_out($out);
  14305. // ExtGState
  14306. $this->_newobj();
  14307. $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
  14308. $this->_out($out);
  14309. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
  14310. }
  14311. }
  14312. }
  14313. /**
  14314. * Draw the sector of a circle.
  14315. * It can be used for instance to render pie charts.
  14316. * @param float $xc abscissa of the center.
  14317. * @param float $yc ordinate of the center.
  14318. * @param float $r radius.
  14319. * @param float $a start angle (in degrees).
  14320. * @param float $b end angle (in degrees).
  14321. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  14322. * @param float $cw indicates whether to go clockwise (default: true).
  14323. * @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.
  14324. * @author Maxime Delorme, Nicola Asuni
  14325. * @since 3.1.000 (2008-06-09)
  14326. * @public
  14327. */
  14328. public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
  14329. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  14330. }
  14331. /**
  14332. * Draw the sector of an ellipse.
  14333. * It can be used for instance to render pie charts.
  14334. * @param float $xc abscissa of the center.
  14335. * @param float $yc ordinate of the center.
  14336. * @param float $rx the x-axis radius.
  14337. * @param float $ry the y-axis radius.
  14338. * @param float $a start angle (in degrees).
  14339. * @param float $b end angle (in degrees).
  14340. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  14341. * @param float $cw indicates whether to go clockwise.
  14342. * @param float $o origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  14343. * @param integer $nc Number of curves used to draw a 90 degrees portion of arc.
  14344. * @author Maxime Delorme, Nicola Asuni
  14345. * @since 3.1.000 (2008-06-09)
  14346. * @public
  14347. */
  14348. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
  14349. if ($this->state != 2) {
  14350. return;
  14351. }
  14352. if ($this->rtl) {
  14353. $xc = ($this->w - $xc);
  14354. }
  14355. $op = TCPDF_STATIC::getPathPaintOperator($style);
  14356. if ($op == 'f') {
  14357. $line_style = array();
  14358. }
  14359. if ($cw) {
  14360. $d = $b;
  14361. $b = (360 - $a + $o);
  14362. $a = (360 - $d + $o);
  14363. } else {
  14364. $b += $o;
  14365. $a += $o;
  14366. }
  14367. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  14368. $this->_out($op);
  14369. }
  14370. /**
  14371. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  14372. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  14373. * Only vector drawing is supported, not text or bitmap.
  14374. * 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).
  14375. * @param string $file Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  14376. * @param float|null $x Abscissa of the upper-left corner.
  14377. * @param float|null $y Ordinate of the upper-left corner.
  14378. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14379. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14380. * @param mixed $link URL or identifier returned by AddLink().
  14381. * @param boolean $useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  14382. * @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>
  14383. * @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>
  14384. * @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)))
  14385. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  14386. * @param boolean $fixoutvals if true remove values outside the bounding box.
  14387. * @author Valentin Schmidt, Nicola Asuni
  14388. * @since 3.1.000 (2008-06-09)
  14389. * @public
  14390. */
  14391. public function ImageEps($file, $x=null, $y=null, $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
  14392. if ($this->state != 2) {
  14393. return;
  14394. }
  14395. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  14396. // convert EPS to raster image using GD or ImageMagick libraries
  14397. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14398. }
  14399. if (TCPDF_STATIC::empty_string($x)) {
  14400. $x = $this->x;
  14401. }
  14402. if (TCPDF_STATIC::empty_string($y)) {
  14403. $y = $this->y;
  14404. }
  14405. // check page for no-write regions and adapt page margins if necessary
  14406. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14407. $k = $this->k;
  14408. if ($file[0] === '@') { // image from string
  14409. $data = substr($file, 1);
  14410. } else { // EPS/AI file
  14411. $data = $this->getCachedFileContents($file);
  14412. }
  14413. if ($data === FALSE) {
  14414. $this->Error('EPS file not found: '.$file);
  14415. }
  14416. $regs = array();
  14417. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  14418. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  14419. if (count($regs) > 1) {
  14420. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  14421. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  14422. $versexp = explode(' ', $version_str);
  14423. $version = (float)array_pop($versexp);
  14424. if ($version >= 9) {
  14425. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  14426. }
  14427. }
  14428. }
  14429. // strip binary bytes in front of PS-header
  14430. $start = strpos($data, '%!PS-Adobe');
  14431. if ($start > 0) {
  14432. $data = substr($data, $start);
  14433. }
  14434. // find BoundingBox params
  14435. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  14436. if (count($regs) > 1) {
  14437. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  14438. } else {
  14439. $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  14440. }
  14441. $start = strpos($data, '%%EndSetup');
  14442. if ($start === false) {
  14443. $start = strpos($data, '%%EndProlog');
  14444. }
  14445. if ($start === false) {
  14446. $start = strpos($data, '%%BoundingBox');
  14447. }
  14448. $data = substr($data, $start);
  14449. $end = strpos($data, '%%PageTrailer');
  14450. if ($end===false) {
  14451. $end = strpos($data, 'showpage');
  14452. }
  14453. if ($end) {
  14454. $data = substr($data, 0, $end);
  14455. }
  14456. // calculate image width and height on document
  14457. if (($w <= 0) AND ($h <= 0)) {
  14458. $w = ($x2 - $x1) / $k;
  14459. $h = ($y2 - $y1) / $k;
  14460. } elseif ($w <= 0) {
  14461. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  14462. } elseif ($h <= 0) {
  14463. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  14464. }
  14465. // fit the image on available space
  14466. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  14467. if ($this->rasterize_vector_images) {
  14468. // convert EPS to raster image using GD or ImageMagick libraries
  14469. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14470. }
  14471. // set scaling factors
  14472. $scale_x = $w / (($x2 - $x1) / $k);
  14473. $scale_y = $h / (($y2 - $y1) / $k);
  14474. // set alignment
  14475. $this->img_rb_y = $y + $h;
  14476. // set alignment
  14477. if ($this->rtl) {
  14478. if ($palign == 'L') {
  14479. $ximg = $this->lMargin;
  14480. } elseif ($palign == 'C') {
  14481. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14482. } elseif ($palign == 'R') {
  14483. $ximg = $this->w - $this->rMargin - $w;
  14484. } else {
  14485. $ximg = $x - $w;
  14486. }
  14487. $this->img_rb_x = $ximg;
  14488. } else {
  14489. if ($palign == 'L') {
  14490. $ximg = $this->lMargin;
  14491. } elseif ($palign == 'C') {
  14492. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14493. } elseif ($palign == 'R') {
  14494. $ximg = $this->w - $this->rMargin - $w;
  14495. } else {
  14496. $ximg = $x;
  14497. }
  14498. $this->img_rb_x = $ximg + $w;
  14499. }
  14500. if ($useBoundingBox) {
  14501. $dx = $ximg * $k - $x1;
  14502. $dy = $y * $k - $y1;
  14503. } else {
  14504. $dx = $ximg * $k;
  14505. $dy = $y * $k;
  14506. }
  14507. // save the current graphic state
  14508. $this->_out('q'.$this->epsmarker);
  14509. // translate
  14510. $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  14511. // scale
  14512. $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  14513. // handle pc/unix/mac line endings
  14514. $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
  14515. $u=0;
  14516. $cnt = count($lines);
  14517. for ($i=0; $i < $cnt; ++$i) {
  14518. $line = $lines[$i];
  14519. if (($line == '') OR ($line[0] == '%')) {
  14520. continue;
  14521. }
  14522. $len = strlen($line);
  14523. // check for spot color names
  14524. $color_name = '';
  14525. if (strcasecmp('x', substr(trim($line), -1)) == 0) {
  14526. if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
  14527. // extract spot color name
  14528. $color_name = $matches[0];
  14529. // remove color name from string
  14530. $line = str_replace(' '.$color_name, '', $line);
  14531. // remove pharentesis from color name
  14532. $color_name = substr($color_name, 1, -1);
  14533. }
  14534. }
  14535. $chunks = explode(' ', $line);
  14536. $cmd = trim(array_pop($chunks));
  14537. // RGB
  14538. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  14539. $b = array_pop($chunks);
  14540. $g = array_pop($chunks);
  14541. $r = array_pop($chunks);
  14542. $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!
  14543. continue;
  14544. }
  14545. $skip = false;
  14546. if ($fixoutvals) {
  14547. // check for values outside the bounding box
  14548. switch ($cmd) {
  14549. case 'm':
  14550. case 'l':
  14551. case 'L': {
  14552. // skip values outside bounding box
  14553. foreach ($chunks as $key => $val) {
  14554. if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
  14555. $skip = true;
  14556. } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
  14557. $skip = true;
  14558. }
  14559. }
  14560. }
  14561. }
  14562. }
  14563. switch ($cmd) {
  14564. case 'm':
  14565. case 'l':
  14566. case 'v':
  14567. case 'y':
  14568. case 'c':
  14569. case 'k':
  14570. case 'K':
  14571. case 'g':
  14572. case 'G':
  14573. case 's':
  14574. case 'S':
  14575. case 'J':
  14576. case 'j':
  14577. case 'w':
  14578. case 'M':
  14579. case 'd':
  14580. case 'n': {
  14581. if ($skip) {
  14582. break;
  14583. }
  14584. $this->_out($line);
  14585. break;
  14586. }
  14587. case 'x': {// custom fill color
  14588. if (empty($color_name)) {
  14589. // CMYK color
  14590. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14591. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  14592. } else {
  14593. // Spot Color (CMYK + tint)
  14594. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14595. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14596. $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14597. $this->_out($color_cmd);
  14598. }
  14599. break;
  14600. }
  14601. case 'X': { // custom stroke color
  14602. if (empty($color_name)) {
  14603. // CMYK color
  14604. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14605. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  14606. } else {
  14607. // Spot Color (CMYK + tint)
  14608. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14609. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14610. $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14611. $this->_out($color_cmd);
  14612. }
  14613. break;
  14614. }
  14615. case 'Y':
  14616. case 'N':
  14617. case 'V':
  14618. case 'L':
  14619. case 'C': {
  14620. if ($skip) {
  14621. break;
  14622. }
  14623. $line[($len - 1)] = strtolower($cmd);
  14624. $this->_out($line);
  14625. break;
  14626. }
  14627. case 'b':
  14628. case 'B': {
  14629. $this->_out($cmd . '*');
  14630. break;
  14631. }
  14632. case 'f':
  14633. case 'F': {
  14634. if ($u > 0) {
  14635. $isU = false;
  14636. $max = min(($i + 5), $cnt);
  14637. for ($j = ($i + 1); $j < $max; ++$j) {
  14638. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  14639. }
  14640. if ($isU) {
  14641. $this->_out('f*');
  14642. }
  14643. } else {
  14644. $this->_out('f*');
  14645. }
  14646. break;
  14647. }
  14648. case '*u': {
  14649. ++$u;
  14650. break;
  14651. }
  14652. case '*U': {
  14653. --$u;
  14654. break;
  14655. }
  14656. }
  14657. }
  14658. // restore previous graphic state
  14659. $this->_out($this->epsmarker.'Q');
  14660. if (!empty($border)) {
  14661. $bx = $this->x;
  14662. $by = $this->y;
  14663. $this->x = $ximg;
  14664. if ($this->rtl) {
  14665. $this->x += $w;
  14666. }
  14667. $this->y = $y;
  14668. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  14669. $this->x = $bx;
  14670. $this->y = $by;
  14671. }
  14672. if ($link) {
  14673. $this->Link($ximg, $y, $w, $h, $link, 0);
  14674. }
  14675. // set pointer to align the next text/objects
  14676. switch($align) {
  14677. case 'T':{
  14678. $this->y = $y;
  14679. $this->x = $this->img_rb_x;
  14680. break;
  14681. }
  14682. case 'M':{
  14683. $this->y = $y + round($h/2);
  14684. $this->x = $this->img_rb_x;
  14685. break;
  14686. }
  14687. case 'B':{
  14688. $this->y = $this->img_rb_y;
  14689. $this->x = $this->img_rb_x;
  14690. break;
  14691. }
  14692. case 'N':{
  14693. $this->setY($this->img_rb_y);
  14694. break;
  14695. }
  14696. default:{
  14697. break;
  14698. }
  14699. }
  14700. $this->endlinex = $this->img_rb_x;
  14701. }
  14702. /**
  14703. * Set document barcode.
  14704. * @param string $bc barcode
  14705. * @public
  14706. */
  14707. public function setBarcode($bc='') {
  14708. $this->barcode = $bc;
  14709. }
  14710. /**
  14711. * Get current barcode.
  14712. * @return string
  14713. * @public
  14714. * @since 4.0.012 (2008-07-24)
  14715. */
  14716. public function getBarcode() {
  14717. return $this->barcode;
  14718. }
  14719. /**
  14720. * Print a Linear Barcode.
  14721. * @param string $code code to print
  14722. * @param string $type type of barcode (see tcpdf_barcodes_1d.php for supported formats).
  14723. * @param float|null $x x position in user units (null = current x position)
  14724. * @param float|null $y y position in user units (null = current y position)
  14725. * @param float|null $w width in user units (null = remaining page width)
  14726. * @param float|null $h height in user units (null = remaining page height)
  14727. * @param float|null $xres width of the smallest bar in user units (null = default value = 0.4mm)
  14728. * @param array $style array of options:<ul>
  14729. * <li>boolean $style['border'] if true prints a border</li>
  14730. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  14731. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  14732. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  14733. * <li>array $style['fgcolor'] color array for bars and text</li>
  14734. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  14735. * <li>boolean $style['text'] if true prints text below the barcode</li>
  14736. * <li>string $style['label'] override default label</li>
  14737. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  14738. * <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>
  14739. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  14740. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  14741. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  14742. * <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>
  14743. * <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>
  14744. * @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>
  14745. * @author Nicola Asuni
  14746. * @since 3.1.000 (2008-06-09)
  14747. * @public
  14748. */
  14749. public function write1DBarcode($code, $type, $x=null, $y=null, $w=null, $h=null, $xres=null, $style=array(), $align='') {
  14750. if (TCPDF_STATIC::empty_string(trim($code))) {
  14751. return;
  14752. }
  14753. require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php');
  14754. // save current graphic settings
  14755. $gvars = $this->getGraphicVars();
  14756. // create new barcode object
  14757. $barcodeobj = new TCPDFBarcode($code, $type);
  14758. $arrcode = $barcodeobj->getBarcodeArray();
  14759. if (empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
  14760. $this->Error('Error in 1D barcode string');
  14761. }
  14762. if ($arrcode['maxh'] <= 0) {
  14763. $arrcode['maxh'] = 1;
  14764. }
  14765. // set default values
  14766. if (!isset($style['position'])) {
  14767. $style['position'] = '';
  14768. } elseif ($style['position'] == 'S') {
  14769. // keep this for backward compatibility
  14770. $style['position'] = '';
  14771. $style['stretch'] = true;
  14772. }
  14773. if (!isset($style['fitwidth'])) {
  14774. if (!isset($style['stretch'])) {
  14775. $style['fitwidth'] = true;
  14776. } else {
  14777. $style['fitwidth'] = false;
  14778. }
  14779. }
  14780. if ($style['fitwidth']) {
  14781. // disable stretch
  14782. $style['stretch'] = false;
  14783. }
  14784. if (!isset($style['stretch'])) {
  14785. if (($w === '') OR ($w <= 0)) {
  14786. $style['stretch'] = false;
  14787. } else {
  14788. $style['stretch'] = true;
  14789. }
  14790. }
  14791. if (!isset($style['fgcolor'])) {
  14792. $style['fgcolor'] = array(0,0,0); // default black
  14793. }
  14794. if (!isset($style['bgcolor'])) {
  14795. $style['bgcolor'] = false; // default transparent
  14796. }
  14797. if (!isset($style['border'])) {
  14798. $style['border'] = false;
  14799. }
  14800. $fontsize = 0;
  14801. if (!isset($style['text'])) {
  14802. $style['text'] = false;
  14803. }
  14804. if ($style['text'] AND isset($style['font'])) {
  14805. if (isset($style['fontsize'])) {
  14806. $fontsize = $style['fontsize'];
  14807. }
  14808. $this->setFont($style['font'], '', $fontsize);
  14809. }
  14810. if (!isset($style['stretchtext'])) {
  14811. $style['stretchtext'] = 4;
  14812. }
  14813. if (TCPDF_STATIC::empty_string($x)) {
  14814. $x = $this->x;
  14815. }
  14816. if (TCPDF_STATIC::empty_string($y)) {
  14817. $y = $this->y;
  14818. }
  14819. // check page for no-write regions and adapt page margins if necessary
  14820. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14821. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  14822. if ($this->rtl) {
  14823. $w = $x - $this->lMargin;
  14824. } else {
  14825. $w = $this->w - $this->rMargin - $x;
  14826. }
  14827. }
  14828. // padding
  14829. if (!isset($style['padding'])) {
  14830. $padding = 0;
  14831. } elseif ($style['padding'] === 'auto') {
  14832. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  14833. } else {
  14834. $padding = floatval($style['padding']);
  14835. }
  14836. // horizontal padding
  14837. if (!isset($style['hpadding'])) {
  14838. $hpadding = $padding;
  14839. } elseif ($style['hpadding'] === 'auto') {
  14840. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  14841. } else {
  14842. $hpadding = floatval($style['hpadding']);
  14843. }
  14844. // vertical padding
  14845. if (!isset($style['vpadding'])) {
  14846. $vpadding = $padding;
  14847. } elseif ($style['vpadding'] === 'auto') {
  14848. $vpadding = ($hpadding / 2);
  14849. } else {
  14850. $vpadding = floatval($style['vpadding']);
  14851. }
  14852. // calculate xres (single bar width)
  14853. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  14854. if ($style['stretch']) {
  14855. $xres = $max_xres;
  14856. } else {
  14857. if (TCPDF_STATIC::empty_string($xres)) {
  14858. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  14859. }
  14860. if ($xres > $max_xres) {
  14861. // correct xres to fit on $w
  14862. $xres = $max_xres;
  14863. }
  14864. if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  14865. OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  14866. $hpadding = 10 * $xres;
  14867. if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  14868. $vpadding = ($hpadding / 2);
  14869. }
  14870. }
  14871. }
  14872. if ($style['fitwidth']) {
  14873. $wold = $w;
  14874. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  14875. if (isset($style['cellfitalign'])) {
  14876. switch ($style['cellfitalign']) {
  14877. case 'L': {
  14878. if ($this->rtl) {
  14879. $x -= ($wold - $w);
  14880. }
  14881. break;
  14882. }
  14883. case 'R': {
  14884. if (!$this->rtl) {
  14885. $x += ($wold - $w);
  14886. }
  14887. break;
  14888. }
  14889. case 'C': {
  14890. if ($this->rtl) {
  14891. $x -= (($wold - $w) / 2);
  14892. } else {
  14893. $x += (($wold - $w) / 2);
  14894. }
  14895. break;
  14896. }
  14897. default : {
  14898. break;
  14899. }
  14900. }
  14901. }
  14902. }
  14903. $text_height = $this->getCellHeight($fontsize / $this->k);
  14904. // height
  14905. if (TCPDF_STATIC::empty_string($h) OR ($h <= 0)) {
  14906. // set default height
  14907. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  14908. }
  14909. $barh = $h - $text_height - (2 * $vpadding);
  14910. if ($barh <=0) {
  14911. // try to reduce font or padding to fit barcode on available height
  14912. if ($text_height > $h) {
  14913. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  14914. $text_height = $this->getCellHeight($fontsize / $this->k);
  14915. $this->setFont($style['font'], '', $fontsize);
  14916. }
  14917. if ($vpadding > 0) {
  14918. $vpadding = (($h - $text_height) / 4);
  14919. }
  14920. $barh = $h - $text_height - (2 * $vpadding);
  14921. }
  14922. // fit the barcode on available space
  14923. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  14924. // set alignment
  14925. $this->img_rb_y = $y + $h;
  14926. // set alignment
  14927. if ($this->rtl) {
  14928. if ($style['position'] == 'L') {
  14929. $xpos = $this->lMargin;
  14930. } elseif ($style['position'] == 'C') {
  14931. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14932. } elseif ($style['position'] == 'R') {
  14933. $xpos = $this->w - $this->rMargin - $w;
  14934. } else {
  14935. $xpos = $x - $w;
  14936. }
  14937. $this->img_rb_x = $xpos;
  14938. } else {
  14939. if ($style['position'] == 'L') {
  14940. $xpos = $this->lMargin;
  14941. } elseif ($style['position'] == 'C') {
  14942. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14943. } elseif ($style['position'] == 'R') {
  14944. $xpos = $this->w - $this->rMargin - $w;
  14945. } else {
  14946. $xpos = $x;
  14947. }
  14948. $this->img_rb_x = $xpos + $w;
  14949. }
  14950. $xpos_rect = $xpos;
  14951. if (!isset($style['align'])) {
  14952. $style['align'] = 'C';
  14953. }
  14954. switch ($style['align']) {
  14955. case 'L': {
  14956. $xpos = $xpos_rect + $hpadding;
  14957. break;
  14958. }
  14959. case 'R': {
  14960. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  14961. break;
  14962. }
  14963. case 'C':
  14964. default : {
  14965. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  14966. break;
  14967. }
  14968. }
  14969. $xpos_text = $xpos;
  14970. // barcode is always printed in LTR direction
  14971. $tempRTL = $this->rtl;
  14972. $this->rtl = false;
  14973. // print background color
  14974. if ($style['bgcolor']) {
  14975. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  14976. } elseif ($style['border']) {
  14977. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  14978. }
  14979. // set foreground color
  14980. $this->setDrawColorArray($style['fgcolor']);
  14981. $this->setTextColorArray($style['fgcolor']);
  14982. // print bars
  14983. foreach ($arrcode['bcode'] as $k => $v) {
  14984. $bw = ($v['w'] * $xres);
  14985. if ($v['t']) {
  14986. // draw a vertical bar
  14987. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  14988. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  14989. }
  14990. $xpos += $bw;
  14991. }
  14992. // print text
  14993. if ($style['text']) {
  14994. if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) {
  14995. $label = $style['label'];
  14996. } else {
  14997. $label = $code;
  14998. }
  14999. $txtwidth = ($arrcode['maxw'] * $xres);
  15000. if ($this->GetStringWidth($label) > $txtwidth) {
  15001. $style['stretchtext'] = 2;
  15002. }
  15003. // print text
  15004. $this->x = $xpos_text;
  15005. $this->y = $y + $vpadding + $barh;
  15006. $cellpadding = $this->cell_padding;
  15007. $this->setCellPadding(0);
  15008. $this->Cell($txtwidth, 0, $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
  15009. $this->cell_padding = $cellpadding;
  15010. }
  15011. // restore original direction
  15012. $this->rtl = $tempRTL;
  15013. // restore previous settings
  15014. $this->setGraphicVars($gvars);
  15015. // set pointer to align the next text/objects
  15016. switch($align) {
  15017. case 'T':{
  15018. $this->y = $y;
  15019. $this->x = $this->img_rb_x;
  15020. break;
  15021. }
  15022. case 'M':{
  15023. $this->y = $y + round($h / 2);
  15024. $this->x = $this->img_rb_x;
  15025. break;
  15026. }
  15027. case 'B':{
  15028. $this->y = $this->img_rb_y;
  15029. $this->x = $this->img_rb_x;
  15030. break;
  15031. }
  15032. case 'N':{
  15033. $this->setY($this->img_rb_y);
  15034. break;
  15035. }
  15036. default:{
  15037. break;
  15038. }
  15039. }
  15040. $this->endlinex = $this->img_rb_x;
  15041. }
  15042. /**
  15043. * Print 2D Barcode.
  15044. * @param string $code code to print
  15045. * @param string $type type of barcode (see tcpdf_barcodes_2d.php for supported formats).
  15046. * @param float|null $x x position in user units
  15047. * @param float|null $y y position in user units
  15048. * @param float|null $w width in user units
  15049. * @param float|null $h height in user units
  15050. * @param array $style array of options:<ul>
  15051. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  15052. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  15053. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  15054. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  15055. * <li>int $style['module_width'] width of a single module in points</li>
  15056. * <li>int $style['module_height'] height of a single module in points</li>
  15057. * <li>array $style['fgcolor'] color array for bars and text</li>
  15058. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  15059. * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li>
  15060. * @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>
  15061. * @param boolean $distort if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  15062. * @author Nicola Asuni
  15063. * @since 4.5.037 (2009-04-07)
  15064. * @public
  15065. */
  15066. public function write2DBarcode($code, $type, $x=null, $y=null, $w=null, $h=null, $style=array(), $align='', $distort=false) {
  15067. if (TCPDF_STATIC::empty_string(trim($code))) {
  15068. return;
  15069. }
  15070. require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php');
  15071. // save current graphic settings
  15072. $gvars = $this->getGraphicVars();
  15073. // create new barcode object
  15074. $barcodeobj = new TCPDF2DBarcode($code, $type);
  15075. $arrcode = $barcodeobj->getBarcodeArray();
  15076. if (empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
  15077. $this->Error('Error in 2D barcode string');
  15078. }
  15079. // set default values
  15080. if (!isset($style['position'])) {
  15081. $style['position'] = '';
  15082. }
  15083. if (!isset($style['fgcolor'])) {
  15084. $style['fgcolor'] = array(0,0,0); // default black
  15085. }
  15086. if (!isset($style['bgcolor'])) {
  15087. $style['bgcolor'] = false; // default transparent
  15088. }
  15089. if (!isset($style['border'])) {
  15090. $style['border'] = false;
  15091. }
  15092. // padding
  15093. if (!isset($style['padding'])) {
  15094. $style['padding'] = 0;
  15095. } elseif ($style['padding'] === 'auto') {
  15096. $style['padding'] = 4;
  15097. }
  15098. if (!isset($style['hpadding'])) {
  15099. $style['hpadding'] = $style['padding'];
  15100. } elseif ($style['hpadding'] === 'auto') {
  15101. $style['hpadding'] = 4;
  15102. }
  15103. if (!isset($style['vpadding'])) {
  15104. $style['vpadding'] = $style['padding'];
  15105. } elseif ($style['vpadding'] === 'auto') {
  15106. $style['vpadding'] = 4;
  15107. }
  15108. $hpad = (2 * $style['hpadding']);
  15109. $vpad = (2 * $style['vpadding']);
  15110. // cell (module) dimension
  15111. if (!isset($style['module_width'])) {
  15112. $style['module_width'] = 1; // width of a single module in points
  15113. }
  15114. if (!isset($style['module_height'])) {
  15115. $style['module_height'] = 1; // height of a single module in points
  15116. }
  15117. if (TCPDF_STATIC::empty_string($x)) {
  15118. $x = $this->x;
  15119. }
  15120. if (TCPDF_STATIC::empty_string($y)) {
  15121. $y = $this->y;
  15122. }
  15123. // check page for no-write regions and adapt page margins if necessary
  15124. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  15125. // number of barcode columns and rows
  15126. $rows = $arrcode['num_rows'];
  15127. $cols = $arrcode['num_cols'];
  15128. if (($rows <= 0) || ($cols <= 0)){
  15129. $this->Error('Error in 2D barcode string');
  15130. }
  15131. // module width and height
  15132. $mw = $style['module_width'];
  15133. $mh = $style['module_height'];
  15134. if (($mw <= 0) OR ($mh <= 0)) {
  15135. $this->Error('Error in 2D barcode string');
  15136. }
  15137. // get max dimensions
  15138. if ($this->rtl) {
  15139. $maxw = $x - $this->lMargin;
  15140. } else {
  15141. $maxw = $this->w - $this->rMargin - $x;
  15142. }
  15143. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  15144. $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
  15145. $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
  15146. if (!$distort) {
  15147. if (($maxw * $ratioHW) > $maxh) {
  15148. $maxw = $maxh * $ratioWH;
  15149. }
  15150. if (($maxh * $ratioWH) > $maxw) {
  15151. $maxh = $maxw * $ratioHW;
  15152. }
  15153. }
  15154. // set maximum dimensions
  15155. if ($w > $maxw) {
  15156. $w = $maxw;
  15157. }
  15158. if ($h > $maxh) {
  15159. $h = $maxh;
  15160. }
  15161. // set dimensions
  15162. if ((TCPDF_STATIC::empty_string($w) OR ($w <= 0)) AND (TCPDF_STATIC::empty_string($h) OR ($h <= 0))) {
  15163. $w = ($cols + $hpad) * ($mw / $this->k);
  15164. $h = ($rows + $vpad) * ($mh / $this->k);
  15165. } elseif (($w === '') OR ($w <= 0)) {
  15166. $w = $h * $ratioWH;
  15167. } elseif (($h === '') OR ($h <= 0)) {
  15168. $h = $w * $ratioHW;
  15169. }
  15170. // barcode size (excluding padding)
  15171. $bw = ($w * $cols) / ($cols + $hpad);
  15172. $bh = ($h * $rows) / ($rows + $vpad);
  15173. // dimension of single barcode cell unit
  15174. $cw = $bw / $cols;
  15175. $ch = $bh / $rows;
  15176. if (!$distort) {
  15177. if (($cw / $ch) > ($mw / $mh)) {
  15178. // correct horizontal distortion
  15179. $cw = $ch * $mw / $mh;
  15180. $bw = $cw * $cols;
  15181. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  15182. } else {
  15183. // correct vertical distortion
  15184. $ch = $cw * $mh / $mw;
  15185. $bh = $ch * $rows;
  15186. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  15187. }
  15188. }
  15189. // fit the barcode on available space
  15190. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  15191. // set alignment
  15192. $this->img_rb_y = $y + $h;
  15193. // set alignment
  15194. if ($this->rtl) {
  15195. if ($style['position'] == 'L') {
  15196. $xpos = $this->lMargin;
  15197. } elseif ($style['position'] == 'C') {
  15198. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15199. } elseif ($style['position'] == 'R') {
  15200. $xpos = $this->w - $this->rMargin - $w;
  15201. } else {
  15202. $xpos = $x - $w;
  15203. }
  15204. $this->img_rb_x = $xpos;
  15205. } else {
  15206. if ($style['position'] == 'L') {
  15207. $xpos = $this->lMargin;
  15208. } elseif ($style['position'] == 'C') {
  15209. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15210. } elseif ($style['position'] == 'R') {
  15211. $xpos = $this->w - $this->rMargin - $w;
  15212. } else {
  15213. $xpos = $x;
  15214. }
  15215. $this->img_rb_x = $xpos + $w;
  15216. }
  15217. $xstart = $xpos + ($style['hpadding'] * $cw);
  15218. $ystart = $y + ($style['vpadding'] * $ch);
  15219. // barcode is always printed in LTR direction
  15220. $tempRTL = $this->rtl;
  15221. $this->rtl = false;
  15222. // print background color
  15223. if ($style['bgcolor']) {
  15224. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  15225. } elseif ($style['border']) {
  15226. $this->Rect($xpos, $y, $w, $h, 'D');
  15227. }
  15228. // set foreground color
  15229. $this->setDrawColorArray($style['fgcolor']);
  15230. // print barcode cells
  15231. // for each row
  15232. for ($r = 0; $r < $rows; ++$r) {
  15233. $xr = $xstart;
  15234. // for each column
  15235. for ($c = 0; $c < $cols; ++$c) {
  15236. if ($arrcode['bcode'][$r][$c] == 1) {
  15237. // draw a single barcode cell
  15238. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  15239. }
  15240. $xr += $cw;
  15241. }
  15242. $ystart += $ch;
  15243. }
  15244. // restore original direction
  15245. $this->rtl = $tempRTL;
  15246. // restore previous settings
  15247. $this->setGraphicVars($gvars);
  15248. // set pointer to align the next text/objects
  15249. switch($align) {
  15250. case 'T':{
  15251. $this->y = $y;
  15252. $this->x = $this->img_rb_x;
  15253. break;
  15254. }
  15255. case 'M':{
  15256. $this->y = $y + round($h/2);
  15257. $this->x = $this->img_rb_x;
  15258. break;
  15259. }
  15260. case 'B':{
  15261. $this->y = $this->img_rb_y;
  15262. $this->x = $this->img_rb_x;
  15263. break;
  15264. }
  15265. case 'N':{
  15266. $this->setY($this->img_rb_y);
  15267. break;
  15268. }
  15269. default:{
  15270. break;
  15271. }
  15272. }
  15273. $this->endlinex = $this->img_rb_x;
  15274. }
  15275. /**
  15276. * Returns an array containing current margins:
  15277. * <ul>
  15278. <li>$ret['left'] = left margin</li>
  15279. <li>$ret['right'] = right margin</li>
  15280. <li>$ret['top'] = top margin</li>
  15281. <li>$ret['bottom'] = bottom margin</li>
  15282. <li>$ret['header'] = header margin</li>
  15283. <li>$ret['footer'] = footer margin</li>
  15284. <li>$ret['cell'] = cell padding array</li>
  15285. <li>$ret['padding_left'] = cell left padding</li>
  15286. <li>$ret['padding_top'] = cell top padding</li>
  15287. <li>$ret['padding_right'] = cell right padding</li>
  15288. <li>$ret['padding_bottom'] = cell bottom padding</li>
  15289. * </ul>
  15290. * @return array containing all margins measures
  15291. * @public
  15292. * @since 3.2.000 (2008-06-23)
  15293. */
  15294. public function getMargins() {
  15295. $ret = array(
  15296. 'left' => $this->lMargin,
  15297. 'right' => $this->rMargin,
  15298. 'top' => $this->tMargin,
  15299. 'bottom' => $this->bMargin,
  15300. 'header' => $this->header_margin,
  15301. 'footer' => $this->footer_margin,
  15302. 'cell' => $this->cell_padding,
  15303. 'padding_left' => $this->cell_padding['L'],
  15304. 'padding_top' => $this->cell_padding['T'],
  15305. 'padding_right' => $this->cell_padding['R'],
  15306. 'padding_bottom' => $this->cell_padding['B']
  15307. );
  15308. return $ret;
  15309. }
  15310. /**
  15311. * Returns an array containing original margins:
  15312. * <ul>
  15313. <li>$ret['left'] = left margin</li>
  15314. <li>$ret['right'] = right margin</li>
  15315. * </ul>
  15316. * @return array containing all margins measures
  15317. * @public
  15318. * @since 4.0.012 (2008-07-24)
  15319. */
  15320. public function getOriginalMargins() {
  15321. $ret = array(
  15322. 'left' => $this->original_lMargin,
  15323. 'right' => $this->original_rMargin
  15324. );
  15325. return $ret;
  15326. }
  15327. /**
  15328. * Returns the current font size.
  15329. * @return float current font size
  15330. * @public
  15331. * @since 3.2.000 (2008-06-23)
  15332. */
  15333. public function getFontSize() {
  15334. return $this->FontSize;
  15335. }
  15336. /**
  15337. * Returns the current font size in points unit.
  15338. * @return int current font size in points unit
  15339. * @public
  15340. * @since 3.2.000 (2008-06-23)
  15341. */
  15342. public function getFontSizePt() {
  15343. return $this->FontSizePt;
  15344. }
  15345. /**
  15346. * Returns the current font family name.
  15347. * @return string current font family name
  15348. * @public
  15349. * @since 4.3.008 (2008-12-05)
  15350. */
  15351. public function getFontFamily() {
  15352. return $this->FontFamily;
  15353. }
  15354. /**
  15355. * Returns the current font style.
  15356. * @return string current font style
  15357. * @public
  15358. * @since 4.3.008 (2008-12-05)
  15359. */
  15360. public function getFontStyle() {
  15361. return $this->FontStyle;
  15362. }
  15363. /**
  15364. * Cleanup HTML code (requires HTML Tidy library).
  15365. * @param string $html htmlcode to fix
  15366. * @param string $default_css CSS commands to add
  15367. * @param array|null $tagvs parameters for setHtmlVSpace method
  15368. * @param array|null $tidy_options options for tidy_parse_string function
  15369. * @return string XHTML code cleaned up
  15370. * @author Nicola Asuni
  15371. * @public
  15372. * @since 5.9.017 (2010-11-16)
  15373. * @see setHtmlVSpace()
  15374. */
  15375. public function fixHTMLCode($html, $default_css='', $tagvs=null, $tidy_options=null) {
  15376. return TCPDF_STATIC::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces);
  15377. }
  15378. /**
  15379. * Returns the border width from CSS property
  15380. * @param string $width border width
  15381. * @return int with in user units
  15382. * @protected
  15383. * @since 5.7.000 (2010-08-02)
  15384. */
  15385. protected function getCSSBorderWidth($width) {
  15386. if ($width == 'thin') {
  15387. $width = (2 / $this->k);
  15388. } elseif ($width == 'medium') {
  15389. $width = (4 / $this->k);
  15390. } elseif ($width == 'thick') {
  15391. $width = (6 / $this->k);
  15392. } else {
  15393. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  15394. }
  15395. return $width;
  15396. }
  15397. /**
  15398. * Returns the border dash style from CSS property
  15399. * @param string $style border style to convert
  15400. * @return int sash style (return -1 in case of none or hidden border)
  15401. * @protected
  15402. * @since 5.7.000 (2010-08-02)
  15403. */
  15404. protected function getCSSBorderDashStyle($style) {
  15405. switch (strtolower($style)) {
  15406. case 'none':
  15407. case 'hidden': {
  15408. $dash = -1;
  15409. break;
  15410. }
  15411. case 'dotted': {
  15412. $dash = 1;
  15413. break;
  15414. }
  15415. case 'dashed': {
  15416. $dash = 3;
  15417. break;
  15418. }
  15419. case 'double':
  15420. case 'groove':
  15421. case 'ridge':
  15422. case 'inset':
  15423. case 'outset':
  15424. case 'solid':
  15425. default: {
  15426. $dash = 0;
  15427. break;
  15428. }
  15429. }
  15430. return $dash;
  15431. }
  15432. /**
  15433. * Returns the border style array from CSS border properties
  15434. * @param string $cssborder border properties
  15435. * @return array containing border properties
  15436. * @protected
  15437. * @since 5.7.000 (2010-08-02)
  15438. */
  15439. protected function getCSSBorderStyle($cssborder) {
  15440. $bprop = preg_split('/[\s]+/', trim($cssborder));
  15441. $count = count($bprop);
  15442. if ($count > 0 && $bprop[$count - 1] === '!important') {
  15443. unset($bprop[$count - 1]);
  15444. --$count;
  15445. }
  15446. $border = array(); // value to be returned
  15447. switch ($count) {
  15448. case 2: {
  15449. $width = 'medium';
  15450. $style = $bprop[0];
  15451. $color = $bprop[1];
  15452. break;
  15453. }
  15454. case 1: {
  15455. $width = 'medium';
  15456. $style = $bprop[0];
  15457. $color = 'black';
  15458. break;
  15459. }
  15460. case 0: {
  15461. $width = 'medium';
  15462. $style = 'solid';
  15463. $color = 'black';
  15464. break;
  15465. }
  15466. default: {
  15467. $width = $bprop[0];
  15468. $style = $bprop[1];
  15469. $color = $bprop[2];
  15470. break;
  15471. }
  15472. }
  15473. if ($style == 'none') {
  15474. return array();
  15475. }
  15476. $border['cap'] = 'square';
  15477. $border['join'] = 'miter';
  15478. $border['dash'] = $this->getCSSBorderDashStyle($style);
  15479. if ($border['dash'] < 0) {
  15480. return array();
  15481. }
  15482. $border['width'] = $this->getCSSBorderWidth($width);
  15483. $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color, $this->spot_colors);
  15484. return $border;
  15485. }
  15486. /**
  15487. * Get the internal Cell padding from CSS attribute.
  15488. * @param string $csspadding padding properties
  15489. * @param float $width width of the containing element
  15490. * @return array of cell paddings
  15491. * @public
  15492. * @since 5.9.000 (2010-10-04)
  15493. */
  15494. public function getCSSPadding($csspadding, $width=0) {
  15495. $padding = preg_split('/[\s]+/', trim($csspadding));
  15496. $cell_padding = array(); // value to be returned
  15497. switch (count($padding)) {
  15498. case 4: {
  15499. $cell_padding['T'] = $padding[0];
  15500. $cell_padding['R'] = $padding[1];
  15501. $cell_padding['B'] = $padding[2];
  15502. $cell_padding['L'] = $padding[3];
  15503. break;
  15504. }
  15505. case 3: {
  15506. $cell_padding['T'] = $padding[0];
  15507. $cell_padding['R'] = $padding[1];
  15508. $cell_padding['B'] = $padding[2];
  15509. $cell_padding['L'] = $padding[1];
  15510. break;
  15511. }
  15512. case 2: {
  15513. $cell_padding['T'] = $padding[0];
  15514. $cell_padding['R'] = $padding[1];
  15515. $cell_padding['B'] = $padding[0];
  15516. $cell_padding['L'] = $padding[1];
  15517. break;
  15518. }
  15519. case 1: {
  15520. $cell_padding['T'] = $padding[0];
  15521. $cell_padding['R'] = $padding[0];
  15522. $cell_padding['B'] = $padding[0];
  15523. $cell_padding['L'] = $padding[0];
  15524. break;
  15525. }
  15526. default: {
  15527. return $this->cell_padding;
  15528. }
  15529. }
  15530. if ($width == 0) {
  15531. $width = $this->w - $this->lMargin - $this->rMargin;
  15532. }
  15533. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  15534. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  15535. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  15536. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  15537. return $cell_padding;
  15538. }
  15539. /**
  15540. * Get the internal Cell margin from CSS attribute.
  15541. * @param string $cssmargin margin properties
  15542. * @param float $width width of the containing element
  15543. * @return array of cell margins
  15544. * @public
  15545. * @since 5.9.000 (2010-10-04)
  15546. */
  15547. public function getCSSMargin($cssmargin, $width=0) {
  15548. $margin = preg_split('/[\s]+/', trim($cssmargin));
  15549. $cell_margin = array(); // value to be returned
  15550. switch (count($margin)) {
  15551. case 4: {
  15552. $cell_margin['T'] = $margin[0];
  15553. $cell_margin['R'] = $margin[1];
  15554. $cell_margin['B'] = $margin[2];
  15555. $cell_margin['L'] = $margin[3];
  15556. break;
  15557. }
  15558. case 3: {
  15559. $cell_margin['T'] = $margin[0];
  15560. $cell_margin['R'] = $margin[1];
  15561. $cell_margin['B'] = $margin[2];
  15562. $cell_margin['L'] = $margin[1];
  15563. break;
  15564. }
  15565. case 2: {
  15566. $cell_margin['T'] = $margin[0];
  15567. $cell_margin['R'] = $margin[1];
  15568. $cell_margin['B'] = $margin[0];
  15569. $cell_margin['L'] = $margin[1];
  15570. break;
  15571. }
  15572. case 1: {
  15573. $cell_margin['T'] = $margin[0];
  15574. $cell_margin['R'] = $margin[0];
  15575. $cell_margin['B'] = $margin[0];
  15576. $cell_margin['L'] = $margin[0];
  15577. break;
  15578. }
  15579. default: {
  15580. return $this->cell_margin;
  15581. }
  15582. }
  15583. if ($width == 0) {
  15584. $width = $this->w - $this->lMargin - $this->rMargin;
  15585. }
  15586. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  15587. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  15588. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  15589. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  15590. return $cell_margin;
  15591. }
  15592. /**
  15593. * Get the border-spacing from CSS attribute.
  15594. * @param string $cssbspace border-spacing CSS properties
  15595. * @param float $width width of the containing element
  15596. * @return array of border spacings
  15597. * @public
  15598. * @since 5.9.010 (2010-10-27)
  15599. */
  15600. public function getCSSBorderMargin($cssbspace, $width=0) {
  15601. $space = preg_split('/[\s]+/', trim($cssbspace));
  15602. $border_spacing = array(); // value to be returned
  15603. switch (count($space)) {
  15604. case 2: {
  15605. $border_spacing['H'] = $space[0];
  15606. $border_spacing['V'] = $space[1];
  15607. break;
  15608. }
  15609. case 1: {
  15610. $border_spacing['H'] = $space[0];
  15611. $border_spacing['V'] = $space[0];
  15612. break;
  15613. }
  15614. default: {
  15615. return array('H' => 0, 'V' => 0);
  15616. }
  15617. }
  15618. if ($width == 0) {
  15619. $width = $this->w - $this->lMargin - $this->rMargin;
  15620. }
  15621. $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
  15622. $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
  15623. return $border_spacing;
  15624. }
  15625. /**
  15626. * Returns the letter-spacing value from CSS value
  15627. * @param string $spacing letter-spacing value
  15628. * @param float $parent font spacing (tracking) value of the parent element
  15629. * @return float quantity to increases or decreases the space between characters in a text.
  15630. * @protected
  15631. * @since 5.9.000 (2010-10-02)
  15632. */
  15633. protected function getCSSFontSpacing($spacing, $parent=0) {
  15634. $val = 0; // value to be returned
  15635. $spacing = trim($spacing);
  15636. switch ($spacing) {
  15637. case 'normal': {
  15638. $val = 0;
  15639. break;
  15640. }
  15641. case 'inherit': {
  15642. if ($parent == 'normal') {
  15643. $val = 0;
  15644. } else {
  15645. $val = $parent;
  15646. }
  15647. break;
  15648. }
  15649. default: {
  15650. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  15651. }
  15652. }
  15653. return $val;
  15654. }
  15655. /**
  15656. * Returns the percentage of font stretching from CSS value
  15657. * @param string $stretch stretch mode
  15658. * @param float $parent stretch value of the parent element
  15659. * @return float font stretching percentage
  15660. * @protected
  15661. * @since 5.9.000 (2010-10-02)
  15662. */
  15663. protected function getCSSFontStretching($stretch, $parent=100) {
  15664. $val = 100; // value to be returned
  15665. $stretch = trim($stretch);
  15666. switch ($stretch) {
  15667. case 'ultra-condensed': {
  15668. $val = 40;
  15669. break;
  15670. }
  15671. case 'extra-condensed': {
  15672. $val = 55;
  15673. break;
  15674. }
  15675. case 'condensed': {
  15676. $val = 70;
  15677. break;
  15678. }
  15679. case 'semi-condensed': {
  15680. $val = 85;
  15681. break;
  15682. }
  15683. case 'normal': {
  15684. $val = 100;
  15685. break;
  15686. }
  15687. case 'semi-expanded': {
  15688. $val = 115;
  15689. break;
  15690. }
  15691. case 'expanded': {
  15692. $val = 130;
  15693. break;
  15694. }
  15695. case 'extra-expanded': {
  15696. $val = 145;
  15697. break;
  15698. }
  15699. case 'ultra-expanded': {
  15700. $val = 160;
  15701. break;
  15702. }
  15703. case 'wider': {
  15704. $val = ($parent + 10);
  15705. break;
  15706. }
  15707. case 'narrower': {
  15708. $val = ($parent - 10);
  15709. break;
  15710. }
  15711. case 'inherit': {
  15712. if ($parent == 'normal') {
  15713. $val = 100;
  15714. } else {
  15715. $val = $parent;
  15716. }
  15717. break;
  15718. }
  15719. default: {
  15720. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  15721. }
  15722. }
  15723. return $val;
  15724. }
  15725. /**
  15726. * Convert HTML string containing font size value to points
  15727. * @param string $val String containing font size value and unit.
  15728. * @param float $refsize Reference font size in points.
  15729. * @param float $parent_size Parent font size in points.
  15730. * @param string $defaultunit Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  15731. * @return float value in points
  15732. * @public
  15733. */
  15734. public function getHTMLFontUnits($val, $refsize=12, $parent_size=12, $defaultunit='pt') {
  15735. $refsize = TCPDF_FONTS::getFontRefSize($refsize);
  15736. $parent_size = TCPDF_FONTS::getFontRefSize($parent_size, $refsize);
  15737. switch ($val) {
  15738. case 'xx-small': {
  15739. $size = ($refsize - 4);
  15740. break;
  15741. }
  15742. case 'x-small': {
  15743. $size = ($refsize - 3);
  15744. break;
  15745. }
  15746. case 'small': {
  15747. $size = ($refsize - 2);
  15748. break;
  15749. }
  15750. case 'medium': {
  15751. $size = $refsize;
  15752. break;
  15753. }
  15754. case 'large': {
  15755. $size = ($refsize + 2);
  15756. break;
  15757. }
  15758. case 'x-large': {
  15759. $size = ($refsize + 4);
  15760. break;
  15761. }
  15762. case 'xx-large': {
  15763. $size = ($refsize + 6);
  15764. break;
  15765. }
  15766. case 'smaller': {
  15767. $size = ($parent_size - 3);
  15768. break;
  15769. }
  15770. case 'larger': {
  15771. $size = ($parent_size + 3);
  15772. break;
  15773. }
  15774. default: {
  15775. $parentSize = $this->getHTMLUnitToUnits($parent_size, $refsize, $defaultunit, true);
  15776. $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true);
  15777. }
  15778. }
  15779. return $size;
  15780. }
  15781. /**
  15782. * Returns the HTML DOM array.
  15783. * @param string $html html code
  15784. * @return array
  15785. * @protected
  15786. * @since 3.2.000 (2008-06-20)
  15787. */
  15788. protected function getHtmlDomArray($html) {
  15789. // set inheritable properties fot the first void element
  15790. // 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
  15791. $dom = array(
  15792. array(
  15793. 'tag' => false,
  15794. 'block' => false,
  15795. 'value' => '',
  15796. 'parent' => 0,
  15797. 'hide' => false,
  15798. 'fontname' => $this->FontFamily,
  15799. 'fontstyle' => $this->FontStyle,
  15800. 'fontsize' => $this->FontSizePt,
  15801. 'font-stretch' => $this->font_stretching,
  15802. 'letter-spacing' => $this->font_spacing,
  15803. 'stroke' => $this->textstrokewidth,
  15804. 'fill' => (($this->textrendermode % 2) == 0),
  15805. 'clip' => ($this->textrendermode > 3),
  15806. 'line-height' => $this->cell_height_ratio,
  15807. 'bgcolor' => false,
  15808. 'fgcolor' => $this->fgcolor, // color
  15809. 'strokecolor' => $this->strokecolor,
  15810. 'align' => '',
  15811. 'listtype' => '',
  15812. 'text-indent' => 0,
  15813. 'text-transform' => '',
  15814. 'border' => array(),
  15815. 'dir' => $this->rtl?'rtl':'ltr',
  15816. 'width' => 0,
  15817. 'height' => 0,
  15818. 'x' => 0,
  15819. 'y' => 0,
  15820. 'w' => 0,
  15821. 'h' => 0,
  15822. 'l' => 0,
  15823. 't' => 0,
  15824. 'r' => 0,
  15825. 'b' => 0,
  15826. 'padding' => array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0),
  15827. 'margin' => array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0),
  15828. 'border-spacing' => array('H' => 0, 'V' => 0),
  15829. 'border-collapse' => 'separate',
  15830. )
  15831. );
  15832. if(empty($html)) {
  15833. return $dom;
  15834. }
  15835. // array of CSS styles ( selector => properties).
  15836. $css = array();
  15837. // get CSS array defined at previous call
  15838. $matches = array();
  15839. if (preg_match_all('/<cssarray>([^\<]*?)<\/cssarray>/is', $html, $matches) > 0) {
  15840. if (isset($matches[1][0])) {
  15841. $css = array_merge($css, json_decode($this->unhtmlentities($matches[1][0]), true));
  15842. }
  15843. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/is', '', $html);
  15844. }
  15845. // extract external CSS files
  15846. $matches = array();
  15847. if (preg_match_all('/<link([^\>]*?)>/is', $html, $matches) > 0) {
  15848. foreach ($matches[1] as $key => $link) {
  15849. $type = array();
  15850. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
  15851. $type = array();
  15852. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  15853. // get 'all' and 'print' media, other media types are discarded
  15854. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15855. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15856. $type = array();
  15857. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
  15858. // read CSS data file
  15859. $cssdata = $this->getCachedFileContents(trim($type[1]));
  15860. if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) {
  15861. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15862. }
  15863. }
  15864. }
  15865. }
  15866. }
  15867. }
  15868. // extract style tags
  15869. $matches = array();
  15870. if (preg_match_all('/<style([^\>]*?)>([^\<]*?)<\/style>/is', $html, $matches) > 0) {
  15871. foreach ($matches[1] as $key => $media) {
  15872. $type = array();
  15873. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  15874. // get 'all' and 'print' media, other media types are discarded
  15875. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15876. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15877. $cssdata = $matches[2][$key];
  15878. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15879. }
  15880. }
  15881. }
  15882. // create a special tag to contain the CSS array (used for table content)
  15883. $csstagarray = '<cssarray>'.htmlentities(json_encode($css)).'</cssarray>';
  15884. // remove head and style blocks
  15885. $html = preg_replace('/<head([^\>]*?)>(.*?)<\/head>/is', '', $html);
  15886. $html = preg_replace('/<style([^\>]*?)>([^\<]*?)<\/style>/is', '', $html);
  15887. // define block tags
  15888. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  15889. // define self-closing tags
  15890. $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  15891. // remove all unsupported tags (the line below lists all supported tags)
  15892. $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>');
  15893. //replace some blank characters
  15894. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  15895. $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);
  15896. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  15897. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  15898. $html = strtr($html, $repTable);
  15899. $offset = 0;
  15900. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  15901. $html_a = substr($html, 0, $offset);
  15902. $html_b = substr($html, $offset, ($pos - $offset + 6));
  15903. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  15904. // preserve newlines on <pre> tag
  15905. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  15906. }
  15907. while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  15908. // preserve spaces on <pre> tag
  15909. $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  15910. }
  15911. $html = $html_a.$html_b.substr($html, $pos + 6);
  15912. $offset = strlen($html_a.$html_b);
  15913. }
  15914. $offset = 0;
  15915. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  15916. $html_a = substr($html, 0, $offset);
  15917. $html_b = substr($html, $offset, ($pos - $offset + 11));
  15918. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  15919. // preserve newlines on <textarea> tag
  15920. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  15921. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  15922. }
  15923. $html = $html_a.$html_b.substr($html, $pos + 11);
  15924. $offset = strlen($html_a.$html_b);
  15925. }
  15926. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  15927. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  15928. $offset = 0;
  15929. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  15930. $html_a = substr($html, 0, $offset);
  15931. $html_b = substr($html, $offset, ($pos - $offset + 9));
  15932. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  15933. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  15934. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  15935. }
  15936. $html = $html_a.$html_b.substr($html, $pos + 9);
  15937. $offset = strlen($html_a.$html_b);
  15938. }
  15939. if (preg_match("'</select'si", $html)) {
  15940. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  15941. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  15942. }
  15943. $html = str_replace("\n", ' ', $html);
  15944. // restore textarea newlines
  15945. $html = str_replace('<TBR>', "\n", $html);
  15946. // remove extra spaces from code
  15947. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  15948. $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
  15949. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  15950. $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
  15951. $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);
  15952. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  15953. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  15954. $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
  15955. $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
  15956. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  15957. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  15958. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  15959. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  15960. $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  15961. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  15962. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  15963. $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
  15964. $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
  15965. $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  15966. // trim string
  15967. $html = $this->stringTrim($html);
  15968. // fix br tag after li
  15969. $html = preg_replace('/<li><br([^\>]*)>/', '<li> <br\\1>', $html);
  15970. // fix first image tag alignment
  15971. $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
  15972. // pattern for generic tag
  15973. $tagpattern = '/(<[^>]+>)/';
  15974. // explodes the string
  15975. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  15976. // count elements
  15977. $maxel = count($a);
  15978. $elkey = 0;
  15979. $thead = false; // true when we are inside the THEAD tag
  15980. $key = 1;
  15981. $level = array();
  15982. array_push($level, 0); // root
  15983. while ($elkey < $maxel) {
  15984. $dom[$key] = array();
  15985. $element = $a[$elkey];
  15986. $dom[$key]['elkey'] = $elkey;
  15987. if (preg_match($tagpattern, $element)) {
  15988. // html tag
  15989. $element = substr($element, 1, -1);
  15990. // get tag name
  15991. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  15992. $tagname = strtolower($tag[1]);
  15993. // check if we are inside a table header
  15994. if ($tagname == 'thead') {
  15995. if ($element[0] == '/') {
  15996. $thead = false;
  15997. } else {
  15998. $thead = true;
  15999. }
  16000. ++$elkey;
  16001. continue;
  16002. }
  16003. $dom[$key]['tag'] = true;
  16004. $dom[$key]['value'] = $tagname;
  16005. if (in_array($dom[$key]['value'], $blocktags)) {
  16006. $dom[$key]['block'] = true;
  16007. } else {
  16008. $dom[$key]['block'] = false;
  16009. }
  16010. if ($element[0] == '/') {
  16011. // *** closing html tag
  16012. $dom[$key]['opening'] = false;
  16013. $dom[$key]['parent'] = end($level);
  16014. array_pop($level);
  16015. $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
  16016. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  16017. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  16018. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  16019. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  16020. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  16021. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  16022. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  16023. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  16024. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  16025. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  16026. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  16027. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  16028. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  16029. $dom[$key]['text-transform'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['text-transform'];
  16030. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  16031. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  16032. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  16033. }
  16034. // set the number of columns in table tag
  16035. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  16036. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  16037. }
  16038. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  16039. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  16040. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  16041. $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]);
  16042. }
  16043. $key = $i;
  16044. // mark nested tables
  16045. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  16046. // remove thead sections from nested tables
  16047. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  16048. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  16049. }
  16050. // store header rows on a new table
  16051. if (
  16052. ($dom[$key]['value'] === 'tr')
  16053. && !empty($dom[($dom[$key]['parent'])]['thead'])
  16054. && ($dom[($dom[$key]['parent'])]['thead'] === true)
  16055. ) {
  16056. if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  16057. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  16058. }
  16059. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  16060. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  16061. }
  16062. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  16063. $dom[($dom[$key]['parent'])]['attribute'] = array();
  16064. }
  16065. // header elements must be always contained in a single page
  16066. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  16067. }
  16068. if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  16069. // remove the nobr attributes from the table header
  16070. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  16071. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  16072. }
  16073. } else {
  16074. // *** opening or self-closing html tag
  16075. $dom[$key]['opening'] = true;
  16076. $dom[$key]['parent'] = end($level);
  16077. if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  16078. // self-closing tag
  16079. $dom[$key]['self'] = true;
  16080. } else {
  16081. // opening tag
  16082. array_push($level, $key);
  16083. $dom[$key]['self'] = false;
  16084. }
  16085. // copy some values from parent
  16086. $parentkey = 0;
  16087. if ($key > 0) {
  16088. $parentkey = $dom[$key]['parent'];
  16089. $dom[$key]['hide'] = $dom[$parentkey]['hide'];
  16090. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  16091. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  16092. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  16093. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  16094. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  16095. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  16096. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  16097. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  16098. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16099. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  16100. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  16101. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  16102. $dom[$key]['align'] = $dom[$parentkey]['align'];
  16103. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  16104. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  16105. $dom[$key]['text-transform'] = $dom[$parentkey]['text-transform'];
  16106. $dom[$key]['border'] = array();
  16107. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  16108. }
  16109. // get attributes
  16110. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  16111. $dom[$key]['attribute'] = array(); // reset attribute array
  16112. foreach($attr_array[1] as $id => $name) {
  16113. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  16114. }
  16115. if (!empty($css)) {
  16116. // merge CSS style to current style
  16117. list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom, $key, $css);
  16118. $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']);
  16119. }
  16120. // split style attributes
  16121. if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  16122. // get style attributes
  16123. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  16124. $dom[$key]['style'] = array(); // reset style attribute array
  16125. foreach($style_array[1] as $id => $name) {
  16126. // in case of duplicate attribute the last replace the previous
  16127. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  16128. }
  16129. // --- get some style attributes ---
  16130. // text direction
  16131. if (isset($dom[$key]['style']['direction'])) {
  16132. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  16133. }
  16134. // display
  16135. if (isset($dom[$key]['style']['display'])) {
  16136. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
  16137. }
  16138. // font family
  16139. if (isset($dom[$key]['style']['font-family'])) {
  16140. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  16141. }
  16142. // list-style-type
  16143. if (isset($dom[$key]['style']['list-style-type'])) {
  16144. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  16145. if ($dom[$key]['listtype'] == 'inherit') {
  16146. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  16147. }
  16148. }
  16149. // text-indent
  16150. if (isset($dom[$key]['style']['text-indent'])) {
  16151. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  16152. if ($dom[$key]['text-indent'] == 'inherit') {
  16153. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  16154. }
  16155. }
  16156. // text-transform
  16157. if (isset($dom[$key]['style']['text-transform'])) {
  16158. $dom[$key]['text-transform'] = $dom[$key]['style']['text-transform'];
  16159. }
  16160. // font size
  16161. if (isset($dom[$key]['style']['font-size'])) {
  16162. $fsize = trim($dom[$key]['style']['font-size']);
  16163. $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
  16164. }
  16165. // font-stretch
  16166. if (isset($dom[$key]['style']['font-stretch'])) {
  16167. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  16168. }
  16169. // letter-spacing
  16170. if (isset($dom[$key]['style']['letter-spacing'])) {
  16171. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  16172. }
  16173. // line-height (internally is the cell height ratio)
  16174. if (isset($dom[$key]['style']['line-height'])) {
  16175. $lineheight = trim($dom[$key]['style']['line-height']);
  16176. switch ($lineheight) {
  16177. // A normal line height. This is default
  16178. case 'normal': {
  16179. $dom[$key]['line-height'] = $dom[0]['line-height'];
  16180. break;
  16181. }
  16182. case 'inherit': {
  16183. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16184. }
  16185. default: {
  16186. if (is_numeric($lineheight)) {
  16187. // convert to percentage of font height
  16188. $lineheight = ($lineheight * 100).'%';
  16189. }
  16190. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  16191. if (substr($lineheight, -1) !== '%') {
  16192. if ($dom[$key]['fontsize'] <= 0) {
  16193. $dom[$key]['line-height'] = 1;
  16194. } else {
  16195. $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding['T'] - $this->cell_padding['B']) / $dom[$key]['fontsize']);
  16196. }
  16197. }
  16198. }
  16199. }
  16200. }
  16201. // font style
  16202. if (isset($dom[$key]['style']['font-weight'])) {
  16203. if (strtolower($dom[$key]['style']['font-weight'][0]) == 'n') {
  16204. if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
  16205. $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
  16206. }
  16207. } elseif (strtolower($dom[$key]['style']['font-weight'][0]) == 'b') {
  16208. $dom[$key]['fontstyle'] .= 'B';
  16209. }
  16210. }
  16211. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style'][0]) == 'i')) {
  16212. $dom[$key]['fontstyle'] .= 'I';
  16213. }
  16214. // font color
  16215. if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) {
  16216. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors);
  16217. } elseif ($dom[$key]['value'] == 'a') {
  16218. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16219. }
  16220. // background color
  16221. if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) {
  16222. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors);
  16223. }
  16224. // text-decoration
  16225. if (isset($dom[$key]['style']['text-decoration'])) {
  16226. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  16227. foreach ($decors as $dec) {
  16228. $dec = trim($dec);
  16229. if (!TCPDF_STATIC::empty_string($dec)) {
  16230. if ($dec[0] == 'u') {
  16231. // underline
  16232. $dom[$key]['fontstyle'] .= 'U';
  16233. } elseif ($dec[0] == 'l') {
  16234. // line-through
  16235. $dom[$key]['fontstyle'] .= 'D';
  16236. } elseif ($dec[0] == 'o') {
  16237. // overline
  16238. $dom[$key]['fontstyle'] .= 'O';
  16239. }
  16240. }
  16241. }
  16242. } elseif ($dom[$key]['value'] == 'a') {
  16243. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16244. }
  16245. // check for width attribute
  16246. if (isset($dom[$key]['style']['width'])) {
  16247. $dom[$key]['width'] = $dom[$key]['style']['width'];
  16248. }
  16249. // check for height attribute
  16250. if (isset($dom[$key]['style']['height'])) {
  16251. $dom[$key]['height'] = $dom[$key]['style']['height'];
  16252. }
  16253. // check for text alignment
  16254. if (isset($dom[$key]['style']['text-align'])) {
  16255. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align'][0]);
  16256. }
  16257. // check for CSS border properties
  16258. if (isset($dom[$key]['style']['border'])) {
  16259. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  16260. if (!empty($borderstyle)) {
  16261. $dom[$key]['border']['LTRB'] = $borderstyle;
  16262. }
  16263. }
  16264. if (isset($dom[$key]['style']['border-color'])) {
  16265. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  16266. if (isset($brd_colors[3])) {
  16267. $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors);
  16268. }
  16269. if (isset($brd_colors[1])) {
  16270. $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors);
  16271. }
  16272. if (isset($brd_colors[0])) {
  16273. $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors);
  16274. }
  16275. if (isset($brd_colors[2])) {
  16276. $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors);
  16277. }
  16278. }
  16279. if (isset($dom[$key]['style']['border-width'])) {
  16280. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  16281. if (isset($brd_widths[3])) {
  16282. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  16283. }
  16284. if (isset($brd_widths[1])) {
  16285. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  16286. }
  16287. if (isset($brd_widths[0])) {
  16288. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  16289. }
  16290. if (isset($brd_widths[2])) {
  16291. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  16292. }
  16293. }
  16294. if (isset($dom[$key]['style']['border-style'])) {
  16295. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  16296. if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
  16297. $dom[$key]['border']['L']['cap'] = 'square';
  16298. $dom[$key]['border']['L']['join'] = 'miter';
  16299. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  16300. if ($dom[$key]['border']['L']['dash'] < 0) {
  16301. $dom[$key]['border']['L'] = array();
  16302. }
  16303. }
  16304. if (isset($brd_styles[1])) {
  16305. $dom[$key]['border']['R']['cap'] = 'square';
  16306. $dom[$key]['border']['R']['join'] = 'miter';
  16307. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  16308. if ($dom[$key]['border']['R']['dash'] < 0) {
  16309. $dom[$key]['border']['R'] = array();
  16310. }
  16311. }
  16312. if (isset($brd_styles[0])) {
  16313. $dom[$key]['border']['T']['cap'] = 'square';
  16314. $dom[$key]['border']['T']['join'] = 'miter';
  16315. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  16316. if ($dom[$key]['border']['T']['dash'] < 0) {
  16317. $dom[$key]['border']['T'] = array();
  16318. }
  16319. }
  16320. if (isset($brd_styles[2])) {
  16321. $dom[$key]['border']['B']['cap'] = 'square';
  16322. $dom[$key]['border']['B']['join'] = 'miter';
  16323. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  16324. if ($dom[$key]['border']['B']['dash'] < 0) {
  16325. $dom[$key]['border']['B'] = array();
  16326. }
  16327. }
  16328. }
  16329. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  16330. foreach ($cellside as $bsk => $bsv) {
  16331. if (isset($dom[$key]['style']['border-'.$bsv])) {
  16332. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  16333. if (!empty($borderstyle)) {
  16334. $dom[$key]['border'][$bsk] = $borderstyle;
  16335. }
  16336. }
  16337. if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  16338. $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors);
  16339. }
  16340. if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  16341. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  16342. }
  16343. if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  16344. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  16345. if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  16346. $dom[$key]['border'][$bsk] = array();
  16347. }
  16348. }
  16349. }
  16350. // check for CSS padding properties
  16351. if (isset($dom[$key]['style']['padding'])) {
  16352. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  16353. } else {
  16354. $dom[$key]['padding'] = $this->cell_padding;
  16355. }
  16356. foreach ($cellside as $psk => $psv) {
  16357. if (isset($dom[$key]['style']['padding-'.$psv])) {
  16358. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
  16359. }
  16360. }
  16361. // check for CSS margin properties
  16362. if (isset($dom[$key]['style']['margin'])) {
  16363. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  16364. } else {
  16365. $dom[$key]['margin'] = $this->cell_margin;
  16366. }
  16367. foreach ($cellside as $psk => $psv) {
  16368. if (isset($dom[$key]['style']['margin-'.$psv])) {
  16369. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
  16370. }
  16371. }
  16372. // check for CSS border-spacing properties
  16373. if (isset($dom[$key]['style']['border-spacing'])) {
  16374. $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  16375. }
  16376. // page-break-inside
  16377. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  16378. $dom[$key]['attribute']['nobr'] = 'true';
  16379. }
  16380. // page-break-before
  16381. if (isset($dom[$key]['style']['page-break-before'])) {
  16382. if ($dom[$key]['style']['page-break-before'] == 'always') {
  16383. $dom[$key]['attribute']['pagebreak'] = 'true';
  16384. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  16385. $dom[$key]['attribute']['pagebreak'] = 'left';
  16386. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  16387. $dom[$key]['attribute']['pagebreak'] = 'right';
  16388. }
  16389. }
  16390. // page-break-after
  16391. if (isset($dom[$key]['style']['page-break-after'])) {
  16392. if ($dom[$key]['style']['page-break-after'] == 'always') {
  16393. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  16394. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  16395. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  16396. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  16397. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  16398. }
  16399. }
  16400. }
  16401. if (isset($dom[$key]['attribute']['display'])) {
  16402. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
  16403. }
  16404. if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  16405. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  16406. if (!empty($borderstyle)) {
  16407. $dom[$key]['border']['LTRB'] = $borderstyle;
  16408. }
  16409. }
  16410. // check for font tag
  16411. if ($dom[$key]['value'] == 'font') {
  16412. // font family
  16413. if (isset($dom[$key]['attribute']['face'])) {
  16414. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  16415. }
  16416. // font size
  16417. if (isset($dom[$key]['attribute']['size'])) {
  16418. if ($key > 0) {
  16419. if ($dom[$key]['attribute']['size'][0] == '+') {
  16420. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  16421. } elseif ($dom[$key]['attribute']['size'][0] == '-') {
  16422. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  16423. } else {
  16424. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16425. }
  16426. } else {
  16427. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16428. }
  16429. }
  16430. }
  16431. // force natural alignment for lists
  16432. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  16433. AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  16434. if ($this->rtl) {
  16435. $dom[$key]['align'] = 'R';
  16436. } else {
  16437. $dom[$key]['align'] = 'L';
  16438. }
  16439. }
  16440. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  16441. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16442. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  16443. }
  16444. }
  16445. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  16446. $dom[$key]['fontstyle'] .= 'B';
  16447. }
  16448. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  16449. $dom[$key]['fontstyle'] .= 'I';
  16450. }
  16451. if ($dom[$key]['value'] == 'u') {
  16452. $dom[$key]['fontstyle'] .= 'U';
  16453. }
  16454. if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  16455. $dom[$key]['fontstyle'] .= 'D';
  16456. }
  16457. if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  16458. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16459. }
  16460. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  16461. $dom[$key]['fontname'] = $this->default_monospaced_font;
  16462. }
  16463. 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)) {
  16464. // headings h1, h2, h3, h4, h5, h6
  16465. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16466. $headsize = (4 - intval($dom[$key]['value'][1])) * 2;
  16467. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  16468. }
  16469. if (!isset($dom[$key]['style']['font-weight'])) {
  16470. $dom[$key]['fontstyle'] .= 'B';
  16471. }
  16472. }
  16473. if (($dom[$key]['value'] == 'table')) {
  16474. $dom[$key]['rows'] = 0; // number of rows
  16475. $dom[$key]['trids'] = array(); // IDs of TR elements
  16476. $dom[$key]['thead'] = ''; // table header rows
  16477. }
  16478. if (($dom[$key]['value'] == 'tr')) {
  16479. $dom[$key]['cols'] = 0;
  16480. if ($thead) {
  16481. $dom[$key]['thead'] = true;
  16482. // rows on thead block are printed as a separate table
  16483. } else {
  16484. $dom[$key]['thead'] = false;
  16485. $parent = $dom[$key]['parent'];
  16486. if (!isset($dom[$parent]['rows'])) {
  16487. $dom[$parent]['rows'] = 0;
  16488. }
  16489. // store the number of rows on table element
  16490. ++$dom[$parent]['rows'];
  16491. if (!isset($dom[$parent]['trids'])) {
  16492. $dom[$parent]['trids'] = array();
  16493. }
  16494. // store the TR elements IDs on table element
  16495. array_push($dom[$parent]['trids'], $key);
  16496. }
  16497. }
  16498. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  16499. if (isset($dom[$key]['attribute']['colspan'])) {
  16500. $colspan = intval($dom[$key]['attribute']['colspan']);
  16501. } else {
  16502. $colspan = 1;
  16503. }
  16504. $dom[$key]['attribute']['colspan'] = $colspan;
  16505. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  16506. }
  16507. // text direction
  16508. if (isset($dom[$key]['attribute']['dir'])) {
  16509. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  16510. }
  16511. // set foreground color attribute
  16512. if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) {
  16513. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors);
  16514. } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  16515. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16516. }
  16517. // set background color attribute
  16518. if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) {
  16519. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors);
  16520. }
  16521. // set stroke color attribute
  16522. if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) {
  16523. $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors);
  16524. }
  16525. // check for width attribute
  16526. if (isset($dom[$key]['attribute']['width'])) {
  16527. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  16528. }
  16529. // check for height attribute
  16530. if (isset($dom[$key]['attribute']['height'])) {
  16531. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  16532. }
  16533. // check for text alignment
  16534. if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  16535. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align'][0]);
  16536. }
  16537. // check for text rendering mode (the following attributes do not exist in HTML)
  16538. if (isset($dom[$key]['attribute']['stroke'])) {
  16539. // font stroke width
  16540. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  16541. }
  16542. if (isset($dom[$key]['attribute']['fill'])) {
  16543. // font fill
  16544. if ($dom[$key]['attribute']['fill'] == 'true') {
  16545. $dom[$key]['fill'] = true;
  16546. } else {
  16547. $dom[$key]['fill'] = false;
  16548. }
  16549. }
  16550. if (isset($dom[$key]['attribute']['clip'])) {
  16551. // clipping mode
  16552. if ($dom[$key]['attribute']['clip'] == 'true') {
  16553. $dom[$key]['clip'] = true;
  16554. } else {
  16555. $dom[$key]['clip'] = false;
  16556. }
  16557. }
  16558. } // end opening tag
  16559. } else {
  16560. // text
  16561. $dom[$key]['tag'] = false;
  16562. $dom[$key]['block'] = false;
  16563. $dom[$key]['parent'] = end($level);
  16564. $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  16565. if (!empty($dom[$dom[$key]['parent']]['text-transform'])) {
  16566. // text-transform for unicode requires mb_convert_case (Multibyte String Functions)
  16567. if (function_exists('mb_convert_case')) {
  16568. $ttm = array('capitalize' => MB_CASE_TITLE, 'uppercase' => MB_CASE_UPPER, 'lowercase' => MB_CASE_LOWER);
  16569. if (isset($ttm[$dom[$dom[$key]['parent']]['text-transform']])) {
  16570. $element = mb_convert_case($element, $ttm[$dom[$dom[$key]['parent']]['text-transform']], $this->encoding);
  16571. }
  16572. } elseif (!$this->isunicode) {
  16573. switch ($dom[$dom[$key]['parent']]['text-transform']) {
  16574. case 'capitalize': {
  16575. $element = ucwords(strtolower($element));
  16576. break;
  16577. }
  16578. case 'uppercase': {
  16579. $element = strtoupper($element);
  16580. break;
  16581. }
  16582. case 'lowercase': {
  16583. $element = strtolower($element);
  16584. break;
  16585. }
  16586. }
  16587. }
  16588. $element = preg_replace("/&NBSP;/i", "&nbsp;", $element);
  16589. }
  16590. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  16591. }
  16592. ++$elkey;
  16593. ++$key;
  16594. }
  16595. return $dom;
  16596. }
  16597. /**
  16598. * Returns the string used to find spaces
  16599. * @return string
  16600. * @protected
  16601. * @author Nicola Asuni
  16602. * @since 4.8.024 (2010-01-15)
  16603. */
  16604. protected function getSpaceString() {
  16605. $spacestr = chr(32);
  16606. if ($this->isUnicodeFont()) {
  16607. $spacestr = chr(0).chr(32);
  16608. }
  16609. return $spacestr;
  16610. }
  16611. /**
  16612. * Calculates the hash value of the given data.
  16613. *
  16614. * @param string $data The data to be hashed.
  16615. * @return string The hashed value of the data.
  16616. */
  16617. protected function hashTCPDFtag($data) {
  16618. return hash_hmac('sha256', $data, $this->hash_key, false);
  16619. }
  16620. /**
  16621. * Serialize data to be used with TCPDF tag in HTML code.
  16622. * @param string $method TCPDF method name
  16623. * @param array $params Method parameters
  16624. * @return string Serialized data
  16625. * @public static
  16626. */
  16627. public function serializeTCPDFtag($method, $params=array()) {
  16628. $data = array('m' => $method, 'p' => $params);
  16629. $encoded = urlencode(json_encode($data));
  16630. $hash = $this->hashTCPDFtag($encoded);
  16631. return strlen($hash).'+'.$hash.'+'.$encoded;
  16632. }
  16633. /**
  16634. * Unserialize data to be used with TCPDF tag in HTML code.
  16635. * @param string $data serialized data
  16636. * @return array containing unserialized data
  16637. * @protected static
  16638. */
  16639. protected function unserializeTCPDFtag($data) {
  16640. $hpos = strpos($data, '+');
  16641. $hlen = intval(substr($data, 0, $hpos));
  16642. $hash = substr($data, $hpos + 1, $hlen);
  16643. $encoded = substr($data, $hpos + 2 + $hlen);
  16644. if ($hash != $this->hashTCPDFtag($encoded)) {
  16645. $this->Error('Invalid parameters');
  16646. }
  16647. return json_decode(urldecode($encoded), true);
  16648. }
  16649. /**
  16650. * Check if a TCPDF tag is allowed
  16651. * @param string $method TCPDF method name
  16652. * @return boolean
  16653. * @protected
  16654. */
  16655. protected function allowedTCPDFtag($method) {
  16656. if (defined('K_ALLOWED_TCPDF_TAGS')) {
  16657. return (strpos(K_ALLOWED_TCPDF_TAGS, '|'.$method.'|') !== false);
  16658. }
  16659. return false;
  16660. }
  16661. /**
  16662. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  16663. * 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 />
  16664. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  16665. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16666. * 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
  16667. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16668. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  16669. * @param float $h Cell minimum height. The cell extends automatically if needed.
  16670. * @param float|null $x upper-left corner X coordinate
  16671. * @param float|null $y upper-left corner Y coordinate
  16672. * @param string $html html text to print. Default value: empty string.
  16673. * @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)))
  16674. * @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> Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  16675. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  16676. * @param boolean $reseth if true reset the last cell height (default true).
  16677. * @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>
  16678. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  16679. * @see Multicell(), writeHTML()
  16680. * @public
  16681. */
  16682. public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
  16683. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
  16684. }
  16685. /**
  16686. * Allows to preserve some HTML formatting (limited support).<br />
  16687. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16688. * 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
  16689. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16690. * @param string $html text to display
  16691. * @param boolean $ln if true add a new line after text (default = true)
  16692. * @param boolean $fill Indicates if the background must be painted (true) or transparent (false).
  16693. * @param boolean $reseth if true reset the last cell height (default false).
  16694. * @param boolean $cell if true add the current left (or right for RTL) padding to each Write (default false).
  16695. * @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>
  16696. * @public
  16697. */
  16698. public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
  16699. $gvars = $this->getGraphicVars();
  16700. // store current values
  16701. $prev_cell_margin = $this->cell_margin;
  16702. $prev_cell_padding = $this->cell_padding;
  16703. $prevPage = $this->page;
  16704. $prevlMargin = $this->lMargin;
  16705. $prevrMargin = $this->rMargin;
  16706. $curfontname = $this->FontFamily;
  16707. $curfontstyle = $this->FontStyle;
  16708. $curfontsize = $this->FontSizePt;
  16709. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  16710. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  16711. $curfontstretcing = $this->font_stretching;
  16712. $curfonttracking = $this->font_spacing;
  16713. $this->newline = true;
  16714. $newline = true;
  16715. $startlinepage = $this->page;
  16716. $minstartliney = $this->y;
  16717. $maxbottomliney = 0;
  16718. $startlinex = $this->x;
  16719. $startliney = $this->y;
  16720. $yshift = 0;
  16721. $loop = 0;
  16722. $curpos = 0;
  16723. $this_method_vars = array();
  16724. $undo = false;
  16725. $fontaligned = false;
  16726. $reverse_dir = false; // true when the text direction is reversed
  16727. $this->premode = false;
  16728. if ($this->inxobj) {
  16729. // we are inside an XObject template
  16730. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  16731. } elseif (isset($this->PageAnnots[$this->page])) {
  16732. $pask = count($this->PageAnnots[$this->page]);
  16733. } else {
  16734. $pask = 0;
  16735. }
  16736. if ($this->inxobj) {
  16737. // we are inside an XObject template
  16738. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  16739. } elseif (!$this->InFooter) {
  16740. if (isset($this->footerlen[$this->page])) {
  16741. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  16742. } else {
  16743. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  16744. }
  16745. $startlinepos = $this->footerpos[$this->page];
  16746. } else {
  16747. // we are inside the footer
  16748. $startlinepos = $this->pagelen[$this->page];
  16749. }
  16750. $lalign = $align;
  16751. $plalign = $align;
  16752. if ($this->rtl) {
  16753. $w = $this->x - $this->lMargin;
  16754. } else {
  16755. $w = $this->w - $this->rMargin - $this->x;
  16756. }
  16757. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  16758. if ($cell) {
  16759. if ($this->rtl) {
  16760. $this->x -= $this->cell_padding['R'];
  16761. $this->lMargin += $this->cell_padding['L'];
  16762. } else {
  16763. $this->x += $this->cell_padding['L'];
  16764. $this->rMargin += $this->cell_padding['R'];
  16765. }
  16766. }
  16767. if ($this->customlistindent >= 0) {
  16768. $this->listindent = $this->customlistindent;
  16769. } else {
  16770. $this->listindent = $this->GetStringWidth('000000');
  16771. }
  16772. $this->listindentlevel = 0;
  16773. // save previous states
  16774. $prev_cell_height_ratio = $this->cell_height_ratio;
  16775. $prev_listnum = $this->listnum;
  16776. $prev_listordered = $this->listordered;
  16777. $prev_listcount = $this->listcount;
  16778. $prev_lispacer = $this->lispacer;
  16779. $this->listnum = 0;
  16780. $this->listordered = array();
  16781. $this->listcount = array();
  16782. $this->lispacer = '';
  16783. if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) {
  16784. // reset row height
  16785. $this->resetLastH();
  16786. }
  16787. $dom = $this->getHtmlDomArray($html);
  16788. $maxel = count($dom);
  16789. $key = 0;
  16790. while ($key < $maxel) {
  16791. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
  16792. // store the node key
  16793. $hidden_node_key = $key;
  16794. if ($dom[$key]['self']) {
  16795. // skip just this self-closing tag
  16796. ++$key;
  16797. } else {
  16798. // skip this and all children tags
  16799. while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
  16800. // skip hidden objects
  16801. ++$key;
  16802. }
  16803. ++$key;
  16804. }
  16805. }
  16806. if ($key == $maxel) break;
  16807. if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  16808. // check for pagebreak
  16809. if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  16810. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16811. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16812. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16813. }
  16814. if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  16815. OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  16816. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16817. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16818. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16819. }
  16820. }
  16821. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  16822. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  16823. $dom[$key]['attribute']['nobr'] = false;
  16824. } else {
  16825. // store current object
  16826. $this->startTransaction();
  16827. // save this method vars
  16828. $this_method_vars['html'] = $html;
  16829. $this_method_vars['ln'] = $ln;
  16830. $this_method_vars['fill'] = $fill;
  16831. $this_method_vars['reseth'] = $reseth;
  16832. $this_method_vars['cell'] = $cell;
  16833. $this_method_vars['align'] = $align;
  16834. $this_method_vars['gvars'] = $gvars;
  16835. $this_method_vars['prevPage'] = $prevPage;
  16836. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  16837. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  16838. $this_method_vars['prevlMargin'] = $prevlMargin;
  16839. $this_method_vars['prevrMargin'] = $prevrMargin;
  16840. $this_method_vars['curfontname'] = $curfontname;
  16841. $this_method_vars['curfontstyle'] = $curfontstyle;
  16842. $this_method_vars['curfontsize'] = $curfontsize;
  16843. $this_method_vars['curfontascent'] = $curfontascent;
  16844. $this_method_vars['curfontdescent'] = $curfontdescent;
  16845. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  16846. $this_method_vars['curfonttracking'] = $curfonttracking;
  16847. $this_method_vars['minstartliney'] = $minstartliney;
  16848. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  16849. $this_method_vars['yshift'] = $yshift;
  16850. $this_method_vars['startlinepage'] = $startlinepage;
  16851. $this_method_vars['startlinepos'] = $startlinepos;
  16852. $this_method_vars['startlinex'] = $startlinex;
  16853. $this_method_vars['startliney'] = $startliney;
  16854. $this_method_vars['newline'] = $newline;
  16855. $this_method_vars['loop'] = $loop;
  16856. $this_method_vars['curpos'] = $curpos;
  16857. $this_method_vars['pask'] = $pask;
  16858. $this_method_vars['lalign'] = $lalign;
  16859. $this_method_vars['plalign'] = $plalign;
  16860. $this_method_vars['w'] = $w;
  16861. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  16862. $this_method_vars['prev_listnum'] = $prev_listnum;
  16863. $this_method_vars['prev_listordered'] = $prev_listordered;
  16864. $this_method_vars['prev_listcount'] = $prev_listcount;
  16865. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  16866. $this_method_vars['fontaligned'] = $fontaligned;
  16867. $this_method_vars['key'] = $key;
  16868. $this_method_vars['dom'] = $dom;
  16869. }
  16870. }
  16871. // print THEAD block
  16872. if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  16873. if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) {
  16874. $this->inthead = true;
  16875. // print table header (thead)
  16876. $this->writeHTML($this->thead, false, false, false, false, '');
  16877. // check if we are on a new page or on a new column
  16878. if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
  16879. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  16880. // restore previous object
  16881. $this->rollbackTransaction(true);
  16882. // restore previous values
  16883. foreach ($this_method_vars as $vkey => $vval) {
  16884. $$vkey = $vval;
  16885. }
  16886. // disable table header
  16887. $tmp_thead = $this->thead;
  16888. $this->thead = '';
  16889. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16890. $pre_y = $this->y;
  16891. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  16892. // fix for multicolumn mode
  16893. $startliney = $this->y;
  16894. }
  16895. $this->start_transaction_page = $this->page;
  16896. $this->start_transaction_y = $this->y;
  16897. // restore table header
  16898. $this->thead = $tmp_thead;
  16899. // fix table border properties
  16900. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  16901. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  16902. } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  16903. $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
  16904. } else {
  16905. $tmp_cellspacing = 0;
  16906. }
  16907. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  16908. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  16909. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  16910. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  16911. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  16912. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  16913. // print table header (thead)
  16914. $this->writeHTML($this->thead, false, false, false, false, '');
  16915. }
  16916. }
  16917. // move $key index forward to skip THEAD block
  16918. while ( ($key < $maxel) AND (!(
  16919. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  16920. OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  16921. ++$key;
  16922. }
  16923. }
  16924. if ($dom[$key]['tag'] OR ($key == 0)) {
  16925. if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  16926. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  16927. }
  16928. // vertically align image in line
  16929. if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  16930. // get image height
  16931. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], ($dom[$key]['fontsize'] / $this->k), 'px');
  16932. $autolinebreak = false;
  16933. if (!empty($dom[$key]['width'])) {
  16934. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], ($dom[$key]['fontsize'] / $this->k), 'px', false);
  16935. if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
  16936. AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
  16937. OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
  16938. // add automatic line break
  16939. $autolinebreak = true;
  16940. $this->Ln('', $cell);
  16941. if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  16942. // go back to evaluate this line break
  16943. --$key;
  16944. }
  16945. }
  16946. }
  16947. if (!$autolinebreak) {
  16948. if ($this->inPageBody()) {
  16949. $pre_y = $this->y;
  16950. // check for page break
  16951. if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
  16952. // fix for multicolumn mode
  16953. $startliney = $this->y;
  16954. }
  16955. }
  16956. if ($this->page > $startlinepage) {
  16957. // fix line splitted over two pages
  16958. if (isset($this->footerlen[$startlinepage])) {
  16959. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16960. }
  16961. // line to be moved one page forward
  16962. $pagebuff = $this->getPageBuffer($startlinepage);
  16963. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16964. $tstart = substr($pagebuff, 0, $startlinepos);
  16965. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16966. // remove line from previous page
  16967. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16968. $pagebuff = $this->getPageBuffer($this->page);
  16969. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16970. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16971. // add line start to current page
  16972. $yshift = ($minstartliney - $this->y);
  16973. if ($fontaligned) {
  16974. $yshift += ($curfontsize / $this->k);
  16975. }
  16976. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16977. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16978. // shift the annotations and links
  16979. if (isset($this->PageAnnots[$this->page])) {
  16980. $next_pask = count($this->PageAnnots[$this->page]);
  16981. } else {
  16982. $next_pask = 0;
  16983. }
  16984. if (isset($this->PageAnnots[$startlinepage])) {
  16985. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16986. if ($pak >= $pask) {
  16987. $this->PageAnnots[$this->page][] = $pac;
  16988. unset($this->PageAnnots[$startlinepage][$pak]);
  16989. $npak = count($this->PageAnnots[$this->page]) - 1;
  16990. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16991. }
  16992. }
  16993. }
  16994. $pask = $next_pask;
  16995. $startlinepos = $this->cntmrk[$this->page];
  16996. $startlinepage = $this->page;
  16997. $startliney = $this->y;
  16998. $this->newline = false;
  16999. }
  17000. $this->y += ($this->getCellHeight($curfontsize / $this->k) - ($curfontdescent * $this->cell_height_ratio) - $imgh);
  17001. $minstartliney = min($this->y, $minstartliney);
  17002. $maxbottomliney = ($startliney + $this->getCellHeight($curfontsize / $this->k));
  17003. }
  17004. } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  17005. // account for different font size
  17006. $pfontname = $curfontname;
  17007. $pfontstyle = $curfontstyle;
  17008. $pfontsize = $curfontsize;
  17009. $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname);
  17010. $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle);
  17011. $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize);
  17012. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  17013. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  17014. if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  17015. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  17016. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  17017. if (($key < ($maxel - 1)) AND (
  17018. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
  17019. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  17020. OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize)
  17021. AND ($fontsize >= 0) AND ($curfontsize >= 0)
  17022. AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname)))
  17023. )) {
  17024. if ($this->page > $startlinepage) {
  17025. // fix lines splitted over two pages
  17026. if (isset($this->footerlen[$startlinepage])) {
  17027. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17028. }
  17029. // line to be moved one page forward
  17030. $pagebuff = $this->getPageBuffer($startlinepage);
  17031. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  17032. $tstart = substr($pagebuff, 0, $startlinepos);
  17033. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  17034. // remove line start from previous page
  17035. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  17036. $pagebuff = $this->getPageBuffer($this->page);
  17037. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  17038. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  17039. // add line start to current page
  17040. $yshift = ($minstartliney - $this->y);
  17041. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  17042. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  17043. // shift the annotations and links
  17044. if (isset($this->PageAnnots[$this->page])) {
  17045. $next_pask = count($this->PageAnnots[$this->page]);
  17046. } else {
  17047. $next_pask = 0;
  17048. }
  17049. if (isset($this->PageAnnots[$startlinepage])) {
  17050. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  17051. if ($pak >= $pask) {
  17052. $this->PageAnnots[$this->page][] = $pac;
  17053. unset($this->PageAnnots[$startlinepage][$pak]);
  17054. $npak = count($this->PageAnnots[$this->page]) - 1;
  17055. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  17056. }
  17057. }
  17058. }
  17059. $pask = $next_pask;
  17060. $startlinepos = $this->cntmrk[$this->page];
  17061. $startlinepage = $this->page;
  17062. $startliney = $this->y;
  17063. }
  17064. if (!isset($dom[$key]['line-height'])) {
  17065. $dom[$key]['line-height'] = $this->cell_height_ratio;
  17066. }
  17067. if (!$dom[$key]['block']) {
  17068. 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']))) {
  17069. $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  17070. }
  17071. if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  17072. $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
  17073. 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)))) {
  17074. $minstartliney = min($this->y, $line_align_data[1]);
  17075. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $line_align_data[2]);
  17076. } else {
  17077. $minstartliney = min($this->y, $minstartliney);
  17078. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $maxbottomliney);
  17079. }
  17080. $line_align_data = $current_line_align_data;
  17081. }
  17082. }
  17083. $this->cell_height_ratio = $dom[$key]['line-height'];
  17084. $fontaligned = true;
  17085. }
  17086. $this->setFont($fontname, $fontstyle, $fontsize);
  17087. // reset row height
  17088. $this->resetLastH();
  17089. $curfontname = $fontname;
  17090. $curfontstyle = $fontstyle;
  17091. $curfontsize = $fontsize;
  17092. $curfontascent = $fontascent;
  17093. $curfontdescent = $fontdescent;
  17094. }
  17095. }
  17096. // set text rendering mode
  17097. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  17098. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  17099. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  17100. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  17101. if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  17102. $this->setFontStretching($dom[$key]['font-stretch']);
  17103. }
  17104. if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  17105. $this->setFontSpacing($dom[$key]['letter-spacing']);
  17106. }
  17107. if (($plalign == 'J') AND $dom[$key]['block']) {
  17108. $plalign = '';
  17109. }
  17110. // get current position on page buffer
  17111. $curpos = $this->pagelen[$startlinepage];
  17112. if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  17113. $this->setFillColorArray($dom[$key]['bgcolor']);
  17114. $wfill = true;
  17115. } else {
  17116. $wfill = $fill | false;
  17117. }
  17118. if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  17119. $this->setTextColorArray($dom[$key]['fgcolor']);
  17120. }
  17121. if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  17122. $this->setDrawColorArray($dom[$key]['strokecolor']);
  17123. }
  17124. if (isset($dom[$key]['align'])) {
  17125. $lalign = $dom[$key]['align'];
  17126. }
  17127. if (TCPDF_STATIC::empty_string($lalign)) {
  17128. $lalign = $align;
  17129. }
  17130. }
  17131. // align lines
  17132. if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  17133. $newline = true;
  17134. $fontaligned = false;
  17135. // we are at the beginning of a new line
  17136. if (isset($startlinex)) {
  17137. $yshift = ($minstartliney - $startliney);
  17138. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  17139. $yshift = 0;
  17140. }
  17141. $t_x = 0;
  17142. // the last line must be shifted to be aligned as requested
  17143. $linew = abs($this->endlinex - $startlinex);
  17144. if ($this->inxobj) {
  17145. // we are inside an XObject template
  17146. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  17147. if (isset($opentagpos)) {
  17148. $midpos = $opentagpos;
  17149. } else {
  17150. $midpos = 0;
  17151. }
  17152. if ($midpos > 0) {
  17153. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  17154. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  17155. } else {
  17156. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  17157. $pend = '';
  17158. }
  17159. } else {
  17160. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  17161. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17162. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17163. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  17164. } elseif (isset($opentagpos)) {
  17165. $midpos = $opentagpos;
  17166. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17167. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17168. $midpos = $this->footerpos[$startlinepage];
  17169. } else {
  17170. $midpos = 0;
  17171. }
  17172. if ($midpos > 0) {
  17173. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  17174. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  17175. } else {
  17176. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  17177. $pend = '';
  17178. }
  17179. }
  17180. if ((((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  17181. // calculate shifting amount
  17182. $tw = $w;
  17183. if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
  17184. $tw += $this->cell_padding['R'];
  17185. }
  17186. if ($this->lMargin != $prevlMargin) {
  17187. $tw += ($prevlMargin - $this->lMargin);
  17188. }
  17189. if ($this->rMargin != $prevrMargin) {
  17190. $tw += ($prevrMargin - $this->rMargin);
  17191. }
  17192. $one_space_width = $this->GetStringWidth(chr(32));
  17193. $no = 0; // number of spaces on a line contained on a single block
  17194. if ($this->isRTLTextDir()) { // RTL
  17195. // remove left space if exist
  17196. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  17197. if ($pos1 > 0) {
  17198. $pos1 = intval($pos1);
  17199. if ($this->isUnicodeFont()) {
  17200. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  17201. $spacelen = 2;
  17202. } else {
  17203. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  17204. $spacelen = 1;
  17205. }
  17206. if ($pos1 == $pos2) {
  17207. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  17208. if (substr($pmid, $pos1, 4) == '[()]') {
  17209. $linew -= $one_space_width;
  17210. } elseif ($pos1 == strpos($pmid, '[(')) {
  17211. $no = 1;
  17212. }
  17213. }
  17214. }
  17215. } else { // LTR
  17216. // remove right space if exist
  17217. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  17218. if ($pos1 > 0) {
  17219. $pos1 = intval($pos1);
  17220. if ($this->isUnicodeFont()) {
  17221. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  17222. $spacelen = 2;
  17223. } else {
  17224. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  17225. $spacelen = 1;
  17226. }
  17227. if ($pos1 == $pos2) {
  17228. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  17229. $linew -= $one_space_width;
  17230. }
  17231. }
  17232. }
  17233. $mdiff = ($tw - $linew);
  17234. if ($plalign == 'C') {
  17235. if ($this->rtl) {
  17236. $t_x = -($mdiff / 2);
  17237. } else {
  17238. $t_x = ($mdiff / 2);
  17239. }
  17240. } elseif ($plalign == 'R') {
  17241. // right alignment on LTR document
  17242. $t_x = $mdiff;
  17243. } elseif ($plalign == 'L') {
  17244. // left alignment on RTL document
  17245. $t_x = -$mdiff;
  17246. } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  17247. // Justification
  17248. if ($this->isRTLTextDir()) {
  17249. // align text on the left
  17250. $t_x = -$mdiff;
  17251. }
  17252. $ns = 0; // number of spaces
  17253. $pmidtemp = $pmid;
  17254. // escape special characters
  17255. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  17256. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  17257. // search spaces
  17258. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
  17259. $spacestr = $this->getSpaceString();
  17260. $maxkk = count($lnstring[1]) - 1;
  17261. for ($kk=0; $kk <= $maxkk; ++$kk) {
  17262. // restore special characters
  17263. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  17264. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  17265. // store number of spaces on the strings
  17266. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  17267. // count total spaces on line
  17268. $ns += $lnstring[2][$kk];
  17269. $lnstring[3][$kk] = $ns;
  17270. }
  17271. if ($ns == 0) {
  17272. $ns = 1;
  17273. }
  17274. // calculate additional space to add to each existing space
  17275. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  17276. if ($this->FontSize <= 0) {
  17277. $this->FontSize = 1;
  17278. }
  17279. $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  17280. if ($this->font_spacing != 0) {
  17281. // fixed spacing mode
  17282. $osw = -1000 * $this->font_spacing / $this->FontSize;
  17283. $spacewidthu += $osw;
  17284. }
  17285. $nsmax = $ns;
  17286. $ns = 0;
  17287. reset($lnstring);
  17288. $offset = 0;
  17289. $strcount = 0;
  17290. $prev_epsposbeg = 0;
  17291. $textpos = 0;
  17292. if ($this->isRTLTextDir()) {
  17293. $textpos = $this->wPt;
  17294. }
  17295. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
  17296. // check if we are inside a string section '[( ... )]'
  17297. $stroffset = strpos($pmid, '[(', $offset);
  17298. if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  17299. // set offset to the end of string section
  17300. $offset = strpos($pmid, ')]', $stroffset);
  17301. while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
  17302. $offset = strpos($pmid, ')]', ($offset + 1));
  17303. }
  17304. if ($offset === false) {
  17305. $this->Error('HTML Justification: malformed PDF code.');
  17306. }
  17307. continue;
  17308. }
  17309. if ($this->isRTLTextDir()) {
  17310. $spacew = ($spacewidth * ($nsmax - $ns));
  17311. } else {
  17312. $spacew = ($spacewidth * $ns);
  17313. }
  17314. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  17315. $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset);
  17316. if ($epsposend !== null) {
  17317. $epsposend += strlen($this->epsmarker.'Q');
  17318. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
  17319. if ($epsposbeg === null) {
  17320. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
  17321. $prev_epsposbeg = $epsposbeg;
  17322. }
  17323. if (($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) {
  17324. // shift EPS images
  17325. $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
  17326. $pmid_b = substr($pmid, 0, $epsposbeg);
  17327. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  17328. $pmid_e = substr($pmid, $epsposend);
  17329. $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  17330. $offset = $epsposend;
  17331. continue;
  17332. }
  17333. }
  17334. $currentxpos = 0;
  17335. // shift blocks of code
  17336. switch ($strpiece[2][0]) {
  17337. case 'Td':
  17338. case 'cm':
  17339. case 'm':
  17340. case 'l': {
  17341. // get current X position
  17342. preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
  17343. if (!isset($xmatches[1])) {
  17344. break;
  17345. }
  17346. $currentxpos = $xmatches[1];
  17347. $textpos = $currentxpos;
  17348. if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  17349. $ns = $lnstring[3][$strcount];
  17350. if ($this->isRTLTextDir()) {
  17351. $spacew = ($spacewidth * ($nsmax - $ns));
  17352. }
  17353. ++$strcount;
  17354. }
  17355. // justify block
  17356. if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $pmatch) == 1) {
  17357. $newpmid = sprintf('%F',(floatval($pmatch[1]) + $spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4];
  17358. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17359. unset($pmatch, $newpmid);
  17360. }
  17361. break;
  17362. }
  17363. case 're': {
  17364. // justify block
  17365. if (!TCPDF_STATIC::empty_string($this->lispacer)) {
  17366. $this->lispacer = '';
  17367. break;
  17368. }
  17369. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
  17370. if (!isset($xmatches[1])) {
  17371. break;
  17372. }
  17373. $currentxpos = $xmatches[1];
  17374. $x_diff = 0;
  17375. $w_diff = 0;
  17376. if ($this->isRTLTextDir()) { // RTL
  17377. if ($currentxpos < $textpos) {
  17378. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  17379. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17380. } else {
  17381. if ($strcount > 0) {
  17382. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  17383. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17384. }
  17385. }
  17386. } else { // LTR
  17387. if ($currentxpos > $textpos) {
  17388. if ($strcount > 0) {
  17389. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  17390. }
  17391. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17392. } else {
  17393. if ($strcount > 1) {
  17394. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  17395. }
  17396. if ($strcount > 0) {
  17397. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17398. }
  17399. }
  17400. }
  17401. if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $pmatch) == 1) {
  17402. $newx = sprintf('%F',(floatval($pmatch[1]) + $x_diff));
  17403. $neww = sprintf('%F',(floatval($pmatch[3]) + $w_diff));
  17404. $newpmid = $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6];
  17405. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17406. unset($pmatch, $newpmid, $newx, $neww);
  17407. }
  17408. break;
  17409. }
  17410. case 'c': {
  17411. // get current X position
  17412. 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);
  17413. if (!isset($xmatches[1])) {
  17414. break;
  17415. }
  17416. $currentxpos = $xmatches[1];
  17417. // justify block
  17418. 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) {
  17419. $newx1 = sprintf('%F',(floatval($pmatch[1]) + $spacew));
  17420. $newx2 = sprintf('%F',(floatval($pmatch[3]) + $spacew));
  17421. $newx3 = sprintf('%F',(floatval($pmatch[5]) + $spacew));
  17422. $newpmid = $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8];
  17423. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17424. unset($pmatch, $newpmid, $newx1, $newx2, $newx3);
  17425. }
  17426. break;
  17427. }
  17428. }
  17429. // shift the annotations and links
  17430. $cxpos = ($currentxpos / $this->k);
  17431. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  17432. if ($this->inxobj) {
  17433. // we are inside an XObject template
  17434. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17435. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17436. if ($cxpos > $lmpos) {
  17437. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  17438. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17439. } else {
  17440. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17441. }
  17442. break;
  17443. }
  17444. }
  17445. } elseif (isset($this->PageAnnots[$this->page])) {
  17446. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17447. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17448. if ($cxpos > $lmpos) {
  17449. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  17450. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17451. } else {
  17452. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17453. }
  17454. break;
  17455. }
  17456. }
  17457. }
  17458. } // end of while
  17459. // remove markers
  17460. $pmid = str_replace('x*#!#*x', '', $pmid);
  17461. if ($this->isUnicodeFont()) {
  17462. // multibyte characters
  17463. $spacew = $spacewidthu;
  17464. if ($this->font_stretching != 100) {
  17465. // word spacing is affected by stretching
  17466. $spacew /= ($this->font_stretching / 100);
  17467. }
  17468. // escape special characters
  17469. $pos = 0;
  17470. $pmid = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmid);
  17471. $pmid = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmid);
  17472. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmid, $pamatch) > 0) {
  17473. foreach($pamatch[0] as $pk => $pmatch) {
  17474. $replace = $pamatch[1][$pk];
  17475. $replace = str_replace('#!#OP#!#', '(', $replace);
  17476. $replace = str_replace('#!#CP#!#', ')', $replace);
  17477. $newpmid = '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacew).' (', $replace).')]';
  17478. $pos = strpos($pmid, $pmatch, $pos);
  17479. if ($pos !== FALSE) {
  17480. $pmid = substr_replace($pmid, $newpmid, $pos, strlen($pmatch));
  17481. }
  17482. ++$pos;
  17483. }
  17484. unset($pamatch);
  17485. }
  17486. if ($this->inxobj) {
  17487. // we are inside an XObject template
  17488. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  17489. } else {
  17490. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
  17491. }
  17492. $endlinepos = strlen($pstart."\n".$pmid."\n");
  17493. } else {
  17494. // non-unicode (single-byte characters)
  17495. if ($this->font_stretching != 100) {
  17496. // word spacing (Tw) is affected by stretching
  17497. $spacewidth /= ($this->font_stretching / 100);
  17498. }
  17499. $rs = sprintf('%F Tw', $spacewidth);
  17500. $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
  17501. if ($this->inxobj) {
  17502. // we are inside an XObject template
  17503. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  17504. } else {
  17505. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  17506. }
  17507. $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  17508. }
  17509. }
  17510. } // end of J
  17511. } // end if $startlinex
  17512. if (($t_x != 0) OR ($yshift < 0)) {
  17513. // shift the line
  17514. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  17515. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17516. $endlinepos = strlen($pstart);
  17517. if ($this->inxobj) {
  17518. // we are inside an XObject template
  17519. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17520. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17521. if ($pak >= $pask) {
  17522. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17523. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17524. }
  17525. }
  17526. } else {
  17527. $this->setPageBuffer($startlinepage, $pstart.$pend);
  17528. // shift the annotations and links
  17529. if (isset($this->PageAnnots[$this->page])) {
  17530. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17531. if ($pak >= $pask) {
  17532. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17533. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17534. }
  17535. }
  17536. }
  17537. }
  17538. $this->y -= $yshift;
  17539. }
  17540. }
  17541. $pbrk = $this->checkPageBreak($this->lasth);
  17542. $this->newline = false;
  17543. $startlinex = $this->x;
  17544. $startliney = $this->y;
  17545. if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  17546. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  17547. } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  17548. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  17549. } else {
  17550. $minstartliney = $startliney;
  17551. $maxbottomliney = ($this->y + $this->getCellHeight($fontsize / $this->k));
  17552. }
  17553. $startlinepage = $this->page;
  17554. if (isset($endlinepos) AND (!$pbrk)) {
  17555. $startlinepos = $endlinepos;
  17556. } else {
  17557. if ($this->inxobj) {
  17558. // we are inside an XObject template
  17559. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17560. } elseif (!$this->InFooter) {
  17561. if (isset($this->footerlen[$this->page])) {
  17562. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17563. } else {
  17564. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17565. }
  17566. $startlinepos = $this->footerpos[$this->page];
  17567. } else {
  17568. $startlinepos = $this->pagelen[$this->page];
  17569. }
  17570. }
  17571. unset($endlinepos);
  17572. $plalign = $lalign;
  17573. if (isset($this->PageAnnots[$this->page])) {
  17574. $pask = count($this->PageAnnots[$this->page]);
  17575. } else {
  17576. $pask = 0;
  17577. }
  17578. if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  17579. AND (isset($this->emptypagemrk[$this->page]))
  17580. AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  17581. $this->setFont($fontname, $fontstyle, $fontsize);
  17582. if ($wfill) {
  17583. $this->setFillColorArray($this->bgcolor);
  17584. }
  17585. }
  17586. } // end newline
  17587. if (isset($opentagpos)) {
  17588. unset($opentagpos);
  17589. }
  17590. if ($dom[$key]['tag']) {
  17591. if ($dom[$key]['opening']) {
  17592. // get text indentation (if any)
  17593. if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  17594. $this->textindent = $dom[$key]['text-indent'];
  17595. $this->newline = true;
  17596. }
  17597. // table
  17598. if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
  17599. // available page width
  17600. if ($this->rtl) {
  17601. $wtmp = $this->x - $this->lMargin;
  17602. } else {
  17603. $wtmp = $this->w - $this->rMargin - $this->x;
  17604. }
  17605. // get cell spacing
  17606. if (isset($dom[$key]['attribute']['cellspacing'])) {
  17607. $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  17608. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  17609. } elseif (isset($dom[$key]['border-spacing'])) {
  17610. $cellspacing = $dom[$key]['border-spacing'];
  17611. } else {
  17612. $cellspacing = array('H' => 0, 'V' => 0);
  17613. }
  17614. // table width
  17615. if (isset($dom[$key]['width'])) {
  17616. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  17617. } else {
  17618. $table_width = $wtmp;
  17619. }
  17620. $table_width -= (2 * $cellspacing['H']);
  17621. if (!$this->inthead) {
  17622. $this->y += $cellspacing['V'];
  17623. }
  17624. if ($this->rtl) {
  17625. $cellspacingx = -$cellspacing['H'];
  17626. } else {
  17627. $cellspacingx = $cellspacing['H'];
  17628. }
  17629. // total table width without cellspaces
  17630. $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  17631. // minimum column width
  17632. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  17633. // array of custom column widths
  17634. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  17635. }
  17636. // table row
  17637. if ($dom[$key]['value'] == 'tr') {
  17638. // reset column counter
  17639. $colid = 0;
  17640. }
  17641. // table cell
  17642. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  17643. $trid = $dom[$key]['parent'];
  17644. $table_el = $dom[$trid]['parent'];
  17645. if (!isset($dom[$table_el]['cols'])) {
  17646. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  17647. }
  17648. // store border info
  17649. $tdborder = 0;
  17650. if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  17651. $tdborder = $dom[$key]['border'];
  17652. }
  17653. $colspan = intval($dom[$key]['attribute']['colspan']);
  17654. if ($colspan <= 0) {
  17655. $colspan = 1;
  17656. }
  17657. $old_cell_padding = $this->cell_padding;
  17658. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  17659. $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  17660. $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
  17661. } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  17662. $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
  17663. } else {
  17664. $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
  17665. }
  17666. $this->cell_padding = $current_cell_padding;
  17667. if (isset($dom[$key]['height'])) {
  17668. // minimum cell height
  17669. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  17670. } else {
  17671. $cellh = 0;
  17672. }
  17673. if (isset($dom[$key]['content'])) {
  17674. $cell_content = $dom[$key]['content'];
  17675. } else {
  17676. $cell_content = '&nbsp;';
  17677. }
  17678. $tagtype = $dom[$key]['value'];
  17679. $parentid = $key;
  17680. while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  17681. // move $key index forward
  17682. ++$key;
  17683. }
  17684. if (!isset($dom[$trid]['startpage'])) {
  17685. $dom[$trid]['startpage'] = $this->page;
  17686. } else {
  17687. $this->setPage($dom[$trid]['startpage']);
  17688. }
  17689. if (!isset($dom[$trid]['startcolumn'])) {
  17690. $dom[$trid]['startcolumn'] = $this->current_column;
  17691. } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  17692. $tmpx = $this->x;
  17693. $this->selectColumn($dom[$trid]['startcolumn']);
  17694. $this->x = $tmpx;
  17695. }
  17696. if (!isset($dom[$trid]['starty'])) {
  17697. $dom[$trid]['starty'] = $this->y;
  17698. } else {
  17699. $this->y = $dom[$trid]['starty'];
  17700. }
  17701. if (!isset($dom[$trid]['startx'])) {
  17702. $dom[$trid]['startx'] = $this->x;
  17703. $this->x += $cellspacingx;
  17704. } else {
  17705. $this->x += ($cellspacingx / 2);
  17706. }
  17707. if (isset($dom[$parentid]['attribute']['rowspan'])) {
  17708. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  17709. } else {
  17710. $rowspan = 1;
  17711. }
  17712. // skip row-spanned cells started on the previous rows
  17713. if (isset($dom[$table_el]['rowspans'])) {
  17714. $rsk = 0;
  17715. $rskmax = count($dom[$table_el]['rowspans']);
  17716. while ($rsk < $rskmax) {
  17717. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  17718. $rsstartx = $trwsp['startx'];
  17719. $rsendx = $trwsp['endx'];
  17720. // account for margin changes
  17721. if ($trwsp['startpage'] < $this->page) {
  17722. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  17723. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  17724. $rsstartx -= $dl;
  17725. $rsendx -= $dl;
  17726. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  17727. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  17728. $rsstartx += $dl;
  17729. $rsendx += $dl;
  17730. }
  17731. }
  17732. if (($trwsp['rowspan'] > 0)
  17733. AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  17734. AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  17735. AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  17736. // set the starting X position of the current cell
  17737. $this->x = $rsendx + $cellspacingx;
  17738. // increment column indicator
  17739. $colid += $trwsp['colspan'];
  17740. if (($trwsp['rowspan'] == 1)
  17741. AND (isset($dom[$trid]['endy']))
  17742. AND (isset($dom[$trid]['endpage']))
  17743. AND (isset($dom[$trid]['endcolumn']))
  17744. AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  17745. AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17746. // set ending Y position for row
  17747. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17748. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  17749. }
  17750. $rsk = 0;
  17751. } else {
  17752. ++$rsk;
  17753. }
  17754. }
  17755. }
  17756. if (isset($dom[$parentid]['width'])) {
  17757. // user specified width
  17758. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  17759. $tmpcw = ($cellw / $colspan);
  17760. for ($i = 0; $i < $colspan; ++$i) {
  17761. $table_colwidths[($colid + $i)] = $tmpcw;
  17762. }
  17763. } else {
  17764. // inherit column width
  17765. $cellw = 0;
  17766. for ($i = 0; $i < $colspan; ++$i) {
  17767. $cellw += (isset($table_colwidths[($colid + $i)]) ? $table_colwidths[($colid + $i)] : 0);
  17768. }
  17769. }
  17770. $cellw += (($colspan - 1) * $cellspacing['H']);
  17771. // increment column indicator
  17772. $colid += $colspan;
  17773. // add rowspan information to table element
  17774. if ($rowspan > 1) {
  17775. $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));
  17776. }
  17777. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  17778. if ($rowspan > 1) {
  17779. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  17780. }
  17781. // push background colors
  17782. if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  17783. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  17784. }
  17785. // store border info
  17786. if (!empty($tdborder)) {
  17787. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  17788. }
  17789. $prevLastH = $this->lasth;
  17790. // store some info for multicolumn mode
  17791. if ($this->rtl) {
  17792. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  17793. } else {
  17794. $this->colxshift['x'] = $this->x - $this->lMargin;
  17795. }
  17796. $this->colxshift['s'] = $cellspacing;
  17797. $this->colxshift['p'] = $current_cell_padding;
  17798. // ****** write the cell content ******
  17799. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
  17800. // restore some values
  17801. $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  17802. $this->lasth = $prevLastH;
  17803. $this->cell_padding = $old_cell_padding;
  17804. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  17805. // update the end of row position
  17806. if ($rowspan <= 1) {
  17807. if (isset($dom[$trid]['endy'])) {
  17808. if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  17809. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  17810. } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
  17811. $dom[$trid]['endy'] = $this->y;
  17812. }
  17813. } else {
  17814. $dom[$trid]['endy'] = $this->y;
  17815. }
  17816. if (isset($dom[$trid]['endpage'])) {
  17817. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  17818. } else {
  17819. $dom[$trid]['endpage'] = $this->page;
  17820. }
  17821. if (isset($dom[$trid]['endcolumn'])) {
  17822. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  17823. } else {
  17824. $dom[$trid]['endcolumn'] = $this->current_column;
  17825. }
  17826. } else {
  17827. // account for row-spanned cells
  17828. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  17829. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  17830. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  17831. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  17832. }
  17833. if (isset($dom[$table_el]['rowspans'])) {
  17834. // update endy and endpage on rowspanned cells
  17835. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  17836. if ($trwsp['rowspan'] > 0) {
  17837. if (isset($dom[$trid]['endpage'])) {
  17838. if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17839. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17840. } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  17841. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  17842. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  17843. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  17844. } else {
  17845. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  17846. }
  17847. }
  17848. }
  17849. }
  17850. }
  17851. $this->x += ($cellspacingx / 2);
  17852. } else {
  17853. // opening tag (or self-closing tag)
  17854. if (!isset($opentagpos)) {
  17855. if ($this->inxobj) {
  17856. // we are inside an XObject template
  17857. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17858. } elseif (!$this->InFooter) {
  17859. if (isset($this->footerlen[$this->page])) {
  17860. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17861. } else {
  17862. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17863. }
  17864. $opentagpos = $this->footerpos[$this->page];
  17865. }
  17866. }
  17867. $dom = $this->openHTMLTagHandler($dom, $key, $cell);
  17868. }
  17869. } else { // closing tag
  17870. $prev_numpages = $this->numpages;
  17871. $old_bordermrk = $this->bordermrk[$this->page];
  17872. $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  17873. if ($this->bordermrk[$this->page] > $old_bordermrk) {
  17874. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  17875. }
  17876. if ($prev_numpages > $this->numpages) {
  17877. $startlinepage = $this->page;
  17878. }
  17879. }
  17880. } elseif (strlen($dom[$key]['value']) > 0) {
  17881. // print list-item
  17882. if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  17883. $this->setFont($pfontname, $pfontstyle, $pfontsize);
  17884. $this->resetLastH();
  17885. $minstartliney = $this->y;
  17886. $maxbottomliney = ($startliney + $this->getCellHeight($this->FontSize));
  17887. if (is_numeric($pfontsize) AND ($pfontsize > 0)) {
  17888. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  17889. }
  17890. $this->setFont($curfontname, $curfontstyle, $curfontsize);
  17891. $this->resetLastH();
  17892. if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
  17893. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  17894. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  17895. $this->y += ($this->getCellHeight(($pfontsize - $curfontsize) / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  17896. $minstartliney = min($this->y, $minstartliney);
  17897. $maxbottomliney = max(($this->y + $this->getCellHeight($pfontsize / $this->k)), $maxbottomliney);
  17898. }
  17899. }
  17900. // text
  17901. $this->htmlvspace = 0;
  17902. $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']);
  17903. if ((!$this->premode) AND $this->isRTLTextDir() AND !$isRTLString) {
  17904. // reverse spaces order
  17905. $lsp = ''; // left spaces
  17906. $rsp = ''; // right spaces
  17907. if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17908. $lsp = $matches[1];
  17909. }
  17910. if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17911. $rsp = $matches[1];
  17912. }
  17913. $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  17914. }
  17915. if ($newline) {
  17916. if (!$this->premode) {
  17917. $prelen = strlen($dom[$key]['value']);
  17918. if ($this->isRTLTextDir() AND !$isRTLString) {
  17919. // right trim except non-breaking space
  17920. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  17921. } else {
  17922. // left trim except non-breaking space
  17923. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  17924. }
  17925. $postlen = strlen($dom[$key]['value']);
  17926. if (($postlen == 0) AND ($prelen > 0)) {
  17927. $dom[$key]['trimmed_space'] = true;
  17928. }
  17929. }
  17930. $newline = false;
  17931. $firstblock = true;
  17932. } else {
  17933. $firstblock = false;
  17934. // replace empty multiple spaces string with a single space
  17935. $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  17936. }
  17937. $strrest = '';
  17938. if ($this->rtl) {
  17939. $this->x -= $this->textindent;
  17940. } else {
  17941. $this->x += $this->textindent;
  17942. }
  17943. if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  17944. $strlinelen = $this->GetStringWidth($dom[$key]['value']);
  17945. if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  17946. // HTML <a> Link
  17947. $hrefcolor = '';
  17948. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  17949. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  17950. }
  17951. $hrefstyle = -1;
  17952. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  17953. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  17954. }
  17955. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  17956. } else {
  17957. $wadj = 0; // space to leave for block continuity
  17958. if ($this->rtl) {
  17959. $cwa = ($this->x - $this->lMargin);
  17960. } else {
  17961. $cwa = ($this->w - $this->rMargin - $this->x);
  17962. }
  17963. if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
  17964. // check the next text blocks for continuity
  17965. $nkey = ($key + 1);
  17966. $write_block = true;
  17967. $same_textdir = true;
  17968. $tmp_fontname = $this->FontFamily;
  17969. $tmp_fontstyle = $this->FontStyle;
  17970. $tmp_fontsize = $this->FontSizePt;
  17971. while ($write_block AND isset($dom[$nkey])) {
  17972. if ($dom[$nkey]['tag']) {
  17973. if ($dom[$nkey]['block']) {
  17974. // end of block
  17975. $write_block = false;
  17976. }
  17977. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  17978. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  17979. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  17980. $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  17981. } else {
  17982. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/', $this->re_space['m'], $dom[$nkey]['value']);
  17983. if (isset($nextstr[0]) AND $same_textdir) {
  17984. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  17985. if (isset($nextstr[1])) {
  17986. $write_block = false;
  17987. }
  17988. }
  17989. }
  17990. ++$nkey;
  17991. }
  17992. }
  17993. if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
  17994. $wadj = 0;
  17995. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $dom[$key]['value']);
  17996. $numblks = count($nextstr);
  17997. if ($numblks > 1) {
  17998. // try to split on blank spaces
  17999. $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
  18000. } else {
  18001. // set the entire block on new line
  18002. $wadj = $this->GetStringWidth($nextstr[0]);
  18003. }
  18004. }
  18005. // check for reversed text direction
  18006. if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  18007. // LTR text on RTL direction or RTL text on LTR direction
  18008. $reverse_dir = true;
  18009. $this->rtl = !$this->rtl;
  18010. $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
  18011. if ($this->rtl) {
  18012. $this->x += $revshift;
  18013. } else {
  18014. $this->x -= $revshift;
  18015. }
  18016. $xws = $this->x;
  18017. }
  18018. // ****** write only until the end of the line and get the rest ******
  18019. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  18020. // restore default direction
  18021. if ($reverse_dir AND ($wadj == 0)) {
  18022. $this->x = $xws; // @phpstan-ignore-line
  18023. $this->rtl = !$this->rtl;
  18024. $reverse_dir = false;
  18025. }
  18026. }
  18027. }
  18028. $this->textindent = 0;
  18029. if (strlen($strrest) > 0) {
  18030. // store the remaining string on the previous $key position
  18031. $this->newline = true;
  18032. if ($strrest == $dom[$key]['value']) {
  18033. // used to avoid infinite loop
  18034. ++$loop;
  18035. } else {
  18036. $loop = 0;
  18037. }
  18038. $dom[$key]['value'] = $strrest;
  18039. if ($cell) {
  18040. if ($this->rtl) {
  18041. $this->x -= $this->cell_padding['R'];
  18042. } else {
  18043. $this->x += $this->cell_padding['L'];
  18044. }
  18045. }
  18046. if ($loop < 3) {
  18047. --$key;
  18048. }
  18049. } else {
  18050. $loop = 0;
  18051. // add the positive font spacing of the last character (if any)
  18052. if ($this->font_spacing > 0) {
  18053. if ($this->rtl) {
  18054. $this->x -= $this->font_spacing;
  18055. } else {
  18056. $this->x += $this->font_spacing;
  18057. }
  18058. }
  18059. }
  18060. }
  18061. ++$key;
  18062. 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')) {
  18063. // check if we are on a new page or on a new column
  18064. if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
  18065. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  18066. // restore previous object
  18067. $this->rollbackTransaction(true);
  18068. // restore previous values
  18069. foreach ($this_method_vars as $vkey => $vval) {
  18070. $$vkey = $vval;
  18071. }
  18072. if (!empty($dom[$key]['thead'])) {
  18073. $this->inthead = true;
  18074. }
  18075. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18076. $pre_y = $this->y;
  18077. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  18078. $startliney = $this->y;
  18079. }
  18080. $undo = true; // avoid infinite loop
  18081. } else {
  18082. $undo = false;
  18083. }
  18084. }
  18085. } // end for each $key
  18086. // align the last line
  18087. if (isset($startlinex)) {
  18088. $yshift = ($minstartliney - $startliney);
  18089. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  18090. $yshift = 0;
  18091. }
  18092. $t_x = 0;
  18093. // the last line must be shifted to be aligned as requested
  18094. $linew = abs($this->endlinex - $startlinex);
  18095. if ($this->inxobj) {
  18096. // we are inside an XObject template
  18097. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  18098. if (isset($opentagpos)) {
  18099. $midpos = $opentagpos;
  18100. } else {
  18101. $midpos = 0;
  18102. }
  18103. if ($midpos > 0) {
  18104. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  18105. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  18106. } else {
  18107. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  18108. $pend = '';
  18109. }
  18110. } else {
  18111. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  18112. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18113. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18114. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  18115. } elseif (isset($opentagpos)) {
  18116. $midpos = $opentagpos;
  18117. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18118. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18119. $midpos = $this->footerpos[$startlinepage];
  18120. } else {
  18121. $midpos = 0;
  18122. }
  18123. if ($midpos > 0) {
  18124. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  18125. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  18126. } else {
  18127. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  18128. $pend = '';
  18129. }
  18130. }
  18131. if ((((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  18132. // calculate shifting amount
  18133. $tw = $w;
  18134. if ($this->lMargin != $prevlMargin) {
  18135. $tw += ($prevlMargin - $this->lMargin);
  18136. }
  18137. if ($this->rMargin != $prevrMargin) {
  18138. $tw += ($prevrMargin - $this->rMargin);
  18139. }
  18140. $one_space_width = $this->GetStringWidth(chr(32));
  18141. $no = 0; // number of spaces on a line contained on a single block
  18142. if ($this->isRTLTextDir()) { // RTL
  18143. // remove left space if exist
  18144. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  18145. if ($pos1 > 0) {
  18146. $pos1 = intval($pos1);
  18147. if ($this->isUnicodeFont()) {
  18148. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  18149. $spacelen = 2;
  18150. } else {
  18151. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  18152. $spacelen = 1;
  18153. }
  18154. if ($pos1 == $pos2) {
  18155. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  18156. if (substr($pmid, $pos1, 4) == '[()]') {
  18157. $linew -= $one_space_width;
  18158. } elseif ($pos1 == strpos($pmid, '[(')) {
  18159. $no = 1;
  18160. }
  18161. }
  18162. }
  18163. } else { // LTR
  18164. // remove right space if exist
  18165. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  18166. if ($pos1 > 0) {
  18167. $pos1 = intval($pos1);
  18168. if ($this->isUnicodeFont()) {
  18169. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  18170. $spacelen = 2;
  18171. } else {
  18172. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  18173. $spacelen = 1;
  18174. }
  18175. if ($pos1 == $pos2) {
  18176. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  18177. $linew -= $one_space_width;
  18178. }
  18179. }
  18180. }
  18181. $mdiff = ($tw - $linew);
  18182. if ($plalign == 'C') {
  18183. if ($this->rtl) {
  18184. $t_x = -($mdiff / 2);
  18185. } else {
  18186. $t_x = ($mdiff / 2);
  18187. }
  18188. } elseif ($plalign == 'R') {
  18189. // right alignment on LTR document
  18190. $t_x = $mdiff;
  18191. } elseif ($plalign == 'L') {
  18192. // left alignment on RTL document
  18193. $t_x = -$mdiff;
  18194. }
  18195. } // end if startlinex
  18196. if (($t_x != 0) OR ($yshift < 0)) {
  18197. // shift the line
  18198. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  18199. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  18200. $endlinepos = strlen($pstart);
  18201. if ($this->inxobj) {
  18202. // we are inside an XObject template
  18203. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  18204. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  18205. if ($pak >= $pask) {
  18206. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  18207. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  18208. }
  18209. }
  18210. } else {
  18211. $this->setPageBuffer($startlinepage, $pstart.$pend);
  18212. // shift the annotations and links
  18213. if (isset($this->PageAnnots[$this->page])) {
  18214. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  18215. if ($pak >= $pask) {
  18216. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  18217. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  18218. }
  18219. }
  18220. }
  18221. }
  18222. $this->y -= $yshift;
  18223. $yshift = 0;
  18224. }
  18225. }
  18226. // restore previous values
  18227. $this->setGraphicVars($gvars);
  18228. if ($this->num_columns > 1) {
  18229. $this->selectColumn();
  18230. } elseif ($this->page > $prevPage) {
  18231. $this->lMargin = $this->pagedim[$this->page]['olm'];
  18232. $this->rMargin = $this->pagedim[$this->page]['orm'];
  18233. }
  18234. // restore previous list state
  18235. $this->cell_height_ratio = $prev_cell_height_ratio;
  18236. $this->listnum = $prev_listnum;
  18237. $this->listordered = $prev_listordered;
  18238. $this->listcount = $prev_listcount;
  18239. $this->lispacer = $prev_lispacer;
  18240. if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  18241. $this->Ln($this->lasth);
  18242. if (($this->y < $maxbottomliney) AND ($startlinepage == $this->page)) {
  18243. $this->y = $maxbottomliney;
  18244. }
  18245. }
  18246. unset($dom);
  18247. }
  18248. /**
  18249. * Process opening tags.
  18250. * @param array $dom html dom array
  18251. * @param int $key current element id
  18252. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  18253. * @return array $dom
  18254. * @protected
  18255. */
  18256. protected function openHTMLTagHandler($dom, $key, $cell) {
  18257. $tag = $dom[$key];
  18258. $parent = $dom[($dom[$key]['parent'])];
  18259. $firsttag = ($key == 1);
  18260. // check for text direction attribute
  18261. if (isset($tag['dir'])) {
  18262. $this->setTempRTL($tag['dir']);
  18263. } else {
  18264. $this->tmprtl = false;
  18265. }
  18266. if ($tag['block']) {
  18267. $hbz = 0; // distance from y to line bottom
  18268. $hb = 0; // vertical space between block tags
  18269. // calculate vertical space for block tags
  18270. if (isset($this->tagvspaces[$tag['value']][0]['h']) && !empty($this->tagvspaces[$tag['value']][0]['h']) && ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  18271. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  18272. } elseif (isset($tag['fontsize'])) {
  18273. $cur_h = $this->getCellHeight($tag['fontsize'] / $this->k);
  18274. } else {
  18275. $cur_h = $this->getCellHeight($this->FontSize);
  18276. }
  18277. if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  18278. $on = $this->tagvspaces[$tag['value']][0]['n'];
  18279. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18280. $on = 0.6;
  18281. } else {
  18282. $on = 1;
  18283. }
  18284. if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br', 'hr')))) {
  18285. $hb = 0;
  18286. } else {
  18287. $hb = ($on * $cur_h);
  18288. }
  18289. if (($this->htmlvspace <= 0) AND ($on > 0)) {
  18290. if (isset($parent['fontsize'])) {
  18291. $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  18292. } else {
  18293. $hbz = $this->getCellHeight($this->FontSize);
  18294. }
  18295. }
  18296. if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
  18297. // fix vertical space after table
  18298. $hbz = 0;
  18299. }
  18300. // closing vertical space
  18301. $hbc = 0;
  18302. if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18303. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18304. } elseif (isset($parent['fontsize'])) {
  18305. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  18306. } else {
  18307. $pre_h = $this->getCellHeight($this->FontSize);
  18308. }
  18309. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18310. $cn = $this->tagvspaces[$tag['value']][1]['n'];
  18311. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18312. $cn = 0.6;
  18313. } else {
  18314. $cn = 1;
  18315. }
  18316. if (isset($this->tagvspaces[$tag['value']][1])) {
  18317. $hbc = ($cn * $pre_h);
  18318. }
  18319. }
  18320. // Opening tag
  18321. switch($tag['value']) {
  18322. case 'table': {
  18323. $cp = 0;
  18324. $cs = 0;
  18325. $dom[$key]['rowspans'] = array();
  18326. if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  18327. $this->htmlvspace = 0;
  18328. // set table header
  18329. if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) {
  18330. // set table header
  18331. $this->thead = $dom[$key]['thead'];
  18332. if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  18333. $this->theadMargins = array();
  18334. $this->theadMargins['cell_padding'] = $this->cell_padding;
  18335. $this->theadMargins['lmargin'] = $this->lMargin;
  18336. $this->theadMargins['rmargin'] = $this->rMargin;
  18337. $this->theadMargins['page'] = $this->page;
  18338. $this->theadMargins['cell'] = $cell;
  18339. $this->theadMargins['gvars'] = $this->getGraphicVars();
  18340. }
  18341. }
  18342. }
  18343. // store current margins and page
  18344. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  18345. if (isset($tag['attribute']['cellpadding'])) {
  18346. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  18347. $this->setCellPadding($pad);
  18348. } elseif (isset($tag['padding'])) {
  18349. $this->cell_padding = $tag['padding'];
  18350. }
  18351. if (isset($tag['attribute']['cellspacing'])) {
  18352. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  18353. } elseif (isset($tag['border-spacing'])) {
  18354. $cs = $tag['border-spacing']['V'];
  18355. }
  18356. $prev_y = $this->y;
  18357. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
  18358. $this->inthead = true;
  18359. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18360. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18361. }
  18362. break;
  18363. }
  18364. case 'tr': {
  18365. // array of columns positions
  18366. $dom[$key]['cellpos'] = array();
  18367. break;
  18368. }
  18369. case 'hr': {
  18370. if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  18371. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  18372. } else {
  18373. $hrHeight = $this->GetLineWidth();
  18374. }
  18375. $this->addHTMLVertSpace($hbz, max($hb, ($hrHeight / 2)), $cell, $firsttag);
  18376. $x = $this->GetX();
  18377. $y = $this->GetY();
  18378. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  18379. if ($cell) {
  18380. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  18381. }
  18382. if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  18383. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  18384. } else {
  18385. $hrWidth = $wtmp;
  18386. }
  18387. $prevlinewidth = $this->GetLineWidth();
  18388. $this->setLineWidth($hrHeight);
  18389. $lineStyle = array();
  18390. if (isset($tag['fgcolor'])) {
  18391. $lineStyle['color'] = $tag['fgcolor'];
  18392. }
  18393. if (isset($tag['fgcolor'])) {
  18394. $lineStyle['color'] = $tag['fgcolor'];
  18395. }
  18396. if (isset($tag['style']['cap'])) {
  18397. $lineStyle['cap'] = $tag['style']['cap'];
  18398. }
  18399. if (isset($tag['style']['join'])) {
  18400. $lineStyle['join'] = $tag['style']['join'];
  18401. }
  18402. if (isset($tag['style']['dash'])) {
  18403. $lineStyle['dash'] = $tag['style']['dash'];
  18404. }
  18405. if (isset($tag['style']['phase'])) {
  18406. $lineStyle['phase'] = $tag['style']['phase'];
  18407. }
  18408. $lineStyle = array_filter($lineStyle);
  18409. $this->Line($x, $y, $x + $hrWidth, $y, $lineStyle);
  18410. $this->setLineWidth($prevlinewidth);
  18411. $this->addHTMLVertSpace(max($hbc, ($hrHeight / 2)), 0, $cell, !isset($dom[($key + 1)]));
  18412. break;
  18413. }
  18414. case 'a': {
  18415. if (array_key_exists('href', $tag['attribute'])) {
  18416. $this->HREF['url'] = $tag['attribute']['href'];
  18417. }
  18418. break;
  18419. }
  18420. case 'img': {
  18421. if (empty($tag['attribute']['src'])) {
  18422. break;
  18423. }
  18424. $imgsrc = $tag['attribute']['src'];
  18425. if ($imgsrc[0] === '@') {
  18426. // data stream
  18427. $imgsrc = '@'.base64_decode(substr($imgsrc, 1));
  18428. $type = '';
  18429. } else if (preg_match('@^data:image/([^;]*);base64,(.*)@', $imgsrc, $reg)) {
  18430. $imgsrc = '@'.base64_decode($reg[2]);
  18431. $type = $reg[1];
  18432. } elseif (strpos($imgsrc, '../') !== false) {
  18433. // accessing parent folders is not allowed
  18434. break;
  18435. } elseif ( $this->allowLocalFiles && substr($imgsrc, 0, 7) === 'file://') {
  18436. // get image type from a local file path
  18437. $imgsrc = substr($imgsrc, 7);
  18438. $type = TCPDF_IMAGES::getImageFileType($imgsrc);
  18439. } else {
  18440. if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  18441. // fix image path
  18442. $findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']);
  18443. if (($findroot === false) OR ($findroot > 1)) {
  18444. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  18445. $imgsrc = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc;
  18446. } else {
  18447. $imgsrc = $_SERVER['DOCUMENT_ROOT'].$imgsrc;
  18448. }
  18449. }
  18450. $imgsrc = urldecode($imgsrc);
  18451. $testscrtype = @parse_url($imgsrc);
  18452. if (empty($testscrtype['query'])) {
  18453. // convert URL to server path
  18454. $imgsrc = str_replace(K_PATH_URL, K_PATH_MAIN, $imgsrc);
  18455. } elseif (preg_match('|^https?://|', $imgsrc) !== 1) {
  18456. // convert URL to server path
  18457. $imgsrc = str_replace(K_PATH_MAIN, K_PATH_URL, $imgsrc);
  18458. }
  18459. }
  18460. // get image type
  18461. $type = TCPDF_IMAGES::getImageFileType($imgsrc);
  18462. }
  18463. if (!isset($tag['width'])) {
  18464. $tag['width'] = 0;
  18465. }
  18466. if (!isset($tag['height'])) {
  18467. $tag['height'] = 0;
  18468. }
  18469. //if (!isset($tag['attribute']['align'])) {
  18470. // the only alignment supported is "bottom"
  18471. // further development is required for other modes.
  18472. $tag['attribute']['align'] = 'bottom';
  18473. //}
  18474. switch($tag['attribute']['align']) {
  18475. case 'top': {
  18476. $align = 'T';
  18477. break;
  18478. }
  18479. case 'middle': {
  18480. $align = 'M';
  18481. break;
  18482. }
  18483. case 'bottom': {
  18484. $align = 'B';
  18485. break;
  18486. }
  18487. default: {
  18488. $align = 'B';
  18489. break;
  18490. }
  18491. }
  18492. $prevy = $this->y;
  18493. $xpos = $this->x;
  18494. $imglink = '';
  18495. if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) {
  18496. $imglink = $this->HREF['url'];
  18497. if ($imglink[0] == '#') {
  18498. // convert url to internal link
  18499. $lnkdata = explode(',', $imglink);
  18500. if (isset($lnkdata[0])) {
  18501. $page = intval(substr($lnkdata[0], 1));
  18502. if (empty($page) OR ($page <= 0)) {
  18503. $page = $this->page;
  18504. }
  18505. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  18506. $lnky = floatval($lnkdata[1]);
  18507. } else {
  18508. $lnky = 0;
  18509. }
  18510. $imglink = $this->AddLink();
  18511. $this->setLink($imglink, $lnky, $page);
  18512. }
  18513. }
  18514. }
  18515. $border = 0;
  18516. if (isset($tag['border']) AND !empty($tag['border'])) {
  18517. // currently only support 1 (frame) or a combination of 'LTRB'
  18518. $border = $tag['border'];
  18519. }
  18520. $iw = '';
  18521. if (isset($tag['width'])) {
  18522. $iw = $this->getHTMLUnitToUnits($tag['width'], ($tag['fontsize'] / $this->k), 'px', false);
  18523. }
  18524. $ih = '';
  18525. if (isset($tag['height'])) {
  18526. $ih = $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k), 'px', false);
  18527. }
  18528. if (($type == 'eps') OR ($type == 'ai')) {
  18529. $this->ImageEps($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  18530. } elseif ($type == 'svg') {
  18531. $this->ImageSVG($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  18532. } else {
  18533. $this->Image($imgsrc, $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  18534. }
  18535. switch($align) {
  18536. case 'T': {
  18537. $this->y = $prevy;
  18538. break;
  18539. }
  18540. case 'M': {
  18541. $this->y = (($this->img_rb_y + $prevy - ($this->getCellHeight($tag['fontsize'] / $this->k))) / 2);
  18542. break;
  18543. }
  18544. case 'B': {
  18545. $this->y = $this->img_rb_y - ($this->getCellHeight($tag['fontsize'] / $this->k) - ($this->getFontDescent($tag['fontname'], $tag['fontstyle'], $tag['fontsize']) * $this->cell_height_ratio));
  18546. break;
  18547. }
  18548. }
  18549. break;
  18550. }
  18551. case 'dl': {
  18552. ++$this->listnum;
  18553. if ($this->listnum == 1) {
  18554. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18555. } else {
  18556. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18557. }
  18558. break;
  18559. }
  18560. case 'dt': {
  18561. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18562. break;
  18563. }
  18564. case 'dd': {
  18565. if ($this->rtl) {
  18566. $this->rMargin += $this->listindent;
  18567. } else {
  18568. $this->lMargin += $this->listindent;
  18569. }
  18570. ++$this->listindentlevel;
  18571. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18572. break;
  18573. }
  18574. case 'ul':
  18575. case 'ol': {
  18576. ++$this->listnum;
  18577. if ($tag['value'] == 'ol') {
  18578. $this->listordered[$this->listnum] = true;
  18579. } else {
  18580. $this->listordered[$this->listnum] = false;
  18581. }
  18582. if (isset($tag['attribute']['start'])) {
  18583. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  18584. } else {
  18585. $this->listcount[$this->listnum] = 0;
  18586. }
  18587. if ($this->rtl) {
  18588. $this->rMargin += $this->listindent;
  18589. $this->x -= $this->listindent;
  18590. } else {
  18591. $this->lMargin += $this->listindent;
  18592. $this->x += $this->listindent;
  18593. }
  18594. ++$this->listindentlevel;
  18595. if ($this->listnum == 1) {
  18596. if ($key > 1) {
  18597. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18598. }
  18599. } else {
  18600. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18601. }
  18602. break;
  18603. }
  18604. case 'li': {
  18605. if ($key > 2) {
  18606. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18607. }
  18608. if ($this->listordered[$this->listnum]) {
  18609. // ordered item
  18610. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18611. $this->lispacer = $parent['attribute']['type'];
  18612. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18613. $this->lispacer = $parent['listtype'];
  18614. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18615. $this->lispacer = $this->lisymbol;
  18616. } else {
  18617. $this->lispacer = '#';
  18618. }
  18619. ++$this->listcount[$this->listnum];
  18620. if (isset($tag['attribute']['value'])) {
  18621. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  18622. }
  18623. } else {
  18624. // unordered item
  18625. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18626. $this->lispacer = $parent['attribute']['type'];
  18627. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18628. $this->lispacer = $parent['listtype'];
  18629. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18630. $this->lispacer = $this->lisymbol;
  18631. } else {
  18632. $this->lispacer = '!';
  18633. }
  18634. }
  18635. break;
  18636. }
  18637. case 'blockquote': {
  18638. if ($this->rtl) {
  18639. $this->rMargin += $this->listindent;
  18640. } else {
  18641. $this->lMargin += $this->listindent;
  18642. }
  18643. ++$this->listindentlevel;
  18644. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18645. break;
  18646. }
  18647. case 'br': {
  18648. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18649. break;
  18650. }
  18651. case 'div': {
  18652. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18653. break;
  18654. }
  18655. case 'p': {
  18656. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18657. break;
  18658. }
  18659. case 'pre': {
  18660. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18661. $this->premode = true;
  18662. break;
  18663. }
  18664. case 'sup': {
  18665. $this->setXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  18666. break;
  18667. }
  18668. case 'sub': {
  18669. $this->setXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  18670. break;
  18671. }
  18672. case 'h1':
  18673. case 'h2':
  18674. case 'h3':
  18675. case 'h4':
  18676. case 'h5':
  18677. case 'h6': {
  18678. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18679. break;
  18680. }
  18681. // Form fields (since 4.8.000 - 2009-09-07)
  18682. case 'form': {
  18683. if (isset($tag['attribute']['action'])) {
  18684. $this->form_action = $tag['attribute']['action'];
  18685. } else {
  18686. $this->Error('Please explicitly set action attribute path!');
  18687. }
  18688. if (isset($tag['attribute']['enctype'])) {
  18689. $this->form_enctype = $tag['attribute']['enctype'];
  18690. } else {
  18691. $this->form_enctype = 'application/x-www-form-urlencoded';
  18692. }
  18693. if (isset($tag['attribute']['method'])) {
  18694. $this->form_mode = $tag['attribute']['method'];
  18695. } else {
  18696. $this->form_mode = 'post';
  18697. }
  18698. break;
  18699. }
  18700. case 'input': {
  18701. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18702. $name = $tag['attribute']['name'];
  18703. } else {
  18704. break;
  18705. }
  18706. $prop = array();
  18707. $opt = array();
  18708. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18709. $prop['readonly'] = true;
  18710. }
  18711. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18712. $value = $tag['attribute']['value'];
  18713. }
  18714. if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) {
  18715. $opt['maxlen'] = intval($tag['attribute']['maxlength']);
  18716. }
  18717. $h = $this->getCellHeight($this->FontSize);
  18718. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18719. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  18720. } else {
  18721. $w = $h;
  18722. }
  18723. if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  18724. $checked = true;
  18725. } else {
  18726. $checked = false;
  18727. }
  18728. if (isset($tag['align'])) {
  18729. switch ($tag['align']) {
  18730. case 'C': {
  18731. $opt['q'] = 1;
  18732. break;
  18733. }
  18734. case 'R': {
  18735. $opt['q'] = 2;
  18736. break;
  18737. }
  18738. case 'L':
  18739. default: {
  18740. break;
  18741. }
  18742. }
  18743. }
  18744. switch ($tag['attribute']['type']) {
  18745. case 'text': {
  18746. if (isset($value)) {
  18747. $opt['v'] = $value;
  18748. }
  18749. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18750. break;
  18751. }
  18752. case 'password': {
  18753. if (isset($value)) {
  18754. $opt['v'] = $value;
  18755. }
  18756. $prop['password'] = 'true';
  18757. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18758. break;
  18759. }
  18760. case 'checkbox': {
  18761. if (!isset($value)) {
  18762. break;
  18763. }
  18764. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  18765. break;
  18766. }
  18767. case 'radio': {
  18768. if (!isset($value)) {
  18769. break;
  18770. }
  18771. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  18772. break;
  18773. }
  18774. case 'submit': {
  18775. if (!isset($value)) {
  18776. $value = 'submit';
  18777. }
  18778. $w = $this->GetStringWidth($value) * 1.5;
  18779. $h *= 1.6;
  18780. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18781. $action = array();
  18782. $action['S'] = 'SubmitForm';
  18783. $action['F'] = $this->form_action;
  18784. if ($this->form_enctype != 'FDF') {
  18785. $action['Flags'] = array('ExportFormat');
  18786. }
  18787. if ($this->form_mode == 'get') {
  18788. $action['Flags'] = array('GetMethod');
  18789. }
  18790. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  18791. break;
  18792. }
  18793. case 'reset': {
  18794. if (!isset($value)) {
  18795. $value = 'reset';
  18796. }
  18797. $w = $this->GetStringWidth($value) * 1.5;
  18798. $h *= 1.6;
  18799. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18800. $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
  18801. break;
  18802. }
  18803. case 'file': {
  18804. $prop['fileSelect'] = 'true';
  18805. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18806. if (!isset($value)) {
  18807. $value = '*';
  18808. }
  18809. $w = $this->GetStringWidth($value) * 2;
  18810. $h *= 1.2;
  18811. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18812. $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  18813. $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18814. break;
  18815. }
  18816. case 'hidden': {
  18817. if (isset($value)) {
  18818. $opt['v'] = $value;
  18819. }
  18820. $opt['f'] = array('invisible', 'hidden');
  18821. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  18822. break;
  18823. }
  18824. case 'image': {
  18825. // THIS TYPE MUST BE FIXED
  18826. if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) {
  18827. $img = $tag['attribute']['src'];
  18828. } else {
  18829. break;
  18830. }
  18831. $value = 'img';
  18832. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  18833. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18834. $jsaction = $tag['attribute']['onclick'];
  18835. } else {
  18836. $jsaction = '';
  18837. }
  18838. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18839. break;
  18840. }
  18841. case 'button': {
  18842. if (!isset($value)) {
  18843. $value = ' ';
  18844. }
  18845. $w = $this->GetStringWidth($value) * 1.5;
  18846. $h *= 1.6;
  18847. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18848. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18849. $jsaction = $tag['attribute']['onclick'];
  18850. } else {
  18851. $jsaction = '';
  18852. }
  18853. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18854. break;
  18855. }
  18856. }
  18857. break;
  18858. }
  18859. case 'textarea': {
  18860. $prop = array();
  18861. $opt = array();
  18862. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18863. $prop['readonly'] = true;
  18864. }
  18865. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18866. $name = $tag['attribute']['name'];
  18867. } else {
  18868. break;
  18869. }
  18870. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18871. $opt['v'] = $tag['attribute']['value'];
  18872. }
  18873. if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) {
  18874. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  18875. } else {
  18876. $w = 40;
  18877. }
  18878. if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) {
  18879. $h = intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize);
  18880. } else {
  18881. $h = 10;
  18882. }
  18883. $prop['multiline'] = 'true';
  18884. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18885. break;
  18886. }
  18887. case 'select': {
  18888. $h = $this->getCellHeight($this->FontSize);
  18889. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18890. $h *= ($tag['attribute']['size'] + 1);
  18891. }
  18892. $prop = array();
  18893. $opt = array();
  18894. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18895. $name = $tag['attribute']['name'];
  18896. } else {
  18897. break;
  18898. }
  18899. $w = 0;
  18900. if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) {
  18901. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  18902. $values = array();
  18903. foreach ($options as $val) {
  18904. if (strpos($val, '#!TaB!#') !== false) {
  18905. $opts = explode('#!TaB!#', $val);
  18906. $values[] = $opts;
  18907. $w = max($w, $this->GetStringWidth($opts[1]));
  18908. } else {
  18909. $values[] = $val;
  18910. $w = max($w, $this->GetStringWidth($val));
  18911. }
  18912. }
  18913. } else {
  18914. break;
  18915. }
  18916. $w *= 2;
  18917. if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  18918. $prop['multipleSelection'] = 'true';
  18919. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18920. } else {
  18921. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18922. }
  18923. break;
  18924. }
  18925. case 'tcpdf': {
  18926. if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  18927. // Special tag used to call TCPDF methods
  18928. // This tag is disabled by default by the K_TCPDF_CALLS_IN_HTML constant on TCPDF configuration file.
  18929. // Please use this feature only if you are in control of the HTML content and you are sure that it does not contain any harmful code.
  18930. if (!empty($tag['attribute']['data'])) {
  18931. $tcpdf_tag_data = $this->unserializeTCPDFtag($tag['attribute']['data']);
  18932. if ($this->allowedTCPDFtag($tcpdf_tag_data['m'])) {
  18933. call_user_func_array(array($this, $tcpdf_tag_data['m']), $tcpdf_tag_data['p']);
  18934. }
  18935. $this->newline = true;
  18936. }
  18937. }
  18938. break;
  18939. }
  18940. default: {
  18941. break;
  18942. }
  18943. }
  18944. // define tags that support borders and background colors
  18945. $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  18946. if (in_array($tag['value'], $bordertags)) {
  18947. // set border
  18948. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  18949. }
  18950. if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  18951. $pba = $dom[$key]['attribute']['pagebreakafter'];
  18952. // check for pagebreak
  18953. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  18954. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18955. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18956. }
  18957. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  18958. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  18959. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18960. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18961. }
  18962. }
  18963. return $dom;
  18964. }
  18965. /**
  18966. * Process closing tags.
  18967. * @param array $dom html dom array
  18968. * @param int $key current element id
  18969. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  18970. * @param int $maxbottomliney maximum y value of current line
  18971. * @return array $dom
  18972. * @protected
  18973. */
  18974. protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
  18975. $tag = $dom[$key];
  18976. $parent = $dom[($dom[$key]['parent'])];
  18977. $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
  18978. $in_table_head = false;
  18979. // maximum x position (used to draw borders)
  18980. if ($this->rtl) {
  18981. $xmax = $this->w;
  18982. } else {
  18983. $xmax = 0;
  18984. }
  18985. if ($tag['block']) {
  18986. $hbz = 0; // distance from y to line bottom
  18987. $hb = 0; // vertical space between block tags
  18988. // calculate vertical space for block tags
  18989. if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18990. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18991. } elseif (isset($parent['fontsize'])) {
  18992. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  18993. } else {
  18994. $pre_h = $this->getCellHeight($this->FontSize);
  18995. }
  18996. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18997. $cn = $this->tagvspaces[$tag['value']][1]['n'];
  18998. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18999. $cn = 0.6;
  19000. } else {
  19001. $cn = 1;
  19002. }
  19003. if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
  19004. $hb = 0;
  19005. } else {
  19006. $hb = ($cn * $pre_h);
  19007. }
  19008. if ($maxbottomliney > $this->PageBreakTrigger) {
  19009. $hbz = $this->getCellHeight($this->FontSize);
  19010. } elseif ($this->y < $maxbottomliney) {
  19011. $hbz = ($maxbottomliney - $this->y);
  19012. }
  19013. }
  19014. // Closing tag
  19015. switch($tag['value']) {
  19016. case 'tr': {
  19017. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  19018. if (!isset($parent['endy'])) {
  19019. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  19020. $parent['endy'] = $this->y;
  19021. }
  19022. if (!isset($parent['endpage'])) {
  19023. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  19024. $parent['endpage'] = $this->page;
  19025. }
  19026. if (!isset($parent['endcolumn'])) {
  19027. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  19028. $parent['endcolumn'] = $this->current_column;
  19029. }
  19030. // update row-spanned cells
  19031. if (isset($dom[$table_el]['rowspans'])) {
  19032. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19033. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  19034. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  19035. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  19036. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  19037. } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  19038. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  19039. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  19040. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  19041. }
  19042. }
  19043. }
  19044. // report new endy and endpage to the rowspanned cells
  19045. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19046. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  19047. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  19048. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  19049. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  19050. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  19051. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  19052. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  19053. }
  19054. }
  19055. // update remaining rowspanned cells
  19056. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19057. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  19058. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  19059. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  19060. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  19061. }
  19062. }
  19063. }
  19064. $prev_page = $this->page;
  19065. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  19066. if ($this->num_columns > 1) {
  19067. if (($prev_page < $this->page)
  19068. AND ((($this->current_column == 0) AND ($dom[($dom[$key]['parent'])]['endcolumn'] == ($this->num_columns - 1)))
  19069. OR ($this->current_column == $dom[($dom[$key]['parent'])]['endcolumn']))) {
  19070. // page jump
  19071. $this->selectColumn(0);
  19072. $dom[($dom[$key]['parent'])]['endcolumn'] = 0;
  19073. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  19074. } else {
  19075. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  19076. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  19077. }
  19078. } else {
  19079. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  19080. }
  19081. if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  19082. $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  19083. } elseif (isset($dom[$table_el]['border-spacing'])) {
  19084. $this->y += $dom[$table_el]['border-spacing']['V'];
  19085. }
  19086. $this->Ln(0, $cell);
  19087. if ($this->current_column == $parent['startcolumn']) {
  19088. $this->x = $parent['startx'];
  19089. }
  19090. // account for booklet mode
  19091. if ($this->page > $parent['startpage']) {
  19092. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  19093. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  19094. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  19095. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  19096. }
  19097. }
  19098. break;
  19099. }
  19100. case 'tablehead':
  19101. // closing tag used for the thead part
  19102. $in_table_head = true;
  19103. $this->inthead = false;
  19104. case 'table': {
  19105. $table_el = $parent;
  19106. // set default border
  19107. if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  19108. // set default border
  19109. $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
  19110. } else {
  19111. $border = 0;
  19112. }
  19113. $default_border = $border;
  19114. // fix bottom line alignment of last line before page break
  19115. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  19116. // update row-spanned cells
  19117. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  19118. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  19119. if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
  19120. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  19121. }
  19122. if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
  19123. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  19124. }
  19125. }
  19126. }
  19127. if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  19128. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  19129. $dom[$prevtrkey]['endy'] = $pgendy;
  19130. // update row-spanned cells
  19131. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  19132. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  19133. if (($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  19134. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  19135. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  19136. }
  19137. }
  19138. }
  19139. }
  19140. $prevtrkey = $trkey;
  19141. $table_el = $dom[($dom[$key]['parent'])];
  19142. }
  19143. // for each row
  19144. if (!empty($table_el['trids'])) {
  19145. unset($xmax);
  19146. }
  19147. foreach ($table_el['trids'] as $j => $trkey) {
  19148. $parent = $dom[$trkey];
  19149. if (!isset($xmax)) {
  19150. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  19151. }
  19152. // for each cell on the row
  19153. foreach ($parent['cellpos'] as $k => $cellpos) {
  19154. if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  19155. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  19156. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  19157. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  19158. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  19159. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  19160. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  19161. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  19162. } else {
  19163. $endy = $parent['endy'];
  19164. $startpage = $parent['startpage'];
  19165. $endpage = $parent['endpage'];
  19166. $startcolumn = $parent['startcolumn'];
  19167. $endcolumn = $parent['endcolumn'];
  19168. }
  19169. if ($this->num_columns == 0) {
  19170. $this->num_columns = 1;
  19171. }
  19172. if (isset($cellpos['border'])) {
  19173. $border = $cellpos['border'];
  19174. }
  19175. if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  19176. $this->setFillColorArray($cellpos['bgcolor']);
  19177. $fill = true;
  19178. } else {
  19179. $fill = false;
  19180. }
  19181. $x = $cellpos['startx'];
  19182. $y = $parent['starty'];
  19183. $starty = $y;
  19184. $w = abs($cellpos['endx'] - $cellpos['startx']);
  19185. // get border modes
  19186. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19187. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19188. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19189. // design borders around HTML cells.
  19190. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19191. $ccode = '';
  19192. $this->setPage($page);
  19193. if ($this->num_columns < 2) {
  19194. // single-column mode
  19195. $this->x = $x;
  19196. $this->y = $this->tMargin;
  19197. }
  19198. // account for margin changes
  19199. if ($page > $startpage) {
  19200. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19201. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19202. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19203. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19204. }
  19205. }
  19206. if ($startpage == $endpage) { // single page
  19207. $deltacol = 0;
  19208. $deltath = 0;
  19209. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19210. $this->selectColumn($column);
  19211. if ($startcolumn == $endcolumn) { // single column
  19212. $cborder = $border;
  19213. $h = $endy - $parent['starty'];
  19214. $this->y = $y;
  19215. $this->x = $x;
  19216. } elseif ($column == $startcolumn) { // first column
  19217. $cborder = $border_start;
  19218. $this->y = $starty;
  19219. $this->x = $x;
  19220. $h = $this->h - $this->y - $this->bMargin;
  19221. if ($this->rtl) {
  19222. $deltacol = $this->x + $this->rMargin - $this->w;
  19223. } else {
  19224. $deltacol = $this->x - $this->lMargin;
  19225. }
  19226. } elseif ($column == $endcolumn) { // end column
  19227. $cborder = $border_end;
  19228. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19229. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19230. }
  19231. $this->x += $deltacol;
  19232. $h = $endy - $this->y;
  19233. } else { // middle column
  19234. $cborder = $border_middle;
  19235. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19236. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19237. }
  19238. $this->x += $deltacol;
  19239. $h = $this->h - $this->y - $this->bMargin;
  19240. }
  19241. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19242. } // end for each column
  19243. } elseif ($page == $startpage) { // first page
  19244. $deltacol = 0;
  19245. $deltath = 0;
  19246. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19247. $this->selectColumn($column);
  19248. if ($column == $startcolumn) { // first column
  19249. $cborder = $border_start;
  19250. $this->y = $starty;
  19251. $this->x = $x;
  19252. $h = $this->h - $this->y - $this->bMargin;
  19253. if ($this->rtl) {
  19254. $deltacol = $this->x + $this->rMargin - $this->w;
  19255. } else {
  19256. $deltacol = $this->x - $this->lMargin;
  19257. }
  19258. } else { // middle column
  19259. $cborder = $border_middle;
  19260. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19261. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19262. }
  19263. $this->x += $deltacol;
  19264. $h = $this->h - $this->y - $this->bMargin;
  19265. }
  19266. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19267. } // end for each column
  19268. } elseif ($page == $endpage) { // last page
  19269. $deltacol = 0;
  19270. $deltath = 0;
  19271. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19272. $this->selectColumn($column);
  19273. if ($column == $endcolumn) { // end column
  19274. $cborder = $border_end;
  19275. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19276. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19277. }
  19278. $this->x += $deltacol;
  19279. $h = $endy - $this->y;
  19280. } else { // middle column
  19281. $cborder = $border_middle;
  19282. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19283. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19284. }
  19285. $this->x += $deltacol;
  19286. $h = $this->h - $this->y - $this->bMargin;
  19287. }
  19288. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19289. } // end for each column
  19290. } else { // middle page
  19291. $deltacol = 0;
  19292. $deltath = 0;
  19293. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19294. $this->selectColumn($column);
  19295. $cborder = $border_middle;
  19296. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19297. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19298. }
  19299. $this->x += $deltacol;
  19300. $h = $this->h - $this->y - $this->bMargin;
  19301. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19302. } // end for each column
  19303. }
  19304. if (!empty($cborder) OR !empty($fill)) {
  19305. $offsetlen = strlen($ccode);
  19306. // draw border and fill
  19307. if ($this->inxobj) {
  19308. // we are inside an XObject template
  19309. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19310. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19311. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19312. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19313. } else {
  19314. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19315. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19316. }
  19317. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19318. $pstart = substr($pagebuff, 0, $pagemark);
  19319. $pend = substr($pagebuff, $pagemark);
  19320. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19321. } else {
  19322. // draw border and fill
  19323. if (end($this->transfmrk[$this->page]) !== false) {
  19324. $pagemarkkey = key($this->transfmrk[$this->page]);
  19325. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19326. } elseif ($this->InFooter) {
  19327. $pagemark = $this->footerpos[$this->page];
  19328. } else {
  19329. $pagemark = $this->intmrk[$this->page];
  19330. }
  19331. $pagebuff = $this->getPageBuffer($this->page);
  19332. $pstart = substr($pagebuff, 0, $pagemark);
  19333. $pend = substr($pagebuff, $pagemark);
  19334. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19335. }
  19336. }
  19337. } // end for each page
  19338. // restore default border
  19339. $border = $default_border;
  19340. } // end for each cell on the row
  19341. if (isset($table_el['attribute']['cellspacing'])) {
  19342. $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  19343. } elseif (isset($table_el['border-spacing'])) {
  19344. $this->y += $table_el['border-spacing']['V'];
  19345. }
  19346. $this->Ln(0, $cell);
  19347. $this->x = $parent['startx'];
  19348. if ($endpage > $startpage) {
  19349. if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19350. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  19351. } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19352. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  19353. }
  19354. }
  19355. }
  19356. if (!$in_table_head) { // we are not inside a thead section
  19357. $this->cell_padding = isset($table_el['old_cell_padding']) ? $table_el['old_cell_padding'] : null;
  19358. // reset row height
  19359. $this->resetLastH();
  19360. if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
  19361. $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  19362. if (($plendiff > 0) AND ($plendiff < 60)) {
  19363. $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  19364. if (substr($pagediff, 0, 5) == 'BT /F') {
  19365. // the difference is only a font setting
  19366. $plendiff = 0;
  19367. }
  19368. }
  19369. if ($plendiff == 0) {
  19370. // remove last blank page
  19371. $this->deletePage($this->numpages);
  19372. }
  19373. }
  19374. if (isset($this->theadMargins['top'])) {
  19375. // restore top margin
  19376. $this->tMargin = $this->theadMargins['top'];
  19377. }
  19378. if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  19379. // reset main table header
  19380. $this->thead = '';
  19381. $this->theadMargins = array();
  19382. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  19383. }
  19384. }
  19385. $parent = $table_el;
  19386. break;
  19387. }
  19388. case 'a': {
  19389. $this->HREF = array();
  19390. break;
  19391. }
  19392. case 'sup': {
  19393. $this->setXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  19394. break;
  19395. }
  19396. case 'sub': {
  19397. $this->setXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
  19398. break;
  19399. }
  19400. case 'div': {
  19401. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19402. break;
  19403. }
  19404. case 'blockquote': {
  19405. if ($this->rtl) {
  19406. $this->rMargin -= $this->listindent;
  19407. } else {
  19408. $this->lMargin -= $this->listindent;
  19409. }
  19410. --$this->listindentlevel;
  19411. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19412. break;
  19413. }
  19414. case 'p': {
  19415. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19416. break;
  19417. }
  19418. case 'pre': {
  19419. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19420. $this->premode = false;
  19421. break;
  19422. }
  19423. case 'dl': {
  19424. --$this->listnum;
  19425. if ($this->listnum <= 0) {
  19426. $this->listnum = 0;
  19427. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19428. } else {
  19429. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19430. }
  19431. $this->resetLastH();
  19432. break;
  19433. }
  19434. case 'dt': {
  19435. $this->lispacer = '';
  19436. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19437. break;
  19438. }
  19439. case 'dd': {
  19440. $this->lispacer = '';
  19441. if ($this->rtl) {
  19442. $this->rMargin -= $this->listindent;
  19443. } else {
  19444. $this->lMargin -= $this->listindent;
  19445. }
  19446. --$this->listindentlevel;
  19447. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19448. break;
  19449. }
  19450. case 'ul':
  19451. case 'ol': {
  19452. --$this->listnum;
  19453. $this->lispacer = '';
  19454. if ($this->rtl) {
  19455. $this->rMargin -= $this->listindent;
  19456. } else {
  19457. $this->lMargin -= $this->listindent;
  19458. }
  19459. --$this->listindentlevel;
  19460. if ($this->listnum <= 0) {
  19461. $this->listnum = 0;
  19462. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19463. } else {
  19464. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19465. }
  19466. $this->resetLastH();
  19467. break;
  19468. }
  19469. case 'li': {
  19470. $this->lispacer = '';
  19471. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19472. break;
  19473. }
  19474. case 'h1':
  19475. case 'h2':
  19476. case 'h3':
  19477. case 'h4':
  19478. case 'h5':
  19479. case 'h6': {
  19480. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19481. break;
  19482. }
  19483. // Form fields (since 4.8.000 - 2009-09-07)
  19484. case 'form': {
  19485. $this->form_action = '';
  19486. $this->form_enctype = 'application/x-www-form-urlencoded';
  19487. break;
  19488. }
  19489. default : {
  19490. break;
  19491. }
  19492. }
  19493. // draw border and background (if any)
  19494. $this->drawHTMLTagBorder($parent, $xmax);
  19495. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  19496. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  19497. // check for pagebreak
  19498. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  19499. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19500. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19501. }
  19502. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  19503. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  19504. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19505. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19506. }
  19507. }
  19508. $this->tmprtl = false;
  19509. return $dom;
  19510. }
  19511. /**
  19512. * Add vertical spaces if needed.
  19513. * @param string $hbz Distance between current y and line bottom.
  19514. * @param string $hb The height of the break.
  19515. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  19516. * @param boolean $firsttag set to true when the tag is the first.
  19517. * @param boolean $lasttag set to true when the tag is the last.
  19518. * @protected
  19519. */
  19520. protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
  19521. if ($firsttag) {
  19522. $this->Ln(0, $cell);
  19523. $this->htmlvspace = 0;
  19524. return;
  19525. }
  19526. if ($lasttag) {
  19527. $this->Ln($hbz, $cell);
  19528. $this->htmlvspace = 0;
  19529. return;
  19530. }
  19531. if ($hb < $this->htmlvspace) {
  19532. $hd = 0;
  19533. } else {
  19534. $hd = $hb - $this->htmlvspace;
  19535. $this->htmlvspace = $hb;
  19536. }
  19537. $this->Ln(($hbz + $hd), $cell);
  19538. }
  19539. /**
  19540. * Return the starting coordinates to draw an html border
  19541. * @return array containing top-left border coordinates
  19542. * @protected
  19543. * @since 5.7.000 (2010-08-03)
  19544. */
  19545. protected function getBorderStartPosition() {
  19546. if ($this->rtl) {
  19547. $xmax = $this->lMargin;
  19548. } else {
  19549. $xmax = $this->w - $this->rMargin;
  19550. }
  19551. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
  19552. }
  19553. /**
  19554. * Draw an HTML block border and fill
  19555. * @param array $tag array of tag properties.
  19556. * @param int $xmax end X coordinate for border.
  19557. * @protected
  19558. * @since 5.7.000 (2010-08-03)
  19559. */
  19560. protected function drawHTMLTagBorder($tag, $xmax) {
  19561. if (!isset($tag['borderposition'])) {
  19562. // nothing to draw
  19563. return;
  19564. }
  19565. $prev_x = $this->x;
  19566. $prev_y = $this->y;
  19567. $prev_lasth = $this->lasth;
  19568. $border = 0;
  19569. $fill = false;
  19570. $this->lasth = 0;
  19571. if (isset($tag['border']) AND !empty($tag['border'])) {
  19572. // get border style
  19573. $border = $tag['border'];
  19574. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  19575. // border for table header
  19576. $border = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19577. }
  19578. }
  19579. if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  19580. // get background color
  19581. $old_bgcolor = $this->bgcolor;
  19582. $this->setFillColorArray($tag['bgcolor']);
  19583. $fill = true;
  19584. }
  19585. if (!$border AND !$fill) {
  19586. // nothing to draw
  19587. return;
  19588. }
  19589. if (isset($tag['attribute']['cellspacing'])) {
  19590. $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  19591. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  19592. } elseif (isset($tag['border-spacing'])) {
  19593. $cellspacing = $tag['border-spacing'];
  19594. } else {
  19595. $cellspacing = array('H' => 0, 'V' => 0);
  19596. }
  19597. if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  19598. // draw the border externally respect the sqare edge.
  19599. $border['mode'] = 'ext';
  19600. }
  19601. if ($this->rtl) {
  19602. if ($xmax >= $tag['borderposition']['x']) {
  19603. $xmax = $tag['borderposition']['xmax'];
  19604. }
  19605. $w = ($tag['borderposition']['x'] - $xmax);
  19606. } else {
  19607. if ($xmax <= $tag['borderposition']['x']) {
  19608. $xmax = $tag['borderposition']['xmax'];
  19609. }
  19610. $w = ($xmax - $tag['borderposition']['x']);
  19611. }
  19612. if ($w <= 0) {
  19613. return;
  19614. }
  19615. $w += $cellspacing['H'];
  19616. $startpage = $tag['borderposition']['page'];
  19617. $startcolumn = $tag['borderposition']['column'];
  19618. $x = $tag['borderposition']['x'];
  19619. $y = $tag['borderposition']['y'];
  19620. $endpage = $this->page;
  19621. $starty = $tag['borderposition']['y'] - $cellspacing['V'];
  19622. $currentY = $this->y;
  19623. $this->x = $x;
  19624. // get latest column
  19625. $endcolumn = $this->current_column;
  19626. if ($this->num_columns == 0) {
  19627. $this->num_columns = 1;
  19628. }
  19629. // get border modes
  19630. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19631. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19632. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19633. // temporary disable page regions
  19634. $temp_page_regions = $this->page_regions;
  19635. $this->page_regions = array();
  19636. // design borders around HTML cells.
  19637. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19638. $ccode = '';
  19639. $this->setPage($page);
  19640. if ($this->num_columns < 2) {
  19641. // single-column mode
  19642. $this->x = $x;
  19643. $this->y = $this->tMargin;
  19644. }
  19645. // account for margin changes
  19646. if ($page > $startpage) {
  19647. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19648. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19649. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19650. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19651. }
  19652. }
  19653. if ($startpage == $endpage) {
  19654. // single page
  19655. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19656. $this->selectColumn($column);
  19657. if ($startcolumn == $endcolumn) { // single column
  19658. $cborder = $border;
  19659. $h = ($currentY - $y) + $cellspacing['V'];
  19660. $this->y = $starty;
  19661. } elseif ($column == $startcolumn) { // first column
  19662. $cborder = $border_start;
  19663. $this->y = $starty;
  19664. $h = $this->h - $this->y - $this->bMargin;
  19665. } elseif ($column == $endcolumn) { // end column
  19666. $cborder = $border_end;
  19667. $h = $currentY - $this->y;
  19668. } else { // middle column
  19669. $cborder = $border_middle;
  19670. $h = $this->h - $this->y - $this->bMargin;
  19671. }
  19672. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19673. } // end for each column
  19674. } elseif ($page == $startpage) { // first page
  19675. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19676. $this->selectColumn($column);
  19677. if ($column == $startcolumn) { // first column
  19678. $cborder = $border_start;
  19679. $this->y = $starty;
  19680. $h = $this->h - $this->y - $this->bMargin;
  19681. } else { // middle column
  19682. $cborder = $border_middle;
  19683. $h = $this->h - $this->y - $this->bMargin;
  19684. }
  19685. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19686. } // end for each column
  19687. } elseif ($page == $endpage) { // last page
  19688. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19689. $this->selectColumn($column);
  19690. if ($column == $endcolumn) {
  19691. // end column
  19692. $cborder = $border_end;
  19693. $h = $currentY - $this->y;
  19694. } else {
  19695. // middle column
  19696. $cborder = $border_middle;
  19697. $h = $this->h - $this->y - $this->bMargin;
  19698. }
  19699. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19700. } // end for each column
  19701. } else { // middle page
  19702. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19703. $this->selectColumn($column);
  19704. $cborder = $border_middle;
  19705. $h = $this->h - $this->y - $this->bMargin;
  19706. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19707. } // end for each column
  19708. }
  19709. if ($cborder OR $fill) {
  19710. $offsetlen = strlen($ccode);
  19711. // draw border and fill
  19712. if ($this->inxobj) {
  19713. // we are inside an XObject template
  19714. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19715. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19716. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19717. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19718. } else {
  19719. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19720. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19721. }
  19722. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19723. $pstart = substr($pagebuff, 0, $pagemark);
  19724. $pend = substr($pagebuff, $pagemark);
  19725. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19726. } else {
  19727. if (end($this->transfmrk[$this->page]) !== false) {
  19728. $pagemarkkey = key($this->transfmrk[$this->page]);
  19729. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19730. } elseif ($this->InFooter) {
  19731. $pagemark = $this->footerpos[$this->page];
  19732. } else {
  19733. $pagemark = $this->intmrk[$this->page];
  19734. }
  19735. $pagebuff = $this->getPageBuffer($this->page);
  19736. $pstart = substr($pagebuff, 0, $pagemark);
  19737. $pend = substr($pagebuff, $pagemark);
  19738. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19739. $this->bordermrk[$this->page] += $offsetlen;
  19740. $this->cntmrk[$this->page] += $offsetlen;
  19741. }
  19742. }
  19743. } // end for each page
  19744. // restore page regions
  19745. $this->page_regions = $temp_page_regions;
  19746. if (isset($old_bgcolor)) {
  19747. // restore background color
  19748. $this->setFillColorArray($old_bgcolor);
  19749. }
  19750. // restore pointer position
  19751. $this->x = $prev_x;
  19752. $this->y = $prev_y;
  19753. $this->lasth = $prev_lasth;
  19754. }
  19755. /**
  19756. * Set the default bullet to be used as LI bullet symbol
  19757. * @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')
  19758. * @public
  19759. * @since 4.0.028 (2008-09-26)
  19760. */
  19761. public function setLIsymbol($symbol='!') {
  19762. // check for custom image symbol
  19763. if (substr($symbol, 0, 4) == 'img|') {
  19764. $this->lisymbol = $symbol;
  19765. return;
  19766. }
  19767. $symbol = strtolower($symbol);
  19768. $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');
  19769. if (in_array($symbol, $valid_symbols)) {
  19770. $this->lisymbol = $symbol;
  19771. } else {
  19772. $this->lisymbol = '';
  19773. }
  19774. }
  19775. /**
  19776. * Set the booklet mode for double-sided pages.
  19777. * @param boolean $booklet true set the booklet mode on, false otherwise.
  19778. * @param float $inner Inner page margin.
  19779. * @param float $outer Outer page margin.
  19780. * @public
  19781. * @since 4.2.000 (2008-10-29)
  19782. */
  19783. public function setBooklet($booklet=true, $inner=-1, $outer=-1) {
  19784. $this->booklet = $booklet;
  19785. if ($inner >= 0) {
  19786. $this->lMargin = $inner;
  19787. }
  19788. if ($outer >= 0) {
  19789. $this->rMargin = $outer;
  19790. }
  19791. }
  19792. /**
  19793. * Swap the left and right margins.
  19794. * @param boolean $reverse if true swap left and right margins.
  19795. * @protected
  19796. * @since 4.2.000 (2008-10-29)
  19797. */
  19798. protected function swapMargins($reverse=true) {
  19799. if ($reverse) {
  19800. // swap left and right margins
  19801. $mtemp = $this->original_lMargin;
  19802. $this->original_lMargin = $this->original_rMargin;
  19803. $this->original_rMargin = $mtemp;
  19804. $deltam = $this->original_lMargin - $this->original_rMargin;
  19805. $this->lMargin += $deltam;
  19806. $this->rMargin -= $deltam;
  19807. }
  19808. }
  19809. /**
  19810. * Set the vertical spaces for HTML tags.
  19811. * The array must have the following structure (example):
  19812. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  19813. * The first array level contains the tag names,
  19814. * the second level contains 0 for opening tags or 1 for closing tags,
  19815. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  19816. * If the h parameter is not specified, default values are used.
  19817. * @param array $tagvs array of tags and relative vertical spaces.
  19818. * @public
  19819. * @since 4.2.001 (2008-10-30)
  19820. */
  19821. public function setHtmlVSpace($tagvs) {
  19822. $this->tagvspaces = $tagvs;
  19823. }
  19824. /**
  19825. * Set custom width for list indentation.
  19826. * @param float $width width of the indentation. Use negative value to disable it.
  19827. * @public
  19828. * @since 4.2.007 (2008-11-12)
  19829. */
  19830. public function setListIndentWidth($width) {
  19831. return $this->customlistindent = floatval($width);
  19832. }
  19833. /**
  19834. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  19835. * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page.
  19836. * @public
  19837. * @since 4.2.010 (2008-11-14)
  19838. */
  19839. public function setOpenCell($isopen) {
  19840. $this->opencell = $isopen;
  19841. }
  19842. /**
  19843. * Set the color and font style for HTML links.
  19844. * @param array $color RGB array of colors
  19845. * @param string $fontstyle additional font styles to add
  19846. * @public
  19847. * @since 4.4.003 (2008-12-09)
  19848. */
  19849. public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
  19850. $this->htmlLinkColorArray = $color;
  19851. $this->htmlLinkFontStyle = $fontstyle;
  19852. }
  19853. /**
  19854. * Convert HTML string containing value and unit of measure to user's units or points.
  19855. * @param string $htmlval String containing values and unit.
  19856. * @param string $refsize Reference value in points.
  19857. * @param string $defaultunit Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  19858. * @param boolean $points If true returns points, otherwise returns value in user's units.
  19859. * @return float value in user's unit or point if $points=true
  19860. * @public
  19861. * @since 4.4.004 (2008-12-10)
  19862. */
  19863. public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
  19864. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  19865. $retval = 0;
  19866. $value = 0;
  19867. $unit = 'px';
  19868. if ($points) {
  19869. $k = 1;
  19870. } else {
  19871. $k = $this->k;
  19872. }
  19873. if (in_array($defaultunit, $supportedunits)) {
  19874. $unit = $defaultunit;
  19875. }
  19876. if (is_numeric($htmlval)) {
  19877. $value = floatval($htmlval);
  19878. } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
  19879. $value = floatval($mnum[1]);
  19880. if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
  19881. if (in_array($munit[1], $supportedunits)) {
  19882. $unit = $munit[1];
  19883. }
  19884. }
  19885. }
  19886. switch ($unit) {
  19887. // percentage
  19888. case '%': {
  19889. $retval = (($value * $refsize) / 100);
  19890. break;
  19891. }
  19892. // relative-size
  19893. case 'em': {
  19894. $retval = ($value * $refsize);
  19895. break;
  19896. }
  19897. // height of lower case 'x' (about half the font-size)
  19898. case 'ex': {
  19899. $retval = ($value * ($refsize / 2));
  19900. break;
  19901. }
  19902. // absolute-size
  19903. case 'in': {
  19904. $retval = (($value * $this->dpi) / $k);
  19905. break;
  19906. }
  19907. // centimeters
  19908. case 'cm': {
  19909. $retval = (($value / 2.54 * $this->dpi) / $k);
  19910. break;
  19911. }
  19912. // millimeters
  19913. case 'mm': {
  19914. $retval = (($value / 25.4 * $this->dpi) / $k);
  19915. break;
  19916. }
  19917. // one pica is 12 points
  19918. case 'pc': {
  19919. $retval = (($value * 12) / $k);
  19920. break;
  19921. }
  19922. // points
  19923. case 'pt': {
  19924. $retval = ($value / $k);
  19925. break;
  19926. }
  19927. // pixels
  19928. case 'px': {
  19929. $retval = $this->pixelsToUnits($value);
  19930. if ($points) {
  19931. $retval *= $this->k;
  19932. }
  19933. break;
  19934. }
  19935. }
  19936. return $retval;
  19937. }
  19938. /**
  19939. * Output an HTML list bullet or ordered item symbol
  19940. * @param int $listdepth list nesting level
  19941. * @param string $listtype type of list
  19942. * @param float $size current font size
  19943. * @protected
  19944. * @since 4.4.004 (2008-12-10)
  19945. */
  19946. protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
  19947. if ($this->state != 2) {
  19948. return;
  19949. }
  19950. $size /= $this->k;
  19951. $fill = '';
  19952. $bgcolor = $this->bgcolor;
  19953. $color = $this->fgcolor;
  19954. $strokecolor = $this->strokecolor;
  19955. $width = 0;
  19956. $textitem = '';
  19957. $tmpx = $this->x;
  19958. $lspace = $this->GetStringWidth(' ');
  19959. if ($listtype == '^') {
  19960. // special symbol used for avoid justification of rect bullet
  19961. $this->lispacer = '';
  19962. return;
  19963. } elseif ($listtype == '!') {
  19964. // set default list type for unordered list
  19965. $deftypes = array('disc', 'circle', 'square');
  19966. $listtype = $deftypes[($listdepth - 1) % 3];
  19967. } elseif ($listtype == '#') {
  19968. // set default list type for ordered list
  19969. $listtype = 'decimal';
  19970. } elseif (substr($listtype, 0, 4) == 'img|') {
  19971. // custom image type ('img|type|width|height|image.ext')
  19972. $img = explode('|', $listtype);
  19973. $listtype = 'img';
  19974. }
  19975. switch ($listtype) {
  19976. // unordered types
  19977. case 'none': {
  19978. break;
  19979. }
  19980. case 'disc': {
  19981. $r = $size / 6;
  19982. $lspace += (2 * $r);
  19983. if ($this->rtl) {
  19984. $this->x += $lspace;
  19985. } else {
  19986. $this->x -= $lspace;
  19987. }
  19988. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
  19989. break;
  19990. }
  19991. case 'circle': {
  19992. $r = $size / 6;
  19993. $lspace += (2 * $r);
  19994. if ($this->rtl) {
  19995. $this->x += $lspace;
  19996. } else {
  19997. $this->x -= $lspace;
  19998. }
  19999. $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
  20000. $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
  20001. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
  20002. $this->_out($prev_line_style); // restore line settings
  20003. break;
  20004. }
  20005. case 'square': {
  20006. $l = $size / 3;
  20007. $lspace += $l;
  20008. if ($this->rtl) {;
  20009. $this->x += $lspace;
  20010. } else {
  20011. $this->x -= $lspace;
  20012. }
  20013. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  20014. break;
  20015. }
  20016. case 'img': {
  20017. // 1=>type, 2=>width, 3=>height, 4=>image.ext
  20018. $lspace += $img[2];
  20019. if ($this->rtl) {;
  20020. $this->x += $lspace;
  20021. } else {
  20022. $this->x -= $lspace;
  20023. }
  20024. $imgtype = strtolower($img[1]);
  20025. $prev_y = $this->y;
  20026. switch ($imgtype) {
  20027. case 'svg': {
  20028. $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
  20029. break;
  20030. }
  20031. case 'ai':
  20032. case 'eps': {
  20033. $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
  20034. break;
  20035. }
  20036. default: {
  20037. $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);
  20038. break;
  20039. }
  20040. }
  20041. $this->y = $prev_y;
  20042. break;
  20043. }
  20044. // ordered types
  20045. // $this->listcount[$this->listnum];
  20046. // $textitem
  20047. case '1':
  20048. case 'decimal': {
  20049. $textitem = $this->listcount[$this->listnum];
  20050. break;
  20051. }
  20052. case 'decimal-leading-zero': {
  20053. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  20054. break;
  20055. }
  20056. case 'i':
  20057. case 'lower-roman': {
  20058. $textitem = strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]));
  20059. break;
  20060. }
  20061. case 'I':
  20062. case 'upper-roman': {
  20063. $textitem = TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]);
  20064. break;
  20065. }
  20066. case 'a':
  20067. case 'lower-alpha':
  20068. case 'lower-latin': {
  20069. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  20070. break;
  20071. }
  20072. case 'A':
  20073. case 'upper-alpha':
  20074. case 'upper-latin': {
  20075. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  20076. break;
  20077. }
  20078. case 'lower-greek': {
  20079. $textitem = TCPDF_FONTS::unichr((945 + $this->listcount[$this->listnum] - 1), $this->isunicode);
  20080. break;
  20081. }
  20082. /*
  20083. // Types to be implemented (special handling)
  20084. case 'hebrew': {
  20085. break;
  20086. }
  20087. case 'armenian': {
  20088. break;
  20089. }
  20090. case 'georgian': {
  20091. break;
  20092. }
  20093. case 'cjk-ideographic': {
  20094. break;
  20095. }
  20096. case 'hiragana': {
  20097. break;
  20098. }
  20099. case 'katakana': {
  20100. break;
  20101. }
  20102. case 'hiragana-iroha': {
  20103. break;
  20104. }
  20105. case 'katakana-iroha': {
  20106. break;
  20107. }
  20108. */
  20109. default: {
  20110. $textitem = $this->listcount[$this->listnum];
  20111. }
  20112. }
  20113. if (!TCPDF_STATIC::empty_string($textitem)) {
  20114. // Check whether we need a new page or new column
  20115. $prev_y = $this->y;
  20116. $h = $this->getCellHeight($this->FontSize);
  20117. if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
  20118. $tmpx = $this->x;
  20119. }
  20120. // print ordered item
  20121. if ($this->rtl) {
  20122. $textitem = '.'.$textitem;
  20123. } else {
  20124. $textitem = $textitem.'.';
  20125. }
  20126. $lspace += $this->GetStringWidth($textitem);
  20127. if ($this->rtl) {
  20128. $this->x += $lspace;
  20129. } else {
  20130. $this->x -= $lspace;
  20131. }
  20132. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  20133. }
  20134. $this->x = $tmpx;
  20135. $this->lispacer = '^';
  20136. // restore colors
  20137. $this->setFillColorArray($bgcolor);
  20138. $this->setDrawColorArray($strokecolor);
  20139. $this->settextColorArray($color);
  20140. }
  20141. /**
  20142. * Returns current graphic variables as array.
  20143. * @return array of graphic variables
  20144. * @protected
  20145. * @since 4.2.010 (2008-11-14)
  20146. */
  20147. protected function getGraphicVars() {
  20148. $grapvars = array(
  20149. 'FontFamily' => $this->FontFamily,
  20150. 'FontStyle' => $this->FontStyle,
  20151. 'FontSizePt' => $this->FontSizePt,
  20152. 'rMargin' => $this->rMargin,
  20153. 'lMargin' => $this->lMargin,
  20154. 'cell_padding' => $this->cell_padding,
  20155. 'cell_margin' => $this->cell_margin,
  20156. 'LineWidth' => $this->LineWidth,
  20157. 'linestyleWidth' => $this->linestyleWidth,
  20158. 'linestyleCap' => $this->linestyleCap,
  20159. 'linestyleJoin' => $this->linestyleJoin,
  20160. 'linestyleDash' => $this->linestyleDash,
  20161. 'textrendermode' => $this->textrendermode,
  20162. 'textstrokewidth' => $this->textstrokewidth,
  20163. 'DrawColor' => $this->DrawColor,
  20164. 'FillColor' => $this->FillColor,
  20165. 'TextColor' => $this->TextColor,
  20166. 'ColorFlag' => $this->ColorFlag,
  20167. 'bgcolor' => $this->bgcolor,
  20168. 'fgcolor' => $this->fgcolor,
  20169. 'htmlvspace' => $this->htmlvspace,
  20170. 'listindent' => $this->listindent,
  20171. 'listindentlevel' => $this->listindentlevel,
  20172. 'listnum' => $this->listnum,
  20173. 'listordered' => $this->listordered,
  20174. 'listcount' => $this->listcount,
  20175. 'lispacer' => $this->lispacer,
  20176. 'cell_height_ratio' => $this->cell_height_ratio,
  20177. 'font_stretching' => $this->font_stretching,
  20178. 'font_spacing' => $this->font_spacing,
  20179. 'alpha' => $this->alpha,
  20180. // extended
  20181. 'lasth' => $this->lasth,
  20182. 'tMargin' => $this->tMargin,
  20183. 'bMargin' => $this->bMargin,
  20184. 'AutoPageBreak' => $this->AutoPageBreak,
  20185. 'PageBreakTrigger' => $this->PageBreakTrigger,
  20186. 'x' => $this->x,
  20187. 'y' => $this->y,
  20188. 'w' => $this->w,
  20189. 'h' => $this->h,
  20190. 'wPt' => $this->wPt,
  20191. 'hPt' => $this->hPt,
  20192. 'fwPt' => $this->fwPt,
  20193. 'fhPt' => $this->fhPt,
  20194. 'page' => $this->page,
  20195. 'current_column' => $this->current_column,
  20196. 'num_columns' => $this->num_columns
  20197. );
  20198. return $grapvars;
  20199. }
  20200. /**
  20201. * Set graphic variables.
  20202. * @param array $gvars array of graphic variablesto restore
  20203. * @param boolean $extended if true restore extended graphic variables
  20204. * @protected
  20205. * @since 4.2.010 (2008-11-14)
  20206. */
  20207. protected function setGraphicVars($gvars, $extended=false) {
  20208. if ($this->state != 2) {
  20209. return;
  20210. }
  20211. $this->FontFamily = $gvars['FontFamily'];
  20212. $this->FontStyle = $gvars['FontStyle'];
  20213. $this->FontSizePt = $gvars['FontSizePt'];
  20214. $this->rMargin = $gvars['rMargin'];
  20215. $this->lMargin = $gvars['lMargin'];
  20216. $this->cell_padding = $gvars['cell_padding'];
  20217. $this->cell_margin = $gvars['cell_margin'];
  20218. $this->LineWidth = $gvars['LineWidth'];
  20219. $this->linestyleWidth = $gvars['linestyleWidth'];
  20220. $this->linestyleCap = $gvars['linestyleCap'];
  20221. $this->linestyleJoin = $gvars['linestyleJoin'];
  20222. $this->linestyleDash = $gvars['linestyleDash'];
  20223. $this->textrendermode = $gvars['textrendermode'];
  20224. $this->textstrokewidth = $gvars['textstrokewidth'];
  20225. $this->DrawColor = $gvars['DrawColor'];
  20226. $this->FillColor = $gvars['FillColor'];
  20227. $this->TextColor = $gvars['TextColor'];
  20228. $this->ColorFlag = $gvars['ColorFlag'];
  20229. $this->bgcolor = $gvars['bgcolor'];
  20230. $this->fgcolor = $gvars['fgcolor'];
  20231. $this->htmlvspace = $gvars['htmlvspace'];
  20232. $this->listindent = $gvars['listindent'];
  20233. $this->listindentlevel = $gvars['listindentlevel'];
  20234. $this->listnum = $gvars['listnum'];
  20235. $this->listordered = $gvars['listordered'];
  20236. $this->listcount = $gvars['listcount'];
  20237. $this->lispacer = $gvars['lispacer'];
  20238. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  20239. $this->font_stretching = $gvars['font_stretching'];
  20240. $this->font_spacing = $gvars['font_spacing'];
  20241. $this->alpha = $gvars['alpha'];
  20242. if ($extended) {
  20243. // restore extended values
  20244. $this->lasth = $gvars['lasth'];
  20245. $this->tMargin = $gvars['tMargin'];
  20246. $this->bMargin = $gvars['bMargin'];
  20247. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  20248. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  20249. $this->x = $gvars['x'];
  20250. $this->y = $gvars['y'];
  20251. $this->w = $gvars['w'];
  20252. $this->h = $gvars['h'];
  20253. $this->wPt = $gvars['wPt'];
  20254. $this->hPt = $gvars['hPt'];
  20255. $this->fwPt = $gvars['fwPt'];
  20256. $this->fhPt = $gvars['fhPt'];
  20257. $this->page = $gvars['page'];
  20258. $this->current_column = $gvars['current_column'];
  20259. $this->num_columns = $gvars['num_columns'];
  20260. }
  20261. $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  20262. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  20263. $this->setFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  20264. }
  20265. }
  20266. /**
  20267. * Outputs the "save graphics state" operator 'q'
  20268. * @protected
  20269. */
  20270. protected function _outSaveGraphicsState() {
  20271. $this->_out('q');
  20272. }
  20273. /**
  20274. * Outputs the "restore graphics state" operator 'Q'
  20275. * @protected
  20276. */
  20277. protected function _outRestoreGraphicsState() {
  20278. $this->_out('Q');
  20279. }
  20280. /**
  20281. * Set buffer content (always append data).
  20282. * @param string $data data
  20283. * @protected
  20284. * @since 4.5.000 (2009-01-02)
  20285. */
  20286. protected function setBuffer($data) {
  20287. $this->bufferlen += strlen($data);
  20288. $this->buffer .= $data;
  20289. }
  20290. /**
  20291. * Replace the buffer content
  20292. * @param string $data data
  20293. * @protected
  20294. * @since 5.5.000 (2010-06-22)
  20295. */
  20296. protected function replaceBuffer($data) {
  20297. $this->bufferlen = strlen($data);
  20298. $this->buffer = $data;
  20299. }
  20300. /**
  20301. * Get buffer content.
  20302. * @return string buffer content
  20303. * @protected
  20304. * @since 4.5.000 (2009-01-02)
  20305. */
  20306. protected function getBuffer() {
  20307. return $this->buffer;
  20308. }
  20309. /**
  20310. * Set page buffer content.
  20311. * @param int $page page number
  20312. * @param string $data page data
  20313. * @param boolean $append if true append data, false replace.
  20314. * @protected
  20315. * @since 4.5.000 (2008-12-31)
  20316. */
  20317. protected function setPageBuffer($page, $data, $append=false) {
  20318. if ($append) {
  20319. $this->pages[$page] .= $data;
  20320. } else {
  20321. $this->pages[$page] = $data;
  20322. }
  20323. if ($append AND isset($this->pagelen[$page])) {
  20324. $this->pagelen[$page] += strlen($data);
  20325. } else {
  20326. $this->pagelen[$page] = strlen($data);
  20327. }
  20328. }
  20329. /**
  20330. * Get page buffer content.
  20331. * @param int $page page number
  20332. * @return string page buffer content or false in case of error
  20333. * @protected
  20334. * @since 4.5.000 (2008-12-31)
  20335. */
  20336. protected function getPageBuffer($page) {
  20337. if (isset($this->pages[$page])) {
  20338. return $this->pages[$page];
  20339. }
  20340. return false;
  20341. }
  20342. /**
  20343. * Set image buffer content.
  20344. * @param string $image image key
  20345. * @param array $data image data
  20346. * @return int image index number
  20347. * @protected
  20348. * @since 4.5.000 (2008-12-31)
  20349. */
  20350. protected function setImageBuffer($image, $data) {
  20351. if (($data['i'] = array_search($image, $this->imagekeys)) === FALSE) {
  20352. $this->imagekeys[$this->numimages] = $image;
  20353. $data['i'] = $this->numimages;
  20354. ++$this->numimages;
  20355. }
  20356. $this->images[$image] = $data;
  20357. return $data['i'];
  20358. }
  20359. /**
  20360. * Set image buffer content for a specified sub-key.
  20361. * @param string $image image key
  20362. * @param string $key image sub-key
  20363. * @param array $data image data
  20364. * @protected
  20365. * @since 4.5.000 (2008-12-31)
  20366. */
  20367. protected function setImageSubBuffer($image, $key, $data) {
  20368. if (!isset($this->images[$image])) {
  20369. $this->setImageBuffer($image, array());
  20370. }
  20371. $this->images[$image][$key] = $data;
  20372. }
  20373. /**
  20374. * Get image buffer content.
  20375. * @param string $image image key
  20376. * @return string|false image buffer content or false in case of error
  20377. * @protected
  20378. * @since 4.5.000 (2008-12-31)
  20379. */
  20380. protected function getImageBuffer($image) {
  20381. if (isset($this->images[$image])) {
  20382. return $this->images[$image];
  20383. }
  20384. return false;
  20385. }
  20386. /**
  20387. * Set font buffer content.
  20388. * @param string $font font key
  20389. * @param array $data font data
  20390. * @protected
  20391. * @since 4.5.000 (2009-01-02)
  20392. */
  20393. protected function setFontBuffer($font, $data) {
  20394. $this->fonts[$font] = $data;
  20395. if (!in_array($font, $this->fontkeys)) {
  20396. $this->fontkeys[] = $font;
  20397. // store object ID for current font
  20398. ++$this->n;
  20399. $this->font_obj_ids[$font] = $this->n;
  20400. $this->setFontSubBuffer($font, 'n', $this->n);
  20401. }
  20402. }
  20403. /**
  20404. * Set font buffer content.
  20405. * @param string $font font key
  20406. * @param string $key font sub-key
  20407. * @param mixed $data font data
  20408. * @protected
  20409. * @since 4.5.000 (2009-01-02)
  20410. */
  20411. protected function setFontSubBuffer($font, $key, $data) {
  20412. if (!isset($this->fonts[$font])) {
  20413. $this->setFontBuffer($font, array());
  20414. }
  20415. $this->fonts[$font][$key] = $data;
  20416. }
  20417. /**
  20418. * Get font buffer content.
  20419. * @param string $font font key
  20420. * @return string|false font buffer content or false in case of error
  20421. * @protected
  20422. * @since 4.5.000 (2009-01-02)
  20423. */
  20424. protected function getFontBuffer($font) {
  20425. if (isset($this->fonts[$font])) {
  20426. return $this->fonts[$font];
  20427. }
  20428. return false;
  20429. }
  20430. /**
  20431. * Move a page to a previous position.
  20432. * @param int $frompage number of the source page
  20433. * @param int $topage number of the destination page (must be less than $frompage)
  20434. * @return bool true in case of success, false in case of error.
  20435. * @public
  20436. * @since 4.5.000 (2009-01-02)
  20437. */
  20438. public function movePage($frompage, $topage) {
  20439. if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
  20440. return false;
  20441. }
  20442. if ($frompage == $this->page) {
  20443. // close the page before moving it
  20444. $this->endPage();
  20445. }
  20446. // move all page-related states
  20447. $tmppage = $this->getPageBuffer($frompage);
  20448. $tmppagedim = $this->pagedim[$frompage];
  20449. $tmppagelen = $this->pagelen[$frompage];
  20450. $tmpintmrk = $this->intmrk[$frompage];
  20451. $tmpbordermrk = $this->bordermrk[$frompage];
  20452. $tmpcntmrk = $this->cntmrk[$frompage];
  20453. $tmppageobjects = $this->pageobjects[$frompage];
  20454. if (isset($this->footerpos[$frompage])) {
  20455. $tmpfooterpos = $this->footerpos[$frompage];
  20456. }
  20457. if (isset($this->footerlen[$frompage])) {
  20458. $tmpfooterlen = $this->footerlen[$frompage];
  20459. }
  20460. if (isset($this->transfmrk[$frompage])) {
  20461. $tmptransfmrk = $this->transfmrk[$frompage];
  20462. }
  20463. if (isset($this->PageAnnots[$frompage])) {
  20464. $tmpannots = $this->PageAnnots[$frompage];
  20465. }
  20466. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20467. for ($i = $frompage; $i > $topage; --$i) {
  20468. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
  20469. --$this->pagegroups[$this->newpagegroup[$i]];
  20470. break;
  20471. }
  20472. }
  20473. for ($i = $topage; $i > 0; --$i) {
  20474. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
  20475. ++$this->pagegroups[$this->newpagegroup[$i]];
  20476. break;
  20477. }
  20478. }
  20479. }
  20480. for ($i = $frompage; $i > $topage; --$i) {
  20481. $j = $i - 1;
  20482. // shift pages down
  20483. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20484. $this->pagedim[$i] = $this->pagedim[$j];
  20485. $this->pagelen[$i] = $this->pagelen[$j];
  20486. $this->intmrk[$i] = $this->intmrk[$j];
  20487. $this->bordermrk[$i] = $this->bordermrk[$j];
  20488. $this->cntmrk[$i] = $this->cntmrk[$j];
  20489. $this->pageobjects[$i] = $this->pageobjects[$j];
  20490. if (isset($this->footerpos[$j])) {
  20491. $this->footerpos[$i] = $this->footerpos[$j];
  20492. } elseif (isset($this->footerpos[$i])) {
  20493. unset($this->footerpos[$i]);
  20494. }
  20495. if (isset($this->footerlen[$j])) {
  20496. $this->footerlen[$i] = $this->footerlen[$j];
  20497. } elseif (isset($this->footerlen[$i])) {
  20498. unset($this->footerlen[$i]);
  20499. }
  20500. if (isset($this->transfmrk[$j])) {
  20501. $this->transfmrk[$i] = $this->transfmrk[$j];
  20502. } elseif (isset($this->transfmrk[$i])) {
  20503. unset($this->transfmrk[$i]);
  20504. }
  20505. if (isset($this->PageAnnots[$j])) {
  20506. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20507. } elseif (isset($this->PageAnnots[$i])) {
  20508. unset($this->PageAnnots[$i]);
  20509. }
  20510. if (isset($this->newpagegroup[$j])) {
  20511. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20512. unset($this->newpagegroup[$j]);
  20513. }
  20514. if ($this->currpagegroup == $j) {
  20515. $this->currpagegroup = $i;
  20516. }
  20517. }
  20518. $this->setPageBuffer($topage, $tmppage);
  20519. $this->pagedim[$topage] = $tmppagedim;
  20520. $this->pagelen[$topage] = $tmppagelen;
  20521. $this->intmrk[$topage] = $tmpintmrk;
  20522. $this->bordermrk[$topage] = $tmpbordermrk;
  20523. $this->cntmrk[$topage] = $tmpcntmrk;
  20524. $this->pageobjects[$topage] = $tmppageobjects;
  20525. if (isset($tmpfooterpos)) {
  20526. $this->footerpos[$topage] = $tmpfooterpos;
  20527. } elseif (isset($this->footerpos[$topage])) {
  20528. unset($this->footerpos[$topage]);
  20529. }
  20530. if (isset($tmpfooterlen)) {
  20531. $this->footerlen[$topage] = $tmpfooterlen;
  20532. } elseif (isset($this->footerlen[$topage])) {
  20533. unset($this->footerlen[$topage]);
  20534. }
  20535. if (isset($tmptransfmrk)) {
  20536. $this->transfmrk[$topage] = $tmptransfmrk;
  20537. } elseif (isset($this->transfmrk[$topage])) {
  20538. unset($this->transfmrk[$topage]);
  20539. }
  20540. if (isset($tmpannots)) {
  20541. $this->PageAnnots[$topage] = $tmpannots;
  20542. } elseif (isset($this->PageAnnots[$topage])) {
  20543. unset($this->PageAnnots[$topage]);
  20544. }
  20545. // adjust outlines
  20546. $tmpoutlines = $this->outlines;
  20547. foreach ($tmpoutlines as $key => $outline) {
  20548. if (!$outline['f']) {
  20549. if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  20550. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  20551. } elseif ($outline['p'] == $frompage) {
  20552. $this->outlines[$key]['p'] = $topage;
  20553. }
  20554. }
  20555. }
  20556. // adjust dests
  20557. $tmpdests = $this->dests;
  20558. foreach ($tmpdests as $key => $dest) {
  20559. if (!$dest['f']) {
  20560. if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
  20561. $this->dests[$key]['p'] = ($dest['p'] + 1);
  20562. } elseif ($dest['p'] == $frompage) {
  20563. $this->dests[$key]['p'] = $topage;
  20564. }
  20565. }
  20566. }
  20567. // adjust links
  20568. $tmplinks = $this->links;
  20569. foreach ($tmplinks as $key => $link) {
  20570. if (!$link['f']) {
  20571. if (($link['p'] >= $topage) AND ($link['p'] < $frompage)) {
  20572. $this->links[$key]['p'] = ($link['p'] + 1);
  20573. } elseif ($link['p'] == $frompage) {
  20574. $this->links[$key]['p'] = $topage;
  20575. }
  20576. }
  20577. }
  20578. // adjust javascript
  20579. $jfrompage = $frompage;
  20580. $jtopage = $topage;
  20581. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20582. foreach($pamatch[0] as $pk => $pmatch) {
  20583. $pagenum = intval($pamatch[3][$pk]) + 1;
  20584. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  20585. $newpage = ($pagenum + 1);
  20586. } elseif ($pagenum == $jfrompage) {
  20587. $newpage = $jtopage;
  20588. } else {
  20589. $newpage = $pagenum;
  20590. }
  20591. --$newpage;
  20592. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20593. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20594. }
  20595. unset($pamatch);
  20596. }
  20597. // return to last page
  20598. $this->lastPage(true);
  20599. return true;
  20600. }
  20601. /**
  20602. * Remove the specified page.
  20603. * @param int $page page to remove
  20604. * @return bool true in case of success, false in case of error.
  20605. * @public
  20606. * @since 4.6.004 (2009-04-23)
  20607. */
  20608. public function deletePage($page) {
  20609. if (($page < 1) OR ($page > $this->numpages)) {
  20610. return false;
  20611. }
  20612. // delete current page
  20613. unset($this->pages[$page]);
  20614. unset($this->pagedim[$page]);
  20615. unset($this->pagelen[$page]);
  20616. unset($this->intmrk[$page]);
  20617. unset($this->bordermrk[$page]);
  20618. unset($this->cntmrk[$page]);
  20619. foreach ($this->pageobjects[$page] as $oid) {
  20620. if (isset($this->offsets[$oid])){
  20621. unset($this->offsets[$oid]);
  20622. }
  20623. }
  20624. unset($this->pageobjects[$page]);
  20625. if (isset($this->footerpos[$page])) {
  20626. unset($this->footerpos[$page]);
  20627. }
  20628. if (isset($this->footerlen[$page])) {
  20629. unset($this->footerlen[$page]);
  20630. }
  20631. if (isset($this->transfmrk[$page])) {
  20632. unset($this->transfmrk[$page]);
  20633. }
  20634. if (isset($this->PageAnnots[$page])) {
  20635. unset($this->PageAnnots[$page]);
  20636. }
  20637. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20638. for ($i = $page; $i > 0; --$i) {
  20639. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
  20640. --$this->pagegroups[$this->newpagegroup[$i]];
  20641. break;
  20642. }
  20643. }
  20644. }
  20645. if (isset($this->pageopen[$page])) {
  20646. unset($this->pageopen[$page]);
  20647. }
  20648. if ($page < $this->numpages) {
  20649. // update remaining pages
  20650. for ($i = $page; $i < $this->numpages; ++$i) {
  20651. $j = $i + 1;
  20652. // shift pages
  20653. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20654. $this->pagedim[$i] = $this->pagedim[$j];
  20655. $this->pagelen[$i] = $this->pagelen[$j];
  20656. $this->intmrk[$i] = $this->intmrk[$j];
  20657. $this->bordermrk[$i] = $this->bordermrk[$j];
  20658. $this->cntmrk[$i] = $this->cntmrk[$j];
  20659. $this->pageobjects[$i] = $this->pageobjects[$j];
  20660. if (isset($this->footerpos[$j])) {
  20661. $this->footerpos[$i] = $this->footerpos[$j];
  20662. } elseif (isset($this->footerpos[$i])) {
  20663. unset($this->footerpos[$i]);
  20664. }
  20665. if (isset($this->footerlen[$j])) {
  20666. $this->footerlen[$i] = $this->footerlen[$j];
  20667. } elseif (isset($this->footerlen[$i])) {
  20668. unset($this->footerlen[$i]);
  20669. }
  20670. if (isset($this->transfmrk[$j])) {
  20671. $this->transfmrk[$i] = $this->transfmrk[$j];
  20672. } elseif (isset($this->transfmrk[$i])) {
  20673. unset($this->transfmrk[$i]);
  20674. }
  20675. if (isset($this->PageAnnots[$j])) {
  20676. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20677. } elseif (isset($this->PageAnnots[$i])) {
  20678. unset($this->PageAnnots[$i]);
  20679. }
  20680. if (isset($this->newpagegroup[$j])) {
  20681. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20682. unset($this->newpagegroup[$j]);
  20683. }
  20684. if ($this->currpagegroup == $j) {
  20685. $this->currpagegroup = $i;
  20686. }
  20687. if (isset($this->pageopen[$j])) {
  20688. $this->pageopen[$i] = $this->pageopen[$j];
  20689. } elseif (isset($this->pageopen[$i])) {
  20690. unset($this->pageopen[$i]);
  20691. }
  20692. }
  20693. // remove last page
  20694. unset($this->pages[$this->numpages]);
  20695. unset($this->pagedim[$this->numpages]);
  20696. unset($this->pagelen[$this->numpages]);
  20697. unset($this->intmrk[$this->numpages]);
  20698. unset($this->bordermrk[$this->numpages]);
  20699. unset($this->cntmrk[$this->numpages]);
  20700. foreach ($this->pageobjects[$this->numpages] as $oid) {
  20701. if (isset($this->offsets[$oid])){
  20702. unset($this->offsets[$oid]);
  20703. }
  20704. }
  20705. unset($this->pageobjects[$this->numpages]);
  20706. if (isset($this->footerpos[$this->numpages])) {
  20707. unset($this->footerpos[$this->numpages]);
  20708. }
  20709. if (isset($this->footerlen[$this->numpages])) {
  20710. unset($this->footerlen[$this->numpages]);
  20711. }
  20712. if (isset($this->transfmrk[$this->numpages])) {
  20713. unset($this->transfmrk[$this->numpages]);
  20714. }
  20715. if (isset($this->PageAnnots[$this->numpages])) {
  20716. unset($this->PageAnnots[$this->numpages]);
  20717. }
  20718. if (isset($this->newpagegroup[$this->numpages])) {
  20719. unset($this->newpagegroup[$this->numpages]);
  20720. }
  20721. if ($this->currpagegroup == $this->numpages) {
  20722. $this->currpagegroup = ($this->numpages - 1);
  20723. }
  20724. if (isset($this->pagegroups[$this->numpages])) {
  20725. unset($this->pagegroups[$this->numpages]);
  20726. }
  20727. if (isset($this->pageopen[$this->numpages])) {
  20728. unset($this->pageopen[$this->numpages]);
  20729. }
  20730. }
  20731. --$this->numpages;
  20732. $this->page = $this->numpages;
  20733. // adjust outlines
  20734. $tmpoutlines = $this->outlines;
  20735. foreach ($tmpoutlines as $key => $outline) {
  20736. if (!$outline['f']) {
  20737. if ($outline['p'] > $page) {
  20738. $this->outlines[$key]['p'] = $outline['p'] - 1;
  20739. } elseif ($outline['p'] == $page) {
  20740. unset($this->outlines[$key]);
  20741. }
  20742. }
  20743. }
  20744. // adjust dests
  20745. $tmpdests = $this->dests;
  20746. foreach ($tmpdests as $key => $dest) {
  20747. if (!$dest['f']) {
  20748. if ($dest['p'] > $page) {
  20749. $this->dests[$key]['p'] = $dest['p'] - 1;
  20750. } elseif ($dest['p'] == $page) {
  20751. unset($this->dests[$key]);
  20752. }
  20753. }
  20754. }
  20755. // adjust links
  20756. $tmplinks = $this->links;
  20757. foreach ($tmplinks as $key => $link) {
  20758. if (!$link['f']) {
  20759. if ($link['p'] > $page) {
  20760. $this->links[$key]['p'] = $link['p'] - 1;
  20761. } elseif ($link['p'] == $page) {
  20762. unset($this->links[$key]);
  20763. }
  20764. }
  20765. }
  20766. // adjust javascript
  20767. $jpage = $page;
  20768. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20769. foreach($pamatch[0] as $pk => $pmatch) {
  20770. $pagenum = intval($pamatch[3][$pk]) + 1;
  20771. if ($pagenum >= $jpage) {
  20772. $newpage = ($pagenum - 1);
  20773. } elseif ($pagenum == $jpage) {
  20774. $newpage = 1;
  20775. } else {
  20776. $newpage = $pagenum;
  20777. }
  20778. --$newpage;
  20779. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20780. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20781. }
  20782. unset($pamatch);
  20783. }
  20784. // return to last page
  20785. if ($this->numpages > 0) {
  20786. $this->lastPage(true);
  20787. }
  20788. return true;
  20789. }
  20790. /**
  20791. * Clone the specified page to a new page.
  20792. * @param int $page number of page to copy (0 = current page)
  20793. * @return bool true in case of success, false in case of error.
  20794. * @public
  20795. * @since 4.9.015 (2010-04-20)
  20796. */
  20797. public function copyPage($page=0) {
  20798. if ($page == 0) {
  20799. // default value
  20800. $page = $this->page;
  20801. }
  20802. if (($page < 1) OR ($page > $this->numpages)) {
  20803. return false;
  20804. }
  20805. // close the last page
  20806. $this->endPage();
  20807. // copy all page-related states
  20808. ++$this->numpages;
  20809. $this->page = $this->numpages;
  20810. $this->setPageBuffer($this->page, $this->getPageBuffer($page));
  20811. $this->pagedim[$this->page] = $this->pagedim[$page];
  20812. $this->pagelen[$this->page] = $this->pagelen[$page];
  20813. $this->intmrk[$this->page] = $this->intmrk[$page];
  20814. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  20815. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  20816. $this->pageobjects[$this->page] = $this->pageobjects[$page];
  20817. $this->pageopen[$this->page] = false;
  20818. if (isset($this->footerpos[$page])) {
  20819. $this->footerpos[$this->page] = $this->footerpos[$page];
  20820. }
  20821. if (isset($this->footerlen[$page])) {
  20822. $this->footerlen[$this->page] = $this->footerlen[$page];
  20823. }
  20824. if (isset($this->transfmrk[$page])) {
  20825. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  20826. }
  20827. if (isset($this->PageAnnots[$page])) {
  20828. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  20829. }
  20830. if (isset($this->newpagegroup[$page])) {
  20831. // start a new group
  20832. $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
  20833. $this->currpagegroup = $this->newpagegroup[$this->page];
  20834. $this->pagegroups[$this->currpagegroup] = 1;
  20835. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  20836. ++$this->pagegroups[$this->currpagegroup];
  20837. }
  20838. // copy outlines
  20839. $tmpoutlines = $this->outlines;
  20840. foreach ($tmpoutlines as $key => $outline) {
  20841. if ($outline['p'] == $page) {
  20842. $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']);
  20843. }
  20844. }
  20845. // copy links
  20846. $tmplinks = $this->links;
  20847. foreach ($tmplinks as $key => $link) {
  20848. if ($link['p'] == $page) {
  20849. $this->links[] = array('p' => $this->page, 'y' => $link['y'], 'f' => $link['f']);
  20850. }
  20851. }
  20852. // return to last page
  20853. $this->lastPage(true);
  20854. return true;
  20855. }
  20856. /**
  20857. * Output a Table of Content Index (TOC).
  20858. * This method must be called after all Bookmarks were set.
  20859. * Before calling this method you have to open the page using the addTOCPage() method.
  20860. * After calling this method you have to call endTOCPage() to close the TOC page.
  20861. * You can override this method to achieve different styles.
  20862. * @param int|null $page page number where this TOC should be inserted (leave empty for current page).
  20863. * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment).
  20864. * @param string $filler string used to fill the space between text and page number.
  20865. * @param string $toc_name name to use for TOC bookmark.
  20866. * @param string $style Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20867. * @param array $color RGB color array for bookmark title (values from 0 to 255).
  20868. * @public
  20869. * @author Nicola Asuni
  20870. * @since 4.5.000 (2009-01-02)
  20871. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  20872. */
  20873. public function addTOC($page=null, $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
  20874. $fontsize = $this->FontSizePt;
  20875. $fontfamily = $this->FontFamily;
  20876. $fontstyle = $this->FontStyle;
  20877. $w = $this->w - $this->lMargin - $this->rMargin;
  20878. $spacer = $this->GetStringWidth(chr(32)) * 4;
  20879. $lmargin = $this->lMargin;
  20880. $rmargin = $this->rMargin;
  20881. $x_start = $this->GetX();
  20882. $page_first = $this->page;
  20883. $current_page = $this->page;
  20884. $page_fill_start = false;
  20885. $page_fill_end = false;
  20886. $current_column = $this->current_column;
  20887. if (TCPDF_STATIC::empty_string($numbersfont)) {
  20888. $numbersfont = $this->default_monospaced_font;
  20889. }
  20890. if (TCPDF_STATIC::empty_string($filler)) {
  20891. $filler = ' ';
  20892. }
  20893. if (TCPDF_STATIC::empty_string($page)) {
  20894. $gap = ' ';
  20895. } else {
  20896. $gap = '';
  20897. if ($page < 1) {
  20898. $page = 1;
  20899. }
  20900. }
  20901. $this->setFont($numbersfont, $fontstyle, $fontsize);
  20902. $numwidth = $this->GetStringWidth('00000');
  20903. $maxpage = 0; //used for pages on attached documents
  20904. foreach ($this->outlines as $key => $outline) {
  20905. // check for extra pages (used for attachments)
  20906. if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
  20907. $outline['p'] += ($this->page - $page_first);
  20908. }
  20909. if ($this->rtl) {
  20910. $aligntext = 'R';
  20911. $alignnum = 'L';
  20912. } else {
  20913. $aligntext = 'L';
  20914. $alignnum = 'R';
  20915. }
  20916. if ($outline['l'] == 0) {
  20917. $this->setFont($fontfamily, $outline['s'].'B', $fontsize);
  20918. } else {
  20919. $this->setFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
  20920. }
  20921. $this->setTextColorArray($outline['c']);
  20922. // check for page break
  20923. $this->checkPageBreak(2 * $this->getCellHeight($this->FontSize));
  20924. // set margins and X position
  20925. if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  20926. $this->lMargin = $lmargin;
  20927. $this->rMargin = $rmargin;
  20928. } else {
  20929. if ($this->current_column != $current_column) {
  20930. if ($this->rtl) {
  20931. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  20932. } else {
  20933. $x_start = $this->columns[$this->current_column]['x'];
  20934. }
  20935. }
  20936. $lmargin = $this->lMargin;
  20937. $rmargin = $this->rMargin;
  20938. $current_page = $this->page;
  20939. $current_column = $this->current_column;
  20940. }
  20941. $this->setX($x_start);
  20942. $indent = ($spacer * $outline['l']);
  20943. if ($this->rtl) {
  20944. $this->x -= $indent;
  20945. $this->rMargin = $this->w - $this->x;
  20946. } else {
  20947. $this->x += $indent;
  20948. $this->lMargin = $this->x;
  20949. }
  20950. $link = $this->AddLink();
  20951. $this->setLink($link, $outline['y'], $outline['p']);
  20952. // write the text
  20953. if ($this->rtl) {
  20954. $txt = ' '.$outline['t'];
  20955. } else {
  20956. $txt = $outline['t'].' ';
  20957. }
  20958. $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
  20959. if ($this->rtl) {
  20960. $tw = $this->x - $this->lMargin;
  20961. } else {
  20962. $tw = $this->w - $this->rMargin - $this->x;
  20963. }
  20964. $this->setFont($numbersfont, $fontstyle, $fontsize);
  20965. if (TCPDF_STATIC::empty_string($page)) {
  20966. $pagenum = $outline['p'];
  20967. } else {
  20968. // placemark to be replaced with the correct number
  20969. $pagenum = '{#'.($outline['p']).'}';
  20970. if ($this->isUnicodeFont()) {
  20971. $pagenum = '{'.$pagenum.'}';
  20972. }
  20973. $maxpage = max($maxpage, $outline['p']);
  20974. }
  20975. $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
  20976. $wfiller = $this->GetStringWidth($filler);
  20977. if ($wfiller > 0) {
  20978. $numfills = floor($fw / $wfiller);
  20979. } else {
  20980. $numfills = 0;
  20981. }
  20982. if ($numfills > 0) {
  20983. $rowfill = str_repeat($filler, $numfills);
  20984. } else {
  20985. $rowfill = '';
  20986. }
  20987. if ($this->rtl) {
  20988. $pagenum = $pagenum.$gap.$rowfill;
  20989. } else {
  20990. $pagenum = $rowfill.$gap.$pagenum;
  20991. }
  20992. // write the number
  20993. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  20994. }
  20995. $page_last = $this->getPage();
  20996. $numpages = ($page_last - $page_first + 1);
  20997. // account for booklet mode
  20998. if ($this->booklet) {
  20999. // check if a blank page is required before TOC
  21000. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  21001. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  21002. if ($page_fill_start) {
  21003. // add a page at the end (to be moved before TOC)
  21004. $this->addPage();
  21005. ++$page_last;
  21006. ++$numpages;
  21007. }
  21008. if ($page_fill_end) {
  21009. // add a page at the end
  21010. $this->addPage();
  21011. ++$page_last;
  21012. ++$numpages;
  21013. }
  21014. }
  21015. $maxpage = max($maxpage, $page_last);
  21016. if (!TCPDF_STATIC::empty_string($page)) {
  21017. for ($p = $page_first; $p <= $page_last; ++$p) {
  21018. // get page data
  21019. $temppage = $this->getPageBuffer($p);
  21020. for ($n = 1; $n <= $maxpage; ++$n) {
  21021. // update page numbers
  21022. $a = '{#'.$n.'}';
  21023. // get page number aliases
  21024. $pnalias = $this->getInternalPageNumberAliases($a);
  21025. // calculate replacement number
  21026. if (($n >= $page) AND ($n <= $this->numpages)) {
  21027. $np = $n + $numpages;
  21028. } else {
  21029. $np = $n;
  21030. }
  21031. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  21032. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  21033. // replace aliases with numbers
  21034. foreach ($pnalias['u'] as $u) {
  21035. $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
  21036. if ($this->rtl) {
  21037. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  21038. } else {
  21039. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  21040. }
  21041. $temppage = str_replace($u, $nr, $temppage);
  21042. }
  21043. foreach ($pnalias['a'] as $a) {
  21044. $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
  21045. if ($this->rtl) {
  21046. $nr = $na.' '.$sfill;
  21047. } else {
  21048. $nr = $sfill.' '.$na;
  21049. }
  21050. $temppage = str_replace($a, $nr, $temppage);
  21051. }
  21052. }
  21053. // save changes
  21054. $this->setPageBuffer($p, $temppage);
  21055. }
  21056. // move pages
  21057. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  21058. if ($page_fill_start) {
  21059. $this->movePage($page_last, $page_first);
  21060. }
  21061. for ($i = 0; $i < $numpages; ++$i) {
  21062. $this->movePage($page_last, $page);
  21063. }
  21064. }
  21065. }
  21066. /**
  21067. * Output a Table Of Content Index (TOC) using HTML templates.
  21068. * This method must be called after all Bookmarks were set.
  21069. * Before calling this method you have to open the page using the addTOCPage() method.
  21070. * After calling this method you have to call endTOCPage() to close the TOC page.
  21071. * @param int|null $page page number where this TOC should be inserted (leave empty for current page).
  21072. * @param string $toc_name name to use for TOC bookmark.
  21073. * @param array $templates array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  21074. * @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)
  21075. * @param string $style Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  21076. * @param array $color RGB color array for title (values from 0 to 255).
  21077. * @public
  21078. * @author Nicola Asuni
  21079. * @since 5.0.001 (2010-05-06)
  21080. * @see addTOCPage(), endTOCPage(), addTOC()
  21081. */
  21082. public function addHTMLTOC($page=null, $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
  21083. $filler = ' ';
  21084. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  21085. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  21086. // set new style for link
  21087. $this->htmlLinkColorArray = array();
  21088. $this->htmlLinkFontStyle = '';
  21089. $page_first = $this->getPage();
  21090. $page_fill_start = false;
  21091. $page_fill_end = false;
  21092. // get the font type used for numbers in each template
  21093. $current_font = $this->FontFamily;
  21094. foreach ($templates as $level => $html) {
  21095. $dom = $this->getHtmlDomArray($html);
  21096. foreach ($dom as $key => $value) {
  21097. if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  21098. $this->setFont($dom[($key - 1)]['fontname']);
  21099. $templates['F'.$level] = $this->isUnicodeFont();
  21100. }
  21101. }
  21102. }
  21103. $this->setFont($current_font);
  21104. $maxpage = 0; //used for pages on attached documents
  21105. foreach ($this->outlines as $key => $outline) {
  21106. // get HTML template
  21107. $row = $templates[$outline['l']];
  21108. if (TCPDF_STATIC::empty_string($page)) {
  21109. $pagenum = $outline['p'];
  21110. } else {
  21111. // placemark to be replaced with the correct number
  21112. $pagenum = '{#'.($outline['p']).'}';
  21113. if (isset($templates['F'.$outline['l']]) && $templates['F'.$outline['l']]) {
  21114. $pagenum = '{'.$pagenum.'}';
  21115. }
  21116. $maxpage = max($maxpage, $outline['p']);
  21117. }
  21118. // replace templates with current values
  21119. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  21120. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  21121. // add link to page
  21122. $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  21123. // write bookmark entry
  21124. $this->writeHTML($row, false, false, true, false, '');
  21125. }
  21126. // restore link styles
  21127. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  21128. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  21129. // move TOC page and replace numbers
  21130. $page_last = $this->getPage();
  21131. $numpages = ($page_last - $page_first + 1);
  21132. // account for booklet mode
  21133. if ($this->booklet) {
  21134. // check if a blank page is required before TOC
  21135. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  21136. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  21137. if ($page_fill_start) {
  21138. // add a page at the end (to be moved before TOC)
  21139. $this->addPage();
  21140. ++$page_last;
  21141. ++$numpages;
  21142. }
  21143. if ($page_fill_end) {
  21144. // add a page at the end
  21145. $this->addPage();
  21146. ++$page_last;
  21147. ++$numpages;
  21148. }
  21149. }
  21150. $maxpage = max($maxpage, $page_last);
  21151. if (!TCPDF_STATIC::empty_string($page)) {
  21152. for ($p = $page_first; $p <= $page_last; ++$p) {
  21153. // get page data
  21154. $temppage = $this->getPageBuffer($p);
  21155. for ($n = 1; $n <= $maxpage; ++$n) {
  21156. // update page numbers
  21157. $a = '{#'.$n.'}';
  21158. // get page number aliases
  21159. $pnalias = $this->getInternalPageNumberAliases($a);
  21160. // calculate replacement number
  21161. if ($n >= $page) {
  21162. $np = $n + $numpages;
  21163. } else {
  21164. $np = $n;
  21165. }
  21166. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  21167. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  21168. // replace aliases with numbers
  21169. foreach ($pnalias['u'] as $u) {
  21170. if ($correct_align) {
  21171. $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
  21172. if ($this->rtl) {
  21173. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  21174. } else {
  21175. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  21176. }
  21177. } else {
  21178. $nr = $nu;
  21179. }
  21180. $temppage = str_replace($u, $nr, $temppage);
  21181. }
  21182. foreach ($pnalias['a'] as $a) {
  21183. if ($correct_align) {
  21184. $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
  21185. if ($this->rtl) {
  21186. $nr = $na.' '.$sfill;
  21187. } else {
  21188. $nr = $sfill.' '.$na;
  21189. }
  21190. } else {
  21191. $nr = $na;
  21192. }
  21193. $temppage = str_replace($a, $nr, $temppage);
  21194. }
  21195. }
  21196. // save changes
  21197. $this->setPageBuffer($p, $temppage);
  21198. }
  21199. // move pages
  21200. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  21201. if ($page_fill_start) {
  21202. $this->movePage($page_last, $page_first);
  21203. }
  21204. for ($i = 0; $i < $numpages; ++$i) {
  21205. $this->movePage($page_last, $page);
  21206. }
  21207. }
  21208. }
  21209. /**
  21210. * Stores a copy of the current TCPDF object used for undo operation.
  21211. * @public
  21212. * @since 4.5.029 (2009-03-19)
  21213. */
  21214. public function startTransaction() {
  21215. if (isset($this->objcopy)) {
  21216. // remove previous copy
  21217. $this->commitTransaction();
  21218. }
  21219. // record current page number and Y position
  21220. $this->start_transaction_page = $this->page;
  21221. $this->start_transaction_y = $this->y;
  21222. // clone current object
  21223. $this->objcopy = TCPDF_STATIC::objclone($this);
  21224. }
  21225. /**
  21226. * Delete the copy of the current TCPDF object used for undo operation.
  21227. * @public
  21228. * @since 4.5.029 (2009-03-19)
  21229. */
  21230. public function commitTransaction() {
  21231. if (isset($this->objcopy)) {
  21232. $this->objcopy->_destroy(true, true);
  21233. /* The unique file_id should not be used during cleanup again */
  21234. $this->objcopy->file_id = NULL;
  21235. unset($this->objcopy);
  21236. }
  21237. }
  21238. /**
  21239. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  21240. * @param boolean $self if true restores current class object to previous state without the need of reassignment via the returned value.
  21241. * @return TCPDF object.
  21242. * @public
  21243. * @since 4.5.029 (2009-03-19)
  21244. */
  21245. public function rollbackTransaction($self=false) {
  21246. if (!isset($this->objcopy)) {
  21247. return $this;
  21248. }
  21249. $file_id = $this->file_id;
  21250. $objcopy = $this->objcopy;
  21251. $this->_destroy(true, true);
  21252. if ($self) {
  21253. $objvars = get_object_vars($objcopy);
  21254. foreach ($objvars as $key => $value) {
  21255. $this->$key = $value;
  21256. }
  21257. $objcopy->_destroy(true, true);
  21258. unset($objcopy);
  21259. return $this;
  21260. }
  21261. $this->file_id = $file_id;
  21262. return $objcopy;
  21263. }
  21264. // --- MULTI COLUMNS METHODS -----------------------
  21265. /**
  21266. * Set multiple columns of the same size
  21267. * @param int $numcols number of columns (set to zero to disable columns mode)
  21268. * @param int $width column width
  21269. * @param int|null $y column starting Y position (leave empty for current Y position)
  21270. * @public
  21271. * @since 4.9.001 (2010-03-28)
  21272. */
  21273. public function setEqualColumns($numcols=0, $width=0, $y=null) {
  21274. $this->columns = array();
  21275. if ($numcols < 2) {
  21276. $numcols = 0;
  21277. $this->columns = array();
  21278. } else {
  21279. // maximum column width
  21280. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  21281. if (($width == 0) OR ($width > $maxwidth)) {
  21282. $width = $maxwidth;
  21283. }
  21284. if (TCPDF_STATIC::empty_string($y)) {
  21285. $y = $this->y;
  21286. }
  21287. // space between columns
  21288. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  21289. // fill the columns array (with, space, starting Y position)
  21290. for ($i = 0; $i < $numcols; ++$i) {
  21291. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  21292. }
  21293. }
  21294. $this->num_columns = $numcols;
  21295. $this->current_column = 0;
  21296. $this->column_start_page = $this->page;
  21297. $this->selectColumn(0);
  21298. }
  21299. /**
  21300. * Remove columns and reset page margins.
  21301. * @public
  21302. * @since 5.9.072 (2011-04-26)
  21303. */
  21304. public function resetColumns() {
  21305. $this->lMargin = $this->original_lMargin;
  21306. $this->rMargin = $this->original_rMargin;
  21307. $this->setEqualColumns();
  21308. }
  21309. /**
  21310. * Set columns array.
  21311. * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  21312. * @param array $columns
  21313. * @public
  21314. * @since 4.9.001 (2010-03-28)
  21315. */
  21316. public function setColumnsArray($columns) {
  21317. $this->columns = $columns;
  21318. $this->num_columns = count($columns);
  21319. $this->current_column = 0;
  21320. $this->column_start_page = $this->page;
  21321. $this->selectColumn(0);
  21322. }
  21323. /**
  21324. * Set position at a given column
  21325. * @param int|null $col column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  21326. * @public
  21327. * @since 4.9.001 (2010-03-28)
  21328. */
  21329. public function selectColumn($col=null) {
  21330. if (TCPDF_STATIC::empty_string($col)) {
  21331. $col = $this->current_column;
  21332. } elseif ($col >= $this->num_columns) {
  21333. $col = 0;
  21334. }
  21335. $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  21336. $enable_thead = false;
  21337. if ($this->num_columns > 1) {
  21338. if ($col != $this->current_column) {
  21339. // move Y pointer at the top of the column
  21340. if ($this->column_start_page == $this->page) {
  21341. $this->y = $this->columns[$col]['y'];
  21342. } else {
  21343. $this->y = $this->tMargin;
  21344. }
  21345. // Avoid to write table headers more than once
  21346. if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
  21347. $enable_thead = true;
  21348. $this->maxselcol['page'] = $this->page;
  21349. $this->maxselcol['column'] = $col;
  21350. }
  21351. }
  21352. $xshift = $this->colxshift;
  21353. // set X position of the current column by case
  21354. $listindent = ($this->listindentlevel * $this->listindent);
  21355. // calculate column X position
  21356. $colpos = 0;
  21357. for ($i = 0; $i < $col; ++$i) {
  21358. $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
  21359. }
  21360. if ($this->rtl) {
  21361. $x = $this->w - $this->original_rMargin - $colpos;
  21362. $this->rMargin = ($this->w - $x + $listindent);
  21363. $this->lMargin = ($x - $this->columns[$col]['w']);
  21364. $this->x = $x - $listindent;
  21365. } else {
  21366. $x = $this->original_lMargin + $colpos;
  21367. $this->lMargin = ($x + $listindent);
  21368. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  21369. $this->x = $x + $listindent;
  21370. }
  21371. $this->columns[$col]['x'] = $x;
  21372. }
  21373. $this->current_column = $col;
  21374. // fix for HTML mode
  21375. $this->newline = true;
  21376. // print HTML table header (if any)
  21377. if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) {
  21378. if ($enable_thead) {
  21379. // print table header
  21380. $this->writeHTML($this->thead, false, false, false, false, '');
  21381. $this->y += $xshift['s']['V'];
  21382. // store end of header position
  21383. if (!isset($this->columns[$col]['th'])) {
  21384. $this->columns[$col]['th'] = array();
  21385. }
  21386. $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  21387. $this->lasth = 0;
  21388. } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  21389. $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
  21390. }
  21391. }
  21392. // account for an html table cell over multiple columns
  21393. if ($this->rtl) {
  21394. $this->rMargin += $xshift['x'];
  21395. $this->x -= ($xshift['x'] + $xshift['p']['R']);
  21396. } else {
  21397. $this->lMargin += $xshift['x'];
  21398. $this->x += $xshift['x'] + $xshift['p']['L'];
  21399. }
  21400. }
  21401. /**
  21402. * Return the current column number
  21403. * @return int current column number
  21404. * @public
  21405. * @since 5.5.011 (2010-07-08)
  21406. */
  21407. public function getColumn() {
  21408. return $this->current_column;
  21409. }
  21410. /**
  21411. * Return the current number of columns.
  21412. * @return int number of columns
  21413. * @public
  21414. * @since 5.8.018 (2010-08-25)
  21415. */
  21416. public function getNumberOfColumns() {
  21417. return $this->num_columns;
  21418. }
  21419. /**
  21420. * Set Text rendering mode.
  21421. * @param int $stroke outline size in user units (0 = disable).
  21422. * @param boolean $fill if true fills the text (default).
  21423. * @param boolean $clip if true activate clipping mode
  21424. * @public
  21425. * @since 4.9.008 (2009-04-02)
  21426. */
  21427. public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
  21428. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  21429. // convert text rendering parameters
  21430. if ($stroke < 0 || !is_numeric($stroke)) {
  21431. $stroke = 0;
  21432. }
  21433. if ($fill === true) {
  21434. if ($stroke > 0) {
  21435. if ($clip === true) {
  21436. // Fill, then stroke text and add to path for clipping
  21437. $textrendermode = 6;
  21438. } else {
  21439. // Fill, then stroke text
  21440. $textrendermode = 2;
  21441. }
  21442. $textstrokewidth = $stroke;
  21443. } else {
  21444. if ($clip === true) {
  21445. // Fill text and add to path for clipping
  21446. $textrendermode = 4;
  21447. } else {
  21448. // Fill text
  21449. $textrendermode = 0;
  21450. }
  21451. }
  21452. } else {
  21453. if ($stroke > 0) {
  21454. if ($clip === true) {
  21455. // Stroke text and add to path for clipping
  21456. $textrendermode = 5;
  21457. } else {
  21458. // Stroke text
  21459. $textrendermode = 1;
  21460. }
  21461. $textstrokewidth = $stroke;
  21462. } else {
  21463. if ($clip === true) {
  21464. // Add text to path for clipping
  21465. $textrendermode = 7;
  21466. } else {
  21467. // Neither fill nor stroke text (invisible)
  21468. $textrendermode = 3;
  21469. }
  21470. }
  21471. }
  21472. $this->textrendermode = $textrendermode;
  21473. $this->textstrokewidth = $stroke;
  21474. }
  21475. /**
  21476. * Set parameters for drop shadow effect for text.
  21477. * @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.
  21478. * @since 5.9.174 (2012-07-25)
  21479. * @public
  21480. */
  21481. public function setTextShadow($params=array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal')) {
  21482. if (isset($params['enabled'])) {
  21483. $this->txtshadow['enabled'] = $params['enabled']?true:false;
  21484. } else {
  21485. $this->txtshadow['enabled'] = false;
  21486. }
  21487. if (isset($params['depth_w'])) {
  21488. $this->txtshadow['depth_w'] = floatval($params['depth_w']);
  21489. } else {
  21490. $this->txtshadow['depth_w'] = 0;
  21491. }
  21492. if (isset($params['depth_h'])) {
  21493. $this->txtshadow['depth_h'] = floatval($params['depth_h']);
  21494. } else {
  21495. $this->txtshadow['depth_h'] = 0;
  21496. }
  21497. if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
  21498. $this->txtshadow['color'] = $params['color'];
  21499. } else {
  21500. $this->txtshadow['color'] = $this->strokecolor;
  21501. }
  21502. if (isset($params['opacity'])) {
  21503. $this->txtshadow['opacity'] = min(1, max(0, floatval($params['opacity'])));
  21504. } else {
  21505. $this->txtshadow['opacity'] = 1;
  21506. }
  21507. 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'))) {
  21508. $this->txtshadow['blend_mode'] = $params['blend_mode'];
  21509. } else {
  21510. $this->txtshadow['blend_mode'] = 'Normal';
  21511. }
  21512. if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
  21513. $this->txtshadow['enabled'] = false;
  21514. }
  21515. }
  21516. /**
  21517. * Return the text shadow parameters array.
  21518. * @return array array of parameters.
  21519. * @since 5.9.174 (2012-07-25)
  21520. * @public
  21521. */
  21522. public function getTextShadow() {
  21523. return $this->txtshadow;
  21524. }
  21525. /**
  21526. * Returns an array of chars containing soft hyphens.
  21527. * @param array $word array of chars
  21528. * @param array $patterns Array of hypenation patterns.
  21529. * @param array $dictionary Array of words to be returned without applying the hyphenation algorithm.
  21530. * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
  21531. * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
  21532. * @param int $charmin Minimum word length to apply the hyphenation algorithm.
  21533. * @param int $charmax Maximum length of broken piece of word.
  21534. * @return array text with soft hyphens
  21535. * @author Nicola Asuni
  21536. * @since 4.9.012 (2010-04-12)
  21537. * @protected
  21538. */
  21539. protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21540. $hyphenword = array(); // hyphens positions
  21541. $numchars = count($word);
  21542. if ($numchars <= $charmin) {
  21543. return $word;
  21544. }
  21545. $word_string = TCPDF_FONTS::UTF8ArrSubString($word, '', '', $this->isunicode);
  21546. // some words will be returned as-is
  21547. $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})(\]?)$/';
  21548. if (preg_match($pattern, $word_string) > 0) {
  21549. // email
  21550. return $word;
  21551. }
  21552. $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})(\]?)$/';
  21553. if (preg_match($pattern, $word_string) > 0) {
  21554. // URL
  21555. return $word;
  21556. }
  21557. if (isset($dictionary[$word_string])) {
  21558. return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont);
  21559. }
  21560. // surround word with '_' characters
  21561. $tmpword = array_merge(array(46), $word, array(46));
  21562. $tmpnumchars = $numchars + 2;
  21563. $maxpos = $tmpnumchars - 1;
  21564. for ($pos = 0; $pos < $maxpos; ++$pos) {
  21565. $imax = min(($tmpnumchars - $pos), $charmax);
  21566. for ($i = 1; $i <= $imax; ++$i) {
  21567. $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode));
  21568. if (isset($patterns[$subword])) {
  21569. $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont);
  21570. $pattern_length = count($pattern);
  21571. $digits = 1;
  21572. for ($j = 0; $j < $pattern_length; ++$j) {
  21573. // check if $pattern[$j] is a number = hyphenation level (only numbers from 1 to 5 are valid)
  21574. if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  21575. if ($j == 0) {
  21576. $zero = $pos - 1;
  21577. } else {
  21578. $zero = $pos + $j - $digits;
  21579. }
  21580. // get hyphenation level
  21581. $level = ($pattern[$j] - 48);
  21582. // if two levels from two different patterns match at the same point, the higher one is selected.
  21583. if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] < $level)) {
  21584. $hyphenword[$zero] = $level;
  21585. }
  21586. ++$digits;
  21587. }
  21588. }
  21589. }
  21590. }
  21591. }
  21592. $inserted = 0;
  21593. $maxpos = $numchars - $rightmin;
  21594. for ($i = $leftmin; $i <= $maxpos; ++$i) {
  21595. // only odd levels indicate allowed hyphenation points
  21596. if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  21597. // 173 = soft hyphen character
  21598. array_splice($word, $i + $inserted, 0, 173);
  21599. ++$inserted;
  21600. }
  21601. }
  21602. return $word;
  21603. }
  21604. /**
  21605. * Returns text with soft hyphens.
  21606. * @param string $text text to process
  21607. * @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/
  21608. * @param array $dictionary Array of words to be returned without applying the hyphenation algorithm.
  21609. * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
  21610. * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
  21611. * @param int $charmin Minimum word length to apply the hyphenation algorithm.
  21612. * @param int $charmax Maximum length of broken piece of word.
  21613. * @return string text with soft hyphens
  21614. * @author Nicola Asuni
  21615. * @since 4.9.012 (2010-04-12)
  21616. * @public
  21617. */
  21618. public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21619. $text = $this->unhtmlentities($text);
  21620. $word = array(); // last word
  21621. $txtarr = array(); // text to be returned
  21622. $intag = false; // true if we are inside an HTML tag
  21623. $skip = false; // true to skip hyphenation
  21624. if (!is_array($patterns)) {
  21625. $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
  21626. }
  21627. // get array of characters
  21628. $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  21629. // for each char
  21630. foreach ($unichars as $char) {
  21631. if ((!$intag) AND (!$skip) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
  21632. // letter character
  21633. $word[] = $char;
  21634. } else {
  21635. // other type of character
  21636. if (!TCPDF_STATIC::empty_string($word)) {
  21637. // hypenate the word
  21638. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21639. $word = array();
  21640. }
  21641. $txtarr[] = $char;
  21642. if (chr($char) == '<') {
  21643. // we are inside an HTML tag
  21644. $intag = true;
  21645. } elseif ($intag AND (chr($char) == '>')) {
  21646. // end of HTML tag
  21647. $intag = false;
  21648. // check for style tag
  21649. $expected = array(115, 116, 121, 108, 101); // = 'style'
  21650. $current = array_slice($txtarr, -6, 5); // last 5 chars
  21651. $compare = array_diff($expected, $current);
  21652. if (empty($compare)) {
  21653. // check if it is a closing tag
  21654. $expected = array(47); // = '/'
  21655. $current = array_slice($txtarr, -7, 1);
  21656. $compare = array_diff($expected, $current);
  21657. if (empty($compare)) {
  21658. // closing style tag
  21659. $skip = false;
  21660. } else {
  21661. // opening style tag
  21662. $skip = true;
  21663. }
  21664. }
  21665. }
  21666. }
  21667. }
  21668. if (!TCPDF_STATIC::empty_string($word)) {
  21669. // hypenate the word
  21670. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21671. }
  21672. // convert char array to string and return
  21673. return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
  21674. }
  21675. /**
  21676. * Enable/disable rasterization of vector images using ImageMagick library.
  21677. * @param boolean $mode if true enable rasterization, false otherwise.
  21678. * @public
  21679. * @since 5.0.000 (2010-04-27)
  21680. */
  21681. public function setRasterizeVectorImages($mode) {
  21682. $this->rasterize_vector_images = $mode;
  21683. }
  21684. /**
  21685. * Enable or disable default option for font subsetting.
  21686. * @param boolean $enable if true enable font subsetting by default.
  21687. * @author Nicola Asuni
  21688. * @public
  21689. * @since 5.3.002 (2010-06-07)
  21690. */
  21691. public function setFontSubsetting($enable=true) {
  21692. if ($this->pdfa_mode) {
  21693. $this->font_subsetting = false;
  21694. } else {
  21695. $this->font_subsetting = $enable ? true : false;
  21696. }
  21697. }
  21698. /**
  21699. * Return the default option for font subsetting.
  21700. * @return bool default font subsetting state.
  21701. * @author Nicola Asuni
  21702. * @public
  21703. * @since 5.3.002 (2010-06-07)
  21704. */
  21705. public function getFontSubsetting() {
  21706. return $this->font_subsetting;
  21707. }
  21708. /**
  21709. * Left trim the input string
  21710. * @param string $str string to trim
  21711. * @param string $replace string that replace spaces.
  21712. * @return string left trimmed string
  21713. * @author Nicola Asuni
  21714. * @public
  21715. * @since 5.8.000 (2010-08-11)
  21716. */
  21717. public function stringLeftTrim($str, $replace='') {
  21718. return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
  21719. }
  21720. /**
  21721. * Right trim the input string
  21722. * @param string $str string to trim
  21723. * @param string $replace string that replace spaces.
  21724. * @return string right trimmed string
  21725. * @author Nicola Asuni
  21726. * @public
  21727. * @since 5.8.000 (2010-08-11)
  21728. */
  21729. public function stringRightTrim($str, $replace='') {
  21730. return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
  21731. }
  21732. /**
  21733. * Trim the input string
  21734. * @param string $str string to trim
  21735. * @param string $replace string that replace spaces.
  21736. * @return string trimmed string
  21737. * @author Nicola Asuni
  21738. * @public
  21739. * @since 5.8.000 (2010-08-11)
  21740. */
  21741. public function stringTrim($str, $replace='') {
  21742. $str = $this->stringLeftTrim($str, $replace);
  21743. $str = $this->stringRightTrim($str, $replace);
  21744. return $str;
  21745. }
  21746. /**
  21747. * Return true if the current font is unicode type.
  21748. * @return bool true for unicode font, false otherwise.
  21749. * @author Nicola Asuni
  21750. * @public
  21751. * @since 5.8.002 (2010-08-14)
  21752. */
  21753. public function isUnicodeFont() {
  21754. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  21755. }
  21756. /**
  21757. * Return normalized font name
  21758. * @param string $fontfamily property string containing font family names
  21759. * @return string normalized font name
  21760. * @author Nicola Asuni
  21761. * @public
  21762. * @since 5.8.004 (2010-08-17)
  21763. */
  21764. public function getFontFamilyName($fontfamily) {
  21765. // remove spaces and symbols
  21766. $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
  21767. // extract all font names
  21768. $fontslist = preg_split('/[,]/', $fontfamily);
  21769. // find first valid font name
  21770. foreach ($fontslist as $font) {
  21771. // replace font variations
  21772. $font = preg_replace('/regular$/', '', $font);
  21773. $font = preg_replace('/italic$/', 'I', $font);
  21774. $font = preg_replace('/oblique$/', 'I', $font);
  21775. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  21776. // replace common family names and core fonts
  21777. $pattern = array();
  21778. $replacement = array();
  21779. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  21780. $replacement[] = 'times';
  21781. $pattern[] = '/^sansserif/';
  21782. $replacement[] = 'helvetica';
  21783. $pattern[] = '/^monospace/';
  21784. $replacement[] = 'courier';
  21785. $font = preg_replace($pattern, $replacement, $font);
  21786. if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
  21787. return $font;
  21788. }
  21789. }
  21790. // return current font as default
  21791. return $this->CurrentFont['fontkey'];
  21792. }
  21793. /**
  21794. * Start a new XObject Template.
  21795. * 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).
  21796. * 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.
  21797. * Note: X,Y coordinates will be reset to 0,0.
  21798. * @param int $w Template width in user units (empty string or zero = page width less margins).
  21799. * @param int $h Template height in user units (empty string or zero = page height less margins).
  21800. * @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).
  21801. * @return string|false the XObject Template ID in case of success or false in case of error.
  21802. * @author Nicola Asuni
  21803. * @public
  21804. * @since 5.8.017 (2010-08-24)
  21805. * @see endTemplate(), printTemplate()
  21806. */
  21807. public function startTemplate($w=0, $h=0, $group=false) {
  21808. if ($this->inxobj) {
  21809. // we are already inside an XObject template
  21810. return false;
  21811. }
  21812. $this->inxobj = true;
  21813. ++$this->n;
  21814. // XObject ID
  21815. $this->xobjid = 'XT'.$this->n;
  21816. // object ID
  21817. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  21818. // store current graphic state
  21819. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  21820. // initialize data
  21821. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  21822. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  21823. $this->xobjects[$this->xobjid]['outdata'] = '';
  21824. $this->xobjects[$this->xobjid]['xobjects'] = array();
  21825. $this->xobjects[$this->xobjid]['images'] = array();
  21826. $this->xobjects[$this->xobjid]['fonts'] = array();
  21827. $this->xobjects[$this->xobjid]['annotations'] = array();
  21828. $this->xobjects[$this->xobjid]['extgstates'] = array();
  21829. $this->xobjects[$this->xobjid]['gradients'] = array();
  21830. $this->xobjects[$this->xobjid]['spot_colors'] = array();
  21831. // set new environment
  21832. $this->num_columns = 1;
  21833. $this->current_column = 0;
  21834. $this->setAutoPageBreak(false);
  21835. if (($w === '') OR ($w <= 0)) {
  21836. $w = $this->w - $this->lMargin - $this->rMargin;
  21837. }
  21838. if (($h === '') OR ($h <= 0)) {
  21839. $h = $this->h - $this->tMargin - $this->bMargin;
  21840. }
  21841. $this->xobjects[$this->xobjid]['x'] = 0;
  21842. $this->xobjects[$this->xobjid]['y'] = 0;
  21843. $this->xobjects[$this->xobjid]['w'] = $w;
  21844. $this->xobjects[$this->xobjid]['h'] = $h;
  21845. $this->w = $w;
  21846. $this->h = $h;
  21847. $this->wPt = $this->w * $this->k;
  21848. $this->hPt = $this->h * $this->k;
  21849. $this->fwPt = $this->wPt;
  21850. $this->fhPt = $this->hPt;
  21851. $this->x = 0;
  21852. $this->y = 0;
  21853. $this->lMargin = 0;
  21854. $this->rMargin = 0;
  21855. $this->tMargin = 0;
  21856. $this->bMargin = 0;
  21857. // set group mode
  21858. $this->xobjects[$this->xobjid]['group'] = $group;
  21859. return $this->xobjid;
  21860. }
  21861. /**
  21862. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  21863. * 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).
  21864. * 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.
  21865. * @return string|false the XObject Template ID in case of success or false in case of error.
  21866. * @author Nicola Asuni
  21867. * @public
  21868. * @since 5.8.017 (2010-08-24)
  21869. * @see startTemplate(), printTemplate()
  21870. */
  21871. public function endTemplate() {
  21872. if (!$this->inxobj) {
  21873. // we are not inside a template
  21874. return false;
  21875. }
  21876. $this->inxobj = false;
  21877. // restore previous graphic state
  21878. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  21879. return $this->xobjid;
  21880. }
  21881. /**
  21882. * Print an XObject Template.
  21883. * You can print an XObject Template inside the currently opened Template.
  21884. * 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).
  21885. * 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.
  21886. * @param string $id The ID of XObject Template to print.
  21887. * @param float|null $x X position in user units (empty string = current x position)
  21888. * @param float|null $y Y position in user units (empty string = current y position)
  21889. * @param float $w Width in user units (zero = remaining page width)
  21890. * @param float $h Height in user units (zero = remaining page height)
  21891. * @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>
  21892. * @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>
  21893. * @param boolean $fitonpage If true the template is resized to not exceed page dimensions.
  21894. * @author Nicola Asuni
  21895. * @public
  21896. * @since 5.8.017 (2010-08-24)
  21897. * @see startTemplate(), endTemplate()
  21898. */
  21899. public function printTemplate($id, $x=null, $y=null, $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
  21900. if ($this->state != 2) {
  21901. return;
  21902. }
  21903. if (!isset($this->xobjects[$id])) {
  21904. $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  21905. }
  21906. if ($this->inxobj) {
  21907. if ($id == $this->xobjid) {
  21908. // close current template
  21909. $this->endTemplate();
  21910. } else {
  21911. // use the template as resource for the template currently opened
  21912. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  21913. }
  21914. }
  21915. // set default values
  21916. if (TCPDF_STATIC::empty_string($x)) {
  21917. $x = $this->x;
  21918. }
  21919. if (TCPDF_STATIC::empty_string($y)) {
  21920. $y = $this->y;
  21921. }
  21922. // check page for no-write regions and adapt page margins if necessary
  21923. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  21924. $ow = $this->xobjects[$id]['w'];
  21925. if ($ow <= 0) {
  21926. $ow = 1;
  21927. }
  21928. $oh = $this->xobjects[$id]['h'];
  21929. if ($oh <= 0) {
  21930. $oh = 1;
  21931. }
  21932. // calculate template width and height on document
  21933. if (($w <= 0) AND ($h <= 0)) {
  21934. $w = $ow;
  21935. $h = $oh;
  21936. } elseif ($w <= 0) {
  21937. $w = $h * $ow / $oh;
  21938. } elseif ($h <= 0) {
  21939. $h = $w * $oh / $ow;
  21940. }
  21941. // fit the template on available space
  21942. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  21943. // set page alignment
  21944. $rb_y = $y + $h;
  21945. // set alignment
  21946. if ($this->rtl) {
  21947. if ($palign == 'L') {
  21948. $xt = $this->lMargin;
  21949. } elseif ($palign == 'C') {
  21950. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21951. } elseif ($palign == 'R') {
  21952. $xt = $this->w - $this->rMargin - $w;
  21953. } else {
  21954. $xt = $x - $w;
  21955. }
  21956. $rb_x = $xt;
  21957. } else {
  21958. if ($palign == 'L') {
  21959. $xt = $this->lMargin;
  21960. } elseif ($palign == 'C') {
  21961. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21962. } elseif ($palign == 'R') {
  21963. $xt = $this->w - $this->rMargin - $w;
  21964. } else {
  21965. $xt = $x;
  21966. }
  21967. $rb_x = $xt + $w;
  21968. }
  21969. // print XObject Template + Transformation matrix
  21970. $this->StartTransform();
  21971. // translate and scale
  21972. $sx = ($w / $ow);
  21973. $sy = ($h / $oh);
  21974. $tm = array();
  21975. $tm[0] = $sx;
  21976. $tm[1] = 0;
  21977. $tm[2] = 0;
  21978. $tm[3] = $sy;
  21979. $tm[4] = $xt * $this->k;
  21980. $tm[5] = ($this->h - $h - $y) * $this->k;
  21981. $this->Transform($tm);
  21982. // set object
  21983. $this->_out('/'.$id.' Do');
  21984. $this->StopTransform();
  21985. // add annotations
  21986. if (!empty($this->xobjects[$id]['annotations'])) {
  21987. foreach ($this->xobjects[$id]['annotations'] as $annot) {
  21988. // transform original coordinates
  21989. $coordlt = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  21990. $ax = ($coordlt[4] / $this->k);
  21991. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  21992. $coordrb = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  21993. $aw = ($coordrb[4] / $this->k) - $ax;
  21994. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  21995. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  21996. }
  21997. }
  21998. // set pointer to align the next text/objects
  21999. switch($align) {
  22000. case 'T': {
  22001. $this->y = $y;
  22002. $this->x = $rb_x;
  22003. break;
  22004. }
  22005. case 'M': {
  22006. $this->y = $y + round($h/2);
  22007. $this->x = $rb_x;
  22008. break;
  22009. }
  22010. case 'B': {
  22011. $this->y = $rb_y;
  22012. $this->x = $rb_x;
  22013. break;
  22014. }
  22015. case 'N': {
  22016. $this->setY($rb_y);
  22017. break;
  22018. }
  22019. default:{
  22020. break;
  22021. }
  22022. }
  22023. }
  22024. /**
  22025. * Set the percentage of character stretching.
  22026. * @param int $perc percentage of stretching (100 = no stretching)
  22027. * @author Nicola Asuni
  22028. * @public
  22029. * @since 5.9.000 (2010-09-29)
  22030. */
  22031. public function setFontStretching($perc=100) {
  22032. $this->font_stretching = $perc;
  22033. }
  22034. /**
  22035. * Get the percentage of character stretching.
  22036. * @return float stretching value
  22037. * @author Nicola Asuni
  22038. * @public
  22039. * @since 5.9.000 (2010-09-29)
  22040. */
  22041. public function getFontStretching() {
  22042. return $this->font_stretching;
  22043. }
  22044. /**
  22045. * Set the amount to increase or decrease the space between characters in a text.
  22046. * @param float $spacing amount to increase or decrease the space between characters in a text (0 = default spacing)
  22047. * @author Nicola Asuni
  22048. * @public
  22049. * @since 5.9.000 (2010-09-29)
  22050. */
  22051. public function setFontSpacing($spacing=0) {
  22052. $this->font_spacing = $spacing;
  22053. }
  22054. /**
  22055. * Get the amount to increase or decrease the space between characters in a text.
  22056. * @return int font spacing (tracking) value
  22057. * @author Nicola Asuni
  22058. * @public
  22059. * @since 5.9.000 (2010-09-29)
  22060. */
  22061. public function getFontSpacing() {
  22062. return $this->font_spacing;
  22063. }
  22064. /**
  22065. * Return an array of no-write page regions
  22066. * @return array of no-write page regions
  22067. * @author Nicola Asuni
  22068. * @public
  22069. * @since 5.9.003 (2010-10-13)
  22070. * @see setPageRegions(), addPageRegion()
  22071. */
  22072. public function getPageRegions() {
  22073. return $this->page_regions;
  22074. }
  22075. /**
  22076. * Set no-write regions on page.
  22077. * 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.
  22078. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22079. * You can set multiple regions for the same page.
  22080. * @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.
  22081. * @author Nicola Asuni
  22082. * @public
  22083. * @since 5.9.003 (2010-10-13)
  22084. * @see addPageRegion(), getPageRegions()
  22085. */
  22086. public function setPageRegions($regions=array()) {
  22087. // empty current regions array
  22088. $this->page_regions = array();
  22089. // add regions
  22090. foreach ($regions as $data) {
  22091. $this->addPageRegion($data);
  22092. }
  22093. }
  22094. /**
  22095. * Add a single no-write region on selected page.
  22096. * 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.
  22097. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22098. * You can set multiple regions for the same page.
  22099. * @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).
  22100. * @author Nicola Asuni
  22101. * @public
  22102. * @since 5.9.003 (2010-10-13)
  22103. * @see setPageRegions(), getPageRegions()
  22104. */
  22105. public function addPageRegion($region) {
  22106. if (!isset($region['page']) OR empty($region['page'])) {
  22107. $region['page'] = $this->page;
  22108. }
  22109. if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  22110. AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  22111. AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  22112. $this->page_regions[] = $region;
  22113. }
  22114. }
  22115. /**
  22116. * Remove a single no-write region.
  22117. * @param int $key region key
  22118. * @author Nicola Asuni
  22119. * @public
  22120. * @since 5.9.003 (2010-10-13)
  22121. * @see setPageRegions(), getPageRegions()
  22122. */
  22123. public function removePageRegion($key) {
  22124. if (isset($this->page_regions[$key])) {
  22125. unset($this->page_regions[$key]);
  22126. }
  22127. }
  22128. /**
  22129. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  22130. * 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.
  22131. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22132. * @param float $h height of the text/image/object to print in user units
  22133. * @param float $x current X coordinate in user units
  22134. * @param float $y current Y coordinate in user units
  22135. * @return float[] array($x, $y)
  22136. * @author Nicola Asuni
  22137. * @protected
  22138. * @since 5.9.003 (2010-10-13)
  22139. */
  22140. protected function checkPageRegions($h, $x, $y) {
  22141. // set default values
  22142. if ($x === '') {
  22143. $x = $this->x;
  22144. }
  22145. if ($y === '') {
  22146. $y = $this->y;
  22147. }
  22148. if (!$this->check_page_regions OR empty($this->page_regions)) {
  22149. // no page regions defined
  22150. return array($x, $y);
  22151. }
  22152. if (empty($h)) {
  22153. $h = $this->getCellHeight($this->FontSize);
  22154. }
  22155. // check for page break
  22156. if ($this->checkPageBreak($h, $y)) {
  22157. // the content will be printed on a new page
  22158. $x = $this->x;
  22159. $y = $this->y;
  22160. }
  22161. if ($this->num_columns > 1) {
  22162. if ($this->rtl) {
  22163. $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  22164. } else {
  22165. $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  22166. }
  22167. } else {
  22168. if ($this->rtl) {
  22169. $this->lMargin = max($this->clMargin, $this->original_lMargin);
  22170. } else {
  22171. $this->rMargin = max($this->crMargin, $this->original_rMargin);
  22172. }
  22173. }
  22174. // adjust coordinates and page margins
  22175. foreach ($this->page_regions as $regid => $regdata) {
  22176. if ($regdata['page'] == $this->page) {
  22177. // check region boundaries
  22178. if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  22179. // Y is inside the region
  22180. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  22181. $yt = max($y, $regdata['yt']);
  22182. $yb = min(($yt + $h), $regdata['yb']);
  22183. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  22184. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  22185. if ($regdata['side'] == 'L') { // left side
  22186. $new_margin = max($xt, $xb);
  22187. if ($this->lMargin < $new_margin) {
  22188. if ($this->rtl) {
  22189. // adjust left page margin
  22190. $this->lMargin = max(0, $new_margin);
  22191. }
  22192. if ($x < $new_margin) {
  22193. // adjust x position
  22194. $x = $new_margin;
  22195. if ($new_margin > ($this->w - $this->rMargin)) {
  22196. // adjust y position
  22197. $y = $regdata['yb'] - $h;
  22198. }
  22199. }
  22200. }
  22201. } elseif ($regdata['side'] == 'R') { // right side
  22202. $new_margin = min($xt, $xb);
  22203. if (($this->w - $this->rMargin) > $new_margin) {
  22204. if (!$this->rtl) {
  22205. // adjust right page margin
  22206. $this->rMargin = max(0, ($this->w - $new_margin));
  22207. }
  22208. if ($x > $new_margin) {
  22209. // adjust x position
  22210. $x = $new_margin;
  22211. if ($new_margin > $this->lMargin) {
  22212. // adjust y position
  22213. $y = $regdata['yb'] - $h;
  22214. }
  22215. }
  22216. }
  22217. }
  22218. }
  22219. }
  22220. }
  22221. return array($x, $y);
  22222. }
  22223. // --- SVG METHODS ---------------------------------------------------------
  22224. /**
  22225. * Embedd a Scalable Vector Graphics (SVG) image.
  22226. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  22227. * @param string $file Name of the SVG file or a '@' character followed by the SVG data string.
  22228. * @param float|null $x Abscissa of the upper-left corner.
  22229. * @param float|null $y Ordinate of the upper-left corner.
  22230. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22231. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22232. * @param mixed $link URL or identifier returned by AddLink().
  22233. * @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.
  22234. * @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>
  22235. * @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)))
  22236. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  22237. * @author Nicola Asuni
  22238. * @since 5.0.000 (2010-05-02)
  22239. * @public
  22240. */
  22241. public function ImageSVG($file, $x=null, $y=null, $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
  22242. if ($this->state != 2) {
  22243. return;
  22244. }
  22245. // reset SVG vars
  22246. $this->svggradients = array();
  22247. $this->svggradientid = 0;
  22248. $this->svgdefsmode = false;
  22249. $this->svgdefs = array();
  22250. $this->svgclipmode = false;
  22251. $this->svgclippaths = array();
  22252. $this->svgcliptm = array();
  22253. $this->svgclipid = 0;
  22254. $this->svgtext = '';
  22255. $this->svgtextmode = array();
  22256. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  22257. // convert SVG to raster image using GD or ImageMagick libraries
  22258. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22259. }
  22260. if ($file[0] === '@') { // image from string
  22261. $this->svgdir = '';
  22262. $svgdata = substr($file, 1);
  22263. } else { // SVG file
  22264. $this->svgdir = dirname($file);
  22265. $svgdata = $this->getCachedFileContents($file);
  22266. }
  22267. if ($svgdata === FALSE) {
  22268. $this->Error('SVG file not found: '.$file);
  22269. }
  22270. if (TCPDF_STATIC::empty_string($x)) {
  22271. $x = $this->x;
  22272. }
  22273. if (TCPDF_STATIC::empty_string($y)) {
  22274. $y = $this->y;
  22275. }
  22276. // check page for no-write regions and adapt page margins if necessary
  22277. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  22278. $k = $this->k;
  22279. $ox = 0;
  22280. $oy = 0;
  22281. $ow = $w;
  22282. $oh = $h;
  22283. $aspect_ratio_align = 'xMidYMid';
  22284. $aspect_ratio_ms = 'meet';
  22285. $regs = array();
  22286. // get original image width and height
  22287. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  22288. if (isset($regs[1]) AND !empty($regs[1])) {
  22289. $tmp = array();
  22290. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22291. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  22292. }
  22293. $tmp = array();
  22294. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22295. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  22296. }
  22297. $tmp = array();
  22298. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22299. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  22300. }
  22301. $tmp = array();
  22302. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22303. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  22304. }
  22305. $tmp = array();
  22306. $view_box = array();
  22307. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
  22308. if (count($tmp) == 5) {
  22309. array_shift($tmp);
  22310. foreach ($tmp as $key => $val) {
  22311. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  22312. }
  22313. $ox = $view_box[0];
  22314. $oy = $view_box[1];
  22315. }
  22316. // get aspect ratio
  22317. $tmp = array();
  22318. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22319. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  22320. switch (count($aspect_ratio)) {
  22321. case 3: {
  22322. $aspect_ratio_align = $aspect_ratio[1];
  22323. $aspect_ratio_ms = $aspect_ratio[2];
  22324. break;
  22325. }
  22326. case 2: {
  22327. $aspect_ratio_align = $aspect_ratio[0];
  22328. $aspect_ratio_ms = $aspect_ratio[1];
  22329. break;
  22330. }
  22331. case 1: {
  22332. $aspect_ratio_align = $aspect_ratio[0];
  22333. $aspect_ratio_ms = 'meet';
  22334. break;
  22335. }
  22336. }
  22337. }
  22338. }
  22339. }
  22340. if ($ow <= 0) {
  22341. $ow = 1;
  22342. }
  22343. if ($oh <= 0) {
  22344. $oh = 1;
  22345. }
  22346. // calculate image width and height on document
  22347. if (($w <= 0) AND ($h <= 0)) {
  22348. // convert image size to document unit
  22349. $w = $ow;
  22350. $h = $oh;
  22351. } elseif ($w <= 0) {
  22352. $w = $h * $ow / $oh;
  22353. } elseif ($h <= 0) {
  22354. $h = $w * $oh / $ow;
  22355. }
  22356. // fit the image on available space
  22357. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  22358. if ($this->rasterize_vector_images) {
  22359. // convert SVG to raster image using GD or ImageMagick libraries
  22360. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22361. }
  22362. // set alignment
  22363. $this->img_rb_y = $y + $h;
  22364. // set alignment
  22365. if ($this->rtl) {
  22366. if ($palign == 'L') {
  22367. $ximg = $this->lMargin;
  22368. } elseif ($palign == 'C') {
  22369. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22370. } elseif ($palign == 'R') {
  22371. $ximg = $this->w - $this->rMargin - $w;
  22372. } else {
  22373. $ximg = $x - $w;
  22374. }
  22375. $this->img_rb_x = $ximg;
  22376. } else {
  22377. if ($palign == 'L') {
  22378. $ximg = $this->lMargin;
  22379. } elseif ($palign == 'C') {
  22380. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22381. } elseif ($palign == 'R') {
  22382. $ximg = $this->w - $this->rMargin - $w;
  22383. } else {
  22384. $ximg = $x;
  22385. }
  22386. $this->img_rb_x = $ximg + $w;
  22387. }
  22388. // store current graphic vars
  22389. $gvars = $this->getGraphicVars();
  22390. // store SVG position and scale factors
  22391. $svgoffset_x = ($ximg - $ox) * $this->k;
  22392. $svgoffset_y = -($y - $oy) * $this->k;
  22393. if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  22394. $ow = $view_box[2];
  22395. $oh = $view_box[3];
  22396. } else {
  22397. if ($ow <= 0) {
  22398. $ow = $w;
  22399. }
  22400. if ($oh <= 0) {
  22401. $oh = $h;
  22402. }
  22403. }
  22404. $svgscale_x = $w / $ow;
  22405. $svgscale_y = $h / $oh;
  22406. // scaling and alignment
  22407. if ($aspect_ratio_align != 'none') {
  22408. // store current scaling values
  22409. $svgscale_old_x = $svgscale_x;
  22410. $svgscale_old_y = $svgscale_y;
  22411. // force uniform scaling
  22412. if ($aspect_ratio_ms == 'slice') {
  22413. // the entire viewport is covered by the viewBox
  22414. if ($svgscale_x > $svgscale_y) {
  22415. $svgscale_y = $svgscale_x;
  22416. } elseif ($svgscale_x < $svgscale_y) {
  22417. $svgscale_x = $svgscale_y;
  22418. }
  22419. } else { // meet
  22420. // the entire viewBox is visible within the viewport
  22421. if ($svgscale_x < $svgscale_y) {
  22422. $svgscale_y = $svgscale_x;
  22423. } elseif ($svgscale_x > $svgscale_y) {
  22424. $svgscale_x = $svgscale_y;
  22425. }
  22426. }
  22427. // correct X alignment
  22428. switch (substr($aspect_ratio_align, 1, 3)) {
  22429. case 'Min': {
  22430. // do nothing
  22431. break;
  22432. }
  22433. case 'Max': {
  22434. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  22435. break;
  22436. }
  22437. default:
  22438. case 'Mid': {
  22439. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  22440. break;
  22441. }
  22442. }
  22443. // correct Y alignment
  22444. switch (substr($aspect_ratio_align, 5)) {
  22445. case 'Min': {
  22446. // do nothing
  22447. break;
  22448. }
  22449. case 'Max': {
  22450. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  22451. break;
  22452. }
  22453. default:
  22454. case 'Mid': {
  22455. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  22456. break;
  22457. }
  22458. }
  22459. }
  22460. // store current page break mode
  22461. $page_break_mode = $this->AutoPageBreak;
  22462. $page_break_margin = $this->getBreakMargin();
  22463. $cell_padding = $this->cell_padding;
  22464. $this->setCellPadding(0);
  22465. $this->setAutoPageBreak(false);
  22466. // save the current graphic state
  22467. $this->_out('q'.$this->epsmarker);
  22468. // set initial clipping mask
  22469. $this->Rect($ximg, $y, $w, $h, 'CNZ', array(), array());
  22470. // scale and translate
  22471. $e = $ox * $this->k * (1 - $svgscale_x);
  22472. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  22473. $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e + $svgoffset_x), ($f + $svgoffset_y)));
  22474. // creates a new XML parser to be used by the other XML functions
  22475. $parser = xml_parser_create('UTF-8');
  22476. // the following function allows to use parser inside object
  22477. xml_set_object($parser, $this);
  22478. // disable case-folding for this XML parser
  22479. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  22480. // sets the element handler functions for the XML parser
  22481. xml_set_element_handler($parser, 'startSVGElementHandler', 'endSVGElementHandler');
  22482. // sets the character data handler function for the XML parser
  22483. xml_set_character_data_handler($parser, 'segSVGContentHandler');
  22484. // start parsing an XML document
  22485. if (!xml_parse($parser, $svgdata)) {
  22486. $error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser));
  22487. $this->Error($error_message);
  22488. }
  22489. // free this XML parser
  22490. xml_parser_free($parser);
  22491. // >= PHP 7.0.0 "explicitly unset the reference to parser to avoid memory leaks"
  22492. unset($parser);
  22493. // restore previous graphic state
  22494. $this->_out($this->epsmarker.'Q');
  22495. // restore graphic vars
  22496. $this->setGraphicVars($gvars);
  22497. $this->lasth = $gvars['lasth'];
  22498. if (!empty($border)) {
  22499. $bx = $this->x;
  22500. $by = $this->y;
  22501. $this->x = $ximg;
  22502. if ($this->rtl) {
  22503. $this->x += $w;
  22504. }
  22505. $this->y = $y;
  22506. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  22507. $this->x = $bx;
  22508. $this->y = $by;
  22509. }
  22510. if ($link) {
  22511. $this->Link($ximg, $y, $w, $h, $link, 0);
  22512. }
  22513. // set pointer to align the next text/objects
  22514. switch($align) {
  22515. case 'T':{
  22516. $this->y = $y;
  22517. $this->x = $this->img_rb_x;
  22518. break;
  22519. }
  22520. case 'M':{
  22521. $this->y = $y + round($h/2);
  22522. $this->x = $this->img_rb_x;
  22523. break;
  22524. }
  22525. case 'B':{
  22526. $this->y = $this->img_rb_y;
  22527. $this->x = $this->img_rb_x;
  22528. break;
  22529. }
  22530. case 'N':{
  22531. $this->setY($this->img_rb_y);
  22532. break;
  22533. }
  22534. default:{
  22535. // restore pointer to starting position
  22536. $this->x = $gvars['x'];
  22537. $this->y = $gvars['y'];
  22538. $this->page = $gvars['page'];
  22539. $this->current_column = $gvars['current_column'];
  22540. $this->tMargin = $gvars['tMargin'];
  22541. $this->bMargin = $gvars['bMargin'];
  22542. $this->w = $gvars['w'];
  22543. $this->h = $gvars['h'];
  22544. $this->wPt = $gvars['wPt'];
  22545. $this->hPt = $gvars['hPt'];
  22546. $this->fwPt = $gvars['fwPt'];
  22547. $this->fhPt = $gvars['fhPt'];
  22548. break;
  22549. }
  22550. }
  22551. $this->endlinex = $this->img_rb_x;
  22552. // restore page break
  22553. $this->setAutoPageBreak($page_break_mode, $page_break_margin);
  22554. $this->cell_padding = $cell_padding;
  22555. }
  22556. /**
  22557. * Convert SVG transformation matrix to PDF.
  22558. * @param array $tm original SVG transformation matrix
  22559. * @return array transformation matrix
  22560. * @protected
  22561. * @since 5.0.000 (2010-05-02)
  22562. */
  22563. protected function convertSVGtMatrix($tm) {
  22564. $a = $tm[0];
  22565. $b = -$tm[1];
  22566. $c = -$tm[2];
  22567. $d = $tm[3];
  22568. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  22569. $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  22570. $x = 0;
  22571. $y = $this->h * $this->k;
  22572. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  22573. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  22574. return array($a, $b, $c, $d, $e, $f);
  22575. }
  22576. /**
  22577. * Apply SVG graphic transformation matrix.
  22578. * @param array $tm original SVG transformation matrix
  22579. * @protected
  22580. * @since 5.0.000 (2010-05-02)
  22581. */
  22582. protected function SVGTransform($tm) {
  22583. $this->Transform($this->convertSVGtMatrix($tm));
  22584. }
  22585. /**
  22586. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  22587. * @param array $svgstyle array of SVG styles to apply
  22588. * @param array $prevsvgstyle array of previous SVG style
  22589. * @param int $x X origin of the bounding box
  22590. * @param int $y Y origin of the bounding box
  22591. * @param int $w width of the bounding box
  22592. * @param int $h height of the bounding box
  22593. * @param string $clip_function clip function
  22594. * @param array $clip_params array of parameters for clipping function
  22595. * @return string style
  22596. * @author Nicola Asuni
  22597. * @since 5.0.000 (2010-05-02)
  22598. * @protected
  22599. */
  22600. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
  22601. if ($this->state != 2) {
  22602. return;
  22603. }
  22604. $objstyle = '';
  22605. $minlen = (0.01 / $this->k); // minimum acceptable length
  22606. if (!isset($svgstyle['opacity'])) {
  22607. return $objstyle;
  22608. }
  22609. // clip-path
  22610. $regs = array();
  22611. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
  22612. $clip_path = $this->svgclippaths[$regs[1]];
  22613. foreach ($clip_path as $cp) {
  22614. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  22615. }
  22616. }
  22617. // opacity
  22618. if ($svgstyle['opacity'] != 1) {
  22619. $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
  22620. }
  22621. // color
  22622. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors);
  22623. $this->setFillColorArray($fill_color);
  22624. // text color
  22625. $text_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors);
  22626. $this->setTextColorArray($text_color);
  22627. // clip
  22628. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
  22629. $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
  22630. $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
  22631. $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
  22632. $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
  22633. $cx = $x + $left;
  22634. $cy = $y + $top;
  22635. $cw = $w - $left - $right;
  22636. $ch = $h - $top - $bottom;
  22637. if ($svgstyle['clip-rule'] == 'evenodd') {
  22638. $clip_rule = 'CNZ';
  22639. } else {
  22640. $clip_rule = 'CEO';
  22641. }
  22642. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  22643. }
  22644. // fill
  22645. $regs = array();
  22646. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
  22647. // gradient
  22648. $gradient = $this->svggradients[$regs[1]];
  22649. if (isset($gradient['xref'])) {
  22650. // reference to another gradient definition
  22651. $newgradient = $this->svggradients[$gradient['xref']];
  22652. $newgradient['coords'] = $gradient['coords'];
  22653. $newgradient['mode'] = $gradient['mode'];
  22654. $newgradient['type'] = $gradient['type'];
  22655. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  22656. if (isset($gradient['gradientTransform'])) {
  22657. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  22658. }
  22659. $gradient = $newgradient;
  22660. }
  22661. //save current Graphic State
  22662. $this->_outSaveGraphicsState();
  22663. //set clipping area
  22664. if (!empty($clip_function) AND method_exists($this, $clip_function)) {
  22665. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  22666. if ((!isset($gradient['type']) OR ($gradient['type'] != 3)) AND is_array($bbox) AND (count($bbox) == 4)) {
  22667. list($x, $y, $w, $h) = $bbox;
  22668. }
  22669. }
  22670. if ($gradient['mode'] == 'measure') {
  22671. if (!isset($gradient['coords'][4])) {
  22672. $gradient['coords'][4] = 0.5;
  22673. }
  22674. if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  22675. $gtm = $gradient['gradientTransform'];
  22676. // apply transformation matrix
  22677. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  22678. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  22679. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  22680. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  22681. $r = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  22682. $gradient['coords'][0] = $xa;
  22683. $gradient['coords'][1] = $ya;
  22684. $gradient['coords'][2] = $xb;
  22685. $gradient['coords'][3] = $yb;
  22686. $gradient['coords'][4] = $r;
  22687. }
  22688. // convert SVG coordinates to user units
  22689. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  22690. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  22691. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  22692. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  22693. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  22694. if ($w <= $minlen) {
  22695. $w = $minlen;
  22696. }
  22697. if ($h <= $minlen) {
  22698. $h = $minlen;
  22699. }
  22700. // shift units
  22701. if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  22702. // convert to SVG coordinate system
  22703. $gradient['coords'][0] += $x;
  22704. $gradient['coords'][1] += $y;
  22705. $gradient['coords'][2] += $x;
  22706. $gradient['coords'][3] += $y;
  22707. }
  22708. // calculate percentages
  22709. $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
  22710. $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
  22711. $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
  22712. $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
  22713. $gradient['coords'][4] /= $w;
  22714. } elseif ($gradient['mode'] == 'percentage') {
  22715. foreach($gradient['coords'] as $key => $val) {
  22716. $gradient['coords'][$key] = (intval($val) / 100);
  22717. if ($val < 0) {
  22718. $gradient['coords'][$key] = 0;
  22719. } elseif ($val > 1) {
  22720. $gradient['coords'][$key] = 1;
  22721. }
  22722. }
  22723. }
  22724. if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  22725. // single color (no shading)
  22726. $gradient['coords'][0] = 1;
  22727. $gradient['coords'][1] = 0;
  22728. $gradient['coords'][2] = 0.999;
  22729. $gradient['coords'][3] = 0;
  22730. }
  22731. // swap Y coordinates
  22732. $tmp = $gradient['coords'][1];
  22733. $gradient['coords'][1] = $gradient['coords'][3];
  22734. $gradient['coords'][3] = $tmp;
  22735. // set transformation map for gradient
  22736. $cy = ($this->h - $y);
  22737. if ($gradient['type'] == 3) {
  22738. // circular gradient
  22739. $cy -= ($gradient['coords'][1] * ($w + $h));
  22740. $h = $w = max($w, $h);
  22741. } else {
  22742. $cy -= $h;
  22743. }
  22744. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), ($cy * $this->k)));
  22745. if (count($gradient['stops']) > 1) {
  22746. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  22747. }
  22748. } elseif ($svgstyle['fill'] != 'none') {
  22749. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
  22750. if ($svgstyle['fill-opacity'] != 1) {
  22751. $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
  22752. }
  22753. $this->setFillColorArray($fill_color);
  22754. if ($svgstyle['fill-rule'] == 'evenodd') {
  22755. $objstyle .= 'F*';
  22756. } else {
  22757. $objstyle .= 'F';
  22758. }
  22759. }
  22760. // stroke
  22761. if ($svgstyle['stroke'] != 'none') {
  22762. if ($svgstyle['stroke-opacity'] != 1) {
  22763. $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false);
  22764. } elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i', $svgstyle['stroke'], $rgba_matches)) {
  22765. $this->setAlpha($rgba_matches[1], 'Normal', $this->alpha['ca'], false);
  22766. }
  22767. $stroke_style = array(
  22768. 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors),
  22769. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  22770. 'cap' => $svgstyle['stroke-linecap'],
  22771. 'join' => $svgstyle['stroke-linejoin']
  22772. );
  22773. if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  22774. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  22775. }
  22776. $this->setLineStyle($stroke_style);
  22777. $objstyle .= 'D';
  22778. }
  22779. // font
  22780. $regs = array();
  22781. if (!empty($svgstyle['font'])) {
  22782. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
  22783. $font_family = $this->getFontFamilyName($regs[1]);
  22784. } else {
  22785. $font_family = $svgstyle['font-family'];
  22786. }
  22787. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22788. $font_size = trim($regs[1]);
  22789. } else {
  22790. $font_size = $svgstyle['font-size'];
  22791. }
  22792. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22793. $font_style = trim($regs[1]);
  22794. } else {
  22795. $font_style = $svgstyle['font-style'];
  22796. }
  22797. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22798. $font_weight = trim($regs[1]);
  22799. } else {
  22800. $font_weight = $svgstyle['font-weight'];
  22801. }
  22802. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22803. $font_stretch = trim($regs[1]);
  22804. } else {
  22805. $font_stretch = $svgstyle['font-stretch'];
  22806. }
  22807. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22808. $font_spacing = trim($regs[1]);
  22809. } else {
  22810. $font_spacing = $svgstyle['letter-spacing'];
  22811. }
  22812. } else {
  22813. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  22814. $font_size = $svgstyle['font-size'];
  22815. $font_style = $svgstyle['font-style'];
  22816. $font_weight = $svgstyle['font-weight'];
  22817. $font_stretch = $svgstyle['font-stretch'];
  22818. $font_spacing = $svgstyle['letter-spacing'];
  22819. }
  22820. $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit);
  22821. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  22822. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  22823. switch ($font_style) {
  22824. case 'italic': {
  22825. $font_style = 'I';
  22826. break;
  22827. }
  22828. case 'oblique': {
  22829. $font_style = 'I';
  22830. break;
  22831. }
  22832. default:
  22833. case 'normal': {
  22834. $font_style = '';
  22835. break;
  22836. }
  22837. }
  22838. switch ($font_weight) {
  22839. case 'bold':
  22840. case 'bolder': {
  22841. $font_style .= 'B';
  22842. break;
  22843. }
  22844. case 'normal': {
  22845. if ((substr($font_family, -1) == 'I') AND (substr($font_family, -2, 1) == 'B')) {
  22846. $font_family = substr($font_family, 0, -2).'I';
  22847. } elseif (substr($font_family, -1) == 'B') {
  22848. $font_family = substr($font_family, 0, -1);
  22849. }
  22850. break;
  22851. }
  22852. }
  22853. switch ($svgstyle['text-decoration']) {
  22854. case 'underline': {
  22855. $font_style .= 'U';
  22856. break;
  22857. }
  22858. case 'overline': {
  22859. $font_style .= 'O';
  22860. break;
  22861. }
  22862. case 'line-through': {
  22863. $font_style .= 'D';
  22864. break;
  22865. }
  22866. default:
  22867. case 'none': {
  22868. break;
  22869. }
  22870. }
  22871. $this->setFont($font_family, $font_style, $font_size);
  22872. $this->setFontStretching($font_stretch);
  22873. $this->setFontSpacing($font_spacing);
  22874. return $objstyle;
  22875. }
  22876. /**
  22877. * Draws an SVG path
  22878. * @param string $d attribute d of the path SVG element
  22879. * @param string $style Style of rendering. Possible values are:
  22880. * <ul>
  22881. * <li>D or empty string: Draw (default).</li>
  22882. * <li>F: Fill.</li>
  22883. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22884. * <li>DF or FD: Draw and fill.</li>
  22885. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22886. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  22887. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  22888. * </ul>
  22889. * @return array of container box measures (x, y, w, h)
  22890. * @author Nicola Asuni
  22891. * @since 5.0.000 (2010-05-02)
  22892. * @protected
  22893. */
  22894. protected function SVGPath($d, $style='') {
  22895. if ($this->state != 2) {
  22896. return;
  22897. }
  22898. // set fill/stroke style
  22899. $op = TCPDF_STATIC::getPathPaintOperator($style, '');
  22900. if (empty($op)) {
  22901. return;
  22902. }
  22903. $paths = array();
  22904. $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
  22905. $d = preg_replace('/(\.[0-9]+)(\.)/s', '\\1 \\2', $d);
  22906. preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
  22907. $x = 0;
  22908. $y = 0;
  22909. $x1 = 0;
  22910. $y1 = 0;
  22911. $x2 = 0;
  22912. $y2 = 0;
  22913. $xmin = 2147483647;
  22914. $xmax = 0;
  22915. $ymin = 2147483647;
  22916. $ymax = 0;
  22917. $xinitial = 0;
  22918. $yinitial = 0;
  22919. $relcoord = false;
  22920. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  22921. $firstcmd = true; // used to print first point
  22922. // draw curve pieces
  22923. foreach ($paths as $key => $val) {
  22924. // get curve type
  22925. $cmd = trim($val[1]);
  22926. if (strtolower($cmd) == $cmd) {
  22927. // use relative coordinated instead of absolute
  22928. $relcoord = true;
  22929. $xoffset = $x;
  22930. $yoffset = $y;
  22931. } else {
  22932. $relcoord = false;
  22933. $xoffset = 0;
  22934. $yoffset = 0;
  22935. }
  22936. $params = array();
  22937. if (isset($val[2])) {
  22938. // get curve parameters
  22939. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  22940. $params = array();
  22941. foreach ($rawparams as $ck => $cp) {
  22942. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  22943. if (abs($params[$ck]) < $minlen) {
  22944. // approximate little values to zero
  22945. $params[$ck] = 0;
  22946. }
  22947. }
  22948. }
  22949. // store current origin point
  22950. $x0 = $x;
  22951. $y0 = $y;
  22952. switch (strtoupper($cmd)) {
  22953. case 'M': { // moveto
  22954. foreach ($params as $ck => $cp) {
  22955. if (($ck % 2) == 0) {
  22956. $x = $cp + $xoffset;
  22957. } else {
  22958. $y = $cp + $yoffset;
  22959. if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22960. if ($ck == 1) {
  22961. $this->_outPoint($x, $y);
  22962. $firstcmd = false;
  22963. $xinitial = $x;
  22964. $yinitial = $y;
  22965. } else {
  22966. $this->_outLine($x, $y);
  22967. }
  22968. $x0 = $x;
  22969. $y0 = $y;
  22970. }
  22971. $xmin = min($xmin, $x);
  22972. $ymin = min($ymin, $y);
  22973. $xmax = max($xmax, $x);
  22974. $ymax = max($ymax, $y);
  22975. if ($relcoord) {
  22976. $xoffset = $x;
  22977. $yoffset = $y;
  22978. }
  22979. }
  22980. }
  22981. break;
  22982. }
  22983. case 'L': { // lineto
  22984. foreach ($params as $ck => $cp) {
  22985. if (($ck % 2) == 0) {
  22986. $x = $cp + $xoffset;
  22987. } else {
  22988. $y = $cp + $yoffset;
  22989. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22990. $this->_outLine($x, $y);
  22991. $x0 = $x;
  22992. $y0 = $y;
  22993. }
  22994. $xmin = min($xmin, $x);
  22995. $ymin = min($ymin, $y);
  22996. $xmax = max($xmax, $x);
  22997. $ymax = max($ymax, $y);
  22998. if ($relcoord) {
  22999. $xoffset = $x;
  23000. $yoffset = $y;
  23001. }
  23002. }
  23003. }
  23004. break;
  23005. }
  23006. case 'H': { // horizontal lineto
  23007. foreach ($params as $ck => $cp) {
  23008. $x = $cp + $xoffset;
  23009. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  23010. $this->_outLine($x, $y);
  23011. $x0 = $x;
  23012. $y0 = $y;
  23013. }
  23014. $xmin = min($xmin, $x);
  23015. $xmax = max($xmax, $x);
  23016. if ($relcoord) {
  23017. $xoffset = $x;
  23018. }
  23019. }
  23020. break;
  23021. }
  23022. case 'V': { // vertical lineto
  23023. foreach ($params as $ck => $cp) {
  23024. $y = $cp + $yoffset;
  23025. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  23026. $this->_outLine($x, $y);
  23027. $x0 = $x;
  23028. $y0 = $y;
  23029. }
  23030. $ymin = min($ymin, $y);
  23031. $ymax = max($ymax, $y);
  23032. if ($relcoord) {
  23033. $yoffset = $y;
  23034. }
  23035. }
  23036. break;
  23037. }
  23038. case 'C': { // curveto
  23039. foreach ($params as $ck => $cp) {
  23040. $params[$ck] = $cp;
  23041. if ((($ck + 1) % 6) == 0) {
  23042. $x1 = $params[($ck - 5)] + $xoffset;
  23043. $y1 = $params[($ck - 4)] + $yoffset;
  23044. $x2 = $params[($ck - 3)] + $xoffset;
  23045. $y2 = $params[($ck - 2)] + $yoffset;
  23046. $x = $params[($ck - 1)] + $xoffset;
  23047. $y = $params[($ck)] + $yoffset;
  23048. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  23049. $xmin = min($xmin, $x, $x1, $x2);
  23050. $ymin = min($ymin, $y, $y1, $y2);
  23051. $xmax = max($xmax, $x, $x1, $x2);
  23052. $ymax = max($ymax, $y, $y1, $y2);
  23053. if ($relcoord) {
  23054. $xoffset = $x;
  23055. $yoffset = $y;
  23056. }
  23057. }
  23058. }
  23059. break;
  23060. }
  23061. case 'S': { // shorthand/smooth curveto
  23062. foreach ($params as $ck => $cp) {
  23063. $params[$ck] = $cp;
  23064. if ((($ck + 1) % 4) == 0) {
  23065. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
  23066. $x1 = (2 * $x) - $x2;
  23067. $y1 = (2 * $y) - $y2;
  23068. } else {
  23069. $x1 = $x;
  23070. $y1 = $y;
  23071. }
  23072. $x2 = $params[($ck - 3)] + $xoffset;
  23073. $y2 = $params[($ck - 2)] + $yoffset;
  23074. $x = $params[($ck - 1)] + $xoffset;
  23075. $y = $params[($ck)] + $yoffset;
  23076. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  23077. $xmin = min($xmin, $x, $x1, $x2);
  23078. $ymin = min($ymin, $y, $y1, $y2);
  23079. $xmax = max($xmax, $x, $x1, $x2);
  23080. $ymax = max($ymax, $y, $y1, $y2);
  23081. if ($relcoord) {
  23082. $xoffset = $x;
  23083. $yoffset = $y;
  23084. }
  23085. }
  23086. }
  23087. break;
  23088. }
  23089. case 'Q': { // quadratic Bezier curveto
  23090. foreach ($params as $ck => $cp) {
  23091. $params[$ck] = $cp;
  23092. if ((($ck + 1) % 4) == 0) {
  23093. // convert quadratic points to cubic points
  23094. $x1 = $params[($ck - 3)] + $xoffset;
  23095. $y1 = $params[($ck - 2)] + $yoffset;
  23096. $xa = ($x + (2 * $x1)) / 3;
  23097. $ya = ($y + (2 * $y1)) / 3;
  23098. $x = $params[($ck - 1)] + $xoffset;
  23099. $y = $params[($ck)] + $yoffset;
  23100. $xb = ($x + (2 * $x1)) / 3;
  23101. $yb = ($y + (2 * $y1)) / 3;
  23102. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  23103. $xmin = min($xmin, $x, $xa, $xb);
  23104. $ymin = min($ymin, $y, $ya, $yb);
  23105. $xmax = max($xmax, $x, $xa, $xb);
  23106. $ymax = max($ymax, $y, $ya, $yb);
  23107. if ($relcoord) {
  23108. $xoffset = $x;
  23109. $yoffset = $y;
  23110. }
  23111. }
  23112. }
  23113. break;
  23114. }
  23115. case 'T': { // shorthand/smooth quadratic Bezier curveto
  23116. foreach ($params as $ck => $cp) {
  23117. $params[$ck] = $cp;
  23118. if (($ck % 2) != 0) {
  23119. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
  23120. $x1 = (2 * $x) - $x1;
  23121. $y1 = (2 * $y) - $y1;
  23122. } else {
  23123. $x1 = $x;
  23124. $y1 = $y;
  23125. }
  23126. // convert quadratic points to cubic points
  23127. $xa = ($x + (2 * $x1)) / 3;
  23128. $ya = ($y + (2 * $y1)) / 3;
  23129. $x = $params[($ck - 1)] + $xoffset;
  23130. $y = $params[($ck)] + $yoffset;
  23131. $xb = ($x + (2 * $x1)) / 3;
  23132. $yb = ($y + (2 * $y1)) / 3;
  23133. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  23134. $xmin = min($xmin, $x, $xa, $xb);
  23135. $ymin = min($ymin, $y, $ya, $yb);
  23136. $xmax = max($xmax, $x, $xa, $xb);
  23137. $ymax = max($ymax, $y, $ya, $yb);
  23138. if ($relcoord) {
  23139. $xoffset = $x;
  23140. $yoffset = $y;
  23141. }
  23142. }
  23143. }
  23144. break;
  23145. }
  23146. case 'A': { // elliptical arc
  23147. foreach ($params as $ck => $cp) {
  23148. $params[$ck] = $cp;
  23149. if ((($ck + 1) % 7) == 0) {
  23150. $x0 = $x;
  23151. $y0 = $y;
  23152. $rx = max(abs($params[($ck - 6)]), .000000001);
  23153. $ry = max(abs($params[($ck - 5)]), .000000001);
  23154. $ang = -$rawparams[($ck - 4)];
  23155. $angle = deg2rad($ang);
  23156. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  23157. $fs = $rawparams[($ck - 2)]; // sweep-flag
  23158. $x = $params[($ck - 1)] + $xoffset;
  23159. $y = $params[$ck] + $yoffset;
  23160. if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
  23161. // endpoints are almost identical
  23162. $xmin = min($xmin, $x);
  23163. $ymin = min($ymin, $y);
  23164. $xmax = max($xmax, $x);
  23165. $ymax = max($ymax, $y);
  23166. } else {
  23167. $cos_ang = cos($angle);
  23168. $sin_ang = sin($angle);
  23169. $a = (($x0 - $x) / 2);
  23170. $b = (($y0 - $y) / 2);
  23171. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  23172. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  23173. $rx2 = $rx * $rx;
  23174. $ry2 = $ry * $ry;
  23175. $xa2 = $xa * $xa;
  23176. $ya2 = $ya * $ya;
  23177. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  23178. if ($delta > 1) {
  23179. $rx *= sqrt($delta);
  23180. $ry *= sqrt($delta);
  23181. $rx2 = $rx * $rx;
  23182. $ry2 = $ry * $ry;
  23183. }
  23184. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  23185. if ($numerator < 0) {
  23186. $root = 0;
  23187. } else {
  23188. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  23189. }
  23190. if ($fa == $fs){
  23191. $root *= -1;
  23192. }
  23193. $cax = $root * (($rx * $ya) / $ry);
  23194. $cay = -$root * (($ry * $xa) / $rx);
  23195. // coordinates of ellipse center
  23196. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  23197. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  23198. // get angles
  23199. $angs = TCPDF_STATIC::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  23200. $dang = TCPDF_STATIC::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
  23201. if (($fs == 0) AND ($dang > 0)) {
  23202. $dang -= (2 * M_PI);
  23203. } elseif (($fs == 1) AND ($dang < 0)) {
  23204. $dang += (2 * M_PI);
  23205. }
  23206. $angf = $angs - $dang;
  23207. if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
  23208. // reverse angles
  23209. $tmp = $angs;
  23210. $angs = $angf;
  23211. $angf = $tmp;
  23212. }
  23213. $angs = round(rad2deg($angs), 6);
  23214. $angf = round(rad2deg($angf), 6);
  23215. // covent angles to positive values
  23216. if (($angs < 0) AND ($angf < 0)) {
  23217. $angs += 360;
  23218. $angf += 360;
  23219. }
  23220. $pie = false;
  23221. if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
  23222. $pie = true;
  23223. }
  23224. list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
  23225. $xmin = min($xmin, $x, $axmin);
  23226. $ymin = min($ymin, $y, $aymin);
  23227. $xmax = max($xmax, $x, $axmax);
  23228. $ymax = max($ymax, $y, $aymax);
  23229. }
  23230. if ($relcoord) {
  23231. $xoffset = $x;
  23232. $yoffset = $y;
  23233. }
  23234. }
  23235. }
  23236. break;
  23237. }
  23238. case 'Z': {
  23239. $this->_out('h');
  23240. $x = $x0 = $xinitial;
  23241. $y = $y0 = $yinitial;
  23242. break;
  23243. }
  23244. }
  23245. $firstcmd = false;
  23246. } // end foreach
  23247. $this->_out($op);
  23248. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  23249. }
  23250. /**
  23251. * Return the tag name without the namespace
  23252. * @param string $name Tag name
  23253. * @protected
  23254. */
  23255. protected function removeTagNamespace($name) {
  23256. if(strpos($name, ':') !== false) {
  23257. $parts = explode(':', $name);
  23258. return $parts[(sizeof($parts) - 1)];
  23259. }
  23260. return $name;
  23261. }
  23262. /**
  23263. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  23264. * @param resource|string $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  23265. * @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.
  23266. * @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.
  23267. * @param array $ctm tranformation matrix for clipping mode (starting transformation matrix).
  23268. * @author Nicola Asuni
  23269. * @since 5.0.000 (2010-05-02)
  23270. * @protected
  23271. */
  23272. protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
  23273. $name = $this->removeTagNamespace($name);
  23274. // check if we are in clip mode
  23275. if ($this->svgclipmode) {
  23276. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
  23277. return;
  23278. }
  23279. if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
  23280. if (isset($attribs['id'])) {
  23281. $attribs['child_elements'] = array();
  23282. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  23283. return;
  23284. }
  23285. if (end($this->svgdefs) !== FALSE) {
  23286. $last_svgdefs_id = key($this->svgdefs);
  23287. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23288. $attribs['id'] = 'DF_'.(count($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements']) + 1);
  23289. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  23290. return;
  23291. }
  23292. }
  23293. return;
  23294. }
  23295. $clipping = false;
  23296. if ($parser == 'clip-path') {
  23297. // set clipping mode
  23298. $clipping = true;
  23299. }
  23300. // get styling properties
  23301. $prev_svgstyle = $this->svgstyles[max(0,(count($this->svgstyles) - 1))]; // previous style
  23302. $svgstyle = $this->svgstyles[0]; // set default style
  23303. if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
  23304. // default fill attribute for clipping
  23305. $attribs['fill'] = 'none';
  23306. }
  23307. if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style']) AND ($attribs['style'][0] != ';')) {
  23308. // fix style for regular expression
  23309. $attribs['style'] = ';'.$attribs['style'];
  23310. }
  23311. foreach ($prev_svgstyle as $key => $val) {
  23312. if (in_array($key, TCPDF_IMAGES::$svginheritprop)) {
  23313. // inherit previous value
  23314. $svgstyle[$key] = $val;
  23315. }
  23316. if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) {
  23317. // specific attribute settings
  23318. if ($attribs[$key] == 'inherit') {
  23319. $svgstyle[$key] = $val;
  23320. } else {
  23321. $svgstyle[$key] = $attribs[$key];
  23322. }
  23323. } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  23324. // CSS style syntax
  23325. $attrval = array();
  23326. if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
  23327. if ($attrval[1] == 'inherit') {
  23328. $svgstyle[$key] = $val;
  23329. } else {
  23330. $svgstyle[$key] = $attrval[1];
  23331. }
  23332. }
  23333. }
  23334. }
  23335. // transformation matrix
  23336. if (!empty($ctm)) {
  23337. $tm = $ctm;
  23338. } else {
  23339. $tm = array(1,0,0,1,0,0);
  23340. }
  23341. if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  23342. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, TCPDF_STATIC::getSVGTransformMatrix($attribs['transform']));
  23343. }
  23344. $svgstyle['transfmatrix'] = $tm;
  23345. $invisible = false;
  23346. if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  23347. // the current graphics element is invisible (nothing is painted)
  23348. $invisible = true;
  23349. }
  23350. // process tag
  23351. switch($name) {
  23352. case 'defs': {
  23353. $this->svgdefsmode = true;
  23354. break;
  23355. }
  23356. // clipPath
  23357. case 'clipPath': {
  23358. if ($invisible) {
  23359. break;
  23360. }
  23361. $this->svgclipmode = true;
  23362. if (!isset($attribs['id'])) {
  23363. $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  23364. }
  23365. $this->svgclipid = $attribs['id'];
  23366. $this->svgclippaths[$this->svgclipid] = array();
  23367. $this->svgcliptm[$this->svgclipid] = $tm;
  23368. break;
  23369. }
  23370. case 'svg': {
  23371. // start of SVG object
  23372. if(++$this->svg_tag_depth <= 1) {
  23373. break;
  23374. }
  23375. // inner SVG
  23376. array_push($this->svgstyles, $svgstyle);
  23377. $this->StartTransform();
  23378. $svgX = (isset($attribs['x'])?$attribs['x']:0);
  23379. $svgY = (isset($attribs['y'])?$attribs['y']:0);
  23380. $svgW = (isset($attribs['width'])?$attribs['width']:0);
  23381. $svgH = (isset($attribs['height'])?$attribs['height']:0);
  23382. // set x, y position using transform matrix
  23383. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array( 1, 0, 0, 1, $svgX, $svgY));
  23384. $this->SVGTransform($tm);
  23385. // set clipping for width and height
  23386. $x = 0;
  23387. $y = 0;
  23388. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):$this->w);
  23389. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):$this->h);
  23390. // draw clipping rect
  23391. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  23392. // parse viewbox, calculate extra transformation matrix
  23393. if (isset($attribs['viewBox'])) {
  23394. $tmp = array();
  23395. preg_match_all("/[0-9]+/", $attribs['viewBox'], $tmp);
  23396. $tmp = $tmp[0];
  23397. if (sizeof($tmp) == 4) {
  23398. $vx = $tmp[0];
  23399. $vy = $tmp[1];
  23400. $vw = $tmp[2];
  23401. $vh = $tmp[3];
  23402. // get aspect ratio
  23403. $tmp = array();
  23404. $aspectX = 'xMid';
  23405. $aspectY = 'YMid';
  23406. $fit = 'meet';
  23407. if (isset($attribs['preserveAspectRatio'])) {
  23408. if($attribs['preserveAspectRatio'] == 'none') {
  23409. $fit = 'none';
  23410. } else {
  23411. preg_match_all('/[a-zA-Z]+/', $attribs['preserveAspectRatio'], $tmp);
  23412. $tmp = $tmp[0];
  23413. if ((sizeof($tmp) == 2) AND (strlen($tmp[0]) == 8) AND (in_array($tmp[1], array('meet', 'slice', 'none')))) {
  23414. $aspectX = substr($tmp[0], 0, 4);
  23415. $aspectY = substr($tmp[0], 4, 4);
  23416. $fit = $tmp[1];
  23417. }
  23418. }
  23419. }
  23420. $wr = ($svgW / $vw);
  23421. $hr = ($svgH / $vh);
  23422. $ax = $ay = 0;
  23423. if ((($fit == 'meet') AND ($hr < $wr)) OR (($fit == 'slice') AND ($hr > $wr))) {
  23424. if ($aspectX == 'xMax') {
  23425. $ax = (($vw * ($wr / $hr)) - $vw);
  23426. }
  23427. if ($aspectX == 'xMid') {
  23428. $ax = ((($vw * ($wr / $hr)) - $vw) / 2);
  23429. }
  23430. $wr = $hr;
  23431. } elseif ((($fit == 'meet') AND ($hr > $wr)) OR (($fit == 'slice') AND ($hr < $wr))) {
  23432. if ($aspectY == 'YMax') {
  23433. $ay = (($vh * ($hr / $wr)) - $vh);
  23434. }
  23435. if ($aspectY == 'YMid') {
  23436. $ay = ((($vh * ($hr / $wr)) - $vh) / 2);
  23437. }
  23438. $hr = $wr;
  23439. }
  23440. $newtm = array($wr, 0, 0, $hr, (($wr * ($ax - $vx)) - $svgX), (($hr * ($ay - $vy)) - $svgY));
  23441. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, $newtm);
  23442. $this->SVGTransform($tm);
  23443. }
  23444. }
  23445. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23446. break;
  23447. }
  23448. case 'g': {
  23449. // group together related graphics elements
  23450. array_push($this->svgstyles, $svgstyle);
  23451. $this->StartTransform();
  23452. $x = (isset($attribs['x'])?$attribs['x']:0);
  23453. $y = (isset($attribs['y'])?$attribs['y']:0);
  23454. $w = 1;//(isset($attribs['width'])?$attribs['width']:1);
  23455. $h = 1;//(isset($attribs['height'])?$attribs['height']:1);
  23456. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23457. $this->SVGTransform($tm);
  23458. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23459. break;
  23460. }
  23461. case 'linearGradient': {
  23462. if ($this->pdfa_mode && $this->pdfa_version < 2) {
  23463. break;
  23464. }
  23465. if (!isset($attribs['id'])) {
  23466. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23467. }
  23468. $this->svggradientid = $attribs['id'];
  23469. $this->svggradients[$this->svggradientid] = array();
  23470. $this->svggradients[$this->svggradientid]['type'] = 2;
  23471. $this->svggradients[$this->svggradientid]['stops'] = array();
  23472. if (isset($attribs['gradientUnits'])) {
  23473. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23474. } else {
  23475. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23476. }
  23477. //$attribs['spreadMethod']
  23478. if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
  23479. OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
  23480. OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
  23481. OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
  23482. OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
  23483. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23484. } else {
  23485. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23486. }
  23487. $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
  23488. $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
  23489. $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
  23490. $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
  23491. if (isset($attribs['gradientTransform'])) {
  23492. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23493. }
  23494. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  23495. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23496. // gradient is defined on another place
  23497. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23498. }
  23499. break;
  23500. }
  23501. case 'radialGradient': {
  23502. if ($this->pdfa_mode && $this->pdfa_version < 2) {
  23503. break;
  23504. }
  23505. if (!isset($attribs['id'])) {
  23506. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23507. }
  23508. $this->svggradientid = $attribs['id'];
  23509. $this->svggradients[$this->svggradientid] = array();
  23510. $this->svggradients[$this->svggradientid]['type'] = 3;
  23511. $this->svggradients[$this->svggradientid]['stops'] = array();
  23512. if (isset($attribs['gradientUnits'])) {
  23513. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23514. } else {
  23515. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23516. }
  23517. //$attribs['spreadMethod']
  23518. if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
  23519. OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
  23520. OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')))) {
  23521. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23522. } elseif (isset($attribs['r']) AND is_numeric($attribs['r']) AND ($attribs['r']) <= 1) {
  23523. $this->svggradients[$this->svggradientid]['mode'] = 'ratio';
  23524. } else {
  23525. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23526. }
  23527. $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  23528. $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  23529. $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  23530. $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  23531. $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  23532. if (isset($attribs['gradientTransform'])) {
  23533. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23534. }
  23535. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  23536. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23537. // gradient is defined on another place
  23538. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23539. }
  23540. break;
  23541. }
  23542. case 'stop': {
  23543. // gradient stops
  23544. if (substr($attribs['offset'], -1) == '%') {
  23545. $offset = floatval(substr($attribs['offset'], 0, -1)) / 100;
  23546. } else {
  23547. $offset = floatval($attribs['offset']);
  23548. if ($offset > 1) {
  23549. $offset /= 100;
  23550. }
  23551. }
  23552. $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black';
  23553. $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  23554. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
  23555. break;
  23556. }
  23557. // paths
  23558. case 'path': {
  23559. if ($invisible) {
  23560. break;
  23561. }
  23562. if (isset($attribs['d'])) {
  23563. $d = trim($attribs['d']);
  23564. if (!empty($d)) {
  23565. $x = (isset($attribs['x'])?$attribs['x']:0);
  23566. $y = (isset($attribs['y'])?$attribs['y']:0);
  23567. $w = (isset($attribs['width'])?$attribs['width']:1);
  23568. $h = (isset($attribs['height'])?$attribs['height']:1);
  23569. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23570. if ($clipping) {
  23571. $this->SVGTransform($tm);
  23572. $this->SVGPath($d, 'CNZ');
  23573. } else {
  23574. $this->StartTransform();
  23575. $this->SVGTransform($tm);
  23576. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ'));
  23577. if (!empty($obstyle)) {
  23578. $this->SVGPath($d, $obstyle);
  23579. }
  23580. $this->StopTransform();
  23581. }
  23582. }
  23583. }
  23584. break;
  23585. }
  23586. // shapes
  23587. case 'rect': {
  23588. if ($invisible) {
  23589. break;
  23590. }
  23591. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23592. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23593. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23594. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23595. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  23596. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
  23597. if ($clipping) {
  23598. $this->SVGTransform($tm);
  23599. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  23600. } else {
  23601. $this->StartTransform();
  23602. $this->SVGTransform($tm);
  23603. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  23604. if (!empty($obstyle)) {
  23605. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  23606. }
  23607. $this->StopTransform();
  23608. }
  23609. break;
  23610. }
  23611. case 'circle': {
  23612. if ($invisible) {
  23613. break;
  23614. }
  23615. $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
  23616. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23617. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23618. $x = ($cx - $r);
  23619. $y = ($cy - $r);
  23620. $w = (2 * $r);
  23621. $h = $w;
  23622. if ($clipping) {
  23623. $this->SVGTransform($tm);
  23624. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  23625. } else {
  23626. $this->StartTransform();
  23627. $this->SVGTransform($tm);
  23628. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
  23629. if (!empty($obstyle)) {
  23630. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  23631. }
  23632. $this->StopTransform();
  23633. }
  23634. break;
  23635. }
  23636. case 'ellipse': {
  23637. if ($invisible) {
  23638. break;
  23639. }
  23640. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  23641. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
  23642. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23643. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23644. $x = ($cx - $rx);
  23645. $y = ($cy - $ry);
  23646. $w = (2 * $rx);
  23647. $h = (2 * $ry);
  23648. if ($clipping) {
  23649. $this->SVGTransform($tm);
  23650. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  23651. } else {
  23652. $this->StartTransform();
  23653. $this->SVGTransform($tm);
  23654. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  23655. if (!empty($obstyle)) {
  23656. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  23657. }
  23658. $this->StopTransform();
  23659. }
  23660. break;
  23661. }
  23662. case 'line': {
  23663. if ($invisible) {
  23664. break;
  23665. }
  23666. $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
  23667. $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
  23668. $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
  23669. $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
  23670. $x = $x1;
  23671. $y = $y1;
  23672. $w = abs($x2 - $x1);
  23673. $h = abs($y2 - $y1);
  23674. if (!$clipping) {
  23675. $this->StartTransform();
  23676. $this->SVGTransform($tm);
  23677. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
  23678. $this->Line($x1, $y1, $x2, $y2);
  23679. $this->StopTransform();
  23680. }
  23681. break;
  23682. }
  23683. case 'polyline':
  23684. case 'polygon': {
  23685. if ($invisible) {
  23686. break;
  23687. }
  23688. $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  23689. $points = trim($points);
  23690. // note that point may use a complex syntax not covered here
  23691. $points = preg_split('/[\,\s]+/si', $points);
  23692. if (count($points) < 4) {
  23693. break;
  23694. }
  23695. $p = array();
  23696. $xmin = 2147483647;
  23697. $xmax = 0;
  23698. $ymin = 2147483647;
  23699. $ymax = 0;
  23700. foreach ($points as $key => $val) {
  23701. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  23702. if (($key % 2) == 0) {
  23703. // X coordinate
  23704. $xmin = min($xmin, $p[$key]);
  23705. $xmax = max($xmax, $p[$key]);
  23706. } else {
  23707. // Y coordinate
  23708. $ymin = min($ymin, $p[$key]);
  23709. $ymax = max($ymax, $p[$key]);
  23710. }
  23711. }
  23712. $x = $xmin;
  23713. $y = $ymin;
  23714. $w = ($xmax - $xmin);
  23715. $h = ($ymax - $ymin);
  23716. if ($name == 'polyline') {
  23717. $this->StartTransform();
  23718. $this->SVGTransform($tm);
  23719. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
  23720. if (!empty($obstyle)) {
  23721. $this->PolyLine($p, $obstyle, array(), array());
  23722. }
  23723. $this->StopTransform();
  23724. } else { // polygon
  23725. if ($clipping) {
  23726. $this->SVGTransform($tm);
  23727. $this->Polygon($p, 'CNZ', array(), array(), true);
  23728. } else {
  23729. $this->StartTransform();
  23730. $this->SVGTransform($tm);
  23731. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
  23732. if (!empty($obstyle)) {
  23733. $this->Polygon($p, $obstyle, array(), array(), true);
  23734. }
  23735. $this->StopTransform();
  23736. }
  23737. }
  23738. break;
  23739. }
  23740. // image
  23741. case 'image': {
  23742. if ($invisible) {
  23743. break;
  23744. }
  23745. if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  23746. break;
  23747. }
  23748. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23749. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23750. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23751. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23752. $img = $attribs['xlink:href'];
  23753. if (!$clipping) {
  23754. $this->StartTransform();
  23755. $this->SVGTransform($tm);
  23756. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  23757. if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
  23758. // embedded image encoded as base64
  23759. $img = '@'.base64_decode(substr($img, strlen($m[0])));
  23760. } else {
  23761. // fix image path
  23762. if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) {
  23763. // replace relative path with full server path
  23764. $img = $this->svgdir.'/'.$img;
  23765. }
  23766. if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  23767. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  23768. if (($findroot === false) OR ($findroot > 1)) {
  23769. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  23770. $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
  23771. } else {
  23772. $img = $_SERVER['DOCUMENT_ROOT'].$img;
  23773. }
  23774. }
  23775. }
  23776. $img = urldecode($img);
  23777. $testscrtype = @parse_url($img);
  23778. if (empty($testscrtype['query'])) {
  23779. // convert URL to server path
  23780. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  23781. } elseif (preg_match('|^https?://|', $img) !== 1) {
  23782. // convert server path to URL
  23783. $img = str_replace(K_PATH_MAIN, K_PATH_URL, $img);
  23784. }
  23785. }
  23786. // get image type
  23787. $imgtype = TCPDF_IMAGES::getImageFileType($img);
  23788. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  23789. $this->ImageEps($img, $x, $y, $w, $h);
  23790. } elseif ($imgtype == 'svg') {
  23791. // store SVG vars
  23792. $svggradients = $this->svggradients;
  23793. $svggradientid = $this->svggradientid;
  23794. $svgdefsmode = $this->svgdefsmode;
  23795. $svgdefs = $this->svgdefs;
  23796. $svgclipmode = $this->svgclipmode;
  23797. $svgclippaths = $this->svgclippaths;
  23798. $svgcliptm = $this->svgcliptm;
  23799. $svgclipid = $this->svgclipid;
  23800. $svgtext = $this->svgtext;
  23801. $svgtextmode = $this->svgtextmode;
  23802. $this->ImageSVG($img, $x, $y, $w, $h);
  23803. // restore SVG vars
  23804. $this->svggradients = $svggradients;
  23805. $this->svggradientid = $svggradientid;
  23806. $this->svgdefsmode = $svgdefsmode;
  23807. $this->svgdefs = $svgdefs;
  23808. $this->svgclipmode = $svgclipmode;
  23809. $this->svgclippaths = $svgclippaths;
  23810. $this->svgcliptm = $svgcliptm;
  23811. $this->svgclipid = $svgclipid;
  23812. $this->svgtext = $svgtext;
  23813. $this->svgtextmode = $svgtextmode;
  23814. } else {
  23815. $this->Image($img, $x, $y, $w, $h);
  23816. }
  23817. $this->StopTransform();
  23818. }
  23819. break;
  23820. }
  23821. // text
  23822. case 'text':
  23823. case 'tspan': {
  23824. if (isset($this->svgtextmode['text-anchor']) AND !empty($this->svgtext)) {
  23825. // @TODO: unsupported feature
  23826. }
  23827. // only basic support - advanced features must be implemented
  23828. $this->svgtextmode['invisible'] = $invisible;
  23829. if ($invisible) {
  23830. break;
  23831. }
  23832. array_push($this->svgstyles, $svgstyle);
  23833. if (isset($attribs['x'])) {
  23834. $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false);
  23835. } elseif ($name == 'tspan') {
  23836. $x = $this->x;
  23837. } else {
  23838. $x = 0;
  23839. }
  23840. if (isset($attribs['dx'])) {
  23841. $x += $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit, false);
  23842. }
  23843. if (isset($attribs['y'])) {
  23844. $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false);
  23845. } elseif ($name == 'tspan') {
  23846. $y = $this->y;
  23847. } else {
  23848. $y = 0;
  23849. }
  23850. if (isset($attribs['dy'])) {
  23851. $y += $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit, false);
  23852. }
  23853. $svgstyle['text-color'] = $svgstyle['fill'];
  23854. $this->svgtext = '';
  23855. if (isset($svgstyle['text-anchor'])) {
  23856. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  23857. } else {
  23858. $this->svgtextmode['text-anchor'] = 'start';
  23859. }
  23860. if (isset($svgstyle['direction'])) {
  23861. if ($svgstyle['direction'] == 'rtl') {
  23862. $this->svgtextmode['rtl'] = true;
  23863. } else {
  23864. $this->svgtextmode['rtl'] = false;
  23865. }
  23866. } else {
  23867. $this->svgtextmode['rtl'] = false;
  23868. }
  23869. if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  23870. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  23871. } else {
  23872. $this->svgtextmode['stroke'] = false;
  23873. }
  23874. $this->StartTransform();
  23875. $this->SVGTransform($tm);
  23876. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  23877. $this->x = $x;
  23878. $this->y = $y;
  23879. break;
  23880. }
  23881. // use
  23882. case 'use': {
  23883. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23884. $svgdefid = substr($attribs['xlink:href'], 1);
  23885. if (isset($this->svgdefs[$svgdefid])) {
  23886. $use = $this->svgdefs[$svgdefid];
  23887. if (isset($attribs['xlink:href'])) {
  23888. unset($attribs['xlink:href']);
  23889. }
  23890. if (isset($attribs['id'])) {
  23891. unset($attribs['id']);
  23892. }
  23893. if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
  23894. $attribs['x'] += $use['attribs']['x'];
  23895. }
  23896. if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
  23897. $attribs['y'] += $use['attribs']['y'];
  23898. }
  23899. if (empty($attribs['style'])) {
  23900. $attribs['style'] = '';
  23901. }
  23902. if (!empty($use['attribs']['style'])) {
  23903. // merge styles
  23904. $attribs['style'] = str_replace(';;',';',';'.$use['attribs']['style'].$attribs['style']);
  23905. }
  23906. $attribs = array_merge($use['attribs'], $attribs);
  23907. $this->startSVGElementHandler($parser, $use['name'], $attribs);
  23908. return;
  23909. }
  23910. }
  23911. break;
  23912. }
  23913. default: {
  23914. break;
  23915. }
  23916. } // end of switch
  23917. // process child elements
  23918. if (!empty($attribs['child_elements'])) {
  23919. $child_elements = $attribs['child_elements'];
  23920. unset($attribs['child_elements']);
  23921. foreach($child_elements as $child_element) {
  23922. if (empty($child_element['attribs']['closing_tag'])) {
  23923. $this->startSVGElementHandler('child-tag', $child_element['name'], $child_element['attribs']);
  23924. } else {
  23925. if (isset($child_element['attribs']['content'])) {
  23926. $this->svgtext = $child_element['attribs']['content'];
  23927. }
  23928. $this->endSVGElementHandler('child-tag', $child_element['name']);
  23929. }
  23930. }
  23931. }
  23932. }
  23933. /**
  23934. * Sets the closing SVG element handler function for the XML parser.
  23935. * @param resource|string $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  23936. * @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.
  23937. * @author Nicola Asuni
  23938. * @since 5.0.000 (2010-05-02)
  23939. * @protected
  23940. */
  23941. protected function endSVGElementHandler($parser, $name) {
  23942. $name = $this->removeTagNamespace($name);
  23943. if ($this->svgdefsmode AND !in_array($name, array('defs', 'clipPath', 'linearGradient', 'radialGradient', 'stop'))) {;
  23944. if (end($this->svgdefs) !== FALSE) {
  23945. $last_svgdefs_id = key($this->svgdefs);
  23946. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23947. foreach($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) {
  23948. if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) {
  23949. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext));
  23950. return;
  23951. }
  23952. }
  23953. if ($this->svgdefs[$last_svgdefs_id]['name'] == $name) {
  23954. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext));
  23955. return;
  23956. }
  23957. }
  23958. }
  23959. return;
  23960. }
  23961. switch($name) {
  23962. case 'defs': {
  23963. $this->svgdefsmode = false;
  23964. break;
  23965. }
  23966. // clipPath
  23967. case 'clipPath': {
  23968. $this->svgclipmode = false;
  23969. break;
  23970. }
  23971. case 'svg': {
  23972. if (--$this->svg_tag_depth <= 0) {
  23973. break;
  23974. }
  23975. }
  23976. case 'g': {
  23977. // ungroup: remove last style from array
  23978. array_pop($this->svgstyles);
  23979. $this->StopTransform();
  23980. break;
  23981. }
  23982. case 'text':
  23983. case 'tspan': {
  23984. if ($this->svgtextmode['invisible']) {
  23985. // This implementation must be fixed to following the rule:
  23986. // 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.
  23987. break;
  23988. }
  23989. // print text
  23990. $text = $this->svgtext;
  23991. //$text = $this->stringTrim($text);
  23992. $textlen = $this->GetStringWidth($text);
  23993. if ($this->svgtextmode['text-anchor'] != 'start') {
  23994. // check if string is RTL text
  23995. if ($this->svgtextmode['text-anchor'] == 'end') {
  23996. if ($this->svgtextmode['rtl']) {
  23997. $this->x += $textlen;
  23998. } else {
  23999. $this->x -= $textlen;
  24000. }
  24001. } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  24002. if ($this->svgtextmode['rtl']) {
  24003. $this->x += ($textlen / 2);
  24004. } else {
  24005. $this->x -= ($textlen / 2);
  24006. }
  24007. }
  24008. }
  24009. $textrendermode = $this->textrendermode;
  24010. $textstrokewidth = $this->textstrokewidth;
  24011. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  24012. if ($name == 'text') {
  24013. // store current coordinates
  24014. $tmpx = $this->x;
  24015. $tmpy = $this->y;
  24016. }
  24017. // print the text
  24018. $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  24019. if ($name == 'text') {
  24020. // restore coordinates
  24021. $this->x = $tmpx;
  24022. $this->y = $tmpy;
  24023. }
  24024. // restore previous rendering mode
  24025. $this->textrendermode = $textrendermode;
  24026. $this->textstrokewidth = $textstrokewidth;
  24027. $this->svgtext = '';
  24028. $this->StopTransform();
  24029. if (!$this->svgdefsmode) {
  24030. array_pop($this->svgstyles);
  24031. }
  24032. break;
  24033. }
  24034. default: {
  24035. break;
  24036. }
  24037. }
  24038. }
  24039. /**
  24040. * Sets the character data handler function for the XML parser.
  24041. * @param resource $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  24042. * @param string $data The second parameter, data, contains the character data as a string.
  24043. * @author Nicola Asuni
  24044. * @since 5.0.000 (2010-05-02)
  24045. * @protected
  24046. */
  24047. protected function segSVGContentHandler($parser, $data) {
  24048. $this->svgtext .= $data;
  24049. }
  24050. // --- END SVG METHODS -----------------------------------------------------
  24051. /**
  24052. * Keeps files in memory, so it doesn't need to downloaded everytime in a loop
  24053. * @param string $file
  24054. * @return string
  24055. */
  24056. protected function getCachedFileContents($file)
  24057. {
  24058. if (!isset($this->fileContentCache[$file])) {
  24059. $this->fileContentCache[$file] = TCPDF_STATIC::fileGetContents($file);
  24060. }
  24061. return $this->fileContentCache[$file];
  24062. }
  24063. /**
  24064. * Avoid multiple calls to an external server to see if a file exists
  24065. * @param string $file
  24066. * @return bool
  24067. */
  24068. protected function fileExists($file)
  24069. {
  24070. if (isset($this->fileContentCache[$file]) || false !== $this->getImageBuffer($file)) {
  24071. return true;
  24072. }
  24073. return TCPDF_STATIC::file_exists($file);
  24074. }
  24075. } // END OF TCPDF CLASS
  24076. //============================================================+
  24077. // END OF FILE
  24078. //============================================================+